From: Chi Zhiling <chizhiling@163.com>
To: Namjae Jeon <linkinjeon@kernel.org>,
sj1557.seo@samsung.com, yuezhang.mo@sony.com, brauner@kernel.org,
djwong@kernel.org, hch@lst.de
Cc: linux-fsdevel@vger.kernel.org, anmuxixixi@gmail.com,
dxdt@dev.snart.me, chizhiling@kylinos.cn,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 08/11] exfat: add iomap buffered I/O support
Date: Thu, 14 May 2026 09:39:05 +0800 [thread overview]
Message-ID: <67ea38e7-ec7f-4ade-8962-074c60a45321@163.com> (raw)
In-Reply-To: <20260513112156.9122-9-linkinjeon@kernel.org>
On 5/13/26 19:21, Namjae Jeon wrote:
> +static int __exfat_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
> + unsigned int flags, struct iomap *iomap, bool may_alloc)
> +{
> + struct super_block *sb = inode->i_sb;
> + struct exfat_sb_info *sbi = EXFAT_SB(sb);
> + struct exfat_inode_info *ei = EXFAT_I(inode);
> + unsigned int cluster, num_clusters;
> + loff_t cluster_offset, cluster_length;
> + int err;
> + bool balloc = false;
> +
> + if (!may_alloc) {
> + /* Completely beyond EOF. Treat as hole */
> + if (i_size_read(inode) <= offset) {
> + iomap->type = IOMAP_HOLE;
> + iomap->addr = IOMAP_NULL_ADDR;
> + iomap->offset = offset;
> + iomap->length = length;
> + return 0;
> + }
> +
> + /* Clamp length if the requested range goes beyond i_size */
> + if (offset + length > i_size_read(inode))
> + length = round_up(i_size_read(inode),
> + i_blocksize(inode)) - offset;
> + }
> +
> + num_clusters = exfat_bytes_to_cluster_round_up(sbi,
> + offset + length) - exfat_bytes_to_cluster(sbi, offset);
> +
> + mutex_lock(&sbi->s_lock);
> + iomap->bdev = inode->i_sb->s_bdev;
> + iomap->offset = offset;
> +
> + err = exfat_map_cluster(inode, exfat_bytes_to_cluster(sbi, offset),
> + &cluster, &num_clusters, may_alloc, &balloc);
> + if (err)
> + goto out;
> +
> + cluster_offset = exfat_cluster_offset(sbi, offset);
> + cluster_length = exfat_cluster_to_bytes(sbi, num_clusters);
> +
> + iomap->length = min_t(loff_t, length, cluster_length - cluster_offset);
> + iomap->addr = exfat_cluster_to_phys(sbi, cluster) + cluster_offset;
> + iomap->type = IOMAP_MAPPED;
> + if (may_alloc) {
> + if (balloc)
> + iomap->flags = IOMAP_F_NEW;
> + else if (iomap->offset + iomap->length >= ei->valid_size) {
> + /*
> + * This is a write that starts at or extends beyond
> + * the current valid_size. The region between the old
> + * valid_size and the end of this write needs to be
> + * zeroed in the page cache to prevent stale data
> + * exposure (see IOMAP_F_ZERO_TAIL handling in
> + * __iomap_write_begin()).
> + */
> + iomap->flags = IOMAP_F_ZERO_TAIL;
> + }
> + } else {
> + if (offset >= ei->valid_size)
> + iomap->type = IOMAP_UNWRITTEN;
> +
> + if (iomap->type == IOMAP_MAPPED &&
> + iomap->offset < ei->valid_size &&
> + iomap->offset + iomap->length > ei->valid_size) {
> + iomap->length = round_up(ei->valid_size,
> + i_blocksize(inode)) -
> + iomap->offset;
> + }
Hi, you can write it like this:
if (offset >= ei->valid_size) {
iomap->type = IOMAP_UNWRITTEN;
} else if (offset + iomap->length > ei->valid_size) {
iomap->length = round_up(ei->valid_size,
i_blocksize(inode)) -
iomap->offset;
}
Thanks,
next prev parent reply other threads:[~2026-05-14 1:39 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 11:21 [PATCH v3 00/11] exfat: convert to iomap Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 01/11] iomap: introduce IOMAP_F_ZERO_TAIL flag Namjae Jeon
2026-05-15 4:48 ` Christoph Hellwig
2026-05-15 5:52 ` Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 02/11] exfat: replace unsafe macros with static inline functions Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 03/11] exfat: add balloc parameter to exfat_map_cluster() for iomap support Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 04/11] exfat: add exfat_file_open() Namjae Jeon
2026-05-13 12:06 ` CharSyam
2026-05-13 14:11 ` Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 05/11] exfat: add support for multi-cluster allocation Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 06/11] exfat: add data_start_bytes and exfat_cluster_to_phys() helper Namjae Jeon
2026-05-13 15:17 ` CharSyam
2026-05-13 23:43 ` Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 07/11] exfat: fix implicit declaration of brelse() Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 08/11] exfat: add iomap buffered I/O support Namjae Jeon
2026-05-14 1:39 ` Chi Zhiling [this message]
2026-05-14 1:47 ` Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 09/11] exfat: add iomap direct " Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 10/11] exfat: add support for SEEK_HOLE and SEEK_DATA in llseek Namjae Jeon
2026-05-13 11:21 ` [PATCH v3 11/11] exfat: make exfat_truncate() return error code Namjae Jeon
2026-05-15 4:50 ` [PATCH v3 00/11] exfat: convert to iomap Christoph Hellwig
2026-05-15 5:57 ` Namjae Jeon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=67ea38e7-ec7f-4ade-8962-074c60a45321@163.com \
--to=chizhiling@163.com \
--cc=anmuxixixi@gmail.com \
--cc=brauner@kernel.org \
--cc=chizhiling@kylinos.cn \
--cc=djwong@kernel.org \
--cc=dxdt@dev.snart.me \
--cc=hch@lst.de \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sj1557.seo@samsung.com \
--cc=yuezhang.mo@sony.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.