【操作系统学习笔记】文件管理1.5
参考书籍: 王道考研
视频地址: Bilibili
逻辑结构 VS 物理结构
-
逻辑结构: 从用户角度看,由创建文件的用户自己设计的
-
无结构文件
// 在用户看来是一篇连续的空间 FILE *fp = fopen("test.txt", "r"); if (fp == NULL) {puts("文件打开失败!");exit(0); } fseek(fp, 16, SEEK_SET); char c = fgetc(fp); printf("字符: %d", c); fclose(fp);
-
有结构文件
-
顺序文件
typedef struct {int number;char name[30];char major[30]; } Student;// 写入 FILE *fp = fopen("students.txt", "w"); if (fp == NULL) {printf("文件打开失败!");exit(0); } Student student[N]; for (int i = 0; i < N; i++) {student[i].number = i;student[i].name[0] = '?';student[i].major[0] = '?'; }fwrite(student, sizeof(Student), N, fp); fclose(fp);
// 读取 FILE *fp = fopen("students.txt", "r"); if (fp == NULL) {printf("文件打开失败!");exit(0); } fseek(fp, 5 * sizeof(Student), SEEK_SET); Student stu; fread(&stu, sizeof(Student), 1, fp); printf("学生编号: %d", stu.number); fclose(fp);
- 顺序存储
- 链式存储
-
索引文件
-
索引顺序文件
-
-
-
物理结构: 从操作系统看,由操作系统决定
// 在操作系统看来是一堆二进制数据
- 连续分配
- 链接分配
- 索引分配