summaryrefslogtreecommitdiff
path: root/reference/C/MAN/stat.htm
blob: 37ba91b5f78bc3d689545b4ee9a8f663f92e3c33 (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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<TITLE>stat</TITLE>
<body bgcolor="#ffffcc">
<hr>
<pre>



<h3>STAT(2)             Linux Programmer's Manual             STAT(2)
</h3>

<h3>NAME
</h3>       stat, fstat, lstat - get file status

<h3>SYNOPSIS
</h3>       #include &lt;sys/stat.h&gt;
       #include &lt;unistd.h&gt;

       int stat(const char *file_name, struct stat *buf);
       int fstat(int filedes, struct stat *buf);
       int lstat(const char *file_name, struct stat *buf);

<h3>DESCRIPTION
</h3>       These  functions  return  information  about the specified
       file.  You do not need any access rights to  the  file  to
       get  this  information  but  you need search rights to all
       directories named in the path leading to the file.

       stat stats the file pointed to by file_name and  fills  in
       buf.

       lstat  is  identical  to  stat,  only  the  link itself is
       stated, not the file  that  is  obtained  by  tracing  the
       links.

       fstat  is identical to stat, only the open file pointed to
       by filedes (as returned by fopen(3) ) is stated  in  place
       of file_name.


       They  all  return  a  stat structure, which is declared as
       follows:

              struct stat
              {
                  dev_t         st_dev;      /* device */
                  ino_t         st_ino;      /* inode */
                  umode_t       st_mode;     /* protection */
                  nlink_t       st_nlink;    /* number of hard links */
                  uid_t         st_uid;      /* user ID of owner */
                  gid_t         st_gid;      /* group ID of owner */
                  dev_t         st_rdev;     /* device type (if inode device) */
                  off_t         st_size;     /* total size, in bytes */
                  unsigned long st_blksize;  /* blocksize for filesystem I/O */
                  unsigned long st_blocks;   /* number of blocks allocated */
                  time_t        st_atime;    /* time of last access */
                  time_t        st_mtime;    /* time of last modification */
                  time_t        st_ctime;    /* time of last change */
              };

       Note that st_blocks may not always be in terms  of  blocks
       of  size  st_blksize, and that st_blksize may instead pro-
       vide a notion of the "preferred" blocksize  for  efficient
       file system I/O.




<h3>Linux 1.1.75              1 January 1995                        1
</h3>




<h3>STAT(2)             Linux Programmer's Manual             STAT(2)
</h3>

       Not all of the Linux filesystems implement all of the time
       fields.  Traditionally, st_atime is changed  by  mknod(2),
       utime(2), read(2), write(2), and truncate(2).

       Traditionally,  st_mtime is changed by mknod(2), utime(2),
       and write(2).  The st_mtime is not changed for changes  in
       owner, group, hard link count, or mode.

       Traditionally,  st_ctime  is changed by writing or by set-
       ting inode information (i.e., owner,  group,  link  count,
       mode, etc.).

       The following macros are defined to check the file type:

              S_ISLNK(m)  is it a symbolic link

              S_ISREG(m)  regular file

              S_ISDIR(m)  directory

              S_ISCHR(m)  character device

              S_ISBLK(m)  block device

              S_ISFIFO(m) fifo

              S_ISSOCK(m) socket

       The following flags are defined for the st_mode field:

              S_IFMT   00170000  bitmask  for  the file type bit-
                       fields

              S_IFSOCK 0140000 socket

              S_IFLNK  0120000 symbolic link

              S_IFREG  0100000 regular file

              S_IFBLK  0060000 block device

              S_IFDIR  0040000 directory

              S_IFCHR  0020000 character device

              S_IFIFO  0010000 fifo

              S_ISUID  0004000 set UID bit

              S_ISGID  0002000 set GID bit

              S_ISVTX  0001000 sticky bit

              S_IRWXU  00700 user (file owner)  has  read,  write



<h3>Linux 1.1.75              1 January 1995                        2
</h3>




<h3>STAT(2)             Linux Programmer's Manual             STAT(2)
</h3>

                       and execute permission

              S_IRUSR (S_IREAD)
                       00400 user has read permission

              S_IWUSR (S_IWRITE)
                       00200 user has write permission

              S_IXUSR (S_IEXEC)
                       00100 user has execute permission

              S_IRWXG  00070  group  has  read, write and execute
                       permission

              S_IRGRP  00040 group has read permission

              S_IWGRP  00020 group has write permission

              S_IXGRP  00010 group has execute permission

              S_IRWXO  00007 others have read, write and  execute
                       permission

              S_IROTH  00004 others have read permission

              S_IWOTH  00002 others have write permisson

              S_IXOTH  00001 others have execute permission

<h3>RETURN VALUE
</h3>       On  success,  zero is returned.  On error, -1 is returned,
       and errno is set appropriately.

<h3>ERRORS
</h3>       EBADF   filedes is bad.

       ENOENT  File does not exist.

<h3>CONFORMING TO
</h3>       SVID  (not  lstat()),  AT&T  (not  lstat()),  POSIX   (not
       lstat()), X/OPEN (not lstat()), BSD 4.3

</pre>
<hr>
<h3>SEE ALSO
</h3><p>
<a href=chmod.htm>chmod</a>, 
<a href=chown.htm>chown</a>, 
<a href=readlink.htm>readlink</a>, 
<a href=utime.htm>utime</a>, 
<pre>













<h3>Linux 1.1.75              1 January 1995                        3
</h3>


</pre>
<P>
<hr>
<p>
<center>
<table border=2 width=80%>
<tr align=center>
<td width=25%>
<a href=../cref.html>Top</a>
</td><td width=25%>
<a href=../master_index.html>Master Index</a>
</td><td width=25%>
<a href=../SYNTAX/keywords.html>Keywords</a>
</td><td width=25%>
<a href=../FUNCTIONS/funcref.htm>Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>

This manual page was brought to you by <i>mjl_man V-2.0</i>