X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/fac3bbf2b2634f4f15cb33ece3acfa39db1433df..a5338b60e111972364a8bc6f07011c6defd213d2:/lunaix-os/kernel/fs/vfs.c diff --git a/lunaix-os/kernel/fs/vfs.c b/lunaix-os/kernel/fs/vfs.c index 53d21d8..11896ec 100644 --- a/lunaix-os/kernel/fs/vfs.c +++ b/lunaix-os/kernel/fs/vfs.c @@ -657,7 +657,9 @@ __DEFINE_LXSYSCALL3(int, read, int, fd, void*, buf, size_t, count) goto done; } + cpu_enable_interrupt(); errno = file->ops.read(file, buf, count, file->f_pos); + cpu_disable_interrupt(); if (errno > 0) { file->f_pos += errno; @@ -683,7 +685,9 @@ __DEFINE_LXSYSCALL3(int, write, int, fd, void*, buf, size_t, count) goto done; } + cpu_enable_interrupt(); errno = file->ops.write(file, buf, count, file->f_pos); + cpu_disable_interrupt(); if (errno > 0) { file->f_pos += errno; @@ -941,7 +945,7 @@ __DEFINE_LXSYSCALL1(int, fsync, int, fildes) } int -__vfs_dup_fd(struct v_fd* old, struct v_fd** new) +vfs_dup_fd(struct v_fd* old, struct v_fd** new) { int errno = 0; struct v_fd* copied = cake_grab(fd_pile); @@ -949,10 +953,13 @@ __vfs_dup_fd(struct v_fd* old, struct v_fd** new) memcpy(copied, old, sizeof(struct v_fd)); old->file->ref_count++; + *new = copied; + return errno; } -__DEFINE_LXSYSCALL2(int, dup2, int, oldfd, int, newfd) +int +vfs_dup2(int oldfd, int newfd) { if (newfd == oldfd) { return newfd; @@ -960,7 +967,7 @@ __DEFINE_LXSYSCALL2(int, dup2, int, oldfd, int, newfd) int errno; struct v_fd *oldfd_s, *newfd_s; - if (!GET_FD(oldfd, oldfd_s) || TEST_FD(newfd)) { + if (!GET_FD(oldfd, oldfd_s) || !TEST_FD(newfd)) { errno = EBADF; goto done; } @@ -969,7 +976,7 @@ __DEFINE_LXSYSCALL2(int, dup2, int, oldfd, int, newfd) goto done; } - if (!(errno = __vfs_dup_fd(oldfd_s, &newfd_s))) { + if (!(errno = vfs_dup_fd(oldfd_s, &newfd_s))) { __current->fdtable->fds[newfd] = newfd_s; return newfd; } @@ -978,6 +985,11 @@ done: return DO_STATUS(errno); } +__DEFINE_LXSYSCALL2(int, dup2, int, oldfd, int, newfd) +{ + return vfs_dup2(oldfd, newfd); +} + __DEFINE_LXSYSCALL1(int, dup, int, oldfd) { int errno, newfd; @@ -985,7 +997,7 @@ __DEFINE_LXSYSCALL1(int, dup, int, oldfd) if (!GET_FD(oldfd, oldfd_s)) { errno = EBADF; } else if (!(errno = vfs_alloc_fdslot(&newfd)) && - !(errno = __vfs_dup_fd(oldfd_s, &newfd_s))) { + !(errno = vfs_dup_fd(oldfd_s, &newfd_s))) { __current->fdtable->fds[newfd] = newfd_s; return newfd; }