]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fscrypt: pass a byte offset to fscrypt_zeroout_range
authorChristoph Hellwig <hch@lst.de>
Mon, 2 Mar 2026 14:18:16 +0000 (06:18 -0800)
committerEric Biggers <ebiggers@kernel.org>
Mon, 9 Mar 2026 20:31:51 +0000 (13:31 -0700)
Logical offsets into an inode are usually expressed as bytes in the VFS.
Switch fscrypt_zeroout_range to that convention.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20260302141922.370070-12-hch@lst.de
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
fs/crypto/bio.c
fs/ext4/inode.c
fs/f2fs/file.c
include/linux/fscrypt.h

index 303b5acc66a92662361c58aa3b50275ae686e84c..a07ac8dcf851f1a1204ccee368da110926b8c91c 100644 (file)
@@ -113,7 +113,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
- * @lblk: the first file logical block to zero out
+ * @pos: the first file position (in bytes) to zero out
  * @pblk: the first filesystem physical block to zero out
  * @len: number of blocks to zero out
  *
@@ -127,7 +127,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, pgoff_t lblk,
+int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
                          sector_t pblk, unsigned int len)
 {
        const struct fscrypt_inode_info *ci = fscrypt_get_inode_info_raw(inode);
@@ -135,9 +135,8 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
        const unsigned int du_size = 1U << du_bits;
        const unsigned int du_per_page_bits = PAGE_SHIFT - du_bits;
        const unsigned int du_per_page = 1U << du_per_page_bits;
-       u64 du_index = (u64)lblk << (inode->i_blkbits - du_bits);
+       u64 du_index = pos >> du_bits;
        u64 du_remaining = (u64)len << (inode->i_blkbits - 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;
index 396dc3a5d16b4dc4d3e5c6541871a9bb896f6d7a..945613c95ffa16236330f7804880b6aa923e7cae 100644 (file)
@@ -405,7 +405,8 @@ int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk,
        KUNIT_STATIC_STUB_REDIRECT(ext4_issue_zeroout, inode, lblk, pblk, len);
 
        if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode))
-               return fscrypt_zeroout_range(inode, lblk, pblk, len);
+               return fscrypt_zeroout_range(inode,
+                               (loff_t)lblk << inode->i_blkbits, pblk, len);
 
        ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS);
        if (ret > 0)
index c8a2f17a8f11cfc746c6a6ec4a225199929c2ee6..239c2666ceb5201b25176b7ca67dbbb4c0cbb930 100644 (file)
@@ -4162,7 +4162,9 @@ 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, off, block, len);
+                       ret = fscrypt_zeroout_range(inode,
+                                       (loff_t)off << inode->i_blkbits, block,
+                                       len);
                else
                        ret = blkdev_issue_zeroout(bdev, sector, nr_sects,
                                        GFP_NOFS, 0);
index 90f75fe0e1c9a7048686d367033becc599f2cf8b..9fc15e1fbe570f716cca5f0db7e46523c3adc0bd 100644 (file)
@@ -450,7 +450,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, pgoff_t lblk,
+int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
                          sector_t pblk, unsigned int len);
 
 /* hooks.c */
@@ -755,7 +755,7 @@ static inline bool fscrypt_decrypt_bio(struct bio *bio)
        return true;
 }
 
-static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
+static inline int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
                                        sector_t pblk, unsigned int len)
 {
        return -EOPNOTSUPP;