2009-10-30 18 views
2

這是一個後續我的其他問題在這裏:如何在Linux中使用C獲得更多文件的vfat屬性?

How to read vfat attributes of files in Linux using C

-

我看到這個結構在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) */ 
}; 

我的問題是,是否有可能在我的用戶應用程序中填充這樣一個結構體?我的應用程序要求是它應該能夠遍歷vfat文件系統,並獲取它找到的每個目錄/文件的vfat屬性(msdos_dir_entry)。

謝謝。

+0

http://www.mjmwired.net /kernel/Documentation/filesystems/vfat.txt – gcb 2011-09-06 06:32:54

回答

4

實際上,通過組合從fstat(),FAT_IOCTL_GET_ATTRIBUTES和VFAT_IOCTL_READDIR_BOTH ioctls獲得的信息,您幾乎可以獲得所有這些信息。雖然看起來不太好,因爲對於前兩者你需要文件fd,後兩者你需要該文件所在的目錄的fd。

+0

剛纔我也剛剛得出這個結論,你說得對,看起來不太好。但這是一個要求,所以我沒有多少選擇。 =) 您能舉例說明如何使用FAT_IOCTL_GET_ATTRIBUTES和VFAT_IOCTL_READDIR_BOTH嗎? ephemient已經在另一個問題中爲我提供了一個例子,但我會欣賞更多的例子(因爲我對ioctl不是很熟悉)。 謝謝。 – Katsupoy 2009-10-30 06:38:06

+0

如果您有Linux源代碼的副本,請查看目錄ioctls的'/ usr/src/linux/fs/fat/dir.c'。它不會填充'struct msdos_dir_entry',但它會填充兩個'struct __fat_dirent'(一個用於短名稱,一個用於長名稱)。 – ephemient 2009-10-30 19:34:14

相關問題