Re: [PATCH v4 2/6] fat: add fat_fallocate operation

From: OGAWA Hirofumi
Date: Tue Mar 18 2014 - 10:55:57 EST


Namjae Jeon <linkinjeon@xxxxxxxxx> writes:

> + if (mode & FALLOC_FL_KEEP_SIZE) {
> + /* First compute the number of clusters to be allocated */
> + mm_bytes = offset + len - round_up(MSDOS_I(inode)->i_disksize,
> + sbi->cluster_size);
> + nr_cluster = (mm_bytes + (sbi->cluster_size - 1)) >>
> + sbi->cluster_bits;
> +
> + /* Start the allocation.We are not zeroing out the clusters */
> + while (nr_cluster-- > 0) {
> + err = fat_alloc_clusters(inode, &cluster, 1);
> + if (err) {
> + fat_msg(sb, KERN_ERR,
> + "fat_fallocate(): fat_alloc_clusters() error");
> + goto error;
> + }
> + err = fat_chain_add(inode, cluster, 1);
> + if (err) {
> + fat_free_clusters(inode, cluster);
> + goto error;
> + }
> + MSDOS_I(inode)->i_disksize += sbi->cluster_size;
> + }

Hm. This ->i_disksize calculation is right? Why do we use cluster align
here? My concern is, say blocksize == 512 and clustersize == 4096,

0 512 5120
| | |
+-------+-----------+------+
4096

Before fallocate(), ->i_disksize == 512. Then user called fallocate()
with offset == 512 and len == 4608.

After that, this sets ->i_disksize += 4096, == 4608? I think, we should
set ->i_disksize == 5120, finally. I can be missing something though.
--
OGAWA Hirofumi <hirofumi@xxxxxxxxxxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/