Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

520 lines
18 KiB

  1. /*++
  2. Copyright (c) 1996-2000 Microsoft Corporation
  3. Module Name:
  4. Udf.h
  5. Abstract:
  6. This module contains all definitions specified by the OSTA UDF standard which
  7. are not defined in ISO 13346 and associated errta. UDF is a subset of ISO 13346
  8. which restricts many facets of the ISO standard and is currently standardized
  9. by the Optical Storage Technology Association (http://www.osta.org). Some
  10. aspects of the structures we read may seem illogical unless viewed in this light.
  11. Unless otherwise specified, section references will be to ISO 13346.
  12. Also unless otherwise specified, all descriptors mentioned will be sector aligned
  13. A UDF volume is recognized by searching the Volume Recognition Area (2/8.3) for a
  14. Volume Structure Descriptor (2/9.1) which advertises itself as NSR02, the filesystem
  15. format specified by ISO 13346 section 4. This is aligned to match ISO 9660, and the
  16. first descriptor may in fact be a 9660 PVD. ISO 13346 descriptors are bounded by
  17. a Begin Extended Area descriptor (2/9.2) and a Terminate Extended Area descriptor
  18. (2/9.3).
  19. +-------+-------+ +-------+ +-------+
  20. | | | | | | |
  21. | CD001 | BEA01 | ... | NSR02 | ... | TEA01 |
  22. | | | | | | |
  23. +-------+-------+ +-------+ +-------+
  24. A UDF volume is then discovered by looking for an Anchor Volume Descriptor (3/10.2),
  25. which reveals the location of a pair of extents of the physical volume that contain
  26. copies of the Volume Descriptor Sequence. Both of these copies are defined to be
  27. equivalent (duplication is intended for diasaster recovery).
  28. +-------+ +------------------------------------+
  29. | | -----------> | |
  30. | AVD | | Main Volume Descriptor Sequence |
  31. | | ----+ | |
  32. +-------+ | +------------------------------------+
  33. |
  34. | +------------------------------------+
  35. | | |
  36. +------> | Reserve Volume Descriptor Sequence |
  37. | |
  38. +------------------------------------+
  39. An ISO 13346 logical (mountable) volume is composed of a number Np of physical partitions
  40. spread across a number Nd of physical volumes (media), all of which may be multiply
  41. referenced to create a numbed Nv of logical volumes. While ISO 13346 allows this level of
  42. complexity, UDF restricts as follows: Nv = 1 and Np = Nd except if Nd = 1 then perhaps
  43. Np = 2 and one partition is read/write while the other is readonly. There are three levels
  44. of conforming implementations which are defined by ISO 1336 in 3/11 which progress from 1,
  45. a restricted Nd = 1, to 3 where Nd > 1. This is a readonly level 2 implementation, which
  46. is an unrestricted single physical media implementation - other than those imposed by UDF.
  47. A Volume Descriptor Sequence is composed of a number of descriptors which collectively nail
  48. down a volume:
  49. Primary Volume Descriptor (PVD) Identification of the physical media and its
  50. (3/10.1) relation to a volume set.
  51. Volume Descriptor Pointer (VSD) Identification of a continuing extent of the Volume
  52. (3/10.3) Descriptor Sequence (the VDS need not be a single
  53. extent).
  54. Implementation Use Volume Desciptor (IUVD) Exactly that.
  55. (3/10.4)
  56. Partition Descriptor (PD) Identification of a linear extent of sectors
  57. (3/10.5) on a physical media (type 1) or an implementation
  58. defined object (type 2).
  59. Logical Volume Descriptor (LVD) Identification of a mountable volume by
  60. (3/10.6) referring to partition(s) and a location for
  61. a File Set Descriptor.
  62. Unallocated Space Descriptor (USD) Identification of an unallocated extents of the
  63. (3/10.8) media which could be added to existing partitions
  64. or allocated through new partitions.
  65. Terminating Descriptor (TD) A method of terminating the Volume Descriptor
  66. (3/10.9) Sequence. A VDS may also be terminated by an
  67. unrecorded sector or running to the end of an
  68. extent.
  69. An ISO 13346 volume set is a grouping of physical media, identified collectively by examining
  70. the PVD of each unit. A Volume Descriptor Sequence is recorded on each constituent of the volume
  71. set, but only the volume with the highest Volume Sequence Number may contain LVD. An LVD may
  72. refer to any PD on any member of the volume set.
  73. Each descriptor contains a Volume Sequence Number which allows an otherwise identification
  74. equivalent descriptor (i.e., specifies the same Partition Number (for PD), same Logical
  75. Volume Identifier (for LVD), etc. (3/8.4.3)) to override one of lower VSN.
  76. So, a picture of what a Volume Descriptor Sequence could look like is
  77. +------+------+------+------+------+
  78. | | | | | |
  79. | PVD | LVD | PD | PD | VDP |
  80. | | | | | |
  81. +------+------+------+------+------+
  82. |
  83. | +------+------+------+------+
  84. | | | | | |
  85. +->| USD | IUVD | IUVD | TD |
  86. | | | | |
  87. +------+------+------+------+
  88. The LVD points to a File Set Descriptor (4/14.1), which finally points to a root directory.
  89. // @@BEGIN_DDKSPLIT
  90. Author:
  91. Dan Lovinger [DanLo] 10-Jul-1996
  92. Revision History:
  93. Tom Jolly [TomJolly] 1-March-2000 UDF 2.01 support
  94. // @@END_DDKSPLIT
  95. --*/
  96. #ifndef _UDF_
  97. #define _UDF_
  98. #include <iso13346.h>
  99. //
  100. // This is the version of UDF that we recognize, per the Domain Identifier
  101. // specification in UDF 2.1.5.3.
  102. //
  103. // The values below indicate we understand UDF 2.01. We will also define
  104. // specific revisions so that we can assert correctness for some structures
  105. // that we know appeared for the first time in certain specifications.
  106. //
  107. //
  108. #define UDF_VERSION_100 0x0100
  109. #define UDF_VERSION_101 0x0101
  110. #define UDF_VERSION_102 0x0102
  111. #define UDF_VERSION_150 0x0150
  112. #define UDF_VERSION_200 0x0200
  113. #define UDF_VERSION_201 0x0201
  114. #define UDF_VERSION_RECOGNIZED UDF_VERSION_201
  115. #define UDF_VERSION_MINIMUM UDF_VERSION_100
  116. //
  117. // Method 2 Fixup.
  118. //
  119. // This really isn't UDF, but for lack of a better place ... and since we are doing
  120. // the work for UDF only. In the filesystem. Sigh.
  121. //
  122. // Various bad CD-ROM units, when reading fixed-packet CD-RW media, fail to map out
  123. // the runin/out blocks that follow each packet of 32 sectors on the media. As a
  124. // result, we have to fixup all of the byte offsets to read the image.
  125. //
  126. // Note: fixed packet. Variable packet discs do have the runin/out exposed, but
  127. // imaging software will have realized this and numbered sectors right.
  128. //
  129. // Normally we would refuse to deal with this garbage, but Adaptec made the decision
  130. // for us by having their reader handle these drives. So that we don't have to deal
  131. // with endless "but it works with Adaptec", we've got to do it here.
  132. //
  133. // This is really depressing.
  134. //
  135. #define CDRW_PACKET_LENGTH 32
  136. #define CDRW_RUNOUT_LENGTH 7
  137. //
  138. // LONGLONG UdfMethod2TransformByteOffset (
  139. // PVCB Vcb,
  140. // LONGLONG ByteOffset
  141. // )
  142. //
  143. // Takes a normal byteoffset and adds in the differential implied by the number
  144. // of runout areas it spans.
  145. //
  146. #define UdfMethod2TransformByteOffset(V, BO) \
  147. ((BO) + LlBytesFromSectors((V), ((LlSectorsFromBytes((V), BO) / CDRW_PACKET_LENGTH) * CDRW_RUNOUT_LENGTH)))
  148. #define UdfMethod2TransformSector(V, S) \
  149. ((S) + ((S) / CDRW_PACKET_LENGTH) * CDRW_RUNOUT_LENGTH)
  150. //
  151. // ULONG UdfMethod2NextRunoutInSectors (
  152. // PVCB Vcb,
  153. // LONGLONG ByteOffset
  154. // )
  155. //
  156. // Takes a normal byteoffset and figures out how many sectors remain until the next
  157. // (forward) runout area.
  158. //
  159. #define UdfMethod2NextRunoutInSectors(V, BO) \
  160. (CDRW_PACKET_LENGTH - (LlSectorsFromBytes((V), (BO)) % CDRW_PACKET_LENGTH))
  161. //
  162. // Generic constants
  163. //
  164. #define BYTE_COUNT_8_DOT_3 (24)
  165. //
  166. // Constants for the name transform algorithm. Names greater than MAXLEN will be
  167. // rendered. MAX_PATH comes from user-side includes that we don't get here.
  168. //
  169. // UDF specifies rules for converting names from illegal->legal forms for a given OS.
  170. // The rest of the constants/macros are used to convert the clipped code for these
  171. // algorithims into a form we can directly use.
  172. //
  173. // The NativeCharLength question is really not answerable for the non-8.3 case, since
  174. // NT internally is completely ignorant of the eventual destination of the name.
  175. //
  176. #define MAX_PATH 260
  177. #define MAX_LEN (MAX_PATH - 5)
  178. #define EXT_LEN 5
  179. #define CRC_LEN 5
  180. #define DOS_NAME_LEN 8
  181. #define DOS_EXT_LEN 3
  182. #define DOS_CRC_LEN 4
  183. #define IsFileNameCharLegal(c) UdfIsCharacterLegal(c)
  184. #define IsDeviceName(s, n) FALSE
  185. #define NativeCharLength(c) 1
  186. #define UnicodeToUpper(c) (c)
  187. #define INT16 SHORT
  188. #define UINT16 USHORT
  189. #define UNICODE_CHAR WCHAR
  190. #define PERIOD (L'.')
  191. #define SPACE (L' ')
  192. #define CRC_MARK (L'#')
  193. #define ILLEGAL_CHAR_MARK (L'_')
  194. //
  195. // Place a non-tail recursable depth limit on ICB hierarchies. We cannot read
  196. // ICB hierarchies that are deeper than this.
  197. //
  198. #define UDF_ICB_RECURSION_LIMIT 10
  199. //
  200. // Entity ID (REGID) Suffixes are used in UDF to encode extra information away from
  201. // the string data in the Identifier. See UDF 2.1.4.2.
  202. //
  203. //
  204. // A Domain Suffix is encoded for the Logical Volume Descriptor and File Set Descriptor
  205. //
  206. typedef struct _UDF_SUFFIX_DOMAIN {
  207. USHORT UdfRevision;
  208. UCHAR Flags;
  209. UCHAR Reserved[5];
  210. } UDF_SUFFIX_DOMAIN, *PUDF_SUFFIX_DOMAIN;
  211. #define UDF_SUFFIX_DOMAIN_FLAG_HARD_WRITEPROTECT 0x01
  212. #define UDF_SUFFIX_DOMAIN_FLAG_SOFT_WRITEPROTECT 0x02
  213. //
  214. // A UDF Suffix is encoded for extended attributes, Implementation Use Volume
  215. // Descriptors and VATs (among others).
  216. //
  217. typedef struct _UDF_SUFFIX_UDF {
  218. USHORT UdfRevision;
  219. UCHAR OSClass;
  220. UCHAR OSIdentifier;
  221. UCHAR Reserved[4];
  222. } UDF_SUFFIX_UDF, *PUDF_SUFFIX_UDF;
  223. //
  224. // An Implementation Suffix is encoded for almost every other structure containing
  225. // an Entity ID.
  226. //
  227. typedef struct _UDF_SUFFIX_IMPLEMENTATION {
  228. UCHAR OSClass;
  229. UCHAR OSIdentifier;
  230. UCHAR ImplementationUse[6];
  231. } UDF_SUFFIX_IMPLEMENTATION, *PUDF_SUFFIX_IMPLEMENTATION;
  232. //
  233. // OS Classes and Identifiers are defined by OSTA as of UDF 1.50
  234. //
  235. // We also take the minor liberty of defining an invalid set for
  236. // the purposes of hinting internally that we don't care about them.
  237. // It is unlikely that UDF will ever hit 255, even though these are
  238. // technically avaliable for allocation.
  239. //
  240. #define OSCLASS_INVALID 255
  241. #define OSIDENTIFIER_INVALID 255
  242. #define OSCLASS_UNDEFINED 0
  243. #define OSCLASS_DOS 1
  244. #define OSCLASS_OS2 2
  245. #define OSCLASS_MACOS 3
  246. #define OSCLASS_UNIX 4
  247. #define OSCLASS_WIN9X 5
  248. #define OSCLASS_WINNT 6
  249. #define OSIDENTIFIER_DOS_DOS 0
  250. #define OSIDENTIFIER_OS2_OS2 0
  251. #define OSIDENTIFIER_MACOS_MACOS7 0
  252. #define OSIDENTIFIER_UNIX_GENERIC 0
  253. #define OSIDENTIFIER_UNIX_AIX 1
  254. #define OSIDENTIFIER_UNIX_SOLARIS 2
  255. #define OSIDENTIFIER_UNIX_HPUX 3
  256. #define OSIDENTIFIER_UNIX_IRIX 4
  257. #define OSIDENTIFIER_UNIX_LINUX 5
  258. #define OSIDENTIFIER_UNIX_MKLINUX 6
  259. #define OSIDENTIFIER_UNIX_FREEBSD 7
  260. #define OSIDENTIFIER_WIN9X_WIN95 0
  261. #define OSIDENTIFIED_WINNT_WINNT 0
  262. //
  263. // Character Set Lists are actually just a 32bit word where each bit N on/off specifies
  264. // that Character Set N is used on the volume. Per UDF, the only character set we
  265. // recognize is CS0, so construct a bitmask Character Set List for that. (1/7.2.11)
  266. //
  267. #define UDF_CHARSETLIST 0x00000001
  268. //
  269. // Generic partition map for UDF. This allows partition maps to be typed and the
  270. // UDF entity identifier for the various type 2 maps to be inspected.
  271. //
  272. typedef struct _PARTMAP_UDF_GENERIC {
  273. UCHAR Type; // Partition Map Type = 2
  274. UCHAR Length; // Partition Map Length = 64
  275. UCHAR Reserved2[2]; // Reserved Padding
  276. REGID PartID; // Paritition Entity Identifier
  277. UCHAR Reserved24[28]; // Reserved Padding
  278. } PARTMAP_UDF_GENERIC, *PPARTMAP_UDF_GENERIC;
  279. //
  280. // UDF 1.50 CD UDF Partition Types
  281. //
  282. //////////
  283. // UDF Virtual Partitions are identified via a type 2 partition map of the following form.
  284. //////////
  285. typedef struct _PARTMAP_VIRTUAL {
  286. UCHAR Type; // Partition Map Type = 2
  287. UCHAR Length; // Partition Map Length = 64
  288. UCHAR Reserved2[2]; // Reserved Padding
  289. REGID PartID; // Paritition Entity Identifier
  290. // == UdfVirtualPartitionDomainIdentifier
  291. USHORT VolSetSeq; // Volume Set Sequence
  292. USHORT Partition; // Related Partition
  293. UCHAR Reserved40[24]; // Reserved Padding
  294. } PARTMAP_VIRTUAL, *PPARTMAP_VIRTUAL;
  295. //
  296. // UDF 2.00 CD UDF VAT Header
  297. //
  298. // Note that values in this record supedcede those in the LDV or LVID
  299. //
  300. typedef struct _VAT_HEADER {
  301. USHORT Length; // Header length = 152 + ImpUseLength
  302. USHORT ImpUseLength;
  303. UCHAR VolumeID[128];
  304. ULONG PreviousVatIcbLbn;
  305. ULONG FileFidCount;
  306. ULONG NonParentDirFidCount;
  307. USHORT MinUdfReadRevision;
  308. USHORT MinUdfWriteRevision;
  309. USHORT MaxUdfWriteRevision;
  310. USHORT Reserved;
  311. UCHAR ImpUse[0];
  312. // VAT entries immediately follow impuse data.
  313. //
  314. // UINT32 Lba of virtual sector 0
  315. // UINT32 Lba of virtual sector 1
  316. // ...
  317. } VAT_HEADER, *PVAT_HEADER;
  318. //
  319. // A UDF 1.50 VAT minimally contains a mapping for a single block, the REGID identifying
  320. // the VAT, and the identification of a previous VAT ICB location.
  321. //
  322. // A UDF 2.0x VAT minimally contains a VAT header, and a mapping for a single block.
  323. //
  324. // We also identify
  325. // an arbitrary sanity limit that the VAT isn't bigger than 8mb since it is extremely
  326. // difficult to imagine such a VAT existing in practice since each sector describes
  327. // (on most of our media) 2048/4 = 512 entries ... meaning at 8mb the VAT would
  328. // describe ~2^21 blocks. 4/12/01 Increased for DVD-R.
  329. //
  330. #define UDF_CDUDF_TRAILING_DATA_SIZE (sizeof(REGID) + sizeof(ULONG))
  331. #define UDF_CDUDF_MINIMUM_150_VAT_SIZE (sizeof(ULONG) + UDF_CDUDF_TRAILING_DATA_SIZE)
  332. #define UDF_CDUDF_MINIMUM_20x_VAT_SIZE (sizeof(ULONG) + sizeof( VAT_HEADER))
  333. #define UDF_CDUDF_MAXIMUM_VAT_SIZE (16 * 1024 * 1024)
  334. //////////
  335. // UDF Sparable Partitions are identified via a type 2 partition map of the following form.
  336. //////////
  337. typedef struct _PARTMAP_SPARABLE {
  338. UCHAR Type; // Partition Map Type = 2
  339. UCHAR Length; // Partition Map Length = 64
  340. UCHAR Reserved2[2]; // Reserved Padding
  341. REGID PartID; // Paritition Entity Identifier
  342. // == UdfSparablePartitionDomainIdentifier
  343. USHORT VolSetSeq; // Volume Set Sequence
  344. USHORT Partition; // Related Partition
  345. USHORT PacketLength; // Packet Length == 32 (number of data blocks
  346. // per packet)
  347. UCHAR NumSparingTables; // Number of pparing tables on the media
  348. UCHAR Reserved43; // Reserved Padding
  349. ULONG TableSize; // Size of sparing tables
  350. ULONG TableLocation[4]; // Location of each sparing table (each
  351. // sparing table should be in a distinct packet)
  352. } PARTMAP_SPARABLE, *PPARTMAP_SPARABLE;
  353. //
  354. // Sparing tables lead off with this header structure.
  355. //
  356. typedef struct _SPARING_TABLE_HEADER {
  357. DESTAG Destag; // Ident = 0
  358. REGID RegID; // == UdfSparingTableIdentifier
  359. USHORT TableEntries; // Number of entries in the table
  360. USHORT Reserved50; // Reserved Padding
  361. ULONG Sequence; // Sequence Number (incremented on rewrite of table)
  362. } *PSPARING_TABLE_HEADER, SPARING_TABLE_HEADER;
  363. //
  364. // Sparing table map entries.
  365. //
  366. typedef struct _SPARING_TABLE_ENTRY {
  367. ULONG Original; // Original LBN
  368. ULONG Mapped; // Mapped PSN
  369. } *PSPARING_TABLE_ENTRY, SPARING_TABLE_ENTRY;
  370. //
  371. // Fixed values for original sectors, indicating that either the
  372. // mapped packet is avaliable for sparing use or is defective.
  373. //
  374. #define UDF_SPARING_AVALIABLE 0xffffffff
  375. #define UDF_SPARING_DEFECTIVE 0xfffffff0
  376. //
  377. // The unit of media in each sparing packet is fixed at 32 physical sectors.
  378. //
  379. #define UDF_SPARING_PACKET_LENGTH CDRW_PACKET_LENGTH
  380. //
  381. // Additional Values defined in UDF, over and above those in ISO13346.h
  382. //
  383. // ICBTAG_FILE_T_... - Values for icbtag_FileType
  384. #define ICBTAG_FILE_T_VAT 248 // VAT (new format - UDF 2.00 and later)
  385. #define ICBTAG_FILE_T_REALTIME 249 // Real Time File (UDF 2.01, 2.3.5.2.1)
  386. #endif // _UDF_