:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / fs / ntfs / mft.c
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 2002 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /* $Id$
20  *
21  * COPYRIGHT:        See COPYING in the top level directory
22  * PROJECT:          ReactOS kernel
23  * FILE:             services/fs/ntfs/mft.c
24  * PURPOSE:          NTFS filesystem driver
25  * PROGRAMMER:       Eric Kohl
26  */
27
28 /* INCLUDES *****************************************************************/
29
30 #include <ddk/ntddk.h>
31
32 //#define NDEBUG
33 #include <debug.h>
34
35 #include "ntfs.h"
36
37
38 /* FUNCTIONS ****************************************************************/
39
40
41 NTSTATUS
42 NtfsOpenMft(PDEVICE_OBJECT DeviceObject,
43             PDEVICE_EXTENSION Vcb)
44 {
45   PVOID Buffer;
46   PFILE_RECORD_HEADER RecordHeader;
47   PATTRIBUTE Attribute;
48   NTSTATUS Status;
49
50   DPRINT1("NtfsOpenMft() called\n");
51
52   Buffer = ExAllocatePool(NonPagedPool,
53                           Vcb->NtfsInfo.BytesPerCluster);
54   if (Buffer == NULL)
55     {
56       return(STATUS_INSUFFICIENT_RESOURCES);
57     }
58
59
60   /* read first MFT cluster */
61   Status = NtfsReadRawSectors(DeviceObject,
62                               Vcb->NtfsInfo.MftStart.u.LowPart * Vcb->NtfsInfo.SectorsPerCluster,
63                               Vcb->NtfsInfo.SectorsPerCluster,
64                               Vcb->NtfsInfo.BytesPerSector,
65                               (PVOID)Buffer);
66   if (NT_SUCCESS(Status))
67     {
68       /* Enumerate MFT records */
69       RecordHeader = Buffer;
70       while (((ULONG)RecordHeader - (ULONG)Buffer) < Vcb->NtfsInfo.BytesPerCluster)
71         {
72           DbgPrint("\n");
73 //        DbgPrint("Magic: %.04s\n", (PCHAR)&RecordHeader->Ntfs.Type);
74 //        DbgPrint("Real size: %lx\n", RecordHeader->RealSize);
75 //        DbgPrint("AllocSize: %lx\n", RecordHeader->AllocSize);
76
77           /* Enumerate attributes */
78           Attribute = (PATTRIBUTE)((ULONG)RecordHeader + 
79                                    RecordHeader->Ntfs.UsnOffset +
80                                    RecordHeader->Ntfs.UsnSize * sizeof(USHORT));
81           while (Attribute->AttributeType != 0xFFFFFFFF)
82             {
83               NtfsDumpAttribute(Attribute);
84
85               Attribute = (PATTRIBUTE)((ULONG)Attribute + Attribute->Length);
86             }
87
88
89           RecordHeader = (PFILE_RECORD_HEADER)((ULONG)RecordHeader + RecordHeader->BytesAllocated);
90         }
91
92     }
93
94   ExFreePool(Buffer);
95
96   return(Status);
97 }
98
99
100 /* EOF */