Allows the operating system to do book keeping and provides a convenient to use

Allows the operating system to do book keeping and

This preview shows page 15 - 25 out of 70 pages.

Allows the operating system to do book-keeping and provides a convenient to use “handle” called a file descriptor Eg. in C: fd = open(“foo”); Open can take options, for example to create the file if it doesn’t exist, to open read only, or to zero it out (truncate), or append mode Must “close” file when you are done with it
Image of page 15
Reading and Writing File descriptor used for subsequent read and write operations read(fd, 25), write(fd,”this is some good text”) Read and write operations are “statefull” in that they read/write at the position last read/written to Random reads/writes require that to say where in the file you want the operation to take place, using a “seek” operation lseek(fd,36); write(fd,”this is 36 bytes into the file”);
Image of page 16
File and directory When creating a file Bookkeeping data structure created (inode): recording size of file, location of its blocks, etc. Linking a human-readable name to the file Putting the link in a directory 17
Image of page 17
Info about file (stored in inode) struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; /* number of hard links */ uid_t st_uid; /* user ID of owner */ gid_t st_gid; /* group ID of owner */ dev_t st_rdev; /* device ID (if special file) */ off_t st_size; /* total size, in bytes */ blksize_t st_blksize; /* blocksize for filesystem I/O */ blkcnt_t st_blocks; /* number of blocks allocated */ time_t st_atime; /* time of last access */ time_t st_mtime; /* time of last modification */ time_t st_ctime; /* time of last change to inode, e.g., permission */ }; 18
Image of page 18
Stat example a.txt abc def abc def abc def 19 Block size # of allocated blocks Id of device Inode # User id Group id # of hard links Access permission
Image of page 19
Hard link example ln a.txt b.txt b.txt is a hard link 20 # of hard links Increased to 2 Same inode
Image of page 20
Hard links and limitations Hard link Create another name for the same file in the directory of the file the name is supposed to link to New name points to the same inode No copying of data involved Limitations Cannot create link to a directory: avoid cycles in directory tree Can not link to files on another partition (inode unique only in the same partition) 21
Image of page 21
Example Entries in directory inf551 (itself stored as a file) 22 Inumber Name Type 410837 a.txt regular file 410837 b.txt regular file
Image of page 22
Delete Unlink() Executed when you issue unlink/rm, in Unix E.g., "unlink b.txt" (or "rm b.txt") Link count in the inode for the file will decrement by 1 23 struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; /* number of hard links */
Image of page 23
Files have… A name, which is a human readable form File names live in directories The directory is not part of the name!!
Image of page 24
Image of page 25

You've reached the end of your free preview.

Want to read all 70 pages?

  • Spring '18

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes