ext4.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. /*
  2. * ext4.h
  3. *
  4. * Copyright (C) 1992, 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. *
  9. * from
  10. *
  11. * linux/include/linux/minix_fs.h
  12. *
  13. * Copyright (C) 1991, 1992 Linus Torvalds
  14. */
  15. #ifndef _EXT4_H
  16. #define _EXT4_H
  17. #include <linux/types.h>
  18. #include <linux/blkdev.h>
  19. #include <linux/magic.h>
  20. #include "ext4_i.h"
  21. /*
  22. * The fourth extended filesystem constants/structures
  23. */
  24. /*
  25. * Define EXT4FS_DEBUG to produce debug messages
  26. */
  27. #undef EXT4FS_DEBUG
  28. /*
  29. * Define EXT4_RESERVATION to reserve data blocks for expanding files
  30. */
  31. #define EXT4_DEFAULT_RESERVE_BLOCKS 8
  32. /*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
  33. #define EXT4_MAX_RESERVE_BLOCKS 1027
  34. #define EXT4_RESERVE_WINDOW_NOT_ALLOCATED 0
  35. /*
  36. * Debug code
  37. */
  38. #ifdef EXT4FS_DEBUG
  39. #define ext4_debug(f, a...) \
  40. do { \
  41. printk (KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \
  42. __FILE__, __LINE__, __func__); \
  43. printk (KERN_DEBUG f, ## a); \
  44. } while (0)
  45. #else
  46. #define ext4_debug(f, a...) do {} while (0)
  47. #endif
  48. #define EXT4_MULTIBLOCK_ALLOCATOR 1
  49. /* prefer goal again. length */
  50. #define EXT4_MB_HINT_MERGE 1
  51. /* blocks already reserved */
  52. #define EXT4_MB_HINT_RESERVED 2
  53. /* metadata is being allocated */
  54. #define EXT4_MB_HINT_METADATA 4
  55. /* first blocks in the file */
  56. #define EXT4_MB_HINT_FIRST 8
  57. /* search for the best chunk */
  58. #define EXT4_MB_HINT_BEST 16
  59. /* data is being allocated */
  60. #define EXT4_MB_HINT_DATA 32
  61. /* don't preallocate (for tails) */
  62. #define EXT4_MB_HINT_NOPREALLOC 64
  63. /* allocate for locality group */
  64. #define EXT4_MB_HINT_GROUP_ALLOC 128
  65. /* allocate goal blocks or none */
  66. #define EXT4_MB_HINT_GOAL_ONLY 256
  67. /* goal is meaningful */
  68. #define EXT4_MB_HINT_TRY_GOAL 512
  69. struct ext4_allocation_request {
  70. /* target inode for block we're allocating */
  71. struct inode *inode;
  72. /* logical block in target inode */
  73. ext4_lblk_t logical;
  74. /* phys. target (a hint) */
  75. ext4_fsblk_t goal;
  76. /* the closest logical allocated block to the left */
  77. ext4_lblk_t lleft;
  78. /* phys. block for ^^^ */
  79. ext4_fsblk_t pleft;
  80. /* the closest logical allocated block to the right */
  81. ext4_lblk_t lright;
  82. /* phys. block for ^^^ */
  83. ext4_fsblk_t pright;
  84. /* how many blocks we want to allocate */
  85. unsigned long len;
  86. /* flags. see above EXT4_MB_HINT_* */
  87. unsigned long flags;
  88. };
  89. /*
  90. * Special inodes numbers
  91. */
  92. #define EXT4_BAD_INO 1 /* Bad blocks inode */
  93. #define EXT4_ROOT_INO 2 /* Root inode */
  94. #define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */
  95. #define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */
  96. #define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */
  97. #define EXT4_JOURNAL_INO 8 /* Journal inode */
  98. /* First non-reserved inode for old ext4 filesystems */
  99. #define EXT4_GOOD_OLD_FIRST_INO 11
  100. /*
  101. * Maximal count of links to a file
  102. */
  103. #define EXT4_LINK_MAX 65000
  104. /*
  105. * Macro-instructions used to manage several block sizes
  106. */
  107. #define EXT4_MIN_BLOCK_SIZE 1024
  108. #define EXT4_MAX_BLOCK_SIZE 65536
  109. #define EXT4_MIN_BLOCK_LOG_SIZE 10
  110. #ifdef __KERNEL__
  111. # define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize)
  112. #else
  113. # define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size)
  114. #endif
  115. #define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof (__u32))
  116. #ifdef __KERNEL__
  117. # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
  118. #else
  119. # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
  120. #endif
  121. #ifdef __KERNEL__
  122. #define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits)
  123. #define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size)
  124. #define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino)
  125. #else
  126. #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
  127. EXT4_GOOD_OLD_INODE_SIZE : \
  128. (s)->s_inode_size)
  129. #define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
  130. EXT4_GOOD_OLD_FIRST_INO : \
  131. (s)->s_first_ino)
  132. #endif
  133. #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits)))
  134. /*
  135. * Structure of a blocks group descriptor
  136. */
  137. struct ext4_group_desc
  138. {
  139. __le32 bg_block_bitmap_lo; /* Blocks bitmap block */
  140. __le32 bg_inode_bitmap_lo; /* Inodes bitmap block */
  141. __le32 bg_inode_table_lo; /* Inodes table block */
  142. __le16 bg_free_blocks_count; /* Free blocks count */
  143. __le16 bg_free_inodes_count; /* Free inodes count */
  144. __le16 bg_used_dirs_count; /* Directories count */
  145. __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
  146. __u32 bg_reserved[2]; /* Likely block/inode bitmap checksum */
  147. __le16 bg_itable_unused; /* Unused inodes count */
  148. __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */
  149. __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
  150. __le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */
  151. __le32 bg_inode_table_hi; /* Inodes table block MSB */
  152. __le16 bg_free_blocks_count_hi;/* Free blocks count MSB */
  153. __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */
  154. __le16 bg_used_dirs_count_hi; /* Directories count MSB */
  155. __le16 bg_itable_unused_hi; /* Unused inodes count MSB */
  156. __u32 bg_reserved2[3];
  157. };
  158. /*
  159. * Structure of a flex block group info
  160. */
  161. struct flex_groups {
  162. __u32 free_inodes;
  163. __u32 free_blocks;
  164. };
  165. #define EXT4_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */
  166. #define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */
  167. #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */
  168. #ifdef __KERNEL__
  169. #include "ext4_sb.h"
  170. #endif
  171. /*
  172. * Macro-instructions used to manage group descriptors
  173. */
  174. #define EXT4_MIN_DESC_SIZE 32
  175. #define EXT4_MIN_DESC_SIZE_64BIT 64
  176. #define EXT4_MAX_DESC_SIZE EXT4_MIN_BLOCK_SIZE
  177. #define EXT4_DESC_SIZE(s) (EXT4_SB(s)->s_desc_size)
  178. #ifdef __KERNEL__
  179. # define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group)
  180. # define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block)
  181. # define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group)
  182. # define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits)
  183. #else
  184. # define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
  185. # define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_DESC_SIZE(s))
  186. # define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
  187. #endif
  188. /*
  189. * Constants relative to the data blocks
  190. */
  191. #define EXT4_NDIR_BLOCKS 12
  192. #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS
  193. #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1)
  194. #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1)
  195. #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1)
  196. /*
  197. * Inode flags
  198. */
  199. #define EXT4_SECRM_FL 0x00000001 /* Secure deletion */
  200. #define EXT4_UNRM_FL 0x00000002 /* Undelete */
  201. #define EXT4_COMPR_FL 0x00000004 /* Compress file */
  202. #define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */
  203. #define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */
  204. #define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */
  205. #define EXT4_NODUMP_FL 0x00000040 /* do not dump file */
  206. #define EXT4_NOATIME_FL 0x00000080 /* do not update atime */
  207. /* Reserved for compression usage... */
  208. #define EXT4_DIRTY_FL 0x00000100
  209. #define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
  210. #define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */
  211. #define EXT4_ECOMPR_FL 0x00000800 /* Compression error */
  212. /* End compression flags --- maybe not all used */
  213. #define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */
  214. #define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */
  215. #define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
  216. #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */
  217. #define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
  218. #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
  219. #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */
  220. #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
  221. #define EXT4_EXT_MIGRATE 0x00100000 /* Inode is migrating */
  222. #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
  223. #define EXT4_FL_USER_VISIBLE 0x000BDFFF /* User visible flags */
  224. #define EXT4_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
  225. /*
  226. * Inode dynamic state flags
  227. */
  228. #define EXT4_STATE_JDATA 0x00000001 /* journaled data exists */
  229. #define EXT4_STATE_NEW 0x00000002 /* inode is newly created */
  230. #define EXT4_STATE_XATTR 0x00000004 /* has in-inode xattrs */
  231. #define EXT4_STATE_NO_EXPAND 0x00000008 /* No space for expansion */
  232. /* Used to pass group descriptor data when online resize is done */
  233. struct ext4_new_group_input {
  234. __u32 group; /* Group number for this data */
  235. __u64 block_bitmap; /* Absolute block number of block bitmap */
  236. __u64 inode_bitmap; /* Absolute block number of inode bitmap */
  237. __u64 inode_table; /* Absolute block number of inode table start */
  238. __u32 blocks_count; /* Total number of blocks in this group */
  239. __u16 reserved_blocks; /* Number of reserved blocks in this group */
  240. __u16 unused;
  241. };
  242. /* The struct ext4_new_group_input in kernel space, with free_blocks_count */
  243. struct ext4_new_group_data {
  244. __u32 group;
  245. __u64 block_bitmap;
  246. __u64 inode_bitmap;
  247. __u64 inode_table;
  248. __u32 blocks_count;
  249. __u16 reserved_blocks;
  250. __u16 unused;
  251. __u32 free_blocks_count;
  252. };
  253. /*
  254. * Following is used by preallocation code to tell get_blocks() that we
  255. * want uninitialzed extents.
  256. */
  257. #define EXT4_CREATE_UNINITIALIZED_EXT 2
  258. /*
  259. * ioctl commands
  260. */
  261. #define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS
  262. #define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS
  263. #define EXT4_IOC_GETVERSION _IOR('f', 3, long)
  264. #define EXT4_IOC_SETVERSION _IOW('f', 4, long)
  265. #define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
  266. #define EXT4_IOC_GROUP_ADD _IOW('f', 8,struct ext4_new_group_input)
  267. #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION
  268. #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION
  269. #ifdef CONFIG_JBD2_DEBUG
  270. #define EXT4_IOC_WAIT_FOR_READONLY _IOR('f', 99, long)
  271. #endif
  272. #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)
  273. #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long)
  274. #define EXT4_IOC_MIGRATE _IO('f', 7)
  275. /*
  276. * ioctl commands in 32 bit emulation
  277. */
  278. #define EXT4_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  279. #define EXT4_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  280. #define EXT4_IOC32_GETVERSION _IOR('f', 3, int)
  281. #define EXT4_IOC32_SETVERSION _IOW('f', 4, int)
  282. #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
  283. #define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)
  284. #define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
  285. #ifdef CONFIG_JBD2_DEBUG
  286. #define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
  287. #endif
  288. #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION
  289. #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
  290. /*
  291. * Mount options
  292. */
  293. struct ext4_mount_options {
  294. unsigned long s_mount_opt;
  295. uid_t s_resuid;
  296. gid_t s_resgid;
  297. unsigned long s_commit_interval;
  298. #ifdef CONFIG_QUOTA
  299. int s_jquota_fmt;
  300. char *s_qf_names[MAXQUOTAS];
  301. #endif
  302. };
  303. /*
  304. * Structure of an inode on the disk
  305. */
  306. struct ext4_inode {
  307. __le16 i_mode; /* File mode */
  308. __le16 i_uid; /* Low 16 bits of Owner Uid */
  309. __le32 i_size_lo; /* Size in bytes */
  310. __le32 i_atime; /* Access time */
  311. __le32 i_ctime; /* Inode Change time */
  312. __le32 i_mtime; /* Modification time */
  313. __le32 i_dtime; /* Deletion Time */
  314. __le16 i_gid; /* Low 16 bits of Group Id */
  315. __le16 i_links_count; /* Links count */
  316. __le32 i_blocks_lo; /* Blocks count */
  317. __le32 i_flags; /* File flags */
  318. union {
  319. struct {
  320. __le32 l_i_version;
  321. } linux1;
  322. struct {
  323. __u32 h_i_translator;
  324. } hurd1;
  325. struct {
  326. __u32 m_i_reserved1;
  327. } masix1;
  328. } osd1; /* OS dependent 1 */
  329. __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */
  330. __le32 i_generation; /* File version (for NFS) */
  331. __le32 i_file_acl_lo; /* File ACL */
  332. __le32 i_size_high;
  333. __le32 i_obso_faddr; /* Obsoleted fragment address */
  334. union {
  335. struct {
  336. __le16 l_i_blocks_high; /* were l_i_reserved1 */
  337. __le16 l_i_file_acl_high;
  338. __le16 l_i_uid_high; /* these 2 fields */
  339. __le16 l_i_gid_high; /* were reserved2[0] */
  340. __u32 l_i_reserved2;
  341. } linux2;
  342. struct {
  343. __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
  344. __u16 h_i_mode_high;
  345. __u16 h_i_uid_high;
  346. __u16 h_i_gid_high;
  347. __u32 h_i_author;
  348. } hurd2;
  349. struct {
  350. __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
  351. __le16 m_i_file_acl_high;
  352. __u32 m_i_reserved2[2];
  353. } masix2;
  354. } osd2; /* OS dependent 2 */
  355. __le16 i_extra_isize;
  356. __le16 i_pad1;
  357. __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */
  358. __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */
  359. __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
  360. __le32 i_crtime; /* File Creation time */
  361. __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
  362. __le32 i_version_hi; /* high 32 bits for 64-bit version */
  363. };
  364. #define EXT4_EPOCH_BITS 2
  365. #define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)
  366. #define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS)
  367. /*
  368. * Extended fields will fit into an inode if the filesystem was formatted
  369. * with large inodes (-I 256 or larger) and there are not currently any EAs
  370. * consuming all of the available space. For new inodes we always reserve
  371. * enough space for the kernel's known extended fields, but for inodes
  372. * created with an old kernel this might not have been the case. None of
  373. * the extended inode fields is critical for correct filesystem operation.
  374. * This macro checks if a certain field fits in the inode. Note that
  375. * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize
  376. */
  377. #define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \
  378. ((offsetof(typeof(*ext4_inode), field) + \
  379. sizeof((ext4_inode)->field)) \
  380. <= (EXT4_GOOD_OLD_INODE_SIZE + \
  381. (einode)->i_extra_isize)) \
  382. static inline __le32 ext4_encode_extra_time(struct timespec *time)
  383. {
  384. return cpu_to_le32((sizeof(time->tv_sec) > 4 ?
  385. time->tv_sec >> 32 : 0) |
  386. ((time->tv_nsec << 2) & EXT4_NSEC_MASK));
  387. }
  388. static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra)
  389. {
  390. if (sizeof(time->tv_sec) > 4)
  391. time->tv_sec |= (__u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK)
  392. << 32;
  393. time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> 2;
  394. }
  395. #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \
  396. do { \
  397. (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \
  398. if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
  399. (raw_inode)->xtime ## _extra = \
  400. ext4_encode_extra_time(&(inode)->xtime); \
  401. } while (0)
  402. #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \
  403. do { \
  404. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
  405. (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \
  406. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
  407. (raw_inode)->xtime ## _extra = \
  408. ext4_encode_extra_time(&(einode)->xtime); \
  409. } while (0)
  410. #define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \
  411. do { \
  412. (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \
  413. if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
  414. ext4_decode_extra_time(&(inode)->xtime, \
  415. raw_inode->xtime ## _extra); \
  416. } while (0)
  417. #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \
  418. do { \
  419. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
  420. (einode)->xtime.tv_sec = \
  421. (signed)le32_to_cpu((raw_inode)->xtime); \
  422. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
  423. ext4_decode_extra_time(&(einode)->xtime, \
  424. raw_inode->xtime ## _extra); \
  425. } while (0)
  426. #define i_disk_version osd1.linux1.l_i_version
  427. #if defined(__KERNEL__) || defined(__linux__)
  428. #define i_reserved1 osd1.linux1.l_i_reserved1
  429. #define i_file_acl_high osd2.linux2.l_i_file_acl_high
  430. #define i_blocks_high osd2.linux2.l_i_blocks_high
  431. #define i_uid_low i_uid
  432. #define i_gid_low i_gid
  433. #define i_uid_high osd2.linux2.l_i_uid_high
  434. #define i_gid_high osd2.linux2.l_i_gid_high
  435. #define i_reserved2 osd2.linux2.l_i_reserved2
  436. #elif defined(__GNU__)
  437. #define i_translator osd1.hurd1.h_i_translator
  438. #define i_uid_high osd2.hurd2.h_i_uid_high
  439. #define i_gid_high osd2.hurd2.h_i_gid_high
  440. #define i_author osd2.hurd2.h_i_author
  441. #elif defined(__masix__)
  442. #define i_reserved1 osd1.masix1.m_i_reserved1
  443. #define i_file_acl_high osd2.masix2.m_i_file_acl_high
  444. #define i_reserved2 osd2.masix2.m_i_reserved2
  445. #endif /* defined(__KERNEL__) || defined(__linux__) */
  446. /*
  447. * File system states
  448. */
  449. #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */
  450. #define EXT4_ERROR_FS 0x0002 /* Errors detected */
  451. #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */
  452. /*
  453. * Misc. filesystem flags
  454. */
  455. #define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */
  456. #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */
  457. #define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */
  458. /*
  459. * Mount flags
  460. */
  461. #define EXT4_MOUNT_CHECK 0x00001 /* Do mount-time checks */
  462. #define EXT4_MOUNT_OLDALLOC 0x00002 /* Don't use the new Orlov allocator */
  463. #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */
  464. #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */
  465. #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */
  466. #define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */
  467. #define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */
  468. #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */
  469. #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/
  470. #define EXT4_MOUNT_ABORT 0x00200 /* Fatal error detected */
  471. #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */
  472. #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */
  473. #define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */
  474. #define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */
  475. #define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */
  476. #define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */
  477. #define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */
  478. #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
  479. #define EXT4_MOUNT_RESERVATION 0x10000 /* Preallocation */
  480. #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
  481. #define EXT4_MOUNT_NOBH 0x40000 /* No bufferheads */
  482. #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
  483. #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
  484. #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
  485. #define EXT4_MOUNT_EXTENTS 0x400000 /* Extents support */
  486. #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
  487. #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
  488. #define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */
  489. #define EXT4_MOUNT_MBALLOC 0x4000000 /* Buddy allocation support */
  490. /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
  491. #ifndef _LINUX_EXT2_FS_H
  492. #define clear_opt(o, opt) o &= ~EXT4_MOUNT_##opt
  493. #define set_opt(o, opt) o |= EXT4_MOUNT_##opt
  494. #define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \
  495. EXT4_MOUNT_##opt)
  496. #else
  497. #define EXT2_MOUNT_NOLOAD EXT4_MOUNT_NOLOAD
  498. #define EXT2_MOUNT_ABORT EXT4_MOUNT_ABORT
  499. #define EXT2_MOUNT_DATA_FLAGS EXT4_MOUNT_DATA_FLAGS
  500. #endif
  501. #define ext4_set_bit ext2_set_bit
  502. #define ext4_set_bit_atomic ext2_set_bit_atomic
  503. #define ext4_clear_bit ext2_clear_bit
  504. #define ext4_clear_bit_atomic ext2_clear_bit_atomic
  505. #define ext4_test_bit ext2_test_bit
  506. #define ext4_find_first_zero_bit ext2_find_first_zero_bit
  507. #define ext4_find_next_zero_bit ext2_find_next_zero_bit
  508. #define ext4_find_next_bit ext2_find_next_bit
  509. /*
  510. * Maximal mount counts between two filesystem checks
  511. */
  512. #define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
  513. #define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */
  514. /*
  515. * Behaviour when detecting errors
  516. */
  517. #define EXT4_ERRORS_CONTINUE 1 /* Continue execution */
  518. #define EXT4_ERRORS_RO 2 /* Remount fs read-only */
  519. #define EXT4_ERRORS_PANIC 3 /* Panic */
  520. #define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
  521. /*
  522. * Structure of the super block
  523. */
  524. struct ext4_super_block {
  525. /*00*/ __le32 s_inodes_count; /* Inodes count */
  526. __le32 s_blocks_count_lo; /* Blocks count */
  527. __le32 s_r_blocks_count_lo; /* Reserved blocks count */
  528. __le32 s_free_blocks_count_lo; /* Free blocks count */
  529. /*10*/ __le32 s_free_inodes_count; /* Free inodes count */
  530. __le32 s_first_data_block; /* First Data Block */
  531. __le32 s_log_block_size; /* Block size */
  532. __le32 s_obso_log_frag_size; /* Obsoleted fragment size */
  533. /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */
  534. __le32 s_obso_frags_per_group; /* Obsoleted fragments per group */
  535. __le32 s_inodes_per_group; /* # Inodes per group */
  536. __le32 s_mtime; /* Mount time */
  537. /*30*/ __le32 s_wtime; /* Write time */
  538. __le16 s_mnt_count; /* Mount count */
  539. __le16 s_max_mnt_count; /* Maximal mount count */
  540. __le16 s_magic; /* Magic signature */
  541. __le16 s_state; /* File system state */
  542. __le16 s_errors; /* Behaviour when detecting errors */
  543. __le16 s_minor_rev_level; /* minor revision level */
  544. /*40*/ __le32 s_lastcheck; /* time of last check */
  545. __le32 s_checkinterval; /* max. time between checks */
  546. __le32 s_creator_os; /* OS */
  547. __le32 s_rev_level; /* Revision level */
  548. /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */
  549. __le16 s_def_resgid; /* Default gid for reserved blocks */
  550. /*
  551. * These fields are for EXT4_DYNAMIC_REV superblocks only.
  552. *
  553. * Note: the difference between the compatible feature set and
  554. * the incompatible feature set is that if there is a bit set
  555. * in the incompatible feature set that the kernel doesn't
  556. * know about, it should refuse to mount the filesystem.
  557. *
  558. * e2fsck's requirements are more strict; if it doesn't know
  559. * about a feature in either the compatible or incompatible
  560. * feature set, it must abort and not try to meddle with
  561. * things it doesn't understand...
  562. */
  563. __le32 s_first_ino; /* First non-reserved inode */
  564. __le16 s_inode_size; /* size of inode structure */
  565. __le16 s_block_group_nr; /* block group # of this superblock */
  566. __le32 s_feature_compat; /* compatible feature set */
  567. /*60*/ __le32 s_feature_incompat; /* incompatible feature set */
  568. __le32 s_feature_ro_compat; /* readonly-compatible feature set */
  569. /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */
  570. /*78*/ char s_volume_name[16]; /* volume name */
  571. /*88*/ char s_last_mounted[64]; /* directory where last mounted */
  572. /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */
  573. /*
  574. * Performance hints. Directory preallocation should only
  575. * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
  576. */
  577. __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
  578. __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
  579. __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */
  580. /*
  581. * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
  582. */
  583. /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */
  584. /*E0*/ __le32 s_journal_inum; /* inode number of journal file */
  585. __le32 s_journal_dev; /* device number of journal file */
  586. __le32 s_last_orphan; /* start of list of inodes to delete */
  587. __le32 s_hash_seed[4]; /* HTREE hash seed */
  588. __u8 s_def_hash_version; /* Default hash version to use */
  589. __u8 s_reserved_char_pad;
  590. __le16 s_desc_size; /* size of group descriptor */
  591. /*100*/ __le32 s_default_mount_opts;
  592. __le32 s_first_meta_bg; /* First metablock block group */
  593. __le32 s_mkfs_time; /* When the filesystem was created */
  594. __le32 s_jnl_blocks[17]; /* Backup of the journal inode */
  595. /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
  596. /*150*/ __le32 s_blocks_count_hi; /* Blocks count */
  597. __le32 s_r_blocks_count_hi; /* Reserved blocks count */
  598. __le32 s_free_blocks_count_hi; /* Free blocks count */
  599. __le16 s_min_extra_isize; /* All inodes have at least # bytes */
  600. __le16 s_want_extra_isize; /* New inodes should reserve # bytes */
  601. __le32 s_flags; /* Miscellaneous flags */
  602. __le16 s_raid_stride; /* RAID stride */
  603. __le16 s_mmp_interval; /* # seconds to wait in MMP checking */
  604. __le64 s_mmp_block; /* Block for multi-mount protection */
  605. __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
  606. __u8 s_log_groups_per_flex; /* FLEX_BG group size */
  607. __u8 s_reserved_char_pad2;
  608. __le16 s_reserved_pad;
  609. __u32 s_reserved[162]; /* Padding to the end of the block */
  610. };
  611. #ifdef __KERNEL__
  612. static inline struct ext4_sb_info * EXT4_SB(struct super_block *sb)
  613. {
  614. return sb->s_fs_info;
  615. }
  616. static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
  617. {
  618. return container_of(inode, struct ext4_inode_info, vfs_inode);
  619. }
  620. static inline struct timespec ext4_current_time(struct inode *inode)
  621. {
  622. return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
  623. current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
  624. }
  625. static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
  626. {
  627. return ino == EXT4_ROOT_INO ||
  628. ino == EXT4_JOURNAL_INO ||
  629. ino == EXT4_RESIZE_INO ||
  630. (ino >= EXT4_FIRST_INO(sb) &&
  631. ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count));
  632. }
  633. #else
  634. /* Assume that user mode programs are passing in an ext4fs superblock, not
  635. * a kernel struct super_block. This will allow us to call the feature-test
  636. * macros from user land. */
  637. #define EXT4_SB(sb) (sb)
  638. #endif
  639. #define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime
  640. /*
  641. * Codes for operating systems
  642. */
  643. #define EXT4_OS_LINUX 0
  644. #define EXT4_OS_HURD 1
  645. #define EXT4_OS_MASIX 2
  646. #define EXT4_OS_FREEBSD 3
  647. #define EXT4_OS_LITES 4
  648. /*
  649. * Revision levels
  650. */
  651. #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */
  652. #define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
  653. #define EXT4_CURRENT_REV EXT4_GOOD_OLD_REV
  654. #define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV
  655. #define EXT4_GOOD_OLD_INODE_SIZE 128
  656. /*
  657. * Feature set definitions
  658. */
  659. #define EXT4_HAS_COMPAT_FEATURE(sb,mask) \
  660. ( EXT4_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
  661. #define EXT4_HAS_RO_COMPAT_FEATURE(sb,mask) \
  662. ( EXT4_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
  663. #define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \
  664. ( EXT4_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
  665. #define EXT4_SET_COMPAT_FEATURE(sb,mask) \
  666. EXT4_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
  667. #define EXT4_SET_RO_COMPAT_FEATURE(sb,mask) \
  668. EXT4_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
  669. #define EXT4_SET_INCOMPAT_FEATURE(sb,mask) \
  670. EXT4_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
  671. #define EXT4_CLEAR_COMPAT_FEATURE(sb,mask) \
  672. EXT4_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
  673. #define EXT4_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
  674. EXT4_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
  675. #define EXT4_CLEAR_INCOMPAT_FEATURE(sb,mask) \
  676. EXT4_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
  677. #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
  678. #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
  679. #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  680. #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
  681. #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
  682. #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
  683. #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
  684. #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
  685. #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
  686. #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
  687. #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
  688. #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
  689. #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
  690. #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
  691. #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
  692. #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
  693. #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
  694. #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
  695. #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
  696. #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
  697. #define EXT4_FEATURE_INCOMPAT_MMP 0x0100
  698. #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
  699. #define EXT4_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
  700. #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \
  701. EXT4_FEATURE_INCOMPAT_RECOVER| \
  702. EXT4_FEATURE_INCOMPAT_META_BG| \
  703. EXT4_FEATURE_INCOMPAT_EXTENTS| \
  704. EXT4_FEATURE_INCOMPAT_64BIT| \
  705. EXT4_FEATURE_INCOMPAT_FLEX_BG)
  706. #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  707. EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
  708. EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
  709. EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
  710. EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
  711. EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\
  712. EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
  713. /*
  714. * Default values for user and/or group using reserved blocks
  715. */
  716. #define EXT4_DEF_RESUID 0
  717. #define EXT4_DEF_RESGID 0
  718. /*
  719. * Default mount options
  720. */
  721. #define EXT4_DEFM_DEBUG 0x0001
  722. #define EXT4_DEFM_BSDGROUPS 0x0002
  723. #define EXT4_DEFM_XATTR_USER 0x0004
  724. #define EXT4_DEFM_ACL 0x0008
  725. #define EXT4_DEFM_UID16 0x0010
  726. #define EXT4_DEFM_JMODE 0x0060
  727. #define EXT4_DEFM_JMODE_DATA 0x0020
  728. #define EXT4_DEFM_JMODE_ORDERED 0x0040
  729. #define EXT4_DEFM_JMODE_WBACK 0x0060
  730. /*
  731. * Structure of a directory entry
  732. */
  733. #define EXT4_NAME_LEN 255
  734. struct ext4_dir_entry {
  735. __le32 inode; /* Inode number */
  736. __le16 rec_len; /* Directory entry length */
  737. __le16 name_len; /* Name length */
  738. char name[EXT4_NAME_LEN]; /* File name */
  739. };
  740. /*
  741. * The new version of the directory entry. Since EXT4 structures are
  742. * stored in intel byte order, and the name_len field could never be
  743. * bigger than 255 chars, it's safe to reclaim the extra byte for the
  744. * file_type field.
  745. */
  746. struct ext4_dir_entry_2 {
  747. __le32 inode; /* Inode number */
  748. __le16 rec_len; /* Directory entry length */
  749. __u8 name_len; /* Name length */
  750. __u8 file_type;
  751. char name[EXT4_NAME_LEN]; /* File name */
  752. };
  753. /*
  754. * Ext4 directory file types. Only the low 3 bits are used. The
  755. * other bits are reserved for now.
  756. */
  757. #define EXT4_FT_UNKNOWN 0
  758. #define EXT4_FT_REG_FILE 1
  759. #define EXT4_FT_DIR 2
  760. #define EXT4_FT_CHRDEV 3
  761. #define EXT4_FT_BLKDEV 4
  762. #define EXT4_FT_FIFO 5
  763. #define EXT4_FT_SOCK 6
  764. #define EXT4_FT_SYMLINK 7
  765. #define EXT4_FT_MAX 8
  766. /*
  767. * EXT4_DIR_PAD defines the directory entries boundaries
  768. *
  769. * NOTE: It must be a multiple of 4
  770. */
  771. #define EXT4_DIR_PAD 4
  772. #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1)
  773. #define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \
  774. ~EXT4_DIR_ROUND)
  775. #define EXT4_MAX_REC_LEN ((1<<16)-1)
  776. static inline unsigned ext4_rec_len_from_disk(__le16 dlen)
  777. {
  778. unsigned len = le16_to_cpu(dlen);
  779. if (len == EXT4_MAX_REC_LEN)
  780. return 1 << 16;
  781. return len;
  782. }
  783. static inline __le16 ext4_rec_len_to_disk(unsigned len)
  784. {
  785. if (len == (1 << 16))
  786. return cpu_to_le16(EXT4_MAX_REC_LEN);
  787. else if (len > (1 << 16))
  788. BUG();
  789. return cpu_to_le16(len);
  790. }
  791. /*
  792. * Hash Tree Directory indexing
  793. * (c) Daniel Phillips, 2001
  794. */
  795. #define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \
  796. EXT4_FEATURE_COMPAT_DIR_INDEX) && \
  797. (EXT4_I(dir)->i_flags & EXT4_INDEX_FL))
  798. #define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX)
  799. #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
  800. /* Legal values for the dx_root hash_version field: */
  801. #define DX_HASH_LEGACY 0
  802. #define DX_HASH_HALF_MD4 1
  803. #define DX_HASH_TEA 2
  804. #ifdef __KERNEL__
  805. /* hash info structure used by the directory hash */
  806. struct dx_hash_info
  807. {
  808. u32 hash;
  809. u32 minor_hash;
  810. int hash_version;
  811. u32 *seed;
  812. };
  813. #define EXT4_HTREE_EOF 0x7fffffff
  814. /*
  815. * Control parameters used by ext4_htree_next_block
  816. */
  817. #define HASH_NB_ALWAYS 1
  818. /*
  819. * Describe an inode's exact location on disk and in memory
  820. */
  821. struct ext4_iloc
  822. {
  823. struct buffer_head *bh;
  824. unsigned long offset;
  825. ext4_group_t block_group;
  826. };
  827. static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc)
  828. {
  829. return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset);
  830. }
  831. /*
  832. * This structure is stuffed into the struct file's private_data field
  833. * for directories. It is where we put information so that we can do
  834. * readdir operations in hash tree order.
  835. */
  836. struct dir_private_info {
  837. struct rb_root root;
  838. struct rb_node *curr_node;
  839. struct fname *extra_fname;
  840. loff_t last_pos;
  841. __u32 curr_hash;
  842. __u32 curr_minor_hash;
  843. __u32 next_hash;
  844. };
  845. /* calculate the first block number of the group */
  846. static inline ext4_fsblk_t
  847. ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no)
  848. {
  849. return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) +
  850. le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
  851. }
  852. /*
  853. * Special error return code only used by dx_probe() and its callers.
  854. */
  855. #define ERR_BAD_DX_DIR -75000
  856. void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
  857. unsigned long *blockgrpp, ext4_grpblk_t *offsetp);
  858. /*
  859. * Function prototypes
  860. */
  861. /*
  862. * Ok, these declarations are also in <linux/kernel.h> but none of the
  863. * ext4 source programs needs to include it so they are duplicated here.
  864. */
  865. # define NORET_TYPE /**/
  866. # define ATTRIB_NORET __attribute__((noreturn))
  867. # define NORET_AND noreturn,
  868. /* balloc.c */
  869. extern unsigned int ext4_block_group(struct super_block *sb,
  870. ext4_fsblk_t blocknr);
  871. extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb,
  872. ext4_fsblk_t blocknr);
  873. extern int ext4_bg_has_super(struct super_block *sb, ext4_group_t group);
  874. extern unsigned long ext4_bg_num_gdb(struct super_block *sb,
  875. ext4_group_t group);
  876. extern ext4_fsblk_t ext4_new_meta_block(handle_t *handle, struct inode *inode,
  877. ext4_fsblk_t goal, int *errp);
  878. extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
  879. ext4_fsblk_t goal, unsigned long *count, int *errp);
  880. extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
  881. ext4_lblk_t iblock, ext4_fsblk_t goal,
  882. unsigned long *count, int *errp);
  883. extern ext4_fsblk_t ext4_old_new_blocks(handle_t *handle, struct inode *inode,
  884. ext4_fsblk_t goal, unsigned long *count, int *errp);
  885. extern ext4_fsblk_t ext4_has_free_blocks(struct ext4_sb_info *sbi,
  886. ext4_fsblk_t nblocks);
  887. extern void ext4_free_blocks (handle_t *handle, struct inode *inode,
  888. ext4_fsblk_t block, unsigned long count, int metadata);
  889. extern void ext4_free_blocks_sb (handle_t *handle, struct super_block *sb,
  890. ext4_fsblk_t block, unsigned long count,
  891. unsigned long *pdquot_freed_blocks);
  892. extern ext4_fsblk_t ext4_count_free_blocks (struct super_block *);
  893. extern void ext4_check_blocks_bitmap (struct super_block *);
  894. extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
  895. ext4_group_t block_group,
  896. struct buffer_head ** bh);
  897. extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
  898. extern void ext4_init_block_alloc_info(struct inode *);
  899. extern void ext4_rsv_window_add(struct super_block *sb, struct ext4_reserve_window_node *rsv);
  900. /* dir.c */
  901. extern int ext4_check_dir_entry(const char *, struct inode *,
  902. struct ext4_dir_entry_2 *,
  903. struct buffer_head *, unsigned long);
  904. extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
  905. __u32 minor_hash,
  906. struct ext4_dir_entry_2 *dirent);
  907. extern void ext4_htree_free_dir_info(struct dir_private_info *p);
  908. /* fsync.c */
  909. extern int ext4_sync_file (struct file *, struct dentry *, int);
  910. /* hash.c */
  911. extern int ext4fs_dirhash(const char *name, int len, struct
  912. dx_hash_info *hinfo);
  913. /* ialloc.c */
  914. extern struct inode * ext4_new_inode (handle_t *, struct inode *, int);
  915. extern void ext4_free_inode (handle_t *, struct inode *);
  916. extern struct inode * ext4_orphan_get (struct super_block *, unsigned long);
  917. extern unsigned long ext4_count_free_inodes (struct super_block *);
  918. extern unsigned long ext4_count_dirs (struct super_block *);
  919. extern void ext4_check_inodes_bitmap (struct super_block *);
  920. extern unsigned long ext4_count_free (struct buffer_head *, unsigned);
  921. /* mballoc.c */
  922. extern long ext4_mb_stats;
  923. extern long ext4_mb_max_to_scan;
  924. extern int ext4_mb_init(struct super_block *, int);
  925. extern int ext4_mb_release(struct super_block *);
  926. extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
  927. struct ext4_allocation_request *, int *);
  928. extern int ext4_mb_reserve_blocks(struct super_block *, int);
  929. extern void ext4_mb_discard_inode_preallocations(struct inode *);
  930. extern int __init init_ext4_mballoc(void);
  931. extern void exit_ext4_mballoc(void);
  932. extern void ext4_mb_free_blocks(handle_t *, struct inode *,
  933. unsigned long, unsigned long, int, unsigned long *);
  934. extern int ext4_mb_add_more_groupinfo(struct super_block *sb,
  935. ext4_group_t i, struct ext4_group_desc *desc);
  936. extern void ext4_mb_update_group_info(struct ext4_group_info *grp,
  937. ext4_grpblk_t add);
  938. /* inode.c */
  939. int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
  940. struct buffer_head *bh, ext4_fsblk_t blocknr);
  941. struct buffer_head *ext4_getblk(handle_t *, struct inode *,
  942. ext4_lblk_t, int, int *);
  943. struct buffer_head *ext4_bread(handle_t *, struct inode *,
  944. ext4_lblk_t, int, int *);
  945. int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
  946. ext4_lblk_t iblock, unsigned long maxblocks,
  947. struct buffer_head *bh_result,
  948. int create, int extend_disksize);
  949. extern struct inode *ext4_iget(struct super_block *, unsigned long);
  950. extern int ext4_write_inode (struct inode *, int);
  951. extern int ext4_setattr (struct dentry *, struct iattr *);
  952. extern void ext4_delete_inode (struct inode *);
  953. extern int ext4_sync_inode (handle_t *, struct inode *);
  954. extern void ext4_discard_reservation (struct inode *);
  955. extern void ext4_dirty_inode(struct inode *);
  956. extern int ext4_change_inode_journal_flag(struct inode *, int);
  957. extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
  958. extern int ext4_can_truncate(struct inode *inode);
  959. extern void ext4_truncate (struct inode *);
  960. extern void ext4_set_inode_flags(struct inode *);
  961. extern void ext4_get_inode_flags(struct ext4_inode_info *);
  962. extern void ext4_set_aops(struct inode *inode);
  963. extern int ext4_writepage_trans_blocks(struct inode *);
  964. extern int ext4_block_truncate_page(handle_t *handle, struct page *page,
  965. struct address_space *mapping, loff_t from);
  966. /* ioctl.c */
  967. extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
  968. extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long);
  969. /* migrate.c */
  970. extern int ext4_ext_migrate(struct inode *, struct file *, unsigned int,
  971. unsigned long);
  972. /* namei.c */
  973. extern int ext4_orphan_add(handle_t *, struct inode *);
  974. extern int ext4_orphan_del(handle_t *, struct inode *);
  975. extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
  976. __u32 start_minor_hash, __u32 *next_hash);
  977. /* resize.c */
  978. extern int ext4_group_add(struct super_block *sb,
  979. struct ext4_new_group_data *input);
  980. extern int ext4_group_extend(struct super_block *sb,
  981. struct ext4_super_block *es,
  982. ext4_fsblk_t n_blocks_count);
  983. /* super.c */
  984. extern void ext4_error (struct super_block *, const char *, const char *, ...)
  985. __attribute__ ((format (printf, 3, 4)));
  986. extern void __ext4_std_error (struct super_block *, const char *, int);
  987. extern void ext4_abort (struct super_block *, const char *, const char *, ...)
  988. __attribute__ ((format (printf, 3, 4)));
  989. extern void ext4_warning (struct super_block *, const char *, const char *, ...)
  990. __attribute__ ((format (printf, 3, 4)));
  991. extern void ext4_update_dynamic_rev (struct super_block *sb);
  992. extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb,
  993. __u32 compat);
  994. extern int ext4_update_rocompat_feature(handle_t *handle,
  995. struct super_block *sb, __u32 rocompat);
  996. extern int ext4_update_incompat_feature(handle_t *handle,
  997. struct super_block *sb, __u32 incompat);
  998. extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
  999. struct ext4_group_desc *bg);
  1000. extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
  1001. struct ext4_group_desc *bg);
  1002. extern ext4_fsblk_t ext4_inode_table(struct super_block *sb,
  1003. struct ext4_group_desc *bg);
  1004. extern void ext4_block_bitmap_set(struct super_block *sb,
  1005. struct ext4_group_desc *bg, ext4_fsblk_t blk);
  1006. extern void ext4_inode_bitmap_set(struct super_block *sb,
  1007. struct ext4_group_desc *bg, ext4_fsblk_t blk);
  1008. extern void ext4_inode_table_set(struct super_block *sb,
  1009. struct ext4_group_desc *bg, ext4_fsblk_t blk);
  1010. static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
  1011. {
  1012. return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
  1013. le32_to_cpu(es->s_blocks_count_lo);
  1014. }
  1015. static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es)
  1016. {
  1017. return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) |
  1018. le32_to_cpu(es->s_r_blocks_count_lo);
  1019. }
  1020. static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es)
  1021. {
  1022. return ((ext4_fsblk_t)le32_to_cpu(es->s_free_blocks_count_hi) << 32) |
  1023. le32_to_cpu(es->s_free_blocks_count_lo);
  1024. }
  1025. static inline void ext4_blocks_count_set(struct ext4_super_block *es,
  1026. ext4_fsblk_t blk)
  1027. {
  1028. es->s_blocks_count_lo = cpu_to_le32((u32)blk);
  1029. es->s_blocks_count_hi = cpu_to_le32(blk >> 32);
  1030. }
  1031. static inline void ext4_free_blocks_count_set(struct ext4_super_block *es,
  1032. ext4_fsblk_t blk)
  1033. {
  1034. es->s_free_blocks_count_lo = cpu_to_le32((u32)blk);
  1035. es->s_free_blocks_count_hi = cpu_to_le32(blk >> 32);
  1036. }
  1037. static inline void ext4_r_blocks_count_set(struct ext4_super_block *es,
  1038. ext4_fsblk_t blk)
  1039. {
  1040. es->s_r_blocks_count_lo = cpu_to_le32((u32)blk);
  1041. es->s_r_blocks_count_hi = cpu_to_le32(blk >> 32);
  1042. }
  1043. static inline loff_t ext4_isize(struct ext4_inode *raw_inode)
  1044. {
  1045. return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) |
  1046. le32_to_cpu(raw_inode->i_size_lo);
  1047. }
  1048. static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size)
  1049. {
  1050. raw_inode->i_size_lo = cpu_to_le32(i_size);
  1051. raw_inode->i_size_high = cpu_to_le32(i_size >> 32);
  1052. }
  1053. static inline
  1054. struct ext4_group_info *ext4_get_group_info(struct super_block *sb,
  1055. ext4_group_t group)
  1056. {
  1057. struct ext4_group_info ***grp_info;
  1058. long indexv, indexh;
  1059. grp_info = EXT4_SB(sb)->s_group_info;
  1060. indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb));
  1061. indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1);
  1062. return grp_info[indexv][indexh];
  1063. }
  1064. static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi,
  1065. ext4_group_t block_group)
  1066. {
  1067. return block_group >> sbi->s_log_groups_per_flex;
  1068. }
  1069. static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi)
  1070. {
  1071. return 1 << sbi->s_log_groups_per_flex;
  1072. }
  1073. #define ext4_std_error(sb, errno) \
  1074. do { \
  1075. if ((errno)) \
  1076. __ext4_std_error((sb), __func__, (errno)); \
  1077. } while (0)
  1078. /*
  1079. * Inodes and files operations
  1080. */
  1081. /* dir.c */
  1082. extern const struct file_operations ext4_dir_operations;
  1083. /* file.c */
  1084. extern const struct inode_operations ext4_file_inode_operations;
  1085. extern const struct file_operations ext4_file_operations;
  1086. /* namei.c */
  1087. extern const struct inode_operations ext4_dir_inode_operations;
  1088. extern const struct inode_operations ext4_special_inode_operations;
  1089. /* symlink.c */
  1090. extern const struct inode_operations ext4_symlink_inode_operations;
  1091. extern const struct inode_operations ext4_fast_symlink_inode_operations;
  1092. /* extents.c */
  1093. extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
  1094. extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
  1095. extern int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
  1096. ext4_lblk_t iblock,
  1097. unsigned long max_blocks, struct buffer_head *bh_result,
  1098. int create, int extend_disksize);
  1099. extern void ext4_ext_truncate(struct inode *, struct page *);
  1100. extern void ext4_ext_init(struct super_block *);
  1101. extern void ext4_ext_release(struct super_block *);
  1102. extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset,
  1103. loff_t len);
  1104. extern int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode,
  1105. sector_t block, unsigned long max_blocks,
  1106. struct buffer_head *bh, int create,
  1107. int extend_disksize);
  1108. #endif /* __KERNEL__ */
  1109. #endif /* _EXT4_H */