Ticket #9486: 0001-iso9660-fs-driver-bugfix-code-refactoring.patch

File 0001-iso9660-fs-driver-bugfix-code-refactoring.patch, 11.5 KB (added by beos_zealot, 8 years ago)
  • src/add-ons/kernel/file_systems/iso9660/iso9660.cpp

    From eb77916297d1108126b2e0e56f76f5dc8c6149f8 Mon Sep 17 00:00:00 2001
    From: Gediminas Jarulaitis <beos.zealot@gmail.com>
    Date: Sun, 3 Mar 2013 20:12:52 +0200
    Subject: [PATCH] iso9660 fs driver bugfix + code refactoring
    
    ---
     .../kernel/file_systems/iso9660/iso9660.cpp        |  141 +++++++++++---------
     src/add-ons/kernel/file_systems/iso9660/iso9660.h  |   25 ++--
     2 files changed, 94 insertions(+), 72 deletions(-)
    
    diff --git a/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp b/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp
    index 039c57d..8012b87 100644
    a b sanitize_iso_name(iso9660_inode* node, bool removeTrailingPoints)  
    144144static int
    145145init_volume_date(ISOVolDate *date, char *buffer)
    146146{
    147     memcpy(date, buffer, 17);
     147    memcpy(date, buffer, ISO_VOL_DATE_SIZE);
    148148    return 0;
    149149}
    150150
    init_volume_date(ISOVolDate *date, char *buffer)  
    152152static int
    153153init_node_date(ISORecDate *date, char *buffer)
    154154{
    155     memcpy(date, buffer, 7);
     155    memcpy(date, buffer, sizeof(struct ISORecDate));
    156156    return 0;
    157157}
    158158
    InitVolDesc(iso9660_volume *volume, char *buffer)  
    162162{
    163163    TRACE(("InitVolDesc - ENTER\n"));
    164164
    165     volume->volDescType = *(uint8 *)buffer++;
    166 
    167     volume->stdIDString[5] = '\0';
    168     strncpy(volume->stdIDString, buffer, 5);
    169     buffer += 5;
     165    volume->volDescType = *(uint8 *)buffer;
     166    buffer += sizeof(volume->volDescType);
     167   
     168    const size_t kStdIDStringLen = sizeof(volume->stdIDString) - 1;
     169    volume->stdIDString[kStdIDStringLen] = '\0';
     170    strncpy(volume->stdIDString, buffer, kStdIDStringLen);
     171    buffer += kStdIDStringLen;
    170172
    171173    volume->volDescVersion = *(uint8 *)buffer;
    172     buffer += 2; // 8th byte unused
    173 
    174     volume->systemIDString[32] = '\0';
    175     strncpy(volume->systemIDString, buffer, 32);
    176     buffer += 32;
     174    buffer += sizeof(volume->volDescVersion);
     175   
     176    buffer += sizeof(volume->unused1); // skip unused 8th byte
     177
     178    const size_t kSystemIDStringLen = sizeof(volume->systemIDString) - 1;
     179    volume->systemIDString[kSystemIDStringLen] = '\0';
     180    strncpy(volume->systemIDString, buffer, kSystemIDStringLen);
     181    buffer += kSystemIDStringLen;
    177182    TRACE(("InitVolDesc - system id string is %s\n", volume->systemIDString));
    178 
    179     volume->volIDString[32] = '\0';
    180     strncpy(volume->volIDString, buffer, 32);
    181     buffer += (32 + 80-73 + 1); // bytes 80-73 unused
     183   
     184    const size_t kVolIDStringLen = sizeof(volume->volIDString) - 1;
     185    volume->volIDString[kVolIDStringLen] = '\0';
     186    strncpy(volume->volIDString, buffer, kVolIDStringLen);
     187    buffer += kVolIDStringLen;
    182188    TRACE(("InitVolDesc - volume id string is %s\n", volume->volIDString));
    183189
     190    buffer += sizeof(volume->unused2) - 1; // skip unused 73-80 bytes
     191
    184192    volume->volSpaceSize[LSB_DATA] = *(uint32 *)buffer;
    185     buffer += 4;
     193    buffer += sizeof(volume->volSpaceSize[LSB_DATA]);
    186194    volume->volSpaceSize[MSB_DATA] = *(uint32 *)buffer;
    187     buffer+= (4 + 120-89 + 1);      // bytes 120-89 unused
    188 
     195    buffer += sizeof(volume->volSpaceSize[MSB_DATA]);
     196   
     197    buffer += sizeof(volume->unused3) - 1; // skip unused 89-120 bytes
     198   
    189199    volume->volSetSize[LSB_DATA] = *(uint16*)buffer;
    190     buffer += 2;
     200    buffer += sizeof(volume->volSetSize[LSB_DATA]);
    191201    volume->volSetSize[MSB_DATA] = *(uint16*)buffer;
    192     buffer += 2;
     202    buffer += sizeof(volume->volSetSize[MSB_DATA]);
    193203
    194204    volume->volSeqNum[LSB_DATA] = *(uint16*)buffer;
    195     buffer += 2;
     205    buffer += sizeof(volume->volSeqNum[LSB_DATA]);
    196206    volume->volSeqNum[MSB_DATA] = *(uint16*)buffer;
    197     buffer += 2;
     207    buffer += sizeof(volume->volSeqNum[MSB_DATA]);
    198208
    199209    volume->logicalBlkSize[LSB_DATA] = *(uint16*)buffer;
    200     buffer += 2;
     210    buffer += sizeof(volume->logicalBlkSize[LSB_DATA]);
    201211    volume->logicalBlkSize[MSB_DATA] = *(uint16*)buffer;
    202     buffer += 2;
     212    buffer += sizeof(volume->logicalBlkSize[MSB_DATA]);
    203213
    204214    volume->pathTblSize[LSB_DATA] = *(uint32*)buffer;
    205     buffer += 4;
     215    buffer += sizeof(volume->pathTblSize[LSB_DATA]);
    206216    volume->pathTblSize[MSB_DATA] = *(uint32*)buffer;
    207     buffer += 4;
     217    buffer += sizeof(volume->pathTblSize[MSB_DATA]);
    208218
    209219    volume->lPathTblLoc[LSB_DATA] = *(uint16*)buffer;
    210     buffer += 2;
     220    buffer += sizeof(volume->lPathTblLoc[LSB_DATA]);
    211221    volume->lPathTblLoc[MSB_DATA] = *(uint16*)buffer;
    212     buffer += 2;
     222    buffer += sizeof(volume->lPathTblLoc[MSB_DATA]);
    213223
    214224    volume->optLPathTblLoc[LSB_DATA] = *(uint16*)buffer;
    215     buffer += 2;
     225    buffer += sizeof(volume->optLPathTblLoc[LSB_DATA]);
    216226    volume->optLPathTblLoc[MSB_DATA] = *(uint16*)buffer;
    217     buffer += 2;
     227    buffer += sizeof(volume->optLPathTblLoc[MSB_DATA]);
    218228
    219229    volume->mPathTblLoc[LSB_DATA] = *(uint16*)buffer;
    220     buffer += 2;
     230    buffer += sizeof(volume->mPathTblLoc[LSB_DATA]);
    221231    volume->mPathTblLoc[MSB_DATA] = *(uint16*)buffer;
    222     buffer += 2;
     232    buffer += sizeof(volume->mPathTblLoc[MSB_DATA]);
    223233
    224234    volume->optMPathTblLoc[LSB_DATA] = *(uint16*)buffer;
    225     buffer += 2;
     235    buffer += sizeof(volume->optMPathTblLoc[LSB_DATA]);
    226236    volume->optMPathTblLoc[MSB_DATA] = *(uint16*)buffer;
    227     buffer += 2;
     237    buffer += sizeof(volume->optMPathTblLoc[MSB_DATA]);
    228238
    229239    // Fill in directory record.
    230240    volume->joliet_level = 0;
    231241    InitNode(volume, &volume->rootDirRec, buffer, NULL);
    232242
    233243    volume->rootDirRec.id = ISO_ROOTNODE_ID;
    234     buffer += 34;
    235 
    236     volume->volSetIDString[128] = '\0';
    237     strncpy(volume->volSetIDString, buffer, 128);
    238     buffer += 128;
     244    buffer += ISO_ROOT_DIR_REC_SIZE;
     245   
     246    const size_t kVolSetIDStringLen = sizeof(volume->volSetIDString) - 1;
     247    volume->volSetIDString[kVolSetIDStringLen] = '\0';
     248    strncpy(volume->volSetIDString, buffer, kVolSetIDStringLen);
     249    buffer += kVolSetIDStringLen;
    239250    TRACE(("InitVolDesc - volume set id string is %s\n", volume->volSetIDString));
    240251
    241     volume->pubIDString[128] = '\0';
    242     strncpy(volume->pubIDString, buffer, 128);
    243     buffer += 128;
     252    const size_t kPubIDStringLen = sizeof(volume->pubIDString) - 1;
     253    volume->pubIDString[kPubIDStringLen] = '\0';
     254    strncpy(volume->pubIDString, buffer, kPubIDStringLen);
     255    buffer += kPubIDStringLen;
    244256    TRACE(("InitVolDesc - volume pub id string is %s\n", volume->pubIDString));
    245257
    246     volume->dataPreparer[128] = '\0';
    247     strncpy(volume->dataPreparer, buffer, 128);
    248     buffer += 128;
     258    const size_t kDataPreparerLen = sizeof(volume->dataPreparer) - 1;
     259    volume->dataPreparer[kDataPreparerLen] = '\0';
     260    strncpy(volume->dataPreparer, buffer, kDataPreparerLen);
     261    buffer += kDataPreparerLen;
    249262    TRACE(("InitVolDesc - volume dataPreparer string is %s\n", volume->dataPreparer));
    250263
    251     volume->appIDString[128] = '\0';
    252     strncpy(volume->appIDString, buffer, 128);
    253     buffer += 128;
     264    const size_t kAppIDStringLen = sizeof(volume->appIDString) - 1;
     265    volume->appIDString[kAppIDStringLen] = '\0';
     266    strncpy(volume->appIDString, buffer, kAppIDStringLen);
     267    buffer += kAppIDStringLen;
    254268    TRACE(("InitVolDesc - volume app id string is %s\n", volume->appIDString));
    255269
    256     volume->copyright[38] = '\0';
    257     strncpy(volume->copyright, buffer, 38);
    258     buffer += 38;
     270    const size_t kCopyrightLen = sizeof(volume->copyright) - 1;
     271    volume->copyright[kCopyrightLen] = '\0';
     272    strncpy(volume->copyright, buffer, kCopyrightLen);
     273    buffer += kCopyrightLen;
    259274    TRACE(("InitVolDesc - copyright is %s\n", volume->copyright));
    260275
    261     volume->abstractFName[38] = '\0';
    262     strncpy(volume->abstractFName, buffer, 38);
    263     buffer += 38;
     276    const size_t kAbstractFNameLen = sizeof(volume->abstractFName) - 1;
     277    volume->abstractFName[kAbstractFNameLen] = '\0';
     278    strncpy(volume->abstractFName, buffer, kAbstractFNameLen);
     279    buffer += kAbstractFNameLen;
    264280
    265     volume->biblioFName[38] = '\0';
    266     strncpy(volume->biblioFName, buffer, 38);
    267     buffer += 38;
     281    const size_t kBiblioFNameLen = sizeof(volume->biblioFName) - 1;
     282    volume->biblioFName[kBiblioFNameLen] = '\0';
     283    strncpy(volume->biblioFName, buffer, kBiblioFNameLen);
     284    buffer += kBiblioFNameLen;
    268285
    269286    init_volume_date(&volume->createDate, buffer);
    270     buffer += 17;
     287    buffer += ISO_VOL_DATE_SIZE;
    271288
    272289    init_volume_date(&volume->modDate, buffer);
    273     buffer += 17;
     290    buffer += ISO_VOL_DATE_SIZE;
    274291
    275292    init_volume_date(&volume->expireDate, buffer);
    276     buffer += 17;
     293    buffer += ISO_VOL_DATE_SIZE;
    277294
    278295    init_volume_date(&volume->effectiveDate, buffer);
    279     buffer += 17;
     296    buffer += ISO_VOL_DATE_SIZE;
    280297
    281298    volume->fileStructVers = *(uint8*)buffer;
    282299    return B_OK;
  • src/add-ons/kernel/file_systems/iso9660/iso9660.h

    diff --git a/src/add-ons/kernel/file_systems/iso9660/iso9660.h b/src/add-ons/kernel/file_systems/iso9660/iso9660.h
    index 32da4d8..a98c6d8 100644
    a b typedef struct ISOVolDate {  
    5656    int8    offsetGMT;
    5757} ISOVolDate;
    5858
     59// Size of volume date and time data
     60#define ISO_VOL_DATE_SIZE 17
     61
    5962typedef struct ISORecDate {
    6063    uint8   year;           // Year - 1900
    6164    uint8   month;
    struct iso9660_volume {  
    183186    uint8           volDescType;        // Volume Descriptor type                               byte1
    184187    char            stdIDString[6];     // Standard ID, 1 extra for null                        byte2-6
    185188    uint8           volDescVersion;     // Volume Descriptor version                            byte7
    186                                                                             // 8th byte unused
     189    uint8           unused1;            // Unused Field                                         byte8
    187190    char            systemIDString[33]; // System ID, 1 extra for null                          byte9-40
    188191    char            volIDString[33];    // Volume ID, 1 extra for null                          byte41-72
    189                                                                             // bytes 73-80 unused
    190     uint32          volSpaceSize[2];    // #logical blocks, lsb and msb                                 byte81-88
    191                                                                         // bytes 89-120 unused
     192    char            unused2[9];         // Unused Field                                         byte73-80
     193    uint32          volSpaceSize[2];    // #logical blocks, lsb and msb                         byte81-88
     194    char            unused3[33];        // Unused Field                                         byte89-120
    192195    uint16          volSetSize[2];      // Assigned Volume Set Size of Vol                      byte121-124
    193196    uint16          volSeqNum[2];       // Ordinal number of volume in Set                      byte125-128
    194197    uint16          logicalBlkSize[2];  // Logical blocksize, usually 2048                      byte129-132
    195198    uint32          pathTblSize[2];     // Path table size                                      byte133-149
    196     uint16          lPathTblLoc[2];     // Loc (Logical block #) of "Type L" path table     byte141-144
    197     uint16          optLPathTblLoc[2];  // Loc (Logical block #) of optional Type L path tbl        byte145-148
    198     uint16          mPathTblLoc[2];     // Loc (Logical block #) of "Type M" path table     byte149-152
    199     uint16          optMPathTblLoc[2];      // Loc (Logical block #) of optional Type M path tbl    byte153-156
    200     iso9660_inode           rootDirRec;         // Directory record for root directory                  byte157-190
     199    uint16          lPathTblLoc[2];     // Loc (Logical block #) of "Type L" path table         byte141-144
     200    uint16          optLPathTblLoc[2];  // Loc (Logical block #) of optional Type L path tbl    byte145-148
     201    uint16          mPathTblLoc[2];     // Loc (Logical block #) of "Type M" path table         byte149-152
     202    uint16          optMPathTblLoc[2];  // Loc (Logical block #) of optional Type M path tbl    byte153-156
     203    iso9660_inode   rootDirRec;         // Directory record for root directory                  byte157-190
    201204    char            volSetIDString[129]; // Name of multi-volume set where vol is member        byte191-318
    202205    char            pubIDString[129];   // Name of publisher                                    byte319-446
    203206    char            dataPreparer[129];  // Name of data preparer                                byte447-574
    204207    char            appIDString[129];   // Identifies data fomrat                               byte575-702
    205208    char            copyright[38];      // Copyright string                                     byte703-739
    206209    char            abstractFName[38];  // Name of file in root that has abstract               byte740-776
    207     char            biblioFName[38];    // Name of file in root that has biblio             byte777-813
     210    char            biblioFName[38];    // Name of file in root that has biblio                 byte777-813
    208211
    209212    ISOVolDate      createDate;         // Creation date                                        byte
    210213    ISOVolDate      modDate;            // Modification date
    struct iso9660_volume {  
    214217    uint8           fileStructVers;     // File structure version                               byte882
    215218};
    216219
     220// Size of root directory record
     221#define ISO_ROOT_DIR_REC_SIZE 34
    217222
    218223status_t ISOMount(const char *path, uint32 flags, iso9660_volume** _newVolume,
    219224    bool allowJoliet);