Skip to content

Commit

Permalink
chore: bump nix dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
oll3 committed Sep 20, 2021
1 parent f9e865d commit bcce957
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = ["filesystem", "asynchronous", "os", "network-programming"]
async-trait = "0.1"
byteorder = "1.4"
futures-util = { version = "0.3", default-features = false }
nix = "0.20"
nix = "0.22"
tokio = { version = "1" }

[dev-dependencies]
Expand Down
50 changes: 27 additions & 23 deletions src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,75 +25,79 @@ pub fn set_sock<F>(f: &F, sock: RawFd) -> io::Result<i32>
where
F: AsRawFd,
{
Errno::result(unsafe { ioctl(f.as_raw_fd(), request_code_none!(0xab, 0), sock) })
.map_err(errno_to_io)
Ok(Errno::result(unsafe {
ioctl(f.as_raw_fd(), request_code_none!(0xab, 0), sock)
})?)
}

pub fn set_block_size<F>(f: &F, size: u32) -> io::Result<i32>
where
F: AsRawFd,
{
Errno::result(unsafe { ioctl(f.as_raw_fd(), request_code_none!(0xab, 1), size) })
.map_err(errno_to_io)
Ok(Errno::result(unsafe {
ioctl(f.as_raw_fd(), request_code_none!(0xab, 1), size)
})?)
}

pub fn do_it<F>(f: &F) -> io::Result<i32>
where
F: AsRawFd,
{
Errno::result(unsafe { ioctl(f.as_raw_fd(), request_code_none!(0xab, 3)) }).map_err(errno_to_io)
Ok(Errno::result(unsafe {
ioctl(f.as_raw_fd(), request_code_none!(0xab, 3))
})?)
}

pub fn clear_sock<F>(f: &F) -> io::Result<i32>
where
F: AsRawFd,
{
Errno::result(unsafe { ioctl(f.as_raw_fd(), request_code_none!(0xab, 4)) }).map_err(errno_to_io)
Ok(Errno::result(unsafe {
ioctl(f.as_raw_fd(), request_code_none!(0xab, 4))
})?)
}

pub fn clear_queue<F>(f: &F) -> io::Result<i32>
where
F: AsRawFd,
{
Errno::result(unsafe { ioctl(f.as_raw_fd(), request_code_none!(0xab, 5)) }).map_err(errno_to_io)
Ok(Errno::result(unsafe {
ioctl(f.as_raw_fd(), request_code_none!(0xab, 5))
})?)
}

pub fn set_size_blocks<F>(f: &F, size: u64) -> io::Result<i32>
where
F: AsRawFd,
{
Errno::result(unsafe { ioctl(f.as_raw_fd(), request_code_none!(0xab, 7), size) })
.map_err(errno_to_io)
Ok(Errno::result(unsafe {
ioctl(f.as_raw_fd(), request_code_none!(0xab, 7), size)
})?)
}

pub fn disconnect<F>(f: &F) -> io::Result<i32>
where
F: AsRawFd,
{
Errno::result(unsafe { ioctl(f.as_raw_fd(), request_code_none!(0xab, 8)) }).map_err(errno_to_io)
Ok(Errno::result(unsafe {
ioctl(f.as_raw_fd(), request_code_none!(0xab, 8))
})?)
}

pub fn set_timeout<F>(f: &F, timeout: u64) -> io::Result<i32>
where
F: AsRawFd,
{
Errno::result(unsafe { ioctl(f.as_raw_fd(), request_code_none!(0xab, 9), timeout) })
.map_err(errno_to_io)
Ok(Errno::result(unsafe {
ioctl(f.as_raw_fd(), request_code_none!(0xab, 9), timeout)
})?)
}

pub fn set_flags<F>(f: &F, flags: u64) -> io::Result<i32>
where
F: AsRawFd,
{
Errno::result(unsafe { ioctl(f.as_raw_fd(), request_code_none!(0xab, 10), flags) })
.map_err(errno_to_io)
}

fn errno_to_io(error: nix::Error) -> io::Error {
match error {
nix::Error::Sys(errno) => io::Error::from_raw_os_error(errno as i32),
nix::Error::InvalidPath => io::Error::from(io::ErrorKind::InvalidInput),
nix::Error::InvalidUtf8 => io::Error::from(io::ErrorKind::InvalidData),
nix::Error::UnsupportedOperation => io::Error::new(io::ErrorKind::Other, "not supported"),
}
Ok(Errno::result(unsafe {
ioctl(f.as_raw_fd(), request_code_none!(0xab, 10), flags)
})?)
}

0 comments on commit bcce957

Please sign in to comment.