SEM/ YEAR : VI / III CS2028 UNIX INTERNALS UNIT III – System Calls for File System PART A 1. Write the syntax of read system call? Number = read(fd, buffer, count) Where fd is file descriptor, buffer is the address of data structure, count is the number of bytes that the user wants to read. 2. What are the inputs of read algorithm? User file descriptor Address of buffer in user process Number of bytes to read 3. What are the I/O parameters saved in U area? Mode Count Offset Address Flag 4. Write the syntax for write system call? Number = write(fd, buffer, count) Where fd is file descriptor, buffer is the address of data structure, count is the number of bytes that the user wants to read. 5. Write the syntax for lseek algorithm? Position = lseek(fd, offset, reference); 6. Write the syntax for file creation? Fd = create(pathname, modes); 7. What are the inputs for making the new node? Node File type Permissions Major, minor device number NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE,TRICHY-621214 8. Write the syntax for change owner and change mode? MAY JUNE 2013 Chown(pathname, owner, group); Chmod(pathname, mode); 9. What are the types of pipe? Named pipe Unnamed pipe 10. Write the syntax for mounting a file system? Mount(special pathname, directory pathname, options); Where special pathname is the name of device, directory path name is the directory in the existing hierarchy. 11. What are the fields in mount table entry? A device number A pointer to a buffer A pointer to the inode A pointer to root inode 12. What are the inputs of mount algorithm? File name of block special file Directory name of mount point Options(read only) 13. Write syntax for pipe system call? Pipe(fdptr) Where fdptr is the pointer to an integer array. 14. What’s the use of dup system call? The dup system call copies a file descriptor in to the first slot of the user file descriptor table. NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE,TRICHY-621214 15. Write the syntax for dup system call? MAY JUNE 2013 newfd = dup(fd) CS605 16. What is the use of fiag register? The flag register indicates if address is in user or kernel memory. 17. What are the flags present in open system call? O_CREAT O_TRUNC 18. What the use of algorithm chdir? The algorithm chdir changes the current directory of a process. The syntax is Chdir(pathname); 19. Write the syntax for STAT and FSTAT? Stat(pathname, statbuffer); Fstat(fd, statbuffer); 20. What are the inputs of link algorithm? Existing file name New file name 21.Write the syntax of mount and dismount system calls. April may 2008 The syntax for the mount system call is: mount (special pathname, directory pathname, options); where special Pathname is the name of the device special file of the disk section containing the file system to be mounted, directory Pathname is the directory in the existing hierarchy where the filesystem will be mounted (called the mount point), options indicate whether the file system should be mounted “read only”(system calls such as Write and create that write the file system will fail) NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE,TRICHY-621214 22.Give the functionality of iseek(). APRIL MAY 2008 he lseek() function allows the file offset to be set beyond the end of the file (but this does not change the size of the file). If data is later written at this point, subsequent reads of the data in the gap (a "hole") return null bytes (’\0’) until data is actually written into the gap. PART B 1. Explain details about the System Calls for the File System NOV DEC 2007 System calls for accessing existing files, such as open, read, write, lseek, and close. System calls to create new files, creat and mknod. System calls that manipulate the inode or that maneuver through the file system: chdir, chroot, chown, chmod, stat, and fstat. Advanced system calls: pipe and dup for the imple mentation of pipes in the shell; o Mount and umount extend the file system tree visible to users; o Link and unlink change the structure of the file system hierarchy. Three kernel data structures: o File table; with one entry allocated for every opened file in the system. o User file descriptor table; with one entry allocated for every file descriptor known to a process. o Mount table; containing information for every active file system. Relationship between system calls and the algorithms: o It classifies the system calls into several categories, although some system calls appear in more than one category: o System calls that return file descriptor for use in other system calls; o System calls that use the namei algorithm to parse a path name; o System calls that set or change the attribute of a file; o System calls that assign and free inodes, using algorithms ialloc and ifree; o System calls that do I/O to and from a process , using algorithms alloc, free, and the buffer allocation algorithms; o System calls that change the structure of the file system; o System calls that allows a process to change its view of the file system tree. 2. Write short notes on Open APRIL MAY 2008 Open The open system call is the first step a process must take access the data in a file. The syntax for the open system call is: NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE,TRICHY-621214 fd = open(pathname, flags, modes); where pathname is a filename, flags indicate the type of open (such as, reading or writing), and modes give the file permissions if the file is being created. The open system call returns an integer, called the user file descriptor. open() system call return the value -1, if they fail. The other file operations, such reading, writing, seeking, duplicating the file descriptor, setting file I/O parameters, determining file status, and closing the file, use the file descriptor that the open system call returns. Explanation of the algorithm for opening a file (fig 3.2) o The kernel searches the file systems for the filename parameter using algorithm namei. o It checks permissions for opening the file after it finds the in-core inode and allocates an entry in the file table for the open file. File table entry contains a pointer to the inode of the open file and a field that indicates the byte offset in the file where the kernel excepts the next read or write to begin. o The kernel initializes the offset to 0 during the open call, meaning that the initial read or write starts at the beginning of a file by default. o Alternatively, a process can open a file in write-append mode, in which case the kernel initializes the offset to the size of the file. o The kernel allocates an entry in a private table in the process u area, called the user file descriptor table, and notes the index of this entry. The index is the file descriptor that is returned to the user. o The entry in the user file table points to the entry in the global file table. Suppose a process executes the following code, opening the file “/etc/passwd” twice, once read-only and once write-only, and the file “local” once for reading and writing. fd1 = open(“/etc/passwd”, O_RDONLY); . fd2 = open(“local”, O_RDWR); . fd3 = open(“etc/passwd”, O_WRONLY); NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE,TRICHY-621214 Fig 3.3 shows the relationship between the inode table, file table, and user file descriptor table data structures. Each open return a file descriptor to the process and the corresponding entry in the user file descriptor table points to a unique entry in the kernel file table even though one file (“/etc/passwd”) is opened twice. The file table entries of all instances of an open file point to one entry in the in-core inode table. The process can read or write the file “/etc/passwd” but only through the file descriptors 3 and 5 (fig 3.3) The kernel notes the capability to read or write the file in the file table entry allocated during the open call. Suppose a second process executes the following code: o fd1 = open(“/etc/passwd”, O_RDONLY); o fd2 = open(“private”, O_RDONLY); NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE,TRICHY-621214 Fig 3.4 shows the relationship between the appropriate data structures while both processes have the files open. Again, each open call results in allocation of a unique entry in the user file descriptor table and in the kernel file table, but the kernel contains at most one entry per file in the in-core inode table. The user file descriptor table entry could conceivably contain the file offset for the position of the next I/O operation and point directly to the in-core inode entry for the file, eliminating the need for separate kernel file table. The examples above show, a one-to-one relationship between users file descriptor entries and kernel file table entries. Thompson notes, the file table implementation as a separate structure to allow sharing of the offset pointer between several users file descriptors. o The dup and fork system calls, manipulate the data structures to allow such sharing. The first three user file descriptors (0, 1, & 2) are called the standard input, standard output, and standard error file descriptors. 3. Write short notes on write Read APRIL MAY 2008 Read The syntax of the read system call is number = read(fd, buffer, count); where fd is the file descriptor returned by open, buffer is the address of a data structure in the user process that will contain the read data on successful completion of the call, count is the number of bytes actually read.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages35 Page
-
File Size-