典型的文件扩展名 Extension Meaning file bak Backup file file. c C source program file. gif Compuserve Graphical Interchange Format image file. hl Help file file. html World Wide Web Hyper Text Markup Language document file. jpg Still picture encoded with the JPEG standard file. mp3 Music encoded in MPEG layer 3 audio format file. mpg g Movie encoded with the MPEG standard file. o Object file(compiler output, not yet linked file. pdf Portable document format file file.ps Postscript file file. tex Input for the TEX formatting program file. txt General text file file. zip Compressed archive 2002-7-5 东北大学软件所于戈 第五章分布式文件管理
2002-7-5 东北大学软件所 于戈 第五章 分布式文件管理 6 典型的文件扩展名
文件的属性 Attribute Meaning ProtectionWho can access the file and in what way Password Password needed to access the file Creator ID of the person who created the file Owner Current owner Read-only flag o for read/write; 1 for read only idden fla o for normal; 1 for do not display in listings System flag O for normal files: 1 for system file Archive fl nlag 0 for has been backed up: 1 for needs to be backed up ASCI/binary flag o for ASCll file; 1 for binary file Random access flag 0 for sequential access only; 1 for random access Temporary flag o for normal; 1 for delete file on process exit Lock flags I O for unlocked; nonzero for locked Record length Number of bytes in a record Key position Offset of the key within each record Key length Number of bytes in the key field Creation time Date and time the file was created Time of last access Date and time the file was last accessed Time of last change Date and time the file has last changed Current size Number of bytes in the file Maximum size Number of bytes the file may grow to 2002-7-5 第五章分布式文件管理 7 东北大学软件所于戈
2002-7-5 东北大学软件所 于戈 第五章 分布式文件管理 7 文件的属性
文件基本操作 1. Create 7. Append 2. Delete 8 Seek 3. Open 9. Get attributes 4. Close 10. Set Attributes e 5. Read 11.Rename 6. Write 2002-7-5 东北大学软件所于戈 第五章分布式文件管理
2002-7-5 东北大学软件所 于戈 第五章 分布式文件管理 8 文件基本操作 1. Create 2. Delete 3. Open 4. Close 5. Read 6. Write 7. Append 8. Seek 9. Get attributes 10.Set Attributes 11.Rename
文件操作举例 /* 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 *argv D) /* ANSI prototype刘 #define BUF SIZE 4096 / use a buffer size of 4096 bytes #define OUTPUT MODE 0700 / protection bits for output file * e int main(int argc, char *argvD) int in fd. out fd. rd count wt count: char buffer[BUF SIZE if (argc I= 3)exit(1); / syntax error if argc is not 3 2002-7-5 第五章分布式文件管理 9 东北大学软件所于戈
2002-7-5 东北大学软件所 于戈 第五章 分布式文件管理 9 文件操作举例
文件操作举例 / Open the input file and create the output file * in_ fd= open(argv[1],ORDONLY): / open the source file * if (in_fd 0)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 * / Copy loop * while(TRUE)I rd- count= read(in_fd, buffer, BUF SIZE); * read a block of data * if (rd_count <= 0)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(out fd); if(rd_count = 0) /* no error on last read exit(O) else 2002 exit(5 / error on last read * 10 东北
2002-7-5 东北大学软件所 于戈 第五章 分布式文件管理 10 文件操作举例