Week 5 - File Systems - File Systems INF 551 Wensheng Wu 1 Roadmap Files and directories CRUD operations How to implement them Data structures Access

Week 5 - File Systems - File Systems INF 551 Wensheng Wu 1...

This preview shows page 1 - 18 out of 67 pages.

File Systems INF 551 Wensheng Wu 1
Image of page 1
Roadmap Files and directories CRUD operations How to implement them Data structures Access methods 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 a call to system function 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
File descriptor Note open() return file descriptor Typically an integer Reserved fds: stdin 0, stdout, 1, stderr 2 7
Image of page 7
Read read(fd, buffer, size) Read from file “fd” < size> number of bytes And store them in buffer Read starts from the current offset of fd Initially at 0 8
Image of page 8
Write write(fd, buffer, size) Write to file fd < size> number of bytes stored in buffer Also start from the current offset 9
Image of page 9
Random read and write off_t lseek(int fd, off_t offset, int whence) If whence is SEEK_SET, the offset is set to offset bytes from the beginning of file 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 (often offset is negative, e.g., -8 for 8 bytes from the end) whence: from where 10
Image of page 10
11 Copy a file rw-r--r– => 110 (user permission) 100 (group) 100 (others)
Image of page 11
File permission mode 12 rw-r--r– => 110 (user permission) 100 (group) 100 (others)
Image of page 12
Resources for system calls open: (system_call ) read: (system_call) write: (system_call ) close: (system_call) 13
Image of page 13
Resources for system calls man –S 2 read Find it in the Section 2 of the manual 14
Image of page 14
Install gcc on EC2 sudo yum groupinstall "Development Tools" Will install other dev. tools too E.g., perl, bison, flex, automake, autoconf Usage: gcc -o copy2 copy2.c 15
Image of page 15
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 16
Image of page 16
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 */ };
Image of page 17
Image of page 18

You've reached the end of your free preview.

Want to read all 67 pages?

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

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