tailieunhanh - UNIX Filesystems Evolution Design and Implementation PHẦN 2

Trong ví dụ này, sau khi gọi close (), tập tin có kích thước 2048 byte. Các dữ liệu ghi vào tập tin được lưu trữ trong hai khối 1k. Bây giờ, xem xét ví dụ dưới đây: người sử dụng tạo ra () lseek để 1k viết (1k 'B) gần () hệ thống tập tin Tạo một tập tin mới Không có hiệu lực vào tập tin Phân bổ một khối mới 1k phạm vi 1024-2047 byte Đóng tập tin | File-Based Concepts 21 - - regular file d - directory s - symbolic link p - named pipe c - character special b - block special I---- link count -rw-r--r- 1 spate fcf L-T- user oL user group user group and other permissions file name file size 137564 Feb 13 09 05 date of last modification Figure File properties shown by typing ls -l Thus the caller specifies the pathname of a file for which properties are to be read and gets all of this information passed back in a stat structure defined as follows struct stat dev_t ino_t mode_t nlink_t uid_t gid_t dev_t off_t time_t time_t time_t long blkcnt_t st_dev st_ino st_mode st_nlink st_uid st_gid st_rdev st_size st_atime st_mtime st_ctime st_blksize st_blocks ID of device containing file Inode number file serial number File mode Number of links to file User ID of file Group ID of file Device ID for char blk special file File size in bytes regular file Time of last access Time of last data modification Time of last status change Preferred I O block size Number of 512 byte blocks allocated Given this information it is relatively easy to map the fields shown here to the information displayed by the ls command. To help show how this works an abbreviated version of the ls command is shown below. Note that this is not complete nor is it the best way to implement the command. It does however show how to obtain information about individual files. 1 include 2 include 3 include 4 include 5 include 6 include 7 include 8 include 9 include sys sys sys sys 22 UNIX Filesystems Evolution Design and Implementation 10 11 define BUFSZ 1024 12 13 main 14 15 struct dirent dir 16 struct stat st 17 struct passwd pw 18 struct group grp 19 char buf BUFSZ bp ftime 20 int dfd fd nread 21 22 dfd open . O_RDONLY 23 bzero buf BUFSZ 24 while nread getdents dfd struct dirent buf 25 BUFSZ 0 26 bp buf 27 dir struct dirent buf 28 do 29 if dir- d_reclen 0 30 stat dir- d_name

TỪ KHÓA LIÊN QUAN