1 .\" Copyright (c) 2017 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH INODE 7 2021-03-22 "Linux" "Linux Programmer's Manual"
7 inode \- file inode information
9 Each file has an inode containing metadata about the file.
10 An application can retrieve this metadata using
12 (or related calls), which returns a
20 The following is a list of the information typically found in,
21 or associated with, the file inode,
22 with the names of the corresponding structure fields returned by
27 Device where inode resides
28 \fIstat.st_dev\fP; \fIstatx.stx_dev_minor\fP and \fIstatx.stx_dev_major\fP
30 Each inode (as well as the associated file) resides in a filesystem
31 that is hosted on a device.
32 That device is identified by the combination of its major ID
33 (which identifies the general class of device)
34 and minor ID (which identifies a specific instance in the general class).
37 \fIstat.st_ino\fP; \fIstatx.stx_ino\fP
39 Each file in a filesystem has a unique inode number.
40 Inode numbers are guaranteed to be unique only within a filesystem
41 (i.e., the same inode numbers may be used by different filesystems,
42 which is the reason that hard links may not cross filesystem boundaries).
43 This field contains the file's inode number.
46 \fIstat.st_mode\fP; \fIstatx.stx_mode\fP
48 See the discussion of file type and mode, below.
51 \fIstat.st_nlink\fP; \fIstatx.stx_nlink\fP
53 This field contains the number of hard links to the file.
54 Additional links to an existing file are created using
59 \fIstat.st_uid\fP; \fIstatx.stx_uid\fP
61 This field records the user ID of the owner of the file.
62 For newly created files,
63 the file user ID is the effective user ID of the creating process.
64 The user ID of a file can be changed using
68 \fIstat.st_gid\fP; \fIstatx.stx_gid\fP
70 The inode records the ID of the group owner of the file.
71 For newly created files,
72 the file group ID is either the group ID of the parent directory or
73 the effective group ID of the creating process,
74 depending on whether or not the set-group-ID bit
75 is set on the parent directory (see below).
76 The group ID of a file can be changed using
79 Device represented by this inode
80 \fIstat.st_rdev\fP; \fIstatx.stx_rdev_minor\fP and \fIstatx.stx_rdev_major\fP
82 If this file (inode) represents a device,
83 then the inode records the major and minor ID of that device.
86 \fIstat.st_size\fP; \fIstatx.stx_size\fP
88 This field gives the size of the file (if it is a regular
89 file or a symbolic link) in bytes.
90 The size of a symbolic link is the length of the pathname
91 it contains, without a terminating null byte.
93 Preferred block size for I/O
94 \fIstat.st_blksize\fP; \fIstatx.stx_blksize\fP
96 This field gives the "preferred" blocksize for efficient filesystem I/O.
97 (Writing to a file in smaller chunks may cause
98 an inefficient read-modify-rewrite.)
100 Number of blocks allocated to the file
101 \fIstat.st_blocks\fP; \fIstatx.stx_size\fP
103 This field indicates the number of blocks allocated to the file,
105 (This may be smaller than
107 when the file has holes.)
109 The POSIX.1 standard notes
110 .\" Rationale for sys/stat.h in POSIX.1-2008
111 that the unit for the
115 structure is not defined by the standard.
116 On many implementations it is 512 bytes;
117 on a few systems, a different unit is used, such as 1024.
118 Furthermore, the unit may differ on a per-filesystem basis.
120 Last access timestamp (atime)
121 \fIstat.st_atime\fP; \fIstatx.stx_atime\fP
123 This is the file's last access timestamp.
124 It is changed by file accesses, for example, by
131 (of more than zero bytes).
132 Other interfaces, such as
134 may or may not update the atime timestamp
136 Some filesystem types allow mounting in such a way that file
137 and/or directory accesses do not cause an update of the atime timestamp.
145 and related information in
147 In addition, the atime timestamp
148 is not updated if a file is opened with the
153 File creation (birth) timestamp (btime)
154 (not returned in the \fIstat\fP structure); \fIstatx.stx_btime\fP
156 The file's creation timestamp.
157 This is set on file creation and not changed subsequently.
159 The btime timestamp was not historically present on UNIX systems
160 and is not currently supported by most Linux filesystems.
161 .\" FIXME Is it supported on ext4 and XFS?
163 Last modification timestamp (mtime)
164 \fIstat.st_mtime\fP; \fIstatx.stx_mtime\fP
166 This is the file's last modification timestamp.
167 It is changed by file modifications, for example, by
173 (of more than zero bytes).
174 Moreover, the mtime timestamp
175 of a directory is changed by the creation or deletion of files
177 The mtime timestamp is
179 changed for changes in owner, group, hard link count, or mode.
181 Last status change timestamp (ctime)
182 \fIstat.st_ctime\fP; \fIstatx.stx_ctime\fP
184 This is the file's last status change timestamp.
185 It is changed by writing or by setting inode information
186 (i.e., owner, group, link count, mode, etc.).
188 The timestamp fields report time measured with a zero point at the
190 1970-01-01 00:00:00 +0000, UTC (see
193 Nanosecond timestamps are supported on XFS, JFS, Btrfs, and
194 ext4 (since Linux 2.6.23).
195 .\" commit ef7f38359ea8b3e9c7f2cae9a4d4935f55ca9e80
196 Nanosecond timestamps are not supported in ext2, ext3, and Reiserfs.
197 In order to return timestamps with nanosecond precision,
198 the timestamp fields in the
202 structures are defined as structures that include a nanosecond component.
208 On filesystems that do not support subsecond timestamps,
209 the nanosecond fields in the
213 structures are returned with the value 0.
215 .SS The file type and mode
222 field) contains the file type and mode.
226 bits corresponding to the mask
230 the 12 bits corresponding to the mask 07777 as the
232 and the least significant 9 bits (0777) as the
233 .IR "file permission bits" .
235 The following mask values are defined for the file type:
239 S_IFMT 0170000 bit mask for the file type bit field
241 S_IFSOCK 0140000 socket
242 S_IFLNK 0120000 symbolic link
243 S_IFREG 0100000 regular file
244 S_IFBLK 0060000 block device
245 S_IFDIR 0040000 directory
246 S_IFCHR 0020000 character device
251 Thus, to test for a regular file (for example), one could write:
256 if ((sb.st_mode & S_IFMT) == S_IFREG) {
257 /* Handle regular file */
262 Because tests of the above form are common, additional
263 macros are defined by POSIX to allow the test of the file type in
265 to be written more concisely:
269 is it a regular file?
284 symbolic link? (Not in POSIX.1-1996.)
287 socket? (Not in POSIX.1-1996.)
290 The preceding code snippet could thus be rewritten as:
295 if (S_ISREG(sb.st_mode)) {
296 /* Handle regular file */
301 The definitions of most of the above file type test macros
302 are provided if any of the following feature test macros is defined:
304 (in glibc 2.19 and earlier),
306 (in glibc 2.19 and earlier),
309 (in glibc 2.20 and later).
310 In addition, definitions of all of the above macros except
320 can also be exposed either by defining
322 with a value of 500 or greater or (since glibc 2.24) by defining both
325 .BR _XOPEN_SOURCE_EXTENDED .
329 is exposed if any of the following feature test macros is defined:
331 (in glibc 2.19 and earlier),
333 (in glibc 2.20 and later),
335 with a value of 500 or greater,
337 with a value of 200112L or greater, or (since glibc 2.24) by defining both
340 .BR _XOPEN_SOURCE_EXTENDED .
342 The following mask values are defined for
343 the file mode component of the
352 set-user-ID bit (see \fBexecve\fP(2))
355 set-group-ID bit (see below)
358 sticky bit (see below)
362 owner has read, write, and execute permission
365 owner has read permission
368 owner has write permission
371 owner has execute permission
375 group has read, write, and execute permission
378 group has read permission
381 group has write permission
384 group has execute permission
388 others (not in group) have read, write, and execute permission
391 others have read permission
394 others have write permission
397 others have execute permission
406 has several special uses.
407 For a directory, it indicates that BSD semantics are to be used
408 for that directory: files created there inherit their group ID from
409 the directory, not from the effective group ID of the creating process,
410 and directories created there will also get the
413 For an executable file, the set-group-ID bit causes the effective group ID
414 of a process that executes the file to change as described in
416 For a file that does not have the group execution bit
419 the set-group-ID bit indicates mandatory file/record locking.
423 on a directory means that a file
424 in that directory can be renamed or deleted only by the owner
425 of the file, by the owner of the directory, and by a privileged
428 If you need to obtain the definition of the
436 with the value 500 or greater (before including
440 POSIX.1-1990 did not describe the
451 constants, but instead specified the use of
457 constants are present in POSIX.1-2001 and later.
464 POSIX.1-1996, but both are present in POSIX.1-2001;
465 the former is from SVID 4, the latter from SUSv2.
467 UNIX\ V7 (and later systems) had
473 prescribes the synonyms
479 For pseudofiles that are autogenerated by the kernel, the file size
480 (\fIstat.st_size\fP; \fIstatx.stx_size\fP)
481 reported by the kernel is not accurate.
482 For example, the value 0 is returned for many files under the
485 while various files under
487 report a size of 4096 bytes, even though the file content is smaller.
488 For such files, one should simply try to read as many bytes as possible
489 (and append \(aq\e0\(aq to the returned buffer
490 if it is to be interpreted as a string).