From patchwork Wed Aug 16 01:13:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 13354484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61A03C001B0 for ; Wed, 16 Aug 2023 01:44:30 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qW5aH-00082n-5D; Wed, 16 Aug 2023 01:44:29 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <35yLcZAYKAMot748u3w44w1u.s42@flex--drosen.bounces.google.com>) id 1qW5aC-00082h-BP for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:44:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SA/1yfAoX2EpXEod91FzbUD3eWop9hZZxbYcZZE7f8k=; b=m3v2GwdAji3edzr4neOCGCv+0h +98bN46viML/+4nXhXBNBvO/9RhR2p9PN+DAAxXJZPpRdH2G1GyudA2HOARuQjb67d74bNLWkKsPR PiMqX5oueatcykqYtuAPYxk8XzpzLZb+roRcDFA0IeMJw1AQ0G4c6irdkJm/nsWjhokI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=SA/1yfAoX2EpXEod91FzbUD3eWop9hZZxbYcZZE7f8k=; b=bICQXSiJ4CuwmyN2L9Eh8tHy9t 6bt3fpKueEi3YTsvKJcTlCbuThw4NyDIiv4PFM3Aqb7OwdPTsD4L+78mijxw2vlWtPjtd9FPuwt6r xQ0eHZxJWD7TXCxx7fMdGromsXTeKtR/FMNdxdAFmxHqwZ5Ihb+ghtC6T2jFVFKT+fX0=; Received: from mail-qv1-f74.google.com ([209.85.219.74]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qW5a8-0000uB-Lg for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:44:22 +0000 Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6418d208874so55070456d6.1 for ; Tue, 15 Aug 2023 18:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692150255; x=1692755055; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SA/1yfAoX2EpXEod91FzbUD3eWop9hZZxbYcZZE7f8k=; b=l1EuEps4r3vJwru5JpV37rWlwh1IocYCTvXDI1tx2omdMITxQxJmJ+Ll98D+rkqb6t uk+SInMM2NDg2a0L0pSs+pWpKHmruZKqMb3DHv8kKV8D6BQbgTF8EfK1uhp+1cAfFGfp oS2vHwLkVTFwYXDnuFhyx2KhntMUvx6G86IjTZusbYkr/JWjorBNtdfSqQcDpcFlrckn 5Wecs2aZlc9zAc26fQzSceHtpRPBeh5L51R3SHDY1Y1XTbY2VNUZO2HvXWnyZsA8DsQ9 Y2TFs0Wdew37bStIG7wqUX9AavEXht0eHk3WmwO7BPxT6GHVh08FIFvpk3vkI/Vpe50c wHZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692150255; x=1692755055; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SA/1yfAoX2EpXEod91FzbUD3eWop9hZZxbYcZZE7f8k=; b=gEZn+b/IiGhMdDnj7PrKDDQEHhEok7CkJLwt2FqNqTsi1FWEat3UzNtGLFwCMNHVDQ ho+PslDRPsWeSDj4WItq7ffQ65d1HO1eGrIVysVJgb4D43bp8q7rOaLgwsGW5IO2GW2b lYd1obuYiNgtzRUoBEnoKLuebtLKKRS4GggJNUNljeBr22zF1ScdtVMk/YBRylNqajQx LdQBednZTzVwnbqu+uZ9EtbuPbRBa+nUJuwnnaI8BVDYKwf8T7qWD7T3KY3/XlbWzJBf s/a8WIaEIzzUz8OQvYNaB4WvrgyTb1Gd7lAp/uw63EdPsCn6C3WKuV6324u3mTUMZMF8 94+Q== X-Gm-Message-State: AOJu0YwEaS950x13z2mLHcYZ03b7rcRPvRIRqbeJVXl9dRQ/f0UvtEjO W129i8Xx4+9UcbNh4+1Bb5qgybIBNxX8wJyABUS8IcWuRX3huhqTtY2hORqf+ZIN2zL+C7lxkLi 6oMzYUS+3JI756KxrnqQCfSgQc2ysTXf2eh15tBZfELEDX1CzX4wU9lCEtNbXKZaVegKtHJsug/ ebUSvgSM8= X-Google-Smtp-Source: AGHT+IE/7SNqvZXm1RBc7gAmDAkWWClq/KRuNiexRyKvMe/5h02N3fp/U+Rt4SOLcvzvI34D6TWzKcBZsP4= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:19fa:33cd:f272:37ec]) (user=drosen job=sendgmr) by 2002:a25:ab72:0:b0:d40:932e:f7b1 with SMTP id u105-20020a25ab72000000b00d40932ef7b1mr5366ybi.7.1692148455452; Tue, 15 Aug 2023 18:14:15 -0700 (PDT) Date: Tue, 15 Aug 2023 18:13:53 -0700 In-Reply-To: <20230816011359.1964484-1-drosen@google.com> Mime-Version: 1.0 References: <20230816011359.1964484-1-drosen@google.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog Message-ID: <20230816011359.1964484-2-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qW5a8-0000uB-Lg Subject: [f2fs-dev] [PATCH 1/7] f2fs-tools: Define constants in terms of BLKSIZE X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Rosenberg via Linux-f2fs-devel From: Daniel Rosenberg Reply-To: Daniel Rosenberg Cc: Jaegeuk Kim , kernel-team@android.com, Daniel Rosenberg Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This converts the various block size based constants to be defined in terms of the block size. This makes it possible to change the block size by changing only F2FS_BLKSIZE_BITS in f2fs_fs.h Signed-off-by: Daniel Rosenberg --- fsck/fsck.h | 2 +- fsck/mount.c | 4 +- include/f2fs_fs.h | 81 +++++++++++++++++++++++------------------ mkfs/f2fs_format.c | 12 +++--- mkfs/f2fs_format_main.c | 2 +- 5 files changed, 55 insertions(+), 46 deletions(-) diff --git a/fsck/fsck.h b/fsck/fsck.h index 0f7caf4..89d0b22 100644 --- a/fsck/fsck.h +++ b/fsck/fsck.h @@ -126,7 +126,7 @@ struct f2fs_fsck { struct quota_ctx *qctx; }; -#define BLOCK_SZ 4096 +#define BLOCK_SZ F2FS_BLKSIZE struct block { unsigned char buf[BLOCK_SZ]; }; diff --git a/fsck/mount.c b/fsck/mount.c index 5e687a8..831a7a3 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -995,8 +995,8 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr) blocksize = 1 << get_sb(log_blocksize); if (F2FS_BLKSIZE != blocksize) { - MSG(0, "Invalid blocksize (%u), supports only 4KB\n", - blocksize); + MSG(0, "Invalid blocksize (%u), supports only (%u)\n", + blocksize, F2FS_BLKSIZE); return -1; } diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 7e7db22..6975143 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -385,18 +385,18 @@ static inline uint64_t bswap_64(uint64_t val) #define SECTOR_SHIFT 9 #endif #define F2FS_SUPER_MAGIC 0xF2F52010 /* F2FS Magic Number */ -#define CP_CHKSUM_OFFSET 4092 +#define CP_CHKSUM_OFFSET (F2FS_BLKSIZE - sizeof(__le32)) #define SB_CHKSUM_OFFSET 3068 #define MAX_PATH_LEN 64 #define MAX_DEVICES 8 #define F2FS_BYTES_TO_BLK(bytes) ((bytes) >> F2FS_BLKSIZE_BITS) -#define F2FS_BLKSIZE_BITS 12 +#define F2FS_BLKSIZE_BITS 12 /* 4KB block */ /* for mkfs */ #define F2FS_NUMBER_OF_CHECKPOINT_PACK 2 #define DEFAULT_SECTOR_SIZE 512 -#define DEFAULT_SECTORS_PER_BLOCK 8 +#define DEFAULT_SECTORS_PER_BLOCK (1 << (F2FS_BLKSIZE_BITS - SECTOR_SHIFT)) #define DEFAULT_BLOCKS_PER_SEGMENT 512 #define DEFAULT_SEGMENTS_PER_SECTION 1 @@ -627,8 +627,8 @@ enum { */ #define F2FS_SUPER_OFFSET 1024 /* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ -#define F2FS_MAX_LOG_SECTOR_SIZE 12 /* 12 bits for 4096 bytes */ -#define F2FS_BLKSIZE 4096 /* support only 4KB block */ +#define F2FS_MAX_LOG_SECTOR_SIZE F2FS_BLKSIZE_BITS /* 12 bits for 4096 bytes */ +#define F2FS_BLKSIZE (1 << F2FS_BLKSIZE_BITS)/* support only 4KB block */ #define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_EXTENSION_LEN 8 /* max size of extension */ #define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE) @@ -642,7 +642,7 @@ enum { #define F2FS_META_INO(sbi) (sbi->meta_ino_num) #define F2FS_MAX_QUOTAS 3 -#define QUOTA_DATA 2 +#define QUOTA_DATA (((1024 * 6 - 1) / F2FS_BLKSIZE) + 1) #define QUOTA_INO(sb,t) (le32_to_cpu((sb)->qf_ino[t])) /* @@ -853,7 +853,7 @@ static_assert(sizeof(struct f2fs_checkpoint) == 192, ""); /* * For orphan inode management */ -#define F2FS_ORPHANS_PER_BLOCK 1020 +#define F2FS_ORPHANS_PER_BLOCK ((F2FS_BLKSIZE - 4 * sizeof(__le32)) / sizeof(__le32)) struct f2fs_orphan_block { __le32 ino[F2FS_ORPHANS_PER_BLOCK]; /* inode numbers */ @@ -864,7 +864,7 @@ struct f2fs_orphan_block { __le32 check_sum; /* CRC32 for orphan inode block */ }; -static_assert(sizeof(struct f2fs_orphan_block) == 4096, ""); +static_assert(sizeof(struct f2fs_orphan_block) == F2FS_BLKSIZE, ""); /* * For NODE structure @@ -884,13 +884,31 @@ static_assert(sizeof(struct f2fs_extent) == 12, ""); /* 200 bytes for inline xattrs by default */ #define DEFAULT_INLINE_XATTR_ADDRS 50 -#define DEF_ADDRS_PER_INODE 923 /* Address Pointers in an Inode */ + +struct node_footer { + __le32 nid; /* node id */ + __le32 ino; /* inode number */ + __le32 flag; /* include cold/fsync/dentry marks and offset */ + __le64 cp_ver __attribute__((packed)); /* checkpoint version */ + __le32 next_blkaddr; /* next node page block address */ +}; + +static_assert(sizeof(struct node_footer) == 24, ""); + +#define OFFSET_OF_END_OF_I_EXT 360 +#define SIZE_OF_I_NID 20 +/* Address Pointers in an Inode */ +#define DEF_ADDRS_PER_INODE ((F2FS_BLKSIZE - OFFSET_OF_END_OF_I_EXT \ + - SIZE_OF_I_NID \ + - sizeof(struct node_footer)) / sizeof(__le32)) #define CUR_ADDRS_PER_INODE(inode) (DEF_ADDRS_PER_INODE - \ __get_extra_isize(inode)) #define ADDRS_PER_INODE(i) addrs_per_inode(i) -#define DEF_ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block */ +/* Address Pointers in a Direct Block */ +#define DEF_ADDRS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32)) #define ADDRS_PER_BLOCK(i) addrs_per_block(i) -#define NIDS_PER_BLOCK 1018 /* Node IDs in an Indirect Block */ +/* Node IDs in an Indirect Block */ +#define NIDS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32)) #define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1) #define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2) @@ -1024,19 +1042,19 @@ struct f2fs_inode { static_assert(offsetof(struct f2fs_inode, i_extra_end) - offsetof(struct f2fs_inode, i_extra_isize) == 36, ""); -static_assert(sizeof(struct f2fs_inode) == 4072, ""); +static_assert(sizeof(struct f2fs_inode) == F2FS_BLKSIZE - 24, ""); struct direct_node { __le32 addr[DEF_ADDRS_PER_BLOCK]; /* array of data block address */ }; -static_assert(sizeof(struct direct_node) == 4072, ""); +static_assert(sizeof(struct direct_node) == F2FS_BLKSIZE - 24, ""); struct indirect_node { __le32 nid[NIDS_PER_BLOCK]; /* array of data block address */ }; -static_assert(sizeof(struct indirect_node) == 4072, ""); +static_assert(sizeof(struct indirect_node) == F2FS_BLKSIZE - 24, ""); enum { COLD_BIT_SHIFT = 0, @@ -1047,15 +1065,6 @@ enum { #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ >> OFFSET_BIT_SHIFT) -struct node_footer { - __le32 nid; /* node id */ - __le32 ino; /* inode nunmber */ - __le32 flag; /* include cold/fsync/dentry marks and offset */ - __le64 cp_ver __attribute__((packed)); /* checkpoint version */ - __le32 next_blkaddr; /* next node page block address */ -}; - -static_assert(sizeof(struct node_footer) == 24, ""); struct f2fs_node { /* can be one of three types: inode, direct, and indirect types */ @@ -1067,7 +1076,7 @@ struct f2fs_node { struct node_footer footer; }; -static_assert(sizeof(struct f2fs_node) == 4096, ""); +static_assert(sizeof(struct f2fs_node) == F2FS_BLKSIZE, ""); /* * For NAT entries @@ -1089,7 +1098,7 @@ struct f2fs_nat_block { struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK]; }; -static_assert(sizeof(struct f2fs_nat_block) == 4095, ""); +static_assert(sizeof(struct f2fs_nat_block) == F2FS_BLKSIZE - (F2FS_BLKSIZE % 9), ""); /* * For SIT entries @@ -1140,13 +1149,13 @@ struct f2fs_sit_block { struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK]; }; -static_assert(sizeof(struct f2fs_sit_block) == 4070, ""); +static_assert(sizeof(struct f2fs_sit_block) == F2FS_BLKSIZE - (F2FS_BLKSIZE % 74), ""); /* * 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. + * One summary block contains exactly 2048 summary entries, which represents + * exactly 32MB segment by default. Not allow to change the basic units. * * NOTE: For initializing fields, you must use set_summary * @@ -1157,7 +1166,7 @@ static_assert(sizeof(struct f2fs_sit_block) == 4070, ""); * 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 ENTRIES_IN_SUM (F2FS_BLKSIZE / 8) #define SUMMARY_SIZE (7) /* sizeof(struct summary) */ #define SUM_FOOTER_SIZE (5) /* sizeof(struct summary_footer) */ #define SUM_ENTRIES_SIZE (SUMMARY_SIZE * ENTRIES_IN_SUM) @@ -1225,7 +1234,7 @@ struct nat_journal { __u8 reserved[NAT_JOURNAL_RESERVED]; }; -static_assert(sizeof(struct nat_journal) == 505, ""); +static_assert(sizeof(struct nat_journal) == (F2FS_BLKSIZE / 8) - 7, ""); struct sit_journal_entry { __le32 segno; @@ -1239,14 +1248,14 @@ struct sit_journal { __u8 reserved[SIT_JOURNAL_RESERVED]; }; -static_assert(sizeof(struct sit_journal) == 505, ""); +static_assert(sizeof(struct sit_journal) == (F2FS_BLKSIZE / 8) - 7, ""); struct f2fs_extra_info { __le64 kbytes_written; __u8 reserved[EXTRA_INFO_RESERVED]; } __attribute__((packed)); -static_assert(sizeof(struct f2fs_extra_info) == 505, ""); +static_assert(sizeof(struct f2fs_extra_info) == (F2FS_BLKSIZE / 8) - 7, ""); struct f2fs_journal { union { @@ -1261,7 +1270,7 @@ struct f2fs_journal { }; } __attribute__((packed)); -static_assert(sizeof(struct f2fs_journal) == 507, ""); +static_assert(sizeof(struct f2fs_journal) == (F2FS_BLKSIZE / 8) - 5, ""); /* 4KB-sized summary block structure */ struct f2fs_summary_block { @@ -1270,7 +1279,7 @@ struct f2fs_summary_block { struct summary_footer footer; }; -static_assert(sizeof(struct f2fs_summary_block) == 4096, ""); +static_assert(sizeof(struct f2fs_summary_block) == F2FS_BLKSIZE, ""); /* * For directory operations @@ -1289,8 +1298,8 @@ typedef __le32 f2fs_hash_t; #define GET_DENTRY_SLOTS(x) ((x + F2FS_SLOT_LEN - 1) >> F2FS_SLOT_LEN_BITS) /* the number of dentry in a block */ -#define NR_DENTRY_IN_BLOCK 214 - +#define NR_DENTRY_IN_BLOCK ((BITS_PER_BYTE * F2FS_BLKSIZE) / \ + ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1)) /* MAX level for dir lookup */ #define MAX_DIR_HASH_DEPTH 63 diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index 019fb3a..7ad9acf 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -1372,7 +1372,7 @@ static int f2fs_write_default_quota(int qtype, __le32 raw_id) memcpy(filebuf + 5136, &dqblk, sizeof(struct v2r1_disk_dqblk)); - /* Write two blocks */ + /* Write quota blocks */ for (i = 0; i < QUOTA_DATA; i++) { blkaddr = alloc_next_free_block(CURSEG_HOT_DATA); @@ -1385,13 +1385,13 @@ static int f2fs_write_default_quota(int qtype, __le32 raw_id) update_sit_journal(CURSEG_HOT_DATA); update_summary_entry(CURSEG_HOT_DATA, le32_to_cpu(sb->qf_ino[qtype]), i); - } + DBG(1, "\tWriting quota data, at offset %08x (%d/%d)\n", + blkaddr, i + 1, QUOTA_DATA); - DBG(1, "\tWriting quota data, at offset %08x, %08x\n", - blkaddr - 1, blkaddr); + } free(filebuf); - return blkaddr - 1; + return blkaddr + 1 - QUOTA_DATA; } static int f2fs_write_qf_inode(int qtype) @@ -1426,7 +1426,7 @@ static int f2fs_write_qf_inode(int qtype) else ASSERT(0); - /* write two blocks */ + /* write quota blocks */ data_blkaddr = f2fs_write_default_quota(qtype, raw_id); if (data_blkaddr == 0) { free(raw_node); diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c index d8c9cea..c0f4253 100644 --- a/mkfs/f2fs_format_main.c +++ b/mkfs/f2fs_format_main.c @@ -141,7 +141,7 @@ static void add_default_options(void) /* -d1 -f -w 4096 -R 0:0 */ c.dbg_lv = 1; force_overwrite = 1; - c.wanted_sector_size = 4096; + c.wanted_sector_size = c.blksize; c.root_uid = c.root_gid = 0; /* RO doesn't need any other features */ From patchwork Wed Aug 16 01:13:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 13354486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F78CC001DE for ; Wed, 16 Aug 2023 01:46:55 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qW5cc-00085e-Pd; Wed, 16 Aug 2023 01:46:54 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <36SLcZAYKAMwv96Aw5y66y3w.u64@flex--drosen.bounces.google.com>) id 1qW5cb-00085Y-8T for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:46:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=L4D7lyseRfeNGNPXt8iGTjc32JT/WjMSoEi0kpw6uDw=; b=i7QFa+C3qsgs/VoONjJ6TK7Lkp MPjGHkb0ICsAsrA9aOrA/3ZT9SJyHmFcMYugld9+EioXhKFCCJqxz5MNL3V6OtlDGFaO6HWz1ViVN QUSYuN549HoWpYpk2EE8FqjPNAvhqe0hF9Wu+XuDzhQjoAhnGtN6OdQUE4lohF305rMw=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=L4D7lyseRfeNGNPXt8iGTjc32JT/WjMSoEi0kpw6uDw=; b=Rp88hcMkBJ7xoM4dCBK8Ov8Myx RrTiUBVXyZQw6pLIuEB/+Yx8wE8s4ZmQL5ylkV7T1Ufhaovv1sZG/myKPWZ+mmDHQp++DbrIIIfk7 zlCTLP/Tr+WPaU4+1sY4HZVF4Q35ETKE+gAXv4itqMaMcUq+hSIxpL544T3WQPgpcdJ8=; Received: from mail-pj1-f73.google.com ([209.85.216.73]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qW5cZ-006iI7-H5 for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:46:53 +0000 Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-26b639eb9d9so3439319a91.2 for ; Tue, 15 Aug 2023 18:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692150406; x=1692755206; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=L4D7lyseRfeNGNPXt8iGTjc32JT/WjMSoEi0kpw6uDw=; b=Nz55VNXyBQbxF6L9Ri+eZa/Kq3eAdPcW3xDU8KnzSm3U/2QzJeXSqFqrvmDE3/DUnT BF156BpO5F/bCV8a8UoKLaaLQUuf3QKUG5XhZFhbbHQbu61iDvYgWDg8r7eswIvoJOnM ssW05SjwOBMiyhRAKnMfXg+VLU3ryMoeJsnuVvSi01TdwzbVajOYKg4AxrQ952Lm8TOk sKCi6skKP1gF1hzCr0v9BQCz80IHLenaSbAhqwLL/WOHottLznCjuG59c7FACDWI0ej/ 9ILE7tGMCaiHcqjGenhjrag2r8kJE7NNxQy65Q9nhXUlDKvzs9DQWlGpI7SfhJOUKAR3 wDZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692150406; x=1692755206; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=L4D7lyseRfeNGNPXt8iGTjc32JT/WjMSoEi0kpw6uDw=; b=D5/wpl8MQHAqS/KNIEJnm3dNVmg5+tXnbXcJsz9QKH9uIAz7IR7V1j4mTMBjlhiwIH 2J6NOX+hjdo7yZmxGONQ8uFanRHn6PzrmjoIyE3GNOc+SCrg5GiQ8jn67vNg6HrsYBhq jADq2omAKD1cZH8KzCaV+agzqId8hi+1rLRNJSM+sEGeI1o049kMdn6ppDEQhi0ZKlKn j7bviWsBllLhCIqFfroSNUBwXjKo7geYqnklYEJdhPYCwu8bVP3psRzn7+A617kjm153 wnfOUfFGCMTcdCWr3rZbJ3Ei8rkufxX+luveRcuE7h98w520C4F4AQi7GKvDaOrLRhaJ jTdg== X-Gm-Message-State: AOJu0Ywtc9n69BAfv6htDWUwypYY1z+euCu8Q7fwzef+ZF2DrZAz1vYv yId7mcMbcu8ES0p9wfV9aZcsHnRNnYFmTm1LI7W2bvfHXsfZdvjnNHbmeYQzbRmkS11XJfBcUbf rh/0dSfzfA+6NdIf8rn2odaosN3XvCxXguq+r20jKz2LVMjkOV2TQREgpABX7Sn71p/DZ1UE5Yt hzFIkf/wE= X-Google-Smtp-Source: AGHT+IHPKq4dxMpmFe1RHPEYqfZigCi4wfShOxZoTQXA5+b0ZOtDJl6Wc3Sm7OkPs2vHyantx3U8v3JOCkg= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:19fa:33cd:f272:37ec]) (user=drosen job=sendgmr) by 2002:a25:748e:0:b0:d6b:7397:a16f with SMTP id p136-20020a25748e000000b00d6b7397a16fmr7184ybc.1.1692148457722; Tue, 15 Aug 2023 18:14:17 -0700 (PDT) Date: Tue, 15 Aug 2023 18:13:54 -0700 In-Reply-To: <20230816011359.1964484-1-drosen@google.com> Mime-Version: 1.0 References: <20230816011359.1964484-1-drosen@google.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog Message-ID: <20230816011359.1964484-3-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qW5cZ-006iI7-H5 Subject: [f2fs-dev] [PATCH 2/7] f2fs-tools: Refactor Orphan Block struct X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Rosenberg via Linux-f2fs-devel From: Daniel Rosenberg Reply-To: Daniel Rosenberg Cc: Jaegeuk Kim , kernel-team@android.com, Daniel Rosenberg Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This splits off access to the orphan block's footer into a macro call as its location is dependent on block size. Because of this, you should use F2FS_BLKSIZE instead of sizeof(struct f2fs_orphan_block) Signed-off-by: Daniel Rosenberg --- fsck/fsck.c | 4 ++-- fsck/main.c | 1 + include/f2fs_fs.h | 23 ++++++++++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/fsck/fsck.c b/fsck/fsck.c index 78ffdb6..e0dce16 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -2058,7 +2058,7 @@ int fsck_chk_orphan_node(struct f2fs_sb_info *sbi) u32 new_entry_count = 0; ASSERT(ret >= 0); - entry_count = le32_to_cpu(orphan_blk->entry_count); + entry_count = le32_to_cpu(F2FS_ORPHAN_BLOCK_FOOTER(orphan_blk)->entry_count); for (j = 0; j < entry_count; j++) { nid_t ino = le32_to_cpu(orphan_blk->ino[j]); @@ -2094,7 +2094,7 @@ int fsck_chk_orphan_node(struct f2fs_sb_info *sbi) } if (f2fs_dev_is_writable() && c.fix_on && entry_count != new_entry_count) { - new_blk->entry_count = cpu_to_le32(new_entry_count); + F2FS_ORPHAN_BLOCK_FOOTER(new_blk)->entry_count = cpu_to_le32(new_entry_count); ret = dev_write_block(new_blk, start_blk + i); ASSERT(ret >= 0); } diff --git a/fsck/main.c b/fsck/main.c index 3690c74..15e2e4e 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -803,6 +803,7 @@ void f2fs_parse_options(int argc, char *argv[]) return; } + check_block_struct_sizes(); /* print out error */ switch (err) { case EWRONG_OPT: diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 6975143..c5b1e26 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -21,6 +21,7 @@ #define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */ #endif +#include #include #include #include @@ -855,8 +856,19 @@ static_assert(sizeof(struct f2fs_checkpoint) == 192, ""); */ #define F2FS_ORPHANS_PER_BLOCK ((F2FS_BLKSIZE - 4 * sizeof(__le32)) / sizeof(__le32)) +/* + * On disk layout is: + * __le32 ino[F2FS_ORPHANS_PER_BLOCK]; + * struct f2fs_ophan_block_footer + * + * Do NOT use sizeof, use F2FS_BLKSIZE instead + */ struct f2fs_orphan_block { - __le32 ino[F2FS_ORPHANS_PER_BLOCK]; /* inode numbers */ + __le32 ino[0]; /* F2FS_ORPHANS_PER_BLOCK inode numbers */ +}; +#define F2FS_ORPHAN_BLOCK_FOOTER(blk) ((struct orphan_block_footer *)&(blk)->ino[F2FS_ORPHANS_PER_BLOCK]) + +struct orphan_block_footer { __le32 reserved; /* reserved */ __le16 blk_addr; /* block index in current CP */ __le16 blk_count; /* Number of orphan inode blocks in CP */ @@ -864,8 +876,6 @@ struct f2fs_orphan_block { __le32 check_sum; /* CRC32 for orphan inode block */ }; -static_assert(sizeof(struct f2fs_orphan_block) == F2FS_BLKSIZE, ""); - /* * For NODE structure */ @@ -1956,4 +1966,11 @@ extern char *f2fs_encoding2str(const int encoding); extern int f2fs_get_encoding_flags(int encoding); extern int f2fs_str2encoding_flags(char **param, __u16 *flags); +static inline void check_block_struct_sizes(void) +{ + /* Check Orphan Block Size */ + assert(F2FS_ORPHANS_PER_BLOCK * sizeof(__le32) + + sizeof(struct orphan_block_footer) == F2FS_BLKSIZE); +} + #endif /*__F2FS_FS_H */ From patchwork Wed Aug 16 01:13:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 13354483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3FF38C001DE for ; Wed, 16 Aug 2023 01:43:27 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qW5ZD-0007oQ-Oc; Wed, 16 Aug 2023 01:43:24 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <36yLcZAYKAM4xB8Cy708805y.w86@flex--drosen.bounces.google.com>) id 1qW5ZC-0007oK-8W for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:43:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=8gZqwInXuZVoNlp4G9vw1F1FWhGh1+GbA4znhkDam+I=; b=ffN/h6q50YcLs7DnWDQ94AdUwO LHh9AHlpM7gDnXa3JUaKlfp8wU6W9SFF6CBa4sXaL69/X3yuSNCP2snj+lonqXHelt5uAwxGeVZyZ i0W+tzNlH7GcH4O/7O01V3AtVWVgZ92M43Ams0KapfO2O+GvinG7OsWGXQCaBu4oAKGE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=8gZqwInXuZVoNlp4G9vw1F1FWhGh1+GbA4znhkDam+I=; b=l6fmkH+ENtahk8M+7TNOc8fOHR sUEXqrf4SUnw8TrHM/VYPyORrWXPMsE6J2rCiuc4zR3Ct753xZFM+sYTEgULqEyYxNiTGHVzCpnse c51KJaCodDuTuHE44AMozRqTOvI4cP2zc5lSuJH5lyeZIlS7IRZPiSAXl9sqd1DWXy54=; Received: from mail-oa1-f74.google.com ([209.85.160.74]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qW5Z9-0000t7-S0 for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:43:23 +0000 Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-1c4dd4aafa5so2662330fac.0 for ; Tue, 15 Aug 2023 18:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692150194; x=1692754994; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8gZqwInXuZVoNlp4G9vw1F1FWhGh1+GbA4znhkDam+I=; b=Gf0+5MEcvNGzmY2+8K0eaOdmkqHWDWFYZSMs8optnYHqRTJ4r6rqwsf2xjLTc8p9Wa q5AcI1fqa1kQ8L7j5sbqOlGtMuzGoyuOAbm+8P1B0OHVXESL7ZIyMAqwZO0tgjSFnAcm C2D/ndLmTKpEfgvYcRPC85tbMdoM+E87fxdwG67G68bOONL2sUiNsDF4sM22EDhZPcq/ GBsN0/CI2WlvKTTHyBJQWYYY6kumQQoLjWJ5bJ1/dFi+ZGdHsnaPyb58vtfmQiOUN74A 104PJLIvBj5rqT3E88M4U9bBl6qsOxGaM1++XlzMhK46bPWZ4g2RwZUiI17nrcMnW/Qu RQOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692150194; x=1692754994; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8gZqwInXuZVoNlp4G9vw1F1FWhGh1+GbA4znhkDam+I=; b=S4ybGsi6HofNuAvUC7ZFGgcI8TcyDb+LP9DDuNbcmkTgRjfhUP4FVh4JWu0+Buv4hv gE6bhtd1ayJroz8TTpg+JsGHKsrYyUuWliLjNqlInitYq8EC2b8aXh37FZEaM0a3Qff/ i/yZBZxYh9ZhzA7FXnzzpxFC3BvoY3XBNJhPuSupAmOlwYDb18pLaDV0zWzR06OFkurT k6I1mYdVh+r3xO66uSRZMyL/INUTiu6vWtJB9v78Rj3OPPkji3hRI+x8xfiiPHKVeMZW lA0+kPbXgsSvQ0B/M6ThpeNnNxHKgyYPiqta9+7/zAbl+HvGTwfoqfafKnPeMZXsR+n2 dPBA== X-Gm-Message-State: AOJu0YxbD7ycKdiPCqSLPqsvhWQuFVu+cNg/l0QqWtV1DI5xoyNwnrXz R1IoiHeG94Bxd0eMUC79KwhuLYnPhtlcbaOORzUw5jXX3Tv1ltJDSAbXgYWepKCiGFiSbSu6gEf KopX/n9Mi2QS+5OPh9qMLA2C6S1/Ka+euLrEmxWxa4rV5YgXdoU/lfG9dOj2yzej63nvjiy74sC Pa66A40Hw= X-Google-Smtp-Source: AGHT+IEACJWLI2BMNpu5njYuw3knwnUgxiHr+BWFstGHgRniIQ1HawlT1486pkvjPAIsfv6vEhsNuMvdfW4= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:19fa:33cd:f272:37ec]) (user=drosen job=sendgmr) by 2002:a05:6902:1021:b0:d2c:649:f848 with SMTP id x1-20020a056902102100b00d2c0649f848mr15853ybt.1.1692148459919; Tue, 15 Aug 2023 18:14:19 -0700 (PDT) Date: Tue, 15 Aug 2023 18:13:55 -0700 In-Reply-To: <20230816011359.1964484-1-drosen@google.com> Mime-Version: 1.0 References: <20230816011359.1964484-1-drosen@google.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog Message-ID: <20230816011359.1964484-4-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qW5Z9-0000t7-S0 Subject: [f2fs-dev] [PATCH 3/7] f2fs-tools: Refactor f2fs_node struct and friends X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Rosenberg via Linux-f2fs-devel From: Daniel Rosenberg Reply-To: Daniel Rosenberg Cc: Jaegeuk Kim , kernel-team@android.com, Daniel Rosenberg Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This converts inodes, direct nodes, and indirect nodes over to not being based on a 4K page size. f2fs_inode's i_nids field should now be accessed via a macro, as it's location depends on block size. Access to direct nodes and indirect nodes is unchanged. The node footer's location is also based on block sized, and accessed via a macro. With these changes, you should use F2FS_BLKSIZE in place of sizeof(struct f2fs_node) Signed-off-by: Daniel Rosenberg --- fsck/dir.c | 20 ++++++++--------- fsck/dump.c | 24 ++++++++++----------- fsck/f2fs.h | 2 +- fsck/fsck.c | 54 +++++++++++++++++++++++----------------------- fsck/mount.c | 20 ++++++++--------- fsck/node.c | 12 +++++------ fsck/node.h | 20 ++++++++--------- include/f2fs_fs.h | 54 +++++++++++++++++++++++++++++++++------------- lib/libf2fs.c | 2 +- mkfs/f2fs_format.c | 10 ++++----- 10 files changed, 121 insertions(+), 97 deletions(-) diff --git a/fsck/dir.c b/fsck/dir.c index a20aa8b..08523d9 100644 --- a/fsck/dir.c +++ b/fsck/dir.c @@ -116,7 +116,7 @@ static int find_in_level(struct f2fs_sb_info *sbi, struct f2fs_node *dir, struct dnode_of_data dn; void *dentry_blk; int max_slots = 214; - nid_t ino = le32_to_cpu(dir->footer.ino); + nid_t ino = le32_to_cpu(F2FS_NODE_FOOTER(dir)->ino); f2fs_hash_t namehash; unsigned int dir_level = dir->i.i_dir_level; int ret = 0; @@ -239,7 +239,7 @@ int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent, dentry_hash = f2fs_dentry_hash(get_encoding(sbi), IS_CASEFOLDED(&parent->i), name, name_len); - pino = le32_to_cpu(parent->footer.ino); + pino = le32_to_cpu(F2FS_NODE_FOOTER(parent)->ino); dir_level = parent->i.i_dir_level; if (!pino) { @@ -340,7 +340,7 @@ add_dentry: static void make_empty_dir(struct f2fs_sb_info *sbi, struct f2fs_node *inode) { struct f2fs_dentry_block *dent_blk; - nid_t ino = le32_to_cpu(inode->footer.ino); + nid_t ino = le32_to_cpu(F2FS_NODE_FOOTER(inode)->ino); nid_t pino = le32_to_cpu(inode->i.i_pino); struct f2fs_summary sum; struct node_info ni; @@ -381,7 +381,7 @@ static void make_empty_dir(struct f2fs_sb_info *sbi, struct f2fs_node *inode) static void page_symlink(struct f2fs_sb_info *sbi, struct f2fs_node *inode, const char *symname, int symlen) { - nid_t ino = le32_to_cpu(inode->footer.ino); + nid_t ino = le32_to_cpu(F2FS_NODE_FOOTER(inode)->ino); struct f2fs_summary sum; struct node_info ni; char *data_blk; @@ -531,10 +531,10 @@ static void init_inode_block(struct f2fs_sb_info *sbi, set_file_temperature(sbi, node_blk, de->name); - node_blk->footer.ino = cpu_to_le32(de->ino); - node_blk->footer.nid = cpu_to_le32(de->ino); - node_blk->footer.flag = 0; - node_blk->footer.cp_ver = ckpt->checkpoint_ver; + F2FS_NODE_FOOTER(node_blk)->ino = cpu_to_le32(de->ino); + F2FS_NODE_FOOTER(node_blk)->nid = cpu_to_le32(de->ino); + F2FS_NODE_FOOTER(node_blk)->flag = 0; + F2FS_NODE_FOOTER(node_blk)->cp_ver = ckpt->checkpoint_ver; set_cold_node(node_blk, S_ISDIR(mode)); if (S_ISDIR(mode)) { @@ -556,7 +556,7 @@ int convert_inline_dentry(struct f2fs_sb_info *sbi, struct f2fs_node *node, { struct f2fs_inode *inode = &(node->i); unsigned int dir_level = node->i.i_dir_level; - nid_t ino = le32_to_cpu(node->footer.ino); + nid_t ino = le32_to_cpu(F2FS_NODE_FOOTER(node)->ino); char inline_data[MAX_INLINE_DATA(node)]; struct dnode_of_data dn; struct f2fs_dentry_ptr d; @@ -751,7 +751,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de) ret = f2fs_add_link(sbi, parent, child->i.i_name, le32_to_cpu(child->i.i_namelen), - le32_to_cpu(child->footer.ino), + le32_to_cpu(F2FS_NODE_FOOTER(child)->ino), map_de_type(le16_to_cpu(child->i.i_mode)), ni.blk_addr, 1); if (ret) { diff --git a/fsck/dump.c b/fsck/dump.c index e7a1c5c..5a9c440 100644 --- a/fsck/dump.c +++ b/fsck/dump.c @@ -71,7 +71,7 @@ void nat_dump(struct f2fs_sb_info *sbi, nid_t start_nat, nid_t end_nat) "nid:%5u\tino:%5u\toffset:%5u" "\tblkaddr:%10u\tpack:%d\n", ni.nid, ni.ino, - le32_to_cpu(node_block->footer.flag) >> + le32_to_cpu(F2FS_NODE_FOOTER(node_block)->flag) >> OFFSET_BIT_SHIFT, ni.blk_addr, pack); ret = write(fd, buf, strlen(buf)); @@ -92,7 +92,7 @@ void nat_dump(struct f2fs_sb_info *sbi, nid_t start_nat, nid_t end_nat) "nid:%5u\tino:%5u\toffset:%5u" "\tblkaddr:%10u\tpack:%d\n", ni.nid, ni.ino, - le32_to_cpu(node_block->footer.flag) >> + le32_to_cpu(F2FS_NODE_FOOTER(node_block)->flag) >> OFFSET_BIT_SHIFT, ni.blk_addr, pack); ret = write(fd, buf, strlen(buf)); @@ -456,17 +456,17 @@ static int dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid, for (i = 0; i < 5; i++) { if (i == 0 || i == 1) dump_node_blk(sbi, TYPE_DIRECT_NODE, - le32_to_cpu(node_blk->i.i_nid[i]), + le32_to_cpu(F2FS_INODE_I_NID(&node_blk->i, i)), addr_per_block, &ofs); else if (i == 2 || i == 3) dump_node_blk(sbi, TYPE_INDIRECT_NODE, - le32_to_cpu(node_blk->i.i_nid[i]), + le32_to_cpu(F2FS_INODE_I_NID(&node_blk->i, i)), addr_per_block, &ofs); else if (i == 4) dump_node_blk(sbi, TYPE_DOUBLE_INDIRECT_NODE, - le32_to_cpu(node_blk->i.i_nid[i]), + le32_to_cpu(F2FS_INODE_I_NID(&node_blk->i, i)), addr_per_block, &ofs); else @@ -570,11 +570,11 @@ void dump_node_scan_disk(struct f2fs_sb_info *sbi, nid_t nid) ret = dev_read_block(node_blk, blkaddr); ASSERT(ret >= 0); - if (le32_to_cpu(node_blk->footer.ino) != nid || - le32_to_cpu(node_blk->footer.nid) != nid) + if (le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino) != nid || + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid) != nid) continue; MSG(0, "Info: nid: %u, blkaddr: %lu\n", nid, blkaddr); - MSG(0, "node_blk.footer.flag [0x%x]\n", le32_to_cpu(node_blk->footer.flag)); + MSG(0, "node_blk.footer.flag [0x%x]\n", le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->flag)); MSG(0, "node_blk.footer.cp_ver [%x]\n", (u32)(cpver_of_node(node_blk))); print_inode_info(sbi, node_blk, 0); } @@ -608,11 +608,11 @@ int dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force) if (!is_sit_bitmap_set(sbi, ni.blk_addr)) MSG(force, "Invalid sit bitmap, %u\n\n", ni.blk_addr); - DBG(1, "node_blk.footer.ino [0x%x]\n", le32_to_cpu(node_blk->footer.ino)); - DBG(1, "node_blk.footer.nid [0x%x]\n", le32_to_cpu(node_blk->footer.nid)); + DBG(1, "node_blk.footer.ino [0x%x]\n", le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino)); + DBG(1, "node_blk.footer.nid [0x%x]\n", le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid)); - if (le32_to_cpu(node_blk->footer.ino) == ni.ino && - le32_to_cpu(node_blk->footer.nid) == ni.nid) { + if (le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino) == ni.ino && + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid) == ni.nid) { if (!c.show_file_map) print_node_info(sbi, node_blk, force); diff --git a/fsck/f2fs.h b/fsck/f2fs.h index 9791071..0b136b0 100644 --- a/fsck/f2fs.h +++ b/fsck/f2fs.h @@ -332,7 +332,7 @@ static inline void *inline_data_addr(struct f2fs_node *node_blk) static inline unsigned int ofs_of_node(struct f2fs_node *node_blk) { - unsigned flag = le32_to_cpu(node_blk->footer.flag); + unsigned flag = le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->flag); return flag >> OFFSET_BIT_SHIFT; } diff --git a/fsck/fsck.c b/fsck/fsck.c index e0dce16..769ee65 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -243,7 +243,7 @@ static int is_valid_summary(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ret = dev_read_block(node_blk, ni.blk_addr); ASSERT(ret >= 0); - if (le32_to_cpu(node_blk->footer.nid) != nid) + if (le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid) != nid) goto out; /* check its block address */ @@ -436,33 +436,33 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid, ASSERT(ret >= 0); if (ntype == TYPE_INODE && - node_blk->footer.nid != node_blk->footer.ino) { + F2FS_NODE_FOOTER(node_blk)->nid != F2FS_NODE_FOOTER(node_blk)->ino) { ASSERT_MSG("nid[0x%x] footer.nid[0x%x] footer.ino[0x%x]", - nid, le32_to_cpu(node_blk->footer.nid), - le32_to_cpu(node_blk->footer.ino)); + nid, le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid), + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino)); return -EINVAL; } - if (ni->ino != le32_to_cpu(node_blk->footer.ino)) { + if (ni->ino != le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino)) { ASSERT_MSG("nid[0x%x] nat_entry->ino[0x%x] footer.ino[0x%x]", - nid, ni->ino, le32_to_cpu(node_blk->footer.ino)); + nid, ni->ino, le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino)); return -EINVAL; } if (ntype != TYPE_INODE && IS_INODE(node_blk)) { ASSERT_MSG("nid[0x%x] footer.nid[0x%x] footer.ino[0x%x]", - nid, le32_to_cpu(node_blk->footer.nid), - le32_to_cpu(node_blk->footer.ino)); + nid, le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid), + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino)); return -EINVAL; } - if (le32_to_cpu(node_blk->footer.nid) != nid) { + if (le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid) != nid) { ASSERT_MSG("nid[0x%x] blk_addr[0x%x] footer.nid[0x%x]", nid, ni->blk_addr, - le32_to_cpu(node_blk->footer.nid)); + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid)); return -EINVAL; } if (ntype == TYPE_XATTR) { - u32 flag = le32_to_cpu(node_blk->footer.flag); + u32 flag = le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->flag); if ((flag >> OFFSET_BIT_SHIFT) != XATTR_NODE_OFFSET) { ASSERT_MSG("xnid[0x%x] has wrong ofs:[0x%x]", @@ -674,9 +674,9 @@ retry: ret = dev_read_block(node_blk, blkaddr); ASSERT(ret >= 0); - if (le32_to_cpu(node_blk->footer.ino) != + if (le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino) != root_ino || - le32_to_cpu(node_blk->footer.nid) != + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid) != root_ino) continue; @@ -1131,13 +1131,13 @@ check_next: /* readahead node blocks */ for (idx = 0; idx < 5; idx++) { - u32 nid = le32_to_cpu(node_blk->i.i_nid[idx]); + u32 nid = le32_to_cpu(F2FS_INODE_I_NID(&node_blk->i, idx)); fsck_reada_node_block(sbi, nid); } /* check node blocks in inode */ for (idx = 0; idx < 5; idx++) { - nid_t i_nid = le32_to_cpu(node_blk->i.i_nid[idx]); + nid_t i_nid = le32_to_cpu(F2FS_INODE_I_NID(&node_blk->i, idx)); if (idx == 0 || idx == 1) ntype = TYPE_DIRECT_NODE; @@ -1157,7 +1157,7 @@ check_next: *blk_cnt = *blk_cnt + 1; } else if (ret == -EINVAL) { if (c.fix_on) { - node_blk->i.i_nid[idx] = 0; + F2FS_INODE_I_NID(&node_blk->i, idx) = 0; need_fix = 1; FIX_MSG("[0x%x] i_nid[%d] = 0", nid, idx); } @@ -1230,17 +1230,17 @@ skip_blkcnt_fix: file_enc_name(&node_blk->i)); if (ftype == F2FS_FT_ORPHAN) DBG(1, "Orphan Inode: 0x%x [%s] i_blocks: %u\n\n", - le32_to_cpu(node_blk->footer.ino), + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino), en, (u32)i_blocks); if (is_qf_ino(F2FS_RAW_SUPER(sbi), nid)) DBG(1, "Quota Inode: 0x%x [%s] i_blocks: %u\n\n", - le32_to_cpu(node_blk->footer.ino), + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino), en, (u32)i_blocks); if (ftype == F2FS_FT_DIR) { DBG(1, "Directory Inode: 0x%x [%s] depth: %d has %d files\n\n", - le32_to_cpu(node_blk->footer.ino), en, + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino), en, le32_to_cpu(node_blk->i.i_current_depth), child.files); @@ -1276,7 +1276,7 @@ skip_blkcnt_fix: (c.preen_mode != PREEN_MODE_2 || i_gc_failures != 0x01)) { DBG(1, "Regular Inode: 0x%x [%s] depth: %d\n\n", - le32_to_cpu(node_blk->footer.ino), en, + le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino), en, i_gc_failures); if (c.fix_on) { @@ -1436,7 +1436,7 @@ skip: if (need_fix && f2fs_dev_is_writable()) { struct node_info ni; - nid_t nid = le32_to_cpu(node_blk->footer.nid); + nid_t nid = le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid); get_node_info(sbi, nid, &ni); ret = dev_write_block(node_blk, ni.blk_addr); @@ -1478,7 +1478,7 @@ skip: if (need_fix && f2fs_dev_is_writable()) { struct node_info ni; - nid_t nid = le32_to_cpu(node_blk->footer.nid); + nid_t nid = le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->nid); get_node_info(sbi, nid, &ni); ret = dev_write_block(node_blk, ni.blk_addr); @@ -2826,7 +2826,7 @@ static struct f2fs_node *fsck_get_lpf(struct f2fs_sb_info *sbi) de.ino, ni.blk_addr); } - c.lpf_ino = le32_to_cpu(node->footer.ino); + c.lpf_ino = le32_to_cpu(F2FS_NODE_FOOTER(node)->ino); return node; out: free(node); @@ -2839,7 +2839,7 @@ static int fsck_do_reconnect_file(struct f2fs_sb_info *sbi, { char name[80]; size_t namelen; - nid_t ino = le32_to_cpu(fnode->footer.ino); + nid_t ino = le32_to_cpu(F2FS_NODE_FOOTER(fnode)->ino); struct node_info ni; int ftype, ret; @@ -2853,7 +2853,7 @@ static int fsck_do_reconnect_file(struct f2fs_sb_info *sbi, return -EEXIST; } - get_node_info(sbi, le32_to_cpu(lpf->footer.ino), &ni); + get_node_info(sbi, le32_to_cpu(F2FS_NODE_FOOTER(lpf)->ino), &ni); ftype = map_de_type(le16_to_cpu(fnode->i.i_mode)); ret = f2fs_add_link(sbi, lpf, (unsigned char *)name, namelen, ino, ftype, ni.blk_addr, 0); @@ -2866,7 +2866,7 @@ static int fsck_do_reconnect_file(struct f2fs_sb_info *sbi, memcpy(fnode->i.i_name, name, namelen); fnode->i.i_namelen = cpu_to_le32(namelen); fnode->i.i_pino = c.lpf_ino; - get_node_info(sbi, le32_to_cpu(fnode->footer.ino), &ni); + get_node_info(sbi, le32_to_cpu(F2FS_NODE_FOOTER(fnode)->ino), &ni); ret = dev_write_block(fnode, ni.blk_addr); ASSERT(ret >= 0); @@ -3017,7 +3017,7 @@ static void fsck_failed_reconnect_file(struct f2fs_sb_info *sbi, nid_t ino) } for (i = 0; i < 5; i++) { - nid = le32_to_cpu(node->i.i_nid[i]); + nid = le32_to_cpu(F2FS_INODE_I_NID(&node->i, i)); if (!nid) continue; diff --git a/fsck/mount.c b/fsck/mount.c index 831a7a3..b9fff15 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -364,11 +364,11 @@ void print_inode_info(struct f2fs_sb_info *sbi, blkaddr, blkaddr); } - DISP_u32(inode, i_nid[0]); /* direct */ - DISP_u32(inode, i_nid[1]); /* direct */ - DISP_u32(inode, i_nid[2]); /* indirect */ - DISP_u32(inode, i_nid[3]); /* indirect */ - DISP_u32(inode, i_nid[4]); /* double indirect */ + DISP_u32(F2FS_INODE_NIDS(inode), i_nid[0]); /* direct */ + DISP_u32(F2FS_INODE_NIDS(inode), i_nid[1]); /* direct */ + DISP_u32(F2FS_INODE_NIDS(inode), i_nid[2]); /* indirect */ + DISP_u32(F2FS_INODE_NIDS(inode), i_nid[3]); /* indirect */ + DISP_u32(F2FS_INODE_NIDS(inode), i_nid[4]); /* double indirect */ xattr_addr = read_all_xattrs(sbi, node); if (!xattr_addr) @@ -393,8 +393,8 @@ out: void print_node_info(struct f2fs_sb_info *sbi, struct f2fs_node *node_block, int verbose) { - nid_t ino = le32_to_cpu(node_block->footer.ino); - nid_t nid = le32_to_cpu(node_block->footer.nid); + nid_t ino = le32_to_cpu(F2FS_NODE_FOOTER(node_block)->ino); + nid_t nid = le32_to_cpu(F2FS_NODE_FOOTER(node_block)->nid); /* Is this inode? */ if (ino == nid) { DBG(verbose, "Node ID [0x%x:%u] is inode\n", nid, nid); @@ -2058,7 +2058,7 @@ static void restore_node_summary(struct f2fs_sb_info *sbi, for (i = 0; i < sbi->blocks_per_seg; i++, sum_entry++) { ret = dev_read_block(node_blk, addr); ASSERT(ret >= 0); - sum_entry->nid = node_blk->footer.nid; + sum_entry->nid = F2FS_NODE_FOOTER(node_blk)->nid; addr++; } free(node_blk); @@ -2453,7 +2453,7 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid, /* check extent cache entry */ if (!IS_INODE(node_blk)) { - get_node_info(sbi, le32_to_cpu(node_blk->footer.ino), &ni); + get_node_info(sbi, le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino), &ni); /* read inode block */ ret = dev_read_block(node_blk, ni.blk_addr); @@ -3568,7 +3568,7 @@ static int loop_node_chain_fix(block_t blkaddr_fast, } while (blkaddr != blkaddr_entry); /* fix the blkaddr of last node with NULL_ADDR. */ - node_blk->footer.next_blkaddr = NULL_ADDR; + F2FS_NODE_FOOTER(node_blk)->next_blkaddr = NULL_ADDR; if (IS_INODE(node_blk)) err = write_inode(node_blk, blkaddr_tmp); else diff --git a/fsck/node.c b/fsck/node.c index 49bc2b6..3761470 100644 --- a/fsck/node.c +++ b/fsck/node.c @@ -66,7 +66,7 @@ int f2fs_rebuild_qf_inode(struct f2fs_sb_info *sbi, int qtype) if (is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) cp_ver |= (cur_cp_crc(ckpt) << 32); - raw_node->footer.cp_ver = cpu_to_le64(cp_ver); + F2FS_NODE_FOOTER(raw_node)->cp_ver = cpu_to_le64(cp_ver); get_node_info(sbi, ino, &ni); set_summary(&sum, ino, 0, ni.version); @@ -128,10 +128,10 @@ block_t new_node_block(struct f2fs_sb_info *sbi, node_blk = calloc(BLOCK_SZ, 1); ASSERT(node_blk); - node_blk->footer.nid = cpu_to_le32(dn->nid); - node_blk->footer.ino = f2fs_inode->footer.ino; - node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT); - node_blk->footer.cp_ver = ckpt->checkpoint_ver; + F2FS_NODE_FOOTER(node_blk)->nid = cpu_to_le32(dn->nid); + F2FS_NODE_FOOTER(node_blk)->ino = F2FS_NODE_FOOTER(f2fs_inode)->ino; + F2FS_NODE_FOOTER(node_blk)->flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT); + F2FS_NODE_FOOTER(node_blk)->cp_ver = ckpt->checkpoint_ver; set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode))); type = CURSEG_COLD_NODE; @@ -155,7 +155,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi, } /* update nat info */ - update_nat_blkaddr(sbi, le32_to_cpu(f2fs_inode->footer.ino), + update_nat_blkaddr(sbi, le32_to_cpu(F2FS_NODE_FOOTER(f2fs_inode)->ino), dn->nid, blkaddr); dn->node_blk = node_blk; diff --git a/fsck/node.h b/fsck/node.h index d38c322..a6108ac 100644 --- a/fsck/node.h +++ b/fsck/node.h @@ -20,13 +20,13 @@ static inline bool IS_INODE(struct f2fs_node *node) { - return node->footer.ino == node->footer.nid; + return F2FS_NODE_FOOTER(node)->nid == F2FS_NODE_FOOTER(node)->ino; } static inline unsigned int ADDRS_PER_PAGE(struct f2fs_sb_info *sbi, struct f2fs_node *node_blk, struct f2fs_node *inode_blk) { - nid_t ino = le32_to_cpu(node_blk->footer.ino); + nid_t ino = le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino); unsigned int nblocks; if (IS_INODE(node_blk)) @@ -71,7 +71,7 @@ static inline block_t datablock_addr(struct f2fs_node *node_page, 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); + F2FS_INODE_I_NID(&rn->i, off - NODE_DIR1_BLOCK) = cpu_to_le32(nid); else rn->in.nid[off] = cpu_to_le32(nid); } @@ -79,7 +79,7 @@ static inline void set_nid(struct f2fs_node * rn, int off, nid_t nid, int i) 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]); + return le32_to_cpu(F2FS_INODE_I_NID(&rn->i, off - NODE_DIR1_BLOCK)); else return le32_to_cpu(rn->in.nid[off]); } @@ -127,12 +127,12 @@ static inline int IS_DNODE(struct f2fs_node *node_page) static inline nid_t ino_of_node(struct f2fs_node *node_blk) { - return le32_to_cpu(node_blk->footer.ino); + return le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->ino); } static inline __u64 cpver_of_node(struct f2fs_node *node_blk) { - return le64_to_cpu(node_blk->footer.cp_ver); + return le64_to_cpu(F2FS_NODE_FOOTER(node_blk)->cp_ver); } static inline bool is_recoverable_dnode(struct f2fs_sb_info *sbi, @@ -153,23 +153,23 @@ static inline bool is_recoverable_dnode(struct f2fs_sb_info *sbi, static inline block_t next_blkaddr_of_node(struct f2fs_node *node_blk) { - return le32_to_cpu(node_blk->footer.next_blkaddr); + return le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->next_blkaddr); } static inline int is_node(struct f2fs_node *node_blk, int type) { - return le32_to_cpu(node_blk->footer.flag) & (1 << type); + return le32_to_cpu(F2FS_NODE_FOOTER(node_blk)->flag) & (1 << type); } static inline void set_cold_node(struct f2fs_node *rn, bool is_dir) { - unsigned int flag = le32_to_cpu(rn->footer.flag); + unsigned int flag = le32_to_cpu(F2FS_NODE_FOOTER(rn)->flag); if (is_dir) flag &= ~(0x1 << COLD_BIT_SHIFT); else flag |= (0x1 << COLD_BIT_SHIFT); - rn->footer.flag = cpu_to_le32(flag); + F2FS_NODE_FOOTER(rn)->flag = cpu_to_le32(flag); } #define is_fsync_dnode(node_blk) is_node(node_blk, FSYNC_BIT_SHIFT) diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index c5b1e26..13a1c14 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -995,6 +995,14 @@ struct f2fs_compr_blk_cnt { * inode flags */ #define F2FS_COMPR_FL 0x00000004 /* Compress file */ +/* + * On disk layout is + * struct f2fs_inode + * struct f2fs_inode_nids + * + * where the size of f2fs_inode depends on block size. + * Do NOT use sizeof + */ struct f2fs_inode { __le16 i_mode; /* file mode */ __u8 i_advise; /* file hints */ @@ -1044,28 +1052,28 @@ struct f2fs_inode { */ __le32 i_extra_end[0]; /* for attribute size calculation */ } __attribute__((packed)); - __le32 i_addr[DEF_ADDRS_PER_INODE]; /* Pointers to data blocks */ + __le32 i_addr[0]; /* Pointers to DEF_ADDRS_PER_INODE data blocks */ }; +}; +struct f2fs_inode_nids { __le32 i_nid[5]; /* direct(2), indirect(2), double_indirect(1) node id */ }; +#define F2FS_INODE_NIDS(inode) ((struct f2fs_inode_nids *)(&(inode)->i_addr[DEF_ADDRS_PER_INODE])) +#define F2FS_INODE_I_NID(inode, i) (F2FS_INODE_NIDS((inode))->i_nid[(i)]) + static_assert(offsetof(struct f2fs_inode, i_extra_end) - offsetof(struct f2fs_inode, i_extra_isize) == 36, ""); -static_assert(sizeof(struct f2fs_inode) == F2FS_BLKSIZE - 24, ""); struct direct_node { - __le32 addr[DEF_ADDRS_PER_BLOCK]; /* array of data block address */ + __le32 addr[0]; /* array of DEF_ADDRS_PER_BLOCK data block address */ }; -static_assert(sizeof(struct direct_node) == F2FS_BLKSIZE - 24, ""); - struct indirect_node { - __le32 nid[NIDS_PER_BLOCK]; /* array of data block address */ + __le32 nid[0]; /* array of NIDS_PER_BLOCK data block address */ }; -static_assert(sizeof(struct indirect_node) == F2FS_BLKSIZE - 24, ""); - enum { COLD_BIT_SHIFT = 0, FSYNC_BIT_SHIFT, @@ -1075,7 +1083,14 @@ enum { #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ >> OFFSET_BIT_SHIFT) - +/* + * On disk format is: + * struct f2fs_node + * struct node_footer + * + * where the size of f2fs_node depends on Block Size. + * Do NOT use sizeof. Use F2FS_BLKSIZE instead. + */ struct f2fs_node { /* can be one of three types: inode, direct, and indirect types */ union { @@ -1083,10 +1098,9 @@ struct f2fs_node { struct direct_node dn; struct indirect_node in; }; - struct node_footer footer; }; - -static_assert(sizeof(struct f2fs_node) == F2FS_BLKSIZE, ""); +#define F2FS_NODE_FOOTER(blk) ((struct node_footer *)\ + &(((char *)(&(blk)->i))[F2FS_BLKSIZE - sizeof(struct node_footer)])) /* * For NAT entries @@ -1783,9 +1797,9 @@ static inline void show_version(const char *prog) static inline void f2fs_init_inode(struct f2fs_super_block *sb, struct f2fs_node *raw_node, nid_t ino, time_t mtime, mode_t mode) { - raw_node->footer.nid = cpu_to_le32(ino); - raw_node->footer.ino = cpu_to_le32(ino); - raw_node->footer.cp_ver = cpu_to_le64(1); + F2FS_NODE_FOOTER(raw_node)->nid = cpu_to_le32(ino); + F2FS_NODE_FOOTER(raw_node)->ino = cpu_to_le32(ino); + F2FS_NODE_FOOTER(raw_node)->cp_ver = cpu_to_le64(1); raw_node->i.i_uid = cpu_to_le32(c.root_uid); raw_node->i.i_gid = cpu_to_le32(c.root_gid); @@ -1971,6 +1985,16 @@ static inline void check_block_struct_sizes(void) /* Check Orphan Block Size */ assert(F2FS_ORPHANS_PER_BLOCK * sizeof(__le32) + sizeof(struct orphan_block_footer) == F2FS_BLKSIZE); + + /* Check Inode Block Size */ + assert(offsetof(struct f2fs_inode, i_extra_isize) + DEF_ADDRS_PER_INODE * sizeof(__le32) + + sizeof(struct f2fs_inode_nids) + sizeof(struct node_footer) == F2FS_BLKSIZE); + + /* Check Direct Block Size */ + assert(DEF_ADDRS_PER_BLOCK * sizeof(__le32) + sizeof(struct node_footer) == F2FS_BLKSIZE); + + /* Check Indirect Block Size */ + assert(NIDS_PER_BLOCK * sizeof(__le32) + sizeof(struct node_footer) == F2FS_BLKSIZE); } #endif /*__F2FS_FS_H */ diff --git a/lib/libf2fs.c b/lib/libf2fs.c index 577a7e8..838ba7e 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -574,7 +574,7 @@ int f2fs_crc_valid(uint32_t blk_crc, void *buf, int len) __u32 f2fs_inode_chksum(struct f2fs_node *node) { struct f2fs_inode *ri = &node->i; - __le32 ino = node->footer.ino; + __le32 ino = F2FS_NODE_FOOTER(node)->ino; __le32 gen = ri->i_generation; __u32 chksum, chksum_seed; __u32 dummy_cs = 0; diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index 7ad9acf..e8565ee 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -1106,7 +1106,7 @@ static int f2fs_discard_obsolete_dnode(void) if (c.zoned_mode || c.feature & F2FS_FEATURE_RO) return 0; - raw_node = calloc(sizeof(struct f2fs_node), 1); + raw_node = calloc(F2FS_BLKSIZE, 1); if (raw_node == NULL) { MSG(1, "\tError: Calloc Failed for discard_raw_node!!!\n"); return -1; @@ -1130,7 +1130,7 @@ static int f2fs_discard_obsolete_dnode(void) return -1; } - next_blkaddr = le32_to_cpu(raw_node->footer.next_blkaddr); + next_blkaddr = le32_to_cpu(F2FS_NODE_FOOTER(raw_node)->next_blkaddr); memset(raw_node, 0, F2FS_BLKSIZE); DBG(1, "\tDiscard dnode, at offset 0x%08"PRIx64"\n", offset); @@ -1297,7 +1297,7 @@ static int f2fs_write_root_inode(void) cpu_to_le32(data_blkaddr); node_blkaddr = alloc_next_free_block(CURSEG_HOT_NODE); - raw_node->footer.next_blkaddr = cpu_to_le32(node_blkaddr + 1); + F2FS_NODE_FOOTER(raw_node)->next_blkaddr = cpu_to_le32(node_blkaddr + 1); DBG(1, "\tWriting root inode (hot node), offset 0x%x\n", node_blkaddr); if (write_inode(raw_node, node_blkaddr) < 0) { @@ -1415,7 +1415,7 @@ static int f2fs_write_qf_inode(int qtype) raw_node->i.i_flags = F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL; node_blkaddr = alloc_next_free_block(CURSEG_HOT_NODE); - raw_node->footer.next_blkaddr = cpu_to_le32(node_blkaddr + 1); + F2FS_NODE_FOOTER(raw_node)->next_blkaddr = cpu_to_le32(node_blkaddr + 1); if (qtype == 0) raw_id = raw_node->i.i_uid; @@ -1550,7 +1550,7 @@ static int f2fs_write_lpf_inode(void) memcpy(raw_node->i.i_name, LPF, strlen(LPF)); node_blkaddr = alloc_next_free_block(CURSEG_HOT_NODE); - raw_node->footer.next_blkaddr = cpu_to_le32(node_blkaddr + 1); + F2FS_NODE_FOOTER(raw_node)->next_blkaddr = cpu_to_le32(node_blkaddr + 1); data_blkaddr = f2fs_add_default_dentry_lpf(); if (data_blkaddr == 0) { From patchwork Wed Aug 16 01:13:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 13354485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8AAF8C001B0 for ; Wed, 16 Aug 2023 01:45:14 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qW5ay-0007rX-Li; Wed, 16 Aug 2023 01:45:13 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <37iLcZAYKANE0EBF1A3BB381.zB9@flex--drosen.bounces.google.com>) id 1qW5ax-0007rR-KV for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:45:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=EtokK/S0JdydvYkGO4D4dn6PL0VDx3I2PilqfFBiRjU=; b=gPkEkAStaOKcHlkArooNaGxz6m BkNlcJQAOMR/azL1u8nV0XvPGIs1FIC6/argX7kenkq981hDNGR4DXmWo54r2W08/WTFKx/bXXTDV ZjaTxmkXR5TQ06epv0vHfQdEbfv52vyFaTougVk5Kn7n0vq9+r0p/QXzp+HR5fYLjlOc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=EtokK/S0JdydvYkGO4D4dn6PL0VDx3I2PilqfFBiRjU=; b=k0so4gM3F9kKmdMah79jnIU8Qy o3J/YXCZRmprSfew2RrmIfySoVJ4ZXZ5nwSyZGba0KqM1M0Mb/1KppwkR9RhZCpKvWXsD1yYh2fpp pO3hAHm2hUgysb0pPT+C7gY8q6k4p+0AaOekoSCdJyzhdeo8xCjUmcYFMIPdHDU3bqCY=; Received: from mail-yw1-f201.google.com ([209.85.128.201]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qW5ay-006iEv-3X for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:45:12 +0000 Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-58c4d30c349so23436437b3.2 for ; Tue, 15 Aug 2023 18:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692150306; x=1692755106; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EtokK/S0JdydvYkGO4D4dn6PL0VDx3I2PilqfFBiRjU=; b=6x7srC3tM5DZrrk/i/hyQRMxY/pnLHc06l8yLb2KkzJBmYE0+/A+Par/1BmUBRleEF 4pg54Ypj5FYh0SHCwHiaHwQ1VCR4MrHBYIuKUyy1F2ZU2xddO0wicnRxIgqmo8b+9sgQ hMDcrK45LHGCumHpIf2Ty285ozg9wk4LS8JlV29EGcXg4oSBybaS7jWTu/sVHztWnbBy 9Ukq70sTT1Cbau2heVS3mt10CzNeqwYZfTUBA7AJqwF0B6N6312BubN14NPd0DTP/Z5m QL8cGLQkoqTb1035MvsGQd1kAqqW/d0F6KmzoGm38h2XWSWYDl63np93+MhJ3ryRRY3B V1Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692150306; x=1692755106; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EtokK/S0JdydvYkGO4D4dn6PL0VDx3I2PilqfFBiRjU=; b=c24c3I0pioBD4NxSWoLLreSqAh5m9FK6Dxk3BPxtO+yHuhIeneAF4kAJznxcM/mWCf yUE50GD3pXmq/V2LYmSQSAyVY5IMkE7X1WX/a9mA9bGuLQAN+cLBweQnWDosnhUfOwUc a/tRTTCEKkLDkjhbFNUdXOmZZyzNJjG4tVGHtfgpnZRh/TrVDBBZC1rta4bRiIHsKwi3 6MkJItacGk8UCUfGsqeMG0glV7wTAhb/ULUVrTXxeUtgEGREYXunBrx3ZqWcnYI0268s 6E1m3SuvEkjFFFq0b9fvQuADHR2/WCE6jfHPtE3akvog4/d6eu0LrkX/oqsOpK2d4KYs MiHw== X-Gm-Message-State: AOJu0YxxZBd5YrNoD2Fw44m/j96qN1cQR9YKV2eE7yVGOElFPlzxdrGu e5YRpPiQCtntcOjir1URr8DkXsifSLdRVajzEK/KZFfrVKhYkHAP6nknxobcdaKMKmzFnGwsEFl J+DipFnjMyBuZYzQPkZwuEK0KnpF2GIXobX6lMkJRhTbZy/QbMcoBe4hVg3U9KOMmrPwE6Fxmmk XyE1fDFrU= X-Google-Smtp-Source: AGHT+IHtVp52aojaLVtqsEIM5SrI6ZlcQAM7/pFgr/ZT6cqeUx1hwc74hOqkdh79OKO+tfluCLvB5RJMt0g= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:19fa:33cd:f272:37ec]) (user=drosen job=sendgmr) by 2002:a05:690c:731:b0:586:4eae:b943 with SMTP id bt17-20020a05690c073100b005864eaeb943mr3656ywb.8.1692148462518; Tue, 15 Aug 2023 18:14:22 -0700 (PDT) Date: Tue, 15 Aug 2023 18:13:56 -0700 In-Reply-To: <20230816011359.1964484-1-drosen@google.com> Mime-Version: 1.0 References: <20230816011359.1964484-1-drosen@google.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog Message-ID: <20230816011359.1964484-5-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qW5ay-006iEv-3X Subject: [f2fs-dev] [PATCH 4/7] f2fs-tools: Refactor SIT/NAT block structs X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Rosenberg via Linux-f2fs-devel From: Daniel Rosenberg Reply-To: Daniel Rosenberg Cc: Jaegeuk Kim , kernel-team@android.com, Daniel Rosenberg Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This converts f2fs_nat_block and f2fs_sit_block to be variable length arrays. This does not change the way they are accessed, but removes a misleading statment that these sizes are fixed, as opposed to deriving from F2FS_BLKSIZE Signed-off-by: Daniel Rosenberg --- include/f2fs_fs.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 13a1c14..b2d479f 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1119,11 +1119,9 @@ struct f2fs_nat_entry { static_assert(sizeof(struct f2fs_nat_entry) == 9, ""); struct f2fs_nat_block { - struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK]; + struct f2fs_nat_entry entries[0]; /* NAT_ENTRY_PER_BLOCK */ }; -static_assert(sizeof(struct f2fs_nat_block) == F2FS_BLKSIZE - (F2FS_BLKSIZE % 9), ""); - /* * For SIT entries * @@ -1169,12 +1167,14 @@ struct f2fs_sit_entry { static_assert(sizeof(struct f2fs_sit_entry) == 74, ""); +/* + * On disk layout is: + * struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK]; + */ struct f2fs_sit_block { - struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK]; + struct f2fs_sit_entry entries[0]; }; -static_assert(sizeof(struct f2fs_sit_block) == F2FS_BLKSIZE - (F2FS_BLKSIZE % 74), ""); - /* * For segment summary * @@ -1995,6 +1995,14 @@ static inline void check_block_struct_sizes(void) /* Check Indirect Block Size */ assert(NIDS_PER_BLOCK * sizeof(__le32) + sizeof(struct node_footer) == F2FS_BLKSIZE); + + /* Check NAT Block Size */ + assert((NAT_ENTRY_PER_BLOCK + 1) * sizeof(struct f2fs_nat_entry) > F2FS_BLKSIZE); + assert(NAT_ENTRY_PER_BLOCK * sizeof(struct f2fs_nat_entry) <= F2FS_BLKSIZE); + + /* Check SIT Block Size */ + assert((SIT_ENTRY_PER_BLOCK + 1) * sizeof(struct f2fs_nat_entry) > F2FS_BLKSIZE); + assert(SIT_ENTRY_PER_BLOCK * sizeof(struct f2fs_sit_entry) <= F2FS_BLKSIZE); } #endif /*__F2FS_FS_H */ From patchwork Wed Aug 16 01:13:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 13354488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06591C001DE for ; Wed, 16 Aug 2023 01:47:22 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qW5d2-0002lz-AS; Wed, 16 Aug 2023 01:47:20 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <38CLcZAYKANM2GDH3C5DD5A3.1DB@flex--drosen.bounces.google.com>) id 1qW5d0-0002lt-OS for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:47:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SLgKVOvEplZtsuPWS6Tv/NtMiPXnZlAdbUVysQPROQQ=; b=NWgU8RHi6vRT+m7rnj71M2ueTD NQ7A8lAz/UbzmfuGO3D7uU+e4nJErF+/oiO+dDbOVnqRkP8hcHOymr0DXGj9hUn2nAu1+dpRiCud0 c0MZbtYzJ/G2ZbEvjAVp3omJauggu/JkUUI21T9AFc9ynCs8k9xafBcAhMcUiSP71W/0=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=SLgKVOvEplZtsuPWS6Tv/NtMiPXnZlAdbUVysQPROQQ=; b=Q1BxULDaBYoJOAU8QEvFQZNDHr Ri8p8KiDb4sfk+Mn2T+66qBiZZ4BpVGKTvZ6gHl4sgfG37zdyUP8QT9YxsoYL1Zur+2DUrE8+Gpum bitFbtD4RUHZvAYXCEYuci0dpZi7Mcef1B2eIX/hM0yZnZhi0P8M3EkYwm67dfIkfdjc=; Received: from mail-yb1-f201.google.com ([209.85.219.201]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qW5cy-0000yV-UJ for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 01:47:18 +0000 Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-d6adc83eb10so2956513276.2 for ; Tue, 15 Aug 2023 18:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692150431; x=1692755231; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SLgKVOvEplZtsuPWS6Tv/NtMiPXnZlAdbUVysQPROQQ=; b=qTOS297j5ddHJmeXyaadeepQpIPYjXy25FeUmMt6YYY9PVF19Q+lVO/DAFqpEL/kSr r30xJlySG2Q5eVDHOHU8/mgQnPpigw+aanubqG4h2F7Y657Lxum1wq6Kz4vCGE3ULNqe vZgvrIrCK2qAqSDCLT3jbra8YgSElZGtiCJV8UgXga6OxtquDZlIw2S/QNqVY7g2Q7U2 dwsi0Tm/1DQ28BuGGXSuF+XFAW1IQvZ5EzoyhzOe5kfdzJdZEkZpbATY/Rw1j66Eu94W 6EFVTNvfvLR9Sj7lWZ2WJvDEfplFC/2wXEJLuWHzV/ih8Y5nXyVyzrHvp+0evvNUKqwc UUwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692150431; x=1692755231; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SLgKVOvEplZtsuPWS6Tv/NtMiPXnZlAdbUVysQPROQQ=; b=T/CXPsVzna4+2eS53BwucvdYSTpBwvgGI4cK+kCUbbxfF1+ccNP7Mw3EUR2MwyPAVA itY3AOL6MC9DPzC9JwiewXLVUjcDKxyEiiA7ie8zbQZ2nzDYonuQ5Dk3c7x2o4uLPV0V +NSoZ+Yd94z0WuMN9WA4oI9wQLN+GH5MV0CYEfvWaBhOoYb+1+w0YmzRMk6qdmz1cqlu 7UXsxjpXJ/ME+bB7PQ3rnOAs5V2x9noe00ZU8m+xHCuDVTT2l18WRbvdO//lE7xU8Lwp vnG9vACK+wmayt38I5kmrk7WGaoIyQhkCN6cKE85xeR5ywPBRaDpM/ZdgGGa5IBhBAmM 0fMw== X-Gm-Message-State: AOJu0YzmmIqRmR9NuymbTXyfblgPYwWn9zOXaJyekZDDoihTLFx4oEUS Vj5AvR8c4p95cL/8VHIgsUHyM02ltbsZTSjJOxy5rTCbOAfD3/iJeN9gj7TDDAm+cjcz2cJxkgL LZ8mrf071hk1KhsiM630KEC7KX9/si67vb+CFoFiV1rrRTf8Jjs5s4pnQK/jhtKfnHaj6mZh5Ja eQ6j1KAbw= X-Google-Smtp-Source: AGHT+IEIwuibXt852AHwKqI4cyE0USP/R+Nb2GYoyDKdD6p0nse/0M+Bdca7cNUMtUKpPaSwfWPIRTPgXxc= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:19fa:33cd:f272:37ec]) (user=drosen job=sendgmr) by 2002:a25:ad95:0:b0:d64:f7ec:6d5d with SMTP id z21-20020a25ad95000000b00d64f7ec6d5dmr5697ybi.10.1692148464713; Tue, 15 Aug 2023 18:14:24 -0700 (PDT) Date: Tue, 15 Aug 2023 18:13:57 -0700 In-Reply-To: <20230816011359.1964484-1-drosen@google.com> Mime-Version: 1.0 References: <20230816011359.1964484-1-drosen@google.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog Message-ID: <20230816011359.1964484-6-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qW5cy-0000yV-UJ Subject: [f2fs-dev] [PATCH 5/7] f2fs-tools: Refactor Summary block struct and friends X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Rosenberg via Linux-f2fs-devel From: Daniel Rosenberg Reply-To: Daniel Rosenberg Cc: Jaegeuk Kim , kernel-team@android.com, Daniel Rosenberg Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This splits off access to the summary block's journal and footer into a macro call, as their location is dependent on block size. Because of this you should use F2FS_BLKSIZE instead of sizeof(struct summary_block) Signed-off-by: Daniel Rosenberg --- fsck/f2fs.h | 4 +-- fsck/fsck.c | 12 +++---- fsck/mount.c | 48 +++++++++++++-------------- fsck/resize.c | 2 +- include/f2fs_fs.h | 83 +++++++++++++++++++++++++++++++++------------- mkfs/f2fs_format.c | 16 ++++----- 6 files changed, 101 insertions(+), 64 deletions(-) diff --git a/fsck/f2fs.h b/fsck/f2fs.h index 0b136b0..a0fca45 100644 --- a/fsck/f2fs.h +++ b/fsck/f2fs.h @@ -608,8 +608,8 @@ static inline int inline_xattr_size(struct f2fs_inode *inode) } extern int lookup_nat_in_journal(struct f2fs_sb_info *sbi, u32 nid, struct f2fs_nat_entry *ne); -#define IS_SUM_NODE_SEG(footer) (footer.entry_type == SUM_TYPE_NODE) -#define IS_SUM_DATA_SEG(footer) (footer.entry_type == SUM_TYPE_DATA) +#define IS_SUM_NODE_SEG(sum) (F2FS_SUMMARY_BLOCK_FOOTER(sum)->entry_type == SUM_TYPE_NODE) +#define IS_SUM_DATA_SEG(sum) (F2FS_SUMMARY_BLOCK_FOOTER(sum)->entry_type == SUM_TYPE_DATA) static inline unsigned int dir_buckets(unsigned int level, int dir_level) { diff --git a/fsck/fsck.c b/fsck/fsck.c index 769ee65..e605d3c 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -172,7 +172,7 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid, se = get_seg_entry(sbi, segno); if(IS_NODESEG(se->type)) { ASSERT_MSG("Summary footer indicates a node segment: 0x%x", segno); - sum_blk->footer.entry_type = SUM_TYPE_NODE; + F2FS_SUMMARY_BLOCK_FOOTER(sum_blk)->entry_type = SUM_TYPE_NODE; } else { ret = -EINVAL; goto out; @@ -297,7 +297,7 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr, se = get_seg_entry(sbi, segno); if (IS_DATASEG(se->type)) { ASSERT_MSG("Summary footer indicates a data segment: 0x%x", segno); - sum_blk->footer.entry_type = SUM_TYPE_DATA; + F2FS_SUMMARY_BLOCK_FOOTER(sum_blk)->entry_type = SUM_TYPE_DATA; } else { ret = -EINVAL; goto out; @@ -3299,16 +3299,16 @@ int fsck_chk_curseg_info(struct f2fs_sb_info *sbi) se->type = i; ret = -1; } - if (i <= CURSEG_COLD_DATA && IS_SUM_DATA_SEG(sum_blk->footer)) { + if (i <= CURSEG_COLD_DATA && IS_SUM_DATA_SEG(sum_blk)) { continue; - } else if (i > CURSEG_COLD_DATA && IS_SUM_NODE_SEG(sum_blk->footer)) { + } else if (i > CURSEG_COLD_DATA && IS_SUM_NODE_SEG(sum_blk)) { continue; } else { ASSERT_MSG("Incorrect curseg [%d]: segno [0x%x] " "type(SSA) [%d]", i, curseg->segno, - sum_blk->footer.entry_type); + F2FS_SUMMARY_BLOCK_FOOTER(sum_blk)->entry_type); if (c.fix_on || c.preen_mode) - sum_blk->footer.entry_type = + F2FS_SUMMARY_BLOCK_FOOTER(sum_blk)->entry_type = i <= CURSEG_COLD_DATA ? SUM_TYPE_DATA : SUM_TYPE_NODE; ret = -1; diff --git a/fsck/mount.c b/fsck/mount.c index b9fff15..732bfb3 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -1588,7 +1588,7 @@ static int f2fs_early_init_nid_bitmap(struct f2fs_sb_info *sbi) int nid_bitmap_size = (nm_i->max_nid + BITS_PER_BYTE - 1) / BITS_PER_BYTE; struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); struct f2fs_summary_block *sum = curseg->sum_blk; - struct f2fs_journal *journal = &sum->journal; + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(sum); nid_t nid; int i; @@ -1773,7 +1773,7 @@ static int check_nat_bits(struct f2fs_sb_info *sbi, 8 + F2FS_BLKSIZE - 1); unsigned char *nat_bits, *full_nat_bits, *empty_nat_bits; struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); - struct f2fs_journal *journal = &curseg->sum_blk->journal; + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); uint32_t i, j; block_t blkaddr; int err = 0; @@ -1974,12 +1974,12 @@ void reset_curseg(struct f2fs_sb_info *sbi, int type) struct summary_footer *sum_footer; struct seg_entry *se; - sum_footer = &(curseg->sum_blk->footer); + sum_footer = F2FS_SUMMARY_BLOCK_FOOTER(curseg->sum_blk); memset(sum_footer, 0, sizeof(struct summary_footer)); if (IS_DATASEG(type)) - SET_SUM_TYPE(sum_footer, SUM_TYPE_DATA); + SET_SUM_TYPE(curseg->sum_blk, SUM_TYPE_DATA); if (IS_NODESEG(type)) - SET_SUM_TYPE(sum_footer, SUM_TYPE_NODE); + SET_SUM_TYPE(curseg->sum_blk, SUM_TYPE_NODE); se = get_seg_entry(sbi, curseg->segno); se->type = type; se->dirty = 1; @@ -2002,10 +2002,10 @@ static void read_compacted_summaries(struct f2fs_sb_info *sbi) ASSERT(ret >= 0); curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); - memcpy(&curseg->sum_blk->journal.n_nats, kaddr, SUM_JOURNAL_SIZE); + memcpy(&F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk)->n_nats, kaddr, SUM_JOURNAL_SIZE); curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); - memcpy(&curseg->sum_blk->journal.n_sits, kaddr + SUM_JOURNAL_SIZE, + memcpy(&F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk)->n_sits, kaddr + SUM_JOURNAL_SIZE, SUM_JOURNAL_SIZE); offset = 2 * SUM_JOURNAL_SIZE; @@ -2088,7 +2088,7 @@ static void read_normal_summaries(struct f2fs_sb_info *sbi, int type) blk_addr = GET_SUM_BLKADDR(sbi, segno); } - sum_blk = malloc(sizeof(*sum_blk)); + sum_blk = malloc(F2FS_BLKSIZE); ASSERT(sum_blk); ret = dev_read_block(sum_blk, blk_addr); @@ -2098,7 +2098,7 @@ static void read_normal_summaries(struct f2fs_sb_info *sbi, int type) restore_node_summary(sbi, segno, sum_blk); curseg = CURSEG_I(sbi, type); - memcpy(curseg->sum_blk, sum_blk, sizeof(*sum_blk)); + memcpy(curseg->sum_blk, sum_blk, F2FS_BLKSIZE); reset_curseg(sbi, type); free(sum_blk); } @@ -2122,7 +2122,7 @@ void update_sum_entry(struct f2fs_sb_info *sbi, block_t blk_addr, sum_blk = get_sum_block(sbi, segno, &type); memcpy(&sum_blk->entries[offset], sum, sizeof(*sum)); - sum_blk->footer.entry_type = IS_NODESEG(se->type) ? SUM_TYPE_NODE : + F2FS_SUMMARY_BLOCK_FOOTER(sum_blk)->entry_type = IS_NODESEG(se->type) ? SUM_TYPE_NODE : SUM_TYPE_DATA; /* write SSA all the time */ @@ -2164,7 +2164,7 @@ static int build_curseg(struct f2fs_sb_info *sbi) SM_I(sbi)->curseg_array = array; for (i = 0; i < NR_CURSEG_TYPE; i++) { - array[i].sum_blk = calloc(sizeof(*(array[i].sum_blk)), 1); + array[i].sum_blk = calloc(F2FS_BLKSIZE, 1); if (!array[i].sum_blk) { MSG(1, "\tError: Calloc failed for build_curseg!!\n"); goto seg_cleanup; @@ -2334,7 +2334,7 @@ struct f2fs_summary_block *get_sum_block(struct f2fs_sb_info *sbi, for (type = 0; type < NR_CURSEG_NODE_TYPE; type++) { if (segno == get_cp(cur_node_segno[type])) { curseg = CURSEG_I(sbi, CURSEG_HOT_NODE + type); - if (!IS_SUM_NODE_SEG(curseg->sum_blk->footer)) { + if (!IS_SUM_NODE_SEG(curseg->sum_blk)) { ASSERT_MSG("segno [0x%x] indicates a data " "segment, but should be node", segno); @@ -2349,7 +2349,7 @@ struct f2fs_summary_block *get_sum_block(struct f2fs_sb_info *sbi, for (type = 0; type < NR_CURSEG_DATA_TYPE; type++) { if (segno == get_cp(cur_data_segno[type])) { curseg = CURSEG_I(sbi, type); - if (IS_SUM_NODE_SEG(curseg->sum_blk->footer)) { + if (IS_SUM_NODE_SEG(curseg->sum_blk)) { ASSERT_MSG("segno [0x%x] indicates a node " "segment, but should be data", segno); @@ -2367,9 +2367,9 @@ struct f2fs_summary_block *get_sum_block(struct f2fs_sb_info *sbi, ret = dev_read_block(sum_blk, ssa_blk); ASSERT(ret >= 0); - if (IS_SUM_NODE_SEG(sum_blk->footer)) + if (IS_SUM_NODE_SEG(sum_blk)) *ret_type = SEG_TYPE_NODE; - else if (IS_SUM_DATA_SEG(sum_blk->footer)) + else if (IS_SUM_DATA_SEG(sum_blk)) *ret_type = SEG_TYPE_DATA; return sum_blk; @@ -2519,7 +2519,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) { struct sit_info *sit_i = SIT_I(sbi); struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); - struct f2fs_journal *journal = &curseg->sum_blk->journal; + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); struct f2fs_sit_block *sit_blk; struct seg_entry *se; struct f2fs_sit_entry sit; @@ -2685,7 +2685,7 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi) sit_blk = calloc(BLOCK_SZ, 1); ASSERT(sit_blk); /* remove sit journal */ - sum->journal.n_sits = 0; + F2FS_SUMMARY_BLOCK_JOURNAL(sum)->n_sits = 0; ptr = fsck->main_area_bitmap; @@ -2726,7 +2726,7 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi) static int flush_sit_journal_entries(struct f2fs_sb_info *sbi) { struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); - struct f2fs_journal *journal = &curseg->sum_blk->journal; + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); struct sit_info *sit_i = SIT_I(sbi); struct f2fs_sit_block *sit_blk; unsigned int segno; @@ -2760,7 +2760,7 @@ static int flush_sit_journal_entries(struct f2fs_sb_info *sbi) static int flush_nat_journal_entries(struct f2fs_sb_info *sbi) { struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); - struct f2fs_journal *journal = &curseg->sum_blk->journal; + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); struct f2fs_nat_block *nat_block; pgoff_t block_addr; int entry_off; @@ -3064,7 +3064,7 @@ void zero_journal_entries(struct f2fs_sb_info *sbi) int i; for (i = 0; i < NO_CHECK_TYPE; i++) - CURSEG_I(sbi, i)->sum_blk->journal.n_nats = 0; + F2FS_SUMMARY_BLOCK_JOURNAL(CURSEG_I(sbi, i)->sum_blk)->n_nats = 0; } void write_curseg_info(struct f2fs_sb_info *sbi) @@ -3092,7 +3092,7 @@ int lookup_nat_in_journal(struct f2fs_sb_info *sbi, u32 nid, struct f2fs_nat_entry *raw_nat) { struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); - struct f2fs_journal *journal = &curseg->sum_blk->journal; + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); int i = 0; for (i = 0; i < nats_in_cursum(journal); i++) { @@ -3109,7 +3109,7 @@ int lookup_nat_in_journal(struct f2fs_sb_info *sbi, u32 nid, void nullify_nat_entry(struct f2fs_sb_info *sbi, u32 nid) { struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); - struct f2fs_journal *journal = &curseg->sum_blk->journal; + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); struct f2fs_nat_block *nat_block; pgoff_t block_addr; int entry_off; @@ -3153,7 +3153,7 @@ void update_nat_journal_blkaddr(struct f2fs_sb_info *sbi, u32 nid, block_t blkaddr) { struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); - struct f2fs_journal *journal = &curseg->sum_blk->journal; + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); int i; for (i = 0; i < nats_in_cursum(journal); i++) { @@ -3314,7 +3314,7 @@ void write_checkpoints(struct f2fs_sb_info *sbi) void build_nat_area_bitmap(struct f2fs_sb_info *sbi) { struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); - struct f2fs_journal *journal = &curseg->sum_blk->journal; + struct f2fs_journal *journal = F2FS_SUMMARY_BLOCK_JOURNAL(curseg->sum_blk); struct f2fs_fsck *fsck = F2FS_FSCK(sbi); struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); struct f2fs_nm_info *nm_i = NM_I(sbi); diff --git a/fsck/resize.c b/fsck/resize.c index 2fd3941..6c3f4bd 100644 --- a/fsck/resize.c +++ b/fsck/resize.c @@ -222,7 +222,7 @@ static void move_ssa(struct f2fs_sb_info *sbi, unsigned int segno, ASSERT(ret >= 0); DBG(1, "Write summary block: (%d) segno=%x/%x --> (%d) %x\n", type, segno, GET_SUM_BLKADDR(sbi, segno), - IS_SUM_NODE_SEG(sum_blk->footer), + IS_SUM_NODE_SEG(sum_blk), new_sum_blk_addr); } if (type == SEG_TYPE_NODE || type == SEG_TYPE_DATA || diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index b2d479f..e6c68b2 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -620,8 +620,8 @@ enum { /* * Copied from fs/f2fs/segment.h */ -#define GET_SUM_TYPE(footer) ((footer)->entry_type) -#define SET_SUM_TYPE(footer, type) ((footer)->entry_type = type) +#define GET_SUM_TYPE(sum) (F2FS_SUMMARY_BLOCK_FOOTER(sum)->entry_type) +#define SET_SUM_TYPE(sum, type) (F2FS_SUMMARY_BLOCK_FOOTER(sum)->entry_type = type) /* * Copied from include/linux/f2fs_sb.h @@ -630,6 +630,7 @@ enum { #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE F2FS_BLKSIZE_BITS /* 12 bits for 4096 bytes */ #define F2FS_BLKSIZE (1 << F2FS_BLKSIZE_BITS)/* support only 4KB block */ +#define F2FS_MAX_BLKSIZE 16384 #define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_EXTENSION_LEN 8 /* max size of extension */ #define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE) @@ -1253,13 +1254,15 @@ struct nat_journal_entry { static_assert(sizeof(struct nat_journal_entry) == 13, ""); +/* + * Layout is as follows: + * struct nat_journal_entry entries[NAT_JOURNAL_ENTRIES]; + * __u8 reserved[NAT_JOURNAL_RESERVED]; + */ struct nat_journal { - struct nat_journal_entry entries[NAT_JOURNAL_ENTRIES]; - __u8 reserved[NAT_JOURNAL_RESERVED]; + struct nat_journal_entry entries[0]; }; -static_assert(sizeof(struct nat_journal) == (F2FS_BLKSIZE / 8) - 7, ""); - struct sit_journal_entry { __le32 segno; struct f2fs_sit_entry se; @@ -1267,20 +1270,28 @@ struct sit_journal_entry { static_assert(sizeof(struct sit_journal_entry) == 78, ""); +/* + * Layout is as follows: + * struct sit_journal_entry entries[SIT_JOURNAL_ENTRIES]; + * __u8 reserved[SIT_JOURNAL_RESERVED]; + */ struct sit_journal { - struct sit_journal_entry entries[SIT_JOURNAL_ENTRIES]; - __u8 reserved[SIT_JOURNAL_RESERVED]; + struct sit_journal_entry entries[0]; }; -static_assert(sizeof(struct sit_journal) == (F2FS_BLKSIZE / 8) - 7, ""); - +/* + * Layout is as follows: + * __le64 kbytes_written; + * __u8 reserved[EXTRA_INFO_RESERVED]; + */ struct f2fs_extra_info { __le64 kbytes_written; - __u8 reserved[EXTRA_INFO_RESERVED]; + __u8 reserved[0]; } __attribute__((packed)); -static_assert(sizeof(struct f2fs_extra_info) == (F2FS_BLKSIZE / 8) - 7, ""); - +/* + * This struct's used size depends on F2FS_BLKSIZE. DO NOT use sizeof + */ struct f2fs_journal { union { __le16 n_nats; @@ -1294,16 +1305,22 @@ struct f2fs_journal { }; } __attribute__((packed)); -static_assert(sizeof(struct f2fs_journal) == (F2FS_BLKSIZE / 8) - 5, ""); - -/* 4KB-sized summary block structure */ +/* + * Block-sized summary block structure + * Layout of f2fs_summary block is + * struct f2fs_summary entries[ENTRIES_IN_SUM]; + * struct f2fs_journal journal; + * struct summary_footer footer; + * + * Do NOT use sizeof, use F2FS_BLKSIZE + * + */ struct f2fs_summary_block { - struct f2fs_summary entries[ENTRIES_IN_SUM]; - struct f2fs_journal journal; - struct summary_footer footer; + struct f2fs_summary entries[0]; }; - -static_assert(sizeof(struct f2fs_summary_block) == F2FS_BLKSIZE, ""); +#define F2FS_SUMMARY_BLOCK_JOURNAL(blk) ((struct f2fs_journal *)(&(blk)->entries[ENTRIES_IN_SUM])) +#define F2FS_SUMMARY_BLOCK_FOOTER(blk) ((struct summary_footer *)&((char *)\ + (&(blk)->entries[0]))[F2FS_BLKSIZE - SUM_FOOTER_SIZE]) /* * For directory operations @@ -1511,9 +1528,15 @@ struct f2fs_configuration { compress_config_t compress; block_t curseg_offset[NR_CURSEG_TYPE]; - struct f2fs_journal sit_jnl; - struct f2fs_journal nat_jnl; struct f2fs_summary sum[NR_CURSEG_TYPE][MAX_CACHE_SUMS]; + union { + struct f2fs_journal sit_jnl; + char sit_bytes[F2FS_MAX_BLKSIZE]; + }; + union { + struct f2fs_journal nat_jnl; + char nat_bytes[F2FS_MAX_BLKSIZE]; + }; }; extern int utf8_to_utf16(char *, const char *, size_t, size_t); @@ -2003,6 +2026,20 @@ static inline void check_block_struct_sizes(void) /* Check SIT Block Size */ assert((SIT_ENTRY_PER_BLOCK + 1) * sizeof(struct f2fs_nat_entry) > F2FS_BLKSIZE); assert(SIT_ENTRY_PER_BLOCK * sizeof(struct f2fs_sit_entry) <= F2FS_BLKSIZE); + + /* Check NAT Journal Block Size */ + assert(sizeof(struct f2fs_summary) * ENTRIES_IN_SUM + + NAT_JOURNAL_ENTRIES * sizeof(struct sit_journal_entry) + + NAT_JOURNAL_RESERVED + sizeof(struct summary_footer) == F2FS_BLKSIZE); + + /* Check SIT Journal Block Size */ + assert(sizeof(struct f2fs_summary) * ENTRIES_IN_SUM + + SIT_JOURNAL_ENTRIES * sizeof(struct nat_journal_entry) + + SIT_JOURNAL_RESERVED + sizeof(struct summary_footer) == F2FS_BLKSIZE); + + /* Check Info Journal Block Size */ + assert(sizeof(struct f2fs_summary) * ENTRIES_IN_SUM + sizeof(__le64) + + EXTRA_INFO_RESERVED + sizeof(struct summary_footer) == F2FS_BLKSIZE); } #endif /*__F2FS_FS_H */ diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index e8565ee..461bd77 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -929,8 +929,8 @@ static int f2fs_write_check_point_pack(void) sum_compact_p += SUM_JOURNAL_SIZE; /* hot data summary */ - memset(sum, 0, sizeof(struct f2fs_summary_block)); - SET_SUM_TYPE((&sum->footer), SUM_TYPE_DATA); + memset(sum, 0, F2FS_BLKSIZE); + SET_SUM_TYPE(sum, SUM_TYPE_DATA); sum_entry = (struct f2fs_summary *)sum_compact_p; memcpy(sum_entry, c.sum[CURSEG_HOT_DATA], @@ -948,8 +948,8 @@ static int f2fs_write_check_point_pack(void) } /* Prepare and write Segment summary for HOT_NODE */ - memset(sum, 0, sizeof(struct f2fs_summary_block)); - SET_SUM_TYPE((&sum->footer), SUM_TYPE_NODE); + memset(sum, 0, F2FS_BLKSIZE); + SET_SUM_TYPE(sum, SUM_TYPE_NODE); memcpy(sum->entries, c.sum[CURSEG_HOT_NODE], sizeof(struct f2fs_summary) * MAX_CACHE_SUMS); @@ -962,8 +962,8 @@ static int f2fs_write_check_point_pack(void) } /* Fill segment summary for WARM_NODE to zero. */ - memset(sum, 0, sizeof(struct f2fs_summary_block)); - SET_SUM_TYPE((&sum->footer), SUM_TYPE_NODE); + memset(sum, 0, F2FS_BLKSIZE); + SET_SUM_TYPE(sum, SUM_TYPE_NODE); cp_seg_blk++; DBG(1, "\tWriting Segment summary for WARM_NODE, at offset 0x%08"PRIx64"\n", @@ -974,8 +974,8 @@ static int f2fs_write_check_point_pack(void) } /* Fill segment summary for COLD_NODE to zero. */ - memset(sum, 0, sizeof(struct f2fs_summary_block)); - SET_SUM_TYPE((&sum->footer), SUM_TYPE_NODE); + memset(sum, 0, F2FS_BLKSIZE); + SET_SUM_TYPE(sum, SUM_TYPE_NODE); cp_seg_blk++; DBG(1, "\tWriting Segment summary for COLD_NODE, at offset 0x%08"PRIx64"\n", cp_seg_blk); From patchwork Wed Aug 16 01:13:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 13354515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8EA64C04A6A for ; Wed, 16 Aug 2023 02:14:33 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qW63L-00021h-Jh; Wed, 16 Aug 2023 02:14:32 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <38iLcZAYKANU4IFJ5E7FF7C5.3FD@flex--drosen.bounces.google.com>) id 1qW63K-00021b-6D for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 02:14:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=i3fLgyvcZKZlhjVUn/VWflr0S7LY1e32RwdKatmiAG4=; b=g+tk4UHZVw62H6ElTGMZ2wUpJQ lo0GtT2EOlF2q26k9RhKk4+XD6qr9HlwkbDThh3rgZTLiPkC6o7SCRSaFt4iC0Noi05djlenAj4VN xkDuu1iOgY8Ej+XdvUaSL4qiS+Vhu307kB8mK2D8fos97ZVIB2vuIRNjlXUhUfsNgN3E=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=i3fLgyvcZKZlhjVUn/VWflr0S7LY1e32RwdKatmiAG4=; b=hw+2TBL3rxlYSLWo6AjYzlluT+ d0pkifBtzHX80p1h61vLPjaVtngTDBppnbDm9gpIispGBDIXmHcxNU6LmNO9VIik/Nt9zWlL2Lv+1 E9mhN/nmHqN0rJfK0gPsDxyOQ0Owx+lil8VNupwdn1reU/yIX6PzAygkK1zdujtjbuHQ=; Received: from mail-yw1-f202.google.com ([209.85.128.202]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qW63J-006j5T-BG for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 02:14:31 +0000 Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-589c2516024so60999657b3.3 for ; Tue, 15 Aug 2023 19:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692152063; x=1692756863; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=i3fLgyvcZKZlhjVUn/VWflr0S7LY1e32RwdKatmiAG4=; b=dQkupbLKB6l/MTEilcDw9OEzP4Icex3/oMpCJtNTGVw4Qodkd9D+3sru2EgSSaBrmh tQNUgXXB5PgsViOygAKWzn+Byc75phrM1PeJ4yfi/jeDtNkYJCcZ9g5eRmqPAHdyn0ng R+aDdJbHi8YMEacsbuHMoYDw7VRX9/c+lVckXSsxnvBSw1TAy0hsjCAqJvRx57CfOgey wCMQfN4Ho830kINDYYlPo5T50KU4cduVVbVWkYrZGOAKwBAh/XCQFE1n7f/vOk2dsED+ 1MI5wuRPYLgm4xYoiLl2FjHMkANYN6unjsHVKG/oa7ZbaoHXwcbYxCsBktbWMyiLvIXc 0gyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692152063; x=1692756863; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i3fLgyvcZKZlhjVUn/VWflr0S7LY1e32RwdKatmiAG4=; b=FCKhW/XQDMAIhHNFPoOay+rjlwDPwpt55cchMq0NP/DqjsRUbv9Zo2OwlLkYGRCaco p3ylAnsCQr3eyxchRpU/fp/VYoieg6PLGd1g0uKjQ6xO2plxO2uM3LUQHZ7hMxLk515o 6Nyl0Rr6lCHDnOTl51Dogb+HuLUAzonKpsEMRKHUBGHTwRYgGpOYlmymuaIVuZd+XNPS b6PUOF4daXMz9xeaTvxdYUioN3KACVrfKEcozcN/tsT5GPInIBvofXslKIUIA0iz5iBY w6eyWK0R6Z50v6Q9rdvyo2zfFtAgWssDSfqFJyWTtmwQpiRVpThYdDyIVC+qYYmjt09v pMww== X-Gm-Message-State: AOJu0YyOMnZT4HFjGhviK13NKIbGeYr0mC5w/169e0BvKOeV6mhSgCy0 9+Rn66U4Psdvqz8TRc1aPYDzxObFt1DqpVkrotia27KxT0HRHJCsl/+4efFElL6MvwHKhNwD3Ar eZQIKLqsMsDMKyXba9do4eE8RRIR9/cdKE6rO2FJH67g2pyq1+13iw6jL9c357NaSl+xQc/9fuV 6S8svB6nY= X-Google-Smtp-Source: AGHT+IG9+qsH2AJ0xUabzztT9CPprqSBx+aOOO+gKZSHB8qarHoK7PwgLYQhK5qMdFI26PHh/5DW4PaOgvY= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:19fa:33cd:f272:37ec]) (user=drosen job=sendgmr) by 2002:a81:b64c:0:b0:56f:f62b:7a11 with SMTP id h12-20020a81b64c000000b0056ff62b7a11mr3225ywk.8.1692148466610; Tue, 15 Aug 2023 18:14:26 -0700 (PDT) Date: Tue, 15 Aug 2023 18:13:58 -0700 In-Reply-To: <20230816011359.1964484-1-drosen@google.com> Mime-Version: 1.0 References: <20230816011359.1964484-1-drosen@google.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog Message-ID: <20230816011359.1964484-7-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qW63J-006j5T-BG Subject: [f2fs-dev] [PATCH 6/7] f2fs-tools: Refactor f2fs_dentry_block struct X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Rosenberg via Linux-f2fs-devel From: Daniel Rosenberg Reply-To: Daniel Rosenberg Cc: Jaegeuk Kim , kernel-team@android.com, Daniel Rosenberg Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This moves access to f2fs_dentry_block's dentry list and filename list behind a macro, as their locations depend on block size. Since struct f2fs_dentry_block no longer represents the full block, use F2FS_BLKSIZE instead of sizeof(struct f2fs_dentry_block) Signed-off-by: Daniel Rosenberg --- fsck/dir.c | 26 +++++++++++----------- fsck/fsck.c | 2 +- include/f2fs_fs.h | 30 ++++++++++++++++++++------ mkfs/f2fs_format.c | 54 +++++++++++++++++++++++----------------------- 4 files changed, 65 insertions(+), 47 deletions(-) diff --git a/fsck/dir.c b/fsck/dir.c index 08523d9..05d291c 100644 --- a/fsck/dir.c +++ b/fsck/dir.c @@ -43,8 +43,8 @@ void make_dentry_ptr(struct f2fs_dentry_ptr *d, struct f2fs_node *node_blk, d->max = NR_DENTRY_IN_BLOCK; d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; d->bitmap = t->dentry_bitmap; - d->dentry = t->dentry; - d->filename = t->filename; + d->dentry = F2FS_DENTRY_BLOCK_DENTRIES(t); + d->filename = F2FS_DENTRY_BLOCK_FILENAMES(t); } else { int entry_cnt = NR_INLINE_DENTRY(node_blk); int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(node_blk); @@ -352,17 +352,17 @@ static void make_empty_dir(struct f2fs_sb_info *sbi, struct f2fs_node *inode) dent_blk = calloc(BLOCK_SZ, 1); ASSERT(dent_blk); - dent_blk->dentry[0].hash_code = 0; - dent_blk->dentry[0].ino = cpu_to_le32(ino); - dent_blk->dentry[0].name_len = cpu_to_le16(1); - dent_blk->dentry[0].file_type = F2FS_FT_DIR; - memcpy(dent_blk->filename[0], ".", 1); - - dent_blk->dentry[1].hash_code = 0; - dent_blk->dentry[1].ino = cpu_to_le32(pino); - dent_blk->dentry[1].name_len = cpu_to_le16(2); - dent_blk->dentry[1].file_type = F2FS_FT_DIR; - memcpy(dent_blk->filename[1], "..", 2); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).hash_code = 0; + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).ino = cpu_to_le32(ino); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).name_len = cpu_to_le16(1); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).file_type = F2FS_FT_DIR; + memcpy(F2FS_DENTRY_BLOCK_FILENAME(dent_blk, 0), ".", 1); + + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).hash_code = 0; + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).ino = cpu_to_le32(pino); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).name_len = cpu_to_le16(2); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).file_type = F2FS_FT_DIR; + memcpy(F2FS_DENTRY_BLOCK_FILENAME(dent_blk, 1), "..", 2); test_and_set_bit_le(0, dent_blk->dentry_bitmap); test_and_set_bit_le(1, dent_blk->dentry_bitmap); diff --git a/fsck/fsck.c b/fsck/fsck.c index e605d3c..13494b0 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -1963,7 +1963,7 @@ int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi, int casefolded, u32 blk_addr, dentries = __chk_dentries(sbi, casefolded, child, de_blk->dentry_bitmap, - de_blk->dentry, de_blk->filename, + F2FS_DENTRY_BLOCK_DENTRIES(de_blk), F2FS_DENTRY_BLOCK_FILENAMES(de_blk), NR_DENTRY_IN_BLOCK, last_blk, enc_name); if (dentries < 0 && f2fs_dev_is_writable()) { diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index e6c68b2..adbd381 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1365,16 +1365,29 @@ struct f2fs_dir_entry { static_assert(sizeof(struct f2fs_dir_entry) == 11, ""); -/* 4KB-sized directory entry block */ +/* + * Block-sized directory entry block + * On disk structure: + * struct f2fs_dentry_block; + * __u8 reserved[SIZE_OF_RESERVED]; + * struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK]; + * __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; + * + * Do NOT use sizeof. Use F2FS_BLKSIZE instead + */ 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]; + __u8 dentry_bitmap[0]; /* size is SIZE_OF_DENTRY_BITMAP, based on block size */ }; -static_assert(sizeof(struct f2fs_dentry_block) == F2FS_BLKSIZE, ""); +#define F2FS_DENTRY_BLOCK_DENTRIES(blk) ((struct f2fs_dir_entry *)\ + &((blk)->dentry_bitmap[SIZE_OF_DENTRY_BITMAP + SIZE_OF_RESERVED])) +#define F2FS_DENTRY_BLOCK_DENTRY(blk, i) (F2FS_DENTRY_BLOCK_DENTRIES((blk))[(i)]) + +#define F2FS_DENTRY_BLOCK_FILENAMES(blk) ((__u8(*)[F2FS_SLOT_LEN])&F2FS_DENTRY_BLOCK_DENTRY(blk,\ + NR_DENTRY_IN_BLOCK)) +#define F2FS_DENTRY_BLOCK_FILENAME(blk, i) (&((__u8 *)&F2FS_DENTRY_BLOCK_DENTRY(blk,\ + NR_DENTRY_IN_BLOCK))[(i) * F2FS_SLOT_LEN]) /* for inline stuff */ #define DEF_INLINE_RESERVED_SIZE 1 @@ -2040,6 +2053,11 @@ static inline void check_block_struct_sizes(void) /* Check Info Journal Block Size */ assert(sizeof(struct f2fs_summary) * ENTRIES_IN_SUM + sizeof(__le64) + EXTRA_INFO_RESERVED + sizeof(struct summary_footer) == F2FS_BLKSIZE); + + /* Check Dentry Block Size */ + assert(sizeof(__u8) * (SIZE_OF_DENTRY_BITMAP + SIZE_OF_RESERVED) + + NR_DENTRY_IN_BLOCK * sizeof(struct f2fs_dir_entry) + + NR_DENTRY_IN_BLOCK * F2FS_SLOT_LEN * sizeof(u8) == F2FS_BLKSIZE); } #endif /*__F2FS_FS_H */ diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index 461bd77..e1dd5c5 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -1219,17 +1219,17 @@ static block_t f2fs_add_default_dentry_root(void) return 0; } - dent_blk->dentry[0].hash_code = 0; - dent_blk->dentry[0].ino = sb->root_ino; - dent_blk->dentry[0].name_len = cpu_to_le16(1); - dent_blk->dentry[0].file_type = F2FS_FT_DIR; - memcpy(dent_blk->filename[0], ".", 1); - - dent_blk->dentry[1].hash_code = 0; - dent_blk->dentry[1].ino = sb->root_ino; - dent_blk->dentry[1].name_len = cpu_to_le16(2); - dent_blk->dentry[1].file_type = F2FS_FT_DIR; - memcpy(dent_blk->filename[1], "..", 2); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).hash_code = 0; + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).ino = sb->root_ino; + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).name_len = cpu_to_le16(1); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).file_type = F2FS_FT_DIR; + memcpy(F2FS_DENTRY_BLOCK_FILENAME(dent_blk, 0), ".", 1); + + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).hash_code = 0; + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).ino = sb->root_ino; + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).name_len = cpu_to_le16(2); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).file_type = F2FS_FT_DIR; + memcpy(F2FS_DENTRY_BLOCK_FILENAME(dent_blk, 1), "..", 2); /* bitmap for . and .. */ test_and_set_bit_le(0, dent_blk->dentry_bitmap); @@ -1239,13 +1239,13 @@ static block_t f2fs_add_default_dentry_root(void) int len = strlen(LPF); f2fs_hash_t hash = f2fs_dentry_hash(0, 0, (unsigned char *)LPF, len); - dent_blk->dentry[2].hash_code = cpu_to_le32(hash); - dent_blk->dentry[2].ino = cpu_to_le32(c.lpf_ino); - dent_blk->dentry[2].name_len = cpu_to_le16(len); - dent_blk->dentry[2].file_type = F2FS_FT_DIR; - memcpy(dent_blk->filename[2], LPF, F2FS_SLOT_LEN); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 2).hash_code = cpu_to_le32(hash); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 2).ino = cpu_to_le32(c.lpf_ino); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 2).name_len = cpu_to_le16(len); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 2).file_type = F2FS_FT_DIR; + memcpy(F2FS_DENTRY_BLOCK_FILENAME(dent_blk, 2), LPF, F2FS_SLOT_LEN); - memcpy(dent_blk->filename[3], &LPF[F2FS_SLOT_LEN], + memcpy(F2FS_DENTRY_BLOCK_FILENAME(dent_blk, 3), &LPF[F2FS_SLOT_LEN], len - F2FS_SLOT_LEN); test_and_set_bit_le(2, dent_blk->dentry_bitmap); @@ -1496,17 +1496,17 @@ static block_t f2fs_add_default_dentry_lpf(void) return 0; } - dent_blk->dentry[0].hash_code = 0; - dent_blk->dentry[0].ino = cpu_to_le32(c.lpf_ino); - dent_blk->dentry[0].name_len = cpu_to_le16(1); - dent_blk->dentry[0].file_type = F2FS_FT_DIR; - memcpy(dent_blk->filename[0], ".", 1); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).hash_code = 0; + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).ino = cpu_to_le32(c.lpf_ino); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).name_len = cpu_to_le16(1); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 0).file_type = F2FS_FT_DIR; + memcpy(F2FS_DENTRY_BLOCK_FILENAME(dent_blk, 0), ".", 1); - dent_blk->dentry[1].hash_code = 0; - dent_blk->dentry[1].ino = sb->root_ino; - dent_blk->dentry[1].name_len = cpu_to_le16(2); - dent_blk->dentry[1].file_type = F2FS_FT_DIR; - memcpy(dent_blk->filename[1], "..", 2); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).hash_code = 0; + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).ino = sb->root_ino; + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).name_len = cpu_to_le16(2); + F2FS_DENTRY_BLOCK_DENTRY(dent_blk, 1).file_type = F2FS_FT_DIR; + memcpy(F2FS_DENTRY_BLOCK_FILENAME(dent_blk, 1), "..", 2); test_and_set_bit_le(0, dent_blk->dentry_bitmap); test_and_set_bit_le(1, dent_blk->dentry_bitmap); From patchwork Wed Aug 16 01:13:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 13354517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E13EC001DE for ; Wed, 16 Aug 2023 02:20:21 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qW68y-0003EA-Bk; Wed, 16 Aug 2023 02:20:20 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <39CLcZAYKANc6KHL7G9HH9E7.5HF@flex--drosen.bounces.google.com>) id 1qW68x-0003E3-Uq for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 02:20:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=iTr7HAKWpBensaRIYG4CBZPMVmoz2vxieul5vJXQRDo=; b=RrkuTCfLhDpNVIibizsmo4UsKn ZMaYAeZW8uT1yP0HNTJQ6SgaIBSP5t4m7+84Xcx4r/NH1bkLIeWR3pmUNUJyjwGUadiRdTdaw4F6R yjYdihI/FCwU0f2IOcTmb6WSqibeLnUtkjsHPiCBv6AJCNH72WMddomiYBwqCenhSbLA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=iTr7HAKWpBensaRIYG4CBZPMVmoz2vxieul5vJXQRDo=; b=Z27v+pMD2EiIUGzAYg6ponMFeo AxWZT5wSUcL24AQAE8J/bZbluTcU82XJEkCpILSYRsy4Hz3FjeSrCs8YpF6kVgKgXr7NfeuRFfVwI 3A6aNs6jHrMLDHX2bV7WFHMFKui4YJ8wMLoxEshxAFrlQjrMxjoTAFcKMad0UedxONkI=; Received: from mail-pl1-f202.google.com ([209.85.214.202]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qW68x-006jE5-H3 for linux-f2fs-devel@lists.sourceforge.net; Wed, 16 Aug 2023 02:20:20 +0000 Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1bde651db83so29979595ad.3 for ; Tue, 15 Aug 2023 19:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692152414; x=1692757214; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iTr7HAKWpBensaRIYG4CBZPMVmoz2vxieul5vJXQRDo=; b=Lf0TG8ohTEAa1u/OOxyETmy2fpu5KUYt6rOvC/0/cwtFV7ND91BSWJwVgjiWVjqVOD NSy6PxhOlYp1baYvddDAvXGXaqFUPNF0fgjnXV7859WDULSm+tWab7gQE6br3TTYxTs5 QlEGIxSDchNVEnxs4TyisXGfWTLeHxrqyw6hgDdhV6+xQbEqNo9xARia7fZ2qVx1rO+/ UB9ry0tMBoImsS5RGF/2oZxywEWGRCvFfMjlzWex9E8MrOuCQOgrbqUm2YHRfQBK+GSx gms8vvab2JrvtQsRK7sRZ6jY9FbIZaiD34qwqnUH+ELzNXbF9/Vw4sohor1HKobmGgvg eHtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692152414; x=1692757214; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iTr7HAKWpBensaRIYG4CBZPMVmoz2vxieul5vJXQRDo=; b=ef5M+57zYadWTb2MtmfrnprX7X/ZDhvcOWqreL3qaYkujxtukeOKp9x+o4Kyx2XRJl +w3e1mD9AQztgNHApLbrsFWHFs0q0zZHRPBDVdhawOYPGkWZrmG9Nhv4GXjD6zrAYJlH 8tpQeqQBNULU776GBiLdb2MI5Pdt/923Q3WS1RVZRlvJ22lrKrfWnlvP2bqQVSR5Hhjk d99Ievsn8YBihLmDNXIk5HJepfvRKJuCrIZP8XHGwkLNc/XQbPVq+4IL7oQag6iir471 bCYyZaEUWN+rDoUvF9jQ4vW8YHYJcYyZShZreLYhH8Znr/5n12D1pmPg/tHPTVC0RNzd aDUA== X-Gm-Message-State: AOJu0Yzkd860xpDkAqfde+6ct40ex3YsboIYIP0QFDcD13PyORRSRFBP LsTm9Kj8FID8SioVi4gurEj7QZCn+TTzCWYHW46ETE+9jXNFTxS3daDCNyFX7BXqM25HXTJ818u Xu60AG6QiR1GStql1iaO0ymoOlwHO3jRsmrGQQHUf06956/JaMHmXRb3aCxR32vjCSV6ByY9cDB 6lEc1qyl4= X-Google-Smtp-Source: AGHT+IGs7F+E3YEa9T5M4mscnecF0cnx8Epu1G2l8cc1clq4db2ejO3JIn/oKvYoKyG5Li6Px6lyslxqv3w= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:19fa:33cd:f272:37ec]) (user=drosen job=sendgmr) by 2002:a81:4524:0:b0:57a:793:7fb0 with SMTP id s36-20020a814524000000b0057a07937fb0mr4154ywa.3.1692148468877; Tue, 15 Aug 2023 18:14:28 -0700 (PDT) Date: Tue, 15 Aug 2023 18:13:59 -0700 In-Reply-To: <20230816011359.1964484-1-drosen@google.com> Mime-Version: 1.0 References: <20230816011359.1964484-1-drosen@google.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog Message-ID: <20230816011359.1964484-8-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qW68x-006jE5-H3 Subject: [f2fs-dev] [PATCH 7/7] f2fs-tools: Support different block sizes X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Rosenberg via Linux-f2fs-devel From: Daniel Rosenberg Reply-To: Daniel Rosenberg Cc: Jaegeuk Kim , kernel-team@android.com, Daniel Rosenberg Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This adds support for 4K and 16K block size using the same binary. mkfs can choose block size via the -b option, with other tools getting the blocksize from the superblock. On mount time, we can't rely on block size for the location for the superblock, since that information is in the superblock. If the first superblock is corrupt, we will attempt to find the second superblock at a 4K block offset, and then a 16K block offset if that fails. Signed-off-by: Daniel Rosenberg --- fsck/dir.c | 2 +- fsck/dump.c | 4 ++-- fsck/fsck.h | 3 --- fsck/mount.c | 27 +++++++++++++++++++++------ include/f2fs_fs.h | 10 +++++++--- lib/libf2fs.c | 2 ++ man/sload.f2fs.8 | 2 +- mkfs/f2fs_format_main.c | 12 +++++++++++- mkfs/f2fs_format_utils.c | 2 +- 9 files changed, 46 insertions(+), 18 deletions(-) diff --git a/fsck/dir.c b/fsck/dir.c index 05d291c..21d9da3 100644 --- a/fsck/dir.c +++ b/fsck/dir.c @@ -474,7 +474,7 @@ static void init_inode_block(struct f2fs_sb_info *sbi, if (de->file_type == F2FS_FT_DIR) { mode |= S_IFDIR; - size = 4096; + size = F2FS_BLKSIZE; links++; blocks++; } else if (de->file_type == F2FS_FT_REG_FILE) { diff --git a/fsck/dump.c b/fsck/dump.c index 5a9c440..ecadfdd 100644 --- a/fsck/dump.c +++ b/fsck/dump.c @@ -687,8 +687,8 @@ static void dump_data_offset(u32 blk_addr, int ofs_in_node) bidx += ofs_in_node; setlocale(LC_ALL, ""); - MSG(0, " - Data offset : 0x%x (4KB), %'u (bytes)\n", - bidx, bidx * 4096); + MSG(0, " - Data offset : 0x%x (BLOCK), %'u (bytes)\n", + bidx, bidx * F2FS_BLKSIZE); free(node_blk); } diff --git a/fsck/fsck.h b/fsck/fsck.h index 89d0b22..091b5d8 100644 --- a/fsck/fsck.h +++ b/fsck/fsck.h @@ -127,9 +127,6 @@ struct f2fs_fsck { }; #define BLOCK_SZ F2FS_BLKSIZE -struct block { - unsigned char buf[BLOCK_SZ]; -}; enum NODE_TYPE { TYPE_INODE = 37, diff --git a/fsck/mount.c b/fsck/mount.c index 732bfb3..0ba087e 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -994,11 +994,15 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr) return -1; blocksize = 1 << get_sb(log_blocksize); - if (F2FS_BLKSIZE != blocksize) { - MSG(0, "Invalid blocksize (%u), supports only (%u)\n", - blocksize, F2FS_BLKSIZE); + if (blocksize < F2FS_MIN_BLKSIZE || blocksize > F2FS_MAX_BLKSIZE) { + MSG(0, "Invalid blocksize (%u), must be between 4KB and 16KB\n", + blocksize); return -1; } + c.blksize_bits = get_sb(log_blocksize); + c.blksize = blocksize; + c.sectors_per_blk = F2FS_BLKSIZE / c.sector_size; + check_block_struct_sizes(); /* check log blocks per segment */ if (get_sb(log_blocks_per_seg) != 9) { @@ -1007,7 +1011,7 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr) return -1; } - /* Currently, support 512/1024/2048/4096 bytes sector size */ + /* Currently, support powers of 2 from 512 to BLOCK SIZE bytes sector size */ if (get_sb(log_sectorsize) > F2FS_MAX_LOG_SECTOR_SIZE || get_sb(log_sectorsize) < F2FS_MIN_LOG_SECTOR_SIZE) { MSG(0, "Invalid log sectorsize (%u)\n", get_sb(log_sectorsize)); @@ -3854,9 +3858,20 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi) sbi->active_logs = NR_CURSEG_TYPE; ret = validate_super_block(sbi, SB0_ADDR); if (ret) { + /* Assuming 4K Block Size */ + c.blksize_bits = 12; + c.blksize = 1 << c.blksize_bits; + MSG(0, "Looking for secondary superblock assuming 4K Block Size\n"); ret = validate_super_block(sbi, SB1_ADDR); - if (ret) - return -1; + if (ret) { + /* Trying 16K Block Size */ + c.blksize_bits = 14; + c.blksize = 1 << c.blksize_bits; + MSG(0, "Looking for secondary superblock assuming 16K Block Size\n"); + ret = validate_super_block(sbi, SB1_ADDR); + if (ret) + return -1; + } } sb = F2FS_RAW_SUPER(sbi); diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index adbd381..a5587d3 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -392,7 +392,7 @@ static inline uint64_t bswap_64(uint64_t val) #define MAX_DEVICES 8 #define F2FS_BYTES_TO_BLK(bytes) ((bytes) >> F2FS_BLKSIZE_BITS) -#define F2FS_BLKSIZE_BITS 12 /* 4KB block */ +#define F2FS_BLKSIZE_BITS c.blksize_bits /* for mkfs */ #define F2FS_NUMBER_OF_CHECKPOINT_PACK 2 @@ -400,6 +400,7 @@ static inline uint64_t bswap_64(uint64_t val) #define DEFAULT_SECTORS_PER_BLOCK (1 << (F2FS_BLKSIZE_BITS - SECTOR_SHIFT)) #define DEFAULT_BLOCKS_PER_SEGMENT 512 #define DEFAULT_SEGMENTS_PER_SECTION 1 +#define DEFAULT_BLKSIZE_BITS 12 /* 4096 */ #define VERSION_LEN 256 #define VERSION_TIMESTAMP_LEN 4 @@ -628,9 +629,10 @@ enum { */ #define F2FS_SUPER_OFFSET 1024 /* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ -#define F2FS_MAX_LOG_SECTOR_SIZE F2FS_BLKSIZE_BITS /* 12 bits for 4096 bytes */ -#define F2FS_BLKSIZE (1 << F2FS_BLKSIZE_BITS)/* support only 4KB block */ +#define F2FS_MAX_LOG_SECTOR_SIZE F2FS_BLKSIZE_BITS /* max sector size is block size */ +#define F2FS_MIN_BLKSIZE 4096 #define F2FS_MAX_BLKSIZE 16384 +#define F2FS_BLKSIZE c.blksize /* support configurable block size */ #define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_EXTENSION_LEN 8 /* max size of extension */ #define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE) @@ -1510,6 +1512,8 @@ struct f2fs_configuration { uint32_t lpf_ino; uint32_t root_uid; uint32_t root_gid; + uint32_t blksize; + uint32_t blksize_bits; /* defragmentation parameters */ int defrag_shrink; diff --git a/lib/libf2fs.c b/lib/libf2fs.c index 838ba7e..59e6f40 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -689,6 +689,8 @@ void f2fs_init_configuration(void) memset(&c, 0, sizeof(struct f2fs_configuration)); c.ndevs = 1; + c.blksize = 1 << DEFAULT_BLKSIZE_BITS; + c.blksize_bits = DEFAULT_BLKSIZE_BITS; c.sectors_per_blk = DEFAULT_SECTORS_PER_BLOCK; c.blks_per_seg = DEFAULT_BLOCKS_PER_SEGMENT; c.wanted_total_sectors = -1; diff --git a/man/sload.f2fs.8 b/man/sload.f2fs.8 index ed5ee4b..f213dea 100644 --- a/man/sload.f2fs.8 +++ b/man/sload.f2fs.8 @@ -82,7 +82,7 @@ independently. Specify cluster size in power of two blocks. The minimum value is 2 (4 blocks, default). The maximum value is 8 (256 blocks). -Note that a block contains 4096 bytes. +Note that a block contains 4096 or 16384 bytes. This option must be used with option \fB\-c\fR. .TP .BI \-a " compression-algorithm" diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c index c0f4253..7470322 100644 --- a/mkfs/f2fs_format_main.c +++ b/mkfs/f2fs_format_main.c @@ -52,6 +52,7 @@ static void mkfs_usage() MSG(0, "\nUsage: mkfs.f2fs [options] device [sectors]\n"); MSG(0, "[options]:\n"); MSG(0, " -a heap-based allocation [default:0]\n"); + MSG(0, " -b filesystem block size [default:4096]\n"); MSG(0, " -c device1[,device2,...] up to 7 additional devices, except meta device\n"); MSG(0, " -d debug level [default:0]\n"); MSG(0, " -e [cold file ext list] e.g. \"mp3,gif,mov\"\n"); @@ -177,7 +178,7 @@ static void add_default_options(void) static void f2fs_parse_options(int argc, char *argv[]) { - static const char *option_string = "qa:c:C:d:e:E:g:hil:mo:O:rR:s:S:z:t:T:U:Vfw:Z:"; + static const char *option_string = "qa:b:c:C:d:e:E:g:hil:mo:O:rR:s:S:z:t:T:U:Vfw:Z:"; static const struct option long_opts[] = { { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' }, { .name = NULL, .has_arg = 0, .flag = NULL, .val = 0 } @@ -194,6 +195,15 @@ static void f2fs_parse_options(int argc, char *argv[]) case 'a': c.heap = atoi(optarg); break; + case 'b': + c.blksize = atoi(optarg); + c.blksize_bits = log_base_2(c.blksize); + c.sectors_per_blk = DEFAULT_SECTORS_PER_BLOCK; + if ((1 << c.blksize_bits) != c.blksize) { + MSG(0, "Error: Block size must be power of 2"); + mkfs_usage(); + } + break; case 'c': if (c.ndevs >= MAX_DEVICES) { MSG(0, "Error: Too many devices\n"); diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c index 448fbaa..579a39a 100644 --- a/mkfs/f2fs_format_utils.c +++ b/mkfs/f2fs_format_utils.c @@ -126,7 +126,7 @@ static bool is_wiped_device(int i) int fd = dev->fd; char *buf, *zero_buf; bool wiped = true; - int nblocks = 4096; /* 16MB size */ + int nblocks = (4096 * 4096) / F2FS_BLKSIZE; /* 16MB size */ int j; /* let's trim the other devices except the first device */