|
Packit |
7cfc04 |
'\" et
|
|
Packit |
7cfc04 |
.TH FCHOWN "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH PROLOG
|
|
Packit |
7cfc04 |
This manual page is part of the POSIX Programmer's Manual.
|
|
Packit |
7cfc04 |
The Linux implementation of this interface may differ (consult
|
|
Packit |
7cfc04 |
the corresponding Linux manual page for details of Linux behavior),
|
|
Packit |
7cfc04 |
or the interface may not be implemented on Linux.
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
fchown
|
|
Packit |
7cfc04 |
\(em change owner and group of a file
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
#include <unistd.h>
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
int fchown(int \fIfildes\fP, uid_t \fIowner\fP, gid_t \fIgroup\fP);
|
|
Packit |
7cfc04 |
.fi
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIfchown\fR()
|
|
Packit |
7cfc04 |
function shall be equivalent to
|
|
Packit |
7cfc04 |
\fIchown\fR()
|
|
Packit |
7cfc04 |
except that the file whose owner and group are changed is
|
|
Packit |
7cfc04 |
specified by the file descriptor
|
|
Packit |
7cfc04 |
.IR fildes .
|
|
Packit |
7cfc04 |
.SH "RETURN VALUE"
|
|
Packit |
7cfc04 |
Upon successful completion,
|
|
Packit |
7cfc04 |
\fIfchown\fR()
|
|
Packit |
7cfc04 |
shall return 0. Otherwise, it shall return \(mi1 and set
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
to indicate the error.
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIfchown\fR()
|
|
Packit |
7cfc04 |
function shall fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EBADF
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR fildes
|
|
Packit |
7cfc04 |
argument is not an open file descriptor.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EPERM
|
|
Packit |
7cfc04 |
The effective user ID does not match the owner of the file or the
|
|
Packit |
7cfc04 |
process does not have appropriate privileges and _POSIX_CHOWN_RESTRICTED
|
|
Packit |
7cfc04 |
indicates that such privilege is required.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EROFS
|
|
Packit |
7cfc04 |
The file referred to by
|
|
Packit |
7cfc04 |
.IR fildes
|
|
Packit |
7cfc04 |
resides on a read-only file system.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIfchown\fR()
|
|
Packit |
7cfc04 |
function may fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EINVAL
|
|
Packit |
7cfc04 |
The owner or group ID is not a value supported by the implementation.
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR fildes
|
|
Packit |
7cfc04 |
argument refers to a pipe or socket
|
|
Packit |
7cfc04 |
or an
|
|
Packit |
7cfc04 |
\fIfattach\fR()-ed
|
|
Packit |
7cfc04 |
STREAM
|
|
Packit |
7cfc04 |
and the implementation disallows execution of
|
|
Packit |
7cfc04 |
\fIfchown\fR()
|
|
Packit |
7cfc04 |
on a pipe.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EIO
|
|
Packit |
7cfc04 |
A physical I/O error has occurred.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EINTR
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIfchown\fR()
|
|
Packit |
7cfc04 |
function was interrupted by a signal which was caught.
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.IR "The following sections are informative."
|
|
Packit |
7cfc04 |
.SH EXAMPLES
|
|
Packit |
7cfc04 |
.SS "Changing the Current Owner of a File"
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The following example shows how to change the owner of a file named
|
|
Packit |
7cfc04 |
.BR /home/cnd/mod1
|
|
Packit |
7cfc04 |
to ``jones'' and the group to ``cnd''.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The numeric value for the user ID is obtained by extracting the user ID
|
|
Packit |
7cfc04 |
from the user database entry associated with ``jones''. Similarly, the
|
|
Packit |
7cfc04 |
numeric value for the group ID is obtained by extracting the group ID
|
|
Packit |
7cfc04 |
from the group database entry associated with ``cnd''. This example
|
|
Packit |
7cfc04 |
assumes the calling program has appropriate privileges.
|
|
Packit |
7cfc04 |
.sp
|
|
Packit |
7cfc04 |
.RS 4
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
\fB
|
|
Packit |
7cfc04 |
#include <sys/types.h>
|
|
Packit |
7cfc04 |
#include <unistd.h>
|
|
Packit |
7cfc04 |
#include <fcntl.h>
|
|
Packit |
7cfc04 |
#include <pwd.h>
|
|
Packit |
7cfc04 |
#include <grp.h>
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
struct passwd *pwd;
|
|
Packit |
7cfc04 |
struct group *grp;
|
|
Packit |
7cfc04 |
int fildes;
|
|
Packit |
7cfc04 |
\&...
|
|
Packit |
7cfc04 |
fildes = open("/home/cnd/mod1", O_RDWR);
|
|
Packit |
7cfc04 |
pwd = getpwnam("jones");
|
|
Packit |
7cfc04 |
grp = getgrnam("cnd");
|
|
Packit |
7cfc04 |
fchown(fildes, pwd->pw_uid, grp->gr_gid);
|
|
Packit |
7cfc04 |
.fi \fR
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.SH "APPLICATION USAGE"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH RATIONALE
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "FUTURE DIRECTIONS"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "SEE ALSO"
|
|
Packit |
7cfc04 |
.IR "\fIchown\fR\^(\|)"
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The Base Definitions volume of POSIX.1\(hy2008,
|
|
Packit |
7cfc04 |
.IR "\fB<unistd.h>\fP"
|
|
Packit |
7cfc04 |
.SH COPYRIGHT
|
|
Packit |
7cfc04 |
Portions of this text are reprinted and reproduced in electronic form
|
|
Packit |
7cfc04 |
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
|
|
Packit |
7cfc04 |
-- Portable Operating System Interface (POSIX), The Open Group Base
|
|
Packit |
7cfc04 |
Specifications Issue 7, Copyright (C) 2013 by the Institute of
|
|
Packit |
7cfc04 |
Electrical and Electronics Engineers, Inc and The Open Group.
|
|
Packit |
7cfc04 |
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
|
|
Packit |
7cfc04 |
event of any discrepancy between this version and the original IEEE and
|
|
Packit |
7cfc04 |
The Open Group Standard, the original IEEE and The Open Group Standard
|
|
Packit |
7cfc04 |
is the referee document. The original Standard can be obtained online at
|
|
Packit |
7cfc04 |
http://www.unix.org/online.html .
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
Any typographical or formatting errors that appear
|
|
Packit |
7cfc04 |
in this page are most likely
|
|
Packit |
7cfc04 |
to have been introduced during the conversion of the source files to
|
|
Packit |
7cfc04 |
man page format. To report such errors, see
|
|
Packit |
7cfc04 |
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|