1 / 18

Files

Files. System Calls for File System. Accessing files Open, read, write, lseek, close Creating files Create, mknod. System Calls for File System. Manipulation & Navigation Chdir, chroot, chown, chmod, stat, fstat Special file and operations Pipes, dup

howardp
Download Presentation

Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Files

  2. System Calls for File System • Accessing files • Open, read, write, lseek, close • Creating files • Create, mknod

  3. System Calls for File System • Manipulation & Navigation • Chdir, chroot, chown, chmod, stat, fstat • Special file and operations • Pipes, dup • Extending and changing the file system • Mount, umount, link and unlink

  4. Open • Opens a file located on the file system by returning an integer – file descriptor (fd) • Other system calls then use the fd to carry out operations on the opened file • Read, write, lseek, etc. • Fd = open(char, flags, mode)

  5. Open • Input to the open system call is • Pathname – char string • Open flags – integer value • Mode – integer value • Kernel converts the char file name into an inode

  6. Open • Allocates an entry in file table • File table entry has a pointer to the inode and field that indicates the byte offset • Byte offset is typically set to Zero, the beginning of the file, but can be set to the end of the file.

  7. Open Algorithm

  8. Data Structures After Open

  9. Data Structure After 2 Processes

  10. Notes about Open System Call • Each open system call • Returns a single user file descriptor • Points to a unique file table index • Inode table entry can have multiple links

  11. Reading and Writing • Once a file is opened • We can then operate on it via the file descriptor (i.e. fd) • Open system call syntax • open(fd, buffer, count) • fd – file descriptor • buffer – place to store read data • count – number of bytes to read

  12. Read and U Area • Sets I/O parameters namely • Mode (Read or Write) • Count field • Target address for user data buffer • Byte offset in file where I/O should begin • Address Flag (User or Kernel)

  13. Read Example

  14. Writing • Similar to read • Except • Allocate new data blocks • Allocate new indirect blocks • Updates inode for file. • What does datum does it update in inode? • Disk Block, indirect block, file size, modification time, etc,

  15. Write System Call • Syntax of write system call • write(fd, buffer, modes); • fd is file descriptor • buffer is memory where data to write is found • Count is number of bytes to write

  16. Writing Notes • Data is written in at most one block size • Write system call may have to read a block before it writes • Inode for file is locked until write() is completed • Allocation of new blocks • Modifies inode

  17. Pipes • Allows the exchange of data between processes • Data exchange is in a FIFO manner • Can be used to synchronize process executions

  18. Pipes • Two classes of pipes • Named pipes • Use open • Unnamed pipes • Use pipe system call • Use traditional

More Related