CS360 Lab #5 -- Jtar

  • Jim Plank
  • CS360

  • So, this is your first real systems program. You will be writing a pared-down version of tar(1). It will help you to read the man page for tar, and try using it a bit. Use ``tar cvf tarfile files'' to create a tar file, and ``tar xpfv tarfile'' to unpack a tar file. Jtar will work like ``tar cf - files'' and ``tar xpf -''.

    Description of jtar

    Your job is to write the program jtar. Like tar, jtar can be called in one of two ways:

    Examples

    Suppose we have an example user fred, and suppose he cd's to the directory /home/plank/cs360/labs/lab3, and does the following.
    UNIX> cd ~plank/cs360/labs/lab5/example-d1
    UNIX> ls -l
    total 76
    -rw-r--r-- 1 plank loci 22299 2010-02-12 15:08 lecture.html
    -rw-r--r-- 1 plank loci   737 2010-02-12 15:08 makefile
    -rwxr-xr-x 1 plank loci  8338 2010-02-12 15:09 o1
    -r--r--r-- 1 plank loci   461 2010-02-12 15:08 o1.c
    -rw-r--r-- 1 plank loci  3312 2010-02-12 15:09 o1.o
    -rw-r--r-- 1 plank loci   552 2010-02-12 15:08 o2.c
    -r--r--r-- 1 plank loci   803 2010-02-12 15:08 openunique_1.c
    -rw-r--r-- 1 plank loci  1076 2010-02-12 15:08 openunique_2.c
    -rw-r--r-- 1 plank loci   670 2010-02-12 15:08 openunique_3.c
    -rw-r--r-- 1 plank loci  1077 2010-02-12 15:08 openunique_4.c
    -r--r--r-- 1 plank loci   881 2010-02-12 15:08 um1.c
    -rw-r--r-- 1 plank loci   165 2010-02-12 15:08 um2.c
    UNIX> ~plank/cs360/labs/lab5/jtar c . > ~/tarfile
    UNIX> ls -l ~/tarfile
    -rw-r--r-- 1 plank loci 41692 2010-02-12 15:12 /home/plank/tarfile
    UNIX> 
    
    What he has done is create a tarfile which holds the stuff in my directory cs360/labs/lab5/example-d1. Now, he can recreate those files in a directory of his own:
    UNIX> pwd
    /home/fred
    UNIX> cd
    UNIX> mkdir tmpdir
    UNIX> cd tmpdir
    UNIX> ~plank/cs360/labs/lab5/jtar x < ../tarfile
    UNIX> ls -l
    total 76
    -rw-r--r-- 1 fred loci 22299 2010-02-12 15:08 lecture.html
    -rw-r--r-- 1 fred loci   737 2010-02-12 15:08 makefile
    -rwxr-xr-x 1 fred loci  8338 2010-02-12 15:09 o1
    -r--r--r-- 1 fred loci   461 2010-02-12 15:08 o1.c
    -rw-r--r-- 1 fred loci  3312 2010-02-12 15:09 o1.o
    -rw-r--r-- 1 fred loci   552 2010-02-12 15:08 o2.c
    -r--r--r-- 1 fred loci   803 2010-02-12 15:08 openunique_1.c
    -rw-r--r-- 1 fred loci  1076 2010-02-12 15:08 openunique_2.c
    -rw-r--r-- 1 fred loci   670 2010-02-12 15:08 openunique_3.c
    -rw-r--r-- 1 fred loci  1077 2010-02-12 15:08 openunique_4.c
    -r--r--r-- 1 fred loci   881 2010-02-12 15:08 um1.c
    -rw-r--r-- 1 fred loci   165 2010-02-12 15:08 um2.c
    UNIX> 
    
    All of the files are recreated with the same protection modes and the same modification times. They also have the same access times (as you would be able to see with ls -lu). Jtar also saves hard links and directories, as well as the contents of directories. However, jtar ignores soft links and all other non-regular files. Thus, for example, suppose that fred cd's to the directory /home/plank/cs360/labs/lab5/example-d2, and does the following:
    UNIX> cd /home/plank/cs360/labs/lab5/example-d2
    UNIX> ls -l
    total 12
    -rw-r--r-- 2 plank guest   11 1995-02-20 10:29 f2
    -rw-r--r-- 2 plank guest   11 1995-02-20 10:29 f2-hard-link
    lrwxrwxrwx 1 plank loci     2 2009-01-19 17:07 f2-soft-link -> f2
    dr-xr-xr-x 2 plank guest 4096 1995-02-20 10:29 sub_dir
    UNIX> ls -l sub_dir
    total 4
    -r--r--r-- 1 plank guest 11 1995-02-20 10:29 f1
    UNIX> ~plank/cs360/labs/lab5/jtar c . > ~/tarfile-2
    UNIX> ~plank/cs360/labs/lab5/jtar c sub_dir > ~/tarfile-3
    UNIX> ~plank/cs360/labs/lab5/jtar c sub_dir/f1 > ~/tarfile-4
    UNIX> ls -l ~/tarfile*
    -rw-r--r-- 1 fred loci 41692 2010-02-12 15:12 /home/plank/tarfile
    -rw-r--r-- 1 fred loci   522 2010-02-12 15:27 /home/plank/tarfile-2
    -rw-r--r-- 1 fred loci   212 2010-02-12 15:27 /home/plank/tarfile-3
    -rw-r--r-- 1 fred loci   113 2010-02-12 15:27 /home/plank/tarfile-4
    UNIX> 
    
    So, what's going on? The directory has 3 files and a subdirectory. f2 and f2-hard-link are the same file (i.e. both links to the same file), and f2-soft-link is a soft link to f2. Sub_dir is a subdirectory with one file. Note the protection modes of both sub_dir and f1.

    Now, fred first extracts tarfile-2:

    UNIX> cd
    UNIX> pwd
    /home/fred
    UNIX> rm -rf tmpfile
    UNIX> mkdir tmpfile
    UNIX> cd tmpfile
    UNIX> ~plank/cs360/labs/lab5/jtar x < ~/tarfile-2
    UNIX> ls -l
    total 12
    -rw-r--r-- 2 fred loci   11 1995-02-20 10:29 f2
    -rw-r--r-- 2 fred loci   11 1995-02-20 10:29 f2-hard-link
    dr-xr-xr-x 2 fred loci 4096 1995-02-20 10:29 sub_dir
    UNIX> ls -l sub_dir
    total 4
    -r--r--r-- 1 plank loci 11 1995-02-20 10:29 f1
    UNIX>
    
    Jtar remade all the files in ~plank/cs360/labs/lab5/example-d2 with the exception of the symbolic link. Again, all the protection modes and times are the same. It also remade the directory and its files, and again protection modes and times are the same. The files f2 and f2-hard-link are linked to the same file.

    Now, fred tries again with tarfile-3:

    UNIX> cd 
    UNIX> rm -rf tmpfile
    rm: cannot remove `tmpfile/sub_dir/f1': Permission denied
    UNIX> chmod 0755 tmpfile/sub_dir
    UNIX> rm -rf tmpfile
    UNIX> mkdir tmpfile
    UNIX> cd tmpfile
    UNIX> ~plank/cs360/labs/lab5/jtar x < ~/tarfile-3
    UNIX> ls -l
    total 4
    dr-xr-xr-x 2 fred loci 4096 1995-02-20 10:29 sub_dir
    UNIX> ls -l sub_dir
    total 4
    -r--r--r-- 1fredplank loci 11 1995-02-20 10:29 f1
    UNIX> 
    
    First, the rm -rf failed because the of protections of sub_dir -- they had to be changed so that the directory could be deleted. The untarring of tarfile-3 creates only sub_dir and its contents. Again, the protections are as they were.

    Now tarfile-4:

    UNIX> chmod 0755 sub_dir
    UNIX> cd
    UNIX> rm -rf tmpfile
    UNIX> mkdir tmpfile
    UNIX> cd tmpfile
    UNIX> ~plank/cs360/labs/lab5/jtar x < ~/tarfile-4
    UNIX> ls -l
    total 4
    drwxr-xr-x 2 fred loci 4096 2010-02-12 15:37 sub_dir
    UNIX> ls -l sub_dir
    total 4
    -r--r--r-- 1 fred loci 11 1995-02-20 10:29 f1
    UNIX> 
    
    This time sub_dir has been created, but the modification times and permissions were not reset to their original values. Why? Because jtar only records the times for the last file in the given pathnames. All of the other directories leading up to that last file are simply created with mkdir().

    Finally, if you can't read a file or directory, then it's ok for jtar to fail on it. For example:

    UNIX> touch f1.txt
    UNIX> chmod 0 f1.txt
    UNIX> ~plank/cs360/labs/lab5/jtar c f1.txt > ~/tarfile
    Couldn't open f1.txt
    UNIX> 
    

    The cv and xv options

    Jtar should also support the options cv and xv in place of c and x. This should work just as before, only jtar should print on standard error the directories and files that are saved, along with their sizes as it does so. For example:
    UNIX> cd ~plank/cs360/labs/lab5/example-d2
    UNIX> ../jtar cv . > ~/tarfile-4
    Directory .
    Regular File ./f2 11
    Directory ./sub_dir
    Regular File ./sub_dir/f1 11
    Regular File ./f2-hard-link 11
    (link ./f2-hard-link to ./f2)
    Ignoring soft link: ./f2-soft-link
    UNIX> cd
    UNIX> rm -rf tmpdir
    UNIX> mkdir tmpdir
    UNIX> ~plank/cs360/labs/lab5/jtar xv < ~/tarfile-4
    File: .
    File: ./f2
    File: ./sub_dir
    File: ./sub_dir/f1
    File: ./f2-hard-link
    UNIX> 
    
    You will not be graded on your cv and xv outputs. They are simply there to help you out.

    Duplicates

    cd ~plank/cs360/labs/lab5/example-d2 mamba/example-d2: ../jtar c . . . > ~/tarfile-5 If duplicate files are somehow specified, tar should be able to recognize that, and only save one copy. For example:
    UNIX> ~plank/cs360/labs/lab5/jtar c . > ~/tmpfile-5
    UNIX> ~plank/cs360/labs/lab5/jtar c . . . > ~/tmpfile-6
    UNIX> ~plank/cs360/labs/lab5/jtar c . . . f2 f2 f2 f2 > ~/tmpfile-7
    UNIX> ls -l ~/tmpfile*
    -rw-r--r-- 1 plank loci  522 2010-02-12 15:53 /home/plank/tmpfile-5
    -rw-r--r-- 1 plank loci  522 2010-02-12 15:53 /home/plank/tmpfile-6
    -rw-r--r-- 1 plank loci  898 2010-02-12 15:53 /home/plank/tmpfile-7
    UNIX>
    
    Note that tmpfile-6 is the same size as tmpfile-5, and that tmpfile-7 is a little bigger. The reason is that my version of jtar ignores duplicate directories, but for each file specified on the command line, it stores the files name and stat buf. It only stores the contents once. Yours does not have to do exactly as mine does, but it should not store duplicate contents for duplicate files.

    The simplest way to identify duplicate files is to make use of the library call realpath() (read the man page). You can maintain a rb-tree of real path names, and whenever you discover a duplicate, you can ignore it. (You still need a rb-tree for inodes so that you can recognize hard links).


    A word of warning

    Make sure you always try to extract files into a clean directory. Do not extract files into your working directory, because if you have a bug, you may trash your files. I've heard of students trashing their home directories doing this program. Make sure you be careful not to let that happen to you. Saving full path names or following .. in this assigment can also do this. Be careful.

    Also

    No use of the system() command is allowed. You must make use of the system calls that Unix provides for you (note that "system call" is different from the system() procedure call).

    My jtar

    When in doubt, check your code against my jtar. Let me know if you find bugs.

    tar-checker

    I have written a program called tar-checker, which takes two directories as command line arguments, and tests to see whether they are the same. You may give it optional arguments that help refine the testing. The default is to simply check whether the same files and directories exist in both directories. For example, the directory example-d3 contains three files -- f1.txt, f2.txt and f3.txt, which contain a single line of text. There is a directory dir1, which also contains a file f3.txt, which is a link to f3.tx in the original directory. The listing below shows both the "full time" listing, and the inode numbers so that you can see the hard links:
    UNIX> ls -li --full-time /home/plank/cs360/labs/lab5/example-d3
    total 16
    5492237 dr-xr-xr-x 2 plank loci 4096 2010-02-15 16:44:10.000000000 -0500 dir1
    5492235 -rw-r--r-- 1 plank loci   11 2010-02-15 16:43:03.000000000 -0500 f1.txt
    5492245 -rw-r--r-- 1 plank loci   11 2010-02-17 08:57:35.000000000 -0500 f2.txt
    5492238 -r--r--r-- 2 plank loci   15 2010-02-15 16:43:14.000000000 -0500 f3.txt
    UNIX> ls -li --full-time /home/plank/cs360/labs/lab5/example-d3/dir1
    total 4
    5492238 -r--r--r-- 2 plank loci 15 2010-02-15 16:43:14.000000000 -0500 f3.txt
    UNIX> 
    
    If I use "cp -r" to make a copy of the directory, you'll see that the files are the same, but there are a few differences. First, the f3.txt files are no longer links to each other. Second, the modification times of all the files are different. Since the default of tar-checker is to just check that the names of the files are the same, it works fine (no output means that the two directories are the same):
    UNIX> cp -r ~plank/cs360/labs/lab5/example-d3 d3-copy
    UNIX> ls -li --full-time d3-copy
    total 16
    5342067 dr-xr-xr-x 2 plank loci 4096 2010-02-17 09:03:23.000000000 -0500 dir1
    5342066 -rw-r--r-- 1 plank loci   11 2010-02-17 09:03:23.000000000 -0500 f1.txt
    5342064 -rw-r--r-- 1 plank loci   11 2010-02-17 09:03:23.000000000 -0500 f2.txt
    5342065 -r--r--r-- 1 plank loci   15 2010-02-17 09:03:23.000000000 -0500 f3.txt
    UNIX> ls -li --full-time d3-copy/dir1
    total 4
    5342068 -r--r--r-- 1 plank loci 15 2010-02-17 09:03:23.000000000 -0500 f3.txt
    UNIX> ~plank/cs360/labs/lab5/tar-checker ~plank/cs360/labs/lab5/example-d3 d3-copy
    UNIX> 
    
    There are four optional arguments to tar-checker: In the example above, the contents and permissions of the files will match, but the times and the links will not:
    UNIX> ~plank/cs360/labs/lab5/tar-checker ~plank/cs360/labs/lab5/example-d3 d3-copy c
    UNIX> ~plank/cs360/labs/lab5/tar-checker ~plank/cs360/labs/lab5/example-d3 d3-copy l
    Error: files f3.txt and dir1/f3.txt are links in /home/plank/cs360/labs/lab5/example-d3 but not in d3-copy
    UNIX> ~plank/cs360/labs/lab5/tar-checker ~plank/cs360/labs/lab5/example-d3 d3-copy p
    UNIX> ~plank/cs360/labs/lab5/tar-checker ~plank/cs360/labs/lab5/example-d3 d3-copy t
    Error: dir1: modification times don't match.
    UNIX> 
    
    I'll fix the links and the modification times:
    UNIX> rm d3-copy/f3.txt
    rm: remove write-protected regular file `d3-copy/f3.txt'? y
    UNIX> ln d3-copy/dir1/f3.txt d3-copy
    UNIX> ~plank/cs360/labs/lab5/tar-checker ~plank/cs360/labs/lab5/example-d3 d3-copy l
    UNIX> touch -t 02151643.14 d3-copy/f3.txt
    UNIX> touch -t 02170857.35 d3-copy/f2.txt
    UNIX> touch -t 02151643.03 d3-copy/f1.txt
    UNIX> touch -t 02151644.10 d3-copy/dir1
    UNIX> ~plank/cs360/labs/lab5/tar-checker ~plank/cs360/labs/lab5/example-d3 d3-copy t
    UNIX> 
    
    tar-checker ignores hard links.

    mrd

    The program in the grading scripts directory -- /home/plank/cs360/labs/lab5/Gradescript-Examples/mrd -- may be used to generate random directories for testing. The usage is:

    usage: mrd seed dir-level fpd randprot(n|y|d) linkperc stem
    

    The arguments are:

    A couple quick examples:
    UNIX> mkdir tmp
    UNIX> cd tmp
    UNIX> /home/plank/cs360/labs/lab5/Gradescript-Examples/mrd 2 1 15 y 0 ex1
    UNIX> ls -li --full-time ex1
    total 52
    5310623 -r--r----- 1 plank loci 11 2009-09-11 11:54:43.000000000 -0400 b6lAEuZwl
    5310624 -r---wx-w- 1 plank loci 50 2009-05-09 16:18:49.000000000 -0400 bQEFP4vdBVq4
    5310625 -r--rwx-w- 1 plank loci 75 2009-09-02 00:06:30.000000000 -0400 ce7gwhmc
    5310617 -rw-rw--wx 1 plank loci 30 2009-07-25 02:45:32.000000000 -0400 CPt2
    5310618 -r--r--rw- 1 plank loci 77 2009-06-14 22:14:06.000000000 -0400 DVD
    5310619 -r---wxr-x 1 plank loci 67 2009-01-21 19:02:02.000000000 -0500 GPX5v
    5310620 -r-------- 1 plank loci 57 2009-08-27 14:45:30.000000000 -0400 HHOSU2o5
    5310621 -rwxr--r-x 1 plank loci  9 2009-03-16 02:02:49.000000000 -0400 JikTtd0eo
    5310626 -r-x-w--w- 1 plank loci 21 2009-08-02 18:45:41.000000000 -0400 kQV5
    5310627 -r-x--xr-- 1 plank loci 63 2009-03-18 20:50:19.000000000 -0400 oUqOzTZXl3SZ94V
    5310628 -r---wx--- 1 plank loci 38 2009-03-10 15:02:32.000000000 -0400 wb31yIuVqOuDZ
    5310629 -rwx-w---- 1 plank loci 29 2009-05-09 00:11:45.000000000 -0400 zOCTn9
    5310622 -r--r--r-- 1 plank loci 32 2009-08-12 12:55:34.000000000 -0400 ZUl
    UNIX> /home/plank/cs360/labs/lab5/Gradescript-Examples/mrd 2 1 15 y 25 ex1
    ./ex1/DVD: Permission denied
    UNIX> /home/plank/cs360/labs/lab5/Gradescript-Examples/mrd 2 1 15 y 25 ex2
    UNIX> ls -li --full-time ex2
    total 52
    5310635 -r--r----- 1 plank loci 10 2009-12-14 19:12:52.000000000 -0500 b6lAEuZwl
    5310636 -r---wx-w- 1 plank loci 71 2009-02-02 13:53:50.000000000 -0500 bQEFP4vdBVq4
    5310631 -r--rwx-w- 1 plank loci 77 2009-05-05 08:43:42.000000000 -0400 DVD
    5310637 -r---wxr-x 1 plank loci 57 2009-12-14 03:17:42.000000000 -0500 eIPt2ytg1e7gwhmc
    5310632 -r-------- 3 plank loci 17 2009-02-13 18:54:12.000000000 -0500 GPX5v
    5310632 -r-------- 3 plank loci 17 2009-02-13 18:54:12.000000000 -0500 HHOSU2o5
    5310638 -r--r--rw- 1 plank loci 76 2009-05-27 02:47:54.000000000 -0400 h-srhxrJI0
    5310633 -rwxr--r-x 1 plank loci 59 2009-08-09 22:56:06.000000000 -0400 JikTtd0eo
    5310639 -r-x-w--w- 1 plank loci 62 2009-08-10 13:09:44.000000000 -0400 kQV5
    5310640 -r-x--xr-- 1 plank loci  6 2009-04-17 14:05:39.000000000 -0400 oUqOzTZXl3SZ94V
    5310641 -r---wx--- 1 plank loci 68 2009-08-15 02:23:23.000000000 -0400 wb31yIuVqOuDZ
    5310632 -r-------- 3 plank loci 17 2009-02-13 18:54:12.000000000 -0500 zOCTn9
    5310634 -r--r--r-- 1 plank loci 64 2009-10-16 02:03:51.000000000 -0400 ZUl
    UNIX> 
    
    Both ex1 and ex2 are one-level directories with random protections. The only difference is that ex1's linkperc was zero, so all files are distinct. In ex2, linkperc was 25 percent, which resulted in files "GPX5v", "HHOSU2o5" and "zOCTn9" being hard links to one another.

    Further examples:

    UNIX> /home/plank/cs360/labs/lab5/Gradescript-Examples/mrd 2 3 15 y 25 ex3
    UNIX> ls -li --full-time ex3
    total 8
    5310643 -r---wx-w- 2 plank loci   77 2009-04-06 08:32:04.000000000 -0400 CqOhUikTtd0eo1
    5310644 drwxr-xr-x 4 plank loci 4096 2009-01-05 16:03:25.000000000 -0500 JfHOSU2o56Nxb31y
    UNIX> ls -li --full-time ex3/JfHOSU2o56Nxb31y
    total 32
    5310658 -r---wxrw- 2 plank loci   75 2009-02-16 02:52:30.000000000 -0500 DuZwlRtaTPX5
    5310647 -r------w- 1 plank loci   38 2009-11-05 06:42:11.000000000 -0500 eIPt2ytg1e7gwhmc
    5310648 drwxr-xr-x 2 plank loci 4096 2009-02-12 02:39:13.000000000 -0500 gDOyVZ
    5310655 -r-xrwxr-x 1 plank loci   19 2009-06-05 17:33:57.000000000 -0400 khxrJI0zvvYOxt
    5310645 -rwx---r-- 2 plank loci   45 2009-05-07 13:56:31.000000000 -0400 OZ94Vkv3aOCTn9k
    5310656 drwxr-xr-x 2 plank loci 4096 2009-11-18 01:40:52.000000000 -0500 pVqOuDZXzoYQV51BP
    5310646 -r----xr-- 1 plank loci   44 2009-12-30 05:36:56.000000000 -0500 TFP4vdBVq4ob3
    5310667 -rw-rw---- 1 plank loci   20 2009-01-09 06:38:41.000000000 -0500 zzT
    UNIX> ls -li --full-time ex3/JfHOSU2o56Nxb31y/gDOyVZ
    total 28
    5310654 -r-x-w---x 1 plank loci 36 2009-06-25 06:08:18.000000000 -0400 c51a8mwuo7pczb2l
    5310643 -r---wx-w- 2 plank loci 77 2009-04-06 08:32:04.000000000 -0400 cQysyAo2q-ntP
    5310649 -r-x-w---- 1 plank loci 62 2009-01-07 17:13:47.000000000 -0500 FqSkvK
    5310650 -r-------- 1 plank loci  6 2009-03-21 07:56:05.000000000 -0400 Lwh3N9
    5310651 -r---wxr-x 1 plank loci 68 2009-04-12 17:06:22.000000000 -0400 RsJqfSWHdm
    5310652 -rw------x 1 plank loci 50 2009-09-05 23:22:11.000000000 -0400 WJZ808hh
    5310653 -rw--w--wx 1 plank loci 12 2009-09-11 02:08:21.000000000 -0400 YH-N
    UNIX> ls -li --full-time ex3/JfHOSU2o56Nxb31y/pVqOuDZXzoYQV51BP
    total 44
    5310660 -r--r--rwx 1 plank loci 31 2009-12-27 17:17:11.000000000 -0500 e2ArwPda
    5310661 -rw------- 1 plank loci 44 2009-02-23 23:18:33.000000000 -0500 g10Ld
    5310657 -rw-r--r-- 1 plank loci 57 2009-09-09 06:40:52.000000000 -0400 KQofGOKqwJzB
    5310662 -rw--w---- 1 plank loci 67 2009-10-05 22:25:58.000000000 -0400 mgjGHFXVg1p-M2oUN
    5310645 -rwx---r-- 2 plank loci 45 2009-05-07 13:56:31.000000000 -0400 sslAo
    5310658 -r---wxrw- 2 plank loci 75 2009-02-16 02:52:30.000000000 -0500 UR7XeW
    5310663 -r---wxr-- 1 plank loci 34 2009-10-24 00:33:06.000000000 -0400 uSuQOeW8HvXjM
    5310664 -rw--w--w- 1 plank loci 65 2009-07-26 16:13:06.000000000 -0400 v688KhmqdCGZHI
    5310659 -r---wx--x 1 plank loci 59 2009-04-25 08:24:30.000000000 -0400 Vv1-w6WcDc5M-1uPb
    5310665 -r-----r-- 1 plank loci  4 2009-10-16 11:48:52.000000000 -0400 wxr
    5310666 -rwx---r-x 1 plank loci 32 2009-08-10 18:23:06.000000000 -0400 zDavFl
    UNIX> /home/plank/cs360/labs/lab5/jtar c ex3 > tarfile
    UNIX> mv ex3 ex3-old
    UNIX> /home/plank/cs360/labs/lab5/jtar x <  tarfile
    UNIX> /home/plank/cs360/labs/lab5/tar-checker ex3 ex3-old c t l p
    UNIX> ls -li --full-time ex3/JfHOSU2o56Nxb31y/pVqOuDZXzoYQV51BP
    total 44
    5310684 -r--r--rwx 1 plank loci 31 2009-12-27 17:17:11.000000000 -0500 e2ArwPda
    5310690 -rw------- 1 plank loci 44 2009-02-23 23:18:33.000000000 -0500 g10Ld
    5310686 -rw-r--r-- 1 plank loci 57 2009-09-09 06:40:52.000000000 -0400 KQofGOKqwJzB
    5310682 -rw--w---- 1 plank loci 67 2009-10-05 22:25:58.000000000 -0400 mgjGHFXVg1p-M2oUN
    5310683 -rwx---r-- 2 plank loci 45 2009-05-07 13:56:31.000000000 -0400 sslAo
    5310680 -r---wxrw- 2 plank loci 75 2009-02-16 02:52:30.000000000 -0500 UR7XeW
    5310687 -r---wxr-- 1 plank loci 34 2009-10-24 00:33:06.000000000 -0400 uSuQOeW8HvXjM
    5310688 -rw--w--w- 1 plank loci 65 2009-07-26 16:13:06.000000000 -0400 v688KhmqdCGZHI
    5310681 -r---wx--x 1 plank loci 59 2009-04-25 08:24:30.000000000 -0400 Vv1-w6WcDc5M-1uPb
    5310689 -r-----r-- 1 plank loci  4 2009-10-16 11:48:52.000000000 -0400 wxr
    5310685 -rwx---r-x 1 plank loci 32 2009-08-10 18:23:06.000000000 -0400 zDavFl
    UNIX> 
    
    For ex3, we specify dir-level to be three. As such, ex3 has one subdirectory, "JfHOSU2o56Nxb31y", and that directory has two subdirectories: "gDOyVZ" and "pVqOuDZXzoYQV51BP". You can see from the inode numbers that "ex3/JfHOSU2o56Nxb31y/DuZwlRtaTPX5" is hard linked to "ex3/JfHOSU2o56Nxb31y/pVqOuDZXzoYQV51BP/UR7XeW".

    One more example:

    UNIX> /home/plank/cs360/labs/lab5/Gradescript-Examples/mrd 100 3 15 d 25 ex4
    UNIX> ls -l ex4
    total 36
    -r-------- 2 plank loci   49 2009-11-03 22:47 bk96SQ0XulqX2
    dr-x---r-x 7 plank loci 4096 2009-05-31 18:51 eNilEiW6LqL
    -r---wx--- 1 plank loci   10 2009-08-29 04:49 JRTSdgoOJ9SZe
    -r------w- 2 plank loci   53 2009-08-09 00:54 KZvw52JrO9WQG98X0
    drwxr---wx 6 plank loci 4096 2009-11-22 17:50 PPIaXLtmhxQlc
    -rw-rw-rwx 4 plank loci   59 2009-06-30 08:01 qCslBEuiCTdW
    -r------wx 1 plank loci   39 2009-04-07 19:45 R19I3CMOfYUC5u
    dr-x--x--- 3 plank loci 4096 2009-08-31 01:57 sKl09
    -r--rwxrw- 1 plank loci   31 2009-05-11 09:03 yzNqGZVUrvJSWKzqc
    UNIX> /home/plank/cs360/labs/lab5/jtar c ex4 > tarfile
    UNIX> mv ex4 ex4-old
    UNIX> /home/plank/cs360/labs/lab5/jtar x ex4 < tarfile
    UNIX> /home/plank/cs360/labs/lab5/tar-checker ex4 ex4-old c t l p
    UNIX> 
    
    This is the tough case, since directories "ex4/eNilEiW6LqL" and "ex4/sKl09" don't have their write bits set. Your jtar has to work with this case.

    Removing these directories is a bit subtle, again because the write bit isn't set.

    UNIX> rm -rf ex4
    rm: cannot remove `ex4/eNilEiW6LqL/H3fNgWEKn7TwWirTl/QRPhTjV2Tg': Permission denied
    rm: cannot remove `ex4/eNilEiW6LqL/H3fNgWEKn7TwWirTl/yYTIWJFn5': Permission denied
    rm: cannot remove `ex4/eNilEiW6LqL/H3fNgWEKn7TwWirTl/LHSpl6': Permission denied
    rm: cannot remove `ex4/eNilEiW6LqL/H3fNgWEKn7TwWirTl/uTO9g8Ovm': Permission denied
    ....
    UNIX> 
    
    Fortunately, chmod has a "recursive" option which sets all files reachable from the argument. That makes it easier:
    UNIX> chmod -R 0700 ex4 ex4-old
    UNIX> rm -rf ex4 ex4-old
    

    The gradescript

    The grading script uses mrd to generate random test directories. Cases 1-30 test only links, time and protection, or contents. Cases 31-90 test all of them. In cases 1-70, the protection mode of directories is always 0755. In cases 71 through 100, they are generated with the 'd' option to mrd. Finally, cases 91 through 100 limit you to 7 open file descriptors.

    It's best to run the grading script in a clean directory that simply has a copy of your jtar in it.


    Strategy

    This is a nontrivial program. The following is the strategy that I used for writing jtar. You may want to use a different strategy if you find that easier; however, this one has the benefit of creating jtar in small pieces, each of which may be tested before going on.