Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Bad address (os error 14) when trying to unmount filesystem #90

Closed
0x6D70 opened this issue Jan 16, 2024 · 3 comments
Closed

Error: Bad address (os error 14) when trying to unmount filesystem #90

0x6D70 opened this issue Jan 16, 2024 · 3 comments

Comments

@0x6D70
Copy link

0x6D70 commented Jan 16, 2024

The code below fails with the error Error: Bad address (os error 14)

let data_vec = vec![0_u8; 64 * 1024 * 1024];
let mut disk = Cursor::new(data_vec);

format_volume(&mut disk, FormatVolumeOptions::new().fat_type(fatfs::FatType::Fat32))?;

let fs = fatfs::FileSystem::new(disk, fatfs::FsOptions::new())?;

fs.unmount()?;

Is there an issue with my code or the library?

@rafalh
Copy link
Owner

rafalh commented Jan 16, 2024

What version are you using? I tried it with version 0.3.6 and it doesn't fail for me. With master branch it fails to compile.

@0x6D70
Copy link
Author

0x6D70 commented Jan 17, 2024

Thanks with 0.3.6 it seems to work now.
But how am I supposed to read the data_vec afterwards? @rafalh

let data_vec = vec![0_u8; 64 * 1024 * 1024];
let mut disk = Cursor::new(data_vec);

format_volume(&mut disk, FormatVolumeOptions::new().fat_type(fatfs::FatType::Fat32))?;

let fs = fatfs::FileSystem::new(disk, fatfs::FsOptions::new())?;

fs.unmount()?;

fs::write(diskname, data_vec)?;  // ERROR: value used after move !!!

@rafalh
Copy link
Owner

rafalh commented Jan 17, 2024

Currently it is not possible to get back the inner disk object from FileSystem when unmounting (issue #34).
But if what you want to achieve is to write a filesystem image to a local file you can pass std::fs::File object directly to FileSystem::new instead of using Cursor with in-memory vector.

Edit: More generic approach would be to borrow Vec/Cursor instead of passing ownership. It is important to make sure passed type implements Read+Write+Seek. Fortunately Rust std lib helps here because &Read implements Read etc. Following code should work (I pass &mut disk instead of disk to FileSystem::new so it is borrowed and can still be used after fs object is destroyed):

    let data_vec = vec![0_u8; 64 * 1024 * 1024];
    let mut disk = Cursor::new(data_vec);

    format_volume(&mut disk, FormatVolumeOptions::new().fat_type(fatfs::FatType::Fat32))?;

    let fs = fatfs::FileSystem::new(&mut disk, fatfs::FsOptions::new())?;

    fs.unmount()?;
    let data_vec = disk.into_inner();
    fs::write(diskname, data_vec)?;

@0x6D70 0x6D70 closed this as completed Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants