From cde1fb287cea83e55eff507d13e6d65a4a7970b7 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Mon, 23 Mar 2009 22:47:47 +0000 Subject: [PATCH] DEVEL15-vol-lock-fd-type-20090323 LICENSE IPL10 the lock_fd field of DiskPartition[64] is a file descriptor. On Windows this is a HANDLE and on *nix platforms an int. OpenAFS uses the FD_t type to provide platform specific type info for file descriptors. Use it for the lock_fd field and the salvageLock in ObtainsSalvageLock(). Finally, the on the wire diskPartition[64] struct in volser/volint.xg also contains a lock_fd field. This is an on the wire field and must be left at a fixed width of 32-bits. Since a file descriptor is not portable across machines we truncate the 64-bit HANDLE value to fit in the 32-bit lock_fd field when necessary. (cherry picked from commit a209012f1a3f83959f9df14ebad4aa2b50bacae0) --- src/vol/partition.c | 10 +++++----- src/vol/partition.h | 2 +- src/vol/vol-salvage.c | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/vol/partition.c b/src/vol/partition.c index bf4fdff05..26898caed 100644 --- a/src/vol/partition.c +++ b/src/vol/partition.c @@ -271,7 +271,7 @@ VInitPartition_r(char *path, char *devname, Device dev) strncpy(dp->devName, devname, strlen(devname) + 1); dp->device = dev; #endif - dp->lock_fd = -1; + dp->lock_fd = INVALID_FD; dp->flags = 0; dp->f_files = 1; /* just a default value */ #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV) @@ -1094,15 +1094,15 @@ VLockPartition_r(char *name) if (!dp) return; - if (dp->lock_fd == -1) { + if (dp->lock_fd == INVALID_FD) { char path[64]; int rc; (void)sprintf(path, "%s\\%s", VPartitionPath(dp), LOCKFILE); dp->lock_fd = - (int)CreateFile(path, GENERIC_WRITE, + (FD_t)CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); - assert(dp->lock_fd != (int)INVALID_HANDLE_VALUE); + assert(dp->lock_fd != INVALID_FD); memset((char *)&lap, 0, sizeof(lap)); rc = LockFileEx((HANDLE) dp->lock_fd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, @@ -1123,7 +1123,7 @@ VUnlockPartition_r(char *name) UnlockFileEx((HANDLE) dp->lock_fd, 0, 1, 0, &lap); CloseHandle((HANDLE) dp->lock_fd); - dp->lock_fd = -1; + dp->lock_fd = INVALID_FD; } #else /* AFS_NT40_ENV */ diff --git a/src/vol/partition.h b/src/vol/partition.h index afdb8d18a..a8206f0a6 100644 --- a/src/vol/partition.h +++ b/src/vol/partition.h @@ -57,7 +57,7 @@ struct DiskPartition64 { char *devName; /* Device mounted on */ Device device; /* device number */ afs_int32 index; /* partition index (0<=x<=VOLMAXPARTS) */ - int lock_fd; /* File descriptor of this partition if locked; otherwise -1; + FD_t lock_fd; /* File descriptor of this partition if locked; otherwise -1; * Not used by the file server */ afs_int64 free; /* Total number of blocks (1K) presumed * available on this partition (accounting diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 6aae12e45..d7bb864ea 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -336,13 +336,13 @@ childJob_t myjob = { SALVAGER_MAGIC, NOT_CHILD, "" }; void ObtainSalvageLock(void) { - int salvageLock; + FD_t salvageLock; #ifdef AFS_NT40_ENV salvageLock = - (int)CreateFile(AFSDIR_SERVER_SLVGLOCK_FILEPATH, 0, 0, NULL, + (FD_t)CreateFile(AFSDIR_SERVER_SLVGLOCK_FILEPATH, 0, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (salvageLock == (int)INVALID_HANDLE_VALUE) { + if (salvageLock == INVALID_FD) { fprintf(stderr, "salvager: There appears to be another salvager running! Aborted.\n"); Exit(1); @@ -790,7 +790,7 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) * modified to actually do that so that the NT crt can be used there. */ inodeFd = - _open_osfhandle((long)nt_open(inodeListPath, O_RDWR, 0), O_RDWR); + _open_osfhandle((intptr_t)nt_open(inodeListPath, O_RDWR, 0), O_RDWR); nt_unlink(inodeListPath); /* NT's crt unlink won't if file is open. */ #else inodeFd = afs_open(inodeListPath, O_RDONLY); -- 2.39.5