How to get more vfat attributes of files in Linux

2020-02-29 14:16发布

问题:

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

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.

回答1:

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.



标签: c linux