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