mod linux;
use linux::*;
use embedded_sdmmc::{ShortFileName, VolumeIdx};
type Error = embedded_sdmmc::Error<std::io::Error>;
type Directory<'a> = embedded_sdmmc::Directory<'a, LinuxBlockDevice, Clock, 8, 4, 4>;
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
fn main() -> Result<(), Error> {
env_logger::init();
let mut args = std::env::args().skip(1);
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
let root_dir = volume.open_root_dir()?;
list_dir(root_dir, "/")?;
Ok(())
}
fn list_dir(directory: Directory<'_>, path: &str) -> Result<(), Error> {
println!("Listing {}", path);
let mut children = Vec::new();
directory.iterate_dir(|entry| {
println!(
"{:12} {:9} {} {}",
entry.name,
entry.size,
entry.mtime,
if entry.attributes.is_directory() {
"<DIR>"
} else {
""
}
);
if entry.attributes.is_directory()
&& entry.name != ShortFileName::parent_dir()
&& entry.name != ShortFileName::this_dir()
{
children.push(entry.name.clone());
}
})?;
for child_name in children {
let child_dir = directory.open_dir(&child_name)?;
let child_path = if path == "/" {
format!("/{}", child_name)
} else {
format!("{}/{}", path, child_name)
};
list_dir(child_dir, &child_path)?;
}
Ok(())
}