00001 /*++ 00002 00003 Copyright (c) 1996 Microsoft Corporation 00004 00005 Module Name: 00006 00007 Udf.h 00008 00009 Abstract: 00010 00011 This module contains all definitions specified by the OSTA UDF standard which 00012 are not defined in ISO 13346 and associated errta. UDF is a subset of ISO 13346 00013 which restricts many facets of the ISO standard and is currently standardized 00014 by the Optical Storage Technology Association (http://www.osta.org). Some 00015 aspects of the structures we read may seem illogical unless viewed in this light. 00016 00017 Unless otherwise specified, section references will be to ISO 13346. 00018 00019 Also unless otherwise specified, all descriptors mentioned will be sector aligned 00020 00021 A UDF volume is recognized by searching the Volume Recognition Area (2/8.3) for a 00022 Volume Structure Descriptor (2/9.1) which advertises itself as NSR02, the filesystem 00023 format specified by ISO 13346 section 4. This is aligned to match ISO 9660, and the 00024 first descriptor may in fact be a 9660 PVD. ISO 13346 descriptors are bounded by 00025 a Begin Extended Area descriptor (2/9.2) and a Terminate Extended Area descriptor 00026 (2/9.3). 00027 00028 +-------+-------+ +-------+ +-------+ 00029 | | | | | | | 00030 | CD001 | BEA01 | ... | NSR02 | ... | TEA01 | 00031 | | | | | | | 00032 +-------+-------+ +-------+ +-------+ 00033 00034 A UDF volume is then discovered by looking for an Anchor Volume Descriptor (3/10.2), 00035 which reveals the location of a pair of extents of the physical volume that contain 00036 copies of the Volume Descriptor Sequence. Both of these copies are defined to be 00037 equivalent (duplication is intended for diasaster recovery). 00038 00039 +-------+ +------------------------------------+ 00040 | | -----------> | | 00041 | AVD | | Main Volume Descriptor Sequence | 00042 | | ----+ | | 00043 +-------+ | +------------------------------------+ 00044 | 00045 | +------------------------------------+ 00046 | | | 00047 +------> | Reserve Volume Descriptor Sequence | 00048 | | 00049 +------------------------------------+ 00050 00051 An ISO 13346 logical (mountable) volume is composed of a number Np of physical partitions 00052 spread across a number Nd of physical volumes (media), all of which may be multiply 00053 referenced to create a numbed Nv of logical volumes. While ISO 13346 allows this level of 00054 complexity, UDF restricts as follows: Nv = 1 and Np = Nd except if Nd = 1 then perhaps 00055 Np = 2 and one partition is read/write while the other is readonly. There are three levels 00056 of conforming implementations which are defined by ISO 1336 in 3/11 which progress from 1, 00057 a restricted Nd = 1, to 3 where Nd > 1. This is a readonly level 2 implementation, which 00058 is an unrestricted single physical media implementation - other than those imposed by UDF. 00059 00060 A Volume Descriptor Sequence is composed of a number of descriptors which collectively nail 00061 down a volume: 00062 00063 Primary Volume Descriptor (PVD) Identification of the physical media and its 00064 (3/10.1) relation to a volume set. 00065 00066 Volume Descriptor Pointer (VSD) Identification of a continuing extent of the Volume 00067 (3/10.3) Descriptor Sequence (the VDS need not be a single 00068 extent). 00069 00070 Implementation Use Volume Desciptor (IUVD) Exactly that. 00071 (3/10.4) 00072 00073 Partition Descriptor (PD) Identification of a linear extent of sectors 00074 (3/10.5) on a physical media (type 1) or an implementation 00075 defined object (type 2). 00076 00077 Logical Volume Descriptor (LVD) Identification of a mountable volume by 00078 (3/10.6) referring to partition(s) and a location for 00079 a File Set Descriptor. 00080 00081 Unallocated Space Descriptor (USD) Identification of an unallocated extents of the 00082 (3/10.8) media which could be added to existing partitions 00083 or allocated through new partitions. 00084 00085 Terminating Descriptor (TD) A method of terminating the Volume Descriptor 00086 (3/10.9) Sequence. A VDS may also be terminated by an 00087 unrecorded sector or running to the end of an 00088 extent. 00089 00090 An ISO 13346 volume set is a grouping of physical media, identified collectively by examining 00091 the PVD of each unit. A Volume Descriptor Sequence is recorded on each constituent of the volume 00092 set, but only the volume with the highest Volume Sequence Number may contain LVD. An LVD may 00093 refer to any PD on any member of the volume set. 00094 00095 Each descriptor contains a Volume Sequence Number which allows an otherwise identification 00096 equivalent descriptor (i.e., specifies the same Partition Number (for PD), same Logical 00097 Volume Identifier (for LVD), etc. (3/8.4.3)) to override one of lower VSN. 00098 00099 So, a picture of what a Volume Descriptor Sequence could look like is 00100 00101 +------+------+------+------+------+ 00102 | | | | | | 00103 | PVD | LVD | PD | PD | VDP | 00104 | | | | | | 00105 +------+------+------+------+------+ 00106 | 00107 | +------+------+------+------+ 00108 | | | | | | 00109 +->| USD | IUVD | IUVD | TD | 00110 | | | | | 00111 +------+------+------+------+ 00112 00113 The LVD points to a File Set Descriptor (4/14.1), which finally points to a root directory. 00114 00115 Author: 00116 00117 Dan Lovinger [DanLo] 10-Jul-1996 00118 00119 Revision History: 00120 00121 --*/ 00122 00123 #ifndef _UDF_ 00124 #define _UDF_ 00125 00126 #include <iso13346.h> 00127 00128 // 00129 // This is the version of UDF that we recognize, per the Domain Identifier 00130 // specification in UDF 2.1.5.3. 00131 // 00132 // The values below indicate we understand UDF 1.50. We will also define 00133 // specific revisions so that we can assert correctness for some structures 00134 // that we know appeared for the first time in certain specifications. 00135 // 00136 // 00137 00138 #define UDF_VERSION_100 0x0100 00139 #define UDF_VERSION_101 0x0101 00140 #define UDF_VERSION_102 0x0102 00141 #define UDF_VERSION_150 0x0150 00142 00143 #define UDF_VERSION_RECOGNIZED UDF_VERSION_150 00144 00145 #define UDF_VERSION_MINIMUM UDF_VERSION_100 00146 00147 00148 // 00149 // Method 2 Fixup. 00150 // 00151 // This really isn't UDF, but for lack of a better place ... and since we are doing 00152 // the work for UDF only. In the filesystem. Sigh. 00153 // 00154 // Various bad CD-ROM units, when reading fixed-packet CD-RW media, fail to map out 00155 // the runin/out blocks that follow each packet of 32 sectors on the media. As a 00156 // result, we have to fixup all of the byte offsets to read the image. 00157 // 00158 // Note: fixed packet. Variable packet discs do have the runin/out exposed, but 00159 // imaging software will have realized this and numbered sectors right. 00160 // 00161 // Normally we would refuse to deal with this garbage, but Adaptec made the decision 00162 // for us by having their reader handle these drives. So that we don't have to deal 00163 // with endless "but it works with Adaptec", we've got to do it here. 00164 // 00165 // This is really depressing. 00166 // 00167 00168 #define CDRW_PACKET_LENGTH 32 00169 #define CDRW_RUNOUT_LENGTH 7 00170 00171 // 00172 // LONGLONG UdfMethod2TransformByteOffset ( 00173 // PVCB Vcb, 00174 // LONGLONG ByteOffset 00175 // ) 00176 // 00177 // Takes a normal byteoffset and adds in the differential implied by the number 00178 // of runout areas it spans. 00179 // 00180 00181 #define UdfMethod2TransformByteOffset(V, BO) \ 00182 ((BO) + LlBytesFromSectors((V), ((LlSectorsFromBytes((V), BO) / CDRW_PACKET_LENGTH) * CDRW_RUNOUT_LENGTH))) 00183 00184 #define UdfMethod2TransformSector(V, S) \ 00185 ((S) + ((S) / CDRW_PACKET_LENGTH) * CDRW_RUNOUT_LENGTH) 00186 00187 // 00188 // ULONG UdfMethod2NextRunoutInSectors ( 00189 // PVCB Vcb, 00190 // LONGLONG ByteOffset 00191 // ) 00192 // 00193 // Takes a normal byteoffset and figures out how many sectors remain until the next 00194 // (forward) runout area. 00195 // 00196 00197 #define UdfMethod2NextRunoutInSectors(V, BO) \ 00198 (CDRW_PACKET_LENGTH - (LlSectorsFromBytes((V), (BO)) % CDRW_PACKET_LENGTH)) 00199 00200 00201 // 00202 // Generic constants 00203 // 00204 00205 #define BYTE_COUNT_8_DOT_3 (24) 00206 00207 // 00208 // Constants for the name transform algorithm. Names greater than MAXLEN will be 00209 // rendered. MAX_PATH comes from user-side includes that we don't get here. 00210 // 00211 // UDF specifies rules for converting names from illegal->legal forms for a given OS. 00212 // The rest of the constants/macros are used to convert the clipped code for these 00213 // algorithims into a form we can directly use. 00214 // 00215 // The NativeCharLength question is really not answerable for the non-8.3 case, since 00216 // NT internally is completely ignorant of the eventual destination of the name. 00217 // 00218 00219 #define MAX_PATH 260 00220 00221 #define MAX_LEN (MAX_PATH - 5) 00222 #define EXT_LEN 5 00223 #define CRC_LEN 5 00224 00225 #define DOS_NAME_LEN 8 00226 #define DOS_EXT_LEN 3 00227 #define DOS_CRC_LEN 4 00228 00229 #define IsFileNameCharLegal(c) UdfIsCharacterLegal(c) 00230 #define IsDeviceName(s, n) FALSE 00231 #define NativeCharLength(c) 1 00232 #define UnicodeToUpper(c) (c) 00233 00234 #define INT16 LONG 00235 #define UINT16 ULONG 00236 #define UNICODE_CHAR WCHAR 00237 00238 #define PERIOD (L'.') 00239 #define SPACE (L' ') 00240 #define CRC_MARK (L'#') 00241 #define ILLEGAL_CHAR_MARK (L'_') 00242 00243 // 00244 // Place a non-tail recursable depth limit on ICB hierarchies. We cannot read 00245 // ICB hierarchies that are deeper than this. 00246 // 00247 00248 #define UDF_ICB_RECURSION_LIMIT 10 00249 00250 00251 // 00252 // Entity ID (REGID) Suffixes are used in UDF to encode extra information away from 00253 // the string data in the Identifier. See UDF 2.1.4.2. 00254 // 00255 00256 // 00257 // A Domain Suffix is encoded for the Logical Volume Descriptor and File Set Descriptor 00258 // 00259 00260 typedef struct _UDF_SUFFIX_DOMAIN { 00261 00262 USHORT UdfRevision; 00263 UCHAR Flags; 00264 UCHAR Reserved[5]; 00265 00266 } UDF_SUFFIX_DOMAIN, *PUDF_SUFFIX_DOMAIN; 00267 00268 #define UDF_SUFFIX_DOMAIN_FLAG_HARD_WRITEPROTECT 0x01 00269 #define UDF_SUFFIX_DOMAIN_FLAG_SOFT_WRITEPROTECT 0x02 00270 00271 // 00272 // A UDF Suffix is encoded for extended attributes, Implementation Use Volume 00273 // Descriptors and VATs (among others). 00274 // 00275 00276 typedef struct _UDF_SUFFIX_UDF { 00277 00278 USHORT UdfRevision; 00279 UCHAR OSClass; 00280 UCHAR OSIdentifier; 00281 UCHAR Reserved[4]; 00282 00283 } UDF_SUFFIX_UDF, *PUDF_SUFFIX_UDF; 00284 00285 // 00286 // An Implementation Suffix is encoded for almost every other structure containing 00287 // an Entity ID. 00288 // 00289 00290 typedef struct _UDF_SUFFIX_IMPLEMENTATION { 00291 00292 UCHAR OSClass; 00293 UCHAR OSIdentifier; 00294 UCHAR ImplementationUse[6]; 00295 00296 } UDF_SUFFIX_IMPLEMENTATION, *PUDF_SUFFIX_IMPLEMENTATION; 00297 00298 // 00299 // OS Classes and Identifiers are defined by OSTA as of UDF 1.50 00300 // 00301 // We also take the minor liberty of defining an invalid set for 00302 // the purposes of hinting internally that we don't care about them. 00303 // It is unlikely that UDF will ever hit 255, even though these are 00304 // technically avaliable for allocation. 00305 // 00306 00307 #define OSCLASS_INVALID 255 00308 #define OSIDENTIFIER_INVALID 255 00309 00310 00311 #define OSCLASS_UNDEFINED 0 00312 #define OSCLASS_DOS 1 00313 #define OSCLASS_OS2 2 00314 #define OSCLASS_MACOS 3 00315 #define OSCLASS_UNIX 4 00316 #define OSCLASS_WIN9X 5 00317 #define OSCLASS_WINNT 6 00318 00319 #define OSIDENTIFIER_DOS_DOS 0 00320 00321 #define OSIDENTIFIER_OS2_OS2 0 00322 00323 #define OSIDENTIFIER_MACOS_MACOS7 0 00324 00325 #define OSIDENTIFIER_UNIX_GENERIC 0 00326 #define OSIDENTIFIER_UNIX_AIX 1 00327 #define OSIDENTIFIER_UNIX_SOLARIS 2 00328 #define OSIDENTIFIER_UNIX_HPUX 3 00329 #define OSIDENTIFIER_UNIX_IRIX 4 00330 #define OSIDENTIFIER_UNIX_LINUX 5 00331 #define OSIDENTIFIER_UNIX_MKLINUX 6 00332 #define OSIDENTIFIER_UNIX_FREEBSD 7 00333 00334 #define OSIDENTIFIER_WIN9X_WIN95 0 00335 00336 #define OSIDENTIFIED_WINNT_WINNT 0 00337 00338 00339 // 00340 // Character Set Lists are actually just a 32bit word where each bit N on/off specifies 00341 // that Character Set N is used on the volume. Per UDF, the only character set we 00342 // recognize is CS0, so construct a bitmask Character Set List for that. (1/7.2.11) 00343 // 00344 00345 #define UDF_CHARSETLIST 0x00000001 00346 00347 00348 // 00349 // Generic partition map for UDF. This allows partition maps to be typed and the 00350 // UDF entity identifier for the various type 2 maps to be inspected. 00351 // 00352 00353 typedef struct _PARTMAP_UDF_GENERIC { 00354 00355 UCHAR Type; // Partition Map Type = 2 00356 UCHAR Length; // Partition Map Length = 64 00357 UCHAR Reserved2[2]; // Reserved Padding 00358 REGID PartID; // Paritition Entity Identifier 00359 UCHAR Reserved24[28]; // Reserved Padding 00360 00361 } PARTMAP_UDF_GENERIC, *PPARTMAP_UDF_GENERIC; 00362 00363 // 00364 // UDF 1.50 CD UDF Partition Types 00365 // 00366 00368 // UDF Virtual Partitions are identified via a type 2 partition map of the following form. 00370 00371 typedef struct _PARTMAP_VIRTUAL { 00372 00373 UCHAR Type; // Partition Map Type = 2 00374 UCHAR Length; // Partition Map Length = 64 00375 UCHAR Reserved2[2]; // Reserved Padding 00376 REGID PartID; // Paritition Entity Identifier 00377 // == UdfVirtualPartitionDomainIdentifier 00378 USHORT VolSetSeq; // Volume Set Sequence 00379 USHORT Partition; // Related Partition 00380 UCHAR Reserved40[24]; // Reserved Padding 00381 00382 } PARTMAP_VIRTUAL, *PPARTMAP_VIRTUAL; 00383 00384 // 00385 // A VAT minimally contains a mapping for a single block, the REGID identifying 00386 // the VAT, and the identification of a previous VAT ICB location. We also identify 00387 // an arbitrary sanity limit that the VAT isn't bigger than 8mb since it is extremely 00388 // difficult to imagine such a VAT existing in practice since each sector describes 00389 // (on most of our media) 2048/4 = 512 entries ... meaning at 8mb the VAT would 00390 // describe ~2^21 blocks. 00391 // 00392 00393 #define UDF_CDUDF_TRAILING_DATA_SIZE (sizeof(REGID) + sizeof(ULONG)) 00394 00395 #define UDF_CDUDF_MINIMUM_VAT_SIZE (sizeof(ULONG) + UDF_CDUDF_TRAILING_DATA_SIZE) 00396 #define UDF_CDUDF_MAXIMUM_VAT_SIZE (UDF_CDUDF_MINIMUM_VAT_SIZE + (8 * 1024 * 1024)) 00397 00399 // UDF Sparable Partitions are identified via a type 2 partition map of the following form. 00401 00402 typedef struct _PARTMAP_SPARABLE { 00403 00404 UCHAR Type; // Partition Map Type = 2 00405 UCHAR Length; // Partition Map Length = 64 00406 UCHAR Reserved2[2]; // Reserved Padding 00407 REGID PartID; // Paritition Entity Identifier 00408 // == UdfSparablePartitionDomainIdentifier 00409 USHORT VolSetSeq; // Volume Set Sequence 00410 USHORT Partition; // Related Partition 00411 USHORT PacketLength; // Packet Length == 32 (number of data blocks 00412 // per packet) 00413 UCHAR NumSparingTables; // Number of pparing tables on the media 00414 UCHAR Reserved43; // Reserved Padding 00415 ULONG TableSize; // Size of sparing tables 00416 ULONG TableLocation[4]; // Location of each sparing table (each 00417 // sparing table should be in a distinct packet) 00418 00419 } PARTMAP_SPARABLE, *PPARTMAP_SPARABLE; 00420 00421 // 00422 // Sparing tables lead off with this header structure. 00423 // 00424 00425 typedef struct _SPARING_TABLE_HEADER { 00426 00427 DESTAG Destag; // Ident = 0 00428 REGID RegID; // == UdfSparingTableIdentifier 00429 USHORT TableEntries; // Number of entries in the table 00430 USHORT Reserved50; // Reserved Padding 00431 ULONG Sequence; // Sequence Number (incremented on rewrite of table) 00432 00433 } *PSPARING_TABLE_HEADER, SPARING_TABLE_HEADER; 00434 00435 // 00436 // Sparing table map entries. 00437 // 00438 00439 typedef struct _SPARING_TABLE_ENTRY { 00440 00441 ULONG Original; // Original LBN 00442 ULONG Mapped; // Mapped PSN 00443 00444 } *PSPARING_TABLE_ENTRY, SPARING_TABLE_ENTRY; 00445 00446 // 00447 // Fixed values for original sectors, indicating that either the 00448 // mapped packet is avaliable for sparing use or is defective. 00449 // 00450 00451 #define UDF_SPARING_AVALIABLE 0xffffffff 00452 #define UDF_SPARING_DEFECTIVE 0xfffffff0 00453 00454 // 00455 // The unit of media in each sparing packet is fixed at 32 physical sectors. 00456 // 00457 00458 #define UDF_SPARING_PACKET_LENGTH CDRW_PACKET_LENGTH 00459 00460 #endif // _UDF_