]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
smb/server: fix incorrect file size in get_file_compression_info()
authorChenXiaoSong <chenxiaosong@kylinos.cn>
Tue, 9 Jun 2026 06:10:28 +0000 (06:10 +0000)
committerSteve French <stfrench@microsoft.com>
Tue, 16 Jun 2026 23:57:21 +0000 (18:57 -0500)
Before this patch, we got the wrong file size:

  - client: touch /mnt/file
  - client: smbinfo setcompression default /mnt/file
  - client: dd if=/dev/zero of=/mnt/file bs=1 count=1000
  - client: smbinfo filecompressioninfo /mnt/file
            Compressed File Size: 4096
            Compression Format: 2 (LZNT1)

After this patch, we get the correct file size:

  - client: smbinfo filecompressioninfo /mnt/file
            Compressed File Size: 1000
            Compression Format: 2 (LZNT1)

Note that the actual compressed file size must be got by other methods.
For Btrfs, use the following command to get actual compressed file size:

  - server: compsize /export/file
            Processed 1 file, 0 regular extents (0 refs), 1 inline.
            Type       Perc     Disk Usage   Uncompressed Referenced
            TOTAL        4%       47B        1000B        1000B
            zlib         4%       47B        1000B        1000B

Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/smb2pdu.c

index 6258a8a92c566cb6ee9eb1b625214a92c51bac0a..327ec625d42b79892e220ebdabcfa8660d090dcd 100644 (file)
@@ -5292,7 +5292,7 @@ static int get_file_compression_info(struct smb2_query_info_rsp *rsp,
                return ret;
 
        file_info = (struct smb2_file_comp_info *)rsp->Buffer;
-       file_info->CompressedFileSize = cpu_to_le64(stat.blocks << 9);
+       file_info->CompressedFileSize = cpu_to_le64(min_t(u64, stat.blocks << 9, stat.size));
        file_info->CompressionFormat = cpu_to_le16(fmt);
        file_info->CompressionUnitShift = 0;
        file_info->ChunkShift = 0;