#include <unistd.h> int chown(const char *path, uid_t owner, gid_t group);Service Program Name: QP0LLIB1
The chown() function changes the owner and primary group of a file. If the named file is a symbolic link, chown() resolves the symbolic link. The permissions of the previous owner or primary group to the object are revoked.
If the file is checked out by another user (someone other than the user profile of the current job), chown() fails with the [EBUSY] error.
When chown() completes successfully, it updates the change time of the file.
(Input) A pointer to the null-terminated path name of the file whose owner and group are being changed.
This parameter is assumed to be represented in the CCSID (coded character set identifier) currently in effect for the job. If the CCSID of the job is 65535, this parameter is assumed to be represented in the default CCSID of the job.
See QlgChown()--Change Owner and Group of File for a description and an example of supplying the path in any CCSID.
(Input) The user ID (UID) of the new owner of the file.
(Input) The group ID (GID) of the new primary group for the file.
The new primary group user cannot be the owner of the object.
Note: Changing the owner or the primary group causes the S_ISUID (set-user-ID) and S_ISGID (set-group-ID) bits of the file mode to be cleared, unless the caller has all object (*ALLOBJ) special authority. If the caller does have *ALLOBJ special authority, the bits are not changed. This does not apply to directories or FIFO special files. See the chmod() documentation.
Note: Adopted authority is not used.
Authorization Required for chown() (excluding QSYS.LIB, independent ASP QSYS.LIB, and QDLS)
Object Referred to | Authority Required | errno |
---|---|---|
Each directory in the path name preceding the object | *X | EACCES |
Object, when changing the owner | Owner and *OBJEXIST (also see Note 1) |
EPERM |
Object, when changing the primary group | See Note 2 | EPERM |
Previous owner's user profile, when changing the owner | *DLT | EPERM |
New owner's user profile, when changing the owner | *ADD | EPERM |
User profile of previous primary group, when changing the primary group | *DLT | EPERM |
New primary group's user profile, when changing the primary group | *ADD | EPERM |
Note:
|
Authorization Required for chown() in the QSYS.LIB and independent ASP QSYS.LIB File Systems
Object Referred to | Authority Required | errno |
---|---|---|
Each directory in the path name preceding the object | *X See Note 1 |
EACCES |
Object when changing the owner | See Note 2(a) | EPERM |
Object when changing the primary group | See Note 2(b) | EPERM |
Note:
|
Authorization Required for chown() in the QDLS File System
Object Referred to | Authority Required | errno |
---|---|---|
Each directory in the path name preceding the object | *X | EACCES |
Object | *ALLOBJ Special Authority or Owner |
EPERM |
Previous owner's user profile, when changing the owner | *DLT | EPERM |
New owner's user profile, when changing the owner | *ADD | EPERM |
Previous primary group's user profile, when changing the primary group | *DLT | EPERM |
New primary group's user profile, when changing the primary group | *ADD | EPERM |
Authorization Required for chown() in the QOPT File System
Object Referred to | Authority Required | errno |
---|---|---|
Volume authorization list | *CHANGE | EACCES |
Each directory in the path name preceding the object. | *X | EACCES |
Object | *ALLOBJ Special Authority or Owner |
EPERM |
If chown() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
Error condition | Additional information |
---|---|
[EACCES] |
If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems. |
[EAGAIN] | |
[EBADFID] | |
[EBADNAME] | |
[EBUSY] | |
[ECONVERT] | |
[EDAMAGE] | |
[EFAULT] | |
[EFILECVT] | |
[EINTR] | |
[EINVAL] |
The owner or group is not a valid user ID (UID) or group ID (GID). The owner is the current primary group of the object. |
[EIO] | |
[EJRNDAMAGE] | |
[EJRNENTTOOLONG] | |
[EJRNINACTIVE] | |
[EJRNRCVSPC] | |
[ELOOP] | |
[ENAMETOOLONG] | |
[ENEWJRN] | |
[ENEWJRNRCV] | |
[ENOENT] | |
[ENOSPC] | |
[ENOTAVAIL] | |
[ENOTDIR] | |
[ENOTSAFE] | |
[ENOTSUP] | |
[EPERM] | |
[EROOBJ] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[EUNKNOWN] |
The following messages may be sent from this API:
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPFA0D4 E | File system error occurred. Error number &1. |
CPF3CF2 E | Error(s) occurred during running of &1 API. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
chown() is not supported for member (.MBR) objects.
The owner and primary group of the /QDLS directory (root folder) cannot be changed. If an attempt is made to change the owner and primary group, error ENOTSUP error is returned.
Changing the owner and primary group is allowed only for an object that exists on a volume formatted in Universal Disk Format (UDF). For all other media formats, ENOTSUP will be returned.
QOPT file system objects that have owners will not be recognized by the Work with Objects by Owner (WRKOBJOWN) CL command. Likewise, QOPT objects that have a primary group will not be recognized by the Work Objects by Primary Group) CL command.
The QFileSvr.400 file system does not support chown().
The QNetWare file system does not support primary group. The GID must be zero.
The owner of files and directories cannot be changed. All files and directories in QNTC are owned by the QDFTOWN user profile.
See Code disclaimer information for information pertaining to code examples.
The following example changes the owner and group of a file:
#include <stdio.h> #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> main() { char fn[]="temp.file"; int file_descriptor; struct stat info; if ((file_descriptor = creat(fn, S_IRWXU)) == -1) perror("creat() error"); else { close(file_descriptor); stat(fn, &info); printf("original owner was %d and group was %d\n", info.st_uid, info.st_gid); if (chown(fn, 152, 0) != 0) perror("chown() error"); else { stat(fn, &info); printf("after chown(), owner is %d and group is %d\n", info.st_uid, info.st_gid); } unlink(fn); } }
Output:
original owner was 137 and group was 0 after chown(), owner is 152 and group is 0
Top | UNIX-Type APIs | APIs by category |