文章随机晒最新文章关照最多的

jiayi Rss

Ownership of New Files and Directories

| Posted in APUE |

4

When we described the creation of a new file using either open or creat, we never said what values were assigned to the user ID and group ID of the new file. We’ll see how to create a new directory when we describe the mkdir function. The rules for the ownership of a new directory are identical to the rules in this section for the ownership of a new file.

The user ID of a new file is set to the effective user ID of the process. POSIX.1 allows an implementation to choose one of the following options to determine the group ID of a new file.

  1. The group ID of a new file can be the effective group ID of the process. # Linux 2.6.22.5-31 compliant this rule

  2. The group ID of a new file can be the group ID of the directory in which the file is being created.

    FreeBSD 5.2.1 and Mac OS X 10.3 always uses the group ID of the directory as the group ID of the new file.

    The Linux ext2 and ext3 file systems allow the choice between these two POSIX.1 options to be made on a file system basis, using a special flag to the mount(1) command. On Linux 2.4.22 (with the proper mount option) and Solaris 9, the group ID of a new file depends on whether the set-group-ID bit is set for the directory in which the file is being created. If this bit is set for the directory, the group ID of the new file is set to the group ID of the directory; otherwise, the group ID of the new file is set to the effective group ID of the process.

Using the second optioninheriting the group ID of the directoryassures us that all files and directories created in that directory will have the group ID belonging to the directory. This group ownership of files and directories will then propagate down the hierarchy from that point. This is used, for example, in the /var/spool/mail directory on Linux.

Directories are created with the mkdir function and deleted with the rmdir function.

 

#include <sys/stat.h>

int mkdir(const char *pathname, mode_t mode);

    Returns: 0 if OK, 1 on error

An empty directory is deleted with the rmdir function. Recall that an empty directory is one that contains entries only for dot and dot-dot. 

 

#include <unistd.h>

int rmdir(const char *pathname);

Returns: 0 if OK, 1 on error

Comments (4)

厄,每次都强迫我的视觉~~

英文明显延长我的阅读时间 。。。

why the older and newer post links at the bottom of the post , always link to the same post …. something wrong ?

@daniel
The newer and older links at the bottom of my post are in the category which is the same as the current post belongs to. They loop from the last one to the first one. If the number of the category’s post is less than 3,you will see certain same links…

Write a comment

You must be logged in to post a comment.