cberner / fuser

Filesystem in Userspace (FUSE) for Rust
MIT License
836 stars 114 forks source link

Bugfixed support for compilation with musl without libfuse present #185

Closed gdox closed 3 years ago

gdox commented 3 years ago

An explanation of the unsafe block:

Musl has a different msghdr structure than glibc. It looks as follows:

pub struct msghdr {
    pub msg_name: *mut ::c_void,
    pub msg_namelen: ::socklen_t,
    pub msg_iov: *mut ::iovec,
    #[cfg(target_endian = "big")]
    __pad1: ::c_int,
    pub msg_iovlen: ::c_int,
    #[cfg(target_endian = "little")]
    __pad1: ::c_int,
    pub msg_control: *mut ::c_void,
    #[cfg(target_endian = "big")]
    __pad2: ::c_int,
    pub msg_controllen: ::socklen_t,
    #[cfg(target_endian = "little")]
    __pad2: ::c_int,
    pub msg_flags: ::c_int,
}

The padding fields are necessary due to memory layout, however they are also private, which in conjunction with the lack of constructor means it is impossible to construct a msghdr without resorting to unsafe code. On the other hand the padding guarantees that [0; size_of::<msghdr>()] is a valid representation, which is why I resorted to MaybeUninit::zeroed as unsafe constructor.

In addition struct update syntax (msghdr {..MaybeUninit::zeroed()}) sadly does not work with private fields, so I had to resort to first constructing a zeroed msghdr and then updating the individual fields.

cberner commented 3 years ago

Lgtm, but can you run cargo fmt and amend your commit to fix the CI?

cberner commented 3 years ago

Merged. Thanks!

messense commented 2 years ago

Can we have a new release with this please?

cberner commented 2 years ago

Yep. Just released 0.10.0!