r6580: fixed the bug that caused the truncation of the main file on a stream
authorAndrew Tridgell <tridge@samba.org>
Mon, 2 May 2005 15:59:34 +0000 (15:59 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:27 +0000 (13:16 -0500)
open with openx and the 'truncate if exists' flag

source/ntvfs/posix/pvfs_open.c
source/ntvfs/posix/xattr_system.c

index e68670f7cc5d4076881dab265d3027611a5af207..4a2c8ea247cefd6670f11c3060c6d86e12663769 100644 (file)
@@ -856,7 +856,7 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs,
        uint32_t create_options;
        uint32_t share_access;
        uint32_t access_mask;
-       BOOL stream_existed;
+       BOOL stream_existed, stream_truncate=False;
 
        /* use the generic mapping code to avoid implementing all the
           different open calls. */
@@ -892,13 +892,16 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
+       flags = 0;
+
        switch (io->generic.in.open_disposition) {
        case NTCREATEX_DISP_SUPERSEDE:
-               flags = O_TRUNC;
-               break;
-
        case NTCREATEX_DISP_OVERWRITE_IF:
-               flags = O_TRUNC;
+               if (name->stream_name == NULL) {
+                       flags = O_TRUNC;
+               } else {
+                       stream_truncate = True;
+               }
                break;
 
        case NTCREATEX_DISP_OPEN:
@@ -912,7 +915,11 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs,
                if (!name->stream_exists) {
                        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
                }
-               flags = O_TRUNC;
+               if (name->stream_name == NULL) {
+                       flags = O_TRUNC;
+               } else {
+                       stream_truncate = True;
+               }
                break;
 
        case NTCREATEX_DISP_CREATE:
@@ -1075,6 +1082,13 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs,
                        talloc_free(lck);
                        return status;
                }
+               if (stream_truncate) {
+                       status = pvfs_stream_truncate(pvfs, f->handle->name, fd, 0);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               talloc_free(lck);
+                               return status;
+                       }
+               }
        }
 
        /* re-resolve the open fd */
index 3b8becf6fec87982477a37d362c46168f6f5d138..4101b69ed73320be9ab632b2c4345cfa89b3c0ed 100644 (file)
@@ -37,7 +37,7 @@ NTSTATUS pull_xattr_blob_system(struct pvfs_state *pvfs,
 #if HAVE_XATTR_SUPPORT
        int ret;
 
-       *blob = data_blob_talloc(mem_ctx, NULL, estimated_size);
+       *blob = data_blob_talloc(mem_ctx, NULL, estimated_size+16);
        if (blob->data == NULL) {
                return NT_STATUS_NO_MEMORY;
        }