From: I.You on
Hi there.

I'm trying to get the informations - filesystem name, etc - of disk
partition, and if unformatted volume, want to get like "unknown filesystem or
unformatted".

Also, I want to get the informations of partition which is formatted by
linux filesystem and unmounted if linux filesystem driver is running.

So I tested simply as follow:


....
....

/* open */
hdrive = CreateFile("\\\\.\\" DEVICE_NAME, GENERIC_READ | GENERIC_WRITE, 0, \
NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
LastError = GetLastError();

if (!DeviceIoControl(
hdrive,
IOCTL_EXT2_PARTITION,
&Ext2Partition,
sizeof(EXT2_PARTITION),
NULL,
0,
&BytesReturned,
NULL))
{
CloseHandle(hdrive);
// return;
}

CloseHandle(hdrive);

for(i=0; i<DISK; i++) {
for(j=1; j<PARTITION; j++) {
sprintf(DevName, "\\Device\\Harddisk%d\\Partition%d", i, j);

GetVolumeInformation(DevName, NULL, 0, NULL, NULL,
&FileSystemFlag, FileSystemName, 63);
}
}
}



However, CreateFile failed and LastError code was ERROR_FILE_NOT_FOUND.

DEVICE_NAME is defined as service name of the driver.

Also, even in case of Harddisk0\\Partition1 which is NTFS, nothing was
pointed to FileSystemName in GetVolumeInformation.

It fails too though DevName is "C:" and LastError code is ERROR_INVALID_NAME.

but I want to get the information from even unmounted volume.


What is wrong?

I wish your advices.


From: Maxim S. Shatskih on
> but I want to get the information from even unmounted volume.

Windows only allows you to get the filesystem name and free blocks count (as
any other "volume information") from _mounted_ volumes.

If you are not happy with this - then sorry, write your own kernel-mode module
which will do the filesystem layout parsing, scanning allocation bitmaps etc
and provide this info.

Note: in Windows, the volumes are usually always mounted. The disk volume is
not mounted only if there are no drive letters to it, and anyway triggering a
mount with the purpose of getting the FS name is fine.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim(a)storagecraft.com
http://www.storagecraft.com

From: I.You on
Thanks a lot, Maxim.

What I'm trying to do is that detecting all disks and all partitions
(mounted or not) in system and then mounting (and assigning a drive letter)
the partition if it's ext2 filesystem.
So I try to write the APPLICATION program, which loads the ext2 filesystem
driver for windows.

In order to do this, I tried to use a few DDK functions (Nt*** functions)
but it's failed. So now I'm trying to use GetVolumeInformation but it's not
good too.

I have no idea what to do. Is there any good idea?

Anyway, I'm considering as follow:

1. Retrieving currently assigned drive letters (including CD-ROM drive).
Q: Is it possible for "QueryDosDevice" to detect CD-ROM drive? If not, other
ways?

2. Retrieving the number of disks and partitions in each disk in system.
Q: IOCTL_DISK_GET_DRIVE_LAYOUT_EX is for Retrieving the number of
partitions, then the number of disks?

3. Retrieving the filesystem name or something of each partition which is
not mounted.
Q: Is it possible to retrieve the filesystem name of each partition by using
DeviceIoControl? However, I wonder how to retrieve information about each
partition in DeviceIoControl, since the device it handles is not each
partition but filesystem driver.


I have no idea how to solve this because I'm a beginner.
So I think writing my own kernel-mode module is too difficult.

I wish your good advices.





"Maxim S. Shatskih" wrote:

> > but I want to get the information from even unmounted volume.
>
> Windows only allows you to get the filesystem name and free blocks count (as
> any other "volume information") from _mounted_ volumes.
>
> If you are not happy with this - then sorry, write your own kernel-mode module
> which will do the filesystem layout parsing, scanning allocation bitmaps etc
> and provide this info.
>
> Note: in Windows, the volumes are usually always mounted. The disk volume is
> not mounted only if there are no drive letters to it, and anyway triggering a
> mount with the purpose of getting the FS name is fine.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim(a)storagecraft.com
> http://www.storagecraft.com
>
>
From: Anton Bassov on

It is really easy to detect unformatted or Linux-formatted partitions....

What you have to is to open every physical disk on the system with
CreateFile(), and then read disk's partition table. Please note that
CreateFile() works only with symbolic links and not with actual names
(i.e"\\.\PhysicalDriveX" and not \\Device\\HarddiskX") - this is why you got
an error in your first CreateFile() call.

Concerning the second one, it would fail even if CreateFile() could work
with actual names - the name of the partition is in the form
"\\Device\\HarddiskX\DP(1)0x7e....." and not in the form
"\\Device\\HarddiskX\Partition1". Therefore, the name is just invalid.

Concerning the rest..... the system would not create a device object for the
partition unless it recognizes the file system the partition it is formatted
with. Therefore, if you want your partition to be recognized, FS driver has
to get loaded. When it comes to mounting file system on the partition and
assigning drive letter to it, this is done automatically by the system if
your partition is recognized.


Anton Bassov




"I.You" wrote:

> Thanks a lot, Maxim.
>
> What I'm trying to do is that detecting all disks and all partitions
> (mounted or not) in system and then mounting (and assigning a drive letter)
> the partition if it's ext2 filesystem.
> So I try to write the APPLICATION program, which loads the ext2 filesystem
> driver for windows.
>
> In order to do this, I tried to use a few DDK functions (Nt*** functions)
> but it's failed. So now I'm trying to use GetVolumeInformation but it's not
> good too.
>
> I have no idea what to do. Is there any good idea?
>
> Anyway, I'm considering as follow:
>
> 1. Retrieving currently assigned drive letters (including CD-ROM drive).
> Q: Is it possible for "QueryDosDevice" to detect CD-ROM drive? If not, other
> ways?
>
> 2. Retrieving the number of disks and partitions in each disk in system.
> Q: IOCTL_DISK_GET_DRIVE_LAYOUT_EX is for Retrieving the number of
> partitions, then the number of disks?
>
> 3. Retrieving the filesystem name or something of each partition which is
> not mounted.
> Q: Is it possible to retrieve the filesystem name of each partition by using
> DeviceIoControl? However, I wonder how to retrieve information about each
> partition in DeviceIoControl, since the device it handles is not each
> partition but filesystem driver.
>
>
> I have no idea how to solve this because I'm a beginner.
> So I think writing my own kernel-mode module is too difficult.
>
> I wish your good advices.
>
>
>
>
>
> "Maxim S. Shatskih" wrote:
>
> > > but I want to get the information from even unmounted volume.
> >
> > Windows only allows you to get the filesystem name and free blocks count (as
> > any other "volume information") from _mounted_ volumes.
> >
> > If you are not happy with this - then sorry, write your own kernel-mode module
> > which will do the filesystem layout parsing, scanning allocation bitmaps etc
> > and provide this info.
> >
> > Note: in Windows, the volumes are usually always mounted. The disk volume is
> > not mounted only if there are no drive letters to it, and anyway triggering a
> > mount with the purpose of getting the FS name is fine.
> >
> > --
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > maxim(a)storagecraft.com
> > http://www.storagecraft.com
> >
> >
From: Maxim S. Shatskih on
> (mounted or not) in system and then mounting (and assigning a drive letter)
> the partition if it's ext2 filesystem.

Windows is unable to assign the drive letter to a partition whose MBR type byte
is not saying "FAT" (3 different values IIRC) or "IFS partition". NTFS uses the
"IFS partition" value.

So, to assign the drive letter to ext2 in Windows, you must either patch the
MBR type byte to "NTFS" (it's safe Windows-side, and probably even safe
Linux-side), or use your own drive letter assignment which will bypass
MountMgr - so, no FindXxxVolume calls will work on your ext2 volume.

Windows does not pay any attention to MBR type byte in choosing a filesystem to
mount - it tries them all, and the first which will recognize the metadata will
go. This is like Linux's "autofs" feature, and this is the only way in Windows
to mount a filesystem.

Usually, in Windows, all filesystems are always mounted, they are dismounted
rather rarely - a) as a last step of FORMAT/CHKDSK /F to throw away any
in-memory volume data which can be stale b) when the drive letter is revoked c)
as the last step of restore from image backup - the image backup software
mimics FORMAT in this.

> 1. Retrieving currently assigned drive letters (including CD-ROM drive).

GetLogicalDriveStrings

> 2. Retrieving the number of disks and partitions in each disk in system.
> Q: IOCTL_DISK_GET_DRIVE_LAYOUT_EX is for Retrieving the number of
> partitions, then the number of disks?

SetupDiGetClassDevs with "Disk" device interface GUID. This gives you some
handle + a friendly name for the UI.

Then SetupDiGetDeviceInterfaceDetail to retrieve an openable filename for the
handle of the found disk.

Then CreateFile and IOCTL_STORAGE_GET_DEVICE_NUMBER down this filename. It gets
the Disk Number.

IOCTL_DISK_GET_DRIVE_LAYOUT_EX can also be sent down the same filename to read
the partition table.

To associate the physical disks (above) to the volumes (C: or such) - open a
volume as \\.\D:, and send IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS down.

If the volume is not a software RAID (Dynamic Disk) - then you will have only 1
extent, and Disk Number in the extent can be associated with the Disk Number of
the physical disk.

This is how you associate volumes to physical disks (LUNs).

> Q: Is it possible to retrieve the filesystem name of each partition by using
> DeviceIoControl?

By handle? Only the undocumented NtQueryVolumeInformationFile.
By name? GetVolumeInformation.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim(a)storagecraft.com
http://www.storagecraft.com