ext4_fs.h 39 KB

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