mirror of
https://gitee.com/openharmony/third_party_f2fs-tools
synced 2024-11-23 10:10:00 +00:00
dad33a1ee7
This patch adds an option 'extra_attr' in mkfs for enabling v2 f2fs inode format in kernel codes. Also this patch makes fsck to support recognize v2 inode format, below is v2 format description: Original one: struct f2fs_inode { ... struct f2fs_extent i_ext; __le32 i_addr[DEF_ADDRS_PER_INODE]; __le32 i_nid[DEF_NIDS_PER_INODE]; } Extended one: struct f2fs_inode { ... struct f2fs_extent i_ext; union { struct { __le16 i_extra_isize; __le16 i_padding; __le32 i_extra_end[0]; }; __le32 i_addr[DEF_ADDRS_PER_INODE]; }; __le32 i_nid[DEF_NIDS_PER_INODE]; } Once F2FS_EXTRA_ATTR is set, we will steal four bytes in the head of i_addr field for storing i_extra_isize and i_padding. with i_extra_isize, we can calculate actual size of reserved space in i_addr, available attribute fields included in total extra attribute fields for current inode can be described as below: +--------------------+ | .i_mode | | ... | | .i_ext | +--------------------+ | .i_extra_isize |-----+ | .i_padding | | | .i_prjid | | | .i_atime_extra | | | .i_ctime_extra | | | .i_mtime_extra |<----+ | .i_inode_cs |<----- store blkaddr/inline from here | .i_xattr_cs | | ... | +--------------------+ | | | block address | | | +--------------------+ | .i_nid | +--------------------+ | node_footer | | (nid, ino, offset) | +--------------------+ Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
107 lines
2.4 KiB
C
107 lines
2.4 KiB
C
/**
|
|
* node.h
|
|
*
|
|
* Many parts of codes are copied from Linux kernel/fs/f2fs.
|
|
*
|
|
* Copyright (C) 2015 Huawei Ltd.
|
|
* Witten by:
|
|
* Hou Pengyang <houpengyang@huawei.com>
|
|
* Liu Shuoran <liushuoran@huawei.com>
|
|
* Jaegeuk Kim <jaegeuk@kernel.org>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
#ifndef _NODE_H_
|
|
#define _NODE_H_
|
|
|
|
#include "fsck.h"
|
|
|
|
#define ADDRS_PER_PAGE(page) \
|
|
(IS_INODE(page) ? ADDRS_PER_INODE(&page->i) : ADDRS_PER_BLOCK)
|
|
|
|
static inline int IS_INODE(struct f2fs_node *node)
|
|
{
|
|
return ((node)->footer.nid == (node)->footer.ino);
|
|
}
|
|
|
|
static inline __le32 *blkaddr_in_inode(struct f2fs_node *node)
|
|
{
|
|
return node->i.i_addr + get_extra_isize(node);
|
|
}
|
|
|
|
static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
|
|
{
|
|
return IS_INODE(node) ? blkaddr_in_inode(node) : node->dn.addr;
|
|
}
|
|
|
|
static inline block_t datablock_addr(struct f2fs_node *node_page,
|
|
unsigned int offset)
|
|
{
|
|
__le32 *addr_array;
|
|
|
|
ASSERT(node_page);
|
|
addr_array = blkaddr_in_node(node_page);
|
|
return le32_to_cpu(addr_array[offset]);
|
|
}
|
|
|
|
static inline void set_nid(struct f2fs_node * rn, int off, nid_t nid, int i)
|
|
{
|
|
if (i)
|
|
rn->i.i_nid[off - NODE_DIR1_BLOCK] = cpu_to_le32(nid);
|
|
else
|
|
rn->in.nid[off] = cpu_to_le32(nid);
|
|
}
|
|
|
|
static inline nid_t get_nid(struct f2fs_node * rn, int off, int i)
|
|
{
|
|
if (i)
|
|
return le32_to_cpu(rn->i.i_nid[off - NODE_DIR1_BLOCK]);
|
|
else
|
|
return le32_to_cpu(rn->in.nid[off]);
|
|
}
|
|
|
|
enum {
|
|
ALLOC_NODE, /* allocate a new node page if needed */
|
|
LOOKUP_NODE, /* lookup up a node without readahead */
|
|
LOOKUP_NODE_RA,
|
|
};
|
|
|
|
static inline void set_new_dnode(struct dnode_of_data *dn,
|
|
struct f2fs_node *iblk, struct f2fs_node *nblk, nid_t nid)
|
|
{
|
|
memset(dn, 0, sizeof(*dn));
|
|
dn->inode_blk = iblk;
|
|
dn->node_blk = nblk;
|
|
dn->nid = nid;
|
|
dn->idirty = 0;
|
|
dn->ndirty = 0;
|
|
}
|
|
|
|
static inline void inc_inode_blocks(struct dnode_of_data *dn)
|
|
{
|
|
u64 blocks = le64_to_cpu(dn->inode_blk->i.i_blocks);
|
|
|
|
dn->inode_blk->i.i_blocks = cpu_to_le64(blocks + 1);
|
|
dn->idirty = 1;
|
|
}
|
|
|
|
static inline int IS_DNODE(struct f2fs_node *node_page)
|
|
{
|
|
unsigned int ofs = ofs_of_node(node_page);
|
|
|
|
if (ofs == 3 || ofs == 4 + NIDS_PER_BLOCK ||
|
|
ofs == 5 + 2 * NIDS_PER_BLOCK)
|
|
return 0;
|
|
|
|
if (ofs >= 6 + 2 * NIDS_PER_BLOCK) {
|
|
ofs -= 6 + 2 * NIDS_PER_BLOCK;
|
|
if (!((long int)ofs % (NIDS_PER_BLOCK + 1)))
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
#endif
|