- struct hbucket* bucket = __dcache_get_bucket(parent, dnode->name.hash);
- hlist_add(&bucket->head, &dnode->hash_list);
-}
-
-int
-__vfs_walk(struct v_dnode* start,
- const char* path,
- struct v_dnode** dentry,
- struct hstr* component,
- int walk_options)
-{
- int errno = 0;
- int i = 0, j = 0;
-
- if (path[0] == PATH_DELIM || !start) {
- if ((walk_options & VFS_WALK_FSRELATIVE) && start) {
- start = start->super_block->root;
- } else {
- start = root_sb->root;
- }
- i++;
- }
-
- struct v_dnode* dnode;
- struct v_dnode* current_level = start;
-
- char name_content[VFS_NAME_MAXLEN];
- struct hstr name = HSTR(name_content, 0);
-
- char current = path[i++], lookahead;
- while (current) {
- lookahead = path[i++];
- if (current != PATH_DELIM) {
- if (j >= VFS_NAME_MAXLEN - 1) {
- return ENAMETOOLONG;
- }
- if (!VFS_VALID_CHAR(current)) {
- return EINVAL;
- }
- name_content[j++] = current;
- if (lookahead) {
- goto cont;
- }
- }
-
- // handling cases like /^.*(\/+).*$/
- if (lookahead == PATH_DELIM) {
- goto cont;
- }
-
- name_content[j] = 0;
- name.len = j;
- hstr_rehash(&name, HSTR_FULL_HASH);
-
- if (!lookahead && (walk_options & VFS_WALK_PARENT)) {
- if (component) {
- component->hash = name.hash;
- component->len = j;
- strcpy(component->value, name_content);
- }
- break;
- }
-
- dnode = vfs_dcache_lookup(current_level, &name);
-
- if (!dnode) {
- dnode = vfs_d_alloc();
- dnode->name = HHSTR(valloc(VFS_NAME_MAXLEN), j, name.hash);
-
- strcpy(dnode->name.value, name_content);
-
- errno =
- current_level->inode->ops.dir_lookup(current_level->inode, dnode);
-
- if (errno == ENOENT && (walk_options & VFS_WALK_MKPARENT)) {
- if (!current_level->inode->ops.mkdir) {
- errno = ENOTSUP;
- } else {
- errno = current_level->inode->ops.mkdir(
- current_level->inode, dnode);
- }
- }
-
- if (errno) {
- goto error;
- }
-
- vfs_dcache_add(current_level, dnode);
-
- dnode->parent = current_level;
- llist_append(¤t_level->children, &dnode->siblings);
- }