chmode
驱动牛犊
驱动牛犊
  • 注册日期2001-08-06
  • 最后登录2001-12-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1225回复:4

哪位大虾能回答这个问题?快来帮帮忙

楼主#
更多 发布于:2001-12-16 00:54
哪位大虾知道这个问题的答案,请多多指教:
    如何通过盘符(如 D:、E:)获之它所在的物理硬盘编号和分区编号。
sunwang
驱动牛犊
驱动牛犊
  • 注册日期2001-05-09
  • 最后登录2001-12-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2001-12-16 09:25
//From DDK2k,maybe some help for you.


IoReadPartitionTable
NTSTATUS
  IoReadPartitionTable(
  IN PDEVICE_OBJECT  DeviceObject,
  IN ULONG  SectorSize,
  IN BOOLEAN  ReturnRecognizedPartitions,
  OUT struct _DRIVE_LAYOUT_INFORMATION  **PartitionBuffer
  );
IoReadPartitionTable reads a list of partitions on a disk having a specified sector size and creates an entry in the partition list for each recognized partition.

Parameters
DeviceObject
Points to the device object for the disk whose partitions are to be read.
SectorSize
Specifies the size of the sectors on the disk.
ReturnRecognizedPartitions
Indicates whether only recognized partitions or all partition entries should be returned.
PartitionBuffer
Is a pointer to an uninitialized address. If successful, IoReadPartitionTable allocates the memory for this buffer from nonpaged pool and returns the drive layout information in it.
Include
ntddk.h

Return Value
This routine returns a value of STATUS_SUCCESS if at least one sector table was read. Otherwise, it returns an error status and sets the pointer at PartitionBuffer to NULL.

Comments
Disk device drivers call this routine during driver initialization.

It is the responsibility of the caller to deallocate the PartitionBuffer that was allocated by this routine with ExFreePool.

The algorithm used by this routine is determined by the Boolean value ReturnRecognizedPartitions:

Read each partition table and, for each valid and recognized partition found, fill in a partition information entry. Extended partitions are located in order to find other partition tables, but no entries are built for them.
Read each partition table and, for each and every entry, fill in a partition information entry. Extended partitions are located to find each partition on the disk, and entries are built for these as well.
The drive layout structure contains a variable-sized array of partition information elements, defined as follows:

typedef struct _DRIVE_LAYOUT_INFORMATION {
    ULONG PartitionCount;
    ULONG Signature;                // of disk
    PARTITION_INFORMATION PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION;
 
typedef strtuct _PARTITION_INFORMATION {
    LARGE_INTEGER StartingOffset;
    LARGE_INTEGER PartitionLength;
    ULONG HiddenSectors;
    ULONG PartitionNumber;
    UCHAR PartitionType;            // 12-bit FAT etc.
    BOOLEAN BootIndicator;
    BOOLEAN RecognizedPartition;
    BOOLEAN RewritePartition;
} PARTITION_INFORMATION, *PPARTITION_INFORMATION;
For the currently defined PartitionType values, see the Win32 SDK.

Note that disk drivers also use the DRIVE_LAYOUT_INFORMATION structure to return and set partition information in response to IRP_MJ_DEVICE_CONTROL requests with the following I/O control codes:

IOCTL_DISK_GET_PARTITION_INFO
IOCTL_DISK_GET_DRIVE_LAYOUT
IOCTL_DISK_SET_DRIVE_LAYOUT

Callers of IoReadPartitionTable must be running at IRQL PASSIVE_LEVEL.

See Also
IOCTL_DISK_GET_PARTITION_INFO, IOCTL_DISK_GET_DRIVE_LAYOUT, IOCTL_DISK_SET_DRIVE_LAYOUT, IoSetPartitionInformation, IoWritePartitionTable
^十万就结婚^
sunwang
驱动牛犊
驱动牛犊
  • 注册日期2001-05-09
  • 最后登录2001-12-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2001-12-16 09:36
//From <<inside windows 2000,3rd>>

//chapter 4.1 boot process and chapter 10.2 partitioning,there is one solution.....reference to mbr

//cheer!
^十万就结婚^
sunwang
驱动牛犊
驱动牛犊
  • 注册日期2001-05-09
  • 最后登录2001-12-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2001-12-16 10:24
http://www.sysinternals.com/ntw2k/info/diskkey.shtml

//=====================================================================
//
// Diskkey.c
//
// Copyright (C) 1997 Mark Russinovich
//
// This program dumps information from the
// HKLM\\SYSTEM\\DISK\\Information value.
//
//====================================================================
#include <windows.h>
#include <stdio.h>
#include <winioctl.h>
#include <conio.h>
#include \"diskkey.h\"

//
// Name of the DISK key and information value
//
char DiskKeyName[] = \"SYSTEM\\\\Disk\";
char DiskValueName[] = \"Information\";

//
// The disk information
//
PDISK_CONFIG_HEADER DiskInformation;
char *DiskInfoBuffer;

//
// FT-type strings
//
char PartTypes[][32] = {
\"Mirror\",
\"Stripe\",
\"ParityStripe\",
\"VolumeSet\",
\"NonFt\",
\"WholeDisk\"
};

//
// FT-volume states
//
char FtStates[][32] = {
\"Healthy\",
\"Orphaned\",
\"Regenerating\",
\"Initializing\",
\"SyncWithCopy\"
};

//
// FT-partition states
//
char FtPartStates[][32] = {
    \"FtStateOk\",      
    \"FtHasOrphan\",  
    \"FtDisabled\",    
    \"FtRegenerating\",
    \"FtInitializing\",
    \"FtCheckParity\",  
    \"FtNoCheckData\"  
};


//----------------------------------------------------------------------
//
// PrintError
//
// Formats an error message for the last error
//
//----------------------------------------------------------------------
void PrintError()
{
char *errMsg;

FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &errMsg, 0, NULL );
printf(\"%s\\n\", errMsg );
LocalFree( errMsg );
}

//----------------------------------------------------------------------
//
// DumpMember
//
// Dumps information on an FT Member
//
//----------------------------------------------------------------------
void DumpMember( PFT_MEMBER_DESCRIPTION MemberInfo )
{
printf(\"      Disk [%d] Parition [%d]\\n\",
MemberInfo->LogicalNumber >> 16,
MemberInfo->LogicalNumber & 0xFFFF );
printf(\"         State          : %s\\n\", FtPartStates[ MemberInfo->State ] );
printf(\"\\n\");
}

//----------------------------------------------------------------------
//
// DumpFtInformation
//
// Dumps information on FT groups.
//
//----------------------------------------------------------------------
int DumpFtInformation( int GroupNum, PFT_DESCRIPTION FtDescription )
{
int i;

printf(\"  [%d] FT Group of type %s\\n\", GroupNum,
PartTypes[ FtDescription->Type ] );
printf(\"      State             : %s\\n\\n\",
FtStates[ FtDescription->FtVolumeState ] );
for( i = 0; i < FtDescription->NumberOfMembers; i++ ) {

DumpMember( &FtDescription->FtMemberDescription );
}
return (sizeof( FT_DESCRIPTION ) +
   ((FtDescription->NumberOfMembers - 1) * sizeof( FT_MEMBER_DESCRIPTION )));
}


//----------------------------------------------------------------------
//
// DumpPartition
//
// Dumps the partition buffer.
//
//----------------------------------------------------------------------
void DumpPartition( PDISK_PARTITION PartInfo )
{
printf(\"     [%d] Partition type : %s\\n\", PartInfo->LogicalNumber,
PartTypes[ PartInfo->FtType ]);
if( !PartInfo->DriveLetter )
printf(\"         Drive letter   : system-assigned\\n\" );
else
printf(\"         Drive letter   : %c\\n\", PartInfo->DriveLetter );
printf(\"         Start offset   : %I64d MB\\n\", PartInfo->StartingOffset.QuadPart / (1024*1024) );
printf(\"         Length         : %I64d MB\\n\", PartInfo->Length.QuadPart / (1024*1024) );
if( PartInfo->FtType != NonFT ) {
printf(\"         FT-State       : %s\\n\", FtStates[ PartInfo->FtState ] );
printf(\"         FT-Group       : %d\\n\", PartInfo->FtGroup );
printf(\"         FT-Member      : %d\\n\", PartInfo->FtMember );
}
printf(\"\\n\");
}


//----------------------------------------------------------------------
//
// DumpDiskInformation
//
// Dump information about one disk.
//
//----------------------------------------------------------------------
int DumpDiskInformation( int DiskNum, PDISK_DESCRIPTION DiskDescription )
{
int i;
PDISK_PARTITION partInfo;
PPARTITION_HEADER partHeader;

if( DiskDescription->NumberOfPartitions ) {

partHeader = (PPARTITION_HEADER) (char *) &DiskDescription->PartitionHeader;


printf(\"  [%d] Disk Signature    : %08x\\n\\n\", DiskNum,
partHeader->Signature );

for( i = 0; i < DiskDescription->NumberOfPartitions; i++ ) {

partInfo = (PDISK_PARTITION) ( (char *) &partHeader->Partitions +
i * sizeof( DISK_PARTITION ));
DumpPartition( partInfo );
}  
}
return  ( (DiskDescription->NumberOfPartitions ?
sizeof( PARTITION_HEADER ): sizeof(DISK_DESCRIPTION)) +
( DiskDescription->NumberOfPartitions * sizeof( DISK_PARTITION )));
}


//----------------------------------------------------------------------
//
// DumpAllInformation
//
// Starts with the header, and calls sub-dumping functions.
//
//----------------------------------------------------------------------
void DumpAllInformation()
{
PDISK_REGISTRY diskInfo;
char *diskDescription;
PFT_REGISTRY ftInfo;
char *ftDescription;
int i;

printf(\"Disk key version: %d\\n\", DiskInformation->Version );

//
// Dump the individual disk information
//
printf(\"\\nDisk Information\\n\"
    \"----------------\\n\");
diskInfo = (PDISK_REGISTRY) &DiskInfoBuffer[ DiskInformation->DiskInformationOffset ];
diskDescription = (char *) &diskInfo->Disks[0];
for( i = 0; i < diskInfo->NumberOfDisks; i++ ) {

diskDescription += DumpDiskInformation( i, (PDISK_DESCRIPTION) diskDescription );
}

//
// Dump Fault-tolerant group information
//
if( DiskInformation->FtInformationSize ) {
printf(\"\\nFT Information\\n\"
    \"--------------\\n\");
ftInfo = (PFT_REGISTRY) &DiskInfoBuffer[ DiskInformation->FtInformationOffset ];
ftDescription = (char *) &ftInfo->FtDescription[0];
for( i = 0; i < ftInfo->NumberOfComponents; i++ ) {

ftDescription += DumpFtInformation( i, (PFT_DESCRIPTION) ftDescription );
}
}
}



//----------------------------------------------------------------------
//
// ReadDiskInformation
//
// Just reads the disk information value.
//
//----------------------------------------------------------------------
BOOLEAN ReadDiskInformation()
{
int informationSize;
DWORD status, disktype;
HKEY hDiskKey;

//
// Open the disk key
//
if( RegOpenKey( HKEY_LOCAL_MACHINE, DiskKeyName, &hDiskKey ) != ERROR_SUCCESS) {
printf(\"Error opening DISK key: \");
PrintError();
return FALSE;
}

  //
// Read the value, allocating larger buffers if necessary
  //
  informationSize = 0;
  // Read to null buffer to find value size
  RegQueryValueEx( hDiskKey, DiskValueName, NULL, &disktype, NULL,
&informationSize );
  DiskInformation = (PDISK_CONFIG_HEADER) malloc( informationSize  );
 
  status = RegQueryValueEx( hDiskKey, DiskValueName, 0, &disktype,
  (PBYTE) DiskInformation, &informationSize );

//
// Did we read the value successfully?
//
if( status != ERROR_SUCCESS ) {

printf(\"Error reading DISK\\\\Information value: \" );
PrintError();
RegCloseKey( hDiskKey );
return FALSE;
}

DiskInfoBuffer = (char *) DiskInformation;
RegCloseKey( hDiskKey );
return TRUE;
}


//----------------------------------------------------------------------
//
// main
//
// Drive the show.
//
//----------------------------------------------------------------------
int main( int argc, char *argv[])
{
printf(\"\\nDiskkey V1.1 - HKLM\\\\SYSTEM\\\\DISK dump program\\n\");
printf(\"Copyright (C) 1997 Mark Russinovich\\n\");
printf(\"http://www.ntinternals.com\\n\\n\");

//
// Read the disk key
//
if( !ReadDiskInformation() ) return -1;

//
// Dump it
//
DumpAllInformation();
return 0;
}
^十万就结婚^
chmode
驱动牛犊
驱动牛犊
  • 注册日期2001-08-06
  • 最后登录2001-12-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2001-12-17 09:15
sunwang,我对你的感激之情如滔滔江水、连绵不绝...
游客

返回顶部