3 Copyright (c) 1989-2000 Microsoft Corporation
11 This module defines the on-disk structure of the Cdfs file system.
20 // Sector size on Cdrom disks is hard-coded to 2048
24 #define SECTOR_SIZE (2048)
27 #define RAW_SECTOR_SIZE (2352)
28 #define SECTOR_MASK (SECTOR_SIZE - 1)
29 #define INVERSE_SECTOR_MASK ~(SECTOR_SIZE - 1)
32 #define SECTOR_SHIFT (11)
35 #define XA_SECTOR_SIZE (2352)
38 // Cdfs file id is a large integer.
41 typedef LARGE_INTEGER FILE_ID
;
42 typedef FILE_ID
*PFILE_ID
;
45 // The following constants are values from the disk.
48 #define FIRST_VD_SECTOR (16)
50 #define VOL_ID_LEN (5)
51 #define ESC_SEQ_LEN (3)
55 #define VD_TERMINATOR (255)
56 #define VD_PRIMARY (1)
57 #define VD_SECONDARY (2)
59 #define VOLUME_ID_LENGTH (32)
62 // Leave the following so that CdfsBoot.c will compile
65 #define CD_SECTOR_SIZE (2048)
67 #define ISO_VOL_ID "CD001"
68 #define HSG_VOL_ID "CDROM"
70 #define ISO_ATTR_MULTI 0x0080
71 #define ISO_ATTR_DIRECTORY 0x0002
73 #define MIN_DIR_REC_SIZE (sizeof( RAW_DIR_REC ) - MAX_FILE_ID_LENGTH)
75 #define RVD_STD_ID( r, i ) (i ? r->StandardId : \
76 ((PRAW_HSG_VD) r)->StandardId )
78 #define RVD_DESC_TYPE( r, i ) (i ? r->DescType : \
79 ((PRAW_HSG_VD) r)->DescType )
81 #define RVD_VERSION( r, i ) (i ? r->Version : \
82 ((PRAW_HSG_VD) r)->Version )
84 #define RVD_LB_SIZE( r, i ) (i ? r->LogicalBlkSzI : \
85 ((PRAW_HSG_VD) r)->LogicalBlkSzI )
87 #define RVD_VOL_SIZE( r, i ) (i ? r->VolSpaceI : \
88 ((PRAW_HSG_VD) r)->VolSpaceI )
90 #define RVD_ROOT_DE( r, i ) (i ? r->RootDe : \
91 ((PRAW_HSG_VD) r)->RootDe )
93 #define DE_FILE_FLAGS( iso, de ) (iso ? de->FlagsISO : de->FlagsHSG)
96 // Data track flag for track entries in TOC
99 #define TOC_DATA_TRACK (0x04)
100 #define TOC_LAST_TRACK (0xaa)
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.
108 // Both of these structures are aligned correctly so that no
109 // special macros will be needed to unpack them.
113 // Declaration of length of root directory entry in volume descriptor
116 #define LEN_ROOT_DE (34)
119 // Maximum length of file ID on the disk. We allow file size beyond the ISO 9660
123 #define MAX_FILE_ID_LENGTH (255)
126 typedef struct _RAW_ISO_VD
{
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
166 typedef RAW_ISO_VD
*PRAW_ISO_VD
;
169 typedef struct _RAW_HSG_VD
{
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
210 typedef RAW_HSG_VD
*PRAW_HSG_VD
;
213 typedef struct _RAW_JOLIET_VD
{
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, Joliet 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
253 typedef RAW_JOLIET_VD
*PRAW_JOLIET_VD
;
256 // Macros to access the different volume descriptors.
259 #define CdRvdId(R,F) ( \
260 FlagOn( (F), VCB_STATE_HSG ) ? \
261 ((PRAW_HSG_VD) (R))->StandardId : \
262 ((PRAW_ISO_VD) (R))->StandardId \
265 #define CdRvdVersion(R,F) ( \
266 FlagOn( (F), VCB_STATE_HSG ) ? \
267 ((PRAW_HSG_VD) (R))->Version : \
268 ((PRAW_ISO_VD) (R))->Version \
271 #define CdRvdDescType(R,F) ( \
272 FlagOn( (F), VCB_STATE_HSG ) ? \
273 ((PRAW_HSG_VD) (R))->DescType : \
274 ((PRAW_ISO_VD) (R))->DescType \
277 #define CdRvdEsc(R,F) ( \
278 FlagOn( (F), VCB_STATE_HSG ) ? \
279 ((PRAW_HSG_VD) (R))->CharSet : \
280 ((PRAW_ISO_VD) (R))->CharSet \
283 #define CdRvdVolId(R,F) ( \
284 FlagOn( (F), VCB_STATE_HSG ) ? \
285 ((PRAW_HSG_VD) (R))->VolumeId : \
286 ((PRAW_ISO_VD) (R))->VolumeId \
289 #define CdRvdBlkSz(R,F) ( \
290 FlagOn( (F), VCB_STATE_HSG ) ? \
291 ((PRAW_HSG_VD) (R))->LogicalBlkSzI :\
292 ((PRAW_ISO_VD) (R))->LogicalBlkSzI \
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] \
301 #define CdRvdPtSz(R,F) ( \
302 FlagOn( (F), VCB_STATE_HSG ) ? \
303 ((PRAW_HSG_VD) (R))->PathTableSzI : \
304 ((PRAW_ISO_VD) (R))->PathTableSzI \
307 #define CdRvdDirent(R,F) ( \
308 FlagOn( (F), VCB_STATE_HSG ) ? \
309 ((PRAW_HSG_VD) (R))->RootDe : \
310 ((PRAW_ISO_VD) (R))->RootDe \
313 #define CdRvdVolSz(R,F) ( \
314 FlagOn( (F), VCB_STATE_HSG ) ? \
315 ((PRAW_HSG_VD) (R))->VolSpaceI : \
316 ((PRAW_ISO_VD) (R))->VolSpaceI \
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.
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.
330 typedef struct _RAW_DIRENT
{
346 UCHAR FileId
[MAX_FILE_ID_LENGTH
];
349 typedef RAW_DIRENT RAW_DIR_REC
;
350 typedef RAW_DIRENT
*PRAW_DIR_REC
;
351 typedef RAW_DIRENT
*PRAW_DIRENT
;
353 #define CD_ATTRIBUTE_HIDDEN (0x01)
354 #define CD_ATTRIBUTE_DIRECTORY (0x02)
355 #define CD_ATTRIBUTE_ASSOC (0x04)
356 #define CD_ATTRIBUTE_MULTI (0x80)
358 #define CD_BASE_YEAR (1900)
360 #define MIN_RAW_DIRENT_LEN (FIELD_OFFSET( RAW_DIRENT, FileId ) + 1)
362 #define BYTE_COUNT_8_DOT_3 (24)
364 #define SHORT_NAME_SHIFT (5)
367 // The following macro recovers the correct flag field.
370 #define CdRawDirentFlags(IC,RD) ( \
371 FlagOn( (IC)->Vcb->VcbState, VCB_STATE_HSG) ? \
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
382 // The restriction to the interval [-48, 52] comes from 9660 8.4.26.1
385 // CdConvertCdTimeToNtTime (
386 // IN PIRP_CONTEXT IrpContext,
388 // OUT PLARGE_INTEGER NtTime
392 #define GMT_OFFSET_TO_NT ((LONGLONG) 15 * 60 * 1000 * 1000 * 10)
394 #define CdConvertCdTimeToNtTime(IC,CD,NT) { \
395 TIME_FIELDS _TimeField; \
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; \
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.
419 typedef struct _RAW_PATH_ISO
{
425 UCHAR DirId
[MAX_FILE_ID_LENGTH
];
428 typedef RAW_PATH_ISO
*PRAW_PATH_ISO
;
429 typedef RAW_PATH_ISO RAW_PATH_ENTRY
;
430 typedef RAW_PATH_ISO
*PRAW_PATH_ENTRY
;
432 typedef struct _RAW_PATH_HSG
{
438 UCHAR DirId
[MAX_FILE_ID_LENGTH
];
441 typedef RAW_PATH_HSG
*PRAW_PATH_HSG
;
443 #define MIN_RAW_PATH_ENTRY_LEN (FIELD_OFFSET( RAW_PATH_ENTRY, DirId ) + 1)
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.
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
455 #define CdRawPathIdLen(IC, RP) ( \
456 FlagOn( (IC)->Vcb->VcbState, VCB_STATE_HSG ) ? \
457 ((PRAW_PATH_HSG) (RP))->DirIdLen : \
461 #define CdRawPathXar(IC, RP) ( \
462 FlagOn( (IC)->Vcb->VcbState, VCB_STATE_HSG ) ? \
463 ((PRAW_PATH_HSG) (RP))->XarLen : \
467 #define CdRawPathLoc(IC, RP) ( \
468 FlagOn( (IC)->Vcb->VcbState, VCB_STATE_HSG ) ? \
469 ((PRAW_PATH_HSG) (RP))->DirLoc : \
475 // System use are for XA data. The following is the system use area for
476 // directory entries on XA data disks.
479 typedef struct _SYSTEM_USE_XA
{
482 // Owner ID. Not used in this version.
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.
496 // XA signature. This value must be 'XA'.
508 // Not used in this version.
514 typedef SYSTEM_USE_XA
*PSYSTEM_USE_XA
;
516 #define SYSTEM_USE_XA_FORM1 (0x0008)
517 #define SYSTEM_USE_XA_FORM2 (0x0010)
518 #define SYSTEM_USE_XA_DA (0x0040)
520 #define SYSTEM_XA_SIGNATURE (0x4158)
522 typedef enum _XA_EXTENT_TYPE
{
529 typedef XA_EXTENT_TYPE
*PXA_EXTENT_TYPE
;