How to read vfat attributes of files in Linux using C
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/开发者_C百科libc/manual/html_node/Attribute-Meanings.html#Attribute-Meanings
These don't contain any vfat attributes however. Can anybody help?
Thanks,
Katsupoy
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);
精彩评论