[FREELDR] Fix remaining hwdisk and FATX bugs (#1766)
authorStanislav Motylkov <x86corez@gmail.com>
Mon, 29 Jul 2019 22:27:36 +0000 (01:27 +0300)
committerHermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Mon, 29 Jul 2019 22:27:36 +0000 (00:27 +0200)
- DiskGetFileInformation() should return relative addresses -- relative to the beginning of the "device" (partition, or disk) in question.
- FatXSearchDirectoryBufferForFile() should assign file attributes.
- Minor code style improvements in FatOpenVolume().

CORE-16216 CORE-16248

Co-authored-by: Victor Perevertkin <victor@perevertkin.ru>
boot/freeldr/freeldr/arch/i386/hwdisk.c
boot/freeldr/freeldr/lib/fs/fat.c

index 50bb00e..bae615b 100644 (file)
@@ -65,8 +65,8 @@ DiskGetFileInformation(ULONG FileId, FILEINFORMATION* Information)
     DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
 
     RtlZeroMemory(Information, sizeof(FILEINFORMATION));
-    Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
-    Information->CurrentAddress.QuadPart = (Context->SectorOffset + Context->SectorNumber) * Context->SectorSize;
+    Information->EndingAddress.QuadPart = Context->SectorCount * Context->SectorSize;
+    Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
 
     return ESUCCESS;
 }
index 6af232b..6daa1a0 100644 (file)
@@ -266,12 +266,12 @@ BOOLEAN FatOpenVolume(PFAT_VOLUME_INFO Volume, PFAT_BOOTSECTOR BootSector, ULONG
     {
         Volume->BytesPerSector = 512;
         Volume->SectorsPerCluster = SWAPD(FatXVolumeBootSector->SectorsPerCluster);
-        Volume->FatSectorStart = (4096 / Volume->BytesPerSector);
+        Volume->FatSectorStart = (0x1000 / Volume->BytesPerSector);
         Volume->ActiveFatSectorStart = Volume->FatSectorStart;
         Volume->NumberOfFats = 1;
         FatSize = (ULONG)(PartitionSectorCount / Volume->SectorsPerCluster *
                   (Volume->FatType == FATX16 ? 2 : 4));
-        Volume->SectorsPerFat = (((FatSize + 4095) / 4096) * 4096) / Volume->BytesPerSector;
+        Volume->SectorsPerFat = ROUND_UP(FatSize, 0x1000) / Volume->BytesPerSector;
 
         Volume->RootDirSectorStart = Volume->FatSectorStart + Volume->NumberOfFats * Volume->SectorsPerFat;
         Volume->RootDirSectors = FatXVolumeBootSector->SectorsPerCluster;
@@ -720,6 +720,7 @@ static BOOLEAN FatXSearchDirectoryBufferForFile(PFAT_VOLUME_INFO Volume, PVOID D
             /*
              * We found the entry, now fill in the FAT_FILE_INFO struct
              */
+            FatFileInfoPointer->Attributes = DirEntry->Attr;
             FatFileInfoPointer->FileSize = DirEntry->Size;
             FatFileInfoPointer->FilePointer = 0;