The documentation on IOCTL_MOUNTDEV_QUERY_UNIQUE_ID
is a bit confusing... exactly what kind of ID should be returned in the MOUNTDEV_UNIQUE_ID
structure?
The documentation for
typedef struct _MOUNTDEV_UNIQUE_ID {
USHORT UniqueIdLength;
UCHAR UniqueId[1];
} MOUNTDEV_UNIQUE_ID, *PMOUNTDEV_UNIQUE_ID;
says:
UniqueIdLength
- Contains the length of unique volume ID.
UniqueId
- Contains the unique volume ID. The format for unique volume names is
"\??\Volume{GUID}\"
, where GUID is a globally unique identifier that identifies the volume.
However, there's something weird here: What should be the exact format of UniqueId
? If it's meant to be in the \??\Volume{GUID}\
format, then what's the point of the UniqueIdLength
field -- aren't they all the same size? Otherwise, what format does the device ID need to be in?
Furthermore, is this a device ID or a volume ID? In other words, is this supposed to be unique per medium (e.g. CD) or per device (CD drive)?
This kind of struct is pretty common in MS APIs - the UniqueID[1]
variable is just a placeholder, in reality it's used as a UniqueId[UniqueIdLength]
variable.
The ID is unique both per medium and per device - it depends on whether you're talking to a volume driver or a device class driver. The ID is intended to identify "something that can be mounted" - so e.g. a CD-ROM device, a fixed disk partition or an unpartitioned removable disk. The mount manager uses the ID a.o. to lookup where this particular volume was mounted before, and remount it at the same point.