summaryrefslogtreecommitdiff
path: root/static/v10/man2/stat.2
blob: 03d25626630c8ff6184b6394c169b5a8ffd53cbf (plain)
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
.TH STAT 2
.CT 2 file_inq_creat
.SH NAME
stat, lstat, fstat \(mi get file status
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.B #include <sys/stat.h>
.PP
.B int stat(name, buf)
.B char *name;
.B struct stat *buf;
.PP
.B int lstat(name, buf)
.B char *name;
.B struct stat *buf;
.PP
.B int fstat(fildes, buf)
.B struct stat *buf;
.fi
.SH DESCRIPTION
.I Stat
puts detailed information about the file
.I name
in a structure whose address is
.IR buf .
.I Lstat
does the same except when
.I name
is a symbolic
link (see
.IR link (2)),
in which case it
supplies information about the link itself.
.I Fstat
does the same for an open file
known by a file descriptor.
.PP
It is unnecessary to have any
permissions at all with respect to
.IR name ,
but all directories
leading to the file must be searchable.
.nf
.ta \w'\fLnnnnnnnn\fP'u +\w'\fLunsigned short st_mode; \fP'u
\fLstruct stat
{
	\fLdev_t st_dev;\fR	major/minor device numbers for the inode
	\fLino_t st_ino;\fP	inode number
	\fLunsigned short st_mode;\fP	file mode encoded as below
	\fLshort st_nlink;\fP	number of links (not symbolic links)
	\fLshort st_uid;\fP	uid of owner
	\fLshort st_gid;\fP	gid of owner
	\fLdev_t st_rdev;\fP	if special, the major/minor device numbers
	\fLoff_t st_size;\fP	size in bytes
	\fLtime_t st_atime;\fP	time file was last read or created
	\fLtime_t st_mtime;\fP	time file was last written or created
	\fLtime_t st_ctime;\fP	time file or inode was last written or created
\fL};\fP
.fi
.PP
For reasons of efficiency,
.B st_atime
is not set when a directory
is searched, although this might be more logical.
.PP
The bits in
.B st_mode
are defined by
.nf
.ft L
.ta 12n 22n
.ft P
\fLS_IFMT	0170000\fP	file type
\fLS_IFDIR	0040000\fP	directory
\fLS_IFCHR	0020000\fP	special character device
\fLS_IFBLK	0060000\fP	special block device
\fLS_IFREG	0100000\fP	regular file
\fLS_IFLNK	0120000\fP	symbolic link
\fLS_ISUID	0004000\fP	set userid on execution
\fLS_ISGID	0002000\fP	set groupid on execution
\fLS_ICCTYP	0007000\fP	type of concurrency control
\fLS_ISYNC	0001000\fP	1 writer and n readers (synchronized access)
\fLS_IEXCL	0003000\fP	1 writer or n readers (exclusive access)
\fLS_IAPPEND	0005000\fP	append-only file
\fLS_IBLIND	0007000\fP	blind directory
\fL	0000400\fP	read by owner
\fL	0000200\fP	write by owner
\fL	0000100\fP	execute (search on directory) by owner
\fL	0000070\fP	read, write, execute (search) by group
\fL	0000007\fP	read, write, execute (search) by others
.fi
.PP
.B S_IFMT
and
.B S_ICCTYP
are field masks; the other constants encode modes.
Codes contained in the 
.B S_IFMT
field are mutually exclusive.
Codes containing bit 01000 are incompatible with other
codes contained in the
.B S_ICCTYP
field.
.PP
.I Fstat,
which reads the inode,
and
.IR write (2)
can be performed on the same file descriptor only if
the security labels of file and process reach the same value
or if the process has capability
.BR T_NOCHK .
.SH "SEE ALSO"
.IR chmod (1), 
.IR ls (1), 
.IR stat (1),
.IR chmod (2), 
.IR filsys (5)
.SH DIAGNOSTICS
.BR EACCES ,
.BR EBADF ,
.BR EFAULT ,
.BR EIO ,
.BR ELAB ,
.BR ELOOP ,
.BR ENOENT ,
.BR ENOTDIR