Skip to content
Open
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
50 changes: 40 additions & 10 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 5 additions & 4 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 = "0.2.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,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"

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