Manual Page Result
0
Command: stat | Section: 2 | Source: UNIX v10 | File: stat.2
STAT(2) System Calls Manual STAT(2)
NAME
stat, lstat, fstat - get file status
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
int stat(name, buf)
char *name;
struct stat *buf;
int lstat(name, buf)
char *name;
struct stat *buf;
int fstat(fildes, buf)
struct stat *buf;
DESCRIPTION
Stat puts detailed information about the file name in a structure whose
address is buf. Lstat does the same except that when name is a sym-
bolic link (see link(2)), it supplies information about the link it-
self. Fstat does what stat does for the file open on descriptor
fildes.
It is unnecessary to have any permissions at all with respect to name,
but all directories leading to the file must be searchable.
struct stat
{
dev_t st_dev; device number for this file system
ino_t st_ino; inode number
unsigned short st_mode; file mode encoded as below
short st_nlink; number of links (not symbolic links)
short st_uid; uid of owner
short st_gid; gid of owner
dev_t st_rdev; if device file, the device number
off_t st_size; size in bytes
time_t st_atime; time file was last read or created
time_t st_mtime; time file was last written or created
time_t st_ctime; time file or inode was last written or created
};
The bits in st_mode are defined by
S_IFMT 0170000 file type
S_IFDIR 0040000 directory
S_IFCHR 0020000 character device
S_IFBLK 0060000 block device
S_IFREG 0100000 regular file
S_IFLNK 0120000 symbolic link
S_ISUID 0004000 set userid on execution
S_ISGID 0002000 set groupid on execution
S_ICCTYP 0007000 type of concurrency control
S_ISYNC 0001000 1 writer and n readers (synchronized access)
S_IEXCL 0003000 1 writer or n readers (exclusive access)
0000400 read permission by owner
0000200 write permission by owner
0000100 execute permission (search on directory) by owner
0000070 read, write, execute (search) by group
0000007 read, write, execute (search) by others
S_IFMT and S_ICCTYP are field masks; the other constants encode modes.
Codes contained in the S_IFMT field are mutually exclusive. If bit is
set, the concurrency modes contained in S_ICCTYP are in effect; other-
wise the set-id flags S_ISUID and S_ISGID apply.
The concurrency modes affect open and creat calls. Synchronized ac-
cess, S_ISYNC, guards against inconsistent updates by forbidding con-
current opens for writing. Exclusive access, S_IEXCL, guards against
inconsistent views by forbidding concurrent opens if one is for writ-
ing.
SEE ALSO
chmod(1), ls(1), chmod(2), filsys(5)
DIAGNOSTICS
stat, lstat: EACCES, EFAULT, EIO, ELOOP, ENOENT, ENOTDIR
fstat: EBADF, EFAULT, EIO
BUGS
For efficiency, st_atime is not set when a directory is searched, al-
though this might be more logical.
STAT(2)