#xattr #unix #extended-attribute

extattr

Extended Attributes API bindings for Rust

3 releases (1 stable)

1.0.0 Dec 9, 2022
0.1.1 Nov 4, 2022
0.1.0 Nov 2, 2022

#790 in Filesystem

Download history 67/week @ 2023-11-20 42/week @ 2023-11-27 17/week @ 2023-12-04 20/week @ 2023-12-11 19/week @ 2023-12-18 33/week @ 2023-12-25 104/week @ 2024-01-01 219/week @ 2024-01-08 134/week @ 2024-01-15 59/week @ 2024-01-22 97/week @ 2024-01-29 98/week @ 2024-02-05 122/week @ 2024-02-12 162/week @ 2024-02-19 262/week @ 2024-02-26 150/week @ 2024-03-04

698 downloads per month

GPL-2.0-only

110KB
2.5K SLoC

extattr

Cirrus Build Status crates.io Crates.io docs.rs MSRV License

Yet another Extended Attributes library for Rust.

Table of contents

Supported platforms and their documents

Why another crate for EA? Any difference from xattr?

Extended Attributes syscalls vary across implementations, for example, to set an EA:

// Linux
int setxattr(const char *path, const char *name, const void *value, 
             size_t size, int flags);

// FreeBSD
ssize_t extattr_set_file(const char *path, int attrnamespace,
	 const char *attrname, const void *data, size_t	nbytes);

// macOS
int setxattr(const char *path, const char *name, void *value, size_t size,
         u_int32_t position, int options);

xattr erases differences in those APIs and provides a consistent, rusty interface.

// A consistent API that would work on every OS
pub fn set<N, P>(path: P, name: N, value: &[u8]) -> Result<()> 

extattr aims to provide bindings close to the native one.

// Linux
pub fn setxattr<P, S, B>(
    path: P,
    name: S,
    value: B,
    flags: Flags,
) -> Result<()>

// FreeBSD
pub fn extattr_set_file<P, S, B>(
    path: P,
    attrnamespace: AttrNamespace,
    attrname: S,
    data: B
) -> Result<()>

// macOS
pub fn setxattr<P, S, B>(
    path: P,
    name: S,
    value: B,
    position: u32,
    options: Options
) -> Result<()>

In most cases, you would like to use xattr instead of extattr. However, if you are on Linux and want to use that extra flags argument, or you are on macOS and want to use the arguments position and options, then extattr probably is a good choice:)

Minimum Supported Rust Version (MSRV)

extattr is supported on Rust 1.56.1 and higher. The MSRV will not be changed without bumping the major version.

Contributing

Contributions of all forms are welcome, feel free to file an issue or make a pull request!

Test before your commit
  1. Format the code

    $ cargo fmt
    
  2. Pass the tests

    $ cargo test
    

Dependencies

~75–315KB