Index: samba-4.0.24/lib/param/param_functions.c
===================================================================
--- samba-4.0.24.orig/lib/param/param_functions.c
+++ samba-4.0.24/lib/param/param_functions.c
@@ -109,6 +109,7 @@ FN_LOCAL_BOOL(onlyuser, bOnlyUser)
 FN_LOCAL_PARM_BOOL(manglednames, bMangledNames)
 FN_LOCAL_BOOL(symlinks, bSymlinks)
 FN_LOCAL_BOOL(syncalways, bSyncAlways)
+FN_LOCAL_BOOL(loose_allocate, bLooseAllocate)
 FN_LOCAL_BOOL(strict_allocate, bStrictAllocate)
 FN_LOCAL_BOOL(delete_readonly, bDeleteReadonly)
 FN_LOCAL_BOOL(fake_oplocks, bFakeOplocks)
Index: samba-4.0.24/lib/param/param_table.c
===================================================================
--- samba-4.0.24.orig/lib/param/param_table.c
+++ samba-4.0.24/lib/param/param_table.c
@@ -1869,6 +1869,15 @@ static struct parm_struct parm_table[] =
 		.flags		= FLAG_ADVANCED,
 	},
 	{
+		.label		= "loose allocate",
+		.type		= P_BOOL,
+		.p_class	= P_LOCAL,
+		.offset		= LOCAL_VAR(bLooseAllocate),
+		.special	= NULL,
+		.enum_list	= NULL,
+		.flags		= FLAG_ADVANCED | FLAG_SHARE,
+	},
+	{
 		.label		= "strict allocate",
 		.type		= P_BOOL,
 		.p_class	= P_LOCAL,
Index: samba-4.0.24/source3/include/proto.h
===================================================================
--- samba-4.0.24.orig/source3/include/proto.h
+++ samba-4.0.24/source3/include/proto.h
@@ -1299,6 +1299,7 @@ bool lp_widelinks(int );
 bool lp_symlinks(int );
 bool lp_syncalways(int );
 bool lp_strict_allocate(int );
+bool lp_loose_allocate(int );
 bool lp_strict_sync(int );
 bool lp_map_system(int );
 bool lp_delete_readonly(int );
Index: samba-4.0.24/source3/modules/vfs_default.c
===================================================================
--- samba-4.0.24.orig/source3/modules/vfs_default.c
+++ samba-4.0.24/source3/modules/vfs_default.c
@@ -1345,28 +1345,7 @@ static uint64_t vfswrap_get_alloc_size(v
 	   signed (according to POSIX) and can be less than 64-bits.
 	   Ensure when we're converting to 64 bits wide we don't
 	   sign extend. */
-#if defined(SIZEOF_BLKCNT_T_8)
 	result = (uint64_t)STAT_ST_BLOCKSIZE * (uint64_t)sbuf->st_ex_blocks;
-#elif defined(SIZEOF_BLKCNT_T_4)
-	{
-		uint64_t bs = ((uint64_t)sbuf->st_ex_blocks) & 0xFFFFFFFFLL;
-		result = (uint64_t)STAT_ST_BLOCKSIZE * bs;
-	}
-#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
@@ -1690,6 +1669,9 @@ static int vfswrap_ftruncate(vfs_handle_
 		return result;
 	}
 
+	if (lp_loose_allocate(SNUM(fsp->conn)) && !fsp->is_sparse)
+		goto done;
+
 	/* we used to just check HAVE_FTRUNCATE_EXTEND and only use
 	   ftruncate if the system supports it. Then I discovered that
 	   you can have some filesystems that support ftruncate
Index: samba-4.0.24/source3/param/loadparm.c
===================================================================
--- samba-4.0.24.orig/source3/param/loadparm.c
+++ samba-4.0.24/source3/param/loadparm.c
@@ -235,6 +235,7 @@ static struct loadparm_service sDefault
 	.bWidelinks = false,
 	.bSymlinks = true,
 	.bSyncAlways = false,
+	.bLooseAllocate = false,
 	.bStrictAllocate = false,
 	.bStrictSync = false,
 	.magic_char = '~',
Index: samba-4.0.24/source3/autoconf/lib/param/param_local.h
===================================================================
--- samba-4.0.24.orig/source3/autoconf/lib/param/param_local.h
+++ /dev/null
@@ -1,142 +0,0 @@
-#ifndef __AUTOCONF_LIB_PARAM_PARAM_LOCAL_H__
-#define __AUTOCONF_LIB_PARAM_PARAM_LOCAL_H__
-
-/* This file was automatically generated by mkparamdefs.pl. DO NOT EDIT */
-
-/**
- * This structure describes a single service.
- */
-struct loadparm_service 
-{
-	char *  szPath;
-	const char **  szHostsallow;
-	const char **  szHostsdeny;
-	char *  fstype;
-	const char **  ntvfs_handler;
-	bool   bMSDfsRoot;
-	bool   bBrowseable;
-	bool   bRead_only;
-	bool   bPrint_ok;
-	bool   bMap_hidden;
-	bool   bMap_archive;
-	bool   bOpLocks;
-	bool   bStrictSync;
-	bool   bMap_system;
-	int   iMaxConnections;
-	int   iCSCPolicy;
-	int   iCreate_mask;
-	int   iCreate_force_mode;
-	int   iDir_mask;
-	int   iDir_force_mode;
-	char *  szPreExec;
-	char *  szPostExec;
-	char *  szRootPreExec;
-	char *  szRootPostExec;
-	char *  szDontdescend;
-	char *  szUsername;
-	const char **  szInvalidUsers;
-	const char **  szValidUsers;
-	const char **  szAdminUsers;
-	char *  szPrintcommand;
-	char *  szLpqcommand;
-	char *  szLprmcommand;
-	char *  szLppausecommand;
-	char *  szLpresumecommand;
-	char *  szQueuepausecommand;
-	char *  szQueueresumecommand;
-	char *  szPrintername;
-	char *  szPrintjobUsername;
-	char *  szMagicScript;
-	char *  szMagicOutput;
-	char *  comment;
-	char *  force_user;
-	char *  force_group;
-	const char **  readlist;
-	const char **  writelist;
-	const char **  printer_admin;
-	const char **  szVfsObjects;
-	char *  szMSDfsProxy;
-	char *  volume;
-	char *  szVetoFiles;
-	char *  szHideFiles;
-	char *  szVetoOplockFiles;
-	char *  szAioWriteBehind;
-	char *  szDfree;
-	bool   autoloaded;
-	bool   bPreexecClose;
-	bool   bRootpreexecClose;
-	int   iCaseSensitive;
-	bool   bCasePreserve;
-	bool   bShortCasePreserve;
-	bool   bHideDotFiles;
-	bool   bHideSpecialFiles;
-	bool   bHideUnReadable;
-	bool   bHideUnWriteableFiles;
-	bool   bAccessBasedShareEnum;
-	bool   bNo_set_dir;
-	bool   bGuest_ok;
-	bool   bGuest_only;
-	bool   bAdministrative_share;
-	bool   bPrintNotifyBackchannel;
-	bool   bStoreDosAttributes;
-	bool   bDmapiSupport;
-	bool   bLocking;
-	int   iStrictLocking;
-	bool   bPosixLocking;
-	bool   bKernelOplocks;
-	bool   bLevel2OpLocks;
-	bool   bKernelShareModes;
-	bool   bOnlyUser;
-	bool   bMangledNames;
-	bool   bSymlinks;
-	bool   bSyncAlways;
-	bool   bStrictAllocate;
-	bool   bDeleteReadonly;
-	bool   bFakeOplocks;
-	bool   bDeleteVetoFiles;
-	bool   bDosFilemode;
-	bool   bDosFiletimes;
-	bool   bDosFiletimeResolution;
-	bool   bFakeDirCreateTimes;
-	bool   bBlockingLocks;
-	bool   bInheritPerms;
-	bool   bInheritACLS;
-	bool   bInheritOwner;
-	bool   bUseClientDriver;
-	bool   bDefaultDevmode;
-	bool   bForcePrintername;
-	bool   bNTAclSupport;
-	bool   bForceUnknownAclUser;
-	bool   bEASupport;
-	bool   bUseSendfile;
-	bool   bProfileAcls;
-	bool   bMap_acl_inherit;
-	bool   bAfs_Share;
-	bool   bAclCheckPermissions;
-	bool   bAclGroupControl;
-	bool   bAclMapFullControl;
-	bool   bAclAllowExecuteAlways;
-	int   iDefaultCase;
-	int   iMinPrintSpace;
-	int   iPrinting;
-	int   iMaxReportedPrintJobs;
-	int   iOplockContentionLimit;
-	int   iWriteCacheSize;
-	int   iBlock_size;
-	int   iDfreeCacheTime;
-	int   iallocation_roundup_size;
-	int   iAioReadSize;
-	int   iAioWriteSize;
-	int   iMap_readonly;
-	int   iDirectoryNameCacheSize;
-	int   ismb_encrypt;
-	char   magic_char;
-	char *  szCupsOptions;
-	bool   bChangeNotify;
-	bool   bKernelChangeNotify;
-	bool   bDurableHandles;
-LOADPARM_EXTRA_LOCALS
-};
-
-#endif /* __AUTOCONF_LIB_PARAM_PARAM_LOCAL_H__ */
-
