From: Anton Bassov on
Maxim,

Although everything you said is correct, all this stuff comes into a play
only *AFTER*
partition gets recognized and a device object gets created for it. In order
for partition to get recognized, FS that it is formatted with has to get
loaded.

However, the OP wants to check whether there is any ExtX-formatted partition,
i.e. whether his app should load FS driver. In such case the only thing he
can do is to read raw sectors from the disk - no other options are available
before FS gets loaded.

In fact, I think he just should configure FS driver to get loaded at the
boot time,
rather than making an app worry about these things....

Concerning all other things that you have mentioned, it is driver's and not
app's responsibility - if driver does everything properly, the partition will
get mounted automatically.....

Anton Bassov

"Maxim S. Shatskih" wrote:

> > (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
>
>
From: Corinna Vinschen on
Anton Bassov wrote:
> 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.

That's not quite right. Until NT4 the \\Device\\HarddiskX\PartitionY
names where the actual device names for the partitions on disks, with
Partition0 being the name of the complete disk. Beginning with W2K, the
actual device names changed, probably for an easier transition to
dynamic disks which didn't exist under NT4. However, the old partition
naming scheme still exists, from W2K to Vista. The difference is that
\\Device\\HarddiskX\PartitionY is now a symbolic link to the actual
device name. But you can still use this naming scheme to access
disk partitions or the whole disk in calls to ZwCreateFile/ZwOpenFile.


Corinna

--
Antworten an o.g. (existierende) Adresse werden ungelesen verworfen.
Private Mails bitte an corinnaPLOPvinschenPINGde.
From: I.You on
Thanks a lot Maxim, Anton and Corinna.

Although I'm confused since your opinions are all different, helpful to me
anyway.

I will try it as you say.

Thank you for your kindness.


"Anton Bassov" wrote:

> Maxim,
>
> Although everything you said is correct, all this stuff comes into a play
> only *AFTER*
> partition gets recognized and a device object gets created for it. In order
> for partition to get recognized, FS that it is formatted with has to get
> loaded.
>
> However, the OP wants to check whether there is any ExtX-formatted partition,
> i.e. whether his app should load FS driver. In such case the only thing he
> can do is to read raw sectors from the disk - no other options are available
> before FS gets loaded.
>
> In fact, I think he just should configure FS driver to get loaded at the
> boot time,
> rather than making an app worry about these things....
>
> Concerning all other things that you have mentioned, it is driver's and not
> app's responsibility - if driver does everything properly, the partition will
> get mounted automatically.....
>
> Anton Bassov
>
> "Maxim S. Shatskih" wrote:
>
> > > (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
> >
> >
From: Maxim S. Shatskih on
> However, the OP wants to check whether there is any ExtX-formatted partition,
> i.e. whether his app should load FS driver. In such case the only thing he
> can do is to read raw sectors from the disk - no other options are available
> before FS gets loaded.

Correct.

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

From: Anton Bassov on
> The difference is that
> \\Device\\HarddiskX\PartitionY is now a symbolic link to the actual
> device name.

This is simply wrong.....

Symbolic link just cannot be in the form "\\Device\\HarddiskX\PartitionY" -
it has to be in the form "\\DosDevices\\xxxx" and not "\\Device\\xxxx".....

Anton Bassov




"Corinna Vinschen" wrote:

> Anton Bassov wrote:
> > 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.
>
> That's not quite right. Until NT4 the \\Device\\HarddiskX\PartitionY
> names where the actual device names for the partitions on disks, with
> Partition0 being the name of the complete disk. Beginning with W2K, the
> actual device names changed, probably for an easier transition to
> dynamic disks which didn't exist under NT4. However, the old partition
> naming scheme still exists, from W2K to Vista. The difference is that
> \\Device\\HarddiskX\PartitionY is now a symbolic link to the actual
> device name. But you can still use this naming scheme to access
> disk partitions or the whole disk in calls to ZwCreateFile/ZwOpenFile.
>
>
> Corinna
>
> --
> Antworten an o.g. (existierende) Adresse werden ungelesen verworfen.
> Private Mails bitte an corinnaPLOPvinschenPINGde.
>