btrfs_diskformat/core/inode_item.rs
1use crate::Time;
2use bitflags::bitflags;
3use static_assertions::const_assert_eq;
4use zerocopy::little_endian::{U32 as U32LE, U64 as U64LE};
5use zerocopy_derive::*;
6
7/// Contains traditional inode data and attributes.
8#[derive(Copy, Clone, Debug, Hash, IntoBytes, FromBytes, Unaligned, KnownLayout, Immutable)]
9#[repr(C, packed)]
10pub struct InodeItem {
11 // FIXME: add documentation!
12 pub generation: U64LE,
13
14 // FIXME: add documentation!
15 pub transid: U64LE,
16
17 /// The size of a file, in bytes.
18 pub size: U64LE,
19
20 /// The size allocated to the file, in bytes.
21 ///
22 /// This is equal to the sum of all of the extent data for the inode.
23 /// This is 0 for directories.
24 pub nbytes: U64LE,
25
26 /// This contains the byte offset of a block group when structure is a free space inode.
27 ///
28 /// This value is unused for normal inodes.
29 pub block_group: U64LE,
30
31 /// Count of inode references for the inode.
32 ///
33 /// When used outside of a file tree, this value is 1.
34 pub nlink: U32LE,
35
36 /// The user ID of the owner in Unix.
37 pub uid: U32LE,
38
39 /// The group ID of the group owner in Unix.
40 pub gid: U32LE,
41
42 /// The Unix protection mode.
43 pub mode: U32LE,
44
45 /// The device identifier (if a special file).
46 pub rdev: U64LE,
47
48 /// Flags for the inode. See [InodeFlags] for values.
49 pub flags: U64LE,
50
51 /// A sequence number used for compatibility with NFS.
52 ///
53 /// This value is initialized to 0 and incremented each time [mtime] is updated.
54 ///
55 /// [mtime]: InodeItem::mtime
56 pub sequence: U64LE,
57
58 pub _unused: [u64; 4],
59
60 /// Timestamp of the last access to the inode.
61 pub atime: Time,
62
63 /// Timestamp of the last change to the inode's properties.
64 pub ctime: Time,
65
66 /// Timestamp of the last change to the inode's contents.
67 pub mtime: Time,
68
69 /// Timestamp of the creation of the inode.
70 pub otime: Time,
71}
72const_assert_eq!(core::mem::size_of::<InodeItem>(), 160);
73
74bitflags! {
75 pub struct InodeFlags: u64 {
76 /// Do not perform checksum operations.
77 const NO_DATA_SUM = 0x1;
78
79 /// Do not perform copy-on-write for data extents when the reference count is 1.
80 const NO_DATA_COW = 0x2;
81
82 /// The inode is read-only, regardless of permissions or ownership.
83 const READ_ONLY = 0x4;
84
85 /// Do not perform compression.
86 const NO_COMPRESS = 0x8;
87
88 /// Denotes preallocated extents are present. Hints that filesystem should avoid CoWing
89 /// those extents.
90 const PREALLOC = 0x10;
91
92 /// Operations on this inode should be performed synchronously.
93 const SYNC = 0x20;
94
95 /// The inode is read-only; regardless of permissions or ownership.
96 const IMMUTABLE = 0x40;
97
98 /// The inode is append-only.
99 const APPEND = 0x80;
100
101 /// Do not consider the inode for dumping when using the Unix program `dump`.
102 const NO_DUMP = 0x100;
103
104 /// Do not update [`atime`](InodeItem::atime).
105 const NO_ATIME = 0x200;
106
107 /// Operations on directory should be performed synchronously.
108 const DIR_SYNC = 0x400;
109
110 /// Perform compression for the inode.
111 const COMPRESS = 0x800;
112 }
113}