[Concept,10/15] ext4l: Fix dquot functions to update i_blocks

Message ID 20251230234134.906477-11-sjg@u-boot.org
State New
Headers
Series ext4l: Infrastructure and fixes for write support (part K) |

Commit Message

Simon Glass Dec. 30, 2025, 11:41 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

The dquot_alloc_block(), dquot_free_block() and dquot_alloc_block_nofail()
functions are stubs that do nothing. These functions are called by ext4
when allocating and freeing blocks, and they should update the inode's
i_blocks field.

Fix these functions to properly track block allocation in i_blocks,
which is stored in 512-byte units.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/ext4_uboot.h |  3 ++-
 fs/ext4l/stub.c       | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index 610fe34b556..c5eddca3aef 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -375,7 +375,8 @@  struct buffer_head *sb_getblk(struct super_block *sb, sector_t block);
 
 /* Quota operations - stubs (only define if quotaops.h not included) */
 #ifndef _LINUX_QUOTAOPS_H
-#define dquot_alloc_block_nofail(inode, nr)	({ (void)(inode); (void)(nr); 0; })
+#define dquot_alloc_block_nofail(inode, nr)	\
+	({ (inode)->i_blocks += (nr) << ((inode)->i_blkbits - 9); 0; })
 #define dquot_initialize(inode)			({ (void)(inode); 0; })
 #define dquot_free_inode(inode)			do { (void)(inode); } while (0)
 #define dquot_alloc_inode(inode)		({ (void)(inode); 0; })
diff --git a/fs/ext4l/stub.c b/fs/ext4l/stub.c
index 2d066be4af3..ce68ec28b20 100644
--- a/fs/ext4l/stub.c
+++ b/fs/ext4l/stub.c
@@ -669,11 +669,22 @@  void dquot_free_space_nodirty(struct inode *inode, loff_t size)
 
 int dquot_alloc_block(struct inode *inode, loff_t nr)
 {
+	/*
+	 * Update i_blocks to reflect the allocated blocks.
+	 * i_blocks is in 512-byte units, so convert from fs blocks.
+	 */
+	inode->i_blocks += nr << (inode->i_blkbits - 9);
+
 	return 0;
 }
 
 void dquot_free_block(struct inode *inode, loff_t nr)
 {
+	/*
+	 * Update i_blocks to reflect the freed blocks.
+	 * i_blocks is in 512-byte units, so convert from fs blocks.
+	 */
+	inode->i_blocks -= nr << (inode->i_blkbits - 9);
 }
 
 /*