Skip to content
Snippets Groups Projects
Verified Commit 415e501f authored by Aditya Gupta's avatar Aditya Gupta
Browse files

Some custom readability changes

BREAKING CHANGE: Usages of `redoxfs` binary should be replaced with `redoxfs-mount`

1. Renamed `redoxfs` binary to `redoxfs-mount`, for a consistent name convention as others
2. Some Comments
parent bbdaba45
Branches master
No related tags found
No related merge requests found
Pipeline #10080 failed
......@@ -13,7 +13,7 @@ name = "redoxfs"
path = "src/lib.rs"
[[bin]]
name = "redoxfs"
name = "redoxfs-mount"
path = "src/bin/mount.rs"
doc = false
required-features = ["std"]
......
......@@ -147,6 +147,7 @@ fn filesystem_by_path(
bootloader_password()
};
/* `image` is a `DiskFile` object, `disk` is a `DiskCache` object, actually the DiskCache object is passed to FileSystem::open */
match DiskFile::open(&path).map(|image| DiskCache::new(image)) {
Ok(disk) => match redoxfs::FileSystem::open(
disk,
......@@ -351,6 +352,7 @@ fn main() {
}
};
/* If block_opt is None (since 3rd argument is optional), it will still continue, and later in FileSystem::open, try all blocks to look for the first valid block (precisely said, the first block whose header is valid */
let block_opt = match args.next() {
Some(arg) => match u64::from_str_radix(&arg, 16) {
Ok(block) => Some(block),
......
......@@ -46,6 +46,11 @@ impl Disk for DiskFile {
Ok(count)
}
/*
* @note This function takes block number, not actual location, then multiplies it by BLOCK_SIZE to get actual location
*
* @todo Check if we can use File::write_at(...) method directly also
**/
unsafe fn write_at(&mut self, block: u64, buffer: &[u8]) -> Result<usize> {
try_disk!(self.file.seek(SeekFrom::Start(block * BLOCK_SIZE)));
let count = try_disk!(self.file.write(buffer));
......
......@@ -22,12 +22,14 @@ pub struct FileSystem<D: Disk> {
impl<D: Disk> FileSystem<D> {
/// Open a file system on a disk
/* Returns a FileSystem object with the first block, whose header was valid, trying all block ids from [0,65536) */
pub fn open(
mut disk: D,
password_opt: Option<&[u8]>,
block_opt: Option<u64>,
squash: bool,
) -> Result<Self> {
/* This .map_or(...) basically returns a range, the return type is based on the first argument, which is a range, and is Option contains a value, the function is run, which will return the range id..id+1, ALSO, since end of range is EXCLUSIVE (https://devdocs.io/rust/std/ops/struct.range), so the range basically contains ONLY id */
for ring_block in block_opt.map_or(0..65536, |x| x..x + 1) {
let mut header = Header::default();
unsafe { disk.read_at(ring_block, &mut header)? };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment