文件 文件的使用 3两类接口: ■操作或控制台命令,如DOS命令:dir,cd等 ■系统调用(AP),如open, write等,功能包括: 建立文件 〔打开文件 3读/写文件 〔%文件控制 关闭文件 〔%撤消文件
文件 文件的使用 两类接口: 操作或控制台命令,如DOS命令:dir,cd等 系统调用(API),如open,write等,功能包括: 建立文件 打开文件 读/写文件 文件控制 关闭文件 撤消文件 …
文件系统系统调用实例(1) /* File copy program. Error checking and reporting is minimal. * #include <sys/types. h> /* include necessary header files * #include <fcntl. h> #include <stdlib. h> #include <unistd. h> int main(int argc, char *argu); /★ANS| prototype* #define BUF SIZE 4096 /* use a buffer size of 4096 bytes *y #define OUTPUT MODE 0700 / protection bits for output file int main(int argc, char *argil int in fd. out fd. rd count wt count char buffer[BUFS忆zE; (argc != 3)exit(1) / syntax error if argc is not 3 */ /* Open the input file and create the output file *y in_fd= open(argv[1],O_RDONLY open the source file * if (in_fd <O)exit(2); /* if it cannot be opened exit * out_ fd= creat(argv[2], OUTPUT MODE);/* create the destination file * if (out fd <O)exit(3); /* if it cannot be created. exit *
. . . 文件系统系统调用实例(1)
文件系统系统调用实例(2 / Copy loop * while(TRUe rd_count= read(in_fd, buffer, BUFSIZE); / read a block of data * if (rd_count <=O)break; /* if end of file or error, exit loop * wt_count= write(out_fd, buffer, rd_count); / write data * if (wt_count <=O)exit(4); /* wt_ count <=0 is an error / Close the files * close(in_fd) close(outfd) if (rd_count==O) / no error on last read * exit(O) Ise exit(5); / error on last read *
文件系统系统调用实例(2)
文件目录 ■什么是文件目录? %是文件系统建立和维护的关于系统的所有文件的清单, 每个目录项对应一个文件的信息描述,该目录项又称 为文件控制块(FCB) 3目录信息也以文件的形式存放,称为且录文件 ■文件控制块的基本内容: 3文件存取控制信息,如文件名、用户名、文件主存取 权限等 〔悠文件结构信息,文件逻辑结构、文件的物理结构等 文件使用信息,已打开该文件的进程数、文件的修改 情况等 〔文件管理信息,文件建立日期、文件访问日期等
文件目录 什么是文件目录? 是文件系统建立和维护的关于系统的所有文件的清单, 每个目录项对应一个文件的信息描述,该目录项又称 为文件控制块(FCB)。 目录信息也以文件的形式存放,称为目录文件。 文件控制块的基本内容: 文件存取控制信息,如文件名、用户名、文件主存取 权限等 文件结构信息,文件逻辑结构、文件的物理结构等 文件使用信息,已打开该文件的进程数、文件的修改 情况等 文件管理信息,文件建立日期、文件访问日期等
文件目录 如何实现“按名存取 当用户要求存取某个文件时,系统査找目录文 件,获得对应的文件目录 3在文件目录中,根据用户给定的文件名寻找到 对应该文件的文件控制块(文件目录项 3通过文件控制块所记录的该文件的相关信息 (如文件信息存放的相对位置或文件信息首块 的物理位置)依次存取该文件的内容
文件目录 如何实现“按名存取”? 当用户要求存取某个文件时,系统查找目录文 件,获得对应的文件目录。 在文件目录中,根据用户给定的文件名寻找到 对应该文件的文件控制块(文件目录项) 通过文件控制块所记录的该文件的相关信息 (如文件信息存放的相对位置或文件信息首块 的物理位置)依次存取该文件的内容