git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat: refine symbolic link support.
[lunaix-os.git]
/
lunaix-os
/
kernel
/
fs
/
vfs.c
diff --git
a/lunaix-os/kernel/fs/vfs.c
b/lunaix-os/kernel/fs/vfs.c
index 9680f2e9056a274b734d048853c4001cea05e254..7959fc3ffc3cce0cc58d79ec40ec777666480e5f 100644
(file)
--- a/
lunaix-os/kernel/fs/vfs.c
+++ b/
lunaix-os/kernel/fs/vfs.c
@@
-44,7
+44,6
@@
*/
#include <klibc/string.h>
*/
#include <klibc/string.h>
-#include <lunaix/dirent.h>
#include <lunaix/foptions.h>
#include <lunaix/fs.h>
#include <lunaix/mm/cake.h>
#include <lunaix/foptions.h>
#include <lunaix/fs.h>
#include <lunaix/mm/cake.h>
@@
-53,9
+52,12
@@
#include <lunaix/process.h>
#include <lunaix/spike.h>
#include <lunaix/syscall.h>
#include <lunaix/process.h>
#include <lunaix/spike.h>
#include <lunaix/syscall.h>
+#include <lunaix/syscall_utils.h>
#include <lunaix/fs/twifs.h>
#include <lunaix/fs/twifs.h>
+#include <sys/dirent_defs.h>
+
static struct cake_pile* dnode_pile;
static struct cake_pile* inode_pile;
static struct cake_pile* file_pile;
static struct cake_pile* dnode_pile;
static struct cake_pile* inode_pile;
static struct cake_pile* file_pile;
@@
-513,6
+515,7
@@
vfs_i_free(struct v_inode* inode)
/* ---- System call definition and support ---- */
#define FLOCATE_CREATE_EMPTY 1
/* ---- System call definition and support ---- */
#define FLOCATE_CREATE_EMPTY 1
+#define FLOCATE_CREATE_ONLY 2
int
vfs_getfd(int fd, struct v_fd** fd_s)
int
vfs_getfd(int fd, struct v_fd** fd_s)
@@
-539,7
+542,13
@@
__vfs_try_locate_file(const char* path,
}
errno = vfs_walk(*fdir, name.value, file, NULL, 0);
}
errno = vfs_walk(*fdir, name.value, file, NULL, 0);
- if (errno != ENOENT || !(options & FLOCATE_CREATE_EMPTY)) {
+
+ if (errno != ENOENT && (options & FLOCATE_CREATE_ONLY)) {
+ return EEXIST;
+ }
+
+ if (errno != ENOENT ||
+ !(options & (FLOCATE_CREATE_EMPTY | FLOCATE_CREATE_ONLY))) {
return errno;
}
return errno;
}
@@
-624,13
+633,13
@@
__vfs_readdir_callback(struct dir_context* dctx,
const int len,
const int dtype)
{
const int len,
const int dtype)
{
- struct
dirent* dent = (struct
dirent*)dctx->cb_data;
+ struct
lx_dirent* dent = (struct lx_
dirent*)dctx->cb_data;
strncpy(dent->d_name, name, DIRENT_NAME_MAX_LEN);
dent->d_nlen = len;
dent->d_type = dtype;
}
strncpy(dent->d_name, name, DIRENT_NAME_MAX_LEN);
dent->d_nlen = len;
dent->d_type = dtype;
}
-__DEFINE_LXSYSCALL2(int,
readdir, int, fd, struct
dirent*, dent)
+__DEFINE_LXSYSCALL2(int,
sys_readdir, int, fd, struct lx_
dirent*, dent)
{
struct v_fd* fd_s;
int errno;
{
struct v_fd* fd_s;
int errno;
@@
-1199,30
+1208,37
@@
__DEFINE_LXSYSCALL2(int,
link_target)
{
int errno;
link_target)
{
int errno;
- struct v_dnode* dnode;
- if ((errno = vfs_walk_proc(pathname, &dnode, NULL, 0))) {
+ struct v_dnode *dnode, *file;
+ if ((errno = __vfs_try_locate_file(
+ pathname, &dnode, &file, FLOCATE_CREATE_ONLY))) {
goto done;
}
goto done;
}
- if (errno = vfs_check_writable(
dnod
e)) {
+ if (errno = vfs_check_writable(
fil
e)) {
goto done;
}
goto done;
}
- if (!
dnod
e->inode->ops->set_symlink) {
+ if (!
fil
e->inode->ops->set_symlink) {
errno = ENOTSUP;
goto done;
}
errno = ENOTSUP;
goto done;
}
- lock_inode(
dnod
e->inode);
+ lock_inode(
fil
e->inode);
- errno =
dnode->inode->ops->set_symlink(dnod
e->inode, link_target);
+ errno =
file->inode->ops->set_symlink(fil
e->inode, link_target);
- unlock_inode(
dnod
e->inode);
+ unlock_inode(
fil
e->inode);
done:
return DO_STATUS(errno);
}
done:
return DO_STATUS(errno);
}
+void
+vfs_ref_file(struct v_file* file)
+{
+ atomic_fetch_add(&file->ref_count, 1);
+}
+
void
vfs_ref_dnode(struct v_dnode* dnode)
{
void
vfs_ref_dnode(struct v_dnode* dnode)
{
@@
-1314,7
+1330,7
@@
__DEFINE_LXSYSCALL2(char*, getcwd, char*, buf, size_t, size)
}
}
}
}
- buf[len
+ 1
] = '\0';
+ buf[len] = '\0';
ret_ptr = buf;
ret_ptr = buf;