Obviously, as long as you have the IopParseDevice hack in action in
usetup, you cannot expect FS to given you reliable information when you
open the device since you directly talk to scsiport driver.
Le 26/05/2018 à 19:18, Hermès Bélusca-Maïto a écrit :
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=56ea51bbe498d126a61ba…
commit 56ea51bbe498d126a61bab93c7ae95860bd290f2
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat May 13 16:20:10 2017 +0000
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat May 26 19:09:38 2018 +0200
[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
---
base/setup/usetup/fslist.c | 131 ++++++++++++++++++++++++++++++++++++++++-----
base/setup/usetup/fslist.h | 10 ++--
2 files changed, 122 insertions(+), 19 deletions(-)
diff --git a/base/setup/usetup/fslist.c b/base/setup/usetup/fslist.c
index 0b190d4a8b..1eb158b777 100644
--- a/base/setup/usetup/fslist.c
+++ b/base/setup/usetup/fslist.c
@@ -35,7 +35,7 @@
VOID
AddProvider(
IN OUT PFILE_SYSTEM_LIST List,
- IN LPCWSTR FileSystemName,
+ IN PCWSTR FileSystemName,
IN FORMATEX FormatFunc,
IN CHKDSKEX ChkdskFunc)
{
@@ -69,7 +69,7 @@ AddProvider(
PFILE_SYSTEM_ITEM
GetFileSystemByName(
IN PFILE_SYSTEM_LIST List,
- IN LPWSTR FileSystemName)
+ IN PWSTR FileSystemName)
{
PLIST_ENTRY ListEntry;
PFILE_SYSTEM_ITEM Item;
@@ -87,6 +87,80 @@ GetFileSystemByName(
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
GetFileSystem(
@@ -94,7 +168,11 @@ GetFileSystem(
IN struct _PARTENTRY* PartEntry)
{
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;
@@ -106,6 +184,26 @@ GetFileSystem(
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...
*
@@ -141,12 +239,19 @@ GetFileSystem(
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!
- if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType ==
PARTITION_IFS)
- DPRINT1("Recognized file system %S that doesn't support write support
yet!\n", FileSystemName);
+ if (FileSystemName)
+ {
+ if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType
== PARTITION_IFS)
+ DPRINT1("Recognized file system %S that doesn't support write
support yet!\n", FileSystemName);
+ }
DPRINT1("GetFileSystem -- PartitionType: 0x%02X ; FileSystemName (guessed):
%S\n",
- PartEntry->PartitionType, FileSystemName);
+ PartEntry->PartitionType, FileSystemName ? FileSystemName :
L"None");
if (FileSystemName != NULL)
CurrentFileSystem = GetFileSystemByName(FileSystemList, FileSystemName);
@@ -160,7 +265,7 @@ CreateFileSystemList(
IN SHORT Left,
IN SHORT Top,
IN BOOLEAN ForceFormat,
- IN LPCWSTR ForceFileSystem)
+ IN PCWSTR SelectFileSystem)
{
PFILE_SYSTEM_LIST List;
PFILE_SYSTEM_ITEM Item;
@@ -183,16 +288,16 @@ CreateFileSystemList(
if (!ForceFormat)
{
- /* Add 'Keep' provider */
+ /* Add the 'Keep existing filesystem' dummy provider */
AddProvider(List, NULL, NULL, NULL);
}
- /* Search for ForceFileSystem in list */
+ /* Search for SelectFileSystem in list */
ListEntry = List->ListHead.Flink;
while (ListEntry != &List->ListHead)
{
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;
break;
@@ -205,7 +310,6 @@ CreateFileSystemList(
return List;
}
-
VOID
DestroyFileSystemList(
IN PFILE_SYSTEM_LIST List)
@@ -226,7 +330,6 @@ DestroyFileSystemList(
RtlFreeHeap(ProcessHeap, 0, List);
}
-
VOID
DrawFileSystemList(
IN PFILE_SYSTEM_LIST List)
@@ -264,7 +367,9 @@ DrawFileSystemList(
snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_FORMATDISK2),
Item->FileSystemName);
}
else
+ {
snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_KEEPFORMAT));
+ }
if (ListEntry == &List->Selected->ListEntry)
CONSOLE_SetInvertedTextXY(List->Left,
@@ -279,7 +384,6 @@ DrawFileSystemList(
}
}
-
VOID
ScrollDownFileSystemList(
IN PFILE_SYSTEM_LIST List)
@@ -291,7 +395,6 @@ ScrollDownFileSystemList(
}
}
-
VOID
ScrollUpFileSystemList(
IN PFILE_SYSTEM_LIST List)
diff --git a/base/setup/usetup/fslist.h b/base/setup/usetup/fslist.h
index 685a2cfe2e..4433d381ba 100644
--- a/base/setup/usetup/fslist.h
+++ b/base/setup/usetup/fslist.h
@@ -31,7 +31,7 @@
typedef struct _FILE_SYSTEM_ITEM
{
LIST_ENTRY ListEntry;
- LPCWSTR FileSystemName; /* Not owned by the item */
+ PCWSTR FileSystemName; /* Not owned by the item */
FORMATEX FormatFunc;
CHKDSKEX ChkdskFunc;
BOOLEAN QuickFormat;
@@ -46,16 +46,16 @@ typedef struct _FILE_SYSTEM_LIST
} FILE_SYSTEM_LIST, *PFILE_SYSTEM_LIST;
VOID
-FS_AddProvider(
+AddProvider(
IN OUT PFILE_SYSTEM_LIST List,
- IN LPCWSTR FileSystemName,
+ IN PCWSTR FileSystemName,
IN FORMATEX FormatFunc,
IN CHKDSKEX ChkdskFunc);
PFILE_SYSTEM_ITEM
GetFileSystemByName(
IN PFILE_SYSTEM_LIST List,
- IN LPWSTR FileSystemName);
+ IN PWSTR FileSystemName);
struct _PARTENTRY; // Defined in partlist.h
PFILE_SYSTEM_ITEM
@@ -68,7 +68,7 @@ CreateFileSystemList(
IN SHORT Left,
IN SHORT Top,
IN BOOLEAN ForceFormat,
- IN LPCWSTR ForceFileSystem);
+ IN PCWSTR SelectFileSystem);
VOID
DestroyFileSystemList(
--
Pierre Schweitzer <pierre at reactos.org>
System & Network Administrator
Senior Kernel Developer
ReactOS Deutschland e.V.