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