Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libnfs"
version = "0.1.1"
version = "2.0.0"
authors = ["Chris Holcombe <xfactor973@gmail.com>"]
description = "libnfs bindings allow you to create nfs mounts in memory/userspace"
homepage = "https://github.com/cholcombe973/libnfs"
Expand All @@ -10,7 +10,7 @@ license = "MIT"
readme = "README.md"
keywords = ["nfs"]
categories = ["api-bindings", "network-programming", "filesystem", "external-ffi-bindings"]
edition = '2018'
edition = '2021'


[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() -> Result<()> {
}

println!("creating file");
let file = nfs.create(
let file = nfs.creat(
&Path::new("/rust"),
OFlag::O_SYNC,
Mode::S_IROTH | Mode::S_IWOTH,
Expand Down
43 changes: 29 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,16 @@ impl Nfs {
/// O_SYNC
/// O_EXCL
/// O_TRUNC
pub fn create(&mut self, path: &Path, flags: OFlag, mode: Mode) -> Result<NfsFile> {
pub fn creat(&mut self, path: &Path, flags: OFlag, mode: Mode) -> Result<NfsFile> {
let path = CString::new(path.as_os_str().as_bytes())?;
unsafe {
let mut file_handle: *mut nfsfh = ptr::null_mut();
check_retcode(
self.context.0,
nfs_create(
nfs_creat(
self.context.0,
path.as_ptr(),
flags.bits(),
mode.bits() as i32,
flags.bits() | (mode.bits() as i32),
&mut file_handle,
),
)?;
Expand All @@ -252,15 +251,15 @@ impl Nfs {
}

/// Get the maximum supported READ3 size by the server
pub fn get_readmax(&self) -> Result<u64> {
pub fn get_readmax(&self) -> Result<usize> {
unsafe {
let max = nfs_get_readmax(self.context.0);
Ok(max)
}
}

/// Get the maximum supported WRITE3 size by the server
pub fn get_writemax(&self) -> Result<u64> {
pub fn get_writemax(&self) -> Result<usize> {
unsafe {
let max = nfs_get_writemax(self.context.0);
Ok(max)
Expand Down Expand Up @@ -523,9 +522,17 @@ impl Nfs {
}

/// Modify Connect Parameters
pub fn set_readahead(&self, size: u32) -> Result<()> {
pub fn set_readmax(&self, size: usize) -> Result<()> {
unsafe {
nfs_set_readmax(self.context.0, size);
}
Ok(())
}

/// Modify Connect Parameters
pub fn set_writemax(&self, size: usize) -> Result<()> {
unsafe {
nfs_set_readahead(self.context.0, size);
nfs_set_writemax(self.context.0, size);
}
Ok(())
}
Expand All @@ -538,6 +545,14 @@ impl Nfs {
Ok(())
}

/// Modify Connect Parameters
pub fn set_autoreconnect(&self, num_retries: i32) -> Result<()> {
unsafe {
nfs_set_autoreconnect(self.context.0, num_retries);
}
Ok(())
}

pub fn stat64(&self, path: &Path) -> Result<nfs_stat_64> {
let path = CString::new(path.as_os_str().as_bytes())?;
unsafe {
Expand Down Expand Up @@ -655,15 +670,15 @@ impl NfsFile {
}
}

pub fn pread(&self, count: u64, offset: u64) -> Result<Vec<u8>> {
pub fn pread(&self, count: usize, offset: u64) -> Result<Vec<u8>> {
let mut buffer: Vec<u8> = Vec::with_capacity(count as usize);
unsafe {
let read_size = nfs_pread(
self.nfs.0,
self.handle,
offset,
count,
buffer.as_mut_ptr() as *mut _,
count,
offset,
);
check_retcode(self.nfs.0, read_size)?;
buffer.set_len(read_size as usize);
Expand All @@ -676,16 +691,16 @@ impl NfsFile {
let write_size = nfs_pwrite(
self.nfs.0,
self.handle,
offset,
buffer.len() as u64,
buffer.as_ptr() as *mut _,
buffer.len() as usize,
offset,
);
check_retcode(self.nfs.0, write_size)?;
Ok(write_size)
}
}

pub fn read(&self, count: u64) -> Result<Vec<u8>> {
pub fn read(&self, count: usize) -> Result<Vec<u8>> {
self.pread(count, 0)
}

Expand Down