X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/0cf90cca0c924622f3fee8d2a3fafa8238363dc6..34f6af4f61e0eec9c96113e07f140b609b4113c8:/lunaix-os/kernel/fs/path_walk.c diff --git a/lunaix-os/kernel/fs/path_walk.c b/lunaix-os/kernel/fs/path_walk.c index cd0ac01..84e04d0 100644 --- a/lunaix-os/kernel/fs/path_walk.c +++ b/lunaix-os/kernel/fs/path_walk.c @@ -6,6 +6,7 @@ #include #define VFS_SYMLINK_DEPTH 16 +#define VFS_SYMLINK_MAXLEN 512 extern struct lru_zone *dnode_lru, *inode_lru; @@ -31,7 +32,7 @@ __vfs_walk(struct v_dnode* start, } else { start = vfs_sysroot; if (!vfs_sysroot->mnt) { - panick("vfs: no root"); + fail("vfs: no root"); } } @@ -43,8 +44,8 @@ __vfs_walk(struct v_dnode* start, assert(start); struct v_dnode* dnode; - struct v_inode* current_inode; struct v_dnode* current_level = start; + struct v_inode* current_inode = current_level->inode; struct hstr name = HSTR(fname_buffer, 0); @@ -80,38 +81,6 @@ __vfs_walk(struct v_dnode* start, break; } - current_inode = current_level->inode; - - if ((current_inode->itype & VFS_IFSYMLINK) && - !(walk_options & VFS_WALK_NOFOLLOW)) { - const char* link; - - lock_inode(current_inode); - if ((errno = - current_inode->ops->read_symlink(current_inode, &link))) { - unlock_inode(current_inode); - goto error; - } - unlock_inode(current_inode); - - errno = __vfs_walk(current_level->parent, - link, - &dnode, - NULL, - 0, - depth + 1, - fname_buffer + name.len + 1); - - if (errno) { - goto error; - } - - // reposition the resolved subtree pointed by symlink - // vfs_dcache_rehash(current_level->parent, dnode); - current_level = dnode; - current_inode = dnode->inode; - } - lock_dnode(current_level); dnode = vfs_dcache_lookup(current_level, &name); @@ -149,6 +118,48 @@ __vfs_walk(struct v_dnode* start, j = 0; current_level = dnode; + current_inode = current_level->inode; + + assert(current_inode); + + if (check_symlink_node(current_inode) && + !(walk_options & VFS_WALK_NOFOLLOW)) { + const char* link; + struct v_inode_ops* iops; + + iops = current_inode->ops; + + if (!iops->read_symlink) { + errno = ENOTSUP; + goto error; + } + + lock_inode(current_inode); + + errno = iops->read_symlink(current_inode, &link); + if ((errno < 0)) { + unlock_inode(current_inode); + goto error; + } + + unlock_inode(current_inode); + + errno = __vfs_walk(current_level->parent, + link, + &dnode, + NULL, + 0, + depth + 1, + fname_buffer + name.len + 1); + + if (errno) { + goto error; + } + + current_level = dnode; + current_inode = dnode->inode; + } + cont: current = lookahead; }; @@ -170,6 +181,11 @@ vfs_walk(struct v_dnode* start, struct hstr* component, int options) { + if (!path) { + *dentry = NULL; + return 0; + } + // allocate a file name stack for path walking and recursion to resolve // symlink char* name_buffer = valloc(2048);