vol: fix CreateFile params nt_unlink and nt_open
authorJeffrey Altman <jaltman@your-file-system.com>
Thu, 20 Jan 2011 07:15:18 +0000 (02:15 -0500)
committerDerrick Brashear <shadow@dementia.org>
Sat, 22 Jan 2011 20:44:36 +0000 (12:44 -0800)
nt_unlink: when opening a file handle to assign delete on close
status the caller must request DELETE permission.

nt_open: make sure that DELETE permission along with FILE_SHARE_DELETE
is requested if we wish to permit another CreateFile call in the future
to assign delete on close.

Change-Id: Ib971ecc098dbc5eb64dcbfed93c334397c9d8ac9
Reviewed-on: http://gerrit.openafs.org/3711
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Rod Widdowson <rdw@steadingsoftware.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/vol/ntops.c

index 47ae1d7..15cf555 100644 (file)
  *
  * This nt_unlink has the delete on last close semantics of the Unix unlink
  * with a minor twist. Subsequent CreateFile calls on this file can succeed
- * if they open for delete. It's also unclear what happens if a CreateFile
- * call tries to create a new file with the same name. Fortunately, neither
- * case should occur as part of nt_dec.
+ * if they open for delete. If a CreateFile call tries to create a new file
+ * with the same name it will fail. Fortunately, neither case should occur
+ * as part of nt_dec.
  */
 int
 nt_unlink(char *name)
 {
     HANDLE fh;
 
-    fh = CreateFile(name, GENERIC_READ | GENERIC_WRITE,
+    fh = CreateFile(name,
+                    GENERIC_READ | GENERIC_WRITE | DELETE,
                    FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
                    NULL, OPEN_EXISTING,
-                   BASEFILEATTRIBUTE | FILE_FLAG_DELETE_ON_CLOSE |
-                   FILE_FLAG_POSIX_SEMANTICS, NULL);
+                   BASEFILEATTRIBUTE | FILE_FLAG_DELETE_ON_CLOSE | FILE_FLAG_POSIX_SEMANTICS,
+                    NULL);
     if (fh != INVALID_HANDLE_VALUE)
        CloseHandle(fh);
     else {
@@ -79,14 +80,16 @@ nt_open(char *name, int flags, int mode)
 {
     HANDLE fh;
     DWORD nt_access = 0;
-    DWORD nt_share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+    DWORD nt_share = FILE_SHARE_READ;
     DWORD nt_create = 0;
     /* Really use the sequential one for data files, random for meta data. */
     DWORD FandA = BASEFILEATTRIBUTE | FILE_FLAG_SEQUENTIAL_SCAN;
 
     /* set access */
-    if ((flags & O_RDWR) || (flags & O_WRONLY))
+    if ((flags & O_RDWR) || (flags & O_WRONLY)) {
        nt_access |= GENERIC_WRITE;
+        nt_share  |= FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+    }
     if ((flags & O_RDWR) || (flags == O_RDONLY))
        nt_access |= GENERIC_READ;