Changeset f49638e in mainline


Ignore:
Timestamp:
2011-11-22T10:01:42Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8be96a0
Parents:
ebeaaa06
Message:

directory entry delete operation (without HTree index modification)

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/Makefile

    rebeaaa06 rf49638e  
    2929USPACE_PREFIX = ../..
    3030LIBRARY = libext4
    31 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
    32 LIBS = $(LIBBLOCK_PREFIX)/libblock.a
     31EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBPOSIX_PREFIX)
     32LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBPOSIX_PREFIX)/libposix.a
    3333
    3434SOURCES = \
  • uspace/lib/ext4/libext4_directory.c

    rebeaaa06 rf49638e  
    3838#include <byteorder.h>
    3939#include <errno.h>
     40#include <malloc.h>
     41#include <string.h>
    4042#include "libext4.h"
    4143
     
    241243
    242244
     245int 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
     251        int rc;
     252        ext4_directory_iterator_t it;
     253
     254        rc = ext4_directory_iterator_init(&it, fs, inode_ref, 0);
     255        if (rc != EOK) {
     256                return rc;
     257        }
     258
     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
     287skip:
     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
     303
     304        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
     305        uint32_t pos = it.current_offset % block_size;
     306
     307        ext4_directory_entry_ll_set_inode(it.current, 0);
     308
     309        if (pos != 0) {
     310                uint32_t offset = 0;
     311
     312                ext4_directory_entry_ll_t *tmp_dentry = it.current_block->data;
     313                uint16_t tmp_dentry_length =
     314                                ext4_directory_entry_ll_get_entry_length(tmp_dentry);
     315
     316                while ((offset + tmp_dentry_length) < pos) {
     317                        offset += ext4_directory_entry_ll_get_entry_length(tmp_dentry);
     318                        tmp_dentry = it.current_block->data + offset;
     319                        tmp_dentry_length =
     320                                        ext4_directory_entry_ll_get_entry_length(tmp_dentry);
     321                }
     322
     323                assert(tmp_dentry_length + offset == pos);
     324
     325                uint16_t del_entry_length =
     326                                ext4_directory_entry_ll_get_entry_length(it.current);
     327                ext4_directory_entry_ll_set_entry_length(tmp_dentry,
     328                                tmp_dentry_length + del_entry_length);
     329
     330        }
     331
     332
     333        it.current_block->dirty = true;
     334
     335        ext4_directory_iterator_fini(&it);
     336        return EOK;
     337}
    243338
    244339
  • uspace/lib/ext4/libext4_directory.h

    rebeaaa06 rf49638e  
    8080extern int ext4_directory_iterator_fini(ext4_directory_iterator_t *);
    8181
     82extern int ext4_directory_remove_entry(ext4_filesystem_t* ,
     83                ext4_inode_ref_t *, const char *name);
     84
    8285#endif
    8386
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    rebeaaa06 rf49638e  
    446446int ext4fs_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *name)
    447447{
    448 
    449         return ENOTSUP;
    450 
    451448        int rc;
    452449
     
    463460
    464461        // Remove entry from parent directory
    465         // TODO
    466 //      rc = ext4_directory_remove_entry(EXT4FS_NODE(pfn), name);
    467 //      if (rc != EOK) {
    468 //              return rc;
    469 //      }
     462        ext4_inode_ref_t *parent = EXT4FS_NODE(pfn)->inode_ref;
     463        ext4_filesystem_t *fs = EXT4FS_NODE(pfn)->instance->filesystem;
     464        rc = ext4_directory_remove_entry(fs, parent, name);
     465        if (rc != EOK) {
     466                return rc;
     467        }
    470468
    471469        // Decrement links count
     
    489487                parent_inode_ref->dirty = true;
    490488        }
    491 
    492489
    493490        return EOK;
Note: See TracChangeset for help on using the changeset viewer.