diff --git a/reactos/drivers/fs/ntfs/attrib.c b/reactos/drivers/fs/ntfs/attrib.c index 69c8fe0b0e0..0f3f657548c 100644 --- a/reactos/drivers/fs/ntfs/attrib.c +++ b/reactos/drivers/fs/ntfs/attrib.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: attrib.c,v 1.9 2004/01/28 20:53:06 ekohl Exp $ +/* $Id: attrib.c,v 1.10 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -279,7 +279,8 @@ NtfsDumpFileAttributes (PFILE_RECORD_HEADER FileRecord) PATTRIBUTE Attribute; Attribute = (PATTRIBUTE)((ULONG_PTR)FileRecord + FileRecord->AttributeOffset); - while (Attribute->AttributeType !=-1) + while (Attribute < (PATTRIBUTE)((ULONG_PTR)FileRecord + FileRecord->BytesInUse) && + Attribute->AttributeType != -1) { NtfsDumpAttribute (Attribute); diff --git a/reactos/drivers/fs/ntfs/close.c b/reactos/drivers/fs/ntfs/close.c index 9c95e94af1a..f01c3c46452 100755 --- a/reactos/drivers/fs/ntfs/close.c +++ b/reactos/drivers/fs/ntfs/close.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: close.c,v 1.1 2003/07/17 13:31:39 chorns Exp $ +/* $Id: close.c,v 1.2 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -30,7 +30,7 @@ #include -//#define NDEBUG +#define NDEBUG #include #include "ntfs.h" diff --git a/reactos/drivers/fs/ntfs/create.c b/reactos/drivers/fs/ntfs/create.c index 2c90949cb24..979f2582c3e 100644 --- a/reactos/drivers/fs/ntfs/create.c +++ b/reactos/drivers/fs/ntfs/create.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: create.c,v 1.3 2003/11/13 15:26:34 ekohl Exp $ +/* $Id: create.c,v 1.4 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -29,7 +29,7 @@ #include -//#define NDEBUG +#define NDEBUG #include #include "ntfs.h" diff --git a/reactos/drivers/fs/ntfs/dirctl.c b/reactos/drivers/fs/ntfs/dirctl.c index 5f6ab07dda7..1afc0e05afd 100644 --- a/reactos/drivers/fs/ntfs/dirctl.c +++ b/reactos/drivers/fs/ntfs/dirctl.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: dirctl.c,v 1.7 2003/11/13 15:26:34 ekohl Exp $ +/* $Id: dirctl.c,v 1.8 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -29,7 +29,7 @@ #include -//#define NDEBUG +#define NDEBUG #include #include "ntfs.h" diff --git a/reactos/drivers/fs/ntfs/fcb.c b/reactos/drivers/fs/ntfs/fcb.c index c38a7f98444..b4a7bff55b7 100644 --- a/reactos/drivers/fs/ntfs/fcb.c +++ b/reactos/drivers/fs/ntfs/fcb.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: fcb.c,v 1.10 2004/01/28 20:53:06 ekohl Exp $ +/* $Id: fcb.c,v 1.11 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -32,7 +32,7 @@ #include "ntfs.h" -//#define NDEBUG +#define NDEBUG #include diff --git a/reactos/drivers/fs/ntfs/finfo.c b/reactos/drivers/fs/ntfs/finfo.c index 201cc950951..ca5d1b92ad9 100644 --- a/reactos/drivers/fs/ntfs/finfo.c +++ b/reactos/drivers/fs/ntfs/finfo.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: finfo.c,v 1.2 2003/07/17 13:31:39 chorns Exp $ +/* $Id: finfo.c,v 1.3 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -29,7 +29,7 @@ #include -//#define NDEBUG +#define NDEBUG #include #include "ntfs.h" diff --git a/reactos/drivers/fs/ntfs/fsctl.c b/reactos/drivers/fs/ntfs/fsctl.c index 737fda90c4f..df09b4007e0 100644 --- a/reactos/drivers/fs/ntfs/fsctl.c +++ b/reactos/drivers/fs/ntfs/fsctl.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: fsctl.c,v 1.9 2003/11/12 15:30:21 ekohl Exp $ +/* $Id: fsctl.c,v 1.10 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -31,7 +31,7 @@ #include #include -#define NDEBUG +//#define NDEBUG #include #include "ntfs.h" @@ -122,7 +122,7 @@ NtfsHasFileSystem(PDEVICE_OBJECT DeviceToMount) static NTSTATUS NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, - PNTFS_INFO NtfsInfo) + PDEVICE_EXTENSION DeviceExt) { DISK_GEOMETRY DiskGeometry; PFILE_RECORD_HEADER MftRecord; @@ -130,9 +130,9 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, PVOLINFO_ATTRIBUTE VolumeInfo; PBOOT_SECTOR BootSector; PATTRIBUTE Attribute; - ULONG FileRecordSize; ULONG Size; NTSTATUS Status; + PNTFS_INFO NtfsInfo = &DeviceExt->NtfsInfo; DPRINT("NtfsGetVolumeData() called\n"); @@ -179,7 +179,10 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, NtfsInfo->MftStart.QuadPart = BootSector->MftLocation; NtfsInfo->MftMirrStart.QuadPart = BootSector->MftMirrLocation; NtfsInfo->SerialNumber = BootSector->SerialNumber; - NtfsInfo->ClustersPerFileRecord = BootSector->ClustersPerMftRecord; + if (BootSector->ClustersPerMftRecord > 0) + NtfsInfo->BytesPerFileRecord = BootSector->ClustersPerMftRecord * NtfsInfo->BytesPerCluster; + else + NtfsInfo->BytesPerFileRecord = 1 << (-BootSector->ClustersPerMftRecord); //#ifndef NDEBUG DbgPrint("Boot sector information:\n"); @@ -199,13 +202,8 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, ExFreePool(BootSector); - if (NtfsInfo->ClustersPerFileRecord == 0xF6) - FileRecordSize = NtfsInfo->ClustersPerFileRecord * NtfsInfo->BytesPerCluster; - else - FileRecordSize = NtfsInfo->BytesPerCluster; - MftRecord = ExAllocatePool(NonPagedPool, - FileRecordSize); + NtfsInfo->BytesPerFileRecord); if (MftRecord == NULL) { return STATUS_INSUFFICIENT_RESOURCES; @@ -213,7 +211,7 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, Status = NtfsReadSectors(DeviceObject, NtfsInfo->MftStart.u.LowPart * NtfsInfo->SectorsPerCluster, - FileRecordSize / NtfsInfo->BytesPerSector, + NtfsInfo->BytesPerFileRecord / NtfsInfo->BytesPerSector, NtfsInfo->BytesPerSector, (PVOID)MftRecord, TRUE); @@ -223,32 +221,20 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, return Status; } - if (NtfsInfo->ClustersPerFileRecord == 0xF6) + VolumeRecord = ExAllocatePool(NonPagedPool, NtfsInfo->BytesPerFileRecord); + if (VolumeRecord == NULL) { - VolumeRecord = (PVOID)((ULONG_PTR)MftRecord + 3 * (NtfsInfo->BytesPerCluster / 4)); + ExFreePool (MftRecord); + return STATUS_INSUFFICIENT_RESOURCES; } - else - { - VolumeRecord = ExAllocatePool(NonPagedPool, - FileRecordSize); - if (VolumeRecord == NULL) - { - ExFreePool (MftRecord); - return STATUS_INSUFFICIENT_RESOURCES; - } - /* Read cluster MftStart + 3 (Volume File) */ - Status = NtfsReadSectors(DeviceObject, - (NtfsInfo->MftStart.u.LowPart + 3) * NtfsInfo->SectorsPerCluster, - FileRecordSize / NtfsInfo->BytesPerSector, - NtfsInfo->BytesPerSector, - (PVOID)VolumeRecord, - TRUE); - if (!NT_SUCCESS(Status)) - { - ExFreePool (MftRecord); - return Status; - } + /* Read Volume File (MFT index 3) */ + DeviceExt->StorageDevice = DeviceObject; + Status = ReadFileRecord(DeviceExt, 3, VolumeRecord, MftRecord); + if (!NT_SUCCESS(Status)) + { + ExFreePool (MftRecord); + return Status; } #ifndef NDEBUG @@ -266,10 +252,10 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, /* Get volume name */ Attribute = FindAttribute (VolumeRecord, AttributeVolumeName, NULL); DPRINT("Attribute %p\n", Attribute); - DPRINT("Data length %lu\n", AttributeDataLength (Attribute)); if (Attribute != NULL && ((PRESIDENT_ATTRIBUTE)Attribute)->ValueLength != 0) { + DPRINT("Data length %lu\n", AttributeDataLength (Attribute)); NtfsInfo->VolumeLabelLength = min (((PRESIDENT_ATTRIBUTE)Attribute)->ValueLength, MAXIMUM_VOLUME_LABEL_LENGTH); RtlCopyMemory (NtfsInfo->VolumeLabel, @@ -284,10 +270,10 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, /* Get volume information */ Attribute = FindAttribute (VolumeRecord, AttributeVolumeInformation, NULL); DPRINT("Attribute %p\n", Attribute); - DPRINT("Data length %lu\n", AttributeDataLength (Attribute)); if (Attribute != NULL && ((PRESIDENT_ATTRIBUTE)Attribute)->ValueLength != 0) { + DPRINT("Data length %lu\n", AttributeDataLength (Attribute)); VolumeInfo = (PVOID)((ULONG_PTR)Attribute + ((PRESIDENT_ATTRIBUTE)Attribute)->ValueOffset); NtfsInfo->MajorVersion = VolumeInfo->MajorVersion; @@ -295,10 +281,6 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, NtfsInfo->Flags = VolumeInfo->Flags; } - if (NtfsInfo->ClustersPerFileRecord != 0xF6) - { - ExFreePool (VolumeRecord); - } ExFreePool (MftRecord); return Status; @@ -353,7 +335,7 @@ NtfsMountVolume(PDEVICE_OBJECT DeviceObject, sizeof(DEVICE_EXTENSION)); Status = NtfsGetVolumeData(DeviceToMount, - &DeviceExt->NtfsInfo); + DeviceExt); if (!NT_SUCCESS(Status)) goto ByeBye; diff --git a/reactos/drivers/fs/ntfs/mft.c b/reactos/drivers/fs/ntfs/mft.c index 60f5cd6851e..5cd19e28a4f 100644 --- a/reactos/drivers/fs/ntfs/mft.c +++ b/reactos/drivers/fs/ntfs/mft.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: mft.c,v 1.4 2003/11/13 15:26:34 ekohl Exp $ +/* $Id: mft.c,v 1.5 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -31,7 +31,7 @@ #include #include -//#define NDEBUG +#define NDEBUG #include #include "ntfs.h" @@ -60,8 +60,7 @@ NtfsOpenMft (PDEVICE_EXTENSION Vcb) DPRINT1("NtfsOpenMft() called\n"); - BytesPerFileRecord = - Vcb->NtfsInfo.ClustersPerFileRecord * Vcb->NtfsInfo.BytesPerCluster; + BytesPerFileRecord = Vcb->NtfsInfo.BytesPerFileRecord; MftRecord = ExAllocatePool(NonPagedPool, BytesPerFileRecord); @@ -129,7 +128,8 @@ FindAttribute (PFILE_RECORD_HEADER FileRecord, PATTRIBUTE Attribute; Attribute = (PATTRIBUTE)((ULONG_PTR)FileRecord + FileRecord->AttributeOffset); - while (Attribute->AttributeType != -1) + while (Attribute < (PATTRIBUTE)((ULONG_PTR)FileRecord + FileRecord->BytesInUse) && + Attribute->AttributeType != -1) { if (Attribute->AttributeType == Type) { @@ -189,18 +189,17 @@ ReadAttribute (PATTRIBUTE attr, -VOID +NTSTATUS ReadFileRecord (PDEVICE_EXTENSION Vcb, ULONG index, PFILE_RECORD_HEADER file, PFILE_RECORD_HEADER Mft) { PVOID p; - ULONG clusters = Vcb->NtfsInfo.ClustersPerFileRecord; - ULONG BytesPerFileRecord = clusters * Vcb->NtfsInfo.BytesPerCluster; + ULONG BytesPerFileRecord = Vcb->NtfsInfo.BytesPerFileRecord; + ULONG clusters = max(BytesPerFileRecord / Vcb->NtfsInfo.BytesPerCluster, 1); - - p = ExAllocatePool(NonPagedPool, BytesPerFileRecord); + p = ExAllocatePool(NonPagedPool, clusters * Vcb->NtfsInfo.BytesPerCluster); ULONGLONG vcn = index * BytesPerFileRecord / Vcb->NtfsInfo.BytesPerCluster; @@ -215,6 +214,8 @@ ReadFileRecord (PDEVICE_EXTENSION Vcb, ExFreePool(p); FixupUpdateSequenceArray(file); + + return STATUS_SUCCESS; } diff --git a/reactos/drivers/fs/ntfs/ntfs.c b/reactos/drivers/fs/ntfs/ntfs.c index dea8bec382a..1f25cdb0d9b 100644 --- a/reactos/drivers/fs/ntfs/ntfs.c +++ b/reactos/drivers/fs/ntfs/ntfs.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: ntfs.c,v 1.5 2004/02/10 16:22:56 navaraf Exp $ +/* $Id: ntfs.c,v 1.6 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -30,7 +30,7 @@ #include #include -//#define NDEBUG +#define NDEBUG #include #include "ntfs.h" diff --git a/reactos/drivers/fs/ntfs/ntfs.h b/reactos/drivers/fs/ntfs/ntfs.h index d184a0beed2..35121155a26 100644 --- a/reactos/drivers/fs/ntfs/ntfs.h +++ b/reactos/drivers/fs/ntfs/ntfs.h @@ -29,8 +29,10 @@ typedef struct _BOOT_SECTOR ULONGLONG SectorCount; ULONGLONG MftLocation; ULONGLONG MftMirrLocation; - ULONG ClustersPerMftRecord; - ULONG ClustersPerIndexRecord; + CHAR ClustersPerMftRecord; + BYTE Unused3[3]; + CHAR ClustersPerIndexRecord; + BYTE Unused4[3]; ULONGLONG SerialNumber; // 0x48 UCHAR BootCode[432]; // 0x50 } __attribute__((packed)) BOOT_SECTOR, *PBOOT_SECTOR; @@ -49,7 +51,7 @@ typedef struct _NTFS_INFO ULONGLONG SectorCount; ULARGE_INTEGER MftStart; ULARGE_INTEGER MftMirrStart; - ULONG ClustersPerFileRecord; + ULONG BytesPerFileRecord; ULONGLONG SerialNumber; USHORT VolumeLabelLength; @@ -423,7 +425,7 @@ ReadAttribute(PATTRIBUTE attr, PVOID buffer, PDEVICE_EXTENSION Vcb, ULONG AttributeDataLength(PATTRIBUTE attr); -VOID +NTSTATUS ReadFileRecord (PDEVICE_EXTENSION Vcb, ULONG index, PFILE_RECORD_HEADER file, diff --git a/reactos/drivers/fs/ntfs/rw.c b/reactos/drivers/fs/ntfs/rw.c index eeeeaf069b8..0f2e757795d 100755 --- a/reactos/drivers/fs/ntfs/rw.c +++ b/reactos/drivers/fs/ntfs/rw.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: rw.c,v 1.2 2003/11/13 15:26:34 ekohl Exp $ +/* $Id: rw.c,v 1.3 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -31,7 +31,7 @@ #include #include -//#define NDEBUG +#define NDEBUG #include #include "ntfs.h" diff --git a/reactos/drivers/fs/ntfs/volinfo.c b/reactos/drivers/fs/ntfs/volinfo.c index bcc8d44f667..155a176ab8e 100644 --- a/reactos/drivers/fs/ntfs/volinfo.c +++ b/reactos/drivers/fs/ntfs/volinfo.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: volinfo.c,v 1.3 2003/11/12 15:30:21 ekohl Exp $ +/* $Id: volinfo.c,v 1.4 2004/06/05 08:28:37 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -29,7 +29,7 @@ #include -//#define NDEBUG +#define NDEBUG #include #include "ntfs.h"