f2fs.h (31881d74b6dd1a6c530cff61248def4f2da38bee) f2fs.h (7e586fa0244578320fcced9cc08c6b124f727c35)
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

--- 23 unchanged lines hidden (view full) ---

32#define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
33#define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
34#define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
35
36#define ver_after(a, b) (typecheck(unsigned long long, a) && \
37 typecheck(unsigned long long, b) && \
38 ((long long)((a) - (b)) > 0))
39
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

--- 23 unchanged lines hidden (view full) ---

32#define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
33#define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
34#define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
35
36#define ver_after(a, b) (typecheck(unsigned long long, a) && \
37 typecheck(unsigned long long, b) && \
38 ((long long)((a) - (b)) > 0))
39
40typedef u64 block_t;
40typedef u32 block_t; /*
41 * should not change u32, since it is the on-disk block
42 * address format, __le32.
43 */
41typedef u32 nid_t;
42
43struct f2fs_mount_info {
44 unsigned int opt;
45};
46
44typedef u32 nid_t;
45
46struct f2fs_mount_info {
47 unsigned int opt;
48};
49
47static inline __u32 f2fs_crc32(void *buff, size_t len)
50#define CRCPOLY_LE 0xedb88320
51
52static inline __u32 f2fs_crc32(void *buf, size_t len)
48{
53{
49 return crc32_le(F2FS_SUPER_MAGIC, buff, len);
54 unsigned char *p = (unsigned char *)buf;
55 __u32 crc = F2FS_SUPER_MAGIC;
56 int i;
57
58 while (len--) {
59 crc ^= *p++;
60 for (i = 0; i < 8; i++)
61 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
62 }
63 return crc;
50}
51
64}
65
52static inline bool f2fs_crc_valid(__u32 blk_crc, void *buff, size_t buff_size)
66static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
53{
67{
54 return f2fs_crc32(buff, buff_size) == blk_crc;
68 return f2fs_crc32(buf, buf_size) == blk_crc;
55}
56
57/*
58 * For checkpoint manager
59 */
60enum {
61 NAT_BITMAP,
62 SIT_BITMAP

--- 80 unchanged lines hidden (view full) ---

143 u32 blk_addr; /* start block address of the extent */
144 unsigned int len; /* length of the extent */
145};
146
147/*
148 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
149 */
150#define FADVISE_COLD_BIT 0x01
69}
70
71/*
72 * For checkpoint manager
73 */
74enum {
75 NAT_BITMAP,
76 SIT_BITMAP

--- 80 unchanged lines hidden (view full) ---

157 u32 blk_addr; /* start block address of the extent */
158 unsigned int len; /* length of the extent */
159};
160
161/*
162 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
163 */
164#define FADVISE_COLD_BIT 0x01
151#define FADVISE_CP_BIT 0x02
165#define FADVISE_LOST_PINO_BIT 0x02
152
153struct f2fs_inode_info {
154 struct inode vfs_inode; /* serve a vfs inode */
155 unsigned long i_flags; /* keep an inode flags for ioctl */
156 unsigned char i_advise; /* use to give file attribute hints */
157 unsigned int i_current_depth; /* use only in directory structure */
158 unsigned int i_pino; /* parent inode number */
159 umode_t i_acl_mode; /* keep file acl mode temporarily */

--- 204 unchanged lines hidden (view full) ---

364 /* for orphan inode management */
365 struct list_head orphan_inode_list; /* orphan inode list */
366 struct mutex orphan_inode_mutex; /* for orphan inode list */
367 unsigned int n_orphans; /* # of orphan inodes */
368
369 /* for directory inode management */
370 struct list_head dir_inode_list; /* dir inode list */
371 spinlock_t dir_inode_lock; /* for dir inode list lock */
166
167struct f2fs_inode_info {
168 struct inode vfs_inode; /* serve a vfs inode */
169 unsigned long i_flags; /* keep an inode flags for ioctl */
170 unsigned char i_advise; /* use to give file attribute hints */
171 unsigned int i_current_depth; /* use only in directory structure */
172 unsigned int i_pino; /* parent inode number */
173 umode_t i_acl_mode; /* keep file acl mode temporarily */

--- 204 unchanged lines hidden (view full) ---

378 /* for orphan inode management */
379 struct list_head orphan_inode_list; /* orphan inode list */
380 struct mutex orphan_inode_mutex; /* for orphan inode list */
381 unsigned int n_orphans; /* # of orphan inodes */
382
383 /* for directory inode management */
384 struct list_head dir_inode_list; /* dir inode list */
385 spinlock_t dir_inode_lock; /* for dir inode list lock */
372 unsigned int n_dirty_dirs; /* # of dir inodes */
373
374 /* basic file system units */
375 unsigned int log_sectors_per_block; /* log2 sectors per block */
376 unsigned int log_blocksize; /* log2 block size */
377 unsigned int blocksize; /* block size */
378 unsigned int root_ino_num; /* root inode number*/
379 unsigned int node_ino_num; /* node inode number*/
380 unsigned int meta_ino_num; /* meta inode number*/

--- 20 unchanged lines hidden (view full) ---

401 struct mutex gc_mutex; /* mutex for GC */
402 struct f2fs_gc_kthread *gc_thread; /* GC thread */
403 unsigned int cur_victim_sec; /* current victim section num */
404
405 /*
406 * for stat information.
407 * one is for the LFS mode, and the other is for the SSR mode.
408 */
386
387 /* basic file system units */
388 unsigned int log_sectors_per_block; /* log2 sectors per block */
389 unsigned int log_blocksize; /* log2 block size */
390 unsigned int blocksize; /* block size */
391 unsigned int root_ino_num; /* root inode number*/
392 unsigned int node_ino_num; /* node inode number*/
393 unsigned int meta_ino_num; /* meta inode number*/

--- 20 unchanged lines hidden (view full) ---

414 struct mutex gc_mutex; /* mutex for GC */
415 struct f2fs_gc_kthread *gc_thread; /* GC thread */
416 unsigned int cur_victim_sec; /* current victim section num */
417
418 /*
419 * for stat information.
420 * one is for the LFS mode, and the other is for the SSR mode.
421 */
422#ifdef CONFIG_F2FS_STAT_FS
409 struct f2fs_stat_info *stat_info; /* FS status information */
410 unsigned int segment_count[2]; /* # of allocated segments */
411 unsigned int block_count[2]; /* # of allocated blocks */
423 struct f2fs_stat_info *stat_info; /* FS status information */
424 unsigned int segment_count[2]; /* # of allocated segments */
425 unsigned int block_count[2]; /* # of allocated blocks */
412 unsigned int last_victim[2]; /* last victim segment # */
413 int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
414 int bg_gc; /* background gc calls */
426 int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
427 int bg_gc; /* background gc calls */
428 unsigned int n_dirty_dirs; /* # of dir inodes */
429#endif
430 unsigned int last_victim[2]; /* last victim segment # */
415 spinlock_t stat_lock; /* lock for stat operations */
416};
417
418/*
419 * Inline functions
420 */
421static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
422{

--- 67 unchanged lines hidden (view full) ---

490{
491 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
492 ckpt_flags &= (~f);
493 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
494}
495
496static inline void mutex_lock_all(struct f2fs_sb_info *sbi)
497{
431 spinlock_t stat_lock; /* lock for stat operations */
432};
433
434/*
435 * Inline functions
436 */
437static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
438{

--- 67 unchanged lines hidden (view full) ---

506{
507 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
508 ckpt_flags &= (~f);
509 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
510}
511
512static inline void mutex_lock_all(struct f2fs_sb_info *sbi)
513{
498 int i = 0;
499 for (; i < NR_GLOBAL_LOCKS; i++)
500 mutex_lock(&sbi->fs_lock[i]);
514 int i;
515
516 for (i = 0; i < NR_GLOBAL_LOCKS; i++) {
517 /*
518 * This is the only time we take multiple fs_lock[]
519 * instances; the order is immaterial since we
520 * always hold cp_mutex, which serializes multiple
521 * such operations.
522 */
523 mutex_lock_nest_lock(&sbi->fs_lock[i], &sbi->cp_mutex);
524 }
501}
502
503static inline void mutex_unlock_all(struct f2fs_sb_info *sbi)
504{
505 int i = 0;
506 for (; i < NR_GLOBAL_LOCKS; i++)
507 mutex_unlock(&sbi->fs_lock[i]);
508}

--- 329 unchanged lines hidden (view full) ---

838 ret = mask & *addr;
839 *addr &= ~mask;
840 return ret;
841}
842
843/* used for f2fs_inode_info->flags */
844enum {
845 FI_NEW_INODE, /* indicate newly allocated inode */
525}
526
527static inline void mutex_unlock_all(struct f2fs_sb_info *sbi)
528{
529 int i = 0;
530 for (; i < NR_GLOBAL_LOCKS; i++)
531 mutex_unlock(&sbi->fs_lock[i]);
532}

--- 329 unchanged lines hidden (view full) ---

862 ret = mask & *addr;
863 *addr &= ~mask;
864 return ret;
865}
866
867/* used for f2fs_inode_info->flags */
868enum {
869 FI_NEW_INODE, /* indicate newly allocated inode */
870 FI_DIRTY_INODE, /* indicate inode is dirty or not */
846 FI_INC_LINK, /* need to increment i_nlink */
847 FI_ACL_MODE, /* indicate acl mode */
848 FI_NO_ALLOC, /* should not allocate any blocks */
871 FI_INC_LINK, /* need to increment i_nlink */
872 FI_ACL_MODE, /* indicate acl mode */
873 FI_NO_ALLOC, /* should not allocate any blocks */
874 FI_UPDATE_DIR, /* should update inode block for consistency */
875 FI_DELAY_IPUT, /* used for the recovery */
849};
850
851static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
852{
853 set_bit(flag, &fi->flags);
854}
855
856static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)

--- 16 unchanged lines hidden (view full) ---

873{
874 if (is_inode_flag_set(fi, FI_ACL_MODE)) {
875 clear_inode_flag(fi, FI_ACL_MODE);
876 return 1;
877 }
878 return 0;
879}
880
876};
877
878static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
879{
880 set_bit(flag, &fi->flags);
881}
882
883static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)

--- 16 unchanged lines hidden (view full) ---

900{
901 if (is_inode_flag_set(fi, FI_ACL_MODE)) {
902 clear_inode_flag(fi, FI_ACL_MODE);
903 return 1;
904 }
905 return 0;
906}
907
908static inline int f2fs_readonly(struct super_block *sb)
909{
910 return sb->s_flags & MS_RDONLY;
911}
912
881/*
882 * file.c
883 */
884int f2fs_sync_file(struct file *, loff_t, loff_t, int);
885void truncate_data_blocks(struct dnode_of_data *);
886void f2fs_truncate(struct inode *);
913/*
914 * file.c
915 */
916int f2fs_sync_file(struct file *, loff_t, loff_t, int);
917void truncate_data_blocks(struct dnode_of_data *);
918void f2fs_truncate(struct inode *);
919int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
887int f2fs_setattr(struct dentry *, struct iattr *);
888int truncate_hole(struct inode *, pgoff_t, pgoff_t);
920int f2fs_setattr(struct dentry *, struct iattr *);
921int truncate_hole(struct inode *, pgoff_t, pgoff_t);
922int truncate_data_blocks_range(struct dnode_of_data *, int);
889long f2fs_ioctl(struct file *, unsigned int, unsigned long);
890long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
891
892/*
893 * inode.c
894 */
895void f2fs_set_inode_flags(struct inode *);
896struct inode *f2fs_iget(struct super_block *, unsigned long);

--- 11 unchanged lines hidden (view full) ---

908 * dir.c
909 */
910struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
911 struct page **);
912struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
913ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
914void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
915 struct page *, struct inode *);
923long f2fs_ioctl(struct file *, unsigned int, unsigned long);
924long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
925
926/*
927 * inode.c
928 */
929void f2fs_set_inode_flags(struct inode *);
930struct inode *f2fs_iget(struct super_block *, unsigned long);

--- 11 unchanged lines hidden (view full) ---

942 * dir.c
943 */
944struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
945 struct page **);
946struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
947ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
948void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
949 struct page *, struct inode *);
916void init_dent_inode(const struct qstr *, struct page *);
917int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
918void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
919int f2fs_make_empty(struct inode *, struct inode *);
920bool f2fs_empty_dir(struct inode *);
921
922static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
923{
924 return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,

--- 18 unchanged lines hidden (view full) ---

943struct dnode_of_data;
944struct node_info;
945
946int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
947void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
948int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
949int truncate_inode_blocks(struct inode *, pgoff_t);
950int remove_inode_page(struct inode *);
950int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
951void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
952int f2fs_make_empty(struct inode *, struct inode *);
953bool f2fs_empty_dir(struct inode *);
954
955static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
956{
957 return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,

--- 18 unchanged lines hidden (view full) ---

976struct dnode_of_data;
977struct node_info;
978
979int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
980void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
981int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
982int truncate_inode_blocks(struct inode *, pgoff_t);
983int remove_inode_page(struct inode *);
951int new_inode_page(struct inode *, const struct qstr *);
952struct page *new_node_page(struct dnode_of_data *, unsigned int);
984struct page *new_inode_page(struct inode *, const struct qstr *);
985struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
953void ra_node_page(struct f2fs_sb_info *, nid_t);
954struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
955struct page *get_node_page_ra(struct page *, int);
956void sync_inode_page(struct dnode_of_data *);
957int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
958bool alloc_nid(struct f2fs_sb_info *, nid_t *);
959void alloc_nid_done(struct f2fs_sb_info *, nid_t);
960void alloc_nid_failed(struct f2fs_sb_info *, nid_t);

--- 8 unchanged lines hidden (view full) ---

969int __init create_node_manager_caches(void);
970void destroy_node_manager_caches(void);
971
972/*
973 * segment.c
974 */
975void f2fs_balance_fs(struct f2fs_sb_info *);
976void invalidate_blocks(struct f2fs_sb_info *, block_t);
986void ra_node_page(struct f2fs_sb_info *, nid_t);
987struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
988struct page *get_node_page_ra(struct page *, int);
989void sync_inode_page(struct dnode_of_data *);
990int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
991bool alloc_nid(struct f2fs_sb_info *, nid_t *);
992void alloc_nid_done(struct f2fs_sb_info *, nid_t);
993void alloc_nid_failed(struct f2fs_sb_info *, nid_t);

--- 8 unchanged lines hidden (view full) ---

1002int __init create_node_manager_caches(void);
1003void destroy_node_manager_caches(void);
1004
1005/*
1006 * segment.c
1007 */
1008void f2fs_balance_fs(struct f2fs_sb_info *);
1009void invalidate_blocks(struct f2fs_sb_info *, block_t);
977void locate_dirty_segment(struct f2fs_sb_info *, unsigned int);
978void clear_prefree_segments(struct f2fs_sb_info *);
979int npages_for_summary_flush(struct f2fs_sb_info *);
980void allocate_new_segments(struct f2fs_sb_info *);
981struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
982struct bio *f2fs_bio_alloc(struct block_device *, int);
983void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool sync);
984void write_meta_page(struct f2fs_sb_info *, struct page *);
985void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,

--- 20 unchanged lines hidden (view full) ---

1006struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
1007long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
1008int check_orphan_space(struct f2fs_sb_info *);
1009void add_orphan_inode(struct f2fs_sb_info *, nid_t);
1010void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
1011int recover_orphan_inodes(struct f2fs_sb_info *);
1012int get_valid_checkpoint(struct f2fs_sb_info *);
1013void set_dirty_dir_page(struct inode *, struct page *);
1010void clear_prefree_segments(struct f2fs_sb_info *);
1011int npages_for_summary_flush(struct f2fs_sb_info *);
1012void allocate_new_segments(struct f2fs_sb_info *);
1013struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
1014struct bio *f2fs_bio_alloc(struct block_device *, int);
1015void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool sync);
1016void write_meta_page(struct f2fs_sb_info *, struct page *);
1017void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,

--- 20 unchanged lines hidden (view full) ---

1038struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
1039long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
1040int check_orphan_space(struct f2fs_sb_info *);
1041void add_orphan_inode(struct f2fs_sb_info *, nid_t);
1042void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
1043int recover_orphan_inodes(struct f2fs_sb_info *);
1044int get_valid_checkpoint(struct f2fs_sb_info *);
1045void set_dirty_dir_page(struct inode *, struct page *);
1046void add_dirty_dir_inode(struct inode *);
1014void remove_dirty_dir_inode(struct inode *);
1047void remove_dirty_dir_inode(struct inode *);
1048struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
1015void sync_dirty_dir_inodes(struct f2fs_sb_info *);
1016void write_checkpoint(struct f2fs_sb_info *, bool);
1017void init_orphan_info(struct f2fs_sb_info *);
1018int __init create_checkpoint_caches(void);
1019void destroy_checkpoint_caches(void);
1020
1021/*
1022 * data.c
1023 */
1024int reserve_new_block(struct dnode_of_data *);
1025void update_extent_cache(block_t, struct dnode_of_data *);
1026struct page *find_data_page(struct inode *, pgoff_t, bool);
1027struct page *get_lock_data_page(struct inode *, pgoff_t);
1049void sync_dirty_dir_inodes(struct f2fs_sb_info *);
1050void write_checkpoint(struct f2fs_sb_info *, bool);
1051void init_orphan_info(struct f2fs_sb_info *);
1052int __init create_checkpoint_caches(void);
1053void destroy_checkpoint_caches(void);
1054
1055/*
1056 * data.c
1057 */
1058int reserve_new_block(struct dnode_of_data *);
1059void update_extent_cache(block_t, struct dnode_of_data *);
1060struct page *find_data_page(struct inode *, pgoff_t, bool);
1061struct page *get_lock_data_page(struct inode *, pgoff_t);
1028struct page *get_new_data_page(struct inode *, pgoff_t, bool);
1062struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
1029int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
1030int do_write_data_page(struct page *);
1031
1032/*
1033 * gc.c
1034 */
1035int start_gc_thread(struct f2fs_sb_info *);
1036void stop_gc_thread(struct f2fs_sb_info *);

--- 100 unchanged lines hidden ---
1063int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
1064int do_write_data_page(struct page *);
1065
1066/*
1067 * gc.c
1068 */
1069int start_gc_thread(struct f2fs_sb_info *);
1070void stop_gc_thread(struct f2fs_sb_info *);

--- 100 unchanged lines hidden ---