1. 程式人生 > >f2fs study 筆記之二: SSA揭秘

f2fs study 筆記之二: SSA揭秘

筆記 dentry pac amp mat one += reg pos

node inode

node: used to locate block;
inode: upper lawyer logical entity (file/directory)

block ?和file name如何關聯

計算出hash 值之後,根據 inode 去讀對應的block:
這裏除了比較hash值之外,還會比較file name,所以可以避免hash沖突。

hash 函數在 hash.c 裏面: fs/f2fs/hash.c

  1. f2fs_dentry_block:

/ 4KB-sized directory entry block /
struct f2fs_dentry_block {

/ validity bitmap for directory entries in each block /
u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP];
u8 reserved[SIZE_OF_RESERVED];
struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK];
__u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN];
} __packed;

  1. f2fs_dir_entry

/ One directory entry slot representing F2FS_SLOT_LEN-sized file name

/
struct f2fs_dir_entry {
le32 hash_code; / hash code of file name /
le32 ino; / inode number /
le16 name_len; / lengh of file name /
u8 file_type; / file type /
} __packed;

  1. NAT

struct f2fs_nat_entry {
u8 version; / latest version of cached nat entry /
le32 ino; / inode number

/
__le32 block_addr; / block address /
} __packed;

hash ?過程

struct f2fs_dir_entry f2fs_find_target_dentry(struct fscrypt_name fname,
f2fs_hash_t namehash, int max_slots,
struct f2fs_dentry_ptr
d)
{
struct f2fs_dir_entry *de;
unsigned long bit_pos = 0;
int max_len = 0;

    if (max_slots)
            *max_slots = 0;
    while (bit_pos < d->max) {
            if (!test_bit_le(bit_pos, d->bitmap)) {
                    bit_pos++;
                    max_len++;
                    continue;
            }

            de = &d->dentry[bit_pos];

            if (unlikely(!de->name_len)) {
                    bit_pos++;
                    continue;
            }

            if (**de->hash_code == namehash &&
                fscrypt_match_name(fname, d->filename[bit_pos],
                                   le16_to_cpu(de->name_len)))**
                    goto found;

            if (max_slots && max_len > *max_slots)
                    *max_slots = max_len;
            max_len = 0;

            bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
    }
  1. called in find_in_block()

called in find_in_level()
called in __f2fs_find_entry()
called by f2fs_add_regular_entry()

inode 和文件名、目錄名如何關聯

SSA 的主要作用

哪些類型的數據會用到SSA?

在IO路徑上SSA 如何工作?

參考

f2fs study 筆記之二: SSA揭秘