fatr not working with new fat12 images
kallisti5 opened this issue · 2 comments
kallisti5 commented
Creating a new 16MiB image, attempting to inject 84K file via fatr:
kallisti5@eris fatr :( $ dd if=/dev/zero of=/home/kallisti5/fat12.img bs=$((1024*1024)) count=16
16+0 records in
16+0 records out
16777216 bytes (17 MB, 16 MiB) copied, 0.00789041 s, 2.1 GB/s
kallisti5@eris fatr :) $ ls -lah /home/kallisti5/fat12.img
-rw-rw-r-- 1 kallisti5 kallisti5 16M Aug 11 08:04 /home/kallisti5/fat12.img
kallisti5@eris fatr :) $ mkfs.fat -F12 /home/kallisti5/fat12.img
mkfs.fat 4.1 (2017-01-24)
kallisti5@eris fatr :) $ file /home/kallisti5/fat12.img
/home/kallisti5/fat12.img: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 16, reserved sectors 16, root entries 512, sectors 32768 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 16, sectors/track 32, heads 64, serial number 0xb6b5b284, unlabeled, FAT (12 bit)
kallisti5@eris fatr :) $ ./target/debug/
build/ deps/ examples/ fatr .fingerprint/ incremental/ native/
kallisti5@eris fatr :) $ ./target/debug/fatr ls /home/kallisti5/fat12.img
kallisti5@eris fatr :) $ ./target/debug/fatr add /home/kallisti5/error.png /home/kallisti5/fat12.img
error: no free entries
Injecting the file with linux mount, but not showing via fatr ls:
kallisti5@eris fatr :( $ mkdir /tmp/mount
kallisti5@eris fatr :( $ sudo mount /home/kallisti5/fat12.img /tmp/mount
kallisti5@eris fatr :( $ sudo cp ~/error.png /tmp/mount/
kallisti5@eris fatr :) $ sudo umount /tmp/mount
kallisti5@eris fatr :) $ ./target/debug/fatr ls /home/kallisti5/fat12.img
kallisti5@eris fatr :) $
kallisti5 commented
Hm, a little troubleshooting:
diff --git a/src/fat/image.rs b/src/fat/image.rs
index 9357cf3..d874fad 100644
--- a/src/fat/image.rs
+++ b/src/fat/image.rs
@@ -75,6 +75,7 @@ impl Image {
// TODO: Make this an iterator
pub fn root_entries(&self) -> Vec<RootEntry> {
+ println!("root_dir: {:?}", self.root_dir);
self.root_dir
.chunks(BYTES_PER_ROOT_ENTRY)
.map(|chunk| {
@@ -83,10 +84,11 @@ impl Image {
let entry: RootEntry;
unsafe { entry = mem::transmute(entry_bytes); }
+ println!("entry: {:?}", entry);
entry
})
.filter(|entry| { entry.filename[0] != 0xe5 })
- .take_while(|entry| { entry.filename[0] != 0 })
+ //.take_while(|entry| { entry.filename[0] != 0 })
.collect::<Vec<RootEntry>>()
}
Full data attached.
$ file ~/fat12.img
/home/kallisti5/fat12.img: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 16, reserved sectors 16, root entries 512, sectors 32768 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 16, sectors/track 32, heads 64, serial number 0xa658378, unlabeled, FAT (12 bit)
Looks like:
- Root entries aren't populated in order from 0+
- Root entry offsets incorrect?
kallisti5 commented
After using the data from the BIOS Param Block instead of making assumptions on sector sizes, starting to see some life from fatr on fat12 images created under Linux:
kallisti5@nyx fatr :) $ ./target/debug/fatr ls ~/fat12.img
BIOSParam { bytes_per_sector: 512, sectors_per_cluster: 4, reserved_sectors: 1, fat_count: 2, max_roots: 512, sectors: 8192, media_id: 248, sectors_per_fat: 6 }
HAIKU . 0
Atest.. 4294967295
TEST .TXT 7