vfs: add vfs_openat
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
51928ebca4
commit
733b9a7c47
2 changed files with 18 additions and 9 deletions
26
fs/vfs/vfs.c
26
fs/vfs/vfs.c
|
|
@ -85,19 +85,16 @@ static int next_level(const char *path, dirent_t *dent, dirent_t **out_dirent)
|
|||
return -ENOENT;
|
||||
}
|
||||
|
||||
int vfs_open(const char *abs_path, dirent_t **out)
|
||||
int vfs_openat(dirent_t *in, const char *name, dirent_t **out)
|
||||
{
|
||||
if (!abs_path || !out)
|
||||
if (!in || !name || !out)
|
||||
return -EINVAL;
|
||||
|
||||
if (!root_fs->root_dirent)
|
||||
return -ENOENT;
|
||||
|
||||
char *path_optr = path_trim(abs_path);
|
||||
char *path_optr = path_trim(name);
|
||||
if (!path_optr)
|
||||
return -ENOMEM;
|
||||
|
||||
dirent_t *current_dir = root_fs->root_dirent;
|
||||
dirent_t *current_dir = in;
|
||||
dirent_inc_ref(current_dir);
|
||||
|
||||
if (*path_optr == '\0') {
|
||||
|
|
@ -138,6 +135,17 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int vfs_open(const char *abs_path, dirent_t **out)
|
||||
{
|
||||
if (!abs_path || !out)
|
||||
return -EINVAL;
|
||||
|
||||
if (!root_fs->root_dirent)
|
||||
return -ENOENT;
|
||||
|
||||
return vfs_openat(root_fs->root_dirent, abs_path, out);
|
||||
}
|
||||
|
||||
void vfs_close(dirent_t *dent)
|
||||
{
|
||||
dirent_dec_ref(dent);
|
||||
|
|
@ -182,7 +190,7 @@ int vfs_creat(dirent_t *parent, const char *name, u64 mode, int flags, dirent_t
|
|||
|
||||
write_lock(&ino->rwlock);
|
||||
|
||||
if ((ino->mode &S_IFMT) != S_IFDIR) {
|
||||
if ((ino->mode & S_IFMT) != S_IFDIR) {
|
||||
write_unlock(&ino->rwlock);
|
||||
return -ENOTDIR;
|
||||
}
|
||||
|
|
@ -231,7 +239,7 @@ int vfs_unlink(dirent_t *parent, const char *name)
|
|||
|
||||
write_lock(&ino->rwlock);
|
||||
|
||||
if ((ino->mode & S_IFMT)!= S_IFDIR) {
|
||||
if ((ino->mode & S_IFMT) != S_IFDIR) {
|
||||
write_unlock(&ino->rwlock);
|
||||
return -ENOTDIR;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue