Changeset 8271ae37 in mainline


Ignore:
Timestamp:
2012-02-26T13:05:51Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
528acda
Parents:
ff415f62
Message:

mkexfat: Move checksum sectors initialization outside the Extended Boot Sector initialization function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/mkexfat/mkexfat.c

    rff415f62 r8271ae37  
    6767/** First sector of the Main Boot Sector Backup */
    6868#define MBS_BACKUP_SECTOR 12
     69
     70/** VBR Checksum sector */
     71#define VBR_CHECKSUM_SECTOR 11
     72
     73/** VBR Backup Checksum sector */
     74#define VBR_BACKUP_CHECKSUM_SECTOR 23
    6975
    7076/** Size of the Main Extended Boot Region */
     
    252258        exfat_bs_t mbs;
    253259        uint32_t vbr_checksum;
    254         uint32_t initial_checksum;
     260        uint32_t *chksum_sector;
    255261        int rc;
     262        unsigned idx;
     263
     264        chksum_sector = calloc(cfg->sector_size, sizeof(uint8_t));
     265        if (!chksum_sector)
     266                return ENOMEM;
    256267
    257268        vbr_checksum = vbr_initialize(&mbs, cfg);
    258         initial_checksum = vbr_checksum;
    259269
    260270        /* Write the Main Boot Sector to disk */
    261271        rc = block_write_direct(service_id, MBS_SECTOR, 1, &mbs);
    262272        if (rc != EOK)
    263                 return rc;
     273                goto exit;
    264274
    265275        /* Write the Main extended boot sectors to disk */
    266276        rc = ebs_write(service_id, cfg, EBS_SECTOR_START, &vbr_checksum);
    267277        if (rc != EOK)
    268                 return rc;
     278                goto exit;
    269279
    270280        /* Write the Main Boot Sector backup to disk */
    271281        rc = block_write_direct(service_id, MBS_BACKUP_SECTOR, 1, &mbs);
    272282        if (rc != EOK)
    273                 return rc;
    274 
    275         /* Restore the checksum to its initial value */
    276         vbr_checksum = initial_checksum;
     283                goto exit;
     284
     285        /* Initialize the checksum sectors */
     286        for (idx = 0; idx < cfg->sector_size / sizeof(uint32_t); ++idx)
     287                chksum_sector[idx] = host2uint32_t_le(vbr_checksum);
     288
     289        /* Write the main checksum sector to disk */
     290        rc = block_write_direct(service_id,
     291            VBR_CHECKSUM_SECTOR, 1, chksum_sector);
     292        if (rc != EOK)
     293                goto exit;
     294
     295        /* Write the backup checksum sector to disk */
     296        rc = block_write_direct(service_id,
     297            VBR_BACKUP_CHECKSUM_SECTOR, 1, chksum_sector);
     298        if (rc != EOK)
     299                goto exit;
    277300
    278301        /* Write the Main extended boot sectors backup to disk */
    279         return ebs_write(service_id, cfg,
     302        rc = ebs_write(service_id, cfg,
    280303            EBS_BACKUP_SECTOR_START, &vbr_checksum);
     304
     305exit:
     306        free(chksum_sector);
     307        return rc;
    281308}
    282309
     
    293320        uint32_t *ebs = calloc(cfg->sector_size, sizeof(uint8_t));
    294321        int i, rc;
    295         unsigned idx;
    296322
    297323        if (!ebs)
     
    328354        if (rc != EOK)
    329355                goto exit;
    330 
    331         /* Write the checksum sector */
    332         for (idx = 0; idx < cfg->sector_size / sizeof(uint32_t); ++idx)
    333                 ebs[idx] = host2uint32_t_le(*chksum);
    334 
    335         rc = block_write_direct(service_id, i + base, 1, ebs);
    336356
    337357exit:
     
    526546                    start_sec + i, 1, buf);
    527547                if (rc != EOK)
    528                         break;
    529         }
    530 
     548                        goto exit;
     549        }
     550
     551exit:
    531552        free(buf);
    532553        return rc;
Note: See TracChangeset for help on using the changeset viewer.