VFS system call
- Interfaces for specific File Systems, like ramfs, s5fs.
- 在Linux中,文件名字没有缀;“file”与“directory”无区别
- 所有涉及“绝对路径”最后一级拆分的,会先将trailing “/” 去掉
- lookup()这个函数作用巨大:
- 在dir_inode中,找名字是“name”的entry,并把该entry变为vnode放到result中
- ramfs_lookup => entry => vget(entry) => ramfs_read_vnode(vnode) => 完整vnode
- VFS-AFS-VFS: “虚、实连接的小能手”
- 递归进行name resolution
- 问 parent inode:你是否包含名字为“name”的entry?
- if Yes,把该entry以 child inode的形式返回
- 递归进行lookup,直至找到目标name的inode
以vn_mode来区别inode的类型**
1
2
3
4
5S_IFDIR directory
S_IFREG regular
S_IFLNK symlink
S_IFCHR character special
S_IFBLK block special为什么 dir_namev() 与 lookup() 一起使用?直接使用open_namev()可以么??
1. open
1 | int do_open(const char *filename, int oflags) |
2. read
1 | int do_read(int fd, void *buf, size_t nbytes) |
3. write
1 | int do_write(int fd, const void *buf, size_t nbytes) |
4. close
1 |
|
5. duplicate a file_descriptor
1 | int do_dup(int fd) |
6. duplicate with a designated file_descriptor
1 | int do_dup2(int ofd, int nfd) |
7. mknode
1 | int do_mknod(const char *path, int mode, unsigned devid) |
8. make directory
1 | int do_mkdir(const char *path) |
9. remove directory
1 | int do_rmdir(const char *path) |
10. unlink
1 | int do_unlink(const char *path) |
11. link
1 | int do_link(const char *from, const char *to) |
12. rename
1 | int do_rename(const char *oldname, const char *newname) |
13. change dir
1 | int do_chdir(const char *path) |
14. get dir entry
1 | int do_getdent(int fd, struct dirent *dirp) |
15. lseek
1 | int do_lseek(int fd, int offset, int whence) |
16. statistic
1 | int do_stat(const char *path, struct stat *buf) |