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
userspace fun: maze game and a new device to support it
[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 490b4dfd285cc05a7c7791427a60984f3ebc2204..d4bc56a65c3f6784ef444b0ebcc271eec79b65fc 100644
(file)
--- a/
lunaix-os/kernel/fs/vfs.c
+++ b/
lunaix-os/kernel/fs/vfs.c
@@
-47,7
+47,6
@@
#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>
-#include <lunaix/mm/page.h>
#include <lunaix/mm/valloc.h>
#include <lunaix/process.h>
#include <lunaix/spike.h>
#include <lunaix/mm/valloc.h>
#include <lunaix/process.h>
#include <lunaix/spike.h>
@@
-117,7
+116,7
@@
__dcache_hash(struct v_dnode* parent, u32_t* hash)
// 确保低位更加随机
_hash = _hash ^ (_hash >> VFS_HASHBITS);
// 与parent的指针值做加法,来减小碰撞的可能性。
// 确保低位更加随机
_hash = _hash ^ (_hash >> VFS_HASHBITS);
// 与parent的指针值做加法,来减小碰撞的可能性。
- _hash += (u32_t)
parent
;
+ _hash += (u32_t)
__ptr(parent)
;
*hash = _hash;
return &dnode_cache[_hash & VFS_HASH_MASK];
}
*hash = _hash;
return &dnode_cache[_hash & VFS_HASH_MASK];
}
@@
-860,7
+859,7
@@
vfs_readlink(struct v_dnode* dnode, char* buf, size_t size)
int
vfs_get_dtype(int itype)
{
int
vfs_get_dtype(int itype)
{
- if ((itype & VFS_IFSYMLINK)) {
+ if ((itype & VFS_IFSYMLINK)
== VFS_IFSYMLINK
) {
return DT_SYMLINK;
} else if (!(itype & VFS_IFFILE)) {
return DT_DIR;
return DT_SYMLINK;
} else if (!(itype & VFS_IFFILE)) {
return DT_DIR;
@@
-1003,6
+1002,11
@@
__DEFINE_LXSYSCALL1(int, mkdir, const char*, path)
goto done;
}
goto done;
}
+ if (!(errno = vfs_walk(parent, name_value, &dir, NULL, 0))) {
+ errno = EEXIST;
+ goto done;
+ }
+
if ((errno = vfs_check_writable(parent))) {
goto done;
}
if ((errno = vfs_check_writable(parent))) {
goto done;
}
@@
-1235,14
+1239,19
@@
void
vfs_ref_dnode(struct v_dnode* dnode)
{
atomic_fetch_add(&dnode->ref_count, 1);
vfs_ref_dnode(struct v_dnode* dnode)
{
atomic_fetch_add(&dnode->ref_count, 1);
- mnt_mkbusy(dnode->mnt);
+
+ if (dnode->mnt) {
+ mnt_mkbusy(dnode->mnt);
+ }
}
void
vfs_unref_dnode(struct v_dnode* dnode)
{
atomic_fetch_sub(&dnode->ref_count, 1);
}
void
vfs_unref_dnode(struct v_dnode* dnode)
{
atomic_fetch_sub(&dnode->ref_count, 1);
- mnt_chillax(dnode->mnt);
+ if (dnode->mnt) {
+ mnt_chillax(dnode->mnt);
+ }
}
int
}
int
@@
-1327,7
+1336,7
@@
__DEFINE_LXSYSCALL2(char*, getcwd, char*, buf, size_t, size)
ret_ptr = buf;
done:
ret_ptr = buf;
done:
-
__current->k_status = errno
;
+
syscall_result(errno)
;
return ret_ptr;
}
return ret_ptr;
}
@@
-1444,11
+1453,11
@@
__DEFINE_LXSYSCALL2(int, fstat, int, fd, struct file_stat*, stat)
.st_blocks = vino->lb_usage,
.st_size = vino->fsize,
.mode = vino->itype,
.st_blocks = vino->lb_usage,
.st_size = vino->fsize,
.mode = vino->itype,
- .st_ioblksize = P
G
_SIZE,
+ .st_ioblksize = P
AGE
_SIZE,
.st_blksize = vino->sb->blksize};
if (VFS_DEVFILE(vino->itype)) {
.st_blksize = vino->sb->blksize};
if (VFS_DEVFILE(vino->itype)) {
- struct device* rdev =
(struct device*)vino->data
;
+ struct device* rdev =
resolve_device(vino->data)
;
if (!rdev || rdev->magic != DEV_STRUCT_MAGIC) {
errno = EINVAL;
goto done;
if (!rdev || rdev->magic != DEV_STRUCT_MAGIC) {
errno = EINVAL;
goto done;