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

File 0002-iso9660-fs-driver-code-refactoring-with-bugfix.patch, 11.4 KB (added by beos_zealot, 12 years ago)
  • src/add-ons/kernel/file_systems/iso9660/iso9660.cpp

    From eb8f2f38824861ff723f5378e6941564f796636b Mon Sep 17 00:00:00 2001
    From: Gediminas Jarulaitis <beos.zealot@gmail.com>
    Date: Fri, 1 Mar 2013 21:14:31 +0200
    Subject: [PATCH 2/2] iso9660 fs driver code refactoring with bugfix
    
    ---
     .../kernel/file_systems/iso9660/iso9660.cpp        |  138 +++++++++++---------
     src/add-ons/kernel/file_systems/iso9660/iso9660.h  |   25 ++--
     2 files changed, 92 insertions(+), 71 deletions(-)
    
    diff --git a/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp b/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp
    index c115cc6..3d7dba0 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)  
    163163    TRACE(("InitVolDesc - ENTER\n"));
    164164
    165165    volume->volDescType = *(uint8 *)buffer++;
    166 
    167     volume->stdIDString[5] = '\0';
    168     strncpy(volume->stdIDString, buffer, 5);
    169     buffer += 5;
     166   
     167    const size_t kStdIDStringLen = sizeof(volume->stdIDString) - 1;
     168    volume->stdIDString[kStdIDStringLen] = '\0';
     169    strncpy(volume->stdIDString, buffer, kStdIDStringLen);
     170    buffer += kStdIDStringLen;
    170171
    171172    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;
     173    buffer += sizeof(volume->volDescVersion);
     174   
     175    buffer += sizeof(volume->unused1); // skip unused 8th byte
     176
     177    const size_t kSystemIDStringLen = sizeof(volume->systemIDString) - 1;
     178    volume->systemIDString[kSystemIDStringLen] = '\0';
     179    strncpy(volume->systemIDString, buffer, kSystemIDStringLen);
     180    buffer += kSystemIDStringLen;
    177181    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
     182   
     183    const size_t kVolIDStringLen = sizeof(volume->volIDString) - 1;
     184    volume->volIDString[kVolIDStringLen] = '\0';
     185    strncpy(volume->volIDString, buffer, kVolIDStringLen);
     186    buffer += kVolIDStringLen;
    182187    TRACE(("InitVolDesc - volume id string is %s\n", volume->volIDString));
    183188
     189    buffer += sizeof(volume->unused2) - 1; // skip unused 80-73 bytes
     190
    184191    volume->volSpaceSize[LSB_DATA] = *(uint32 *)buffer;
    185     buffer += 4;
     192    buffer += sizeof(volume->volSpaceSize[LSB_DATA]);
    186193    volume->volSpaceSize[MSB_DATA] = *(uint32 *)buffer;
    187     buffer+= (4 + 120-89 + 1);      // bytes 120-89 unused
    188 
     194    buffer += sizeof(volume->volSpaceSize[MSB_DATA]);
     195   
     196    buffer += sizeof(volume->unused3) - 1; // skip unused 89-120 bytes
     197   
    189198    volume->volSetSize[LSB_DATA] = *(uint16*)buffer;
    190     buffer += 2;
     199    buffer += sizeof(volume->volSetSize[LSB_DATA]);
    191200    volume->volSetSize[MSB_DATA] = *(uint16*)buffer;
    192     buffer += 2;
     201    buffer += sizeof(volume->volSetSize[MSB_DATA]);
    193202
    194203    volume->volSeqNum[LSB_DATA] = *(uint16*)buffer;
    195     buffer += 2;
     204    buffer += sizeof(volume->volSeqNum[LSB_DATA]);
    196205    volume->volSeqNum[MSB_DATA] = *(uint16*)buffer;
    197     buffer += 2;
     206    buffer += sizeof(volume->volSeqNum[MSB_DATA]);
    198207
    199208    volume->logicalBlkSize[LSB_DATA] = *(uint16*)buffer;
    200     buffer += 2;
     209    buffer += sizeof(volume->logicalBlkSize[LSB_DATA]);
    201210    volume->logicalBlkSize[MSB_DATA] = *(uint16*)buffer;
    202     buffer += 2;
     211    buffer += sizeof(volume->logicalBlkSize[MSB_DATA]);
    203212
    204213    volume->pathTblSize[LSB_DATA] = *(uint32*)buffer;
    205     buffer += 4;
     214    buffer += sizeof(volume->pathTblSize[LSB_DATA]);
    206215    volume->pathTblSize[MSB_DATA] = *(uint32*)buffer;
    207     buffer += 4;
     216    buffer += sizeof(volume->pathTblSize[MSB_DATA]);
    208217
    209218    volume->lPathTblLoc[LSB_DATA] = *(uint16*)buffer;
    210     buffer += 2;
     219    buffer += sizeof(volume->lPathTblLoc[LSB_DATA]);
    211220    volume->lPathTblLoc[MSB_DATA] = *(uint16*)buffer;
    212     buffer += 2;
     221    buffer += sizeof(volume->lPathTblLoc[MSB_DATA]);
    213222
    214223    volume->optLPathTblLoc[LSB_DATA] = *(uint16*)buffer;
    215     buffer += 2;
     224    buffer += sizeof(volume->optLPathTblLoc[LSB_DATA]);
    216225    volume->optLPathTblLoc[MSB_DATA] = *(uint16*)buffer;
    217     buffer += 2;
     226    buffer += sizeof(volume->optLPathTblLoc[MSB_DATA]);
    218227
    219228    volume->mPathTblLoc[LSB_DATA] = *(uint16*)buffer;
    220     buffer += 2;
     229    buffer += sizeof(volume->mPathTblLoc[LSB_DATA]);
    221230    volume->mPathTblLoc[MSB_DATA] = *(uint16*)buffer;
    222     buffer += 2;
     231    buffer += sizeof(volume->mPathTblLoc[MSB_DATA]);
    223232
    224233    volume->optMPathTblLoc[LSB_DATA] = *(uint16*)buffer;
    225     buffer += 2;
     234    buffer += sizeof(volume->optMPathTblLoc[LSB_DATA]);
    226235    volume->optMPathTblLoc[MSB_DATA] = *(uint16*)buffer;
    227     buffer += 2;
     236    buffer += sizeof(volume->optMPathTblLoc[MSB_DATA]);
    228237
    229238    // Fill in directory record.
    230239    volume->joliet_level = 0;
    231240    InitNode(volume, &volume->rootDirRec, buffer, NULL);
    232241
    233242    volume->rootDirRec.id = ISO_ROOTNODE_ID;
    234     buffer += 34;
    235 
    236     volume->volSetIDString[128] = '\0';
    237     strncpy(volume->volSetIDString, buffer, 128);
    238     buffer += 128;
     243    buffer += ISO_ROOT_DIR_REC_SIZE;
     244   
     245    const size_t kVolSetIDStringLen = sizeof(volume->volSetIDString) - 1;
     246    volume->volSetIDString[kVolSetIDStringLen] = '\0';
     247    strncpy(volume->volSetIDString, buffer, kVolSetIDStringLen);
     248    buffer += kVolSetIDStringLen;
    239249    TRACE(("InitVolDesc - volume set id string is %s\n", volume->volSetIDString));
    240250
    241     volume->pubIDString[128] = '\0';
    242     strncpy(volume->pubIDString, buffer, 128);
    243     buffer += 128;
     251    const size_t kPubIDStringLen = sizeof(volume->pubIDString) - 1;
     252    volume->pubIDString[kPubIDStringLen] = '\0';
     253    strncpy(volume->pubIDString, buffer, kPubIDStringLen);
     254    buffer += kPubIDStringLen;
    244255    TRACE(("InitVolDesc - volume pub id string is %s\n", volume->pubIDString));
    245256
    246     volume->dataPreparer[128] = '\0';
    247     strncpy(volume->dataPreparer, buffer, 128);
    248     buffer += 128;
     257    const size_t kDataPreparerLen = sizeof(volume->dataPreparer) - 1;
     258    volume->dataPreparer[kDataPreparerLen] = '\0';
     259    strncpy(volume->dataPreparer, buffer, kDataPreparerLen);
     260    buffer += kDataPreparerLen;
    249261    TRACE(("InitVolDesc - volume dataPreparer string is %s\n", volume->dataPreparer));
    250262
    251     volume->appIDString[128] = '\0';
    252     strncpy(volume->appIDString, buffer, 128);
    253     buffer += 128;
     263    const size_t kAppIDStringLen = sizeof(volume->appIDString) - 1;
     264    volume->appIDString[kAppIDStringLen] = '\0';
     265    strncpy(volume->appIDString, buffer, kAppIDStringLen);
     266    buffer += kAppIDStringLen;
    254267    TRACE(("InitVolDesc - volume app id string is %s\n", volume->appIDString));
    255268
    256     volume->copyright[37] = '\0';
    257     strncpy(volume->copyright, buffer, 37);
    258     buffer += 37;
     269    const size_t kCopyrightLen = sizeof(volume->copyright) - 1;
     270    volume->copyright[kCopyrightLen] = '\0';
     271    strncpy(volume->copyright, buffer, kCopyrightLen);
     272    buffer += kCopyrightLen;
    259273    TRACE(("InitVolDesc - copyright is %s\n", volume->copyright));
    260274
    261     volume->abstractFName[37] = '\0';
    262     strncpy(volume->abstractFName, buffer, 37);
    263     buffer += 37;
     275    const size_t kAbstractFNameLen = sizeof(volume->abstractFName) - 1;
     276    volume->abstractFName[kAbstractFNameLen] = '\0';
     277    strncpy(volume->abstractFName, buffer, kAbstractFNameLen);
     278    buffer += kAbstractFNameLen;
    264279
    265     volume->biblioFName[37] = '\0';
    266     strncpy(volume->biblioFName, buffer, 37);
    267     buffer += 37;
     280    const size_t kBiblioFNameLen = sizeof(volume->biblioFName) - 1;
     281    volume->biblioFName[kBiblioFNameLen] = '\0';
     282    strncpy(volume->biblioFName, buffer, kBiblioFNameLen);
     283    buffer += kBiblioFNameLen;
    268284
    269285    init_volume_date(&volume->createDate, buffer);
    270     buffer += 17;
     286    buffer += ISO_VOL_DATE_SIZE;
    271287
    272288    init_volume_date(&volume->modDate, buffer);
    273     buffer += 17;
     289    buffer += ISO_VOL_DATE_SIZE;
    274290
    275291    init_volume_date(&volume->expireDate, buffer);
    276     buffer += 17;
     292    buffer += ISO_VOL_DATE_SIZE;
    277293
    278294    init_volume_date(&volume->effectiveDate, buffer);
    279     buffer += 17;
     295    buffer += ISO_VOL_DATE_SIZE;
    280296
    281297    volume->fileStructVers = *(uint8*)buffer;
    282298    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..1a54c05 100644
    a b typedef struct ISOVolDate {  
    5656    int8    offsetGMT;
    5757} ISOVolDate;
    5858
     59// Size of date and time field
     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// Root directory record size
     221#define ISO_ROOT_DIR_REC_SIZE 34
    217222
    218223status_t ISOMount(const char *path, uint32 flags, iso9660_volume** _newVolume,
    219224    bool allowJoliet);