Changeset 2cf95e8 in mainline


Ignore:
Timestamp:
2011-03-29T19:26:24Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3317724
Parents:
77a2d77
Message:

Add a function to free an entry in the inode or zone bitmap

Location:
uspace/srv/fs/minixfs
Files:
2 edited

Legend:

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

    r77a2d77 r2cf95e8  
    161161/*mfs_balloc.c*/
    162162extern int
    163 mfs_alloc_bit(struct mfs_instance *inst, uint32_t *idx, bmap_id_t id);
     163mfs_alloc_bit(struct mfs_instance *inst, uint32_t *idx, bmap_id_t bid);
     164
     165extern int
     166mfs_free_bit(struct mfs_instance *inst, uint32_t idx, bmap_id_t bid);
    164167
    165168#endif
  • uspace/srv/fs/minixfs/mfs_balloc.c

    r77a2d77 r2cf95e8  
    77static int
    88find_free_bit_and_set(bitchunk_t *b, const int bsize, const bool native);
     9
     10int
     11mfs_free_bit(struct mfs_instance *inst, uint32_t idx, bmap_id_t bid)
     12{
     13        struct mfs_sb_info *sbi;
     14        int r;
     15        unsigned start_block;
     16        block_t *b;
     17
     18        assert(inst != NULL);
     19        sbi = inst->sbi;
     20        assert(sbi != NULL);
     21
     22        if (bid == BMAP_ZONE) {
     23                start_block = 2 + sbi->ibmap_blocks;
     24                if (idx > sbi->nzones) {
     25                        printf(NAME ": Error! Trying to free beyond the" \
     26                                        "bitmap max size\n");
     27                        return -1;
     28                }
     29        } else {
     30                /*bid == BMAP_INODE*/
     31                start_block = 2;
     32                if (idx > sbi->ninodes) {
     33                        printf(NAME ": Error! Trying to free beyond the" \
     34                                        "bitmap max size\n");
     35                        return -1;
     36                }
     37        }
     38
     39        /*Compute the bitmap block*/
     40        uint32_t block = idx / (sbi->block_size * 8) + start_block;
     41
     42        r = block_get(&b, inst->handle, block, BLOCK_FLAGS_NONE);
     43        if (r != EOK)
     44                goto out_err;
     45
     46        /*Compute the bit index in the block*/
     47        idx %= (sbi->block_size * 8);
     48        bitchunk_t *ptr = b->data;
     49        bitchunk_t chunk;
     50
     51        chunk = conv32(sbi->native, ptr[idx / 32]);
     52        chunk &= ~(1 << (idx % 32));
     53        ptr[idx / 32] = conv32(sbi->native, chunk);
     54        b->dirty = true;
     55        r = EOK;
     56        block_put(b);
     57
     58out_err:
     59        return r;
     60}
    961
    1062int
Note: See TracChangeset for help on using the changeset viewer.