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

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