DUE: Friday, 12/13/2019

In this lab we are going to work with the Posix file interface

Where to start? Have a look at OSTEP, Ch. 39, especially 39.8 and 39.11. Read manual pages for stat(2), opendir(3), readdir(2), and scandir(3).

NOTE: As always, it's optional, but strongly encouraged, to make your program verbose so that it's printing what it's doing - be thorough. Also, use "valgrind" to help you find bugs, especially memory leaks! You should aim to have no reported leaks at all.

  1. Begin by running /bin/ls -ai1 [thing] on several things, both files and directories. Find some symbolic links and run it on those. Then do the same with /bin/ls -ail1 [thing] and figure out what all the columns mean.
  2. Implement a version of your program that takes one argument and duplicates the output of /bin/ls -ai1 [thing] if thing is just a file. Note that this means finding the inode number of the file. Use lstat(2) to do this so that you are getting information about symbolic links themselves. As a general rule, if you find a type that is probably really a number, it's probably safe to just cast it to int.
  3. Implement a version of your program that can also handle directories as the argument, again duplicating the output of /bin/ls -ai1 [thing] . There's some sample code in the man page of scandir(3) that could be very helpful here - you may just borrow it with attribution in a comment.
  4. Implement a version of your program that duplicates the output of /bin/ls -ail1 [thing] on regular files and symbolic links. Don't fuss too much about getting the date formatted correctly, but you might want to look at man pages for strftime and localtime. If you want to see how complex handling time is, man 7 time and settle in for a long read :-).
  5. Finally, implement a version of your program that can duplicate the output of of /bin/ls -ail1 [thing] on directories. Getting the output correct for symbolic links is optional here, but would be quite impressive.
  6. Optionally, implement a version of your program that can duplicate the output of of /bin/ls -Rail1 [thing] on directories. Good luck!