MountMgr does not return all the mount points... WHY???

Hi,

I’m trying to enumerate all the mount points that belongs to the drive.
I’m using MountMgr services for this. Works great for drive letter-based
mount points, but in case of the mount point is located in the NTFS folder
MountMgr just does not show it! What could be a problem and how can I
enumerate *ALL* mount points?

Thanks!

Anton Kolomyeytsev

P.S. OSR’s tools shows the same so this is not my mistake.

#ifndef MOUNTMGR_C

#define MOUNTMGR_C

#include <stdio.h>

#include <windows.h>

#include <winioctl.h>

#include “MountMgr.h”

#define ANSI_MOUNTMGR_DOS_DEVICE_NAME “\\.\MountPointManager”

int
__cdecl
main(
IN INT p__INT Argc,
IN PCHAR p
PCHAR__Argv
)
{
HANDLE l__HANDLE MountMgrDevice = INVALID_HANDLE_VALUE;

UCHAR l
UCHAR__InputBuffer[4096];

UCHAR l__UCHAR__OutputBuffer[16384];

PMOUNTMGR_MOUNT_POINT l__PMOUNTMGR_MOUNT_POINT = (
PMOUNTMGR_MOUNT_POINT )( &l UCHAR InputBuffer );

PMOUNTMGR_MOUNT_POINTS l__PMOUNTMGR_MOUNT_POINTS = (
PMOUNTMGR_MOUNT_POINTS )( &l__UCHAR__OutputBuffer );

ULONG l__ULONG UCHARsReturned = 0;

LONG l
LONG Index = 0;

CHAR l
CHAR__SymbolicLinkName[MAX_PATH];

if ( p__INT__Argc < 2 )
{
printf( “\nMountMgr.exe:main(): EXITing with failure, device name
to query required!!!\n” );

printf( “MountMgr.exe:main(): Example: MountMgr.exe
\Device\CdRom0\n” );

return 1;
}

l__HANDLE__MountMgrDevice =
CreateFile(
ANSI_MOUNTMGR_DOS_DEVICE_NAME,
( GENERIC_READ | GENERIC_WRITE ),
( FILE_SHARE_READ | FILE_SHARE_WRITE ),
NULL,
OPEN_EXISTING,
0,
NULL
);

if ( l__HANDLE__MountMgrDevice == INVALID_HANDLE_VALUE )
{
printf(
“\nMountMgr.exe:main(): EXITing with failure, CreateFile( ‘%s’
) failed, status %ld!!!\n”,
ANSI_MOUNTMGR_DOS_DEVICE_NAME,
GetLastError()
);

return 1;
}

RtlZeroMemory(
&l__UCHAR__InputBuffer,
sizeof( l__UCHAR__InputBuffer )
);

RtlZeroMemory(
&l__UCHAR__OutputBuffer,
sizeof( l__UCHAR__OutputBuffer )
);

l__PMOUNTMGR_MOUNT_POINT->DeviceNameOffset = sizeof(
MOUNTMGR_MOUNT_POINT );

l__PMOUNTMGR_MOUNT_POINT->DeviceNameLength = ( 2 * strlen(
p__PCHAR__Argv[1] ) );

if (
MultiByteToWideChar(
CP_ACP,
0,
p__PCHAR__Argv[1],
( -1 ), // Our input string is zero-terminated
( PUSHORT )( &l__UCHAR__InputBuffer[sizeof(
MOUNTMGR_MOUNT_POINT )] ),
( ( sizeof( l__UCHAR__InputBuffer ) - sizeof(
MOUNTMGR_MOUNT_POINT ) ) / 2 )
) == 0
)
{
printf(
“\nMountMgr.exe:main(): EXITing with failure,
MultiByteToWideChar(…) failed, status %ld!!!\n”,
GetLastError()
);

CloseHandle( l__HANDLE__MountMgrDevice );

return 1;
}

l__PMOUNTMGR_MOUNT_POINTS->Size = sizeof( l UCHAR OutputBuffer );

if (
DeviceIoControl(
l HANDLE MountMgrDevice,
IOCTL_MOUNTMGR_QUERY_POINTS,
l__PMOUNTMGR_MOUNT_POINT,
sizeof( l__UCHAR__InputBuffer ),
l__PMOUNTMGR_MOUNT_POINTS,
sizeof( l UCHAR OutputBuffer ),
&l ULONG UCHARsReturned,
NULL
) == FALSE
)
{
printf(
“\nMountMgr.exe:main(): EXITing with failure, DeviceIoControl(
0x%08X ) failed, status %ld!!!\n”,
IOCTL_MOUNTMGR_QUERY_POINTS,
GetLastError()
);

CloseHandle( l HANDLE MountMgrDevice );

return 1;
}

printf(
“\nMountMgr.exe:main(): Number of mount points: %ld\n\n”,
l__PMOUNTMGR_MOUNT_POINTS->NumberOfMountPoints
);

for ( l__LONG Index = 0; l LONG__Index < ( LONG )( l__PMOUNTMGR_MOUNT_POINTS->NumberOfMountPoints );
l LONG Index++ )
{
RtlZeroMemory(
&l CHAR SymbolicLinkName,
sizeof( l CHAR SymbolicLinkName )
);

if (
WideCharToMultiByte(
CP_ACP,
0, // Default flags
( PWCHAR )( &l UCHAR OutputBuffer[
l__PMOUNTMGR_MOUNT_POINTS->MountPoints[l__LONG__Index
].SymbolicLinkNameOffset ] ),
( l__PMOUNTMGR_MOUNT_POINTS->MountPoints[l LONG Index
].SymbolicLinkNameLength / sizeof( WCHAR ) ),
( PCHAR )( &l CHAR SymbolicLinkName ),
sizeof( l CHAR SymbolicLinkName ),
NULL, // Default character to be used
NULL
) == 0
)
{
printf(
“\nMountMgr.exe:main(): EXITing with failure,
WideCharToMultiByte(…) failed, status %ld!!!\n”,
GetLastError()
);

CloseHandle( l HANDLE MountMgrDevice );

return 1;
}

printf(
“Symbolic link %ld of %ld name: %s\n”,
( l LONG Index + 1 ),
l PMOUNTMGR_MOUNT_POINTS->NumberOfMountPoints,
l
CHAR__SymbolicLinkName
);
}

CloseHandle( l__HANDLE__MountMgrDevice );

return 0;
}

#endif //MOUNTMGR_C</winioctl.h></windows.h></stdio.h>

Hi,

here is what one guy from Redmond wrote to me in private (he did not want
to tell his name and e-mail so I’ve removed them from the body of the
message). I’m sharing this stuff with you - maybe someone someday…

Regard,
Anton Kolomyeytsev

Look at the following functions in MSDN:

GetVolumeNameForVolumeMountPoint()
GetVolumePathNamesForVolumeName()

The idea is that, even when using a mount point, the volume GUID exists
and won’t change for a given unique device(*). You can freely interchange
the following types of strings:
\?\Volume{aaaabbbb-cccc-dddd-eeee-ffff00001111}
\.\Z:
You may also be able to use (I haven’t done so):
\.\Z:\Mountpoints\18GDrive

(*) Definition of a unique device is dependent upon bus types and device
ability. For example, USB devices with unique serial numbers can change
ports and be the same device, but older SCSI drives are “new” by changing
SCSI IDs or buses.

Please feel free to forward the above information back to the list, but
please remove any reference to my name and e-mail address to help me
reduce spam.

Thanks,
.

Hi,

I’m trying to enumerate all the mount points that belongs to the drive.
I’m using MountMgr services for this. Works great for drive letter-based
mount points, but in case of the mount point is located in the NTFS folder
MountMgr just does not show it! What could be a problem and how can I
enumerate *ALL* mount points?

Thanks!

Anton Kolomyeytsev

P.S. OSR’s tools shows the same so this is not my mistake.

#ifndef MOUNTMGR_C

#define MOUNTMGR_C

#include <stdio.h>
>
> #include <windows.h>
>
> #include <winioctl.h>
>
>
> #include “MountMgr.h”
>
>
> #define ANSI_MOUNTMGR_DOS_DEVICE_NAME “\\.\MountPointManager”
>
>
> int
> __cdecl
> main(
> IN INT p__INT Argc,
> IN PCHAR p
PCHAR__Argv
> )
> {
> HANDLE l__HANDLE MountMgrDevice = INVALID_HANDLE_VALUE;
>
> UCHAR l
UCHAR__InputBuffer[4096];
>
> UCHAR l__UCHAR__OutputBuffer[16384];
>
> PMOUNTMGR_MOUNT_POINT l__PMOUNTMGR_MOUNT_POINT = (
> PMOUNTMGR_MOUNT_POINT )( &l UCHAR InputBuffer );
>
> PMOUNTMGR_MOUNT_POINTS l__PMOUNTMGR_MOUNT_POINTS = (
> PMOUNTMGR_MOUNT_POINTS )( &l__UCHAR__OutputBuffer );
>
> ULONG l__ULONG UCHARsReturned = 0;
>
> LONG l
LONG Index = 0;
>
> CHAR l
CHAR__SymbolicLinkName[MAX_PATH];
>
> if ( p__INT__Argc < 2 )
> {
> printf( “\nMountMgr.exe:main(): EXITing with failure, device name
> to query required!!!\n” );
>
> printf( “MountMgr.exe:main(): Example: MountMgr.exe
> \Device\CdRom0\n” );
>
> return 1;
> }
>
> l__HANDLE__MountMgrDevice =
> CreateFile(
> ANSI_MOUNTMGR_DOS_DEVICE_NAME,
> ( GENERIC_READ | GENERIC_WRITE ),
> ( FILE_SHARE_READ | FILE_SHARE_WRITE ),
> NULL,
> OPEN_EXISTING,
> 0,
> NULL
> );
>
> if ( l__HANDLE__MountMgrDevice == INVALID_HANDLE_VALUE )
> {
> printf(
> “\nMountMgr.exe:main(): EXITing with failure, CreateFile( ‘%s’
> ) failed, status %ld!!!\n”,
> ANSI_MOUNTMGR_DOS_DEVICE_NAME,
> GetLastError()
> );
>
> return 1;
> }
>
> RtlZeroMemory(
> &l__UCHAR__InputBuffer,
> sizeof( l__UCHAR__InputBuffer )
> );
>
> RtlZeroMemory(
> &l__UCHAR__OutputBuffer,
> sizeof( l__UCHAR__OutputBuffer )
> );
>
> l__PMOUNTMGR_MOUNT_POINT->DeviceNameOffset = sizeof(
> MOUNTMGR_MOUNT_POINT );
>
> l__PMOUNTMGR_MOUNT_POINT->DeviceNameLength = ( 2 * strlen(
> p__PCHAR__Argv[1] ) );
>
> if (
> MultiByteToWideChar(
> CP_ACP,
> 0,
> p__PCHAR__Argv[1],
> ( -1 ), // Our input string is zero-terminated
> ( PUSHORT )( &l__UCHAR__InputBuffer[sizeof(
> MOUNTMGR_MOUNT_POINT )] ),
> ( ( sizeof( l__UCHAR__InputBuffer ) - sizeof(
> MOUNTMGR_MOUNT_POINT ) ) / 2 )
> ) == 0
> )
> {
> printf(
> “\nMountMgr.exe:main(): EXITing with failure,
> MultiByteToWideChar(…) failed, status %ld!!!\n”,
> GetLastError()
> );
>
> CloseHandle( l__HANDLE__MountMgrDevice );
>
> return 1;
> }
>
> l__PMOUNTMGR_MOUNT_POINTS->Size = sizeof( l UCHAR OutputBuffer );
>
> if (
> DeviceIoControl(
> l HANDLE MountMgrDevice,
> IOCTL_MOUNTMGR_QUERY_POINTS,
> l__PMOUNTMGR_MOUNT_POINT,
> sizeof( l__UCHAR__InputBuffer ),
> l__PMOUNTMGR_MOUNT_POINTS,
> sizeof( l UCHAR OutputBuffer ),
> &l ULONG UCHARsReturned,
> NULL
> ) == FALSE
> )
> {
> printf(
> “\nMountMgr.exe:main(): EXITing with failure, DeviceIoControl(
> 0x%08X ) failed, status %ld!!!\n”,
> IOCTL_MOUNTMGR_QUERY_POINTS,
> GetLastError()
> );
>
> CloseHandle( l HANDLE MountMgrDevice );
>
> return 1;
> }
>
> printf(
> “\nMountMgr.exe:main(): Number of mount points: %ld\n\n”,
> l__PMOUNTMGR_MOUNT_POINTS->NumberOfMountPoints
> );
>
> for ( l__LONG Index = 0; l LONG__Index < ( LONG )( l__PMOUNTMGR_MOUNT_POINTS->NumberOfMountPoints );
> l LONG Index++ )
> {
> RtlZeroMemory(
> &l CHAR SymbolicLinkName,
> sizeof( l CHAR SymbolicLinkName )
> );
>
> if (
> WideCharToMultiByte(
> CP_ACP,
> 0, // Default flags
> ( PWCHAR )( &l UCHAR OutputBuffer[
> l__PMOUNTMGR_MOUNT_POINTS->MountPoints[l__LONG__Index
>].SymbolicLinkNameOffset ] ),
> ( l__PMOUNTMGR_MOUNT_POINTS->MountPoints[l LONG Index
>].SymbolicLinkNameLength / sizeof( WCHAR ) ),
> ( PCHAR )( &l CHAR SymbolicLinkName ),
> sizeof( l CHAR SymbolicLinkName ),
> NULL, // Default character to be used
> NULL
> ) == 0
> )
> {
> printf(
> “\nMountMgr.exe:main(): EXITing with failure,
> WideCharToMultiByte(…) failed, status %ld!!!\n”,
> GetLastError()
> );
>
> CloseHandle( l HANDLE MountMgrDevice );
>
> return 1;
> }
>
> printf(
> “Symbolic link %ld of %ld name: %s\n”,
> ( l LONG Index + 1 ),
> l PMOUNTMGR_MOUNT_POINTS->NumberOfMountPoints,
> l
CHAR__SymbolicLinkName
> );
> }
>
> CloseHandle( l__HANDLE__MountMgrDevice );
>
> return 0;
> }
>
>
> #endif //MOUNTMGR_C</winioctl.h></windows.h></stdio.h>