]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
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>
Tue, 8 Feb 2011 06:22:02 +0000 (22:22 -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.

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>
(cherry picked from commit 5fdc2679dc973fa45bf4b3bc7f21a527492868db)

Change-Id: I63855a65c5e209dc7b601e5b5b67ccb21bfb653c
Reviewed-on: http://gerrit.openafs.org/3856
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
src/vol/ntops.c

index 4155e13672b1efc6f149aaa22f431e3c3c1fb237..18a847ccb36425e437e115661ad6ebcc72112a60 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 {
@@ -78,14 +79,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;