Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wrong xattr syscalls on NetBSD #2961

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SteveLauC
Copy link
Contributor

I am not 100% sure that these bindings are wrong because I can not find them in the NetBSD manual.

But according to sys/sys/xattr.h, they seems to be wrong:

int	setxattr(const char *, const char *, const void *, size_t, int);
int	lsetxattr(const char *, const char *, const void *, size_t, int);

int	fremovexattr(int, const char *);
// Current bindings in `libc`:

pub fn setxattr(
    path: *const ::c_char,
    name: *const ::c_char,
    value: *const ::c_void,
    size: ::size_t,
) -> ::c_int;
pub fn lsetxattr(
    path: *const ::c_char,
    name: *const ::c_char,
    value: *const ::c_void,
    size: ::size_t,
) -> ::c_int;
pub fn fremovexattr(
    fd: ::c_int, 
    path: *const ::c_char, 
    name: *const ::c_char
) -> ::c_int;

Friendly ping @devnexen who originally added them in #2514 .

@rust-highfive
Copy link

r? @JohnTitor

(rust-highfive has picked a reviewer for you, use r? to override)

@JohnTitor
Copy link
Member

I think this is a breaking change as it changes the interface. I'm, however, fine to accept it as long as they aren't usable at all across all NetBSD versions (that makes it possible to assume there's no real user). Could you make sure of that?

@SteveLauC
Copy link
Contributor Author

Yes, this is a breaking change. I will try to fire up a NetBSD VM to test the current APIs.

@SteveLauC
Copy link
Contributor Author

SteveLauC commented Nov 4, 2022

Hi, guys, I just have NetBSD installed (including Rust toolchain and the GCC compiler), so I am ready to test the existing bindings.
Screenshot from 2022-11-04 17-39-43

But I may need some help on how to test them.

What values should be passed for those function parameters that do not exist? (the path argument in removexattr) For parameters that are not exposed, should we just ignore them (flag argument of setxattr and lsetxattr)?

Friendly ping @JohnTitor


UPDATE: I just found that the extended attribute is not enabled by default on NetBSD.

#include <sys/xattr.h>
#include <stdio.h>   
#include <errno.h>
 
int main(int ac, char *av[]) {
        int res = setxattr("/home/steve/workspace/c/file", "user.first_ea", "first_ea", 8, 0);
 
 
        if (res == -1) {
                printf("errno = %d\n", errno);
                perror(NULL);
        } else {
                printf("success");
        }
        return 0;
}
$ gcc main.c && ./a.out
errno = 86
Not supported

So now I need to find a way to enable it...

@SteveLauC
Copy link
Contributor Author

SteveLauC commented Nov 4, 2022

Though EA is not enabled, I still tested the following code snippet:

use libc::{__errno, c_char, c_void, lsetxattr, perror, fremovexattr, setxattr};
use std::{        
    ptr::null_mut,
    os::unix::io::AsRawFd,     
    fs::File,                                  
};       
            
fn test_setxattr() {        
    println!("Testing setxattr:");
    let res = unsafe {
        setxattr(
            "/home/steve/workspace/rust/Cargo.toml\0".as_ptr() as *mut c_char,
            "user.first\0".as_ptr() as *mut c_char,
            "first\0".as_ptr() as *mut c_void,
            5,                                                              
        )                     
    };               
                                                                                          
    if res == -1 {
        unsafe {
            perror(null_mut());
            println!("errno = {}", *__errno());
        }                      
    } else {                                   
        println!("success");
    }       
    println!();             
}    
               
 
fn test_lsetxattr() {
    println!("Testing lsetxattr:");
    let res = unsafe {
        lsetxattr(   
            "/home/steve/workspace/rust/Cargo.toml\0".as_ptr() as *mut c_char,
            "user.first\0".as_ptr() as *mut c_char,
            "user.first\0".as_ptr() as *mut c_char,
            "first\0".as_ptr() as *mut c_void,
            5,
        )
    };

    if res == -1 {
        unsafe {
            perror(null_mut());
            println!("errno = {}", *__errno());
        }
    } else {
        println!("success");
    }
    println!();
}

fn test_fremovexattr() {
    println!("Testing fremovexattr:");
    let file = File::open("/home/steve/workspace/rust/Cargo.toml").unwrap();
    let fd = file.as_raw_fd();
    let res = unsafe{
        fremovexattr(fd, "user.fist\0".as_ptr() as *mut c_char, null_mut() as *mut c_char)
    };
    if res == -1 {
        unsafe {
            perror(null_mut());
            println!("errno = {}", *__errno());
        }
    } else {
        println!("success");
    }
    println!();
}

fn main() {
    test_setxattr();
    test_lsetxattr();
    test_fremovexattr();
}
$ cargo r -q
Testing setxattr:
Not supported
errno = 86

Testing lsetxattr:
Not supported
errno = 86

Testing fremovexattr:
Not supported
errno = 86

The existing bindings seemed to work, at least they showed me that EA is not supported.

@SteveLauC
Copy link
Contributor Author

NetBSD 10 will be the first official release with full extended attribute support in FFS

If we would like to test these bindings further, we have to wait for the NetBSD 10 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants