ocfs2_fs.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * ocfs2_fs.h
  5. *
  6. * On-disk structures for OCFS2.
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License, version 2, as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program; if not, write to the
  21. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. * Boston, MA 021110-1307, USA.
  23. */
  24. #ifndef _OCFS2_FS_H
  25. #define _OCFS2_FS_H
  26. /* Version */
  27. #define OCFS2_MAJOR_REV_LEVEL 0
  28. #define OCFS2_MINOR_REV_LEVEL 90
  29. /*
  30. * An OCFS2 volume starts this way:
  31. * Sector 0: Valid ocfs1_vol_disk_hdr that cleanly fails to mount OCFS.
  32. * Sector 1: Valid ocfs1_vol_label that cleanly fails to mount OCFS.
  33. * Block OCFS2_SUPER_BLOCK_BLKNO: OCFS2 superblock.
  34. *
  35. * All other structures are found from the superblock information.
  36. *
  37. * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors. eg, for a
  38. * blocksize of 2K, it is 4096 bytes into disk.
  39. */
  40. #define OCFS2_SUPER_BLOCK_BLKNO 2
  41. /*
  42. * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could
  43. * grow if needed.
  44. */
  45. #define OCFS2_MIN_CLUSTERSIZE 4096
  46. #define OCFS2_MAX_CLUSTERSIZE 1048576
  47. /*
  48. * Blocks cannot be bigger than clusters, so the maximum blocksize is the
  49. * minimum cluster size.
  50. */
  51. #define OCFS2_MIN_BLOCKSIZE 512
  52. #define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE
  53. /* Filesystem magic number */
  54. #define OCFS2_SUPER_MAGIC 0x7461636f
  55. /* Object signatures */
  56. #define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2"
  57. #define OCFS2_INODE_SIGNATURE "INODE01"
  58. #define OCFS2_EXTENT_BLOCK_SIGNATURE "EXBLK01"
  59. #define OCFS2_GROUP_DESC_SIGNATURE "GROUP01"
  60. #define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01"
  61. /* Compatibility flags */
  62. #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
  63. ( OCFS2_SB(sb)->s_feature_compat & (mask) )
  64. #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
  65. ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
  66. #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
  67. ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
  68. #define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
  69. OCFS2_SB(sb)->s_feature_compat |= (mask)
  70. #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
  71. OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
  72. #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
  73. OCFS2_SB(sb)->s_feature_incompat |= (mask)
  74. #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
  75. OCFS2_SB(sb)->s_feature_compat &= ~(mask)
  76. #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
  77. OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
  78. #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
  79. OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
  80. #define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
  81. | OCFS2_FEATURE_COMPAT_JBD2_SB)
  82. #define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
  83. | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
  84. | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
  85. | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
  86. | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
  87. | OCFS2_FEATURE_INCOMPAT_XATTR)
  88. #define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
  89. | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
  90. | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
  91. /*
  92. * Heartbeat-only devices are missing journals and other files. The
  93. * filesystem driver can't load them, but the library can. Never put
  94. * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
  95. */
  96. #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
  97. /*
  98. * tunefs sets this incompat flag before starting the resize and clears it
  99. * at the end. This flag protects users from inadvertently mounting the fs
  100. * after an aborted run without fsck-ing.
  101. */
  102. #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
  103. /* Used to denote a non-clustered volume */
  104. #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
  105. /* Support for sparse allocation in b-trees */
  106. #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
  107. /*
  108. * Tunefs sets this incompat flag before starting an operation which
  109. * would require cleanup on abort. This is done to protect users from
  110. * inadvertently mounting the fs after an aborted run without
  111. * fsck-ing.
  112. *
  113. * s_tunefs_flags on the super block describes precisely which
  114. * operations were in progress.
  115. */
  116. #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
  117. /* Support for data packed into inode blocks */
  118. #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
  119. /*
  120. * Support for alternate, userspace cluster stacks. If set, the superblock
  121. * field s_cluster_info contains a tag for the alternate stack in use as
  122. * well as the name of the cluster being joined.
  123. * mount.ocfs2 must pass in a matching stack name.
  124. *
  125. * If not set, the classic stack will be used. This is compatbile with
  126. * all older versions.
  127. */
  128. #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
  129. /* Support for the extended slot map */
  130. #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
  131. /* Support for extended attributes */
  132. #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
  133. /* Metadata checksum and error correction */
  134. #define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
  135. /*
  136. * backup superblock flag is used to indicate that this volume
  137. * has backup superblocks.
  138. */
  139. #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
  140. /*
  141. * The filesystem will correctly handle journal feature bits.
  142. */
  143. #define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
  144. /*
  145. * Unwritten extents support.
  146. */
  147. #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
  148. /*
  149. * Maintain quota information for this filesystem
  150. */
  151. #define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
  152. #define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
  153. /* The byte offset of the first backup block will be 1G.
  154. * The following will be 4G, 16G, 64G, 256G and 1T.
  155. */
  156. #define OCFS2_BACKUP_SB_START 1 << 30
  157. /* the max backup superblock nums */
  158. #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
  159. /*
  160. * Flags on ocfs2_super_block.s_tunefs_flags
  161. */
  162. #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
  163. /*
  164. * Flags on ocfs2_dinode.i_flags
  165. */
  166. #define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
  167. #define OCFS2_UNUSED2_FL (0x00000002)
  168. #define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
  169. #define OCFS2_UNUSED3_FL (0x00000008)
  170. /* System inode flags */
  171. #define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
  172. #define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
  173. #define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
  174. #define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
  175. #define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
  176. #define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
  177. #define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
  178. #define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
  179. #define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
  180. /*
  181. * Flags on ocfs2_dinode.i_dyn_features
  182. *
  183. * These can change much more often than i_flags. When adding flags,
  184. * keep in mind that i_dyn_features is only 16 bits wide.
  185. */
  186. #define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
  187. #define OCFS2_HAS_XATTR_FL (0x0002)
  188. #define OCFS2_INLINE_XATTR_FL (0x0004)
  189. #define OCFS2_INDEXED_DIR_FL (0x0008)
  190. /* Inode attributes, keep in sync with EXT2 */
  191. #define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
  192. #define OCFS2_UNRM_FL (0x00000002) /* Undelete */
  193. #define OCFS2_COMPR_FL (0x00000004) /* Compress file */
  194. #define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
  195. #define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
  196. #define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
  197. #define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
  198. #define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
  199. #define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
  200. #define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
  201. #define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
  202. /*
  203. * Extent record flags (e_node.leaf.flags)
  204. */
  205. #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
  206. * unwritten */
  207. /*
  208. * ioctl commands
  209. */
  210. #define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
  211. #define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
  212. #define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
  213. #define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
  214. /*
  215. * Space reservation / allocation / free ioctls and argument structure
  216. * are designed to be compatible with XFS.
  217. *
  218. * ALLOCSP* and FREESP* are not and will never be supported, but are
  219. * included here for completeness.
  220. */
  221. struct ocfs2_space_resv {
  222. __s16 l_type;
  223. __s16 l_whence;
  224. __s64 l_start;
  225. __s64 l_len; /* len == 0 means until end of file */
  226. __s32 l_sysid;
  227. __u32 l_pid;
  228. __s32 l_pad[4]; /* reserve area */
  229. };
  230. #define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
  231. #define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
  232. #define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
  233. #define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
  234. #define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
  235. #define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
  236. #define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
  237. #define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
  238. /* Used to pass group descriptor data when online resize is done */
  239. struct ocfs2_new_group_input {
  240. __u64 group; /* Group descriptor's blkno. */
  241. __u32 clusters; /* Total number of clusters in this group */
  242. __u32 frees; /* Total free clusters in this group */
  243. __u16 chain; /* Chain for this group */
  244. __u16 reserved1;
  245. __u32 reserved2;
  246. };
  247. #define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
  248. #define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
  249. #define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
  250. /*
  251. * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
  252. */
  253. #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
  254. /*
  255. * superblock s_state flags
  256. */
  257. #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
  258. /* Limit of space in ocfs2_dir_entry */
  259. #define OCFS2_MAX_FILENAME_LEN 255
  260. /* Maximum slots on an ocfs2 file system */
  261. #define OCFS2_MAX_SLOTS 255
  262. /* Slot map indicator for an empty slot */
  263. #define OCFS2_INVALID_SLOT -1
  264. #define OCFS2_VOL_UUID_LEN 16
  265. #define OCFS2_MAX_VOL_LABEL_LEN 64
  266. /* The alternate, userspace stack fields */
  267. #define OCFS2_STACK_LABEL_LEN 4
  268. #define OCFS2_CLUSTER_NAME_LEN 16
  269. /* Journal limits (in bytes) */
  270. #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
  271. /*
  272. * Default local alloc size (in megabytes)
  273. *
  274. * The value chosen should be such that most allocations, including new
  275. * block groups, use local alloc.
  276. */
  277. #define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
  278. /*
  279. * Inline extended attribute size (in bytes)
  280. * The value chosen should be aligned to 16 byte boundaries.
  281. */
  282. #define OCFS2_MIN_XATTR_INLINE_SIZE 256
  283. struct ocfs2_system_inode_info {
  284. char *si_name;
  285. int si_iflags;
  286. int si_mode;
  287. };
  288. /* System file index */
  289. enum {
  290. BAD_BLOCK_SYSTEM_INODE = 0,
  291. GLOBAL_INODE_ALLOC_SYSTEM_INODE,
  292. SLOT_MAP_SYSTEM_INODE,
  293. #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
  294. HEARTBEAT_SYSTEM_INODE,
  295. GLOBAL_BITMAP_SYSTEM_INODE,
  296. USER_QUOTA_SYSTEM_INODE,
  297. GROUP_QUOTA_SYSTEM_INODE,
  298. #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
  299. ORPHAN_DIR_SYSTEM_INODE,
  300. EXTENT_ALLOC_SYSTEM_INODE,
  301. INODE_ALLOC_SYSTEM_INODE,
  302. JOURNAL_SYSTEM_INODE,
  303. LOCAL_ALLOC_SYSTEM_INODE,
  304. TRUNCATE_LOG_SYSTEM_INODE,
  305. LOCAL_USER_QUOTA_SYSTEM_INODE,
  306. LOCAL_GROUP_QUOTA_SYSTEM_INODE,
  307. NUM_SYSTEM_INODES
  308. };
  309. static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
  310. /* Global system inodes (single copy) */
  311. /* The first two are only used from userspace mfks/tunefs */
  312. [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
  313. [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
  314. /* These are used by the running filesystem */
  315. [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
  316. [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
  317. [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
  318. [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
  319. [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
  320. /* Slot-specific system inodes (one copy per slot) */
  321. [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
  322. [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
  323. [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
  324. [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
  325. [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
  326. [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
  327. [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
  328. [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
  329. };
  330. /* Parameter passed from mount.ocfs2 to module */
  331. #define OCFS2_HB_NONE "heartbeat=none"
  332. #define OCFS2_HB_LOCAL "heartbeat=local"
  333. /*
  334. * OCFS2 directory file types. Only the low 3 bits are used. The
  335. * other bits are reserved for now.
  336. */
  337. #define OCFS2_FT_UNKNOWN 0
  338. #define OCFS2_FT_REG_FILE 1
  339. #define OCFS2_FT_DIR 2
  340. #define OCFS2_FT_CHRDEV 3
  341. #define OCFS2_FT_BLKDEV 4
  342. #define OCFS2_FT_FIFO 5
  343. #define OCFS2_FT_SOCK 6
  344. #define OCFS2_FT_SYMLINK 7
  345. #define OCFS2_FT_MAX 8
  346. /*
  347. * OCFS2_DIR_PAD defines the directory entries boundaries
  348. *
  349. * NOTE: It must be a multiple of 4
  350. */
  351. #define OCFS2_DIR_PAD 4
  352. #define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
  353. #define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
  354. #define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
  355. OCFS2_DIR_ROUND) & \
  356. ~OCFS2_DIR_ROUND)
  357. #define OCFS2_LINK_MAX 32000
  358. #define S_SHIFT 12
  359. static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
  360. [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
  361. [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
  362. [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
  363. [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
  364. [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
  365. [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
  366. [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
  367. };
  368. /*
  369. * Convenience casts
  370. */
  371. #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
  372. /*
  373. * Block checking structure. This is used in metadata to validate the
  374. * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
  375. * zeros.
  376. */
  377. struct ocfs2_block_check {
  378. /*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
  379. __le16 bc_ecc; /* Single-error-correction parity vector.
  380. This is a simple Hamming code dependant
  381. on the blocksize. OCFS2's maximum
  382. blocksize, 4K, requires 16 parity bits,
  383. so we fit in __le16. */
  384. __le16 bc_reserved1;
  385. /*08*/
  386. };
  387. /*
  388. * On disk extent record for OCFS2
  389. * It describes a range of clusters on disk.
  390. *
  391. * Length fields are divided into interior and leaf node versions.
  392. * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
  393. */
  394. struct ocfs2_extent_rec {
  395. /*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
  396. union {
  397. __le32 e_int_clusters; /* Clusters covered by all children */
  398. struct {
  399. __le16 e_leaf_clusters; /* Clusters covered by this
  400. extent */
  401. __u8 e_reserved1;
  402. __u8 e_flags; /* Extent flags */
  403. };
  404. };
  405. __le64 e_blkno; /* Physical disk offset, in blocks */
  406. /*10*/
  407. };
  408. struct ocfs2_chain_rec {
  409. __le32 c_free; /* Number of free bits in this chain. */
  410. __le32 c_total; /* Number of total bits in this chain */
  411. __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
  412. };
  413. struct ocfs2_truncate_rec {
  414. __le32 t_start; /* 1st cluster in this log */
  415. __le32 t_clusters; /* Number of total clusters covered */
  416. };
  417. /*
  418. * On disk extent list for OCFS2 (node in the tree). Note that this
  419. * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
  420. * offsets are relative to ocfs2_dinode.id2.i_list or
  421. * ocfs2_extent_block.h_list, respectively.
  422. */
  423. struct ocfs2_extent_list {
  424. /*00*/ __le16 l_tree_depth; /* Extent tree depth from this
  425. point. 0 means data extents
  426. hang directly off this
  427. header (a leaf)
  428. NOTE: The high 8 bits cannot be
  429. used - tree_depth is never that big.
  430. */
  431. __le16 l_count; /* Number of extent records */
  432. __le16 l_next_free_rec; /* Next unused extent slot */
  433. __le16 l_reserved1;
  434. __le64 l_reserved2; /* Pad to
  435. sizeof(ocfs2_extent_rec) */
  436. /*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
  437. };
  438. /*
  439. * On disk allocation chain list for OCFS2. Note that this is
  440. * contained inside ocfs2_dinode, so the offsets are relative to
  441. * ocfs2_dinode.id2.i_chain.
  442. */
  443. struct ocfs2_chain_list {
  444. /*00*/ __le16 cl_cpg; /* Clusters per Block Group */
  445. __le16 cl_bpc; /* Bits per cluster */
  446. __le16 cl_count; /* Total chains in this list */
  447. __le16 cl_next_free_rec; /* Next unused chain slot */
  448. __le64 cl_reserved1;
  449. /*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
  450. };
  451. /*
  452. * On disk deallocation log for OCFS2. Note that this is
  453. * contained inside ocfs2_dinode, so the offsets are relative to
  454. * ocfs2_dinode.id2.i_dealloc.
  455. */
  456. struct ocfs2_truncate_log {
  457. /*00*/ __le16 tl_count; /* Total records in this log */
  458. __le16 tl_used; /* Number of records in use */
  459. __le32 tl_reserved1;
  460. /*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
  461. };
  462. /*
  463. * On disk extent block (indirect block) for OCFS2
  464. */
  465. struct ocfs2_extent_block
  466. {
  467. /*00*/ __u8 h_signature[8]; /* Signature for verification */
  468. struct ocfs2_block_check h_check; /* Error checking */
  469. /*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
  470. extent_header belongs to */
  471. __le16 h_suballoc_bit; /* Bit offset in suballocator
  472. block group */
  473. __le32 h_fs_generation; /* Must match super block */
  474. __le64 h_blkno; /* Offset on disk, in blocks */
  475. /*20*/ __le64 h_reserved3;
  476. __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
  477. of next leaf header pointing
  478. to data */
  479. /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
  480. /* Actual on-disk size is one block */
  481. };
  482. /*
  483. * On disk slot map for OCFS2. This defines the contents of the "slot_map"
  484. * system file. A slot is valid if it contains a node number >= 0. The
  485. * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
  486. */
  487. struct ocfs2_slot_map {
  488. /*00*/ __le16 sm_slots[0];
  489. /*
  490. * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
  491. * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
  492. */
  493. };
  494. struct ocfs2_extended_slot {
  495. /*00*/ __u8 es_valid;
  496. __u8 es_reserved1[3];
  497. __le32 es_node_num;
  498. /*10*/
  499. };
  500. /*
  501. * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
  502. * is set. It separates out the valid marker from the node number, and
  503. * has room to grow. Unlike the old slot map, this format is defined by
  504. * i_size.
  505. */
  506. struct ocfs2_slot_map_extended {
  507. /*00*/ struct ocfs2_extended_slot se_slots[0];
  508. /*
  509. * Actual size is i_size of the slot_map system file. It should
  510. * match s_max_slots * sizeof(struct ocfs2_extended_slot)
  511. */
  512. };
  513. struct ocfs2_cluster_info {
  514. /*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
  515. __le32 ci_reserved;
  516. /*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
  517. /*18*/
  518. };
  519. /*
  520. * On disk superblock for OCFS2
  521. * Note that it is contained inside an ocfs2_dinode, so all offsets
  522. * are relative to the start of ocfs2_dinode.id2.
  523. */
  524. struct ocfs2_super_block {
  525. /*00*/ __le16 s_major_rev_level;
  526. __le16 s_minor_rev_level;
  527. __le16 s_mnt_count;
  528. __le16 s_max_mnt_count;
  529. __le16 s_state; /* File system state */
  530. __le16 s_errors; /* Behaviour when detecting errors */
  531. __le32 s_checkinterval; /* Max time between checks */
  532. /*10*/ __le64 s_lastcheck; /* Time of last check */
  533. __le32 s_creator_os; /* OS */
  534. __le32 s_feature_compat; /* Compatible feature set */
  535. /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
  536. __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
  537. __le64 s_root_blkno; /* Offset, in blocks, of root directory
  538. dinode */
  539. /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
  540. directory dinode */
  541. __le32 s_blocksize_bits; /* Blocksize for this fs */
  542. __le32 s_clustersize_bits; /* Clustersize for this fs */
  543. /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
  544. before tunefs required */
  545. __le16 s_tunefs_flag;
  546. __le32 s_uuid_hash; /* hash value of uuid */
  547. __le64 s_first_cluster_group; /* Block offset of 1st cluster
  548. * group header */
  549. /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
  550. /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
  551. /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
  552. stack. Only valid
  553. with INCOMPAT flag. */
  554. /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
  555. for this fs*/
  556. __le16 s_reserved0;
  557. __le32 s_reserved1;
  558. /*C0*/ __le64 s_reserved2[16]; /* Fill out superblock */
  559. /*140*/
  560. /*
  561. * NOTE: As stated above, all offsets are relative to
  562. * ocfs2_dinode.id2, which is at 0xC0 in the inode.
  563. * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
  564. * our smallest blocksize, which is 512 bytes. To ensure this,
  565. * we reserve the space in s_reserved2. Anything past s_reserved2
  566. * will not be available on the smallest blocksize.
  567. */
  568. };
  569. /*
  570. * Local allocation bitmap for OCFS2 slots
  571. * Note that it exists inside an ocfs2_dinode, so all offsets are
  572. * relative to the start of ocfs2_dinode.id2.
  573. */
  574. struct ocfs2_local_alloc
  575. {
  576. /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
  577. __le16 la_size; /* Size of included bitmap, in bytes */
  578. __le16 la_reserved1;
  579. __le64 la_reserved2;
  580. /*10*/ __u8 la_bitmap[0];
  581. };
  582. /*
  583. * Data-in-inode header. This is only used if i_dyn_features has
  584. * OCFS2_INLINE_DATA_FL set.
  585. */
  586. struct ocfs2_inline_data
  587. {
  588. /*00*/ __le16 id_count; /* Number of bytes that can be used
  589. * for data, starting at id_data */
  590. __le16 id_reserved0;
  591. __le32 id_reserved1;
  592. __u8 id_data[0]; /* Start of user data */
  593. };
  594. /*
  595. * On disk inode for OCFS2
  596. */
  597. struct ocfs2_dinode {
  598. /*00*/ __u8 i_signature[8]; /* Signature for validation */
  599. __le32 i_generation; /* Generation number */
  600. __le16 i_suballoc_slot; /* Slot suballocator this inode
  601. belongs to */
  602. __le16 i_suballoc_bit; /* Bit offset in suballocator
  603. block group */
  604. /*10*/ __le16 i_reserved0;
  605. __le16 i_xattr_inline_size;
  606. __le32 i_clusters; /* Cluster count */
  607. __le32 i_uid; /* Owner UID */
  608. __le32 i_gid; /* Owning GID */
  609. /*20*/ __le64 i_size; /* Size in bytes */
  610. __le16 i_mode; /* File mode */
  611. __le16 i_links_count; /* Links count */
  612. __le32 i_flags; /* File flags */
  613. /*30*/ __le64 i_atime; /* Access time */
  614. __le64 i_ctime; /* Creation time */
  615. /*40*/ __le64 i_mtime; /* Modification time */
  616. __le64 i_dtime; /* Deletion time */
  617. /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
  618. __le64 i_last_eb_blk; /* Pointer to last extent
  619. block */
  620. /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
  621. __le32 i_atime_nsec;
  622. __le32 i_ctime_nsec;
  623. __le32 i_mtime_nsec;
  624. /*70*/ __le32 i_attr;
  625. __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
  626. was set in i_flags */
  627. __le16 i_dyn_features;
  628. __le64 i_xattr_loc;
  629. /*80*/ struct ocfs2_block_check i_check; /* Error checking */
  630. /*88*/ __le64 i_reserved2[6];
  631. /*B8*/ union {
  632. __le64 i_pad1; /* Generic way to refer to this
  633. 64bit union */
  634. struct {
  635. __le64 i_rdev; /* Device number */
  636. } dev1;
  637. struct { /* Info for bitmap system
  638. inodes */
  639. __le32 i_used; /* Bits (ie, clusters) used */
  640. __le32 i_total; /* Total bits (clusters)
  641. available */
  642. } bitmap1;
  643. struct { /* Info for journal system
  644. inodes */
  645. __le32 ij_flags; /* Mounted, version, etc. */
  646. __le32 ij_recovery_generation; /* Incremented when the
  647. journal is recovered
  648. after an unclean
  649. shutdown */
  650. } journal1;
  651. } id1; /* Inode type dependant 1 */
  652. /*C0*/ union {
  653. struct ocfs2_super_block i_super;
  654. struct ocfs2_local_alloc i_lab;
  655. struct ocfs2_chain_list i_chain;
  656. struct ocfs2_extent_list i_list;
  657. struct ocfs2_truncate_log i_dealloc;
  658. struct ocfs2_inline_data i_data;
  659. __u8 i_symlink[0];
  660. } id2;
  661. /* Actual on-disk size is one block */
  662. };
  663. /*
  664. * On-disk directory entry structure for OCFS2
  665. *
  666. * Packed as this structure could be accessed unaligned on 64-bit platforms
  667. */
  668. struct ocfs2_dir_entry {
  669. /*00*/ __le64 inode; /* Inode number */
  670. __le16 rec_len; /* Directory entry length */
  671. __u8 name_len; /* Name length */
  672. __u8 file_type;
  673. /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
  674. /* Actual on-disk length specified by rec_len */
  675. } __attribute__ ((packed));
  676. /*
  677. * On disk allocator group structure for OCFS2
  678. */
  679. struct ocfs2_group_desc
  680. {
  681. /*00*/ __u8 bg_signature[8]; /* Signature for validation */
  682. __le16 bg_size; /* Size of included bitmap in
  683. bytes. */
  684. __le16 bg_bits; /* Bits represented by this
  685. group. */
  686. __le16 bg_free_bits_count; /* Free bits count */
  687. __le16 bg_chain; /* What chain I am in. */
  688. /*10*/ __le32 bg_generation;
  689. __le32 bg_reserved1;
  690. __le64 bg_next_group; /* Next group in my list, in
  691. blocks */
  692. /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
  693. blocks */
  694. __le64 bg_blkno; /* Offset on disk, in blocks */
  695. /*30*/ struct ocfs2_block_check bg_check; /* Error checking */
  696. __le64 bg_reserved2;
  697. /*40*/ __u8 bg_bitmap[0];
  698. };
  699. /*
  700. * On disk extended attribute structure for OCFS2.
  701. */
  702. /*
  703. * ocfs2_xattr_entry indicates one extend attribute.
  704. *
  705. * Note that it can be stored in inode, one block or one xattr bucket.
  706. */
  707. struct ocfs2_xattr_entry {
  708. __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
  709. __le16 xe_name_offset; /* byte offset from the 1st entry in the
  710. local xattr storage(inode, xattr block or
  711. xattr bucket). */
  712. __u8 xe_name_len; /* xattr name len, does't include prefix. */
  713. __u8 xe_type; /* the low 7 bits indicate the name prefix
  714. * type and the highest bit indicates whether
  715. * the EA is stored in the local storage. */
  716. __le64 xe_value_size; /* real xattr value length. */
  717. };
  718. /*
  719. * On disk structure for xattr header.
  720. *
  721. * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
  722. * the local xattr storage.
  723. */
  724. struct ocfs2_xattr_header {
  725. __le16 xh_count; /* contains the count of how
  726. many records are in the
  727. local xattr storage. */
  728. __le16 xh_free_start; /* current offset for storing
  729. xattr. */
  730. __le16 xh_name_value_len; /* total length of name/value
  731. length in this bucket. */
  732. __le16 xh_num_buckets; /* Number of xattr buckets
  733. in this extent record,
  734. only valid in the first
  735. bucket. */
  736. struct ocfs2_block_check xh_check; /* Error checking
  737. (Note, this is only
  738. used for xattr
  739. buckets. A block uses
  740. xb_check and sets
  741. this field to zero.) */
  742. struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
  743. };
  744. /*
  745. * On disk structure for xattr value root.
  746. *
  747. * When an xattr's value is large enough, it is stored in an external
  748. * b-tree like file data. The xattr value root points to this structure.
  749. */
  750. struct ocfs2_xattr_value_root {
  751. /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
  752. __le32 xr_reserved0;
  753. __le64 xr_last_eb_blk; /* Pointer to last extent block */
  754. /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
  755. };
  756. /*
  757. * On disk structure for xattr tree root.
  758. *
  759. * It is used when there are too many extended attributes for one file. These
  760. * attributes will be organized and stored in an indexed-btree.
  761. */
  762. struct ocfs2_xattr_tree_root {
  763. /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
  764. __le32 xt_reserved0;
  765. __le64 xt_last_eb_blk; /* Pointer to last extent block */
  766. /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
  767. };
  768. #define OCFS2_XATTR_INDEXED 0x1
  769. #define OCFS2_HASH_SHIFT 5
  770. #define OCFS2_XATTR_ROUND 3
  771. #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
  772. ~(OCFS2_XATTR_ROUND))
  773. #define OCFS2_XATTR_BUCKET_SIZE 4096
  774. #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
  775. / OCFS2_MIN_BLOCKSIZE)
  776. /*
  777. * On disk structure for xattr block.
  778. */
  779. struct ocfs2_xattr_block {
  780. /*00*/ __u8 xb_signature[8]; /* Signature for verification */
  781. __le16 xb_suballoc_slot; /* Slot suballocator this
  782. block belongs to. */
  783. __le16 xb_suballoc_bit; /* Bit offset in suballocator
  784. block group */
  785. __le32 xb_fs_generation; /* Must match super block */
  786. /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
  787. struct ocfs2_block_check xb_check; /* Error checking */
  788. /*20*/ __le16 xb_flags; /* Indicates whether this block contains
  789. real xattr or a xattr tree. */
  790. __le16 xb_reserved0;
  791. __le32 xb_reserved1;
  792. __le64 xb_reserved2;
  793. /*30*/ union {
  794. struct ocfs2_xattr_header xb_header; /* xattr header if this
  795. block contains xattr */
  796. struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
  797. block cotains xattr
  798. tree. */
  799. } xb_attrs;
  800. };
  801. #define OCFS2_XATTR_ENTRY_LOCAL 0x80
  802. #define OCFS2_XATTR_TYPE_MASK 0x7F
  803. static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
  804. int local)
  805. {
  806. if (local)
  807. xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
  808. else
  809. xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
  810. }
  811. static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
  812. {
  813. return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
  814. }
  815. static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
  816. {
  817. xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
  818. }
  819. static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
  820. {
  821. return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
  822. }
  823. /*
  824. * On disk structures for global quota file
  825. */
  826. /* Magic numbers and known versions for global quota files */
  827. #define OCFS2_GLOBAL_QMAGICS {\
  828. 0x0cf52470, /* USRQUOTA */ \
  829. 0x0cf52471 /* GRPQUOTA */ \
  830. }
  831. #define OCFS2_GLOBAL_QVERSIONS {\
  832. 0, \
  833. 0, \
  834. }
  835. /* Each block of each quota file has a certain fixed number of bytes reserved
  836. * for OCFS2 internal use at its end. OCFS2 can use it for things like
  837. * checksums, etc. */
  838. #define OCFS2_QBLK_RESERVED_SPACE 8
  839. /* Generic header of all quota files */
  840. struct ocfs2_disk_dqheader {
  841. __le32 dqh_magic; /* Magic number identifying file */
  842. __le32 dqh_version; /* Quota format version */
  843. };
  844. #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
  845. /* Information header of global quota file (immediately follows the generic
  846. * header) */
  847. struct ocfs2_global_disk_dqinfo {
  848. /*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
  849. __le32 dqi_igrace; /* Grace time for inode softlimit excess */
  850. __le32 dqi_syncms; /* Time after which we sync local changes to
  851. * global quota file */
  852. __le32 dqi_blocks; /* Number of blocks in quota file */
  853. /*10*/ __le32 dqi_free_blk; /* First free block in quota file */
  854. __le32 dqi_free_entry; /* First block with free dquot entry in quota
  855. * file */
  856. };
  857. /* Structure with global user / group information. We reserve some space
  858. * for future use. */
  859. struct ocfs2_global_disk_dqblk {
  860. /*00*/ __le32 dqb_id; /* ID the structure belongs to */
  861. __le32 dqb_use_count; /* Number of nodes having reference to this structure */
  862. __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
  863. /*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
  864. __le64 dqb_curinodes; /* current # allocated inodes */
  865. /*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
  866. __le64 dqb_bsoftlimit; /* preferred limit on disk space */
  867. /*30*/ __le64 dqb_curspace; /* current space occupied */
  868. __le64 dqb_btime; /* time limit for excessive disk use */
  869. /*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
  870. __le64 dqb_pad1;
  871. /*50*/ __le64 dqb_pad2;
  872. };
  873. /*
  874. * On-disk structures for local quota file
  875. */
  876. /* Magic numbers and known versions for local quota files */
  877. #define OCFS2_LOCAL_QMAGICS {\
  878. 0x0cf524c0, /* USRQUOTA */ \
  879. 0x0cf524c1 /* GRPQUOTA */ \
  880. }
  881. #define OCFS2_LOCAL_QVERSIONS {\
  882. 0, \
  883. 0, \
  884. }
  885. /* Quota flags in dqinfo header */
  886. #define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
  887. * quota has been cleanly turned off) */
  888. #define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
  889. /* Information header of local quota file (immediately follows the generic
  890. * header) */
  891. struct ocfs2_local_disk_dqinfo {
  892. __le32 dqi_flags; /* Flags for quota file */
  893. __le32 dqi_chunks; /* Number of chunks of quota structures
  894. * with a bitmap */
  895. __le32 dqi_blocks; /* Number of blocks allocated for quota file */
  896. };
  897. /* Header of one chunk of a quota file */
  898. struct ocfs2_local_disk_chunk {
  899. __le32 dqc_free; /* Number of free entries in the bitmap */
  900. u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
  901. * chunk of quota file */
  902. };
  903. /* One entry in local quota file */
  904. struct ocfs2_local_disk_dqblk {
  905. /*00*/ __le64 dqb_id; /* id this quota applies to */
  906. __le64 dqb_spacemod; /* Change in the amount of used space */
  907. /*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
  908. };
  909. /*
  910. * The quota trailer lives at the end of each quota block.
  911. */
  912. struct ocfs2_disk_dqtrailer {
  913. /*00*/ struct ocfs2_block_check dq_check; /* Error checking */
  914. /*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
  915. };
  916. static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
  917. void *buf)
  918. {
  919. char *ptr = buf;
  920. ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
  921. return (struct ocfs2_disk_dqtrailer *)ptr;
  922. }
  923. #ifdef __KERNEL__
  924. static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
  925. {
  926. return sb->s_blocksize -
  927. offsetof(struct ocfs2_dinode, id2.i_symlink);
  928. }
  929. static inline int ocfs2_max_inline_data(struct super_block *sb)
  930. {
  931. return sb->s_blocksize -
  932. offsetof(struct ocfs2_dinode, id2.i_data.id_data);
  933. }
  934. static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
  935. struct ocfs2_dinode *di)
  936. {
  937. unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
  938. if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
  939. return sb->s_blocksize -
  940. offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
  941. xattrsize;
  942. else
  943. return sb->s_blocksize -
  944. offsetof(struct ocfs2_dinode, id2.i_data.id_data);
  945. }
  946. static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
  947. {
  948. int size;
  949. size = sb->s_blocksize -
  950. offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
  951. return size / sizeof(struct ocfs2_extent_rec);
  952. }
  953. static inline int ocfs2_extent_recs_per_inode_with_xattr(
  954. struct super_block *sb,
  955. struct ocfs2_dinode *di)
  956. {
  957. int size;
  958. unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
  959. if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
  960. size = sb->s_blocksize -
  961. offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
  962. xattrsize;
  963. else
  964. size = sb->s_blocksize -
  965. offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
  966. return size / sizeof(struct ocfs2_extent_rec);
  967. }
  968. static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
  969. {
  970. int size;
  971. size = sb->s_blocksize -
  972. offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
  973. return size / sizeof(struct ocfs2_chain_rec);
  974. }
  975. static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
  976. {
  977. int size;
  978. size = sb->s_blocksize -
  979. offsetof(struct ocfs2_extent_block, h_list.l_recs);
  980. return size / sizeof(struct ocfs2_extent_rec);
  981. }
  982. static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
  983. {
  984. u16 size;
  985. size = sb->s_blocksize -
  986. offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
  987. return size;
  988. }
  989. static inline int ocfs2_group_bitmap_size(struct super_block *sb)
  990. {
  991. int size;
  992. size = sb->s_blocksize -
  993. offsetof(struct ocfs2_group_desc, bg_bitmap);
  994. return size;
  995. }
  996. static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
  997. {
  998. int size;
  999. size = sb->s_blocksize -
  1000. offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
  1001. return size / sizeof(struct ocfs2_truncate_rec);
  1002. }
  1003. static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
  1004. {
  1005. u64 offset = OCFS2_BACKUP_SB_START;
  1006. if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
  1007. offset <<= (2 * index);
  1008. offset >>= sb->s_blocksize_bits;
  1009. return offset;
  1010. }
  1011. return 0;
  1012. }
  1013. static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
  1014. {
  1015. int size;
  1016. size = sb->s_blocksize -
  1017. offsetof(struct ocfs2_xattr_block,
  1018. xb_attrs.xb_root.xt_list.l_recs);
  1019. return size / sizeof(struct ocfs2_extent_rec);
  1020. }
  1021. #else
  1022. static inline int ocfs2_fast_symlink_chars(int blocksize)
  1023. {
  1024. return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
  1025. }
  1026. static inline int ocfs2_max_inline_data(int blocksize)
  1027. {
  1028. return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
  1029. }
  1030. static inline int ocfs2_extent_recs_per_inode(int blocksize)
  1031. {
  1032. int size;
  1033. size = blocksize -
  1034. offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
  1035. return size / sizeof(struct ocfs2_extent_rec);
  1036. }
  1037. static inline int ocfs2_chain_recs_per_inode(int blocksize)
  1038. {
  1039. int size;
  1040. size = blocksize -
  1041. offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
  1042. return size / sizeof(struct ocfs2_chain_rec);
  1043. }
  1044. static inline int ocfs2_extent_recs_per_eb(int blocksize)
  1045. {
  1046. int size;
  1047. size = blocksize -
  1048. offsetof(struct ocfs2_extent_block, h_list.l_recs);
  1049. return size / sizeof(struct ocfs2_extent_rec);
  1050. }
  1051. static inline int ocfs2_local_alloc_size(int blocksize)
  1052. {
  1053. int size;
  1054. size = blocksize -
  1055. offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
  1056. return size;
  1057. }
  1058. static inline int ocfs2_group_bitmap_size(int blocksize)
  1059. {
  1060. int size;
  1061. size = blocksize -
  1062. offsetof(struct ocfs2_group_desc, bg_bitmap);
  1063. return size;
  1064. }
  1065. static inline int ocfs2_truncate_recs_per_inode(int blocksize)
  1066. {
  1067. int size;
  1068. size = blocksize -
  1069. offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
  1070. return size / sizeof(struct ocfs2_truncate_rec);
  1071. }
  1072. static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
  1073. {
  1074. uint64_t offset = OCFS2_BACKUP_SB_START;
  1075. if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
  1076. offset <<= (2 * index);
  1077. offset /= blocksize;
  1078. return offset;
  1079. }
  1080. return 0;
  1081. }
  1082. static inline int ocfs2_xattr_recs_per_xb(int blocksize)
  1083. {
  1084. int size;
  1085. size = blocksize -
  1086. offsetof(struct ocfs2_xattr_block,
  1087. xb_attrs.xb_root.xt_list.l_recs);
  1088. return size / sizeof(struct ocfs2_extent_rec);
  1089. }
  1090. #endif /* __KERNEL__ */
  1091. static inline int ocfs2_system_inode_is_global(int type)
  1092. {
  1093. return ((type >= 0) &&
  1094. (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
  1095. }
  1096. static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
  1097. int type, int slot)
  1098. {
  1099. int chars;
  1100. /*
  1101. * Global system inodes can only have one copy. Everything
  1102. * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
  1103. * list has a copy per slot.
  1104. */
  1105. if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
  1106. chars = snprintf(buf, len, "%s",
  1107. ocfs2_system_inodes[type].si_name);
  1108. else
  1109. chars = snprintf(buf, len,
  1110. ocfs2_system_inodes[type].si_name,
  1111. slot);
  1112. return chars;
  1113. }
  1114. static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
  1115. umode_t mode)
  1116. {
  1117. de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
  1118. }
  1119. #endif /* _OCFS2_FS_H */