fs/ntfs3: Make ntfs_fallocate return -ENOSPC instead of -EFBIG
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Fri, 13 May 2022 16:21:54 +0000 (19:21 +0300)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Wed, 3 Aug 2022 15:25:05 +0000 (18:25 +0300)
In some cases we need to return ENOSPC
Fixes xfstest generic/213
Fixes: 114346978cf6 ("fs/ntfs3: Check new size for limits")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/file.c

index cf16bde810cce760441fd1febb8e229d1325d99c..b5f8837f41454cbe285f60c9207051f6143a4158 100644 (file)
@@ -671,6 +671,19 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
                ni_unlock(ni);
        } else {
                /* Check new size. */
+
+               /* generic/213: expected -ENOSPC instead of -EFBIG. */
+               if (!is_supported_holes) {
+                       loff_t to_alloc = new_size - inode_get_bytes(inode);
+
+                       if (to_alloc > 0 &&
+                           (to_alloc >> sbi->cluster_bits) >
+                                   wnd_zeroes(&sbi->used.bitmap)) {
+                               err = -ENOSPC;
+                               goto out;
+                       }
+               }
+
                err = inode_newsize_ok(inode, new_size);
                if (err)
                        goto out;