Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl PassthroughFs {

let passthrough_file_attr = FileAttr {
ino: 2,
size: 123456,
size: 123_456,
blocks: 1,
atime: UNIX_EPOCH, // 1970-01-01 00:00:00
mtime: UNIX_EPOCH,
Expand Down
14 changes: 9 additions & 5 deletions src/ll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ macro_rules! errno {
};
}

macro_rules! no_xattr_doc {
() => {"Use this as an error return from getxattr/removexattr to indicate that the xattr doesn't exist. This resolves to the appropriate platform-specific error code."}
}

/// Represents an error code to be returned to the caller
#[derive(Debug)]
pub struct Errno(pub NonZeroI32);
Expand Down Expand Up @@ -213,14 +217,14 @@ impl Errno {
/// No data available
#[cfg(target_os = "linux")]
pub const ENODATA: Errno = errno!(libc::ENODATA);
#[doc = no_xattr_doc!()]
#[cfg(target_os = "linux")]
pub const NO_XATTR: Errno = Self::ENODATA;

/// Attribute not found
#[cfg(not(target_os = "linux"))]
pub const ENOATTR: Errno = errno!(libc::ENOATTR);

/// Use this as an error return from getxattr/removexattr to indicate that the xattr doesn't
/// exist. This resolves to the appropriate platform specific error code.
#[cfg(target_os = "linux")]
pub const NO_XATTR: Errno = Self::ENODATA;
#[doc = no_xattr_doc!()]
#[cfg(not(target_os = "linux"))]
pub const NO_XATTR: Errno = Self::ENOATTR;

Expand Down
46 changes: 44 additions & 2 deletions src/ll/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2175,8 +2175,9 @@ mod tests {
use super::*;
use std::ffi::OsStr;

#[cfg(target_endian = "big")]
#[cfg(all(target_endian = "big", not(feature = "abi-7-36")))]
const INIT_REQUEST: AlignedData<[u8; 56]> = AlignedData([
// decimal 56 == hex 0x38
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x1a, // len, opcode
0xde, 0xad, 0xbe, 0xef, 0xba, 0xad, 0xd0, 0x0d, // unique
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, // nodeid
Expand All @@ -2186,8 +2187,9 @@ mod tests {
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // max_readahead, flags
]);

#[cfg(target_endian = "little")]
#[cfg(all(target_endian = "little", not(feature = "abi-7-36")))]
const INIT_REQUEST: AlignedData<[u8; 56]> = AlignedData([
// decimal 56 == hex 0x38
0x38, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, // len, opcode
0x0d, 0xf0, 0xad, 0xba, 0xef, 0xbe, 0xad, 0xde, // unique
0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, // nodeid
Expand All @@ -2197,6 +2199,40 @@ mod tests {
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // max_readahead, flags
]);

#[cfg(all(target_endian = "big", feature = "abi-7-36"))]
const INIT_REQUEST: AlignedData<[u8; 104]> = AlignedData([
// decimal 104 == hex 0x68
0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x1a, // len, opcode
0xde, 0xad, 0xbe, 0xef, 0xba, 0xad, 0xd0, 0x0d, // unique
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, // nodeid
0xc0, 0x01, 0xd0, 0x0d, 0xc0, 0x01, 0xca, 0xfe, // uid, gid
0xc0, 0xde, 0xba, 0x5e, 0x00, 0x00, 0x00, 0x00, // pid, padding
0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, // major, minor
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // max_readahead, flags
0x00, 0x00, 0x00, 0x00, // flags2 //TODO: nonzero data
0x00, 0x00, 0x00, 0x00, // eleven unused fields
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);

#[cfg(all(target_endian = "little", feature = "abi-7-36"))]
const INIT_REQUEST: AlignedData<[u8; 104]> = AlignedData([
// decimal 104 == hex 0x68
0x68, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, // len, opcode
0x0d, 0xf0, 0xad, 0xba, 0xef, 0xbe, 0xad, 0xde, // unique
0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, // nodeid
0x0d, 0xd0, 0x01, 0xc0, 0xfe, 0xca, 0x01, 0xc0, // uid, gid
0x5e, 0xba, 0xde, 0xc0, 0x00, 0x00, 0x00, 0x00, // pid, padding
0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // major, minor
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // max_readahead, flags
0x00, 0x00, 0x00, 0x00, // flags2 //TODO: nonzero data
0x00, 0x00, 0x00, 0x00, // eleven unused fields
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);

#[cfg(target_endian = "big")]
const MKNOD_REQUEST: AlignedData<[u8; 56]> = [
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x08, // len, opcode
Expand Down Expand Up @@ -2231,15 +2267,21 @@ mod tests {
#[test]
fn short_read() {
match AnyRequest::try_from(&INIT_REQUEST[..48]) {
#[cfg(not(feature = "abi-7-36"))]
Err(RequestError::ShortRead(48, 56)) => (),
#[cfg(feature = "abi-7-36")]
Err(RequestError::ShortRead(48, 104)) => (),
_ => panic!("Unexpected request parsing result"),
}
}

#[test]
fn init() {
let req = AnyRequest::try_from(&INIT_REQUEST[..]).unwrap();
#[cfg(not(feature = "abi-7-36"))]
assert_eq!(req.header.len, 56);
#[cfg(feature = "abi-7-36")]
assert_eq!(req.header.len, 104);
assert_eq!(req.header.opcode, 26);
assert_eq!(req.unique(), RequestId(0xdead_beef_baad_f00d));
assert_eq!(req.nodeid(), INodeNo(0x1122_3344_5566_7788));
Expand Down