Commit 3191d7d1 authored by Jeremy Soller's avatar Jeremy Soller

Add argument to locate redoxfs by block

parent bede93cd
Pipeline #6319 passed with stages
in 2 minutes and 49 seconds
......@@ -77,7 +77,7 @@ fn capability_mode() {
}
fn usage() {
println!("redoxfs [--uuid] [disk or uuid] [mountpoint]");
println!("redoxfs [--uuid] [disk or uuid] [mountpoint] [block in hex]");
}
enum DiskId {
......@@ -127,7 +127,7 @@ fn disk_paths(paths: &mut Vec<String>) {
}
}
fn daemon(disk_id: &DiskId, mountpoint: &str, mut write: File) -> ! {
fn daemon(disk_id: &DiskId, mountpoint: &str, block_opt: Option<u64>, mut write: File) -> ! {
setsig();
let mut paths = vec![];
......@@ -146,7 +146,7 @@ fn daemon(disk_id: &DiskId, mountpoint: &str, mut write: File) -> ! {
for path in paths {
println!("redoxfs: opening {}", path);
match DiskFile::open(&path).map(|image| DiskCache::new(image)) {
Ok(disk) => match redoxfs::FileSystem::open(disk) {
Ok(disk) => match redoxfs::FileSystem::open(disk, block_opt) {
Ok(filesystem) => {
println!("redoxfs: opened filesystem on {} with uuid {}", path,
Uuid::from_bytes(&filesystem.header.1.uuid).unwrap().hyphenated());
......@@ -200,7 +200,7 @@ fn daemon(disk_id: &DiskId, mountpoint: &str, mut write: File) -> ! {
fn print_uuid(path: &str) {
match DiskFile::open(&path).map(|image| DiskCache::new(image)) {
Ok(disk) => match redoxfs::FileSystem::open(disk) {
Ok(disk) => match redoxfs::FileSystem::open(disk, None) {
Ok(filesystem) => {
println!("{}", Uuid::from_bytes(&filesystem.header.1.uuid).unwrap().hyphenated());
},
......@@ -263,6 +263,18 @@ fn main() {
}
};
let block_opt = match args.next() {
Some(arg) => match u64::from_str_radix(&arg, 16) {
Ok(block) => Some(block),
Err(err) => {
println!("redoxfs: invalid block '{}': {}", arg, err);
usage();
process::exit(1);
}
},
None => None,
};
let mut pipes = [0; 2];
if pipe(&mut pipes) == 0 {
let mut read = unsafe { File::from_raw_fd(pipes[0] as RawFd) };
......@@ -272,7 +284,7 @@ fn main() {
if pid == 0 {
drop(read);
daemon(&disk_id, &mountpoint, write);
daemon(&disk_id, &mountpoint, block_opt, write);
} else if pid > 0 {
drop(write);
......
......@@ -13,8 +13,8 @@ pub struct FileSystem<D: Disk> {
impl<D: Disk> FileSystem<D> {
/// Open a file system on a disk
pub fn open(mut disk: D) -> Result<Self> {
for block in 0..65536 {
pub fn open(mut disk: D, block_opt: Option<u64>) -> Result<Self> {
for block in block_opt.map_or(0..65536, |x| x..x + 1) {
let mut header = (0, Header::default());
disk.read_at(block + header.0, &mut header.1)?;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment