News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Enumarating NT device names of hard disk volumes

Started by Vortex, November 29, 2009, 01:42:18 PM

Previous topic - Next topic

Vortex

Is there a way to get a list of NT devices names associated with hard disk volumes?

Here is how it should look :


\Device\HarddiskVolume1
\Device\HarddiskVolume2
\Device\HarddiskVolume3
.
.
.


The reason to get this list is to detect and find programmatically EISA partition(s) displayed by Windows Disk Manager.

dedndave

hi Erol
i seem to recall Hutch playing with a little program to do that a while back
you might find it using advanced search and look only at stuff from Hutch or Hutch--

evlncrn8

QueryDosDevice will get you most of what you need...
either calling it to get all the device names and processing them or doing it as
c:\
d:\
e:\

and so on will also get you the information you need

Vortex

Hi Dave,

Thanks, I will search the forum.

Hi evlncrn8,

Today, I already tested QueryDosDevice but it cannot detect partitions with different IDs. A normal NTFS partition displays an ID number of 0x07 and it can be detected with QueryDosDevice. The problem is that a recovery partition on your hard disk ( an EISA partition ) cannot be identified with QueryDosDevice.

dedndave

Erol,
if you are refering to the partition "type ID", my "normal" NTFS partitions are type 7
my recovery partition is type 12h, although, this varies from one OEM to another
i have discovered that i can simply change the partition type ID to 7 and reboot to access the recovery partition
i use MBRWizard to change it
perhaps you can dig into it enough to get some ideas
there are two versions available
the newer version is a GUI app
the older version is a simpler console app - this is the one i use
http://mbrwizard.com/download.php

modules used:

Addr:0002071E hint(0034) Name: CloseHandle
Addr:0002072C hint(03A4) Name: WriteFile
Addr:00020738 hint(02F2) Name: SetConsoleCursorPosition
Addr:00020754 hint(01B9) Name: GetStdHandle
Addr:00020764 hint(0053) Name: CreateFileA
Addr:00020772 hint(034F) Name: SetVolumeMountPointA
Addr:0002078A hint(0088) Name: DeleteVolumeMountPointA
Addr:000207A4 hint(034D) Name: SetVolumeLabelA
Addr:000207B6 hint(0142) Name: GetCurrentProcess
Addr:000207CA hint(01E8) Name: GetVersion
Addr:000207D8 hint(00C7) Name: FillConsoleOutputCharacterA
Addr:000207F6 hint(0137) Name: GetConsoleScreenBufferInfo
Addr:00020814 hint(01D5) Name: GetTempPathA
Addr:0002070E hint(0171) Name: GetLastError
Addr:00020836 hint(02B5) Name: ReadFile
Addr:00020842 hint(01ED) Name: GetVolumeNameForVolumeMountPointA
Addr:00020866 hint(00E7) Name: FindVolumeClose
Addr:00020878 hint(00DF) Name: FindNextVolumeA
Addr:0002088A hint(01EB) Name: GetVolumeInformationA
Addr:000208A2 hint(00D7) Name: FindFirstVolumeA
Addr:000208B6 hint(0176) Name: GetLogicalDriveStringsA
Addr:00020DF0 hint(02FD) Name: SetConsoleMode
Addr:00020DDC hint(02AA) Name: ReadConsoleInputA
Addr:00020824 hint(031B) Name: SetFilePointer
Addr:000206FC hint(008A) Name: DeviceIoControl
Addr:0002094C hint(02D7) Name: RtlUnwind
Addr:00020958 hint(0098) Name: EnterCriticalSection
Addr:00020970 hint(0251) Name: LeaveCriticalSection
Addr:00020988 hint(0110) Name: GetCommandLineA
Addr:0002099A hint(0216) Name: HeapFree
Addr:000209A6 hint(01E9) Name: GetVersionExA
Addr:000209B6 hint(0210) Name: HeapAlloc
Addr:000209C2 hint(01A3) Name: GetProcessHeap
Addr:000209D4 hint(035E) Name: TerminateProcess
Addr:000209E8 hint(036E) Name: UnhandledExceptionFilter
Addr:00020A04 hint(034A) Name: SetUnhandledExceptionFilter
Addr:00020A22 hint(0239) Name: IsDebuggerPresent
Addr:00020A36 hint(02A7) Name: RaiseException
Addr:00020A48 hint(01A0) Name: GetProcAddress
Addr:00020A5A hint(017F) Name: GetModuleHandleA
Addr:00020A6E hint(0365) Name: TlsGetValue
Addr:00020A7C hint(0363) Name: TlsAlloc
Addr:00020A88 hint(0366) Name: TlsSetValue
Addr:00020A96 hint(0364) Name: TlsFree
Addr:00020AA0 hint(022C) Name: InterlockedIncrement
Addr:00020AB8 hint(0328) Name: SetLastError
Addr:00020AC8 hint(0146) Name: GetCurrentThreadId
Addr:00020ADE hint(0228) Name: InterlockedDecrement
Addr:00020AF6 hint(0394) Name: WideCharToMultiByte
Addr:00020B0C hint(0122) Name: GetConsoleCP
Addr:00020B1C hint(0133) Name: GetConsoleMode
Addr:00020B2E hint(0324) Name: SetHandleCount
Addr:00020B40 hint(0166) Name: GetFileType
Addr:00020B4E hint(01B7) Name: GetStartupInfoA
Addr:00020B60 hint(0081) Name: DeleteCriticalSection
Addr:00020B78 hint(0356) Name: Sleep
Addr:00020B80 hint(00B9) Name: ExitProcess
Addr:00020B8E hint(0104) Name: GetCPInfo
Addr:00020B9A hint(00FD) Name: GetACP
Addr:00020BA4 hint(0193) Name: GetOEMCP
Addr:00020BB0 hint(0244) Name: LCMapStringA
Addr:00020BC0 hint(0275) Name: MultiByteToWideChar
Addr:00020BD6 hint(0245) Name: LCMapStringW
Addr:00020BE6 hint(017D) Name: GetModuleFileNameA
Addr:00020BFC hint(00F6) Name: FreeEnvironmentStringsA
Addr:00020C16 hint(0155) Name: GetEnvironmentStrings
Addr:00020C2E hint(00F7) Name: FreeEnvironmentStringsW
Addr:00020C48 hint(0157) Name: GetEnvironmentStringsW
Addr:00020C62 hint(0214) Name: HeapDestroy
Addr:00020C70 hint(0212) Name: HeapCreate
Addr:00020C7E hint(0383) Name: VirtualFree
Addr:00020C8C hint(02A3) Name: QueryPerformanceCounter
Addr:00020CA6 hint(01DF) Name: GetTickCount
Addr:00020CB6 hint(0143) Name: GetCurrentProcessId
Addr:00020CCC hint(01CA) Name: GetSystemTimeAsFileTime
Addr:00020CE6 hint(0381) Name: VirtualAlloc
Addr:00020CF6 hint(021A) Name: HeapReAlloc
Addr:00020D04 hint(021C) Name: HeapSize
Addr:00020D10 hint(0337) Name: SetStdHandle
Addr:00020D20 hint(00EE) Name: FlushFileBuffers
Addr:00020D34 hint(0399) Name: WriteConsoleA
Addr:00020D44 hint(0135) Name: GetConsoleOutputCP
Addr:00020D5A hint(03A3) Name: WriteConsoleW
Addr:00020D6A hint(0223) Name: InitializeCriticalSection
Addr:00020D86 hint(0252) Name: LoadLibraryA
Addr:00020D96 hint(01BA) Name: GetStringTypeA
Addr:00020DA8 hint(01BD) Name: GetStringTypeW
Addr:00020DBA hint(0174) Name: GetLocaleInfoA
Addr:00020DCC hint(0310) Name: SetEndOfFile

   Import Module 002: USER32.dll

Addr:000208DE hint(00E1) Name: ExitWindowsEx

   Import Module 003: ADVAPI32.dll

Addr:00020912 hint(014F) Name: LookupPrivilegeValueA
Addr:000208FA hint(001C) Name: AdjustTokenPrivileges
Addr:0002092A hint(01AC) Name: OpenProcessToken

Vortex

Hi Dave,

Quotemy recovery partition is type 12h

That one is a "Compaq" recovery partition if I remember well. You can create recovery partitions with the help of a tool like Paragon Hard Disc Manager. It's enough to modify the partition ID from 0x07 NTFS to 0x012. I can access the recovery partition by assigning a letter with DefineDosDevice. The problem is that you need to find the matching NT device name to use DefineDosDevice. If you can enumarate all the NT device names, you can find the symbolic name associated with the recovery partition. For the moment, I find manually the recovery partition. Assuming that this recovery partition is the last one on the disc drive :

DefineDosDevice(DDD_RAW_TARGET_PATH,"M:","\Device\HarddiskVolume3")

I need a method to find programmatically all those \Device\HarddiskVolumeX symbols.

dedndave

yes - well - this one is a sony
i know that dell uses something different - 0DFh or something like that, which is a "maintainence" partition
i dug into this a little bit, once
it was a little over my head because i was new to 32-bit apps
but, i seem to recall one of the functions listed above enumerates all the volumes on a system
in fact, as i remember, you had to use 2 or 3 functions together to enumerate the list and make sense of it
because you had to get the OS "volume name", which is a unique identifier - not necessarily meaningful otherwise
at that point, i stopped messsing with it
you should be able to get the info you want using only the functions listed above
hope this helps, though

Vortex

Hi Dave,

Thanks for the info.

I will try to find a solution using the DeviceIoControl function with the IOCTL_DISK_GET_DRIVE_LAYOUT_EX parameter.