1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::{env::args_os, fs::File, io::Write};
fn main() -> Result<(), std::io::Error> {
let args: Vec<_> = args_os().collect();
if args.len() == 1 {
eprintln!("usage: {:?} <diskFileName> ", args[0].as_os_str());
return Err(std::io::ErrorKind::InvalidInput.into());
}
println!("Creating a 128KB file in {:?}", args[1]);
println!("This file will act as a dummy disk and will hold your filesystem");
let mut my_disk = File::create(&args[1])?;
println!("Formatting your filesystem...");
let mut buf = [0u8; 1024];
buf[0] = 1;
my_disk.write(&buf)?;
buf[0] = 0;
for _ in 0..127 {
my_disk.write(&buf)?;
}
Ok(())
}