[DISKPART] Print proper file system information for the FILESYSTEMS command

This commit is contained in:
Eric Kohl 2022-06-19 15:40:08 +02:00
parent b6d1d1fd7d
commit f79ec61bdc
14 changed files with 133 additions and 21 deletions

View File

@ -190,6 +190,7 @@ typedef struct _VOLENTRY
ULONG VolumeNumber;
WCHAR VolumeName[MAX_PATH];
WCHAR DeviceName[MAX_PATH];
WCHAR DriveLetter;

View File

@ -11,6 +11,104 @@
#define NDEBUG
#include <debug.h>
static
BOOL
GetFileSystemInfo(
PVOLENTRY VolumeEntry)
{
WCHAR VolumeNameBuffer[MAX_PATH];
UNICODE_STRING VolumeName;
HANDLE VolumeHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
ULONG ulSize, ulClusterSize = 0;
FILE_FS_FULL_SIZE_INFORMATION SizeInfo;
FILE_FS_FULL_SIZE_INFORMATION FullSizeInfo;
PFILE_FS_ATTRIBUTE_INFORMATION pAttributeInfo = NULL;
NTSTATUS Status;
wcscpy(VolumeNameBuffer, VolumeEntry->DeviceName);
wcscat(VolumeNameBuffer, L"\\");
RtlInitUnicodeString(&VolumeName, VolumeNameBuffer);
InitializeObjectAttributes(&ObjectAttributes,
&VolumeName,
0,
NULL,
NULL);
Status = NtOpenFile(&VolumeHandle,
SYNCHRONIZE,
&ObjectAttributes,
&IoStatusBlock,
0,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_FOR_BACKUP_INTENT);
if (!NT_SUCCESS(Status))
{
if (Status == STATUS_NO_MEDIA_IN_DEVICE)
{
ConResPuts(StdOut, IDS_ERROR_NO_MEDIUM);
return FALSE;
}
else if (Status == STATUS_UNRECOGNIZED_VOLUME)
{
ConResPuts(StdOut, IDS_FILESYSTEMS_CURRENT);
ConPuts(StdOut, L"\n");
ConResPrintf(StdOut, IDS_FILESYSTEMS_TYPE, L"RAW");
ConResPrintf(StdOut, IDS_FILESYSTEMS_CLUSTERSIZE, 512);
}
return TRUE;
}
ulSize = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 255 * sizeof(WCHAR);
pAttributeInfo = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
ulSize);
Status = NtQueryVolumeInformationFile(VolumeHandle,
&IoStatusBlock,
pAttributeInfo,
ulSize,
FileFsAttributeInformation);
Status = NtQueryVolumeInformationFile(VolumeHandle,
&IoStatusBlock,
&FullSizeInfo,
sizeof(FILE_FS_FULL_SIZE_INFORMATION),
FileFsFullSizeInformation);
if (NT_SUCCESS(Status))
{
ulClusterSize = FullSizeInfo.BytesPerSector * FullSizeInfo.SectorsPerAllocationUnit;
}
else
{
Status = NtQueryVolumeInformationFile(VolumeHandle,
&IoStatusBlock,
&SizeInfo,
sizeof(FILE_FS_SIZE_INFORMATION),
FileFsSizeInformation);
if (NT_SUCCESS(Status))
{
ulClusterSize = SizeInfo.BytesPerSector * SizeInfo.SectorsPerAllocationUnit;
}
}
ConResPuts(StdOut, IDS_FILESYSTEMS_CURRENT);
ConPuts(StdOut, L"\n");
ConResPrintf(StdOut, IDS_FILESYSTEMS_TYPE, pAttributeInfo->FileSystemName);
ConResPrintf(StdOut, IDS_FILESYSTEMS_CLUSTERSIZE, ulClusterSize);
if (pAttributeInfo)
RtlFreeHeap(RtlGetProcessHeap(), 0, pAttributeInfo);
NtClose(VolumeHandle);
return TRUE;
}
BOOL
filesystems_main(
@ -24,13 +122,16 @@ filesystems_main(
}
ConPuts(StdOut, L"\n");
ConResPuts(StdOut, IDS_FILESYSTEMS_CURRENT);
ConPuts(StdOut, L"\n");
ConResPrintf(StdOut, IDS_FILESYSTEMS_TYPE, (CurrentVolume->pszFilesystem == NULL) ? L"RAW" : CurrentVolume->pszFilesystem);
ConResPrintf(StdOut, IDS_FILESYSTEMS_CLUSTERSIZE);
ConPuts(StdOut, L"\n");
ConResPuts(StdOut, IDS_FILESYSTEMS_FORMATTING);
if (GetFileSystemInfo(CurrentVolume))
{
ConPuts(StdOut, L"\n");
ConResPuts(StdOut, IDS_FILESYSTEMS_FORMATTING);
/* FIXME: List available file systems */
}
ConPuts(StdOut, L"\n");
return TRUE;

View File

@ -72,7 +72,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Aktuelles Dateisystem\n"
IDS_FILESYSTEMS_FORMATTING "Zur Formatierung unterstützte Dateisysteme\n"
IDS_FILESYSTEMS_TYPE "Typ : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Größe der Zuordnungseinheit: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Größe der Zuordnungseinheit: %lu\n"
END
STRINGTABLE
@ -233,4 +233,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Error opening script: %s\n"
IDS_ERROR_MSG_BAD_ARG "Error processing argument: %s\n"
IDS_ERROR_INVALID_ARGS "Invalid arguments\n"
IDS_ERROR_NO_MEDIUM "Es befindet sich kein Medium im Gerät.\n"
END

View File

@ -72,7 +72,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Current Filesystem\n"
IDS_FILESYSTEMS_FORMATTING "Filesystems available for formatting\n"
IDS_FILESYSTEMS_TYPE "Type : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: %lu\n"
END
STRINGTABLE
@ -233,4 +233,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Error opening script: %s\n"
IDS_ERROR_MSG_BAD_ARG "Error processing argument: %s\n"
IDS_ERROR_INVALID_ARGS "Invalid arguments\n"
IDS_ERROR_NO_MEDIUM "No medium in device.\n"
END

View File

@ -72,7 +72,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Current Filesystem\n"
IDS_FILESYSTEMS_FORMATTING "Filesystems available for formatting\n"
IDS_FILESYSTEMS_TYPE "Type : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: %lu\n"
END
STRINGTABLE
@ -233,4 +233,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Błąd podczas otwierania skryptu: %s\n"
IDS_ERROR_MSG_BAD_ARG "Błąd przetwarzania argumentu: %s\n"
IDS_ERROR_INVALID_ARGS "Nieprawidłowe argumenty\n"
IDS_ERROR_NO_MEDIUM "No medium in device.\n"
END

View File

@ -74,7 +74,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Current Filesystem\n"
IDS_FILESYSTEMS_FORMATTING "Filesystems available for formatting\n"
IDS_FILESYSTEMS_TYPE "Type : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: %lu\n"
END
STRINGTABLE
@ -235,4 +235,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Erro ao abrir o script: %s\n"
IDS_ERROR_MSG_BAD_ARG "Erro ao processar o argumento: %s\n"
IDS_ERROR_INVALID_ARGS "Argumento inválido\n"
IDS_ERROR_NO_MEDIUM "No medium in device.\n"
END

View File

@ -74,7 +74,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Current Filesystem\n"
IDS_FILESYSTEMS_FORMATTING "Filesystems available for formatting\n"
IDS_FILESYSTEMS_TYPE "Type : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: %lu\n"
END
STRINGTABLE
@ -235,4 +235,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Eroare la deschiderea fișierului script: %s\n"
IDS_ERROR_MSG_BAD_ARG "Eroare la prelucrarea argumentului: %s\n"
IDS_ERROR_INVALID_ARGS "Argumente nevalide\n"
IDS_ERROR_NO_MEDIUM "No medium in device.\n"
END

View File

@ -74,7 +74,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Current Filesystem\n"
IDS_FILESYSTEMS_FORMATTING "Filesystems available for formatting\n"
IDS_FILESYSTEMS_TYPE "Type : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: %lu\n"
END
STRINGTABLE
@ -235,4 +235,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Ошибка открытия скрипта: %s\n"
IDS_ERROR_MSG_BAD_ARG "Ошибка обработки параметров: %s\n"
IDS_ERROR_INVALID_ARGS "Ошибка в указании параметров\n"
IDS_ERROR_NO_MEDIUM "No medium in device.\n"
END

View File

@ -76,7 +76,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Current Filesystem\n"
IDS_FILESYSTEMS_FORMATTING "Filesystems available for formatting\n"
IDS_FILESYSTEMS_TYPE "Type : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: %lu\n"
END
STRINGTABLE
@ -237,4 +237,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Error në hapjen e skriptes: %s\n"
IDS_ERROR_MSG_BAD_ARG "Error argumenti i procesimit: %s\n"
IDS_ERROR_INVALID_ARGS "Invalid arguments\n"
IDS_ERROR_NO_MEDIUM "No medium in device.\n"
END

View File

@ -74,7 +74,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Current Filesystem\n"
IDS_FILESYSTEMS_FORMATTING "Filesystems available for formatting\n"
IDS_FILESYSTEMS_TYPE "Type : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: %lu\n"
END
STRINGTABLE
@ -235,4 +235,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Betik açmada yanlışlık: %s\n"
IDS_ERROR_MSG_BAD_ARG "Argüman işlemede yanlışlık: %s\n"
IDS_ERROR_INVALID_ARGS "Geçersiz değiştirgenler\n"
IDS_ERROR_NO_MEDIUM "No medium in device.\n"
END

View File

@ -81,7 +81,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Current Filesystem\n"
IDS_FILESYSTEMS_FORMATTING "Filesystems available for formatting\n"
IDS_FILESYSTEMS_TYPE "Type : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: %lu\n"
END
STRINGTABLE
@ -242,4 +242,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "打开脚本时出错:%s\n"
IDS_ERROR_MSG_BAD_ARG "处理参数时出错:%s\n"
IDS_ERROR_INVALID_ARGS "无效的参数\n"
IDS_ERROR_NO_MEDIUM "No medium in device.\n"
END

View File

@ -75,7 +75,7 @@ BEGIN
IDS_FILESYSTEMS_CURRENT "Current Filesystem\n"
IDS_FILESYSTEMS_FORMATTING "Filesystems available for formatting\n"
IDS_FILESYSTEMS_TYPE "Type : %s\n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: \n"
IDS_FILESYSTEMS_CLUSTERSIZE "Cluster size: %lu\n"
END
STRINGTABLE
@ -236,4 +236,5 @@ BEGIN
IDS_ERROR_MSG_NO_SCRIPT "錯誤開始的指令碼: %s\n"
IDS_ERROR_MSG_BAD_ARG "錯誤處理參數: %s\n"
IDS_ERROR_INVALID_ARGS "無效的參數\n"
IDS_ERROR_NO_MEDIUM "No medium in device.\n"
END

View File

@ -1254,7 +1254,7 @@ GetVolumeExtents(
static
VOID
GetVolumeType(
HANDLE VolumeHandle,
_In_ HANDLE VolumeHandle,
_In_ PVOLENTRY VolumeEntry)
{
FILE_FS_DEVICE_INFORMATION DeviceInfo;
@ -1306,7 +1306,6 @@ AddVolumeToList(
WCHAR szFilesystem[MAX_PATH + 1];
DWORD CharCount = 0;
WCHAR DeviceName[MAX_PATH] = L"";
size_t Index = 0;
OBJECT_ATTRIBUTES ObjectAttributes;
@ -1329,7 +1328,7 @@ AddVolumeToList(
pszVolumeName[Index] = L'\0';
CharCount = QueryDosDeviceW(&pszVolumeName[4], DeviceName, ARRAYSIZE(DeviceName));
CharCount = QueryDosDeviceW(&pszVolumeName[4], VolumeEntry->DeviceName, ARRAYSIZE(VolumeEntry->DeviceName));
pszVolumeName[Index] = L'\\';
@ -1339,9 +1338,9 @@ AddVolumeToList(
return;
}
DPRINT("DeviceName: %S\n", DeviceName);
DPRINT("DeviceName: %S\n", VolumeEntry->DeviceName);
RtlInitUnicodeString(&Name, DeviceName);
RtlInitUnicodeString(&Name, VolumeEntry->DeviceName);
InitializeObjectAttributes(&ObjectAttributes,
&Name,

View File

@ -185,3 +185,4 @@
#define IDS_ERROR_MSG_NO_SCRIPT 2000
#define IDS_ERROR_MSG_BAD_ARG 2001
#define IDS_ERROR_INVALID_ARGS 2002
#define IDS_ERROR_NO_MEDIUM 2003