Changeset 8be96a0 in mainline


Ignore:
Timestamp:
2011-11-22T12:15:37Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bf66ef4
Parents:
f49638e
Message:

code optimalization (removed duplicity) and destroy functions implementation started

Location:
uspace
Files:
3 edited

Legend:

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

    rf49638e r8be96a0  
    7575            ext4_superblock_get_minor_rev_level(sb) < 5) {
    7676
    77                 return de->name_length;
    78         }
    79 
    80         return ((uint16_t)de->name_length_high) << 8 |
    81             ((uint16_t)de->name_length);
    82 
     77                return ((uint16_t)de->name_length_high) << 8 |
     78                            ((uint16_t)de->name_length);
     79
     80        }
     81        return de->name_length;
    8382
    8483}
     
    8786                ext4_directory_entry_ll_t *de, uint16_t length)
    8887{
    89 
    9088        de->name_length = (length << 8) >> 8;
    9189
    92         if (ext4_superblock_get_rev_level(sb) > 0 ||
    93                     ext4_superblock_get_minor_rev_level(sb) >= 5) {
     90        if (ext4_superblock_get_rev_level(sb) == 0 &&
     91                    ext4_superblock_get_minor_rev_level(sb) < 5) {
    9492
    9593                de->name_length_high = length >> 8;
    9694        }
    97 
    9895}
    9996
     
    243240
    244241
     242int ext4_directory_find_entry(ext4_directory_iterator_t *it,
     243                ext4_inode_ref_t *parent, const char *name)
     244{
     245        int rc;
     246        uint32_t name_size = strlen(name);
     247
     248        // Index search
     249        if (ext4_superblock_has_feature_compatible(it->fs->superblock, EXT4_FEATURE_COMPAT_DIR_INDEX) &&
     250                        ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) {
     251
     252                rc = ext4_directory_dx_find_entry(it, it->fs, parent, name_size, name);
     253
     254                // Check if index is not corrupted
     255                if (rc != EXT4_ERR_BAD_DX_DIR) {
     256
     257                        if (rc != EOK) {
     258                                return rc;
     259                        }
     260                        return EOK;
     261                }
     262
     263                EXT4FS_DBG("index is corrupted - doing linear search");
     264        }
     265
     266        bool found = false;
     267        // Linear search
     268        while (it->current != NULL) {
     269                uint32_t inode = ext4_directory_entry_ll_get_inode(it->current);
     270
     271                /* ignore empty directory entries */
     272                if (inode != 0) {
     273                        uint16_t entry_name_size = ext4_directory_entry_ll_get_name_length(
     274                                        it->fs->superblock, it->current);
     275
     276                        if (entry_name_size == name_size && bcmp(name, it->current->name,
     277                                    name_size) == 0) {
     278                                found = true;
     279                                break;
     280                        }
     281                }
     282
     283                rc = ext4_directory_iterator_next(it);
     284                if (rc != EOK) {
     285                        return rc;
     286                }
     287        }
     288
     289        if (!found) {
     290                return ENOENT;
     291        }
     292
     293        return EOK;
     294}
     295
     296
    245297int ext4_directory_remove_entry(ext4_filesystem_t* fs,
    246                 ext4_inode_ref_t *inode_ref, const char *name)
    247 {
    248 
    249         // TODO modify HTREE index if exists
    250 
     298                ext4_inode_ref_t *parent, const char *name)
     299{
    251300        int rc;
    252301        ext4_directory_iterator_t it;
    253302
    254         rc = ext4_directory_iterator_init(&it, fs, inode_ref, 0);
     303        if (!ext4_inode_is_type(fs->superblock, parent->inode,
     304            EXT4_INODE_MODE_DIRECTORY)) {
     305                return ENOTDIR;
     306        }
     307
     308        rc = ext4_directory_iterator_init(&it, fs, parent, 0);
    255309        if (rc != EOK) {
    256310                return rc;
    257311        }
    258312
    259         uint16_t name_size = strlen(name);
    260         bool found = false;
    261 
    262         while (it.current != NULL) {
    263 
    264                 if (it.current->inode == 0) {
    265                         goto skip;
    266                 }
    267 
    268                 uint16_t entry_name_size = ext4_directory_entry_ll_get_name_length(
    269                     fs->superblock, it.current);
    270 
    271                 /* skip . and .. */
    272                 if (entry_name_size == 1 && name[0] == '.') {
    273                         goto skip;
    274                 }
    275 
    276                 if (entry_name_size == 2 && name[0] == '.' && name[1] == '.') {
    277                         goto skip;
    278                 }
    279 
    280                 if (name_size == entry_name_size &&
    281                                 bcmp(name, &it.current->name, name_size) == 0) {
    282 
    283                         found = true;
    284                         break;
    285                 }
    286 
    287 skip:
    288                 rc = ext4_directory_iterator_next(&it);
    289                 if (rc != EOK) {
    290                         ext4_directory_iterator_fini(&it);
    291                         return rc;
    292                 }
    293         }
    294 
    295         if (! found) {
    296                 rc = ext4_directory_iterator_fini(&it);
    297                 if (rc != EOK) {
    298                         return rc;
    299                 }
    300                 return ENOENT;
    301         }
    302 
     313        rc = ext4_directory_find_entry(&it, parent, name);
     314        if (rc != EOK) {
     315                ext4_directory_iterator_fini(&it);
     316                return rc;
     317        }
     318
     319        if (rc != EOK) {
     320                ext4_directory_iterator_fini(&it);
     321                return rc;
     322        }
     323
     324        // TODO modify HTREE index if exists
    303325
    304326        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
  • uspace/lib/ext4/libext4_directory.h

    rf49638e r8be96a0  
    7777                ext4_filesystem_t *, ext4_inode_ref_t *, aoff64_t);
    7878extern int ext4_directory_iterator_next(ext4_directory_iterator_t *);
    79 extern int ext4_directory_iterator_seek(ext4_directory_iterator_t *, aoff64_t pos);
     79extern int ext4_directory_iterator_seek(ext4_directory_iterator_t *, aoff64_t);
    8080extern int ext4_directory_iterator_fini(ext4_directory_iterator_t *);
    8181
     82extern int ext4_directory_find_entry(ext4_directory_iterator_t *,
     83                ext4_inode_ref_t *, const char *);
    8284extern int ext4_directory_remove_entry(ext4_filesystem_t* ,
    83                 ext4_inode_ref_t *, const char *name);
     85                ext4_inode_ref_t *, const char *);
    8486
    8587#endif
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    rf49638e r8be96a0  
    205205        ext4_directory_iterator_t it;
    206206        int rc;
    207         size_t name_size;
    208         size_t component_size;
    209         bool found = false;
    210         uint32_t inode;
    211207
    212208        fs = eparent->instance->filesystem;
     
    217213        }
    218214
    219         component_size = strlen(component);
    220 
    221         if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_COMPAT_DIR_INDEX) &&
    222                         ext4_inode_has_flag(eparent->inode_ref->inode, EXT4_INODE_FLAG_INDEX)) {
    223 
    224                 rc = ext4_directory_dx_find_entry(&it, fs, eparent->inode_ref, component_size, component);
    225 
    226                 // Index isn't corrupted
    227                 if (rc != EXT4_ERR_BAD_DX_DIR) {
    228 
    229                         if (rc != EOK) {
    230                                 return rc;
    231                         }
    232 
    233                         inode = ext4_directory_entry_ll_get_inode(it.current);
    234 
    235                         rc = ext4fs_node_get_core(rfn, eparent->instance, inode);
    236                         ext4_directory_iterator_fini(&it);
    237                         return rc;
    238                 }
    239 
    240         }
    241 
    242215        rc = ext4_directory_iterator_init(&it, fs, eparent->inode_ref, 0);
    243216        if (rc != EOK) {
     
    245218        }
    246219
    247         while (it.current != NULL) {
    248                 inode = ext4_directory_entry_ll_get_inode(it.current);
    249 
    250                 /* ignore empty directory entries */
    251                 if (inode != 0) {
    252                         name_size = ext4_directory_entry_ll_get_name_length(fs->superblock,
    253                                 it.current);
    254 
    255                         if (name_size == component_size && bcmp(component, &it.current->name,
    256                                     name_size) == 0) {
    257                                 rc = ext4fs_node_get_core(rfn, eparent->instance,
    258                                         inode);
    259                                 if (rc != EOK) {
    260                                         ext4_directory_iterator_fini(&it);
    261                                         return rc;
    262                                 }
    263                                 found = true;
    264                                 break;
    265                         }
    266                 }
    267 
    268                 rc = ext4_directory_iterator_next(&it);
    269                 if (rc != EOK) {
    270                         ext4_directory_iterator_fini(&it);
    271                         return rc;
    272                 }
     220        rc = ext4_directory_find_entry(&it, eparent->inode_ref, component);
     221        if (rc != EOK) {
     222                ext4_directory_iterator_fini(&it);
     223                return rc;
     224        }
     225
     226        uint32_t inode = ext4_directory_entry_ll_get_inode(it.current);
     227
     228        rc = ext4fs_node_get_core(rfn, eparent->instance, inode);
     229        if (rc != EOK) {
     230                ext4_directory_iterator_fini(&it);
     231                return rc;
    273232        }
    274233
    275234        ext4_directory_iterator_fini(&it);
    276 
    277         if (!found) {
    278                 return ENOENT;
    279         }
    280 
    281235        return EOK;
    282236}
     
    791745    ext4fs_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes)
    792746{
    793 
    794747        ext4_directory_iterator_t it;
    795748        aoff64_t next;
     
    11511104static int ext4fs_destroy(service_id_t service_id, fs_index_t index)
    11521105{
    1153         EXT4FS_DBG("not supported");
    1154 
    1155         //TODO
    1156         return ENOTSUP;
     1106        int rc;
     1107        fs_node_t *fn;
     1108
     1109        rc = ext4fs_node_get(&fn, service_id, index);
     1110        if (rc != EOK) {
     1111                return rc;
     1112        }
     1113
     1114        /* Destroy the inode */
     1115        return ext4fs_destroy_node(fn);
    11571116}
    11581117
Note: See TracChangeset for help on using the changeset viewer.