diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index df7094e..e3854cc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,24 +1,54 @@ -name: Rust +# Directory structure +# +# By default things occur in $GITHUB_WORKSPACE; as we have to work +# with multiple directories, to keep things clean we use +# subdirectories: +# +# $GITHUB_WORKSPACE/libnfs/ The original C-base C-targetting libnfs +# $GITHUB_WORKSPACE/rs-libnfs/ The code from this repo + +name: Build rs-libnfs on: push: - branches: [ "master" ] + branches: [ "*" ] pull_request: - branches: [ "master" ] + branches: [ "*" ] + workflow_dispatch: + branches: [ "*" ] + inputs: + name: + description: "manual run" env: CARGO_TERM_COLOR: always jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Install libnfs-dev - run: sudo apt-get install -y libnfs-dev - - name: Build - run: cargo build --verbose + - name: Install prerequisites + run: sudo apt-get install -y libkrb5-dev + - name: Clone libnfs + uses: actions/checkout@v4 + with: + repository: sahlberg/libnfs + path: libnfs/ + ref: c09a0f1c90b869b1b1d81df7d80552923150540b + - name: Build and install libnfs + working-directory: libnfs/ + run: | + ./bootstrap + ./configure + make -j4 + sudo make install + - name: Checkout rs-libnfs + uses: actions/checkout@v4 + with: + path: rs-libnfs/ + - name: Build rs-libnfs + working-directory: rs-libnfs/ + run: cargo build --verbose - name: Run tests + working-directory: rs-libnfs/ run: cargo test --verbose diff --git a/Cargo.toml b/Cargo.toml index 79222e8..f840141 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libnfs" -version = "0.1.1" +version = "0.2.0" authors = ["Chris Holcombe "] description = "libnfs bindings allow you to create nfs mounts in memory/userspace" homepage = "https://github.com/cholcombe973/libnfs" @@ -10,10 +10,11 @@ license = "MIT" readme = "README.md" keywords = ["nfs"] categories = ["api-bindings", "network-programming", "filesystem", "external-ffi-bindings"] -edition = '2018' - +edition = '2021' [dependencies] libc = "~0.2" -libnfs-sys = "~0.2" +# Presently the version of crates.io doesn't work (needs update) +libnfs-sys = { git = "https://github.com/cholcombe973/libnfs-sys", ref="890d7566e284ffb00b9d42dedc3cdc1340922e5a" } nix = "~0.25" + diff --git a/examples/basic.rs b/examples/basic.rs index 2659fc1..73c519c 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -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, diff --git a/src/lib.rs b/src/lib.rs index 9a50d97..7df6b8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -220,17 +220,16 @@ impl Nfs { /// O_SYNC /// O_EXCL /// O_TRUNC - pub fn create(&mut self, path: &Path, flags: OFlag, mode: Mode) -> Result { + pub fn creat(&mut self, path: &Path, flags: OFlag, mode: Mode) -> Result { 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, ), )?; @@ -252,7 +251,7 @@ impl Nfs { } /// Get the maximum supported READ3 size by the server - pub fn get_readmax(&self) -> Result { + pub fn get_readmax(&self) -> Result { unsafe { let max = nfs_get_readmax(self.context.0); Ok(max) @@ -260,7 +259,7 @@ impl Nfs { } /// Get the maximum supported WRITE3 size by the server - pub fn get_writemax(&self) -> Result { + pub fn get_writemax(&self) -> Result { unsafe { let max = nfs_get_writemax(self.context.0); Ok(max) @@ -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(()) } @@ -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 { let path = CString::new(path.as_os_str().as_bytes())?; unsafe { @@ -655,15 +670,15 @@ impl NfsFile { } } - pub fn pread(&self, count: u64, offset: u64) -> Result> { + pub fn pread(&self, count: usize, offset: u64) -> Result> { let mut buffer: Vec = 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); @@ -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> { + pub fn read(&self, count: usize) -> Result> { self.pread(count, 0) }