Trying to fix the string corruption bug, working on NTFS driver
[tpg/acess2.git] / Modules / Filesystems / NTFS / common.h
1 /*
2  */
3 #ifndef _COMMON_H_
4 #define _COMMON_H_
5
6 // === STRUCTURES ===
7 /**
8  * In-memory representation of an NTFS Disk
9  */
10 typedef struct sNTFS_Disk
11 {
12          int    FD;
13         Uint64  MFTOfs;
14         tVFS_Node       RootNode;
15 }       tNTFS_Disk;
16
17 typedef struct sNTFS_BootSector
18 {
19         // 0
20         Uint8   Jump[3];
21         Uint8   SystemID[8];    // = "NTFS    "
22         Uint16  BytesPerSector;
23         Uint8   SectorsPerCluster;
24         
25         // 14
26         Uint8   Unused[7];
27         Uint8   MediaDescriptor;
28         Uint16  Unused2;
29         Uint16  SectorsPerTrack;
30         
31         Uint64  Unused3;
32         Uint32  Unknown;
33         
34         // 38
35         Uint64  TotalSectorCount;       // Size of volume in sectors
36         Uint64  MFTStart;       // Logical Cluster Number of Cluster 0 of MFT
37         Uint64  MFTMirrorStart; // Logical Cluster Number of Cluster 0 of MFT Backup
38         
39         // 60
40         // If either of these are -ve, the size can be obtained via
41         // SizeInBytes = 2^(-1 * Value)
42         Uint32  ClustersPerMFTRecord;
43         Uint32  ClustersPerIndexRecord;
44         
45         Uint64  SerialNumber;
46         
47         Uint8   Padding[515-offsetof(tNTFS_BootSector, Padding)];
48         
49 }       tNTFS_BootSector;
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 }       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   ResidentFlag;   // (What does this mean?)
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;
120                         Uint64  LastVCN;
121                         Uint16  DataRunOfs;
122                         Uint16  CompressionUnitSize;
123                         Uint32  Padding;
124                         Uint64  AllocatedSize;
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 }       tNTFS_FILE_Attrib;
132
133 #endif

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