1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
'\" et
.TH FSTAT "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.SH NAME
fstat
\(em get file status
.SH SYNOPSIS
.LP
.nf
#include <sys/stat.h>
.P
int fstat(int \fIfildes\fP, struct stat *\fIbuf\fP);
.fi
.SH DESCRIPTION
The
\fIfstat\fR()
function shall obtain information about an open file associated with
the file descriptor
.IR fildes ,
and shall write it to the area pointed to by
.IR buf .
.P
If
.IR fildes
references a shared memory object, the implementation shall update in
the
.BR stat
structure pointed to by the
.IR buf
argument the
.IR st_uid ,
.IR st_gid ,
.IR st_size ,
and
.IR st_mode
fields, and only the S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and
S_IWOTH file permission bits need be valid.
The implementation may update other fields and flags.
.P
If
.IR fildes
references a typed memory object, the implementation shall update in
the
.BR stat
structure pointed to by the
.IR buf
argument the
.IR st_uid ,
.IR st_gid ,
.IR st_size ,
and
.IR st_mode
fields, and only the S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and
S_IWOTH file permission bits need be valid. The implementation
may update other fields and flags.
.P
The
.IR buf
argument is a pointer to a
.BR stat
structure, as defined in
.IR <sys/stat.h> ,
into which information is placed concerning the file.
.P
For all other file types defined in this volume of POSIX.1\(hy2008, the structure members
.IR st_mode ,
.IR st_ino ,
.IR st_dev ,
.IR st_uid ,
.IR st_gid ,
.IR st_atim ,
.IR st_ctim ,
and
.IR st_mtim
shall have meaningful values and the value of the
.IR st_nlink
member shall be set to the number of links to the file.
.P
An implementation that provides additional or alternative file access
control mechanisms may, under implementation-defined conditions,
cause
\fIfstat\fR()
to fail.
.P
The
\fIfstat\fR()
function shall update any time-related fields (as described in the Base Definitions volume of POSIX.1\(hy2008,
.IR "Section 4.8" ", " "File Times Update"),
before writing into the
.BR stat
structure.
.SH "RETURN VALUE"
Upon successful completion, 0 shall be returned. Otherwise, \(mi1 shall be
returned and
.IR errno
set to indicate the error.
.SH ERRORS
The
\fIfstat\fR()
function shall fail if:
.TP
.BR EBADF
The
.IR fildes
argument is not a valid file descriptor.
.TP
.BR EIO
An I/O error occurred while reading from the file system.
.TP
.BR EOVERFLOW
The file size in bytes or the number of blocks allocated to the file or
the file serial number cannot be represented correctly in the structure
pointed to by
.IR buf .
.P
The
\fIfstat\fR()
function may fail if:
.TP
.BR EOVERFLOW
One of the values is too large to store into the structure pointed to
by the
.IR buf
argument.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
.SS "Obtaining File Status Information "
.P
The following example shows how to obtain file status information for a
file named
.BR /home/cnd/mod1 .
The structure variable
.IR buffer
is defined for the
.BR stat
structure. The
.BR /home/cnd/mod1
file is opened with read/write privileges and is passed to the open
file descriptor
.IR fildes .
.sp
.RS 4
.nf
\fB
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
.P
struct stat buffer;
int status;
\&...
fildes = open("/home/cnd/mod1", O_RDWR);
status = fstat(fildes, &buffer);
.fi \fR
.P
.RE
.SH "APPLICATION USAGE"
None.
.SH RATIONALE
None.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIfstatat\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2008,
.IR "Section 4.8" ", " "File Times Update",
.IR "\fB<sys_stat.h>\fP",
.IR "\fB<sys_types.h>\fP"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.unix.org/online.html .
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|