vol-lock-fd-type-20090323
authorJeffrey Altman <jaltman@secure-endpoints.com>
Mon, 23 Mar 2009 22:47:36 +0000 (22:47 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Mon, 23 Mar 2009 22:47:36 +0000 (22:47 +0000)
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.

src/vol/partition.c
src/vol/partition.h
src/vol/vol-salvage.c

index bf4fdff..26898ca 100644 (file)
@@ -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 */
 
index afdb8d1..a8206f0 100644 (file)
@@ -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
index 37a4057..91b3d33 100644 (file)
@@ -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);