Remove DUX/OSF code
[openafs.git] / src / vol / partition.c
index b874a21..215e935 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
 #include <ctype.h>
-#include <string.h>
+
 #ifdef AFS_NT40_ENV
 #include <windows.h>
 #include <winbase.h>
 #include <winioctl.h>
 #else
-#include <sys/param.h>
-#include <sys/types.h>
-#include <unistd.h>
 
 #if AFS_HAVE_STATVFS || AFS_HAVE_STATVFS64
 #include <sys/statvfs.h>
 #endif
 
 #if !defined(AFS_SGI_ENV)
-#ifdef AFS_OSF_ENV
-#include <sys/mount.h>
-#include <ufs/fs.h>
-#else /* AFS_OSF_ENV */
 #ifdef AFS_VFSINCL_ENV
 #define VFS
 #ifdef AFS_SUN5_ENV
 #include <sys/fs.h>
 #endif
 #endif /* AFS_VFSINCL_ENV */
-#endif /* AFS_OSF_ENV */
-#include <errno.h>
-#include <sys/stat.h>
-#include <stdio.h>
 #include <sys/file.h>
 #ifdef AFS_AIX_ENV
 #include <sys/vfs.h>
@@ -73,8 +63,6 @@
 #else
 #ifdef AFS_HPUX_ENV
 #include <sys/vfs.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <checklist.h>
 #else
 #if    defined(AFS_SUN_ENV)
@@ -84,7 +72,6 @@
 #endif
 #endif
 #ifdef AFS_SUN5_ENV
-#include <unistd.h>
 #include <sys/mnttab.h>
 #include <sys/mntent.h>
 #else
 #endif /* AFS_SGI_ENV */
 #endif /* AFS_NT40_ENV */
 #if defined(AFS_SGI_ENV)
-#include <sys/errno.h>
-#include <sys/stat.h>
-#include <stdio.h>
 #include <sys/file.h>
 #include <mntent.h>
 #endif
 
-#include <rx/xdr.h>
+#include <afs/opr.h>
+#ifdef AFS_PTHREAD_ENV
+# include <opr/lock.h>
+#endif
 #include <afs/afsint.h>
+#include <rx/rx_queue.h>
 #include "nfs.h"
 #include <afs/errors.h>
 #include "lock.h"
 #include "lwp.h"
 #include <afs/afssyscalls.h>
 #include "ihandle.h"
+#include "common.h"
 #ifdef AFS_NAMEI_ENV
 #ifdef AFS_NT40_ENV
 #include "ntops.h"
 #else
 #include "namei_ops.h"
-#include <dirent.h>
 #endif /* AFS_NT40_ENV */
 #endif /* AFS_NAMEI_ENV */
 #include "vnode.h"
 #include "volume.h"
 #include "partition.h"
-#ifdef AFS_PTHREAD_ENV
-#include <assert.h>
-#else /* AFS_PTHREAD_ENV */
-#include <afs/assert.h>
-#endif /* AFS_PTHREAD_ENV */
 
 #if defined(AFS_HPUX_ENV)
-#include <sys/types.h>
 #include <sys/privgrp.h>
 #endif /* defined(AFS_HPUX_ENV) */
 
 #include <jfs/filsys.h>
 #endif
 
-#ifdef O_LARGEFILE
-
-#define afs_stat       stat64
-#define afs_open       open64
-#define afs_fopen      fopen64
-#ifndef AFS_NT40_ENV
-#if AFS_HAVE_STATVFS64
-# define afs_statvfs   statvfs64
-#else
-# if AFS_HAVE_STATFS64
-#  define afs_statfs   statfs64
-#else
-#  if AFS_HAVE_STATVFS
-#   define afs_statvfs statvfs
-#  else
-#   define afs_statfs  statfs
-#  endif /* !AFS_HAVE_STATVFS */
-# endif        /* !AFS_HAVE_STATFS64 */
-#endif /* !AFS_HAVE_STATVFS64 */
-#endif /* !AFS_NT40_ENV */
-
-#else /* !O_LARGEFILE */
-
-#define afs_stat       stat
-#define afs_open       open
-#define afs_fopen      fopen
-#ifndef AFS_NT40_ENV
-#if AFS_HAVE_STATVFS
-#define afs_statvfs    statvfs
-#else /* !AFS_HAVE_STATVFS */
-#define afs_statfs     statfs
-#endif /* !AFS_HAVE_STATVFS */
-#endif /* !AFS_NT40_ENV */
-
-#endif /* !O_LARGEFILE */
-
-/*@printflike@*/ extern void Log(const char *format, ...);
+#ifdef AFS_NT40_ENV
+extern int VValidVPTEntry(struct vptab *vptp);
+#endif
 
 int aixlow_water = 8;          /* default 8% */
 struct DiskPartition64 *DiskPartitionList;
@@ -234,9 +182,9 @@ VerifyXFSInodeSize(char *part, char *fstype)
 int
 VInitPartitionPackage(void)
 {
-#ifdef AFS_DEMAND_ATTACH_ENV
+#ifdef AFS_DEMAND_ATTACH_FS
     memset(&DiskPartitionTable, 0, sizeof(DiskPartitionTable));
-#endif /* AFS_DEMAND_ATTACH_ENV */
+#endif /* AFS_DEMAND_ATTACH_FS */
     return 0;
 }
 
@@ -245,7 +193,7 @@ VInitPartition_r(char *path, char *devname, Device dev)
 {
     struct DiskPartition64 *dp, *op;
 
-    dp = (struct DiskPartition64 *)malloc(sizeof(struct DiskPartition64));
+    dp = malloc(sizeof(struct DiskPartition64));
     /* Add it to the end, to preserve order when we print statistics */
     for (op = DiskPartitionList; op; op = op->next) {
        if (!op->next)
@@ -256,22 +204,20 @@ VInitPartition_r(char *path, char *devname, Device dev)
     else
        DiskPartitionList = dp;
     dp->next = 0;
-    dp->name = (char *)malloc(strlen(path) + 1);
-    strncpy(dp->name, path, strlen(path) + 1);
+    dp->name = strdup(path);
     dp->index = volutil_GetPartitionID(path);
 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
     /* Create a lockfile for the partition, of the form /vicepa/Lock/vicepa */
-    dp->devName = (char *)malloc(2 * strlen(path) + 6);
+    dp->devName = malloc(2 * strlen(path) + 6);
     strcpy(dp->devName, path);
-    strcat(dp->devName, "/");
+    strcat(dp->devName, OS_DIRSEP);
     strcat(dp->devName, "Lock");
     mkdir(dp->devName, 0700);
     strcat(dp->devName, path);
     close(afs_open(dp->devName, O_RDWR | O_CREAT, 0600));
     dp->device = dp->index;
 #else
-    dp->devName = (char *)malloc(strlen(devname) + 1);
-    strncpy(dp->devName, devname, strlen(devname) + 1);
+    dp->devName = strdup(devname);
     dp->device = dev;
 #endif
     dp->lock_fd = INVALID_FD;
@@ -285,16 +231,16 @@ VInitPartition_r(char *path, char *devname, Device dev)
 #ifdef AFS_DEMAND_ATTACH_FS
     AddPartitionToTable_r(dp);
     queue_Init(&dp->vol_list.head);
-    assert(pthread_cond_init(&dp->vol_list.cv, NULL) == 0);
+    CV_INIT(&dp->vol_list.cv, "vol list", CV_DEFAULT, 0);
     dp->vol_list.len = 0;
     dp->vol_list.busy = 0;
     {
        char lockpath[MAXPATHLEN+1];
-       afs_snprintf(lockpath, MAXPATHLEN, "%s/" AFS_PARTLOCK_FILE, dp->name);
+       snprintf(lockpath, MAXPATHLEN, "%s/" AFS_PARTLOCK_FILE, dp->name);
        lockpath[MAXPATHLEN] = '\0';
        VLockFileInit(&dp->headerLockFile, lockpath);
 
-       afs_snprintf(lockpath, MAXPATHLEN, "%s/" AFS_VOLUMELOCK_FILE, dp->name);
+       snprintf(lockpath, MAXPATHLEN, "%s/" AFS_VOLUMELOCK_FILE, dp->name);
        lockpath[MAXPATHLEN] = '\0';
        VLockFileInit(&dp->volLockFile, lockpath);
     }
@@ -325,10 +271,10 @@ VInitPartition(char *path, char *devname, Device dev)
  *
  * Use partition name as devname.
  */
-int
-VCheckPartition(char *part, char *devname)
+static int
+VCheckPartition(char *part, char *devname, int logging)
 {
-    struct afs_stat status;
+    struct afs_stat_st status;
 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_NT40_ENV)
     char AFSIDatPath[MAXPATHLEN];
 #endif
@@ -338,10 +284,23 @@ VCheckPartition(char *part, char *devname)
     if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
        return 0;
     }
+    if (volutil_GetPartitionID(part) == -1) {
+       Log("Warning: %s is a bad partition name; ignored.\n", part);
+       return 0;
+    }
     if (afs_stat(part, &status) < 0) {
        Log("VInitVnodes: Couldn't find file system %s; ignored\n", part);
        return 0;
     }
+    if (logging) {
+       Log("This program is compiled without AFS_NAMEI_ENV, and "
+           "partition %s is mounted with the 'logging' option. "
+           "Using the inode fileserver backend with 'logging' UFS "
+           "partitions causes volume corruption, so please either "
+           "mount the partition without logging, or use the namei "
+           "fileserver backend. Aborting...\n", part);
+       return -1;
+    }
 #ifndef AFS_AIX32_ENV
     if (programType == fileServer) {
        char salvpath[MAXPATHLEN];
@@ -363,7 +322,7 @@ VCheckPartition(char *part, char *devname)
        struct dirent *dp;
 
        dirp = opendir(part);
-       assert(dirp);
+       opr_Assert(dirp);
        while ((dp = readdir(dirp))) {
            if (dp->d_name[0] == 'V') {
                Log("This program is compiled with AFS_NAMEI_ENV, but partition %s seems to contain volumes which don't use the namei-interface; aborting\n", part);
@@ -386,13 +345,6 @@ VCheckPartition(char *part, char *devname)
 #endif /* AFS_NAMEI_ENV */
 #endif /* !AFS_LINUX20_ENV && !AFS_NT40_ENV */
 
-#if defined(AFS_DUX40_ENV) && !defined(AFS_NAMEI_ENV)
-    if (status.st_ino != ROOTINO) {
-       Log("%s is not a mounted file system; ignored.\n", part);
-       return 0;
-    }
-#endif
-
     VInitPartition(part, devname, status.st_dev);
 
     return 0;
@@ -402,20 +354,36 @@ VCheckPartition(char *part, char *devname)
  * attached (return value 1), or only attached when it is a separately
  * mounted partition (return value 0).  For non-NAMEI environments, it
  * always returns 0.
+ *
+ * *awouldattach will be set to 1 if the given path at least looks like a vice
+ * partition (that is, if we return 0, the only thing preventing this partition
+ * from being attached is the existence of the AlwaysAttach file), or to 0
+ * otherwise. *awouldattach is set regardless of whether or not the partition
+ * should always be attached or not.
  */
 static int
-VIsAlwaysAttach(char *part)
+VIsAlwaysAttach(char *part, int *awouldattach)
 {
 #ifdef AFS_NAMEI_ENV
-    struct afs_stat st;
+    struct afs_stat_st st;
     char checkfile[256];
     int ret;
+#endif /* AFS_NAMEI_ENV */
 
+    if (awouldattach) {
+       *awouldattach = 0;
+    }
+
+#ifdef AFS_NAMEI_ENV
     if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE))
        return 0;
 
+    if (awouldattach) {
+       *awouldattach = 1;
+    }
+
     strncpy(checkfile, part, 100);
-    strcat(checkfile, "/");
+    strcat(checkfile, OS_DIRSEP);
     strcat(checkfile, VICE_ALWAYSATTACH_FILE);
 
     ret = afs_stat(checkfile, &st);
@@ -425,29 +393,75 @@ VIsAlwaysAttach(char *part)
 #endif /* AFS_NAMEI_ENV */
 }
 
+/* VIsNeverAttach() checks whether a /vicepX directory should never be
+ * attached (return value 1), or follow the normal mounting logic. The
+ * Always Attach flag may override the NeverAttach flag.
+ */
+static int
+VIsNeverAttach(char *part)
+{
+    struct afs_stat_st st;
+    char checkfile[256];
+    int ret;
+
+    if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE))
+       return 0;
+
+    strncpy(checkfile, part, 100);
+    strcat(checkfile, OS_DIRSEP);
+    strcat(checkfile, VICE_NEVERATTACH_FILE);
+
+    ret = afs_stat(checkfile, &st);
+    return (ret < 0) ? 0 : 1;
+}
+
 /* VAttachPartitions2() looks for and attaches /vicepX partitions
  * where a special file (VICE_ALWAYSATTACH_FILE) exists.  This is
  * used to attach /vicepX directories which aren't on dedicated
  * partitions, in the NAMEI fileserver.
  */
-void
+static void
 VAttachPartitions2(void)
 {
 #ifdef AFS_NAMEI_ENV
     DIR *dirp;
     struct dirent *de;
     char pname[32];
+    int wouldattach;
 
-    dirp = opendir("/");
+    dirp = opendir(OS_DIRSEP);
     while ((de = readdir(dirp))) {
-       strcpy(pname, "/");
+       strcpy(pname, OS_DIRSEP);
        strncat(pname, de->d_name, 20);
        pname[sizeof(pname) - 1] = '\0';
 
        /* Only keep track of "/vicepx" partitions since automounter
         * may hose us */
-       if (VIsAlwaysAttach(pname))
-           VCheckPartition(pname, "");
+       if (VIsAlwaysAttach(pname, &wouldattach)) {
+           VCheckPartition(pname, "", 0);
+       } else {
+           struct afs_stat_st st;
+           if (wouldattach && VGetPartition(pname, 0) == NULL &&
+               afs_stat(pname, &st) == 0 && S_ISDIR(st.st_mode)) {
+
+               /* This is a /vicep* dir, and it has not been attached as a
+                * partition. This probably means that this is a /vicep* dir
+                * that is not a separate partition, so just give a notice so
+                * admins are not confused as to why their /vicep* dirs are not
+                * being attached.
+                *
+                * It is possible that the dir _is_ a separate partition and we
+                * failed to attach it earlier, making this message a bit
+                * confusing. But that should be rare, and an error message
+                * about the failure will already be logged right before this,
+                * so it should be clear enough. */
+
+               Log("VAttachPartitions: not attaching %s; either it is not a "
+                   "separate partition, or it failed to attach (create the "
+                   "file %s/" VICE_ALWAYSATTACH_FILE " to force attachment)\n",
+                   pname, pname);
+           }
+       }
     }
     closedir(dirp);
 #endif /* AFS_NAMEI_ENV */
@@ -468,6 +482,7 @@ VAttachPartitions(void)
        exit(-1);
     }
     while (!getmntent(mntfile, &mnt)) {
+       int logging = 0;
        /* Ignore non ufs or non read/write partitions */
        /* but allow zfs too if we're in the NAMEI environment */
        if (
@@ -479,24 +494,22 @@ VAttachPartitions(void)
 #endif
            || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
            continue;
-       
+
+       /* Skip this Partition? */
+       if (VIsNeverAttach(mnt.mnt_mountp))
+           continue;
+
        /* If we're going to always attach this partition, do it later. */
-       if (VIsAlwaysAttach(mnt.mnt_mountp))
+       if (VIsAlwaysAttach(mnt.mnt_mountp, NULL))
            continue;
 
 #ifndef AFS_NAMEI_ENV
        if (hasmntopt(&mnt, "logging") != NULL) {
-           Log("This program is compiled without AFS_NAMEI_ENV, and "
-               "partition %s is mounted with the 'logging' option. "
-               "Using the inode fileserver backend with 'logging' UFS "
-               "partitions causes volume corruption, so please either "
-               "mount the partition without logging, or use the namei "
-               "fileserver backend. Aborting...\n", mnt.mnt_mountp);
-           errors++;
+           logging = 1;
        }
 #endif /* !AFS_NAMEI_ENV */
 
-       if (VCheckPartition(mnt.mnt_mountp, mnt.mnt_special) < 0)
+       if (VCheckPartition(mnt.mnt_mountp, mnt.mnt_special, logging) < 0)
            errors++;
     }
 
@@ -525,11 +538,15 @@ VAttachPartitions(void)
        if (!hasmntopt(mntent, MNTOPT_RW))
            continue;
 
+       /* Skip this Partition? */
+       if (VIsNeverAttach(mntent->mnt_dir))
+           continue;
+
        /* If we're going to always attach this partition, do it later. */
-       if (VIsAlwaysAttach(mntent->mnt_dir))
+       if (VIsAlwaysAttach(mntent->mnt_dir, NULL))
            continue;
 
-       if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname) < 0)
+       if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname, 0) < 0)
            errors++;
     }
 
@@ -546,10 +563,10 @@ VAttachPartitions(void)
  * (This function was grabbed from df.c)
  */
 int
-getmount(register struct vmount **vmountpp)
+getmount(struct vmount **vmountpp)
 {
     int size;
-    register struct vmount *vm;
+    struct vmount *vm;
     int nmounts;
 
     /* set initial size of mntctl buffer to a MAGIC NUMBER */
@@ -557,7 +574,7 @@ getmount(register struct vmount **vmountpp)
 
     /* try the operation until ok or a fatal error */
     while (1) {
-       if ((vm = (struct vmount *)malloc(size)) == NULL) {
+       if ((vm = malloc(size)) == NULL) {
            /* failed getting memory for mount status buf */
            perror("FATAL ERROR: get_stat malloc failed\n");
            exit(-1);
@@ -628,11 +645,15 @@ VAttachPartitions(void)
 #endif
 #endif
 
+       /* Skip this Partition? */
+       if (VIsNeverAttach(part))
+           continue;
+
        /* If we're going to always attach this partition, do it later. */
-       if (VIsAlwaysAttach(part))
+       if (VIsAlwaysAttach(part, NULL))
            continue;
 
-       if (VCheckPartition(part, vmt2dataptr(vmountp, VMT_OBJECT)) < 0)
+       if (VCheckPartition(part, vmt2dataptr(vmountp, VMT_OBJECT), 0) < 0)
            errors++;
     }
 
@@ -642,7 +663,7 @@ VAttachPartitions(void)
     return errors;
 }
 #endif
-#if defined(AFS_DUX40_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 int
 VAttachPartitions(void)
 {
@@ -658,11 +679,15 @@ VAttachPartitions(void)
        if (strcmp(fsent->fs_type, "rw") != 0)
            continue;
 
+       /* Skip this Partition? */
+       if (VIsNeverAttach(fsent->fs_file))
+           continue;
+
        /* If we're going to always attach this partition, do it later. */
-       if (VIsAlwaysAttach(fsent->fs_file))
+       if (VIsAlwaysAttach(fsent->fs_file, NULL))
            continue;
 
-       if (VCheckPartition(fsent->fs_file, fsent->fs_spec) < 0)
+       if (VCheckPartition(fsent->fs_file, fsent->fs_spec, 0) < 0)
            errors++;
     }
     endfsent();
@@ -675,8 +700,6 @@ VAttachPartitions(void)
 #endif
 
 #ifdef AFS_NT40_ENV
-#include <string.h>
-#include <sys/stat.h>
 /* VValidVPTEntry
  *
  * validate names in vptab.
@@ -686,7 +709,7 @@ VAttachPartitions(void)
  * 0 invalid entry
  */
 
-int
+static int
 VValidVPTEntry(struct vptab *vpe)
 {
     int len = strlen(vpe->vp_name);
@@ -725,7 +748,7 @@ VValidVPTEntry(struct vptab *vpe)
     return 1;
 }
 
-int
+static int
 VCheckPartition(char *partName)
 {
     char volRoot[4];
@@ -796,7 +819,7 @@ VAttachPartitions(void)
         * doing this for us.
         */
        if (programType == fileServer) {
-           struct afs_stat status;
+           struct afs_stat_st status;
            char salvpath[MAXPATHLEN];
            strcpy(salvpath, entry.vp_dev);
            strcat(salvpath, "\\FORCESALVAGE");
@@ -842,11 +865,15 @@ VAttachPartitions(void)
        }
     }
     while ((mntent = getmntent(mfd))) {
+       /* Skip this Partition? */
+       if (VIsNeverAttach(mntent->mnt_dir))
+           continue;
+
        /* If we're going to always attach this partition, do it later. */
-       if (VIsAlwaysAttach(mntent->mnt_dir))
+       if (VIsAlwaysAttach(mntent->mnt_dir, NULL))
            continue;
 
-       if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname) < 0)
+       if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname, 0) < 0)
            errors++;
     }
     endmntent(mfd);
@@ -875,7 +902,7 @@ VPartitionPath(struct DiskPartition64 *part)
 struct DiskPartition64 *
 VGetPartition_r(char *name, int abortp)
 {
-    register struct DiskPartition64 *dp;
+    struct DiskPartition64 *dp;
 #ifdef AFS_DEMAND_ATTACH_FS
     dp = VLookupPartition_r(name);
 #else /* AFS_DEMAND_ATTACH_FS */
@@ -885,7 +912,7 @@ VGetPartition_r(char *name, int abortp)
     }
 #endif /* AFS_DEMAND_ATTACH_FS */
     if (abortp)
-       assert(dp != NULL);
+       opr_Assert(dp != NULL);
     return dp;
 }
 
@@ -901,7 +928,7 @@ VGetPartition(char *name, int abortp)
 
 #ifdef AFS_NT40_ENV
 void
-VSetPartitionDiskUsage_r(register struct DiskPartition64 *dp)
+VSetPartitionDiskUsage_r(struct DiskPartition64 *dp)
 {
     ULARGE_INTEGER free_user, total, free_total;
     int ufree, tot, tfree;
@@ -925,7 +952,7 @@ VSetPartitionDiskUsage_r(register struct DiskPartition64 *dp)
 
 #else
 void
-VSetPartitionDiskUsage_r(register struct DiskPartition64 *dp)
+VSetPartitionDiskUsage_r(struct DiskPartition64 *dp)
 {
     int bsize, code;
     afs_int64 totalblks, free, used, availblks;
@@ -991,7 +1018,7 @@ VSetPartitionDiskUsage_r(register struct DiskPartition64 *dp)
 #endif /* AFS_NT40_ENV */
 
 void
-VSetPartitionDiskUsage(register struct DiskPartition64 *dp)
+VSetPartitionDiskUsage(struct DiskPartition64 *dp)
 {
     VOL_LOCK;
     VSetPartitionDiskUsage_r(dp);
@@ -1092,12 +1119,17 @@ VPrintDiskStats_r(void)
 {
     struct DiskPartition64 *dp;
     for (dp = DiskPartitionList; dp; dp = dp->next) {
-       Log("Partition %s: %d available 1K blocks (minfree=%d), ", dp->name,
-           dp->totalUsable, dp->minFree);
-       if (dp->free < 0)
-           Log("overallocated by %d blocks\n", -dp->free);
-       else
-           Log("%d free blocks\n", dp->free);
+       if (dp->free < 0) {
+           Log("Partition %s: %lld "
+               " available 1K blocks (minfree=%lld), "
+               "overallocated by %lld blocks\n", dp->name,
+               dp->totalUsable, dp->minFree, -dp->free);
+       } else {
+           Log("Partition %s: %lld"
+               " available 1K blocks (minfree=%lld), "
+               "%lld free blocks\n", dp->name,
+               dp->totalUsable, dp->minFree, dp->free);
+       }
     }
 }
 
@@ -1128,19 +1160,19 @@ VLockPartition_r(char *name)
            (FD_t)CreateFile(path, GENERIC_WRITE,
                            FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                            CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL);
-       assert(dp->lock_fd != INVALID_FD);
+       opr_Assert(dp->lock_fd != INVALID_FD);
 
        memset(&lap, 0, sizeof(lap));
        rc = LockFileEx((HANDLE) dp->lock_fd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1,
                        0, &lap);
-       assert(rc);
+       opr_Assert(rc);
     }
 }
 
 void
 VUnlockPartition_r(char *name)
 {
-    register struct DiskPartition64 *dp = VGetPartition_r(name, 0);
+    struct DiskPartition64 *dp = VGetPartition_r(name, 0);
     OVERLAPPED lap;
 
     if (!dp)
@@ -1163,7 +1195,7 @@ VUnlockPartition_r(char *name)
 void
 VLockPartition_r(char *name)
 {
-    register struct DiskPartition64 *dp = VGetPartition_r(name, 0);
+    struct DiskPartition64 *dp = VGetPartition_r(name, 0);
     char *partitionName;
     int retries, code;
     struct timeval pausing;
@@ -1187,7 +1219,7 @@ VLockPartition_r(char *name)
 
     if (!dp)
        return;                 /* no partition, will fail later */
-    if (dp->lock_fd != -1)
+    if (dp->lock_fd != INVALID_FD)
        return;
 
 #if    defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
@@ -1205,8 +1237,12 @@ VLockPartition_r(char *name)
 #endif
 
     for (retries = 25; retries; retries--) {
-       dp->lock_fd = afs_open(partitionName, code);
-       if (dp->lock_fd != -1)
+       if (code & O_CREAT)
+           dp->lock_fd = afs_open(partitionName, code, 0644);
+       else
+           dp->lock_fd = afs_open(partitionName, code);
+
+       if (dp->lock_fd != INVALID_FD)
            break;
        if (errno == ENOENT)
            code |= O_CREAT;
@@ -1214,11 +1250,11 @@ VLockPartition_r(char *name)
        pausing.tv_usec = 500000;
        select(0, NULL, NULL, NULL, &pausing);
     }
-    assert(retries != 0);
+    opr_Assert(retries != 0);
 
 #if defined (AFS_HPUX_ENV)
 
-    assert(getprivgrp(privGrpList) == 0);
+    opr_Verify(getprivgrp(privGrpList) == 0);
 
     /*
      * In general, it will difficult and time-consuming ,if not impossible,
@@ -1239,26 +1275,26 @@ VLockPartition_r(char *name)
     if (((*globalMask) & privmask(PRIV_LOCKRDONLY)) == 0) {
        /* allow everybody to set a lock on a read-only file descriptor */
        (*globalMask) |= privmask(PRIV_LOCKRDONLY);
-       assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask)
-              == 0);
+       opr_Verify(setprivgrp(PRIV_GLOBAL,
+                             privGrpList[globalMaskIndex].priv_mask) == 0);
 
        lockfRtn = lockf(dp->lock_fd, F_LOCK, 0);
 
        /* remove the privilege granted to everybody to lock a read-only fd */
        (*globalMask) &= ~(privmask(PRIV_LOCKRDONLY));
-       assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask)
-              == 0);
+       opr_Verify(setprivgrp(PRIV_GLOBAL,
+                             privGrpList[globalMaskIndex].priv_mask) == 0);
     } else {
        /* in this case, we should be able to do this with impunity, anyway */
        lockfRtn = lockf(dp->lock_fd, F_LOCK, 0);
     }
 
-    assert(lockfRtn != -1);
+    opr_Assert(lockfRtn != -1);
 #else
 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
-    assert(lockf(dp->lock_fd, F_LOCK, 0) != -1);
+    opr_Verify(lockf(dp->lock_fd, F_LOCK, 0) != -1);
 #else
-    assert(flock(dp->lock_fd, LOCK_EX) == 0);
+    opr_Verify(flock(dp->lock_fd, LOCK_EX) == 0);
 #endif /* defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) */
 #endif
 }
@@ -1266,11 +1302,11 @@ VLockPartition_r(char *name)
 void
 VUnlockPartition_r(char *name)
 {
-    register struct DiskPartition64 *dp = VGetPartition_r(name, 0);
+    struct DiskPartition64 *dp = VGetPartition_r(name, 0);
     if (!dp)
        return;                 /* no partition, will fail later */
     close(dp->lock_fd);
-    dp->lock_fd = -1;
+    dp->lock_fd = INVALID_FD;
 }
 
 #endif /* AFS_NT40_ENV */
@@ -1355,7 +1391,7 @@ VPartHeaderUnlock(struct DiskPartition64 *dp, int locktype)
  * @internal volume package internal use only
  */
 
-struct DiskPartition64 * 
+struct DiskPartition64 *
 VGetPartitionById_r(afs_int32 id, int abortp)
 {
     struct DiskPartition64 *dp = NULL;
@@ -1365,7 +1401,7 @@ VGetPartitionById_r(afs_int32 id, int abortp)
     }
 
     if (abortp) {
-       assert(dp != NULL);
+       opr_Assert(dp != NULL);
     }
     return dp;
 }
@@ -1395,7 +1431,7 @@ VGetPartitionById(afs_int32 id, int abortp)
     return dp;
 }
 
-static struct DiskPartition64 * 
+static struct DiskPartition64 *
 VLookupPartition_r(char * path)
 {
     afs_int32 id = volutil_GetPartitionID(path);
@@ -1406,18 +1442,18 @@ VLookupPartition_r(char * path)
     return DiskPartitionTable[id];
 }
 
-static void 
+static void
 AddPartitionToTable_r(struct DiskPartition64 *dp)
 {
-    assert(dp->index >= 0 && dp->index <= VOLMAXPARTS);
+    opr_Assert(dp->index >= 0 && dp->index <= VOLMAXPARTS);
     DiskPartitionTable[dp->index] = dp;
 }
 
 #if 0
-static void 
+static void
 DeletePartitionFromTable_r(struct DiskPartition64 *dp)
 {
-    assert(dp->index >= 0 && dp->index <= VOLMAXPARTS);
+    opr_Assert(dp->index >= 0 && dp->index <= VOLMAXPARTS);
     DiskPartitionTable[dp->index] = NULL;
 }
 #endif