file-systems.pdf - File Systems INF 551 Wensheng Wu 1 Roadmap \u2022 Files and directories \u2013 CRUD operations \u2022 How to implement them \u2013 Data

file-systems.pdf - File Systems INF 551 Wensheng Wu 1...

This preview shows page 1 - 18 out of 72 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: stored in blocks on storage device Has user defined name: hello.txt & low-level name, e.g., inode number: 410689 Files are organized into directories (folders) each may have a list of files and/or subdirectories That is, directories can be nested 3
Image of page 3
Example 4 Root directory Empty directory
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 |: Bitwise OR operator
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 0 8
Image of page 8
Write write(fd, buffer, size) Write to file fd < size> number of bytes stored in buffer Also start writing 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 "0" starts an octal number => permissions: 110 (owner) rw- 100 (group) r-- 100 (others) r-- Pointer to a character array
Image of page 11
File permission mode 12 rw-r--r– => 110 (owner 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 (inode) created: 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 */
Image of page 17
Image of page 18

You've reached the end of your free preview.

Want to read all 72 pages?

  • Fall '14
  • inumber

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