阅读:2430回复:18
有谁知道怎样枚举系统的物理硬盘吗?以及这些物理硬盘和那些逻辑盘对应?
有那位知道的,请赐教!
[编辑 - 7/13/02 by roger_ding] |
|
沙发#
发布于:2002-07-12 23:39
在DDK里面有函数可以得到有多少个物理硬盘的啊!至于你说的物理硬盘和逻辑硬盘的对应关系!你的说法可能有误,我的理解是逻辑分区属于那个物理硬盘,也可以通过取设备对象来得到的!你去看看DDK里面的例子吧!在src里面的
NTDDK\\src\\storage\\filters\\diskperf |
|
板凳#
发布于:2002-07-13 11:27
先谢谢你的回答,不过有两点我没说清楚,我想在AP这一层实现它,还有就是要在9x下也能工作,2000下其实就可以用MS的enumdisk来实现,但9x下我不知道该怎么做?
|
|
地板#
发布于:2002-07-13 11:35
先谢谢你的回答,不过有两点我没说清楚,我想在AP这一层实现它,还有就是要在9x下也能工作,2000下其实就可以用MS的enumdisk来实现,但9x下我不知道该怎么做? GetLogicalDrives可以得到所有的逻辑盘,然后用GetDriveType可以看它是不是硬盘 好好看看File I/O API吧 |
|
|
地下室#
发布于:2002-07-13 11:55
那样只能得到逻辑盘,但我想知道系统中有多少物理硬盘以及每个物理硬盘对应哪几个逻辑盘
|
|
5楼#
发布于:2002-07-15 10:04
在应用层的话可以用createfile的啊!你去看看该函数的使用吧!具体的我先不告诉你了,因为里面有一些说明,自己再考虑一下就可以解决的了!2K和9x是一样的方法
|
|
6楼#
发布于:2002-07-15 15:14
在应用层的话可以用createfile的啊!你去看看该函数的使用吧!具体的我先不告诉你了,因为里面有一些说明,自己再考虑一下就可以解决的了!2K和9x是一样的方法 可有的方法只是针对2000的,9x下应该怎么做呢? 拜托了!如果9x也可以的话我送你40分! 有源码的话可以发到我mail里 mail:roger_ding@yahoo.com.cn |
|
7楼#
发布于:2002-07-15 15:25
9x下用VWIN32直接访问硬盘
|
|
|
8楼#
发布于:2002-07-15 16:13
我认为应该通过端口I/O来访问,君不见BIOS怎么检测硬盘的吗~~~
|
|
9楼#
发布于:2002-07-15 16:44
唉,你怎么不去看msdn上面的说明啊!
The CreateFile function creates or opens the following objects and returns a handle that can be used to access the object: Consoles Communications resources Directories (open only) Disk devices (Windows NT/2000 only) Files Mailslots Pipes HANDLE CreateFile( LPCTSTR lpFileName, // file name DWORD dwDesiredAccess, // access mode DWORD dwShareMode, // share mode LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD DWORD dwCreationDisposition, // how to create DWORD dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile // handle to template file ); Disk Devices Volume handles may be opened as noncached at the discretion of the file system, even when the noncached option is not specified with CreateFile. You should assume that all Microsoft file systems open volume handles as noncached. The restrictions on noncached I/O for files apply to volumes as well. A file system may or may not require buffer alignment even though the data is noncached. However, if the noncached option is specified when opening a volume, buffer alignment is enforced regardless of the file system on the volume. It is recommended on all file systems that you open volume handles as noncached and follow the noncached I/O restrictions. Windows NT/2000: You can use the CreateFile function to open a disk drive or a partition on a disk drive. The function returns a handle to the disk device; that handle can be used with the DeviceIOControl function. The following requirements must be met in order for such a call to succeed: The caller must have administrative privileges for the operation to succeed on a hard disk drive. The lpFileName string should be of the form \\\\.\\PHYSICALDRIVEx to open the hard disk x. Hard disk numbers start at zero. For example: String Meaning \\\\.\\PHYSICALDRIVE2 Obtains a handle to the third physical drive on the user\'s computer. For an example showing how to open a physical drive, see Calling DeviceIoControl on Windows NT/2000. The lpFileName string should be \\\\.\\x: to open a floppy drive x or a partition x on a hard disk. For example: String Meaning \\\\.\\A: Obtains a handle to drive A on the user\'s computer. \\\\.\\C: Obtains a handle to drive C on the user\'s computer. There is no trailing backslash in a drive name. The string \"\\\\.\\c:\\\" refers to the root directory of drive C. On Windows 2000, you can also open a volume by referring to its unique volume name. In this case also, there should be no trailing backslash on the unique volume name. Note that all I/O buffers should be sector aligned (aligned on addresses in memory that are integer multiples of the volume\'s sector size), even if the disk device is opened without the FILE_FLAG_NO_BUFFERING flag. Depending the disk, this requirement may not be enforced. Windows 95: This technique does not work for opening a logical drive. In Windows 95, specifying a string in this form causes CreateFile to return an error. The dwCreationDisposition parameter must have the OPEN_EXISTING value. When opening a floppy disk or a partition on a hard disk, you must set the FILE_SHARE_WRITE flag in the dwShareMode parameter. 当你需要知道有几个物理硬盘的时候只需要通过一个循环就可以了!对于一般的机器x不会大于4的啊! |
|
10楼#
发布于:2002-07-15 23:03
可是我上面说的是要9x能工作的,\"\\\\\\\\.\\\\C:\", \"\"\\\\\\\\.\\\\PHYSICALDRIVEx\"在9x不行的! :(
\"Windows 95/98/Me: This technique does not work for opening a logical drive. Specifying a string in this form causes CreateFile to return an error.\" 而且最重要的是要知道某个物理硬盘上有几个逻辑盘,你还有什么更好的方法吗?谢了! |
|
11楼#
发布于:2002-07-16 18:53
\"Windows 95/98/Me: This technique does not work for opening a logical drive. Specifying a string in this form causes CreateFile to return an error.\"
但是可以对物理的硬盘 |
|
12楼#
发布于:2002-07-16 18:53
在9x下可以用int13的
|
|
13楼#
发布于:2002-07-17 09:12
HANDLE hDev=CreateFile(\"\\\\\\\\.\\\\PHYSICALDRIVE0\",GENERIC_READ,FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
在9x不成功???,那物理硬盘还有什么方法打开呢? int13怎么调用可以求得物理盘和逻辑盘的对应关系? |
|
14楼#
发布于:2002-07-18 16:28
可以采用WMI(Windows管理接口)的方法。
SDK\\Samples\\SysMgmt\\WMI\\VC\\下的SimpleClient是用来列举逻辑盘的;WMIDiskPerf我也没看过,不知道是干什么的。 当然,WMI也有列举物理盘的方法,我想,可以先列举出物理盘,再查询与其关联的逻辑盘。 这种方法比较麻烦,但可以得到关于查询对象的所有的信息,比如各逻辑盘的大小、剩余多少空间等等。 |
|
15楼#
发布于:2002-07-19 01:53
CM_Enumerate_Classes_Ex
or CM_Enumerate_Classes |
|
16楼#
发布于:2002-08-07 21:50
[quote]先谢谢你的回答,不过有两点我没说清楚,我想在AP这一层实现它,还有就是要在9x下也能工作,2000下其实就可以用MS的enumdisk来实现,但9x下我不知道该怎么做? GetLogicalDrives可以得到所有的逻辑盘,然后用GetDriveType可以看它是不是硬盘 好好看看File I/O API吧 [/quote] 这个是应用层的,DDK 中有响应的函数吗? DRIVER中要知道当前系统中的逻辑盘怎么办呢? 不会还要APP告诉它吧,谢谢 |
|
17楼#
发布于:2004-05-26 10:29
IOCTL_DISK_CONTROLLER_NUMBER可以试试看
|
|
18楼#
发布于:2004-05-26 16:14
IOCTL_DISK_CONTROLLER_NUMBER可以试试看利害, :cool: |
|