btrfs_diskformat/core/
inode_item.rs

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