hpfs.h 18 KB

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