Changeset 87337dc5 in mainline for uspace/app/mkexfat/mkexfat.c


Ignore:
Timestamp:
2018-07-09T15:00:24Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d054ad3
Parents:
914c693
git-author:
Jiri Svoboda <jiri@…> (2018-07-08 19:58:56)
git-committer:
Jiri Svoboda <jiri@…> (2018-07-09 15:00:24)
Message:

Random number generator interface. FAT and exFAT should be created with random volume serial numbers.

File:
1 edited

Legend:

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

    r914c693 r87337dc5  
    4646#include <byteorder.h>
    4747#include <align.h>
     48#include <rndgen.h>
    4849#include <str.h>
    4950#include <getopt.h>
     
    243244 * @param mbs Pointer to the Main Boot Sector structure.
    244245 * @param cfg Pointer to the exFAT configuration structure.
    245  * @return    Initial checksum value.
     246 * @param chksum Place to store initial checksum value.
     247 * @return EOK on success or error code
    246248 */
    247249static uint32_t
    248 vbr_initialize(exfat_bs_t *mbs, exfat_cfg_t *cfg)
    249 {
     250vbr_initialize(exfat_bs_t *mbs, exfat_cfg_t *cfg, uint32_t *chksum)
     251{
     252        rndgen_t *rndgen;
     253        errno_t rc;
     254        uint32_t vsn;
     255
     256        /* Generate volume serial number */
     257
     258        rc = rndgen_create(&rndgen);
     259        if (rc != EOK)
     260                return rc;
     261
     262        rc = rndgen_uint32(rndgen, &vsn);
     263        if (rc != EOK) {
     264                rndgen_destroy(rndgen);
     265                return rc;
     266        }
     267
     268        rndgen_destroy(rndgen);
     269
    250270        /* Fill the structure with zeroes */
    251271        memset(mbs, 0, sizeof(exfat_bs_t));
     
    268288
    269289        mbs->rootdir_cluster = host2uint32_t_le(cfg->rootdir_cluster);
    270         mbs->volume_serial = host2uint32_t_le(0xe1028172);
     290        mbs->volume_serial = host2uint32_t_le(vsn);
    271291        mbs->version.major = 1;
    272292        mbs->version.minor = 0;
     
    283303        mbs->signature = host2uint16_t_le(0xAA55);
    284304
    285         return vbr_checksum_start(mbs, sizeof(exfat_bs_t));
     305        *chksum = vbr_checksum_start(mbs, sizeof(exfat_bs_t));
     306        return EOK;
    286307}
    287308
     
    299320                return ENOMEM;
    300321
    301         vbr_checksum = vbr_initialize(&mbs, cfg);
     322        rc = vbr_initialize(&mbs, cfg, &vbr_checksum);
     323        if (rc != EOK)
     324                goto exit;
    302325
    303326        /* Write the Main Boot Sector to disk */
Note: See TracChangeset for help on using the changeset viewer.