Changeset e6edc8d1 in mainline for uspace/srv


Ignore:
Timestamp:
2013-07-11T19:13:37Z (12 years ago)
Author:
Manuele Conti <conti.ma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
67632f7
Parents:
52ff62d3 (diff), 2b3e8840 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline changes.

Location:
uspace/srv/fs/mfs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/mfs/mfs.h

    r52ff62d3 re6edc8d1  
    5858#endif
    5959
     60#define MFS_BMAP_START_BLOCK(sbi, bid) \
     61    ((bid) == BMAP_ZONE ? 2 + (sbi)->ibmap_blocks : 2)
     62
     63#define MFS_BMAP_SIZE_BITS(sbi, bid) \
     64    ((bid) == BMAP_ZONE ? (sbi)->nzones - (sbi)->firstdatazone - 1 : \
     65    (sbi)->ninodes - 1)
     66
     67#define MFS_BMAP_SIZE_BLOCKS(sbi, bid) \
     68    ((bid) == BMAP_ZONE ? (sbi)->zbmap_blocks : (sbi)->ibmap_blocks)
     69
    6070typedef uint32_t bitchunk_t;
    6171
     
    201211mfs_free_zone(struct mfs_instance *inst, uint32_t zone);
    202212
     213extern int
     214mfs_count_free_zones(struct mfs_instance *inst, uint32_t *zones);
     215
     216extern int
     217mfs_count_free_inodes(struct mfs_instance *inst, uint32_t *inodes);
     218
     219
    203220/* mfs_utils.c */
    204221extern uint16_t
  • uspace/srv/fs/mfs/mfs_balloc.c

    r52ff62d3 re6edc8d1  
    4444mfs_alloc_bit(struct mfs_instance *inst, uint32_t *idx, bmap_id_t bid);
    4545
     46static int
     47mfs_count_free_bits(struct mfs_instance *inst, bmap_id_t bid, uint32_t *free);
     48
     49
    4650/**Allocate a new inode.
    4751 *
     
    102106
    103107        return mfs_free_bit(inst, zone, BMAP_ZONE);
     108}
     109
     110/** Count the number of free zones
     111 *
     112 * @param inst          Pointer to the instance structure.
     113 * @param zones         Pointer to the memory location where the result
     114 *                      will be stored.
     115 *
     116 * @return              EOK on success or a negative error code.
     117 */
     118int
     119mfs_count_free_zones(struct mfs_instance *inst, uint32_t *zones)
     120{
     121        return mfs_count_free_bits(inst, BMAP_ZONE, zones);
     122}
     123
     124/** Count the number of free inodes
     125 *
     126 * @param inst          Pointer to the instance structure.
     127 * @param zones         Pointer to the memory location where the result
     128 *                      will be stored.
     129 *
     130 * @return              EOK on success or a negative error code.
     131 */
     132
     133int
     134mfs_count_free_inodes(struct mfs_instance *inst, uint32_t *inodes)
     135{
     136        return mfs_count_free_bits(inst, BMAP_INODE, inodes);
     137}
     138
     139/** Count the number of free bits in a bitmap
     140 *
     141 * @param inst          Pointer to the instance structure.
     142 * @param bid           Type of the bitmap (inode or zone).
     143 * @param free          Pointer to the memory location where the result
     144 *                      will be stores.
     145 *
     146 * @return              EOK on success or a negative error code.
     147 */
     148static int
     149mfs_count_free_bits(struct mfs_instance *inst, bmap_id_t bid, uint32_t *free)
     150{
     151        int r;
     152        unsigned start_block;
     153        unsigned long nblocks;
     154        unsigned long nbits;
     155        unsigned long block;
     156        unsigned long free_bits = 0;
     157        bitchunk_t chunk;
     158        size_t const bitchunk_bits = sizeof(bitchunk_t) * 8;
     159        block_t *b;
     160        struct mfs_sb_info *sbi = inst->sbi;
     161
     162        start_block = MFS_BMAP_START_BLOCK(sbi, bid);
     163        nblocks = MFS_BMAP_SIZE_BLOCKS(sbi, bid);
     164        nbits = MFS_BMAP_SIZE_BITS(sbi, bid);
     165
     166        for (block = 0; block < nblocks; ++block) {
     167                r = block_get(&b, inst->service_id, block + start_block,
     168                    BLOCK_FLAGS_NONE);
     169                if (r != EOK)
     170                        return r;
     171
     172                size_t i;
     173                bitchunk_t *data = (bitchunk_t *) b->data;
     174
     175                /* Read the bitmap block, chunk per chunk,
     176                 * counting the zero bits.
     177                 */
     178                for (i = 0; i < sbi->block_size / sizeof(bitchunk_t); ++i) {
     179                        chunk = conv32(sbi->native, data[i]);
     180
     181                        size_t bit;
     182                        for (bit = 0; bit < bitchunk_bits && nbits > 0;
     183                            ++bit, --nbits) {
     184                                if (!(chunk & (1 << bit)))
     185                                        free_bits++;
     186                        }
     187
     188                        if (nbits == 0)
     189                                break;
     190                }
     191
     192                r = block_put(b);
     193                if (r != EOK)
     194                        return r;
     195        }
     196
     197        *free = free_bits;
     198        assert(nbits == 0);
     199
     200        return EOK;
    104201}
    105202
     
    124221        sbi = inst->sbi;
    125222
     223        start_block = MFS_BMAP_START_BLOCK(sbi, bid);
     224
    126225        if (bid == BMAP_ZONE) {
    127226                search = &sbi->zsearch;
    128                 start_block = 2 + sbi->ibmap_blocks;
    129227                if (idx > sbi->nzones) {
    130                         printf(NAME ": Error! Trying to free beyond the" \
     228                        printf(NAME ": Error! Trying to free beyond the "
    131229                            "bitmap max size\n");
    132230                        return -1;
     
    135233                /* bid == BMAP_INODE */
    136234                search = &sbi->isearch;
    137                 start_block = 2;
    138235                if (idx > sbi->ninodes) {
    139                         printf(NAME ": Error! Trying to free beyond the" \
     236                        printf(NAME ": Error! Trying to free beyond the "
    140237                            "bitmap max size\n");
    141238                        return -1;
     
    192289        sbi = inst->sbi;
    193290
     291        start_block = MFS_BMAP_START_BLOCK(sbi, bid);
     292        limit = MFS_BMAP_SIZE_BITS(sbi, bid);
     293        nblocks = MFS_BMAP_SIZE_BLOCKS(sbi, bid);
     294
    194295        if (bid == BMAP_ZONE) {
    195296                search = &sbi->zsearch;
    196                 start_block = 2 + sbi->ibmap_blocks;
    197                 nblocks = sbi->zbmap_blocks;
    198                 limit = sbi->nzones - sbi->firstdatazone - 1;
    199297        } else {
    200298                /* bid == BMAP_INODE */
    201299                search = &sbi->isearch;
    202                 start_block = 2;
    203                 nblocks = sbi->ibmap_blocks;
    204                 limit = sbi->ninodes;
    205300        }
    206301        bits_per_block = sbi->block_size * 8;
  • uspace/srv/fs/mfs/mfs_dentry.c

    r52ff62d3 re6edc8d1  
    3636 *
    3737 * @param mnode         Pointer to the directory node.
    38  * @param d_info        Pointer to a directory entry structure where the dentry info
    39  *                      will be stored.
     38 * @param d_info        Pointer to a directory entry structure where
     39 *                      the dentry info will be stored.
    4040 * @param index         index of the dentry in the list.
    4141 *
     
    101101/**Write a directory entry on disk.
    102102 *
    103  * @param d_info Pointer to the directory entry structure to write on disk.
     103 * @param d_info The directory entry to write to disk.
    104104 *
    105105 * @return       EOK on success or a negative error code.
     
    240240                                goto out;
    241241                        r = mfs_write_map(mnode, pos, b, &dummy);
    242                         if (r != EOK)
     242                        if (r != EOK) {
     243                                mfs_free_zone(mnode->instance, b);
    243244                                goto out;
     245                        }
    244246                }
    245247
  • uspace/srv/fs/mfs/mfs_ops.c

    r52ff62d3 re6edc8d1  
    9090
    9191/* Hash table interface for open nodes hash table */
    92 
    9392typedef struct {
    9493        service_id_t service_id;
     
    192191                /* This is a V1 or V2 Minix filesystem */
    193192                magic = sb->s_magic;
    194         } else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) {
     193        } else if (check_magic_number(sb3->s_magic, &native,
     194            &version, &longnames)) {
    195195                /* This is a V3 Minix filesystem */
    196196                magic = sb3->s_magic;
     
    347347        uint32_t inum;
    348348
    349         mfsdebug("%s()\n", __FUNCTION__);
    350 
    351349        r = mfs_instance_get(service_id, &inst);
    352350        if (r != EOK)
     
    381379                ino_i->i_mode = S_IFDIR;
    382380                ino_i->i_nlinks = 1; /* This accounts for the '.' dentry */
    383         } else
     381        } else {
    384382                ino_i->i_mode = S_IFREG;
     383                ino_i->i_nlinks = 0;
     384        }
    385385
    386386        ino_i->i_uid = 0;
     
    421421        free(ino_i);
    422422out_err:
     423        mfs_free_inode(inst, inum);
    423424        return r;
    424425}
     
    431432        struct mfs_dentry_info d_info;
    432433        int r;
    433 
    434         mfsdebug("%s()\n", __FUNCTION__);
    435434
    436435        if (!S_ISDIR(ino_i->i_mode))
     
    480479        struct mfs_instance *instance;
    481480
    482         mfsdebug("%s()\n", __FUNCTION__);
    483 
    484481        rc = mfs_instance_get(service_id, &instance);
    485482        if (rc != EOK)
     
    494491        int rc = EOK;
    495492        struct mfs_node *mnode = fsnode->data;
    496 
    497         mfsdebug("%s()\n", __FUNCTION__);
    498493
    499494        fibril_mutex_lock(&open_nodes_lock);
     
    556551        int rc;
    557552
    558         mfsdebug("%s()\n", __FUNCTION__);
    559 
    560553        fibril_mutex_lock(&open_nodes_lock);
    561554
     
    570563        if (already_open) {
    571564                mnode = hash_table_get_inst(already_open, struct mfs_node, link);
     565
    572566                *rfn = mnode->fsnode;
    573567                mnode->refcnt++;
     
    651645        bool destroy_dentry = false;
    652646
    653         mfsdebug("%s()\n", __FUNCTION__);
    654 
    655647        if (str_size(name) > sbi->max_name_len)
    656648                return ENAMETOOLONG;
     
    675667                r = mfs_insert_dentry(child, "..", parent->ino_i->index);
    676668                if (r != EOK) {
     669                        mfs_remove_dentry(child, ".");
    677670                        destroy_dentry = true;
    678671                        goto exit;
     
    702695        bool has_children;
    703696        int r;
    704 
    705         mfsdebug("%s()\n", __FUNCTION__);
    706697
    707698        if (!parent)
     
    926917               
    927918                r = mfs_write_map(mnode, pos, block, &dummy);
    928                 if (r != EOK)
     919                if (r != EOK) {
     920                        mfs_free_zone(mnode->instance, block);
    929921                        goto out_err;
     922                }
    930923
    931924                flags = BLOCK_FLAGS_NOREAD;
     
    967960mfs_destroy(service_id_t service_id, fs_index_t index)
    968961{
    969         fs_node_t *fn;
     962        fs_node_t *fn = NULL;
    970963        int r;
    971964
Note: See TracChangeset for help on using the changeset viewer.