ifd3f / caligula

A user-friendly, lightweight TUI for disk imaging
GNU General Public License v3.0
333 stars 6 forks source link

Failed to write block to disk: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }) on MacOS #124

Closed ifd3f closed 5 months ago

ifd3f commented 5 months ago

This issue has been split off from #105 .

To Reproduce

Steps to reproduce the behavior:

  1. Plug in a USB
  2. ./caligula-x86_64-darwin burn caligula-x86_64-darwin
  3. Go through the prompts
  4. Select the plugged USB
  5. The osascript prompt pops up. Entering in the password, however, does not appear to grant sudo, and the password is asked in the terminal again.
  6. Running yields the error

See the following error logs: 1714950829848.child.log 1714950829848.main.log

2024-05-05T23:14:00.846797Z DEBUG caligula::writer_process::child: Opening file caligula-x86_64-darwin
2024-05-05T23:14:00.846821Z DEBUG caligula::writer_process::child: Got input file size size=3998608
2024-05-05T23:14:00.846829Z DEBUG caligula::writer_process::child: Opening /dev/rdisk2 for writing
2024-05-05T23:14:00.916385Z ERROR caligula::writer_process::child: PanicInfo { payload: Any { .. }, message: Some(Failed to write block to disk: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }), location: Location { file: "src/writer_process/child.rs", line: 185, col: 14 }, can_unwind: true, force_no_backtrace: false }

Since it's at this specific line, that implies we opened it correctly, but the first block isn't even being written.

    #[inline]
    fn on_block(&mut self, block: &[u8], _scratch: &mut [u8]) -> Result<(), ErrorType> {
        trace!(block_len = block.len(), "Writing block");

        let written = self
            .file
            .write(block)
            .expect("Failed to write block to disk"); // line 185
        if written != block.len() {
            return Err(ErrorType::EndOfOutput);
        }
        Ok(())
    }

Originally posted by @ifd3f in https://github.com/ifd3f/caligula/issues/105#issuecomment-2094989965

ifd3f commented 5 months ago

Actually, this works on inputs with sizes aligned to block size. So it's most definitely a block alignment problem.