file-systems.pdf - File Systems INF 551 Wensheng Wu 1 Roadmap Files and directories CRUD operations How to implement them Data structures Access methods

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

This preview shows page 1 - 17 out of 59 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.
Image of page 16
Image of page 17

You've reached the end of your free preview.

Want to read all 59 pages?

  • Fall '14

  • 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