1 .\" Copyright (c) 2017 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH INODE 7 2021-03-22 "Linux" "Linux Programmer's Manual"
27 inode \- file inode information
29 Each file has an inode containing metadata about the file.
30 An application can retrieve this metadata using
32 (or related calls), which returns a
40 The following is a list of the information typically found in,
41 or associated with, the file inode,
42 with the names of the corresponding structure fields returned by
47 Device where inode resides
48 \fIstat.st_dev\fP; \fIstatx.stx_dev_minor\fP and \fIstatx.stx_dev_major\fP
50 Each inode (as well as the associated file) resides in a filesystem
51 that is hosted on a device.
52 That device is identified by the combination of its major ID
53 (which identifies the general class of device)
54 and minor ID (which identifies a specific instance in the general class).
57 \fIstat.st_ino\fP; \fIstatx.stx_ino\fP
59 Each file in a filesystem has a unique inode number.
60 Inode numbers are guaranteed to be unique only within a filesystem
61 (i.e., the same inode numbers may be used by different filesystems,
62 which is the reason that hard links may not cross filesystem boundaries).
63 This field contains the file's inode number.
66 \fIstat.st_mode\fP; \fIstatx.stx_mode\fP
68 See the discussion of file type and mode, below.
71 \fIstat.st_nlink\fP; \fIstatx.stx_nlink\fP
73 This field contains the number of hard links to the file.
74 Additional links to an existing file are created using
79 \fIstat.st_uid\fP; \fIstatx.stx_uid\fP
81 This field records the user ID of the owner of the file.
82 For newly created files,
83 the file user ID is the effective user ID of the creating process.
84 The user ID of a file can be changed using
88 \fIstat.st_gid\fP; \fIstatx.stx_gid\fP
90 The inode records the ID of the group owner of the file.
91 For newly created files,
92 the file group ID is either the group ID of the parent directory or
93 the effective group ID of the creating process,
94 depending on whether or not the set-group-ID bit
95 is set on the parent directory (see below).
96 The group ID of a file can be changed using
99 Device represented by this inode
100 \fIstat.st_rdev\fP; \fIstatx.stx_rdev_minor\fP and \fIstatx.stx_rdev_major\fP
102 If this file (inode) represents a device,
103 then the inode records the major and minor ID of that device.
106 \fIstat.st_size\fP; \fIstatx.stx_size\fP
108 This field gives the size of the file (if it is a regular
109 file or a symbolic link) in bytes.
110 The size of a symbolic link is the length of the pathname
111 it contains, without a terminating null byte.
113 Preferred block size for I/O
114 \fIstat.st_blksize\fP; \fIstatx.stx_blksize\fP
116 This field gives the "preferred" blocksize for efficient filesystem I/O.
117 (Writing to a file in smaller chunks may cause
118 an inefficient read-modify-rewrite.)
120 Number of blocks allocated to the file
121 \fIstat.st_blocks\fP; \fIstatx.stx_size\fP
123 This field indicates the number of blocks allocated to the file,
125 (This may be smaller than
127 when the file has holes.)
129 The POSIX.1 standard notes
130 .\" Rationale for sys/stat.h in POSIX.1-2008
131 that the unit for the
135 structure is not defined by the standard.
136 On many implementations it is 512 bytes;
137 on a few systems, a different unit is used, such as 1024.
138 Furthermore, the unit may differ on a per-filesystem basis.
140 Last access timestamp (atime)
141 \fIstat.st_atime\fP; \fIstatx.stx_atime\fP
143 This is the file's last access timestamp.
144 It is changed by file accesses, for example, by
151 (of more than zero bytes).
152 Other interfaces, such as
154 may or may not update the atime timestamp
156 Some filesystem types allow mounting in such a way that file
157 and/or directory accesses do not cause an update of the atime timestamp.
165 and related information in
167 In addition, the atime timestamp
168 is not updated if a file is opened with the
173 File creation (birth) timestamp (btime)
174 (not returned in the \fIstat\fP structure); \fIstatx.stx_btime\fP
176 The file's creation timestamp.
177 This is set on file creation and not changed subsequently.
179 The btime timestamp was not historically present on UNIX systems
180 and is not currently supported by most Linux filesystems.
181 .\" FIXME Is it supported on ext4 and XFS?
183 Last modification timestamp (mtime)
184 \fIstat.st_mtime\fP; \fIstatx.stx_mtime\fP
186 This is the file's last modification timestamp.
187 It is changed by file modifications, for example, by
193 (of more than zero bytes).
194 Moreover, the mtime timestamp
195 of a directory is changed by the creation or deletion of files
197 The mtime timestamp is
199 changed for changes in owner, group, hard link count, or mode.
201 Last status change timestamp (ctime)
202 \fIstat.st_ctime\fP; \fIstatx.stx_ctime\fP
204 This is the file's last status change timestamp.
205 It is changed by writing or by setting inode information
206 (i.e., owner, group, link count, mode, etc.).
208 The timestamp fields report time measured with a zero point at the
210 1970-01-01 00:00:00 +0000, UTC (see
213 Nanosecond timestamps are supported on XFS, JFS, Btrfs, and
214 ext4 (since Linux 2.6.23).
215 .\" commit ef7f38359ea8b3e9c7f2cae9a4d4935f55ca9e80
216 Nanosecond timestamps are not supported in ext2, ext3, and Reiserfs.
217 In order to return timestamps with nanosecond precision,
218 the timestamp fields in the
222 structures are defined as structures that include a nanosecond component.
228 On filesystems that do not support subsecond timestamps,
229 the nanosecond fields in the
233 structures are returned with the value 0.
235 .SS The file type and mode
242 field) contains the file type and mode.
246 bits corresponding to the mask
250 the 12 bits corresponding to the mask 07777 as the
252 and the least significant 9 bits (0777) as the
253 .IR "file permission bits" .
255 The following mask values are defined for the file type:
259 S_IFMT 0170000 bit mask for the file type bit field
261 S_IFSOCK 0140000 socket
262 S_IFLNK 0120000 symbolic link
263 S_IFREG 0100000 regular file
264 S_IFBLK 0060000 block device
265 S_IFDIR 0040000 directory
266 S_IFCHR 0020000 character device
271 Thus, to test for a regular file (for example), one could write:
276 if ((sb.st_mode & S_IFMT) == S_IFREG) {
277 /* Handle regular file */
282 Because tests of the above form are common, additional
283 macros are defined by POSIX to allow the test of the file type in
285 to be written more concisely:
289 is it a regular file?
304 symbolic link? (Not in POSIX.1-1996.)
307 socket? (Not in POSIX.1-1996.)
310 The preceding code snippet could thus be rewritten as:
315 if (S_ISREG(sb.st_mode)) {
316 /* Handle regular file */
321 The definitions of most of the above file type test macros
322 are provided if any of the following feature test macros is defined:
324 (in glibc 2.19 and earlier),
326 (in glibc 2.19 and earlier),
329 (in glibc 2.20 and later).
330 In addition, definitions of all of the above macros except
340 can also be exposed either by defining
342 with a value of 500 or greater or (since glibc 2.24) by defining both
345 .BR _XOPEN_SOURCE_EXTENDED .
349 is exposed if any of the following feature test macros is defined:
351 (in glibc 2.19 and earlier),
353 (in glibc 2.20 and later),
355 with a value of 500 or greater,
357 with a value of 200112L or greater, or (since glibc 2.24) by defining both
360 .BR _XOPEN_SOURCE_EXTENDED .
362 The following mask values are defined for
363 the file mode component of the
372 set-user-ID bit (see \fBexecve\fP(2))
375 set-group-ID bit (see below)
378 sticky bit (see below)
382 owner has read, write, and execute permission
385 owner has read permission
388 owner has write permission
391 owner has execute permission
395 group has read, write, and execute permission
398 group has read permission
401 group has write permission
404 group has execute permission
408 others (not in group) have read, write, and execute permission
411 others have read permission
414 others have write permission
417 others have execute permission
426 has several special uses.
427 For a directory, it indicates that BSD semantics are to be used
428 for that directory: files created there inherit their group ID from
429 the directory, not from the effective group ID of the creating process,
430 and directories created there will also get the
433 For an executable file, the set-group-ID bit causes the effective group ID
434 of a process that executes the file to change as described in
436 For a file that does not have the group execution bit
439 the set-group-ID bit indicates mandatory file/record locking.
443 on a directory means that a file
444 in that directory can be renamed or deleted only by the owner
445 of the file, by the owner of the directory, and by a privileged
448 If you need to obtain the definition of the
456 with the value 500 or greater (before including
460 POSIX.1-1990 did not describe the
471 constants, but instead specified the use of
477 constants are present in POSIX.1-2001 and later.
484 POSIX.1-1996, but both are present in POSIX.1-2001;
485 the former is from SVID 4, the latter from SUSv2.
487 UNIX\ V7 (and later systems) had
493 prescribes the synonyms
499 For pseudofiles that are autogenerated by the kernel, the file size
500 (\fIstat.st_size\fP; \fIstatx.stx_size\fP)
501 reported by the kernel is not accurate.
502 For example, the value 0 is returned for many files under the
505 while various files under
507 report a size of 4096 bytes, even though the file content is smaller.
508 For such files, one should simply try to read as many bytes as possible
509 (and append \(aq\e0\(aq to the returned buffer
510 if it is to be interpreted as a string).