Skip to content

Commit cd7db2e

Browse files
Christoph HellwigEric Biggers
authored andcommitted
fscrypt: pass a byte offset to fscrypt_zeroout_range
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>
1 parent 90950ee commit cd7db2e

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

fs/crypto/bio.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
113113
/**
114114
* fscrypt_zeroout_range() - zero out a range of blocks in an encrypted file
115115
* @inode: the file's inode
116-
* @lblk: the first file logical block to zero out
116+
* @pos: the first file position (in bytes) to zero out
117117
* @pblk: the first filesystem physical block to zero out
118118
* @len: number of blocks to zero out
119119
*
@@ -127,17 +127,16 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
127127
*
128128
* Return: 0 on success; -errno on failure.
129129
*/
130-
int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
130+
int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
131131
sector_t pblk, unsigned int len)
132132
{
133133
const struct fscrypt_inode_info *ci = fscrypt_get_inode_info_raw(inode);
134134
const unsigned int du_bits = ci->ci_data_unit_bits;
135135
const unsigned int du_size = 1U << du_bits;
136136
const unsigned int du_per_page_bits = PAGE_SHIFT - du_bits;
137137
const unsigned int du_per_page = 1U << du_per_page_bits;
138-
u64 du_index = (u64)lblk << (inode->i_blkbits - du_bits);
138+
u64 du_index = pos >> du_bits;
139139
u64 du_remaining = (u64)len << (inode->i_blkbits - du_bits);
140-
loff_t pos = (loff_t)lblk << inode->i_blkbits;
141140
sector_t sector = pblk << (inode->i_blkbits - SECTOR_SHIFT);
142141
struct page *pages[16]; /* write up to 16 pages at a time */
143142
unsigned int nr_pages;

fs/ext4/inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk,
405405
KUNIT_STATIC_STUB_REDIRECT(ext4_issue_zeroout, inode, lblk, pblk, len);
406406

407407
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode))
408-
return fscrypt_zeroout_range(inode, lblk, pblk, len);
408+
return fscrypt_zeroout_range(inode,
409+
(loff_t)lblk << inode->i_blkbits, pblk, len);
409410

410411
ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS);
411412
if (ret > 0)

fs/f2fs/file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4162,7 +4162,9 @@ static int f2fs_secure_erase(struct block_device *bdev, struct inode *inode,
41624162

41634163
if (!ret && (flags & F2FS_TRIM_FILE_ZEROOUT)) {
41644164
if (IS_ENCRYPTED(inode))
4165-
ret = fscrypt_zeroout_range(inode, off, block, len);
4165+
ret = fscrypt_zeroout_range(inode,
4166+
(loff_t)off << inode->i_blkbits, block,
4167+
len);
41664168
else
41674169
ret = blkdev_issue_zeroout(bdev, sector, nr_sects,
41684170
GFP_NOFS, 0);

include/linux/fscrypt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ u64 fscrypt_fname_siphash(const struct inode *dir, const struct qstr *name);
450450

451451
/* bio.c */
452452
bool fscrypt_decrypt_bio(struct bio *bio);
453-
int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
453+
int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
454454
sector_t pblk, unsigned int len);
455455

456456
/* hooks.c */
@@ -755,7 +755,7 @@ static inline bool fscrypt_decrypt_bio(struct bio *bio)
755755
return true;
756756
}
757757

758-
static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
758+
static inline int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
759759
sector_t pblk, unsigned int len)
760760
{
761761
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)