Changeset 55dbaeb in mainline for uspace/app/mkexfat/mkexfat.c


Ignore:
Timestamp:
2012-02-21T20:02:38Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dabe1664
Parents:
e15f4d5
Message:

mkexfat: Initialize and write the Main Extended Boot Sector to disk.

File:
1 edited

Legend:

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

    re15f4d5 r55dbaeb  
    5353#define FAT_SECTOR_START 128
    5454
     55/** First sector of the Main Extended Boot Region */
     56#define EBS_SECTOR_START 1
     57
     58/** Size of the Main Extended Boot Region */
     59#define EBS_SIZE 8
     60
    5561/** Divide and round up. */
    5662#define div_round_up(a, b) (((a) + (b) - 1) / (b))
     
    178184}
    179185
     186/** Write the Main Extended Boot Sector to disk
     187 *
     188 * @param service_id  The service id.
     189 * @param cfg  Pointer to the exFAT configuration structure.
     190 * @return  EOK on success or a negative error code.
     191 */
     192static int
     193ebs_write(service_id_t service_id, exfat_cfg_t *cfg)
     194{
     195        uint32_t *ebs = calloc(cfg->sector_size, sizeof(uint8_t));
     196        int i, rc;
     197
     198        if (!ebs)
     199                return ENOMEM;
     200
     201        ebs[cfg->sector_size / 4 - 1] = host2uint32_t_le(0xAA550000);
     202
     203        for (i = 0; i < EBS_SIZE; ++i) {
     204                rc = block_write_direct(service_id, i + EBS_SECTOR_START,
     205                    1, ebs);
     206
     207                if (rc != EOK)
     208                        goto exit;
     209        }
     210
     211exit:
     212        free(ebs);
     213        return rc;
     214}
     215
    180216/** Writes the FAT on disk.
    181217 *
     
    304340        }
    305341
     342        rc = ebs_write(service_id, &cfg);
     343        if (rc != EOK) {
     344                printf(NAME ": Error, failed to write the Main Extended Boot" \
     345                    " Sector to disk\n");
     346                return 2;
     347        }
     348
    306349        rc = fat_write(service_id, &cfg);
    307350        if (rc != EOK) {
    308                 printf(NAME ": Error, failed to write the FAT on disk\n");
     351                printf(NAME ": Error, failed to write the FAT to disk\n");
    309352                return 2;
    310353        }
Note: See TracChangeset for help on using the changeset viewer.