From patchwork Fri Aug 25 22:43: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: 13366381 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 13F8CC83F04 for ; Fri, 25 Aug 2023 22:44:22 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qZfXR-00020y-VV; Fri, 25 Aug 2023 22:44:20 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <3ui7pZAYKAOkOcZdPYRZZRWP.NZX@flex--drosen.bounces.google.com>) id 1qZfXP-00020d-1y for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:17 +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=ho3I6bC/6dZHaaLIiUYtafwWZw5KFog8yCN8vQtyLIw=; b=DT8ikGiFFLZTgf33MDJ64NtKZF sjnvb/sdLfxpUksY7omhdgiIcGHVqMCp9yRrlXHkpbGKtAUDbQsCge93a09XMXfhbS1wzedHwmg/x MFSld7D3eZJ/B2oMsxahSclSoVMgWoy2AfG/4OWHVIAQOtEbEeUpFEJxHzH2D7sMrBwg=; 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=ho3I6bC/6dZHaaLIiUYtafwWZw5KFog8yCN8vQtyLIw=; b=F0hMsIj34/jSLrsSmnnzXZCoY1 K8Uv4ON1dDNLrP6xmZSYKulrwi7VY/3gbCGwMK7RenaOPR+e1kgJQdHXzg8MGo/AEwTfBxGN9xwG6 nULctHMeA6F96SbmdTYVE0d53cmBEf0X/JlAqmgICL//lXUekhIaaOGn8ofqGFnO7RL0=; Received: from mail-yb1-f202.google.com ([209.85.219.202]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qZfXM-00FcAM-Bp for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:17 +0000 Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-d74a0f88457so1724948276.2 for ; Fri, 25 Aug 2023 15:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693003450; x=1693608250; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ho3I6bC/6dZHaaLIiUYtafwWZw5KFog8yCN8vQtyLIw=; b=KtGoW6tioHuE3VJrToVL3gwYAzrtNM/yPHT3PFIkWqMQpgOMUp9X1ioBcCksrWURoR R7g/af1tsHysegCYK9s6Fl943dIcRzFp84ymNf0OuvQ5D4mB5Zpsd4rdmWbV4WxNISnX eL4Rt8TyWHgQMQaBk3QNie+GrrvgH+yZ7HSfcYBOdsDaG4hbfimn+CQG/QSvGDYw+0SC f8FkouiVpSZObL8F22DnmIL+cmt453hJ/sLb4Ts/AWMdziBUnbhPVSqXsySsldgaQcQt HmCIVz2MEUZ2/ycfv5hSWonGXbcux9gzMmo7OWM8VJTFmsBVYZJB1VjF9/kquUXGknyI Pwyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693003450; x=1693608250; 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=ho3I6bC/6dZHaaLIiUYtafwWZw5KFog8yCN8vQtyLIw=; b=CcHnxTydVkkotX6EU9Ya5kFoHbLxbBt8qX/E5GHSAO//xUZAiUlX99e65ke35LsRMh wbn8cV4tcNbyOz9AQXKZFy99mw81KumCwLS4pzshV7jOggY5fGKlpaESNtRK5aM5PAnv jrF39DcuuKUOFmrvQSfw/bzXIhCaPe7Bvy+7eYfTIuM+X14X9z87uabjfQ+OvREo6xiN RW2yDtDunIgD4cXW7PFK5Kj4hCYvCtIgtUGVA/qZyLvBaCfiv+e436U2I0FxM8vIKBzD UBt6Q9HBzMbqBuGE1CzC8kQLrOS13T1o+5jPYcyC9ff575wq+GmoZjOP6oF8Eb6VVPqO rxgw== X-Gm-Message-State: AOJu0YwbSFLKMwDHQttF3CwIXGYDaSPTyvPr/qiPIMKIkXBJW97Je+a1 7Ulwa3WVPPz+I2f7jSXKWGaK+T3kBl1VO8lnVYAkFYs5oeman8nbnFWUsWayYREjH+KOd8yx64n 1wUwcRQeZKh8K1TU46iaPunHPrThdzJxAfXRBeELRS5EUR3yE8B6RO9MaWn6mk7LZC+cWJ5mtJV MDkGTX5C8= X-Google-Smtp-Source: AGHT+IEjKzkzS2g8erJd13mpRjsMIXJIAcUoszPOKghGEGrpnPngmachtqm+kFM57AGWSugNH5f8woBaqXU= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:ad1d:adc4:c021:b463]) (user=drosen job=sendgmr) by 2002:a5b:991:0:b0:d07:9d79:881c with SMTP id c17-20020a5b0991000000b00d079d79881cmr541440ybq.11.1693003450649; Fri, 25 Aug 2023 15:44:10 -0700 (PDT) Date: Fri, 25 Aug 2023 15:43:54 -0700 In-Reply-To: <20230825224400.2206278-1-drosen@google.com> Mime-Version: 1.0 References: <20230825224400.2206278-1-drosen@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230825224400.2206278-2-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qZfXM-00FcAM-Bp Subject: [f2fs-dev] [PATCH v2 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/dir.c | 2 +- fsck/dump.c | 4 +- fsck/fsck.h | 2 +- fsck/mount.c | 6 +-- include/f2fs_fs.h | 81 ++++++++++++++++++++++------------------ man/sload.f2fs.8 | 2 +- mkfs/f2fs_format.c | 12 +++--- mkfs/f2fs_format_main.c | 2 +- mkfs/f2fs_format_utils.c | 2 +- 9 files changed, 61 insertions(+), 52 deletions(-) diff --git a/fsck/dir.c b/fsck/dir.c index a20aa8b..33f83ee 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 e7a1c5c..a3fb9bc 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 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..f09e468 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; } @@ -1007,7 +1007,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)); 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/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.c b/mkfs/f2fs_format.c index d937eda..3453e17 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -1370,7 +1370,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); @@ -1383,13 +1383,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) @@ -1424,7 +1424,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 08c1b25..b2b84dd 100644 --- a/mkfs/f2fs_format_main.c +++ b/mkfs/f2fs_format_main.c @@ -139,7 +139,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 = F2FS_BLKSIZE; c.root_uid = c.root_gid = 0; /* RO doesn't need any other features */ diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c index 437f113..1c2003e 100644 --- a/mkfs/f2fs_format_utils.c +++ b/mkfs/f2fs_format_utils.c @@ -116,7 +116,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 */ From patchwork Fri Aug 25 22:43: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: 13366382 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 45FF3C83F05 for ; Fri, 25 Aug 2023 22:44:22 +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 1qZfXR-0001JL-Cp; Fri, 25 Aug 2023 22:44:21 +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 <3vC7pZAYKAOsQebfRaTbbTYR.PbZ@flex--drosen.bounces.google.com>) id 1qZfXP-0001JE-8I for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44: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=ShRdC5A3bR6rHaA/6FNIrg6nwVFYVodqV+8HYnCddrk=; b=Wg1+e2FrA9dk6XZr1Xlqej+nQJ 40EB0Q4XkDIz5eSEJUYsVBo8aqxLS4lQSOtDCf33vpf+/miqNZgq8ajc+4XTBI39Pbkc+RbWKdSh7 uyiabPW0PlAO2NesqQklJhFnmkGxpeX9g2Er6lsx4QnMMBAYP4GRrE4t70G1wUFf2p9M=; 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=ShRdC5A3bR6rHaA/6FNIrg6nwVFYVodqV+8HYnCddrk=; b=eqUg6Qv2UWuhHnZ7t3gUAoA0rB rdYKR+LLY24lgCu992nTnN24TyyEIRFLFBN+TXcxRJR55OFvqA/kcAQc+NZbmZC6wLKM34o33+zbp RnSR5+040qYbEYCUGmBgfOcBoPst5uiMfkH/RMdEqw5pqY8BRScnUwI3f3V4fgHOTstw=; 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 1qZfXO-00FcAZ-Gb for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:19 +0000 Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-58daaa2ba65so21394227b3.1 for ; Fri, 25 Aug 2023 15:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693003453; x=1693608253; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ShRdC5A3bR6rHaA/6FNIrg6nwVFYVodqV+8HYnCddrk=; b=Pyog3vC5V1PzggN1LxO/3FcIqbaNtRet4b5lZ9a9REHC+h8AGuwulZMUcwmRYqXGFR 7M7PZ4Ewk1dKsbL/Hq+dgusMkmnNvVU6xyWefnwVgrBSt8hK2yKbgPPY0pGA4HDdzF9v cp9X9LIzW2pGI6ybyIbZBEXXWuFkscCZ+RMLqWwGComD2rGzMeZ9Lc8xo7yYRlwFJllF 9VIF7y/bz5pJJIauDdnLOydl4o2udnwojd61uapcsYuAU4/MI26dTcBiKkAbqy59IZMY 5Sf2XG4k8G+r9AO/r3phZAl8a3A9EqSEd1ScTJyIjpImpbyf89vYRzZGm0gRnCmmuAdv 9fyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693003453; x=1693608253; 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=ShRdC5A3bR6rHaA/6FNIrg6nwVFYVodqV+8HYnCddrk=; b=dDHTgipqWPWbZYL1FpREizHNZ+NtlZ+iNQgEeH/8nJhGyEEBnGDSdYoEeCmOI81CO9 z26qrdJAVKMtacJQ6/ZRRrTgl1BnZ//ACI8MXFfyRfg2wdw/GbtwEjtYGIyo725yiDN6 jQXes8XEwC4ze1WYVBQ5IJ/w5b+rThuxnhOmZgKipuSDNYb/T0eqNniYtJw6Jla9aaX+ WPYlYRQI1iHomINcSJz83oQNbv9IuQAWCDW2DTzVn7pDr8BDRnLg66dsKIkqNuyW0uaL nQ7P2CX1yNIEUWRY9axhVyzew53RmBkoaOPMe3zlK9WHq9QK9GusXkBABXnChvrsyXYS /m3Q== X-Gm-Message-State: AOJu0Yw/sDXNOLvSAyQCMdhGWYdW4GEQ9RMoHvGafkEZdHUA3Yq8vo2n fx28D90N0KqS+WAUKP6EA3kl8hC1DQwFzx4/ZNWbFsPr8nIJGl1Neq5e0ihyN1uczX82HwnKNC+ nX+MYCArWS84CO7q9LDzhPVP498Y3epbyAX/hl4EkicTUGHEcJtCrzDbuX0TM6CZbc+mOVJCGkB WrluSsn1s= X-Google-Smtp-Source: AGHT+IFooFidhbnje531JHymQoG9BjF/o2BTWliLr+g5ir9pEEiDlSBIfnMiHgbMvFLKKB/YykfhY981Db4= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:ad1d:adc4:c021:b463]) (user=drosen job=sendgmr) by 2002:a25:d2c4:0:b0:d47:5cc3:9917 with SMTP id j187-20020a25d2c4000000b00d475cc39917mr554577ybg.9.1693003452798; Fri, 25 Aug 2023 15:44:12 -0700 (PDT) Date: Fri, 25 Aug 2023 15:43:55 -0700 In-Reply-To: <20230825224400.2206278-1-drosen@google.com> Mime-Version: 1.0 References: <20230825224400.2206278-1-drosen@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230825224400.2206278-3-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qZfXO-00FcAZ-Gb Subject: [f2fs-dev] [PATCH v2 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 Fri Aug 25 22:43: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: 13366384 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 91F71C83F04 for ; Fri, 25 Aug 2023 22:44: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 1qZfXW-0003Nx-2j; Fri, 25 Aug 2023 22:44:27 +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 <3vy7pZAYKAO4TheiUdWeeWbU.Sec@flex--drosen.bounces.google.com>) id 1qZfXU-0003Nl-D7 for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:25 +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=Tvl63k+SkBEdbOEox0yQsjRHTUUbE0p3x/a0euL2/L8=; b=hFZs8c1OX6WBx9t2zt0w/EmfuR zAPD1esbUCnrL3lMib/Ze3kbrqkigyGH3a3Q5P1m2PjMxSTdUDvzVy6mv/aSOKbl2PLhbPHoPss6M KYE7XGTymi09eZM1rP2a0UuKd7wbexypFdcQRi6LwwiuTidrV8cwfKjfpIopw+RSNrdQ=; 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=Tvl63k+SkBEdbOEox0yQsjRHTUUbE0p3x/a0euL2/L8=; b=DAZYxImBYrf9yEkbKDC60j6pBR AV8ben2Dx2UAdtoYAek0m6oovK9H0Ac5TSHfseFoc49iOLXxh3yvCm5hztYni5aQ7JwsxYHoV+2T6 r94pR74nCLRLSwhQyMWFWcrJvfmBEDN3QbW+hUdKfJbcg2tYKAdXBg8Pv2PDUuse4LZU=; Received: from mail-yw1-f201.google.com ([209.85.128.201]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qZfXQ-0007NL-Rt for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:25 +0000 Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-58c8cbf0a0dso50117447b3.1 for ; Fri, 25 Aug 2023 15:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693003455; x=1693608255; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Tvl63k+SkBEdbOEox0yQsjRHTUUbE0p3x/a0euL2/L8=; b=s4Ac/As/Qhhivqdy6bJ2EP67BJ93j83pLO9S7IToYi/bwTSOelFw0XArOGGd0RlX6i iXnbA30t4CTqHWfaL81CEnWj/Kfz/NZOi+5ca5+KeayqXpEzu/gbKluZhoTHukrgBCF5 t9CGEHQu+2FUYzxcYikwTRv88mJ9HGc7dq1b4FhscdKhBYu+KbD6EN2bATnR0zSb5uv1 qI1nViOTFH67Q1oEw65UZSNxbw0b+yHiUEprROPaizLjmzH+JqpH+C6dasb4PovaqetK MxFCTlgl8p9GHd0i7DjVQYJtPWmUOJCmkhETq3YSJo+cs98mknGXJS4z7+HUuGJUQDiq od0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693003455; x=1693608255; 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=Tvl63k+SkBEdbOEox0yQsjRHTUUbE0p3x/a0euL2/L8=; b=JPSXNJ58CBlQ4NLMrbVTrORFqBF3TgTRG4qLtc9bGu2CEcvLLFzOJvFl4hR7EoRvuk 32BoKm3F47LuAf+i9EkB8UGq68bWyXqXCUPiUWhoEudSY/nutvrRTI41pGKl2rbbBsvy bDyEEV8hJ19fnhA9Qmz52IA76AMqjyTv2rdxPOhkmcORoDCUcsWyt4jwB8RXIUBH5oGB rdpNoXk8uvOwXrgl1shx38V0/b/DI07AK+Kcydfrp1pvy1K3Fm+VFe7FLGduLmL1tf4w Gn3+lW0KXtgg16ixLo6cJEjgD4MWY6qJZOnCrByZnTf/Qb5X6VeOSaLJZ7mXMtlKAIvP d7cQ== X-Gm-Message-State: AOJu0Yy5r7jbpWfBsocigkyRjKnupB5EvpHsrCGQKFvtgUsw1a4srPVp gElVFj/hzpRZA4f7CQoHoQJnoAhh8CqBbB7Zl7Ovu+4WUX1TLiLyKOc8v/CauDpji09b2bEdHOG BEnL/LmcwOEg5u5DeDhat2D+h75SUSND6Z1jZ8FtkdgerFbd23a7eJ1+Av8vMHIHTJ/uc9gs3mx chiYwAAO0= X-Google-Smtp-Source: AGHT+IHwkWYj0kVNPPgoNEOlFu0OqFLQZUAMTpc7/hx+SFmnHXYbhh8sVqcfKN38gNKc9WwBbbh//EX9oQI= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:ad1d:adc4:c021:b463]) (user=drosen job=sendgmr) by 2002:a05:690c:2f87:b0:586:e91a:46c2 with SMTP id ew7-20020a05690c2f8700b00586e91a46c2mr567272ywb.4.1693003455139; Fri, 25 Aug 2023 15:44:15 -0700 (PDT) Date: Fri, 25 Aug 2023 15:43:56 -0700 In-Reply-To: <20230825224400.2206278-1-drosen@google.com> Mime-Version: 1.0 References: <20230825224400.2206278-1-drosen@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230825224400.2206278-4-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qZfXQ-0007NL-Rt Subject: [f2fs-dev] [PATCH v2 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 33f83ee..64beaad 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 a3fb9bc..ecadfdd 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 f09e468..162d742 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 c3d5744..8f2cc3b 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -571,7 +571,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 3453e17..50890c8 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -1104,7 +1104,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; @@ -1128,7 +1128,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); @@ -1295,7 +1295,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) { @@ -1413,7 +1413,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; @@ -1548,7 +1548,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 Fri Aug 25 22:43: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: 13366383 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 EA4B7C83F01 for ; Fri, 25 Aug 2023 22:44:25 +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 1qZfXU-0002Kr-Pu; Fri, 25 Aug 2023 22:44:25 +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 <3wS7pZAYKAPAVjgkWfYggYdW.Uge@flex--drosen.bounces.google.com>) id 1qZfXT-0002Kl-74 for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44: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=BcNR9QJ6HdeHoDPjKmDv4X+fDGIBkuMGGFic4LhLUyk=; b=mf0MlAPNZ6TFwlXitJaYUmmxT0 bV/YdfaWSH26YI0IDiG0YHhXKHj8dncVtGRlcSbzQtijOP4HLLb+kchq/+xGT1hPYydyHGGS5LKeB KZvgFfSFL24EU4omvV7H1ZTYOzzHk7CBUEHrdaajDKQ9AKXc2piINj4xlP3HiqlvmVXA=; 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=BcNR9QJ6HdeHoDPjKmDv4X+fDGIBkuMGGFic4LhLUyk=; b=AWdDiWddws++5pZS4EFzIZ2/5C UYPZyM4FVh1JQ7vnugjA3G/l7qyjsAiCy/mKq/4aa6UqAjNuc+UY2hwdNDh9tGX4ob2bi9CKgBID2 Qz4dwUvqy6VlLSlJzl6OXPvuY23SmRZNa7mXyXh6Fz+nly4clh9JkJCm3D81to/XFovA=; 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 1qZfXT-00FcAx-1c for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:23 +0000 Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-58f9db8bc1dso21098027b3.3 for ; Fri, 25 Aug 2023 15:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693003457; x=1693608257; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BcNR9QJ6HdeHoDPjKmDv4X+fDGIBkuMGGFic4LhLUyk=; b=XVtLKkvta/lOqZRbqT/LmfssQwIladMaijZpNT43dpPCr9zI5kg8aynQuRdLmlyWwz wdoBOFXsdNnJtv4hnk8R+meIQ8Mh33V8i3Swx2rxzoOffH4wgBnx8k8I6ih2KNbtHfi3 514PBtEZoWyakNwf6F1jLwyX+dP/Mjr1lr4vZ2vIOdQxg9RFhmdC6WoNlkmLaiHpl65c 9q6Ldk8KdI8Z+e/bs1fpLfN4/aJYZG+XajrcofntM+S8BrJ5nP3fM36QGsuEexCBN9zv e/4RVkMGYz6/4WRb/WXCaho1JWO8Eshg3/8cN1nFsLGgsoW5AyErHvmGJapXJHrsZzzS eNLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693003457; x=1693608257; 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=BcNR9QJ6HdeHoDPjKmDv4X+fDGIBkuMGGFic4LhLUyk=; b=Yr+DZfwb0+hPc2ahamEqqG8NMhbTmEJ6rzAXC/c8bhNoqdKGw3BTdRkg+BPRNgGHFr uUxPHKqNS50iPrq2OkZEOJDXPnFxvhOp+cbewx5Nq02/JftLGn0L9Ze2ANRXzVsfd8HP PqiAcjDgunGH93Gi6Tb8gjmwu+N1212UrmgdgDQoYBI4MGvMcZoeX4kV/++AF9aB8/JM JvlvBDsBuknWJPF0SXp0WoOKgJ0T7ulwrCQdtK4s50kNuA/5cIdaalF1GqjuijQNIguD YlVfOO7sQ5yr5mclq5Khtrmf+XJJ4Glnu+dA0jnKDVh27ak3RXh5tt573qhEl91tJnk0 r8Kg== X-Gm-Message-State: AOJu0YwD2+JpbVU1YETtsg55yu6WcoIGga4cpsu3a1lXy88iO2aUZV/F lOjcAKwpfhFoITvu0XGMYg0NavKEMs0FlSltko7Hh+WWmqb76RAzr5gwop+VKads41SJIIv+Xxp tMphjp8gL3+qqFVdJ7gLofPuNa+2o97x9/lkxMM0KIl6ntSREHROFc6g7hPM/WlB9msfxp7UGoJ xF41Obfx0= X-Google-Smtp-Source: AGHT+IFEiaqFa5Nmp+CuSwe8DLHr4uTzPy5L1/96mNb532st4ab1NpOwY1B2EaiJXxriUAYgcd8Vi8FnBe8= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:ad1d:adc4:c021:b463]) (user=drosen job=sendgmr) by 2002:a25:a2cc:0:b0:d13:856b:c10a with SMTP id c12-20020a25a2cc000000b00d13856bc10amr524189ybn.3.1693003457380; Fri, 25 Aug 2023 15:44:17 -0700 (PDT) Date: Fri, 25 Aug 2023 15:43:57 -0700 In-Reply-To: <20230825224400.2206278-1-drosen@google.com> Mime-Version: 1.0 References: <20230825224400.2206278-1-drosen@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230825224400.2206278-5-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qZfXT-00FcAx-1c Subject: [f2fs-dev] [PATCH v2 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 Fri Aug 25 22:43: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: 13366386 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 4029AC83F05 for ; Fri, 25 Aug 2023 22:44:32 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qZfXc-00022Y-Lf; Fri, 25 Aug 2023 22:44:31 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <3wy7pZAYKAPIXlimYhaiiafY.Wig@flex--drosen.bounces.google.com>) id 1qZfXb-00022J-6l for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:30 +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=p4Iwa3cd6vPKM8a5f0JoGCX6bpTcSPVSv62HG019OqU=; b=hmB5UHRO0Q8VAJtvwDnQXHgpV/ 9EqZTrNI97MOmHZx1nS0dm6sS9PNb/wk/ZoqqdCmpR0I8gfUa33n1Z0lkLT1sW1AS6S0fCMZDetS+ /AVR13pmoogTzGJMbXeLXJ15BCPHLkvBW6+4bkDrMtzTizcBsL2r3lZKYzBlf8dWab24=; 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=p4Iwa3cd6vPKM8a5f0JoGCX6bpTcSPVSv62HG019OqU=; b=i+GvtW546is+rXmA4YvbfZllGu VT30udKkJVH0ZgOqRgknQ2VSf2PDNdouJHxcJFYU4HIaW65HeMc9nK66YaS3zsXwDMmMrHl/55OSm AYGbWerGHmQO+QnZx1jHJI3zF42rBAWc2nJ/cA303/P2XgfDDAOvpnRFatl45ngfW95w=; 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 1qZfXV-00FcB8-KU for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:30 +0000 Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-594e1154756so7987387b3.2 for ; Fri, 25 Aug 2023 15:44:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693003460; x=1693608260; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=p4Iwa3cd6vPKM8a5f0JoGCX6bpTcSPVSv62HG019OqU=; b=drrHz5/DPIqRr0nlW7g3daxW6vIbh3RVzK03yXd04tHr8CBWD9gpvKG0gVU5A6R6zK 6sywqueU065if3aXl9KQnGaZOfLudb5HukkyLmkFzKDTQckv8y+RrMrFJkNYrxanLSrd eWicZ/hGQhJAgMP+sqwugB0rotAvebLsL78jx2G49rKJLqZlLMq0K4Nm1GVjgs725IP0 /BPqVQOUw65ZG6iSN45iOgp7dnUXMnT1PahAEyiJLm+dlEU5RMrxotWTGsOflVFIaOyU cw80c0lzG0WaHmRt4rF13udMLqTH13Z5sw5JsvE9NFLQhgusFrTOgrC1IjfqFronMY66 WcZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693003460; x=1693608260; 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=p4Iwa3cd6vPKM8a5f0JoGCX6bpTcSPVSv62HG019OqU=; b=ML8WRuWCCsuQ6sAvIQ/XUDcEG4Hrf8GO17uXKhF0JkK18e9ZYvti/YV4iGJysFM0D9 uP1iG1rKnrWAbPnK00yfEgwk6/Fi/PfDq5AaEn9ToCiovkX6TaBTCoXywN6r544V+xdd iyDRa7znaMsqPtnAep8xFYJWhh73hfgW5CI7JUbTyOGJrmVCW8xdCQ6oQBKLJ31aHkgu 9IGGYcXCOiqMEEZTou0FBTDbbilTyvP0hUBytFDHn/paqdBdaueg+yyn4iW4w7G8aSvw zriOyNmizJbfaGDPqjGAXrevQCXGhDjFL8z20ciHUELSabzEsFoamLUNf+eFAZsWCvTe UXBw== X-Gm-Message-State: AOJu0Yz78Ug3M6TkWB8NEVoT5DpCz24re/U4BS/aKRF6U9vIr7ZViWHU cIsDe33VT/+cLxMMYi0sKGy5SyY3AU4opKftqe+qrOgg7EoLzDE3UCPNwDaArRm5UhIZ+5HxR+P +u5jAvPYquOCtbwQhnT9R6Bd8qfoMwv53ajpxCp0RljQa6c/6TCJizXftwToN+TrmaSrNJqQpuk FEZ8LMhjM= X-Google-Smtp-Source: AGHT+IHy0YFt9gqfNzdNsc5DUi1FkMLvz33BRNe4zNlP238QfEHOE2sRt29sdATv/hoRkIs73CT2NASc7Rs= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:ad1d:adc4:c021:b463]) (user=drosen job=sendgmr) by 2002:a81:b71a:0:b0:56c:f8b7:d4fa with SMTP id v26-20020a81b71a000000b0056cf8b7d4famr514662ywh.7.1693003459928; Fri, 25 Aug 2023 15:44:19 -0700 (PDT) Date: Fri, 25 Aug 2023 15:43:58 -0700 In-Reply-To: <20230825224400.2206278-1-drosen@google.com> Mime-Version: 1.0 References: <20230825224400.2206278-1-drosen@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230825224400.2206278-6-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qZfXV-00FcB8-KU Subject: [f2fs-dev] [PATCH v2 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 162d742..6220d91 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 50890c8..740e752 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -927,8 +927,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], @@ -946,8 +946,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); @@ -960,8 +960,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", @@ -972,8 +972,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 Fri Aug 25 22:43: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: 13366387 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 42C45C83F04 for ; Fri, 25 Aug 2023 22:44:34 +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 1qZfXd-0002LV-4k; Fri, 25 Aug 2023 22:44:33 +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 <3xS7pZAYKAPQZnkoajckkcha.Yki@flex--drosen.bounces.google.com>) id 1qZfXb-0002LJ-K6 for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:32 +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=UDdV6uDdBALNxpq/V338GEwwvrnFON/4W2F10W8a3hQ=; b=dByjJv/EJWKx30gNsaGiIespyD 9oyCGCCxPa2U7pKsBuFZBoMbOtCvpSoDPY6FOjKOeqy1HRQJBfqPlHo5VW4YiTk6r/7gPkrOstHtg rza2qY5HGOVRL32EbaQVKzJOWRPZo2h+nUvff+DyMeDRiIb+5JdyaJJnJUZaa9G2iXDU=; 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=UDdV6uDdBALNxpq/V338GEwwvrnFON/4W2F10W8a3hQ=; b=b50yqJThGNchq6O/ZD4SDQw6k1 /B/y0ifMGv+C5uCQMdzRDWbW5yBE5RiShGornpdMtN5VRi9fJPhxVp+mww+BZlZDrOC86TYKQ1uET li1lgrH3rbAOg/gkTjn8CkRH29wrbNq2+CEN2RBNouWWx5ZLvFjryRRfMMcrJut/27+s=; 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 1qZfXX-0007Ne-JV for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:31 +0000 Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-d795e8483f8so1259835276.1 for ; Fri, 25 Aug 2023 15:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693003462; x=1693608262; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UDdV6uDdBALNxpq/V338GEwwvrnFON/4W2F10W8a3hQ=; b=qGBmxfTojS/mXSjDn+M/7o2GVovQs+SW0YG88qtrNt0aHiEDP4FjUgPPCvRKkTM9jz aG2YupGu0XdgPnY80f4oljo2SCzof8Yt19W4NJsRZtZ9J5oWalHHWWdFnDxcTsQGO8Y6 l6JwOGHy2TcG0bBq8tDC1yxgcT/vwq09pUJGsxR1Uq5+Y3xx/bDEZ4O8czar2Lb5LgU+ Vq8GH+wn67GM3isD9D5+AaRbzyvxgYIuEbU7IMyi3IhuF2zULeARwWn7vYe9KpK4EbWq YngE+Uaw0YnyhZdiBjYjxtxMXt2gBcnxxjIKEjXWykuNRv9TZf2oQZPrfF0oYK5Mkgew pgDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693003462; x=1693608262; 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=UDdV6uDdBALNxpq/V338GEwwvrnFON/4W2F10W8a3hQ=; b=YGPGxh64xRLU1EkzOi0Yf2i2rNImBLPyg5c00ac/9MMDj1eVsOvhW/tIbGOIk9tDrb qDkUQImYR2C0Fom4oQi1nv1jRj+mjSga0aTqSMBYIJ+sd9qyZizVEq7xKImnLl33SUEZ A7ywg0BeslUZiJM0DKhQGRpIRLLA2697VZ8cK5Q71hBwY0U/ULDjVR9VeSWq0/xkOJ0z 1tgdudO4D3jV3Kc2+VP7oVLfjAqm/9vsz+VnY/cLDX5AEiaxKe8FmKH/0bQvN+oNGQat MD9EaIePvGbU+P7+a+h9fTW1FM0u2si74AW+A41uW5dDGvrmbY8UGK5uuEW1GoZAO1cc TENA== X-Gm-Message-State: AOJu0YyFFVBX/lrUVAH1PZq2g4PWKb5/BfpFJ4olg5utJUJk9aRlc+1w 0Ky3csI/e7v6lv+U8WTF0JeY43ma+XouWdfYoTiSlrO5kgtvlcJbMpXDlImK9Ixy8H0gXuc5Eao Y7nXpXvkwKBOMek/YHshhop1zKk5nQfO6tUdAZroremFbnZj8k07U/kEzg3NvrDlVGo2qY8OT69 TdpYCPOPQ= X-Google-Smtp-Source: AGHT+IGYxMCfTEOBOPqeHdJqBocKlh8+eoZpQyjzHu5uRw8ggc/cMVD7AKX8tpaexsU7d0ceTU67cyvkxgw= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:ad1d:adc4:c021:b463]) (user=drosen job=sendgmr) by 2002:a25:ae9c:0:b0:d77:fb00:b246 with SMTP id b28-20020a25ae9c000000b00d77fb00b246mr399401ybj.1.1693003461882; Fri, 25 Aug 2023 15:44:21 -0700 (PDT) Date: Fri, 25 Aug 2023 15:43:59 -0700 In-Reply-To: <20230825224400.2206278-1-drosen@google.com> Mime-Version: 1.0 References: <20230825224400.2206278-1-drosen@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230825224400.2206278-7-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qZfXX-0007Ne-JV Subject: [f2fs-dev] [PATCH v2 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 64beaad..21d9da3 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 740e752..f2840c8 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -1217,17 +1217,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); @@ -1237,13 +1237,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); @@ -1494,17 +1494,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 Fri Aug 25 22:44:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 13366385 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 48D46C83F06 for ; Fri, 25 Aug 2023 22:44:32 +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 1qZfXb-0001KC-SJ; Fri, 25 Aug 2023 22:44:31 +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 <3yC7pZAYKAPccqnrdmfnnfkd.bnl@flex--drosen.bounces.google.com>) id 1qZfXa-0001K2-Jk for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:30 +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=Ma47L4jaVLdbFhNW27vq8zn9BPtySpWvE3JcMEM4mZs=; b=bBQ3IQpunZcsjYlccvM9ci/9Y5 6ZWpGHwDmOkfdkqn0BSrNYxrVDLtbiiOTyBBDljzrOdI71rng3VzurlzP5M2JLmi9t+6n4ozro/dG Krt8/l2FTg4FoQCKPp98zvhi7xGiq3TaVLBonDSqtnguEtLeDoo3Kra3btl64DQIv/YE=; 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=Ma47L4jaVLdbFhNW27vq8zn9BPtySpWvE3JcMEM4mZs=; b=FA/Ev+ZlEaN5jf0vBTyVxSSb8o tPAuLUFjX3bPWMQm6wzOyHzJibmYerj0Drt/sFvBpCj+JjgDil/HgBa8ldM8sZ1Xq4jCA8pqfyPxz +idMeTLlf+qTOdc5fKj8nX4unOGNwSr90Icd0cS473dJ8gp6bukYKhp6O3S0Ju6+ubUE=; Received: from mail-yb1-f202.google.com ([209.85.219.202]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qZfXZ-00FcBR-SB for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 22:44:30 +0000 Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-d72f3290e6eso1720708276.3 for ; Fri, 25 Aug 2023 15:44:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693003464; x=1693608264; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ma47L4jaVLdbFhNW27vq8zn9BPtySpWvE3JcMEM4mZs=; b=jPpwxfs7PQezFELNbB4y+lwlaM8PmstIQY471RKU06/7zq2tYRs0GBXzyTjQc0pylL tlQP2IU61fuZheWu3W1aPrItJ+WCF3V7kwqhNkEKQ/trW/45qSHHrtj76F7ueXLjCnwO 17krg13Q69TSF7HNoteHyDItpcFgbEnVvjpkwKXrG+XwPJNOSO49MCFeaKf8b3mqCRtk Hd4y8whe6jlD+nkk0H6dnKrD+ZPsA/SzzHiwf0ht2i/vRUBMTGDSNpBj13zckCNZXPBH D1WhAiOaD1p5C3urK6hsTrXqxhSuADzNpUcZuSp5h5N49PgivHf3EOe2TzuC/p7dORmk NxqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693003464; x=1693608264; 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=Ma47L4jaVLdbFhNW27vq8zn9BPtySpWvE3JcMEM4mZs=; b=cLvCCZnUYcbM5ISx+0/4Sfe9YAqju31jVPwbcshkpnlP9fN65qd2RUMLlsMnJOXc2j /SoWBSE84YRrhT5LgHdSCxoJwP5k8x1o0MUuRkmiFJeFSQZN4QeCudyeGzyP50YWTiS4 qB0kwj2Pi7Mq74leQqJLNVKRsy+saWbOwTDpfoh8nOm3+N4J1zIaPZQhgfnzEcryZ1Xs eMThHGGp8PlzR5/xHfQ5dgX7U+8J8UkytUonZSiS6ETladjlExHKYiadE5GFXwhRhkZ9 YrPVBGvKD3u29QDHIuIHlSrkioogiSt0rbT3Yk0UEQ3DZiWkGtJ3wxA4tvpBDUhLY6Ci M44g== X-Gm-Message-State: AOJu0Yy2e9TMv2xDfhKHjBt2TSQh/8H5mlp0zuT1cNFUoP/LlBB5o1E8 WMvzZSWyAUCVvca+RRarckZzxwtOMwA3N93dRcYvozg6tv4f0NfEx59ok6JJptmnizfqIUZcgft Gs37mY2Mx1dfzJmTCYyQoSIkduLg6Fi2UclIzVWn3oLuDNgGT9hdannFDiMJ2S8zlgJaiAtlEdl 3TLXtjAXQ= X-Google-Smtp-Source: AGHT+IHgAERMO7nLPIedGaRmT1QmfxqCM0Wbl9YnxZBVkfd/IwaZaJQvww2kZehXiXCDXRfgEQOGYq62czk= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:ad1d:adc4:c021:b463]) (user=drosen job=sendgmr) by 2002:a05:6902:a8d:b0:d77:d70c:b5cd with SMTP id cd13-20020a0569020a8d00b00d77d70cb5cdmr356669ybb.12.1693003464207; Fri, 25 Aug 2023 15:44:24 -0700 (PDT) Date: Fri, 25 Aug 2023 15:44:00 -0700 In-Reply-To: <20230825224400.2206278-1-drosen@google.com> Mime-Version: 1.0 References: <20230825224400.2206278-1-drosen@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230825224400.2206278-8-drosen@google.com> To: linux-f2fs-devel@lists.sourceforge.net X-Headers-End: 1qZfXZ-00FcBR-SB Subject: [f2fs-dev] [PATCH v2 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/fsck.h | 3 --- fsck/mount.c | 25 ++++++++++++++++++++----- include/f2fs_fs.h | 10 +++++++--- lib/libf2fs.c | 2 ++ mkfs/f2fs_format_main.c | 12 +++++++++++- 5 files changed, 40 insertions(+), 12 deletions(-) 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 6220d91..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) { @@ -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 8f2cc3b..995e42d 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -686,6 +686,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/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c index b2b84dd..349ee75 100644 --- a/mkfs/f2fs_format_main.c +++ b/mkfs/f2fs_format_main.c @@ -50,6 +50,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"); @@ -175,7 +176,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 } @@ -192,6 +193,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");