File Permissions contained several statements about the permissions required for various file-system operations. Use shell commands or write programs to verify or answer the following:
Removing all owner permissions from a file denies the file owner access, even though group and other do have access.
On a directory with read permission but not execute permission, the names of files in the directory can be listed, but the files themselves can’t be accessed, regardless of the permissions on them.
What permissions are required on the parent directory and the file itself in order to create a new file, open a file for reading, open a file for writing, and delete a file? What permissions are required on the source and target directory to rename a file? If the target file of a rename operation already exists, what permissions are required on that file? How does setting the sticky permission bit (chmod +t) of a directory affect renaming and deletion operations?
Do you expect any of a file’s three timestamps to be changed by the stat() system call? If not, explain why.
On a system running Linux 2.6, modify the program in Example 15-1 (t_stat.c
) so that the file timestamps are displayed with nanosecond accuracy.
The access() system call checks permissions using the process’s real user and group IDs. Write a corresponding function that performs the checks according to the process’s effective user and group IDs.
As noted in The Process File Mode Creation Mask: umask(), umask() always sets the process umask and, at the same time, returns a copy of the old umask. How can we obtain a copy of the current process umask while leaving it unchanged?
The chmod a+rX file command enables read permission for all categories of user, and likewise enables execute permission for all categories of user if file is a directory or execute permission is enabled for any of the user categories for file, as demonstrated in the following example:
$ls -ld dir file prog
dr-------- 2 mtk users 48 May 4 12:28 dir -r-------- 1 mtk users 19794 May 4 12:22 file -r-x------ 1 mtk users 19336 May 4 12:21 prog $chmod a+rX dir file prog
$ls -ld dir file prog
dr-xr-xr-x 2 mtk users 48 May 4 12:28 dir -r--r--r-- 1 mtk users 19794 May 4 12:22 file -r-xr-xr-x 1 mtk users 19336 May 4 12:21 prog
Write a program that uses stat() and chmod() to perform the equivalent of chmod a+rX.
Write a simple version of the chattr(1) command, which modifies file i-node flags. See the chattr(1) man page for details of the chattr command-line interface. (You don’t need to implement the -R, -V, and -v options.)