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

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