[NTDLL_APITEST] Query sector size for NtWriteFile tests
authorPierre Schweitzer <pierre@reactos.org>
Thu, 2 May 2019 11:59:47 +0000 (13:59 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Thu, 2 May 2019 11:59:47 +0000 (13:59 +0200)
modules/rostests/apitests/ntdll/NtWriteFile.c

index 1383e4e..7080fa8 100644 (file)
@@ -38,6 +38,24 @@ SizeOfMdl(VOID)
     return Is64BitSystem() ? 48 : 28;
 }
 
     return Is64BitSystem() ? 48 : 28;
 }
 
+static
+ULONG
+SizeOfSector(VOID)
+{
+    BOOL Ret;
+    ULONG SectorSize;
+
+    /* FIXME: Would be better to actually open systemroot */
+    Ret = GetDiskFreeSpaceW(NULL, NULL, &SectorSize, NULL, NULL);
+    ok(Ret != FALSE, "GetDiskFreeSpaceW failed: %lx\n", GetLastError());
+    if (!Ret)
+    {
+        SectorSize = 4096; /* On failure, assume max size */
+    }
+
+    return SectorSize;
+}
+
 START_TEST(NtWriteFile)
 {
     NTSTATUS Status;
 START_TEST(NtWriteFile)
 {
     NTSTATUS Status;
@@ -213,7 +231,10 @@ START_TEST(NtWriteFile)
     ok_hex(Status, STATUS_SUCCESS);
 
     /* Now, testing aligned/non aligned writes */
     ok_hex(Status, STATUS_SUCCESS);
 
     /* Now, testing aligned/non aligned writes */
-    BufferSize = 4096; /* We assume max sector size */
+
+    BufferSize = SizeOfSector();
+    trace("Sector is %ld bytes\n", BufferSize);
+
     Status = NtAllocateVirtualMemory(NtCurrentProcess(),
                                      &Buffer,
                                      0,
     Status = NtAllocateVirtualMemory(NtCurrentProcess(),
                                      &Buffer,
                                      0,