ext4.h 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349
  1. /*
  2. * ext4.h
  3. *
  4. * Copyright (C) 1992, 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. *
  9. * from
  10. *
  11. * linux/include/linux/minix_fs.h
  12. *
  13. * Copyright (C) 1991, 1992 Linus Torvalds
  14. */
  15. #ifndef _EXT4_H
  16. #define _EXT4_H
  17. #include <linux/types.h>
  18. #include <linux/blkdev.h>
  19. #include <linux/magic.h>
  20. #include <linux/jbd2.h>
  21. #include <linux/quota.h>
  22. #include <linux/rwsem.h>
  23. #include <linux/rbtree.h>
  24. #include <linux/seqlock.h>
  25. #include <linux/mutex.h>
  26. #include <linux/timer.h>
  27. #include <linux/version.h>
  28. #include <linux/wait.h>
  29. #include <linux/blockgroup_lock.h>
  30. #include <linux/percpu_counter.h>
  31. #include <linux/ratelimit.h>
  32. #include <crypto/hash.h>
  33. #include <linux/falloc.h>
  34. #include <linux/percpu-rwsem.h>
  35. #ifdef __KERNEL__
  36. #include <linux/compat.h>
  37. #endif
  38. /*
  39. * The fourth extended filesystem constants/structures
  40. */
  41. /*
  42. * with AGGRESSIVE_CHECK allocator runs consistency checks over
  43. * structures. these checks slow things down a lot
  44. */
  45. #define AGGRESSIVE_CHECK__
  46. /*
  47. * with DOUBLE_CHECK defined mballoc creates persistent in-core
  48. * bitmaps, maintains and uses them to check for double allocations
  49. */
  50. #define DOUBLE_CHECK__
  51. /*
  52. * Define EXT4FS_DEBUG to produce debug messages
  53. */
  54. #undef EXT4FS_DEBUG
  55. /*
  56. * Debug code
  57. */
  58. #ifdef EXT4FS_DEBUG
  59. #define ext4_debug(f, a...) \
  60. do { \
  61. printk(KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \
  62. __FILE__, __LINE__, __func__); \
  63. printk(KERN_DEBUG f, ## a); \
  64. } while (0)
  65. #else
  66. #define ext4_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
  67. #endif
  68. /*
  69. * Turn on EXT_DEBUG to get lots of info about extents operations.
  70. */
  71. #define EXT_DEBUG__
  72. #ifdef EXT_DEBUG
  73. #define ext_debug(fmt, ...) printk(fmt, ##__VA_ARGS__)
  74. #else
  75. #define ext_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
  76. #endif
  77. /* data type for block offset of block group */
  78. typedef int ext4_grpblk_t;
  79. /* data type for filesystem-wide blocks number */
  80. typedef unsigned long long ext4_fsblk_t;
  81. /* data type for file logical block number */
  82. typedef __u32 ext4_lblk_t;
  83. /* data type for block group number */
  84. typedef unsigned int ext4_group_t;
  85. enum SHIFT_DIRECTION {
  86. SHIFT_LEFT = 0,
  87. SHIFT_RIGHT,
  88. };
  89. /*
  90. * Flags used in mballoc's allocation_context flags field.
  91. *
  92. * Also used to show what's going on for debugging purposes when the
  93. * flag field is exported via the traceport interface
  94. */
  95. /* prefer goal again. length */
  96. #define EXT4_MB_HINT_MERGE 0x0001
  97. /* blocks already reserved */
  98. #define EXT4_MB_HINT_RESERVED 0x0002
  99. /* metadata is being allocated */
  100. #define EXT4_MB_HINT_METADATA 0x0004
  101. /* first blocks in the file */
  102. #define EXT4_MB_HINT_FIRST 0x0008
  103. /* search for the best chunk */
  104. #define EXT4_MB_HINT_BEST 0x0010
  105. /* data is being allocated */
  106. #define EXT4_MB_HINT_DATA 0x0020
  107. /* don't preallocate (for tails) */
  108. #define EXT4_MB_HINT_NOPREALLOC 0x0040
  109. /* allocate for locality group */
  110. #define EXT4_MB_HINT_GROUP_ALLOC 0x0080
  111. /* allocate goal blocks or none */
  112. #define EXT4_MB_HINT_GOAL_ONLY 0x0100
  113. /* goal is meaningful */
  114. #define EXT4_MB_HINT_TRY_GOAL 0x0200
  115. /* blocks already pre-reserved by delayed allocation */
  116. #define EXT4_MB_DELALLOC_RESERVED 0x0400
  117. /* We are doing stream allocation */
  118. #define EXT4_MB_STREAM_ALLOC 0x0800
  119. /* Use reserved root blocks if needed */
  120. #define EXT4_MB_USE_ROOT_BLOCKS 0x1000
  121. /* Use blocks from reserved pool */
  122. #define EXT4_MB_USE_RESERVED 0x2000
  123. struct ext4_allocation_request {
  124. /* target inode for block we're allocating */
  125. struct inode *inode;
  126. /* how many blocks we want to allocate */
  127. unsigned int len;
  128. /* logical block in target inode */
  129. ext4_lblk_t logical;
  130. /* the closest logical allocated block to the left */
  131. ext4_lblk_t lleft;
  132. /* the closest logical allocated block to the right */
  133. ext4_lblk_t lright;
  134. /* phys. target (a hint) */
  135. ext4_fsblk_t goal;
  136. /* phys. block for the closest logical allocated block to the left */
  137. ext4_fsblk_t pleft;
  138. /* phys. block for the closest logical allocated block to the right */
  139. ext4_fsblk_t pright;
  140. /* flags. see above EXT4_MB_HINT_* */
  141. unsigned int flags;
  142. };
  143. /*
  144. * Logical to physical block mapping, used by ext4_map_blocks()
  145. *
  146. * This structure is used to pass requests into ext4_map_blocks() as
  147. * well as to store the information returned by ext4_map_blocks(). It
  148. * takes less room on the stack than a struct buffer_head.
  149. */
  150. #define EXT4_MAP_NEW (1 << BH_New)
  151. #define EXT4_MAP_MAPPED (1 << BH_Mapped)
  152. #define EXT4_MAP_UNWRITTEN (1 << BH_Unwritten)
  153. #define EXT4_MAP_BOUNDARY (1 << BH_Boundary)
  154. #define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\
  155. EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY)
  156. struct ext4_map_blocks {
  157. ext4_fsblk_t m_pblk;
  158. ext4_lblk_t m_lblk;
  159. unsigned int m_len;
  160. unsigned int m_flags;
  161. };
  162. /*
  163. * Flags for ext4_io_end->flags
  164. */
  165. #define EXT4_IO_END_UNWRITTEN 0x0001
  166. /*
  167. * For converting unwritten extents on a work queue. 'handle' is used for
  168. * buffered writeback.
  169. */
  170. typedef struct ext4_io_end {
  171. struct list_head list; /* per-file finished IO list */
  172. handle_t *handle; /* handle reserved for extent
  173. * conversion */
  174. struct inode *inode; /* file being written to */
  175. struct bio *bio; /* Linked list of completed
  176. * bios covering the extent */
  177. unsigned int flag; /* unwritten or not */
  178. atomic_t count; /* reference counter */
  179. loff_t offset; /* offset in the file */
  180. ssize_t size; /* size of the extent */
  181. } ext4_io_end_t;
  182. struct ext4_io_submit {
  183. struct writeback_control *io_wbc;
  184. struct bio *io_bio;
  185. ext4_io_end_t *io_end;
  186. sector_t io_next_block;
  187. };
  188. /*
  189. * Special inodes numbers
  190. */
  191. #define EXT4_BAD_INO 1 /* Bad blocks inode */
  192. #define EXT4_ROOT_INO 2 /* Root inode */
  193. #define EXT4_USR_QUOTA_INO 3 /* User quota inode */
  194. #define EXT4_GRP_QUOTA_INO 4 /* Group quota inode */
  195. #define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */
  196. #define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */
  197. #define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */
  198. #define EXT4_JOURNAL_INO 8 /* Journal inode */
  199. /* First non-reserved inode for old ext4 filesystems */
  200. #define EXT4_GOOD_OLD_FIRST_INO 11
  201. /*
  202. * Maximal count of links to a file
  203. */
  204. #define EXT4_LINK_MAX 65000
  205. /*
  206. * Macro-instructions used to manage several block sizes
  207. */
  208. #define EXT4_MIN_BLOCK_SIZE 1024
  209. #define EXT4_MAX_BLOCK_SIZE 65536
  210. #define EXT4_MIN_BLOCK_LOG_SIZE 10
  211. #define EXT4_MAX_BLOCK_LOG_SIZE 16
  212. #ifdef __KERNEL__
  213. # define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize)
  214. #else
  215. # define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size)
  216. #endif
  217. #define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof(__u32))
  218. #define EXT4_CLUSTER_SIZE(s) (EXT4_BLOCK_SIZE(s) << \
  219. EXT4_SB(s)->s_cluster_bits)
  220. #ifdef __KERNEL__
  221. # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
  222. # define EXT4_CLUSTER_BITS(s) (EXT4_SB(s)->s_cluster_bits)
  223. #else
  224. # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
  225. #endif
  226. #ifdef __KERNEL__
  227. #define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits)
  228. #define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size)
  229. #define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino)
  230. #else
  231. #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
  232. EXT4_GOOD_OLD_INODE_SIZE : \
  233. (s)->s_inode_size)
  234. #define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
  235. EXT4_GOOD_OLD_FIRST_INO : \
  236. (s)->s_first_ino)
  237. #endif
  238. #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits)))
  239. /* Translate a block number to a cluster number */
  240. #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits)
  241. /* Translate a cluster number to a block number */
  242. #define EXT4_C2B(sbi, cluster) ((cluster) << (sbi)->s_cluster_bits)
  243. /* Translate # of blks to # of clusters */
  244. #define EXT4_NUM_B2C(sbi, blks) (((blks) + (sbi)->s_cluster_ratio - 1) >> \
  245. (sbi)->s_cluster_bits)
  246. /* Mask out the low bits to get the starting block of the cluster */
  247. #define EXT4_PBLK_CMASK(s, pblk) ((pblk) & \
  248. ~((ext4_fsblk_t) (s)->s_cluster_ratio - 1))
  249. #define EXT4_LBLK_CMASK(s, lblk) ((lblk) & \
  250. ~((ext4_lblk_t) (s)->s_cluster_ratio - 1))
  251. /* Get the cluster offset */
  252. #define EXT4_PBLK_COFF(s, pblk) ((pblk) & \
  253. ((ext4_fsblk_t) (s)->s_cluster_ratio - 1))
  254. #define EXT4_LBLK_COFF(s, lblk) ((lblk) & \
  255. ((ext4_lblk_t) (s)->s_cluster_ratio - 1))
  256. /*
  257. * Structure of a blocks group descriptor
  258. */
  259. struct ext4_group_desc
  260. {
  261. __le32 bg_block_bitmap_lo; /* Blocks bitmap block */
  262. __le32 bg_inode_bitmap_lo; /* Inodes bitmap block */
  263. __le32 bg_inode_table_lo; /* Inodes table block */
  264. __le16 bg_free_blocks_count_lo;/* Free blocks count */
  265. __le16 bg_free_inodes_count_lo;/* Free inodes count */
  266. __le16 bg_used_dirs_count_lo; /* Directories count */
  267. __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
  268. __le32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */
  269. __le16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bbitmap) LE */
  270. __le16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+ibitmap) LE */
  271. __le16 bg_itable_unused_lo; /* Unused inodes count */
  272. __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */
  273. __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
  274. __le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */
  275. __le32 bg_inode_table_hi; /* Inodes table block MSB */
  276. __le16 bg_free_blocks_count_hi;/* Free blocks count MSB */
  277. __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */
  278. __le16 bg_used_dirs_count_hi; /* Directories count MSB */
  279. __le16 bg_itable_unused_hi; /* Unused inodes count MSB */
  280. __le32 bg_exclude_bitmap_hi; /* Exclude bitmap block MSB */
  281. __le16 bg_block_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bbitmap) BE */
  282. __le16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+ibitmap) BE */
  283. __u32 bg_reserved;
  284. };
  285. #define EXT4_BG_INODE_BITMAP_CSUM_HI_END \
  286. (offsetof(struct ext4_group_desc, bg_inode_bitmap_csum_hi) + \
  287. sizeof(__le16))
  288. #define EXT4_BG_BLOCK_BITMAP_CSUM_HI_END \
  289. (offsetof(struct ext4_group_desc, bg_block_bitmap_csum_hi) + \
  290. sizeof(__le16))
  291. /*
  292. * Structure of a flex block group info
  293. */
  294. struct flex_groups {
  295. atomic64_t free_clusters;
  296. atomic_t free_inodes;
  297. atomic_t used_dirs;
  298. };
  299. #define EXT4_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */
  300. #define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */
  301. #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */
  302. /*
  303. * Macro-instructions used to manage group descriptors
  304. */
  305. #define EXT4_MIN_DESC_SIZE 32
  306. #define EXT4_MIN_DESC_SIZE_64BIT 64
  307. #define EXT4_MAX_DESC_SIZE EXT4_MIN_BLOCK_SIZE
  308. #define EXT4_DESC_SIZE(s) (EXT4_SB(s)->s_desc_size)
  309. #ifdef __KERNEL__
  310. # define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group)
  311. # define EXT4_CLUSTERS_PER_GROUP(s) (EXT4_SB(s)->s_clusters_per_group)
  312. # define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block)
  313. # define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group)
  314. # define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits)
  315. #else
  316. # define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
  317. # define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_DESC_SIZE(s))
  318. # define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
  319. #endif
  320. /*
  321. * Constants relative to the data blocks
  322. */
  323. #define EXT4_NDIR_BLOCKS 12
  324. #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS
  325. #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1)
  326. #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1)
  327. #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1)
  328. /*
  329. * Inode flags
  330. */
  331. #define EXT4_SECRM_FL 0x00000001 /* Secure deletion */
  332. #define EXT4_UNRM_FL 0x00000002 /* Undelete */
  333. #define EXT4_COMPR_FL 0x00000004 /* Compress file */
  334. #define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */
  335. #define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */
  336. #define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */
  337. #define EXT4_NODUMP_FL 0x00000040 /* do not dump file */
  338. #define EXT4_NOATIME_FL 0x00000080 /* do not update atime */
  339. /* Reserved for compression usage... */
  340. #define EXT4_DIRTY_FL 0x00000100
  341. #define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
  342. #define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */
  343. /* nb: was previously EXT2_ECOMPR_FL */
  344. #define EXT4_ENCRYPT_FL 0x00000800 /* encrypted file */
  345. /* End compression flags --- maybe not all used */
  346. #define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */
  347. #define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */
  348. #define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
  349. #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */
  350. #define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
  351. #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
  352. #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */
  353. #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
  354. #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
  355. #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
  356. #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
  357. #define EXT4_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
  358. #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
  359. #define EXT4_FL_USER_VISIBLE 0x304BDFFF /* User visible flags */
  360. #define EXT4_FL_USER_MODIFIABLE 0x204380FF /* User modifiable flags */
  361. #define EXT4_FL_XFLAG_VISIBLE (EXT4_SYNC_FL | \
  362. EXT4_IMMUTABLE_FL | \
  363. EXT4_APPEND_FL | \
  364. EXT4_NODUMP_FL | \
  365. EXT4_NOATIME_FL | \
  366. EXT4_PROJINHERIT_FL)
  367. /* Flags that should be inherited by new inodes from their parent. */
  368. #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\
  369. EXT4_SYNC_FL | EXT4_NODUMP_FL | EXT4_NOATIME_FL |\
  370. EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\
  371. EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL |\
  372. EXT4_PROJINHERIT_FL)
  373. /* Flags that are appropriate for regular files (all but dir-specific ones). */
  374. #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL))
  375. /* Flags that are appropriate for non-directories/regular files. */
  376. #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL)
  377. /* Mask out flags that are inappropriate for the given type of inode. */
  378. static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags)
  379. {
  380. if (S_ISDIR(mode))
  381. return flags;
  382. else if (S_ISREG(mode))
  383. return flags & EXT4_REG_FLMASK;
  384. else
  385. return flags & EXT4_OTHER_FLMASK;
  386. }
  387. /*
  388. * Inode flags used for atomic set/get
  389. */
  390. enum {
  391. EXT4_INODE_SECRM = 0, /* Secure deletion */
  392. EXT4_INODE_UNRM = 1, /* Undelete */
  393. EXT4_INODE_COMPR = 2, /* Compress file */
  394. EXT4_INODE_SYNC = 3, /* Synchronous updates */
  395. EXT4_INODE_IMMUTABLE = 4, /* Immutable file */
  396. EXT4_INODE_APPEND = 5, /* writes to file may only append */
  397. EXT4_INODE_NODUMP = 6, /* do not dump file */
  398. EXT4_INODE_NOATIME = 7, /* do not update atime */
  399. /* Reserved for compression usage... */
  400. EXT4_INODE_DIRTY = 8,
  401. EXT4_INODE_COMPRBLK = 9, /* One or more compressed clusters */
  402. EXT4_INODE_NOCOMPR = 10, /* Don't compress */
  403. EXT4_INODE_ENCRYPT = 11, /* Encrypted file */
  404. /* End compression flags --- maybe not all used */
  405. EXT4_INODE_INDEX = 12, /* hash-indexed directory */
  406. EXT4_INODE_IMAGIC = 13, /* AFS directory */
  407. EXT4_INODE_JOURNAL_DATA = 14, /* file data should be journaled */
  408. EXT4_INODE_NOTAIL = 15, /* file tail should not be merged */
  409. EXT4_INODE_DIRSYNC = 16, /* dirsync behaviour (directories only) */
  410. EXT4_INODE_TOPDIR = 17, /* Top of directory hierarchies*/
  411. EXT4_INODE_HUGE_FILE = 18, /* Set to each huge file */
  412. EXT4_INODE_EXTENTS = 19, /* Inode uses extents */
  413. EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */
  414. EXT4_INODE_EOFBLOCKS = 22, /* Blocks allocated beyond EOF */
  415. EXT4_INODE_INLINE_DATA = 28, /* Data in inode. */
  416. EXT4_INODE_PROJINHERIT = 29, /* Create with parents projid */
  417. EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */
  418. };
  419. /*
  420. * Since it's pretty easy to mix up bit numbers and hex values, we use a
  421. * build-time check to make sure that EXT4_XXX_FL is consistent with respect to
  422. * EXT4_INODE_XXX. If all is well, the macros will be dropped, so, it won't cost
  423. * any extra space in the compiled kernel image, otherwise, the build will fail.
  424. * It's important that these values are the same, since we are using
  425. * EXT4_INODE_XXX to test for flag values, but EXT4_XXX_FL must be consistent
  426. * with the values of FS_XXX_FL defined in include/linux/fs.h and the on-disk
  427. * values found in ext2, ext3 and ext4 filesystems, and of course the values
  428. * defined in e2fsprogs.
  429. *
  430. * It's not paranoia if the Murphy's Law really *is* out to get you. :-)
  431. */
  432. #define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG))
  433. #define CHECK_FLAG_VALUE(FLAG) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG))
  434. static inline void ext4_check_flag_values(void)
  435. {
  436. CHECK_FLAG_VALUE(SECRM);
  437. CHECK_FLAG_VALUE(UNRM);
  438. CHECK_FLAG_VALUE(COMPR);
  439. CHECK_FLAG_VALUE(SYNC);
  440. CHECK_FLAG_VALUE(IMMUTABLE);
  441. CHECK_FLAG_VALUE(APPEND);
  442. CHECK_FLAG_VALUE(NODUMP);
  443. CHECK_FLAG_VALUE(NOATIME);
  444. CHECK_FLAG_VALUE(DIRTY);
  445. CHECK_FLAG_VALUE(COMPRBLK);
  446. CHECK_FLAG_VALUE(NOCOMPR);
  447. CHECK_FLAG_VALUE(ENCRYPT);
  448. CHECK_FLAG_VALUE(INDEX);
  449. CHECK_FLAG_VALUE(IMAGIC);
  450. CHECK_FLAG_VALUE(JOURNAL_DATA);
  451. CHECK_FLAG_VALUE(NOTAIL);
  452. CHECK_FLAG_VALUE(DIRSYNC);
  453. CHECK_FLAG_VALUE(TOPDIR);
  454. CHECK_FLAG_VALUE(HUGE_FILE);
  455. CHECK_FLAG_VALUE(EXTENTS);
  456. CHECK_FLAG_VALUE(EA_INODE);
  457. CHECK_FLAG_VALUE(EOFBLOCKS);
  458. CHECK_FLAG_VALUE(INLINE_DATA);
  459. CHECK_FLAG_VALUE(PROJINHERIT);
  460. CHECK_FLAG_VALUE(RESERVED);
  461. }
  462. /* Used to pass group descriptor data when online resize is done */
  463. struct ext4_new_group_input {
  464. __u32 group; /* Group number for this data */
  465. __u64 block_bitmap; /* Absolute block number of block bitmap */
  466. __u64 inode_bitmap; /* Absolute block number of inode bitmap */
  467. __u64 inode_table; /* Absolute block number of inode table start */
  468. __u32 blocks_count; /* Total number of blocks in this group */
  469. __u16 reserved_blocks; /* Number of reserved blocks in this group */
  470. __u16 unused;
  471. };
  472. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  473. struct compat_ext4_new_group_input {
  474. u32 group;
  475. compat_u64 block_bitmap;
  476. compat_u64 inode_bitmap;
  477. compat_u64 inode_table;
  478. u32 blocks_count;
  479. u16 reserved_blocks;
  480. u16 unused;
  481. };
  482. #endif
  483. /* The struct ext4_new_group_input in kernel space, with free_blocks_count */
  484. struct ext4_new_group_data {
  485. __u32 group;
  486. __u64 block_bitmap;
  487. __u64 inode_bitmap;
  488. __u64 inode_table;
  489. __u32 blocks_count;
  490. __u16 reserved_blocks;
  491. __u16 unused;
  492. __u32 free_blocks_count;
  493. };
  494. /* Indexes used to index group tables in ext4_new_group_data */
  495. enum {
  496. BLOCK_BITMAP = 0, /* block bitmap */
  497. INODE_BITMAP, /* inode bitmap */
  498. INODE_TABLE, /* inode tables */
  499. GROUP_TABLE_COUNT,
  500. };
  501. /*
  502. * Flags used by ext4_map_blocks()
  503. */
  504. /* Allocate any needed blocks and/or convert an unwritten
  505. extent to be an initialized ext4 */
  506. #define EXT4_GET_BLOCKS_CREATE 0x0001
  507. /* Request the creation of an unwritten extent */
  508. #define EXT4_GET_BLOCKS_UNWRIT_EXT 0x0002
  509. #define EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT (EXT4_GET_BLOCKS_UNWRIT_EXT|\
  510. EXT4_GET_BLOCKS_CREATE)
  511. /* Caller is from the delayed allocation writeout path
  512. * finally doing the actual allocation of delayed blocks */
  513. #define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004
  514. /* caller is from the direct IO path, request to creation of an
  515. unwritten extents if not allocated, split the unwritten
  516. extent if blocks has been preallocated already*/
  517. #define EXT4_GET_BLOCKS_PRE_IO 0x0008
  518. #define EXT4_GET_BLOCKS_CONVERT 0x0010
  519. #define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\
  520. EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT)
  521. /* Convert extent to initialized after IO complete */
  522. #define EXT4_GET_BLOCKS_IO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\
  523. EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT)
  524. /* Eventual metadata allocation (due to growing extent tree)
  525. * should not fail, so try to use reserved blocks for that.*/
  526. #define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020
  527. /* Don't normalize allocation size (used for fallocate) */
  528. #define EXT4_GET_BLOCKS_NO_NORMALIZE 0x0040
  529. /* Request will not result in inode size update (user for fallocate) */
  530. #define EXT4_GET_BLOCKS_KEEP_SIZE 0x0080
  531. /* Convert written extents to unwritten */
  532. #define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0100
  533. /* Write zeros to newly created written extents */
  534. #define EXT4_GET_BLOCKS_ZERO 0x0200
  535. #define EXT4_GET_BLOCKS_CREATE_ZERO (EXT4_GET_BLOCKS_CREATE |\
  536. EXT4_GET_BLOCKS_ZERO)
  537. /* Caller will submit data before dropping transaction handle. This
  538. * allows jbd2 to avoid submitting data before commit. */
  539. #define EXT4_GET_BLOCKS_IO_SUBMIT 0x0400
  540. /*
  541. * The bit position of these flags must not overlap with any of the
  542. * EXT4_GET_BLOCKS_*. They are used by ext4_find_extent(),
  543. * read_extent_tree_block(), ext4_split_extent_at(),
  544. * ext4_ext_insert_extent(), and ext4_ext_create_new_leaf().
  545. * EXT4_EX_NOCACHE is used to indicate that the we shouldn't be
  546. * caching the extents when reading from the extent tree while a
  547. * truncate or punch hole operation is in progress.
  548. */
  549. #define EXT4_EX_NOCACHE 0x40000000
  550. #define EXT4_EX_FORCE_CACHE 0x20000000
  551. /*
  552. * Flags used by ext4_free_blocks
  553. */
  554. #define EXT4_FREE_BLOCKS_METADATA 0x0001
  555. #define EXT4_FREE_BLOCKS_FORGET 0x0002
  556. #define EXT4_FREE_BLOCKS_VALIDATED 0x0004
  557. #define EXT4_FREE_BLOCKS_NO_QUOT_UPDATE 0x0008
  558. #define EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER 0x0010
  559. #define EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER 0x0020
  560. /* Encryption algorithms */
  561. #define EXT4_ENCRYPTION_MODE_INVALID 0
  562. #define EXT4_ENCRYPTION_MODE_AES_256_XTS 1
  563. #define EXT4_ENCRYPTION_MODE_AES_256_GCM 2
  564. #define EXT4_ENCRYPTION_MODE_AES_256_CBC 3
  565. #define EXT4_ENCRYPTION_MODE_AES_256_CTS 4
  566. #include "ext4_crypto.h"
  567. /*
  568. * ioctl commands
  569. */
  570. #define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS
  571. #define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS
  572. #define EXT4_IOC_GETVERSION _IOR('f', 3, long)
  573. #define EXT4_IOC_SETVERSION _IOW('f', 4, long)
  574. #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION
  575. #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION
  576. #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)
  577. #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long)
  578. #define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
  579. #define EXT4_IOC_GROUP_ADD _IOW('f', 8, struct ext4_new_group_input)
  580. #define EXT4_IOC_MIGRATE _IO('f', 9)
  581. /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */
  582. /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */
  583. #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12)
  584. #define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent)
  585. #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64)
  586. #define EXT4_IOC_SWAP_BOOT _IO('f', 17)
  587. #define EXT4_IOC_PRECACHE_EXTENTS _IO('f', 18)
  588. #define EXT4_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct ext4_encryption_policy)
  589. #define EXT4_IOC_GET_ENCRYPTION_PWSALT _IOW('f', 20, __u8[16])
  590. #define EXT4_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct ext4_encryption_policy)
  591. #ifndef FS_IOC_FSGETXATTR
  592. /* Until the uapi changes get merged for project quota... */
  593. #define FS_IOC_FSGETXATTR _IOR('X', 31, struct fsxattr)
  594. #define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr)
  595. /*
  596. * Structure for FS_IOC_FSGETXATTR and FS_IOC_FSSETXATTR.
  597. */
  598. struct fsxattr {
  599. __u32 fsx_xflags; /* xflags field value (get/set) */
  600. __u32 fsx_extsize; /* extsize field value (get/set)*/
  601. __u32 fsx_nextents; /* nextents field value (get) */
  602. __u32 fsx_projid; /* project identifier (get/set) */
  603. unsigned char fsx_pad[12];
  604. };
  605. /*
  606. * Flags for the fsx_xflags field
  607. */
  608. #define FS_XFLAG_REALTIME 0x00000001 /* data in realtime volume */
  609. #define FS_XFLAG_PREALLOC 0x00000002 /* preallocated file extents */
  610. #define FS_XFLAG_IMMUTABLE 0x00000008 /* file cannot be modified */
  611. #define FS_XFLAG_APPEND 0x00000010 /* all writes append */
  612. #define FS_XFLAG_SYNC 0x00000020 /* all writes synchronous */
  613. #define FS_XFLAG_NOATIME 0x00000040 /* do not update access time */
  614. #define FS_XFLAG_NODUMP 0x00000080 /* do not include in backups */
  615. #define FS_XFLAG_RTINHERIT 0x00000100 /* create with rt bit set */
  616. #define FS_XFLAG_PROJINHERIT 0x00000200 /* create with parents projid */
  617. #define FS_XFLAG_NOSYMLINKS 0x00000400 /* disallow symlink creation */
  618. #define FS_XFLAG_EXTSIZE 0x00000800 /* extent size allocator hint */
  619. #define FS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
  620. #define FS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
  621. #define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
  622. #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
  623. #endif /* !defined(FS_IOC_FSGETXATTR) */
  624. #define EXT4_IOC_FSGETXATTR FS_IOC_FSGETXATTR
  625. #define EXT4_IOC_FSSETXATTR FS_IOC_FSSETXATTR
  626. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  627. /*
  628. * ioctl commands in 32 bit emulation
  629. */
  630. #define EXT4_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  631. #define EXT4_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  632. #define EXT4_IOC32_GETVERSION _IOR('f', 3, int)
  633. #define EXT4_IOC32_SETVERSION _IOW('f', 4, int)
  634. #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
  635. #define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)
  636. #define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
  637. #define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input)
  638. #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION
  639. #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
  640. #endif
  641. /* Max physical block we can address w/o extents */
  642. #define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF
  643. /*
  644. * Structure of an inode on the disk
  645. */
  646. struct ext4_inode {
  647. __le16 i_mode; /* File mode */
  648. __le16 i_uid; /* Low 16 bits of Owner Uid */
  649. __le32 i_size_lo; /* Size in bytes */
  650. __le32 i_atime; /* Access time */
  651. __le32 i_ctime; /* Inode Change time */
  652. __le32 i_mtime; /* Modification time */
  653. __le32 i_dtime; /* Deletion Time */
  654. __le16 i_gid; /* Low 16 bits of Group Id */
  655. __le16 i_links_count; /* Links count */
  656. __le32 i_blocks_lo; /* Blocks count */
  657. __le32 i_flags; /* File flags */
  658. union {
  659. struct {
  660. __le32 l_i_version;
  661. } linux1;
  662. struct {
  663. __u32 h_i_translator;
  664. } hurd1;
  665. struct {
  666. __u32 m_i_reserved1;
  667. } masix1;
  668. } osd1; /* OS dependent 1 */
  669. __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */
  670. __le32 i_generation; /* File version (for NFS) */
  671. __le32 i_file_acl_lo; /* File ACL */
  672. __le32 i_size_high;
  673. __le32 i_obso_faddr; /* Obsoleted fragment address */
  674. union {
  675. struct {
  676. __le16 l_i_blocks_high; /* were l_i_reserved1 */
  677. __le16 l_i_file_acl_high;
  678. __le16 l_i_uid_high; /* these 2 fields */
  679. __le16 l_i_gid_high; /* were reserved2[0] */
  680. __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
  681. __le16 l_i_reserved;
  682. } linux2;
  683. struct {
  684. __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
  685. __u16 h_i_mode_high;
  686. __u16 h_i_uid_high;
  687. __u16 h_i_gid_high;
  688. __u32 h_i_author;
  689. } hurd2;
  690. struct {
  691. __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
  692. __le16 m_i_file_acl_high;
  693. __u32 m_i_reserved2[2];
  694. } masix2;
  695. } osd2; /* OS dependent 2 */
  696. __le16 i_extra_isize;
  697. __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */
  698. __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */
  699. __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */
  700. __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
  701. __le32 i_crtime; /* File Creation time */
  702. __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
  703. __le32 i_version_hi; /* high 32 bits for 64-bit version */
  704. __le32 i_projid; /* Project ID */
  705. };
  706. struct move_extent {
  707. __u32 reserved; /* should be zero */
  708. __u32 donor_fd; /* donor file descriptor */
  709. __u64 orig_start; /* logical start offset in block for orig */
  710. __u64 donor_start; /* logical start offset in block for donor */
  711. __u64 len; /* block length to be moved */
  712. __u64 moved_len; /* moved block length */
  713. };
  714. #define EXT4_EPOCH_BITS 2
  715. #define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)
  716. #define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS)
  717. /*
  718. * Extended fields will fit into an inode if the filesystem was formatted
  719. * with large inodes (-I 256 or larger) and there are not currently any EAs
  720. * consuming all of the available space. For new inodes we always reserve
  721. * enough space for the kernel's known extended fields, but for inodes
  722. * created with an old kernel this might not have been the case. None of
  723. * the extended inode fields is critical for correct filesystem operation.
  724. * This macro checks if a certain field fits in the inode. Note that
  725. * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize
  726. */
  727. #define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \
  728. ((offsetof(typeof(*ext4_inode), field) + \
  729. sizeof((ext4_inode)->field)) \
  730. <= (EXT4_GOOD_OLD_INODE_SIZE + \
  731. (einode)->i_extra_isize)) \
  732. /*
  733. * We use an encoding that preserves the times for extra epoch "00":
  734. *
  735. * extra msb of adjust for signed
  736. * epoch 32-bit 32-bit tv_sec to
  737. * bits time decoded 64-bit tv_sec 64-bit tv_sec valid time range
  738. * 0 0 1 -0x80000000..-0x00000001 0x000000000 1901-12-13..1969-12-31
  739. * 0 0 0 0x000000000..0x07fffffff 0x000000000 1970-01-01..2038-01-19
  740. * 0 1 1 0x080000000..0x0ffffffff 0x100000000 2038-01-19..2106-02-07
  741. * 0 1 0 0x100000000..0x17fffffff 0x100000000 2106-02-07..2174-02-25
  742. * 1 0 1 0x180000000..0x1ffffffff 0x200000000 2174-02-25..2242-03-16
  743. * 1 0 0 0x200000000..0x27fffffff 0x200000000 2242-03-16..2310-04-04
  744. * 1 1 1 0x280000000..0x2ffffffff 0x300000000 2310-04-04..2378-04-22
  745. * 1 1 0 0x300000000..0x37fffffff 0x300000000 2378-04-22..2446-05-10
  746. *
  747. * Note that previous versions of the kernel on 64-bit systems would
  748. * incorrectly use extra epoch bits 1,1 for dates between 1901 and
  749. * 1970. e2fsck will correct this, assuming that it is run on the
  750. * affected filesystem before 2242.
  751. */
  752. static inline __le32 ext4_encode_extra_time(struct timespec *time)
  753. {
  754. u32 extra = sizeof(time->tv_sec) > 4 ?
  755. ((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK : 0;
  756. return cpu_to_le32(extra | (time->tv_nsec << EXT4_EPOCH_BITS));
  757. }
  758. static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra)
  759. {
  760. if (unlikely(sizeof(time->tv_sec) > 4 &&
  761. (extra & cpu_to_le32(EXT4_EPOCH_MASK)))) {
  762. #if LINUX_VERSION_CODE < KERNEL_VERSION(4,20,0)
  763. /* Handle legacy encoding of pre-1970 dates with epoch
  764. * bits 1,1. We assume that by kernel version 4.20,
  765. * everyone will have run fsck over the affected
  766. * filesystems to correct the problem. (This
  767. * backwards compatibility may be removed before this
  768. * time, at the discretion of the ext4 developers.)
  769. */
  770. u64 extra_bits = le32_to_cpu(extra) & EXT4_EPOCH_MASK;
  771. if (extra_bits == 3 && ((time->tv_sec) & 0x80000000) != 0)
  772. extra_bits = 0;
  773. time->tv_sec += extra_bits << 32;
  774. #else
  775. time->tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32;
  776. #endif
  777. }
  778. time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS;
  779. }
  780. #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \
  781. do { \
  782. (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \
  783. if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
  784. (raw_inode)->xtime ## _extra = \
  785. ext4_encode_extra_time(&(inode)->xtime); \
  786. } while (0)
  787. #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \
  788. do { \
  789. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
  790. (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \
  791. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
  792. (raw_inode)->xtime ## _extra = \
  793. ext4_encode_extra_time(&(einode)->xtime); \
  794. } while (0)
  795. #define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \
  796. do { \
  797. (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \
  798. if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
  799. ext4_decode_extra_time(&(inode)->xtime, \
  800. raw_inode->xtime ## _extra); \
  801. else \
  802. (inode)->xtime.tv_nsec = 0; \
  803. } while (0)
  804. #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \
  805. do { \
  806. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
  807. (einode)->xtime.tv_sec = \
  808. (signed)le32_to_cpu((raw_inode)->xtime); \
  809. else \
  810. (einode)->xtime.tv_sec = 0; \
  811. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
  812. ext4_decode_extra_time(&(einode)->xtime, \
  813. raw_inode->xtime ## _extra); \
  814. else \
  815. (einode)->xtime.tv_nsec = 0; \
  816. } while (0)
  817. #define i_disk_version osd1.linux1.l_i_version
  818. #if defined(__KERNEL__) || defined(__linux__)
  819. #define i_reserved1 osd1.linux1.l_i_reserved1
  820. #define i_file_acl_high osd2.linux2.l_i_file_acl_high
  821. #define i_blocks_high osd2.linux2.l_i_blocks_high
  822. #define i_uid_low i_uid
  823. #define i_gid_low i_gid
  824. #define i_uid_high osd2.linux2.l_i_uid_high
  825. #define i_gid_high osd2.linux2.l_i_gid_high
  826. #define i_checksum_lo osd2.linux2.l_i_checksum_lo
  827. #elif defined(__GNU__)
  828. #define i_translator osd1.hurd1.h_i_translator
  829. #define i_uid_high osd2.hurd2.h_i_uid_high
  830. #define i_gid_high osd2.hurd2.h_i_gid_high
  831. #define i_author osd2.hurd2.h_i_author
  832. #elif defined(__masix__)
  833. #define i_reserved1 osd1.masix1.m_i_reserved1
  834. #define i_file_acl_high osd2.masix2.m_i_file_acl_high
  835. #define i_reserved2 osd2.masix2.m_i_reserved2
  836. #endif /* defined(__KERNEL__) || defined(__linux__) */
  837. #include "extents_status.h"
  838. /*
  839. * Lock subclasses for i_data_sem in the ext4_inode_info structure.
  840. *
  841. * These are needed to avoid lockdep false positives when we need to
  842. * allocate blocks to the quota inode during ext4_map_blocks(), while
  843. * holding i_data_sem for a normal (non-quota) inode. Since we don't
  844. * do quota tracking for the quota inode, this avoids deadlock (as
  845. * well as infinite recursion, since it isn't turtles all the way
  846. * down...)
  847. *
  848. * I_DATA_SEM_NORMAL - Used for most inodes
  849. * I_DATA_SEM_OTHER - Used by move_inode.c for the second normal inode
  850. * where the second inode has larger inode number
  851. * than the first
  852. * I_DATA_SEM_QUOTA - Used for quota inodes only
  853. */
  854. enum {
  855. I_DATA_SEM_NORMAL = 0,
  856. I_DATA_SEM_OTHER,
  857. I_DATA_SEM_QUOTA,
  858. };
  859. /*
  860. * fourth extended file system inode data in memory
  861. */
  862. struct ext4_inode_info {
  863. __le32 i_data[15]; /* unconverted */
  864. __u32 i_dtime;
  865. ext4_fsblk_t i_file_acl;
  866. /*
  867. * i_block_group is the number of the block group which contains
  868. * this file's inode. Constant across the lifetime of the inode,
  869. * it is ued for making block allocation decisions - we try to
  870. * place a file's data blocks near its inode block, and new inodes
  871. * near to their parent directory's inode.
  872. */
  873. ext4_group_t i_block_group;
  874. ext4_lblk_t i_dir_start_lookup;
  875. #if (BITS_PER_LONG < 64)
  876. unsigned long i_state_flags; /* Dynamic state flags */
  877. #endif
  878. unsigned long i_flags;
  879. /*
  880. * Extended attributes can be read independently of the main file
  881. * data. Taking i_mutex even when reading would cause contention
  882. * between readers of EAs and writers of regular file data, so
  883. * instead we synchronize on xattr_sem when reading or changing
  884. * EAs.
  885. */
  886. struct rw_semaphore xattr_sem;
  887. struct list_head i_orphan; /* unlinked but open inodes */
  888. /*
  889. * i_disksize keeps track of what the inode size is ON DISK, not
  890. * in memory. During truncate, i_size is set to the new size by
  891. * the VFS prior to calling ext4_truncate(), but the filesystem won't
  892. * set i_disksize to 0 until the truncate is actually under way.
  893. *
  894. * The intent is that i_disksize always represents the blocks which
  895. * are used by this file. This allows recovery to restart truncate
  896. * on orphans if we crash during truncate. We actually write i_disksize
  897. * into the on-disk inode when writing inodes out, instead of i_size.
  898. *
  899. * The only time when i_disksize and i_size may be different is when
  900. * a truncate is in progress. The only things which change i_disksize
  901. * are ext4_get_block (growth) and ext4_truncate (shrinkth).
  902. */
  903. loff_t i_disksize;
  904. /*
  905. * i_data_sem is for serialising ext4_truncate() against
  906. * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's
  907. * data tree are chopped off during truncate. We can't do that in
  908. * ext4 because whenever we perform intermediate commits during
  909. * truncate, the inode and all the metadata blocks *must* be in a
  910. * consistent state which allows truncation of the orphans to restart
  911. * during recovery. Hence we must fix the get_block-vs-truncate race
  912. * by other means, so we have i_data_sem.
  913. */
  914. struct rw_semaphore i_data_sem;
  915. /*
  916. * i_mmap_sem is for serializing page faults with truncate / punch hole
  917. * operations. We have to make sure that new page cannot be faulted in
  918. * a section of the inode that is being punched. We cannot easily use
  919. * i_data_sem for this since we need protection for the whole punch
  920. * operation and i_data_sem ranks below transaction start so we have
  921. * to occasionally drop it.
  922. */
  923. struct rw_semaphore i_mmap_sem;
  924. struct inode vfs_inode;
  925. struct jbd2_inode *jinode;
  926. spinlock_t i_raw_lock; /* protects updates to the raw inode */
  927. /*
  928. * File creation time. Its function is same as that of
  929. * struct timespec i_{a,c,m}time in the generic inode.
  930. */
  931. struct timespec i_crtime;
  932. /* mballoc */
  933. struct list_head i_prealloc_list;
  934. spinlock_t i_prealloc_lock;
  935. /* extents status tree */
  936. struct ext4_es_tree i_es_tree;
  937. rwlock_t i_es_lock;
  938. struct list_head i_es_list;
  939. unsigned int i_es_all_nr; /* protected by i_es_lock */
  940. unsigned int i_es_shk_nr; /* protected by i_es_lock */
  941. ext4_lblk_t i_es_shrink_lblk; /* Offset where we start searching for
  942. extents to shrink. Protected by
  943. i_es_lock */
  944. /* ialloc */
  945. ext4_group_t i_last_alloc_group;
  946. /* allocation reservation info for delalloc */
  947. /* In case of bigalloc, these refer to clusters rather than blocks */
  948. unsigned int i_reserved_data_blocks;
  949. unsigned int i_reserved_meta_blocks;
  950. unsigned int i_allocated_meta_blocks;
  951. ext4_lblk_t i_da_metadata_calc_last_lblock;
  952. int i_da_metadata_calc_len;
  953. /* on-disk additional length */
  954. __u16 i_extra_isize;
  955. /* Indicate the inline data space. */
  956. u16 i_inline_off;
  957. u16 i_inline_size;
  958. #ifdef CONFIG_QUOTA
  959. /* quota space reservation, managed internally by quota code */
  960. qsize_t i_reserved_quota;
  961. #endif
  962. /* Lock protecting lists below */
  963. spinlock_t i_completed_io_lock;
  964. /*
  965. * Completed IOs that need unwritten extents handling and have
  966. * transaction reserved
  967. */
  968. struct list_head i_rsv_conversion_list;
  969. struct work_struct i_rsv_conversion_work;
  970. atomic_t i_unwritten; /* Nr. of inflight conversions pending */
  971. spinlock_t i_block_reservation_lock;
  972. /*
  973. * Transactions that contain inode's metadata needed to complete
  974. * fsync and fdatasync, respectively.
  975. */
  976. tid_t i_sync_tid;
  977. tid_t i_datasync_tid;
  978. #ifdef CONFIG_QUOTA
  979. struct dquot *i_dquot[MAXQUOTAS];
  980. #endif
  981. /* Precomputed uuid+inum+igen checksum for seeding inode checksums */
  982. __u32 i_csum_seed;
  983. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  984. /* Encryption params */
  985. struct ext4_crypt_info *i_crypt_info;
  986. #endif
  987. kprojid_t i_projid;
  988. };
  989. /*
  990. * File system states
  991. */
  992. #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */
  993. #define EXT4_ERROR_FS 0x0002 /* Errors detected */
  994. #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */
  995. /*
  996. * Misc. filesystem flags
  997. */
  998. #define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */
  999. #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */
  1000. #define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */
  1001. /*
  1002. * Mount flags set via mount options or defaults
  1003. */
  1004. #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */
  1005. #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */
  1006. #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */
  1007. #define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */
  1008. #define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */
  1009. #define EXT4_MOUNT_ERRORS_MASK 0x00070
  1010. #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */
  1011. #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/
  1012. #ifdef CONFIG_FS_DAX
  1013. #define EXT4_MOUNT_DAX 0x00200 /* Direct Access */
  1014. #else
  1015. #define EXT4_MOUNT_DAX 0
  1016. #endif
  1017. #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */
  1018. #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */
  1019. #define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */
  1020. #define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */
  1021. #define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */
  1022. #define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */
  1023. #define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */
  1024. #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
  1025. #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
  1026. #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
  1027. #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
  1028. #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
  1029. #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
  1030. #define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000 /* Enable support for dio read nolocking */
  1031. #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
  1032. #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
  1033. #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
  1034. #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */
  1035. #define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */
  1036. #define EXT4_MOUNT_DISCARD 0x40000000 /* Issue DISCARD requests */
  1037. #define EXT4_MOUNT_INIT_INODE_TABLE 0x80000000 /* Initialize uninitialized itables */
  1038. /*
  1039. * Mount flags set either automatically (could not be set by mount option)
  1040. * based on per file system feature or property or in special cases such as
  1041. * distinguishing between explicit mount option definition and default.
  1042. */
  1043. #define EXT4_MOUNT2_EXPLICIT_DELALLOC 0x00000001 /* User explicitly
  1044. specified delalloc */
  1045. #define EXT4_MOUNT2_STD_GROUP_SIZE 0x00000002 /* We have standard group
  1046. size of blocksize * 8
  1047. blocks */
  1048. #define EXT4_MOUNT2_HURD_COMPAT 0x00000004 /* Support HURD-castrated
  1049. file systems */
  1050. #define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM 0x00000008 /* User explicitly
  1051. specified journal checksum */
  1052. #define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \
  1053. ~EXT4_MOUNT_##opt
  1054. #define set_opt(sb, opt) EXT4_SB(sb)->s_mount_opt |= \
  1055. EXT4_MOUNT_##opt
  1056. #define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \
  1057. EXT4_MOUNT_##opt)
  1058. #define clear_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 &= \
  1059. ~EXT4_MOUNT2_##opt
  1060. #define set_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 |= \
  1061. EXT4_MOUNT2_##opt
  1062. #define test_opt2(sb, opt) (EXT4_SB(sb)->s_mount_opt2 & \
  1063. EXT4_MOUNT2_##opt)
  1064. #define ext4_test_and_set_bit __test_and_set_bit_le
  1065. #define ext4_set_bit __set_bit_le
  1066. #define ext4_set_bit_atomic ext2_set_bit_atomic
  1067. #define ext4_test_and_clear_bit __test_and_clear_bit_le
  1068. #define ext4_clear_bit __clear_bit_le
  1069. #define ext4_clear_bit_atomic ext2_clear_bit_atomic
  1070. #define ext4_test_bit test_bit_le
  1071. #define ext4_find_next_zero_bit find_next_zero_bit_le
  1072. #define ext4_find_next_bit find_next_bit_le
  1073. extern void ext4_set_bits(void *bm, int cur, int len);
  1074. /*
  1075. * Maximal mount counts between two filesystem checks
  1076. */
  1077. #define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
  1078. #define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */
  1079. /*
  1080. * Behaviour when detecting errors
  1081. */
  1082. #define EXT4_ERRORS_CONTINUE 1 /* Continue execution */
  1083. #define EXT4_ERRORS_RO 2 /* Remount fs read-only */
  1084. #define EXT4_ERRORS_PANIC 3 /* Panic */
  1085. #define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
  1086. /* Metadata checksum algorithm codes */
  1087. #define EXT4_CRC32C_CHKSUM 1
  1088. /*
  1089. * Structure of the super block
  1090. */
  1091. struct ext4_super_block {
  1092. /*00*/ __le32 s_inodes_count; /* Inodes count */
  1093. __le32 s_blocks_count_lo; /* Blocks count */
  1094. __le32 s_r_blocks_count_lo; /* Reserved blocks count */
  1095. __le32 s_free_blocks_count_lo; /* Free blocks count */
  1096. /*10*/ __le32 s_free_inodes_count; /* Free inodes count */
  1097. __le32 s_first_data_block; /* First Data Block */
  1098. __le32 s_log_block_size; /* Block size */
  1099. __le32 s_log_cluster_size; /* Allocation cluster size */
  1100. /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */
  1101. __le32 s_clusters_per_group; /* # Clusters per group */
  1102. __le32 s_inodes_per_group; /* # Inodes per group */
  1103. __le32 s_mtime; /* Mount time */
  1104. /*30*/ __le32 s_wtime; /* Write time */
  1105. __le16 s_mnt_count; /* Mount count */
  1106. __le16 s_max_mnt_count; /* Maximal mount count */
  1107. __le16 s_magic; /* Magic signature */
  1108. __le16 s_state; /* File system state */
  1109. __le16 s_errors; /* Behaviour when detecting errors */
  1110. __le16 s_minor_rev_level; /* minor revision level */
  1111. /*40*/ __le32 s_lastcheck; /* time of last check */
  1112. __le32 s_checkinterval; /* max. time between checks */
  1113. __le32 s_creator_os; /* OS */
  1114. __le32 s_rev_level; /* Revision level */
  1115. /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */
  1116. __le16 s_def_resgid; /* Default gid for reserved blocks */
  1117. /*
  1118. * These fields are for EXT4_DYNAMIC_REV superblocks only.
  1119. *
  1120. * Note: the difference between the compatible feature set and
  1121. * the incompatible feature set is that if there is a bit set
  1122. * in the incompatible feature set that the kernel doesn't
  1123. * know about, it should refuse to mount the filesystem.
  1124. *
  1125. * e2fsck's requirements are more strict; if it doesn't know
  1126. * about a feature in either the compatible or incompatible
  1127. * feature set, it must abort and not try to meddle with
  1128. * things it doesn't understand...
  1129. */
  1130. __le32 s_first_ino; /* First non-reserved inode */
  1131. __le16 s_inode_size; /* size of inode structure */
  1132. __le16 s_block_group_nr; /* block group # of this superblock */
  1133. __le32 s_feature_compat; /* compatible feature set */
  1134. /*60*/ __le32 s_feature_incompat; /* incompatible feature set */
  1135. __le32 s_feature_ro_compat; /* readonly-compatible feature set */
  1136. /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */
  1137. /*78*/ char s_volume_name[16]; /* volume name */
  1138. /*88*/ char s_last_mounted[64]; /* directory where last mounted */
  1139. /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */
  1140. /*
  1141. * Performance hints. Directory preallocation should only
  1142. * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
  1143. */
  1144. __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
  1145. __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
  1146. __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */
  1147. /*
  1148. * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
  1149. */
  1150. /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */
  1151. /*E0*/ __le32 s_journal_inum; /* inode number of journal file */
  1152. __le32 s_journal_dev; /* device number of journal file */
  1153. __le32 s_last_orphan; /* start of list of inodes to delete */
  1154. __le32 s_hash_seed[4]; /* HTREE hash seed */
  1155. __u8 s_def_hash_version; /* Default hash version to use */
  1156. __u8 s_jnl_backup_type;
  1157. __le16 s_desc_size; /* size of group descriptor */
  1158. /*100*/ __le32 s_default_mount_opts;
  1159. __le32 s_first_meta_bg; /* First metablock block group */
  1160. __le32 s_mkfs_time; /* When the filesystem was created */
  1161. __le32 s_jnl_blocks[17]; /* Backup of the journal inode */
  1162. /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
  1163. /*150*/ __le32 s_blocks_count_hi; /* Blocks count */
  1164. __le32 s_r_blocks_count_hi; /* Reserved blocks count */
  1165. __le32 s_free_blocks_count_hi; /* Free blocks count */
  1166. __le16 s_min_extra_isize; /* All inodes have at least # bytes */
  1167. __le16 s_want_extra_isize; /* New inodes should reserve # bytes */
  1168. __le32 s_flags; /* Miscellaneous flags */
  1169. __le16 s_raid_stride; /* RAID stride */
  1170. __le16 s_mmp_update_interval; /* # seconds to wait in MMP checking */
  1171. __le64 s_mmp_block; /* Block for multi-mount protection */
  1172. __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
  1173. __u8 s_log_groups_per_flex; /* FLEX_BG group size */
  1174. __u8 s_checksum_type; /* metadata checksum algorithm used */
  1175. __u8 s_encryption_level; /* versioning level for encryption */
  1176. __u8 s_reserved_pad; /* Padding to next 32bits */
  1177. __le64 s_kbytes_written; /* nr of lifetime kilobytes written */
  1178. __le32 s_snapshot_inum; /* Inode number of active snapshot */
  1179. __le32 s_snapshot_id; /* sequential ID of active snapshot */
  1180. __le64 s_snapshot_r_blocks_count; /* reserved blocks for active
  1181. snapshot's future use */
  1182. __le32 s_snapshot_list; /* inode number of the head of the
  1183. on-disk snapshot list */
  1184. #define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count)
  1185. __le32 s_error_count; /* number of fs errors */
  1186. __le32 s_first_error_time; /* first time an error happened */
  1187. __le32 s_first_error_ino; /* inode involved in first error */
  1188. __le64 s_first_error_block; /* block involved of first error */
  1189. __u8 s_first_error_func[32]; /* function where the error happened */
  1190. __le32 s_first_error_line; /* line number where error happened */
  1191. __le32 s_last_error_time; /* most recent time of an error */
  1192. __le32 s_last_error_ino; /* inode involved in last error */
  1193. __le32 s_last_error_line; /* line number where error happened */
  1194. __le64 s_last_error_block; /* block involved of last error */
  1195. __u8 s_last_error_func[32]; /* function where the error happened */
  1196. #define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts)
  1197. __u8 s_mount_opts[64];
  1198. __le32 s_usr_quota_inum; /* inode for tracking user quota */
  1199. __le32 s_grp_quota_inum; /* inode for tracking group quota */
  1200. __le32 s_overhead_clusters; /* overhead blocks/clusters in fs */
  1201. __le32 s_backup_bgs[2]; /* groups with sparse_super2 SBs */
  1202. __u8 s_encrypt_algos[4]; /* Encryption algorithms in use */
  1203. __u8 s_encrypt_pw_salt[16]; /* Salt used for string2key algorithm */
  1204. __le32 s_lpf_ino; /* Location of the lost+found inode */
  1205. __le32 s_prj_quota_inum; /* inode for tracking project quota */
  1206. __le32 s_checksum_seed; /* crc32c(uuid) if csum_seed set */
  1207. __le32 s_reserved[98]; /* Padding to the end of the block */
  1208. __le32 s_checksum; /* crc32c(superblock) */
  1209. };
  1210. #define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START)
  1211. #ifdef __KERNEL__
  1212. /*
  1213. * run-time mount flags
  1214. */
  1215. #define EXT4_MF_MNTDIR_SAMPLED 0x0001
  1216. #define EXT4_MF_FS_ABORTED 0x0002 /* Fatal error detected */
  1217. #define EXT4_MF_TEST_DUMMY_ENCRYPTION 0x0004
  1218. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  1219. #define DUMMY_ENCRYPTION_ENABLED(sbi) (unlikely((sbi)->s_mount_flags & \
  1220. EXT4_MF_TEST_DUMMY_ENCRYPTION))
  1221. #else
  1222. #define DUMMY_ENCRYPTION_ENABLED(sbi) (0)
  1223. #endif
  1224. /* Number of quota types we support */
  1225. #define EXT4_MAXQUOTAS 3
  1226. /*
  1227. * fourth extended-fs super-block data in memory
  1228. */
  1229. struct ext4_sb_info {
  1230. unsigned long s_desc_size; /* Size of a group descriptor in bytes */
  1231. unsigned long s_inodes_per_block;/* Number of inodes per block */
  1232. unsigned long s_blocks_per_group;/* Number of blocks in a group */
  1233. unsigned long s_clusters_per_group; /* Number of clusters in a group */
  1234. unsigned long s_inodes_per_group;/* Number of inodes in a group */
  1235. unsigned long s_itb_per_group; /* Number of inode table blocks per group */
  1236. unsigned long s_gdb_count; /* Number of group descriptor blocks */
  1237. unsigned long s_desc_per_block; /* Number of group descriptors per block */
  1238. ext4_group_t s_groups_count; /* Number of groups in the fs */
  1239. ext4_group_t s_blockfile_groups;/* Groups acceptable for non-extent files */
  1240. unsigned long s_overhead; /* # of fs overhead clusters */
  1241. unsigned int s_cluster_ratio; /* Number of blocks per cluster */
  1242. unsigned int s_cluster_bits; /* log2 of s_cluster_ratio */
  1243. loff_t s_bitmap_maxbytes; /* max bytes for bitmap files */
  1244. struct buffer_head * s_sbh; /* Buffer containing the super block */
  1245. struct ext4_super_block *s_es; /* Pointer to the super block in the buffer */
  1246. struct buffer_head **s_group_desc;
  1247. unsigned int s_mount_opt;
  1248. unsigned int s_mount_opt2;
  1249. unsigned int s_mount_flags;
  1250. unsigned int s_def_mount_opt;
  1251. ext4_fsblk_t s_sb_block;
  1252. atomic64_t s_resv_clusters;
  1253. kuid_t s_resuid;
  1254. kgid_t s_resgid;
  1255. unsigned short s_mount_state;
  1256. unsigned short s_pad;
  1257. int s_addr_per_block_bits;
  1258. int s_desc_per_block_bits;
  1259. int s_inode_size;
  1260. int s_first_ino;
  1261. unsigned int s_inode_readahead_blks;
  1262. unsigned int s_inode_goal;
  1263. spinlock_t s_next_gen_lock;
  1264. u32 s_next_generation;
  1265. u32 s_hash_seed[4];
  1266. int s_def_hash_version;
  1267. int s_hash_unsigned; /* 3 if hash should be signed, 0 if not */
  1268. struct percpu_counter s_freeclusters_counter;
  1269. struct percpu_counter s_freeinodes_counter;
  1270. struct percpu_counter s_dirs_counter;
  1271. struct percpu_counter s_dirtyclusters_counter;
  1272. struct blockgroup_lock *s_blockgroup_lock;
  1273. struct proc_dir_entry *s_proc;
  1274. struct kobject s_kobj;
  1275. struct completion s_kobj_unregister;
  1276. struct super_block *s_sb;
  1277. /* Journaling */
  1278. struct journal_s *s_journal;
  1279. struct list_head s_orphan;
  1280. struct mutex s_orphan_lock;
  1281. unsigned long s_resize_flags; /* Flags indicating if there
  1282. is a resizer */
  1283. unsigned long s_commit_interval;
  1284. u32 s_max_batch_time;
  1285. u32 s_min_batch_time;
  1286. struct block_device *journal_bdev;
  1287. #ifdef CONFIG_QUOTA
  1288. char *s_qf_names[EXT4_MAXQUOTAS]; /* Names of quota files with journalled quota */
  1289. int s_jquota_fmt; /* Format of quota to use */
  1290. #endif
  1291. unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */
  1292. struct rb_root system_blks;
  1293. #ifdef EXTENTS_STATS
  1294. /* ext4 extents stats */
  1295. unsigned long s_ext_min;
  1296. unsigned long s_ext_max;
  1297. unsigned long s_depth_max;
  1298. spinlock_t s_ext_stats_lock;
  1299. unsigned long s_ext_blocks;
  1300. unsigned long s_ext_extents;
  1301. #endif
  1302. /* for buddy allocator */
  1303. struct ext4_group_info ***s_group_info;
  1304. struct inode *s_buddy_cache;
  1305. spinlock_t s_md_lock;
  1306. unsigned short *s_mb_offsets;
  1307. unsigned int *s_mb_maxs;
  1308. unsigned int s_group_info_size;
  1309. /* tunables */
  1310. unsigned long s_stripe;
  1311. unsigned int s_mb_stream_request;
  1312. unsigned int s_mb_max_to_scan;
  1313. unsigned int s_mb_min_to_scan;
  1314. unsigned int s_mb_stats;
  1315. unsigned int s_mb_order2_reqs;
  1316. unsigned int s_mb_group_prealloc;
  1317. unsigned int s_max_dir_size_kb;
  1318. /* where last allocation was done - for stream allocation */
  1319. unsigned long s_mb_last_group;
  1320. unsigned long s_mb_last_start;
  1321. /* stats for buddy allocator */
  1322. atomic_t s_bal_reqs; /* number of reqs with len > 1 */
  1323. atomic_t s_bal_success; /* we found long enough chunks */
  1324. atomic_t s_bal_allocated; /* in blocks */
  1325. atomic_t s_bal_ex_scanned; /* total extents scanned */
  1326. atomic_t s_bal_goals; /* goal hits */
  1327. atomic_t s_bal_breaks; /* too long searches */
  1328. atomic_t s_bal_2orders; /* 2^order hits */
  1329. spinlock_t s_bal_lock;
  1330. unsigned long s_mb_buddies_generated;
  1331. unsigned long long s_mb_generation_time;
  1332. atomic_t s_mb_lost_chunks;
  1333. atomic_t s_mb_preallocated;
  1334. atomic_t s_mb_discarded;
  1335. atomic_t s_lock_busy;
  1336. /* locality groups */
  1337. struct ext4_locality_group __percpu *s_locality_groups;
  1338. /* for write statistics */
  1339. unsigned long s_sectors_written_start;
  1340. u64 s_kbytes_written;
  1341. /* the size of zero-out chunk */
  1342. unsigned int s_extent_max_zeroout_kb;
  1343. unsigned int s_log_groups_per_flex;
  1344. struct flex_groups *s_flex_groups;
  1345. ext4_group_t s_flex_groups_allocated;
  1346. /* workqueue for reserved extent conversions (buffered io) */
  1347. struct workqueue_struct *rsv_conversion_wq;
  1348. /* timer for periodic error stats printing */
  1349. struct timer_list s_err_report;
  1350. /* Lazy inode table initialization info */
  1351. struct ext4_li_request *s_li_request;
  1352. /* Wait multiplier for lazy initialization thread */
  1353. unsigned int s_li_wait_mult;
  1354. /* Kernel thread for multiple mount protection */
  1355. struct task_struct *s_mmp_tsk;
  1356. /* record the last minlen when FITRIM is called. */
  1357. atomic_t s_last_trim_minblks;
  1358. /* Reference to checksum algorithm driver via cryptoapi */
  1359. struct crypto_shash *s_chksum_driver;
  1360. /* Precomputed FS UUID checksum for seeding other checksums */
  1361. __u32 s_csum_seed;
  1362. /* Reclaim extents from extent status tree */
  1363. struct shrinker s_es_shrinker;
  1364. struct list_head s_es_list; /* List of inodes with reclaimable extents */
  1365. long s_es_nr_inode;
  1366. struct ext4_es_stats s_es_stats;
  1367. struct mb_cache *s_mb_cache;
  1368. spinlock_t s_es_lock ____cacheline_aligned_in_smp;
  1369. /* Ratelimit ext4 messages. */
  1370. struct ratelimit_state s_err_ratelimit_state;
  1371. struct ratelimit_state s_warning_ratelimit_state;
  1372. struct ratelimit_state s_msg_ratelimit_state;
  1373. /* Barrier between changing inodes' journal flags and writepages ops. */
  1374. struct percpu_rw_semaphore s_journal_flag_rwsem;
  1375. };
  1376. static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
  1377. {
  1378. return sb->s_fs_info;
  1379. }
  1380. static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
  1381. {
  1382. return container_of(inode, struct ext4_inode_info, vfs_inode);
  1383. }
  1384. static inline struct timespec ext4_current_time(struct inode *inode)
  1385. {
  1386. return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
  1387. current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
  1388. }
  1389. static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
  1390. {
  1391. return ino == EXT4_ROOT_INO ||
  1392. ino == EXT4_USR_QUOTA_INO ||
  1393. ino == EXT4_GRP_QUOTA_INO ||
  1394. ino == EXT4_BOOT_LOADER_INO ||
  1395. ino == EXT4_JOURNAL_INO ||
  1396. ino == EXT4_RESIZE_INO ||
  1397. (ino >= EXT4_FIRST_INO(sb) &&
  1398. ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count));
  1399. }
  1400. /*
  1401. * Inode dynamic state flags
  1402. */
  1403. enum {
  1404. EXT4_STATE_JDATA, /* journaled data exists */
  1405. EXT4_STATE_NEW, /* inode is newly created */
  1406. EXT4_STATE_XATTR, /* has in-inode xattrs */
  1407. EXT4_STATE_NO_EXPAND, /* No space for expansion */
  1408. EXT4_STATE_DA_ALLOC_CLOSE, /* Alloc DA blks on close */
  1409. EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */
  1410. EXT4_STATE_DIO_UNWRITTEN, /* need convert on dio done*/
  1411. EXT4_STATE_NEWENTRY, /* File just added to dir */
  1412. EXT4_STATE_DIOREAD_LOCK, /* Disable support for dio read
  1413. nolocking */
  1414. EXT4_STATE_MAY_INLINE_DATA, /* may have in-inode data */
  1415. EXT4_STATE_EXT_PRECACHED, /* extents have been precached */
  1416. };
  1417. #define EXT4_INODE_BIT_FNS(name, field, offset) \
  1418. static inline int ext4_test_inode_##name(struct inode *inode, int bit) \
  1419. { \
  1420. return test_bit(bit + (offset), &EXT4_I(inode)->i_##field); \
  1421. } \
  1422. static inline void ext4_set_inode_##name(struct inode *inode, int bit) \
  1423. { \
  1424. set_bit(bit + (offset), &EXT4_I(inode)->i_##field); \
  1425. } \
  1426. static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \
  1427. { \
  1428. clear_bit(bit + (offset), &EXT4_I(inode)->i_##field); \
  1429. }
  1430. /* Add these declarations here only so that these functions can be
  1431. * found by name. Otherwise, they are very hard to locate. */
  1432. static inline int ext4_test_inode_flag(struct inode *inode, int bit);
  1433. static inline void ext4_set_inode_flag(struct inode *inode, int bit);
  1434. static inline void ext4_clear_inode_flag(struct inode *inode, int bit);
  1435. EXT4_INODE_BIT_FNS(flag, flags, 0)
  1436. /* Add these declarations here only so that these functions can be
  1437. * found by name. Otherwise, they are very hard to locate. */
  1438. static inline int ext4_test_inode_state(struct inode *inode, int bit);
  1439. static inline void ext4_set_inode_state(struct inode *inode, int bit);
  1440. static inline void ext4_clear_inode_state(struct inode *inode, int bit);
  1441. #if (BITS_PER_LONG < 64)
  1442. EXT4_INODE_BIT_FNS(state, state_flags, 0)
  1443. static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
  1444. {
  1445. (ei)->i_state_flags = 0;
  1446. }
  1447. #else
  1448. EXT4_INODE_BIT_FNS(state, flags, 32)
  1449. static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
  1450. {
  1451. /* We depend on the fact that callers will set i_flags */
  1452. }
  1453. #endif
  1454. #else
  1455. /* Assume that user mode programs are passing in an ext4fs superblock, not
  1456. * a kernel struct super_block. This will allow us to call the feature-test
  1457. * macros from user land. */
  1458. #define EXT4_SB(sb) (sb)
  1459. #endif
  1460. /*
  1461. * Returns true if the inode is inode is encrypted
  1462. */
  1463. static inline int ext4_encrypted_inode(struct inode *inode)
  1464. {
  1465. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  1466. return ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT);
  1467. #else
  1468. return 0;
  1469. #endif
  1470. }
  1471. #define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime
  1472. /*
  1473. * Codes for operating systems
  1474. */
  1475. #define EXT4_OS_LINUX 0
  1476. #define EXT4_OS_HURD 1
  1477. #define EXT4_OS_MASIX 2
  1478. #define EXT4_OS_FREEBSD 3
  1479. #define EXT4_OS_LITES 4
  1480. /*
  1481. * Revision levels
  1482. */
  1483. #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */
  1484. #define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
  1485. #define EXT4_CURRENT_REV EXT4_GOOD_OLD_REV
  1486. #define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV
  1487. #define EXT4_GOOD_OLD_INODE_SIZE 128
  1488. /*
  1489. * Feature set definitions
  1490. */
  1491. /* Use the ext4_{has,set,clear}_feature_* helpers; these will be removed */
  1492. #define EXT4_HAS_COMPAT_FEATURE(sb,mask) \
  1493. ((EXT4_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask)) != 0)
  1494. #define EXT4_HAS_RO_COMPAT_FEATURE(sb,mask) \
  1495. ((EXT4_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask)) != 0)
  1496. #define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \
  1497. ((EXT4_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask)) != 0)
  1498. #define EXT4_SET_COMPAT_FEATURE(sb,mask) \
  1499. EXT4_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
  1500. #define EXT4_SET_RO_COMPAT_FEATURE(sb,mask) \
  1501. EXT4_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
  1502. #define EXT4_SET_INCOMPAT_FEATURE(sb,mask) \
  1503. EXT4_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
  1504. #define EXT4_CLEAR_COMPAT_FEATURE(sb,mask) \
  1505. EXT4_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
  1506. #define EXT4_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
  1507. EXT4_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
  1508. #define EXT4_CLEAR_INCOMPAT_FEATURE(sb,mask) \
  1509. EXT4_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
  1510. #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
  1511. #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
  1512. #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  1513. #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
  1514. #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
  1515. #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
  1516. #define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200
  1517. #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
  1518. #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
  1519. #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
  1520. #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
  1521. #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
  1522. #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
  1523. #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
  1524. #define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100
  1525. #define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200
  1526. /*
  1527. * METADATA_CSUM also enables group descriptor checksums (GDT_CSUM). When
  1528. * METADATA_CSUM is set, group descriptor checksums use the same algorithm as
  1529. * all other data structures' checksums. However, the METADATA_CSUM and
  1530. * GDT_CSUM bits are mutually exclusive.
  1531. */
  1532. #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
  1533. #define EXT4_FEATURE_RO_COMPAT_READONLY 0x1000
  1534. #define EXT4_FEATURE_RO_COMPAT_PROJECT 0x2000
  1535. #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
  1536. #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
  1537. #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
  1538. #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
  1539. #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
  1540. #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
  1541. #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
  1542. #define EXT4_FEATURE_INCOMPAT_MMP 0x0100
  1543. #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
  1544. #define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 /* EA in inode */
  1545. #define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 /* data in dirent */
  1546. #define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000
  1547. #define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */
  1548. #define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000 /* data in inode */
  1549. #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000
  1550. #define EXT4_FEATURE_COMPAT_FUNCS(name, flagname) \
  1551. static inline bool ext4_has_feature_##name(struct super_block *sb) \
  1552. { \
  1553. return ((EXT4_SB(sb)->s_es->s_feature_compat & \
  1554. cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname)) != 0); \
  1555. } \
  1556. static inline void ext4_set_feature_##name(struct super_block *sb) \
  1557. { \
  1558. EXT4_SB(sb)->s_es->s_feature_compat |= \
  1559. cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname); \
  1560. } \
  1561. static inline void ext4_clear_feature_##name(struct super_block *sb) \
  1562. { \
  1563. EXT4_SB(sb)->s_es->s_feature_compat &= \
  1564. ~cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname); \
  1565. }
  1566. #define EXT4_FEATURE_RO_COMPAT_FUNCS(name, flagname) \
  1567. static inline bool ext4_has_feature_##name(struct super_block *sb) \
  1568. { \
  1569. return ((EXT4_SB(sb)->s_es->s_feature_ro_compat & \
  1570. cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname)) != 0); \
  1571. } \
  1572. static inline void ext4_set_feature_##name(struct super_block *sb) \
  1573. { \
  1574. EXT4_SB(sb)->s_es->s_feature_ro_compat |= \
  1575. cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname); \
  1576. } \
  1577. static inline void ext4_clear_feature_##name(struct super_block *sb) \
  1578. { \
  1579. EXT4_SB(sb)->s_es->s_feature_ro_compat &= \
  1580. ~cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname); \
  1581. }
  1582. #define EXT4_FEATURE_INCOMPAT_FUNCS(name, flagname) \
  1583. static inline bool ext4_has_feature_##name(struct super_block *sb) \
  1584. { \
  1585. return ((EXT4_SB(sb)->s_es->s_feature_incompat & \
  1586. cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname)) != 0); \
  1587. } \
  1588. static inline void ext4_set_feature_##name(struct super_block *sb) \
  1589. { \
  1590. EXT4_SB(sb)->s_es->s_feature_incompat |= \
  1591. cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname); \
  1592. } \
  1593. static inline void ext4_clear_feature_##name(struct super_block *sb) \
  1594. { \
  1595. EXT4_SB(sb)->s_es->s_feature_incompat &= \
  1596. ~cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname); \
  1597. }
  1598. EXT4_FEATURE_COMPAT_FUNCS(dir_prealloc, DIR_PREALLOC)
  1599. EXT4_FEATURE_COMPAT_FUNCS(imagic_inodes, IMAGIC_INODES)
  1600. EXT4_FEATURE_COMPAT_FUNCS(journal, HAS_JOURNAL)
  1601. EXT4_FEATURE_COMPAT_FUNCS(xattr, EXT_ATTR)
  1602. EXT4_FEATURE_COMPAT_FUNCS(resize_inode, RESIZE_INODE)
  1603. EXT4_FEATURE_COMPAT_FUNCS(dir_index, DIR_INDEX)
  1604. EXT4_FEATURE_COMPAT_FUNCS(sparse_super2, SPARSE_SUPER2)
  1605. EXT4_FEATURE_RO_COMPAT_FUNCS(sparse_super, SPARSE_SUPER)
  1606. EXT4_FEATURE_RO_COMPAT_FUNCS(large_file, LARGE_FILE)
  1607. EXT4_FEATURE_RO_COMPAT_FUNCS(btree_dir, BTREE_DIR)
  1608. EXT4_FEATURE_RO_COMPAT_FUNCS(huge_file, HUGE_FILE)
  1609. EXT4_FEATURE_RO_COMPAT_FUNCS(gdt_csum, GDT_CSUM)
  1610. EXT4_FEATURE_RO_COMPAT_FUNCS(dir_nlink, DIR_NLINK)
  1611. EXT4_FEATURE_RO_COMPAT_FUNCS(extra_isize, EXTRA_ISIZE)
  1612. EXT4_FEATURE_RO_COMPAT_FUNCS(quota, QUOTA)
  1613. EXT4_FEATURE_RO_COMPAT_FUNCS(bigalloc, BIGALLOC)
  1614. EXT4_FEATURE_RO_COMPAT_FUNCS(metadata_csum, METADATA_CSUM)
  1615. EXT4_FEATURE_RO_COMPAT_FUNCS(readonly, READONLY)
  1616. EXT4_FEATURE_RO_COMPAT_FUNCS(project, PROJECT)
  1617. EXT4_FEATURE_INCOMPAT_FUNCS(compression, COMPRESSION)
  1618. EXT4_FEATURE_INCOMPAT_FUNCS(filetype, FILETYPE)
  1619. EXT4_FEATURE_INCOMPAT_FUNCS(journal_needs_recovery, RECOVER)
  1620. EXT4_FEATURE_INCOMPAT_FUNCS(journal_dev, JOURNAL_DEV)
  1621. EXT4_FEATURE_INCOMPAT_FUNCS(meta_bg, META_BG)
  1622. EXT4_FEATURE_INCOMPAT_FUNCS(extents, EXTENTS)
  1623. EXT4_FEATURE_INCOMPAT_FUNCS(64bit, 64BIT)
  1624. EXT4_FEATURE_INCOMPAT_FUNCS(mmp, MMP)
  1625. EXT4_FEATURE_INCOMPAT_FUNCS(flex_bg, FLEX_BG)
  1626. EXT4_FEATURE_INCOMPAT_FUNCS(ea_inode, EA_INODE)
  1627. EXT4_FEATURE_INCOMPAT_FUNCS(dirdata, DIRDATA)
  1628. EXT4_FEATURE_INCOMPAT_FUNCS(csum_seed, CSUM_SEED)
  1629. EXT4_FEATURE_INCOMPAT_FUNCS(largedir, LARGEDIR)
  1630. EXT4_FEATURE_INCOMPAT_FUNCS(inline_data, INLINE_DATA)
  1631. EXT4_FEATURE_INCOMPAT_FUNCS(encrypt, ENCRYPT)
  1632. #define EXT2_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR
  1633. #define EXT2_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \
  1634. EXT4_FEATURE_INCOMPAT_META_BG)
  1635. #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  1636. EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
  1637. EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
  1638. #define EXT3_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR
  1639. #define EXT3_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \
  1640. EXT4_FEATURE_INCOMPAT_RECOVER| \
  1641. EXT4_FEATURE_INCOMPAT_META_BG)
  1642. #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  1643. EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
  1644. EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
  1645. #define EXT4_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR
  1646. #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \
  1647. EXT4_FEATURE_INCOMPAT_RECOVER| \
  1648. EXT4_FEATURE_INCOMPAT_META_BG| \
  1649. EXT4_FEATURE_INCOMPAT_EXTENTS| \
  1650. EXT4_FEATURE_INCOMPAT_64BIT| \
  1651. EXT4_FEATURE_INCOMPAT_FLEX_BG| \
  1652. EXT4_FEATURE_INCOMPAT_MMP | \
  1653. EXT4_FEATURE_INCOMPAT_INLINE_DATA | \
  1654. EXT4_FEATURE_INCOMPAT_ENCRYPT | \
  1655. EXT4_FEATURE_INCOMPAT_CSUM_SEED)
  1656. #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  1657. EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
  1658. EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
  1659. EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
  1660. EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
  1661. EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\
  1662. EXT4_FEATURE_RO_COMPAT_HUGE_FILE |\
  1663. EXT4_FEATURE_RO_COMPAT_BIGALLOC |\
  1664. EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\
  1665. EXT4_FEATURE_RO_COMPAT_QUOTA |\
  1666. EXT4_FEATURE_RO_COMPAT_PROJECT)
  1667. #define EXTN_FEATURE_FUNCS(ver) \
  1668. static inline bool ext4_has_unknown_ext##ver##_compat_features(struct super_block *sb) \
  1669. { \
  1670. return ((EXT4_SB(sb)->s_es->s_feature_compat & \
  1671. cpu_to_le32(~EXT##ver##_FEATURE_COMPAT_SUPP)) != 0); \
  1672. } \
  1673. static inline bool ext4_has_unknown_ext##ver##_ro_compat_features(struct super_block *sb) \
  1674. { \
  1675. return ((EXT4_SB(sb)->s_es->s_feature_ro_compat & \
  1676. cpu_to_le32(~EXT##ver##_FEATURE_RO_COMPAT_SUPP)) != 0); \
  1677. } \
  1678. static inline bool ext4_has_unknown_ext##ver##_incompat_features(struct super_block *sb) \
  1679. { \
  1680. return ((EXT4_SB(sb)->s_es->s_feature_incompat & \
  1681. cpu_to_le32(~EXT##ver##_FEATURE_INCOMPAT_SUPP)) != 0); \
  1682. }
  1683. EXTN_FEATURE_FUNCS(2)
  1684. EXTN_FEATURE_FUNCS(3)
  1685. EXTN_FEATURE_FUNCS(4)
  1686. static inline bool ext4_has_compat_features(struct super_block *sb)
  1687. {
  1688. return (EXT4_SB(sb)->s_es->s_feature_compat != 0);
  1689. }
  1690. static inline bool ext4_has_ro_compat_features(struct super_block *sb)
  1691. {
  1692. return (EXT4_SB(sb)->s_es->s_feature_ro_compat != 0);
  1693. }
  1694. static inline bool ext4_has_incompat_features(struct super_block *sb)
  1695. {
  1696. return (EXT4_SB(sb)->s_es->s_feature_incompat != 0);
  1697. }
  1698. /*
  1699. * Default values for user and/or group using reserved blocks
  1700. */
  1701. #define EXT4_DEF_RESUID 0
  1702. #define EXT4_DEF_RESGID 0
  1703. /*
  1704. * Default project ID
  1705. */
  1706. #define EXT4_DEF_PROJID 0
  1707. #define EXT4_DEF_INODE_READAHEAD_BLKS 32
  1708. /*
  1709. * Default mount options
  1710. */
  1711. #define EXT4_DEFM_DEBUG 0x0001
  1712. #define EXT4_DEFM_BSDGROUPS 0x0002
  1713. #define EXT4_DEFM_XATTR_USER 0x0004
  1714. #define EXT4_DEFM_ACL 0x0008
  1715. #define EXT4_DEFM_UID16 0x0010
  1716. #define EXT4_DEFM_JMODE 0x0060
  1717. #define EXT4_DEFM_JMODE_DATA 0x0020
  1718. #define EXT4_DEFM_JMODE_ORDERED 0x0040
  1719. #define EXT4_DEFM_JMODE_WBACK 0x0060
  1720. #define EXT4_DEFM_NOBARRIER 0x0100
  1721. #define EXT4_DEFM_BLOCK_VALIDITY 0x0200
  1722. #define EXT4_DEFM_DISCARD 0x0400
  1723. #define EXT4_DEFM_NODELALLOC 0x0800
  1724. /*
  1725. * Default journal batch times
  1726. */
  1727. #define EXT4_DEF_MIN_BATCH_TIME 0
  1728. #define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */
  1729. /*
  1730. * Minimum number of groups in a flexgroup before we separate out
  1731. * directories into the first block group of a flexgroup
  1732. */
  1733. #define EXT4_FLEX_SIZE_DIR_ALLOC_SCHEME 4
  1734. /*
  1735. * Structure of a directory entry
  1736. */
  1737. #define EXT4_NAME_LEN 255
  1738. struct ext4_dir_entry {
  1739. __le32 inode; /* Inode number */
  1740. __le16 rec_len; /* Directory entry length */
  1741. __le16 name_len; /* Name length */
  1742. char name[EXT4_NAME_LEN]; /* File name */
  1743. };
  1744. /*
  1745. * The new version of the directory entry. Since EXT4 structures are
  1746. * stored in intel byte order, and the name_len field could never be
  1747. * bigger than 255 chars, it's safe to reclaim the extra byte for the
  1748. * file_type field.
  1749. */
  1750. struct ext4_dir_entry_2 {
  1751. __le32 inode; /* Inode number */
  1752. __le16 rec_len; /* Directory entry length */
  1753. __u8 name_len; /* Name length */
  1754. __u8 file_type;
  1755. char name[EXT4_NAME_LEN]; /* File name */
  1756. };
  1757. /*
  1758. * This is a bogus directory entry at the end of each leaf block that
  1759. * records checksums.
  1760. */
  1761. struct ext4_dir_entry_tail {
  1762. __le32 det_reserved_zero1; /* Pretend to be unused */
  1763. __le16 det_rec_len; /* 12 */
  1764. __u8 det_reserved_zero2; /* Zero name length */
  1765. __u8 det_reserved_ft; /* 0xDE, fake file type */
  1766. __le32 det_checksum; /* crc32c(uuid+inum+dirblock) */
  1767. };
  1768. #define EXT4_DIRENT_TAIL(block, blocksize) \
  1769. ((struct ext4_dir_entry_tail *)(((void *)(block)) + \
  1770. ((blocksize) - \
  1771. sizeof(struct ext4_dir_entry_tail))))
  1772. /*
  1773. * Ext4 directory file types. Only the low 3 bits are used. The
  1774. * other bits are reserved for now.
  1775. */
  1776. #define EXT4_FT_UNKNOWN 0
  1777. #define EXT4_FT_REG_FILE 1
  1778. #define EXT4_FT_DIR 2
  1779. #define EXT4_FT_CHRDEV 3
  1780. #define EXT4_FT_BLKDEV 4
  1781. #define EXT4_FT_FIFO 5
  1782. #define EXT4_FT_SOCK 6
  1783. #define EXT4_FT_SYMLINK 7
  1784. #define EXT4_FT_MAX 8
  1785. #define EXT4_FT_DIR_CSUM 0xDE
  1786. /*
  1787. * EXT4_DIR_PAD defines the directory entries boundaries
  1788. *
  1789. * NOTE: It must be a multiple of 4
  1790. */
  1791. #define EXT4_DIR_PAD 4
  1792. #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1)
  1793. #define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \
  1794. ~EXT4_DIR_ROUND)
  1795. #define EXT4_MAX_REC_LEN ((1<<16)-1)
  1796. /*
  1797. * If we ever get support for fs block sizes > page_size, we'll need
  1798. * to remove the #if statements in the next two functions...
  1799. */
  1800. static inline unsigned int
  1801. ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize)
  1802. {
  1803. unsigned len = le16_to_cpu(dlen);
  1804. #if (PAGE_SIZE >= 65536)
  1805. if (len == EXT4_MAX_REC_LEN || len == 0)
  1806. return blocksize;
  1807. return (len & 65532) | ((len & 3) << 16);
  1808. #else
  1809. return len;
  1810. #endif
  1811. }
  1812. static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize)
  1813. {
  1814. if ((len > blocksize) || (blocksize > (1 << 18)) || (len & 3))
  1815. BUG();
  1816. #if (PAGE_SIZE >= 65536)
  1817. if (len < 65536)
  1818. return cpu_to_le16(len);
  1819. if (len == blocksize) {
  1820. if (blocksize == 65536)
  1821. return cpu_to_le16(EXT4_MAX_REC_LEN);
  1822. else
  1823. return cpu_to_le16(0);
  1824. }
  1825. return cpu_to_le16((len & 65532) | ((len >> 16) & 3));
  1826. #else
  1827. return cpu_to_le16(len);
  1828. #endif
  1829. }
  1830. /*
  1831. * Hash Tree Directory indexing
  1832. * (c) Daniel Phillips, 2001
  1833. */
  1834. #define is_dx(dir) (ext4_has_feature_dir_index((dir)->i_sb) && \
  1835. ext4_test_inode_flag((dir), EXT4_INODE_INDEX))
  1836. #define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX)
  1837. #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
  1838. /* Legal values for the dx_root hash_version field: */
  1839. #define DX_HASH_LEGACY 0
  1840. #define DX_HASH_HALF_MD4 1
  1841. #define DX_HASH_TEA 2
  1842. #define DX_HASH_LEGACY_UNSIGNED 3
  1843. #define DX_HASH_HALF_MD4_UNSIGNED 4
  1844. #define DX_HASH_TEA_UNSIGNED 5
  1845. static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
  1846. const void *address, unsigned int length)
  1847. {
  1848. struct {
  1849. struct shash_desc shash;
  1850. char ctx[4];
  1851. } desc;
  1852. int err;
  1853. BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx));
  1854. desc.shash.tfm = sbi->s_chksum_driver;
  1855. desc.shash.flags = 0;
  1856. *(u32 *)desc.ctx = crc;
  1857. err = crypto_shash_update(&desc.shash, address, length);
  1858. BUG_ON(err);
  1859. return *(u32 *)desc.ctx;
  1860. }
  1861. #ifdef __KERNEL__
  1862. /* hash info structure used by the directory hash */
  1863. struct dx_hash_info
  1864. {
  1865. u32 hash;
  1866. u32 minor_hash;
  1867. int hash_version;
  1868. u32 *seed;
  1869. };
  1870. /* 32 and 64 bit signed EOF for dx directories */
  1871. #define EXT4_HTREE_EOF_32BIT ((1UL << (32 - 1)) - 1)
  1872. #define EXT4_HTREE_EOF_64BIT ((1ULL << (64 - 1)) - 1)
  1873. /*
  1874. * Control parameters used by ext4_htree_next_block
  1875. */
  1876. #define HASH_NB_ALWAYS 1
  1877. struct ext4_filename {
  1878. const struct qstr *usr_fname;
  1879. struct ext4_str disk_name;
  1880. struct dx_hash_info hinfo;
  1881. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  1882. struct ext4_str crypto_buf;
  1883. #endif
  1884. };
  1885. #define fname_name(p) ((p)->disk_name.name)
  1886. #define fname_len(p) ((p)->disk_name.len)
  1887. /*
  1888. * Describe an inode's exact location on disk and in memory
  1889. */
  1890. struct ext4_iloc
  1891. {
  1892. struct buffer_head *bh;
  1893. unsigned long offset;
  1894. ext4_group_t block_group;
  1895. };
  1896. static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc)
  1897. {
  1898. return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset);
  1899. }
  1900. /*
  1901. * This structure is stuffed into the struct file's private_data field
  1902. * for directories. It is where we put information so that we can do
  1903. * readdir operations in hash tree order.
  1904. */
  1905. struct dir_private_info {
  1906. struct rb_root root;
  1907. struct rb_node *curr_node;
  1908. struct fname *extra_fname;
  1909. loff_t last_pos;
  1910. __u32 curr_hash;
  1911. __u32 curr_minor_hash;
  1912. __u32 next_hash;
  1913. };
  1914. /* calculate the first block number of the group */
  1915. static inline ext4_fsblk_t
  1916. ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no)
  1917. {
  1918. return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) +
  1919. le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
  1920. }
  1921. /*
  1922. * Special error return code only used by dx_probe() and its callers.
  1923. */
  1924. #define ERR_BAD_DX_DIR (-(MAX_ERRNO - 1))
  1925. /*
  1926. * Timeout and state flag for lazy initialization inode thread.
  1927. */
  1928. #define EXT4_DEF_LI_WAIT_MULT 10
  1929. #define EXT4_DEF_LI_MAX_START_DELAY 5
  1930. #define EXT4_LAZYINIT_QUIT 0x0001
  1931. #define EXT4_LAZYINIT_RUNNING 0x0002
  1932. /*
  1933. * Lazy inode table initialization info
  1934. */
  1935. struct ext4_lazy_init {
  1936. unsigned long li_state;
  1937. struct list_head li_request_list;
  1938. struct mutex li_list_mtx;
  1939. };
  1940. struct ext4_li_request {
  1941. struct super_block *lr_super;
  1942. struct ext4_sb_info *lr_sbi;
  1943. ext4_group_t lr_next_group;
  1944. struct list_head lr_request;
  1945. unsigned long lr_next_sched;
  1946. unsigned long lr_timeout;
  1947. };
  1948. struct ext4_features {
  1949. struct kobject f_kobj;
  1950. struct completion f_kobj_unregister;
  1951. };
  1952. /*
  1953. * This structure will be used for multiple mount protection. It will be
  1954. * written into the block number saved in the s_mmp_block field in the
  1955. * superblock. Programs that check MMP should assume that if
  1956. * SEQ_FSCK (or any unknown code above SEQ_MAX) is present then it is NOT safe
  1957. * to use the filesystem, regardless of how old the timestamp is.
  1958. */
  1959. #define EXT4_MMP_MAGIC 0x004D4D50U /* ASCII for MMP */
  1960. #define EXT4_MMP_SEQ_CLEAN 0xFF4D4D50U /* mmp_seq value for clean unmount */
  1961. #define EXT4_MMP_SEQ_FSCK 0xE24D4D50U /* mmp_seq value when being fscked */
  1962. #define EXT4_MMP_SEQ_MAX 0xE24D4D4FU /* maximum valid mmp_seq value */
  1963. struct mmp_struct {
  1964. __le32 mmp_magic; /* Magic number for MMP */
  1965. __le32 mmp_seq; /* Sequence no. updated periodically */
  1966. /*
  1967. * mmp_time, mmp_nodename & mmp_bdevname are only used for information
  1968. * purposes and do not affect the correctness of the algorithm
  1969. */
  1970. __le64 mmp_time; /* Time last updated */
  1971. char mmp_nodename[64]; /* Node which last updated MMP block */
  1972. char mmp_bdevname[32]; /* Bdev which last updated MMP block */
  1973. /*
  1974. * mmp_check_interval is used to verify if the MMP block has been
  1975. * updated on the block device. The value is updated based on the
  1976. * maximum time to write the MMP block during an update cycle.
  1977. */
  1978. __le16 mmp_check_interval;
  1979. __le16 mmp_pad1;
  1980. __le32 mmp_pad2[226];
  1981. __le32 mmp_checksum; /* crc32c(uuid+mmp_block) */
  1982. };
  1983. /* arguments passed to the mmp thread */
  1984. struct mmpd_data {
  1985. struct buffer_head *bh; /* bh from initial read_mmp_block() */
  1986. struct super_block *sb; /* super block of the fs */
  1987. };
  1988. /*
  1989. * Check interval multiplier
  1990. * The MMP block is written every update interval and initially checked every
  1991. * update interval x the multiplier (the value is then adapted based on the
  1992. * write latency). The reason is that writes can be delayed under load and we
  1993. * don't want readers to incorrectly assume that the filesystem is no longer
  1994. * in use.
  1995. */
  1996. #define EXT4_MMP_CHECK_MULT 2UL
  1997. /*
  1998. * Minimum interval for MMP checking in seconds.
  1999. */
  2000. #define EXT4_MMP_MIN_CHECK_INTERVAL 5UL
  2001. /*
  2002. * Maximum interval for MMP checking in seconds.
  2003. */
  2004. #define EXT4_MMP_MAX_CHECK_INTERVAL 300UL
  2005. /*
  2006. * Function prototypes
  2007. */
  2008. /*
  2009. * Ok, these declarations are also in <linux/kernel.h> but none of the
  2010. * ext4 source programs needs to include it so they are duplicated here.
  2011. */
  2012. # define NORET_TYPE /**/
  2013. # define ATTRIB_NORET __attribute__((noreturn))
  2014. # define NORET_AND noreturn,
  2015. /* bitmap.c */
  2016. extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
  2017. void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
  2018. struct ext4_group_desc *gdp,
  2019. struct buffer_head *bh, int sz);
  2020. int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
  2021. struct ext4_group_desc *gdp,
  2022. struct buffer_head *bh, int sz);
  2023. void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
  2024. struct ext4_group_desc *gdp,
  2025. struct buffer_head *bh);
  2026. int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
  2027. struct ext4_group_desc *gdp,
  2028. struct buffer_head *bh);
  2029. /* balloc.c */
  2030. extern void ext4_get_group_no_and_offset(struct super_block *sb,
  2031. ext4_fsblk_t blocknr,
  2032. ext4_group_t *blockgrpp,
  2033. ext4_grpblk_t *offsetp);
  2034. extern ext4_group_t ext4_get_group_number(struct super_block *sb,
  2035. ext4_fsblk_t block);
  2036. extern unsigned int ext4_block_group(struct super_block *sb,
  2037. ext4_fsblk_t blocknr);
  2038. extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb,
  2039. ext4_fsblk_t blocknr);
  2040. extern int ext4_bg_has_super(struct super_block *sb, ext4_group_t group);
  2041. extern unsigned long ext4_bg_num_gdb(struct super_block *sb,
  2042. ext4_group_t group);
  2043. extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
  2044. ext4_fsblk_t goal,
  2045. unsigned int flags,
  2046. unsigned long *count,
  2047. int *errp);
  2048. extern int ext4_claim_free_clusters(struct ext4_sb_info *sbi,
  2049. s64 nclusters, unsigned int flags);
  2050. extern ext4_fsblk_t ext4_count_free_clusters(struct super_block *);
  2051. extern void ext4_check_blocks_bitmap(struct super_block *);
  2052. extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
  2053. ext4_group_t block_group,
  2054. struct buffer_head ** bh);
  2055. extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
  2056. extern struct buffer_head *ext4_read_block_bitmap_nowait(struct super_block *sb,
  2057. ext4_group_t block_group);
  2058. extern int ext4_wait_block_bitmap(struct super_block *sb,
  2059. ext4_group_t block_group,
  2060. struct buffer_head *bh);
  2061. extern struct buffer_head *ext4_read_block_bitmap(struct super_block *sb,
  2062. ext4_group_t block_group);
  2063. extern unsigned ext4_free_clusters_after_init(struct super_block *sb,
  2064. ext4_group_t block_group,
  2065. struct ext4_group_desc *gdp);
  2066. ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
  2067. /* crypto_policy.c */
  2068. int ext4_is_child_context_consistent_with_parent(struct inode *parent,
  2069. struct inode *child);
  2070. int ext4_inherit_context(struct inode *parent, struct inode *child);
  2071. void ext4_to_hex(char *dst, char *src, size_t src_size);
  2072. int ext4_process_policy(const struct ext4_encryption_policy *policy,
  2073. struct inode *inode);
  2074. int ext4_get_policy(struct inode *inode,
  2075. struct ext4_encryption_policy *policy);
  2076. /* crypto.c */
  2077. extern struct kmem_cache *ext4_crypt_info_cachep;
  2078. bool ext4_valid_contents_enc_mode(uint32_t mode);
  2079. uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size);
  2080. extern struct workqueue_struct *ext4_read_workqueue;
  2081. struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode,
  2082. gfp_t gfp_flags);
  2083. void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx);
  2084. void ext4_restore_control_page(struct page *data_page);
  2085. struct page *ext4_encrypt(struct inode *inode,
  2086. struct page *plaintext_page,
  2087. gfp_t gfp_flags);
  2088. int ext4_decrypt(struct page *page);
  2089. int ext4_encrypted_zeroout(struct inode *inode, ext4_lblk_t lblk,
  2090. ext4_fsblk_t pblk, ext4_lblk_t len);
  2091. extern const struct dentry_operations ext4_encrypted_d_ops;
  2092. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  2093. int ext4_init_crypto(void);
  2094. void ext4_exit_crypto(void);
  2095. static inline int ext4_sb_has_crypto(struct super_block *sb)
  2096. {
  2097. return ext4_has_feature_encrypt(sb);
  2098. }
  2099. #else
  2100. static inline int ext4_init_crypto(void) { return 0; }
  2101. static inline void ext4_exit_crypto(void) { }
  2102. static inline int ext4_sb_has_crypto(struct super_block *sb)
  2103. {
  2104. return 0;
  2105. }
  2106. #endif
  2107. /* crypto_fname.c */
  2108. bool ext4_valid_filenames_enc_mode(uint32_t mode);
  2109. u32 ext4_fname_crypto_round_up(u32 size, u32 blksize);
  2110. unsigned ext4_fname_encrypted_size(struct inode *inode, u32 ilen);
  2111. int ext4_fname_crypto_alloc_buffer(struct inode *inode,
  2112. u32 ilen, struct ext4_str *crypto_str);
  2113. int _ext4_fname_disk_to_usr(struct inode *inode,
  2114. struct dx_hash_info *hinfo,
  2115. const struct ext4_str *iname,
  2116. struct ext4_str *oname);
  2117. int ext4_fname_disk_to_usr(struct inode *inode,
  2118. struct dx_hash_info *hinfo,
  2119. const struct ext4_dir_entry_2 *de,
  2120. struct ext4_str *oname);
  2121. int ext4_fname_usr_to_disk(struct inode *inode,
  2122. const struct qstr *iname,
  2123. struct ext4_str *oname);
  2124. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  2125. void ext4_fname_crypto_free_buffer(struct ext4_str *crypto_str);
  2126. int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname,
  2127. int lookup, struct ext4_filename *fname);
  2128. void ext4_fname_free_filename(struct ext4_filename *fname);
  2129. #else
  2130. static inline
  2131. int ext4_setup_fname_crypto(struct inode *inode)
  2132. {
  2133. return 0;
  2134. }
  2135. static inline void ext4_fname_crypto_free_buffer(struct ext4_str *p) { }
  2136. static inline int ext4_fname_setup_filename(struct inode *dir,
  2137. const struct qstr *iname,
  2138. int lookup, struct ext4_filename *fname)
  2139. {
  2140. fname->usr_fname = iname;
  2141. fname->disk_name.name = (unsigned char *) iname->name;
  2142. fname->disk_name.len = iname->len;
  2143. return 0;
  2144. }
  2145. static inline void ext4_fname_free_filename(struct ext4_filename *fname) { }
  2146. #endif
  2147. /* crypto_key.c */
  2148. void ext4_free_crypt_info(struct ext4_crypt_info *ci);
  2149. void ext4_free_encryption_info(struct inode *inode, struct ext4_crypt_info *ci);
  2150. int _ext4_get_encryption_info(struct inode *inode);
  2151. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  2152. int ext4_has_encryption_key(struct inode *inode);
  2153. static inline int ext4_get_encryption_info(struct inode *inode)
  2154. {
  2155. struct ext4_crypt_info *ci = EXT4_I(inode)->i_crypt_info;
  2156. if (!ci ||
  2157. (ci->ci_keyring_key &&
  2158. (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) |
  2159. (1 << KEY_FLAG_REVOKED) |
  2160. (1 << KEY_FLAG_DEAD)))))
  2161. return _ext4_get_encryption_info(inode);
  2162. return 0;
  2163. }
  2164. static inline struct ext4_crypt_info *ext4_encryption_info(struct inode *inode)
  2165. {
  2166. return EXT4_I(inode)->i_crypt_info;
  2167. }
  2168. #else
  2169. static inline int ext4_has_encryption_key(struct inode *inode)
  2170. {
  2171. return 0;
  2172. }
  2173. static inline int ext4_get_encryption_info(struct inode *inode)
  2174. {
  2175. return 0;
  2176. }
  2177. static inline struct ext4_crypt_info *ext4_encryption_info(struct inode *inode)
  2178. {
  2179. return NULL;
  2180. }
  2181. #endif
  2182. /* dir.c */
  2183. extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *,
  2184. struct file *,
  2185. struct ext4_dir_entry_2 *,
  2186. struct buffer_head *, char *, int,
  2187. unsigned int);
  2188. #define ext4_check_dir_entry(dir, filp, de, bh, buf, size, offset) \
  2189. unlikely(__ext4_check_dir_entry(__func__, __LINE__, (dir), (filp), \
  2190. (de), (bh), (buf), (size), (offset)))
  2191. extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
  2192. __u32 minor_hash,
  2193. struct ext4_dir_entry_2 *dirent,
  2194. struct ext4_str *ent_name);
  2195. extern void ext4_htree_free_dir_info(struct dir_private_info *p);
  2196. extern int ext4_find_dest_de(struct inode *dir, struct inode *inode,
  2197. struct buffer_head *bh,
  2198. void *buf, int buf_size,
  2199. struct ext4_filename *fname,
  2200. struct ext4_dir_entry_2 **dest_de);
  2201. int ext4_insert_dentry(struct inode *dir,
  2202. struct inode *inode,
  2203. struct ext4_dir_entry_2 *de,
  2204. int buf_size,
  2205. struct ext4_filename *fname);
  2206. static inline void ext4_update_dx_flag(struct inode *inode)
  2207. {
  2208. if (!ext4_has_feature_dir_index(inode->i_sb))
  2209. ext4_clear_inode_flag(inode, EXT4_INODE_INDEX);
  2210. }
  2211. static unsigned char ext4_filetype_table[] = {
  2212. DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
  2213. };
  2214. static inline unsigned char get_dtype(struct super_block *sb, int filetype)
  2215. {
  2216. if (!ext4_has_feature_filetype(sb) || filetype >= EXT4_FT_MAX)
  2217. return DT_UNKNOWN;
  2218. return ext4_filetype_table[filetype];
  2219. }
  2220. extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh,
  2221. void *buf, int buf_size);
  2222. /* fsync.c */
  2223. extern int ext4_sync_file(struct file *, loff_t, loff_t, int);
  2224. /* hash.c */
  2225. extern int ext4fs_dirhash(const char *name, int len, struct
  2226. dx_hash_info *hinfo);
  2227. /* ialloc.c */
  2228. extern struct inode *__ext4_new_inode(handle_t *, struct inode *, umode_t,
  2229. const struct qstr *qstr, __u32 goal,
  2230. uid_t *owner, int handle_type,
  2231. unsigned int line_no, int nblocks);
  2232. #define ext4_new_inode(handle, dir, mode, qstr, goal, owner) \
  2233. __ext4_new_inode((handle), (dir), (mode), (qstr), (goal), (owner), \
  2234. 0, 0, 0)
  2235. #define ext4_new_inode_start_handle(dir, mode, qstr, goal, owner, \
  2236. type, nblocks) \
  2237. __ext4_new_inode(NULL, (dir), (mode), (qstr), (goal), (owner), \
  2238. (type), __LINE__, (nblocks))
  2239. extern void ext4_free_inode(handle_t *, struct inode *);
  2240. extern struct inode * ext4_orphan_get(struct super_block *, unsigned long);
  2241. extern unsigned long ext4_count_free_inodes(struct super_block *);
  2242. extern unsigned long ext4_count_dirs(struct super_block *);
  2243. extern void ext4_check_inodes_bitmap(struct super_block *);
  2244. extern void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap);
  2245. extern int ext4_init_inode_table(struct super_block *sb,
  2246. ext4_group_t group, int barrier);
  2247. extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);
  2248. /* mballoc.c */
  2249. extern const struct file_operations ext4_seq_mb_groups_fops;
  2250. extern long ext4_mb_stats;
  2251. extern long ext4_mb_max_to_scan;
  2252. extern int ext4_mb_init(struct super_block *);
  2253. extern int ext4_mb_release(struct super_block *);
  2254. extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
  2255. struct ext4_allocation_request *, int *);
  2256. extern int ext4_mb_reserve_blocks(struct super_block *, int);
  2257. extern void ext4_discard_preallocations(struct inode *);
  2258. extern int __init ext4_init_mballoc(void);
  2259. extern void ext4_exit_mballoc(void);
  2260. extern void ext4_free_blocks(handle_t *handle, struct inode *inode,
  2261. struct buffer_head *bh, ext4_fsblk_t block,
  2262. unsigned long count, int flags);
  2263. extern int ext4_mb_alloc_groupinfo(struct super_block *sb,
  2264. ext4_group_t ngroups);
  2265. extern int ext4_mb_add_groupinfo(struct super_block *sb,
  2266. ext4_group_t i, struct ext4_group_desc *desc);
  2267. extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
  2268. ext4_fsblk_t block, unsigned long count);
  2269. extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
  2270. /* inode.c */
  2271. int ext4_inode_is_fast_symlink(struct inode *inode);
  2272. struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int);
  2273. struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int);
  2274. int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
  2275. struct buffer_head *bh_result, int create);
  2276. int ext4_dax_get_block(struct inode *inode, sector_t iblock,
  2277. struct buffer_head *bh_result, int create);
  2278. int ext4_get_block(struct inode *inode, sector_t iblock,
  2279. struct buffer_head *bh_result, int create);
  2280. int ext4_dio_get_block(struct inode *inode, sector_t iblock,
  2281. struct buffer_head *bh_result, int create);
  2282. int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
  2283. struct buffer_head *bh, int create);
  2284. int ext4_walk_page_buffers(handle_t *handle,
  2285. struct buffer_head *head,
  2286. unsigned from,
  2287. unsigned to,
  2288. int *partial,
  2289. int (*fn)(handle_t *handle,
  2290. struct buffer_head *bh));
  2291. int do_journal_get_write_access(handle_t *handle,
  2292. struct buffer_head *bh);
  2293. #define FALL_BACK_TO_NONDELALLOC 1
  2294. #define CONVERT_INLINE_DATA 2
  2295. extern struct inode *ext4_iget(struct super_block *, unsigned long);
  2296. extern struct inode *ext4_iget_normal(struct super_block *, unsigned long);
  2297. extern int ext4_write_inode(struct inode *, struct writeback_control *);
  2298. extern int ext4_setattr(struct dentry *, struct iattr *);
  2299. extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
  2300. struct kstat *stat);
  2301. extern void ext4_evict_inode(struct inode *);
  2302. extern void ext4_clear_inode(struct inode *);
  2303. extern int ext4_sync_inode(handle_t *, struct inode *);
  2304. extern void ext4_dirty_inode(struct inode *, int);
  2305. extern int ext4_change_inode_journal_flag(struct inode *, int);
  2306. extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
  2307. extern int ext4_inode_attach_jinode(struct inode *inode);
  2308. extern int ext4_can_truncate(struct inode *inode);
  2309. extern void ext4_truncate(struct inode *);
  2310. extern int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length);
  2311. extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);
  2312. extern void ext4_set_inode_flags(struct inode *);
  2313. extern void ext4_get_inode_flags(struct ext4_inode_info *);
  2314. extern int ext4_alloc_da_blocks(struct inode *inode);
  2315. extern void ext4_set_aops(struct inode *inode);
  2316. extern int ext4_writepage_trans_blocks(struct inode *);
  2317. extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
  2318. extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
  2319. loff_t lstart, loff_t lend);
  2320. extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
  2321. extern int ext4_filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  2322. extern qsize_t *ext4_get_reserved_space(struct inode *inode);
  2323. extern int ext4_get_projid(struct inode *inode, kprojid_t *projid);
  2324. extern void ext4_da_update_reserve_space(struct inode *inode,
  2325. int used, int quota_claim);
  2326. extern int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk,
  2327. ext4_fsblk_t pblk, ext4_lblk_t len);
  2328. extern int ext4_get_next_extent(struct inode *inode, ext4_lblk_t lblk,
  2329. unsigned int map_len,
  2330. struct extent_status *result);
  2331. /* indirect.c */
  2332. extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
  2333. struct ext4_map_blocks *map, int flags);
  2334. extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock);
  2335. extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks);
  2336. extern void ext4_ind_truncate(handle_t *, struct inode *inode);
  2337. extern int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
  2338. ext4_lblk_t start, ext4_lblk_t end);
  2339. /* ioctl.c */
  2340. extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
  2341. extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long);
  2342. /* migrate.c */
  2343. extern int ext4_ext_migrate(struct inode *);
  2344. extern int ext4_ind_migrate(struct inode *inode);
  2345. /* namei.c */
  2346. extern int ext4_dirent_csum_verify(struct inode *inode,
  2347. struct ext4_dir_entry *dirent);
  2348. extern int ext4_orphan_add(handle_t *, struct inode *);
  2349. extern int ext4_orphan_del(handle_t *, struct inode *);
  2350. extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
  2351. __u32 start_minor_hash, __u32 *next_hash);
  2352. extern int ext4_search_dir(struct buffer_head *bh,
  2353. char *search_buf,
  2354. int buf_size,
  2355. struct inode *dir,
  2356. struct ext4_filename *fname,
  2357. const struct qstr *d_name,
  2358. unsigned int offset,
  2359. struct ext4_dir_entry_2 **res_dir);
  2360. extern int ext4_generic_delete_entry(handle_t *handle,
  2361. struct inode *dir,
  2362. struct ext4_dir_entry_2 *de_del,
  2363. struct buffer_head *bh,
  2364. void *entry_buf,
  2365. int buf_size,
  2366. int csum_size);
  2367. extern int ext4_empty_dir(struct inode *inode);
  2368. /* resize.c */
  2369. extern int ext4_group_add(struct super_block *sb,
  2370. struct ext4_new_group_data *input);
  2371. extern int ext4_group_extend(struct super_block *sb,
  2372. struct ext4_super_block *es,
  2373. ext4_fsblk_t n_blocks_count);
  2374. extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count);
  2375. /* super.c */
  2376. extern int ext4_seq_options_show(struct seq_file *seq, void *offset);
  2377. extern int ext4_calculate_overhead(struct super_block *sb);
  2378. extern void ext4_superblock_csum_set(struct super_block *sb);
  2379. extern void *ext4_kvmalloc(size_t size, gfp_t flags);
  2380. extern void *ext4_kvzalloc(size_t size, gfp_t flags);
  2381. extern int ext4_alloc_flex_bg_array(struct super_block *sb,
  2382. ext4_group_t ngroup);
  2383. extern const char *ext4_decode_error(struct super_block *sb, int errno,
  2384. char nbuf[16]);
  2385. extern __printf(4, 5)
  2386. void __ext4_error(struct super_block *, const char *, unsigned int,
  2387. const char *, ...);
  2388. extern __printf(5, 6)
  2389. void __ext4_error_inode(struct inode *, const char *, unsigned int, ext4_fsblk_t,
  2390. const char *, ...);
  2391. extern __printf(5, 6)
  2392. void __ext4_error_file(struct file *, const char *, unsigned int, ext4_fsblk_t,
  2393. const char *, ...);
  2394. extern void __ext4_std_error(struct super_block *, const char *,
  2395. unsigned int, int);
  2396. extern __printf(4, 5)
  2397. void __ext4_abort(struct super_block *, const char *, unsigned int,
  2398. const char *, ...);
  2399. extern __printf(4, 5)
  2400. void __ext4_warning(struct super_block *, const char *, unsigned int,
  2401. const char *, ...);
  2402. extern __printf(4, 5)
  2403. void __ext4_warning_inode(const struct inode *inode, const char *function,
  2404. unsigned int line, const char *fmt, ...);
  2405. extern __printf(3, 4)
  2406. void __ext4_msg(struct super_block *, const char *, const char *, ...);
  2407. extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp,
  2408. const char *, unsigned int, const char *);
  2409. extern __printf(7, 8)
  2410. void __ext4_grp_locked_error(const char *, unsigned int,
  2411. struct super_block *, ext4_group_t,
  2412. unsigned long, ext4_fsblk_t,
  2413. const char *, ...);
  2414. #define EXT4_ERROR_INODE(inode, fmt, a...) \
  2415. ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a)
  2416. #define EXT4_ERROR_INODE_BLOCK(inode, block, fmt, a...) \
  2417. ext4_error_inode((inode), __func__, __LINE__, (block), (fmt), ## a)
  2418. #define EXT4_ERROR_FILE(file, block, fmt, a...) \
  2419. ext4_error_file((file), __func__, __LINE__, (block), (fmt), ## a)
  2420. #ifdef CONFIG_PRINTK
  2421. #define ext4_error_inode(inode, func, line, block, fmt, ...) \
  2422. __ext4_error_inode(inode, func, line, block, fmt, ##__VA_ARGS__)
  2423. #define ext4_error_file(file, func, line, block, fmt, ...) \
  2424. __ext4_error_file(file, func, line, block, fmt, ##__VA_ARGS__)
  2425. #define ext4_error(sb, fmt, ...) \
  2426. __ext4_error(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
  2427. #define ext4_abort(sb, fmt, ...) \
  2428. __ext4_abort(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
  2429. #define ext4_warning(sb, fmt, ...) \
  2430. __ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__)
  2431. #define ext4_warning_inode(inode, fmt, ...) \
  2432. __ext4_warning_inode(inode, __func__, __LINE__, fmt, ##__VA_ARGS__)
  2433. #define ext4_msg(sb, level, fmt, ...) \
  2434. __ext4_msg(sb, level, fmt, ##__VA_ARGS__)
  2435. #define dump_mmp_msg(sb, mmp, msg) \
  2436. __dump_mmp_msg(sb, mmp, __func__, __LINE__, msg)
  2437. #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \
  2438. __ext4_grp_locked_error(__func__, __LINE__, sb, grp, ino, block, \
  2439. fmt, ##__VA_ARGS__)
  2440. #else
  2441. #define ext4_error_inode(inode, func, line, block, fmt, ...) \
  2442. do { \
  2443. no_printk(fmt, ##__VA_ARGS__); \
  2444. __ext4_error_inode(inode, "", 0, block, " "); \
  2445. } while (0)
  2446. #define ext4_error_file(file, func, line, block, fmt, ...) \
  2447. do { \
  2448. no_printk(fmt, ##__VA_ARGS__); \
  2449. __ext4_error_file(file, "", 0, block, " "); \
  2450. } while (0)
  2451. #define ext4_error(sb, fmt, ...) \
  2452. do { \
  2453. no_printk(fmt, ##__VA_ARGS__); \
  2454. __ext4_error(sb, "", 0, " "); \
  2455. } while (0)
  2456. #define ext4_abort(sb, fmt, ...) \
  2457. do { \
  2458. no_printk(fmt, ##__VA_ARGS__); \
  2459. __ext4_abort(sb, "", 0, " "); \
  2460. } while (0)
  2461. #define ext4_warning(sb, fmt, ...) \
  2462. do { \
  2463. no_printk(fmt, ##__VA_ARGS__); \
  2464. __ext4_warning(sb, "", 0, " "); \
  2465. } while (0)
  2466. #define ext4_warning_inode(inode, fmt, ...) \
  2467. do { \
  2468. no_printk(fmt, ##__VA_ARGS__); \
  2469. __ext4_warning_inode(inode, "", 0, " "); \
  2470. } while (0)
  2471. #define ext4_msg(sb, level, fmt, ...) \
  2472. do { \
  2473. no_printk(fmt, ##__VA_ARGS__); \
  2474. __ext4_msg(sb, "", " "); \
  2475. } while (0)
  2476. #define dump_mmp_msg(sb, mmp, msg) \
  2477. __dump_mmp_msg(sb, mmp, "", 0, "")
  2478. #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \
  2479. do { \
  2480. no_printk(fmt, ##__VA_ARGS__); \
  2481. __ext4_grp_locked_error("", 0, sb, grp, ino, block, " "); \
  2482. } while (0)
  2483. #endif
  2484. extern void ext4_update_dynamic_rev(struct super_block *sb);
  2485. extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb,
  2486. __u32 compat);
  2487. extern int ext4_update_rocompat_feature(handle_t *handle,
  2488. struct super_block *sb, __u32 rocompat);
  2489. extern int ext4_update_incompat_feature(handle_t *handle,
  2490. struct super_block *sb, __u32 incompat);
  2491. extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
  2492. struct ext4_group_desc *bg);
  2493. extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
  2494. struct ext4_group_desc *bg);
  2495. extern ext4_fsblk_t ext4_inode_table(struct super_block *sb,
  2496. struct ext4_group_desc *bg);
  2497. extern __u32 ext4_free_group_clusters(struct super_block *sb,
  2498. struct ext4_group_desc *bg);
  2499. extern __u32 ext4_free_inodes_count(struct super_block *sb,
  2500. struct ext4_group_desc *bg);
  2501. extern __u32 ext4_used_dirs_count(struct super_block *sb,
  2502. struct ext4_group_desc *bg);
  2503. extern __u32 ext4_itable_unused_count(struct super_block *sb,
  2504. struct ext4_group_desc *bg);
  2505. extern void ext4_block_bitmap_set(struct super_block *sb,
  2506. struct ext4_group_desc *bg, ext4_fsblk_t blk);
  2507. extern void ext4_inode_bitmap_set(struct super_block *sb,
  2508. struct ext4_group_desc *bg, ext4_fsblk_t blk);
  2509. extern void ext4_inode_table_set(struct super_block *sb,
  2510. struct ext4_group_desc *bg, ext4_fsblk_t blk);
  2511. extern void ext4_free_group_clusters_set(struct super_block *sb,
  2512. struct ext4_group_desc *bg,
  2513. __u32 count);
  2514. extern void ext4_free_inodes_set(struct super_block *sb,
  2515. struct ext4_group_desc *bg, __u32 count);
  2516. extern void ext4_used_dirs_set(struct super_block *sb,
  2517. struct ext4_group_desc *bg, __u32 count);
  2518. extern void ext4_itable_unused_set(struct super_block *sb,
  2519. struct ext4_group_desc *bg, __u32 count);
  2520. extern int ext4_group_desc_csum_verify(struct super_block *sb, __u32 group,
  2521. struct ext4_group_desc *gdp);
  2522. extern void ext4_group_desc_csum_set(struct super_block *sb, __u32 group,
  2523. struct ext4_group_desc *gdp);
  2524. extern int ext4_register_li_request(struct super_block *sb,
  2525. ext4_group_t first_not_zeroed);
  2526. static inline int ext4_has_group_desc_csum(struct super_block *sb)
  2527. {
  2528. return ext4_has_feature_gdt_csum(sb) ||
  2529. EXT4_SB(sb)->s_chksum_driver != NULL;
  2530. }
  2531. static inline int ext4_has_metadata_csum(struct super_block *sb)
  2532. {
  2533. WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb) &&
  2534. !EXT4_SB(sb)->s_chksum_driver);
  2535. return (EXT4_SB(sb)->s_chksum_driver != NULL);
  2536. }
  2537. static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
  2538. {
  2539. return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
  2540. le32_to_cpu(es->s_blocks_count_lo);
  2541. }
  2542. static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es)
  2543. {
  2544. return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) |
  2545. le32_to_cpu(es->s_r_blocks_count_lo);
  2546. }
  2547. static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es)
  2548. {
  2549. return ((ext4_fsblk_t)le32_to_cpu(es->s_free_blocks_count_hi) << 32) |
  2550. le32_to_cpu(es->s_free_blocks_count_lo);
  2551. }
  2552. static inline void ext4_blocks_count_set(struct ext4_super_block *es,
  2553. ext4_fsblk_t blk)
  2554. {
  2555. es->s_blocks_count_lo = cpu_to_le32((u32)blk);
  2556. es->s_blocks_count_hi = cpu_to_le32(blk >> 32);
  2557. }
  2558. static inline void ext4_free_blocks_count_set(struct ext4_super_block *es,
  2559. ext4_fsblk_t blk)
  2560. {
  2561. es->s_free_blocks_count_lo = cpu_to_le32((u32)blk);
  2562. es->s_free_blocks_count_hi = cpu_to_le32(blk >> 32);
  2563. }
  2564. static inline void ext4_r_blocks_count_set(struct ext4_super_block *es,
  2565. ext4_fsblk_t blk)
  2566. {
  2567. es->s_r_blocks_count_lo = cpu_to_le32((u32)blk);
  2568. es->s_r_blocks_count_hi = cpu_to_le32(blk >> 32);
  2569. }
  2570. static inline loff_t ext4_isize(struct ext4_inode *raw_inode)
  2571. {
  2572. if (S_ISREG(le16_to_cpu(raw_inode->i_mode)))
  2573. return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) |
  2574. le32_to_cpu(raw_inode->i_size_lo);
  2575. else
  2576. return (loff_t) le32_to_cpu(raw_inode->i_size_lo);
  2577. }
  2578. static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size)
  2579. {
  2580. raw_inode->i_size_lo = cpu_to_le32(i_size);
  2581. raw_inode->i_size_high = cpu_to_le32(i_size >> 32);
  2582. }
  2583. static inline
  2584. struct ext4_group_info *ext4_get_group_info(struct super_block *sb,
  2585. ext4_group_t group)
  2586. {
  2587. struct ext4_group_info ***grp_info;
  2588. long indexv, indexh;
  2589. BUG_ON(group >= EXT4_SB(sb)->s_groups_count);
  2590. grp_info = EXT4_SB(sb)->s_group_info;
  2591. indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb));
  2592. indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1);
  2593. return grp_info[indexv][indexh];
  2594. }
  2595. /*
  2596. * Reading s_groups_count requires using smp_rmb() afterwards. See
  2597. * the locking protocol documented in the comments of ext4_group_add()
  2598. * in resize.c
  2599. */
  2600. static inline ext4_group_t ext4_get_groups_count(struct super_block *sb)
  2601. {
  2602. ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count;
  2603. smp_rmb();
  2604. return ngroups;
  2605. }
  2606. static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi,
  2607. ext4_group_t block_group)
  2608. {
  2609. return block_group >> sbi->s_log_groups_per_flex;
  2610. }
  2611. static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi)
  2612. {
  2613. return 1 << sbi->s_log_groups_per_flex;
  2614. }
  2615. #define ext4_std_error(sb, errno) \
  2616. do { \
  2617. if ((errno)) \
  2618. __ext4_std_error((sb), __func__, __LINE__, (errno)); \
  2619. } while (0)
  2620. #ifdef CONFIG_SMP
  2621. /* Each CPU can accumulate percpu_counter_batch clusters in their local
  2622. * counters. So we need to make sure we have free clusters more
  2623. * than percpu_counter_batch * nr_cpu_ids. Also add a window of 4 times.
  2624. */
  2625. #define EXT4_FREECLUSTERS_WATERMARK (4 * (percpu_counter_batch * nr_cpu_ids))
  2626. #else
  2627. #define EXT4_FREECLUSTERS_WATERMARK 0
  2628. #endif
  2629. /* Update i_disksize. Requires i_mutex to avoid races with truncate */
  2630. static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize)
  2631. {
  2632. WARN_ON_ONCE(S_ISREG(inode->i_mode) &&
  2633. !inode_is_locked(inode));
  2634. down_write(&EXT4_I(inode)->i_data_sem);
  2635. if (newsize > EXT4_I(inode)->i_disksize)
  2636. EXT4_I(inode)->i_disksize = newsize;
  2637. up_write(&EXT4_I(inode)->i_data_sem);
  2638. }
  2639. /* Update i_size, i_disksize. Requires i_mutex to avoid races with truncate */
  2640. static inline int ext4_update_inode_size(struct inode *inode, loff_t newsize)
  2641. {
  2642. int changed = 0;
  2643. if (newsize > inode->i_size) {
  2644. i_size_write(inode, newsize);
  2645. changed = 1;
  2646. }
  2647. if (newsize > EXT4_I(inode)->i_disksize) {
  2648. ext4_update_i_disksize(inode, newsize);
  2649. changed |= 2;
  2650. }
  2651. return changed;
  2652. }
  2653. int ext4_update_disksize_before_punch(struct inode *inode, loff_t offset,
  2654. loff_t len);
  2655. struct ext4_group_info {
  2656. unsigned long bb_state;
  2657. struct rb_root bb_free_root;
  2658. ext4_grpblk_t bb_first_free; /* first free block */
  2659. ext4_grpblk_t bb_free; /* total free blocks */
  2660. ext4_grpblk_t bb_fragments; /* nr of freespace fragments */
  2661. ext4_grpblk_t bb_largest_free_order;/* order of largest frag in BG */
  2662. struct list_head bb_prealloc_list;
  2663. #ifdef DOUBLE_CHECK
  2664. void *bb_bitmap;
  2665. #endif
  2666. struct rw_semaphore alloc_sem;
  2667. ext4_grpblk_t bb_counters[]; /* Nr of free power-of-two-block
  2668. * regions, index is order.
  2669. * bb_counters[3] = 5 means
  2670. * 5 free 8-block regions. */
  2671. };
  2672. #define EXT4_GROUP_INFO_NEED_INIT_BIT 0
  2673. #define EXT4_GROUP_INFO_WAS_TRIMMED_BIT 1
  2674. #define EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT 2
  2675. #define EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT 3
  2676. #define EXT4_MB_GRP_NEED_INIT(grp) \
  2677. (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state)))
  2678. #define EXT4_MB_GRP_BBITMAP_CORRUPT(grp) \
  2679. (test_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &((grp)->bb_state)))
  2680. #define EXT4_MB_GRP_IBITMAP_CORRUPT(grp) \
  2681. (test_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &((grp)->bb_state)))
  2682. #define EXT4_MB_GRP_WAS_TRIMMED(grp) \
  2683. (test_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
  2684. #define EXT4_MB_GRP_SET_TRIMMED(grp) \
  2685. (set_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
  2686. #define EXT4_MB_GRP_CLEAR_TRIMMED(grp) \
  2687. (clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
  2688. #define EXT4_MAX_CONTENTION 8
  2689. #define EXT4_CONTENTION_THRESHOLD 2
  2690. static inline spinlock_t *ext4_group_lock_ptr(struct super_block *sb,
  2691. ext4_group_t group)
  2692. {
  2693. return bgl_lock_ptr(EXT4_SB(sb)->s_blockgroup_lock, group);
  2694. }
  2695. /*
  2696. * Returns true if the filesystem is busy enough that attempts to
  2697. * access the block group locks has run into contention.
  2698. */
  2699. static inline int ext4_fs_is_busy(struct ext4_sb_info *sbi)
  2700. {
  2701. return (atomic_read(&sbi->s_lock_busy) > EXT4_CONTENTION_THRESHOLD);
  2702. }
  2703. static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group)
  2704. {
  2705. spinlock_t *lock = ext4_group_lock_ptr(sb, group);
  2706. if (spin_trylock(lock))
  2707. /*
  2708. * We're able to grab the lock right away, so drop the
  2709. * lock contention counter.
  2710. */
  2711. atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, -1, 0);
  2712. else {
  2713. /*
  2714. * The lock is busy, so bump the contention counter,
  2715. * and then wait on the spin lock.
  2716. */
  2717. atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, 1,
  2718. EXT4_MAX_CONTENTION);
  2719. spin_lock(lock);
  2720. }
  2721. }
  2722. static inline void ext4_unlock_group(struct super_block *sb,
  2723. ext4_group_t group)
  2724. {
  2725. spin_unlock(ext4_group_lock_ptr(sb, group));
  2726. }
  2727. /*
  2728. * Block validity checking
  2729. */
  2730. #define ext4_check_indirect_blockref(inode, bh) \
  2731. ext4_check_blockref(__func__, __LINE__, inode, \
  2732. (__le32 *)(bh)->b_data, \
  2733. EXT4_ADDR_PER_BLOCK((inode)->i_sb))
  2734. #define ext4_ind_check_inode(inode) \
  2735. ext4_check_blockref(__func__, __LINE__, inode, \
  2736. EXT4_I(inode)->i_data, \
  2737. EXT4_NDIR_BLOCKS)
  2738. /*
  2739. * Inodes and files operations
  2740. */
  2741. /* dir.c */
  2742. extern const struct file_operations ext4_dir_operations;
  2743. /* file.c */
  2744. extern const struct inode_operations ext4_file_inode_operations;
  2745. extern const struct file_operations ext4_file_operations;
  2746. extern loff_t ext4_llseek(struct file *file, loff_t offset, int origin);
  2747. /* inline.c */
  2748. extern int ext4_get_max_inline_size(struct inode *inode);
  2749. extern int ext4_find_inline_data_nolock(struct inode *inode);
  2750. extern int ext4_init_inline_data(handle_t *handle, struct inode *inode,
  2751. unsigned int len);
  2752. extern int ext4_destroy_inline_data(handle_t *handle, struct inode *inode);
  2753. extern int ext4_readpage_inline(struct inode *inode, struct page *page);
  2754. extern int ext4_try_to_write_inline_data(struct address_space *mapping,
  2755. struct inode *inode,
  2756. loff_t pos, unsigned len,
  2757. unsigned flags,
  2758. struct page **pagep);
  2759. extern int ext4_write_inline_data_end(struct inode *inode,
  2760. loff_t pos, unsigned len,
  2761. unsigned copied,
  2762. struct page *page);
  2763. extern struct buffer_head *
  2764. ext4_journalled_write_inline_data(struct inode *inode,
  2765. unsigned len,
  2766. struct page *page);
  2767. extern int ext4_da_write_inline_data_begin(struct address_space *mapping,
  2768. struct inode *inode,
  2769. loff_t pos, unsigned len,
  2770. unsigned flags,
  2771. struct page **pagep,
  2772. void **fsdata);
  2773. extern int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
  2774. unsigned len, unsigned copied,
  2775. struct page *page);
  2776. extern int ext4_try_add_inline_entry(handle_t *handle,
  2777. struct ext4_filename *fname,
  2778. struct inode *dir, struct inode *inode);
  2779. extern int ext4_try_create_inline_dir(handle_t *handle,
  2780. struct inode *parent,
  2781. struct inode *inode);
  2782. extern int ext4_read_inline_dir(struct file *filp,
  2783. struct dir_context *ctx,
  2784. int *has_inline_data);
  2785. extern int htree_inlinedir_to_tree(struct file *dir_file,
  2786. struct inode *dir, ext4_lblk_t block,
  2787. struct dx_hash_info *hinfo,
  2788. __u32 start_hash, __u32 start_minor_hash,
  2789. int *has_inline_data);
  2790. extern struct buffer_head *ext4_find_inline_entry(struct inode *dir,
  2791. struct ext4_filename *fname,
  2792. const struct qstr *d_name,
  2793. struct ext4_dir_entry_2 **res_dir,
  2794. int *has_inline_data);
  2795. extern int ext4_delete_inline_entry(handle_t *handle,
  2796. struct inode *dir,
  2797. struct ext4_dir_entry_2 *de_del,
  2798. struct buffer_head *bh,
  2799. int *has_inline_data);
  2800. extern int empty_inline_dir(struct inode *dir, int *has_inline_data);
  2801. extern struct buffer_head *ext4_get_first_inline_block(struct inode *inode,
  2802. struct ext4_dir_entry_2 **parent_de,
  2803. int *retval);
  2804. extern int ext4_inline_data_fiemap(struct inode *inode,
  2805. struct fiemap_extent_info *fieinfo,
  2806. int *has_inline, __u64 start, __u64 len);
  2807. extern int ext4_try_to_evict_inline_data(handle_t *handle,
  2808. struct inode *inode,
  2809. int needed);
  2810. extern void ext4_inline_data_truncate(struct inode *inode, int *has_inline);
  2811. extern int ext4_convert_inline_data(struct inode *inode);
  2812. static inline int ext4_has_inline_data(struct inode *inode)
  2813. {
  2814. return ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA) &&
  2815. EXT4_I(inode)->i_inline_off;
  2816. }
  2817. /* namei.c */
  2818. extern const struct inode_operations ext4_dir_inode_operations;
  2819. extern const struct inode_operations ext4_special_inode_operations;
  2820. extern struct dentry *ext4_get_parent(struct dentry *child);
  2821. extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
  2822. struct ext4_dir_entry_2 *de,
  2823. int blocksize, int csum_size,
  2824. unsigned int parent_ino, int dotdot_real_len);
  2825. extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
  2826. unsigned int blocksize);
  2827. extern int ext4_handle_dirty_dirent_node(handle_t *handle,
  2828. struct inode *inode,
  2829. struct buffer_head *bh);
  2830. #define S_SHIFT 12
  2831. static unsigned char ext4_type_by_mode[S_IFMT >> S_SHIFT] = {
  2832. [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE,
  2833. [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR,
  2834. [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV,
  2835. [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV,
  2836. [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO,
  2837. [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK,
  2838. [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK,
  2839. };
  2840. static inline void ext4_set_de_type(struct super_block *sb,
  2841. struct ext4_dir_entry_2 *de,
  2842. umode_t mode) {
  2843. if (ext4_has_feature_filetype(sb))
  2844. de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
  2845. }
  2846. /* readpages.c */
  2847. extern int ext4_mpage_readpages(struct address_space *mapping,
  2848. struct list_head *pages, struct page *page,
  2849. unsigned nr_pages);
  2850. /* symlink.c */
  2851. extern const struct inode_operations ext4_encrypted_symlink_inode_operations;
  2852. extern const struct inode_operations ext4_symlink_inode_operations;
  2853. extern const struct inode_operations ext4_fast_symlink_inode_operations;
  2854. /* sysfs.c */
  2855. extern int ext4_register_sysfs(struct super_block *sb);
  2856. extern void ext4_unregister_sysfs(struct super_block *sb);
  2857. extern int __init ext4_init_sysfs(void);
  2858. extern void ext4_exit_sysfs(void);
  2859. /* block_validity */
  2860. extern void ext4_release_system_zone(struct super_block *sb);
  2861. extern int ext4_setup_system_zone(struct super_block *sb);
  2862. extern int __init ext4_init_system_zone(void);
  2863. extern void ext4_exit_system_zone(void);
  2864. extern int ext4_data_block_valid(struct ext4_sb_info *sbi,
  2865. ext4_fsblk_t start_blk,
  2866. unsigned int count);
  2867. extern int ext4_check_blockref(const char *, unsigned int,
  2868. struct inode *, __le32 *, unsigned int);
  2869. /* extents.c */
  2870. struct ext4_ext_path;
  2871. struct ext4_extent;
  2872. /*
  2873. * Maximum number of logical blocks in a file; ext4_extent's ee_block is
  2874. * __le32.
  2875. */
  2876. #define EXT_MAX_BLOCKS 0xffffffff
  2877. extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
  2878. extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
  2879. extern int ext4_ext_index_trans_blocks(struct inode *inode, int extents);
  2880. extern int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
  2881. struct ext4_map_blocks *map, int flags);
  2882. extern void ext4_ext_truncate(handle_t *, struct inode *);
  2883. extern int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
  2884. ext4_lblk_t end);
  2885. extern void ext4_ext_init(struct super_block *);
  2886. extern void ext4_ext_release(struct super_block *);
  2887. extern long ext4_fallocate(struct file *file, int mode, loff_t offset,
  2888. loff_t len);
  2889. extern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
  2890. loff_t offset, ssize_t len);
  2891. extern int ext4_map_blocks(handle_t *handle, struct inode *inode,
  2892. struct ext4_map_blocks *map, int flags);
  2893. extern int ext4_ext_calc_metadata_amount(struct inode *inode,
  2894. ext4_lblk_t lblocks);
  2895. extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
  2896. int num,
  2897. struct ext4_ext_path *path);
  2898. extern int ext4_can_extents_be_merged(struct inode *inode,
  2899. struct ext4_extent *ex1,
  2900. struct ext4_extent *ex2);
  2901. extern int ext4_ext_insert_extent(handle_t *, struct inode *,
  2902. struct ext4_ext_path **,
  2903. struct ext4_extent *, int);
  2904. extern struct ext4_ext_path *ext4_find_extent(struct inode *, ext4_lblk_t,
  2905. struct ext4_ext_path **,
  2906. int flags);
  2907. extern void ext4_ext_drop_refs(struct ext4_ext_path *);
  2908. extern int ext4_ext_check_inode(struct inode *inode);
  2909. extern int ext4_find_delalloc_range(struct inode *inode,
  2910. ext4_lblk_t lblk_start,
  2911. ext4_lblk_t lblk_end);
  2912. extern int ext4_find_delalloc_cluster(struct inode *inode, ext4_lblk_t lblk);
  2913. extern ext4_lblk_t ext4_ext_next_allocated_block(struct ext4_ext_path *path);
  2914. extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  2915. __u64 start, __u64 len);
  2916. extern int ext4_ext_precache(struct inode *inode);
  2917. extern int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len);
  2918. extern int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len);
  2919. extern int ext4_swap_extents(handle_t *handle, struct inode *inode1,
  2920. struct inode *inode2, ext4_lblk_t lblk1,
  2921. ext4_lblk_t lblk2, ext4_lblk_t count,
  2922. int mark_unwritten,int *err);
  2923. /* move_extent.c */
  2924. extern void ext4_double_down_write_data_sem(struct inode *first,
  2925. struct inode *second);
  2926. extern void ext4_double_up_write_data_sem(struct inode *orig_inode,
  2927. struct inode *donor_inode);
  2928. extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
  2929. __u64 start_orig, __u64 start_donor,
  2930. __u64 len, __u64 *moved_len);
  2931. /* page-io.c */
  2932. extern int __init ext4_init_pageio(void);
  2933. extern void ext4_exit_pageio(void);
  2934. extern ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags);
  2935. extern ext4_io_end_t *ext4_get_io_end(ext4_io_end_t *io_end);
  2936. extern int ext4_put_io_end(ext4_io_end_t *io_end);
  2937. extern void ext4_put_io_end_defer(ext4_io_end_t *io_end);
  2938. extern void ext4_io_submit_init(struct ext4_io_submit *io,
  2939. struct writeback_control *wbc);
  2940. extern void ext4_end_io_rsv_work(struct work_struct *work);
  2941. extern void ext4_io_submit(struct ext4_io_submit *io);
  2942. extern int ext4_bio_write_page(struct ext4_io_submit *io,
  2943. struct page *page,
  2944. int len,
  2945. struct writeback_control *wbc,
  2946. bool keep_towrite);
  2947. /* mmp.c */
  2948. extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t);
  2949. /*
  2950. * Add new method to test whether block and inode bitmaps are properly
  2951. * initialized. With uninit_bg reading the block from disk is not enough
  2952. * to mark the bitmap uptodate. We need to also zero-out the bitmap
  2953. */
  2954. #define BH_BITMAP_UPTODATE BH_JBDPrivateStart
  2955. static inline int bitmap_uptodate(struct buffer_head *bh)
  2956. {
  2957. return (buffer_uptodate(bh) &&
  2958. test_bit(BH_BITMAP_UPTODATE, &(bh)->b_state));
  2959. }
  2960. static inline void set_bitmap_uptodate(struct buffer_head *bh)
  2961. {
  2962. set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state);
  2963. }
  2964. /*
  2965. * Disable DIO read nolock optimization, so new dioreaders will be forced
  2966. * to grab i_mutex
  2967. */
  2968. static inline void ext4_inode_block_unlocked_dio(struct inode *inode)
  2969. {
  2970. ext4_set_inode_state(inode, EXT4_STATE_DIOREAD_LOCK);
  2971. smp_mb();
  2972. }
  2973. static inline void ext4_inode_resume_unlocked_dio(struct inode *inode)
  2974. {
  2975. smp_mb();
  2976. ext4_clear_inode_state(inode, EXT4_STATE_DIOREAD_LOCK);
  2977. }
  2978. #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
  2979. /* For ioend & aio unwritten conversion wait queues */
  2980. #define EXT4_WQ_HASH_SZ 37
  2981. #define ext4_ioend_wq(v) (&ext4__ioend_wq[((unsigned long)(v)) %\
  2982. EXT4_WQ_HASH_SZ])
  2983. extern wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ];
  2984. #define EXT4_RESIZING 0
  2985. extern int ext4_resize_begin(struct super_block *sb);
  2986. extern void ext4_resize_end(struct super_block *sb);
  2987. static inline void ext4_set_io_unwritten_flag(struct inode *inode,
  2988. struct ext4_io_end *io_end)
  2989. {
  2990. if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) {
  2991. io_end->flag |= EXT4_IO_END_UNWRITTEN;
  2992. atomic_inc(&EXT4_I(inode)->i_unwritten);
  2993. }
  2994. }
  2995. static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end)
  2996. {
  2997. struct inode *inode = io_end->inode;
  2998. if (io_end->flag & EXT4_IO_END_UNWRITTEN) {
  2999. io_end->flag &= ~EXT4_IO_END_UNWRITTEN;
  3000. /* Wake up anyone waiting on unwritten extent conversion */
  3001. if (atomic_dec_and_test(&EXT4_I(inode)->i_unwritten))
  3002. wake_up_all(ext4_ioend_wq(inode));
  3003. }
  3004. }
  3005. static inline bool ext4_aligned_io(struct inode *inode, loff_t off, loff_t len)
  3006. {
  3007. int blksize = 1 << inode->i_blkbits;
  3008. return IS_ALIGNED(off, blksize) && IS_ALIGNED(len, blksize);
  3009. }
  3010. #endif /* __KERNEL__ */
  3011. #define EFSBADCRC EBADMSG /* Bad CRC detected */
  3012. #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
  3013. #endif /* _EXT4_H */