hpfs.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /*
  2. * linux/fs/hpfs/hpfs.h
  3. *
  4. * HPFS structures by Chris Smith, 1993
  5. *
  6. * a little bit modified by Mikulas Patocka, 1998-1999
  7. */
  8. /* The paper
  9. Duncan, Roy
  10. Design goals and implementation of the new High Performance File System
  11. Microsoft Systems Journal Sept 1989 v4 n5 p1(13)
  12. describes what HPFS looked like when it was new, and it is the source
  13. of most of the information given here. The rest is conjecture.
  14. For definitive information on the Duncan paper, see it, not this file.
  15. For definitive information on HPFS, ask somebody else -- this is guesswork.
  16. There are certain to be many mistakes. */
  17. #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
  18. #error unknown endian
  19. #endif
  20. /* Notation */
  21. typedef u32 secno; /* sector number, partition relative */
  22. typedef secno dnode_secno; /* sector number of a dnode */
  23. typedef secno fnode_secno; /* sector number of an fnode */
  24. typedef secno anode_secno; /* sector number of an anode */
  25. typedef u32 time32_t; /* 32-bit time_t type */
  26. /* sector 0 */
  27. /* The boot block is very like a FAT boot block, except that the
  28. 29h signature byte is 28h instead, and the ID string is "HPFS". */
  29. #define BB_MAGIC 0xaa55
  30. struct hpfs_boot_block
  31. {
  32. u8 jmp[3];
  33. u8 oem_id[8];
  34. u8 bytes_per_sector[2]; /* 512 */
  35. u8 sectors_per_cluster;
  36. u8 n_reserved_sectors[2];
  37. u8 n_fats;
  38. u8 n_rootdir_entries[2];
  39. u8 n_sectors_s[2];
  40. u8 media_byte;
  41. __le16 sectors_per_fat;
  42. __le16 sectors_per_track;
  43. __le16 heads_per_cyl;
  44. __le32 n_hidden_sectors;
  45. __le32 n_sectors_l; /* size of partition */
  46. u8 drive_number;
  47. u8 mbz;
  48. u8 sig_28h; /* 28h */
  49. u8 vol_serno[4];
  50. u8 vol_label[11];
  51. u8 sig_hpfs[8]; /* "HPFS " */
  52. u8 pad[448];
  53. __le16 magic; /* aa55 */
  54. };
  55. /* sector 16 */
  56. /* The super block has the pointer to the root directory. */
  57. #define SB_MAGIC 0xf995e849
  58. struct hpfs_super_block
  59. {
  60. __le32 magic; /* f995 e849 */
  61. __le32 magic1; /* fa53 e9c5, more magic? */
  62. u8 version; /* version of a filesystem usually 2 */
  63. u8 funcversion; /* functional version - oldest version
  64. of filesystem that can understand
  65. this disk */
  66. __le16 zero; /* 0 */
  67. __le32 root; /* fnode of root directory */
  68. __le32 n_sectors; /* size of filesystem */
  69. __le32 n_badblocks; /* number of bad blocks */
  70. __le32 bitmaps; /* pointers to free space bit maps */
  71. __le32 zero1; /* 0 */
  72. __le32 badblocks; /* bad block list */
  73. __le32 zero3; /* 0 */
  74. __le32 last_chkdsk; /* date last checked, 0 if never */
  75. __le32 last_optimize; /* date last optimized, 0 if never */
  76. __le32 n_dir_band; /* number of sectors in dir band */
  77. __le32 dir_band_start; /* first sector in dir band */
  78. __le32 dir_band_end; /* last sector in dir band */
  79. __le32 dir_band_bitmap; /* free space map, 1 dnode per bit */
  80. u8 volume_name[32]; /* not used */
  81. __le32 user_id_table; /* 8 preallocated sectors - user id */
  82. u32 zero6[103]; /* 0 */
  83. };
  84. /* sector 17 */
  85. /* The spare block has pointers to spare sectors. */
  86. #define SP_MAGIC 0xf9911849
  87. struct hpfs_spare_block
  88. {
  89. __le32 magic; /* f991 1849 */
  90. __le32 magic1; /* fa52 29c5, more magic? */
  91. #ifdef __LITTLE_ENDIAN
  92. u8 dirty: 1; /* 0 clean, 1 "improperly stopped" */
  93. u8 sparedir_used: 1; /* spare dirblks used */
  94. u8 hotfixes_used: 1; /* hotfixes used */
  95. u8 bad_sector: 1; /* bad sector, corrupted disk (???) */
  96. u8 bad_bitmap: 1; /* bad bitmap */
  97. u8 fast: 1; /* partition was fast formatted */
  98. u8 old_wrote: 1; /* old version wrote to partion */
  99. u8 old_wrote_1: 1; /* old version wrote to partion (?) */
  100. #else
  101. u8 old_wrote_1: 1; /* old version wrote to partion (?) */
  102. u8 old_wrote: 1; /* old version wrote to partion */
  103. u8 fast: 1; /* partition was fast formatted */
  104. u8 bad_bitmap: 1; /* bad bitmap */
  105. u8 bad_sector: 1; /* bad sector, corrupted disk (???) */
  106. u8 hotfixes_used: 1; /* hotfixes used */
  107. u8 sparedir_used: 1; /* spare dirblks used */
  108. u8 dirty: 1; /* 0 clean, 1 "improperly stopped" */
  109. #endif
  110. #ifdef __LITTLE_ENDIAN
  111. u8 install_dasd_limits: 1; /* HPFS386 flags */
  112. u8 resynch_dasd_limits: 1;
  113. u8 dasd_limits_operational: 1;
  114. u8 multimedia_active: 1;
  115. u8 dce_acls_active: 1;
  116. u8 dasd_limits_dirty: 1;
  117. u8 flag67: 2;
  118. #else
  119. u8 flag67: 2;
  120. u8 dasd_limits_dirty: 1;
  121. u8 dce_acls_active: 1;
  122. u8 multimedia_active: 1;
  123. u8 dasd_limits_operational: 1;
  124. u8 resynch_dasd_limits: 1;
  125. u8 install_dasd_limits: 1; /* HPFS386 flags */
  126. #endif
  127. u8 mm_contlgulty;
  128. u8 unused;
  129. __le32 hotfix_map; /* info about remapped bad sectors */
  130. __le32 n_spares_used; /* number of hotfixes */
  131. __le32 n_spares; /* number of spares in hotfix map */
  132. __le32 n_dnode_spares_free; /* spare dnodes unused */
  133. __le32 n_dnode_spares; /* length of spare_dnodes[] list,
  134. follows in this block*/
  135. __le32 code_page_dir; /* code page directory block */
  136. __le32 n_code_pages; /* number of code pages */
  137. __le32 super_crc; /* on HPFS386 and LAN Server this is
  138. checksum of superblock, on normal
  139. OS/2 unused */
  140. __le32 spare_crc; /* on HPFS386 checksum of spareblock */
  141. __le32 zero1[15]; /* unused */
  142. __le32 spare_dnodes[100]; /* emergency free dnode list */
  143. __le32 zero2[1]; /* room for more? */
  144. };
  145. /* The bad block list is 4 sectors long. The first word must be zero,
  146. the remaining words give n_badblocks bad block numbers.
  147. I bet you can see it coming... */
  148. #define BAD_MAGIC 0
  149. /* The hotfix map is 4 sectors long. It looks like
  150. secno from[n_spares];
  151. secno to[n_spares];
  152. The to[] list is initialized to point to n_spares preallocated empty
  153. sectors. The from[] list contains the sector numbers of bad blocks
  154. which have been remapped to corresponding sectors in the to[] list.
  155. n_spares_used gives the length of the from[] list. */
  156. /* Sectors 18 and 19 are preallocated and unused.
  157. Maybe they're spares for 16 and 17, but simple substitution fails. */
  158. /* The code page info pointed to by the spare block consists of an index
  159. block and blocks containing uppercasing tables. I don't know what
  160. these are for (CHKDSK, maybe?) -- OS/2 does not seem to use them
  161. itself. Linux doesn't use them either. */
  162. /* block pointed to by spareblock->code_page_dir */
  163. #define CP_DIR_MAGIC 0x494521f7
  164. struct code_page_directory
  165. {
  166. __le32 magic; /* 4945 21f7 */
  167. __le32 n_code_pages; /* number of pointers following */
  168. __le32 zero1[2];
  169. struct {
  170. __le16 ix; /* index */
  171. __le16 code_page_number; /* code page number */
  172. __le32 bounds; /* matches corresponding word
  173. in data block */
  174. __le32 code_page_data; /* sector number of a code_page_data
  175. containing c.p. array */
  176. __le16 index; /* index in c.p. array in that sector*/
  177. __le16 unknown; /* some unknown value; usually 0;
  178. 2 in Japanese version */
  179. } array[31]; /* unknown length */
  180. };
  181. /* blocks pointed to by code_page_directory */
  182. #define CP_DATA_MAGIC 0x894521f7
  183. struct code_page_data
  184. {
  185. __le32 magic; /* 8945 21f7 */
  186. __le32 n_used; /* # elements used in c_p_data[] */
  187. __le32 bounds[3]; /* looks a bit like
  188. (beg1,end1), (beg2,end2)
  189. one byte each */
  190. __le16 offs[3]; /* offsets from start of sector
  191. to start of c_p_data[ix] */
  192. struct {
  193. __le16 ix; /* index */
  194. __le16 code_page_number; /* code page number */
  195. __le16 unknown; /* the same as in cp directory */
  196. u8 map[128]; /* upcase table for chars 80..ff */
  197. __le16 zero2;
  198. } code_page[3];
  199. u8 incognita[78];
  200. };
  201. /* Free space bitmaps are 4 sectors long, which is 16384 bits.
  202. 16384 sectors is 8 meg, and each 8 meg band has a 4-sector bitmap.
  203. Bit order in the maps is little-endian. 0 means taken, 1 means free.
  204. Bit map sectors are marked allocated in the bit maps, and so are sectors
  205. off the end of the partition.
  206. Band 0 is sectors 0-3fff, its map is in sectors 18-1b.
  207. Band 1 is 4000-7fff, its map is in 7ffc-7fff.
  208. Band 2 is 8000-ffff, its map is in 8000-8003.
  209. The remaining bands have maps in their first (even) or last (odd) 4 sectors
  210. -- if the last, partial, band is odd its map is in its last 4 sectors.
  211. The bitmap locations are given in a table pointed to by the super block.
  212. No doubt they aren't constrained to be at 18, 7ffc, 8000, ...; that is
  213. just where they usually are.
  214. The "directory band" is a bunch of sectors preallocated for dnodes.
  215. It has a 4-sector free space bitmap of its own. Each bit in the map
  216. corresponds to one 4-sector dnode, bit 0 of the map corresponding to
  217. the first 4 sectors of the directory band. The entire band is marked
  218. allocated in the main bitmap. The super block gives the locations
  219. of the directory band and its bitmap. ("band" doesn't mean it is
  220. 8 meg long; it isn't.) */
  221. /* dnode: directory. 4 sectors long */
  222. /* A directory is a tree of dnodes. The fnode for a directory
  223. contains one pointer, to the root dnode of the tree. The fnode
  224. never moves, the dnodes do the B-tree thing, splitting and merging
  225. as files are added and removed. */
  226. #define DNODE_MAGIC 0x77e40aae
  227. struct dnode {
  228. __le32 magic; /* 77e4 0aae */
  229. __le32 first_free; /* offset from start of dnode to
  230. first free dir entry */
  231. #ifdef __LITTLE_ENDIAN
  232. u8 root_dnode: 1; /* Is it root dnode? */
  233. u8 increment_me: 7; /* some kind of activity counter? */
  234. /* Neither HPFS.IFS nor CHKDSK cares
  235. if you change this word */
  236. #else
  237. u8 increment_me: 7; /* some kind of activity counter? */
  238. /* Neither HPFS.IFS nor CHKDSK cares
  239. if you change this word */
  240. u8 root_dnode: 1; /* Is it root dnode? */
  241. #endif
  242. u8 increment_me2[3];
  243. __le32 up; /* (root dnode) directory's fnode
  244. (nonroot) parent dnode */
  245. __le32 self; /* pointer to this dnode */
  246. u8 dirent[2028]; /* one or more dirents */
  247. };
  248. struct hpfs_dirent {
  249. __le16 length; /* offset to next dirent */
  250. #ifdef __LITTLE_ENDIAN
  251. u8 first: 1; /* set on phony ^A^A (".") entry */
  252. u8 has_acl: 1;
  253. u8 down: 1; /* down pointer present (after name) */
  254. u8 last: 1; /* set on phony \377 entry */
  255. u8 has_ea: 1; /* entry has EA */
  256. u8 has_xtd_perm: 1; /* has extended perm list (???) */
  257. u8 has_explicit_acl: 1;
  258. u8 has_needea: 1; /* ?? some EA has NEEDEA set
  259. I have no idea why this is
  260. interesting in a dir entry */
  261. #else
  262. u8 has_needea: 1; /* ?? some EA has NEEDEA set
  263. I have no idea why this is
  264. interesting in a dir entry */
  265. u8 has_explicit_acl: 1;
  266. u8 has_xtd_perm: 1; /* has extended perm list (???) */
  267. u8 has_ea: 1; /* entry has EA */
  268. u8 last: 1; /* set on phony \377 entry */
  269. u8 down: 1; /* down pointer present (after name) */
  270. u8 has_acl: 1;
  271. u8 first: 1; /* set on phony ^A^A (".") entry */
  272. #endif
  273. #ifdef __LITTLE_ENDIAN
  274. u8 read_only: 1; /* dos attrib */
  275. u8 hidden: 1; /* dos attrib */
  276. u8 system: 1; /* dos attrib */
  277. u8 flag11: 1; /* would be volume label dos attrib */
  278. u8 directory: 1; /* dos attrib */
  279. u8 archive: 1; /* dos attrib */
  280. u8 not_8x3: 1; /* name is not 8.3 */
  281. u8 flag15: 1;
  282. #else
  283. u8 flag15: 1;
  284. u8 not_8x3: 1; /* name is not 8.3 */
  285. u8 archive: 1; /* dos attrib */
  286. u8 directory: 1; /* dos attrib */
  287. u8 flag11: 1; /* would be volume label dos attrib */
  288. u8 system: 1; /* dos attrib */
  289. u8 hidden: 1; /* dos attrib */
  290. u8 read_only: 1; /* dos attrib */
  291. #endif
  292. __le32 fnode; /* fnode giving allocation info */
  293. __le32 write_date; /* mtime */
  294. __le32 file_size; /* file length, bytes */
  295. __le32 read_date; /* atime */
  296. __le32 creation_date; /* ctime */
  297. __le32 ea_size; /* total EA length, bytes */
  298. u8 no_of_acls; /* number of ACL's (low 3 bits) */
  299. u8 ix; /* code page index (of filename), see
  300. struct code_page_data */
  301. u8 namelen, name[1]; /* file name */
  302. /* dnode_secno down; btree down pointer, if present,
  303. follows name on next word boundary, or maybe it
  304. precedes next dirent, which is on a word boundary. */
  305. };
  306. /* B+ tree: allocation info in fnodes and anodes */
  307. /* dnodes point to fnodes which are responsible for listing the sectors
  308. assigned to the file. This is done with trees of (length,address)
  309. pairs. (Actually triples, of (length, file-address, disk-address)
  310. which can represent holes. Find out if HPFS does that.)
  311. At any rate, fnodes contain a small tree; if subtrees are needed
  312. they occupy essentially a full block in anodes. A leaf-level tree node
  313. has 3-word entries giving sector runs, a non-leaf node has 2-word
  314. entries giving subtree pointers. A flag in the header says which. */
  315. struct bplus_leaf_node
  316. {
  317. __le32 file_secno; /* first file sector in extent */
  318. __le32 length; /* length, sectors */
  319. __le32 disk_secno; /* first corresponding disk sector */
  320. };
  321. struct bplus_internal_node
  322. {
  323. __le32 file_secno; /* subtree maps sectors < this */
  324. __le32 down; /* pointer to subtree */
  325. };
  326. enum {
  327. BP_hbff = 1,
  328. BP_fnode_parent = 0x20,
  329. BP_binary_search = 0x40,
  330. BP_internal = 0x80
  331. };
  332. struct bplus_header
  333. {
  334. u8 flags; /* bit 0 - high bit of first free entry offset
  335. bit 5 - we're pointed to by an fnode,
  336. the data btree or some ea or the
  337. main ea bootage pointer ea_secno
  338. bit 6 - suggest binary search (unused)
  339. bit 7 - 1 -> (internal) tree of anodes
  340. 0 -> (leaf) list of extents */
  341. u8 fill[3];
  342. u8 n_free_nodes; /* free nodes in following array */
  343. u8 n_used_nodes; /* used nodes in following array */
  344. __le16 first_free; /* offset from start of header to
  345. first free node in array */
  346. union {
  347. struct bplus_internal_node internal[0]; /* (internal) 2-word entries giving
  348. subtree pointers */
  349. struct bplus_leaf_node external[0]; /* (external) 3-word entries giving
  350. sector runs */
  351. } u;
  352. };
  353. static inline bool bp_internal(struct bplus_header *bp)
  354. {
  355. return bp->flags & BP_internal;
  356. }
  357. static inline bool bp_fnode_parent(struct bplus_header *bp)
  358. {
  359. return bp->flags & BP_fnode_parent;
  360. }
  361. /* fnode: root of allocation b+ tree, and EA's */
  362. /* Every file and every directory has one fnode, pointed to by the directory
  363. entry and pointing to the file's sectors or directory's root dnode. EA's
  364. are also stored here, and there are said to be ACL's somewhere here too. */
  365. #define FNODE_MAGIC 0xf7e40aae
  366. enum {FNODE_anode = cpu_to_le16(2), FNODE_dir = cpu_to_le16(256)};
  367. struct fnode
  368. {
  369. __le32 magic; /* f7e4 0aae */
  370. __le32 zero1[2]; /* read history */
  371. u8 len, name[15]; /* true length, truncated name */
  372. __le32 up; /* pointer to file's directory fnode */
  373. __le32 acl_size_l;
  374. __le32 acl_secno;
  375. __le16 acl_size_s;
  376. u8 acl_anode;
  377. u8 zero2; /* history bit count */
  378. __le32 ea_size_l; /* length of disk-resident ea's */
  379. __le32 ea_secno; /* first sector of disk-resident ea's*/
  380. __le16 ea_size_s; /* length of fnode-resident ea's */
  381. __le16 flags; /* bit 1 set -> ea_secno is an anode */
  382. /* bit 8 set -> directory. first & only extent
  383. points to dnode. */
  384. struct bplus_header btree; /* b+ tree, 8 extents or 12 subtrees */
  385. union {
  386. struct bplus_leaf_node external[8];
  387. struct bplus_internal_node internal[12];
  388. } u;
  389. __le32 file_size; /* file length, bytes */
  390. __le32 n_needea; /* number of EA's with NEEDEA set */
  391. u8 user_id[16]; /* unused */
  392. __le16 ea_offs; /* offset from start of fnode
  393. to first fnode-resident ea */
  394. u8 dasd_limit_treshhold;
  395. u8 dasd_limit_delta;
  396. __le32 dasd_limit;
  397. __le32 dasd_usage;
  398. u8 ea[316]; /* zero or more EA's, packed together
  399. with no alignment padding.
  400. (Do not use this name, get here
  401. via fnode + ea_offs. I think.) */
  402. };
  403. static inline bool fnode_in_anode(struct fnode *p)
  404. {
  405. return (p->flags & FNODE_anode) != 0;
  406. }
  407. static inline bool fnode_is_dir(struct fnode *p)
  408. {
  409. return (p->flags & FNODE_dir) != 0;
  410. }
  411. /* anode: 99.44% pure allocation tree */
  412. #define ANODE_MAGIC 0x37e40aae
  413. struct anode
  414. {
  415. __le32 magic; /* 37e4 0aae */
  416. __le32 self; /* pointer to this anode */
  417. __le32 up; /* parent anode or fnode */
  418. struct bplus_header btree; /* b+tree, 40 extents or 60 subtrees */
  419. union {
  420. struct bplus_leaf_node external[40];
  421. struct bplus_internal_node internal[60];
  422. } u;
  423. __le32 fill[3]; /* unused */
  424. };
  425. /* extended attributes.
  426. A file's EA info is stored as a list of (name,value) pairs. It is
  427. usually in the fnode, but (if it's large) it is moved to a single
  428. sector run outside the fnode, or to multiple runs with an anode tree
  429. that points to them.
  430. The value of a single EA is stored along with the name, or (if large)
  431. it is moved to a single sector run, or multiple runs pointed to by an
  432. anode tree, pointed to by the value field of the (name,value) pair.
  433. Flags in the EA tell whether the value is immediate, in a single sector
  434. run, or in multiple runs. Flags in the fnode tell whether the EA list
  435. is immediate, in a single run, or in multiple runs. */
  436. enum {EA_indirect = 1, EA_anode = 2, EA_needea = 128 };
  437. struct extended_attribute
  438. {
  439. u8 flags; /* bit 0 set -> value gives sector number
  440. where real value starts */
  441. /* bit 1 set -> sector is an anode
  442. that points to fragmented value */
  443. /* bit 7 set -> required ea */
  444. u8 namelen; /* length of name, bytes */
  445. u8 valuelen_lo; /* length of value, bytes */
  446. u8 valuelen_hi; /* length of value, bytes */
  447. u8 name[];
  448. /*
  449. u8 name[namelen]; ascii attrib name
  450. u8 nul; terminating '\0', not counted
  451. u8 value[valuelen]; value, arbitrary
  452. if this.flags & 1, valuelen is 8 and the value is
  453. u32 length; real length of value, bytes
  454. secno secno; sector address where it starts
  455. if this.anode, the above sector number is the root of an anode tree
  456. which points to the value.
  457. */
  458. };
  459. static inline bool ea_indirect(struct extended_attribute *ea)
  460. {
  461. return ea->flags & EA_indirect;
  462. }
  463. static inline bool ea_in_anode(struct extended_attribute *ea)
  464. {
  465. return ea->flags & EA_anode;
  466. }
  467. /*
  468. Local Variables:
  469. comment-column: 40
  470. End:
  471. */