1CHOWN(2) Linux Programmer's Manual CHOWN(2)
2
3
4
6 chown, fchown, lchown - change ownership of a file
7
9 #include <sys/types.h>
10 #include <unistd.h>
11
12 int chown(const char *path, uid_t owner, gid_t group);
13 int fchown(int fd, uid_t owner, gid_t group);
14 int lchown(const char *path, uid_t owner, gid_t group);
15
17 These system calls change the owner and group of the file specified by
18 path or by fd. Only a privileged process (Linux: one with the
19 CAP_CHOWN capability) may change the owner of a file. The owner of a
20 file may change the group of the file to any group of which that owner
21 is a member. A privileged process (Linux: with CAP_CHOWN) may change
22 the group arbitrarily.
23
24 If the owner or group is specified as -1, then that ID is not changed.
25
26 When the owner or group of an executable file are changed by a non-
27 superuser, the S_ISUID and S_ISGID mode bits are cleared. POSIX does
28 not specify whether this also should happen when root does the chown();
29 the Linux behaviour depends on the kernel version. In case of a non-
30 group-executable file (with clear S_IXGRP bit) the S_ISGID bit indi‐
31 cates mandatory locking, and is not cleared by a chown().
32
34 On success, zero is returned. On error, -1 is returned, and errno is
35 set appropriately.
36
38 Depending on the file system, other errors can be returned. The more
39 general errors for chown() are listed below.
40
41 EACCES Search permission is denied on a component of the path prefix.
42 (See also path_resolution(2).)
43
44 EFAULT path points outside your accessible address space.
45
46 ELOOP Too many symbolic links were encountered in resolving path.
47
48 ENAMETOOLONG
49 path is too long.
50
51 ENOENT The file does not exist.
52
53 ENOMEM Insufficient kernel memory was available.
54
55 ENOTDIR
56 A component of the path prefix is not a directory.
57
58 EPERM The calling process did not have the required permissions (see
59 above) to change owner and/or group.
60
61 EROFS The named file resides on a read-only file system.
62
63 The general errors for fchown() are listed below:
64
65 EBADF The descriptor is not valid.
66
67 EIO A low-level I/O error occurred while modifying the inode.
68
69 ENOENT See above.
70
71 EPERM See above.
72
73 EROFS See above.
74
76 In versions of Linux prior to 2.1.81 (and distinct from 2.1.46),
77 chown() did not follow symbolic links. Since Linux 2.1.81, chown()
78 does follow symbolic links, and there is a new system call lchown()
79 that does not follow symbolic links. Since Linux 2.1.86, this new call
80 (that has the same semantics as the old chown()) has got the same
81 syscall number, and chown() got the newly introduced number.
82
83 The prototype for fchown() is only available if _BSD_SOURCE is defined.
84
86 4.4BSD, SVr4, POSIX.1-2001.
87
88 The 4.4BSD version can only be used by the superuser (that is, ordinary
89 users cannot give away files).
90
92 The chown() semantics are deliberately violated on NFS file systems
93 which have UID mapping enabled. Additionally, the semantics of all
94 system calls which access the file contents are violated, because
95 chown() may cause immediate access revocation on already open files.
96 Client side caching may lead to a delay between the time where owner‐
97 ship have been changed to allow access for a user and the time where
98 the file can actually be accessed by the user on other clients.
99
101 chmod(2), fchownat(2), flock(2), path_resolution(2)
102
103
104
105Linux 2.6.7 2004-06-23 CHOWN(2)