1
2
3
4
5
6
7
8 #ifndef _LINUX_F2FS_FS_H
9 #define _LINUX_F2FS_FS_H
10
11 #include <linux/pagemap.h>
12 #include <linux/types.h>
13
14 #define F2FS_SUPER_OFFSET 1024
15 #define F2FS_MIN_LOG_SECTOR_SIZE 9
16 #define F2FS_MAX_LOG_SECTOR_SIZE 12
17 #define F2FS_LOG_SECTORS_PER_BLOCK 3
18 #define F2FS_BLKSIZE 4096
19 #define F2FS_BLKSIZE_BITS 12
20 #define F2FS_MAX_EXTENSION 64
21 #define F2FS_EXTENSION_LEN 8
22 #define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) >> F2FS_BLKSIZE_BITS)
23
24 #define NULL_ADDR ((block_t)0)
25 #define NEW_ADDR ((block_t)-1)
26
27 #define F2FS_BYTES_TO_BLK(bytes) ((bytes) >> F2FS_BLKSIZE_BITS)
28 #define F2FS_BLK_TO_BYTES(blk) ((blk) << F2FS_BLKSIZE_BITS)
29
30
31 #define F2FS_RESERVED_NODE_NUM 3
32
33 #define F2FS_ROOT_INO(sbi) ((sbi)->root_ino_num)
34 #define F2FS_NODE_INO(sbi) ((sbi)->node_ino_num)
35 #define F2FS_META_INO(sbi) ((sbi)->meta_ino_num)
36
37 #define F2FS_MAX_QUOTAS 3
38
39 #define F2FS_ENC_UTF8_12_1 1
40 #define F2FS_ENC_STRICT_MODE_FL (1 << 0)
41 #define f2fs_has_strict_mode(sbi) \
42 (sbi->s_encoding_flags & F2FS_ENC_STRICT_MODE_FL)
43
44 #define F2FS_IO_SIZE(sbi) (1 << F2FS_OPTION(sbi).write_io_size_bits)
45 #define F2FS_IO_SIZE_KB(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2))
46 #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12))
47 #define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits)
48 #define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1)
49 #define F2FS_IO_ALIGNED(sbi) (F2FS_IO_SIZE(sbi) > 1)
50
51
52 #define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO)
53
54
55
56
57
58
59
60 #define MAX_ACTIVE_LOGS 16
61 #define MAX_ACTIVE_NODE_LOGS 8
62 #define MAX_ACTIVE_DATA_LOGS 8
63
64 #define VERSION_LEN 256
65 #define MAX_VOLUME_NAME 512
66 #define MAX_PATH_LEN 64
67 #define MAX_DEVICES 8
68
69
70
71
72 struct f2fs_device {
73 __u8 path[MAX_PATH_LEN];
74 __le32 total_segments;
75 } __packed;
76
77 struct f2fs_super_block {
78 __le32 magic;
79 __le16 major_ver;
80 __le16 minor_ver;
81 __le32 log_sectorsize;
82 __le32 log_sectors_per_block;
83 __le32 log_blocksize;
84 __le32 log_blocks_per_seg;
85 __le32 segs_per_sec;
86 __le32 secs_per_zone;
87 __le32 checksum_offset;
88 __le64 block_count;
89 __le32 section_count;
90 __le32 segment_count;
91 __le32 segment_count_ckpt;
92 __le32 segment_count_sit;
93 __le32 segment_count_nat;
94 __le32 segment_count_ssa;
95 __le32 segment_count_main;
96 __le32 segment0_blkaddr;
97 __le32 cp_blkaddr;
98 __le32 sit_blkaddr;
99 __le32 nat_blkaddr;
100 __le32 ssa_blkaddr;
101 __le32 main_blkaddr;
102 __le32 root_ino;
103 __le32 node_ino;
104 __le32 meta_ino;
105 __u8 uuid[16];
106 __le16 volume_name[MAX_VOLUME_NAME];
107 __le32 extension_count;
108 __u8 extension_list[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];
109 __le32 cp_payload;
110 __u8 version[VERSION_LEN];
111 __u8 init_version[VERSION_LEN];
112 __le32 feature;
113 __u8 encryption_level;
114 __u8 encrypt_pw_salt[16];
115 struct f2fs_device devs[MAX_DEVICES];
116 __le32 qf_ino[F2FS_MAX_QUOTAS];
117 __u8 hot_ext_count;
118 __le16 s_encoding;
119 __le16 s_encoding_flags;
120 __u8 reserved[306];
121 __le32 crc;
122 } __packed;
123
124
125
126
127 #define CP_RESIZEFS_FLAG 0x00004000
128 #define CP_DISABLED_QUICK_FLAG 0x00002000
129 #define CP_DISABLED_FLAG 0x00001000
130 #define CP_QUOTA_NEED_FSCK_FLAG 0x00000800
131 #define CP_LARGE_NAT_BITMAP_FLAG 0x00000400
132 #define CP_NOCRC_RECOVERY_FLAG 0x00000200
133 #define CP_TRIMMED_FLAG 0x00000100
134 #define CP_NAT_BITS_FLAG 0x00000080
135 #define CP_CRC_RECOVERY_FLAG 0x00000040
136 #define CP_FASTBOOT_FLAG 0x00000020
137 #define CP_FSCK_FLAG 0x00000010
138 #define CP_ERROR_FLAG 0x00000008
139 #define CP_COMPACT_SUM_FLAG 0x00000004
140 #define CP_ORPHAN_PRESENT_FLAG 0x00000002
141 #define CP_UMOUNT_FLAG 0x00000001
142
143 #define F2FS_CP_PACKS 2
144
145 struct f2fs_checkpoint {
146 __le64 checkpoint_ver;
147 __le64 user_block_count;
148 __le64 valid_block_count;
149 __le32 rsvd_segment_count;
150 __le32 overprov_segment_count;
151 __le32 free_segment_count;
152
153
154 __le32 cur_node_segno[MAX_ACTIVE_NODE_LOGS];
155 __le16 cur_node_blkoff[MAX_ACTIVE_NODE_LOGS];
156
157 __le32 cur_data_segno[MAX_ACTIVE_DATA_LOGS];
158 __le16 cur_data_blkoff[MAX_ACTIVE_DATA_LOGS];
159 __le32 ckpt_flags;
160 __le32 cp_pack_total_block_count;
161 __le32 cp_pack_start_sum;
162 __le32 valid_node_count;
163 __le32 valid_inode_count;
164 __le32 next_free_nid;
165 __le32 sit_ver_bitmap_bytesize;
166 __le32 nat_ver_bitmap_bytesize;
167 __le32 checksum_offset;
168 __le64 elapsed_time;
169
170 unsigned char alloc_type[MAX_ACTIVE_LOGS];
171
172
173 unsigned char sit_nat_version_bitmap[1];
174 } __packed;
175
176 #define CP_CHKSUM_OFFSET 4092
177 #define CP_MIN_CHKSUM_OFFSET \
178 (offsetof(struct f2fs_checkpoint, sit_nat_version_bitmap))
179
180
181
182
183 #define F2FS_ORPHANS_PER_BLOCK 1020
184
185 #define GET_ORPHAN_BLOCKS(n) (((n) + F2FS_ORPHANS_PER_BLOCK - 1) / \
186 F2FS_ORPHANS_PER_BLOCK)
187
188 struct f2fs_orphan_block {
189 __le32 ino[F2FS_ORPHANS_PER_BLOCK];
190 __le32 reserved;
191 __le16 blk_addr;
192 __le16 blk_count;
193 __le32 entry_count;
194 __le32 check_sum;
195 } __packed;
196
197
198
199
200 struct f2fs_extent {
201 __le32 fofs;
202 __le32 blk;
203 __le32 len;
204 } __packed;
205
206 #define F2FS_NAME_LEN 255
207
208 #define DEFAULT_INLINE_XATTR_ADDRS 50
209 #define DEF_ADDRS_PER_INODE 923
210 #define CUR_ADDRS_PER_INODE(inode) (DEF_ADDRS_PER_INODE - \
211 get_extra_isize(inode))
212 #define DEF_NIDS_PER_INODE 5
213 #define ADDRS_PER_INODE(inode) addrs_per_inode(inode)
214 #define DEF_ADDRS_PER_BLOCK 1018
215 #define ADDRS_PER_BLOCK(inode) addrs_per_block(inode)
216 #define NIDS_PER_BLOCK 1018
217
218 #define ADDRS_PER_PAGE(page, inode) \
219 (IS_INODE(page) ? ADDRS_PER_INODE(inode) : ADDRS_PER_BLOCK(inode))
220
221 #define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1)
222 #define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2)
223 #define NODE_IND1_BLOCK (DEF_ADDRS_PER_INODE + 3)
224 #define NODE_IND2_BLOCK (DEF_ADDRS_PER_INODE + 4)
225 #define NODE_DIND_BLOCK (DEF_ADDRS_PER_INODE + 5)
226
227 #define F2FS_INLINE_XATTR 0x01
228 #define F2FS_INLINE_DATA 0x02
229 #define F2FS_INLINE_DENTRY 0x04
230 #define F2FS_DATA_EXIST 0x08
231 #define F2FS_INLINE_DOTS 0x10
232 #define F2FS_EXTRA_ATTR 0x20
233 #define F2FS_PIN_FILE 0x40
234
235 struct f2fs_inode {
236 __le16 i_mode;
237 __u8 i_advise;
238 __u8 i_inline;
239 __le32 i_uid;
240 __le32 i_gid;
241 __le32 i_links;
242 __le64 i_size;
243 __le64 i_blocks;
244 __le64 i_atime;
245 __le64 i_ctime;
246 __le64 i_mtime;
247 __le32 i_atime_nsec;
248 __le32 i_ctime_nsec;
249 __le32 i_mtime_nsec;
250 __le32 i_generation;
251 union {
252 __le32 i_current_depth;
253 __le16 i_gc_failures;
254
255
256
257 };
258 __le32 i_xattr_nid;
259 __le32 i_flags;
260 __le32 i_pino;
261 __le32 i_namelen;
262 __u8 i_name[F2FS_NAME_LEN];
263 __u8 i_dir_level;
264
265 struct f2fs_extent i_ext;
266
267 union {
268 struct {
269 __le16 i_extra_isize;
270 __le16 i_inline_xattr_size;
271 __le32 i_projid;
272 __le32 i_inode_checksum;
273 __le64 i_crtime;
274 __le32 i_crtime_nsec;
275 __le32 i_extra_end[0];
276 } __packed;
277 __le32 i_addr[DEF_ADDRS_PER_INODE];
278 };
279 __le32 i_nid[DEF_NIDS_PER_INODE];
280
281 } __packed;
282
283 struct direct_node {
284 __le32 addr[DEF_ADDRS_PER_BLOCK];
285 } __packed;
286
287 struct indirect_node {
288 __le32 nid[NIDS_PER_BLOCK];
289 } __packed;
290
291 enum {
292 COLD_BIT_SHIFT = 0,
293 FSYNC_BIT_SHIFT,
294 DENT_BIT_SHIFT,
295 OFFSET_BIT_SHIFT
296 };
297
298 #define OFFSET_BIT_MASK (0x07)
299
300 struct node_footer {
301 __le32 nid;
302 __le32 ino;
303 __le32 flag;
304 __le64 cp_ver;
305 __le32 next_blkaddr;
306 } __packed;
307
308 struct f2fs_node {
309
310 union {
311 struct f2fs_inode i;
312 struct direct_node dn;
313 struct indirect_node in;
314 };
315 struct node_footer footer;
316 } __packed;
317
318
319
320
321 #define NAT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_nat_entry))
322
323 struct f2fs_nat_entry {
324 __u8 version;
325 __le32 ino;
326 __le32 block_addr;
327 } __packed;
328
329 struct f2fs_nat_block {
330 struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK];
331 } __packed;
332
333
334
335
336
337
338
339
340 #define SIT_VBLOCK_MAP_SIZE 64
341 #define SIT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_sit_entry))
342
343
344
345
346
347 #define F2FS_MAX_SEGMENT ((16 * 1024 * 1024) / 2)
348
349
350
351
352
353
354 #define SIT_VBLOCKS_SHIFT 10
355 #define SIT_VBLOCKS_MASK ((1 << SIT_VBLOCKS_SHIFT) - 1)
356 #define GET_SIT_VBLOCKS(raw_sit) \
357 (le16_to_cpu((raw_sit)->vblocks) & SIT_VBLOCKS_MASK)
358 #define GET_SIT_TYPE(raw_sit) \
359 ((le16_to_cpu((raw_sit)->vblocks) & ~SIT_VBLOCKS_MASK) \
360 >> SIT_VBLOCKS_SHIFT)
361
362 struct f2fs_sit_entry {
363 __le16 vblocks;
364 __u8 valid_map[SIT_VBLOCK_MAP_SIZE];
365 __le64 mtime;
366 } __packed;
367
368 struct f2fs_sit_block {
369 struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK];
370 } __packed;
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387 #define ENTRIES_IN_SUM 512
388 #define SUMMARY_SIZE (7)
389 #define SUM_FOOTER_SIZE (5)
390 #define SUM_ENTRY_SIZE (SUMMARY_SIZE * ENTRIES_IN_SUM)
391
392
393 struct f2fs_summary {
394 __le32 nid;
395 union {
396 __u8 reserved[3];
397 struct {
398 __u8 version;
399 __le16 ofs_in_node;
400 } __packed;
401 };
402 } __packed;
403
404
405 #define SUM_TYPE_NODE (1)
406 #define SUM_TYPE_DATA (0)
407
408 struct summary_footer {
409 unsigned char entry_type;
410 __le32 check_sum;
411 } __packed;
412
413 #define SUM_JOURNAL_SIZE (F2FS_BLKSIZE - SUM_FOOTER_SIZE -\
414 SUM_ENTRY_SIZE)
415 #define NAT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\
416 sizeof(struct nat_journal_entry))
417 #define NAT_JOURNAL_RESERVED ((SUM_JOURNAL_SIZE - 2) %\
418 sizeof(struct nat_journal_entry))
419 #define SIT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\
420 sizeof(struct sit_journal_entry))
421 #define SIT_JOURNAL_RESERVED ((SUM_JOURNAL_SIZE - 2) %\
422 sizeof(struct sit_journal_entry))
423
424
425
426
427 #define EXTRA_INFO_RESERVED (SUM_JOURNAL_SIZE - 2 - 8)
428
429
430
431
432
433 enum {
434 NAT_JOURNAL = 0,
435 SIT_JOURNAL
436 };
437
438 struct nat_journal_entry {
439 __le32 nid;
440 struct f2fs_nat_entry ne;
441 } __packed;
442
443 struct nat_journal {
444 struct nat_journal_entry entries[NAT_JOURNAL_ENTRIES];
445 __u8 reserved[NAT_JOURNAL_RESERVED];
446 } __packed;
447
448 struct sit_journal_entry {
449 __le32 segno;
450 struct f2fs_sit_entry se;
451 } __packed;
452
453 struct sit_journal {
454 struct sit_journal_entry entries[SIT_JOURNAL_ENTRIES];
455 __u8 reserved[SIT_JOURNAL_RESERVED];
456 } __packed;
457
458 struct f2fs_extra_info {
459 __le64 kbytes_written;
460 __u8 reserved[EXTRA_INFO_RESERVED];
461 } __packed;
462
463 struct f2fs_journal {
464 union {
465 __le16 n_nats;
466 __le16 n_sits;
467 };
468
469 union {
470 struct nat_journal nat_j;
471 struct sit_journal sit_j;
472 struct f2fs_extra_info info;
473 };
474 } __packed;
475
476
477 struct f2fs_summary_block {
478 struct f2fs_summary entries[ENTRIES_IN_SUM];
479 struct f2fs_journal journal;
480 struct summary_footer footer;
481 } __packed;
482
483
484
485
486 #define F2FS_DOT_HASH 0
487 #define F2FS_DDOT_HASH F2FS_DOT_HASH
488 #define F2FS_MAX_HASH (~((0x3ULL) << 62))
489 #define F2FS_HASH_COL_BIT ((0x1ULL) << 63)
490
491 typedef __le32 f2fs_hash_t;
492
493
494 #define F2FS_SLOT_LEN 8
495 #define F2FS_SLOT_LEN_BITS 3
496
497 #define GET_DENTRY_SLOTS(x) (((x) + F2FS_SLOT_LEN - 1) >> F2FS_SLOT_LEN_BITS)
498
499
500 #define MAX_DIR_HASH_DEPTH 63
501
502
503 #define MAX_DIR_BUCKETS (1 << ((MAX_DIR_HASH_DEPTH / 2) - 1))
504
505
506
507
508
509
510
511
512
513
514
515
516
517 #define NR_DENTRY_IN_BLOCK 214
518 #define SIZE_OF_DIR_ENTRY 11
519 #define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \
520 BITS_PER_BYTE)
521 #define SIZE_OF_RESERVED (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \
522 F2FS_SLOT_LEN) * \
523 NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP))
524 #define MIN_INLINE_DENTRY_SIZE 40
525
526
527 struct f2fs_dir_entry {
528 __le32 hash_code;
529 __le32 ino;
530 __le16 name_len;
531 __u8 file_type;
532 } __packed;
533
534
535 struct f2fs_dentry_block {
536
537 __u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP];
538 __u8 reserved[SIZE_OF_RESERVED];
539 struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK];
540 __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN];
541 } __packed;
542
543
544 enum {
545 F2FS_FT_UNKNOWN,
546 F2FS_FT_REG_FILE,
547 F2FS_FT_DIR,
548 F2FS_FT_CHRDEV,
549 F2FS_FT_BLKDEV,
550 F2FS_FT_FIFO,
551 F2FS_FT_SOCK,
552 F2FS_FT_SYMLINK,
553 F2FS_FT_MAX
554 };
555
556 #define S_SHIFT 12
557
558 #define F2FS_DEF_PROJID 0
559
560 #endif