From 24c7a108076b0da88585a7dda23d28dc01296b17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Herv=C3=A9=20Poussineau?= Date: Wed, 26 May 2010 19:58:54 +0000 Subject: [PATCH] [freeldr] Repair NTFS driver. ReactOS is now able to boot (again) from NTFS partitions svn path=/trunk/; revision=47365 --- reactos/boot/freeldr/freeldr/fs/ntfs.c | 28 +++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/reactos/boot/freeldr/freeldr/fs/ntfs.c b/reactos/boot/freeldr/freeldr/fs/ntfs.c index 123edf309cf..aff3bfaa339 100644 --- a/reactos/boot/freeldr/freeldr/fs/ntfs.c +++ b/reactos/boot/freeldr/freeldr/fs/ntfs.c @@ -1,6 +1,7 @@ /* * FreeLoader NTFS support * Copyright (C) 2004 Filip Navara + * Copyright (C) 2009-2010 Hervé Poussineau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +38,7 @@ typedef struct _NTFS_VOLUME_INFO /* FIXME: MFTContext is never freed. */ PNTFS_ATTR_CONTEXT MFTContext; ULONG DeviceId; + PUCHAR TemporarySector; } NTFS_VOLUME_INFO; PNTFS_VOLUME_INFO NtfsVolumes[MAX_FDS]; @@ -147,10 +149,17 @@ static BOOLEAN NtfsDiskRead(PNTFS_VOLUME_INFO Volume, ULONGLONG Offset, ULONGLON ret = ArcSeek(Volume->DeviceId, &Position, SeekAbsolute); if (ret != ESUCCESS) return FALSE; - ReadLength = min(Length, Volume->BootSector.BytesPerSector - (Offset % Volume->BootSector.BytesPerSector)); - ret = ArcRead(Volume->DeviceId, Buffer, ReadLength, &Count); - if (ret != ESUCCESS || Count != ReadLength) + ret = ArcRead(Volume->DeviceId, Volume->TemporarySector, Volume->BootSector.BytesPerSector, &Count); + if (ret != ESUCCESS || Count != Volume->BootSector.BytesPerSector) return FALSE; + ReadLength = min(Length, Volume->BootSector.BytesPerSector - (Offset % Volume->BootSector.BytesPerSector)); + + // + // Copy interesting data + // + RtlCopyMemory(Buffer, + &Volume->TemporarySector[Offset % Volume->BootSector.BytesPerSector], + ReadLength); // // Move to unfilled buffer part @@ -792,6 +801,7 @@ LONG NtfsOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId) return ENOENT; } + FsSetDeviceSpecific(*FileId, FileHandle); return ESUCCESS; } @@ -932,6 +942,18 @@ const DEVVTBL* NtfsMount(ULONG DeviceId) return NULL; } + // + // Keep room to read partial sectors + // + Volume->TemporarySector = MmHeapAlloc(Volume->BootSector.BytesPerSector); + if (!Volume->TemporarySector) + { + FileSystemError("Failed to allocate memory."); + MmHeapFree(Volume->MasterFileTable); + MmHeapFree(Volume); + return NULL; + } + // // Keep device id // -- 2.17.1