For this part of this , you will write a C program that will display the inode meta data for each file given on the command line. You call your source file mystat.c and your program will be called mystat. This program will run directly on os2, not within xv6.
An example of how my program displays the inode data is shown the Figure 4. You might also want to look at the output from the stat command (the command not a system function, man section 1). Though not as pretty (or in some cases as complete as the replacement you will write), it is the standard for showing inode information.
Requirements for your program are:
1. The output of your program should look exactly like mine.
2. Display the file type (regular, directory, symbolic link, …) as a human readable string. If the file is a symbolic link, look 1 step further to find the name of the file to which the symbolic link points.
If the file to which the link points does not exist, indicate that. See Figure 4.
3. Display the inode value.
4. Display the device id.
5. Display the mode as both its octal value and its symbolic representation. The symbolic representation will be the rwx string for user, group, and other. See Figure 4 or ‘ls -l’ for how this should look.
6. Show the hard link count.
7. Show both the uid and gid for the file, as both the symbolic values (names) and numeric values. This will be pretty darn easy if you read through the list of suggested function calls. See Figure 4 for how this should look.
8. File size, in bytes.
9. Block count.
10. Show the 3 time values in local time/date. This will be pretty darn easy if you read through the list of suggested function calls. See Figure 4 for how these appear.
Figure 1: A sample of files to use for your testing. Found in ~chaneyr/Classes/cs444/Labs/Lab3
System and function calls that I believe you will find interesting include: stat()and lstat() (you really want to do “man 2 stat” and read that man entry closely, all of it [yes really, all of it]), readlink(), memset(), getpwuid(), getgrgid(), strcat(), localtime(), and
strftime(). Notice that ctime() is NOT in that list and you don’t want to use it. Since you must be able to show the file type if a file is a symbolic link, I encourage you consider lstat() over stat().
My implementation is about 280 lines long, but there is some dead code in my file. I have code commented out to support features not required for your assignment. There is no complex logic for this application, just a lot of long code showing values from the struct stat structure from sys/stat.h. Honestly, the longest portion of your code will likely be devoted to displaying the symbolic representation of the mode. Formatting these strings is a little awkweird. I suggest you create a function. Don’t worry about sticky bits or set uid/gid bits. Do you know what sticky bits are for or how they used to be used?
You must to be able to show the following file types:
• regular file,
• directory,
• character device,
• block device,
• FIFO/pipe,
• socket, and
• symbolic link (both a good one and a broken one).
When formatting the human readable time for the local time, I’d suggest you consider this "%Y-%m-%d
%H:%M:%S %z (%Z) %a", but read through the format options on strftime(). The executable version of my code is in the directory. You are welcome to run it to see the output.
I have some examples of both a FIFO/pipe, a socket, symbolic link in my Lab3 directory for you to use in testing (the FUNNY* files, Figure 2). You can
find a block device as
/dev/sda and a character device as Figure 3: Block and character files.
/dev/sg0. See Figure 3.
You must have a Makefile that builds the mystat program, without any warnings from the compiler. You must use the following gcc command line options (with gcc as your compiler) in your Makefile when compiling your code: