 | UnTar implementation
 | source code
 | tar/untar/const.h |
 | tar/untar/err.h |
 | tar/untar/err.c |
 | tar/untar/misc.h |
 | tar/untar/misc.c |
 | tar/untar/tar.h
 | This time we formally put the header structure in a header
file. |
 | This is the recommended way since the tar and untar will use
the same structure. |
|
 | tar/untar/untar.c
 | This is the main driver program. It simply calls the untar to
do all the jobs. |
|
 | tar/untar/untar_it.h
 | We have three functions here. The untar is the interface to
the main driver program. The untar_it will untar a block, and
the function is_zero_block tests for a block consisting of all
zeros. |
|
 | tar/untar/untar_it.c
 | untar
 | The program checks for zero blocks. If the next block is
not all zero, then it is the beginning of a file. |
 | After no data was found. The program scans for the right
number of zero blocks in the specification. |
|
 | untar_it
 | Process a file -- it could be a directory or a regular
file. |
 | First it uses a series of sscanf to parse the data in the
header block. |
 | The checksum is verified to ensure data integrity. Note
that the checksum is first read from the header, then filled
with blanks and recomputed. |
 | If this is a directory, we simply call mkdir to create it. |
 | If this is a regular file, we read the contents out of the
tar file, and create the file. |
 | After the file is created, we restore its correct
ownership, permission, and time.
 | ownership
 | Use chown to correct the user id and group id. |
|
 | time information
 | Since the tar file only keeps the modification
time, we simply use it as the last access time. |
|
 | permission bits.
 | We should restore the permission bits with chmod
here, but I forgot to do it. :-) |
|
|
|
 | is_zero_block
 | Simply check for all zeros for a buffer. |
|
|
|
 | Library function used
 | sscanf |
 | mkdir
 | Create a new directory. |
|
 | chown
 | Change the ownership of a file. We need to use this to restore
the user and group id. |
 | BSD enforces that only super user can do this, but System V
allows anyone to do it. POSIX determines this by a system
constant _POSIX_CHOWN_RESTRICTED, usually defined in .
If that is the case, then one can chown only if.
 | He is the superuser, or |
 | The processes has an effective user id of the file, and
the user owns the file, and has an group id equals to the
effective group id of the process. |
|
|
 | utime
 | UNIX has three file times.
 | Time of last access.
 | we can use ls -u to check it. |
 | Affected by, for example, read. |
|
 | Time of modification.
 | The default time reported by ls. |
 | Affected by write(). |
|
 | Time of last i-node change. (We will talk about this in
the next lecture)
 | Check it with ls -c. |
 | Affected by, for example, chmod. |
|
|
 | The utime function can set these times only if you are the
superuser or you own the file. |
 | The utimebuf is used to set the time. If it is NULL the
the access and modification time are set to the current time. If
the pointer is not NULL, it is set to the contents of the
buffer. |
|
 | chmod
 | Change the permission bits of a file. |
 | Caller must be the superuser or have the effective user id of
the file. |
 | The sticky bit
 | On a regular file it means that the file will
"stick" to the swap area and can be moved back
into memory much faster. |
 | On a directory it means that the operation on that
directory is carefully examined. One can remove a file only
if
 | He owns the file. |
 | He owns the directory. |
 | He is the superuser. |
|
 | The restriction on the deletion is to make sure no one
deletes others' files, especially in those directories that
everybody can write (e.g. /tmp). |
|
|
|
|