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

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