|  | 
|  | 1 | +// SPDX-License-Identifier: GPL-2.0 | 
|  | 2 | + | 
|  | 3 | +//! Definitions of tarfs structures. | 
|  | 4 | +
 | 
|  | 5 | +use kernel::types::LE; | 
|  | 6 | + | 
|  | 7 | +/// Flags used in [`Inode::flags`]. | 
|  | 8 | +pub mod inode_flags { | 
|  | 9 | +    /// Indicates that the inode is opaque. | 
|  | 10 | +    /// | 
|  | 11 | +    /// When set, inode will have the "trusted.overlay.opaque" set to "y" at runtime. | 
|  | 12 | +    pub const OPAQUE: u8 = 0x1; | 
|  | 13 | +} | 
|  | 14 | + | 
|  | 15 | +kernel::derive_readable_from_bytes! { | 
|  | 16 | +    /// An inode in the tarfs inode table. | 
|  | 17 | +    #[repr(C)] | 
|  | 18 | +    pub struct Inode { | 
|  | 19 | +        /// The mode of the inode. | 
|  | 20 | +        /// | 
|  | 21 | +        /// The bottom 9 bits are the rwx bits for owner, group, all. | 
|  | 22 | +        /// | 
|  | 23 | +        /// The bits in the [`S_IFMT`] mask represent the file mode. | 
|  | 24 | +        pub mode: LE<u16>, | 
|  | 25 | + | 
|  | 26 | +        /// Tarfs flags for the inode. | 
|  | 27 | +        /// | 
|  | 28 | +        /// Values are drawn from the [`inode_flags`] module. | 
|  | 29 | +        pub flags: u8, | 
|  | 30 | + | 
|  | 31 | +        /// The bottom 4 bits represent the top 4 bits of mtime. | 
|  | 32 | +        pub hmtime: u8, | 
|  | 33 | + | 
|  | 34 | +        /// The owner of the inode. | 
|  | 35 | +        pub owner: LE<u32>, | 
|  | 36 | + | 
|  | 37 | +        /// The group of the inode. | 
|  | 38 | +        pub group: LE<u32>, | 
|  | 39 | + | 
|  | 40 | +        /// The bottom 32 bits of mtime. | 
|  | 41 | +        pub lmtime: LE<u32>, | 
|  | 42 | + | 
|  | 43 | +        /// Size of the contents of the inode. | 
|  | 44 | +        pub size: LE<u64>, | 
|  | 45 | + | 
|  | 46 | +        /// Either the offset to the data, or the major and minor numbers of a device. | 
|  | 47 | +        /// | 
|  | 48 | +        /// For the latter, the 32 LSB are the minor, and the 32 MSB are the major numbers. | 
|  | 49 | +        pub offset: LE<u64>, | 
|  | 50 | +    } | 
|  | 51 | + | 
|  | 52 | +    /// An entry in a tarfs directory entry table. | 
|  | 53 | +    #[repr(C)] | 
|  | 54 | +    pub struct DirEntry { | 
|  | 55 | +        /// The inode number this entry refers to. | 
|  | 56 | +        pub ino: LE<u64>, | 
|  | 57 | + | 
|  | 58 | +        /// The offset to the name of the entry. | 
|  | 59 | +        pub name_offset: LE<u64>, | 
|  | 60 | + | 
|  | 61 | +        /// The length of the name of the entry. | 
|  | 62 | +        pub name_len: LE<u64>, | 
|  | 63 | + | 
|  | 64 | +        /// The type of entry. | 
|  | 65 | +        pub etype: u8, | 
|  | 66 | + | 
|  | 67 | +        /// Unused padding. | 
|  | 68 | +        pub _padding: [u8; 7], | 
|  | 69 | +    } | 
|  | 70 | + | 
|  | 71 | +    /// The super-block of a tarfs instance. | 
|  | 72 | +    #[repr(C)] | 
|  | 73 | +    pub struct Header { | 
|  | 74 | +        /// The offset to the beginning of the inode-table. | 
|  | 75 | +        pub inode_table_offset: LE<u64>, | 
|  | 76 | + | 
|  | 77 | +        /// The number of inodes in the file system. | 
|  | 78 | +        pub inode_count: LE<u64>, | 
|  | 79 | +    } | 
|  | 80 | +} | 
0 commit comments