move raw packed struct to sys module

This commit is contained in:
Szymon Walter 2018-03-18 20:35:55 +01:00
parent 0ffd97d29a
commit 0c750fbdda
5 changed files with 75 additions and 74 deletions

View file

@ -4,15 +4,13 @@
extern crate bitflags; extern crate bitflags;
pub mod error; pub mod error;
pub mod superblock; pub mod sys;
pub mod block_group;
pub mod inode;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::superblock::*; use sys::superblock::*;
use super::block_group::*; use sys::block_group::*;
use super::inode::*; use sys::inode::*;
#[test] #[test]
fn sizes() { fn sizes() {

View file

@ -25,17 +25,17 @@ use error::Error;
#[repr(C, packed)] #[repr(C, packed)]
pub struct BlockGroupDescriptor { pub struct BlockGroupDescriptor {
/// Block address of block usage bitmap /// Block address of block usage bitmap
block_usage_addr: u32, pub block_usage_addr: u32,
/// Block address of inode usage bitmap /// Block address of inode usage bitmap
inode_usage_addr: u32, pub inode_usage_addr: u32,
/// Starting block address of inode table /// Starting block address of inode table
inode_table_block: u32, pub inode_table_block: u32,
/// Number of unallocated blocks in group /// Number of unallocated blocks in group
free_blocks_count: u16, pub free_blocks_count: u16,
/// Number of unallocated inodes in group /// Number of unallocated inodes in group
free_inodes_count: u16, pub free_inodes_count: u16,
/// Number of directories in group /// Number of directories in group
dirs_count: u16, pub dirs_count: u16,
#[doc(hidden)] #[doc(hidden)]
_reserved: [u8; 14], _reserved: [u8; 14],
} }

View file

@ -8,56 +8,56 @@
#[repr(C, packed)] #[repr(C, packed)]
pub struct Inode { pub struct Inode {
/// Type and Permissions (see below) /// Type and Permissions (see below)
type_perm: u16, pub type_perm: u16,
/// User ID /// User ID
uid: u16, pub uid: u16,
/// Lower 32 bits of size in bytes /// Lower 32 bits of size in bytes
size_low: u32, pub size_low: u32,
/// Last Access Time (in POSIX time) /// Last Access Time (in POSIX time)
atime: u32, pub atime: u32,
/// Creation Time (in POSIX time) /// Creation Time (in POSIX time)
ctime: u32, pub ctime: u32,
/// Last Modification time (in POSIX time) /// Last Modification time (in POSIX time)
mtime: u32, pub mtime: u32,
/// Deletion time (in POSIX time) /// Deletion time (in POSIX time)
dtime: u32, pub dtime: u32,
/// Group ID /// Group ID
gid: u16, pub gid: u16,
/// Count of hard links (directory entries) to this inode. When this /// Count of hard links (directory entries) to this inode. When this
/// reaches 0, the data blocks are marked as unallocated. /// reaches 0, the data blocks are marked as unallocated.
hard_links: u16, pub hard_links: u16,
/// Count of disk sectors (not Ext2 blocks) in use by this inode, not /// Count of disk sectors (not Ext2 blocks) in use by this inode, not
/// counting the actual inode structure nor directory entries linking /// counting the actual inode structure nor directory entries linking
/// to the inode. /// to the inode.
sectors_count: u32, pub sectors_count: u32,
/// Flags /// Flags
flags: u32, pub flags: u32,
/// Operating System Specific value #1 /// Operating System Specific value #1
_os_specific_1: u32, pub _os_specific_1: [u8; 4],
/// Direct block pointers /// Direct block pointers
direct_pointer: [u32; 12], pub direct_pointer: [u32; 12],
/// Singly Indirect Block Pointer (Points to a block that is a list of /// Singly Indirect Block Pointer (Points to a block that is a list of
/// block pointers to data) /// block pointers to data)
indirect_pointer: u32, pub indirect_pointer: u32,
/// Doubly Indirect Block Pointer (Points to a block that is a list of /// Doubly Indirect Block Pointer (Points to a block that is a list of
/// block pointers to Singly Indirect Blocks) /// block pointers to Singly Indirect Blocks)
doubly_indirect: u32, pub doubly_indirect: u32,
/// Triply Indirect Block Pointer (Points to a block that is a list of /// Triply Indirect Block Pointer (Points to a block that is a list of
/// block pointers to Doubly Indirect Blocks) /// block pointers to Doubly Indirect Blocks)
triply_indirect: u32, pub triply_indirect: u32,
/// Generation number (Primarily used for NFS) /// Generation number (Primarily used for NFS)
gen_number: u32, pub gen_number: u32,
/// In Ext2 version 0, this field is reserved. In version >= 1, /// In Ext2 version 0, this field is reserved. In version >= 1,
/// Extended attribute block (File ACL). /// Extended attribute block (File ACL).
ext_attribute_block: u32, pub ext_attribute_block: u32,
/// In Ext2 version 0, this field is reserved. In version >= 1, Upper /// In Ext2 version 0, this field is reserved. In version >= 1, Upper
/// 32 bits of file size (if feature bit set) if it's a file, /// 32 bits of file size (if feature bit set) if it's a file,
/// Directory ACL if it's a directory /// Directory ACL if it's a directory
size_high: u32, pub size_high: u32,
/// Block address of fragment /// Block address of fragment
frag_block_addr: u32, pub frag_block_addr: u32,
/// Operating System Specific Value #2 /// Operating System Specific Value #2
_os_specific_2: [u8; 12], pub _os_specific_2: [u8; 12],
} }
bitflags! { bitflags! {

3
src/sys/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod superblock;
pub mod block_group;
pub mod inode;

View file

@ -45,103 +45,103 @@ pub const OS_LITE: u32 = 4;
pub struct Superblock { pub struct Superblock {
// taken from https://wiki.osdev.org/Ext2 // taken from https://wiki.osdev.org/Ext2
/// Total number of inodes in file system /// Total number of inodes in file system
inodes_count: u32, pub inodes_count: u32,
/// Total number of blocks in file system /// Total number of blocks in file system
blocks_count: u32, pub blocks_count: u32,
/// Number of blocks reserved for superuser (see offset 80) /// Number of blocks reserved for superuser (see offset 80)
r_blocks_count: u32, pub r_blocks_count: u32,
/// Total number of unallocated blocks /// Total number of unallocated blocks
free_blocks_count: u32, pub free_blocks_count: u32,
/// Total number of unallocated inodes /// Total number of unallocated inodes
free_inodes_count: u32, pub free_inodes_count: u32,
/// Block number of the block containing the superblock /// Block number of the block containing the superblock
first_data_block: u32, pub first_data_block: u32,
/// log2 (block size) - 10. (In other words, the number to shift 1,024 /// log2 (block size) - 10. (In other words, the number to shift 1,024
/// to the left by to obtain the block size) /// to the left by to obtain the block size)
log_block_size: u32, pub log_block_size: u32,
/// log2 (fragment size) - 10. (In other words, the number to shift /// log2 (fragment size) - 10. (In other words, the number to shift
/// 1,024 to the left by to obtain the fragment size) /// 1,024 to the left by to obtain the fragment size)
log_frag_size: i32, pub log_frag_size: i32,
/// Number of blocks in each block group /// Number of blocks in each block group
blocks_per_group: u32, pub blocks_per_group: u32,
/// Number of fragments in each block group /// Number of fragments in each block group
frags_per_group: u32, pub frags_per_group: u32,
/// Number of inodes in each block group /// Number of inodes in each block group
inodes_per_group: u32, pub inodes_per_group: u32,
/// Last mount time (in POSIX time) /// Last mount time (in POSIX time)
mtime: u32, pub mtime: u32,
/// Last written time (in POSIX time) /// Last written time (in POSIX time)
wtime: u32, pub wtime: u32,
/// Number of times the volume has been mounted since its last /// Number of times the volume has been mounted since its last
/// consistency check (fsck) /// consistency check (fsck)
mnt_count: u16, pub mnt_count: u16,
/// Number of mounts allowed before a consistency check (fsck) must be /// Number of mounts allowed before a consistency check (fsck) must be
/// done /// done
max_mnt_count: i16, pub max_mnt_count: i16,
/// Ext2 signature (0xef53), used to help confirm the presence of Ext2 /// Ext2 signature (0xef53), used to help confirm the presence of Ext2
/// on a volume /// on a volume
magic: u16, pub magic: u16,
/// File system state (see `FS_CLEAN` and `FS_ERR`) /// File system state (see `FS_CLEAN` and `FS_ERR`)
state: u16, pub state: u16,
/// What to do when an error is detected (see `ERR_IGNORE`, `ERR_RONLY` and /// What to do when an error is detected (see `ERR_IGNORE`, `ERR_RONLY` and
/// `ERR_PANIC`) /// `ERR_PANIC`)
errors: u16, pub errors: u16,
/// Minor portion of version (combine with Major portion below to /// Minor portion of version (combine with Major portion below to
/// construct full version field) /// construct full version field)
rev_minor: u16, pub rev_minor: u16,
/// POSIX time of last consistency check (fsck) /// POSIX time of last consistency check (fsck)
lastcheck: u32, pub lastcheck: u32,
/// Interval (in POSIX time) between forced consistency checks (fsck) /// Interval (in POSIX time) between forced consistency checks (fsck)
checkinterval: u32, pub checkinterval: u32,
/// Operating system ID from which the filesystem on this volume was /// Operating system ID from which the filesystem on this volume was
/// created /// created
creator_os: u32, pub creator_os: u32,
/// Major portion of version (combine with Minor portion above to /// Major portion of version (combine with Minor portion above to
/// construct full version field) /// construct full version field)
rev_major: u32, pub rev_major: u32,
/// User ID that can use reserved blocks /// User ID that can use reserved blocks
block_uid: u16, pub block_uid: u16,
/// Group ID that can use reserved blocks /// Group ID that can use reserved blocks
block_gid: u16, pub block_gid: u16,
/// First non-reserved inode in file system. /// First non-reserved inode in file system.
first_inode: u32, pub first_inode: u32,
/// Size of each inode structure in bytes. /// Size of each inode structure in bytes.
inode_size: u16, pub inode_size: u16,
/// Block group that this superblock is part of (if backup copy) /// Block group that this superblock is part of (if backup copy)
block_group: u16, pub block_group: u16,
/// Optional features present (features that are not required to read /// Optional features present (features that are not required to read
/// or write, but usually result in a performance increase) /// or write, but usually result in a performance increase)
features_opt: FeaturesOptional, pub features_opt: FeaturesOptional,
/// Required features present (features that are required to be /// Required features present (features that are required to be
/// supported to read or write) /// supported to read or write)
features_req: FeaturesRequired, pub features_req: FeaturesRequired,
/// Features that if not supported, the volume must be mounted /// Features that if not supported, the volume must be mounted
/// read-only) /// read-only)
features_ronly: FeaturesROnly, pub features_ronly: FeaturesROnly,
/// File system ID (what is output by blkid) /// File system ID (what is output by blkid)
fs_id: [u8; 16], pub fs_id: [u8; 16],
/// Volume name (C-style string: characters terminated by a 0 byte) /// Volume name (C-style string: characters terminated by a 0 byte)
volume_name: [u8; 16], pub volume_name: [u8; 16],
/// Path volume was last mounted to (C-style string: characters /// Path volume was last mounted to (C-style string: characters
/// terminated by a 0 byte) /// terminated by a 0 byte)
last_mnt_path: [u8; 64], pub last_mnt_path: [u8; 64],
/// Compression algorithms used (see Required features above) /// Compression algorithms used (see Required features above)
compression: u32, pub compression: u32,
/// Number of blocks to preallocate for files /// Number of blocks to preallocate for files
prealloc_blocks_files: u8, pub prealloc_blocks_files: u8,
/// Number of blocks to preallocate for directories /// Number of blocks to preallocate for directories
prealloc_blocks_dirs: u8, pub prealloc_blocks_dirs: u8,
#[doc(hidden)] #[doc(hidden)]
_unused: [u8; 2], _unused: [u8; 2],
/// Journal ID (same style as the File system ID above) /// Journal ID (same style as the File system ID above)
journal_id: [u8; 16], pub journal_id: [u8; 16],
/// Journal inode /// Journal inode
journal_inode: u32, pub journal_inode: u32,
/// Journal device /// Journal device
journal_dev: u32, pub journal_dev: u32,
/// Head of orphan inode list /// Head of orphan inode list
journal_orphan_head: u32, pub journal_orphan_head: u32,
#[doc(hidden)] #[doc(hidden)]
_reserved: [u8; 788], _reserved: [u8; 788],
} }