s3: enforce a positive allocation_file_size for non-empty files
authorBjörn Baumbach <bb@sernet.de>
Thu, 27 Mar 2014 10:17:30 +0000 (11:17 +0100)
committerJeremy Allison <jra@samba.org>
Sat, 5 Apr 2014 01:09:00 +0000 (03:09 +0200)
Some file systems do not allocate a block for very
small files. But for non-empty file should report a
positive size.

Pair-Programmed-With: Michael Adam <obnox@samba.org>

Signed-off-by: Björn Baumbach <bb@sernet.de>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Apr  5 03:09:00 CEST 2014 on sn-devel-104

source3/modules/vfs_default.c

index 673ebfe35bf99cefc17257b8d33ea12d069dac7d..a129d81d431ad601e5aa525f4f1d7e8ab1e77b73 100644 (file)
@@ -1538,6 +1538,18 @@ static uint64_t vfswrap_get_alloc_size(vfs_handle_struct *handle,
 #else
 #error SIZEOF_BLKCNT_T_NOT_A_SUPPORTED_VALUE
 #endif
+       if (result == 0) {
+               /*
+                * Some file systems do not allocate a block for very
+                * small files. But for non-empty file should report a
+                * positive size.
+                */
+
+               uint64_t filesize = get_file_size_stat(sbuf);
+               if (filesize > 0) {
+                       result = MIN((uint64_t)STAT_ST_BLOCKSIZE, filesize);
+               }
+       }
 #else
        result = get_file_size_stat(sbuf);
 #endif