6file-system-wf(1) - FileSystems INF551 Wed\/Frisection 1 Roadmap Filesanddirectories CRUDoperations Howtoimplementthem Datastructures Accessmethods \/Os

6file-system-wf(1) - FileSystems INF551 Wed/Frisection 1...

This preview shows page 1 - 15 out of 53 pages.

File Systems INF 551 Wed/Fri section 1
Image of page 1
Roadmap Files and directories CRUD operations How to implement them Data structures Access methods Log structured file system Optimize for modern write heavy I/O’s 2
Image of page 2
Files and Directories File: a linear array of bytes User defined name: hw1.doc Low level name, e.g., inode number: 1344513 Files are organized into directories (folders) each contains a list of files and/or subdirectories That is, directories can be nested 3
Image of page 3
Example 4
Image of page 4
Operations on Files Create Read Update Delete 5
Image of page 5
Create User interface, e.g., via GUI Implementation, e.g., via a C program with function all to open() int fd = open("foo", O_CREAT | O_WRONLY | O_TRUNC); Open with flags indicating the specifics O_CREATE: create a file O_WRONLY: write only O_TRUNC: remove existing contents if exits 6
Image of page 6
Read Note open() return file descriptor Also called handle Typically an integer E.g., stdin 0, stdout, 1, stderr 2 Read(fd, buffer, size) Read from file “fd” size number of bytes and Store them in buffer 7
Image of page 7
Write Write(fd, buffer, size) Write to file fd size number of bytes in buffer 8
Image of page 8
Random Read and Write off_t lseek(int fildes, off_t offset, int whence); If whence is SEEK_SET, the offset is set to offset bytes. If whence is SEEK_CUR, the offset is set to its current location plus offset bytes. If whence is SEEK_END, the offset is set to the size of the file plus offset bytes. 9
Image of page 9
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 forfilesystem 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 status change */ }; 10
Image of page 10
Delete Unlink() Executed when you issue “rm foo” in Unix 11
Image of page 11
Work with Directories Create: mkdir() mkdir xyz Read: opendir(), readdir(), closedir() ls xyz Delete: rmdir() 12
Image of page 12
File and Directory When creating a file Bookkeeping data structure created (inode): size of file, location of its blocks Linking a human readable name to the file Putting the link in a directory 13
Image of page 13
Hard Link Example Hard link is another name for the same file # of links: 2 ln a.txt a1.txt 14
Image of page 14
Image of page 15

You've reached the end of your free preview.

Want to read all 53 pages?

  • 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