Skip to content

Commit

Permalink
Removed useless functions
Browse files Browse the repository at this point in the history
  • Loading branch information
llenotre committed Oct 17, 2022
1 parent be8165b commit 399bb4c
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 182 deletions.
164 changes: 0 additions & 164 deletions src/file/fs/ext2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,170 +1198,6 @@ impl FilesystemType for Ext2FsType {
Ok(Superblock::read(io)?.is_valid())
}

fn create_filesystem(&self, io: &mut dyn IO) -> Result<SharedPtr<dyn Filesystem>, Errno> {
let timestamp = time::get(TimestampScale::Second, true).unwrap_or(0);

let blocks_count = (io.get_size() / DEFAULT_BLOCK_SIZE) as u32;
let groups_count = blocks_count / DEFAULT_BLOCKS_PER_GROUP;

let inodes_count = groups_count * DEFAULT_INODES_PER_GROUP;

let block_usage_bitmap_size =
math::ceil_division(DEFAULT_BLOCKS_PER_GROUP, (DEFAULT_BLOCK_SIZE * 8) as _);
let inode_usage_bitmap_size =
math::ceil_division(DEFAULT_INODES_PER_GROUP, (DEFAULT_BLOCK_SIZE * 8) as _);
let inodes_table_size = math::ceil_division(
DEFAULT_INODES_PER_GROUP * DEFAULT_INODE_SIZE as u32,
(DEFAULT_BLOCK_SIZE * 8) as _,
);

let mut superblock = Superblock {
total_inodes: inodes_count,
total_blocks: blocks_count,
superuser_blocks: 0,
total_unallocated_blocks: blocks_count,
total_unallocated_inodes: inodes_count,
superblock_block_number: (SUPERBLOCK_OFFSET / DEFAULT_BLOCK_SIZE) as _,
block_size_log: (math::log2(DEFAULT_BLOCK_SIZE as usize) - 10) as _,
fragment_size_log: 0,
blocks_per_group: DEFAULT_BLOCKS_PER_GROUP,
fragments_per_group: 0,
inodes_per_group: DEFAULT_INODES_PER_GROUP,
last_mount_timestamp: timestamp as _,
last_write_timestamp: timestamp as _,
mount_count_since_fsck: 0,
mount_count_before_fsck: DEFAULT_MOUNT_COUNT_BEFORE_FSCK,
signature: EXT2_SIGNATURE,
fs_state: FS_STATE_CLEAN,
error_action: ERR_ACTION_READ_ONLY,
minor_version: DEFAULT_MINOR,
last_fsck_timestamp: timestamp as _,
fsck_interval: DEFAULT_FSCK_INTERVAL,
os_id: 0xdeadbeef,
major_version: DEFAULT_MAJOR,
uid_reserved: 0,
gid_reserved: 0,

first_non_reserved_inode: 11,
inode_size: DEFAULT_INODE_SIZE,
superblock_group: ((SUPERBLOCK_OFFSET / DEFAULT_BLOCK_SIZE) as u32
/ DEFAULT_BLOCKS_PER_GROUP) as _,
optional_features: 0,
required_features: 0,
write_required_features: WRITE_REQUIRED_64_BITS,
filesystem_id: [0; 16], // TODO
volume_name: [0; 16], // TODO
last_mount_path: [0; 64], // TODO
compression_algorithms: 0,
files_preallocate_count: 0,
direactories_preallocate_count: 0,
_unused: 0,
journal_id: [0; 16], // TODO
journal_inode: 0, // TODO
journal_device: 0, // TODO
orphan_inode_head: 0, // TODO

_padding: [0; 788],
};

let blk_size = superblock.get_block_size() as u32;
let bgdt_offset = superblock.get_bgdt_offset();
let bgdt_size = math::ceil_division(
groups_count * size_of::<BlockGroupDescriptor>() as u32,
blk_size,
);
let bgdt_end = bgdt_offset + bgdt_size as u64;

for i in 0..groups_count {
let metadata_off = max(i * DEFAULT_BLOCKS_PER_GROUP, bgdt_end as u32);
let metadata_size =
block_usage_bitmap_size + inode_usage_bitmap_size + inodes_table_size;
debug_assert!(bgdt_end + metadata_size as u64 <= DEFAULT_BLOCKS_PER_GROUP as u64);

let block_usage_bitmap_addr = metadata_off;
let inode_usage_bitmap_addr = metadata_off + block_usage_bitmap_size;
let inode_table_start_addr =
metadata_off + block_usage_bitmap_size + inode_usage_bitmap_size;

let bgd = BlockGroupDescriptor {
block_usage_bitmap_addr,
inode_usage_bitmap_addr,
inode_table_start_addr,
unallocated_blocks_number: DEFAULT_BLOCKS_PER_GROUP as _,
unallocated_inodes_number: DEFAULT_INODES_PER_GROUP as _,
directories_number: 0,

_padding: [0; 14],
};
bgd.write(i, &superblock, io)?;
}

superblock.mark_block_used(io, 0)?;

let superblock_blk_offset = SUPERBLOCK_OFFSET as u32 / blk_size;
superblock.mark_block_used(io, superblock_blk_offset)?;

let bgdt_size = size_of::<BlockGroupDescriptor>() as u32 * groups_count;
let bgdt_blk_count = math::ceil_division(bgdt_size, blk_size);
for j in 0..bgdt_blk_count {
let blk = bgdt_offset + j as u64;
superblock.mark_block_used(io, blk as _)?;
}

for i in 0..groups_count {
let bgd = BlockGroupDescriptor::read(i, &superblock, io)?;

for j in 0..block_usage_bitmap_size {
let blk = bgd.block_usage_bitmap_addr + j;
superblock.mark_block_used(io, blk)?;
}

for j in 0..inode_usage_bitmap_size {
let inode = bgd.inode_usage_bitmap_addr + j;
superblock.mark_block_used(io, inode)?;
}

for j in 0..inodes_table_size {
let blk = bgd.inode_table_start_addr + j;
superblock.mark_block_used(io, blk)?;
}
}

for i in 1..superblock.get_first_available_inode() {
let is_dir = i == inode::ROOT_DIRECTORY_INODE;
superblock.mark_inode_used(io, i, is_dir)?;
}

let root_dir = Ext2INode {
mode: inode::INODE_TYPE_DIRECTORY | inode::ROOT_DIRECTORY_DEFAULT_MODE,
uid: 0,
size_low: 0,
ctime: timestamp as _,
mtime: timestamp as _,
atime: timestamp as _,
dtime: 0,
gid: 0,
hard_links_count: 1,
used_sectors: 0,
flags: 0,
os_specific_0: 0,
direct_block_ptrs: [0; inode::DIRECT_BLOCKS_COUNT as usize],
singly_indirect_block_ptr: 0,
doubly_indirect_block_ptr: 0,
triply_indirect_block_ptr: 0,
generation: 0,
extended_attributes_block: 0,
size_high: 0,
fragment_addr: 0,
os_specific_1: [0; 12],
};
root_dir.write(inode::ROOT_DIRECTORY_INODE, &superblock, io)?;
superblock.write(io)?;

let fs = Ext2Fs::new(superblock, io, Path::root(), true)?;
Ok(SharedPtr::new(fs)?)
}

fn load_filesystem(
&self,
io: &mut dyn IO,
Expand Down
6 changes: 0 additions & 6 deletions src/file/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@ pub trait FilesystemType {
/// `io` is the IO interface.
fn detect(&self, io: &mut dyn IO) -> Result<bool, Errno>;

/// Creates a new filesystem on the IO interface and returns its instance.
/// `io` is the IO interface.
/// `fs_id` is the ID of the loaded filesystem. This ID is only used by the kernel and not
/// saved on the storage device.
fn create_filesystem(&self, io: &mut dyn IO) -> Result<SharedPtr<dyn Filesystem>, Errno>;

/// Creates a new instance of the filesystem to mount it.
/// `io` is the IO interface.
/// `mountpath` is the path on which the filesystem is mounted.
Expand Down
4 changes: 0 additions & 4 deletions src/file/fs/procfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ impl FilesystemType for ProcFsType {
Ok(false)
}

fn create_filesystem(&self, _io: &mut dyn IO) -> Result<SharedPtr<dyn Filesystem>, Errno> {
Ok(SharedPtr::new(ProcFS::new(false, Path::root())?)?)
}

fn load_filesystem(
&self,
_io: &mut dyn IO,
Expand Down
8 changes: 0 additions & 8 deletions src/file/fs/tmp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,6 @@ impl FilesystemType for TmpFsType {
Ok(false)
}

fn create_filesystem(&self, _io: &mut dyn IO) -> Result<SharedPtr<dyn Filesystem>, Errno> {
Ok(SharedPtr::new(TmpFS::new(
DEFAULT_MAX_SIZE,
false,
Path::root(),
)?)?)
}

fn load_filesystem(
&self,
_io: &mut dyn IO,
Expand Down

0 comments on commit 399bb4c

Please sign in to comment.