tags:

views:

224

answers:

1

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

+2  A: 

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);
ephemient
Thanks, I'll definitely be trying mtools. Aside from mtools, is there any other known way (or hack) to be able to retrieve the FAT attributes?
Katsupoy
This is better, I'll be trying this in my machine tomorrow. Where is FAT_IOCTL_GET_ATTRIBUTES (and maybe other options that might be useful to me) documented? Thanks.
Katsupoy
I found them while digging through `/usr/src/linux/fs/fat/file.c` -- I've never seen any documentation about these ioctls before.
ephemient
I posted a follow-up question here:http://stackoverflow.com/questions/1648117/how-to-get-more-vfat-attributes-of-files-in-linux-using-c
Katsupoy