Skip to content

Commit

Permalink
calls: Update params in openat2()
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Jul 30, 2024
1 parent 29fe4cc commit 8e74ebb
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 52 deletions.
4 changes: 3 additions & 1 deletion src/calls/getfsstat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ pub unsafe fn getfsstat(buf: Option<&mut [statfs_t]>, mode: i32) -> Result<i32,
let buf_size = buf
.as_ref()
.map_or(0, |buf| buf.len() * core::mem::size_of::<statfs_t>());
let buf_ptr = buf.map_or(0, |buf| buf.as_mut_ptr() as usize);
let buf_ptr = buf.map_or(core::mem::null_mut::<statfs_t>() as usize, |buf| {
buf.as_mut_ptr() as usize
});
let mode = mode as usize;
syscall3(SYS_GETFSSTAT, buf_ptr, buf_size, mode).map(|val| val as i32)
}
4 changes: 3 additions & 1 deletion src/calls/getvfsstat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ pub unsafe fn getvfsstat(buf: Option<&mut [statvfs_t]>, mode: i32) -> Result<i32
let buf_size = buf
.as_ref()
.map_or(0, |buf| buf.len() * core::mem::size_of::<statvfs_t>());
let buf_ptr = buf.map_or(0, |buf| buf.as_mut_ptr() as usize);
let buf_ptr = buf.map_or(core::mem::null_mut::<statvfs_t>() as usize, |buf| {
buf.as_mut_ptr() as usize
});
let mode = mode as usize;
syscall3(SYS_GETVFSSTAT, buf_ptr, buf_size, mode).map(|val| val as i32)
}
8 changes: 3 additions & 5 deletions src/calls/openat2_linux.rs → src/calls/openat2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -20,11 +18,11 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}
8 changes: 3 additions & 5 deletions src/platform/linux-aarch64/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3959,14 +3959,12 @@ pub unsafe fn openat<P: AsRef<Path>>(
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -3976,13 +3974,13 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}

/// Obtain handle for an open file
Expand Down
8 changes: 3 additions & 5 deletions src/platform/linux-arm/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4534,14 +4534,12 @@ pub unsafe fn openat<P: AsRef<Path>>(
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -4551,13 +4549,13 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}

/// Obtain handle for an open file
Expand Down
8 changes: 3 additions & 5 deletions src/platform/linux-mips/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4699,14 +4699,12 @@ pub unsafe fn openat<P: AsRef<Path>>(
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -4716,13 +4714,13 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}

/// Obtain handle for an open file
Expand Down
8 changes: 3 additions & 5 deletions src/platform/linux-mips64/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4449,14 +4449,12 @@ pub unsafe fn openat<P: AsRef<Path>>(
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -4466,13 +4464,13 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}

/// Obtain handle for an open file
Expand Down
8 changes: 3 additions & 5 deletions src/platform/linux-ppc64/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4570,14 +4570,12 @@ pub unsafe fn openat<P: AsRef<Path>>(
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -4587,13 +4585,13 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}

/// Obtain handle for an open file
Expand Down
8 changes: 3 additions & 5 deletions src/platform/linux-riscv64/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3959,14 +3959,12 @@ pub unsafe fn openat<P: AsRef<Path>>(
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -3976,13 +3974,13 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}

/// Obtain handle for an open file
Expand Down
8 changes: 3 additions & 5 deletions src/platform/linux-s390x/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4532,14 +4532,12 @@ pub unsafe fn openat<P: AsRef<Path>>(
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -4549,13 +4547,13 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}

/// Obtain handle for an open file
Expand Down
8 changes: 3 additions & 5 deletions src/platform/linux-x86/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4714,14 +4714,12 @@ pub unsafe fn openat<P: AsRef<Path>>(
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -4731,13 +4729,13 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}

/// Obtain handle for an open file
Expand Down
8 changes: 3 additions & 5 deletions src/platform/linux-x86_64/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4497,14 +4497,12 @@ pub unsafe fn openat<P: AsRef<Path>>(
/// # Examples
///
/// ```
/// use core::mem::size_of;
/// let path = "/etc/passwd";
/// let mut how = nc::open_how_t{
/// flags: nc::O_RDONLY as u64,
/// ..nc::open_how_t::default()
/// };
/// let how_size = size_of::<nc::open_how_t>();
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how, how_size) };
/// let ret = unsafe { nc::openat2(nc::AT_FDCWD, path, &mut how) };
/// assert!(ret.is_ok());
/// let fd = ret.unwrap();
/// let ret = unsafe { nc::close(fd) };
Expand All @@ -4514,13 +4512,13 @@ pub unsafe fn openat2<P: AsRef<Path>>(
dirfd: i32,
pathname: P,
how: &mut open_how_t,
size: size_t,
) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let pathname = CString::new(pathname.as_ref());
let pathname_ptr = pathname.as_ptr() as usize;
let how_ptr = how as *mut open_how_t as usize;
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, size).map(|ret| ret as i32)
let how_size = core::mem::size_of::<open_how_t>();
syscall4(SYS_OPENAT2, dirfd, pathname_ptr, how_ptr, how_size).map(|ret| ret as i32)
}

/// Obtain handle for an open file
Expand Down

0 comments on commit 8e74ebb

Please sign in to comment.