Changeset 8be96a0 in mainline for uspace/lib/ext4/libext4_directory.c
- Timestamp:
- 2011-11-22T12:15:37Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bf66ef4
- Parents:
- f49638e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_directory.c
rf49638e r8be96a0 75 75 ext4_superblock_get_minor_rev_level(sb) < 5) { 76 76 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; 83 82 84 83 } … … 87 86 ext4_directory_entry_ll_t *de, uint16_t length) 88 87 { 89 90 88 de->name_length = (length << 8) >> 8; 91 89 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) { 94 92 95 93 de->name_length_high = length >> 8; 96 94 } 97 98 95 } 99 96 … … 243 240 244 241 242 int 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 245 297 int 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 { 251 300 int rc; 252 301 ext4_directory_iterator_t it; 253 302 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); 255 309 if (rc != EOK) { 256 310 return rc; 257 311 } 258 312 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 303 325 304 326 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
Note:
See TracChangeset
for help on using the changeset viewer.