Listing available drive partitions

kentavr

У меня когда то была проблема когда писал дипломную работу. Эту проблему мне решить не удалось. Я вразных форумах мира писал об этом но полезного ответа не было =(
Может тут кто ни будь знает что делать. И заранее прошу прощения за английский, просто сделал копи паст, если необходимо я всё переведу, хотя думаю что у вас с английским проблем быть не должно.
----
Task:
List all available drive partitions with their volumes, parameteres
(most important size to calculate partition sector count)
This must be windows application.
PartitionSectorCount = PartitionSize / 512;
I used DeviceIoControl(...) API function width
IOCTL_DISK_GET_DRIVE_LAYOUT parameter to list
all available partitions on specified disk.
It works but there is one problem.
It returns all partitions by their numbers, there is no
information about drive letter.
How can I idenitfy partition drive letter?
I need that because drive letter of partition is
a key to open it with CreateFile(...) function
to have direct access to that portion of drive.
There is another solution.
is to
1. open direct access to all portions of drive
2. read MBR (master boot record) which contains main information
about partitions.
I don't like this solution because it's dangerous.
Error in my application may destroy operating system.
That's why I preffer to have full access only to some portion of
drive only to one partition to prevent any damage.
Entering the drive letter and it's number to get
direct access to the partition of the disk drive is
not good, I don't wan't to imagine what will
happen if the drive letter will not correspond to
it's number by user mistake ...
someone told me to use GetFileSize(...)... and something more.
In this case it doesn't work. I even can tell why.
Those APIs are depenending on partitions file system.
Those functions work when there is known file system on specified partition,
Those APIs will fail if there is no, or there is unknown file system on specified
partition.
I need file system independent APIs.
I found such APIs, but they present only on Windows 2003 Server and later versions of windows.
I tried them all before I made this topic.

bastii

ботай WMI, такие классы как:
Win32_DiskDrive
Win32_DiskDriveToDiskPartition
Win32_DiskPartition
Win32_LogicalDiskToPartition
Win32_LogicalDisk

agaaaa

I don't like this solution because it's dangerous.
Error in my application may destroy operating system.
Интересно, как ты нанесёшь вред, только читая информацию с хдд?

kentavr

Интересно, как ты нанесёшь вред, только читая информацию с хдд?
задача была такова
Создать собственную систему управления файлами. Читая MBR для данного диска я должен был определить откуда начинаются и кончаются все primary разделы. В таком случае мой вызов CreateFile-а даст мне доступ не к отдельному разделу как хотелось бы, а к всему диску. Следовательно моя программа может случайно нарушить эти границы и записать какие-то данные вне предполагаемого раздела.
Речь тут идёт о прямом доступе.

kentavr

WMI =)
попробую
хорошо звучит, ведь программа Disk Manager этого рода
Да но WMI не поддерживается ранними версиями windows, тоесть ниже 2000-ого насколько я знаю, хотя это уже не так важно, но отсюда следует, что существует и другой способ.
Оставить комментарий
Имя или ник:
Комментарий: