Modules/NTFS - Implimentation progressing (ReadDir/FindDir appear to work)
[tpg/acess2.git] / KernelLand / Modules / Filesystems / NTFS / ntfs.h
1 /*
2  * Acess2 NTFS Driver
3  * - By John Hodge (thePowersGang)
4  *
5  * ntfs.h
6  * - NTFS on-disk structures
7  */
8 #ifndef _NTFS__NTFS_H_
9 #define _NTFS__NTFS_H_
10
11 typedef struct sNTFS_BootSector tNTFS_BootSector;
12
13 struct sNTFS_BootSector
14 {
15         // 0
16         Uint8   Jump[3];
17         Uint8   SystemID[8];    // = "NTFS    "
18         Uint16  BytesPerSector;
19         Uint8   SectorsPerCluster;
20         
21         // 0xE
22         Uint8   _unused[7];
23         Uint8   MediaDescriptor;
24         Uint16  _unused2;
25         Uint16  SectorsPerTrack;
26         Uint16  Heads;
27         
28         // 0x1C
29         Uint64  _unused3;
30         Uint32  _unknown;       // Usually 0x00800080 (according to Linux docs)
31         
32         // 0x28
33         Uint64  TotalSectorCount;       // Size of volume in sectors
34         Uint64  MFTStart;       // Logical Cluster Number of Cluster 0 of MFT
35         Uint64  MFTMirrorStart; // Logical Cluster Number of Cluster 0 of MFT Backup
36         
37         // 0x40
38         // If either of these are -ve, the size can be obtained via
39         // SizeInBytes = 2^(-1 * Value)
40         Sint8   ClustersPerMFTRecord;
41         Uint8   _unused4[3];
42         Sint8   ClustersPerIndexRecord;
43         Uint8   _unused5[3];
44         
45         Uint64  SerialNumber;
46         
47         Uint8   Padding[512-0x50];
48         
49 } PACKED;
50
51 /**
52  * FILE header, an entry in the MFT
53  */
54 typedef struct sNTFS_FILE_Header
55 {
56         Uint32  Magic;  // 'FILE'
57         Uint16  UpdateSequenceOfs;
58         Uint16  UpdateSequenceSize;     // Size in words of the UpdateSequenceArray
59         
60         Uint64  LSN;    // $LogFile Sequence Number
61         
62         Uint16  SequenceNumber;
63         Uint16  HardLinkCount;  
64         Uint16  FirstAttribOfs; // Size of header?
65         Uint16  Flags;  // 0: In Use, 1: Directory
66         
67         Uint32  RecordSize;             // Real Size of FILE Record
68         Uint32  RecordSpace;    // Allocated Size for FILE Record
69         
70         /**
71          * Base address of the MFT containing this record
72          */
73         Uint64  Reference;      // "File reference to the base FILE record" ???
74         
75         Uint16  NextAttribID;
76         union
77         {
78                 // Only in XP
79                 struct {
80                         Uint16  AlignTo4Byte;
81                         Uint16  RecordNumber;   // Number of this MFT Record
82                         Uint16  UpdateSequenceNumber;
83                         Uint16  UpdateSequenceArray[];
84                 }       XP;
85                 struct {
86                         Uint16  UpdateSequenceNumber;
87                         Uint16  UpdateSequenceArray[];
88                 }       All;
89         } OSDep;        
90         
91 } PACKED        tNTFS_FILE_Header;
92
93 /**
94  * File Attribute, follows the FILE header
95  */
96 typedef struct sNTFS_FILE_Attrib
97 {
98         Uint32  Type;   // See eNTFS_FILE_Attribs
99         Uint32  Size;   // Includes header
100         
101         Uint8   NonresidentFlag;
102         Uint8   NameLength;
103         Uint16  NameOffset;
104         Uint16  Flags;  // 0: Compressed, 14: Encrypted, 15: Sparse
105         Uint16  AttributeID;
106         
107         union
108         {
109                 struct {
110                         Uint32  AttribLen;      // In words
111                         Uint16  AttribOfs;
112                         Uint8   IndexedFlag;
113                         Uint8   Padding;
114                         
115                         Uint16  Name[]; // UTF-16
116                         // Attribute Data
117                 }       Resident;
118                 struct {
119                         Uint64  StartingVCN;    // VCN of first data run
120                         Uint64  LastVCN;        // Last VCN in data runs
121                         Uint16  DataRunOfs;
122                         Uint16  CompressionUnitSize;
123                         Uint32  Padding;
124                         Uint64  AllocatedSize;  // Allocated clusters in bytes
125                         Uint64  RealSize;
126                         Uint64  InitiatedSize;  // One assumes, ammount of actual data stored
127                         Uint16  Name[]; // UTF-16
128                         // Data Runs
129                 }       NonResident;
130         };
131 } PACKED        tNTFS_FILE_Attrib;
132
133 #include "attributes.h"
134
135 typedef struct sNTFS_IndexHeader        tNTFS_IndexHeader;
136 typedef struct sNTFS_IndexEntry_Filename        tNTFS_IndexEntry_Filename;
137
138 struct sNTFS_IndexHeader
139 {
140         Uint32  Magic;  // = 'INDX' LE
141         Uint16  UpdateSequenceOfs;
142         Uint16  UpdateSequenceSize;     // incl number
143         Uint64  LogFileSequenceNum;
144         Uint64  ThisVCN;
145         Uint32  EntriesOffset;  // add 0x18
146         Uint32  EntriesSize;    // (maybe) add 0x18
147         Uint32  EntriesAllocSize;
148         Uint8   Flags;  // [0]: Not leaf node
149         Uint8   _pad[3];
150         Uint16  UpdateSequence;
151         Uint16  UpdateSequenceArray[];
152 } PACKED;
153
154 struct sNTFS_IndexEntry_Filename
155 {
156         Uint64  MFTReference;
157         Uint16  EntrySize;
158         Uint16  FilenameOfs;
159         Uint16  IndexFlags;     // [0]: Points to sub-node, [1]: Last entry in node
160         Uint16  _rsvd;
161
162         #if 1
163         struct sNTFS_Attrib_Filename    Filename;
164         #else
165         Uint64  ParentMFTReference;
166         Uint64  CreationTime;
167         Uint64  ModifcationTime;
168         Uint64  MFTModTime;
169         Uint64  AccessTime;
170         Uint64  AllocSize;
171         Uint64  RealSize;
172         Uint64  FileFlags;
173         
174         Uint8   FilenameLen;
175         Uint8   FilenameNamespace;
176         #endif
177         // Filename
178 };
179
180 #endif
181

UCC git Repository :: git.ucc.asn.au