mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
- Fixed calculation of MFT record size.
- Fixed attribute finding/dumping bounds checking. - Fixed reading of volume information MFT record. - Disabled debug messages. svn path=/trunk/; revision=9615
This commit is contained in:
parent
70dfb7876f
commit
39ff6d3136
12 changed files with 60 additions and 74 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 <ddk/ntddk.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#include "ntfs.h"
|
||||
|
|
|
@ -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 <ddk/ntddk.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#include "ntfs.h"
|
||||
|
|
|
@ -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 <ddk/ntddk.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#include "ntfs.h"
|
||||
|
|
|
@ -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 <debug.h>
|
||||
|
||||
|
||||
|
|
|
@ -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 <ddk/ntddk.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#include "ntfs.h"
|
||||
|
|
|
@ -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 <ddk/ntddk.h>
|
||||
#include <ntos/minmax.h>
|
||||
|
||||
#define NDEBUG
|
||||
//#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#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;
|
||||
|
||||
|
|
|
@ -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 <ddk/ntddk.h>
|
||||
#include <ntos/minmax.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 <ddk/ntddk.h>
|
||||
#include <rosrtl/string.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#include "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,
|
||||
|
|
|
@ -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 <ddk/ntddk.h>
|
||||
#include <ntos/minmax.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#include "ntfs.h"
|
||||
|
|
|
@ -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 <ddk/ntddk.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#include "ntfs.h"
|
||||
|
|
Loading…
Reference in a new issue