From patchwork Mon Dec 22 11:56:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1055 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766404677; bh=HAX/x3Y0uhlfW1eb02VCPuZEHm7us4zfRQbijwyktw0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=BD4x6svQ0kbAnM+sAS7oqyRLauDj5vnr+lXvLTWHmMo37hBOG46YI4b1v9CZrrI9N vHIC8CB6naOxjLjQq4aOYsW1R8AWwOk/iplgZfRwy9d6TWBKhL0g8I0aE5ZwHwlQYw HLIeeHbIRpmMRuaCWchbOoxhLGZ4NCSJJ/qapjMaMoTdZStI7H6TUweNNJ3UfXoaWY BaTTlutZaqHfYg/NSKiZmDwNWGvQfG/eOdzPF7VjTPBRV2PMupqTbOkxjnSbmp0cjP poSU7lEC5InrcnbCBmzwtLfjiBtnMnUcWPZZZ7gLMj0GSGWiihGxs/TavWVcKmmqnT SZez80AlDJi3w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C76F464D3E for ; Mon, 22 Dec 2025 04:57:57 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id In25quHaRU7W for ; Mon, 22 Dec 2025 04:57:57 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766404676; bh=HAX/x3Y0uhlfW1eb02VCPuZEHm7us4zfRQbijwyktw0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=F91e5LbQpMWuo/9Oa2xxQtvAtoY6lPQgqRqNKY9MxOxAx0fX/OicPYM1r9Ikum+D+ cyyWddX5L31i0eZi4qeq0majdvQNp54R0fBDGf0M1rFJN4r+AvDbIzrVKdFj0yOq8z Oo9Ke2RHTMq11F+ymhTXe50+SYI6V83dZtXkR8Ngrk0PS64VmPpjicRM1lw8OJ7q7F phil5HC6bUcEvzi91xQa3L93G0ycn7cEGlN1bFbjchbbKAiq6+UqjzVzJA/OufleHN 4cLooA35CKTXn8h1XVPncZwO+Vn3zC3TaJ4tyXkNVyGS+gmz3MbuAbG2fGtvnwQsmx ABVpGLhzSeaLw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4138D64D8C for ; Mon, 22 Dec 2025 04:57:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766404674; bh=IPRL/tAh6Z17/lBE794lGNn5ghDrE43JwXZvmjc8tls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W83BHm6oaMcaBBTqutu24Dg9ncsllihrX+fH5ziC8LV+9UkidHUu3vC3DbFXFXKLq aopjnp6h9xa68JLJOppCCNGbGgHKZrMqJN3DmxF4UiIshGP189//YzCSHwG9cZDFmi 4jCqohzUyFPvXktAmbfwRcl09Q0Zo8YfOF1kjBxzOgc1CbVwElavdkbv0XZxjIXhcW 0wb5aNyNKJ//rA2EctYIVeC9J2GpvwjIpJRZLs+GJSOWkcWdlmEknQcTOYfoHFj6of 525SzHBIY1GMMznEDpFUJUoUUGSFUDMArHLkh50ogMI/4YkIpis2aKMG0o3THkRimr WNVaXy/MVTRMA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 421DA64C31; Mon, 22 Dec 2025 04:57:54 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id P5KrrMFohfVe; Mon, 22 Dec 2025 04:57:54 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766404673; bh=ogdjcBDaNZlu8LgZEDdF6QBeOrqM4rvB4BM5wwF7px8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R2cW6Iad+KWc/4i5l0s9MvZ9iDufYS9DTZbrc6dyNlA6oczKw/w3ksqBjWsE+W7Q/ o5trtiSOcOW6oO40ypwgpXQABdqn7zYs3hovzl8uPA+HYY2SNzUyPkQpJ/m8bWlBS3 o08OtaWzR5ur7mxLSBzPexmSa9tvUCyM/V8NdOorW0D07+DaC7vS/TJmXBGO2VxhI9 r3rRZwhaLFpOdiY6babeVyTpd4xFRG+qGhnrVFKX6K1muTr5Mi2rXbwbWGacZzfYDw qVlljCJR4nKskKQCOOj5O4eSJFs9tZ+9DZ9iG4SPhCW22MRzl43roDr96ShZ3HJYEv VdlbkbqbBInfQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 99C775FB5A; Mon, 22 Dec 2025 04:57:53 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 22 Dec 2025 04:56:29 -0700 Message-ID: <20251222115639.700578-26-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251222115639.700578-1-sjg@u-boot.org> References: <20251222115639.700578-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GVMV7QMERKPRE6S7HZJ63PCPL5JVWHV6 X-Message-ID-Hash: GVMV7QMERKPRE6S7HZJ63PCPL5JVWHV6 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 25/26] fs: ext4l: Add inode and bmap functions List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add inode allocation and block mapping functions: - iget_locked() - allocate inode by number - new_inode() - allocate new empty inode - ext4_uboot_bmap() - map logical to physical block - bmap() - VFS interface for block mapping Also add i_count reference counter to struct inode. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 9 ++-- fs/ext4l/support.c | 99 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 4 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 5beedb4bb3d..4c4dd2ca559 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -377,8 +377,8 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block); #define ktime_get_real_seconds() (0) #define time_before32(a, b) (0) -/* Inode operations - stubs */ -#define new_inode(sb) ((struct inode *)NULL) +/* Inode operations - iget_locked and new_inode are in interface.c */ +extern struct inode *new_inode(struct super_block *sb); #define i_uid_write(inode, uid) do { } while (0) #define i_gid_write(inode, gid) do { } while (0) #define inode_fsuid_set(inode, idmap) do { } while (0) @@ -820,6 +820,7 @@ struct inode { const struct inode_operations *i_op; const struct file_operations *i_fop; atomic_t i_writecount; /* Count of writers */ + atomic_t i_count; /* Reference count */ struct rw_semaphore i_rwsem; /* inode lock */ const char *i_link; /* Symlink target for fast symlinks */ unsigned short i_write_hint; /* Write life time hint */ @@ -1615,7 +1616,7 @@ static inline unsigned int i_gid_read(const struct inode *inode) #define fs_high2lowgid(gid) ((gid) & 0xFFFF) /* Inode allocation/state operations */ -#define iget_locked(sb, ino) ((struct inode *)NULL) +extern struct inode *iget_locked(struct super_block *sb, unsigned long ino); #define set_nlink(i, n) do { (i)->i_nlink = (n); } while (0) #define inc_nlink(i) do { (i)->i_nlink++; } while (0) #define drop_nlink(i) do { (i)->i_nlink--; } while (0) @@ -2855,7 +2856,7 @@ struct disk_partition *ext4l_get_partition(void); /* JBD2 journal.c stubs */ struct buffer_head *alloc_buffer_head(gfp_t gfp_mask); #define __getblk(bdev, block, size) ({ (void)(bdev); (void)(block); (void)(size); (struct buffer_head *)NULL; }) -#define bmap(inode, block) ({ (void)(inode); (void)(block); 0; }) +int bmap(struct inode *inode, sector_t *block); #define trace_jbd2_update_log_tail(j, t, b, f) \ do { (void)(j); (void)(t); (void)(b); (void)(f); } while (0) diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 2040ad5f480..d1bc32ae8d6 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -39,6 +39,105 @@ u32 ext4l_crc32c(u32 crc, const void *address, unsigned int length) return crc32c_cal(crc, address, length, ext4l_crc32c_table); } +/* + * iget_locked - allocate a new inode + * @sb: super block of filesystem + * @ino: inode number to allocate + * + * U-Boot implementation: allocates ext4_inode_info and returns the embedded + * vfs_inode. In Linux, this would look up the inode in a hash table first. + * Since U-Boot is single-threaded and doesn't cache inodes, we always allocate. + */ +struct inode *iget_locked(struct super_block *sb, unsigned long ino) +{ + struct ext4_inode_info *ei; + struct inode *inode; + + ei = kzalloc(sizeof(struct ext4_inode_info), GFP_KERNEL); + if (!ei) + return NULL; + + /* Get pointer to the embedded vfs_inode using offsetof */ + inode = (struct inode *)((char *)ei + + offsetof(struct ext4_inode_info, vfs_inode)); + inode->i_sb = sb; + inode->i_blkbits = sb->s_blocksize_bits; + inode->i_ino = ino; + inode->i_state = I_NEW; + inode->i_count.counter = 1; + inode->i_mapping = &inode->i_data; + inode->i_data.host = inode; + INIT_LIST_HEAD(&ei->i_es_list); + + return inode; +} + +/* + * new_inode - allocate a new empty inode + * @sb: super block of filesystem + * + * U-Boot implementation: allocates ext4_inode_info for a new inode that + * will be initialised by the caller (e.g., for creating new files). + */ +struct inode *new_inode(struct super_block *sb) +{ + struct ext4_inode_info *ei; + struct inode *inode; + + ei = kzalloc(sizeof(struct ext4_inode_info), GFP_KERNEL); + if (!ei) + return NULL; + + inode = &ei->vfs_inode; + inode->i_sb = sb; + inode->i_blkbits = sb->s_blocksize_bits; + inode->i_nlink = 1; + inode->i_count.counter = 1; + inode->i_mapping = &inode->i_data; + inode->i_data.host = inode; + INIT_LIST_HEAD(&ei->i_es_list); + + return inode; +} + +/* + * ext4_uboot_bmap - map a logical block to a physical block + * @inode: inode to map + * @block: on entry, logical block number; on exit, physical block number + * + * U-Boot implementation of bmap for ext4. Maps a logical block number + * to the corresponding physical block on disk. + */ +int ext4_uboot_bmap(struct inode *inode, sector_t *block) +{ + struct ext4_map_blocks map; + int ret; + + map.m_lblk = *block; + map.m_len = 1; + map.m_flags = 0; + + ret = ext4_map_blocks(NULL, inode, &map, 0); + if (ret > 0) { + *block = map.m_pblk; + return 0; + } + + return ret < 0 ? ret : -EINVAL; +} + +/* + * bmap - map a logical block to a physical block (VFS interface) + * @inode: inode to map + * @blockp: pointer to logical block number; updated to physical block number + * + * This is the VFS bmap interface used by jbd2. + */ +int bmap(struct inode *inode, sector_t *blockp) +{ + return ext4_uboot_bmap(inode, blockp); +} + /* * Buffer cache implementation *