Keep track of the sparse status of an open file handle. Allows bypass of
authorJeremy Allison <jra@samba.org>
Tue, 21 Dec 2010 01:58:33 +0000 (17:58 -0800)
committerJeremy Allison <jra@samba.org>
Tue, 21 Dec 2010 03:12:22 +0000 (04:12 +0100)
strict allocation on sparse files. Files opened as POSIX opens are always
sparse.

Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Tue Dec 21 04:12:22 CET 2010 on sn-devel-104

source3/include/smb.h
source3/modules/vfs_default.c
source3/smbd/dosmode.c
source3/smbd/fileio.c
source3/smbd/open.c

index 2b397cc307d568338f85c16c3effc5dc19dbbf20..8d12fb967d2d11308fd25108bf894827308a4975 100644 (file)
@@ -344,6 +344,7 @@ typedef struct files_struct {
        bool initial_delete_on_close; /* Only set at NTCreateX if file was created. */
        bool delete_on_close;
        bool posix_open;
+       bool is_sparse;
        struct smb_filename *fsp_name;
 
        struct vfs_fsp_data *vfs_extension;
index 54f38c3714b5ee99567be7a23510a70bc687b949..9cca3494137dafc456fb9e5f0b7dab289380954a 100644 (file)
@@ -895,7 +895,7 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_O
 
        START_PROFILE(syscall_ftruncate);
 
-       if (lp_strict_allocate(SNUM(fsp->conn))) {
+       if (lp_strict_allocate(SNUM(fsp->conn)) && !fsp->is_sparse) {
                result = strict_allocate_ftruncate(handle, fsp, len);
                END_PROFILE(syscall_ftruncate);
                return result;
index 2c6dcd00c6cd434805a107be943517a0ed732c02..cf95348583e1d7b26f0793845b8936a2ed8b30f6 100644 (file)
@@ -911,6 +911,8 @@ NTSTATUS file_set_sparse(connection_struct *conn,
                     FILE_NOTIFY_CHANGE_ATTRIBUTES,
                     fsp->fsp_name->base_name);
 
+       fsp->is_sparse = sparse;
+
        return NT_STATUS_OK;
 }
 
index aec6554436cfdbe8eacb3a07f161f1b97ca165b8..da40013bc5b0242623bddda56b7bb56b48f85b9d 100644 (file)
@@ -128,7 +128,8 @@ static ssize_t real_write_file(struct smb_request *req,
                 ret = vfs_write_data(req, fsp, data, n);
         } else {
                fsp->fh->pos = pos;
-               if (pos && lp_strict_allocate(SNUM(fsp->conn))) {
+               if (pos && lp_strict_allocate(SNUM(fsp->conn) &&
+                               !fsp->is_sparse)) {
                        if (vfs_fill_sparse(fsp, pos) == -1) {
                                return -1;
                        }
index 80756d6641f64020889ba2fb29da12812fb8e77a..32a08b5967cf31f8343f4b53f7b3a7bbda2b5088 100644 (file)
@@ -2221,6 +2221,15 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
                }
        }
 
+       /* Determine sparse flag. */
+       if (posix_open) {
+               /* POSIX opens are sparse by default. */
+               fsp->is_sparse = true;
+       } else {
+               fsp->is_sparse = (file_existed &&
+                       (existing_dos_attributes & FILE_ATTRIBUTE_SPARSE));
+       }
+
        /*
         * Take care of inherited ACLs on created files - if default ACL not
         * selected.