Changeset 73196d2 in mainline


Ignore:
Timestamp:
2012-01-21T12:48:03Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5614c7f
Parents:
2d2c6ce
Message:

Skeleton for adding directory entry (without indexing)

Location:
uspace/lib/ext4
Files:
2 edited

Legend:

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

    r2d2c6ce r73196d2  
    239239}
    240240
     241int ext4_directory_add_entry(ext4_filesystem_t *fs, ext4_inode_ref_t * inode_ref,
     242                const char *entry_name, uint32_t child_inode)
     243{
     244        int rc;
     245
     246        // USE index if allowed
     247
     248        uint16_t name_len = strlen(entry_name);
     249        uint16_t required_len = 8 + name_len + (4 - name_len % 4);
     250
     251        ext4_directory_iterator_t it;
     252        rc = ext4_directory_iterator_init(&it, fs, inode_ref, 0);
     253        if (rc != EOK) {
     254                return rc;
     255        }
     256
     257        while (it.current != NULL) {
     258                uint32_t entry_inode = ext4_directory_entry_ll_get_inode(it.current);
     259                uint16_t rec_len = ext4_directory_entry_ll_get_entry_length(it.current);
     260
     261                if ((entry_inode == 0) && (rec_len >= required_len)) {
     262
     263                        // Don't touch entry length
     264                        ext4_directory_entry_ll_set_inode(it.current, child_inode);
     265                        ext4_directory_entry_ll_set_name_length(fs->superblock, it.current, name_len);
     266                        it.current_block->dirty = true;
     267                        return ext4_directory_iterator_fini(&it);
     268                }
     269
     270                if (entry_inode != 0) {
     271
     272                        uint16_t used_name_len = ext4_directory_entry_ll_get_name_length(
     273                                        fs->superblock, it.current);
     274                        uint16_t free_space = rec_len - 8 - (used_name_len + (4- used_name_len % 4));
     275
     276                        if (free_space >= required_len) {
     277                                uint16_t used_len = rec_len - free_space;
     278
     279                                // Cut tail of current entry
     280                                ext4_directory_entry_ll_set_entry_length(it.current, used_len);
     281
     282                                // Jump to newly created
     283                                rc = ext4_directory_iterator_next(&it);
     284                                if (rc != EOK) {
     285                                        return rc;
     286                                }
     287
     288                                // We are sure, that both entries are in the same data block
     289                                // dirtyness will be set now
     290
     291                                ext4_directory_entry_ll_set_inode(it.current, child_inode);
     292                                ext4_directory_entry_ll_set_entry_length(it.current, free_space);
     293                                ext4_directory_entry_ll_set_name_length(
     294                                                fs->superblock, it.current, name_len);
     295                                memcpy(it.current->name, entry_name, name_len);
     296                                it.current_block->dirty = true;
     297                                return ext4_directory_iterator_fini(&it);
     298                        }
     299
     300                }
     301
     302                rc = ext4_directory_iterator_next(&it);
     303                if (rc != EOK) {
     304                        return rc;
     305                }
     306        }
     307
     308        // TODO - no free space found - alloc data block
     309        // and fill the whole block with new entry
     310
     311        // TODO
     312        return EOK;
     313}
    241314
    242315int ext4_directory_find_entry(ext4_directory_iterator_t *it,
  • uspace/lib/ext4/libext4_directory.h

    r2d2c6ce r73196d2  
    8080extern int ext4_directory_iterator_fini(ext4_directory_iterator_t *);
    8181
     82extern int ext4_directory_add_entry(ext4_filesystem_t *, ext4_inode_ref_t *,
     83                const char *, uint32_t);
    8284extern int ext4_directory_find_entry(ext4_directory_iterator_t *,
    8385                ext4_inode_ref_t *, const char *);
Note: See TracChangeset for help on using the changeset viewer.