Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment 4: Files in UNIX Objective: The objective of this assignment is to understand the UNIX file systenm in general, and the structure of i-node
Assignment 4: Files in UNIX Objective: The objective of this assignment is to understand the UNIX file systenm in general, and the structure of i-node and the stat system call in particular. You will also have an opportunity to use system calls that deal with directories such as opendir, closedir and readdir Problem You will write a program that simulates the behaviour of the UNIX command "ls -1". This UNIX command basically gives a long listing of the files in a specific directory. It will produce one line of output for each file/directory in the directory. This line will tell you the permissions that user, group and others have to read, write and execute the file, the number of hardlinks to the file, the login name of the owner, the group name to which the file belongs, the number of characters in the file, the last time the file's contents were modified and last but not least, the name of the file/directory. For example, some typical lines are shown below drwxr-xr1 gopal ff -rw-r 7783 Feb 19 09:57 junk 18806 Feb 2 1998 zero.tex r-r1 gopal staff In UNIX systems, a directory is basically a file consisting of several lines, one per each file/directory present there. The information in there would simply be the name of the file/directory and its inode number. You can get additional information about the file from the actual inode. Fortunately, there is a system call by name stat that will do this job. So, basically you have to open the specified directory using the opendir system call, read the entries in it one by one using the readdir system call, get additional information about each entry using the stat system call, format and print a line of output for each entry and finally close the directory specified using the closedir system call. You can obtain almost all the information you need from the man pages for the system calls opendir, readdir, closedir and stat. The main structure one has to be concerned with when getting information about files is struct stat. struct stat is defined in the header file stat.h. You can get a pointer to stat structure by making the system call stat (there are two other variations of the stat system call lstat and fstat, but the one we will use is stat. You can check out the others also using the man pages). Also, the library function ctime will come in handy to convert Assignment 4: Files in UNIX Objective: The objective of this assignment is to understand the UNIX file systenm in general, and the structure of i-node and the stat system call in particular. You will also have an opportunity to use system calls that deal with directories such as opendir, closedir and readdir Problem You will write a program that simulates the behaviour of the UNIX command "ls -1". This UNIX command basically gives a long listing of the files in a specific directory. It will produce one line of output for each file/directory in the directory. This line will tell you the permissions that user, group and others have to read, write and execute the file, the number of hardlinks to the file, the login name of the owner, the group name to which the file belongs, the number of characters in the file, the last time the file's contents were modified and last but not least, the name of the file/directory. For example, some typical lines are shown below drwxr-xr1 gopal ff -rw-r 7783 Feb 19 09:57 junk 18806 Feb 2 1998 zero.tex r-r1 gopal staff In UNIX systems, a directory is basically a file consisting of several lines, one per each file/directory present there. The information in there would simply be the name of the file/directory and its inode number. You can get additional information about the file from the actual inode. Fortunately, there is a system call by name stat that will do this job. So, basically you have to open the specified directory using the opendir system call, read the entries in it one by one using the readdir system call, get additional information about each entry using the stat system call, format and print a line of output for each entry and finally close the directory specified using the closedir system call. You can obtain almost all the information you need from the man pages for the system calls opendir, readdir, closedir and stat. The main structure one has to be concerned with when getting information about files is struct stat. struct stat is defined in the header file stat.h. You can get a pointer to stat structure by making the system call stat (there are two other variations of the stat system call lstat and fstat, but the one we will use is stat. You can check out the others also using the man pages). Also, the library function ctime will come in handy to convert
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started