8

I'm using a custom Bash script running on a Linux machine to mass-duplicate FAT32-formatted USB drives.

I need to preserve Windows file attributes such as "hidden".

I use rsync (or dd with find and mkdir in newer version to force I/O sync for better stability and optimal bandwidth use).

I blindly tried -X and -A switches for rsync, that are said to preserve some file attributes, but they don't seem to work for Windows file attributes.

Is there any way to read and write Windows file attributes in a Linux environment?

I could apply them after copying if there's no easier way.

I don't want to dd an entire source filesystem, because that is going to be badly unoptimized, especially when you need to write hundreds of drives. Sometimes the drives are 16GB in capacity, and only a few GBs of files on them - and a dumb dd would copy all 16GB, taking way to long for this to work in production.

I've searched the web, but looks like Linux extended attributes have nothing to do with Windows file attributes, and I haven't found any way to read and write this information (or just copy it with the files).

  • Is "hidden" the only one you want to preserve or is there any other one? – M. Becerra Jun 1 '17 at 8:58
  • 2
    Interesting. Does the Linux VFAT driver even export those attributes in any way that could be written? – ilkkachu Jun 1 '17 at 9:01
  • @M.Becerra - currently I only need the "hidden" attribute, and I probably won't need any other in the future. – unfa Jun 1 '17 at 9:52
  • @StephenKitt - I need to be able to read that from the source filesystem and transfer that information to my new duplicated filesystems. I guess a very crude method to override this problem would be to zero-fill the source filesystem (to clean the empty space), create a compressed dd image and write that to the new drives skipping sparse parts to avoid writing out empty parts of the image. That's a bit bruteforce and I guess it wouldn't have a comparable performance to rsync or manual find / mkdir / dd operation I use right now. – unfa Jun 2 '17 at 11:13
  • 1
    @ilkkachu yes, it does, there are two ioctls that can be used to retrieve and set FAT attributes. See fatattr for one implementation of a tool using these. – Stephen Kitt Jun 2 '17 at 23:07
1

I can think of a couple of ways to handle this.

The first is to use Mtools to copy the files. For this to work, you’d need to define “drives” (say A: for the source drive, B: for the target), then you should be able to copy everything, preserving attributes and timestamps, using

mcopy -s -p -m a: b:

(untested).

The second is to post-process the attributes using fatattr (which is available in most distributions). It handles mounted file systems, so you’d copy your file systems in the same way you currently do, then use fatattr to list all the FAT attributes of all the source files, and parse that to instruct fatattr to set the attributes appropriately on the target files.

  • I've had problems with mcopy, it crashed trying to copy "System Volume Information" folder raising a "stack smashing detected" GCC error. So I'll try using fatattr. – unfa Jun 5 '17 at 11:05
  • You’ve got “System Volume Information” on a FAT32 file system? I thought that was a NTFS thing only. – Stephen Kitt Jun 5 '17 at 11:10
  • I'd have to check back. – unfa Jun 21 '18 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.