1 /*++ 2 3 Copyright (c) 1989-2000 Microsoft Corporation 4 5 Module Name: 6 7 Cd.h 8 9 Abstract: 10 11 This module defines the on-disk structure of the Cdfs file system. 12 13 14 --*/ 15 16 #ifndef _CDFS_ 17 #define _CDFS_ 18 19 // 20 // Sector size on Cdrom disks is hard-coded to 2048 21 // 22 23 #ifndef SECTOR_SIZE 24 #define SECTOR_SIZE (2048) 25 #endif 26 27 #define RAW_SECTOR_SIZE (2352) 28 #define SECTOR_MASK (SECTOR_SIZE - 1) 29 #define INVERSE_SECTOR_MASK ~(SECTOR_SIZE - 1) 30 31 #ifndef SECTOR_SHIFT 32 #define SECTOR_SHIFT (11) 33 #endif 34 35 #define XA_SECTOR_SIZE (2352) 36 37 // 38 // Cdfs file id is a large integer. 39 // 40 41 typedef LARGE_INTEGER FILE_ID; 42 typedef FILE_ID *PFILE_ID; 43 44 // 45 // The following constants are values from the disk. 46 // 47 48 #define FIRST_VD_SECTOR (16) 49 50 #define VOL_ID_LEN (5) 51 #define ESC_SEQ_LEN (3) 52 53 #define VERSION_1 (1) 54 55 #define VD_TERMINATOR (255) 56 #define VD_PRIMARY (1) 57 #define VD_SECONDARY (2) 58 59 #define VOLUME_ID_LENGTH (32) 60 61 // 62 // Leave the following so that CdfsBoot.c will compile 63 // 64 65 #define CD_SECTOR_SIZE (2048) 66 67 #define ISO_VOL_ID "CD001" 68 #define HSG_VOL_ID "CDROM" 69 70 #define ISO_ATTR_MULTI 0x0080 71 #define ISO_ATTR_DIRECTORY 0x0002 72 73 #define MIN_DIR_REC_SIZE (sizeof( RAW_DIR_REC ) - MAX_FILE_ID_LENGTH) 74 75 #define RVD_STD_ID( r, i ) (i ? r->StandardId : \ 76 ((PRAW_HSG_VD) r)->StandardId ) 77 78 #define RVD_DESC_TYPE( r, i ) (i ? r->DescType : \ 79 ((PRAW_HSG_VD) r)->DescType ) 80 81 #define RVD_VERSION( r, i ) (i ? r->Version : \ 82 ((PRAW_HSG_VD) r)->Version ) 83 84 #define RVD_LB_SIZE( r, i ) (i ? r->LogicalBlkSzI : \ 85 ((PRAW_HSG_VD) r)->LogicalBlkSzI ) 86 87 #define RVD_VOL_SIZE( r, i ) (i ? r->VolSpaceI : \ 88 ((PRAW_HSG_VD) r)->VolSpaceI ) 89 90 #define RVD_ROOT_DE( r, i ) (i ? r->RootDe : \ 91 ((PRAW_HSG_VD) r)->RootDe ) 92 93 #define DE_FILE_FLAGS( iso, de ) (iso ? de->FlagsISO : de->FlagsHSG) 94 95 // 96 // Data track flag for track entries in TOC 97 // 98 99 #define TOC_DATA_TRACK (0x04) 100 #define TOC_LAST_TRACK (0xaa) 101 102 103 // 104 // There is considerable rearrangement of the volume descriptors for 105 // ISO and HSG. However, within each standard the same structure can 106 // be used for both the primary and secondary descriptors. 107 // 108 // Both of these structures are aligned correctly so that no 109 // special macros will be needed to unpack them. 110 // 111 112 // 113 // Declaration of length of root directory entry in volume descriptor 114 // 115 116 #define LEN_ROOT_DE (34) 117 118 // 119 // Maximum length of file ID on the disk. We allow file size beyond the ISO 9660 120 // standard. 121 // 122 123 #define MAX_FILE_ID_LENGTH (255) 124 125 126 typedef struct _RAW_ISO_VD { 127 128 UCHAR DescType; // volume type: 1 = standard, 2 = coded 129 UCHAR StandardId[5]; // volume structure standard id = CD001 130 UCHAR Version; // volume structure version number = 1 131 UCHAR VolumeFlags; // volume flags 132 UCHAR SystemId[32]; // system identifier 133 UCHAR VolumeId[32]; // volume identifier 134 UCHAR Reserved[8]; // reserved 8 = 0 135 ULONG VolSpaceI; // size of the volume in LBN's Intel 136 ULONG VolSpaceM; // size of the volume in LBN's Motorola 137 UCHAR CharSet[32]; // character set bytes 0 = ASCII 138 USHORT VolSetSizeI; // volume set size Intel 139 USHORT VolSetSizeM; // volume set size Motorola 140 USHORT VolSeqNumI; // volume set sequence number Intel 141 USHORT VolSeqNumM; // volume set sequence number Motorola 142 USHORT LogicalBlkSzI; // logical block size Intel 143 USHORT LogicalBlkSzM; // logical block size Motorola 144 ULONG PathTableSzI; // path table size in bytes Intel 145 ULONG PathTableSzM; // path table size in bytes Motorola 146 ULONG PathTabLocI[2]; // LBN of 2 path tables Intel 147 ULONG PathTabLocM[2]; // LBN of 2 path tables Motorola 148 UCHAR RootDe[LEN_ROOT_DE];// dir entry of the root directory 149 UCHAR VolSetId[128]; // volume set identifier 150 UCHAR PublId[128]; // publisher identifier 151 UCHAR PreparerId[128]; // data preparer identifier 152 UCHAR AppId[128]; // application identifier 153 UCHAR Copyright[37]; // file name of copyright notice 154 UCHAR Abstract[37]; // file name of abstract 155 UCHAR Bibliograph[37]; // file name of bibliography 156 UCHAR CreateDate[17]; // volume creation date and time 157 UCHAR ModDate[17]; // volume modification date and time 158 UCHAR ExpireDate[17]; // volume expiration date and time 159 UCHAR EffectDate[17]; // volume effective date and time 160 UCHAR FileStructVer; // file structure version number = 1 161 UCHAR Reserved3; // reserved 162 UCHAR ResApp[512]; // reserved for application 163 UCHAR Reserved4[653]; // remainder of 2048 bytes reserved 164 165 } RAW_ISO_VD; 166 typedef RAW_ISO_VD *PRAW_ISO_VD; 167 168 169 typedef struct _RAW_HSG_VD { 170 171 ULONG BlkNumI; // logical block number Intel 172 ULONG BlkNumM; // logical block number Motorola 173 UCHAR DescType; // volume type: 1 = standard, 2 = coded 174 UCHAR StandardId[5]; // volume structure standard id = CDROM 175 UCHAR Version; // volume structure version number = 1 176 UCHAR VolumeFlags; // volume flags 177 UCHAR SystemId[32]; // system identifier 178 UCHAR VolumeId[32]; // volume identifier 179 UCHAR Reserved[8]; // reserved 8 = 0 180 ULONG VolSpaceI; // size of the volume in LBN's Intel 181 ULONG VolSpaceM; // size of the volume in LBN's Motorola 182 UCHAR CharSet[32]; // character set bytes 0 = ASCII 183 USHORT VolSetSizeI; // volume set size Intel 184 USHORT VolSetSizeM; // volume set size Motorola 185 USHORT VolSeqNumI; // volume set sequence number Intel 186 USHORT VolSeqNumM; // volume set sequence number Motorola 187 USHORT LogicalBlkSzI; // logical block size Intel 188 USHORT LogicalBlkSzM; // logical block size Motorola 189 ULONG PathTableSzI; // path table size in bytes Intel 190 ULONG PathTableSzM; // path table size in bytes Motorola 191 ULONG PathTabLocI[4]; // LBN of 4 path tables Intel 192 ULONG PathTabLocM[4]; // LBN of 4 path tables Motorola 193 UCHAR RootDe[LEN_ROOT_DE];// dir entry of the root directory 194 UCHAR VolSetId[128]; // volume set identifier 195 UCHAR PublId[128]; // publisher identifier 196 UCHAR PreparerId[128]; // data preparer identifier 197 UCHAR AppId[128]; // application identifier 198 UCHAR Copyright[32]; // file name of copyright notice 199 UCHAR Abstract[32]; // file name of abstract 200 UCHAR CreateDate[16]; // volume creation date and time 201 UCHAR ModDate[16]; // volume modification date and time 202 UCHAR ExpireDate[16]; // volume expiration date and time 203 UCHAR EffectDate[16]; // volume effective date and time 204 UCHAR FileStructVer; // file structure version number 205 UCHAR Reserved3; // reserved 206 UCHAR ResApp[512]; // reserved for application 207 UCHAR Reserved4[680]; // remainder of 2048 bytes reserved 208 209 } RAW_HSG_VD; 210 typedef RAW_HSG_VD *PRAW_HSG_VD; 211 212 213 typedef struct _RAW_JOLIET_VD { 214 215 UCHAR DescType; // volume type: 2 = coded 216 UCHAR StandardId[5]; // volume structure standard id = CD001 217 UCHAR Version; // volume structure version number = 1 218 UCHAR VolumeFlags; // volume flags 219 UCHAR SystemId[32]; // system identifier 220 UCHAR VolumeId[32]; // volume identifier 221 UCHAR Reserved[8]; // reserved 8 = 0 222 ULONG VolSpaceI; // size of the volume in LBN's Intel 223 ULONG VolSpaceM; // size of the volume in LBN's Motorola 224 UCHAR CharSet[32]; // character set bytes 0 = ASCII, Joliett Seq here 225 USHORT VolSetSizeI; // volume set size Intel 226 USHORT VolSetSizeM; // volume set size Motorola 227 USHORT VolSeqNumI; // volume set sequence number Intel 228 USHORT VolSeqNumM; // volume set sequence number Motorola 229 USHORT LogicalBlkSzI; // logical block size Intel 230 USHORT LogicalBlkSzM; // logical block size Motorola 231 ULONG PathTableSzI; // path table size in bytes Intel 232 ULONG PathTableSzM; // path table size in bytes Motorola 233 ULONG PathTabLocI[2]; // LBN of 2 path tables Intel 234 ULONG PathTabLocM[2]; // LBN of 2 path tables Motorola 235 UCHAR RootDe[LEN_ROOT_DE];// dir entry of the root directory 236 UCHAR VolSetId[128]; // volume set identifier 237 UCHAR PublId[128]; // publisher identifier 238 UCHAR PreparerId[128]; // data preparer identifier 239 UCHAR AppId[128]; // application identifier 240 UCHAR Copyright[37]; // file name of copyright notice 241 UCHAR Abstract[37]; // file name of abstract 242 UCHAR Bibliograph[37]; // file name of bibliography 243 UCHAR CreateDate[17]; // volume creation date and time 244 UCHAR ModDate[17]; // volume modification date and time 245 UCHAR ExpireDate[17]; // volume expiration date and time 246 UCHAR EffectDate[17]; // volume effective date and time 247 UCHAR FileStructVer; // file structure version number = 1 248 UCHAR Reserved3; // reserved 249 UCHAR ResApp[512]; // reserved for application 250 UCHAR Reserved4[653]; // remainder of 2048 bytes reserved 251 252 } RAW_JOLIET_VD; 253 typedef RAW_JOLIET_VD *PRAW_JOLIET_VD; 254 255 // 256 // Macros to access the different volume descriptors. 257 // 258 259 #define CdRvdId(R,F) ( \ 260 FlagOn( (F), VCB_STATE_HSG ) ? \ 261 ((PRAW_HSG_VD) (R))->StandardId : \ 262 ((PRAW_ISO_VD) (R))->StandardId \ 263 ) 264 265 #define CdRvdVersion(R,F) ( \ 266 FlagOn( (F), VCB_STATE_HSG ) ? \ 267 ((PRAW_HSG_VD) (R))->Version : \ 268 ((PRAW_ISO_VD) (R))->Version \ 269 ) 270 271 #define CdRvdDescType(R,F) ( \ 272 FlagOn( (F), VCB_STATE_HSG ) ? \ 273 ((PRAW_HSG_VD) (R))->DescType : \ 274 ((PRAW_ISO_VD) (R))->DescType \ 275 ) 276 277 #define CdRvdEsc(R,F) ( \ 278 FlagOn( (F), VCB_STATE_HSG ) ? \ 279 ((PRAW_HSG_VD) (R))->CharSet : \ 280 ((PRAW_ISO_VD) (R))->CharSet \ 281 ) 282 283 #define CdRvdVolId(R,F) ( \ 284 FlagOn( (F), VCB_STATE_HSG ) ? \ 285 ((PRAW_HSG_VD) (R))->VolumeId : \ 286 ((PRAW_ISO_VD) (R))->VolumeId \ 287 ) 288 289 #define CdRvdBlkSz(R,F) ( \ 290 FlagOn( (F), VCB_STATE_HSG ) ? \ 291 ((PRAW_HSG_VD) (R))->LogicalBlkSzI :\ 292 ((PRAW_ISO_VD) (R))->LogicalBlkSzI \ 293 ) 294 295 #define CdRvdPtLoc(R,F) ( \ 296 FlagOn( (F), VCB_STATE_HSG ) ? \ 297 ((PRAW_HSG_VD) (R))->PathTabLocI[0]:\ 298 ((PRAW_ISO_VD) (R))->PathTabLocI[0] \ 299 ) 300 301 #define CdRvdPtSz(R,F) ( \ 302 FlagOn( (F), VCB_STATE_HSG ) ? \ 303 ((PRAW_HSG_VD) (R))->PathTableSzI : \ 304 ((PRAW_ISO_VD) (R))->PathTableSzI \ 305 ) 306 307 #define CdRvdDirent(R,F) ( \ 308 FlagOn( (F), VCB_STATE_HSG ) ? \ 309 ((PRAW_HSG_VD) (R))->RootDe : \ 310 ((PRAW_ISO_VD) (R))->RootDe \ 311 ) 312 313 #define CdRvdVolSz(R,F) ( \ 314 FlagOn( (F), VCB_STATE_HSG ) ? \ 315 ((PRAW_HSG_VD) (R))->VolSpaceI : \ 316 ((PRAW_ISO_VD) (R))->VolSpaceI \ 317 ) 318 319 320 // 321 // This structure is used to overlay a region of a disk sector 322 // to retrieve a single directory entry. There is a difference 323 // in the file flags between the ISO and HSG version and a 324 // additional byte in the ISO for the offset from Greenwich time. 325 // 326 // The disk structure is aligned on a word boundary, so any 32 327 // bit fields will be represented as an array of 16 bit fields. 328 // 329 330 typedef struct _RAW_DIRENT { 331 332 UCHAR DirLen; 333 UCHAR XarLen; 334 UCHAR FileLoc[4]; 335 UCHAR FileLocMot[4]; 336 UCHAR DataLen[4]; 337 UCHAR DataLenMot[4]; 338 UCHAR RecordTime[6]; 339 UCHAR FlagsHSG; 340 UCHAR FlagsISO; 341 UCHAR IntLeaveSize; 342 UCHAR IntLeaveSkip; 343 UCHAR Vssn[2]; 344 UCHAR VssnMot[2]; 345 UCHAR FileIdLen; 346 UCHAR FileId[MAX_FILE_ID_LENGTH]; 347 348 } RAW_DIRENT; 349 typedef RAW_DIRENT RAW_DIR_REC; 350 typedef RAW_DIRENT *PRAW_DIR_REC; 351 typedef RAW_DIRENT *PRAW_DIRENT; 352 353 #define CD_ATTRIBUTE_HIDDEN (0x01) 354 #define CD_ATTRIBUTE_DIRECTORY (0x02) 355 #define CD_ATTRIBUTE_ASSOC (0x04) 356 #define CD_ATTRIBUTE_MULTI (0x80) 357 358 #define CD_BASE_YEAR (1900) 359 360 #define MIN_RAW_DIRENT_LEN (FIELD_OFFSET( RAW_DIRENT, FileId ) + 1) 361 362 #define BYTE_COUNT_8_DOT_3 (24) 363 364 #define SHORT_NAME_SHIFT (5) 365 366 // 367 // The following macro recovers the correct flag field. 368 // 369 370 #define CdRawDirentFlags(IC,RD) ( \ 371 FlagOn( (IC)->Vcb->VcbState, VCB_STATE_HSG) ? \ 372 (RD)->FlagsHSG : \ 373 (RD)->FlagsISO \ 374 ) 375 376 // 377 // The following macro converts from CD time to NT time. On ISO 378 // 9660 media, we now pay attention to the GMT offset (integer 379 // increments of 15 minutes offset from GMT). HSG does not record 380 // this field. 381 // 382 // The restriction to the interval [-48, 52] comes from 9660 8.4.26.1 383 // 384 // VOID 385 // CdConvertCdTimeToNtTime ( 386 // _In_ PIRP_CONTEXT IrpContext, 387 // _In_ PCHAR CdTime, 388 // _Out_ PLARGE_INTEGER NtTime 389 // ); 390 // 391 392 #define GMT_OFFSET_TO_NT ((LONGLONG) 15 * 60 * 1000 * 1000 * 10) 393 394 #define CdConvertCdTimeToNtTime(IC,CD,NT) { \ 395 TIME_FIELDS _TimeField; \ 396 CHAR GmtOffset; \ 397 _TimeField.Year = (CSHORT) *((PCHAR) CD) + CD_BASE_YEAR; \ 398 _TimeField.Month = (CSHORT) *(Add2Ptr( CD, 1, PCHAR )); \ 399 _TimeField .Day = (CSHORT) *(Add2Ptr( CD, 2, PCHAR )); \ 400 _TimeField.Hour = (CSHORT) *(Add2Ptr( CD, 3, PCHAR )); \ 401 _TimeField.Minute = (CSHORT) *(Add2Ptr( CD, 4, PCHAR )); \ 402 _TimeField.Second = (CSHORT) *(Add2Ptr( CD, 5, PCHAR )); \ 403 _TimeField.Milliseconds = (CSHORT) 0; \ 404 RtlTimeFieldsToTime( &_TimeField, NT ); \ 405 if (!FlagOn((IC)->Vcb->VcbState, VCB_STATE_HSG) && \ 406 ((GmtOffset = *(Add2Ptr( CD, 6, PCHAR ))) != 0 ) && \ 407 (GmtOffset >= -48 && GmtOffset <= 52)) { \ 408 (NT)->QuadPart += -GmtOffset * GMT_OFFSET_TO_NT; \ 409 } \ 410 } 411 412 413 // 414 // The on-disk representation of a Path Table entry differs between 415 // the ISO version and the HSG version. The fields are the same 416 // and the same size, but the positions are different. 417 // 418 419 typedef struct _RAW_PATH_ISO { 420 421 UCHAR DirIdLen; 422 UCHAR XarLen; 423 USHORT DirLoc[2]; 424 USHORT ParentNum; 425 UCHAR DirId[MAX_FILE_ID_LENGTH]; 426 427 } RAW_PATH_ISO; 428 typedef RAW_PATH_ISO *PRAW_PATH_ISO; 429 typedef RAW_PATH_ISO RAW_PATH_ENTRY; 430 typedef RAW_PATH_ISO *PRAW_PATH_ENTRY; 431 432 typedef struct _RAW_PATH_HSG { 433 434 USHORT DirLoc[2]; 435 UCHAR XarLen; 436 UCHAR DirIdLen; 437 USHORT ParentNum; 438 UCHAR DirId[MAX_FILE_ID_LENGTH]; 439 440 } RAW_PATH_HSG; 441 typedef RAW_PATH_HSG *PRAW_PATH_HSG; 442 443 #define MIN_RAW_PATH_ENTRY_LEN (FIELD_OFFSET( RAW_PATH_ENTRY, DirId ) + 1) 444 445 // 446 // The following macros are used to recover the different fields of the 447 // Path Table entries. The macro to recover the disk location of the 448 // directory must copy it into a different variable for alignment reasons. 449 // 450 // CdRawPathIdLen - Length of directory name in bytes 451 // CdRawPathXar - Number of Xar blocks 452 // CdRawPathLoc - Address of unaligned ulong for disk offset in blocks 453 // 454 455 #define CdRawPathIdLen(IC, RP) ( \ 456 FlagOn( (IC)->Vcb->VcbState, VCB_STATE_HSG ) ? \ 457 ((PRAW_PATH_HSG) (RP))->DirIdLen : \ 458 (RP)->DirIdLen \ 459 ) 460 461 #define CdRawPathXar(IC, RP) ( \ 462 FlagOn( (IC)->Vcb->VcbState, VCB_STATE_HSG ) ? \ 463 ((PRAW_PATH_HSG) (RP))->XarLen : \ 464 (RP)->XarLen \ 465 ) 466 467 #define CdRawPathLoc(IC, RP) ( \ 468 FlagOn( (IC)->Vcb->VcbState, VCB_STATE_HSG ) ? \ 469 ((PRAW_PATH_HSG) (RP))->DirLoc : \ 470 (RP)->DirLoc \ 471 ) 472 473 474 // 475 // System use are for XA data. The following is the system use area for 476 // directory entries on XA data disks. 477 // 478 479 typedef struct _SYSTEM_USE_XA { 480 481 // 482 // Owner ID. Not used in this version. 483 // 484 485 UCHAR OwnerId[4]; 486 487 // 488 // Extent attributes. Only interested if mode2 form2 or digital audio. 489 // This is stored big endian. We will define the attribute flags so 490 // we can ignore this fact. 491 // 492 493 USHORT Attributes; 494 495 // 496 // XA signature. This value must be 'XA'. 497 // 498 499 USHORT Signature; 500 501 // 502 // File Number. 503 // 504 505 UCHAR FileNumber; 506 507 // 508 // Not used in this version. 509 // 510 511 UCHAR Reserved[5]; 512 513 } SYSTEM_USE_XA; 514 typedef SYSTEM_USE_XA *PSYSTEM_USE_XA; 515 516 #define SYSTEM_USE_XA_FORM1 (0x0008) 517 #define SYSTEM_USE_XA_FORM2 (0x0010) 518 #define SYSTEM_USE_XA_DA (0x0040) 519 520 #define SYSTEM_XA_SIGNATURE (0x4158) 521 522 typedef enum _XA_EXTENT_TYPE { 523 524 Form1Data = 0, 525 Mode2Form2Data, 526 CDAudio 527 528 } XA_EXTENT_TYPE; 529 typedef XA_EXTENT_TYPE *PXA_EXTENT_TYPE; 530 531 #endif // _CDFS_ 532 533 534 535