Leaked source code of windows server 2003
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.

542 lines
19 KiB

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