-
Notifications
You must be signed in to change notification settings - Fork 0
/
oldstat.html
799 lines (595 loc) · 23.6 KB
/
oldstat.html
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:26:50 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>STAT</title>
</head>
<body>
<h1 align="center">STAT</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#VERSIONS">VERSIONS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#EXAMPLE">EXAMPLE</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">stat, fstat,
lstat, fstatat - get file status</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<sys/types.h> <br>
#include <sys/stat.h> <br>
#include <unistd.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
stat(const char *</b><i>pathname</i><b>, struct stat
*</b><i>statbuf</i><b>); <br>
int fstat(int</b> <i>fd</i><b>, struct stat
*</b><i>statbuf</i><b>); <br>
int lstat(const char *</b><i>pathname</i><b>, struct stat
*</b><i>statbuf</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<fcntl.h></b> /* Definition of AT_* constants */
<b><br>
#include <sys/stat.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
fstatat(int</b> <i>dirfd</i><b>, const char
*</b><i>pathname</i><b>, struct stat *</b><i>statbuf</i><b>,
<br>
int</b> <i>flags</i><b>);</b></p>
<p style="margin-left:5%; margin-top: 1em">Feature Test
Macro Requirements for glibc (see
<b>feature_test_macros</b>(7)):</p>
<p style="margin-left:11%; margin-top: 1em"><b>lstat</b>():</p>
<p style="margin-left:17%;">/* glibc 2.19 and earlier */
_BSD_SOURCE <br>
|| /* Since glibc 2.20 */ _DEFAULT_SOURCE <br>
|| _XOPEN_SOURCE >= 500 <br>
|| /* Since glibc 2.10: */
_POSIX_C_SOURCE >= 200112L</p>
<p style="margin-left:11%; margin-top: 1em"><b>fstatat</b>():</p>
<p style="margin-left:17%;">Since glibc 2.10:</p>
<p style="margin-left:23%;">_POSIX_C_SOURCE >= 200809L</p>
<p style="margin-left:17%;">Before glibc 2.10:</p>
<p style="margin-left:23%;">_ATFILE_SOURCE</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">These functions
return information about a file, in the buffer pointed to by
<i>statbuf</i>. No permissions are required on the file
itself, but—in the case of <b>stat</b>(),
<b>fstatat</b>(), and <b>lstat</b>()—execute (search)
permission is required on all of the directories in
<i>pathname</i> that lead to the file.</p>
<p style="margin-left:11%; margin-top: 1em"><b>stat</b>()
and <b>fstatat</b>() retrieve information about the file
pointed to by <i>pathname</i>; the differences for
<b>fstatat</b>() are described below.</p>
<p style="margin-left:11%; margin-top: 1em"><b>lstat</b>()
is identical to <b>stat</b>(), except that if
<i>pathname</i> is a symbolic link, then it returns
information about the link itself, not the file that it
refers to.</p>
<p style="margin-left:11%; margin-top: 1em"><b>fstat</b>()
is identical to <b>stat</b>(), except that the file about
which information is to be retrieved is specified by the
file descriptor <i>fd</i>.</p>
<p style="margin-left:11%; margin-top: 1em"><b>The stat
structure</b> <br>
All of these system calls return a <i>stat</i> structure,
which contains the following fields:</p>
<p style="margin-left:17%; margin-top: 1em">struct stat {
<br>
dev_t st_dev; /* ID of device containing file */ <br>
ino_t st_ino; /* Inode number */ <br>
mode_t st_mode; /* File type and mode */ <br>
nlink_t st_nlink; /* Number of hard links */ <br>
uid_t st_uid; /* User ID of owner */ <br>
gid_t st_gid; /* Group ID of owner */ <br>
dev_t st_rdev; /* Device ID (if special file) */ <br>
off_t st_size; /* Total size, in bytes */ <br>
blksize_t st_blksize; /* Block size for filesystem I/O */
<br>
blkcnt_t st_blocks; /* Number of 512B blocks allocated
*/</p>
<p style="margin-left:17%; margin-top: 1em">/* Since Linux
2.6, the kernel supports nanosecond <br>
precision for the following timestamp fields. <br>
For the details before Linux 2.6, see NOTES. */</p>
<p style="margin-left:17%; margin-top: 1em">struct timespec
st_atim; /* Time of last access */ <br>
struct timespec st_mtim; /* Time of last modification */
<br>
struct timespec st_ctim; /* Time of last status change
*/</p>
<p style="margin-left:17%; margin-top: 1em">#define
st_atime st_atim.tv_sec /* Backward compatibility */ <br>
#define st_mtime st_mtim.tv_sec <br>
#define st_ctime st_ctim.tv_sec <br>
};</p>
<p style="margin-left:11%; margin-top: 1em"><i>Note</i>:
the order of fields in the <i>stat</i> structure varies
somewhat across architectures. In addition, the definition
above does not show the padding bytes that may be present
between some fields on various architectures. Consult the
glibc and kernel source code if you need to know the
details.</p>
<p style="margin-left:11%; margin-top: 1em"><i>Note</i>:
for performance and simplicity reasons, different fields in
the <i>stat</i> structure may contain state information from
different moments during the execution of the system call.
For example, if <i>st_mode</i> or <i>st_uid</i> is changed
by another process by calling <b>chmod</b>(2) or
<b>chown</b>(2), <b>stat</b>() might return the old
<i>st_mode</i> together with the new <i>st_uid</i>, or the
old <i>st_uid</i> together with the new <i>st_mode</i>.</p>
<p style="margin-left:11%; margin-top: 1em">The fields in
the <i>stat</i> structure are as follows:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><i>st_dev</i></p></td>
<td width="2%"></td>
<td width="78%">
<p>This field describes the device on which this file
resides. (The <b>major</b>(3) and <b>minor</b>(3) macros may
be useful to decompose the device ID in this field.)</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><i>st_ino</i></p></td>
<td width="2%"></td>
<td width="78%">
<p>This field contains the file’s inode number.</p></td></tr>
</table>
<p style="margin-left:11%;"><i>st_mode</i></p>
<p style="margin-left:22%;">This field contains the file
type and mode. See <b>inode</b>(7) for further
information.</p>
<p style="margin-left:11%;"><i>st_nlink</i></p>
<p style="margin-left:22%;">This field contains the number
of hard links to the file.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><i>st_uid</i></p></td>
<td width="2%"></td>
<td width="78%">
<p>This field contains the user ID of the owner of the
file.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><i>st_gid</i></p></td>
<td width="2%"></td>
<td width="78%">
<p>This field contains the ID of the group owner of the
file.</p> </td></tr>
</table>
<p style="margin-left:11%;"><i>st_rdev</i></p>
<p style="margin-left:22%;">This field describes the device
that this file (inode) represents.</p>
<p style="margin-left:11%;"><i>st_size</i></p>
<p style="margin-left:22%;">This field gives the size of
the file (if it is a regular file or a symbolic link) in
bytes. The size of a symbolic link is the length of the
pathname it contains, without a terminating null byte.</p>
<p style="margin-left:11%;"><i>st_blksize</i></p>
<p style="margin-left:22%;">This field gives the
"preferred" block size for efficient filesystem
I/O.</p>
<p style="margin-left:11%;"><i>st_blocks</i></p>
<p style="margin-left:22%;">This field indicates the number
of blocks allocated to the file, in 512-byte units. (This
may be smaller than <i>st_size</i>/512 when the file has
holes.)</p>
<p style="margin-left:11%;"><i>st_atime</i></p>
<p style="margin-left:22%;">This is the file’s last
access timestamp.</p>
<p style="margin-left:11%;"><i>st_mtime</i></p>
<p style="margin-left:22%;">This is the file’s last
modification timestamp.</p>
<p style="margin-left:11%;"><i>st_ctime</i></p>
<p style="margin-left:22%;">This is the file’s last
status change timestamp.</p>
<p style="margin-left:11%; margin-top: 1em">For further
information on the above fields, see <b>inode</b>(7).</p>
<p style="margin-left:11%; margin-top: 1em"><b>fstatat()</b>
<br>
The <b>fstatat</b>() system call is a more general interface
for accessing file information which can still provide
exactly the behavior of each of <b>stat</b>(),
<b>lstat</b>(), and <b>fstat</b>().</p>
<p style="margin-left:11%; margin-top: 1em">If the pathname
given in <i>pathname</i> is relative, then it is interpreted
relative to the directory referred to by the file descriptor
<i>dirfd</i> (rather than relative to the current working
directory of the calling process, as is done by
<b>stat</b>() and <b>lstat</b>() for a relative
pathname).</p>
<p style="margin-left:11%; margin-top: 1em">If
<i>pathname</i> is relative and <i>dirfd</i> is the special
value <b>AT_FDCWD</b>, then <i>pathname</i> is interpreted
relative to the current working directory of the calling
process (like <b>stat</b>() and <b>lstat</b>()).</p>
<p style="margin-left:11%; margin-top: 1em">If
<i>pathname</i> is absolute, then <i>dirfd</i> is
ignored.</p>
<p style="margin-left:11%; margin-top: 1em"><i>flags</i>
can either be 0, or include one or more of the following
flags ORed: <b><br>
AT_EMPTY_PATH</b> (since Linux 2.6.39)</p>
<p style="margin-left:22%;">If <i>pathname</i> is an empty
string, operate on the file referred to by <i>dirfd</i>
(which may have been obtained using the <b>open</b>(2)
<b>O_PATH</b> flag). In this case, <i>dirfd</i> can refer to
any type of file, not just a directory, and the behavior of
<b>fstatat</b>() is similar to that of <b>fstat</b>(). If
<i>dirfd</i> is <b>AT_FDCWD</b>, the call operates on the
current working directory. This flag is Linux-specific;
define <b>_GNU_SOURCE</b> to obtain its definition.</p>
<p style="margin-left:11%;"><b>AT_NO_AUTOMOUNT</b> (since
Linux 2.6.38)</p>
<p style="margin-left:22%;">Don’t automount the
terminal ("basename") component of <i>pathname</i>
if it is a directory that is an automount point. This allows
the caller to gather attributes of an automount point
(rather than the location it would mount). Since Linux 4.14,
also don’t instantiate a nonexistent name in an
on-demand directory such as used for automounter indirect
maps. This flag can be used in tools that scan directories
to prevent mass-automounting of a directory of automount
points. The <b>AT_NO_AUTOMOUNT</b> flag has no effect if the
mount point has already been mounted over. This flag is
Linux-specific; define <b>_GNU_SOURCE</b> to obtain its
definition. Both <b>stat</b>() and <b>lstat</b>() act as
though <b>AT_NO_AUTOMOUNT</b> was set.</p>
<p style="margin-left:11%;"><b>AT_SYMLINK_NOFOLLOW</b></p>
<p style="margin-left:22%;">If <i>pathname</i> is a
symbolic link, do not dereference it: instead return
information about the link itself, like <b>lstat</b>(). (By
default, <b>fstatat</b>() dereferences symbolic links, like
<b>stat</b>().)</p>
<p style="margin-left:11%; margin-top: 1em">See
<b>openat</b>(2) for an explanation of the need for
<b>fstatat</b>().</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
zero is returned. On error, -1 is returned, and <i>errno</i>
is set appropriately.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EACCES</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">Search permission is denied for
one of the directories in the path prefix of
<i>pathname</i>. (See also <b>path_resolution</b>(7).)</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EBADF</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>fd</i> is not a valid open file descriptor.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EFAULT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Bad address.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ELOOP</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Too many symbolic links encountered while traversing the
path.</p> </td></tr>
</table>
<p style="margin-left:11%;"><b>ENAMETOOLONG</b></p>
<p style="margin-left:22%;"><i>pathname</i> is too
long.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOENT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>A component of <i>pathname</i> does not exist or is a
dangling symbolic link.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOENT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>pathname</i> is an empty string and
<b>AT_EMPTY_PATH</b> was not specified in <i>flags</i>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOMEM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Out of memory (i.e., kernel memory).</p></td></tr>
</table>
<p style="margin-left:11%;"><b>ENOTDIR</b></p>
<p style="margin-left:22%;">A component of the path prefix
of <i>pathname</i> is not a directory.</p>
<p style="margin-left:11%;"><b>EOVERFLOW</b></p>
<p style="margin-left:22%;"><i>pathname</i> or <i>fd</i>
refers to a file whose size, inode number, or number of
blocks cannot be represented in, respectively, the types
<i>off_t</i>, <i>ino_t</i>, or <i>blkcnt_t</i>. This error
can occur when, for example, an application compiled on a
32-bit platform without <i>-D_FILE_OFFSET_BITS=64</i> calls
<b>stat</b>() on a file whose size exceeds
<i>(1<<31)-1</i> bytes.</p>
<p style="margin-left:11%; margin-top: 1em">The following
additional errors can occur for <b>fstatat</b>():</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EBADF</b></p></td>
<td width="2%"></td>
<td width="56%">
<p><i>dirfd</i> is not a valid file descriptor.</p></td>
<td width="22%">
</td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="56%">
<p>Invalid flag specified in <i>flags</i>.</p></td>
<td width="22%">
</td></tr>
</table>
<p style="margin-left:11%;"><b>ENOTDIR</b></p>
<p style="margin-left:22%;"><i>pathname</i> is relative and
<i>dirfd</i> is a file descriptor referring to a file other
than a directory.</p>
<h2>VERSIONS
<a name="VERSIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>fstatat</b>()
was added to Linux in kernel 2.6.16; library support was
added to glibc in version 2.4.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>stat</b>(),
<b>fstat</b>(), <b>lstat</b>(): SVr4, 4.3BSD, POSIX.1-2001,
POSIX.1.2008.</p>
<p style="margin-left:11%; margin-top: 1em"><b>fstatat</b>():
POSIX.1-2008.</p>
<p style="margin-left:11%; margin-top: 1em">According to
POSIX.1-2001, <b>lstat</b>() on a symbolic link need return
valid information only in the <i>st_size</i> field and the
file type of the <i>st_mode</i> field of the <i>stat</i>
structure. POSIX.1-2008 tightens the specification,
requiring <b>lstat</b>() to return valid information in all
fields except the mode bits in <i>st_mode</i>.</p>
<p style="margin-left:11%; margin-top: 1em">Use of the
<i>st_blocks</i> and <i>st_blksize</i> fields may be less
portable. (They were introduced in BSD. The interpretation
differs between systems, and possibly on a single system
when NFS mounts are involved.)</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>Timestamp
fields</b> <br>
Older kernels and older standards did not support nanosecond
timestamp fields. Instead, there were three timestamp
fields—<i>st_atime</i>, <i>st_mtime</i>, and
<i>st_ctime</i>—typed as <i>time_t</i> that recorded
timestamps with one-second precision.</p>
<p style="margin-left:11%; margin-top: 1em">Since kernel
2.5.48, the <i>stat</i> structure supports nanosecond
resolution for the three file timestamp fields. The
nanosecond components of each timestamp are available via
names of the form <i>st_atim.tv_nsec</i>, if suitable
feature test macros are defined. Nanosecond timestamps were
standardized in POSIX.1-2008, and, starting with version
2.12, glibc exposes the nanosecond component names if
<b>_POSIX_C_SOURCE</b> is defined with the value 200809L or
greater, or <b>_XOPEN_SOURCE</b> is defined with the value
700 or greater. Up to and including glibc 2.19, the
definitions of the nanoseconds components are also defined
if <b>_BSD_SOURCE</b> or <b>_SVID_SOURCE</b> is defined. If
none of the aforementioned macros are defined, then the
nanosecond values are exposed with names of the form
<i>st_atimensec</i>.</p>
<p style="margin-left:11%; margin-top: 1em"><b>C
library/kernel differences</b> <br>
Over time, increases in the size of the <i>stat</i>
structure have led to three successive versions of
<b>stat</b>(): <i>sys_stat</i>() (slot <i>__NR_oldstat</i>),
<i>sys_newstat</i>() (slot <i>__NR_stat</i>), and
<i>sys_stat64()</i> (slot <i>__NR_stat64</i>) on 32-bit
platforms such as i386. The first two versions were already
present in Linux 1.0 (albeit with different names); the last
was added in Linux 2.4. Similar remarks apply for
<b>fstat</b>() and <b>lstat</b>().</p>
<p style="margin-left:11%; margin-top: 1em">The
kernel-internal versions of the <i>stat</i> structure dealt
with by the different versions are, respectively: <i><br>
__old_kernel_stat</i></p>
<p style="margin-left:22%;">The original structure, with
rather narrow fields, and no padding.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><i>stat</i></p></td>
<td width="2%"></td>
<td width="78%">
<p>Larger <i>st_ino</i> field and padding added to various
parts of the structure to allow for future expansion.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><i>stat64</i></p></td>
<td width="2%"></td>
<td width="78%">
<p>Even larger <i>st_ino</i> field, larger <i>st_uid</i>
and <i>st_gid</i> fields to accommodate the Linux-2.4
expansion of UIDs and GIDs to 32 bits, and various other
enlarged fields and further padding in the structure.
(Various padding bytes were eventually consumed in Linux
2.6, with the advent of 32-bit device IDs and nanosecond
components for the timestamp fields.)</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">The glibc
<b>stat</b>() wrapper function hides these details from
applications, invoking the most recent version of the system
call provided by the kernel, and repacking the returned
information if required for old binaries.</p>
<p style="margin-left:11%; margin-top: 1em">On modern
64-bit systems, life is simpler: there is a single
<b>stat</b>() system call and the kernel deals with a
<i>stat</i> structure that contains fields of a sufficient
size.</p>
<p style="margin-left:11%; margin-top: 1em">The underlying
system call employed by the glibc <b>fstatat</b>() wrapper
function is actually called <b>fstatat64</b>() or, on some
architectures, <b>newfstatat</b>().</p>
<h2>EXAMPLE
<a name="EXAMPLE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The following
program calls <b>lstat</b>() and displays selected fields in
the returned <i>stat</i> structure.</p>
<p style="margin-left:11%; margin-top: 1em">#include
<sys/types.h> <br>
#include <sys/stat.h> <br>
#include <time.h> <br>
#include <stdio.h> <br>
#include <stdlib.h> <br>
#include <sys/sysmacros.h></p>
<p style="margin-left:11%; margin-top: 1em">int <br>
main(int argc, char *argv[]) <br>
{ <br>
struct stat sb;</p>
<p style="margin-left:11%; margin-top: 1em">if (argc != 2)
{ <br>
fprintf(stderr, "Usage: %s <pathname>\n",
argv[0]); <br>
exit(EXIT_FAILURE); <br>
}</p>
<p style="margin-left:11%; margin-top: 1em">if
(lstat(argv[1], &sb) == -1) { <br>
perror("lstat"); <br>
exit(EXIT_FAILURE); <br>
}</p>
<p style="margin-left:11%; margin-top: 1em">printf("ID
of containing device: [%lx,%lx]\n",</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p>(long) major(sb.st_dev), (long) minor(sb.st_dev));</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">printf("File
type: ");</p>
<p style="margin-left:11%; margin-top: 1em">switch
(sb.st_mode & S_IFMT) { <br>
case S_IFBLK: printf("block device\n"); break;
<br>
case S_IFCHR: printf("character device\n"); break;
<br>
case S_IFDIR: printf("directory\n"); break; <br>
case S_IFIFO: printf("FIFO/pipe\n"); break; <br>
case S_IFLNK: printf("symlink\n"); break; <br>
case S_IFREG: printf("regular file\n"); break;
<br>
case S_IFSOCK: printf("socket\n"); break; <br>
default: printf("unknown?\n"); break; <br>
}</p>
<p style="margin-left:11%; margin-top: 1em">printf("I-node
number: %ld\n", (long) sb.st_ino);</p>
<p style="margin-left:11%; margin-top: 1em">printf("Mode:
%lo (octal)\n", <br>
(unsigned long) sb.st_mode);</p>
<p style="margin-left:11%; margin-top: 1em">printf("Link
count: %ld\n", (long) sb.st_nlink); <br>
printf("Ownership: UID=%ld GID=%ld\n", <br>
(long) sb.st_uid, (long) sb.st_gid);</p>
<p style="margin-left:11%; margin-top: 1em">printf("Preferred
I/O block size: %ld bytes\n", <br>
(long) sb.st_blksize); <br>
printf("File size: %lld bytes\n", <br>
(long long) sb.st_size); <br>
printf("Blocks allocated: %lld\n", <br>
(long long) sb.st_blocks);</p>
<p style="margin-left:11%; margin-top: 1em">printf("Last
status change: %s", ctime(&sb.st_ctime)); <br>
printf("Last file access: %s",
ctime(&sb.st_atime)); <br>
printf("Last file modification: %s",
ctime(&sb.st_mtime));</p>
<p style="margin-left:11%; margin-top: 1em">exit(EXIT_SUCCESS);
<br>
}</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>ls</b>(1),
<b>stat</b>(1), <b>access</b>(2), <b>chmod</b>(2),
<b>chown</b>(2), <b>readlink</b>(2), <b>statx</b>(2),
<b>utime</b>(2), <b>capabilities</b>(7), <b>inode</b>(7),
<b>symlink</b>(7)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>