1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3 // All rights reserved
4 // This file was released under the GPLv2 on June 2015.
5 ////////////////////////////////////////////////////////////////////
6 
7 #ifndef _OSTA_MISC_H_
8 #define _OSTA_MISC_H_
9 
10 /* based on ECMA 167 structure definitions */
11 #include "ecma_167.h"
12 
13 #pragma pack(push, 1)
14 
15 /* -------- Basic types and constants ----------- */
16 /* UDF character set (UDF 1.50 2.1.2) */
17 #define UDF_CHAR_SET_TYPE   0
18 #define UDF_CHAR_SET_INFO   "OSTA Compressed Unicode"
19 
20 #define UDF_ID_DEVELOPER    ("*WINNT " VER_STR_PRODUCT_NAME " UDF")
21 
22 #define UDF_ID_DEVELOPER_ADAPTEC  "*Adaptec DirectCD"
23 
24 /* UDF 1.02 2.2.6.4 */
25 struct LogicalVolIntegrityDescImpUse
26 {
27     EntityID    impIdent;
28     uint32      numFiles;
29     uint32      numDirs;
30     uint16      minUDFReadRev;
31     uint16      minUDFWriteRev;
32     uint16      maxUDFWriteRev;
33 };
34 
35 /* UDF 1.02 2.2.7.2 */
36 /* LVInformation may be present in ImpUseVolDesc.impUse */
37 struct ImpUseVolDescImpUse
38 {
39     charspec    LVICharset;
40     dstring     logicalVolIdent[128];
41     dstring     LVInfo1[36];
42     dstring     LVInfo2[36];
43     dstring     LVInfo3[36];
44     EntityID    impIdent;
45     uint8       impUse[128];
46 };
47 
48 struct UdfPartitionMap2
49 {
50         uint8           partitionMapType;
51         uint8           partitionMapLength;
52         uint8           reserved1[2];
53         EntityID        partIdent;
54         uint16          volSeqNum;
55         uint16          partitionNum;
56         uint8           reserved2[24];
57 };
58 
59 /* UDF 1.5 2.2.8 */
60 struct VirtualPartitionMap
61 {
62     uint8       partitionMapType;   /* 2 */
63     uint8       partitionMapLength; /* 64 */
64     uint8       reserved1[2];       /* #00 */
65     EntityID    partIdent;
66     uint16      volSeqNum;
67     uint16      partitionNum;
68     uint8       reserved2[24];      /* #00 */
69 };
70 
71 #define UDF_VAT_FREE_ENTRY      0xffffffff
72 
73 /* UDF 1.5 2.2.9 */
74 typedef struct _SPARABLE_PARTITION_MAP
75 {
76     uint8       partitionMapType;   /* 2 */
77     uint8       partitionMapLength; /* 64 */
78     uint8       reserved1[2];       /* #00 */
79     EntityID    partIdent;      /* Flags = 0 */
80                         /* Id = UDF_ID_SPARABLE */
81                         /* IdSuf = 2.1.5.3 */
82     uint16      volSeqNum;
83     uint16      partitionNum;
84     uint16      packetLength;       /* 32 */
85     uint8       numSparingTables;
86     uint8       reserved2[1];       /* #00 */
87     uint32      sizeSparingTable;
88 //  uint32      locSparingTable[0];
89 //  uint8       pad[0];
90 } SPARABLE_PARTITION_MAP, *PSPARABLE_PARTITION_MAP;
91 
92 #define UDF_TYPE1_MAP15         0x1511U
93 #define UDF_VIRTUAL_MAP15       0x1512U
94 #define UDF_VIRTUAL_MAP20       0x2012U
95 #define UDF_SPARABLE_MAP15      0x1522U
96 #define UDF_METADATA_MAP25      0x2522U
97 
98 #ifndef PACKETSIZE_UDF
99 #define PACKETSIZE_UDF              32
100 #endif //PACKETSIZE_UDF
101 
102 /* UDF 2.5 */
103 typedef struct _METADATA_PARTITION_MAP
104 {
105     uint8       partitionMapType;   /* 2 */
106     uint8       partitionMapLength; /* 64 */
107     uint8       reserved1[2];       /* #00 */
108     EntityID    partIdent;      /* Flags = 0 */
109                         /* Id = UDF_ID_METADATA */
110                         /* IdSuf = 2.1.5.3 */
111     uint16      volSeqNum;
112     uint16      partitionNum;
113     uint32      metadataFELocation;
114     uint32      metadataMirrorFELocation;
115     uint32      metadataBitmapFELocation;
116     uint32      allocationUnit; /* blocks */
117     uint16      alignmentUnit; /* blocks */
118     uint8       flags;
119     uint8       pad[5];
120 } METADATA_PARTITION_MAP, *PMETADATA_PARTITION_MAP;
121 
122 #define UDF_METADATA_DUPLICATED 0x01U
123 
124 /* DVD Copyright Management Info, see UDF 1.02 3.3.4.5.1.2 */
125 /* when ImpUseExtendedAttr.impIdent= "*UDF DVD CGMS Info" */
126 struct DVDCopyrightImpUse {
127     uint16 headerChecksum;
128     uint8  CGMSInfo;
129     uint8  dataType;
130     uint8  protectionSystemInfo[4];
131 };
132 
133 /* the impUse of long_ad used in AllocDescs  - UDF 1.02 2.3.10.1 */
134 struct ADImpUse
135 {
136     uint16 flags;
137     uint8  impUse[4];
138 };
139 
140 /* the impUse of long_ad used in AllocDescs  - UDF 1.02 2.3.10.1 */
141 struct FidADImpUse
142 {
143     uint8  reserved[2];
144     uint32 uniqueID;
145 };
146 
147 /* UDF 1.02 2.3.10.1 */
148 #define UDF_EXTENT_LENGTH_MASK      0x3FFFFFFF
149 #define UDF_EXTENT_FLAG_MASK        0xc0000000
150 #define UDF_EXTENT_FLAG_ERASED      0x40000000
151 
152 /*
153  * Important!  VirtualAllocationTables are
154  * very different between 1.5 and 2.0!
155  */
156 
157 /* ----------- 1.5 ------------- */
158 /* UDF 1.5 2.2.10 */
159 #define UDF_FILE_TYPE_VAT15     0x0U
160 
161 /* UDF 1.5 2.2.10 - VAT layout: */
162 struct VirtualAllocationTable15 {
163 /*  uint32 VirtualSector[0];*/
164     EntityID    ident;
165     uint32  previousVATICB;
166    };
167 /* where number of VirtualSector's is (VATSize-36)/4 */
168 
169 /* ----------- 2.0 ------------- */
170 /* UDF 2.0 2.2.10 */
171 #define UDF_FILE_TYPE_VAT20     0xf8U
172 
173 /* UDF 2.0 2.2.10 (different from 1.5!) */
174 struct VirtualAllocationTable20 {
175     uint16 lengthHeader;
176     uint16 lengthImpUse;
177     dstring logicalVolIdent[128];
178     uint32  previousVatICBLoc;
179     uint32  numFIDSFiles;
180     uint32  numFIDSDirectories; /* non-parent */
181     uint16  minReadRevision;
182     uint16  minWriteRevision;
183     uint16  maxWriteRevision;
184     uint16  reserved;
185 /*  uint8   impUse[0];*/
186 /*  uint32  vatEntry[0];*/
187 };
188 
189 /* Sparing maps, see UDF 1.5 2.2.11 */
190 typedef struct _SparingEntry {
191     uint32  origLocation;
192     uint32  mappedLocation;
193 } SparingEntry;
194 
195 #define SPARING_LOC_AVAILABLE  0xffffffff
196 #define SPARING_LOC_CORRUPTED  0xfffffff0
197 
198 typedef SparingEntry   SPARING_ENTRY;
199 typedef SPARING_ENTRY* PSPARING_ENTRY;
200 
201 typedef SPARING_ENTRY  SPARING_MAP;
202 typedef PSPARING_ENTRY PSPARING_MAP;
203 
204 /* sparing maps, see UDF 2.0 2.2.11 */
205 typedef struct _SPARING_TABLE {
206     tag     descTag;
207     EntityID sparingIdent; /* *UDF Sparing Table */
208     uint16   reallocationTableLen;
209     uint16   reserved;  /* #00 */
210     uint32   sequenceNum;
211 //  SparingEntry mapEntry[0];
212 } SPARING_TABLE, *PSPARING_TABLE;
213 
214 /* Identifier Suffixes, see EntityID */
215 
216 typedef struct {
217     uint16 currentRev;
218     uint8  flags;
219     uint8  reserved[5];
220 } domainIdentSuffix;
221 
222 #define ENTITYID_FLAGS_HARD_RO      0x01U
223 #define ENTITYID_FLAGS_SOFT_RO      0x02U
224 
225 typedef struct {
226     uint16 currentRev;
227     uint8  OSClass;
228     uint8  OSIdent;
229     uint8  reserved[4];
230 } UDFIdentSuffix;
231 
232 typedef struct {
233     uint8  OSClass;
234     uint8  OSIdent;
235     uint8  reserved[6];
236 } impIdentSuffix;
237 
238 /* Unique ID maps, see UDF 2.0 2.2.11 */
239 
240 typedef struct {
241     uint32   uniqueID;
242     uint32   parentLogicalBlock;
243     uint32   objectLogicalBlock;
244     uint16   parentPartitionReferenceNum;
245     uint16   objectPartitionReferenceNum;
246 } UniqueIDEntry;
247 
248 typedef UniqueIDEntry        UID_MAPPING_ENTRY;
249 typedef UID_MAPPING_ENTRY*   PUID_MAPPING_ENTRY;
250 
251 typedef struct {
252     EntityID ident;
253     uint32   flags;
254     uint32   entryCount;
255     uint8    reserved[8];
256 //    UniqueIDEntry mapEntry[0];
257 } UniqueIDMappingData;
258 
259 typedef UniqueIDMappingData  UID_MAPPING_TABLE;
260 typedef UID_MAPPING_TABLE*   PUID_MAPPING_TABLE;
261 
262 /* Entity Identifiers (UDF 1.50 6.1) */
263 #define UDF_ID_COMPLIANT    "*OSTA UDF Compliant"
264 #define UDF_ID_LV_INFO      "*UDF LV Info"
265 #define UDF_ID_FREE_EA      "*UDF FreeEASpace"
266 #define UDF_ID_FREE_APP_EA  "*UDF FreeAppEASpace"
267 #define UDF_ID_DVD_CGMS     "*UDF DVD CGMS Info"
268 #define UDF_ID_OS2_EA       "*UDF OS/2 EA"
269 #define UDF_ID_OS2_EA_LENGTH    "*UDF OS/2 EALength"
270 #define UDF_ID_OS400_DIRINFO    "*UDF OS/400 DirInfo"
271 #define UDF_ID_MAC_VOLUME   "*UDF Mac VolumeInfo"
272 #define UDF_ID_MAC_FINDER   "*UDF Mac FinderInfo"
273 #define UDF_ID_MAC_UNIQUE   "*UDF Mac UniqueIDTable"
274 #define UDF_ID_MAC_RESOURCE "*UDF Mac ResourceFork"
275 #define UDF_ID_VIRTUAL      "*UDF Virtual Partition"
276 #define UDF_ID_SPARABLE     "*UDF Sparable Partition"
277 #define UDF_ID_METADATA     "*UDF Metadata Partition"
278 #define UDF_ID_ALLOC        "*UDF Virtual Alloc Tbl"
279 #define UDF_ID_SPARING      "*UDF Sparing Table"
280 
281 /* Operating System Identifiers (UDF 1.50 6.3) */
282 #define UDF_OS_CLASS_UNDEF  0x00U
283 #define UDF_OS_CLASS_DOS    0x01U
284 #define UDF_OS_CLASS_OS2    0x02U
285 #define UDF_OS_CLASS_MAC    0x03U
286 #define UDF_OS_CLASS_UNIX   0x04U
287 #define UDF_OS_CLASS_WIN95  0x05U
288 #define UDF_OS_CLASS_WINNT  0x06U
289 #define UDF_OS_CLASS_OS400  0x07U
290 #define UDF_OS_CLASS_BEOS   0x08U
291 #define UDF_OS_CLASS_WINCE  0x09U
292 
293 #define UDF_OS_ID_GENERIC   0x00U
294 #define UDF_OS_ID_UNDEF     0x00U
295 #define UDF_OS_ID_DOS       0x00U
296 #define UDF_OS_ID_OS2       0x00U
297 #define UDF_OS_ID_MAC       0x00U
298 #define UDF_OS_ID_UNIX      0x00U
299 #define UDF_OS_ID_WIN95     0x00U
300 #define UDF_OS_ID_WINNT     0x00U
301 #define UDF_OS_ID_OS400     0x00U
302 #define UDF_OS_ID_BEOS      0x00U
303 
304 #define UDF_OS_ID_AIX       0x01U
305 #define UDF_OS_ID_SOLARIS   0x02U
306 #define UDF_OS_ID_HPUX      0x03U
307 #define UDF_OS_ID_IRIX      0x04U
308 #define UDF_OS_ID_LINUX     0x05U
309 #define UDF_OS_ID_MKLINUX   0x06U
310 #define UDF_OS_ID_FREEBSD   0x07U
311 #define UDF_OS_ID_NETBSD    0x08U
312 
313 #define UDF_NAME_PAD      4
314 #define UDF_NAME_LEN      255
315 #define UDF_EXT_SIZE      5 // ???
316 #define UDF_PATH_LEN      1023
317 #define UDF_VOL_LABEL_LEN 32
318 
319 /* Reserved file names */
320 
321 #define UDF_FN_NON_ALLOCATABLE      L"Non-Allocatable Space"
322 #define UDF_FN_NON_ALLOCATABLE_2    L"Non-Allocatable List"
323 
324 #define UDF_FN_NON_ALLOCATABLE_USER      "Non-Allocatable Space"
325 #define UDF_FN_NON_ALLOCATABLE_2_USER    "Non-Allocatable List"
326 
327 /* Reserved system stream names */
328 /* METADATA bit shall be set to 1 */
329 
330 #define UDF_SN_UID_MAPPING          L"*UDF Unique ID Mapping Data"
331 #define UDF_SN_NON_ALLOCATABLE      L"*UDF Non-Allocatable Space"
332 #define UDF_SN_POWER_CAL_TABLE      L"*UDF Power Cal Table"
333 #define UDF_SN_BACKUP               L"*UDF Backup"
334 
335 /* Reserved non-system stream names */
336 /* METADATA bit shall be set to 0 */
337 
338 #define UDF_SN_MAC_RESOURCE_FORK    L"*UDF Macintosh Resource Fork"
339 #define UDF_SN_OS2_EA               L"*UDF OS/2 EA"
340 #define UDF_SN_NT_ACL               L"*UDF NT ACL"
341 #define UDF_SN_UNIX_ACL             L"*UDF UNIX ACL"
342 
343 #define UDF_RESERVED_NAME_HDR       L"*UDF "
344 
345 /* ----------- 2.01 ------------ */
346 /* UDF 2.0 2.2.10 */
347 #define UDF_FILE_TYPE_REALTIME    0xf9U
348 
349 #define TID_ADAPTEC_LOGICAL_VOL_DESC      0x9999U
350 
351 #pragma pack(pop)
352 
353 #endif /* _OSTA_MISC_H */
354