Kaynağa Gözat

change(file): add ptr to parent in struct file

greatbridf 2 yıl önce
ebeveyn
işleme
bd25366506
3 değiştirilmiş dosya ile 11 ekleme ve 10 silme
  1. 7 5
      include/kernel/process.hpp
  2. 2 3
      include/kernel/vfs.hpp
  3. 2 2
      src/kernel/syscall.cpp

+ 7 - 5
include/kernel/process.hpp

@@ -209,14 +209,16 @@ public:
                 return -1;
             }
 
-            if (!(dentry->ind->flags.in.file || dentry->ind->flags.in.special_node)) {
-                errno = EISDIR;
-                return -1;
-            }
+            // TODO: check whether dentry is a file if O_DIRECTORY is set
+            // if (!(dentry->ind->flags.in.file || dentry->ind->flags.in.special_node)) {
+            //     errno = EISDIR;
+            //     return -1;
+            // }
 
             auto iter = files->emplace_back(fs::file {
                 fs::file::types::regular_file,
-                { .ind = dentry->ind },
+                dentry->ind,
+                dentry->parent,
                 0,
                 1 });
 

+ 2 - 3
include/kernel/vfs.hpp

@@ -166,9 +166,8 @@ struct file {
     enum class types {
         regular_file,
     } type;
-    union {
-        inode* ind;
-    } impl;
+    inode* ind;
+    vfs::dentry* parent;
     size_t cursor;
     size_t ref;
 };

+ 2 - 2
src/kernel/syscall.cpp

@@ -86,7 +86,7 @@ void _syscall_write(interrupt_stack* data)
         return;
     }
 
-    int n_wrote = fs::vfs_write(file->impl.ind, buf, file->cursor, n);
+    int n_wrote = fs::vfs_write(file->ind, buf, file->cursor, n);
     file->cursor += n_wrote;
     SYSCALL_SET_RETURN_VAL(n_wrote, 0);
 }
@@ -104,7 +104,7 @@ void _syscall_read(interrupt_stack* data)
     }
 
     // TODO: copy to user function !IMPORTANT
-    int n_wrote = fs::vfs_read(file->impl.ind, buf, n, file->cursor, n);
+    int n_wrote = fs::vfs_read(file->ind, buf, n, file->cursor, n);
     file->cursor += n_wrote;
     SYSCALL_SET_RETURN_VAL(n_wrote, 0);
 }