Home > Software engineering >  How to not drive partition/volume information query?
How to not drive partition/volume information query?

Time:10-23

Problem is put forward for Windows is not assigned drive disk partitions, such as ESP, want to read the information, such as file format (FAT32?) , size, volume label, etc.,

Now I can FindFirstVolume, FindNextVolume cycle for all partitions information (contain no allocation of drive partition, but no ESP area ), and use QueryDosDevice become the words \ Device \ HarddiskVolume1 data,

But, the question comes, how further?

I can be changed by GetVolumePathNamesForVolumeName \ Device \ HarddiskVolume1 into drive, but can only get a drive,

Originally GetVolumeInformation can get what I want the file and volume label, but the first parameter is the GetVolumeInformation "C: " is on their Path.

Please help to develop ideas, 40 on the distribution,

PS: VC6 + Win10, good pain, many advanced features are not,,,,,,,,

CodePudding user response:

Now report new problems:

Because is GPT format the hard disk, hidden partition is more, so I made a mistake a problem: FindFirstVolume, FindNextVolume cycle did get no assigned drive area, which is OEM partition, but instead of ESP area (starting area) ,

That is to say: FindFirstVolume, FindNextVolume enumeration didn't normally get to ESP, to ask: are there any other API can get? Administrator privileges I also tried, should not a permissions problem,,,

About GetVolumeInformation, I solved, find GetVolumeInformation VolumeName the way of the first parameter can be a GUID, sweat! .

CodePudding user response:

CodePudding user response:

The question you said I have never heard of, can only come and watch the,

CodePudding user response:

reference jennyvenus reply: 3/f
the question you said I have never heard of, can only come and watch the,

Onlookers is also involved in, thanks to onlookers,

CodePudding user response:

My code: from the concept of Microsoft code transformation, only enough to see the TRACE macro output,

 
BOOL CMyDriveListBox: : initVolumes ()
{
HANDLE FindHandle=INVALID_HANDLE_VALUE;
DWORD Error=ERROR_SUCCESS;
DWORD CharCount=0;
BOOL Success=true;
ES_VOLUME_INFO VolumeInfo;


Cstrings VolumeName=_T (" ");
FindHandle=FindFirstVolume ((LPTSTR) VolumeName GetBuffer (MAX_PATH), MAX_PATH);
If (FindHandle==INVALID_HANDLE_VALUE)
{

TRACE1 (" FindFirstVolume failed with error code % d \ n ", GetLastError ());
Return false;
}

While (Success)
{
This - & gt; ClearVolumeInfo (& amp; VolumeInfo);
TRACE1 (" VolumeName=% s \ n ", VolumeName);/* \ \? \ Volume {4 b82a9cd e78 f62c - 4-8117-0682014 b76b1} \ */
VolumeName. The Format (_T (" % s "), VolumeName);
Int lvo=VolumeName. GetLength ();
//TRACE1 (" path. Right (1) : % s \ n ", VolumeName. Right (1));
If (
(VolumeName. Mid (0, 4)). Compare (_T (" \ \ \ \? \ \ "))!=0
(1)) | | (VolumeName. Right. Compare (_T (" \ \ "))!=0

)
{
TRACE1 (" FindFirstVolume/FindNextVolume returned a bad path: % s \ n ", VolumeName);
//return false.
break;

}

Cstrings DeviceName=_T (" ");
Cstrings strNewVolumeName=_T (" ");
StrNewVolumeName=VolumeName. Mid (4, lvo - 5);
TRACE1 (" strNewVolumeName: % s \ n ", strNewVolumeName);


CharCount=
QueryDosDevice (strNewVolumeName, (LPTSTR) DeviceName. GetBuffer (MAX_PATH), MAX_PATH);
If (CharCount==0)
{
TRACE1 (" QueryDosDeviceW failed with error code % d \ n ", GetLastError ());
//return false.
break;

}
TRACE1 (" \ n - Found a device: % s \ n ", DeviceName);
TRACE1 (" -- -- -- Volume name: % s \ n ", VolumeName);


VolumeInfo. VolumeName=VolumeName;//{GUID}
VolumeInfo. DosDeviceName=DeviceName;

//
DWORD dwReturn=0;
Cstrings strPath=_T (" ");

BOOL bOK=GetVolumePathNamesForVolumeName (VolumeName, (LPTSTR) strPath GetBuffer (MAX_PATH), MAX_PATH, & amp; DwReturn);
If (bOK)
{
StrPath. The Format (_T (" % s "), strPath);
TRACE1 (" -- -- -- Volume Path: % s \ n ", strPath);

(VolumeInfo. Path). The Format (_T (" % s "), strPath);
}

TRACE0 (" -- -- -- \ n ");

M_volue_infos. Add (VolumeInfo);

//
//Move on to the next volume.
Success=FindNextVolume (FindHandle, (LPTSTR) VolumeName GetBuffer (MAX_PATH), MAX_PATH);
If (! Success)
{
Error=GetLastError ();
If (Error!=ERROR_NO_MORE_FILES)
{
TRACE1 (" FindNextVolumeW failed with error code % d \ n ", the error).
break;
}
The else
{
Error=ERROR_SUCCESS;//there is no next//ERROR_NO_MORE_FILES
TRACE1 (" NO MORE FILES! The END! The Error code: % d \ n \ n ", ERROR_NO_MORE_FILES);
break;
}
}

TRACE1 (" \ n - Next - : % s \ n ", VolumeName);

}

FindVolumeClose (FindHandle);
FindHandle=INVALID_HANDLE_VALUE;
return true;

}


The structure definition
 typedef struct _STRUCT_VOLUME_INFO 
{
Cstrings VolumeName;/* \ \? B5d \ Volume {aaa0d9 77-1-11 e6-9 bc7-0015830 cbfeb} \ */
Cstrings DosDeviceName;//\ Device \ HarddiskVolume8
Cstrings Path;//c: \ D: \
Cstrings lable.//possible volume label,
Cstrings FileType.//NTFS? FAT32? ,

} ES_VOLUME_INFO;

,,,,,,
CArray & lt; ES_VOLUME_INFO, ES_VOLUME_INFO & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related