200 likes | 231 Views
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
E N D
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 • Extending and changing the file system • Mount, umount, link and unlink
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)
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
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.
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
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
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)
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,
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
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
Pipes • Allows the exchange of data between processes • Data exchange is in a FIFO manner • Can be used to synchronize process executions
Pipes • Two classes of pipes • Named pipes • Use open • Unnamed pipes • Use pipe system call • Use traditional