Changeset 8be96a0 in mainline
- Timestamp:
- 2011-11-22T12:15:37Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bf66ef4
- Parents:
- f49638e
- Location:
- uspace
- Files:
-
- 3 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); -
uspace/lib/ext4/libext4_directory.h
rf49638e r8be96a0 77 77 ext4_filesystem_t *, ext4_inode_ref_t *, aoff64_t); 78 78 extern int ext4_directory_iterator_next(ext4_directory_iterator_t *); 79 extern int ext4_directory_iterator_seek(ext4_directory_iterator_t *, aoff64_t pos);79 extern int ext4_directory_iterator_seek(ext4_directory_iterator_t *, aoff64_t); 80 80 extern int ext4_directory_iterator_fini(ext4_directory_iterator_t *); 81 81 82 extern int ext4_directory_find_entry(ext4_directory_iterator_t *, 83 ext4_inode_ref_t *, const char *); 82 84 extern int ext4_directory_remove_entry(ext4_filesystem_t* , 83 ext4_inode_ref_t *, const char * name);85 ext4_inode_ref_t *, const char *); 84 86 85 87 #endif -
uspace/srv/fs/ext4fs/ext4fs_ops.c
rf49638e r8be96a0 205 205 ext4_directory_iterator_t it; 206 206 int rc; 207 size_t name_size;208 size_t component_size;209 bool found = false;210 uint32_t inode;211 207 212 208 fs = eparent->instance->filesystem; … … 217 213 } 218 214 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 corrupted227 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 242 215 rc = ext4_directory_iterator_init(&it, fs, eparent->inode_ref, 0); 243 216 if (rc != EOK) { … … 245 218 } 246 219 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; 273 232 } 274 233 275 234 ext4_directory_iterator_fini(&it); 276 277 if (!found) {278 return ENOENT;279 }280 281 235 return EOK; 282 236 } … … 791 745 ext4fs_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes) 792 746 { 793 794 747 ext4_directory_iterator_t it; 795 748 aoff64_t next; … … 1151 1104 static int ext4fs_destroy(service_id_t service_id, fs_index_t index) 1152 1105 { 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); 1157 1116 } 1158 1117
Note:
See TracChangeset
for help on using the changeset viewer.