Skip to content

Commit 5ca1a1f

Browse files
Christoph HellwigEric Biggers
authored andcommitted
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@lst.de> Link: https://lore.kernel.org/r/20260302141922.370070-14-hch@lst.de Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent fb87ab4 commit 5ca1a1f

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

fs/crypto/bio.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
114114
* fscrypt_zeroout_range() - zero out a range of blocks in an encrypted file
115115
* @inode: the file's inode
116116
* @pos: the first file position (in bytes) to zero out
117-
* @pblk: the first filesystem physical block to zero out
117+
* @sector: the first sector to zero out
118118
* @len: bytes to zero out
119119
*
120120
* Zero out filesystem blocks in an encrypted regular file on-disk, i.e. write
@@ -129,7 +129,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
129129
* Return: 0 on success; -errno on failure.
130130
*/
131131
int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
132-
sector_t pblk, u64 len)
132+
sector_t sector, u64 len)
133133
{
134134
const struct fscrypt_inode_info *ci = fscrypt_get_inode_info_raw(inode);
135135
const unsigned int du_bits = ci->ci_data_unit_bits;
@@ -138,7 +138,6 @@ int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
138138
const unsigned int du_per_page = 1U << du_per_page_bits;
139139
u64 du_index = pos >> du_bits;
140140
u64 du_remaining = len >> du_bits;
141-
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;
144143
unsigned int i;

fs/ext4/inode.c

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

407407
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode))
408408
return fscrypt_zeroout_range(inode,
409-
(loff_t)lblk << inode->i_blkbits, pblk,
409+
(loff_t)lblk << inode->i_blkbits,
410+
pblk << (inode->i_blkbits - SECTOR_SHIFT),
410411
(u64)len << inode->i_blkbits);
411412

412413
ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS);

fs/f2fs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4163,7 +4163,7 @@ static int f2fs_secure_erase(struct block_device *bdev, struct inode *inode,
41634163
if (!ret && (flags & F2FS_TRIM_FILE_ZEROOUT)) {
41644164
if (IS_ENCRYPTED(inode))
41654165
ret = fscrypt_zeroout_range(inode,
4166-
(loff_t)off << inode->i_blkbits, block,
4166+
(loff_t)off << inode->i_blkbits, sector,
41674167
(u64)len << inode->i_blkbits);
41684168
else
41694169
ret = blkdev_issue_zeroout(bdev, sector, nr_sects,

include/linux/fscrypt.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ 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, loff_t pos, sector_t pblk,
454-
u64 len);
453+
int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
454+
sector_t sector, u64 len);
455455

456456
/* hooks.c */
457457
int fscrypt_file_open(struct inode *inode, struct file *filp);
@@ -756,7 +756,7 @@ static inline bool fscrypt_decrypt_bio(struct bio *bio)
756756
}
757757

758758
static inline int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
759-
sector_t pblk, u64 len)
759+
sector_t sector, u64 len)
760760
{
761761
return -EOPNOTSUPP;
762762
}

0 commit comments

Comments
 (0)