NTFS Driver work (index headers)
[tpg/acess2.git] / Modules / Filesystems / NTFS / common.h
1 /*
2  * Acess2 - NTFS Driver
3  * By John Hodge (thePowersGang)
4  * This file is published under the terms of the Acess licence. See the
5  * file COPYING for details.
6  *
7  * common.h - Common Types and Definitions
8  */
9 #ifndef _COMMON_H_
10 #define _COMMON_H_
11
12 #include <acess.h>
13 #include <vfs.h>
14
15 typedef Uint16  WCHAR;
16
17 // === STRUCTURES ===
18 /**
19  * In-memory representation of an NTFS Disk
20  */
21 typedef struct sNTFS_Disk
22 {
23          int    FD;
24          int    CacheHandle;
25          
26          int    ClusterSize;
27         Uint64  MFTBase;
28         Uint32  MFTRecSize;
29         
30         tVFS_Node       RootNode;
31 }       tNTFS_Disk;
32
33 typedef struct sNTFS_BootSector
34 {
35         // 0
36         Uint8   Jump[3];
37         Uint8   SystemID[8];    // = "NTFS    "
38         Uint16  BytesPerSector;
39         Uint8   SectorsPerCluster;
40         
41         // 0xE
42         Uint8   Unused[7];
43         Uint8   MediaDescriptor;
44         Uint16  Unused2;
45         Uint16  SectorsPerTrack;
46         Uint16  Heads;
47         
48         // 0x1C
49         Uint64  Unused3;
50         Uint32  Unkown; // Usually 0x00800080 (according to Linux docs)
51         
52         // 0x28
53         Uint64  TotalSectorCount;       // Size of volume in sectors
54         Uint64  MFTStart;       // Logical Cluster Number of Cluster 0 of MFT
55         Uint64  MFTMirrorStart; // Logical Cluster Number of Cluster 0 of MFT Backup
56         
57         // 0x40
58         // If either of these are -ve, the size can be obtained via
59         // SizeInBytes = 2^(-1 * Value)
60         Sint8   ClustersPerMFTRecord;
61         Uint8   Unused4[3];
62         Sint8   ClustersPerIndexRecord;
63         Uint8   Unused5[3];
64         
65         Uint64  SerialNumber;
66         
67         Uint8   Padding[512-0x50];
68         
69 } PACKED        tNTFS_BootSector;
70
71 /**
72  * FILE header, an entry in the MFT
73  */
74 typedef struct sNTFS_FILE_Header
75 {
76         Uint32  Magic;  // 'FILE'
77         Uint16  UpdateSequenceOfs;
78         Uint16  UpdateSequenceSize;     // Size in words of the UpdateSequenceArray
79         
80         Uint64  LSN;    // $LogFile Sequence Number
81         
82         Uint16  SequenceNumber;
83         Uint16  HardLinkCount;  
84         Uint16  FirstAttribOfs; // Size of header?
85         Uint16  Flags;  // 0: In Use, 1: Directory
86         
87         Uint32  RecordSize;             // Real Size of FILE Record
88         Uint32  RecordSpace;    // Allocated Size for FILE Record
89         
90         /**
91          * Base address of the MFT containing this record
92          */
93         Uint64  Reference;      // "File reference to the base FILE record" ???
94         
95         Uint16  NextAttribID;
96         union
97         {
98                 // Only in XP
99                 struct {
100                         Uint16  AlignTo4Byte;
101                         Uint16  RecordNumber;   // Number of this MFT Record
102                         Uint16  UpdateSequenceNumber;
103                         Uint16  UpdateSequenceArray[];
104                 }       XP;
105                 struct {
106                         Uint16  UpdateSequenceNumber;
107                         Uint16  UpdateSequenceArray[];
108                 }       All;
109         } OSDep;        
110         
111 } PACKED        tNTFS_FILE_Header;
112
113 /**
114  * File Attribute, follows the FILE header
115  */
116 typedef struct sNTFS_FILE_Attrib
117 {
118         Uint32  Type;   // See eNTFS_FILE_Attribs
119         Uint32  Size;   // Includes header
120         
121         Uint8   ResidentFlag;   // (What does this mean?)
122         Uint8   NameLength;
123         Uint16  NameOffset;
124         Uint16  Flags;  // 0: Compressed, 14: Encrypted, 15: Sparse
125         Uint16  AttributeID;
126         
127         union
128         {
129                 struct {
130                         Uint32  AttribLen;      // In words
131                         Uint16  AttribOfs;
132                         Uint8   IndexedFlag;
133                         Uint8   Padding;
134                         
135                         Uint16  Name[]; // UTF-16
136                         // Attribute Data
137                 }       Resident;
138                 struct {
139                         Uint64  StartingVCN;
140                         Uint64  LastVCN;
141                         Uint16  DataRunOfs;
142                         Uint16  CompressionUnitSize;
143                         Uint32  Padding;
144                         Uint64  AllocatedSize;
145                         Uint64  RealSize;
146                         Uint64  InitiatedSize;  // One assumes, ammount of actual data stored
147                         Uint16  Name[]; // UTF-16
148                         // Data Runs
149                 }       NonResident;
150         };
151 } PACKED        tNTFS_FILE_Attrib;
152
153 #endif

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