linuxrustpermissionsfs

What's the equivalent to chattr in the rust standard library?


I need to execute the equivalent of chattr +i myfile.txt in rust.

Since the call for chmod is fs::set_permissions() I was expecting something like fs::set_attributes() to also exists, but I cannot find it in the docs.

Is there an std function to set (linux) file attributes?


Solution

  • There is nothing in the standard library for this. The i attribute, and file attributes in general, are very system specific, and are outside the scope for a portable standard library.

    Internally, the chattr uses the FS_IOC_SETFLAGS ioctl. You may have to implement code that uses it yourself, using a crate like nix can help.