![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * linux/fs/hpfs/hpfs.h 0004 * 0005 * HPFS structures by Chris Smith, 1993 0006 * 0007 * a little bit modified by Mikulas Patocka, 1998-1999 0008 */ 0009 0010 /* The paper 0011 0012 Duncan, Roy 0013 Design goals and implementation of the new High Performance File System 0014 Microsoft Systems Journal Sept 1989 v4 n5 p1(13) 0015 0016 describes what HPFS looked like when it was new, and it is the source 0017 of most of the information given here. The rest is conjecture. 0018 0019 For definitive information on the Duncan paper, see it, not this file. 0020 For definitive information on HPFS, ask somebody else -- this is guesswork. 0021 There are certain to be many mistakes. */ 0022 0023 #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN) 0024 #error unknown endian 0025 #endif 0026 0027 /* Notation */ 0028 0029 typedef u32 secno; /* sector number, partition relative */ 0030 0031 typedef secno dnode_secno; /* sector number of a dnode */ 0032 typedef secno fnode_secno; /* sector number of an fnode */ 0033 typedef secno anode_secno; /* sector number of an anode */ 0034 0035 typedef u32 time32_t; /* 32-bit time_t type */ 0036 0037 /* sector 0 */ 0038 0039 /* The boot block is very like a FAT boot block, except that the 0040 29h signature byte is 28h instead, and the ID string is "HPFS". */ 0041 0042 #define BB_MAGIC 0xaa55 0043 0044 struct hpfs_boot_block 0045 { 0046 u8 jmp[3]; 0047 u8 oem_id[8]; 0048 u8 bytes_per_sector[2]; /* 512 */ 0049 u8 sectors_per_cluster; 0050 u8 n_reserved_sectors[2]; 0051 u8 n_fats; 0052 u8 n_rootdir_entries[2]; 0053 u8 n_sectors_s[2]; 0054 u8 media_byte; 0055 __le16 sectors_per_fat; 0056 __le16 sectors_per_track; 0057 __le16 heads_per_cyl; 0058 __le32 n_hidden_sectors; 0059 __le32 n_sectors_l; /* size of partition */ 0060 u8 drive_number; 0061 u8 mbz; 0062 u8 sig_28h; /* 28h */ 0063 u8 vol_serno[4]; 0064 u8 vol_label[11]; 0065 u8 sig_hpfs[8]; /* "HPFS " */ 0066 u8 pad[448]; 0067 __le16 magic; /* aa55 */ 0068 }; 0069 0070 0071 /* sector 16 */ 0072 0073 /* The super block has the pointer to the root directory. */ 0074 0075 #define SB_MAGIC 0xf995e849 0076 0077 struct hpfs_super_block 0078 { 0079 __le32 magic; /* f995 e849 */ 0080 __le32 magic1; /* fa53 e9c5, more magic? */ 0081 u8 version; /* version of a filesystem usually 2 */ 0082 u8 funcversion; /* functional version - oldest version 0083 of filesystem that can understand 0084 this disk */ 0085 __le16 zero; /* 0 */ 0086 __le32 root; /* fnode of root directory */ 0087 __le32 n_sectors; /* size of filesystem */ 0088 __le32 n_badblocks; /* number of bad blocks */ 0089 __le32 bitmaps; /* pointers to free space bit maps */ 0090 __le32 zero1; /* 0 */ 0091 __le32 badblocks; /* bad block list */ 0092 __le32 zero3; /* 0 */ 0093 __le32 last_chkdsk; /* date last checked, 0 if never */ 0094 __le32 last_optimize; /* date last optimized, 0 if never */ 0095 __le32 n_dir_band; /* number of sectors in dir band */ 0096 __le32 dir_band_start; /* first sector in dir band */ 0097 __le32 dir_band_end; /* last sector in dir band */ 0098 __le32 dir_band_bitmap; /* free space map, 1 dnode per bit */ 0099 u8 volume_name[32]; /* not used */ 0100 __le32 user_id_table; /* 8 preallocated sectors - user id */ 0101 u32 zero6[103]; /* 0 */ 0102 }; 0103 0104 0105 /* sector 17 */ 0106 0107 /* The spare block has pointers to spare sectors. */ 0108 0109 #define SP_MAGIC 0xf9911849 0110 0111 struct hpfs_spare_block 0112 { 0113 __le32 magic; /* f991 1849 */ 0114 __le32 magic1; /* fa52 29c5, more magic? */ 0115 0116 #ifdef __LITTLE_ENDIAN 0117 u8 dirty: 1; /* 0 clean, 1 "improperly stopped" */ 0118 u8 sparedir_used: 1; /* spare dirblks used */ 0119 u8 hotfixes_used: 1; /* hotfixes used */ 0120 u8 bad_sector: 1; /* bad sector, corrupted disk (???) */ 0121 u8 bad_bitmap: 1; /* bad bitmap */ 0122 u8 fast: 1; /* partition was fast formatted */ 0123 u8 old_wrote: 1; /* old version wrote to partition */ 0124 u8 old_wrote_1: 1; /* old version wrote to partition (?) */ 0125 #else 0126 u8 old_wrote_1: 1; /* old version wrote to partition (?) */ 0127 u8 old_wrote: 1; /* old version wrote to partition */ 0128 u8 fast: 1; /* partition was fast formatted */ 0129 u8 bad_bitmap: 1; /* bad bitmap */ 0130 u8 bad_sector: 1; /* bad sector, corrupted disk (???) */ 0131 u8 hotfixes_used: 1; /* hotfixes used */ 0132 u8 sparedir_used: 1; /* spare dirblks used */ 0133 u8 dirty: 1; /* 0 clean, 1 "improperly stopped" */ 0134 #endif 0135 0136 #ifdef __LITTLE_ENDIAN 0137 u8 install_dasd_limits: 1; /* HPFS386 flags */ 0138 u8 resynch_dasd_limits: 1; 0139 u8 dasd_limits_operational: 1; 0140 u8 multimedia_active: 1; 0141 u8 dce_acls_active: 1; 0142 u8 dasd_limits_dirty: 1; 0143 u8 flag67: 2; 0144 #else 0145 u8 flag67: 2; 0146 u8 dasd_limits_dirty: 1; 0147 u8 dce_acls_active: 1; 0148 u8 multimedia_active: 1; 0149 u8 dasd_limits_operational: 1; 0150 u8 resynch_dasd_limits: 1; 0151 u8 install_dasd_limits: 1; /* HPFS386 flags */ 0152 #endif 0153 0154 u8 mm_contlgulty; 0155 u8 unused; 0156 0157 __le32 hotfix_map; /* info about remapped bad sectors */ 0158 __le32 n_spares_used; /* number of hotfixes */ 0159 __le32 n_spares; /* number of spares in hotfix map */ 0160 __le32 n_dnode_spares_free; /* spare dnodes unused */ 0161 __le32 n_dnode_spares; /* length of spare_dnodes[] list, 0162 follows in this block*/ 0163 __le32 code_page_dir; /* code page directory block */ 0164 __le32 n_code_pages; /* number of code pages */ 0165 __le32 super_crc; /* on HPFS386 and LAN Server this is 0166 checksum of superblock, on normal 0167 OS/2 unused */ 0168 __le32 spare_crc; /* on HPFS386 checksum of spareblock */ 0169 __le32 zero1[15]; /* unused */ 0170 __le32 spare_dnodes[100]; /* emergency free dnode list */ 0171 __le32 zero2[1]; /* room for more? */ 0172 }; 0173 0174 /* The bad block list is 4 sectors long. The first word must be zero, 0175 the remaining words give n_badblocks bad block numbers. 0176 I bet you can see it coming... */ 0177 0178 #define BAD_MAGIC 0 0179 0180 /* The hotfix map is 4 sectors long. It looks like 0181 0182 secno from[n_spares]; 0183 secno to[n_spares]; 0184 0185 The to[] list is initialized to point to n_spares preallocated empty 0186 sectors. The from[] list contains the sector numbers of bad blocks 0187 which have been remapped to corresponding sectors in the to[] list. 0188 n_spares_used gives the length of the from[] list. */ 0189 0190 0191 /* Sectors 18 and 19 are preallocated and unused. 0192 Maybe they're spares for 16 and 17, but simple substitution fails. */ 0193 0194 0195 /* The code page info pointed to by the spare block consists of an index 0196 block and blocks containing uppercasing tables. I don't know what 0197 these are for (CHKDSK, maybe?) -- OS/2 does not seem to use them 0198 itself. Linux doesn't use them either. */ 0199 0200 /* block pointed to by spareblock->code_page_dir */ 0201 0202 #define CP_DIR_MAGIC 0x494521f7 0203 0204 struct code_page_directory 0205 { 0206 __le32 magic; /* 4945 21f7 */ 0207 __le32 n_code_pages; /* number of pointers following */ 0208 __le32 zero1[2]; 0209 struct { 0210 __le16 ix; /* index */ 0211 __le16 code_page_number; /* code page number */ 0212 __le32 bounds; /* matches corresponding word 0213 in data block */ 0214 __le32 code_page_data; /* sector number of a code_page_data 0215 containing c.p. array */ 0216 __le16 index; /* index in c.p. array in that sector*/ 0217 __le16 unknown; /* some unknown value; usually 0; 0218 2 in Japanese version */ 0219 } array[31]; /* unknown length */ 0220 }; 0221 0222 /* blocks pointed to by code_page_directory */ 0223 0224 #define CP_DATA_MAGIC 0x894521f7 0225 0226 struct code_page_data 0227 { 0228 __le32 magic; /* 8945 21f7 */ 0229 __le32 n_used; /* # elements used in c_p_data[] */ 0230 __le32 bounds[3]; /* looks a bit like 0231 (beg1,end1), (beg2,end2) 0232 one byte each */ 0233 __le16 offs[3]; /* offsets from start of sector 0234 to start of c_p_data[ix] */ 0235 struct { 0236 __le16 ix; /* index */ 0237 __le16 code_page_number; /* code page number */ 0238 __le16 unknown; /* the same as in cp directory */ 0239 u8 map[128]; /* upcase table for chars 80..ff */ 0240 __le16 zero2; 0241 } code_page[3]; 0242 u8 incognita[78]; 0243 }; 0244 0245 0246 /* Free space bitmaps are 4 sectors long, which is 16384 bits. 0247 16384 sectors is 8 meg, and each 8 meg band has a 4-sector bitmap. 0248 Bit order in the maps is little-endian. 0 means taken, 1 means free. 0249 0250 Bit map sectors are marked allocated in the bit maps, and so are sectors 0251 off the end of the partition. 0252 0253 Band 0 is sectors 0-3fff, its map is in sectors 18-1b. 0254 Band 1 is 4000-7fff, its map is in 7ffc-7fff. 0255 Band 2 is 8000-ffff, its map is in 8000-8003. 0256 The remaining bands have maps in their first (even) or last (odd) 4 sectors 0257 -- if the last, partial, band is odd its map is in its last 4 sectors. 0258 0259 The bitmap locations are given in a table pointed to by the super block. 0260 No doubt they aren't constrained to be at 18, 7ffc, 8000, ...; that is 0261 just where they usually are. 0262 0263 The "directory band" is a bunch of sectors preallocated for dnodes. 0264 It has a 4-sector free space bitmap of its own. Each bit in the map 0265 corresponds to one 4-sector dnode, bit 0 of the map corresponding to 0266 the first 4 sectors of the directory band. The entire band is marked 0267 allocated in the main bitmap. The super block gives the locations 0268 of the directory band and its bitmap. ("band" doesn't mean it is 0269 8 meg long; it isn't.) */ 0270 0271 0272 /* dnode: directory. 4 sectors long */ 0273 0274 /* A directory is a tree of dnodes. The fnode for a directory 0275 contains one pointer, to the root dnode of the tree. The fnode 0276 never moves, the dnodes do the B-tree thing, splitting and merging 0277 as files are added and removed. */ 0278 0279 #define DNODE_MAGIC 0x77e40aae 0280 0281 struct dnode { 0282 __le32 magic; /* 77e4 0aae */ 0283 __le32 first_free; /* offset from start of dnode to 0284 first free dir entry */ 0285 #ifdef __LITTLE_ENDIAN 0286 u8 root_dnode: 1; /* Is it root dnode? */ 0287 u8 increment_me: 7; /* some kind of activity counter? */ 0288 /* Neither HPFS.IFS nor CHKDSK cares 0289 if you change this word */ 0290 #else 0291 u8 increment_me: 7; /* some kind of activity counter? */ 0292 /* Neither HPFS.IFS nor CHKDSK cares 0293 if you change this word */ 0294 u8 root_dnode: 1; /* Is it root dnode? */ 0295 #endif 0296 u8 increment_me2[3]; 0297 __le32 up; /* (root dnode) directory's fnode 0298 (nonroot) parent dnode */ 0299 __le32 self; /* pointer to this dnode */ 0300 u8 dirent[2028]; /* one or more dirents */ 0301 }; 0302 0303 struct hpfs_dirent { 0304 __le16 length; /* offset to next dirent */ 0305 0306 #ifdef __LITTLE_ENDIAN 0307 u8 first: 1; /* set on phony ^A^A (".") entry */ 0308 u8 has_acl: 1; 0309 u8 down: 1; /* down pointer present (after name) */ 0310 u8 last: 1; /* set on phony \377 entry */ 0311 u8 has_ea: 1; /* entry has EA */ 0312 u8 has_xtd_perm: 1; /* has extended perm list (???) */ 0313 u8 has_explicit_acl: 1; 0314 u8 has_needea: 1; /* ?? some EA has NEEDEA set 0315 I have no idea why this is 0316 interesting in a dir entry */ 0317 #else 0318 u8 has_needea: 1; /* ?? some EA has NEEDEA set 0319 I have no idea why this is 0320 interesting in a dir entry */ 0321 u8 has_explicit_acl: 1; 0322 u8 has_xtd_perm: 1; /* has extended perm list (???) */ 0323 u8 has_ea: 1; /* entry has EA */ 0324 u8 last: 1; /* set on phony \377 entry */ 0325 u8 down: 1; /* down pointer present (after name) */ 0326 u8 has_acl: 1; 0327 u8 first: 1; /* set on phony ^A^A (".") entry */ 0328 #endif 0329 0330 #ifdef __LITTLE_ENDIAN 0331 u8 read_only: 1; /* dos attrib */ 0332 u8 hidden: 1; /* dos attrib */ 0333 u8 system: 1; /* dos attrib */ 0334 u8 flag11: 1; /* would be volume label dos attrib */ 0335 u8 directory: 1; /* dos attrib */ 0336 u8 archive: 1; /* dos attrib */ 0337 u8 not_8x3: 1; /* name is not 8.3 */ 0338 u8 flag15: 1; 0339 #else 0340 u8 flag15: 1; 0341 u8 not_8x3: 1; /* name is not 8.3 */ 0342 u8 archive: 1; /* dos attrib */ 0343 u8 directory: 1; /* dos attrib */ 0344 u8 flag11: 1; /* would be volume label dos attrib */ 0345 u8 system: 1; /* dos attrib */ 0346 u8 hidden: 1; /* dos attrib */ 0347 u8 read_only: 1; /* dos attrib */ 0348 #endif 0349 0350 __le32 fnode; /* fnode giving allocation info */ 0351 __le32 write_date; /* mtime */ 0352 __le32 file_size; /* file length, bytes */ 0353 __le32 read_date; /* atime */ 0354 __le32 creation_date; /* ctime */ 0355 __le32 ea_size; /* total EA length, bytes */ 0356 u8 no_of_acls; /* number of ACL's (low 3 bits) */ 0357 u8 ix; /* code page index (of filename), see 0358 struct code_page_data */ 0359 u8 namelen; /* file name length */ 0360 u8 name[]; /* file name */ 0361 /* dnode_secno down; btree down pointer, if present, 0362 follows name on next word boundary, or maybe it 0363 precedes next dirent, which is on a word boundary. */ 0364 }; 0365 0366 0367 /* B+ tree: allocation info in fnodes and anodes */ 0368 0369 /* dnodes point to fnodes which are responsible for listing the sectors 0370 assigned to the file. This is done with trees of (length,address) 0371 pairs. (Actually triples, of (length, file-address, disk-address) 0372 which can represent holes. Find out if HPFS does that.) 0373 At any rate, fnodes contain a small tree; if subtrees are needed 0374 they occupy essentially a full block in anodes. A leaf-level tree node 0375 has 3-word entries giving sector runs, a non-leaf node has 2-word 0376 entries giving subtree pointers. A flag in the header says which. */ 0377 0378 struct bplus_leaf_node 0379 { 0380 __le32 file_secno; /* first file sector in extent */ 0381 __le32 length; /* length, sectors */ 0382 __le32 disk_secno; /* first corresponding disk sector */ 0383 }; 0384 0385 struct bplus_internal_node 0386 { 0387 __le32 file_secno; /* subtree maps sectors < this */ 0388 __le32 down; /* pointer to subtree */ 0389 }; 0390 0391 enum { 0392 BP_hbff = 1, 0393 BP_fnode_parent = 0x20, 0394 BP_binary_search = 0x40, 0395 BP_internal = 0x80 0396 }; 0397 struct bplus_header 0398 { 0399 u8 flags; /* bit 0 - high bit of first free entry offset 0400 bit 5 - we're pointed to by an fnode, 0401 the data btree or some ea or the 0402 main ea bootage pointer ea_secno 0403 bit 6 - suggest binary search (unused) 0404 bit 7 - 1 -> (internal) tree of anodes 0405 0 -> (leaf) list of extents */ 0406 u8 fill[3]; 0407 u8 n_free_nodes; /* free nodes in following array */ 0408 u8 n_used_nodes; /* used nodes in following array */ 0409 __le16 first_free; /* offset from start of header to 0410 first free node in array */ 0411 union { 0412 /* (internal) 2-word entries giving subtree pointers */ 0413 DECLARE_FLEX_ARRAY(struct bplus_internal_node, internal); 0414 /* (external) 3-word entries giving sector runs */ 0415 DECLARE_FLEX_ARRAY(struct bplus_leaf_node, external); 0416 } u; 0417 }; 0418 0419 static inline bool bp_internal(struct bplus_header *bp) 0420 { 0421 return bp->flags & BP_internal; 0422 } 0423 0424 static inline bool bp_fnode_parent(struct bplus_header *bp) 0425 { 0426 return bp->flags & BP_fnode_parent; 0427 } 0428 0429 /* fnode: root of allocation b+ tree, and EA's */ 0430 0431 /* Every file and every directory has one fnode, pointed to by the directory 0432 entry and pointing to the file's sectors or directory's root dnode. EA's 0433 are also stored here, and there are said to be ACL's somewhere here too. */ 0434 0435 #define FNODE_MAGIC 0xf7e40aae 0436 0437 enum {FNODE_anode = cpu_to_le16(2), FNODE_dir = cpu_to_le16(256)}; 0438 struct fnode 0439 { 0440 __le32 magic; /* f7e4 0aae */ 0441 __le32 zero1[2]; /* read history */ 0442 u8 len, name[15]; /* true length, truncated name */ 0443 __le32 up; /* pointer to file's directory fnode */ 0444 __le32 acl_size_l; 0445 __le32 acl_secno; 0446 __le16 acl_size_s; 0447 u8 acl_anode; 0448 u8 zero2; /* history bit count */ 0449 __le32 ea_size_l; /* length of disk-resident ea's */ 0450 __le32 ea_secno; /* first sector of disk-resident ea's*/ 0451 __le16 ea_size_s; /* length of fnode-resident ea's */ 0452 0453 __le16 flags; /* bit 1 set -> ea_secno is an anode */ 0454 /* bit 8 set -> directory. first & only extent 0455 points to dnode. */ 0456 struct bplus_header btree; /* b+ tree, 8 extents or 12 subtrees */ 0457 union { 0458 struct bplus_leaf_node external[8]; 0459 struct bplus_internal_node internal[12]; 0460 } u; 0461 0462 __le32 file_size; /* file length, bytes */ 0463 __le32 n_needea; /* number of EA's with NEEDEA set */ 0464 u8 user_id[16]; /* unused */ 0465 __le16 ea_offs; /* offset from start of fnode 0466 to first fnode-resident ea */ 0467 u8 dasd_limit_treshhold; 0468 u8 dasd_limit_delta; 0469 __le32 dasd_limit; 0470 __le32 dasd_usage; 0471 u8 ea[316]; /* zero or more EA's, packed together 0472 with no alignment padding. 0473 (Do not use this name, get here 0474 via fnode + ea_offs. I think.) */ 0475 }; 0476 0477 static inline bool fnode_in_anode(struct fnode *p) 0478 { 0479 return (p->flags & FNODE_anode) != 0; 0480 } 0481 0482 static inline bool fnode_is_dir(struct fnode *p) 0483 { 0484 return (p->flags & FNODE_dir) != 0; 0485 } 0486 0487 0488 /* anode: 99.44% pure allocation tree */ 0489 0490 #define ANODE_MAGIC 0x37e40aae 0491 0492 struct anode 0493 { 0494 __le32 magic; /* 37e4 0aae */ 0495 __le32 self; /* pointer to this anode */ 0496 __le32 up; /* parent anode or fnode */ 0497 0498 struct bplus_header btree; /* b+tree, 40 extents or 60 subtrees */ 0499 union { 0500 struct bplus_leaf_node external[40]; 0501 struct bplus_internal_node internal[60]; 0502 } u; 0503 0504 __le32 fill[3]; /* unused */ 0505 }; 0506 0507 0508 /* extended attributes. 0509 0510 A file's EA info is stored as a list of (name,value) pairs. It is 0511 usually in the fnode, but (if it's large) it is moved to a single 0512 sector run outside the fnode, or to multiple runs with an anode tree 0513 that points to them. 0514 0515 The value of a single EA is stored along with the name, or (if large) 0516 it is moved to a single sector run, or multiple runs pointed to by an 0517 anode tree, pointed to by the value field of the (name,value) pair. 0518 0519 Flags in the EA tell whether the value is immediate, in a single sector 0520 run, or in multiple runs. Flags in the fnode tell whether the EA list 0521 is immediate, in a single run, or in multiple runs. */ 0522 0523 enum {EA_indirect = 1, EA_anode = 2, EA_needea = 128 }; 0524 struct extended_attribute 0525 { 0526 u8 flags; /* bit 0 set -> value gives sector number 0527 where real value starts */ 0528 /* bit 1 set -> sector is an anode 0529 that points to fragmented value */ 0530 /* bit 7 set -> required ea */ 0531 u8 namelen; /* length of name, bytes */ 0532 u8 valuelen_lo; /* length of value, bytes */ 0533 u8 valuelen_hi; /* length of value, bytes */ 0534 u8 name[]; 0535 /* 0536 u8 name[namelen]; ascii attrib name 0537 u8 nul; terminating '\0', not counted 0538 u8 value[valuelen]; value, arbitrary 0539 if this.flags & 1, valuelen is 8 and the value is 0540 u32 length; real length of value, bytes 0541 secno secno; sector address where it starts 0542 if this.anode, the above sector number is the root of an anode tree 0543 which points to the value. 0544 */ 0545 }; 0546 0547 static inline bool ea_indirect(struct extended_attribute *ea) 0548 { 0549 return ea->flags & EA_indirect; 0550 } 0551 0552 static inline bool ea_in_anode(struct extended_attribute *ea) 0553 { 0554 return ea->flags & EA_anode; 0555 } 0556 0557 /* 0558 Local Variables: 0559 comment-column: 40 0560 End: 0561 */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |