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

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