阅读:3446回复:16
有无办法判断磁盘分区类型,如ntfs,fat32
有无办法判断磁盘分区类型,如ntfs,fat32。 谢谢
|
|
最新喜欢:123abc |
沙发#
发布于:2007-09-05 10:07
...很简单的...
|
|
|
板凳#
发布于:2007-09-05 10:30
能否劳驾简单说明一下?谢谢
找到了函数ZwQueryVolumeInformationFile,但它需要handle,希望在FsControlMountVolume中取得,但如何取得handle呢? |
|
地板#
发布于:2007-09-05 10:38
//
// NodeTypeCode values used ranges // // CDFS - 0x0300 - 0x033F // CLFS - 0x0400 - 0x043F // WINFS - 0x0440 - 0x047F // FASTFAT - 0x0500 - 0x053F // RAW - 0x0600 - 0x063F // NTFS - 0x0700 - 0x07FF // UDFS - 0x0900 - 0x093F // EXFAT - 0x0D00 - 0x0D3F // - 0x8000 - 0xBFFF reserved for 3rd party file systems // WIMFilter - 0x1000 - 0x103F // NCFILTER - 0x2200 - 0x223F sample minifilter // RDBSS - 0xEB00 - 0xECFF // NULMRX - 0xFF00 - 0xFF3F sample redirector NodeTypeCode = (PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext |
|
驱动小牛
|
地下室#
发布于:2007-09-05 10:38
在分区的头一个扇区对文件系统有标识,具体要查下资料.
|
|
5楼#
发布于:2007-09-05 12:04
问题解决。谢谢以上热心同仁。采用3楼的方法。
本来是希望取盘符时同时得到分区类型,这样使用时查找即可,但没有找到方法。不过3楼的方法好像对效率没有什么影响。 |
|
6楼#
发布于:2007-09-05 16:43
#1: 分区(卷)的文件系统类型识别过程,不仅涉及检查其引导扇区,通常也要检查文件系统元数据,以便保证一致性。特别地,对于FAT文件系统格式——FAT12、FAT16、FAT32——只能通过卷中簇的数量来判定,没有其他正确的方法。因此,只通过检查引导扇区里的标志来判定并不是正确的做法,虽然往往得出正确的结果。
#2: 用windows API 函数就可以了啊: GetVolumeInformation( LPTSTR lpRootPathName, // 逻辑驱动器的根目录 LPTSTR lpVolumeNameBuffer, // 返回卷的名字 DWORD nVolumeNameSize, // 卷缓冲区的尺寸 LPDWORD lpVolumeSerialNumber, // 卷的序列号 LPDWORD lpMaximumComponentLength, // 返回支持的目录名和文件名的最大字符数 LPDWORD lpFileSystemFlags, // 返回文件系统的标志 LPTSTR lpFileSystemNameBuffer, // 返回文件系统的名字(FAT,HPFS,NTFS或CDFS) DWORD nFileSystemNameSize// 文件系统名字缓冲区的最大尺寸 ) #3: 如何使用: char Volume[256]; DWORD SerialNum; DWORD FileSystemFlags; char lpFileSystemNameBuffer[256]; memset(lpFileSystemNameBuffer, 0, 256); memset(Volume,0,256); CString strDisk("C:\\\\"); GetVolumeInformation(strDisk, Volume, 256, &SerialNum, NULL, &FileSystemFlags, lpFileSystemNameBuffer, 256); CString Vol_Type; if(!strcmp(lpFileSystemNameBuffer, "NTFS")) { Vol_Type = "NTFS"; } else if(!strcmp(lpFileSystemNameBuffer, "FAT32")) { Vol_Type = "FAT32"; } else { //... } |
|
7楼#
发布于:2007-09-05 17:58
引用第6楼flyingstarsoul于2007-09-05 16:43发表的 : 是否应使用ZwQueryVolumeInformationFile?(讨论) |
|
8楼#
发布于:2007-09-05 18:20
引用第6楼flyingstarsoul于2007-09-05 16:43发表的 : 你如果以这种方式判断,也不一定对的。因为那个"FAT32","NTFS" 的字符串,并不是用于判断分区类型的。哪天某个软件把这字符改了,系统分区类型没变,你却得到不对的结果。 |
|
|
9楼#
发布于:2007-09-05 18:24
读取分区的第一个引导扇区,然后判断
|
|
10楼#
发布于:2007-09-05 18:49
...yuanyuan说出来,就不好玩了。。
|
|
|
11楼#
发布于:2007-09-06 11:32
引用第10楼ProPlayboy于2007-09-05 18:49发表的 : 呵呵,来论坛就是来帮人的嘛,我自己也从一无所知成长的,我还是喜欢国外那些论坛里面的坦诚和可爱。 |
|
12楼#
发布于:2007-09-06 11:38
引用第9楼yuanyuan于2007-09-05 18:24发表的 : 能否告知读取方法或函数? |
|
禁止发言
|
13楼#
发布于:2007-09-07 00:12
用户被禁言,该主题自动屏蔽! |
14楼#
发布于:2007-09-07 10:04
引用第8楼ProPlayboy于2007-09-05 18:20发表的 : “不是用于判断分区类型”的,那是用来干什么的呢?? |
|
15楼#
发布于:2007-09-07 10:12
引用第9楼yuanyuan于2007-09-05 18:24发表的 : 具体怎么判断?不会仅仅根据某个标志吧 |
|
16楼#
发布于:2007-09-25 00:03
不要在这里误人子弟了,以下来自微软FAT规范
Now we can determine the FAT type. Please note carefully or you will commit an off-by-one error! In the following example, when it says <, it does not mean <=. Note also that the numbers are correct. The first number for FAT12 is 4085; the second number for FAT16 is 65525. These numbers and the ‘<’ signs are not wrong. If(CountofClusters < 4085) { /* Volume is FAT12 */ } else if(CountofClusters < 65525) { /* Volume is FAT16 */ } else { /* Volume is FAT32 */ } This is the one and only way that FAT type is determined. There is no such thing as a FAT12 volume that has more than 4084 clusters. There is no such thing as a FAT16 volume that has less than 4085 clusters or more than 65,524 clusters. There is no such thing as a FAT32 volume that has less than 65,525 clusters. If you try to make a FAT volume that violates this rule, Microsoft operating systems will not handle them correctly because they will think the volume has a different type of FAT than what you think it does. NOTE: As is noted numerous times earlier, the world is full of FAT code that is wrong. There is a lot of FAT type code that is off by 1 or 2 or 8 or 10 or 16. For this reason, it is highly recommended that if you are formatting a FAT volume which has maximum compatibility with all existing FAT code, then you should you avoid making volumes of any type that have close to 4,085 or 65,525 clusters. Stay at least 16 clusters on each side away from these cut-over cluster counts. 存放在DBR中的分区类型,不一定都正确,即使正确,也不能保证不被非法修改。理论上6楼为正解,但我没亲手测试过哦。 |
|