[USETUP] Enhancements for filesystem utility functions.

- Introduce code that detects the filesystem of a (mounted?) partition, using NtQueryVolumeInformationFile() with FileFsAttributeInformation class,
  aka. rely on ReactOS itself (kernel, storage stack, filesystem drivers...) to recognize the FS on a partition that should normally be seen by the system.
  This currently half-works for whatever reason (to be insvestigated), while it works on Windows.
- Fix few comments & a function parameter name.
- Use NT string pointer types.

svn path=/branches/setup_improvements/; revision=74529
This commit is contained in:
Hermès Bélusca-Maïto 2017-05-13 16:20:10 +00:00
parent 60532e9c43
commit 56ea51bbe4
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 122 additions and 19 deletions

View file

@ -35,7 +35,7 @@
VOID VOID
AddProvider( AddProvider(
IN OUT PFILE_SYSTEM_LIST List, IN OUT PFILE_SYSTEM_LIST List,
IN LPCWSTR FileSystemName, IN PCWSTR FileSystemName,
IN FORMATEX FormatFunc, IN FORMATEX FormatFunc,
IN CHKDSKEX ChkdskFunc) IN CHKDSKEX ChkdskFunc)
{ {
@ -69,7 +69,7 @@ AddProvider(
PFILE_SYSTEM_ITEM PFILE_SYSTEM_ITEM
GetFileSystemByName( GetFileSystemByName(
IN PFILE_SYSTEM_LIST List, IN PFILE_SYSTEM_LIST List,
IN LPWSTR FileSystemName) IN PWSTR FileSystemName)
{ {
PLIST_ENTRY ListEntry; PLIST_ENTRY ListEntry;
PFILE_SYSTEM_ITEM Item; PFILE_SYSTEM_ITEM Item;
@ -87,6 +87,80 @@ GetFileSystemByName(
return NULL; return NULL;
} }
#if 0 // FIXME: To be fully enabled when our storage stack & al. will work better!
/* NOTE: Ripped & adapted from base/system/autochk/autochk.c */
static NTSTATUS
_MyGetFileSystem(
IN struct _PARTENTRY* PartEntry,
IN OUT PWSTR FileSystemName,
IN SIZE_T FileSystemNameSize)
{
NTSTATUS Status;
HANDLE FileHandle;
IO_STATUS_BLOCK IoStatusBlock;
PFILE_FS_ATTRIBUTE_INFORMATION FileFsAttribute;
UCHAR Buffer[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + MAX_PATH * sizeof(WCHAR)];
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING PartitionRootPath;
WCHAR PathBuffer[MAX_PATH];
FileFsAttribute = (PFILE_FS_ATTRIBUTE_INFORMATION)Buffer;
/* Set PartitionRootPath */
swprintf(PathBuffer,
// L"\\Device\\Harddisk%lu\\Partition%lu", // Should work! But because ReactOS sucks atm. it actually doesn't work!!
L"\\Device\\Harddisk%lu\\Partition%lu\\", // HACK: Use this as a temporary hack!
PartEntry->DiskEntry->DiskNumber,
PartEntry->PartitionNumber);
RtlInitUnicodeString(&PartitionRootPath, PathBuffer);
DPRINT("PartitionRootPath: %wZ\n", &PartitionRootPath);
/* Open the partition */
InitializeObjectAttributes(&ObjectAttributes,
&PartitionRootPath,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenFile(&FileHandle, // PartitionHandle,
FILE_GENERIC_READ /* | SYNCHRONIZE */,
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_READ,
0 /* FILE_SYNCHRONOUS_IO_NONALERT */);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to open partition %wZ, Status 0x%08lx\n", &PartitionRootPath, Status);
return Status;
}
/* Retrieve the FS attributes */
Status = NtQueryVolumeInformationFile(FileHandle,
&IoStatusBlock,
FileFsAttribute,
sizeof(Buffer),
FileFsAttributeInformation);
NtClose(FileHandle);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtQueryVolumeInformationFile failed for partition %wZ, Status 0x%08lx\n", &PartitionRootPath, Status);
return Status;
}
if (FileSystemNameSize * sizeof(WCHAR) < FileFsAttribute->FileSystemNameLength + sizeof(WCHAR))
return STATUS_BUFFER_TOO_SMALL;
RtlCopyMemory(FileSystemName,
FileFsAttribute->FileSystemName,
FileFsAttribute->FileSystemNameLength);
FileSystemName[FileFsAttribute->FileSystemNameLength / sizeof(WCHAR)] = UNICODE_NULL;
return STATUS_SUCCESS;
}
#endif
PFILE_SYSTEM_ITEM PFILE_SYSTEM_ITEM
GetFileSystem( GetFileSystem(
@ -94,7 +168,11 @@ GetFileSystem(
IN struct _PARTENTRY* PartEntry) IN struct _PARTENTRY* PartEntry)
{ {
PFILE_SYSTEM_ITEM CurrentFileSystem; PFILE_SYSTEM_ITEM CurrentFileSystem;
LPWSTR FileSystemName = NULL; PWSTR FileSystemName = NULL;
#if 0 // For code temporarily disabled below
NTSTATUS Status;
WCHAR FsRecFileSystemName[MAX_PATH];
#endif
CurrentFileSystem = PartEntry->FileSystem; CurrentFileSystem = PartEntry->FileSystem;
@ -106,6 +184,26 @@ GetFileSystem(
CurrentFileSystem = NULL; CurrentFileSystem = NULL;
#if 0 // FIXME: To be fully enabled when our storage stack & al. will work better!
/*
* We don't have one...
*
* Try to infer one using NT file system recognition.
*/
Status = _MyGetFileSystem(PartEntry, FsRecFileSystemName, ARRAYSIZE(FsRecFileSystemName));
if (NT_SUCCESS(Status) && *FsRecFileSystemName)
{
/* Temporary HACK: map FAT32 back to FAT */
if (wcscmp(FsRecFileSystemName, L"FAT32") == 0)
wcscpy(FsRecFileSystemName, L"FAT");
FileSystemName = FsRecFileSystemName;
goto Quit;
}
#endif
/* /*
* We don't have one... * We don't have one...
* *
@ -141,12 +239,19 @@ GetFileSystem(
FileSystemName = L"NTFS"; /* FIXME: Not quite correct! */ FileSystemName = L"NTFS"; /* FIXME: Not quite correct! */
} }
#if 0
Quit: // For code temporarily disabled above
#endif
// HACK: WARNING: We cannot write on this FS yet! // HACK: WARNING: We cannot write on this FS yet!
if (FileSystemName)
{
if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType == PARTITION_IFS) if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType == PARTITION_IFS)
DPRINT1("Recognized file system %S that doesn't support write support yet!\n", FileSystemName); DPRINT1("Recognized file system %S that doesn't support write support yet!\n", FileSystemName);
}
DPRINT1("GetFileSystem -- PartitionType: 0x%02X ; FileSystemName (guessed): %S\n", DPRINT1("GetFileSystem -- PartitionType: 0x%02X ; FileSystemName (guessed): %S\n",
PartEntry->PartitionType, FileSystemName); PartEntry->PartitionType, FileSystemName ? FileSystemName : L"None");
if (FileSystemName != NULL) if (FileSystemName != NULL)
CurrentFileSystem = GetFileSystemByName(FileSystemList, FileSystemName); CurrentFileSystem = GetFileSystemByName(FileSystemList, FileSystemName);
@ -160,7 +265,7 @@ CreateFileSystemList(
IN SHORT Left, IN SHORT Left,
IN SHORT Top, IN SHORT Top,
IN BOOLEAN ForceFormat, IN BOOLEAN ForceFormat,
IN LPCWSTR ForceFileSystem) IN PCWSTR SelectFileSystem)
{ {
PFILE_SYSTEM_LIST List; PFILE_SYSTEM_LIST List;
PFILE_SYSTEM_ITEM Item; PFILE_SYSTEM_ITEM Item;
@ -183,16 +288,16 @@ CreateFileSystemList(
if (!ForceFormat) if (!ForceFormat)
{ {
/* Add 'Keep' provider */ /* Add the 'Keep existing filesystem' dummy provider */
AddProvider(List, NULL, NULL, NULL); AddProvider(List, NULL, NULL, NULL);
} }
/* Search for ForceFileSystem in list */ /* Search for SelectFileSystem in list */
ListEntry = List->ListHead.Flink; ListEntry = List->ListHead.Flink;
while (ListEntry != &List->ListHead) while (ListEntry != &List->ListHead)
{ {
Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
if (Item->FileSystemName && wcscmp(ForceFileSystem, Item->FileSystemName) == 0) if (Item->FileSystemName && wcscmp(SelectFileSystem, Item->FileSystemName) == 0)
{ {
List->Selected = Item; List->Selected = Item;
break; break;
@ -205,7 +310,6 @@ CreateFileSystemList(
return List; return List;
} }
VOID VOID
DestroyFileSystemList( DestroyFileSystemList(
IN PFILE_SYSTEM_LIST List) IN PFILE_SYSTEM_LIST List)
@ -226,7 +330,6 @@ DestroyFileSystemList(
RtlFreeHeap(ProcessHeap, 0, List); RtlFreeHeap(ProcessHeap, 0, List);
} }
VOID VOID
DrawFileSystemList( DrawFileSystemList(
IN PFILE_SYSTEM_LIST List) IN PFILE_SYSTEM_LIST List)
@ -264,7 +367,9 @@ DrawFileSystemList(
snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_FORMATDISK2), Item->FileSystemName); snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_FORMATDISK2), Item->FileSystemName);
} }
else else
{
snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_KEEPFORMAT)); snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_KEEPFORMAT));
}
if (ListEntry == &List->Selected->ListEntry) if (ListEntry == &List->Selected->ListEntry)
CONSOLE_SetInvertedTextXY(List->Left, CONSOLE_SetInvertedTextXY(List->Left,
@ -279,7 +384,6 @@ DrawFileSystemList(
} }
} }
VOID VOID
ScrollDownFileSystemList( ScrollDownFileSystemList(
IN PFILE_SYSTEM_LIST List) IN PFILE_SYSTEM_LIST List)
@ -291,7 +395,6 @@ ScrollDownFileSystemList(
} }
} }
VOID VOID
ScrollUpFileSystemList( ScrollUpFileSystemList(
IN PFILE_SYSTEM_LIST List) IN PFILE_SYSTEM_LIST List)

View file

@ -31,7 +31,7 @@
typedef struct _FILE_SYSTEM_ITEM typedef struct _FILE_SYSTEM_ITEM
{ {
LIST_ENTRY ListEntry; LIST_ENTRY ListEntry;
LPCWSTR FileSystemName; /* Not owned by the item */ PCWSTR FileSystemName; /* Not owned by the item */
FORMATEX FormatFunc; FORMATEX FormatFunc;
CHKDSKEX ChkdskFunc; CHKDSKEX ChkdskFunc;
BOOLEAN QuickFormat; BOOLEAN QuickFormat;
@ -46,16 +46,16 @@ typedef struct _FILE_SYSTEM_LIST
} FILE_SYSTEM_LIST, *PFILE_SYSTEM_LIST; } FILE_SYSTEM_LIST, *PFILE_SYSTEM_LIST;
VOID VOID
FS_AddProvider( AddProvider(
IN OUT PFILE_SYSTEM_LIST List, IN OUT PFILE_SYSTEM_LIST List,
IN LPCWSTR FileSystemName, IN PCWSTR FileSystemName,
IN FORMATEX FormatFunc, IN FORMATEX FormatFunc,
IN CHKDSKEX ChkdskFunc); IN CHKDSKEX ChkdskFunc);
PFILE_SYSTEM_ITEM PFILE_SYSTEM_ITEM
GetFileSystemByName( GetFileSystemByName(
IN PFILE_SYSTEM_LIST List, IN PFILE_SYSTEM_LIST List,
IN LPWSTR FileSystemName); IN PWSTR FileSystemName);
struct _PARTENTRY; // Defined in partlist.h struct _PARTENTRY; // Defined in partlist.h
PFILE_SYSTEM_ITEM PFILE_SYSTEM_ITEM
@ -68,7 +68,7 @@ CreateFileSystemList(
IN SHORT Left, IN SHORT Left,
IN SHORT Top, IN SHORT Top,
IN BOOLEAN ForceFormat, IN BOOLEAN ForceFormat,
IN LPCWSTR ForceFileSystem); IN PCWSTR SelectFileSystem);
VOID VOID
DestroyFileSystemList( DestroyFileSystemList(