Operating Systems Design 19CS2106R Session-10 Lecture Notes File System Calls
Operating Systems Design 19CS2106R Session-10 Lecture Notes File System Calls
19CS2106R
Session-10
Lecture Notes
File System Calls
Learning Outcomes
Concept of Pipes
• Pipes are the IPC mechanism used for communicating between two or more process in
Linux i.e to pipe the data between TWO processes.
• Their implementation allows processes to communicate even though they do not know
what processes are on the other end of the pipe.
• The command line programs that do the further processing are referred to as filters.
General Syntax:
• Eg : Listing all files and directories and give it as input to more command.
$ ls -l | more .
Here two commands namely, ls-l and more are piped. ls command lists and more command
displays the content one page at a time.
The more command takes the output of $ ls -l as its input. The net effect of this command is
that the output of ls -l is displayed one screen at a time. The pipe acts as a container which takes
the output of ls -l and gives it to more as input.
Unnamed Pipes
• They are created programmatically using the command mkfifo or will be created using
mknod() system call..
pipe (fdptr) ;
where fdptr is the pointer to an integer array that will contain the two file descriptors for
reading and writing the pipe.
• The dup system call copies a file descriptor into the first free slot of the user file
descriptor table, returning the new file descriptor to the user.
where fd is the file descriptor being duped and newfd is the new file descriptor that
references the file.
Because dup duplicates the file descriptor, it increments the count of the corresponding
file table entry, which now has one more file descriptor entry that points to it.
• The link system call links a file to a new name in the file system directory structure,
creating a new directory entry for an existing mode.
where source file name is the name of an existing file and target .file name is the new
(additional) name the file will have after completion of the link call
• Algorithm link
• output: none
• {
• get inode for existing file name (algorithm namei);
• if (too many links on file or linking directory without super user permission)
• {
• return (error);
• }
• unlock inode;
• get parent inode for directory to contain new file name (algorithm namei);
• {
• return (error); }
• Xv6 Case Study : sys_pipe, pipealloc, piperead, pipewrite, sys_dup, filedup, sys_link
and sys_unlink.
unlink (pathname) ;
where pathname identifies the name of the file to be unlinked from the directory hierarchy.
• If a process unlinks a given file, no file is accessible by that name until another directory
entry with that name is created.
https://github.com/mit-pdos/xv6-public/blob/master/sysfile.c
sys-pipe
sys_chdir
Sys_open
• Conduction of ALMs in Breakout Session
ALM-1
• Understand the internal algorithms behind the design of various xv6 file system calls.
• Customize the usertests.c given in xv6 source code base and execute.
ALM-1
ALM-2
For process A, show the relationship between the inode table, file table, and user file
descriptor data structures.
Draw the resulting picture that shows the relationship between the appropriate data
structures while both processes (and no others) have the files open.
ALM-3
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
if (fd > 2)
close(fd);
To see why the if test is needed, assume that fd is 1 and draw a picture of what happens to
the three descriptor entries and the corresponding file table entry with each call to dup2.
Then assume that fd is 3 and draw the same picture.
ALM-4
• Write a program that create two pipes, send filename from command line to child
process. In child read that file and send it back using pipe. Parent process should print
the file. if error occur in child process error must be send to parent process