Changeset 50e754e in mainline


Ignore:
Timestamp:
2012-02-19T20:27:13Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
69c4172
Parents:
3f6d4ea
Message:

mkexfat: Initialize the FAT vector, vbr-backup starts at sector 12.

File:
1 edited

Legend:

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

    r3f6d4ea r50e754e  
    4141#include <assert.h>
    4242#include <errno.h>
     43#include <malloc.h>
    4344#include <byteorder.h>
    4445#include <align.h>
     
    178179}
    179180
     181/** Writes the FAT on disk.
     182 *
     183 * @param cfg Pointer to the exfat_cfg structure.
     184 * @return EOK on success or a negative error code.
     185 */
     186static int
     187fat_write(service_id_t service_id, exfat_cfg_t *cfg)
     188{
     189        unsigned long i;
     190        uint32_t *pfat;
     191        int rc;
     192
     193        pfat = calloc(cfg->fat_sector_count, cfg->sector_size);
     194        if (!pfat)
     195                return ENOMEM;
     196
     197        pfat[0] = host2uint32_t_le(0xFFFFFFF8);
     198        pfat[1] = host2uint32_t_le(0xFFFFFFFF);
     199
     200        rc = block_write_direct(service_id, FAT_SECTOR_START, 1, pfat);
     201        if (rc != EOK)
     202                goto error;
     203
     204        pfat[0] = pfat[1] = 0x00000000;
     205
     206        for (i = FAT_SECTOR_START + 1; i < cfg->fat_sector_count; ++i) {
     207                rc = block_write_direct(service_id, i, 1, pfat);
     208                if (rc != EOK)
     209                        goto error;
     210        }
     211
     212error:
     213        free(pfat);
     214        return rc;
     215}
     216
    180217/** Given a power-of-two number (n), returns the result of log2(n).
    181218 *
     
    260297
    261298        /* Write the VBR backup on disk */
    262         rc = block_write_direct(service_id, 1, 1, &vbr);
     299        rc = block_write_direct(service_id, 12, 1, &vbr);
    263300        if (rc != EOK) {
    264301                printf(NAME ": Error, failed to write the VBR" \
     
    267304        }
    268305
     306        rc = fat_write(service_id, &cfg);
     307        if (rc != EOK) {
     308                printf(NAME ": Error, failed to write the FAT on disk\n");
     309                return 2;
     310        }
     311
    269312        return 0;
    270313}
Note: See TracChangeset for help on using the changeset viewer.