Linux_文件系统 #99
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: HswOAuth/llm_course#99
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
目录
前言
a. 文件 = 内容 + 属性
b. 访问文件之前,都得先打开,修改文件,都是通过执行代码的方式完成修改,文件必须被加载到内存中
c. 谁打开文件?进程在打开文件
d. 一个进程可以打开多少个文件呢?可以打开多个文件
e. 进程和文件的关系,
struct task_struct
和struct XXXX
?f. 系统中是不是所有的文件都被进程打开了?不是!没有被打开的文件?就在磁盘中
C语言文件接口-对比重定向

stdin
,stdout
,stderr
可以直接被使用。extern FILE *stdin/stdout/stderr
:FILE
是 C 语言自己封装的一个结构体,必定要封装特定的fd
。int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
w: 清空文件
-int fd=open("log.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666);
a: 追加文件
-int fd=open("log.txt", O_WRONLY|O_CREAT|O_APPEND, 0666);
文件 fd
fd
呢?文件描述符的本质,就是数组下标。ssize_t write(int fd, const void *buf, size_t count);
ssize_t read(int fd, const void *buf, size_t count);
int close(int fd);
struct_file
存入文件描述符表,通过不同的fd
找到每一个file
结构体(属性,方法集,缓冲区),文件关闭时存入磁盘中。缓冲区问题
XXX\nYYY
a. 强制刷新
b. 进程退出的时候,要自动刷新
FILE
结构来维护的!一个文件维护一个缓冲区test.txt
刷新策略,立即变成了全缓冲,刷新数据,就是清空缓冲区,修改数据的一种方式。文件系统
磁盘的物理存储
cylinder
head
Sector
磁盘的逻辑存储
sector/单盘扇区的=0
sector%单盘扇区的个数=temp
temp/一个磁道上的扇区的个数==我在哪一个磁道
temp%一个磁道上的扇区的个数==结果,我是特定一个磁道的哪一个扇区
Linux 文件系统结构
文件操作
软硬链接
硬链接
.
和..
目录项)。软链接
ln -s
命令创建软链接。示例操作