As a personal project I try to write project with no crates. I need to use syscall ioctl BLKRRPART to re-read partition table on a drive.
This is my current code:
const BLKRRPART: u64 = 0x00001269; // Request number or something.
extern "C" {
fn ioctl(fd: RawFd, request: u64, ...) -> i32;
}
pub fn refresh_partition_table(drive_path: &str) -> Result<(), SpamErrors> {
let dr = File::open(drive_path)?;
let fd: RawFd = dr.as_raw_fd();
// Here we GOOOO
let syscall = unsafe { ioctl(fd, BLKRRPART) };
if syscall == -1 {
return Err(SpamErrors::IOErrors(io::Error::last_os_error().to_string()))
}
Ok(())
}
But when I try to run this, it returns Bad address (os error 14)
and does not work.
I tried searching but I could not find a solution. I also tried to use BLKPG op instead but it returned Invalid argument so I assume I just used it wrongly.
I also tried to pass null pointer from std::ptr::null as an argument but it also did nothing.
Please give answers that do not recommend using some external crates. Thanks.
MarkAssPandi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.