relan / exfat

Free exFAT file system implementation
GNU General Public License v2.0
793 stars 181 forks source link

attrib: Add tool to set or modify file attributes #163

Closed wjt closed 3 years ago

wjt commented 3 years ago

exFAT files may be marked as hidden, read-only, or system. While these flags may be ignored on Unix platforms, it may be useful to mark a file as hidden when building a filesystem image destined for use on Windows.

This new tool allows these three flags to be set or cleared on a single file on a filesystem. If run with no flags, it displays the file's current attributes, including "dir" and "arch" (whatever that is).

ephemient commented 3 years ago

The meaning of dir/arch on exfat should be the same as vfat, see https://manpages.debian.org/ioctl_fat.2.html

wjt commented 3 years ago

Revised with the following changes:

I went down a little rabbit hole — off the back off @ephemient's comment — into whether the FUSE filesystem could implement the same Linux-specific FAT_IOCTL_GET_ATTRIBUTES and FAT_IOCTL_SET_ATTRIBUTES ioctls. Then it would be possible to set these flags on a mounted filesystem. (Or indeed the same xattrs as used in ntfs, as discussed on #46.) In that case I think the tool's usage could be:

exfatattrib [-aAiIsSrR] [-d DEVICE] PATH […]

to support usage both against a mounted filesystem, and against an unmounted partition; and multiple paths. In the case where we need this tool, we do need to set attributes on multiple files, but it's not exactly hard to write a loop; and we need to unmount the filesystem anyway, so the tool as written will work. But perhaps it's worth changing the syntax to:

exfatattrib [-aAiIsSrR] -d DEVICE PATH

i.e. require a -d option, so it could be made optional in future. What do you think? (I have the patch ⅔ written.)

relan commented 3 years ago

i.e. require a -d option, so it could be made optional in future. What do you think?

Sounds good to me. Will you update this PR? FATIOCTL{GET,SET}_ATTRIBUTES support can be added later of course.

wjt commented 3 years ago

Done!

I chose not to implement support for more than one file at once. It might be a nice exercise for a future reader.

wjt commented 3 years ago

And pushed two identical patches with an updated email address.

relan commented 3 years ago

Thanks! Will integrate into 1.4.0.

sl1pkn07 commented 1 week ago

Hi. is possible use this with mounted device?

background: i have an SD wifi Toshiba FlashAir, witch is an SD card with internal Wifi module. One of the configurations is need protect and unprotect determinaded file for activate or deactivate the wifi module (locked file= wifi OFF, unlock file= wifi ON). this can be done easy in a Cameras (Sony A58 for example) with the protect photos option. but is not possible if mount the SD on PC (Archlinux in my case). i saw i can set the protect/unprotect attribute file with this command. but only works with unmounted filesystem. so, is possible do this in mounted device?

greetings

EDIT: i have tested with mounted device (for the SIENCE!) and works!

└───╼  exfatattrib -d /dev/sdf1 DCIM/100__TSB/FA000001.JPG 
Read-only: yes
   Hidden: no
   System: no
  Archive: no
   Volume: no
Directory: no

sorry the noise. i keep this comment here if any see this usseful

i think need clarify is the unmounted device is a really really neccesary in the manpage

EXFATATTRIB(8)                                                                                                                                           System Manager's Manual                                                                                                                                          EXFATATTRIB(8)

NAME
       exfatattrib - Set or display exFAT file attributes

SYNOPSIS
       exfatattrib [ -r | -R | -i | -I | -s | -S | -a | -A ] -d device file

DESCRIPTION
       exfatattrib sets or displays attributes of a file on an exFAT file system.

       device is the path to an unmounted disk partition or disk image file containing an exFAT file system.

greetings

relan commented 1 week ago

Hi @sl1pkn07!

is possible use this with mounted device?

No, this is not supported yet.

EDIT: i have tested with mounted device (for the SIENCE!) and works!

Don't do that! When attributes are modified on a mounted filesystem, this modification is not serialized with modifications made by the FS driver. This can ruin your FS.

sl1pkn07 commented 1 week ago

:(

thanks for the advise

any future plans for implement this?

greetings

relan commented 1 week ago

any future plans for implement this?

No particular plans, though it would be nice to have, of course.