Unix afsd: Check for mountpoint /afs first
[openafs.git] / src / afsd / afsd.c
index 40afb63..495ceb3 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
   *    -rxmaxmtu   Set the max mtu to help with VPN issues.
   *    -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, 
+  *                          the size of the vcache/stat cache pool,
   *                          but increase that pool dynamically as needed.
   *    -debug     Print out additional debugging info.
   *    -kerndev    [OBSOLETE] The kernel device for AFS.
   *    -dontfork   [OBSOLETE] Don't fork off as a new process.
   *    -daemons   The number of background daemons to start (Default: 2).
   *    -rmtsys    Also fires up an afs remote sys call (e.g. pioctl, setpag)
-  *                support daemon 
+  *                support daemon
   *     -chunksize [n]   2^n is the chunksize to be used.  0 is default.
   *     -dcache    The number of data cache entries.
   *     -biods     Number of bkg I/O daemons (AIX3.1 only)
   *    -prealloc  Number of preallocated "small" memory blocks
-  *     -pininodes Number of inodes which can be spared from inode[] for 
-  *                pointing at Vfiles.  If this is set too high, you may have
-  *                system problems, which can only be ameliorated by changing
-  *                NINODE (or equivalent) and rebuilding the kernel.
-  *               This option is now disabled.
   *    -logfile   [OBSOLETE] Place where to put the logfile (default in
   *                <cache>/etc/AFSLog.
   *    -waitclose make close calls always synchronous (slows em down, tho)
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#ifdef IGNORE_SOME_GCC_WARNINGS
+# pragma GCC diagnostic warning "-Wdeprecated-declarations"
+#endif
 
 #define VFS 1
 
+#include <afs/stds.h>
+
 #include <afs/cmd.h>
 
-#include <assert.h>
-#include <potpourri.h>
+#include "afsd.h"
+
+#include <afs/afs_assert.h>
 #include <afs/afsutil.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/file.h>
 #include <errno.h>
 #include <sys/time.h>
-#include <dirent.h>
 #include <sys/wait.h>
 
+/* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
+ * defined */
+#if defined(UKERNEL) && defined(AFS_USR_DARWIN_ENV)
+# undef KERNEL
+# include <dirent.h>
+# define KERNEL
+#else
+# include <dirent.h>
+#endif
+
 
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #include <sys/fs_types.h>
 #endif
 
-#ifdef HAVE_SYS_MOUNT_H
+#if defined(HAVE_SYS_MOUNT_H) && !defined(AFS_ARM_DARWIN_ENV)
 #include <sys/mount.h>
 #endif
 
 #include <mntent.h>
 #endif
 
-#ifdef HAVE_SYS_MOUNT_H
-#include <sys/mount.h>
-#endif
-
 #ifdef HAVE_SYS_VFS_H
 #include <sys/vfs.h>
 #endif
 #include <ctype.h>
 #include <afs/afssyscalls.h>
 #include <afs/afsutil.h>
+#include <afs/sys_prototypes.h>
 
 #ifdef AFS_SGI61_ENV
 #include <unistd.h>
@@ -153,68 +160,44 @@ void set_staticaddrs(void);
 #ifdef AFS_SGI65_ENV
 #include <sched.h>
 #endif
-#ifdef AFS_LINUX20_ENV
-#include <sys/resource.h>
-#endif
+
 #ifdef AFS_DARWIN_ENV
 #ifdef AFS_DARWIN80_ENV
 #include <sys/ioctl.h>
+#include <sys/xattr.h>
 #endif
-#include <mach/mach.h>
-#ifndef AFS_DARWIN100_ENV
-/* Symbols from the DiskArbitration framework */
-kern_return_t DiskArbStart(mach_port_t *);
-kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int,
-                                                        char *);
-#define DISK_ARB_NETWORK_DISK_FLAG 8
-#endif
-#include <mach/mach_port.h>
-#include <mach/mach_interface.h>
-#include <mach/mach_init.h>
-
 #include <CoreFoundation/CoreFoundation.h>
 
 #include <SystemConfiguration/SystemConfiguration.h>
 #include <SystemConfiguration/SCDynamicStore.h>
 
+#ifndef AFS_ARM_DARWIN_ENV
 #include <IOKit/pwr_mgt/IOPMLib.h>
 #include <IOKit/IOMessage.h>
 
-#include <dns_sd.h>
-
-typedef struct DNSSDState
-{
-    DNSServiceRef       service;
-    CFRunLoopSourceRef  source;
-    CFSocketRef         socket;
-} DNSSDState;
-
 static io_connect_t root_port;
 static IONotificationPortRef notify;
 static io_object_t iterator;
+#endif
+
 static CFRunLoopSourceRef source;
 
 static int event_pid;
 
 #endif /* AFS_DARWIN_ENV */
 
-#ifndef MOUNT_AFS
-#define        MOUNT_AFS AFS_MOUNT_AFS
-#endif /* MOUNT_AFS */
-
-#if AFS_HAVE_STATVFS
+#if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
 #include <sys/statvfs.h>
 #else
 #if defined(AFS_SUN_ENV)
 #include <sys/vfs.h>
 #else
-#if !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
+#ifdef HAVE_SYS_STATFS_H
 #include <sys/statfs.h>
 #endif
 #endif
 #endif
 
-
 #undef VIRTUE
 #undef VICE
 
@@ -245,11 +228,6 @@ struct in_addr_42 {
        } S_un_w;
        afs_uint32 S_addr;
     } S_un;
-#define        s_host  S_un.S_un_b.s_b2        /* host on imp */
-#define        s_net   S_un.S_un_b.s_b1        /* network */
-#define        s_imp   S_un.S_un_w.s_w2        /* imp */
-#define        s_impno S_un.S_un_b.s_b4        /* imp # */
-#define        s_lh    S_un.S_un_b.s_b3        /* logical host */
 };
 
 #define        mPrintIPAddr(ipaddr)  printf("[%d.%d.%d.%d] ",          \
@@ -261,37 +239,38 @@ struct in_addr_42 {
 /*
  * Global configuration variables.
  */
-afs_int32 enable_rxbind = 0;
-afs_int32 afs_shutdown = 0;
-afs_int32 cacheBlocks;         /*Num blocks in the cache */
-afs_int32 cacheFiles;          /*Optimal # of files in workstation cache */
-afs_int32 rwpct = 0;
-afs_int32 ropct = 0;
-afs_int32 cacheStatEntries;    /*Number of stat cache entries */
-char cacheBaseDir[1024];       /*Where the workstation AFS cache lives */
-char confDir[1024];            /*Where the workstation AFS configuration lives */
-char fullpn_DCacheFile[1024];  /*Full pathname of DCACHEFILE */
-char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE */
-char fullpn_CellInfoFile[1024];        /*Full pathanem of CELLINFOFILE */
-char fullpn_CacheInfo[1024];   /*Full pathname of CACHEINFO */
-char fullpn_VFile[1024];       /*Full pathname of data cache files */
-char *vFilePtr;                        /*Ptr to the number part of above pathname */
-int sawCacheMountDir = 0;      /* from cmd line */
-int sawCacheBaseDir = 0;
-int sawCacheBlocks = 0;
-int sawDCacheSize = 0;
-int sawBiod = 0;
-int sawCacheStatEntries = 0;
-char cacheMountDir[1024];      /*Mount directory for AFS */
-char rootVolume[64] = "root.afs";      /*AFS root volume name */
-afs_int32 cacheSetTime = FALSE;        /*Keep checking time to avoid drift? */
-afs_int32 isHomeCell;          /*Is current cell info for the home cell? */
+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[1024];        /*Where the workstation AFS cache lives */
+static char confDir[1024];             /*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 */
+static char fullpn_CacheInfo[1024];    /*Full pathname of CACHEINFO */
+static char fullpn_VFile[1024];        /*Full pathname of data cache files */
+static char *vFilePtr;                 /*Ptr to the number part of above pathname */
+static int sawCacheMountDir = 0;       /* from cmd line */
+static int sawCacheBaseDir = 0;
+static int sawCacheBlocks = 0;
+static int sawDCacheSize = 0;
+#ifdef AFS_AIX32_ENV
+static int sawBiod = 0;
+#endif
+static int sawCacheStatEntries = 0;
+char afsd_cacheMountDir[1024]; /*Mount directory for AFS */
+static char rootVolume[64] = "root.afs";       /*AFS root volume name */
+static afs_int32 cacheSetTime = 0;     /*Keep checking time to avoid drift? */
 #ifdef AFS_XBSD_ENV
-int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC;       /*Create & truncate on open */
+static int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC;        /*Create & truncate on open */
 #else
-int createAndTrunc = O_CREAT | O_TRUNC;        /*Create & truncate on open */
+static int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open */
 #endif
-int ownerRWmode = 0600;                /*Read/write OK by owner */
+static int ownerRWmode = 0600;         /*Read/write OK by owner */
 static int filesSet = 0;       /*True if number of files explicitly set */
 static int nFilesPerDir = 2048;        /* # files per cache dir */
 #if defined(AFS_CACHE_BYPASS)
@@ -312,22 +291,17 @@ static int nBiods = 5;            /* AIX3.1 only */
 static int preallocs = 400;    /* Def # of allocated memory blocks */
 static int enable_peer_stats = 0;      /* enable rx stats */
 static int enable_process_stats = 0;   /* enable rx stats */
-#ifdef AFS_AFSDB_ENV
 static int enable_afsdb = 0;   /* enable AFSDB support */
-#endif
 static int enable_dynroot = 0; /* enable dynroot support */
 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;
-#ifdef notdef
-static int inodes = 60;                /* VERY conservative, but has to be */
-#endif
-int afsd_dynamic_vcaches = 0;  /* Enable dynamic-vcache support */
+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? */
-int afsd_CloseSynch = 0;       /*Are closes synchronous or not? */
-int rxmaxmtu = 0;       /* Are we forcing a limit on the mtu? */
+static int afsd_CloseSynch = 0;        /*Are closes synchronous or not? */
+static int rxmaxmtu = 0;       /* Are we forcing a limit on the mtu? */
 
 #ifdef AFS_SGI62_ENV
 #define AFSD_INO_T ino64_t
@@ -345,7 +319,7 @@ int *dir_for_V = NULL;              /* Array: dir of each cache file.
                                 * -2: file exists in top-level
                                 * >=0: file exists in Dxxx
                                 */
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
 AFSD_INO_T *inode_for_V;       /* Array of inodes for desired
                                 * cache files */
 #endif
@@ -355,43 +329,50 @@ int missing_CellInfoFile = 1;     /*Is the CELLINFOFILE missing? */
 int afsd_rmtsys = 0;           /* Default: don't support rmtsys */
 struct afs_cacheParams cparams;        /* params passed to cache manager */
 
-static int HandleMTab(void);
 int PartSizeOverflow(char *path, int cs);
 
-#ifdef AFS_DARWIN_ENV
+#if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
+static void fork_rx_syscall_wait();
+#endif
+#if defined(AFS_SUN510_ENV) || defined(RXK_LISTENER_ENV)
+static void fork_rx_syscall();
+#endif
+static void fork_syscall();
+
+#if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
 static void
-afsd_sleep_callback(void * refCon, io_service_t service, 
+afsd_sleep_callback(void * refCon, io_service_t service,
                    natural_t messageType, void * messageArgument )
 {
     switch (messageType) {
     case kIOMessageCanSystemSleep:
-       /* Idle sleep is about to kick in; can 
-          prevent sleep by calling IOCancelPowerChange, otherwise 
+       /* Idle sleep is about to kick in; can
+          prevent sleep by calling IOCancelPowerChange, otherwise
           if we don't ack in 30s the system sleeps anyway */
-       
+
        /* allow it */
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
-       
+
     case kIOMessageSystemWillSleep:
        /* The system WILL go to sleep. Ack or suffer delay */
-       
+
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
-       
+
     case kIOMessageSystemWillRestart:
        /* The system WILL restart. Ack or suffer delay */
-       
+
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
-       
+
     case kIOMessageSystemWillPowerOn:
     case kIOMessageSystemHasPoweredOn:
        /* coming back from sleep */
-       
+
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
-       
+
     default:
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
@@ -415,10 +396,14 @@ afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
     if (code > 0) {
        /* Note we're refreshing */
        code = code | 0x40000000;
-       call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
+       afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
     } else
        printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
               reason);
+
+    /* Since it's likely this means our DNS server changed, reinit now */
+    if (enable_afsdb)
+       res_init();
 }
 
 /* This function is called when the system's ip addresses may have changed. */
@@ -434,15 +419,16 @@ afsd_ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *in
       CFRelease (timer);
 }
 
-static void 
+static void
 afsd_event_cleanup(int signo) {
 
     CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
     CFRelease (source);
+#ifndef AFS_ARM_DARWIN_ENV
     IODeregisterForSystemPower(&iterator);
     IOServiceClose(root_port);
     IONotificationPortDestroy(notify);
-
+#endif
     exit(0);
 }
 
@@ -453,58 +439,60 @@ afsd_install_events(void)
     SCDynamicStoreContext ctx = {0};
     SCDynamicStoreRef store;
 
+#ifndef AFS_ARM_DARWIN_ENV
     root_port = IORegisterForSystemPower(0,&notify,afsd_sleep_callback,&iterator);
-    
+
     if (root_port) {
        CFRunLoopAddSource(CFRunLoopGetCurrent(),
                           IONotificationPortGetRunLoopSource(notify),
                           kCFRunLoopDefaultMode);
     }
-    
-    
+
+
     store = SCDynamicStoreCreate (NULL,
                                  CFSTR ("AddIPAddressListChangeCallbackSCF"),
                                  afsd_ipaddr_callback, &ctx);
-    
+
     if (store) {
        const void *keys[1];
-       
+
        /* Request IPV4 address change notification */
        keys[0] = (SCDynamicStoreKeyCreateNetworkServiceEntity
                   (NULL, kSCDynamicStoreDomainState,
                    kSCCompAnyRegex, kSCEntNetIPv4));
-       
+
 #if 0
        /* This should tell us when the hostname(s) change. do we care? */
        keys[N] = SCDynamicStoreKeyCreateHostNames (NULL);
 #endif
-       
+
        if (keys[0] != NULL) {
            CFArrayRef pattern_array;
-           
+
            pattern_array = CFArrayCreate (NULL, keys, 1,
                                           &kCFTypeArrayCallBacks);
-           
+
            if (pattern_array != NULL)
            {
                SCDynamicStoreSetNotificationKeys (store, NULL, pattern_array);
                source = SCDynamicStoreCreateRunLoopSource (NULL, store, 0);
-               
+
                CFRelease (pattern_array);
            }
-           
+
            if (keys[0] != NULL)
                CFRelease (keys[0]);
        }
-       
-       CFRelease (store); 
+
+       CFRelease (store);
     }
-    
+#endif
+
     if (source != NULL) {
        CFRunLoopAddSource (CFRunLoopGetCurrent(),
                            source, kCFRunLoopDefaultMode);
     }
-    
+
     signal(SIGTERM, afsd_event_cleanup);
 
     CFRunLoopRun();
@@ -587,7 +575,7 @@ ParseCacheInfoFile(void)
         tbd++);
     /* now copy in the fields not explicitly overridden by cmd args */
     if (!sawCacheMountDir)
-       strcpy(cacheMountDir, tmd);
+       strcpy(afsd_cacheMountDir, tmd);
     if (!sawCacheBaseDir)
        strcpy(cacheBaseDir, tbd);
     if (!sawCacheBlocks)
@@ -607,8 +595,8 @@ ParseCacheInfoFile(void)
 }
 
 /*
- * All failures to open the partition are ignored. Also if the cache dir 
- * isn't a mounted partition it's also ignored since we can't guarantee 
+ * All failures to open the partition are ignored. Also if the cache dir
+ * isn't a mounted partition it's also ignored since we can't guarantee
  * what will be stored afterwards. Too many if's. This is now purely
  * advisory. ODS with over 2G partition also gives warning message.
  *
@@ -619,8 +607,9 @@ ParseCacheInfoFile(void)
 int
 PartSizeOverflow(char *path, int cs)
 {
-    int bsize = -1, totalblks, mint;
-#if AFS_HAVE_STATVFS
+  int bsize = -1;
+  afs_int64 totalblks, mint;
+#if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
     struct statvfs statbuf;
 
     if (statvfs(path, &statbuf) != 0) {
@@ -654,7 +643,7 @@ PartSizeOverflow(char *path, int cs)
     bsize = statbuf.f_bsize;
 #endif
     if (bsize == -1)
-       return 0;               /* sucess */
+       return 0;               /* success */
 
     /* now free and totalblks are in fragment units, but we want them in 1K units */
     if (bsize >= 1024) {
@@ -666,7 +655,7 @@ PartSizeOverflow(char *path, int cs)
     mint = totalblks / 100 * 95;
     if (cs > mint) {
        printf
-           ("Cache size (%d) must be less than 95%% of partition size (which is %d). Lower cache size\n",
+           ("Cache size (%d) must be less than 95%% of partition size (which is %lld). Lower cache size\n",
             cs, mint);
        return 1;
     }
@@ -799,8 +788,26 @@ CreateCacheSubDir(char *basename, int dirNum)
     return (0);
 }
 
+static void
+SetNoBackupAttr(char *fullpn)
+{
+#ifdef AFS_DARWIN80_ENV
+    int ret;
+
+    ret = setxattr(fullpn, "com.apple.metadata:com_apple_backup_excludeItem",
+                  "com.apple.backupd", strlen("com.apple.backupd"), 0,
+                  XATTR_CREATE);
+    if(ret < 0)
+    {
+       if(errno != EEXIST)
+           fprintf(stderr, "afsd: Warning: failed to set attribute to preclude cache backup: %s\n", strerror(errno));
+    }
+#endif
+    return;
+}
+
 static int
-MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile, 
+MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile,
              int maxDir)
 {
     static char rn[] = "MoveCacheFile";
@@ -832,6 +839,7 @@ MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile,
               from, to, ret, errno);
        return -1;
     }
+    SetNoBackupAttr(to);
 
     /* Reset directory pointer; fix file counts */
     dir_for_V[cacheFile] = toDir;
@@ -931,7 +939,7 @@ UnlinkUnwantedFile(char *rn, char *fullpn_FileToDelete, char *fileToDelete)
 
 
 static int
-doSweepAFSCache(int *vFilesFound, 
+doSweepAFSCache(int *vFilesFound,
                char *directory,        /* /path/to/cache/directory */
                int dirNum,             /* current directory number */
                int maxDir)             /* maximum directory number */
@@ -981,13 +989,13 @@ doSweepAFSCache(int *vFilesFound,
     {
        if (afsd_debug) {
            printf("%s: Current directory entry:\n", rn);
-#ifdef AFS_SGI62_ENV
+#if defined(AFS_SGI62_ENV) || defined(AFS_DARWIN90_ENV)
            printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n", currp->d_ino,
                   currp->d_reclen, currp->d_name);
-#elif defined(AFS_DFBSD_ENV)
-           printf("\tinode=%d, name='%s'\n", currp->d_ino, currp->d_name);
+#elif defined(AFS_DFBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
+           printf("\tinode=%ld, name='%s'\n", (long)currp->d_ino, currp->d_name);
 #else
-           printf("\tinode=%d, reclen=%d, name='%s'\n", currp->d_ino,
+           printf("\tinode=%ld, reclen=%d, name='%s'\n", (long)currp->d_ino,
                   currp->d_reclen, currp->d_name);
 #endif
        }
@@ -1007,7 +1015,7 @@ doSweepAFSCache(int *vFilesFound,
             * file's inode, directory, and bump the number of files found
             * total and in this directory.
             */
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
            inode_for_V[vFileNum] = currp->d_ino;
 #endif
            dir_for_V[vFileNum] = dirNum;       /* remember this directory */
@@ -1077,16 +1085,19 @@ doSweepAFSCache(int *vFilesFound,
             * Found the file holding the dcache entries.
             */
            missing_DCacheFile = 0;
+           SetNoBackupAttr(fullpn_DCacheFile);
        } else if (dirNum < 0 && strcmp(currp->d_name, VOLINFOFILE) == 0) {
            /*
             * Found the file holding the volume info.
             */
            missing_VolInfoFile = 0;
+           SetNoBackupAttr(fullpn_VolInfoFile);
        } else if (dirNum < 0 && strcmp(currp->d_name, CELLINFOFILE) == 0) {
            /*
             * Found the file holding the cell info.
             */
            missing_CellInfoFile = 0;
+           SetNoBackupAttr(fullpn_CellInfoFile);
        } else if ((strcmp(currp->d_name, ".") == 0)
                   || (strcmp(currp->d_name, "..") == 0) ||
 #ifdef AFS_DECOSF_ENV
@@ -1146,7 +1157,7 @@ doSweepAFSCache(int *vFilesFound,
                           vFileNum);
                else {
                    struct stat statb;
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
                    assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
 #endif
                    sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
@@ -1159,13 +1170,14 @@ doSweepAFSCache(int *vFilesFound,
                    if (CreateCacheFile(fullpn_VFile, &statb))
                        printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
                    else {
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
                        inode_for_V[vFileNum] = statb.st_ino;
 #endif
                        dir_for_V[vFileNum] = thisDir;
                        cache_dir_list[thisDir]++;
                        (*vFilesFound)++;
                    }
+                   SetNoBackupAttr(fullpn_VFile);
                }
 
            } else if (dir_for_V[vFileNum] >= maxDir
@@ -1261,7 +1273,7 @@ CheckCacheBaseDir(char *dir)
        if (res != 0) {
            return "unable to statfs cache base directory";
        }
-#if !defined(LINUX_USE_FH)
+#if !defined(AFS_LINUX26_ENV)
        if (statfsbuf.f_type == 0x52654973) {   /* REISERFS_SUPER_MAGIC */
            return "cannot use reiserfs as cache partition";
        } else if (statfsbuf.f_type == 0x58465342) {    /* XFS_SUPER_MAGIC */
@@ -1400,9 +1412,11 @@ ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
 
     /* figure out if this is the home cell */
     isHomeCell = (strcmp(aci->name, LclCellName) == 0);
-    if (!isHomeCell)
+    if (!isHomeCell) {
        cellFlags = 2;          /* not home, suid is forbidden */
-
+       if (enable_dynroot == 2)
+           cellFlags |= 8; /* don't display foreign cells until looked up */
+    }
     /* build address list */
     for (i = 0; i < MAXHOSTSPERCELL; i++)
        memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
@@ -1412,7 +1426,7 @@ ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
                                 * for upwards compatibility */
 
     /* configure one cell */
-    code = call_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */
+    code = afsd_call_syscall(AFSOP_ADDCELL2, hosts,    /* server addresses */
                        aci->name,      /* cell name */
                        cellFlags,      /* is this the home cell? */
                        aci->linkedCell);       /* Linked cell, if any */
@@ -1426,11 +1440,10 @@ ConfigCellAlias(struct afsconf_cellalias *aca,
                void *arock, struct afsconf_dir *adir)
 {
     /* push the alias into the kernel */
-    call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
+    afsd_call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
     return 0;
 }
 
-#ifdef AFS_AFSDB_ENV
 static void
 AfsdbLookupHandler(void)
 {
@@ -1449,7 +1462,7 @@ AfsdbLookupHandler(void)
     code = fork();
     if (code == 0) {
        afsd_install_events();
-       exit(1);
+       return;
     } else if (code != -1) {
        event_pid = code;
     }
@@ -1458,7 +1471,7 @@ AfsdbLookupHandler(void)
        /* On some platforms you only get 4 args to an AFS call */
        int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
        code =
-           call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
+           afsd_call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
        if (code) {             /* Something is wrong? */
            sleep(1);
            continue;
@@ -1486,49 +1499,170 @@ AfsdbLookupHandler(void)
 #ifdef AFS_DARWIN_ENV
     kill(event_pid, SIGTERM);
 #endif
-    exit(1);
 }
-#endif
 
-#ifdef mac2
-#include <sys/ioctl.h>
-#endif /* mac2 */
+#ifdef AFS_DARWIN_ENV
+static void
+BkgHandler(void)
+{
+    afs_int32 code;
+    struct afs_uspc_param *uspc;
+    char srcName[256];
+    char dstName[256];
 
-#ifdef AFS_SGI65_ENV
-#define SET_RTPRI(P) {  \
-    struct sched_param sp; \
-    sp.sched_priority = P; \
-    if (sched_setscheduler(0, SCHED_RR, &sp)<0) { \
-       perror("sched_setscheduler"); \
-    } \
+    uspc = (struct afs_uspc_param *)malloc(sizeof(struct afs_uspc_param));
+    memset(uspc, 0, sizeof(struct afs_uspc_param));
+    memset(srcName, 0, sizeof(srcName));
+    memset(dstName, 0, sizeof(dstName));
+
+    /* brscount starts at 0 */
+    uspc->ts = -1;
+
+    while (1) {
+       pid_t child = 0;
+       int status;
+       char srcpath[BUFSIZ];
+       char dstpath[BUFSIZ];
+
+       /* pushing in a buffer this large */
+       uspc->bufSz = 256;
+
+       code = afsd_call_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName);
+       if (code) {             /* Something is wrong? */
+           if (code == -2) /* shutting down */
+               break;
+
+           sleep(1);
+           uspc->retval = -1;
+           continue;
+       }
+
+       switch (uspc->reqtype) {
+       case AFS_USPC_UMV:
+           snprintf(srcpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
+                    uspc->req.umv.sCell, uspc->req.umv.sVolume,
+                    uspc->req.umv.sVnode, uspc->req.umv.sUnique, srcName);
+           snprintf(dstpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
+                    uspc->req.umv.dCell, uspc->req.umv.dVolume,
+                    uspc->req.umv.dVnode, uspc->req.umv.dUnique, dstName);
+           if ((child = fork()) == 0) {
+               /* first child does cp; second, rm. mv would re-enter. */
+
+               switch (uspc->req.umv.idtype) {
+               case IDTYPE_UID:
+                   if (setuid(uspc->req.umv.id) != 0) {
+                       exit(-1);
+                   }
+                   break;
+               default:
+                   exit(-1);
+                   break; /* notreached */
+               }
+               execl("/bin/cp", "(afsd EXDEV helper)", "-PRp", "--", srcpath,
+                     dstpath, (char *) NULL);
+           }
+           if (child == (pid_t) -1) {
+               uspc->retval = -1;
+               continue;
+           }
+
+           if (waitpid(child, &status, 0) == -1)
+               uspc->retval = EIO;
+           else if (WIFEXITED(status) != 0 && WEXITSTATUS(status) == 0) {
+               if ((child = fork()) == 0) {
+                   switch (uspc->req.umv.idtype) {
+                   case IDTYPE_UID:
+                       if (setuid(uspc->req.umv.id) != 0) {
+                           exit(-1);
+                       }
+                       break;
+                   default:
+                       exit(-1);
+                       break; /* notreached */
+                   }
+                   execl("/bin/rm", "(afsd EXDEV helper)", "-rf", "--",
+                         srcpath, (char *) NULL);
+               }
+               if (child == (pid_t) -1) {
+                   uspc->retval = -1;
+                   continue;
+               }
+               if (waitpid(child, &status, 0) == -1)
+                   uspc->retval = EIO;
+               else if (WIFEXITED(status) != 0) {
+                   /* rm exit status */
+                   uspc->retval = WEXITSTATUS(status);
+               } else {
+                   /* rm signal status */
+                   uspc->retval = -(WTERMSIG(status));
+               }
+           } else {
+               /* error from cp: exit or signal status */
+               uspc->retval = (WIFEXITED(status) != 0) ?
+                   WEXITSTATUS(status) : -(WTERMSIG(status));
+           }
+           memset(srcName, 0, sizeof(srcName));
+           memset(dstName, 0, sizeof(dstName));
+           break;
+
+       default:
+           /* unknown req type */
+           uspc->retval = -1;
+           break;
+       }
+    }
 }
-#define SET_AFSD_RTPRI() SET_RTPRI(68)
-#define SET_RX_RTPRI()   SET_RTPRI(199)
-#else
-#ifdef AFS_LINUX20_ENV
-#define SET_AFSD_RTPRI()
-#define SET_RX_RTPRI() do { if (setpriority(PRIO_PROCESS, 0, -10)<0) \
-                          perror("setting rx priority"); \
-                        } while (0)
-#else
-#define SET_AFSD_RTPRI()
-#define SET_RX_RTPRI()
 #endif
+
+static void *
+afsdb_thread(void *rock)
+{
+    /* Since the AFSDB lookup handler runs as a user process,
+     * need to drop the controlling TTY, etc.
+     */
+    if (afsd_daemon(0, 0) == -1) {
+       printf("Error starting AFSDB lookup handler: %s\n",
+              strerror(errno));
+       exit(1);
+    }
+    AfsdbLookupHandler();
+    return NULL;
+}
+
+static void *
+daemon_thread(void *rock)
+{
+#ifdef AFS_DARWIN80_ENV
+    /* Since the background daemon runs as a user process,
+     * need to drop the controlling TTY, etc.
+     */
+    if (afsd_daemon(0, 0) == -1) {
+       printf("Error starting background daemon: %s\n",
+              strerror(errno));
+       exit(1);
+    }
+    BkgHandler();
+#elif defined(AFS_AIX32_ENV)
+    afsd_call_syscall(AFSOP_START_BKG, 0);
+#else
+    afsd_call_syscall(AFSOP_START_BKG);
 #endif
+    return NULL;
+}
+
+#ifndef UKERNEL
+static void *
+rmtsysd_thread(void *rock)
+{
+    rmtsysd();
+    return NULL;
+}
+#endif /* !UKERNEL */
 
 int
 mainproc(struct cmd_syndesc *as, void *arock)
 {
-    static char rn[] = "afsd"; /*Name of this routine */
     afs_int32 code;            /*Result of fork() */
-    int i;
-    int currVFile;             /*Current AFS cache file number passed in */
-    int mountFlags;            /*Flags passed to mount() */
-    int lookupResult;          /*Result of GetLocalCellName() */
-    int cacheIteration;                /*How many times through cache verification */
-    int vFilesFound;           /*How many data cache files were found in sweep */
-    struct afsconf_dir *cdir;  /* config dir */
-    char *fsTypeMsg = NULL;
 #ifdef AFS_SUN5_ENV
     struct stat st;
 #endif
@@ -1577,7 +1711,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
     if (as->parms[6].items) {
        /* -mountdir */
-       strcpy(cacheMountDir, as->parms[6].items->data);
+       strcpy(afsd_cacheMountDir, as->parms[6].items->data);
        sawCacheMountDir = 1;
     }
     if (as->parms[7].items) {
@@ -1586,7 +1720,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
     if (as->parms[8].items) {
        /* -nosettime */
-       cacheSetTime = FALSE;
+       cacheSetTime = 0;
     }
     if (as->parms[9].items) {
        /* -verbose */
@@ -1595,6 +1729,10 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (as->parms[10].items) {
        /* -rmtsys */
        afsd_rmtsys = 1;
+#ifdef UKERNEL
+       printf("-rmtsys not supported for UKERNEL\n");
+       return -1;
+#endif
     }
     if (as->parms[11].items) {
        /* -debug */
@@ -1633,12 +1771,6 @@ mainproc(struct cmd_syndesc *as, void *arock)
        /* -prealloc */
        preallocs = atoi(as->parms[16].items->data);
     }
-#ifdef notdef
-    if (as->parms[17].items) {
-       /* -pininodes */
-       inodes = atoi(as->parms[17].items->data);
-    }
-#endif
     strcpy(confDir, AFSDIR_CLIENT_ETC_DIRPATH);
     if (as->parms[17].items) {
        /* -confdir */
@@ -1656,11 +1788,11 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (as->parms[20].items) {
        /* -shutdown */
        afs_shutdown = 1;
-       /* 
+       /*
         * Cold shutdown is the default
         */
        printf("afsd: Shutting down all afs processes and afs state\n");
-       code = call_syscall(AFSOP_SHUTDOWN, 1);
+       code = afsd_call_syscall(AFSOP_SHUTDOWN, 1);
        if (code) {
            printf("afsd: AFS still mounted; Not shutting down\n");
            exit(1);
@@ -1677,15 +1809,11 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
     if (as->parms[23].items) {
        /* -mem_alloc_sleep */
-       cacheFlags |= AFSCALL_INIT_MEMCACHE_SLEEP;
+       printf("afsd: -mem_alloc_sleep is deprecated -- ignored\n");
     }
     if (as->parms[24].items) {
        /* -afsdb */
-#ifdef AFS_AFSDB_ENV
        enable_afsdb = 1;
-#else
-       printf("afsd: No AFSDB support; ignoring -afsdb");
-#endif
     }
     if (as->parms[25].items) {
        /* -files_per_subdir */
@@ -1724,7 +1852,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
     if (as->parms[32].items) {
        /* -settime */
-       cacheSetTime = TRUE;
+       cacheSetTime = 1;
     }
 
     /* set rx_extraPackets */
@@ -1732,7 +1860,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
        /* -rxpck */
        int rxpck = atoi(as->parms[33].items->data);
        printf("afsd: set rxpck = %d\n", rxpck);
-       code = call_syscall(AFSOP_SET_RXPCK, rxpck);
+       code = afsd_call_syscall(AFSOP_SET_RXPCK, rxpck);
        if (code) {
            printf("afsd: failed to set rxpck\n");
            exit(1);
@@ -1757,7 +1885,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (as->parms[35].items) {
 #ifdef AFS_MAXVCOUNT_ENV
        /* -disable-dynamic-vcaches */
-       afsd_dynamic_vcaches = FALSE;
+       afsd_dynamic_vcaches = 0;
 #else
        printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n");
        exit(1);
@@ -1766,7 +1894,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
 #ifdef AFS_MAXVCOUNT_ENV
     else {
        /* -dynamic-vcaches */
-       afsd_dynamic_vcaches = TRUE;
+       afsd_dynamic_vcaches = 1;
     }
 
     if (afsd_verbose)
@@ -1774,12 +1902,32 @@ mainproc(struct cmd_syndesc *as, void *arock)
 #endif
 
     /* set -rxmaxmtu */
-    if (as->parms[35].items) {
+    if (as->parms[36].items) {
         /* -rxmaxmtu */
-        rxmaxmtu = atoi(as->parms[35].items->data);
+        rxmaxmtu = atoi(as->parms[36].items->data);
     }
+    if (as->parms[37].items) {
+       /* -dynroot-sparse */
+       enable_dynroot = 2;
+    }
+    return 0;
+}
 
-    /*
+int
+afsd_run(void)
+{
+    static char rn[] = "afsd"; /*Name of this routine */
+    struct afsconf_dir *cdir;  /* config dir */
+    struct stat statbuf;
+    int lookupResult;          /*Result of GetLocalCellName() */
+    int i;
+    afs_int32 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 */
+    int currVFile;             /*Current AFS cache file number passed in */
+
+       /*
      * Pull out all the configuration info for the workstation's AFS cache and
      * the cellular community we're willing to let our users see.
      */
@@ -1804,6 +1952,16 @@ mainproc(struct cmd_syndesc *as, void *arock)
        exit(1);
     }
 
+    if (stat(afsd_cacheMountDir, &statbuf)) {
+       printf("afsd: Mountpoint %s missing.\n", afsd_cacheMountDir);
+        exit(1);
+    } else {
+       if (!S_ISDIR(statbuf.st_mode)) {
+           printf("afsd: Mountpoint %s is not a directory.\n", afsd_cacheMountDir);
+           exit(1);
+       }
+    }
+
     /* do some random computations in memcache case to get things to work
      * reasonably no matter which parameters you set.
      */
@@ -1863,7 +2021,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
        /* Disk cache:
         * Compute the number of cache files based on cache size,
         * but only if -files isn't given on the command line.
-        * Don't let # files be so small as to prevent full utilization 
+        * Don't let # files be so small as to prevent full utilization
         * of the cache unless user has explicitly asked for it.
         */
        if (chunkSize == 0) {
@@ -1881,7 +2039,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
 
            cacheFiles = max(cacheFiles, 1000);
 
-           /* Always allow more files than chunks.  Presume average V-file 
+           /* Always allow more files than chunks.  Presume average V-file
             * is ~67% of a chunk...  (another guess, perhaps Honeyman will
             * have a grad student write a paper).  i is KILOBYTES.
             */
@@ -1919,7 +2077,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
        /* This actually needs to
           1) use powers of 2
           2) not second-guess when a chunksize comes from the command line
-          3) be less, um, small. 2^2?? 
+          3) be less, um, small. 2^2??
        */
        /* Sanity check chunkSize */
        i = max(cacheBlocks / 1000, cacheBlocks / cacheFiles);
@@ -1954,7 +2112,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
                   cacheStatEntries);
     }
 
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
     /*
      * Create and zero the inode table for the desired cache files.
      */
@@ -1997,6 +2155,11 @@ mainproc(struct cmd_syndesc *as, void *arock)
     setpgrp(getpid(), 0);
 #endif /* mac2 */
 
+    /*
+     * Set the primary cell name.
+     */
+    afsd_call_syscall(AFSOP_SET_THISCELL, LclCellName);
+
     /* Initialize RX daemons and services */
 
     /* initialize the rx random number generator from user space */
@@ -2012,14 +2175,14 @@ mainproc(struct cmd_syndesc *as, void *arock)
        if (code > 0) {
            if (enable_rxbind)
                code = code | 0x80000000;
-           call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
+               afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
        } else
            printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
                   reason);
     }
 
     /* Set realtime priority for most threads to same as for biod's. */
-    SET_AFSD_RTPRI();
+    afsd_set_afsd_rtpri();
 
 #ifdef AFS_SGI53_ENV
 #ifdef AFS_SGI61_ENV
@@ -2027,7 +2190,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
 #else /* AFS_SGI61_ENV */
     code = get_nfsstaticaddr();
     if (code)
-       call_syscall(AFSOP_NFSSTATICADDR, code);
+       afsd_call_syscall(AFSOP_NFSSTATICADDR, code);
 #endif /* AFS_SGI61_ENV */
 #endif /* AFS_SGI_53_ENV */
 
@@ -2042,59 +2205,29 @@ mainproc(struct cmd_syndesc *as, void *arock)
 #ifdef RXK_LISTENER_ENV
     if (afsd_verbose)
        printf("%s: Forking rx listener daemon.\n", rn);
-    code = fork();
-    if (code == 0) {
-       /* Child */
-       SET_RX_RTPRI();         /* max advised for non-interrupts */
-       call_syscall(AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats,
-                    enable_process_stats);
-       exit(1);
-    }
-#ifdef AFS_SUN510_ENV
-    waitpid((pid_t) -1, NULL, 0);
-#endif
+# ifdef AFS_SUN510_ENV
+    fork_rx_syscall_wait(rn, AFSOP_RXLISTENER_DAEMON, preallocs,
+                         enable_peer_stats, enable_process_stats);
+# else /* !AFS_SUN510_ENV */
+    fork_rx_syscall(rn, AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats,
+                    enable_process_stats);
+# endif /* !AFS_SUN510_ENV */
 #endif
     if (afsd_verbose)
        printf("%s: Forking rx callback listener.\n", rn);
-    code = fork();
-    if (code == 0) {
-       /* Child */
-       call_syscall(AFSOP_START_RXCALLBACK, preallocs);
-       exit(1);
-    }
+    fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs);
 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
     if (afsd_verbose)
        printf("%s: Forking rxevent daemon.\n", rn);
-    code = fork();
-    if (code == 0) {
-       /* Child */
-       SET_RX_RTPRI();         /* max advised for non-interrupts */
-       call_syscall(AFSOP_RXEVENT_DAEMON);
-       exit(1);
-    }
+    fork_rx_syscall(rn, AFSOP_RXEVENT_DAEMON);
 #endif
 
-#ifdef AFS_AFSDB_ENV
     if (enable_afsdb) {
        if (afsd_verbose)
            printf("%s: Forking AFSDB lookup handler.\n", rn);
-       code = fork();
-       if (code == 0) {
-           /* Since the AFSDB lookup handler runs as a user process, 
-            * need to drop the controlling TTY, etc.
-            */
-           if (daemon(0, 0) == -1) {
-               printf("Error starting AFSDB lookup handler: %s\n",
-                      strerror(errno));
-               exit(1);
-           }
-           AfsdbLookupHandler();
-           exit(1);
-       }
+       afsd_fork(0, afsdb_thread, NULL);
     }
-#endif
-
-    code = call_syscall(AFSOP_BASIC_INIT, 1);
+    code = afsd_call_syscall(AFSOP_BASIC_INIT, 1);
     if (code) {
        printf("%s: Error %d in basic initialization.\n", rn, code);
         exit(1);
@@ -2118,19 +2251,16 @@ mainproc(struct cmd_syndesc *as, void *arock)
     cparams.setTimeFlag = cacheSetTime;
     cparams.memCacheFlag = cacheFlags;
     cparams.dynamic_vcaches = afsd_dynamic_vcaches;
-#ifdef notdef
-    cparams.inodes = inodes;
-#endif
-    call_syscall(AFSOP_CACHEINIT, &cparams);
+       afsd_call_syscall(AFSOP_CACHEINIT, &cparams);
 
     /* do it before we init the cache inodes */
     if (enable_splitcache) {
-       call_syscall(AFSOP_BUCKETPCT, 1, rwpct);
-       call_syscall(AFSOP_BUCKETPCT, 2, ropct);
+       afsd_call_syscall(AFSOP_BUCKETPCT, 1, rwpct);
+       afsd_call_syscall(AFSOP_BUCKETPCT, 2, ropct);
     }
 
     if (afsd_CloseSynch)
-       call_syscall(AFSOP_CLOSEWAIT);
+       afsd_call_syscall(AFSOP_CLOSEWAIT);
 
     /*
      * Sweep the workstation AFS cache directory, remembering the inodes of
@@ -2159,28 +2289,11 @@ mainproc(struct cmd_syndesc *as, void *arock)
                     rn, vFilesFound, cacheFiles, cacheIteration);
        } while ((vFilesFound < cacheFiles)
                 && (cacheIteration < MAX_CACHE_LOOPS));
-#ifdef AFS_CACHE_VNODE_PATH
-       if (afsd_debug)
-           printf
-               ("%s: Calling AFSOP_CACHEBASEDIR with '%s'\n",
-                rn, cacheBaseDir);
-       call_syscall(AFSOP_CACHEBASEDIR, cacheBaseDir);
-       if (afsd_debug)
-           printf
-               ("%s: Calling AFSOP_CACHEDIRS with %d dirs\n",
-                rn, nFilesPerDir);
-       call_syscall(AFSOP_CACHEDIRS, nFilesPerDir);
-       if (afsd_debug)
-           printf
-               ("%s: Calling AFSOP_CACHEFILES with %d files\n",
-                rn, cacheFiles);
-       call_syscall(AFSOP_CACHEFILES, cacheFiles);
-#endif
     } else if (afsd_verbose)
        printf("%s: Using memory cache, not swept\n", rn);
 
     /*
-     * Pass the kernel the name of the workstation cache file holding the 
+     * Pass the kernel the name of the workstation cache file holding the
      * dcache entries.
      */
     if (afsd_debug)
@@ -2188,7 +2301,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
               fullpn_DCacheFile);
     /* once again, meaningless for a memory-based cache. */
     if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
-       call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
+       afsd_call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
 
     /*
      * Pass the kernel the name of the workstation cache file holding the
@@ -2197,28 +2310,31 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (afsd_debug)
        printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
               fullpn_CellInfoFile);
-    call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
+       afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
 
     if (rxmaxmtu) {
-    if (afsd_verbose)
-        printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
-    code = call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
-    if (code)
-        printf("%s: Error seting rxmaxmtu\n", rn);
+       if (afsd_verbose)
+            printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
+       code = afsd_call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
+        if (code)
+            printf("%s: Error seting rxmaxmtu\n", rn);
     }
 
     if (enable_dynroot) {
        if (afsd_verbose)
-           printf("%s: Enabling dynroot support in kernel.\n", rn);
-       code = call_syscall(AFSOP_SET_DYNROOT, 1);
+           printf("%s: Enabling dynroot support in kernel%s.\n", rn,
+                  (enable_dynroot==2)?", not showing cells.":"");
+       code = afsd_call_syscall(AFSOP_SET_DYNROOT, 1);
        if (code)
            printf("%s: Error enabling dynroot support.\n", rn);
     }
 
     if (enable_fakestat) {
        if (afsd_verbose)
-           printf("%s: Enabling fakestat support in kernel.\n", rn);
-       code = call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
+           printf("%s: Enabling fakestat support in kernel%s.\n", rn,
+                  (enable_fakestat==2)?" for all mountpoints."
+                  :" for crosscell mountpoints");
+       code = afsd_call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
        if (code)
            printf("%s: Error enabling fakestat support.\n", rn);
     }
@@ -2226,7 +2342,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (enable_backuptree) {
        if (afsd_verbose)
            printf("%s: Enabling backup tree support in kernel.\n", rn);
-       code = call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
+       code = afsd_call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
        if (code)
            printf("%s: Error enabling backup tree support.\n", rn);
     }
@@ -2237,31 +2353,14 @@ mainproc(struct cmd_syndesc *as, void *arock)
     afsconf_CellApply(cdir, ConfigCell, NULL);
     afsconf_CellAliasApply(cdir, ConfigCellAlias, NULL);
 
-    /*
-     * Set the primary cell name.
-     */
-    call_syscall(AFSOP_SET_THISCELL, LclCellName);
-
     /* Initialize AFS daemon threads. */
     if (afsd_verbose)
        printf("%s: Forking AFS daemon.\n", rn);
-    code = fork();
-    if (code == 0) {
-       /* Child */
-       call_syscall(AFSOP_START_AFS);
-       exit(1);
-    }
+    fork_syscall(rn, AFSOP_START_AFS);
 
     if (afsd_verbose)
        printf("%s: Forking Check Server Daemon.\n", rn);
-    code = fork();
-    if (code == 0) {
-       /* Child */
-       code = call_syscall(AFSOP_START_CS);
-       if (code)
-           printf("%s: No check server daemon in client.\n", rn);
-       exit(1);
-    }
+    fork_syscall(rn, AFSOP_START_CS);
 
     if (afsd_verbose)
        printf("%s: Forking %d background daemons.\n", rn, nDaemons);
@@ -2272,16 +2371,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     nDaemons++;
 #endif
     for (i = 0; i < nDaemons; i++) {
-       code = fork();
-       if (code == 0) {
-           /* Child */
-#ifdef AFS_AIX32_ENV
-           call_syscall(AFSOP_START_BKG, 0);
-#else
-           call_syscall(AFSOP_START_BKG);
-#endif
-           exit(1);
-       }
+       afsd_fork(0, daemon_thread, NULL);
     }
 #ifdef AFS_AIX32_ENV
     if (!sawBiod)
@@ -2289,11 +2379,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (nBiods < 5)
        nBiods = 5;
     for (i = 0; i < nBiods; i++) {
-       code = fork();
-       if (code == 0) {        /* Child */
-           call_syscall(AFSOP_START_BKG, nBiods);
-           exit(1);
-       }
+       fork_syscall(rn, AFSOP_START_BKG, nBiods);
     }
 #endif
 
@@ -2304,7 +2390,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
        if (afsd_verbose)
            printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn,
                   rootVolume);
-       call_syscall(AFSOP_ROOTVOLUME, rootVolume);
+       afsd_call_syscall(AFSOP_ROOTVOLUME, rootVolume);
     }
 
     /*
@@ -2316,34 +2402,55 @@ mainproc(struct cmd_syndesc *as, void *arock)
               fullpn_VolInfoFile);
     /* once again, meaningless for a memory-based cache. */
     if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
-       call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
+       afsd_call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
 
-#ifndef AFS_CACHE_VNODE_PATH
     /*
      * Give the kernel the names of the AFS files cached on the workstation's
      * disk.
      */
     if (afsd_debug)
        printf
-           ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
+           ("%s: Calling AFSOP_CACHEFILE for each of the %d files in '%s'\n",
             rn, cacheFiles, cacheBaseDir);
-    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... and again ... */
+    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
+       /* ... and again ... */
+       int nocachefile = 0;
        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);
+               if (code) {
+                   if (currVFile == 0) {
+                       if (afsd_debug)
+                           printf
+                               ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
+                                rn, cacheFiles, cacheBaseDir);
+                       nocachefile = 1;
+                   } else {
+                       printf
+                           ("%s: Error calling AFSOP_CACHEFILE for '%s'\n",
+                            rn, fullpn_VFile);
+                       exit(1);
+                   }
+               } else {
+                   continue;
+               }
+               /* fall through to setup-by-inode */
+           }
 #ifdef AFS_SGI62_ENV
-           call_syscall(AFSOP_CACHEINODE,
+           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]);
 #else
-#if defined(LINUX_USE_FH)
-           sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
-           call_syscall(AFSOP_CACHEFILE, fullpn_VFile);
-#else
-           call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
-#endif
+           printf
+               ("%s: Error calling AFSOP_CACHEINODE: not configured\n",
+                rn);
+           exit(1);
 #endif
        }
-#endif
-
+    }
     /*end for */
     /*
      * All the necessary info has been passed into the kernel to run an AFS
@@ -2352,96 +2459,45 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (afsd_debug)
        printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
               cacheSetTime);
-    call_syscall(AFSOP_GO, cacheSetTime);
+       afsd_call_syscall(AFSOP_GO, cacheSetTime);
 
     /*
-     * At this point, we have finished passing the kernel all the info 
+     * At this point, we have finished passing the kernel all the info
      * it needs to set up the AFS.  Mount the AFS root.
      */
     printf("%s: All AFS daemons started.\n", rn);
 
     if (afsd_verbose)
        printf("%s: Forking trunc-cache daemon.\n", rn);
-    code = fork();
-    if (code == 0) {
-       /* Child */
-       call_syscall(AFSOP_START_TRUNCDAEMON);
-       exit(1);
-    }
+    fork_syscall(rn, AFSOP_START_TRUNCDAEMON);
 
     if (!enable_nomount) {
-
-       mountFlags = 0;         /* Read/write file system, can do setuid() */
-#if    defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
-#ifdef AFS_SUN5_ENV
-       mountFlags |= MS_DATA;
-#else
-       mountFlags |= M_NEWTYPE;        /* This searches by name in vfs_conf.c so don't need to recompile vfs.c because MOUNT_MAXTYPE has changed; it seems that Sun fixed this at last... */
-#endif
-#endif
-
-#if defined(AFS_HPUX100_ENV)
-       mountFlags |= MS_DATA;
-#endif
-
-       if (afsd_verbose)
-           printf("%s: Mounting the AFS root on '%s', flags: %d.\n", rn,
-                  cacheMountDir, mountFlags);
-#if defined(AFS_FBSD60_ENV)
-       /* data must be non-NULL but is otherwise ignored */
-       if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, rn)) < 0) {
-#elif defined(AFS_FBSD_ENV)
-       if ((mount("AFS", cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
-#elif defined(AFS_AIX_ENV)
-       if (aix_vmount()) {
-#elif defined(AFS_HPUX100_ENV)
-       if ((mount("", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
-#elif defined(AFS_SUN5_ENV)
-       if ((mount("AFS", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
-#elif defined(AFS_SGI_ENV)
-       mountFlags = MS_FSS;
-       if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) MOUNT_AFS))
-           < 0) {
-#elif defined(AFS_LINUX20_ENV)
-       if ((mount("AFS", cacheMountDir, MOUNT_AFS, 0, NULL)) < 0) {
-#else
-/* This is the standard mount used by the suns and rts */
-       if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
-#endif
-           printf("%s: Can't mount AFS on %s(%d)\n", rn, cacheMountDir,
-                  errno);
-           exit(1);
-       }
-
-       HandleMTab();
-
+       afsd_mount_afs(rn, afsd_cacheMountDir);
     }
 
+#ifndef UKERNEL
     if (afsd_rmtsys) {
        if (afsd_verbose)
            printf("%s: Forking 'rmtsys' daemon.\n", rn);
-       code = fork();
-       if (code == 0) {
-           /* Child */
-           rmtsysd();
-           exit(1);
-       }
+       afsd_fork(0, rmtsysd_thread, NULL);
     }
+#endif /* !UKERNEL */
     /*
      * Exit successfully.
      */
-    exit(0);
+    return 0;
 }
 
 #include "AFS_component_version_number.c"
 
-
-int
-main(int argc, char **argv)
+void
+afsd_init(void)
 {
     struct cmd_syndesc *ts;
 
     ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
+
+    /* 0 - 10 */
     cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
                "1024 byte blocks in cache");
     cmd_AddParm(ts, "-files", CMD_SINGLE, CMD_OPTIONAL, "files in cache");
@@ -2460,6 +2516,8 @@ main(int argc, char **argv)
                "display lots of information");
     cmd_AddParm(ts, "-rmtsys", CMD_FLAG, CMD_OPTIONAL,
                "start NFS rmtsysd program");
+
+    /* 11 - 20 */
     cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "display debug info");
     cmd_AddParm(ts, "-chunksize", CMD_SINGLE, CMD_OPTIONAL,
                "log(2) of chunk size");
@@ -2469,13 +2527,8 @@ main(int argc, char **argv)
                "number of volume entries");
     cmd_AddParm(ts, "-biods", CMD_SINGLE, CMD_OPTIONAL,
                "number of bkg I/O daemons (aix vm)");
-
     cmd_AddParm(ts, "-prealloc", CMD_SINGLE, CMD_OPTIONAL,
                "number of 'small' preallocated blocks");
-#ifdef notdef
-    cmd_AddParm(ts, "-pininodes", CMD_SINGLE, CMD_OPTIONAL,
-               "number of inodes to hog");
-#endif
     cmd_AddParm(ts, "-confdir", CMD_SINGLE, CMD_OPTIONAL,
                "configuration directory");
     cmd_AddParm(ts, "-logfile", CMD_SINGLE, CMD_OPTIONAL,
@@ -2484,6 +2537,7 @@ main(int argc, char **argv)
                "make close calls synchronous");
     cmd_AddParm(ts, "-shutdown", CMD_FLAG, CMD_OPTIONAL,
                "Shutdown all afs state");
+    /* 21 - 30 */
     cmd_AddParm(ts, "-enable_peer_stats", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
                "Collect rpc statistics by peer");
     cmd_AddParm(ts, "-enable_process_stats", CMD_FLAG,
@@ -2491,11 +2545,8 @@ main(int argc, char **argv)
                "Collect rpc statistics for this process");
     cmd_AddParm(ts, "-mem_alloc_sleep", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE),
                "Allow sleeps when allocating memory cache");
-    cmd_AddParm(ts, "-afsdb", CMD_FLAG, (CMD_OPTIONAL
-#ifndef AFS_AFSDB_ENV
-                                        | CMD_HIDE
-#endif
-               ), "Enable AFSDB support");
+    cmd_AddParm(ts, "-afsdb", CMD_FLAG, (CMD_OPTIONAL),
+               "Enable AFSDB support");
     cmd_AddParm(ts, "-files_per_subdir", CMD_SINGLE, CMD_OPTIONAL,
                "log(2) of the number of cache files per cache subdirectory");
     cmd_AddParm(ts, "-dynroot", CMD_FLAG, CMD_OPTIONAL,
@@ -2507,6 +2558,7 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-nomount", CMD_FLAG, CMD_OPTIONAL, "Do not mount AFS");
     cmd_AddParm(ts, "-backuptree", CMD_FLAG, CMD_OPTIONAL,
                "Prefer backup volumes for mointpoints in backup volumes");
+    /* 31 - 40 */
     cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
                "Bind the Rx socket (one interface only)");
     cmd_AddParm(ts, "-settime", CMD_FLAG, CMD_OPTIONAL, "set the time");
@@ -2514,278 +2566,18 @@ main(int argc, char **argv)
                "set rx_extraPackets to this value");
     cmd_AddParm(ts, "-splitcache", CMD_SINGLE, CMD_OPTIONAL,
                "Percentage RW versus RO in cache (specify as 60/40)");
-    cmd_AddParm(ts, "-disable-dynamic-vcaches", CMD_FLAG, CMD_OPTIONAL, 
+    cmd_AddParm(ts, "-disable-dynamic-vcaches", CMD_FLAG, CMD_OPTIONAL,
                "disable stat/vcache cache growing as needed");
     cmd_AddParm(ts, "-rxmaxmtu", CMD_SINGLE, CMD_OPTIONAL, "set rx max MTU to use");
-    
-    return (cmd_Dispatch(argc, argv));
-}
-
-
-#ifdef AFS_HPUX_ENV
-#define        MOUNTED_TABLE   MNT_MNTTAB
-#else
-#ifdef AFS_SUN5_ENV
-#define        MOUNTED_TABLE   MNTTAB
-#else
-#define        MOUNTED_TABLE   MOUNTED
-#endif
-#endif
-
-static int
-HandleMTab(void)
-{
-#if (defined (AFS_SUN_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)) && !defined(AFS_SUN58_ENV)
-    FILE *tfilep;
-#ifdef AFS_SUN5_ENV
-    char tbuf[16];
-    struct mnttab tmntent;
-
-    memset(&tmntent, '\0', sizeof(struct mnttab));
-    if (!(tfilep = fopen(MOUNTED_TABLE, "a+"))) {
-       printf("Can't open %s\n", MOUNTED_TABLE);
-       perror(MNTTAB);
-       exit(-1);
-    }
-    tmntent.mnt_special = "AFS";
-    tmntent.mnt_mountp = cacheMountDir;
-    tmntent.mnt_fstype = "xx";
-    tmntent.mnt_mntopts = "rw";
-    sprintf(tbuf, "%ld", (long)time((time_t *) 0));
-    tmntent.mnt_time = tbuf;
-    putmntent(tfilep, &tmntent);
-    fclose(tfilep);
-#else
-#if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
-    struct mntent tmntent;
-
-    tfilep = setmntent("/etc/mtab", "a+");
-    tmntent.mnt_fsname = "AFS";
-    tmntent.mnt_dir = cacheMountDir;
-    tmntent.mnt_type = "afs";
-    tmntent.mnt_opts = "rw";
-    tmntent.mnt_freq = 1;
-    tmntent.mnt_passno = 3;
-    addmntent(tfilep, &tmntent);
-    endmntent(tfilep);
-#else
-    struct mntent tmntent;
-
-    memset(&tmntent, '\0', sizeof(struct mntent));
-    tfilep = setmntent(MOUNTED_TABLE, "a+");
-    if (!tfilep) {
-       printf("Can't open %s for write; Not adding afs entry to it\n",
-              MOUNTED_TABLE);
-       return 1;
-    }
-    tmntent.mnt_fsname = "AFS";
-    tmntent.mnt_dir = cacheMountDir;
-    tmntent.mnt_type = "xx";
-    tmntent.mnt_opts = "rw";
-    tmntent.mnt_freq = 1;
-    tmntent.mnt_passno = 3;
-#ifdef AFS_HPUX_ENV
-    tmntent.mnt_type = "afs";
-    tmntent.mnt_time = time(0);
-    tmntent.mnt_cnode = 0;
-#endif
-    addmntent(tfilep, &tmntent);
-    endmntent(tfilep);
-#endif /* AFS_SGI_ENV */
-#endif /* AFS_SUN5_ENV */
-#endif /* unreasonable systems */
-#ifdef AFS_DARWIN_ENV
-#ifndef AFS_DARWIN100_ENV
-    mach_port_t diskarb_port;
-    kern_return_t status;
-
-    status = DiskArbStart(&diskarb_port);
-    if (status == KERN_SUCCESS) {
-       status =
-           DiskArbDiskAppearedWithMountpointPing_auto("AFS",
-                                                      DISK_ARB_NETWORK_DISK_FLAG,
-                                                      cacheMountDir);
-    }
-
-    return status;
-#endif
-#endif /* AFS_DARWIN_ENV */
-    return 0;
+    cmd_AddParm(ts, "-dynroot-sparse", CMD_FLAG, CMD_OPTIONAL,
+               "Enable dynroot support with minimal cell list");
 }
 
-#if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
-
 int
-call_syscall(long param1, long param2, long param3, long param4, long param5, 
-            long param6, long  param7)
+afsd_parse(int argc, char **argv)
 {
-    int error;
-#ifdef AFS_LINUX20_ENV
-    long eparm[4];
-    struct afsprocdata syscall_data;
-    int fd = open(PROC_SYSCALL_FNAME, O_RDWR);
-    if (fd < 0)
-       fd = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR);
-    eparm[0] = param4;
-    eparm[1] = param5;
-    eparm[2] = param6;
-    eparm[3] = param7;
-
-    param4 = (long)eparm;
-
-    syscall_data.syscall = AFSCALL_CALL;
-    syscall_data.param1 = param1;
-    syscall_data.param2 = param2;
-    syscall_data.param3 = param3;
-    syscall_data.param4 = param4;
-    if (fd > 0) {
-       error = ioctl(fd, VIOC_SYSCALL, &syscall_data);
-       close(fd);
-    } else
-#endif
-#ifdef AFS_DARWIN80_ENV
-    struct afssysargs syscall_data;
-    int fd = open(SYSCALL_DEV_FNAME,O_RDWR);
-    syscall_data.syscall = AFSCALL_CALL;
-    syscall_data.param1 = param1;
-    syscall_data.param2 = param2;
-    syscall_data.param3 = param3;
-    syscall_data.param4 = param4;
-    syscall_data.param5 = param5;
-    syscall_data.param6 = param6;
-    if(fd >= 0) {
-       error = ioctl(fd, VIOC_SYSCALL, &syscall_data);
-       close(fd);
-    } else {
-       error = -1;
-    }
-    if (!error)
-      error=syscall_data.retval;
-#else
-    error =
-       syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4,
-               param5, param6, param7);
-#endif
-
-    if (afsd_debug)
-       printf("SScall(%d, %d, %ld)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1,
-              error);
-    return (error);
+    return cmd_Dispatch(argc, argv);
 }
-#else /* AFS_AIX32_ENV */
-#if defined(AFS_SGI_ENV)
-call_syscall(call, parm0, parm1, parm2, parm3, parm4)
-{
-
-    int error;
-
-    error = afs_syscall(call, parm0, parm1, parm2, parm3, parm4);
-    if (afsd_verbose)
-       printf("SScall(%d, %d)=%d ", call, parm0, error);
-
-    return error;
-}
-#else
-call_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6)
-{
-
-    return syscall(AFSCALL_CALL, call, parm0, parm1, parm2, parm3, parm4,
-                  parm5, parm6);
-}
-#endif /* AFS_SGI_ENV */
-#endif /* AFS_AIX32_ENV */
-
-
-#ifdef AFS_AIX_ENV
-/* Special handling for AIX's afs mount operation since they require much more miscl. information before making the vmount(2) syscall */
-#include <sys/vfs.h>
-
-#define        ROUNDUP(x)  (((x) + 3) & ~3)
-
-aix_vmount()
-{
-    struct vmount *vmountp;
-    int size, error;
-
-    size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir) + 1) + 5 * 4;
-    /* Malloc the vmount structure */
-    if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) {
-       printf("Can't allocate space for the vmount structure (AIX)\n");
-       exit(1);
-    }
-
-    /* zero out the vmount structure */
-    memset(vmountp, '\0', size);
-
-    /* transfer info into the vmount structure */
-    vmountp->vmt_revision = VMT_REVISION;
-    vmountp->vmt_length = size;
-    vmountp->vmt_fsid.fsid_dev = 0;
-    vmountp->vmt_fsid.fsid_type = AFS_MOUNT_AFS;
-    vmountp->vmt_vfsnumber = 0;
-    vmountp->vmt_time = 0;     /* We'll put the time soon! */
-    vmountp->vmt_flags = VFS_DEVMOUNT; /* read/write permission */
-    vmountp->vmt_gfstype = AFS_MOUNT_AFS;
-    vmountdata(vmountp, "AFS", cacheMountDir, "", "", "", "rw");
-
-    /* Do the actual mount system call */
-    error = vmount(vmountp, size);
-    free(vmountp);
-    return (error);
-}
-
-vmountdata(struct vmount * vmtp, char *obj, char *stub, char *host,
-          char *hostsname, char *info, char *args)
-{
-    struct data {
-       short vmt_off;
-       short vmt_size;
-    } *vdp, *vdprev;
-    int size;
-
-    vdp = (struct data *)vmtp->vmt_data;
-    vdp->vmt_off = sizeof(struct vmount);
-    size = ROUNDUP(strlen(obj) + 1);
-    vdp->vmt_size = size;
-    strcpy(vmt2dataptr(vmtp, VMT_OBJECT), obj);
-
-    vdprev = vdp;
-    vdp++;
-    vdp->vmt_off = vdprev->vmt_off + size;
-    size = ROUNDUP(strlen(stub) + 1);
-    vdp->vmt_size = size;
-    strcpy(vmt2dataptr(vmtp, VMT_STUB), stub);
-
-    vdprev = vdp;
-    vdp++;
-    vdp->vmt_off = vdprev->vmt_off + size;
-    size = ROUNDUP(strlen(host) + 1);
-    vdp->vmt_size = size;
-    strcpy(vmt2dataptr(vmtp, VMT_HOST), host);
-
-    vdprev = vdp;
-    vdp++;
-    vdp->vmt_off = vdprev->vmt_off + size;
-    size = ROUNDUP(strlen(hostsname) + 1);
-    vdp->vmt_size = size;
-    strcpy(vmt2dataptr(vmtp, VMT_HOSTNAME), hostsname);
-
-
-    vdprev = vdp;
-    vdp++;
-    vdp->vmt_off = vdprev->vmt_off + size;
-    size = ROUNDUP(strlen(info) + 1);
-    vdp->vmt_size = size;
-    strcpy(vmt2dataptr(vmtp, VMT_INFO), info);
-
-    vdprev = vdp;
-    vdp++;
-    vdp->vmt_off = vdprev->vmt_off + size;
-    size = ROUNDUP(strlen(args) + 1);
-    vdp->vmt_size = size;
-    strcpy(vmt2dataptr(vmtp, VMT_ARGS), args);
-}
-#endif /* AFS_AIX_ENV */
 
 #ifdef AFS_SGI53_ENV
 #ifdef AFS_SGI61_ENV
@@ -2868,7 +2660,7 @@ set_staticaddrs(void)
        findDwarfStaticAddresses(fileList, AFS_N_FILELISTS);
 
     if (fileList[0].addrList[0].found) {
-       call_syscall(AFSOP_NFSSTATICADDR2, fileList[0].addrList[0].addr.high,
+       afsd_call_syscall(AFSOP_NFSSTATICADDR2, fileList[0].addrList[0].addr.high,
                     fileList[0].addrList[0].addr.low);
     } else {
        if (afsd_verbose)
@@ -2877,7 +2669,7 @@ set_staticaddrs(void)
     free(fileList[0].addrList);
 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
     if (fileList[1].addrList[0].found && fileList[1].addrList[1].found) {
-       call_syscall(AFSOP_SBLOCKSTATICADDR2,
+       afsd_call_syscall(AFSOP_SBLOCKSTATICADDR2,
                     fileList[1].addrList[0].addr.high,
                     fileList[1].addrList[0].addr.low,
                     fileList[1].addrList[1].addr.high,
@@ -3295,3 +3087,107 @@ get_nfsstaticaddr()
 }
 #endif /* AFS_SGI61_ENV */
 #endif /* AFS_SGI53_ENV */
+
+struct afsd_syscall_args {
+    long syscall;
+    long param1;
+    long param2;
+    long param3;
+    long param4;
+    long param5;
+    const char *rn;
+    int rxpri;
+};
+
+/**
+ * entry point for calling a syscall from another proc/thread.
+ *
+ * @param[in] rock  a struct afsd_syscall_args* specifying what syscall to call
+ *
+ * @return unused
+ *   @retval NULL always
+ */
+static void *
+call_syscall_thread(void *rock)
+{
+    struct afsd_syscall_args *args = rock;
+    int code;
+
+    if (args->rxpri) {
+       afsd_set_rx_rtpri();
+    }
+
+    code = afsd_call_syscall(args->syscall, args->param1, args->param2,
+                                 args->param3, args->param4, args->param5);
+    if (code && args->syscall == AFSOP_START_CS) {
+       printf("%s: No check server daemon in client.\n", args->rn);
+    }
+
+    free(args);
+
+    return NULL;
+}
+
+/**
+ * common code for calling a syscall in another proc/thread.
+ *
+ * @param[in] rx   1 if this is a thread for RX stuff, 0 otherwise
+ * @param[in] wait 1 if we should wait for the new proc/thread to finish, 0 to
+ *                 let it run in the background
+ * @param[in] rn   the name of the running program
+ * @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)
+{
+    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;
+    args->rxpri = rx;
+    args->rn = rn;
+
+    afsd_fork(wait, call_syscall_thread, args);
+}
+
+/**
+ * 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_impl(0, 0, rn, syscall, param1, param2, param3, param4, param5);
+}
+
+#if defined(AFS_SUN510_ENV) || defined(RXK_LISTENER_ENV)
+/**
+ * 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_syscall_impl(1, 0, rn, syscall, param1, param2, param3, param4, param5);
+}
+#endif /* AFS_SUN510_ENV || RXK_LISTENER_ENV */
+
+#if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
+/**
+ * call a syscall in another process or thread, give it RX priority, and wait
+ * 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_syscall_impl(1, 1, rn, syscall, param1, param2, param3, param4, param5);
+}
+#endif /* AFS_SUN510_ENV && RXK_LISTENER_ENV */