Merge branch 'master' into vfs-dev
[lunaix-os.git] / lunaix-os / kernel / fs / vfs.c
index 53d21d8b026baa7f07ce38bc34a12cda78c0ee90..11896ec6730e4377a24d3d4d72b7644622663c51 100644 (file)
@@ -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;
     }