move raw packed struct to `sys` module

pull/3/head
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;
pub mod error;
pub mod superblock;
pub mod block_group;
pub mod inode;
pub mod sys;
#[cfg(test)]
mod tests {
use super::superblock::*;
use super::block_group::*;
use super::inode::*;
use sys::superblock::*;
use sys::block_group::*;
use sys::inode::*;
#[test]
fn sizes() {

View File

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

View File

@ -8,56 +8,56 @@
#[repr(C, packed)]
pub struct Inode {
/// Type and Permissions (see below)
type_perm: u16,
pub type_perm: u16,
/// User ID
uid: u16,
pub uid: u16,
/// Lower 32 bits of size in bytes
size_low: u32,
pub size_low: u32,
/// Last Access Time (in POSIX time)
atime: u32,
pub atime: u32,
/// Creation Time (in POSIX time)
ctime: u32,
pub ctime: u32,
/// Last Modification time (in POSIX time)
mtime: u32,
pub mtime: u32,
/// Deletion time (in POSIX time)
dtime: u32,
pub dtime: u32,
/// Group ID
gid: u16,
pub gid: u16,
/// Count of hard links (directory entries) to this inode. When this
/// 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
/// counting the actual inode structure nor directory entries linking
/// to the inode.
sectors_count: u32,
pub sectors_count: u32,
/// Flags
flags: u32,
pub flags: u32,
/// Operating System Specific value #1
_os_specific_1: u32,
pub _os_specific_1: [u8; 4],
/// 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
/// block pointers to data)
indirect_pointer: u32,
pub indirect_pointer: u32,
/// Doubly Indirect Block Pointer (Points to a block that is a list of
/// 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
/// block pointers to Doubly Indirect Blocks)
triply_indirect: u32,
pub triply_indirect: u32,
/// Generation number (Primarily used for NFS)
gen_number: u32,
pub gen_number: u32,
/// In Ext2 version 0, this field is reserved. In version >= 1,
/// 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
/// 32 bits of file size (if feature bit set) if it's a file,
/// Directory ACL if it's a directory
size_high: u32,
pub size_high: u32,
/// Block address of fragment
frag_block_addr: u32,
pub frag_block_addr: u32,
/// Operating System Specific Value #2
_os_specific_2: [u8; 12],
pub _os_specific_2: [u8; 12],
}
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 {
// taken from https://wiki.osdev.org/Ext2
/// Total number of inodes in file system
inodes_count: u32,
pub inodes_count: u32,
/// Total number of blocks in file system
blocks_count: u32,
pub blocks_count: u32,
/// Number of blocks reserved for superuser (see offset 80)
r_blocks_count: u32,
pub r_blocks_count: u32,
/// Total number of unallocated blocks
free_blocks_count: u32,
pub free_blocks_count: u32,
/// Total number of unallocated inodes
free_inodes_count: u32,
pub free_inodes_count: u32,
/// 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
/// 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
/// 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
blocks_per_group: u32,
pub blocks_per_group: u32,
/// Number of fragments in each block group
frags_per_group: u32,
pub frags_per_group: u32,
/// Number of inodes in each block group
inodes_per_group: u32,
pub inodes_per_group: u32,
/// Last mount time (in POSIX time)
mtime: u32,
pub mtime: u32,
/// Last written time (in POSIX time)
wtime: u32,
pub wtime: u32,
/// Number of times the volume has been mounted since its last
/// consistency check (fsck)
mnt_count: u16,
pub mnt_count: u16,
/// Number of mounts allowed before a consistency check (fsck) must be
/// done
max_mnt_count: i16,
pub max_mnt_count: i16,
/// Ext2 signature (0xef53), used to help confirm the presence of Ext2
/// on a volume
magic: u16,
pub magic: u16,
/// 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
/// `ERR_PANIC`)
errors: u16,
pub errors: u16,
/// Minor portion of version (combine with Major portion below to
/// construct full version field)
rev_minor: u16,
pub rev_minor: u16,
/// POSIX time of last consistency check (fsck)
lastcheck: u32,
pub lastcheck: u32,
/// 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
/// created
creator_os: u32,
pub creator_os: u32,
/// Major portion of version (combine with Minor portion above to
/// construct full version field)
rev_major: u32,
pub rev_major: u32,
/// User ID that can use reserved blocks
block_uid: u16,
pub block_uid: u16,
/// Group ID that can use reserved blocks
block_gid: u16,
pub block_gid: u16,
/// First non-reserved inode in file system.
first_inode: u32,
pub first_inode: u32,
/// 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: u16,
pub block_group: u16,
/// Optional features present (features that are not required to read
/// 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
/// supported to read or write)
features_req: FeaturesRequired,
pub features_req: FeaturesRequired,
/// Features that if not supported, the volume must be mounted
/// read-only)
features_ronly: FeaturesROnly,
pub features_ronly: FeaturesROnly,
/// 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: [u8; 16],
pub volume_name: [u8; 16],
/// Path volume was last mounted to (C-style string: characters
/// terminated by a 0 byte)
last_mnt_path: [u8; 64],
pub last_mnt_path: [u8; 64],
/// Compression algorithms used (see Required features above)
compression: u32,
pub compression: u32,
/// Number of blocks to preallocate for files
prealloc_blocks_files: u8,
pub prealloc_blocks_files: u8,
/// Number of blocks to preallocate for directories
prealloc_blocks_dirs: u8,
pub prealloc_blocks_dirs: u8,
#[doc(hidden)]
_unused: [u8; 2],
/// Journal ID (same style as the File system ID above)
journal_id: [u8; 16],
pub journal_id: [u8; 16],
/// Journal inode
journal_inode: u32,
pub journal_inode: u32,
/// Journal device
journal_dev: u32,
pub journal_dev: u32,
/// Head of orphan inode list
journal_orphan_head: u32,
pub journal_orphan_head: u32,
#[doc(hidden)]
_reserved: [u8; 788],
}