~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/f2fs/f2fs.h

Version: ~ [ linux-5.12 ] ~ [ linux-5.11.16 ] ~ [ linux-5.10.32 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.114 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.188 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.231 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.267 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.267 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp