diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-01-04 14:12:24 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-01-04 14:12:24 +0800 |
| commit | a64d25c07b31d57f8706073e11cd774d0880d6dd (patch) | |
| tree | a4bbae6cff94fa69eea30db865267b211eb4c86b /src/fs/fs.cc | |
| parent | 210025560c80b48af4875af199f183ad709e3bf0 (diff) | |
| parent | d3cf3f08d1343d6b265516d5a79ce2d197b59d26 (diff) | |
| download | lume-a64d25c07b31d57f8706073e11cd774d0880d6dd.tar.gz lume-a64d25c07b31d57f8706073e11cd774d0880d6dd.tar.xz | |
Merge pull request #5 from Richard-Qin-001/dev/file-system
feat(file-system): implement read and write FAT32 File System and basic shell
Diffstat (limited to 'src/fs/fs.cc')
| -rw-r--r-- | src/fs/fs.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/fs/fs.cc b/src/fs/fs.cc index c5a34ee..9e3d50e 100644 --- a/src/fs/fs.cc +++ b/src/fs/fs.cc @@ -149,6 +149,7 @@ namespace VFS Inode *ip, *next; struct Proc *p = myproc(); + // 1. 确定起点 if (*path == '/') { ip = get_root(); @@ -170,6 +171,23 @@ namespace VFS while ((path = skipelem(path, name)) != nullptr) { + if (strcmp(name, ".") == 0) + { + continue; + } + + if (strcmp(name, "..") == 0) + { + Inode *root = get_root(); + bool is_root = (ip->inum == root->inum); + iput(root); + + if (is_root) + { + continue; + } + } + ilock(ip); if (ip->type != T_DIR) @@ -189,4 +207,38 @@ namespace VFS return ip; } + Inode *nameiparent(const char* path, char* name) + { + Inode* ip; + Inode* next; + + if (*path == '/') + ip = get_root(); + else + ip = idup(myproc()->cwd ? myproc()->cwd : get_root()); + + while ((path = skipelem(path, name)) != nullptr) + { + if (*path == 0) + { + return ip; + } + + ilock(ip); + if (ip->type != T_DIR) + { + iunlockput(ip); + return nullptr; + } + + next = ip->lookup(name); + iunlockput(ip); + + ip = next; + if (!ip) + return nullptr; + } + iput(ip); + return nullptr; + } } // namespace VFS |
