Changes in / [065064e6:e3f7418] in mainline


Ignore:
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia64/src/drivers/ski.c

    r065064e6 re3f7418  
    219219                 * self-sufficient.
    220220                 */
     221                sysinfo_set_item_val("fb", NULL, true);
    221222                sysinfo_set_item_val("fb.kind", NULL, 6);
    222223               
  • uspace/app/mkmfs/mkmfs.c

    r065064e6 re3f7418  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
    32 * Copyright (c) 2011 Maurizio Lombardi
    43 * All rights reserved.
     
    5655#define USED    1
    5756
    58 #define UPPER(n, size)                  (((n) / (size)) + (((n) % (size)) != 0))
    59 #define NEXT_DENTRY(p, dirsize)         (p += (dirsize))
     57#define UPPER(n, size)          (((n) / (size)) + (((n) % (size)) != 0))
     58#define NEXT_DENTRY(p, dirsize) (p += (dirsize))
    6059
    6160typedef enum {
     
    6463} help_level_t;
    6564
    66 /*Generic MFS superblock*/
     65/* Generic MFS superblock */
    6766struct mfs_sb_info {
    6867        uint64_t n_inodes;
     
    8483
    8584static void     help_cmd_mkmfs(help_level_t level);
    86 static int      num_of_set_bits(uint32_t n);
     85static bool     is_power_of_two(uint32_t n);
    8786static int      init_superblock(struct mfs_sb_info *sb);
    8887static int      write_superblock(const struct mfs_sb_info *sbi);
     
    118117        struct mfs_sb_info sb;
    119118
    120         /*Default is MinixFS V3*/
     119        /* Default is MinixFS V3 */
    121120        sb.magic = MFS_MAGIC_V3;
    122121        sb.fs_version = 3;
    123122
    124         /*Default block size is 4Kb*/
     123        /* Default block size is 4Kb */
    125124        sb.block_size = MFS_MAX_BLOCKSIZE;
    126125        sb.dirsize = MFS3_DIRSIZE;
     
    136135
    137136        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
    138                 c = getopt_long(argc, argv, "lh12b:i:", long_options, &opt_ind);
     137                c = getopt_long(argc, argv, "lh12b:i:",
     138                    long_options, &opt_ind);
    139139                switch (c) {
    140140                case 'h':
     
    169169
    170170        if (sb.block_size < MFS_MIN_BLOCKSIZE ||
    171                         sb.block_size > MFS_MAX_BLOCKSIZE) {
     171            sb.block_size > MFS_MAX_BLOCKSIZE) {
    172172                printf(NAME ":Error! Invalid block size.\n");
    173173                exit(0);
    174         } else if (num_of_set_bits(sb.block_size) != 1) {
    175                 /*Block size must be a power of 2.*/
     174        } else if (!is_power_of_two(sb.block_size)) {
     175                /* Block size must be a power of 2. */
    176176                printf(NAME ":Error! Invalid block size.\n");
    177177                exit(0);
    178178        } else if (sb.block_size > MFS_BLOCKSIZE &&
    179                         sb.fs_version != 3) {
    180                 printf(NAME ":Error! Block size > 1024 is supported by V3 filesystem only.\n");
     179            sb.fs_version != 3) {
     180                printf(NAME ":Error! Block size > 1024 is "
     181                    "supported by V3 filesystem only.\n");
    181182                exit(0);
    182183        } else if (sb.fs_version == 3 && sb.longnames) {
    183                 printf(NAME ":Error! Long filenames are supported by V1/V2 filesystem only.\n");
     184                printf(NAME ":Error! Long filenames are supported "
     185                    "by V1/V2 filesystem only.\n");
    184186                exit(0);
    185187        }
     
    221223        rc = block_get_nblocks(service_id, &sb.dev_nblocks);
    222224        if (rc != EOK) {
    223                 printf(NAME ": Warning, failed to obtain block device size.\n");
     225                printf(NAME ": Warning, failed to obtain "
     226                    "block device size.\n");
    224227        } else {
    225228                printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n",
    226                                 sb.dev_nblocks);
     229                    sb.dev_nblocks);
    227230        }
    228231
     
    232235        }
    233236
    234         /*Minimum block size is 1 Kb*/
     237        /* Minimum block size is 1 Kb */
    235238        sb.dev_nblocks /= 2;
    236239
    237240        printf(NAME ": Creating Minix file system on device\n");
    238 
    239         /*Initialize superblock*/
     241        printf(NAME ": Writing superblock\n");
     242
     243        /* Initialize superblock */
    240244        if (init_superblock(&sb) != EOK) {
    241245                printf(NAME ": Error. Superblock initialization failed\n");
     
    243247        }
    244248
    245         /*Initialize bitmaps*/
     249        printf(NAME ": Initializing bitmaps\n");
     250
     251        /* Initialize bitmaps */
    246252        if (init_bitmaps(&sb) != EOK) {
    247253                printf(NAME ": Error. Bitmaps initialization failed\n");
     
    249255        }
    250256
    251         /*Init inode table*/
     257        printf(NAME ": Initializing the inode table\n");
     258
     259        /* Init inode table */
    252260        if (init_inode_table(&sb) != EOK) {
    253261                printf(NAME ": Error. Inode table initialization failed\n");
     
    255263        }
    256264
    257         /*Make the root inode*/
     265        printf(NAME ": Creating the root directory inode\n");
     266
     267        /* Make the root inode */
    258268        if (sb.fs_version == 1)
    259269                rc = make_root_ino(&sb);
     
    266276        }
    267277
    268         /*Insert directory entries . and ..*/
     278        /* Insert directory entries . and .. */
    269279        if (insert_dentries(&sb) != EOK) {
    270280                printf(NAME ": Error. Root directory initialization failed\n");
     
    299309
    300310        if (sb->fs_version != 3) {
    301                 /*Directory entries for V1/V2 filesystem*/
     311                /* Directory entries for V1/V2 filesystem */
    302312                struct mfs_dentry *dentry = root_block;
    303313
     
    306316
    307317                dentry = (struct mfs_dentry *) NEXT_DENTRY(dentry_ptr,
    308                                 sb->dirsize);
     318                    sb->dirsize);
    309319
    310320                dentry->d_inum = MFS_ROOT_INO;
    311321                memcpy(dentry->d_name, "..\0", 3);
    312322        } else {
    313                 /*Directory entries for V3 filesystem*/
     323                /* Directory entries for V3 filesystem */
    314324                struct mfs3_dentry *dentry = root_block;
    315325
     
    318328
    319329                dentry = (struct mfs3_dentry *) NEXT_DENTRY(dentry_ptr,
    320                                 sb->dirsize);
     330                    sb->dirsize);
    321331
    322332                dentry->d_inum = MFS_ROOT_INO;
     
    389399        ino_buf[MFS_ROOT_INO - 1].i_gid = 0;
    390400        ino_buf[MFS_ROOT_INO - 1].i_size = (sb->longnames ? MFSL_DIRSIZE :
    391         MFS_DIRSIZE) * 2;
     401            MFS_DIRSIZE) * 2;
    392402        ino_buf[MFS_ROOT_INO - 1].i_mtime = sec;
    393403        ino_buf[MFS_ROOT_INO - 1].i_nlinks = 2;
     
    411421        int rc;
    412422
    413         /*Compute offset of the first inode table block*/
     423        /* Compute offset of the first inode table block */
    414424        const long itable_off = sb->zbmap_blocks + sb->ibmap_blocks + 2;
    415425
     
    454464
    455465        if (sb->longnames)
    456                 sb->magic = sb->fs_version == 1 ? MFS_MAGIC_V1L : MFS_MAGIC_V2L;
    457 
    458         /*Compute the number of zones on disk*/
     466                sb->magic = sb->fs_version == 1 ? MFS_MAGIC_V1L :
     467                    MFS_MAGIC_V2L;
     468
     469        /* Compute the number of zones on disk */
    459470
    460471        if (sb->fs_version == 1) {
    461                 /*Valid only for MFS V1*/
     472                /* Valid only for MFS V1 */
    462473                sb->n_zones = sb->dev_nblocks > UINT16_MAX ?
    463                                 UINT16_MAX : sb->dev_nblocks;
     474                    UINT16_MAX : sb->dev_nblocks;
    464475                ind = MFS_BLOCKSIZE / sizeof(uint16_t);
    465476                ind2 = ind * ind;
    466                 sb->max_file_size = (V1_NR_DIRECT_ZONES + ind + ind2) * MFS_BLOCKSIZE;
     477                sb->max_file_size = (V1_NR_DIRECT_ZONES + ind + ind2) *
     478                    MFS_BLOCKSIZE;
    467479        } else {
    468480                /*Valid for MFS V2/V3*/
     
    472484                else
    473485                        ptrsize = sizeof(uint32_t);
     486
    474487                ind = sb->block_size / ptrsize;
    475488                ind2 = ind * ind;
     
    477490                sb->max_file_size = zones * sb->block_size;
    478491                sb->n_zones = sb->dev_nblocks > UINT32_MAX ?
    479                                 UINT32_MAX : sb->dev_nblocks;
     492                    UINT32_MAX : sb->dev_nblocks;
    480493
    481494                if (sb->fs_version == 3) {
     
    487500        }
    488501
    489         /*Round up the number of inodes to fill block size*/
     502        /* Round up the number of inodes to fill block size */
    490503        if (sb->n_inodes == 0)
    491504                inodes = sb->dev_nblocks / 3;
     
    494507
    495508        if (inodes % sb->ino_per_block)
    496                 inodes = ((inodes / sb->ino_per_block) + 1) * sb->ino_per_block;
     509                inodes = ((inodes / sb->ino_per_block) + 1) *
     510                    sb->ino_per_block;
    497511
    498512        if (sb->fs_version < 3)
     
    501515                sb->n_inodes = inodes > UINT32_MAX ? UINT32_MAX : inodes;
    502516
    503         /*Compute inode bitmap size in blocks*/
     517        /* Compute inode bitmap size in blocks */
    504518        sb->ibmap_blocks = UPPER(sb->n_inodes, sb->block_size * 8);
    505519
    506         /*Compute inode table size*/
     520        /* Compute inode table size */
    507521        sb->itable_size = sb->n_inodes / sb->ino_per_block;
    508522
    509         /*Compute zone bitmap size in blocks*/
     523        /* Compute zone bitmap size in blocks */
    510524        sb->zbmap_blocks = UPPER(sb->n_zones, sb->block_size * 8);
    511525
    512         /*Compute first data zone position*/
     526        /* Compute first data zone position */
    513527        sb->first_data_zone = 2 + sb->itable_size +
    514                         sb->zbmap_blocks + sb->ibmap_blocks;
    515 
    516         /*Set log2 of zone to block ratio to zero*/
     528            sb->zbmap_blocks + sb->ibmap_blocks;
     529
     530        /* Set log2 of zone to block ratio to zero */
    517531        sb->log2_zone_size = 0;
    518532
    519         /*Check for errors*/
     533        /* Check for errors */
    520534        if (sb->first_data_zone >= sb->n_zones) {
    521535                printf(NAME ": Error! Insufficient disk space");
     
    523537        }
    524538
    525         /*Superblock is now ready to be written on disk*/
     539        /* Superblock is now ready to be written on disk */
    526540        printf(NAME ": %d block size\n", sb->block_size);
    527541        printf(NAME ": %d inodes\n", (uint32_t) sb->n_inodes);
     
    530544        printf(NAME ": inode bitmap blocks = %ld\n", sb->ibmap_blocks);
    531545        printf(NAME ": zone bitmap blocks = %ld\n", sb->zbmap_blocks);
    532         printf(NAME ": first data zone = %d\n", (uint32_t) sb->first_data_zone);
     546        printf(NAME ": first data zone = %d\n", (uint32_t)sb->first_data_zone);
    533547        printf(NAME ": max file size = %u\n", sb->max_file_size);
    534548        printf(NAME ": long fnames = %s\n", sb->longnames ? "Yes" : "No");
     
    645659        for (i = 0; i < ibmap_nblocks; ++i) {
    646660                if ((rc = write_block(start_block + i,
    647                                 1, (ibmap_buf8 + i * sb->block_size))) != EOK)
     661                    1, (ibmap_buf8 + i * sb->block_size))) != EOK)
    648662                        return rc;
    649663        }
     
    653667        for (i = 0; i < zbmap_nblocks; ++i) {
    654668                if ((rc = write_block(start_block + i,
    655                                 1, (zbmap_buf8 + i * sb->block_size))) != EOK)
     669                    1, (zbmap_buf8 + i * sb->block_size))) != EOK)
    656670                        return rc;
    657671        }
     
    692706                uint8_t *data_ptr = (uint8_t *) data;
    693707
    694                 rc = block_write_direct(service_id, tmp_off << 2, size << 2, data_ptr);
     708                rc = block_write_direct(service_id, tmp_off << 2,
     709                    size << 2, data_ptr);
    695710
    696711                if (rc != EOK)
     
    700715                tmp_off++;
    701716
    702                 return block_write_direct(service_id, tmp_off << 2, size << 2, data_ptr);
    703         }
    704         return block_write_direct(service_id, off << shift, size << shift, data);
     717                return block_write_direct(service_id, tmp_off << 2,
     718                    size << 2, data_ptr);
     719        }
     720        return block_write_direct(service_id, off << shift,
     721            size << shift, data);
    705722}
    706723
     
    711728        } else {
    712729                printf("Usage: [options] device\n"
    713                                 "-1         Make a Minix version 1 filesystem\n"
    714                                 "-2         Make a Minix version 2 filesystem\n"
    715                                 "-b ##      Specify the block size in bytes (V3 only),\n"
    716                                 "           valid block size values are 1024, 2048 and 4096 bytes per block\n"
    717                                 "-i ##      Specify the number of inodes for the filesystem\n"
    718                                 "-l         Use 30-char long filenames (V1/V2 only)\n");
    719         }
    720 }
    721 
    722 static int num_of_set_bits(uint32_t n)
    723 {
    724         n = n - ((n >> 1) & 0x55555555);
    725         n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    726         return (((n + (n >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
     730                    "-1         Make a Minix version 1 filesystem\n"
     731                    "-2         Make a Minix version 2 filesystem\n"
     732                    "-b ##      Specify the block size in bytes (V3 only),\n"
     733                    "           valid block size values are 1024, 2048 and"
     734                                " 4096 bytes per block\n"
     735                    "-i ##      Specify the number of inodes"
     736                                " for the filesystem\n"
     737                    "-l         Use 30-char long filenames (V1/V2 only)\n");
     738        }
     739}
     740
     741/** Check if a given number is a power of two.
     742 *
     743 * @param n     The number to check.
     744 *
     745 * @return      true if it is a power of two, false otherwise.
     746 */
     747static bool is_power_of_two(uint32_t n)
     748{
     749        if (n == 0)
     750                return false;
     751
     752        return (n & (n - 1)) == 0;
    727753}
    728754
  • uspace/srv/fs/mfs/mfs.c

    r065064e6 re3f7418  
    7474
    7575        async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
    76                                 SERVICE_VFS, 0, 0);
     76            SERVICE_VFS, 0, 0);
    7777
    7878        if (!vfs_sess) {
  • uspace/srv/fs/mfs/mfs_balloc.c

    r065064e6 re3f7418  
    3636static int
    3737find_free_bit_and_set(bitchunk_t *b, const int bsize,
    38                       const bool native, unsigned start_bit);
     38    const bool native, unsigned start_bit);
    3939
    4040static int
     
    129129                if (idx > sbi->nzones) {
    130130                        printf(NAME ": Error! Trying to free beyond the" \
    131                                "bitmap max size\n");
     131                            "bitmap max size\n");
    132132                        return -1;
    133133                }
    134134        } else {
    135                 /*bid == BMAP_INODE*/
     135                /* bid == BMAP_INODE */
    136136                search = &sbi->isearch;
    137137                start_block = 2;
    138138                if (idx > sbi->ninodes) {
    139139                        printf(NAME ": Error! Trying to free beyond the" \
    140                                "bitmap max size\n");
     140                            "bitmap max size\n");
    141141                        return -1;
    142142                }
    143143        }
    144144
    145         /*Compute the bitmap block*/
     145        /* Compute the bitmap block */
    146146        uint32_t block = idx / (sbi->block_size * 8) + start_block;
    147147
     
    150150                goto out_err;
    151151
    152         /*Compute the bit index in the block*/
     152        /* Compute the bit index in the block */
    153153        idx %= (sbi->block_size * 8);
    154154        bitchunk_t *ptr = b->data;
     
    220220
    221221                freebit = find_free_bit_and_set(b->data, sbi->block_size,
    222                                                 sbi->native, tmp);
     222                    sbi->native, tmp);
    223223                if (freebit == -1) {
    224                         /*No free bit in this block*/
     224                        /* No free bit in this block */
    225225                        r = block_put(b);
    226226                        if (r != EOK)
     
    229229                }
    230230
    231                 /*Free bit found in this block, compute the real index*/
     231                /* Free bit found in this block, compute the real index */
    232232                *idx = freebit + bits_per_block * i;
    233233                if (*idx > limit) {
    234                         /*Index is beyond the limit, it is invalid*/
     234                        /* Index is beyond the limit, it is invalid */
    235235                        r = block_put(b);
    236236                        if (r != EOK)
     
    246246
    247247        if (*search > 0) {
    248                 /*Repeat the search from the first bitmap block*/
     248                /* Repeat the search from the first bitmap block */
    249249                *search = 0;
    250250                goto retry;
    251251        }
    252252
    253         /*Free bit not found, return error*/
     253        /* Free bit not found, return error */
    254254        return ENOSPC;
    255255
     
    260260static int
    261261find_free_bit_and_set(bitchunk_t *b, const int bsize,
    262                       const bool native, unsigned start_bit)
     262    const bool native, unsigned start_bit)
    263263{
    264264        int r = -1;
     
    268268
    269269        for (i = start_bit / chunk_bits;
    270              i < bsize / sizeof(bitchunk_t); ++i) {
     270            i < bsize / sizeof(bitchunk_t); ++i) {
     271
    271272                if (!(~b[i])) {
    272                         /*No free bit in this chunk*/
     273                        /* No free bit in this chunk */
    273274                        continue;
    274275                }
  • uspace/srv/fs/mfs/mfs_dentry.c

    r065064e6 re3f7418  
    4444int
    4545mfs_read_dentry(struct mfs_node *mnode,
    46                      struct mfs_dentry_info *d_info, unsigned index)
     46    struct mfs_dentry_info *d_info, unsigned index)
    4747{
    4848        const struct mfs_instance *inst = mnode->instance;
     
    5757
    5858        if (block == 0) {
    59                 /*End of the dentries list*/
     59                /* End of the dentries list */
    6060                r = EOK;
    6161                goto out_err;
     
    7979        } else {
    8080                const int namelen = longnames ? MFS_L_MAX_NAME_LEN :
    81                                     MFS_MAX_NAME_LEN;
     81                    MFS_MAX_NAME_LEN;
    8282
    8383                struct mfs_dentry *d;
    8484
    8585                d = b->data + dentry_off * (longnames ? MFSL_DIRSIZE :
    86                                             MFS_DIRSIZE);
     86                    MFS_DIRSIZE);
    8787                d_info->d_inum = conv16(sbi->native, d->d_inum);
    8888                memcpy(d_info->d_name, d->d_name, namelen);
     
    101101/**Write a directory entry on disk.
    102102 *
    103  * @param d_info        Pointer to the directory entry structure to write on disk.
    104  *
    105  * @return              EOK on success or a negative error code.
     103 * @param d_info Pointer to the directory entry structure to write on disk.
     104 *
     105 * @return       EOK on success or a negative error code.
    106106 */
    107107int
     
    178178
    179179                if (name_len == d_name_len &&
    180                                 !bcmp(d_info.d_name, d_name, name_len)) {
     180                    !bcmp(d_info.d_name, d_name, name_len)) {
     181
    181182                        d_info.d_inum = 0;
    182183                        r = mfs_write_dentry(&d_info);
     
    197198 */
    198199int
    199 mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum)
     200mfs_insert_dentry(struct mfs_node *mnode, const char *d_name,
     201    fs_index_t d_inum)
    200202{
    201203        int r;
     
    209211                return ENAMETOOLONG;
    210212
    211         /*Search for an empty dentry*/
     213        /* Search for an empty dentry */
    212214        unsigned i;
    213215        for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
     
    217219
    218220                if (d_info.d_inum == 0) {
    219                         /*This entry is not used*/
     221                        /* This entry is not used */
    220222                        empty_dentry_found = true;
    221223                        break;
     
    231233
    232234                if (b == 0) {
    233                         /*Increase the inode size*/
     235                        /* Increase the inode size */
    234236
    235237                        uint32_t dummy;
  • uspace/srv/fs/mfs/mfs_inode.c

    r065064e6 re3f7418  
    4242static int
    4343mfs_read_inode_raw(const struct mfs_instance *instance,
    44                 struct mfs_ino_info **ino_ptr, uint16_t inum);
     44    struct mfs_ino_info **ino_ptr, uint16_t inum);
    4545
    4646static int
    4747mfs2_read_inode_raw(const struct mfs_instance *instance,
    48                 struct mfs_ino_info **ino_ptr, uint32_t inum);
     48    struct mfs_ino_info **ino_ptr, uint32_t inum);
    4949
    5050/**Read a MINIX inode from disk
     
    5959int
    6060mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
    61           fs_index_t index)
     61    fs_index_t index)
    6262{
    6363        struct mfs_sb_info *sbi = inst->sbi;
     
    6565
    6666        if (sbi->fs_version == MFS_VERSION_V1) {
    67                 /*Read a MFS V1 inode*/
     67                /* Read a MFS V1 inode */
    6868                r = mfs_read_inode_raw(inst, ino_i, index);
    6969        } else {
    70                 /*Read a MFS V2/V3 inode*/
     70                /* Read a MFS V2/V3 inode */
    7171                r = mfs2_read_inode_raw(inst, ino_i, index);
    7272        }
     
    7777static int
    7878mfs_read_inode_raw(const struct mfs_instance *instance,
    79                 struct mfs_ino_info **ino_ptr, uint16_t inum) {
     79    struct mfs_ino_info **ino_ptr, uint16_t inum)
     80{
    8081        struct mfs_inode *ino;
    8182        struct mfs_ino_info *ino_i = NULL;
     
    8687        sbi = instance->sbi;
    8788
    88         /*inode 0 does not exist*/
     89        /* inode 0 does not exist */
    8990        inum -= 1;
    9091
     
    101102
    102103        r = block_get(&b, instance->service_id,
    103                       itable_off + inum / sbi->ino_per_block,
    104                       BLOCK_FLAGS_NONE);
     104            itable_off + inum / sbi->ino_per_block,
     105            BLOCK_FLAGS_NONE);
     106
    105107        if (r != EOK)
    106108                goto out_err;
     
    134136static int
    135137mfs2_read_inode_raw(const struct mfs_instance *instance,
    136                 struct mfs_ino_info **ino_ptr, uint32_t inum) {
     138    struct mfs_ino_info **ino_ptr, uint32_t inum)
     139{
    137140        struct mfs2_inode *ino;
    138141        struct mfs_ino_info *ino_i = NULL;
     
    150153        sbi = instance->sbi;
    151154
    152         /*inode 0 does not exist*/
     155        /* inode 0 does not exist */
    153156        inum -= 1;
    154157
     
    157160
    158161        r = block_get(&b, instance->service_id,
    159                       itable_off + inum / sbi->ino_per_block,
    160                       BLOCK_FLAGS_NONE);
     162            itable_off + inum / sbi->ino_per_block,
     163            BLOCK_FLAGS_NONE);
     164
    161165        if (r != EOK)
    162166                goto out_err;
     
    322326
    323327        if (size_shrink == 0) {
    324                 /*File is empty*/
     328                /* Nothing to be done */
    325329                return EOK;
    326330        }
     
    333337        ino_i->dirty = true;
    334338
    335         /*Compute the number of zones to free*/
     339        /* Compute the number of zones to free */
    336340        unsigned zones_to_free;
    337341
     
    354358
    355359                if (old_zone == 0)
    356                         continue; /*Sparse block*/
     360                        continue; /* Sparse block */
    357361
    358362                r = mfs_free_zone(mnode->instance, old_zone);
  • uspace/srv/fs/mfs/mfs_ops.c

    r065064e6 re3f7418  
    4343
    4444static bool check_magic_number(uint16_t magic, bool *native,
    45                                mfs_version_t *version, bool *longfilenames);
     45    mfs_version_t *version, bool *longfilenames);
    4646static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
    47                              fs_index_t index);
    48 
     47    fs_index_t index);
    4948static int mfs_node_put(fs_node_t *fsnode);
    5049static int mfs_node_open(fs_node_t *fsnode);
     
    6463static hash_index_t open_nodes_hash(unsigned long key[]);
    6564static int open_nodes_compare(unsigned long key[], hash_count_t keys,
    66                 link_t *item);
     65    link_t *item);
    6766static void open_nodes_remove_cb(link_t *link);
    68 
    6967static int mfs_node_get(fs_node_t **rfn, service_id_t service_id,
    70                         fs_index_t index);
    71 static int
    72 mfs_instance_get(service_id_t service_id, struct mfs_instance **instance);
    73 
     68    fs_index_t index);
     69static int mfs_instance_get(service_id_t service_id,
     70    struct mfs_instance **instance);
     71static int mfs_check_sanity(struct mfs_sb_info *sbi);
     72static bool is_power_of_two(uint32_t n);
    7473
    7574static hash_table_t open_nodes;
     
    9695
    9796/* Hash table interface for open nodes hash table */
    98 static hash_index_t open_nodes_hash(unsigned long key[])
     97static hash_index_t
     98open_nodes_hash(unsigned long key[])
    9999{
    100100        /* TODO: This is very simple and probably can be improved */
     
    102102}
    103103
    104 static int open_nodes_compare(unsigned long key[], hash_count_t keys,
    105                 link_t *item)
     104static int
     105open_nodes_compare(unsigned long key[], hash_count_t keys,
     106    link_t *item)
    106107{
    107108        struct mfs_node *mnode = hash_table_get_instance(item, struct mfs_node, link);
     
    118119}
    119120
    120 static void open_nodes_remove_cb(link_t *link)
     121static void
     122open_nodes_remove_cb(link_t *link)
    121123{
    122124        /* We don't use remove callback for this hash table */
     
    129131};
    130132
    131 int mfs_global_init(void)
     133int
     134mfs_global_init(void)
    132135{
    133136        if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS,
    134                         OPEN_NODES_KEYS, &open_nodes_ops)) {
     137            OPEN_NODES_KEYS, &open_nodes_ops)) {
    135138                return ENOMEM;
    136139        }
     
    140143static int
    141144mfs_mounted(service_id_t service_id, const char *opts, fs_index_t *index,
    142                 aoff64_t *size, unsigned *linkcnt)
     145    aoff64_t *size, unsigned *linkcnt)
    143146{
    144147        enum cache_mode cmode;
     
    163166                return rc;
    164167
    165         /*Allocate space for generic MFS superblock*/
     168        /* Allocate space for generic MFS superblock */
    166169        sbi = malloc(sizeof(*sbi));
    167170        if (!sbi) {
     
    170173        }
    171174
    172         /*Allocate space for filesystem instance*/
     175        /* Allocate space for filesystem instance */
    173176        instance = malloc(sizeof(*instance));
    174177        if (!instance) {
     
    191194
    192195        if (check_magic_number(sb->s_magic, &native, &version, &longnames)) {
    193                 /*This is a V1 or V2 Minix filesystem*/
     196                /* This is a V1 or V2 Minix filesystem */
    194197                magic = sb->s_magic;
    195198        } else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) {
    196                 /*This is a V3 Minix filesystem*/
     199                /* This is a V3 Minix filesystem */
    197200                magic = sb3->s_magic;
    198201        } else {
    199                 /*Not recognized*/
     202                /* Not recognized */
    200203                mfsdebug("magic number not recognized\n");
    201204                rc = ENOTSUP;
     
    205208        mfsdebug("magic number recognized = %04x\n", magic);
    206209
    207         /*Fill superblock info structure*/
     210        /* Fill superblock info structure */
    208211
    209212        sbi->fs_version = version;
     
    243246                sbi->dirsize = longnames ? MFSL_DIRSIZE : MFS_DIRSIZE;
    244247                sbi->max_name_len = longnames ? MFS_L_MAX_NAME_LEN :
    245                                     MFS_MAX_NAME_LEN;
     248                    MFS_MAX_NAME_LEN;
    246249        }
    247250
     
    259262
    260263        sbi->itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks;
     264        if ((rc = mfs_check_sanity(sbi)) != EOK) {
     265                fprintf(stderr, "Filesystem corrupted, invalid superblock");
     266                goto out_error;
     267        }
    261268
    262269        rc = block_cache_init(service_id, sbi->block_size, 0, cmode);
     
    267274        }
    268275
    269         /*Initialize the instance structure and remember it*/
     276        /* Initialize the instance structure and remember it */
    270277        instance->service_id = service_id;
    271278        instance->sbi = sbi;
     
    273280        rc = fs_instance_create(service_id, instance);
    274281        if (rc != EOK) {
    275                 free(instance);
    276                 free(sbi);
    277282                block_cache_fini(service_id);
    278                 block_fini(service_id);
    279283                mfsdebug("fs instance creation failed\n");
    280                 return rc;
     284                goto out_error;
    281285        }
    282286
     
    331335}
    332336
    333 service_id_t mfs_service_get(fs_node_t *fsnode)
     337service_id_t
     338mfs_service_get(fs_node_t *fsnode)
    334339{
    335340        struct mfs_node *node = fsnode->data;
     
    337342}
    338343
    339 static int mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
     344static int
     345mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
    340346{
    341347        int r;
     
    351357                return r;
    352358
    353         /*Alloc a new inode*/
     359        /* Alloc a new inode */
    354360        r = mfs_alloc_inode(inst, &inum);
    355361        if (r != EOK)
     
    378384        if (flags & L_DIRECTORY) {
    379385                ino_i->i_mode = S_IFDIR;
    380                 ino_i->i_nlinks = 2; /*This accounts for the '.' dentry*/
     386                ino_i->i_nlinks = 2; /* This accounts for the '.' dentry */
    381387        } else {
    382388                ino_i->i_mode = S_IFREG;
     
    431437}
    432438
    433 static int mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
     439static int
     440mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
    434441{
    435442        struct mfs_node *mnode = pfn->data;
     
    453460
    454461                if (!d_info.d_inum) {
    455                         /*This entry is not used*/
     462                        /* This entry is not used */
    456463                        continue;
    457464                }
     
    460467
    461468                if (comp_size == dentry_name_size &&
    462                         !bcmp(component, d_info.d_name, dentry_name_size)) {
    463                         /*Hit!*/
     469                    !bcmp(component, d_info.d_name, dentry_name_size)) {
     470                        /* Hit! */
    464471                        mfs_node_core_get(rfn, mnode->instance,
    465                                           d_info.d_inum);
     472                            d_info.d_inum);
    466473                        goto found;
    467474                }
     
    472479}
    473480
    474 static aoff64_t mfs_size_get(fs_node_t *node)
     481static aoff64_t
     482mfs_size_get(fs_node_t *node)
    475483{
    476484        const struct mfs_node *mnode = node->data;
     
    480488static int
    481489mfs_node_get(fs_node_t **rfn, service_id_t service_id,
    482                         fs_index_t index)
     490    fs_index_t index)
    483491{
    484492        int rc;
     
    524532}
    525533
    526 static int mfs_node_open(fs_node_t *fsnode)
     534static int
     535mfs_node_open(fs_node_t *fsnode)
    527536{
    528537        /*
     
    533542}
    534543
    535 static fs_index_t mfs_index_get(fs_node_t *fsnode)
     544static fs_index_t
     545mfs_index_get(fs_node_t *fsnode)
    536546{
    537547        struct mfs_node *mnode = fsnode->data;
     
    539549}
    540550
    541 static unsigned mfs_lnkcnt_get(fs_node_t *fsnode)
     551static unsigned
     552mfs_lnkcnt_get(fs_node_t *fsnode)
    542553{
    543554        struct mfs_node *mnode = fsnode->data;
     
    554565}
    555566
    556 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
    557                              fs_index_t index)
     567static int
     568mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
     569    fs_index_t index)
    558570{
    559571        fs_node_t *node = NULL;
     
    627639}
    628640
    629 static bool mfs_is_directory(fs_node_t *fsnode)
     641static bool
     642mfs_is_directory(fs_node_t *fsnode)
    630643{
    631644        const struct mfs_node *node = fsnode->data;
     
    633646}
    634647
    635 static bool mfs_is_file(fs_node_t *fsnode)
     648static bool
     649mfs_is_file(fs_node_t *fsnode)
    636650{
    637651        struct mfs_node *node = fsnode->data;
     
    639653}
    640654
    641 static int mfs_root_get(fs_node_t **rfn, service_id_t service_id)
     655static int
     656mfs_root_get(fs_node_t **rfn, service_id_t service_id)
    642657{
    643658        int rc = mfs_node_get(rfn, service_id, MFS_ROOT_INO);
     
    645660}
    646661
    647 static int mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
     662static int
     663mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
    648664{
    649665        struct mfs_node *parent = pfn->data;
     
    720736}
    721737
    722 static int mfs_has_children(bool *has_children, fs_node_t *fsnode)
     738static int
     739mfs_has_children(bool *has_children, fs_node_t *fsnode)
    723740{
    724741        struct mfs_node *mnode = fsnode->data;
     
    741758
    742759                if (d_info.d_inum) {
    743                         /*A valid entry has been found*/
     760                        /* A valid entry has been found */
    744761                        *has_children = true;
    745762                        break;
     
    753770static int
    754771mfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos,
    755                 size_t *rbytes)
     772    size_t *rbytes)
    756773{
    757774        int rc;
     
    783800
    784801                if (pos < 2) {
    785                         /*Skip the first two dentries ('.' and '..')*/
     802                        /* Skip the first two dentries ('.' and '..') */
    786803                        pos = 2;
    787804                }
     
    793810
    794811                        if (d_info.d_inum) {
    795                                 /*Dentry found!*/
     812                                /* Dentry found! */
    796813                                goto found;
    797814                        }
     
    809826
    810827                if (pos >= (size_t) ino_i->i_size) {
    811                         /*Trying to read beyond the end of file*/
     828                        /* Trying to read beyond the end of file */
    812829                        bytes = 0;
    813830                        (void) async_data_read_finalize(callid, NULL, 0);
     
    826843
    827844                if (zone == 0) {
    828                         /*sparse file*/
     845                        /* sparse file */
    829846                        uint8_t *buf = malloc(sbi->block_size);
    830847                        if (!buf) {
     
    834851                        memset(buf, 0, sizeof(sbi->block_size));
    835852                        async_data_read_finalize(callid,
    836                                                 buf + pos % sbi->block_size, bytes);
     853                            buf + pos % sbi->block_size, bytes);
    837854                        free(buf);
    838855                        goto out_success;
     
    844861
    845862                async_data_read_finalize(callid, b->data +
    846                                         pos % sbi->block_size, bytes);
     863                    pos % sbi->block_size, bytes);
    847864
    848865                rc = block_put(b);
     
    865882static int
    866883mfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos,
    867                 size_t *wbytes, aoff64_t *nsize)
     884    size_t *wbytes, aoff64_t *nsize)
    868885{
    869886        fs_node_t *fn;
     
    900917
    901918        if (block == 0) {
    902                 /*Writing in a sparse block*/
    903919                uint32_t dummy;
    904920
     
    958974                return ENOENT;
    959975
    960         /*Destroy the inode*/
     976        /* Destroy the inode */
    961977        return mfs_destroy_node(fn);
    962978}
     
    977993        assert(!has_children);
    978994
    979         /*Free the entire inode content*/
     995        /* Free the entire inode content */
    980996        r = mfs_inode_shrink(mnode, mnode->ino_i->i_size);
    981997        if (r != EOK)
    982998                goto out;
    983999
    984         /*Mark the inode as free in the bitmap*/
     1000        /* Mark the inode as free in the bitmap */
    9851001        r = mfs_free_inode(mnode->instance, mnode->ino_i->index);
    9861002
     
    10211037
    10221038        rc = fs_instance_get(service_id, &data);
    1023         if (rc == EOK) {
     1039        if (rc == EOK)
    10241040                *instance = (struct mfs_instance *) data;
    1025         } else {
     1041        else {
    10261042                mfsdebug("instance not found\n");
    10271043        }
     
    10301046}
    10311047
    1032 static bool check_magic_number(uint16_t magic, bool *native,
    1033                                mfs_version_t *version, bool *longfilenames)
     1048static bool
     1049check_magic_number(uint16_t magic, bool *native,
     1050                mfs_version_t *version, bool *longfilenames)
    10341051{
    10351052        bool rc = true;
     
    10591076}
    10601077
     1078/** Filesystem sanity check
     1079 *
     1080 * @param Pointer to the MFS superblock.
     1081 *
     1082 * @return EOK on success, ENOTSUP otherwise.
     1083 */
     1084static int
     1085mfs_check_sanity(struct mfs_sb_info *sbi)
     1086{
     1087        if (!is_power_of_two(sbi->block_size) ||
     1088            sbi->block_size < MFS_MIN_BLOCKSIZE ||
     1089            sbi->block_size > MFS_MAX_BLOCKSIZE)
     1090                return ENOTSUP;
     1091        else if (sbi->ibmap_blocks == 0 || sbi->zbmap_blocks == 0)
     1092                return ENOTSUP;
     1093        else if (sbi->ninodes == 0 || sbi->nzones == 0)
     1094                return ENOTSUP;
     1095        else if (sbi->firstdatazone == 0)
     1096                return ENOTSUP;
     1097
     1098        return EOK;
     1099}
     1100
    10611101static int
    10621102mfs_close(service_id_t service_id, fs_index_t index)
     
    10791119
    10801120        return mfs_node_put(fn);
     1121}
     1122
     1123/** Check if a given number is a power of two.
     1124 *
     1125 * @param n     The number to check.
     1126 *
     1127 * @return      true if it is a power of two, false otherwise.
     1128 */
     1129static bool
     1130is_power_of_two(uint32_t n)
     1131{
     1132        if (n == 0)
     1133                return false;
     1134
     1135        return (n & (n - 1)) == 0;
    10811136}
    10821137
  • uspace/srv/fs/mfs/mfs_rw.c

    r065064e6 re3f7418  
    3636static int
    3737rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
    38               bool write_mode, uint32_t w_block);
     38    bool write_mode, uint32_t w_block);
    3939
    4040static int
     
    6868        const int block_size = sbi->block_size;
    6969
    70         /*Compute relative block number in file*/
     70        /* Compute relative block number in file */
    7171        int rblock = pos / block_size;
    7272
    7373        if (ROUND_UP(mnode->ino_i->i_size, sbi->block_size) < pos) {
    74                 /*Trying to read beyond the end of file*/
     74                /* Trying to read beyond the end of file */
    7575                r = EOK;
    7676                *b = 0;
     
    8585int
    8686mfs_write_map(struct mfs_node *mnode, const uint32_t pos, uint32_t new_zone,
    87           uint32_t *old_zone)
     87    uint32_t *old_zone)
    8888{
    8989        const struct mfs_sb_info *sbi = mnode->instance->sbi;
    9090
    9191        if (pos >= sbi->max_file_size) {
    92                 /*Can't write beyond the maximum file size*/
     92                /* Can't write beyond the maximum file size */
    9393                return EINVAL;
    9494        }
    9595
    96         /*Compute the relative block number in file*/
     96        /* Compute the relative block number in file */
    9797        int rblock = pos / sbi->block_size;
    9898
     
    102102static int
    103103rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
    104               bool write_mode, uint32_t w_block)
     104    bool write_mode, uint32_t w_block)
    105105{
    106106        int r, nr_direct;
     
    123123        }
    124124
    125         /*Check if the wanted block is in the direct zones*/
     125        /* Check if the wanted block is in the direct zones */
    126126        if (rblock < nr_direct) {
    127127                *b = ino_i->i_dzone[rblock];
     
    136136
    137137        if (rblock < ptrs_per_block) {
    138                 /*The wanted block is in the single indirect zone chain*/
     138                /* The wanted block is in the single indirect zone chain */
    139139                if (ino_i->i_izone[0] == 0) {
    140140                        if (write_mode && !deleting) {
     
    168168        rblock -= ptrs_per_block;
    169169
    170         /*The wanted block is in the double indirect zone chain*/
    171 
    172         /*read the first indirect zone of the chain*/
     170        /* The wanted block is in the double indirect zone chain */
     171
     172        /* Read the first indirect zone of the chain */
    173173        if (ino_i->i_izone[1] == 0) {
    174174                if (write_mode && !deleting) {
     
    181181                        ino_i->dirty = true;
    182182                } else {
    183                         /*Sparse block*/
     183                        /* Sparse block */
    184184                        *b = 0;
    185185                        return EOK;
     
    192192
    193193        /*
    194          *Compute the position of the second indirect
    195          *zone pointer in the chain.
     194         * Compute the position of the second indirect
     195         * zone pointer in the chain.
    196196         */
    197197        uint32_t ind2_off = rblock / ptrs_per_block;
    198198
    199         /*read the second indirect zone of the chain*/
     199        /* read the second indirect zone of the chain */
    200200        if (ind_zone[ind2_off] == 0) {
    201201                if (write_mode && !deleting) {
     
    208208                        write_ind_zone(inst, ino_i->i_izone[1], ind_zone);
    209209                } else {
    210                         /*Sparse block*/
     210                        /* Sparse block */
    211211                        r = EOK;
    212212                        *b = 0;
     
    264264
    265265        if (rblock < nr_direct) {
    266                 /*free the single indirect zone*/
     266                /* Free the single indirect zone */
    267267                if (ino_i->i_izone[0]) {
    268268                        r = mfs_free_zone(inst, ino_i->i_izone[0]);
     
    282282                ++fzone_to_free;
    283283
    284         /*free the entire double indirect zone*/
     284        /* Free the entire double indirect zone */
    285285        uint32_t *dbl_zone;
    286286
    287287        if (ino_i->i_izone[1] == 0) {
    288                 /*Nothing to be done*/
     288                /* Nothing to be done */
    289289                return EOK;
    290290        }
     
    350350        block_t *b;
    351351        const int max_ind_zone_ptrs = (MFS_MAX_BLOCKSIZE / sizeof(uint16_t)) *
    352                                       sizeof(uint32_t);
     352            sizeof(uint32_t);
    353353
    354354        *ind_zone = malloc(max_ind_zone_ptrs);
  • uspace/srv/fs/mfs/mfs_utils.c

    r065064e6 re3f7418  
    3434#include "mfs.h"
    3535
    36 uint16_t conv16(bool native, uint16_t n)
     36uint16_t
     37conv16(bool native, uint16_t n)
    3738{
    3839        if (native)
     
    4243}
    4344
    44 uint32_t conv32(bool native, uint32_t n)
     45uint32_t
     46conv32(bool native, uint32_t n)
    4547{
    4648        if (native)
     
    5052}
    5153
    52 uint64_t conv64(bool native, uint64_t n)
     54uint64_t
     55conv64(bool native, uint64_t n)
    5356{
    5457        if (native)
  • uspace/srv/loc/loc.c

    r065064e6 re3f7418  
    11631163        link_initialize(&service->services);
    11641164        link_initialize(&service->server_services);
     1165        list_initialize(&service->cat_memb);
    11651166       
    11661167        /* Get unique service ID */
Note: See TracChangeset for help on using the changeset viewer.