tags:

views:

146

answers:

1

This is a follow-up to my other question here:

http://stackoverflow.com/questions/1644416/how-to-read-vfat-attributes-of-files-in-linux-using-c

--

I saw this struct in linux/msdos_fs.h:

struct msdos_dir_entry {
   __u8  name[8],ext[3];   /* name and extension */
   __u8  attr;    /* attribute bits */
   __u8    lcase;    /* Case for base and extension */
   __u8  ctime_cs;   /* Creation time, centiseconds (0-199) */
   __le16   ctime;      /* Creation time */
   __le16   cdate;      /* Creation date */
   __le16   adate;      /* Last access date */
   __le16   starthi; /* High 16 bits of cluster in FAT32 */
   __le16   time,date,start;/* time, date and first cluster */
   __le32   size;    /* file size (in bytes) */
};

My question is, would it be possible to populate such a struct inside my user application? My app requirement is that it should be able traverse a vfat filesystem, and get the vfat attributes (msdos_dir_entry) for each directory/file it finds.

Thanks.

+2  A: 

Actually you can get almost all of this by combining the information you can get from fstat(), the FAT_IOCTL_GET_ATTRIBUTES and VFAT_IOCTL_READDIR_BOTH ioctls. It's not going to nice to look at though, since for the fromer two you need the file fd and for the latter two you need the fd of the dir the file is located in.

I also just came to this conclusion a while ago, you're right it's not going to be nice to look at. But it's a requirement so I've got little choice. =)May you provide examples how to use FAT_IOCTL_GET_ATTRIBUTES and VFAT_IOCTL_READDIR_BOTH? ephemient already provided me with an example in the other question, but I'll appreciate further examples (since I'm not really familiar with ioctl).Thanks.
Katsupoy
If you have a copy of the Linux source lying around, look at `/usr/src/linux/fs/fat/dir.c` for the directory ioctls. It won't populate a `struct msdos_dir_entry`, but it will populate two `struct __fat_dirent`s (one for the short name, one for the long name).
ephemient