* core program logic what's the file type? call lstat (l is needed to handle symbolic links) file_stat->st_mode tells you the file type how to handle the entries 1. write header populate all of the header fields that are for reg files write the header as a 512 block 2. if it's a regular file; write the file contents open file while: read a 512 byte block from the source if read returns 0, already at EOF -- done write the 512 bte block to the archive if read returns < the requested size, now at EOF -- done 3. if it's a directory open dir while more entries: handle the entry what happens with very deeply nested directory trees? open and opendir calls could fail if you run out of FDs, but on a modern system that's unlikely to happen -- you'll run out of space in prefix first At the end, write two empty blocks (or more, GNU tar rounds up to an particular number of blocks -- see the manual or man page) * some weirdnesses GNU tar does UID and GID differently when it's a large number (see the latest version of the homework spec for details) See "The default blocksize ..." in the standards page description of the ustar format. The full size of a compliant tar file after writing the two empty logical records to terminate the file MUST be an even multiple of the default blocksize. The magic and version values from GNU tar are different fromt what's specified in the pax standard for the ustar format.