ext4_fs.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  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 4096
  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; /* Blocks bitmap block */
  98. __le32 bg_inode_bitmap; /* Inodes bitmap block */
  99. __le32 bg_inode_table; /* 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; /* 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; /* Blocks count */
  458. __le32 s_r_blocks_count; /* Reserved blocks count */
  459. __le32 s_free_blocks_count; /* 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_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
  625. #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \
  626. EXT4_FEATURE_INCOMPAT_RECOVER| \
  627. EXT4_FEATURE_INCOMPAT_META_BG| \
  628. EXT4_FEATURE_INCOMPAT_EXTENTS| \
  629. EXT4_FEATURE_INCOMPAT_64BIT)
  630. #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  631. EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
  632. EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
  633. EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
  634. EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
  635. EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
  636. /*
  637. * Default values for user and/or group using reserved blocks
  638. */
  639. #define EXT4_DEF_RESUID 0
  640. #define EXT4_DEF_RESGID 0
  641. /*
  642. * Default mount options
  643. */
  644. #define EXT4_DEFM_DEBUG 0x0001
  645. #define EXT4_DEFM_BSDGROUPS 0x0002
  646. #define EXT4_DEFM_XATTR_USER 0x0004
  647. #define EXT4_DEFM_ACL 0x0008
  648. #define EXT4_DEFM_UID16 0x0010
  649. #define EXT4_DEFM_JMODE 0x0060
  650. #define EXT4_DEFM_JMODE_DATA 0x0020
  651. #define EXT4_DEFM_JMODE_ORDERED 0x0040
  652. #define EXT4_DEFM_JMODE_WBACK 0x0060
  653. /*
  654. * Structure of a directory entry
  655. */
  656. #define EXT4_NAME_LEN 255
  657. struct ext4_dir_entry {
  658. __le32 inode; /* Inode number */
  659. __le16 rec_len; /* Directory entry length */
  660. __le16 name_len; /* Name length */
  661. char name[EXT4_NAME_LEN]; /* File name */
  662. };
  663. /*
  664. * The new version of the directory entry. Since EXT4 structures are
  665. * stored in intel byte order, and the name_len field could never be
  666. * bigger than 255 chars, it's safe to reclaim the extra byte for the
  667. * file_type field.
  668. */
  669. struct ext4_dir_entry_2 {
  670. __le32 inode; /* Inode number */
  671. __le16 rec_len; /* Directory entry length */
  672. __u8 name_len; /* Name length */
  673. __u8 file_type;
  674. char name[EXT4_NAME_LEN]; /* File name */
  675. };
  676. /*
  677. * Ext4 directory file types. Only the low 3 bits are used. The
  678. * other bits are reserved for now.
  679. */
  680. #define EXT4_FT_UNKNOWN 0
  681. #define EXT4_FT_REG_FILE 1
  682. #define EXT4_FT_DIR 2
  683. #define EXT4_FT_CHRDEV 3
  684. #define EXT4_FT_BLKDEV 4
  685. #define EXT4_FT_FIFO 5
  686. #define EXT4_FT_SOCK 6
  687. #define EXT4_FT_SYMLINK 7
  688. #define EXT4_FT_MAX 8
  689. /*
  690. * EXT4_DIR_PAD defines the directory entries boundaries
  691. *
  692. * NOTE: It must be a multiple of 4
  693. */
  694. #define EXT4_DIR_PAD 4
  695. #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1)
  696. #define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \
  697. ~EXT4_DIR_ROUND)
  698. /*
  699. * Hash Tree Directory indexing
  700. * (c) Daniel Phillips, 2001
  701. */
  702. #define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \
  703. EXT4_FEATURE_COMPAT_DIR_INDEX) && \
  704. (EXT4_I(dir)->i_flags & EXT4_INDEX_FL))
  705. #define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX)
  706. #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
  707. /* Legal values for the dx_root hash_version field: */
  708. #define DX_HASH_LEGACY 0
  709. #define DX_HASH_HALF_MD4 1
  710. #define DX_HASH_TEA 2
  711. #ifdef __KERNEL__
  712. /* hash info structure used by the directory hash */
  713. struct dx_hash_info
  714. {
  715. u32 hash;
  716. u32 minor_hash;
  717. int hash_version;
  718. u32 *seed;
  719. };
  720. #define EXT4_HTREE_EOF 0x7fffffff
  721. /*
  722. * Control parameters used by ext4_htree_next_block
  723. */
  724. #define HASH_NB_ALWAYS 1
  725. /*
  726. * Describe an inode's exact location on disk and in memory
  727. */
  728. struct ext4_iloc
  729. {
  730. struct buffer_head *bh;
  731. unsigned long offset;
  732. unsigned long block_group;
  733. };
  734. static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc)
  735. {
  736. return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset);
  737. }
  738. /*
  739. * This structure is stuffed into the struct file's private_data field
  740. * for directories. It is where we put information so that we can do
  741. * readdir operations in hash tree order.
  742. */
  743. struct dir_private_info {
  744. struct rb_root root;
  745. struct rb_node *curr_node;
  746. struct fname *extra_fname;
  747. loff_t last_pos;
  748. __u32 curr_hash;
  749. __u32 curr_minor_hash;
  750. __u32 next_hash;
  751. };
  752. /* calculate the first block number of the group */
  753. static inline ext4_fsblk_t
  754. ext4_group_first_block_no(struct super_block *sb, unsigned long group_no)
  755. {
  756. return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) +
  757. le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
  758. }
  759. /*
  760. * Special error return code only used by dx_probe() and its callers.
  761. */
  762. #define ERR_BAD_DX_DIR -75000
  763. void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
  764. unsigned long *blockgrpp, ext4_grpblk_t *offsetp);
  765. /*
  766. * Function prototypes
  767. */
  768. /*
  769. * Ok, these declarations are also in <linux/kernel.h> but none of the
  770. * ext4 source programs needs to include it so they are duplicated here.
  771. */
  772. # define NORET_TYPE /**/
  773. # define ATTRIB_NORET __attribute__((noreturn))
  774. # define NORET_AND noreturn,
  775. /* balloc.c */
  776. extern unsigned int ext4_block_group(struct super_block *sb,
  777. ext4_fsblk_t blocknr);
  778. extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb,
  779. ext4_fsblk_t blocknr);
  780. extern int ext4_bg_has_super(struct super_block *sb, int group);
  781. extern unsigned long ext4_bg_num_gdb(struct super_block *sb, int group);
  782. extern ext4_fsblk_t ext4_new_block (handle_t *handle, struct inode *inode,
  783. ext4_fsblk_t goal, int *errp);
  784. extern ext4_fsblk_t ext4_new_blocks (handle_t *handle, struct inode *inode,
  785. ext4_fsblk_t goal, unsigned long *count, int *errp);
  786. extern void ext4_free_blocks (handle_t *handle, struct inode *inode,
  787. ext4_fsblk_t block, unsigned long count);
  788. extern void ext4_free_blocks_sb (handle_t *handle, struct super_block *sb,
  789. ext4_fsblk_t block, unsigned long count,
  790. unsigned long *pdquot_freed_blocks);
  791. extern ext4_fsblk_t ext4_count_free_blocks (struct super_block *);
  792. extern void ext4_check_blocks_bitmap (struct super_block *);
  793. extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
  794. unsigned int block_group,
  795. struct buffer_head ** bh);
  796. extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
  797. extern void ext4_init_block_alloc_info(struct inode *);
  798. extern void ext4_rsv_window_add(struct super_block *sb, struct ext4_reserve_window_node *rsv);
  799. /* dir.c */
  800. extern int ext4_check_dir_entry(const char *, struct inode *,
  801. struct ext4_dir_entry_2 *,
  802. struct buffer_head *, unsigned long);
  803. extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
  804. __u32 minor_hash,
  805. struct ext4_dir_entry_2 *dirent);
  806. extern void ext4_htree_free_dir_info(struct dir_private_info *p);
  807. /* fsync.c */
  808. extern int ext4_sync_file (struct file *, struct dentry *, int);
  809. /* hash.c */
  810. extern int ext4fs_dirhash(const char *name, int len, struct
  811. dx_hash_info *hinfo);
  812. /* ialloc.c */
  813. extern struct inode * ext4_new_inode (handle_t *, struct inode *, int);
  814. extern void ext4_free_inode (handle_t *, struct inode *);
  815. extern struct inode * ext4_orphan_get (struct super_block *, unsigned long);
  816. extern unsigned long ext4_count_free_inodes (struct super_block *);
  817. extern unsigned long ext4_count_dirs (struct super_block *);
  818. extern void ext4_check_inodes_bitmap (struct super_block *);
  819. extern unsigned long ext4_count_free (struct buffer_head *, unsigned);
  820. /* inode.c */
  821. int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
  822. struct buffer_head *bh, ext4_fsblk_t blocknr);
  823. struct buffer_head * ext4_getblk (handle_t *, struct inode *, long, int, int *);
  824. struct buffer_head * ext4_bread (handle_t *, struct inode *, int, int, int *);
  825. int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
  826. sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
  827. int create, int extend_disksize);
  828. extern void ext4_read_inode (struct inode *);
  829. extern int ext4_write_inode (struct inode *, int);
  830. extern int ext4_setattr (struct dentry *, struct iattr *);
  831. extern void ext4_delete_inode (struct inode *);
  832. extern int ext4_sync_inode (handle_t *, struct inode *);
  833. extern void ext4_discard_reservation (struct inode *);
  834. extern void ext4_dirty_inode(struct inode *);
  835. extern int ext4_change_inode_journal_flag(struct inode *, int);
  836. extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
  837. extern void ext4_truncate (struct inode *);
  838. extern void ext4_set_inode_flags(struct inode *);
  839. extern void ext4_get_inode_flags(struct ext4_inode_info *);
  840. extern void ext4_set_aops(struct inode *inode);
  841. extern int ext4_writepage_trans_blocks(struct inode *);
  842. extern int ext4_block_truncate_page(handle_t *handle, struct page *page,
  843. struct address_space *mapping, loff_t from);
  844. /* ioctl.c */
  845. extern int ext4_ioctl (struct inode *, struct file *, unsigned int,
  846. unsigned long);
  847. extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long);
  848. /* namei.c */
  849. extern int ext4_orphan_add(handle_t *, struct inode *);
  850. extern int ext4_orphan_del(handle_t *, struct inode *);
  851. extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
  852. __u32 start_minor_hash, __u32 *next_hash);
  853. /* resize.c */
  854. extern int ext4_group_add(struct super_block *sb,
  855. struct ext4_new_group_data *input);
  856. extern int ext4_group_extend(struct super_block *sb,
  857. struct ext4_super_block *es,
  858. ext4_fsblk_t n_blocks_count);
  859. /* super.c */
  860. extern void ext4_error (struct super_block *, const char *, const char *, ...)
  861. __attribute__ ((format (printf, 3, 4)));
  862. extern void __ext4_std_error (struct super_block *, const char *, int);
  863. extern void ext4_abort (struct super_block *, const char *, const char *, ...)
  864. __attribute__ ((format (printf, 3, 4)));
  865. extern void ext4_warning (struct super_block *, const char *, const char *, ...)
  866. __attribute__ ((format (printf, 3, 4)));
  867. extern void ext4_update_dynamic_rev (struct super_block *sb);
  868. extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
  869. struct ext4_group_desc *bg);
  870. extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
  871. struct ext4_group_desc *bg);
  872. extern ext4_fsblk_t ext4_inode_table(struct super_block *sb,
  873. struct ext4_group_desc *bg);
  874. extern void ext4_block_bitmap_set(struct super_block *sb,
  875. struct ext4_group_desc *bg, ext4_fsblk_t blk);
  876. extern void ext4_inode_bitmap_set(struct super_block *sb,
  877. struct ext4_group_desc *bg, ext4_fsblk_t blk);
  878. extern void ext4_inode_table_set(struct super_block *sb,
  879. struct ext4_group_desc *bg, ext4_fsblk_t blk);
  880. static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
  881. {
  882. return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
  883. le32_to_cpu(es->s_blocks_count);
  884. }
  885. static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es)
  886. {
  887. return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) |
  888. le32_to_cpu(es->s_r_blocks_count);
  889. }
  890. static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es)
  891. {
  892. return ((ext4_fsblk_t)le32_to_cpu(es->s_free_blocks_count_hi) << 32) |
  893. le32_to_cpu(es->s_free_blocks_count);
  894. }
  895. static inline void ext4_blocks_count_set(struct ext4_super_block *es,
  896. ext4_fsblk_t blk)
  897. {
  898. es->s_blocks_count = cpu_to_le32((u32)blk);
  899. es->s_blocks_count_hi = cpu_to_le32(blk >> 32);
  900. }
  901. static inline void ext4_free_blocks_count_set(struct ext4_super_block *es,
  902. ext4_fsblk_t blk)
  903. {
  904. es->s_free_blocks_count = cpu_to_le32((u32)blk);
  905. es->s_free_blocks_count_hi = cpu_to_le32(blk >> 32);
  906. }
  907. static inline void ext4_r_blocks_count_set(struct ext4_super_block *es,
  908. ext4_fsblk_t blk)
  909. {
  910. es->s_r_blocks_count = cpu_to_le32((u32)blk);
  911. es->s_r_blocks_count_hi = cpu_to_le32(blk >> 32);
  912. }
  913. #define ext4_std_error(sb, errno) \
  914. do { \
  915. if ((errno)) \
  916. __ext4_std_error((sb), __FUNCTION__, (errno)); \
  917. } while (0)
  918. /*
  919. * Inodes and files operations
  920. */
  921. /* dir.c */
  922. extern const struct file_operations ext4_dir_operations;
  923. /* file.c */
  924. extern const struct inode_operations ext4_file_inode_operations;
  925. extern const struct file_operations ext4_file_operations;
  926. /* namei.c */
  927. extern const struct inode_operations ext4_dir_inode_operations;
  928. extern const struct inode_operations ext4_special_inode_operations;
  929. /* symlink.c */
  930. extern const struct inode_operations ext4_symlink_inode_operations;
  931. extern const struct inode_operations ext4_fast_symlink_inode_operations;
  932. /* extents.c */
  933. extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
  934. extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
  935. extern int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
  936. ext4_fsblk_t iblock,
  937. unsigned long max_blocks, struct buffer_head *bh_result,
  938. int create, int extend_disksize);
  939. extern void ext4_ext_truncate(struct inode *, struct page *);
  940. extern void ext4_ext_init(struct super_block *);
  941. extern void ext4_ext_release(struct super_block *);
  942. extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset,
  943. loff_t len);
  944. static inline int
  945. ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
  946. unsigned long max_blocks, struct buffer_head *bh,
  947. int create, int extend_disksize)
  948. {
  949. if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)
  950. return ext4_ext_get_blocks(handle, inode, block, max_blocks,
  951. bh, create, extend_disksize);
  952. return ext4_get_blocks_handle(handle, inode, block, max_blocks, bh,
  953. create, extend_disksize);
  954. }
  955. #endif /* __KERNEL__ */
  956. #endif /* _LINUX_EXT4_FS_H */