[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260218061531.3318130-10-hch@lst.de>
Date: Wed, 18 Feb 2026 07:14:47 +0100
From: Christoph Hellwig <hch@....de>
To: Eric Biggers <ebiggers@...nel.org>
Cc: "Theodore Y. Ts'o" <tytso@....edu>,
Jaegeuk Kim <jaegeuk@...nel.org>,
Andreas Dilger <adilger.kernel@...ger.ca>,
Chao Yu <chao@...nel.org>,
Christian Brauner <brauner@...nel.org>,
"Darrick J. Wong" <djwong@...nel.org>,
linux-fscrypt@...r.kernel.org,
linux-ext4@...r.kernel.org,
linux-f2fs-devel@...ts.sourceforge.net,
linux-fsdevel@...r.kernel.org
Subject: [PATCH 9/9] fscrypt: pass a real sector_t to fscrypt_zeroout_range
While the pblk argument to fscrypt_zeroout_range is declared as a
sector_t, it actually is interpreted as a logical block size unit, which
is highly unusual. Switch to passing the 512 byte units that sector_t is
defined for.
Signed-off-by: Christoph Hellwig <hch@....de>
---
fs/crypto/bio.c | 6 ++----
fs/ext4/inode.c | 3 ++-
fs/f2fs/file.c | 2 +-
include/linux/fscrypt.h | 4 ++--
4 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c
index cea931620c04..45fe74aa8366 100644
--- a/fs/crypto/bio.c
+++ b/fs/crypto/bio.c
@@ -114,7 +114,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
* fscrypt_zeroout_range() - zero out a range of blocks in an encrypted file
* @inode: the file's inode
* @pos: the first file logical offset (in bytes) to zero out
- * @pblk: the first filesystem physical block to zero out
+ * @sector: the first sector to zero out
* @len: bytes to zero out
*
* Zero out filesystem blocks in an encrypted regular file on-disk, i.e. write
@@ -128,7 +128,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
* Return: 0 on success; -errno on failure.
*/
int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
- sector_t pblk, unsigned int len)
+ sector_t sector, unsigned int len)
{
const struct fscrypt_inode_info *ci = fscrypt_get_inode_info_raw(inode);
const unsigned int du_bits = ci->ci_data_unit_bits;
@@ -137,8 +137,6 @@ int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
const unsigned int du_per_page = 1U << du_per_page_bits;
u64 du_index = pos >> du_bits;
u64 du_remaining = len >> du_bits;
- loff_t pos = (loff_t)lblk << inode->i_blkbits;
- sector_t sector = pblk << (inode->i_blkbits - SECTOR_SHIFT);
struct page *pages[16]; /* write up to 16 pages at a time */
unsigned int nr_pages;
unsigned int i;
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 675ef741cb30..d0028d6d3de1 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -406,7 +406,8 @@ int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk,
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode))
return fscrypt_zeroout_range(inode,
- (loff_t)lblk << inode->i_blkbits, pblk,
+ (loff_t)lblk << inode->i_blkbits,
+ pblk << (inode->i_blkbits - SECTOR_SHIFT),
len << inode->i_blkbits);
ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 5b7013f7f6a1..ad435dea656a 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4163,7 +4163,7 @@ static int f2fs_secure_erase(struct block_device *bdev, struct inode *inode,
if (!ret && (flags & F2FS_TRIM_FILE_ZEROOUT)) {
if (IS_ENCRYPTED(inode))
ret = fscrypt_zeroout_range(inode,
- (loff_t)off << inode->i_blkbits, block,
+ (loff_t)off << inode->i_blkbits, sector,
len << inode->i_blkbits);
else
ret = blkdev_issue_zeroout(bdev, sector, nr_sects,
diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
index 065f909ebda2..11464bf0a241 100644
--- a/include/linux/fscrypt.h
+++ b/include/linux/fscrypt.h
@@ -451,7 +451,7 @@ u64 fscrypt_fname_siphash(const struct inode *dir, const struct qstr *name);
/* bio.c */
bool fscrypt_decrypt_bio(struct bio *bio);
int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
- sector_t pblk, unsigned int len);
+ sector_t sector, unsigned int len);
/* hooks.c */
int fscrypt_file_open(struct inode *inode, struct file *filp);
@@ -756,7 +756,7 @@ static inline bool fscrypt_decrypt_bio(struct bio *bio)
}
static inline int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
- sector_t pblk, unsigned int len)
+ sector_t sector, unsigned int len)
{
return -EOPNOTSUPP;
}
--
2.47.3
Powered by blists - more mailing lists