From: Jeffrey Altman Date: Thu, 20 Jan 2011 07:15:18 +0000 (-0500) Subject: vol: fix CreateFile params nt_unlink and nt_open X-Git-Tag: openafs-devel-1_7_1~995 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=5fdc2679dc973fa45bf4b3bc7f21a527492868db vol: fix CreateFile params nt_unlink and nt_open 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 Tested-by: BuildBot Reviewed-by: Rod Widdowson Reviewed-by: Derrick Brashear --- diff --git a/src/vol/ntops.c b/src/vol/ntops.c index 47ae1d7..15cf555 100644 --- a/src/vol/ntops.c +++ b/src/vol/ntops.c @@ -46,20 +46,21 @@ * * 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;