src/afsd/afsd.c: Fix misleading indentation
[openafs.git] / src / afsd / afsd.c
index 5fe8b04..0976099 100644 (file)
   *    -blocks     The number of blocks available in the workstation cache.
   *    -files      The target number of files in the workstation cache (Default:
   *                1000).
-  *    -rootvol            The name of the root volume to use.
+  *    -rootvol    The name of the root volume to use.
   *    -stat       The number of stat cache entries.
-  *    -hosts      List of servers to check for volume location info FOR THE
+  *    -hosts      [OBSOLETE] List of servers to check for volume location info FOR THE
   *                HOME CELL.
   *     -memcache   Use an in-memory cache rather than disk.
-  *    -cachedir    The base directory for the workstation cache.
+  *    -cachedir   The base directory for the workstation cache.
   *    -mountdir   The directory on which the AFS is to be mounted.
-  *    -confdir    The configuration directory .
+  *    -confdir    The configuration directory.
   *    -nosettime  Don't keep checking the time to avoid drift (default).
-  *     -settime    Keep checking the time to avoid drift.
+  *     -settime    [IGNORED] Keep checking the time to avoid drift.
   *    -rxmaxmtu   Set the max mtu to help with VPN issues.
-  *    -verbose     Be chatty.
+  *    -verbose    Be chatty.
   *    -disable-dynamic-vcaches     Disable the use of -stat value as the starting size of
   *                          the size of the vcache/stat cache pool,
   *                          but increase that pool dynamically as needed.
   *                support daemon
   *     -chunksize [n]   2^n is the chunksize to be used.  0 is default.
   *     -dcache    The number of data cache entries.
+  *     -volumes    The number of volume entries.
   *     -biods     Number of bkg I/O daemons (AIX3.1 only)
   *    -prealloc  Number of preallocated "small" memory blocks
-  *    -logfile   [OBSOLETE] Place where to put the logfile (default in
+  *    -logfile    [IGNORED] Place where to put the logfile (default in
   *                <cache>/etc/AFSLog.
   *    -waitclose make close calls always synchronous (slows em down, tho)
   *    -files_per_subdir [n]   number of files per cache subdir. (def=2048)
   *    -shutdown  Shutdown afs daemons
+  *    -enable_peer_stats      Collect RPC statistics by peer.
+  *    -enable_process_stats   Collect RPC statistics for this process.
+  *    -mem_alloc_sleep [IGNORED] Sleep when allocating memory.
+  *    -afsdb      Enable AFSDB support.
+  *    -dynroot        Enable dynroot support.
+  *    -dynroot-sparse Enable dynroot support with minimal cell list.
+  *    -fakestat       Enable fake stat() for cross-cell mounts.
+  *    -fakestat-all   Enable fake stat() for all mounts.
+  *    -nomount    Do not mount /afs.
+  *    -backuptree Prefer backup volumes for mountpoints in backup volumes.
+  *    -rxbind     Bind the rx socket.
+  *    -rxpck      Value for rx_extraPackets.
+  *    -splitcache RW/RO ratio for cache.
+  *    -rxmaxfrags Max number of UDP fragments per rx packet.
+  *    -inumcalc  inode number calculation method; 0=compat, 1=MD5 digest
   *---------------------------------------------------------------------------*/
 
 #include <afsconfig.h>
 #include <afs/param.h>
-#include <roken.h>
-
-#ifdef IGNORE_SOME_GCC_WARNINGS
-# pragma GCC diagnostic warning "-Wdeprecated-declarations"
+/* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
+ * defined, and roken includes dirent */
+#if defined(UKERNEL) && defined(AFS_USR_DARWIN_ENV)
+# undef KERNEL
+# include <roken.h>
+# define KERNEL
+#else
+# include <roken.h>
 #endif
 
 #define VFS 1
@@ -75,6 +95,7 @@
 
 #include <sys/file.h>
 #include <sys/wait.h>
+#include <hcrypto/rand.h>
 
 /* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
  * defined */
 #endif
 #include <CoreFoundation/CoreFoundation.h>
 
-#include <SystemConfiguration/SystemConfiguration.h>
-#include <SystemConfiguration/SCDynamicStore.h>
-
+static int event_pid;
 #ifndef AFS_ARM_DARWIN_ENV
-#include <IOKit/pwr_mgt/IOPMLib.h>
-#include <IOKit/IOMessage.h>
-
-static io_connect_t root_port;
-static IONotificationPortRef notify;
-static io_object_t iterator;
+#define MACOS_EVENT_HANDLING 1
 #endif
-
-static CFRunLoopSourceRef source;
-
-static int event_pid;
-
 #endif /* AFS_DARWIN_ENV */
 
 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
@@ -211,15 +220,15 @@ struct in_addr_42 {
 /*
  * Global configuration variables.
  */
-static afs_int32 enable_rxbind = 0;
-static afs_int32 afs_shutdown = 0;
-static afs_int32 cacheBlocks;          /*Num blocks in the cache */
-static afs_int32 cacheFiles;           /*Optimal # of files in workstation cache */
-static afs_int32 rwpct = 0;
-static afs_int32 ropct = 0;
-static afs_int32 cacheStatEntries;     /*Number of stat cache entries */
-static char *cacheBaseDir;             /*Where the workstation AFS cache lives */
-static char *confDir;                  /*Where the workstation AFS configuration lives */
+static int enable_rxbind = 0;
+static int afs_shutdown = 0;
+static int cacheBlocks;                /*Num blocks in the cache */
+static int cacheFiles;         /*Optimal # of files in workstation cache */
+static int rwpct = 0;
+static int ropct = 0;
+static int cacheStatEntries;   /*Number of stat cache entries */
+static char *cacheBaseDir;     /*Where the workstation AFS cache lives */
+static char *confDir;          /*Where the workstation AFS configuration lives */
 static char fullpn_DCacheFile[1024];   /*Full pathname of DCACHEFILE */
 static char fullpn_VolInfoFile[1024];  /*Full pathname of VOLINFOFILE */
 static char fullpn_CellInfoFile[1024]; /*Full pathanem of CELLINFOFILE */
@@ -268,6 +277,7 @@ static int enable_fakestat = 0;     /* enable fakestat support */
 static int enable_backuptree = 0;      /* enable backup tree support */
 static int enable_nomount = 0; /* do not mount */
 static int enable_splitcache = 0;
+static char *inumcalc = NULL;        /* inode number calculation method */
 static int afsd_dynamic_vcaches = 0;   /* Enable dynamic-vcache support */
 int afsd_verbose = 0;          /*Are we being chatty? */
 int afsd_debug = 0;            /*Are we printing debugging info? */
@@ -303,11 +313,13 @@ struct afs_cacheParams cparams;   /* params passed to cache manager */
 
 int PartSizeOverflow(char *path, int cs);
 
+static int afsd_syscall(int code, ...);
+
 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
-static void fork_rx_syscall_wait();
+static void fork_rx_syscall_wait(const char *rn, int syscall, ...);
 #endif
-static void fork_rx_syscall();
-static void fork_syscall();
+static void fork_rx_syscall(const char *rn, int syscall, ...);
+static void fork_syscall(const char *rn, int syscall, ...);
 
 enum optionsList {
     OPT_blocks,
@@ -349,9 +361,21 @@ enum optionsList {
     OPT_rxmaxmtu,
     OPT_dynrootsparse,
     OPT_rxmaxfrags,
+    OPT_inumcalc,
 };
 
-#if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
+#ifdef MACOS_EVENT_HANDLING
+#include <SystemConfiguration/SystemConfiguration.h>
+#include <SystemConfiguration/SCDynamicStore.h>
+
+#include <IOKit/pwr_mgt/IOPMLib.h>
+#include <IOKit/IOMessage.h>
+
+static io_connect_t root_port;
+static IONotificationPortRef notify;
+static io_object_t iterator;
+static CFRunLoopSourceRef source;
+
 static void
 afsd_sleep_callback(void * refCon, io_service_t service,
                    natural_t messageType, void * messageArgument )
@@ -398,17 +422,16 @@ afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
     afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
        mtubuf[MAXIPADDRS];
     char reason[1024];
-    afs_int32 code;
+    int code;
 
-    code =
-       parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
-                     AFSDIR_CLIENT_NETINFO_FILEPATH,
-                     AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
+    code = afsconf_ParseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS,
+                                reason, AFSDIR_CLIENT_NETINFO_FILEPATH,
+                                AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
 
     if (code > 0) {
        /* Note we're refreshing */
        code = code | 0x40000000;
-       afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
+       afsd_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
     } else
        printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
               reason);
@@ -538,7 +561,7 @@ ParseCacheInfoFile(void)
     static char rn[] = "ParseCacheInfoFile";   /*This routine's name */
     FILE *cachefd;             /*Descriptor for cache info file */
     int parseResult;           /*Result of our fscanf() */
-    afs_int32 tCacheBlocks;
+    int tCacheBlocks;
     char tCacheBaseDir[1024], *tbd, tCacheMountDir[1024], *tmd;
 
     if (afsd_debug)
@@ -1036,8 +1059,7 @@ doSweepAFSCache(int *vFilesFound,
                cache_dir_list[dirNum]++;       /* keep directory's file count */
                if (cache_dir_list[dirNum] > nFilesPerDir) {
                    /* Too many files -- add to filelist */
-                   struct afsd_file_list *tmp = (struct afsd_file_list *)
-                       malloc(sizeof(*tmp));
+                   struct afsd_file_list *tmp = malloc(sizeof(*tmp));
                    if (!tmp)
                        printf
                            ("%s: MALLOC FAILED allocating file_list entry\n",
@@ -1331,7 +1353,7 @@ CheckCacheBaseDir(char *dir)
 
                    if (cp = hasmntopt(&mnt, "dev="))
                        rdev =
-                           (int)strtol(cp + strlen("dev="), (char **)NULL,
+                           (int)strtol(cp + strlen("dev="), NULL,
                                        16);
 
                    if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
@@ -1371,7 +1393,7 @@ SweepAFSCache(int *vFilesFound)
     }
 
     if (cache_dir_list == NULL) {
-       cache_dir_list = (int *)malloc(maxDir * sizeof(*cache_dir_list));
+       cache_dir_list = malloc(maxDir * sizeof(*cache_dir_list));
        if (cache_dir_list == NULL) {
            printf("%s: Malloc Failed!\n", rn);
            return (-1);
@@ -1381,17 +1403,15 @@ SweepAFSCache(int *vFilesFound)
     }
 
     if (cache_dir_filelist == NULL) {
-       cache_dir_filelist = (struct afsd_file_list **)
-           malloc(maxDir * sizeof(*cache_dir_filelist));
+       cache_dir_filelist = calloc(maxDir, sizeof(*cache_dir_filelist));
        if (cache_dir_filelist == NULL) {
            printf("%s: Malloc Failed!\n", rn);
            return (-1);
        }
-       memset(cache_dir_filelist, 0, maxDir * sizeof(*cache_dir_filelist));
     }
 
     if (dir_for_V == NULL) {
-       dir_for_V = (int *)malloc(cacheFiles * sizeof(*dir_for_V));
+       dir_for_V = malloc(cacheFiles * sizeof(*dir_for_V));
        if (dir_for_V == NULL) {
            printf("%s: Malloc Failed!\n", rn);
            return (-1);
@@ -1415,7 +1435,7 @@ ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
 {
     int isHomeCell;
     int i, code;
-    afs_int32 cellFlags = 0;
+    int cellFlags = 0;
     afs_int32 hosts[MAXHOSTSPERCELL];
 
     /* figure out if this is the home cell */
@@ -1434,7 +1454,7 @@ ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
                                 * for upwards compatibility */
 
     /* configure one cell */
-    code = afsd_call_syscall(AFSOP_ADDCELL2, hosts,    /* server addresses */
+    code = afsd_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */
                        aci->name,      /* cell name */
                        cellFlags,      /* is this the home cell? */
                        aci->linkedCell);       /* Linked cell, if any */
@@ -1448,7 +1468,7 @@ ConfigCellAlias(struct afsconf_cellalias *aca,
                void *arock, struct afsconf_dir *adir)
 {
     /* push the alias into the kernel */
-    afsd_call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
+    afsd_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
     return 0;
 }
 
@@ -1465,7 +1485,7 @@ AfsdbLookupHandler(void)
     kernelMsg[1] = 0;
     acellName[0] = '\0';
 
-#if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
+#ifdef MACOS_EVENT_HANDLING
     /* Fork the event handler also. */
     code = fork();
     if (code == 0) {
@@ -1479,7 +1499,7 @@ AfsdbLookupHandler(void)
        /* On some platforms you only get 4 args to an AFS call */
        int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
        code =
-           afsd_call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
+           afsd_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
        if (code) {             /* Something is wrong? */
            sleep(1);
            continue;
@@ -1518,8 +1538,7 @@ BkgHandler(void)
     char srcName[256];
     char dstName[256];
 
-    uspc = (struct afs_uspc_param *)malloc(sizeof(struct afs_uspc_param));
-    memset(uspc, 0, sizeof(struct afs_uspc_param));
+    uspc = calloc(1, sizeof(struct afs_uspc_param));
     memset(srcName, 0, sizeof(srcName));
     memset(dstName, 0, sizeof(dstName));
 
@@ -1535,7 +1554,7 @@ BkgHandler(void)
        /* pushing in a buffer this large */
        uspc->bufSz = 256;
 
-       code = afsd_call_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName);
+       code = afsd_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName);
        if (code) {             /* Something is wrong? */
            if (code == -2) /* shutting down */
                break;
@@ -1650,10 +1669,8 @@ daemon_thread(void *rock)
        exit(1);
     }
     BkgHandler();
-#elif defined(AFS_AIX32_ENV)
-    afsd_call_syscall(AFSOP_START_BKG, 0);
 #else
-    afsd_call_syscall(AFSOP_START_BKG);
+    afsd_syscall(AFSOP_START_BKG, 0);
 #endif
     return NULL;
 }
@@ -1667,8 +1684,16 @@ rmtsysd_thread(void *rock)
 }
 #endif /* !UKERNEL */
 
-int
-mainproc(struct cmd_syndesc *as, void *arock)
+/**
+ * Check the command line and cacheinfo options.
+ *
+ * @param[in] as  parsed command line arguments
+ *
+ * @note Invokes the shutdown syscall and exits with 0 when
+ *       -shutdown is given.
+ */
+static int
+CheckOptions(struct cmd_syndesc *as)
 {
     afs_int32 code;            /*Result of fork() */
 #ifdef AFS_SUN5_ENV
@@ -1685,6 +1710,9 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
 #endif
 
+    cmd_OpenConfigFile(AFSDIR_CLIENT_CONFIG_FILE_FILEPATH);
+    cmd_SetCommandName("afsd");
+
     /* call atoi on the appropriate parsed results */
     if (cmd_OptionAsInt(as, OPT_blocks, &cacheBlocks) == 0)
        sawCacheBlocks = 1;
@@ -1769,7 +1797,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
         * Cold shutdown is the default
         */
        printf("afsd: Shutting down all afs processes and afs state\n");
-       code = afsd_call_syscall(AFSOP_SHUTDOWN, 1);
+       code = afsd_syscall(AFSOP_SHUTDOWN, 1);
        if (code) {
            printf("afsd: AFS still mounted; Not shutting down\n");
            exit(1);
@@ -1823,7 +1851,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
        int rxpck;
         cmd_OptionAsInt(as, OPT_rxpck, &rxpck);
        printf("afsd: set rxpck = %d\n", rxpck);
-       code = afsd_call_syscall(AFSOP_SET_RXPCK, rxpck);
+       code = afsd_syscall(AFSOP_SET_RXPCK, rxpck);
        if (code) {
            printf("afsd: failed to set rxpck\n");
            exit(1);
@@ -1874,6 +1902,9 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
 
     cmd_OptionAsInt(as, OPT_rxmaxfrags, &rxmaxfrags);
+    if (cmd_OptionPresent(as, OPT_inumcalc)) {
+       cmd_OptionAsString(as, OPT_inumcalc, &inumcalc);
+    }
 
     /* parse cacheinfo file if this is a diskcache */
     if (ParseCacheInfoFile()) {
@@ -1890,7 +1921,7 @@ afsd_run(void)
     struct afsconf_dir *cdir;  /* config dir */
     int lookupResult;          /*Result of GetLocalCellName() */
     int i;
-    afs_int32 code;            /*Result of fork() */
+    int code;                  /*Result of fork() */
     char *fsTypeMsg = NULL;
     int cacheIteration;                /*How many times through cache verification */
     int vFilesFound;           /*How many data cache files were found in sweep */
@@ -2077,17 +2108,17 @@ afsd_run(void)
     /*
      * Create and zero the inode table for the desired cache files.
      */
-    inode_for_V = (AFSD_INO_T *) malloc(cacheFiles * sizeof(AFSD_INO_T));
+    inode_for_V = calloc(cacheFiles, sizeof(AFSD_INO_T));
     if (inode_for_V == (AFSD_INO_T *) 0) {
        printf
            ("%s: malloc() failed for cache file inode table with %d entries.\n",
             rn, cacheFiles);
        exit(1);
     }
-    memset(inode_for_V, '\0', (cacheFiles * sizeof(AFSD_INO_T)));
     if (afsd_debug)
-       printf("%s: %d inode_for_V entries at 0x%x, %lu bytes\n", rn,
-              cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
+       printf("%s: %d inode_for_V entries at %p, %lu bytes\n", rn,
+              cacheFiles, inode_for_V,
+              (unsigned long)cacheFiles * sizeof(AFSD_INO_T));
 #endif
 
     if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
@@ -2121,24 +2152,30 @@ afsd_run(void)
     /*
      * Set the primary cell name.
      */
-    afsd_call_syscall(AFSOP_SET_THISCELL, LclCellName);
+    afsd_syscall(AFSOP_SET_THISCELL, LclCellName);
 
     /* Initialize RX daemons and services */
 
     /* initialize the rx random number generator from user space */
     {
+       /* rand-fortuna wants at least 128 bytes of seed; be generous. */
+       unsigned char seedbuf[256];
+       if (RAND_bytes(seedbuf, sizeof(seedbuf)) != 1) {
+           printf("SEED_ENTROPY: Error retrieving seed entropy\n");
+       }
+       afsd_syscall(AFSOP_SEED_ENTROPY, seedbuf, sizeof(seedbuf));
+       memset(seedbuf, 0, sizeof(seedbuf));
        /* parse multihomed address files */
        afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
            mtubuf[MAXIPADDRS];
        char reason[1024];
-       code =
-           parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
-                         AFSDIR_CLIENT_NETINFO_FILEPATH,
-                         AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
+       code = afsconf_ParseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
+                                    AFSDIR_CLIENT_NETINFO_FILEPATH,
+                                    AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
        if (code > 0) {
            if (enable_rxbind)
                code = code | 0x80000000;
-               afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
+           afsd_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
        } else
            printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
                   reason);
@@ -2172,7 +2209,7 @@ afsd_run(void)
     fork_rx_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, enable_peer_stats,
                     enable_process_stats);
 #else
-    fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs);
+    fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, 0, 0);
 #endif
 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
     if (afsd_verbose)
@@ -2185,7 +2222,7 @@ afsd_run(void)
            printf("%s: Forking AFSDB lookup handler.\n", rn);
        afsd_fork(0, afsdb_thread, NULL);
     }
-    code = afsd_call_syscall(AFSOP_BASIC_INIT, 1);
+    code = afsd_syscall(AFSOP_BASIC_INIT, 1);
     if (code) {
        printf("%s: Error %d in basic initialization.\n", rn, code);
         exit(1);
@@ -2209,16 +2246,16 @@ afsd_run(void)
     cparams.setTimeFlag = 0;
     cparams.memCacheFlag = cacheFlags;
     cparams.dynamic_vcaches = afsd_dynamic_vcaches;
-       afsd_call_syscall(AFSOP_CACHEINIT, &cparams);
+    afsd_syscall(AFSOP_CACHEINIT, &cparams);
 
     /* do it before we init the cache inodes */
     if (enable_splitcache) {
-       afsd_call_syscall(AFSOP_BUCKETPCT, 1, rwpct);
-       afsd_call_syscall(AFSOP_BUCKETPCT, 2, ropct);
+       afsd_syscall(AFSOP_BUCKETPCT, 1, rwpct);
+       afsd_syscall(AFSOP_BUCKETPCT, 2, ropct);
     }
 
     if (afsd_CloseSynch)
-       afsd_call_syscall(AFSOP_CLOSEWAIT);
+       afsd_syscall(AFSOP_CLOSEWAIT);
 
     /*
      * Sweep the workstation AFS cache directory, remembering the inodes of
@@ -2259,7 +2296,7 @@ afsd_run(void)
               fullpn_DCacheFile);
     /* once again, meaningless for a memory-based cache. */
     if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
-       afsd_call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
+       afsd_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
 
     /*
      * Pass the kernel the name of the workstation cache file holding the
@@ -2269,13 +2306,13 @@ afsd_run(void)
        if (afsd_debug)
            printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
                   fullpn_CellInfoFile);
-       afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
+       afsd_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
     }
 
     if (rxmaxfrags) {
        if (afsd_verbose)
             printf("%s: Setting rxmaxfrags in kernel = %d\n", rn, rxmaxfrags);
-       code = afsd_call_syscall(AFSOP_SET_RXMAXFRAGS, rxmaxfrags);
+       code = afsd_syscall(AFSOP_SET_RXMAXFRAGS, rxmaxfrags);
         if (code)
             printf("%s: Error seting rxmaxfrags\n", rn);
     }
@@ -2283,16 +2320,43 @@ afsd_run(void)
     if (rxmaxmtu) {
        if (afsd_verbose)
             printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
-       code = afsd_call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
+       code = afsd_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
         if (code)
             printf("%s: Error seting rxmaxmtu\n", rn);
     }
 
+    if (inumcalc != NULL) {
+       if (strcmp(inumcalc, "compat") == 0) {
+           if (afsd_verbose) {
+               printf("%s: Setting original inode number calculation method in kernel.\n",
+                      rn);
+           }
+           code = afsd_syscall(AFSOP_SET_INUMCALC, AFS_INUMCALC_COMPAT);
+           if (code) {
+               printf("%s: Error setting inode calculation method: code=%d.\n",
+                      rn, code);
+           }
+       } else if (strcmp(inumcalc, "md5") == 0) {
+           if (afsd_verbose) {
+               printf("%s: Setting md5 digest inode number calculation in kernel.\n",
+                      rn);
+           }
+           code = afsd_syscall(AFSOP_SET_INUMCALC, AFS_INUMCALC_MD5);
+           if (code) {
+               printf("%s: Error setting inode calculation method: code=%d.\n",
+                      rn, code);
+           }
+       } else {
+           printf("%s: Unknown value for -inumcalc: %s."
+                  "Using default inode calculation method.\n", rn, inumcalc);
+       }
+    }
+
     if (enable_dynroot) {
        if (afsd_verbose)
            printf("%s: Enabling dynroot support in kernel%s.\n", rn,
                   (enable_dynroot==2)?", not showing cells.":"");
-       code = afsd_call_syscall(AFSOP_SET_DYNROOT, 1);
+       code = afsd_syscall(AFSOP_SET_DYNROOT, 1);
        if (code)
            printf("%s: Error enabling dynroot support.\n", rn);
     }
@@ -2300,9 +2364,9 @@ afsd_run(void)
     if (enable_fakestat) {
        if (afsd_verbose)
            printf("%s: Enabling fakestat support in kernel%s.\n", rn,
-                  (enable_fakestat==2)?" for all mountpoints."
+                  (enable_fakestat==1)?" for all mountpoints."
                   :" for crosscell mountpoints");
-       code = afsd_call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
+       code = afsd_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
        if (code)
            printf("%s: Error enabling fakestat support.\n", rn);
     }
@@ -2310,7 +2374,7 @@ afsd_run(void)
     if (enable_backuptree) {
        if (afsd_verbose)
            printf("%s: Enabling backup tree support in kernel.\n", rn);
-       code = afsd_call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
+       code = afsd_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
        if (code)
            printf("%s: Error enabling backup tree support.\n", rn);
     }
@@ -2358,7 +2422,7 @@ afsd_run(void)
        if (afsd_verbose)
            printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn,
                   rootVolume);
-       afsd_call_syscall(AFSOP_ROOTVOLUME, rootVolume);
+       afsd_syscall(AFSOP_ROOTVOLUME, rootVolume);
     }
 
     /*
@@ -2370,7 +2434,7 @@ afsd_run(void)
               fullpn_VolInfoFile);
     /* once again, meaningless for a memory-based cache. */
     if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
-       afsd_call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
+       afsd_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
 
     /*
      * Give the kernel the names of the AFS files cached on the workstation's
@@ -2386,7 +2450,7 @@ afsd_run(void)
        for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
            if (!nocachefile) {
                sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
-               code = afsd_call_syscall(AFSOP_CACHEFILE, fullpn_VFile);
+               code = afsd_syscall(AFSOP_CACHEFILE, fullpn_VFile);
                if (code) {
                    if (currVFile == 0) {
                        if (afsd_debug)
@@ -2405,12 +2469,8 @@ afsd_run(void)
                }
                /* fall through to setup-by-inode */
            }
-#ifdef AFS_SGI62_ENV
-           afsd_call_syscall(AFSOP_CACHEINODE,
-                        (afs_uint32) (inode_for_V[currVFile] >> 32),
-                        (afs_uint32) (inode_for_V[currVFile] & 0xffffffff));
-#elif !(defined(AFS_LINUX26_ENV) || defined(AFS_CACHE_VNODE_PATH))
-           afsd_call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
+#if defined(AFS_SGI62_ENV) || !(defined(AFS_LINUX26_ENV) || defined(AFS_CACHE_VNODE_PATH))
+           afsd_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
 #else
            printf
                ("%s: Error calling AFSOP_CACHEINODE: not configured\n",
@@ -2427,7 +2487,7 @@ afsd_run(void)
     if (afsd_debug)
        printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
               0);
-       afsd_call_syscall(AFSOP_GO, 0);
+    afsd_syscall(AFSOP_GO, 0);
 
     /*
      * At this point, we have finished passing the kernel all the info
@@ -2448,6 +2508,9 @@ afsd_run(void)
        if (afsd_verbose)
            printf("%s: Forking 'rmtsys' daemon.\n", rn);
        afsd_fork(0, rmtsysd_thread, NULL);
+       code = afsd_syscall(AFSOP_SET_RMTSYS_FLAG, 1);
+       if (code)
+           printf("%s: Error enabling rmtsys support.\n", rn);
     }
 #endif /* !UKERNEL */
     /*
@@ -2456,14 +2519,16 @@ afsd_run(void)
     return 0;
 }
 
+#ifndef UKERNEL
 #include "AFS_component_version_number.c"
+#endif
 
 void
 afsd_init(void)
 {
     struct cmd_syndesc *ts;
 
-    ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
+    ts = cmd_CreateSyntax(NULL, NULL, NULL, 0, "start AFS");
 
     /* 0 - 10 */
     cmd_AddParmAtOffset(ts, OPT_blocks, "-blocks", CMD_SINGLE,
@@ -2509,11 +2574,9 @@ afsd_init(void)
     cmd_AddParmAtOffset(ts, OPT_shutdown, "-shutdown", CMD_FLAG,
                        CMD_OPTIONAL, "Shutdown all afs state");
     cmd_AddParmAtOffset(ts, OPT_peerstats, "-enable_peer_stats", CMD_FLAG,
-                       CMD_OPTIONAL | CMD_HIDE,
-                       "Collect rpc statistics by peer");
+                       CMD_OPTIONAL, "Collect rpc statistics by peer");
     cmd_AddParmAtOffset(ts, OPT_processstats, "-enable_process_stats",
-                       CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
-                       "Collect rpc statistics for this process");
+                       CMD_FLAG, CMD_OPTIONAL, "Collect rpc statistics for this process");
     cmd_AddParmAtOffset(ts, OPT_memallocsleep, "-mem_alloc_sleep",
                        CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
                        "Allow sleeps when allocating memory cache");
@@ -2535,7 +2598,7 @@ afsd_init(void)
                        CMD_OPTIONAL, "Do not mount AFS");
     cmd_AddParmAtOffset(ts, OPT_backuptree, "-backuptree", CMD_FLAG,
                        CMD_OPTIONAL,
-                       "Prefer backup volumes for mointpoints in backup "
+                       "Prefer backup volumes for mountpoints in backup "
                        "volumes");
     cmd_AddParmAtOffset(ts, OPT_rxbind, "-rxbind", CMD_FLAG,
                        CMD_OPTIONAL,
@@ -2559,24 +2622,29 @@ afsd_init(void)
                        CMD_OPTIONAL,
                        "Set the maximum number of UDP fragments Rx should "
                        "send/receive per Rx packet");
+    cmd_AddParmAtOffset(ts, OPT_inumcalc, "-inumcalc", CMD_SINGLE, CMD_OPTIONAL,
+                       "Set inode number calculation method");
 }
 
+/**
+ * Parse and check the command line options.
+ *
+ * @note The -shutdown command is handled in CheckOptions().
+ */
 int
 afsd_parse(int argc, char **argv)
 {
-    return cmd_Dispatch(argc, argv);
-}
+    struct cmd_syndesc *ts = NULL;
+    int code;
 
-struct afsd_syscall_args {
-    long syscall;
-    long param1;
-    long param2;
-    long param3;
-    long param4;
-    long param5;
-    const char *rn;
-    int rxpri;
-};
+    code = cmd_Parse(argc, argv, &ts);
+    if (code) {
+       return code;
+    }
+    code = CheckOptions(ts);
+    cmd_FreeOptions(&ts);
+    return code;
+}
 
 /**
  * entry point for calling a syscall from another proc/thread.
@@ -2596,8 +2664,7 @@ call_syscall_thread(void *rock)
        afsd_set_rx_rtpri();
     }
 
-    code = afsd_call_syscall(args->syscall, args->param1, args->param2,
-                                 args->param3, args->param4, args->param5);
+    code = afsd_call_syscall(args);
     if (code && args->syscall == AFSOP_START_CS) {
        printf("%s: No check server daemon in client.\n", args->rn);
     }
@@ -2607,6 +2674,100 @@ call_syscall_thread(void *rock)
     return NULL;
 }
 
+static void
+afsd_syscall_populate(struct afsd_syscall_args *args, int syscall, va_list ap)
+{
+    afsd_syscall_param_t *params;
+
+    memset(args, 0, sizeof(struct afsd_syscall_args));
+
+    args->syscall = syscall;
+    params = args->params;
+
+    switch (syscall) {
+    case AFSOP_RXEVENT_DAEMON:
+    case AFSOP_CLOSEWAIT:
+    case AFSOP_START_AFS:
+    case AFSOP_START_CS:
+    case AFSOP_START_TRUNCDAEMON:
+       break;
+    case AFSOP_START_BKG:
+    case AFSOP_SHUTDOWN:
+    case AFSOP_SET_RXPCK:
+    case AFSOP_BASIC_INIT:
+    case AFSOP_SET_RXMAXFRAGS:
+    case AFSOP_SET_RXMAXMTU:
+    case AFSOP_SET_DYNROOT:
+    case AFSOP_SET_FAKESTAT:
+    case AFSOP_SET_BACKUPTREE:
+    case AFSOP_BUCKETPCT:
+    case AFSOP_GO:
+    case AFSOP_SET_RMTSYS_FLAG:
+    case AFSOP_SET_INUMCALC:
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
+       break;
+    case AFSOP_SET_THISCELL:
+    case AFSOP_ROOTVOLUME:
+    case AFSOP_VOLUMEINFO:
+    case AFSOP_CACHEFILE:
+    case AFSOP_CACHEINFO:
+    case AFSOP_CACHEINIT:
+    case AFSOP_CELLINFO:
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       break;
+    case AFSOP_ADDCELLALIAS:
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       break;
+    case AFSOP_AFSDB_HANDLER:
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[2] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
+       break;
+    case AFSOP_BKG_HANDLER:
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[2] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       break;
+    case AFSOP_RXLISTENER_DAEMON:
+    case AFSOP_START_RXCALLBACK:
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
+       params[1] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
+       params[2] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
+       break;
+    case AFSOP_ADVISEADDR:
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
+       params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[2] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[3] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       break;
+    case AFSOP_ADDCELL2:
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[2] = CAST_SYSCALL_PARAM((va_arg(ap, afs_int32)));
+       params[3] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       break;
+    case AFSOP_CACHEINODE:
+#if defined AFS_SGI62_ENV
+       {
+           afs_int64 tmp = va_arg(ap, afs_int64);
+           params[0] = CAST_SYSCALL_PARAM((afs_uint32)(tmp >> 32));
+           params[1] = CAST_SYSCALL_PARAM((afs_uint32)(tmp & 0xffffffff));
+       }
+#else
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, afs_uint32)));
+#endif
+       break;
+    case AFSOP_SEED_ENTROPY:
+       params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
+       params[1] = CAST_SYSCALL_PARAM((va_arg(ap, afs_uint32)));
+       break;
+    default:
+       printf("Unknown syscall enountered: %d\n", syscall);
+       opr_Assert(0);
+    }
+}
+
 /**
  * common code for calling a syscall in another proc/thread.
  *
@@ -2617,19 +2778,12 @@ call_syscall_thread(void *rock)
  * @param[in] syscall syscall to run
  */
 static void
-fork_syscall_impl(int rx, int wait, const char *rn, long syscall, long param1,
-                  long param2, long param3, long param4, long param5)
+fork_syscall_impl(int rx, int wait, const char *rn, int syscall, va_list ap)
 {
     struct afsd_syscall_args *args;
 
     args = malloc(sizeof(*args));
-
-    args->syscall = syscall;
-    args->param1 = param1;
-    args->param2 = param2;
-    args->param3 = param3;
-    args->param4 = param4;
-    args->param5 = param5;
+    afsd_syscall_populate(args, syscall, ap);
     args->rxpri = rx;
     args->rn = rn;
 
@@ -2640,20 +2794,26 @@ fork_syscall_impl(int rx, int wait, const char *rn, long syscall, long param1,
  * call a syscall in another process or thread.
  */
 static void
-fork_syscall(const char *rn, long syscall, long param1, long param2,
-             long param3, long param4, long param5)
+fork_syscall(const char *rn, int syscall, ...)
 {
-    fork_syscall_impl(0, 0, rn, syscall, param1, param2, param3, param4, param5);
+    va_list ap;
+
+    va_start(ap, syscall);
+    fork_syscall_impl(0, 0, rn, syscall, ap);
+    va_end(ap);
 }
 
 /**
  * call a syscall in another process or thread, and give it RX priority.
  */
 static void
-fork_rx_syscall(const char *rn, long syscall, long param1, long param2,
-                long param3, long param4, long param5)
+fork_rx_syscall(const char *rn, int syscall, ...)
 {
-    fork_syscall_impl(1, 0, rn, syscall, param1, param2, param3, param4, param5);
+    va_list ap;
+
+    va_start(ap, syscall);
+    fork_syscall_impl(1, 0, rn, syscall, ap);
+    va_end(ap);
 }
 
 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
@@ -2662,9 +2822,25 @@ fork_rx_syscall(const char *rn, long syscall, long param1, long param2,
  * for it to finish before returning.
  */
 static void
-fork_rx_syscall_wait(const char *rn, long syscall, long param1, long param2,
-                     long param3, long param4, long param5)
+fork_rx_syscall_wait(const char *rn, int syscall, ...)
 {
-    fork_syscall_impl(1, 1, rn, syscall, param1, param2, param3, param4, param5);
+    va_list ap;
+
+    va_start(ap, syscall);
+    fork_syscall_impl(1, 1, rn, syscall, ap);
+    va_end(ap);
 }
 #endif /* AFS_SUN510_ENV && RXK_LISTENER_ENV */
+
+static int
+afsd_syscall(int syscall, ...)
+{
+    va_list ap;
+    struct afsd_syscall_args args;
+
+    va_start(ap, syscall);
+    afsd_syscall_populate(&args, syscall, ap);
+    va_end(ap);
+
+    return afsd_call_syscall(&args);
+}