Home > Software engineering >  GetVolumeInformationW access to the file system is null
GetVolumeInformationW access to the file system is null

Time:11-07

At the beginning of your bosses, I use Win API soon, could you tell me the code is as follows:
TCHAR volumeNameSystem [MAX_PATH];
Memset (volumeNameSystem, 0, sizeof (volumeNameSystem));
Cstrings strVolumeName=cstrings (szVolumeNameBuf);
USES_CONVERSION;
LPWSTR lpVolumeName=A2W (W2A (strVolumeName));
DWORD dwVolumeSerialNum;
DWORD dwMaxCompontentLength;
DWORD dwSysFlags;
GetVolumeInformationW (letter, lpVolumeName, 0, NULL, NULL, NULL, volumeNameSystem, MAX_PATH);
This code is there a problem? Why not get its file system type name? My disk type is NTFS file system, for example, it is empty, read out still hope everyone to give advice to the point to point out mistakes, wrong code? Be very grateful!!!!!

CodePudding user response:

 
#include

Int _tmain (int arg c, _TCHAR * argv [])
{
WCHAR wsVolumeName [256]={0};
DWORD dwVolumeSerialNumber=0;
DWORD dwMaximumComponentLength=0;
DWORD dwpFileSystemFlags=0;
WCHAR wsFileSystemNameBuffer [32]={0};

If (GetVolumeInformationW (
L "C: \ ",
WsVolumeName,
_countof (wsVolumeName),
& DwVolumeSerialNumber,
& DwMaximumComponentLength,
& DwpFileSystemFlags,
WsFileSystemNameBuffer,
_countof (wsFileSystemNameBuffer))
)
{
Wprintf (L "VolumeName=% s \ n", wsVolumeName);
Wprintf (L "SerialNumber=% 4 x - 4 x % \ n",
HIWORD (dwVolumeSerialNumber), LOWORD (dwVolumeSerialNumber));
Wprintf (L "MaximumComponentLength=% u \ n", dwMaximumComponentLength);

# define caseX (x) if (dwpFileSystemFlags & amp; (x)) {printf (" % s \ n ", # x); }

CaseX (FILE_CASE_PRESERVED_NAMES);
CaseX (FILE_CASE_SENSITIVE_SEARCH);
CaseX (FILE_FILE_COMPRESSION);
CaseX (FILE_NAMED_STREAMS);
CaseX (FILE_PERSISTENT_ACLS);
CaseX (FILE_READ_ONLY_VOLUME);
CaseX (FILE_SEQUENTIAL_WRITE_ONCE);
CaseX (FILE_SUPPORTS_ENCRYPTION);
CaseX (FILE_SUPPORTS_OBJECT_IDS);
CaseX (FILE_SUPPORTS_REPARSE_POINTS);
CaseX (FILE_SUPPORTS_SPARSE_FILES);
CaseX (FILE_SUPPORTS_TRANSACTIONS);
CaseX (FILE_UNICODE_ON_DISK);
CaseX (FILE_VOLUME_IS_COMPRESSED);
CaseX (FILE_VOLUME_QUOTAS);

Wprintf (L "FileSystem=% s \ n", wsFileSystemNameBuffer);

}
The else
{
Printf (" GetVolumeInformationW falied % u \ n ", GetLastError ());
}

return 0;
}




CodePudding user response:

reference 1st floor zgl7903 response:
 
#include

Int _tmain (int arg c, _TCHAR * argv [])
{
WCHAR wsVolumeName [256]={0};
DWORD dwVolumeSerialNumber=0;
DWORD dwMaximumComponentLength=0;
DWORD dwpFileSystemFlags=0;
WCHAR wsFileSystemNameBuffer [32]={0};

If (GetVolumeInformationW (
L "C: \ ",
WsVolumeName,
_countof (wsVolumeName),
& DwVolumeSerialNumber,
& DwMaximumComponentLength,
& DwpFileSystemFlags,
WsFileSystemNameBuffer,
_countof (wsFileSystemNameBuffer))
)
{
Wprintf (L "VolumeName=% s \ n", wsVolumeName);
Wprintf (L "SerialNumber=% 4 x - 4 x % \ n",
HIWORD (dwVolumeSerialNumber), LOWORD (dwVolumeSerialNumber));
Wprintf (L "MaximumComponentLength=% u \ n", dwMaximumComponentLength);

# define caseX (x) if (dwpFileSystemFlags & amp; (x)) {printf (" % s \ n ", # x); }

CaseX (FILE_CASE_PRESERVED_NAMES);
CaseX (FILE_CASE_SENSITIVE_SEARCH);
CaseX (FILE_FILE_COMPRESSION);
CaseX (FILE_NAMED_STREAMS);
CaseX (FILE_PERSISTENT_ACLS);
CaseX (FILE_READ_ONLY_VOLUME);
CaseX (FILE_SEQUENTIAL_WRITE_ONCE);
CaseX (FILE_SUPPORTS_ENCRYPTION);
CaseX (FILE_SUPPORTS_OBJECT_IDS);
CaseX (FILE_SUPPORTS_REPARSE_POINTS);
CaseX (FILE_SUPPORTS_SPARSE_FILES);
CaseX (FILE_SUPPORTS_TRANSACTIONS);
CaseX (FILE_UNICODE_ON_DISK);
CaseX (FILE_VOLUME_IS_COMPRESSED);
CaseX (FILE_VOLUME_QUOTAS);

Wprintf (L "FileSystem=% s \ n", wsFileSystemNameBuffer);

}
The else
{
Printf (" GetVolumeInformationW falied % u \ n ", GetLastError ());
}

return 0;
}




reference 1st floor zgl7903 response:
 
#include

Int _tmain (int arg c, _TCHAR * argv [])
{
WCHAR wsVolumeName [256]={0};
DWORD dwVolumeSerialNumber=0;
DWORD dwMaximumComponentLength=0;
DWORD dwpFileSystemFlags=0;
WCHAR wsFileSystemNameBuffer [32]={0};

If (GetVolumeInformationW (
L "C: \ ",
WsVolumeName,
_countof (wsVolumeName),
& DwVolumeSerialNumber,
& DwMaximumComponentLength,
& DwpFileSystemFlags,
WsFileSystemNameBuffer,
_countof (wsFileSystemNameBuffer))
)
{
Wprintf (L "VolumeName=% s \ n", wsVolumeName);
Wprintf (L "SerialNumber=% 4 x - 4 x % \ n",
HIWORD (dwVolumeSerialNumber), LOWORD (dwVolumeSerialNumber));
Wprintf (L "MaximumComponentLength=% u \ n", dwMaximumComponentLength);

# define caseX (x) if (dwpFileSystemFlags & amp; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related