Changeset bc99ed6 in mainline


Ignore:
Timestamp:
2011-03-07T20:20:08Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f5cbd4f
Parents:
e80b1de
Message:

Write superblock on disk directly into init_superblock()

File:
1 edited

Legend:

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

    re80b1de rbc99ed6  
    6363
    6464typedef struct mfs_params {
    65         uint16_t fs_magic;
    66         uint32_t block_size;
    67         size_t devblock_size;
    68         unsigned long n_inodes;
    69         aoff64_t dev_nblocks;
    70         bool fs_longnames;
     65        devmap_handle_t handle;
     66        uint16_t        fs_magic;
     67        uint32_t        block_size;
     68        size_t          devblock_size;
     69        unsigned long   n_inodes;
     70        aoff64_t        dev_nblocks;
     71        bool            fs_longnames;
    7172} mfs_params_t;
    7273
    7374static void     help_cmd_mkminix(help_level_t level);
    7475static int      num_of_set_bits(uint32_t n);
    75 static void     setup_superblock(struct mfs_superblock *sb, mfs_params_t *opt);
    76 static void     setup_superblock_v3(struct mfs3_superblock *sb, mfs_params_t *opt);
    77 static void     setup_bitmaps(devmap_handle_t handle, uint32_t ninodes,
    78                                 uint32_t nzones, int bsize);
     76static void     init_superblock(struct mfs_superblock *sb, mfs_params_t *opt);
     77static void     init_superblock_v3(struct mfs3_superblock *sb, mfs_params_t *opt);
     78static void     init_bitmaps(uint32_t ninodes,  uint32_t nzones, int bsize, mfs_params_t *opt);
    7979static void     mark_bmap(uint8_t *bmap, int idx, int v);
    8080
     
    9494        int rc, c, opt_ind;
    9595        char *device_name;
    96         devmap_handle_t handle;
    9796       
    9897        struct mfs_superblock *sb;
     
    170169        }
    171170
    172         rc = devmap_device_get_handle(device_name, &handle, 0);
     171        rc = devmap_device_get_handle(device_name, &opt.handle, 0);
    173172        if (rc != EOK) {
    174173                printf(NAME ": Error resolving device `%s'.\n", device_name);
     
    176175        }
    177176
    178         rc = block_init(handle, MFS_MIN_BLOCKSIZE);
     177        rc = block_init(opt.handle, MFS_MIN_BLOCKSIZE);
    179178        if (rc != EOK)  {
    180179                printf(NAME ": Error initializing libblock.\n");
     
    182181        }
    183182
    184         rc = block_get_bsize(handle, &opt.devblock_size);
     183        rc = block_get_bsize(opt.handle, &opt.devblock_size);
    185184        if (rc != EOK) {
    186185                printf(NAME ": Error determining device block size.\n");
     
    188187        }
    189188
    190         rc = block_get_nblocks(handle, &opt.dev_nblocks);
     189        rc = block_get_nblocks(opt.handle, &opt.dev_nblocks);
    191190        if (rc != EOK) {
    192191                printf(NAME ": Warning, failed to obtain block device size.\n");
     
    214213                        return 2;
    215214                }
    216                 setup_superblock_v3(sb3, &opt);
    217                 block_write_direct(handle, MFS_SUPERBLOCK, 1, sb3);
    218                 setup_bitmaps(handle, sb3->s_ninodes,
    219                                 sb3->s_nzones, sb3->s_block_size);
     215                init_superblock_v3(sb3, &opt);
     216                init_bitmaps(sb3->s_ninodes, sb3->s_nzones, sb3->s_block_size, &opt);
    220217        } else {
    221218                sb = (struct mfs_superblock *) malloc(sizeof(struct mfs_superblock));
     
    224221                        return 2;
    225222                }
    226                 setup_superblock(sb, &opt);
    227                 block_write_direct(handle, MFS_SUPERBLOCK, 1, sb);
    228                 setup_bitmaps(handle, sb->s_ninodes, sb->s_nzones, MFS_BLOCKSIZE);
     223                init_superblock(sb, &opt);
     224                init_bitmaps(sb->s_ninodes, sb->s_nzones, MFS_BLOCKSIZE, &opt);
    229225        }
    230226
     
    232228}
    233229
    234 static void setup_superblock(struct mfs_superblock *sb, mfs_params_t *opt)
     230static void init_superblock(struct mfs_superblock *sb, mfs_params_t *opt)
    235231{
    236232        int ino_per_block = 0;
     
    297293        printf(NAME ": first data zone = %d\n", sb->s_first_data_zone);
    298294        printf(NAME ": long fnames = %s\n", opt->fs_longnames ? "Yes" : "No");
    299 }
    300 
    301 static void setup_superblock_v3(struct mfs3_superblock *sb, mfs_params_t *opt)
     295
     296        block_write_direct(opt->handle, MFS_SUPERBLOCK, 1, sb);
     297}
     298
     299static void init_superblock_v3(struct mfs3_superblock *sb, mfs_params_t *opt)
    302300{
    303301        int ino_per_block;
     
    348346        printf(NAME ": inode table blocks = %ld\n", ninodes_blocks);
    349347        printf(NAME ": first data zone = %d\n", sb->s_first_data_zone);
    350 }
    351 
    352 static void setup_bitmaps(devmap_handle_t handle, uint32_t ninodes,
    353                                 uint32_t nzones, int bsize)
     348
     349        block_write_direct(opt->handle, MFS_SUPERBLOCK, 1, sb);
     350}
     351
     352static void init_bitmaps(uint32_t ninodes, uint32_t nzones,
     353                                int bsize, mfs_params_t *opt)
    354354{
    355355        uint8_t *ibmap_buf, *zbmap_buf;
     
    372372        zbmap_nblocks *= bsize / MFS_BLOCKSIZE;
    373373
    374         block_write_direct(handle, 2, ibmap_nblocks, ibmap_buf);
    375         block_write_direct(handle, 2 + ibmap_nblocks, zbmap_nblocks, zbmap_buf);
     374        block_write_direct(opt->handle, 2, ibmap_nblocks, ibmap_buf);
     375        block_write_direct(opt->handle, 2 + ibmap_nblocks, zbmap_nblocks, zbmap_buf);
    376376}
    377377
Note: See TracChangeset for help on using the changeset viewer.