1. 程式人生 > >f2f2 學習筆記 之一

f2f2 學習筆記 之一

get systems oct nio basic 什麽 gen point extra

源代碼位置

include/linux/f2fs_fs.h
fs/f2fs/
Documentation/filesystems/f2fs.txt

inode 是什麽?node 是什麽?

需要深入理解node/inode:
node block 是索引節點塊:包括inode ; direct data block; indirect data block;
inode: data block indices; direct block; indirect block; double indirect block;
根據計算一個inode最多能索引的文件的大小的公式,可以加深理解;

dentry block:
目錄相關;

需要先建立起來bucket ; A(2B); 根據name hash值/當前排查層次的bucket 總數,得到一個bucket number,然後據此查對應的bucket;

segment summary

/*

  • For segment summary
  • One summary block contains exactly 512 summary entries, which represents
  • exactly 2MB segment by default. Not allow to change the basic units.
  • NOTE: For initializing fields, you must use set_summary
    • If data page, nid represents dnode‘s nid
    • If node page, nid represents the node page‘s nid.
  • The ofs_in_node is used by only data page. It represents offset
  • from node‘s page‘s beginning to get a data block address.
  • ex) data_blkaddr = (block_t)(nodepage_start_address + ofs_in_node)
    /
    #define ENTRIES_IN_SUM 512
    #define SUMMARY_SIZE (7) /
    sizeof(struct summary) /
    #define SUM_FOOTER_SIZE (5) /
    sizeof(struct summary_footer) /
    #define SUM_ENTRY_SIZE (SUMMARY_SIZE
    ENTRIES_IN_SUM)

/ a summary entry for a 4KB-sized block in a segment /
struct f2fs_summary {
le32 nid; / parent node id /
union {
u8 reserved[3];
struct {
u8 version; / node version number /
le16 ofs_in_node; / block index in parent node /
} packed;
};
}
packed;

/ summary block type, node or data, is stored to the summary_footer /
#define SUM_TYPE_NODE (1)
#define SUM_TYPE_DATA (0)

struct summary_footer {
unsigned char entry_type; / SUM_TYPE_XXX /
__le32 check_sum; / summary checksum /
} __packed;

#define SUM_JOURNAL_SIZE (F2FS_BLKSIZE - SUM_FOOTER_SIZE -\
SUM_ENTRY_SIZE)
#define NAT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\
sizeof(struct nat_journal_entry))
#define NAT_JOURNAL_RESERVED ((SUM_JOURNAL_SIZE - 2) %\
sizeof(struct nat_journal_entry))
#define SIT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\
sizeof(struct sit_journal_entry))
#define SIT_JOURNAL_RESERVED ((SUM_JOURNAL_SIZE - 2) %\
sizeof(struct sit_journal_entry))

/* Reserved area should make size of f2fs_extra_info equals to

  • that of nat_journal and sit_journal.
    */
    #define EXTRA_INFO_RESERVED (SUM_JOURNAL_SIZE - 2 - 8)

/*

  • frequently updated NAT/SIT entries can be stored in the spare area in
  • summary blocks
    */
    enum {
    NAT_JOURNAL = 0,
    SIT_JOURNAL
    };

struct nat_journal_entry {
le32 nid;
struct f2fs_nat_entry ne;
}
packed;

struct nat_journal {
struct nat_journal_entry entries[NAT_JOURNAL_ENTRIES];
__u8 reserved[NAT_JOURNAL_RESERVED];
....
}

file 相關操作

f2fs.h:
file_operations f2fs_file_operations:

fs/f2fs/file.c:

const struct file_operations f2fs_file_operations = {
.llseek = f2fs_llseek,
.read_iter = generic_file_read_iter,
.write_iter = f2fs_file_write_iter,
.open = f2fs_file_open,
.release = f2fs_release_file,
.mmap = f2fs_file_mmap,
.flush = f2fs_file_flush,
.fsync = f2fs_sync_file,
.fallocate = f2fs_fallocate,
.unlocked_ioctl = f2fs_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = f2fs_compat_ioctl,
#endif
.splice_read = generic_file_splice_read,
.splice_write = iter_file_splice_write,
};

open

f2fs_file_open

寫流程

讀流程

journal

checkpoint

參考鏈接

http://www.cnblogs.com/tcicy/p/8506898.html

f2f2 學習筆記 之一