Skip to Content
UNIX Filesystems: Evolution, Design, and Implementation
book

UNIX Filesystems: Evolution, Design, and Implementation

by Steve D. Pate
January 2003
Intermediate to advanced content levelIntermediate to advanced
480 pages
13h 22m
English
Wiley
Content preview from UNIX Filesystems: Evolution, Design, and Implementation

Changing File Ownership

When a file is created, the user and group IDs are set to those of the caller. Occasionally it is useful to change ownership of a file or change the group in which the file resides. Only the root user can change the ownership of a file although any user can change the file's group ID to another group in which the user resides.

There are three calls that can be used to change the file's user and group as shown below:

#include <sys/types.h>
#include <unistd.h>

int chown(const char *path, uid_t owner, gid_t group);
int fchown(int fd, uid_t owner, gid_t group);
int lchown(const char *path, uid_t owner, gid_t group);

The difference between chown() and lchown() is that the lchown() system call operates on the symbolic link specified rather than the file to which it points.

Table 2.1 Permissions Passed to chmod()

PERMISSION DESCRIPTION
S_IRWXU Read, write, execute/search by owner
S_IRUSR Read permission by owner
S_IWUSR Write permission by owner
S_IXUSR Execute/search permission by owner
S_IRWXG Read, write, execute/search by group
S_IRGRP Read permission by group
S_IWGRP Write permission by group
S_IXGRP Execute/search permission by group
S_IRWXO Read, write, execute/search by others
S_IROTH Read permission by others
S_IWOTH Write permission by others
S_IXOTH Execute/search permission by others
S_ISUID Set-user-ID on execution
S_ISGID Set-group-ID on execution
S_ISVTX On directories, set the restricted deletion flag

In addition ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Marshall Kirk McKusick, George V. Neville-Neil, Robert N.M. Watson

Publisher Resources

ISBN: 9780471456759Purchase book