Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 8a49fed in mainline for uspace/srv/fs/minixfs/mfs_inode.c


Ignore:
Timestamp:
2011-04-30T11:45:33Z (11 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master
Children:
44c6091f
Parents:
2874547
Message:

Added implementation of mfs_truncate(), it does not prune indirect blocks yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/minixfs/mfs_inode.c

    r2874547 r8a49fed  
    302302
    303303int
     304inode_shrink(struct mfs_node *mnode, size_t size_shrink)
     305{
     306        struct mfs_sb_info *sbi = mnode->instance->sbi;
     307        struct mfs_ino_info *ino_i = mnode->ino_i;
     308        const size_t bs = sbi->block_size;
     309        int r;
     310
     311        assert(size_shrink > 0);
     312
     313        const size_t old_size = ino_i->i_size;
     314        const size_t new_size = ino_i->i_size - size_shrink;
     315
     316        assert(size_shrink <= old_size);
     317
     318        ino_i->dirty = true;
     319
     320        /*Compute the number of zones to free*/
     321        unsigned zones_to_free = 0;
     322        if (new_size == 0)
     323                ++zones_to_free;
     324
     325        zones_to_free += (old_size / bs) - (new_size / bs);
     326
     327        mfsdebug("zones to free = %u\n", zones_to_free);
     328
     329        uint32_t pos = old_size - 1;
     330        unsigned i;
     331        for (i = 0; i < zones_to_free; ++i, pos -= bs) {
     332                uint32_t old_zone;
     333
     334                r = write_map(mnode, pos, 0, &old_zone);
     335                on_error(r, goto exit_error);
     336
     337                ino_i->i_size -= bs;
     338
     339                if (old_zone == 0)
     340                        continue; /*Sparse block*/
     341
     342                r = mfs_free_bit(mnode->instance, old_zone, BMAP_ZONE);
     343                on_error(r, goto exit_error);
     344        }
     345
     346        ino_i->i_size = new_size;
     347        return EOK;
     348
     349exit_error:
     350        return r;
     351}
     352
     353int
    304354inode_grow(struct mfs_node *mnode, size_t size_grow)
    305355{
Note: See TracChangeset for help on using the changeset viewer.