From b4f321f207f710bd62be53f653f45439e94992e0 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Fri, 23 Mar 2012 13:02:22 -0500 Subject: [PATCH] namei: Abstract out OGM functions a bit more Add GetWinOGM and SetWinOGM for getting and setting the Windows-equivalent of the Unix OGM data. Make those and CheckOGM use GetFileTime/SetFileTime so we can operate just via an FD_t, without needing the full pathname. Modify the NT namei_icreate to use SetWinOGM. Reviewed-on: http://gerrit.openafs.org/6945 Reviewed-by: Jeffrey Altman Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear (cherry picked from commit 0594fc80b48152b4b03edda7e19133b59fc0670e) Change-Id: I65491a9a82911d9c99d6238a4ea66ed400db7aa0 Reviewed-on: http://gerrit.openafs.org/9281 Reviewed-by: Derrick Brashear Reviewed-by: Andrew Deason Reviewed-by: Mark Vitale Reviewed-by: Stephan Wiesand Tested-by: BuildBot --- src/vol/namei_ops.c | 75 ++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index 9095c96a8..3b7dd9597 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -669,24 +669,49 @@ SetOGM(FD_t fd, int parm, int tag) } static int -CheckOGM(namei_t *name, FdHandle_t *fdP, int p1) +SetWinOGM(FD_t fd, int p1, int p2) { - WIN32_FIND_DATA info; - HANDLE dirH; + BOOL code; + FILETIME ftime; - dirH = - FindFirstFileEx(name->n_path, FindExInfoStandard, &info, - FindExSearchNameMatch, NULL, - FIND_FIRST_EX_CASE_SENSITIVE); + ftime.dwHighDateTime = p1; + ftime.dwLowDateTime = p2; - if (!dirH) - return -1; /* Can't get info, leave alone */ + code = SetFileTime(fd, &ftime, NULL /*access*/, NULL /*write*/); + if (!code) + return -1; + return 0; +} - FindClose(dirH); +static int +GetWinOGM(FD_t fd, int *p1, int *p2) +{ + BOOL code; + FILETIME ftime; - if (info.ftCreationTime.dwHighDateTime != (unsigned int)p1) + code = GetFileTime(fd, &ftime, NULL /*access*/, NULL /*write*/); + if (!code) return -1; + *p1 = ftime.dwHighDateTime; + *p2 = ftime.dwLowDateTime; + + return 0; +} + +static int +CheckOGM(FdHandle_t *fdP, int p1) +{ + int ogm_p1, ogm_p2; + + if (GetWinOGM(fdP->fd_fd, &ogm_p1, &ogm_p2)) { + return -1; + } + + if (ogm_p1 != p1) { + return -1; + } + return 0; } #else /* AFS_NT40_ENV */ @@ -723,14 +748,22 @@ GetOGMFromStat(struct afs_stat *status, int *parm, int *tag) } static int -CheckOGM(namei_t *name, FdHandle_t *fdP, int p1) +GetOGM(FdHandle_t *fdP, int *parm, int *tag) { struct afs_stat status; - int parm, tag; if (afs_fstat(fdP->fd_fd, &status) < 0) return -1; + GetOGMFromStat(&status, parm, tag); + return 0; +} - GetOGMFromStat(&status, &parm, &tag); +static int +CheckOGM(FdHandle_t *fdP, int p1) +{ + int parm, tag; + + if (GetOGM(fdP, &parm, &tag) < 0) + return -1; if (parm != p1) return -1; @@ -755,7 +788,7 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint FdHandle_t *fdP; FdHandle_t tfd; int type, tag; - FILETIME ftime; + int ogm_p1, ogm_p2; char *p; b32_string_t str1; @@ -775,8 +808,8 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint * p3 - type * p4 - parent volume id */ - ftime.dwHighDateTime = p1; - ftime.dwLowDateTime = p2; + ogm_p1 = p1; + ogm_p2 = p2; type = p3; tmp.ih_vid = p4; /* Use parent volume id, where this file will be. */ tmp.ih_ino = namei_MakeSpecIno(p1, p3); @@ -797,8 +830,8 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint tmp.ih_vid = p1; tmp.ih_ino = (Inode) p2; - ftime.dwHighDateTime = p3; - ftime.dwLowDateTime = p4; + ogm_p1 = p3; + ogm_p2 = p4; } namei_HandleToName(&name, &tmp); @@ -827,7 +860,7 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint tmp.ih_ino |= (((Inode) tag) << NAMEI_TAGSHIFT); if (!code) { - if (!SetFileTime((HANDLE) fd, &ftime, NULL, NULL)) { + if (SetWinOGM(fd, ogm_p1, ogm_p2)) { errno = OS_ERROR(EBADF); code = -1; } @@ -1028,7 +1061,7 @@ namei_dec(IHandle_t * ih, Inode ino, int p1) return -1; } - if (CheckOGM(&name, fdP, p1) < 0) { + if (CheckOGM(fdP, p1) < 0) { FDH_REALLYCLOSE(fdP); IH_RELEASE(tmp); errno = OS_ERROR(EINVAL); -- 2.39.5