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