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

Changeset ebcaff4 in mainline


Ignore:
Timestamp:
2011-12-03T10:42:28Z (10 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master
Children:
2449396
Parents:
1e48a07e
Message:

Orphaned inodes handling

Location:
uspace/lib/ext4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_filesystem.c

    r1e48a07e rebcaff4  
    783783}
    784784
     785int ext4_filesystem_add_orphan(ext4_filesystem_t *fs,
     786                ext4_inode_ref_t *inode_ref)
     787{
     788        uint32_t next_orphan = ext4_superblock_get_last_orphan(fs->superblock);
     789        ext4_inode_set_deletion_time(inode_ref->inode, next_orphan);
     790        ext4_superblock_set_last_orphan(fs->superblock, inode_ref->index);
     791        inode_ref->dirty = true;
     792
     793        return EOK;
     794}
     795
     796int ext4_filesystem_delete_orphan(ext4_filesystem_t *fs,
     797                ext4_inode_ref_t *inode_ref)
     798{
     799        int rc;
     800
     801        uint32_t last_orphan = ext4_superblock_get_last_orphan(fs->superblock);
     802        assert(last_orphan > 0);
     803
     804        uint32_t next_orphan = ext4_inode_get_deletion_time(inode_ref->inode);
     805
     806        if (last_orphan == inode_ref->index) {
     807                ext4_superblock_set_last_orphan(fs->superblock, next_orphan);
     808                ext4_inode_set_deletion_time(inode_ref->inode, 0);
     809                inode_ref->dirty = true;
     810                return EOK;
     811        }
     812
     813        ext4_inode_ref_t *current;
     814        rc = ext4_filesystem_get_inode_ref(fs, last_orphan, &current);
     815        if (rc != EOK) {
     816                return rc;
     817        }
     818        next_orphan = ext4_inode_get_deletion_time(current->inode);
     819
     820        bool found;
     821
     822        while (next_orphan != 0) {
     823                if (next_orphan == inode_ref->index) {
     824                        next_orphan = ext4_inode_get_deletion_time(inode_ref->inode);
     825                        ext4_inode_set_deletion_time(current->inode, next_orphan);
     826                        current->dirty = true;
     827                        found = true;
     828                        break;
     829                }
     830
     831                ext4_filesystem_put_inode_ref(current);
     832
     833                rc = ext4_filesystem_get_inode_ref(fs, next_orphan, &current);
     834                if (rc != EOK) {
     835                        return rc;
     836                }
     837                next_orphan = ext4_inode_get_deletion_time(current->inode);
     838
     839        }
     840
     841        ext4_inode_set_deletion_time(inode_ref->inode, 0);
     842
     843        rc = ext4_filesystem_put_inode_ref(current);
     844        if (rc != EOK) {
     845                return rc;
     846        }
     847
     848        if (!found) {
     849                return ENOENT;
     850        }
     851
     852        return EOK;
     853}
     854
    785855/**
    786856 * @}
  • uspace/lib/ext4/libext4_filesystem.h

    r1e48a07e rebcaff4  
    7070extern int ext4_filesystem_release_inode_block(ext4_filesystem_t *,
    7171                ext4_inode_ref_t *, uint32_t);
     72extern int ext4_filesystem_add_orphan(ext4_filesystem_t *,
     73                ext4_inode_ref_t *);
     74extern int ext4_filesystem_delete_orphan(ext4_filesystem_t *,
     75                ext4_inode_ref_t *);
    7276#endif
    7377
  • uspace/lib/ext4/libext4_superblock.c

    r1e48a07e rebcaff4  
    354354}
    355355
     356uint32_t ext4_superblock_get_last_orphan(ext4_superblock_t *sb)
     357{
     358        return uint32_t_le2host(sb->last_orphan);
     359}
     360
     361void ext4_superblock_set_last_orphan(ext4_superblock_t *sb, uint32_t last_orphan)
     362{
     363        sb->last_orphan = host2uint32_t_le(last_orphan);
     364}
     365
    356366uint32_t* ext4_superblock_get_hash_seed(ext4_superblock_t *sb)
    357367{
  • uspace/lib/ext4/libext4_superblock.h

    r1e48a07e rebcaff4  
    272272uint32_t s_journal_inum; // Inode number of journal file
    273273uint32_t s_journal_dev; // Device number of journal file
    274 uint32_t s_last_orphan; // Head of list of inodes to delete
    275274*/
     275extern uint32_t ext4_superblock_get_last_orphan(ext4_superblock_t *);
     276extern void ext4_superblock_set_last_orphan(ext4_superblock_t *, uint32_t);
    276277extern uint32_t* ext4_superblock_get_hash_seed(ext4_superblock_t *);
    277278/*
Note: See TracChangeset for help on using the changeset viewer.