Node:File Owner, Next:Permission Bits, Previous:Testing File Type, Up:File Attributes
Every file has an owner which is one of the registered user names defined on the system. Each file also has a group which is one of the defined groups. The file owner can often be useful for showing you who edited the file (especially when you edit with GNU Emacs), but its main purpose is for access control.
The file owner and group play a role in determining access because the file has one set of access permission bits for the owner, another set that applies to users who belong to the file's group, and a third set of bits that applies to everyone else. See Access Permission, for the details of how access is decided based on this data.
When a file is created, its owner is set to the effective user ID of the process that creates it (see Process Persona). The file's group ID may be set to either the effective group ID of the process, or the group ID of the directory that contains the file, depending on the system where the file is stored. When you access a remote file system, it behaves according to its own rules, not according to the system your program is running on. Thus, your program must be prepared to encounter either kind of behavior no matter what kind of system you run it on.
You can change the owner and/or group owner of an existing file using
the chown
function. This is the primitive for the chown
and chgrp
shell commands.
The prototype for this function is declared in unistd.h
.
int chown (const char *filename, uid_t owner, gid_t group) | Function |
The chown function changes the owner of the file filename to
owner, and its group owner to group.
Changing the owner of the file on certain systems clears the set-user-ID and set-group-ID permission bits. (This is because those bits may not be appropriate for the new owner.) Other file permission bits are not changed. The return value is
|
int fchown (int filedes, int owner, int group) | Function |
This is like chown , except that it changes the owner of the open
file with descriptor filedes.
The return value from
|