Skip to content

Commit fb87ab4

Browse files
Christoph HellwigEric Biggers
authored andcommitted
fscrypt: pass a byte length to fscrypt_zeroout_range
Range lengths are usually expressed as bytes in the VFS, switch fscrypt_zeroout_range to this convention. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20260302141922.370070-13-hch@lst.de Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent cd7db2e commit fb87ab4

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

fs/crypto/bio.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,29 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
115115
* @inode: the file's inode
116116
* @pos: the first file position (in bytes) to zero out
117117
* @pblk: the first filesystem physical block to zero out
118-
* @len: number of blocks to zero out
118+
* @len: bytes to zero out
119119
*
120120
* Zero out filesystem blocks in an encrypted regular file on-disk, i.e. write
121121
* ciphertext blocks which decrypt to the all-zeroes block. The blocks must be
122122
* both logically and physically contiguous. It's also assumed that the
123-
* filesystem only uses a single block device, ->s_bdev.
123+
* filesystem only uses a single block device, ->s_bdev. @len must be a
124+
* multiple of the file system logical block size.
124125
*
125126
* Note that since each block uses a different IV, this involves writing a
126127
* different ciphertext to each block; we can't simply reuse the same one.
127128
*
128129
* Return: 0 on success; -errno on failure.
129130
*/
130131
int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
131-
sector_t pblk, unsigned int len)
132+
sector_t pblk, u64 len)
132133
{
133134
const struct fscrypt_inode_info *ci = fscrypt_get_inode_info_raw(inode);
134135
const unsigned int du_bits = ci->ci_data_unit_bits;
135136
const unsigned int du_size = 1U << du_bits;
136137
const unsigned int du_per_page_bits = PAGE_SHIFT - du_bits;
137138
const unsigned int du_per_page = 1U << du_per_page_bits;
138139
u64 du_index = pos >> du_bits;
139-
u64 du_remaining = (u64)len << (inode->i_blkbits - du_bits);
140+
u64 du_remaining = len >> du_bits;
140141
sector_t sector = pblk << (inode->i_blkbits - SECTOR_SHIFT);
141142
struct page *pages[16]; /* write up to 16 pages at a time */
142143
unsigned int nr_pages;
@@ -150,7 +151,7 @@ int fscrypt_zeroout_range(const struct inode *inode, loff_t pos,
150151

151152
if (fscrypt_inode_uses_inline_crypto(inode))
152153
return fscrypt_zeroout_range_inline_crypt(inode, pos, sector,
153-
(u64)len << inode->i_blkbits);
154+
len);
154155

155156
BUILD_BUG_ON(ARRAY_SIZE(pages) > BIO_MAX_VECS);
156157
nr_pages = min_t(u64, ARRAY_SIZE(pages),

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, len);
409+
(loff_t)lblk << inode->i_blkbits, pblk,
410+
(u64)len << inode->i_blkbits);
410411

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

fs/f2fs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4164,7 +4164,7 @@ static int f2fs_secure_erase(struct block_device *bdev, struct inode *inode,
41644164
if (IS_ENCRYPTED(inode))
41654165
ret = fscrypt_zeroout_range(inode,
41664166
(loff_t)off << inode->i_blkbits, block,
4167-
len);
4167+
(u64)len << inode->i_blkbits);
41684168
else
41694169
ret = blkdev_issue_zeroout(bdev, sector, nr_sects,
41704170
GFP_NOFS, 0);

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,
454-
sector_t pblk, unsigned int len);
453+
int fscrypt_zeroout_range(const struct inode *inode, loff_t pos, sector_t pblk,
454+
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, unsigned int len)
759+
sector_t pblk, u64 len)
760760
{
761761
return -EOPNOTSUPP;
762762
}

0 commit comments

Comments
 (0)