f2fs_fs.h revision de6c1c7ce25841547813c71ca3b6d067300f0530
1/** 2 * f2fs_fs.h 3 * 4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 5 * http://www.samsung.com/ 6 * 7 * Dual licensed under the GPL or LGPL version 2 licenses. 8 */ 9#ifndef __F2FS_FS_H__ 10#define __F2FS_FS_H__ 11 12#include <inttypes.h> 13#include <linux/types.h> 14#include <sys/types.h> 15 16#ifdef HAVE_CONFIG_H 17#include <config.h> 18#endif 19 20typedef u_int64_t u64; 21typedef u_int32_t u32; 22typedef u_int16_t u16; 23typedef u_int8_t u8; 24typedef u32 block_t; 25typedef u32 nid_t; 26typedef u8 bool; 27typedef unsigned long pgoff_t; 28 29#if __BYTE_ORDER == __LITTLE_ENDIAN 30#define le16_to_cpu(x) ((__u16)(x)) 31#define le32_to_cpu(x) ((__u32)(x)) 32#define le64_to_cpu(x) ((__u64)(x)) 33#define cpu_to_le16(x) ((__u16)(x)) 34#define cpu_to_le32(x) ((__u32)(x)) 35#define cpu_to_le64(x) ((__u64)(x)) 36#elif __BYTE_ORDER == __BIG_ENDIAN 37#define le16_to_cpu(x) bswap_16(x) 38#define le32_to_cpu(x) bswap_32(x) 39#define le64_to_cpu(x) bswap_64(x) 40#define cpu_to_le16(x) bswap_16(x) 41#define cpu_to_le32(x) bswap_32(x) 42#define cpu_to_le64(x) bswap_64(x) 43#endif 44 45#define typecheck(type,x) \ 46 ({ type __dummy; \ 47 typeof(x) __dummy2; \ 48 (void)(&__dummy == &__dummy2); \ 49 1; \ 50 }) 51 52#define NULL_SEGNO ((unsigned int)~0) 53 54/* 55 * Debugging interfaces 56 */ 57#define FIX_MSG(fmt, ...) \ 58 do { \ 59 printf("[FIX] (%s:%4d) ", __func__, __LINE__); \ 60 printf(" --> "fmt"\n", ##__VA_ARGS__); \ 61 } while (0) 62 63#define ASSERT_MSG(fmt, ...) \ 64 do { \ 65 printf("[ASSERT] (%s:%4d) ", __func__, __LINE__); \ 66 printf(" --> "fmt"\n", ##__VA_ARGS__); \ 67 config.bug_on = 1; \ 68 } while (0) 69 70#define ASSERT(exp) \ 71 do { \ 72 if (!(exp)) { \ 73 printf("[ASSERT] (%s:%4d) " #exp"\n", \ 74 __func__, __LINE__); \ 75 exit(-1); \ 76 } \ 77 } while (0) 78 79#define ERR_MSG(fmt, ...) \ 80 do { \ 81 printf("[%s:%d] " fmt, __func__, __LINE__, ##__VA_ARGS__); \ 82 } while (0) 83 84#define MSG(n, fmt, ...) \ 85 do { \ 86 if (config.dbg_lv >= n) { \ 87 printf(fmt, ##__VA_ARGS__); \ 88 } \ 89 } while (0) 90 91#define DBG(n, fmt, ...) \ 92 do { \ 93 if (config.dbg_lv >= n) { \ 94 printf("[%s:%4d] " fmt, \ 95 __func__, __LINE__, ##__VA_ARGS__); \ 96 } \ 97 } while (0) 98 99/* Display on console */ 100#define DISP(fmt, ptr, member) \ 101 do { \ 102 printf("%-30s" fmt, #member, ((ptr)->member)); \ 103 } while (0) 104 105#define DISP_u32(ptr, member) \ 106 do { \ 107 assert(sizeof((ptr)->member) <= 4); \ 108 printf("%-30s" "\t\t[0x%8x : %u]\n", \ 109 #member, ((ptr)->member), ((ptr)->member)); \ 110 } while (0) 111 112#define DISP_u64(ptr, member) \ 113 do { \ 114 assert(sizeof((ptr)->member) == 8); \ 115 printf("%-30s" "\t\t[0x%8llx : %llu]\n", \ 116 #member, ((ptr)->member), ((ptr)->member)); \ 117 } while (0) 118 119#define DISP_utf(ptr, member) \ 120 do { \ 121 printf("%-30s" "\t\t[%s]\n", #member, ((ptr)->member)); \ 122 } while (0) 123 124/* Display to buffer */ 125#define BUF_DISP_u32(buf, data, len, ptr, member) \ 126 do { \ 127 assert(sizeof((ptr)->member) <= 4); \ 128 snprintf(buf, len, #member); \ 129 snprintf(data, len, "0x%x : %u", ((ptr)->member), \ 130 ((ptr)->member)); \ 131 } while (0) 132 133#define BUF_DISP_u64(buf, data, len, ptr, member) \ 134 do { \ 135 assert(sizeof((ptr)->member) == 8); \ 136 snprintf(buf, len, #member); \ 137 snprintf(data, len, "0x%llx : %llu", ((ptr)->member), \ 138 ((ptr)->member)); \ 139 } while (0) 140 141#define BUF_DISP_utf(buf, data, len, ptr, member) \ 142 snprintf(buf, len, #member) 143 144/* these are defined in kernel */ 145#define PAGE_SIZE 4096 146#define PAGE_CACHE_SIZE 4096 147#define BITS_PER_BYTE 8 148#define F2FS_SUPER_MAGIC 0xF2F52010 /* F2FS Magic Number */ 149#define CHECKSUM_OFFSET 4092 150 151/* for mkfs */ 152#define F2FS_MIN_VOLUME_SIZE 104857600 153#define F2FS_NUMBER_OF_CHECKPOINT_PACK 2 154#define DEFAULT_SECTOR_SIZE 512 155#define DEFAULT_SECTORS_PER_BLOCK 8 156#define DEFAULT_BLOCKS_PER_SEGMENT 512 157#define DEFAULT_SEGMENTS_PER_SECTION 1 158 159enum f2fs_config_func { 160 FSCK, 161 DUMP, 162}; 163 164struct f2fs_configuration { 165 u_int32_t sector_size; 166 u_int32_t reserved_segments; 167 u_int32_t overprovision; 168 u_int32_t cur_seg[6]; 169 u_int32_t segs_per_sec; 170 u_int32_t secs_per_zone; 171 u_int32_t start_sector; 172 u_int64_t total_sectors; 173 u_int32_t sectors_per_blk; 174 u_int32_t blks_per_seg; 175 char *vol_label; 176 int heap; 177 int32_t fd; 178 int32_t dump_fd; 179 char *device_name; 180 char *extension_list; 181 int dbg_lv; 182 int trim; 183 int func; 184 void *private; 185 int fix_on; 186 int fix_cnt; 187 int bug_on; 188 int auto_fix; 189} __attribute__((packed)); 190 191#ifdef CONFIG_64BIT 192#define BITS_PER_LONG 64 193#else 194#define BITS_PER_LONG 32 195#endif 196 197#define BIT_MASK(nr) (1 << (nr % BITS_PER_LONG)) 198#define BIT_WORD(nr) (nr / BITS_PER_LONG) 199 200/* 201 * Copied from fs/f2fs/f2fs.h 202 */ 203#define NR_CURSEG_DATA_TYPE (3) 204#define NR_CURSEG_NODE_TYPE (3) 205#define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 206 207enum { 208 CURSEG_HOT_DATA = 0, /* directory entry blocks */ 209 CURSEG_WARM_DATA, /* data blocks */ 210 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 211 CURSEG_HOT_NODE, /* direct node blocks of directory files */ 212 CURSEG_WARM_NODE, /* direct node blocks of normal files */ 213 CURSEG_COLD_NODE, /* indirect node blocks */ 214 NO_CHECK_TYPE 215}; 216 217/* 218 * Copied from fs/f2fs/segment.h 219 */ 220#define GET_SUM_TYPE(footer) ((footer)->entry_type) 221#define SET_SUM_TYPE(footer, type) ((footer)->entry_type = type) 222 223/* 224 * Copied from include/linux/f2fs_sb.h 225 */ 226#define F2FS_SUPER_OFFSET 1024 /* byte-size offset */ 227#define F2FS_LOG_SECTOR_SIZE 9 /* 9 bits for 512 byte */ 228#define F2FS_LOG_SECTORS_PER_BLOCK 3 /* 4KB: F2FS_BLKSIZE */ 229#define F2FS_BLKSIZE 4096 /* support only 4KB block */ 230#define F2FS_MAX_EXTENSION 64 /* # of extension entries */ 231#define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE) 232 233#define NULL_ADDR 0x0U 234#define NEW_ADDR -1U 235 236#define F2FS_ROOT_INO(sbi) (sbi->root_ino_num) 237#define F2FS_NODE_INO(sbi) (sbi->node_ino_num) 238#define F2FS_META_INO(sbi) (sbi->meta_ino_num) 239 240/* This flag is used by node and meta inodes, and by recovery */ 241#define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO) 242 243/* 244 * For further optimization on multi-head logs, on-disk layout supports maximum 245 * 16 logs by default. The number, 16, is expected to cover all the cases 246 * enoughly. The implementaion currently uses no more than 6 logs. 247 * Half the logs are used for nodes, and the other half are used for data. 248 */ 249#define MAX_ACTIVE_LOGS 16 250#define MAX_ACTIVE_NODE_LOGS 8 251#define MAX_ACTIVE_DATA_LOGS 8 252 253/* 254 * For superblock 255 */ 256struct f2fs_super_block { 257 __le32 magic; /* Magic Number */ 258 __le16 major_ver; /* Major Version */ 259 __le16 minor_ver; /* Minor Version */ 260 __le32 log_sectorsize; /* log2 sector size in bytes */ 261 __le32 log_sectors_per_block; /* log2 # of sectors per block */ 262 __le32 log_blocksize; /* log2 block size in bytes */ 263 __le32 log_blocks_per_seg; /* log2 # of blocks per segment */ 264 __le32 segs_per_sec; /* # of segments per section */ 265 __le32 secs_per_zone; /* # of sections per zone */ 266 __le32 checksum_offset; /* checksum offset inside super block */ 267 __le64 block_count; /* total # of user blocks */ 268 __le32 section_count; /* total # of sections */ 269 __le32 segment_count; /* total # of segments */ 270 __le32 segment_count_ckpt; /* # of segments for checkpoint */ 271 __le32 segment_count_sit; /* # of segments for SIT */ 272 __le32 segment_count_nat; /* # of segments for NAT */ 273 __le32 segment_count_ssa; /* # of segments for SSA */ 274 __le32 segment_count_main; /* # of segments for main area */ 275 __le32 segment0_blkaddr; /* start block address of segment 0 */ 276 __le32 cp_blkaddr; /* start block address of checkpoint */ 277 __le32 sit_blkaddr; /* start block address of SIT */ 278 __le32 nat_blkaddr; /* start block address of NAT */ 279 __le32 ssa_blkaddr; /* start block address of SSA */ 280 __le32 main_blkaddr; /* start block address of main area */ 281 __le32 root_ino; /* root inode number */ 282 __le32 node_ino; /* node inode number */ 283 __le32 meta_ino; /* meta inode number */ 284 __u8 uuid[16]; /* 128-bit uuid for volume */ 285 __le16 volume_name[512]; /* volume name */ 286 __le32 extension_count; /* # of extensions below */ 287 __u8 extension_list[F2FS_MAX_EXTENSION][8]; /* extension array */ 288 __le32 cp_payload; 289} __attribute__((packed)); 290 291/* 292 * For checkpoint 293 */ 294#define CP_FSCK_FLAG 0x00000010 295#define CP_ERROR_FLAG 0x00000008 296#define CP_COMPACT_SUM_FLAG 0x00000004 297#define CP_ORPHAN_PRESENT_FLAG 0x00000002 298#define CP_UMOUNT_FLAG 0x00000001 299 300struct f2fs_checkpoint { 301 __le64 checkpoint_ver; /* checkpoint block version number */ 302 __le64 user_block_count; /* # of user blocks */ 303 __le64 valid_block_count; /* # of valid blocks in main area */ 304 __le32 rsvd_segment_count; /* # of reserved segments for gc */ 305 __le32 overprov_segment_count; /* # of overprovision segments */ 306 __le32 free_segment_count; /* # of free segments in main area */ 307 308 /* information of current node segments */ 309 __le32 cur_node_segno[MAX_ACTIVE_NODE_LOGS]; 310 __le16 cur_node_blkoff[MAX_ACTIVE_NODE_LOGS]; 311 /* information of current data segments */ 312 __le32 cur_data_segno[MAX_ACTIVE_DATA_LOGS]; 313 __le16 cur_data_blkoff[MAX_ACTIVE_DATA_LOGS]; 314 __le32 ckpt_flags; /* Flags : umount and journal_present */ 315 __le32 cp_pack_total_block_count; /* total # of one cp pack */ 316 __le32 cp_pack_start_sum; /* start block number of data summary */ 317 __le32 valid_node_count; /* Total number of valid nodes */ 318 __le32 valid_inode_count; /* Total number of valid inodes */ 319 __le32 next_free_nid; /* Next free node number */ 320 __le32 sit_ver_bitmap_bytesize; /* Default value 64 */ 321 __le32 nat_ver_bitmap_bytesize; /* Default value 256 */ 322 __le32 checksum_offset; /* checksum offset inside cp block */ 323 __le64 elapsed_time; /* mounted time */ 324 /* allocation type of current segment */ 325 unsigned char alloc_type[MAX_ACTIVE_LOGS]; 326 327 /* SIT and NAT version bitmap */ 328 unsigned char sit_nat_version_bitmap[1]; 329} __attribute__((packed)); 330 331/* 332 * For orphan inode management 333 */ 334#define F2FS_ORPHANS_PER_BLOCK 1020 335 336struct f2fs_orphan_block { 337 __le32 ino[F2FS_ORPHANS_PER_BLOCK]; /* inode numbers */ 338 __le32 reserved; /* reserved */ 339 __le16 blk_addr; /* block index in current CP */ 340 __le16 blk_count; /* Number of orphan inode blocks in CP */ 341 __le32 entry_count; /* Total number of orphan nodes in current CP */ 342 __le32 check_sum; /* CRC32 for orphan inode block */ 343} __attribute__((packed)); 344 345/* 346 * For NODE structure 347 */ 348struct f2fs_extent { 349 __le32 fofs; /* start file offset of the extent */ 350 __le32 blk_addr; /* start block address of the extent */ 351 __le32 len; /* lengh of the extent */ 352} __attribute__((packed)); 353 354#define F2FS_NAME_LEN 255 355#define F2FS_INLINE_XATTR_ADDRS 50 /* 200 bytes for inline xattrs */ 356#define DEF_ADDRS_PER_INODE 923 /* Address Pointers in an Inode */ 357#define ADDRS_PER_INODE(fi) addrs_per_inode(fi) 358#define ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block */ 359#define NIDS_PER_BLOCK 1018 /* Node IDs in an Indirect Block */ 360 361#define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1) 362#define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2) 363#define NODE_IND1_BLOCK (DEF_ADDRS_PER_INODE + 3) 364#define NODE_IND2_BLOCK (DEF_ADDRS_PER_INODE + 4) 365#define NODE_DIND_BLOCK (DEF_ADDRS_PER_INODE + 5) 366 367#define F2FS_INLINE_XATTR 0x01 /* file inline xattr flag */ 368#define F2FS_INLINE_DATA 0x02 /* file inline data flag */ 369#define MAX_INLINE_DATA (sizeof(__le32) * (DEF_ADDRS_PER_INODE - \ 370 F2FS_INLINE_XATTR_ADDRS - 1)) 371 372#define INLINE_DATA_OFFSET (PAGE_CACHE_SIZE - sizeof(struct node_footer) \ 373 - sizeof(__le32)*(DEF_ADDRS_PER_INODE + 5 - 1)) 374 375#define DEF_DIR_LEVEL 0 376 377struct f2fs_inode { 378 __le16 i_mode; /* file mode */ 379 __u8 i_advise; /* file hints */ 380 __u8 i_inline; /* file inline flags */ 381 __le32 i_uid; /* user ID */ 382 __le32 i_gid; /* group ID */ 383 __le32 i_links; /* links count */ 384 __le64 i_size; /* file size in bytes */ 385 __le64 i_blocks; /* file size in blocks */ 386 __le64 i_atime; /* access time */ 387 __le64 i_ctime; /* change time */ 388 __le64 i_mtime; /* modification time */ 389 __le32 i_atime_nsec; /* access time in nano scale */ 390 __le32 i_ctime_nsec; /* change time in nano scale */ 391 __le32 i_mtime_nsec; /* modification time in nano scale */ 392 __le32 i_generation; /* file version (for NFS) */ 393 __le32 i_current_depth; /* only for directory depth */ 394 __le32 i_xattr_nid; /* nid to save xattr */ 395 __le32 i_flags; /* file attributes */ 396 __le32 i_pino; /* parent inode number */ 397 __le32 i_namelen; /* file name length */ 398 __u8 i_name[F2FS_NAME_LEN]; /* file name for SPOR */ 399 __u8 i_dir_level; /* dentry_level for large dir */ 400 401 struct f2fs_extent i_ext; /* caching a largest extent */ 402 403 __le32 i_addr[DEF_ADDRS_PER_INODE]; /* Pointers to data blocks */ 404 405 __le32 i_nid[5]; /* direct(2), indirect(2), 406 double_indirect(1) node id */ 407} __attribute__((packed)); 408 409struct direct_node { 410 __le32 addr[ADDRS_PER_BLOCK]; /* array of data block address */ 411} __attribute__((packed)); 412 413struct indirect_node { 414 __le32 nid[NIDS_PER_BLOCK]; /* array of data block address */ 415} __attribute__((packed)); 416 417enum { 418 COLD_BIT_SHIFT = 0, 419 FSYNC_BIT_SHIFT, 420 DENT_BIT_SHIFT, 421 OFFSET_BIT_SHIFT 422}; 423 424#define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 425 >> OFFSET_BIT_SHIFT) 426 427struct node_footer { 428 __le32 nid; /* node id */ 429 __le32 ino; /* inode nunmber */ 430 __le32 flag; /* include cold/fsync/dentry marks and offset */ 431 __le64 cp_ver; /* checkpoint version */ 432 __le32 next_blkaddr; /* next node page block address */ 433} __attribute__((packed)); 434 435struct f2fs_node { 436 /* can be one of three types: inode, direct, and indirect types */ 437 union { 438 struct f2fs_inode i; 439 struct direct_node dn; 440 struct indirect_node in; 441 }; 442 struct node_footer footer; 443} __attribute__((packed)); 444 445/* 446 * For NAT entries 447 */ 448#define NAT_ENTRY_PER_BLOCK (PAGE_CACHE_SIZE / sizeof(struct f2fs_nat_entry)) 449 450struct f2fs_nat_entry { 451 __u8 version; /* latest version of cached nat entry */ 452 __le32 ino; /* inode number */ 453 __le32 block_addr; /* block address */ 454} __attribute__((packed)); 455 456struct f2fs_nat_block { 457 struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK]; 458} __attribute__((packed)); 459 460/* 461 * For SIT entries 462 * 463 * Each segment is 2MB in size by default so that a bitmap for validity of 464 * there-in blocks should occupy 64 bytes, 512 bits. 465 * Not allow to change this. 466 */ 467#define SIT_VBLOCK_MAP_SIZE 64 468#define SIT_ENTRY_PER_BLOCK (PAGE_CACHE_SIZE / sizeof(struct f2fs_sit_entry)) 469 470/* 471 * F2FS uses 4 bytes to represent block address. As a result, supported size of 472 * disk is 16 TB and it equals to 16 * 1024 * 1024 / 2 segments. 473 */ 474#define F2FS_MAX_SEGMENT ((16 * 1024 * 1024) / 2) 475#define MAX_SIT_BITMAP_SIZE ((F2FS_MAX_SEGMENT / SIT_ENTRY_PER_BLOCK) / 8) 476 477/* 478 * Note that f2fs_sit_entry->vblocks has the following bit-field information. 479 * [15:10] : allocation type such as CURSEG_XXXX_TYPE 480 * [9:0] : valid block count 481 */ 482#define SIT_VBLOCKS_SHIFT 10 483#define SIT_VBLOCKS_MASK ((1 << SIT_VBLOCKS_SHIFT) - 1) 484#define GET_SIT_VBLOCKS(raw_sit) \ 485 (le16_to_cpu((raw_sit)->vblocks) & SIT_VBLOCKS_MASK) 486#define GET_SIT_TYPE(raw_sit) \ 487 ((le16_to_cpu((raw_sit)->vblocks) & ~SIT_VBLOCKS_MASK) \ 488 >> SIT_VBLOCKS_SHIFT) 489 490struct f2fs_sit_entry { 491 __le16 vblocks; /* reference above */ 492 __u8 valid_map[SIT_VBLOCK_MAP_SIZE]; /* bitmap for valid blocks */ 493 __le64 mtime; /* segment age for cleaning */ 494} __attribute__((packed)); 495 496struct f2fs_sit_block { 497 struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK]; 498} __attribute__((packed)); 499 500/* 501 * For segment summary 502 * 503 * One summary block contains exactly 512 summary entries, which represents 504 * exactly 2MB segment by default. Not allow to change the basic units. 505 * 506 * NOTE: For initializing fields, you must use set_summary 507 * 508 * - If data page, nid represents dnode's nid 509 * - If node page, nid represents the node page's nid. 510 * 511 * The ofs_in_node is used by only data page. It represents offset 512 * from node's page's beginning to get a data block address. 513 * ex) data_blkaddr = (block_t)(nodepage_start_address + ofs_in_node) 514 */ 515#define ENTRIES_IN_SUM 512 516#define SUMMARY_SIZE (7) /* sizeof(struct summary) */ 517#define SUM_FOOTER_SIZE (5) /* sizeof(struct summary_footer) */ 518#define SUM_ENTRIES_SIZE (SUMMARY_SIZE * ENTRIES_IN_SUM) 519 520/* a summary entry for a 4KB-sized block in a segment */ 521struct f2fs_summary { 522 __le32 nid; /* parent node id */ 523 union { 524 __u8 reserved[3]; 525 struct { 526 __u8 version; /* node version number */ 527 __le16 ofs_in_node; /* block index in parent node */ 528 } __attribute__((packed)); 529 }; 530} __attribute__((packed)); 531 532/* summary block type, node or data, is stored to the summary_footer */ 533#define SUM_TYPE_NODE (1) 534#define SUM_TYPE_DATA (0) 535 536struct summary_footer { 537 unsigned char entry_type; /* SUM_TYPE_XXX */ 538 __u32 check_sum; /* summary checksum */ 539} __attribute__((packed)); 540 541#define SUM_JOURNAL_SIZE (F2FS_BLKSIZE - SUM_FOOTER_SIZE -\ 542 SUM_ENTRIES_SIZE) 543#define NAT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\ 544 sizeof(struct nat_journal_entry)) 545#define NAT_JOURNAL_RESERVED ((SUM_JOURNAL_SIZE - 2) %\ 546 sizeof(struct nat_journal_entry)) 547#define SIT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\ 548 sizeof(struct sit_journal_entry)) 549#define SIT_JOURNAL_RESERVED ((SUM_JOURNAL_SIZE - 2) %\ 550 sizeof(struct sit_journal_entry)) 551/* 552 * frequently updated NAT/SIT entries can be stored in the spare area in 553 * summary blocks 554 */ 555enum { 556 NAT_JOURNAL = 0, 557 SIT_JOURNAL 558}; 559 560struct nat_journal_entry { 561 __le32 nid; 562 struct f2fs_nat_entry ne; 563} __attribute__((packed)); 564 565struct nat_journal { 566 struct nat_journal_entry entries[NAT_JOURNAL_ENTRIES]; 567 __u8 reserved[NAT_JOURNAL_RESERVED]; 568} __attribute__((packed)); 569 570struct sit_journal_entry { 571 __le32 segno; 572 struct f2fs_sit_entry se; 573} __attribute__((packed)); 574 575struct sit_journal { 576 struct sit_journal_entry entries[SIT_JOURNAL_ENTRIES]; 577 __u8 reserved[SIT_JOURNAL_RESERVED]; 578} __attribute__((packed)); 579 580/* 4KB-sized summary block structure */ 581struct f2fs_summary_block { 582 struct f2fs_summary entries[ENTRIES_IN_SUM]; 583 union { 584 __le16 n_nats; 585 __le16 n_sits; 586 }; 587 /* spare area is used by NAT or SIT journals */ 588 union { 589 struct nat_journal nat_j; 590 struct sit_journal sit_j; 591 }; 592 struct summary_footer footer; 593} __attribute__((packed)); 594 595/* 596 * For directory operations 597 */ 598#define F2FS_DOT_HASH 0 599#define F2FS_DDOT_HASH F2FS_DOT_HASH 600#define F2FS_MAX_HASH (~((0x3ULL) << 62)) 601#define F2FS_HASH_COL_BIT ((0x1ULL) << 63) 602 603typedef __le32 f2fs_hash_t; 604 605/* One directory entry slot covers 8bytes-long file name */ 606#define F2FS_SLOT_LEN 8 607#define F2FS_SLOT_LEN_BITS 3 608 609#define GET_DENTRY_SLOTS(x) ((x + F2FS_SLOT_LEN - 1) >> F2FS_SLOT_LEN_BITS) 610 611/* the number of dentry in a block */ 612#define NR_DENTRY_IN_BLOCK 214 613 614/* MAX level for dir lookup */ 615#define MAX_DIR_HASH_DEPTH 63 616 617#define SIZE_OF_DIR_ENTRY 11 /* by byte */ 618#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \ 619 BITS_PER_BYTE) 620#define SIZE_OF_RESERVED (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \ 621 F2FS_SLOT_LEN) * \ 622 NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP)) 623 624/* One directory entry slot representing F2FS_SLOT_LEN-sized file name */ 625struct f2fs_dir_entry { 626 __le32 hash_code; /* hash code of file name */ 627 __le32 ino; /* inode number */ 628 __le16 name_len; /* lengh of file name */ 629 __u8 file_type; /* file type */ 630} __attribute__((packed)); 631 632/* 4KB-sized directory entry block */ 633struct f2fs_dentry_block { 634 /* validity bitmap for directory entries in each block */ 635 __u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP]; 636 __u8 reserved[SIZE_OF_RESERVED]; 637 struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK]; 638 __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; 639} __attribute__((packed)); 640 641/* file types used in inode_info->flags */ 642enum FILE_TYPE { 643 F2FS_FT_UNKNOWN, 644 F2FS_FT_REG_FILE, 645 F2FS_FT_DIR, 646 F2FS_FT_CHRDEV, 647 F2FS_FT_BLKDEV, 648 F2FS_FT_FIFO, 649 F2FS_FT_SOCK, 650 F2FS_FT_SYMLINK, 651 F2FS_FT_MAX, 652 /* added for fsck */ 653 F2FS_FT_ORPHAN, 654 F2FS_FT_XATTR, 655}; 656 657/* from f2fs/segment.h */ 658enum { 659 LFS = 0, 660 SSR 661}; 662 663extern void ASCIIToUNICODE(u_int16_t *, u_int8_t *); 664extern int log_base_2(u_int32_t); 665extern unsigned int addrs_per_inode(struct f2fs_inode *); 666 667extern int get_bits_in_byte(unsigned char n); 668extern int set_bit(unsigned int nr,void * addr); 669extern int clear_bit(unsigned int nr, void * addr); 670extern int test_bit(unsigned int nr, const void * addr); 671extern int f2fs_test_bit(unsigned int, const char *); 672extern int f2fs_set_bit(unsigned int, char *); 673extern int f2fs_clear_bit(unsigned int, char *); 674extern unsigned long find_next_bit(const unsigned long *, 675 unsigned long, unsigned long); 676 677extern u_int32_t f2fs_cal_crc32(u_int32_t, void *, int); 678extern int f2fs_crc_valid(u_int32_t blk_crc, void *buf, int len); 679 680extern void f2fs_init_configuration(struct f2fs_configuration *); 681extern int f2fs_dev_is_umounted(struct f2fs_configuration *); 682extern int f2fs_get_device_info(struct f2fs_configuration *); 683extern void f2fs_finalize_device(struct f2fs_configuration *); 684 685extern int dev_read(void *, __u64, size_t); 686extern int dev_write(void *, __u64, size_t); 687extern int dev_write_block(void *, __u64); 688extern int dev_write_dump(void *, __u64, size_t); 689/* All bytes in the buffer must be 0 use dev_fill(). */ 690extern int dev_fill(void *, __u64, size_t); 691 692extern int dev_read_block(void *, __u64); 693extern int dev_read_blocks(void *, __u64, __u32 ); 694 695f2fs_hash_t f2fs_dentry_hash(const unsigned char *, int); 696 697extern struct f2fs_configuration config; 698 699#endif /*__F2FS_FS_H */ 700