I have a FAT filesystem mounted in Linux with the vfat driver. I want to know how I would be able to read the vfat attributes of a file such as "hidden" and "read-only".
Based on what I've read so far, if I use the stat()
glibc command on a file, I would only be getting the file attributes listed here:
http://www.gnu.org/s/libc/manual/html_node/Attribute-Meanings.html#Attribute-Meanings
These don't contain any vfat attributes however. Can anybody help?
Thanks,
Katsupoy
You can list the attribute of the contents of a particular directory with lsattr command followed with a file or directory name as the argument. As the ls -l command, the -d option with lsattr will list the attributes of the directory itself instead of the files in that directory.
How to view and change the file attributes in Windows. To adjust the attributes of a file in MS-DOS or the Windows command line, use the attrib command. In Linux, Linux variants, and Unix to adjust the file attributes use the chmod command.
Linux has several filesystem drivers for the File Allocation Table (FAT) filesystem format. These are commonly known by the names used in the mount command to invoke particular drivers in the kernel: msdos, vfat, and umsdos.
VFAT enables a hard disk drive to store files with names that are more than eight characters long.
FAT's DOS attributes do not map well to the UNIX filesystem model, so Linux's vfat
driver does not reflect them.
Instead of mounting the filesystem, use mtools to read the filesystem from userspace.
Edit I lied. Apparently the vfat
driver is able to deal with these DOS attributes, at least as of 2.4.29 (I think; my historical logs don't go back that far).
#include <inttypes.h>
#include <sys/ioctl.h>
#include <linux/msdos_fs.h>
int fd = open("/mnt/fat/...", ...);
__u32 attrs;
ioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attrs);
attrs = ATTR_NONE; /* ATTR_{RO,HIDDEN,SYS,VOLUME,DIR,ARCH} */
ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attrs);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With