f2fs.h 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  1. /*
  2. * fs/f2fs/f2fs.h
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef _LINUX_F2FS_H
  12. #define _LINUX_F2FS_H
  13. #include <linux/types.h>
  14. #include <linux/page-flags.h>
  15. #include <linux/buffer_head.h>
  16. #include <linux/slab.h>
  17. #include <linux/crc32.h>
  18. #include <linux/magic.h>
  19. #include <linux/kobject.h>
  20. #include <linux/sched.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/bio.h>
  23. #ifdef CONFIG_F2FS_CHECK_FS
  24. #define f2fs_bug_on(sbi, condition) BUG_ON(condition)
  25. #define f2fs_down_write(x, y) down_write_nest_lock(x, y)
  26. #else
  27. #define f2fs_bug_on(sbi, condition) \
  28. do { \
  29. if (unlikely(condition)) { \
  30. WARN_ON(1); \
  31. set_sbi_flag(sbi, SBI_NEED_FSCK); \
  32. } \
  33. } while (0)
  34. #define f2fs_down_write(x, y) down_write(x)
  35. #endif
  36. /*
  37. * For mount options
  38. */
  39. #define F2FS_MOUNT_BG_GC 0x00000001
  40. #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
  41. #define F2FS_MOUNT_DISCARD 0x00000004
  42. #define F2FS_MOUNT_NOHEAP 0x00000008
  43. #define F2FS_MOUNT_XATTR_USER 0x00000010
  44. #define F2FS_MOUNT_POSIX_ACL 0x00000020
  45. #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
  46. #define F2FS_MOUNT_INLINE_XATTR 0x00000080
  47. #define F2FS_MOUNT_INLINE_DATA 0x00000100
  48. #define F2FS_MOUNT_INLINE_DENTRY 0x00000200
  49. #define F2FS_MOUNT_FLUSH_MERGE 0x00000400
  50. #define F2FS_MOUNT_NOBARRIER 0x00000800
  51. #define F2FS_MOUNT_FASTBOOT 0x00001000
  52. #define F2FS_MOUNT_EXTENT_CACHE 0x00002000
  53. #define F2FS_MOUNT_FORCE_FG_GC 0x00004000
  54. #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
  55. #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
  56. #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
  57. #define ver_after(a, b) (typecheck(unsigned long long, a) && \
  58. typecheck(unsigned long long, b) && \
  59. ((long long)((a) - (b)) > 0))
  60. typedef u32 block_t; /*
  61. * should not change u32, since it is the on-disk block
  62. * address format, __le32.
  63. */
  64. typedef u32 nid_t;
  65. struct f2fs_mount_info {
  66. unsigned int opt;
  67. };
  68. #define F2FS_FEATURE_ENCRYPT 0x0001
  69. #define F2FS_HAS_FEATURE(sb, mask) \
  70. ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
  71. #define F2FS_SET_FEATURE(sb, mask) \
  72. F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)
  73. #define F2FS_CLEAR_FEATURE(sb, mask) \
  74. F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)
  75. #define CRCPOLY_LE 0xedb88320
  76. static inline __u32 f2fs_crc32(void *buf, size_t len)
  77. {
  78. unsigned char *p = (unsigned char *)buf;
  79. __u32 crc = F2FS_SUPER_MAGIC;
  80. int i;
  81. while (len--) {
  82. crc ^= *p++;
  83. for (i = 0; i < 8; i++)
  84. crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
  85. }
  86. return crc;
  87. }
  88. static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
  89. {
  90. return f2fs_crc32(buf, buf_size) == blk_crc;
  91. }
  92. /*
  93. * For checkpoint manager
  94. */
  95. enum {
  96. NAT_BITMAP,
  97. SIT_BITMAP
  98. };
  99. enum {
  100. CP_UMOUNT,
  101. CP_FASTBOOT,
  102. CP_SYNC,
  103. CP_RECOVERY,
  104. CP_DISCARD,
  105. };
  106. #define DEF_BATCHED_TRIM_SECTIONS 32
  107. #define BATCHED_TRIM_SEGMENTS(sbi) \
  108. (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
  109. #define BATCHED_TRIM_BLOCKS(sbi) \
  110. (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
  111. #define DEF_CP_INTERVAL 60 /* 60 secs */
  112. struct cp_control {
  113. int reason;
  114. __u64 trim_start;
  115. __u64 trim_end;
  116. __u64 trim_minlen;
  117. __u64 trimmed;
  118. };
  119. /*
  120. * indicate meta/data type
  121. */
  122. enum {
  123. META_CP,
  124. META_NAT,
  125. META_SIT,
  126. META_SSA,
  127. META_POR,
  128. DATA_GENERIC,
  129. META_GENERIC,
  130. };
  131. /* for the list of ino */
  132. enum {
  133. ORPHAN_INO, /* for orphan ino list */
  134. APPEND_INO, /* for append ino list */
  135. UPDATE_INO, /* for update ino list */
  136. MAX_INO_ENTRY, /* max. list */
  137. };
  138. struct ino_entry {
  139. struct list_head list; /* list head */
  140. nid_t ino; /* inode number */
  141. };
  142. /*
  143. * for the list of directory inodes or gc inodes.
  144. * NOTE: there are two slab users for this structure, if we add/modify/delete
  145. * fields in structure for one of slab users, it may affect fields or size of
  146. * other one, in this condition, it's better to split both of slab and related
  147. * data structure.
  148. */
  149. struct inode_entry {
  150. struct list_head list; /* list head */
  151. struct inode *inode; /* vfs inode pointer */
  152. };
  153. /* for the list of blockaddresses to be discarded */
  154. struct discard_entry {
  155. struct list_head list; /* list head */
  156. block_t blkaddr; /* block address to be discarded */
  157. int len; /* # of consecutive blocks of the discard */
  158. };
  159. /* for the list of fsync inodes, used only during recovery */
  160. struct fsync_inode_entry {
  161. struct list_head list; /* list head */
  162. struct inode *inode; /* vfs inode pointer */
  163. block_t blkaddr; /* block address locating the last fsync */
  164. block_t last_dentry; /* block address locating the last dentry */
  165. block_t last_inode; /* block address locating the last inode */
  166. };
  167. #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
  168. #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
  169. #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
  170. #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
  171. #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
  172. #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
  173. #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum))
  174. #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum))
  175. static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
  176. {
  177. int before = nats_in_cursum(rs);
  178. rs->n_nats = cpu_to_le16(before + i);
  179. return before;
  180. }
  181. static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
  182. {
  183. int before = sits_in_cursum(rs);
  184. rs->n_sits = cpu_to_le16(before + i);
  185. return before;
  186. }
  187. static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size,
  188. int type)
  189. {
  190. if (type == NAT_JOURNAL)
  191. return size <= MAX_NAT_JENTRIES(sum);
  192. return size <= MAX_SIT_JENTRIES(sum);
  193. }
  194. /*
  195. * ioctl commands
  196. */
  197. #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
  198. #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
  199. #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION
  200. #define F2FS_IOCTL_MAGIC 0xf5
  201. #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
  202. #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
  203. #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
  204. #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
  205. #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
  206. #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6)
  207. #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7)
  208. #define F2FS_IOC_SET_ENCRYPTION_POLICY \
  209. _IOR('f', 19, struct f2fs_encryption_policy)
  210. #define F2FS_IOC_GET_ENCRYPTION_PWSALT \
  211. _IOW('f', 20, __u8[16])
  212. #define F2FS_IOC_GET_ENCRYPTION_POLICY \
  213. _IOW('f', 21, struct f2fs_encryption_policy)
  214. /*
  215. * should be same as XFS_IOC_GOINGDOWN.
  216. * Flags for going down operation used by FS_IOC_GOINGDOWN
  217. */
  218. #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */
  219. #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */
  220. #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */
  221. #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */
  222. #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */
  223. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  224. /*
  225. * ioctl commands in 32 bit emulation
  226. */
  227. #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  228. #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  229. #endif
  230. /*
  231. * For INODE and NODE manager
  232. */
  233. /* for directory operations */
  234. struct f2fs_str {
  235. unsigned char *name;
  236. u32 len;
  237. };
  238. struct f2fs_filename {
  239. const struct qstr *usr_fname;
  240. struct f2fs_str disk_name;
  241. f2fs_hash_t hash;
  242. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  243. struct f2fs_str crypto_buf;
  244. #endif
  245. };
  246. #define FSTR_INIT(n, l) { .name = n, .len = l }
  247. #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len)
  248. #define fname_name(p) ((p)->disk_name.name)
  249. #define fname_len(p) ((p)->disk_name.len)
  250. struct f2fs_dentry_ptr {
  251. struct inode *inode;
  252. const void *bitmap;
  253. struct f2fs_dir_entry *dentry;
  254. __u8 (*filename)[F2FS_SLOT_LEN];
  255. int max;
  256. };
  257. static inline void make_dentry_ptr(struct inode *inode,
  258. struct f2fs_dentry_ptr *d, void *src, int type)
  259. {
  260. d->inode = inode;
  261. if (type == 1) {
  262. struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src;
  263. d->max = NR_DENTRY_IN_BLOCK;
  264. d->bitmap = &t->dentry_bitmap;
  265. d->dentry = t->dentry;
  266. d->filename = t->filename;
  267. } else {
  268. struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src;
  269. d->max = NR_INLINE_DENTRY;
  270. d->bitmap = &t->dentry_bitmap;
  271. d->dentry = t->dentry;
  272. d->filename = t->filename;
  273. }
  274. }
  275. /*
  276. * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
  277. * as its node offset to distinguish from index node blocks.
  278. * But some bits are used to mark the node block.
  279. */
  280. #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
  281. >> OFFSET_BIT_SHIFT)
  282. enum {
  283. ALLOC_NODE, /* allocate a new node page if needed */
  284. LOOKUP_NODE, /* look up a node without readahead */
  285. LOOKUP_NODE_RA, /*
  286. * look up a node with readahead called
  287. * by get_data_block.
  288. */
  289. };
  290. #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */
  291. #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
  292. /* vector size for gang look-up from extent cache that consists of radix tree */
  293. #define EXT_TREE_VEC_SIZE 64
  294. /* for in-memory extent cache entry */
  295. #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */
  296. /* number of extent info in extent cache we try to shrink */
  297. #define EXTENT_CACHE_SHRINK_NUMBER 128
  298. struct extent_info {
  299. unsigned int fofs; /* start offset in a file */
  300. u32 blk; /* start block address of the extent */
  301. unsigned int len; /* length of the extent */
  302. };
  303. struct extent_node {
  304. struct rb_node rb_node; /* rb node located in rb-tree */
  305. struct list_head list; /* node in global extent list of sbi */
  306. struct extent_info ei; /* extent info */
  307. };
  308. struct extent_tree {
  309. nid_t ino; /* inode number */
  310. struct rb_root root; /* root of extent info rb-tree */
  311. struct extent_node *cached_en; /* recently accessed extent node */
  312. struct extent_info largest; /* largested extent info */
  313. rwlock_t lock; /* protect extent info rb-tree */
  314. atomic_t refcount; /* reference count of rb-tree */
  315. unsigned int count; /* # of extent node in rb-tree*/
  316. };
  317. /*
  318. * This structure is taken from ext4_map_blocks.
  319. *
  320. * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
  321. */
  322. #define F2FS_MAP_NEW (1 << BH_New)
  323. #define F2FS_MAP_MAPPED (1 << BH_Mapped)
  324. #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten)
  325. #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
  326. F2FS_MAP_UNWRITTEN)
  327. struct f2fs_map_blocks {
  328. block_t m_pblk;
  329. block_t m_lblk;
  330. unsigned int m_len;
  331. unsigned int m_flags;
  332. };
  333. /* for flag in get_data_block */
  334. #define F2FS_GET_BLOCK_READ 0
  335. #define F2FS_GET_BLOCK_DIO 1
  336. #define F2FS_GET_BLOCK_FIEMAP 2
  337. #define F2FS_GET_BLOCK_BMAP 3
  338. /*
  339. * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
  340. */
  341. #define FADVISE_COLD_BIT 0x01
  342. #define FADVISE_LOST_PINO_BIT 0x02
  343. #define FADVISE_ENCRYPT_BIT 0x04
  344. #define FADVISE_ENC_NAME_BIT 0x08
  345. #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
  346. #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
  347. #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT)
  348. #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT)
  349. #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT)
  350. #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT)
  351. #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT)
  352. #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT)
  353. #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
  354. #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT)
  355. #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
  356. /* Encryption algorithms */
  357. #define F2FS_ENCRYPTION_MODE_INVALID 0
  358. #define F2FS_ENCRYPTION_MODE_AES_256_XTS 1
  359. #define F2FS_ENCRYPTION_MODE_AES_256_GCM 2
  360. #define F2FS_ENCRYPTION_MODE_AES_256_CBC 3
  361. #define F2FS_ENCRYPTION_MODE_AES_256_CTS 4
  362. #include "f2fs_crypto.h"
  363. #define DEF_DIR_LEVEL 0
  364. struct f2fs_inode_info {
  365. struct inode vfs_inode; /* serve a vfs inode */
  366. unsigned long i_flags; /* keep an inode flags for ioctl */
  367. unsigned char i_advise; /* use to give file attribute hints */
  368. unsigned char i_dir_level; /* use for dentry level for large dir */
  369. unsigned int i_current_depth; /* use only in directory structure */
  370. unsigned int i_pino; /* parent inode number */
  371. umode_t i_acl_mode; /* keep file acl mode temporarily */
  372. /* Use below internally in f2fs*/
  373. unsigned long flags; /* use to pass per-file flags */
  374. struct rw_semaphore i_sem; /* protect fi info */
  375. atomic_t dirty_pages; /* # of dirty pages */
  376. f2fs_hash_t chash; /* hash value of given file name */
  377. unsigned int clevel; /* maximum level of given file name */
  378. nid_t i_xattr_nid; /* node id that contains xattrs */
  379. unsigned long long xattr_ver; /* cp version of xattr modification */
  380. struct inode_entry *dirty_dir; /* the pointer of dirty dir */
  381. struct list_head inmem_pages; /* inmemory pages managed by f2fs */
  382. struct mutex inmem_lock; /* lock for inmemory pages */
  383. struct extent_tree *extent_tree; /* cached extent_tree entry */
  384. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  385. /* Encryption params */
  386. struct f2fs_crypt_info *i_crypt_info;
  387. #endif
  388. };
  389. static inline void get_extent_info(struct extent_info *ext,
  390. struct f2fs_extent i_ext)
  391. {
  392. ext->fofs = le32_to_cpu(i_ext.fofs);
  393. ext->blk = le32_to_cpu(i_ext.blk);
  394. ext->len = le32_to_cpu(i_ext.len);
  395. }
  396. static inline void set_raw_extent(struct extent_info *ext,
  397. struct f2fs_extent *i_ext)
  398. {
  399. i_ext->fofs = cpu_to_le32(ext->fofs);
  400. i_ext->blk = cpu_to_le32(ext->blk);
  401. i_ext->len = cpu_to_le32(ext->len);
  402. }
  403. static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
  404. u32 blk, unsigned int len)
  405. {
  406. ei->fofs = fofs;
  407. ei->blk = blk;
  408. ei->len = len;
  409. }
  410. static inline bool __is_extent_same(struct extent_info *ei1,
  411. struct extent_info *ei2)
  412. {
  413. return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk &&
  414. ei1->len == ei2->len);
  415. }
  416. static inline bool __is_extent_mergeable(struct extent_info *back,
  417. struct extent_info *front)
  418. {
  419. return (back->fofs + back->len == front->fofs &&
  420. back->blk + back->len == front->blk);
  421. }
  422. static inline bool __is_back_mergeable(struct extent_info *cur,
  423. struct extent_info *back)
  424. {
  425. return __is_extent_mergeable(back, cur);
  426. }
  427. static inline bool __is_front_mergeable(struct extent_info *cur,
  428. struct extent_info *front)
  429. {
  430. return __is_extent_mergeable(cur, front);
  431. }
  432. static inline void __try_update_largest_extent(struct extent_tree *et,
  433. struct extent_node *en)
  434. {
  435. if (en->ei.len > et->largest.len)
  436. et->largest = en->ei;
  437. }
  438. struct f2fs_nm_info {
  439. block_t nat_blkaddr; /* base disk address of NAT */
  440. nid_t max_nid; /* maximum possible node ids */
  441. nid_t available_nids; /* maximum available node ids */
  442. nid_t next_scan_nid; /* the next nid to be scanned */
  443. unsigned int ram_thresh; /* control the memory footprint */
  444. unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */
  445. /* NAT cache management */
  446. struct radix_tree_root nat_root;/* root of the nat entry cache */
  447. struct radix_tree_root nat_set_root;/* root of the nat set cache */
  448. struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
  449. struct list_head nat_entries; /* cached nat entry list (clean) */
  450. unsigned int nat_cnt; /* the # of cached nat entries */
  451. unsigned int dirty_nat_cnt; /* total num of nat entries in set */
  452. /* free node ids management */
  453. struct radix_tree_root free_nid_root;/* root of the free_nid cache */
  454. struct list_head free_nid_list; /* a list for free nids */
  455. spinlock_t free_nid_list_lock; /* protect free nid list */
  456. unsigned int fcnt; /* the number of free node id */
  457. struct mutex build_lock; /* lock for build free nids */
  458. /* for checkpoint */
  459. char *nat_bitmap; /* NAT bitmap pointer */
  460. int bitmap_size; /* bitmap size */
  461. };
  462. /*
  463. * this structure is used as one of function parameters.
  464. * all the information are dedicated to a given direct node block determined
  465. * by the data offset in a file.
  466. */
  467. struct dnode_of_data {
  468. struct inode *inode; /* vfs inode pointer */
  469. struct page *inode_page; /* its inode page, NULL is possible */
  470. struct page *node_page; /* cached direct node page */
  471. nid_t nid; /* node id of the direct node block */
  472. unsigned int ofs_in_node; /* data offset in the node page */
  473. bool inode_page_locked; /* inode page is locked or not */
  474. block_t data_blkaddr; /* block address of the node block */
  475. };
  476. static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  477. struct page *ipage, struct page *npage, nid_t nid)
  478. {
  479. memset(dn, 0, sizeof(*dn));
  480. dn->inode = inode;
  481. dn->inode_page = ipage;
  482. dn->node_page = npage;
  483. dn->nid = nid;
  484. }
  485. /*
  486. * For SIT manager
  487. *
  488. * By default, there are 6 active log areas across the whole main area.
  489. * When considering hot and cold data separation to reduce cleaning overhead,
  490. * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
  491. * respectively.
  492. * In the current design, you should not change the numbers intentionally.
  493. * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
  494. * logs individually according to the underlying devices. (default: 6)
  495. * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
  496. * data and 8 for node logs.
  497. */
  498. #define NR_CURSEG_DATA_TYPE (3)
  499. #define NR_CURSEG_NODE_TYPE (3)
  500. #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  501. enum {
  502. CURSEG_HOT_DATA = 0, /* directory entry blocks */
  503. CURSEG_WARM_DATA, /* data blocks */
  504. CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
  505. CURSEG_HOT_NODE, /* direct node blocks of directory files */
  506. CURSEG_WARM_NODE, /* direct node blocks of normal files */
  507. CURSEG_COLD_NODE, /* indirect node blocks */
  508. NO_CHECK_TYPE,
  509. CURSEG_DIRECT_IO, /* to use for the direct IO path */
  510. };
  511. struct flush_cmd {
  512. struct completion wait;
  513. struct llist_node llnode;
  514. int ret;
  515. };
  516. struct flush_cmd_control {
  517. struct task_struct *f2fs_issue_flush; /* flush thread */
  518. wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */
  519. struct llist_head issue_list; /* list for command issue */
  520. struct llist_node *dispatch_list; /* list for command dispatch */
  521. };
  522. struct f2fs_sm_info {
  523. struct sit_info *sit_info; /* whole segment information */
  524. struct free_segmap_info *free_info; /* free segment information */
  525. struct dirty_seglist_info *dirty_info; /* dirty segment information */
  526. struct curseg_info *curseg_array; /* active segment information */
  527. block_t seg0_blkaddr; /* block address of 0'th segment */
  528. block_t main_blkaddr; /* start block address of main area */
  529. block_t ssa_blkaddr; /* start block address of SSA area */
  530. unsigned int segment_count; /* total # of segments */
  531. unsigned int main_segments; /* # of segments in main area */
  532. unsigned int reserved_segments; /* # of reserved segments */
  533. unsigned int ovp_segments; /* # of overprovision segments */
  534. /* a threshold to reclaim prefree segments */
  535. unsigned int rec_prefree_segments;
  536. /* for small discard management */
  537. struct list_head discard_list; /* 4KB discard list */
  538. int nr_discards; /* # of discards in the list */
  539. int max_discards; /* max. discards to be issued */
  540. /* for batched trimming */
  541. unsigned int trim_sections; /* # of sections to trim */
  542. struct list_head sit_entry_set; /* sit entry set list */
  543. unsigned int ipu_policy; /* in-place-update policy */
  544. unsigned int min_ipu_util; /* in-place-update threshold */
  545. unsigned int min_fsync_blocks; /* threshold for fsync */
  546. /* for flush command control */
  547. struct flush_cmd_control *cmd_control_info;
  548. };
  549. /*
  550. * For superblock
  551. */
  552. /*
  553. * COUNT_TYPE for monitoring
  554. *
  555. * f2fs monitors the number of several block types such as on-writeback,
  556. * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
  557. */
  558. enum count_type {
  559. F2FS_WRITEBACK,
  560. F2FS_DIRTY_DENTS,
  561. F2FS_DIRTY_NODES,
  562. F2FS_DIRTY_META,
  563. F2FS_INMEM_PAGES,
  564. NR_COUNT_TYPE,
  565. };
  566. /*
  567. * The below are the page types of bios used in submit_bio().
  568. * The available types are:
  569. * DATA User data pages. It operates as async mode.
  570. * NODE Node pages. It operates as async mode.
  571. * META FS metadata pages such as SIT, NAT, CP.
  572. * NR_PAGE_TYPE The number of page types.
  573. * META_FLUSH Make sure the previous pages are written
  574. * with waiting the bio's completion
  575. * ... Only can be used with META.
  576. */
  577. #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
  578. enum page_type {
  579. DATA,
  580. NODE,
  581. META,
  582. NR_PAGE_TYPE,
  583. META_FLUSH,
  584. INMEM, /* the below types are used by tracepoints only. */
  585. INMEM_DROP,
  586. IPU,
  587. OPU,
  588. };
  589. struct f2fs_io_info {
  590. struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */
  591. enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
  592. int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */
  593. block_t blk_addr; /* block address to be written */
  594. struct page *page; /* page to be written */
  595. struct page *encrypted_page; /* encrypted page */
  596. bool is_meta; /* indicate borrow meta inode mapping or not */
  597. };
  598. #define is_read_io(rw) (((rw) & 1) == READ)
  599. struct f2fs_bio_info {
  600. struct f2fs_sb_info *sbi; /* f2fs superblock */
  601. struct bio *bio; /* bios to merge */
  602. sector_t last_block_in_bio; /* last block number */
  603. struct f2fs_io_info fio; /* store buffered io info. */
  604. struct rw_semaphore io_rwsem; /* blocking op for bio */
  605. };
  606. /* for inner inode cache management */
  607. struct inode_management {
  608. struct radix_tree_root ino_root; /* ino entry array */
  609. spinlock_t ino_lock; /* for ino entry lock */
  610. struct list_head ino_list; /* inode list head */
  611. unsigned long ino_num; /* number of entries */
  612. };
  613. /* For s_flag in struct f2fs_sb_info */
  614. enum {
  615. SBI_IS_DIRTY, /* dirty flag for checkpoint */
  616. SBI_IS_CLOSE, /* specify unmounting */
  617. SBI_NEED_FSCK, /* need fsck.f2fs to fix */
  618. SBI_POR_DOING, /* recovery is doing or not */
  619. };
  620. struct f2fs_sb_info {
  621. struct super_block *sb; /* pointer to VFS super block */
  622. struct proc_dir_entry *s_proc; /* proc entry */
  623. struct buffer_head *raw_super_buf; /* buffer head of raw sb */
  624. struct f2fs_super_block *raw_super; /* raw super block pointer */
  625. int s_flag; /* flags for sbi */
  626. /* for node-related operations */
  627. struct f2fs_nm_info *nm_info; /* node manager */
  628. struct inode *node_inode; /* cache node blocks */
  629. /* for segment-related operations */
  630. struct f2fs_sm_info *sm_info; /* segment manager */
  631. /* for bio operations */
  632. struct f2fs_bio_info read_io; /* for read bios */
  633. struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */
  634. /* for checkpoint */
  635. struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
  636. int cur_cp_pack; /* remain current cp pack */
  637. struct inode *meta_inode; /* cache meta blocks */
  638. struct mutex cp_mutex; /* checkpoint procedure lock */
  639. struct rw_semaphore cp_rwsem; /* blocking FS operations */
  640. struct rw_semaphore node_write; /* locking node writes */
  641. struct mutex writepages; /* mutex for writepages() */
  642. wait_queue_head_t cp_wait;
  643. long cp_expires, cp_interval; /* next expected periodic cp */
  644. struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
  645. /* for orphan inode, use 0'th array */
  646. unsigned int max_orphans; /* max orphan inodes */
  647. /* for directory inode management */
  648. struct list_head dir_inode_list; /* dir inode list */
  649. spinlock_t dir_inode_lock; /* for dir inode list lock */
  650. /* for extent tree cache */
  651. struct radix_tree_root extent_tree_root;/* cache extent cache entries */
  652. struct rw_semaphore extent_tree_lock; /* locking extent radix tree */
  653. struct list_head extent_list; /* lru list for shrinker */
  654. spinlock_t extent_lock; /* locking extent lru list */
  655. int total_ext_tree; /* extent tree count */
  656. atomic_t total_ext_node; /* extent info count */
  657. /* basic filesystem units */
  658. unsigned int log_sectors_per_block; /* log2 sectors per block */
  659. unsigned int log_blocksize; /* log2 block size */
  660. unsigned int blocksize; /* block size */
  661. unsigned int root_ino_num; /* root inode number*/
  662. unsigned int node_ino_num; /* node inode number*/
  663. unsigned int meta_ino_num; /* meta inode number*/
  664. unsigned int log_blocks_per_seg; /* log2 blocks per segment */
  665. unsigned int blocks_per_seg; /* blocks per segment */
  666. unsigned int segs_per_sec; /* segments per section */
  667. unsigned int secs_per_zone; /* sections per zone */
  668. unsigned int total_sections; /* total section count */
  669. unsigned int total_node_count; /* total node block count */
  670. unsigned int total_valid_node_count; /* valid node block count */
  671. unsigned int total_valid_inode_count; /* valid inode count */
  672. int active_logs; /* # of active logs */
  673. int dir_level; /* directory level */
  674. block_t user_block_count; /* # of user blocks */
  675. block_t total_valid_block_count; /* # of valid blocks */
  676. block_t alloc_valid_block_count; /* # of allocated blocks */
  677. block_t discard_blks; /* discard command candidats */
  678. block_t last_valid_block_count; /* for recovery */
  679. u32 s_next_generation; /* for NFS support */
  680. atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
  681. struct f2fs_mount_info mount_opt; /* mount options */
  682. /* for cleaning operations */
  683. struct mutex gc_mutex; /* mutex for GC */
  684. struct f2fs_gc_kthread *gc_thread; /* GC thread */
  685. unsigned int cur_victim_sec; /* current victim section num */
  686. /* maximum # of trials to find a victim segment for SSR and GC */
  687. unsigned int max_victim_search;
  688. /*
  689. * for stat information.
  690. * one is for the LFS mode, and the other is for the SSR mode.
  691. */
  692. #ifdef CONFIG_F2FS_STAT_FS
  693. struct f2fs_stat_info *stat_info; /* FS status information */
  694. unsigned int segment_count[2]; /* # of allocated segments */
  695. unsigned int block_count[2]; /* # of allocated blocks */
  696. atomic_t inplace_count; /* # of inplace update */
  697. atomic64_t total_hit_ext; /* # of lookup extent cache */
  698. atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */
  699. atomic64_t read_hit_largest; /* # of hit largest extent node */
  700. atomic64_t read_hit_cached; /* # of hit cached extent node */
  701. atomic_t inline_xattr; /* # of inline_xattr inodes */
  702. atomic_t inline_inode; /* # of inline_data inodes */
  703. atomic_t inline_dir; /* # of inline_dentry inodes */
  704. int bg_gc; /* background gc calls */
  705. unsigned int n_dirty_dirs; /* # of dir inodes */
  706. #endif
  707. unsigned int last_victim[2]; /* last victim segment # */
  708. spinlock_t stat_lock; /* lock for stat operations */
  709. /* For sysfs suppport */
  710. struct kobject s_kobj;
  711. struct completion s_kobj_unregister;
  712. /* For shrinker support */
  713. struct list_head s_list;
  714. struct mutex umount_mutex;
  715. unsigned int shrinker_run_no;
  716. };
  717. /*
  718. * Inline functions
  719. */
  720. static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
  721. {
  722. return container_of(inode, struct f2fs_inode_info, vfs_inode);
  723. }
  724. static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
  725. {
  726. return sb->s_fs_info;
  727. }
  728. static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
  729. {
  730. return F2FS_SB(inode->i_sb);
  731. }
  732. static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
  733. {
  734. return F2FS_I_SB(mapping->host);
  735. }
  736. static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
  737. {
  738. return F2FS_M_SB(page->mapping);
  739. }
  740. static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
  741. {
  742. return (struct f2fs_super_block *)(sbi->raw_super);
  743. }
  744. static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
  745. {
  746. return (struct f2fs_checkpoint *)(sbi->ckpt);
  747. }
  748. static inline struct f2fs_node *F2FS_NODE(struct page *page)
  749. {
  750. return (struct f2fs_node *)page_address(page);
  751. }
  752. static inline struct f2fs_inode *F2FS_INODE(struct page *page)
  753. {
  754. return &((struct f2fs_node *)page_address(page))->i;
  755. }
  756. static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
  757. {
  758. return (struct f2fs_nm_info *)(sbi->nm_info);
  759. }
  760. static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
  761. {
  762. return (struct f2fs_sm_info *)(sbi->sm_info);
  763. }
  764. static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
  765. {
  766. return (struct sit_info *)(SM_I(sbi)->sit_info);
  767. }
  768. static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
  769. {
  770. return (struct free_segmap_info *)(SM_I(sbi)->free_info);
  771. }
  772. static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
  773. {
  774. return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
  775. }
  776. static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
  777. {
  778. return sbi->meta_inode->i_mapping;
  779. }
  780. static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
  781. {
  782. return sbi->node_inode->i_mapping;
  783. }
  784. static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
  785. {
  786. return sbi->s_flag & (0x01 << type);
  787. }
  788. static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  789. {
  790. sbi->s_flag |= (0x01 << type);
  791. }
  792. static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  793. {
  794. sbi->s_flag &= ~(0x01 << type);
  795. }
  796. static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
  797. {
  798. return le64_to_cpu(cp->checkpoint_ver);
  799. }
  800. static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  801. {
  802. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  803. return ckpt_flags & f;
  804. }
  805. static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  806. {
  807. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  808. ckpt_flags |= f;
  809. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  810. }
  811. static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  812. {
  813. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  814. ckpt_flags &= (~f);
  815. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  816. }
  817. static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
  818. {
  819. down_read(&sbi->cp_rwsem);
  820. }
  821. static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
  822. {
  823. up_read(&sbi->cp_rwsem);
  824. }
  825. static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
  826. {
  827. f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex);
  828. }
  829. static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
  830. {
  831. up_write(&sbi->cp_rwsem);
  832. }
  833. static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
  834. {
  835. int reason = CP_SYNC;
  836. if (test_opt(sbi, FASTBOOT))
  837. reason = CP_FASTBOOT;
  838. if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
  839. reason = CP_UMOUNT;
  840. return reason;
  841. }
  842. static inline bool __remain_node_summaries(int reason)
  843. {
  844. return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
  845. }
  846. static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
  847. {
  848. return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) ||
  849. is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG));
  850. }
  851. /*
  852. * Check whether the given nid is within node id range.
  853. */
  854. static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
  855. {
  856. if (unlikely(nid < F2FS_ROOT_INO(sbi)))
  857. return -EINVAL;
  858. if (unlikely(nid >= NM_I(sbi)->max_nid))
  859. return -EINVAL;
  860. return 0;
  861. }
  862. #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
  863. /*
  864. * Check whether the inode has blocks or not
  865. */
  866. static inline int F2FS_HAS_BLOCKS(struct inode *inode)
  867. {
  868. if (F2FS_I(inode)->i_xattr_nid)
  869. return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
  870. else
  871. return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
  872. }
  873. static inline bool f2fs_has_xattr_block(unsigned int ofs)
  874. {
  875. return ofs == XATTR_NODE_OFFSET;
  876. }
  877. static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
  878. struct inode *inode, blkcnt_t count)
  879. {
  880. block_t valid_block_count;
  881. spin_lock(&sbi->stat_lock);
  882. valid_block_count =
  883. sbi->total_valid_block_count + (block_t)count;
  884. if (unlikely(valid_block_count > sbi->user_block_count)) {
  885. spin_unlock(&sbi->stat_lock);
  886. return false;
  887. }
  888. inode->i_blocks += count;
  889. sbi->total_valid_block_count = valid_block_count;
  890. sbi->alloc_valid_block_count += (block_t)count;
  891. spin_unlock(&sbi->stat_lock);
  892. return true;
  893. }
  894. static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
  895. struct inode *inode,
  896. blkcnt_t count)
  897. {
  898. spin_lock(&sbi->stat_lock);
  899. f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
  900. f2fs_bug_on(sbi, inode->i_blocks < count);
  901. inode->i_blocks -= count;
  902. sbi->total_valid_block_count -= (block_t)count;
  903. spin_unlock(&sbi->stat_lock);
  904. }
  905. static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
  906. {
  907. atomic_inc(&sbi->nr_pages[count_type]);
  908. set_sbi_flag(sbi, SBI_IS_DIRTY);
  909. }
  910. static inline void inode_inc_dirty_pages(struct inode *inode)
  911. {
  912. atomic_inc(&F2FS_I(inode)->dirty_pages);
  913. if (S_ISDIR(inode->i_mode))
  914. inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
  915. }
  916. static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
  917. {
  918. atomic_dec(&sbi->nr_pages[count_type]);
  919. }
  920. static inline void inode_dec_dirty_pages(struct inode *inode)
  921. {
  922. if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
  923. !S_ISLNK(inode->i_mode))
  924. return;
  925. atomic_dec(&F2FS_I(inode)->dirty_pages);
  926. if (S_ISDIR(inode->i_mode))
  927. dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
  928. }
  929. static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
  930. {
  931. return atomic_read(&sbi->nr_pages[count_type]);
  932. }
  933. static inline int get_dirty_pages(struct inode *inode)
  934. {
  935. return atomic_read(&F2FS_I(inode)->dirty_pages);
  936. }
  937. static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
  938. {
  939. unsigned int pages_per_sec = sbi->segs_per_sec *
  940. (1 << sbi->log_blocks_per_seg);
  941. return ((get_pages(sbi, block_type) + pages_per_sec - 1)
  942. >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
  943. }
  944. static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
  945. {
  946. return sbi->total_valid_block_count;
  947. }
  948. static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
  949. {
  950. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  951. /* return NAT or SIT bitmap */
  952. if (flag == NAT_BITMAP)
  953. return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
  954. else if (flag == SIT_BITMAP)
  955. return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  956. return 0;
  957. }
  958. static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
  959. {
  960. return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
  961. }
  962. static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
  963. {
  964. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  965. int offset;
  966. if (__cp_payload(sbi) > 0) {
  967. if (flag == NAT_BITMAP)
  968. return &ckpt->sit_nat_version_bitmap;
  969. else
  970. return (unsigned char *)ckpt + F2FS_BLKSIZE;
  971. } else {
  972. offset = (flag == NAT_BITMAP) ?
  973. le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
  974. return &ckpt->sit_nat_version_bitmap + offset;
  975. }
  976. }
  977. static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
  978. {
  979. block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  980. if (sbi->cur_cp_pack == 2)
  981. start_addr += sbi->blocks_per_seg;
  982. return start_addr;
  983. }
  984. static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi)
  985. {
  986. block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  987. if (sbi->cur_cp_pack == 1)
  988. start_addr += sbi->blocks_per_seg;
  989. return start_addr;
  990. }
  991. static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi)
  992. {
  993. sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1;
  994. }
  995. static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
  996. {
  997. return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
  998. }
  999. static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
  1000. struct inode *inode)
  1001. {
  1002. block_t valid_block_count;
  1003. unsigned int valid_node_count;
  1004. spin_lock(&sbi->stat_lock);
  1005. valid_block_count = sbi->total_valid_block_count + 1;
  1006. if (unlikely(valid_block_count > sbi->user_block_count)) {
  1007. spin_unlock(&sbi->stat_lock);
  1008. return false;
  1009. }
  1010. valid_node_count = sbi->total_valid_node_count + 1;
  1011. if (unlikely(valid_node_count > sbi->total_node_count)) {
  1012. spin_unlock(&sbi->stat_lock);
  1013. return false;
  1014. }
  1015. if (inode)
  1016. inode->i_blocks++;
  1017. sbi->alloc_valid_block_count++;
  1018. sbi->total_valid_node_count++;
  1019. sbi->total_valid_block_count++;
  1020. spin_unlock(&sbi->stat_lock);
  1021. return true;
  1022. }
  1023. static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
  1024. struct inode *inode)
  1025. {
  1026. spin_lock(&sbi->stat_lock);
  1027. f2fs_bug_on(sbi, !sbi->total_valid_block_count);
  1028. f2fs_bug_on(sbi, !sbi->total_valid_node_count);
  1029. f2fs_bug_on(sbi, !inode->i_blocks);
  1030. inode->i_blocks--;
  1031. sbi->total_valid_node_count--;
  1032. sbi->total_valid_block_count--;
  1033. spin_unlock(&sbi->stat_lock);
  1034. }
  1035. static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
  1036. {
  1037. return sbi->total_valid_node_count;
  1038. }
  1039. static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
  1040. {
  1041. spin_lock(&sbi->stat_lock);
  1042. f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count);
  1043. sbi->total_valid_inode_count++;
  1044. spin_unlock(&sbi->stat_lock);
  1045. }
  1046. static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
  1047. {
  1048. spin_lock(&sbi->stat_lock);
  1049. f2fs_bug_on(sbi, !sbi->total_valid_inode_count);
  1050. sbi->total_valid_inode_count--;
  1051. spin_unlock(&sbi->stat_lock);
  1052. }
  1053. static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
  1054. {
  1055. return sbi->total_valid_inode_count;
  1056. }
  1057. static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
  1058. pgoff_t index, bool for_write)
  1059. {
  1060. if (!for_write)
  1061. return grab_cache_page(mapping, index);
  1062. return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
  1063. }
  1064. static inline void f2fs_copy_page(struct page *src, struct page *dst)
  1065. {
  1066. char *src_kaddr = kmap(src);
  1067. char *dst_kaddr = kmap(dst);
  1068. memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
  1069. kunmap(dst);
  1070. kunmap(src);
  1071. }
  1072. static inline void f2fs_put_page(struct page *page, int unlock)
  1073. {
  1074. if (!page)
  1075. return;
  1076. if (unlock) {
  1077. f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
  1078. unlock_page(page);
  1079. }
  1080. page_cache_release(page);
  1081. }
  1082. static inline void f2fs_put_dnode(struct dnode_of_data *dn)
  1083. {
  1084. if (dn->node_page)
  1085. f2fs_put_page(dn->node_page, 1);
  1086. if (dn->inode_page && dn->node_page != dn->inode_page)
  1087. f2fs_put_page(dn->inode_page, 0);
  1088. dn->node_page = NULL;
  1089. dn->inode_page = NULL;
  1090. }
  1091. static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
  1092. size_t size)
  1093. {
  1094. return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
  1095. }
  1096. static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
  1097. gfp_t flags)
  1098. {
  1099. void *entry;
  1100. entry = kmem_cache_alloc(cachep, flags);
  1101. if (!entry)
  1102. entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
  1103. return entry;
  1104. }
  1105. static inline struct bio *f2fs_bio_alloc(int npages)
  1106. {
  1107. struct bio *bio;
  1108. /* No failure on bio allocation */
  1109. bio = bio_alloc(GFP_NOIO, npages);
  1110. if (!bio)
  1111. bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
  1112. return bio;
  1113. }
  1114. static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
  1115. unsigned long index, void *item)
  1116. {
  1117. while (radix_tree_insert(root, index, item))
  1118. cond_resched();
  1119. }
  1120. #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
  1121. static inline bool IS_INODE(struct page *page)
  1122. {
  1123. struct f2fs_node *p = F2FS_NODE(page);
  1124. return RAW_IS_INODE(p);
  1125. }
  1126. static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
  1127. {
  1128. return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
  1129. }
  1130. static inline block_t datablock_addr(struct page *node_page,
  1131. unsigned int offset)
  1132. {
  1133. struct f2fs_node *raw_node;
  1134. __le32 *addr_array;
  1135. raw_node = F2FS_NODE(node_page);
  1136. addr_array = blkaddr_in_node(raw_node);
  1137. return le32_to_cpu(addr_array[offset]);
  1138. }
  1139. static inline int f2fs_test_bit(unsigned int nr, char *addr)
  1140. {
  1141. int mask;
  1142. addr += (nr >> 3);
  1143. mask = 1 << (7 - (nr & 0x07));
  1144. return mask & *addr;
  1145. }
  1146. static inline void f2fs_set_bit(unsigned int nr, char *addr)
  1147. {
  1148. int mask;
  1149. addr += (nr >> 3);
  1150. mask = 1 << (7 - (nr & 0x07));
  1151. *addr |= mask;
  1152. }
  1153. static inline void f2fs_clear_bit(unsigned int nr, char *addr)
  1154. {
  1155. int mask;
  1156. addr += (nr >> 3);
  1157. mask = 1 << (7 - (nr & 0x07));
  1158. *addr &= ~mask;
  1159. }
  1160. static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
  1161. {
  1162. int mask;
  1163. int ret;
  1164. addr += (nr >> 3);
  1165. mask = 1 << (7 - (nr & 0x07));
  1166. ret = mask & *addr;
  1167. *addr |= mask;
  1168. return ret;
  1169. }
  1170. static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
  1171. {
  1172. int mask;
  1173. int ret;
  1174. addr += (nr >> 3);
  1175. mask = 1 << (7 - (nr & 0x07));
  1176. ret = mask & *addr;
  1177. *addr &= ~mask;
  1178. return ret;
  1179. }
  1180. static inline void f2fs_change_bit(unsigned int nr, char *addr)
  1181. {
  1182. int mask;
  1183. addr += (nr >> 3);
  1184. mask = 1 << (7 - (nr & 0x07));
  1185. *addr ^= mask;
  1186. }
  1187. /* used for f2fs_inode_info->flags */
  1188. enum {
  1189. FI_NEW_INODE, /* indicate newly allocated inode */
  1190. FI_DIRTY_INODE, /* indicate inode is dirty or not */
  1191. FI_DIRTY_DIR, /* indicate directory has dirty pages */
  1192. FI_INC_LINK, /* need to increment i_nlink */
  1193. FI_ACL_MODE, /* indicate acl mode */
  1194. FI_NO_ALLOC, /* should not allocate any blocks */
  1195. FI_FREE_NID, /* free allocated nide */
  1196. FI_UPDATE_DIR, /* should update inode block for consistency */
  1197. FI_NO_EXTENT, /* not to use the extent cache */
  1198. FI_INLINE_XATTR, /* used for inline xattr */
  1199. FI_INLINE_DATA, /* used for inline data*/
  1200. FI_INLINE_DENTRY, /* used for inline dentry */
  1201. FI_APPEND_WRITE, /* inode has appended data */
  1202. FI_UPDATE_WRITE, /* inode has in-place-update data */
  1203. FI_NEED_IPU, /* used for ipu per file */
  1204. FI_ATOMIC_FILE, /* indicate atomic file */
  1205. FI_VOLATILE_FILE, /* indicate volatile file */
  1206. FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */
  1207. FI_DROP_CACHE, /* drop dirty page cache */
  1208. FI_DATA_EXIST, /* indicate data exists */
  1209. FI_INLINE_DOTS, /* indicate inline dot dentries */
  1210. };
  1211. static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
  1212. {
  1213. if (!test_bit(flag, &fi->flags))
  1214. set_bit(flag, &fi->flags);
  1215. }
  1216. static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
  1217. {
  1218. return test_bit(flag, &fi->flags);
  1219. }
  1220. static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  1221. {
  1222. if (test_bit(flag, &fi->flags))
  1223. clear_bit(flag, &fi->flags);
  1224. }
  1225. static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
  1226. {
  1227. fi->i_acl_mode = mode;
  1228. set_inode_flag(fi, FI_ACL_MODE);
  1229. }
  1230. static inline void get_inline_info(struct f2fs_inode_info *fi,
  1231. struct f2fs_inode *ri)
  1232. {
  1233. if (ri->i_inline & F2FS_INLINE_XATTR)
  1234. set_inode_flag(fi, FI_INLINE_XATTR);
  1235. if (ri->i_inline & F2FS_INLINE_DATA)
  1236. set_inode_flag(fi, FI_INLINE_DATA);
  1237. if (ri->i_inline & F2FS_INLINE_DENTRY)
  1238. set_inode_flag(fi, FI_INLINE_DENTRY);
  1239. if (ri->i_inline & F2FS_DATA_EXIST)
  1240. set_inode_flag(fi, FI_DATA_EXIST);
  1241. if (ri->i_inline & F2FS_INLINE_DOTS)
  1242. set_inode_flag(fi, FI_INLINE_DOTS);
  1243. }
  1244. static inline void set_raw_inline(struct f2fs_inode_info *fi,
  1245. struct f2fs_inode *ri)
  1246. {
  1247. ri->i_inline = 0;
  1248. if (is_inode_flag_set(fi, FI_INLINE_XATTR))
  1249. ri->i_inline |= F2FS_INLINE_XATTR;
  1250. if (is_inode_flag_set(fi, FI_INLINE_DATA))
  1251. ri->i_inline |= F2FS_INLINE_DATA;
  1252. if (is_inode_flag_set(fi, FI_INLINE_DENTRY))
  1253. ri->i_inline |= F2FS_INLINE_DENTRY;
  1254. if (is_inode_flag_set(fi, FI_DATA_EXIST))
  1255. ri->i_inline |= F2FS_DATA_EXIST;
  1256. if (is_inode_flag_set(fi, FI_INLINE_DOTS))
  1257. ri->i_inline |= F2FS_INLINE_DOTS;
  1258. }
  1259. static inline int f2fs_has_inline_xattr(struct inode *inode)
  1260. {
  1261. return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
  1262. }
  1263. static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
  1264. {
  1265. if (f2fs_has_inline_xattr(&fi->vfs_inode))
  1266. return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
  1267. return DEF_ADDRS_PER_INODE;
  1268. }
  1269. static inline void *inline_xattr_addr(struct page *page)
  1270. {
  1271. struct f2fs_inode *ri = F2FS_INODE(page);
  1272. return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
  1273. F2FS_INLINE_XATTR_ADDRS]);
  1274. }
  1275. static inline int inline_xattr_size(struct inode *inode)
  1276. {
  1277. if (f2fs_has_inline_xattr(inode))
  1278. return F2FS_INLINE_XATTR_ADDRS << 2;
  1279. else
  1280. return 0;
  1281. }
  1282. static inline int f2fs_has_inline_data(struct inode *inode)
  1283. {
  1284. return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
  1285. }
  1286. static inline void f2fs_clear_inline_inode(struct inode *inode)
  1287. {
  1288. clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
  1289. clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
  1290. }
  1291. static inline int f2fs_exist_data(struct inode *inode)
  1292. {
  1293. return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST);
  1294. }
  1295. static inline int f2fs_has_inline_dots(struct inode *inode)
  1296. {
  1297. return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS);
  1298. }
  1299. static inline bool f2fs_is_atomic_file(struct inode *inode)
  1300. {
  1301. return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE);
  1302. }
  1303. static inline bool f2fs_is_volatile_file(struct inode *inode)
  1304. {
  1305. return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE);
  1306. }
  1307. static inline bool f2fs_is_first_block_written(struct inode *inode)
  1308. {
  1309. return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
  1310. }
  1311. static inline bool f2fs_is_drop_cache(struct inode *inode)
  1312. {
  1313. return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE);
  1314. }
  1315. static inline void *inline_data_addr(struct page *page)
  1316. {
  1317. struct f2fs_inode *ri = F2FS_INODE(page);
  1318. return (void *)&(ri->i_addr[1]);
  1319. }
  1320. static inline int f2fs_has_inline_dentry(struct inode *inode)
  1321. {
  1322. return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY);
  1323. }
  1324. static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
  1325. {
  1326. if (!f2fs_has_inline_dentry(dir))
  1327. kunmap(page);
  1328. }
  1329. static inline int is_file(struct inode *inode, int type)
  1330. {
  1331. return F2FS_I(inode)->i_advise & type;
  1332. }
  1333. static inline void set_file(struct inode *inode, int type)
  1334. {
  1335. F2FS_I(inode)->i_advise |= type;
  1336. }
  1337. static inline void clear_file(struct inode *inode, int type)
  1338. {
  1339. F2FS_I(inode)->i_advise &= ~type;
  1340. }
  1341. static inline int f2fs_readonly(struct super_block *sb)
  1342. {
  1343. return sb->s_flags & MS_RDONLY;
  1344. }
  1345. static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
  1346. {
  1347. return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
  1348. }
  1349. static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
  1350. {
  1351. set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
  1352. sbi->sb->s_flags |= MS_RDONLY;
  1353. }
  1354. static inline bool is_dot_dotdot(const struct qstr *str)
  1355. {
  1356. if (str->len == 1 && str->name[0] == '.')
  1357. return true;
  1358. if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
  1359. return true;
  1360. return false;
  1361. }
  1362. static inline bool f2fs_may_extent_tree(struct inode *inode)
  1363. {
  1364. mode_t mode = inode->i_mode;
  1365. if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) ||
  1366. is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT))
  1367. return false;
  1368. return S_ISREG(mode);
  1369. }
  1370. static inline void *f2fs_kvmalloc(size_t size, gfp_t flags)
  1371. {
  1372. void *ret;
  1373. ret = kmalloc(size, flags | __GFP_NOWARN);
  1374. if (!ret)
  1375. ret = __vmalloc(size, flags, PAGE_KERNEL);
  1376. return ret;
  1377. }
  1378. static inline void *f2fs_kvzalloc(size_t size, gfp_t flags)
  1379. {
  1380. void *ret;
  1381. ret = kzalloc(size, flags | __GFP_NOWARN);
  1382. if (!ret)
  1383. ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
  1384. return ret;
  1385. }
  1386. #define get_inode_mode(i) \
  1387. ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
  1388. (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
  1389. /* get offset of first page in next direct node */
  1390. #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \
  1391. ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \
  1392. (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \
  1393. ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi))
  1394. #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO(fio->type) == META && \
  1395. (!is_read_io(fio->rw) || fio->is_meta))
  1396. bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
  1397. block_t blkaddr, int type);
  1398. void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
  1399. static inline void verify_blkaddr(struct f2fs_sb_info *sbi,
  1400. block_t blkaddr, int type)
  1401. {
  1402. if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) {
  1403. f2fs_msg(sbi->sb, KERN_ERR,
  1404. "invalid blkaddr: %u, type: %d, run fsck to fix.",
  1405. blkaddr, type);
  1406. f2fs_bug_on(sbi, 1);
  1407. }
  1408. }
  1409. static inline bool __is_valid_data_blkaddr(block_t blkaddr)
  1410. {
  1411. if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR)
  1412. return false;
  1413. return true;
  1414. }
  1415. static inline bool is_valid_data_blkaddr(struct f2fs_sb_info *sbi,
  1416. block_t blkaddr)
  1417. {
  1418. if (!__is_valid_data_blkaddr(blkaddr))
  1419. return false;
  1420. verify_blkaddr(sbi, blkaddr, DATA_GENERIC);
  1421. return true;
  1422. }
  1423. /*
  1424. * file.c
  1425. */
  1426. int f2fs_sync_file(struct file *, loff_t, loff_t, int);
  1427. void truncate_data_blocks(struct dnode_of_data *);
  1428. int truncate_blocks(struct inode *, u64, bool);
  1429. int f2fs_truncate(struct inode *, bool);
  1430. int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  1431. int f2fs_setattr(struct dentry *, struct iattr *);
  1432. int truncate_hole(struct inode *, pgoff_t, pgoff_t);
  1433. int truncate_data_blocks_range(struct dnode_of_data *, int);
  1434. long f2fs_ioctl(struct file *, unsigned int, unsigned long);
  1435. long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
  1436. /*
  1437. * inode.c
  1438. */
  1439. void f2fs_set_inode_flags(struct inode *);
  1440. struct inode *f2fs_iget(struct super_block *, unsigned long);
  1441. int try_to_free_nats(struct f2fs_sb_info *, int);
  1442. void update_inode(struct inode *, struct page *);
  1443. void update_inode_page(struct inode *);
  1444. int f2fs_write_inode(struct inode *, struct writeback_control *);
  1445. void f2fs_evict_inode(struct inode *);
  1446. void handle_failed_inode(struct inode *);
  1447. /*
  1448. * namei.c
  1449. */
  1450. struct dentry *f2fs_get_parent(struct dentry *child);
  1451. /*
  1452. * dir.c
  1453. */
  1454. extern unsigned char f2fs_filetype_table[F2FS_FT_MAX];
  1455. void set_de_type(struct f2fs_dir_entry *, umode_t);
  1456. unsigned char get_de_type(struct f2fs_dir_entry *);
  1457. struct f2fs_dir_entry *find_target_dentry(struct f2fs_filename *,
  1458. f2fs_hash_t, int *, struct f2fs_dentry_ptr *);
  1459. bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
  1460. unsigned int, struct f2fs_str *);
  1461. void do_make_empty_dir(struct inode *, struct inode *,
  1462. struct f2fs_dentry_ptr *);
  1463. struct page *init_inode_metadata(struct inode *, struct inode *,
  1464. const struct qstr *, struct page *);
  1465. void update_parent_metadata(struct inode *, struct inode *, unsigned int);
  1466. int room_for_filename(const void *, int, int);
  1467. void f2fs_drop_nlink(struct inode *, struct inode *, struct page *);
  1468. struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
  1469. struct page **);
  1470. struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
  1471. ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
  1472. void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
  1473. struct page *, struct inode *);
  1474. int update_dent_inode(struct inode *, struct inode *, const struct qstr *);
  1475. void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *,
  1476. const struct qstr *, f2fs_hash_t , unsigned int);
  1477. int f2fs_add_regular_entry(struct inode *, const struct qstr *,
  1478. struct inode *, nid_t, umode_t);
  1479. int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t,
  1480. umode_t);
  1481. void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
  1482. struct inode *);
  1483. int f2fs_do_tmpfile(struct inode *, struct inode *);
  1484. bool f2fs_empty_dir(struct inode *);
  1485. static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  1486. {
  1487. return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
  1488. inode, inode->i_ino, inode->i_mode);
  1489. }
  1490. /*
  1491. * super.c
  1492. */
  1493. int f2fs_commit_super(struct f2fs_sb_info *, bool);
  1494. int f2fs_sync_fs(struct super_block *, int);
  1495. extern __printf(3, 4)
  1496. void f2fs_msg(struct super_block *, const char *, const char *, ...);
  1497. int sanity_check_ckpt(struct f2fs_sb_info *sbi);
  1498. /*
  1499. * hash.c
  1500. */
  1501. f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info,
  1502. struct f2fs_filename *fname);
  1503. /*
  1504. * node.c
  1505. */
  1506. struct dnode_of_data;
  1507. struct node_info;
  1508. bool available_free_memory(struct f2fs_sb_info *, int);
  1509. int need_dentry_mark(struct f2fs_sb_info *, nid_t);
  1510. bool is_checkpointed_node(struct f2fs_sb_info *, nid_t);
  1511. bool need_inode_block_update(struct f2fs_sb_info *, nid_t);
  1512. void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
  1513. int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
  1514. int truncate_inode_blocks(struct inode *, pgoff_t);
  1515. int truncate_xattr_node(struct inode *, struct page *);
  1516. int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
  1517. int remove_inode_page(struct inode *);
  1518. struct page *new_inode_page(struct inode *);
  1519. struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
  1520. void ra_node_page(struct f2fs_sb_info *, nid_t);
  1521. struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
  1522. struct page *get_node_page_ra(struct page *, int);
  1523. void sync_inode_page(struct dnode_of_data *);
  1524. int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
  1525. bool alloc_nid(struct f2fs_sb_info *, nid_t *);
  1526. void alloc_nid_done(struct f2fs_sb_info *, nid_t);
  1527. void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
  1528. int try_to_free_nids(struct f2fs_sb_info *, int);
  1529. void recover_inline_xattr(struct inode *, struct page *);
  1530. void recover_xattr_data(struct inode *, struct page *, block_t);
  1531. int recover_inode_page(struct f2fs_sb_info *, struct page *);
  1532. int restore_node_summary(struct f2fs_sb_info *, unsigned int,
  1533. struct f2fs_summary_block *);
  1534. void flush_nat_entries(struct f2fs_sb_info *);
  1535. int build_node_manager(struct f2fs_sb_info *);
  1536. void destroy_node_manager(struct f2fs_sb_info *);
  1537. int __init create_node_manager_caches(void);
  1538. void destroy_node_manager_caches(void);
  1539. /*
  1540. * segment.c
  1541. */
  1542. void register_inmem_page(struct inode *, struct page *);
  1543. int commit_inmem_pages(struct inode *, bool);
  1544. void f2fs_balance_fs(struct f2fs_sb_info *);
  1545. void f2fs_balance_fs_bg(struct f2fs_sb_info *);
  1546. int f2fs_issue_flush(struct f2fs_sb_info *);
  1547. int create_flush_cmd_control(struct f2fs_sb_info *);
  1548. void destroy_flush_cmd_control(struct f2fs_sb_info *);
  1549. void invalidate_blocks(struct f2fs_sb_info *, block_t);
  1550. bool is_checkpointed_data(struct f2fs_sb_info *, block_t);
  1551. void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
  1552. void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *);
  1553. void release_discard_addrs(struct f2fs_sb_info *);
  1554. int npages_for_summary_flush(struct f2fs_sb_info *, bool);
  1555. void allocate_new_segments(struct f2fs_sb_info *);
  1556. int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *);
  1557. struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
  1558. void update_meta_page(struct f2fs_sb_info *, void *, block_t);
  1559. void write_meta_page(struct f2fs_sb_info *, struct page *);
  1560. void write_node_page(unsigned int, struct f2fs_io_info *);
  1561. void write_data_page(struct dnode_of_data *, struct f2fs_io_info *);
  1562. void rewrite_data_page(struct f2fs_io_info *);
  1563. void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *,
  1564. block_t, block_t, unsigned char, bool);
  1565. void allocate_data_block(struct f2fs_sb_info *, struct page *,
  1566. block_t, block_t *, struct f2fs_summary *, int);
  1567. void f2fs_wait_on_page_writeback(struct page *, enum page_type);
  1568. void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t);
  1569. void write_data_summaries(struct f2fs_sb_info *, block_t);
  1570. void write_node_summaries(struct f2fs_sb_info *, block_t);
  1571. int lookup_journal_in_cursum(struct f2fs_summary_block *,
  1572. int, unsigned int, int);
  1573. void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *);
  1574. int build_segment_manager(struct f2fs_sb_info *);
  1575. void destroy_segment_manager(struct f2fs_sb_info *);
  1576. int __init create_segment_manager_caches(void);
  1577. void destroy_segment_manager_caches(void);
  1578. /*
  1579. * checkpoint.c
  1580. */
  1581. struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
  1582. struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
  1583. struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t);
  1584. bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
  1585. block_t blkaddr, int type);
  1586. int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool);
  1587. void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t);
  1588. long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
  1589. void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
  1590. void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
  1591. void release_dirty_inode(struct f2fs_sb_info *);
  1592. bool exist_written_data(struct f2fs_sb_info *, nid_t, int);
  1593. int acquire_orphan_inode(struct f2fs_sb_info *);
  1594. void release_orphan_inode(struct f2fs_sb_info *);
  1595. void add_orphan_inode(struct f2fs_sb_info *, nid_t);
  1596. void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
  1597. int recover_orphan_inodes(struct f2fs_sb_info *);
  1598. int get_valid_checkpoint(struct f2fs_sb_info *);
  1599. void update_dirty_page(struct inode *, struct page *);
  1600. void remove_dirty_dir_inode(struct inode *);
  1601. void sync_dirty_dir_inodes(struct f2fs_sb_info *);
  1602. void write_checkpoint(struct f2fs_sb_info *, struct cp_control *);
  1603. void init_ino_entry_info(struct f2fs_sb_info *);
  1604. int __init create_checkpoint_caches(void);
  1605. void destroy_checkpoint_caches(void);
  1606. /*
  1607. * data.c
  1608. */
  1609. void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
  1610. int f2fs_submit_page_bio(struct f2fs_io_info *);
  1611. void f2fs_submit_page_mbio(struct f2fs_io_info *);
  1612. void set_data_blkaddr(struct dnode_of_data *);
  1613. int reserve_new_block(struct dnode_of_data *);
  1614. int f2fs_get_block(struct dnode_of_data *, pgoff_t);
  1615. int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
  1616. struct page *get_read_data_page(struct inode *, pgoff_t, int, bool);
  1617. struct page *find_data_page(struct inode *, pgoff_t);
  1618. struct page *get_lock_data_page(struct inode *, pgoff_t, bool);
  1619. struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
  1620. int do_write_data_page(struct f2fs_io_info *);
  1621. int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
  1622. void f2fs_invalidate_page(struct page *, unsigned int, unsigned int);
  1623. int f2fs_release_page(struct page *, gfp_t);
  1624. /*
  1625. * gc.c
  1626. */
  1627. int start_gc_thread(struct f2fs_sb_info *);
  1628. void stop_gc_thread(struct f2fs_sb_info *);
  1629. block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
  1630. int f2fs_gc(struct f2fs_sb_info *, bool);
  1631. void build_gc_manager(struct f2fs_sb_info *);
  1632. /*
  1633. * recovery.c
  1634. */
  1635. int recover_fsync_data(struct f2fs_sb_info *, bool);
  1636. bool space_for_roll_forward(struct f2fs_sb_info *);
  1637. /*
  1638. * debug.c
  1639. */
  1640. #ifdef CONFIG_F2FS_STAT_FS
  1641. struct f2fs_stat_info {
  1642. struct list_head stat_list;
  1643. struct f2fs_sb_info *sbi;
  1644. int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
  1645. int main_area_segs, main_area_sections, main_area_zones;
  1646. unsigned long long hit_largest, hit_cached, hit_rbtree;
  1647. unsigned long long hit_total, total_ext;
  1648. int ext_tree, ext_node;
  1649. int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
  1650. int nats, dirty_nats, sits, dirty_sits, fnids;
  1651. int total_count, utilization;
  1652. int bg_gc, inmem_pages, wb_pages;
  1653. int inline_xattr, inline_inode, inline_dir;
  1654. unsigned int valid_count, valid_node_count, valid_inode_count;
  1655. unsigned int bimodal, avg_vblocks;
  1656. int util_free, util_valid, util_invalid;
  1657. int rsvd_segs, overp_segs;
  1658. int dirty_count, node_pages, meta_pages;
  1659. int prefree_count, call_count, cp_count;
  1660. int tot_segs, node_segs, data_segs, free_segs, free_secs;
  1661. int bg_node_segs, bg_data_segs;
  1662. int tot_blks, data_blks, node_blks;
  1663. int bg_data_blks, bg_node_blks;
  1664. int curseg[NR_CURSEG_TYPE];
  1665. int cursec[NR_CURSEG_TYPE];
  1666. int curzone[NR_CURSEG_TYPE];
  1667. unsigned int segment_count[2];
  1668. unsigned int block_count[2];
  1669. unsigned int inplace_count;
  1670. unsigned long long base_mem, cache_mem, page_mem;
  1671. };
  1672. static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
  1673. {
  1674. return (struct f2fs_stat_info *)sbi->stat_info;
  1675. }
  1676. #define stat_inc_cp_count(si) ((si)->cp_count++)
  1677. #define stat_inc_call_count(si) ((si)->call_count++)
  1678. #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
  1679. #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++)
  1680. #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--)
  1681. #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext))
  1682. #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree))
  1683. #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest))
  1684. #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached))
  1685. #define stat_inc_inline_xattr(inode) \
  1686. do { \
  1687. if (f2fs_has_inline_xattr(inode)) \
  1688. (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \
  1689. } while (0)
  1690. #define stat_dec_inline_xattr(inode) \
  1691. do { \
  1692. if (f2fs_has_inline_xattr(inode)) \
  1693. (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \
  1694. } while (0)
  1695. #define stat_inc_inline_inode(inode) \
  1696. do { \
  1697. if (f2fs_has_inline_data(inode)) \
  1698. (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \
  1699. } while (0)
  1700. #define stat_dec_inline_inode(inode) \
  1701. do { \
  1702. if (f2fs_has_inline_data(inode)) \
  1703. (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \
  1704. } while (0)
  1705. #define stat_inc_inline_dir(inode) \
  1706. do { \
  1707. if (f2fs_has_inline_dentry(inode)) \
  1708. (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \
  1709. } while (0)
  1710. #define stat_dec_inline_dir(inode) \
  1711. do { \
  1712. if (f2fs_has_inline_dentry(inode)) \
  1713. (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \
  1714. } while (0)
  1715. #define stat_inc_seg_type(sbi, curseg) \
  1716. ((sbi)->segment_count[(curseg)->alloc_type]++)
  1717. #define stat_inc_block_count(sbi, curseg) \
  1718. ((sbi)->block_count[(curseg)->alloc_type]++)
  1719. #define stat_inc_inplace_blocks(sbi) \
  1720. (atomic_inc(&(sbi)->inplace_count))
  1721. #define stat_inc_seg_count(sbi, type, gc_type) \
  1722. do { \
  1723. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1724. (si)->tot_segs++; \
  1725. if (type == SUM_TYPE_DATA) { \
  1726. si->data_segs++; \
  1727. si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \
  1728. } else { \
  1729. si->node_segs++; \
  1730. si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \
  1731. } \
  1732. } while (0)
  1733. #define stat_inc_tot_blk_count(si, blks) \
  1734. (si->tot_blks += (blks))
  1735. #define stat_inc_data_blk_count(sbi, blks, gc_type) \
  1736. do { \
  1737. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1738. stat_inc_tot_blk_count(si, blks); \
  1739. si->data_blks += (blks); \
  1740. si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \
  1741. } while (0)
  1742. #define stat_inc_node_blk_count(sbi, blks, gc_type) \
  1743. do { \
  1744. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1745. stat_inc_tot_blk_count(si, blks); \
  1746. si->node_blks += (blks); \
  1747. si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \
  1748. } while (0)
  1749. int f2fs_build_stats(struct f2fs_sb_info *);
  1750. void f2fs_destroy_stats(struct f2fs_sb_info *);
  1751. void __init f2fs_create_root_stats(void);
  1752. void f2fs_destroy_root_stats(void);
  1753. #else
  1754. #define stat_inc_cp_count(si)
  1755. #define stat_inc_call_count(si)
  1756. #define stat_inc_bggc_count(si)
  1757. #define stat_inc_dirty_dir(sbi)
  1758. #define stat_dec_dirty_dir(sbi)
  1759. #define stat_inc_total_hit(sb)
  1760. #define stat_inc_rbtree_node_hit(sb)
  1761. #define stat_inc_largest_node_hit(sbi)
  1762. #define stat_inc_cached_node_hit(sbi)
  1763. #define stat_inc_inline_xattr(inode)
  1764. #define stat_dec_inline_xattr(inode)
  1765. #define stat_inc_inline_inode(inode)
  1766. #define stat_dec_inline_inode(inode)
  1767. #define stat_inc_inline_dir(inode)
  1768. #define stat_dec_inline_dir(inode)
  1769. #define stat_inc_seg_type(sbi, curseg)
  1770. #define stat_inc_block_count(sbi, curseg)
  1771. #define stat_inc_inplace_blocks(sbi)
  1772. #define stat_inc_seg_count(sbi, type, gc_type)
  1773. #define stat_inc_tot_blk_count(si, blks)
  1774. #define stat_inc_data_blk_count(sbi, blks, gc_type)
  1775. #define stat_inc_node_blk_count(sbi, blks, gc_type)
  1776. static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
  1777. static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
  1778. static inline void __init f2fs_create_root_stats(void) { }
  1779. static inline void f2fs_destroy_root_stats(void) { }
  1780. #endif
  1781. extern const struct file_operations f2fs_dir_operations;
  1782. extern const struct file_operations f2fs_file_operations;
  1783. extern const struct inode_operations f2fs_file_inode_operations;
  1784. extern const struct address_space_operations f2fs_dblock_aops;
  1785. extern const struct address_space_operations f2fs_node_aops;
  1786. extern const struct address_space_operations f2fs_meta_aops;
  1787. extern const struct inode_operations f2fs_dir_inode_operations;
  1788. extern const struct inode_operations f2fs_symlink_inode_operations;
  1789. extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
  1790. extern const struct inode_operations f2fs_special_inode_operations;
  1791. extern struct kmem_cache *inode_entry_slab;
  1792. /*
  1793. * inline.c
  1794. */
  1795. bool f2fs_may_inline_data(struct inode *);
  1796. bool f2fs_may_inline_dentry(struct inode *);
  1797. void read_inline_data(struct page *, struct page *);
  1798. bool truncate_inline_inode(struct page *, u64);
  1799. int f2fs_read_inline_data(struct inode *, struct page *);
  1800. int f2fs_convert_inline_page(struct dnode_of_data *, struct page *);
  1801. int f2fs_convert_inline_inode(struct inode *);
  1802. int f2fs_write_inline_data(struct inode *, struct page *);
  1803. bool recover_inline_data(struct inode *, struct page *);
  1804. struct f2fs_dir_entry *find_in_inline_dir(struct inode *,
  1805. struct f2fs_filename *, struct page **);
  1806. struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **);
  1807. int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *);
  1808. int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *,
  1809. nid_t, umode_t);
  1810. void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *,
  1811. struct inode *, struct inode *);
  1812. bool f2fs_empty_inline_dir(struct inode *);
  1813. int f2fs_read_inline_dir(struct file *, struct dir_context *,
  1814. struct f2fs_str *);
  1815. int f2fs_inline_data_fiemap(struct inode *,
  1816. struct fiemap_extent_info *, __u64, __u64);
  1817. /*
  1818. * shrinker.c
  1819. */
  1820. unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *);
  1821. unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *);
  1822. void f2fs_join_shrinker(struct f2fs_sb_info *);
  1823. void f2fs_leave_shrinker(struct f2fs_sb_info *);
  1824. /*
  1825. * extent_cache.c
  1826. */
  1827. unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int);
  1828. void f2fs_drop_largest_extent(struct inode *, pgoff_t);
  1829. void f2fs_init_extent_tree(struct inode *, struct f2fs_extent *);
  1830. unsigned int f2fs_destroy_extent_node(struct inode *);
  1831. void f2fs_destroy_extent_tree(struct inode *);
  1832. bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *);
  1833. void f2fs_update_extent_cache(struct dnode_of_data *);
  1834. void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
  1835. pgoff_t, block_t, unsigned int);
  1836. void init_extent_cache_info(struct f2fs_sb_info *);
  1837. int __init create_extent_cache(void);
  1838. void destroy_extent_cache(void);
  1839. /*
  1840. * crypto support
  1841. */
  1842. static inline int f2fs_encrypted_inode(struct inode *inode)
  1843. {
  1844. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  1845. return file_is_encrypt(inode);
  1846. #else
  1847. return 0;
  1848. #endif
  1849. }
  1850. static inline void f2fs_set_encrypted_inode(struct inode *inode)
  1851. {
  1852. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  1853. file_set_encrypt(inode);
  1854. #endif
  1855. }
  1856. static inline bool f2fs_bio_encrypted(struct bio *bio)
  1857. {
  1858. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  1859. return unlikely(bio->bi_private != NULL);
  1860. #else
  1861. return false;
  1862. #endif
  1863. }
  1864. static inline int f2fs_sb_has_crypto(struct super_block *sb)
  1865. {
  1866. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  1867. return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
  1868. #else
  1869. return 0;
  1870. #endif
  1871. }
  1872. static inline bool f2fs_may_encrypt(struct inode *inode)
  1873. {
  1874. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  1875. mode_t mode = inode->i_mode;
  1876. return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
  1877. #else
  1878. return 0;
  1879. #endif
  1880. }
  1881. /* crypto_policy.c */
  1882. int f2fs_is_child_context_consistent_with_parent(struct inode *,
  1883. struct inode *);
  1884. int f2fs_inherit_context(struct inode *, struct inode *, struct page *);
  1885. int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *);
  1886. int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *);
  1887. /* crypt.c */
  1888. extern struct kmem_cache *f2fs_crypt_info_cachep;
  1889. bool f2fs_valid_contents_enc_mode(uint32_t);
  1890. uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t);
  1891. struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *);
  1892. void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *);
  1893. struct page *f2fs_encrypt(struct inode *, struct page *);
  1894. int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *);
  1895. int f2fs_decrypt_one(struct inode *, struct page *);
  1896. void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *);
  1897. /* crypto_key.c */
  1898. void f2fs_free_encryption_info(struct inode *, struct f2fs_crypt_info *);
  1899. /* crypto_fname.c */
  1900. bool f2fs_valid_filenames_enc_mode(uint32_t);
  1901. u32 f2fs_fname_crypto_round_up(u32, u32);
  1902. int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *);
  1903. int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *,
  1904. const struct f2fs_str *, struct f2fs_str *);
  1905. int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *,
  1906. struct f2fs_str *);
  1907. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  1908. void f2fs_restore_and_release_control_page(struct page **);
  1909. void f2fs_restore_control_page(struct page *);
  1910. int __init f2fs_init_crypto(void);
  1911. int f2fs_crypto_initialize(void);
  1912. void f2fs_exit_crypto(void);
  1913. int f2fs_has_encryption_key(struct inode *);
  1914. int f2fs_get_encryption_info(struct inode *inode);
  1915. void f2fs_fname_crypto_free_buffer(struct f2fs_str *);
  1916. int f2fs_fname_setup_filename(struct inode *, const struct qstr *,
  1917. int lookup, struct f2fs_filename *);
  1918. void f2fs_fname_free_filename(struct f2fs_filename *);
  1919. #else
  1920. static inline void f2fs_restore_and_release_control_page(struct page **p) { }
  1921. static inline void f2fs_restore_control_page(struct page *p) { }
  1922. static inline int __init f2fs_init_crypto(void) { return 0; }
  1923. static inline void f2fs_exit_crypto(void) { }
  1924. static inline int f2fs_has_encryption_key(struct inode *i) { return 0; }
  1925. static inline int f2fs_get_encryption_info(struct inode *i) { return 0; }
  1926. static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { }
  1927. static inline int f2fs_fname_setup_filename(struct inode *dir,
  1928. const struct qstr *iname,
  1929. int lookup, struct f2fs_filename *fname)
  1930. {
  1931. memset(fname, 0, sizeof(struct f2fs_filename));
  1932. fname->usr_fname = iname;
  1933. fname->disk_name.name = (unsigned char *)iname->name;
  1934. fname->disk_name.len = iname->len;
  1935. return 0;
  1936. }
  1937. static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { }
  1938. #endif
  1939. #endif