Windows: remove unused variables in fs.c
[openafs.git] / src / WINNT / afsd / fs.c
index f33ffb9..8423fb9 100644 (file)
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
+#include <afsconfig.h>
 #include <afs/param.h>
+#include <roken.h>
+
 #include <afs/stds.h>
+#include <afs/com_err.h>
+#include <afs/cmd.h>
 
 #include <windows.h>
 #include <stdlib.h>
+#include <sys/stat.h>
 #include <malloc.h>
 #include <string.h>
+#include <strsafe.h>
 #include <stdio.h>
 #include <time.h>
 #include <winsock2.h>
 #include <errno.h>
-#include <assert.h>
+#include <afs/afs_assert.h>
 #include <rx/rx_globals.h>
 
 #include <osi.h>
 #include <afsint.h>
+#include <afs/afs_consts.h>
+#include <afs/cellconfig.h>
 #include <afs/ptserver.h>
 #include <afs/ptuser.h>
+#include <afs/volser.h>
+#include <WINNT\afsreg.h>
 
 #include "fs.h"
 #include "fs_utils.h"
+#include "fs_acl.h"
 #include "cmd.h"
 #include "afsd.h"
 #include "cm_ioctl.h"
+#include "parsemode.h"
 
-#define        MAXHOSTS 13
-#define        OMAXHOSTS 8
-#define MAXCELLHOSTS 8
-#define MAXNAME 100
-#define        MAXSIZE 2048
 #define MAXINSIZE 1300    /* pioctl complains if data is larger than this */
 #define VMSGSIZE 128      /* size of msg buf in volume hdr */
-#define MAXCELLCHARS           64
+#define CELL_MAXNAMELEN                256
 #define MAXHOSTCHARS           64
 
-static char space[MAXSIZE];
-static char tspace[1024];
+static char pn[] = "fs";
+
+static char space[AFS_PIOCTL_MAXSIZE];
 
-#ifndef WIN32
 static struct ubik_client *uclient;
-#endif /* not WIN32 */
 
-static int GetClientAddrsCmd(struct cmd_syndesc *asp, char *arock);
-static int SetClientAddrsCmd(struct cmd_syndesc *asp, char *arock);
-static int FlushMountCmd(struct cmd_syndesc *asp, char *arock);
-static int RxStatProcCmd(struct cmd_syndesc *asp, char *arock);
-static int RxStatPeerCmd(struct cmd_syndesc *asp, char *arock);
+/* some forward references */
+static int SetVolCmd(struct cmd_syndesc *as, void *arock);
 
-extern struct cmd_syndesc *cmd_CreateSyntax();
+static int GetCellName(char *cellNamep, struct afsconf_cell *infop);
+static afs_int32 GetCell(char *fname, char *cellname, size_t cell_len);
 
-static int MemDumpCmd(struct cmd_syndesc *asp, char *arock);
-static int CSCPolicyCmd(struct cmd_syndesc *asp, char *arock);
+static int VLDBInit(int noAuthFlag, struct afsconf_cell *infop);
+static int GetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
+static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
+static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
+static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
+static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
 
-extern afs_int32 VL_GetEntryByNameO();
+static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
+static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
+static int MiniDumpCmd(struct cmd_syndesc *asp, void *arock);
 
-static char pn[] = "fs";
 static int rxInitDone = 0;
 
-struct afsconf_cell {
-    char name[MAXCELLCHARS];
-    short numServers;
-    short flags;
-    struct sockaddr_in hostAddr[MAXCELLHOSTS];
-    char hostName[MAXCELLHOSTS][MAXHOSTCHARS];
-    char *linkedCell;
-};      
-
-
-/*
- * Character to use between name and rights in printed representation for
- * DFS ACL's.
- */
-#define DFS_SEPARATOR  ' '
-
-typedef char sec_rgy_name_t[1025];     /* A DCE definition */
-
-struct Acl {
-    int dfs;           /* Originally true if a dfs acl; now also the type
-                         * of the acl (1, 2, or 3, corresponding to object,
-                         * initial dir, or initial object). */
-    sec_rgy_name_t cell; /* DFS cell name */
-    int nplus;
-    int nminus;
-    struct AclEntry *pluslist;
-    struct AclEntry *minuslist;
-};
-
-struct AclEntry {
-    struct AclEntry *next;
-    char name[MAXNAME];
-    afs_int32 rights;
-};
-
-static void 
-ZapAcl (struct Acl *acl)
-{
-    if (!acl)
-        return;
-
-    ZapList(acl->pluslist);
-    ZapList(acl->minuslist);
-    free(acl);
-}
-
-/*
- * Mods for the AFS/DFS protocol translator.
- *
- * DFS rights. It's ugly to put these definitions here, but they 
- * *cannot* change, because they're part of the wire protocol.
- * In any event, the protocol translator will guarantee these
- * assignments for AFS cache managers.
- */
-#define DFS_READ          0x01
-#define DFS_WRITE         0x02
-#define DFS_EXECUTE       0x04
-#define DFS_CONTROL       0x08
-#define DFS_INSERT        0x10
-#define DFS_DELETE        0x20
-
-/* the application definable ones (backwards from AFS) */
-#define DFS_USR0 0x80000000      /* "A" bit */
-#define DFS_USR1 0x40000000      /* "B" bit */
-#define DFS_USR2 0x20000000      /* "C" bit */
-#define DFS_USR3 0x10000000      /* "D" bit */
-#define DFS_USR4 0x08000000      /* "E" bit */
-#define DFS_USR5 0x04000000      /* "F" bit */
-#define DFS_USR6 0x02000000      /* "G" bit */
-#define DFS_USR7 0x01000000      /* "H" bit */
-#define DFS_USRALL     (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
-                        DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
-
 /*
  * Offset of -id switch in command structure for various commands.
  * The -if switch is the next switch always.
@@ -149,7 +86,7 @@ static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
  * return 0, 1 or 2, as appropriate. Abort if both switches are present.
  */
 /* int id; Offset of -id switch; -if is next switch */
-static int 
+static int
 getidf(struct cmd_syndesc *as, int id)
 {
     int idf = 0;
@@ -173,232 +110,207 @@ static int
 PRights(afs_int32 arights, int dfs)
 {
     if (!dfs) {
-       if (arights & PRSFS_READ) 
+       if (arights & PRSFS_READ)
             printf("r");
-       if (arights & PRSFS_LOOKUP) 
+       if (arights & PRSFS_LOOKUP)
             printf("l");
-       if (arights & PRSFS_INSERT) 
+       if (arights & PRSFS_INSERT)
             printf("i");
-       if (arights & PRSFS_DELETE) 
+       if (arights & PRSFS_DELETE)
             printf("d");
-       if (arights & PRSFS_WRITE) 
+       if (arights & PRSFS_WRITE)
             printf("w");
-       if (arights & PRSFS_LOCK) 
+       if (arights & PRSFS_LOCK)
             printf("k");
-       if (arights & PRSFS_ADMINISTER) 
+       if (arights & PRSFS_ADMINISTER)
             printf("a");
-       if (arights & PRSFS_USR0) 
+       if (arights & PRSFS_USR0)
             printf("A");
-       if (arights & PRSFS_USR1) 
+       if (arights & PRSFS_USR1)
             printf("B");
-       if (arights & PRSFS_USR2) 
+       if (arights & PRSFS_USR2)
             printf("C");
-       if (arights & PRSFS_USR3) 
+       if (arights & PRSFS_USR3)
             printf("D");
-       if (arights & PRSFS_USR4) 
+       if (arights & PRSFS_USR4)
             printf("E");
-       if (arights & PRSFS_USR5) 
+       if (arights & PRSFS_USR5)
             printf("F");
-       if (arights & PRSFS_USR6) 
+       if (arights & PRSFS_USR6)
             printf("G");
-       if (arights & PRSFS_USR7) 
+       if (arights & PRSFS_USR7)
             printf("H");
     } else {
-       if (arights & DFS_READ) 
+       if (arights & DFS_READ)
             printf("r");
-        else 
+        else
             printf("-");
-       if (arights & DFS_WRITE) 
-            printf("w"); 
-        else 
+       if (arights & DFS_WRITE)
+            printf("w");
+        else
             printf("-");
-       if (arights & DFS_EXECUTE) 
-            printf("x"); 
-        else 
+       if (arights & DFS_EXECUTE)
+            printf("x");
+        else
             printf("-");
-       if (arights & DFS_CONTROL) 
-            printf("c"); 
-        else 
+       if (arights & DFS_CONTROL)
+            printf("c");
+        else
             printf("-");
-       if (arights & DFS_INSERT) 
-            printf("i"); 
-        else 
+       if (arights & DFS_INSERT)
+            printf("i");
+        else
             printf("-");
-       if (arights & DFS_DELETE) 
-            printf("d"); 
-        else 
+       if (arights & DFS_DELETE)
+            printf("d");
+        else
             printf("-");
-       if (arights & (DFS_USRALL)) 
+       if (arights & (DFS_USRALL))
             printf("+");
-       if (arights & DFS_USR0) 
+       if (arights & DFS_USR0)
             printf("A");
-       if (arights & DFS_USR1) 
+       if (arights & DFS_USR1)
             printf("B");
-       if (arights & DFS_USR2) 
+       if (arights & DFS_USR2)
             printf("C");
-       if (arights & DFS_USR3) 
+       if (arights & DFS_USR3)
             printf("D");
-       if (arights & DFS_USR4) 
+       if (arights & DFS_USR4)
             printf("E");
-       if (arights & DFS_USR5) 
+       if (arights & DFS_USR5)
             printf("F");
-       if (arights & DFS_USR6) 
+       if (arights & DFS_USR6)
             printf("G");
-       if (arights & DFS_USR7) 
+       if (arights & DFS_USR7)
             printf("H");
-    }  
-    return 0;
-}
-
-/* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
-static int 
-InAFS(char *apath)
-{
-    struct ViceIoctl blob;
-    afs_int32 code;
-
-    blob.in_size = 0;
-    blob.out_size = MAXSIZE;
-    blob.out = space;
-
-    code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
-    if (code) {
-       if ((errno == EINVAL) || (errno == ENOENT)) 
-            return 0;
-    }
-    return 1;
-}
-
-/* return a static pointer to a buffer */
-static char *
-Parent(char *apath)
-{
-    char *tp;
-    strcpy(tspace, apath);
-    tp = strrchr(tspace, '\\');
-    if (tp) {
-       *(tp+1) = 0;    /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
-    }
-    else {
-       fs_ExtractDriveLetter(apath, tspace);
-       strcat(tspace, ".");
     }
-    return tspace;
+    return 0;
 }
 
-enum rtype {add, destroy, deny};
-
-static afs_int32 
+static afs_int32
 Convert(char *arights, int dfs, enum rtype *rtypep)
 {
-    int i, len;
     afs_int32 mode;
     char tc;
+    char *tcp;
 
     *rtypep = add;     /* add rights, by default */
 
+                                /* analyze last character of string   */
+    tcp = arights + strlen(arights);
+    if ( tcp-- > arights ) {    /* assure non-empty string            */
+        if ( *tcp == '+' )
+            *rtypep = reladd;   /* '+' indicates more rights          */
+        else if ( *tcp == '-' )
+            *rtypep = reldel;   /* '-' indicates less rights          */
+        else if ( *tcp == '=' )
+            *rtypep = add;      /* '=' also allows old behaviour      */
+        else
+            tcp++;              /* back to original null byte         */
+        *tcp = '\0';            /* do not disturb old strcmp-s        */
+    }
+
     if (dfs) {
        if (!strcmp(arights, "null")) {
            *rtypep = deny;
            return 0;
        }
-       if (!strcmp(arights,"read")) 
+       if (!strcmp(arights,"read"))
             return DFS_READ | DFS_EXECUTE;
-       if (!strcmp(arights, "write")) 
-            return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | 
+       if (!strcmp(arights, "write"))
+            return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
                 DFS_WRITE;
-       if (!strcmp(arights, "all")) 
-            return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | 
+       if (!strcmp(arights, "all"))
+            return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
                 DFS_WRITE | DFS_CONTROL;
     } else {
-       if (!strcmp(arights,"read")) 
+       if (!strcmp(arights,"read"))
             return PRSFS_READ | PRSFS_LOOKUP;
-       if (!strcmp(arights, "write")) 
-            return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | 
+       if (!strcmp(arights, "write"))
+            return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
                 PRSFS_WRITE | PRSFS_LOCK;
-       if (!strcmp(arights, "mail")) 
+       if (!strcmp(arights, "mail"))
             return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
-       if (!strcmp(arights, "all")) 
-            return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | 
+       if (!strcmp(arights, "all"))
+            return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
                 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
     }
     if (!strcmp(arights, "none")) {
        *rtypep = destroy; /* Remove entire entry */
        return 0;
     }
-    len = strlen(arights);
     mode = 0;
-    for(i=0;i<len;i++) {
-        tc = *arights++;
+    tcp = arights;
+    while ((tc = *tcp++)) {
        if (dfs) {
-           if (tc == '-') 
+           if (tc == '-')
                 continue;
-           else if (tc == 'r') 
+           else if (tc == 'r')
                 mode |= DFS_READ;
-           else if (tc == 'w') 
+           else if (tc == 'w')
                 mode |= DFS_WRITE;
-           else if (tc == 'x') 
+           else if (tc == 'x')
                 mode |= DFS_EXECUTE;
-           else if (tc == 'c') 
+           else if (tc == 'c')
                 mode |= DFS_CONTROL;
-           else if (tc == 'i') 
+           else if (tc == 'i')
                 mode |= DFS_INSERT;
-           else if (tc == 'd') 
+           else if (tc == 'd')
                 mode |= DFS_DELETE;
-           else if (tc == 'A') 
+           else if (tc == 'A')
                 mode |= DFS_USR0;
-           else if (tc == 'B') 
+           else if (tc == 'B')
                 mode |= DFS_USR1;
-           else if (tc == 'C') 
+           else if (tc == 'C')
                 mode |= DFS_USR2;
-           else if (tc == 'D') 
+           else if (tc == 'D')
                 mode |= DFS_USR3;
-           else if (tc == 'E') 
+           else if (tc == 'E')
                 mode |= DFS_USR4;
-           else if (tc == 'F') 
+           else if (tc == 'F')
                 mode |= DFS_USR5;
-           else if (tc == 'G') 
+           else if (tc == 'G')
                 mode |= DFS_USR6;
-           else if (tc == 'H') 
+           else if (tc == 'H')
                 mode |= DFS_USR7;
            else {
-               fprintf(stderr, "%s: illegal DFS rights character '%c'.\n", 
+               fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
                          pn, tc);
                exit(1);
            }
        } else {
-           if (tc == 'r') 
+           if (tc == 'r')
                 mode |= PRSFS_READ;
-           else if (tc == 'l') 
+           else if (tc == 'l')
                 mode |= PRSFS_LOOKUP;
-           else if (tc == 'i') 
+           else if (tc == 'i')
                 mode |= PRSFS_INSERT;
-           else if (tc == 'd') 
+           else if (tc == 'd')
                 mode |= PRSFS_DELETE;
-           else if (tc == 'w') 
+           else if (tc == 'w')
                 mode |= PRSFS_WRITE;
-           else if (tc == 'k') 
+           else if (tc == 'k')
                 mode |= PRSFS_LOCK;
-           else if (tc == 'a') 
+           else if (tc == 'a')
                 mode |= PRSFS_ADMINISTER;
-           else if (tc == 'A') 
+           else if (tc == 'A')
                 mode |= PRSFS_USR0;
-           else if (tc == 'B') 
+           else if (tc == 'B')
                 mode |= PRSFS_USR1;
-           else if (tc == 'C') 
+           else if (tc == 'C')
                 mode |= PRSFS_USR2;
-           else if (tc == 'D') 
+           else if (tc == 'D')
                 mode |= PRSFS_USR3;
-           else if (tc == 'E') 
+           else if (tc == 'E')
                 mode |= PRSFS_USR4;
-           else if (tc == 'F') 
+           else if (tc == 'F')
                 mode |= PRSFS_USR5;
-           else if (tc == 'G') 
+           else if (tc == 'G')
                 mode |= PRSFS_USR6;
-           else if (tc == 'H') 
+           else if (tc == 'H')
                 mode |= PRSFS_USR7;
            else {
-               fprintf(stderr, "%s: illegal rights character '%c'.\n", pn, 
+               fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
                          tc);
                exit(1);
            }
@@ -407,205 +319,43 @@ Convert(char *arights, int dfs, enum rtype *rtypep)
     return mode;
 }
 
-static struct AclEntry *
-FindList (struct AclEntry *alist, char *aname)
-{
-    while (alist) {
-        if (!strcasecmp(alist->name, aname)) 
-            return alist;
-        alist = alist->next;
-    }
-    return 0;
-}
-
 /* if no parm specified in a particular slot, set parm to be "." instead */
-static void 
+static void
 SetDotDefault(struct cmd_item **aitemp)
 {
     struct cmd_item *ti;
-    if (*aitemp) 
+    int len_data = 2;
+
+    if (*aitemp)
         return;                        /* already has value */
     /* otherwise, allocate an item representing "." */
     ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
     assert(ti);
     ti->next = (struct cmd_item *) 0;
-    ti->data = (char *) malloc(2);
+    ti->data = (char *) malloc(len_data);
     assert(ti->data);
-    strcpy(ti->data, ".");
-    *aitemp = ti;
-}
-
-static void 
-ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
-{
-    struct AclEntry *tlist;
-    tlist = (plus ? al->pluslist : al->minuslist);
-    tlist = FindList (tlist, aname);
-    if (tlist) {
-        /* Found the item already in the list. */
-        tlist->rights = arights;
-        if (plus)
-            al->nplus -= PruneList(&al->pluslist, al->dfs);
-        else
-            al->nminus -= PruneList(&al->minuslist, al->dfs);
-        return;
-    }
-    /* Otherwise we make a new item and plug in the new data. */
-    tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
-    assert(tlist);
-    strcpy(tlist->name, aname);
-    tlist->rights = arights;
-    if (plus) {
-        tlist->next = al->pluslist;
-        al->pluslist = tlist;
-        al->nplus++;
-        if (arights == 0 || arights == -1)
-           al->nplus -= PruneList(&al->pluslist, al->dfs);
-    } else {
-        tlist->next = al->minuslist;
-        al->minuslist = tlist;
-        al->nminus++;
-        if (arights == 0) 
-            al->nminus -= PruneList(&al->minuslist, al->dfs);
-    }
-}
-
-static void 
-ZapList (struct AclEntry *alist)
-{
-    struct AclEntry *tp, *np;
-    for (tp = alist; tp; tp = np) {
-        np = tp->next;
-        free(tp);
-    }
-}
-
-static int 
-PruneList (struct AclEntry **ae, int dfs)
-{
-    struct AclEntry **lp;
-    struct AclEntry *te, *ne;
-    afs_int32 ctr;
-    ctr = 0;
-    lp = ae;
-    for(te = *ae;te;te=ne) {
-        if ((!dfs && te->rights == 0) || te->rights == -1) {
-            *lp = te->next;
-            ne = te->next;
-            free(te);
-            ctr++;
-       } else {
-            ne = te->next;
-            lp = &te->next;
-       }
+    if( FAILED(StringCbCopy(ti->data, len_data, "."))) {
+        fprintf (stderr, "data - not enough space");
+        exit(1);
     }
-    return ctr;
-}
-
-static char *
-SkipLine (char *astr)
-{
-    while (*astr !='\n') 
-        astr++;
-    astr++;
-    return astr;
-}
-
-/*
- * Create an empty acl, taking into account whether the acl pointed
- * to by astr is an AFS or DFS acl. Only parse this minimally, so we
- * can recover from problems caused by bogus ACL's (in that case, always
- * assume that the acl is AFS: for DFS, the user can always resort to
- * acl_edit, but for AFS there may be no other way out).
- */
-static struct Acl *
-EmptyAcl(char *astr)
-{
-    struct Acl *tp;
-    int junk;
-
-    tp = (struct Acl *)malloc(sizeof (struct Acl));
-    assert(tp);
-    tp->nplus = tp->nminus = 0;
-    tp->pluslist = tp->minuslist = 0;
-    tp->dfs = 0;
-    sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
-    return tp;
-}
-
-static struct Acl *
-ParseAcl (char *astr)
-{
-    int nplus, nminus, i, trights;
-    char tname[MAXNAME];
-    struct AclEntry *first, *last, *tl;
-    struct Acl *ta;
-
-    ta = (struct Acl *) malloc (sizeof (struct Acl));
-    assert(ta);
-    ta->dfs = 0;
-    sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
-    astr = SkipLine(astr);
-    sscanf(astr, "%d", &ta->nminus);
-    astr = SkipLine(astr);
-
-    nplus = ta->nplus;
-    nminus = ta->nminus;
-
-    last = 0;
-    first = 0;
-    for(i=0;i<nplus;i++) {
-        sscanf(astr, "%100s %d", tname, &trights);
-        astr = SkipLine(astr);
-        tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
-        assert(tl);
-        if (!first) 
-            first = tl;
-        strcpy(tl->name, tname);
-        tl->rights = trights;
-        tl->next = 0;
-        if (last) 
-            last->next = tl;
-        last = tl;
-    }
-    ta->pluslist = first;
-
-    last = 0;
-    first = 0;
-    for(i=0;i<nminus;i++) {
-        sscanf(astr, "%100s %d", tname, &trights);
-        astr = SkipLine(astr);
-        tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
-        assert(tl);
-        if (!first) 
-            first = tl;
-        strcpy(tl->name, tname);
-        tl->rights = trights;
-        tl->next = 0;
-        if (last) 
-            last->next = tl;
-        last = tl;
-    }
-    ta->minuslist = first;
-
-    return ta;
+    *aitemp = ti;
 }
 
 static int
 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
 {
-    printf("Volume status for vid = %u named %s\n",status->Vid, name);
+    printf("Volume status for vid = %u named %s is\n",status->Vid, name);
     if (*offmsg != 0)
        printf("Current offline message is %s\n",offmsg);
     if (*motd != 0)
        printf("Current message of the day is %s\n",motd);
     printf("Current disk quota is ");
-    if (status->MaxQuota != 0) 
+    if (status->MaxQuota != 0)
         printf("%d\n", status->MaxQuota);
-    else 
+    else
         printf("unlimited\n");
     printf("Current blocks used are %d\n",status->BlocksInUse);
-    printf("The partition has %d blocks available out of %d\n\n",
+    printf("The partition has %d blocks available out of %d\n",
             status->PartBlocksAvail, status->PartMaxBlocks);
     return 0;
 }
@@ -619,25 +369,25 @@ QuickPrintStatus(VolumeStatus *status, char *name)
     printf("%-25.25s",name);
 
     if (status->MaxQuota != 0) {
-       printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
+       printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
        QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
     } else {
-       printf("no limit%10d", status->BlocksInUse);
+       printf("   no limit %10d", status->BlocksInUse);
     }
     if (QuotaUsed > 90.0){
        printf(" %5.0f%%<<", QuotaUsed);
        WARN = 1;
-    } else 
+    } else
         printf(" %5.0f%%  ", QuotaUsed);
     PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
     if (PartUsed > 97.0){
        printf(" %9.0f%%<<", PartUsed);
        WARN = 1;
-    } else 
+    } else
         printf(" %9.0f%%  ", PartUsed);
     if (WARN){
        printf("  <<WARNING\n");
-    } else 
+    } else
         printf("\n");
     return 0;
 }
@@ -650,185 +400,40 @@ QuickPrintSpace(VolumeStatus *status, char *name)
     printf("%-25.25s",name);
 
     printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
-       
+
     PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
     if (PartUsed > 90.0){
        printf(" %4.0f%%<<", PartUsed);
        WARN = 1;
-    } else 
+    } else
         printf(" %4.0f%%  ", PartUsed);
     if (WARN){
        printf("  <<WARNING\n");
-    } else 
+    } else
         printf("\n");
     return 0;
 }
 
-static char *
-AclToString(struct Acl *acl)
+static DWORD IsFreelance(void)
 {
-    static char mydata[MAXSIZE];
-    char tstring[MAXSIZE];
-    char dfsstring[30];
-    struct AclEntry *tp;
-    
-    if (acl->dfs) 
-        sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
-    else 
-        dfsstring[0] = '\0';
-    sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
-    for (tp = acl->pluslist;tp;tp=tp->next) {
-        sprintf(tstring, "%s %d\n", tp->name, tp->rights);
-        strcat(mydata, tstring);
-    }
-    for (tp = acl->minuslist;tp;tp=tp->next) {
-        sprintf(tstring, "%s %d\n", tp->name, tp->rights);
-        strcat(mydata, tstring);
-    }
-    return mydata;
-}
-
-#define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
-
-BOOL IsAdmin (void)
-{
-    static BOOL fAdmin = FALSE;
-    static BOOL fTested = FALSE;
-
-    if (!fTested)
-    {
-        /* Obtain the SID for the AFS client admin group.  If the group does
-         * not exist, then assume we have AFS client admin privileges.
-         */
-        PSID psidAdmin = NULL;
-        DWORD dwSize, dwSize2;
-        char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
-        char *pszRefDomain = NULL;
-        SID_NAME_USE snu = SidTypeGroup;
-
-        dwSize = sizeof(pszAdminGroup);
-
-        if (!GetComputerName(pszAdminGroup, &dwSize)) {
-            /* Can't get computer name.  We return false in this case.
-               Retain fAdmin and fTested. This shouldn't happen.*/
-            return FALSE;
-        }
-
-        dwSize = 0;
-        dwSize2 = 0;
-
-        strcat(pszAdminGroup,"\\");
-        strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
-
-        LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
-        /* that should always fail. */
-
-        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
-            /* if we can't find the group, then we allow the operation */
-            fAdmin = TRUE;
-            return TRUE;
-        }
-
-        if (dwSize == 0 || dwSize2 == 0) {
-            /* Paranoia */
-            fAdmin = TRUE;
-            return TRUE;
-        }
-
-        psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
-        assert(psidAdmin);
-        pszRefDomain = (char *)malloc(dwSize2);
-        assert(pszRefDomain);
-
-        if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
-            /* We can't lookup the group now even though we looked it up earlier.  
-               Could this happen? */
-            fAdmin = TRUE;
-        } else {
-            /* Then open our current ProcessToken */
-            HANDLE hToken;
-
-            if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
-            {
-
-                if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
-                    /* We'll have to allocate a chunk of memory to store the list of
-                     * groups to which this user belongs; find out how much memory
-                     * we'll need.
-                     */
-                    DWORD dwSize = 0;
-                    PTOKEN_GROUPS pGroups;
-
-                    GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
-
-                    pGroups = (PTOKEN_GROUPS)malloc(dwSize);
-                    assert(pGroups);
-
-                    /* Allocate that buffer, and read in the list of groups. */
-                    if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
-                    {
-                        /* Look through the list of group SIDs and see if any of them
-                         * matches the AFS Client Admin group SID.
-                         */
-                        size_t iGroup = 0;
-                        for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
-                        {
-                            if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
-                                fAdmin = TRUE;
-                            }
-                        }
-                    }
-
-                    if (pGroups)
-                        free(pGroups);
-                }
-
-                /* if do not have permission because we were not explicitly listed
-                 * in the Admin Client Group let's see if we are the SYSTEM account
-                 */
-                if (!fAdmin) {
-                    PTOKEN_USER pTokenUser;
-                    SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
-                    PSID pSidLocalSystem = 0;
-                    DWORD gle;
-
-                    GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
-
-                    pTokenUser = (PTOKEN_USER)malloc(dwSize);
-                    assert(pTokenUser);
-
-                    if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
-                        gle = GetLastError();
-
-                    if (AllocateAndInitializeSid( &SIDAuth, 1,
-                                                  SECURITY_LOCAL_SYSTEM_RID,
-                                                  0, 0, 0, 0, 0, 0, 0,
-                                                  &pSidLocalSystem))
-                    {
-                        if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
-                            fAdmin = TRUE;
-                        }
-
-                        FreeSid(pSidLocalSystem);
-                    }
-
-                    if ( pTokenUser )
-                        free(pTokenUser);
-                }
-            }
-        }
-
-        free(psidAdmin);
-        free(pszRefDomain);
-
-        fTested = TRUE;
-    }
-
-    return fAdmin;
+    HKEY  parmKey;
+    DWORD code;
+    DWORD dummyLen;
+    DWORD enabled = 0;
+
+    code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
+                         0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
+    if (code == ERROR_SUCCESS) {
+        dummyLen = sizeof(cm_freelanceEnabled);
+        code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
+                            (BYTE *) &enabled, &dummyLen);
+        RegCloseKey (parmKey);
+    }
+    return enabled;
 }
 
 static int
-SetACLCmd(struct cmd_syndesc *as, char *arock)
+SetACLCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -838,8 +443,9 @@ SetACLCmd(struct cmd_syndesc *as, char *arock)
     afs_int32 rights;
     int clear;
     int idf = getidf(as, parm_setacl_id);
-
+    size_t len;
     int error = 0;
+    char cell[CELL_MAXNAMELEN];
 
     if (as->parms[2].items)
         clear = 1;
@@ -847,18 +453,37 @@ SetACLCmd(struct cmd_syndesc *as, char *arock)
         clear = 0;
     plusp = !(as->parms[3].items);
     for(ti=as->parms[0].items; ti;ti=ti->next) {
-       blob.out_size = MAXSIZE;
+        code = GetCell(ti->data, cell, sizeof(cell));
+       if (code) {
+           fs_Die(errno, ti->data);
+           error = 1;
+            continue;
+       }
+
+        if ( fs_IsFreelanceRoot(ti->data) ) {
+            fprintf(stderr,"%s: ACLs cannot be set on the Freelance root.afs volume.\n", pn);
+            error = 1;
+            continue;
+        }
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = idf;
        blob.in = blob.out = space;
-       code = pioctl(ti->data, VIOCGETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
            error = 1;
             continue;
        }
         if (ta)
             ZapAcl(ta);
-       ta = ParseAcl(space);
+       ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
+        if (!ta) {
+            fprintf(stderr,
+                    "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                     ti->data);
+            error = 1;
+            continue;
+        }
        if (!plusp && ta->dfs) {
            fprintf(stderr,
                    "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
@@ -869,11 +494,18 @@ SetACLCmd(struct cmd_syndesc *as, char *arock)
        }
         if (ta)
             ZapAcl(ta);
-       if (clear) 
+       if (clear)
             ta = EmptyAcl(space);
-       else 
-            ta = ParseAcl(space);
-       CleanAcl(ta, ti->data);
+       else
+            ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
+        if (!ta) {
+            fprintf(stderr,
+                    "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                     ti->data);
+            error = 1;
+            continue;
+        }
+       CleanAcl(ta, cell);
        for(ui=as->parms[1].items; ui; ui=ui->next->next) {
            enum rtype rtype;
            if (!ui->next) {
@@ -890,16 +522,20 @@ SetACLCmd(struct cmd_syndesc *as, char *arock)
                if (!FindList(tlist, ui->data))
                     continue;
            }
-           if (rtype == deny && !ta->dfs) 
+           if (rtype == deny && !ta->dfs)
                 plusp = 0;
-           if (rtype == destroy && ta->dfs) 
+           if (rtype == destroy && ta->dfs)
                 rights = -1;
-           ChangeList(ta, plusp, ui->data, rights);
+           ChangeList(ta, plusp, ui->data, rights, &rtype);
        }
        blob.in = AclToString(ta);
        blob.out_size=0;
-       blob.in_size = 1+strlen(blob.in);
-       code = pioctl(ti->data, VIOCSETAL, &blob, 1);
+       if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
+           fprintf (stderr, "StringCbLength failure on blob.in");
+           exit(1);
+       }
+       blob.in_size = 1+(long)len;
+       code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
        if (code) {
            if (errno == EINVAL) {
                if (ta->dfs) {
@@ -911,7 +547,7 @@ SetACLCmd(struct cmd_syndesc *as, char *arock)
                    if (!fsenv) {
                        fprintf(stderr,
     "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
-    "\nPossible reasons for this include:\n\n",                            
+    "\nPossible reasons for this include:\n\n",
     " -You may have specified an inappropriate combination of rights.\n",
     "  For example, some DFS-supported filesystems may not allow you to\n",
     "  drop the \"c\" right from \"user_obj\".\n\n",
@@ -928,7 +564,7 @@ SetACLCmd(struct cmd_syndesc *as, char *arock)
     " -If you add a user or group to a DFS ACL, remember that it must be\n",
     "  fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
     "  may be local requirements on the format of the user or group name.\n",
-    "  Check with your cell administrator.\n\n",                           
+    "  Check with your cell administrator.\n\n",
     " -Or numerous other possibilities. It would be great if we could be more\n",
     "  precise about the actual problem, but for various reasons, this is\n",
     "  impractical via this interface.  If you can't figure it out, you\n",
@@ -938,7 +574,7 @@ SetACLCmd(struct cmd_syndesc *as, char *arock)
                    }
                } else {
                    fprintf(stderr,
-                            "%s: Invalid argument, possible reasons include:\n", 
+                            "%s: Invalid argument, possible reasons include:\n",
                              pn);
                    fprintf(stderr,"\t-File not in AFS\n");
                    fprintf(stderr,
@@ -947,7 +583,7 @@ SetACLCmd(struct cmd_syndesc *as, char *arock)
                             "\t-Tried to add non-existent user to access control list\n");
                }
             } else {
-               Die(errno, ti->data);
+               fs_Die(errno, ti->data);
             }
             error = 1;
         }
@@ -957,8 +593,8 @@ SetACLCmd(struct cmd_syndesc *as, char *arock)
     return error;
 }
 
-static int 
-CopyACLCmd(struct cmd_syndesc *as, char *arock)
+static int
+CopyACLCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -968,173 +604,137 @@ CopyACLCmd(struct cmd_syndesc *as, char *arock)
     int clear;
     int idf = getidf(as, parm_copyacl_id);
     int error = 0;
+    size_t len;
+    char cell[CELL_MAXNAMELEN];
 
-    if (as->parms[2].items) 
+    if (as->parms[2].items)
         clear=1;
-    else 
+    else
         clear=0;
-    blob.out_size = MAXSIZE;
+    blob.out_size = AFS_PIOCTL_MAXSIZE;
     blob.in_size = idf;
     blob.in = blob.out = space;
-    code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
+    code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
     if (code) {
-       Die(errno, as->parms[0].items->data);
+       fs_Die(errno, as->parms[0].items->data);
        return 1;
     }
-    fa = ParseAcl(space);
-    CleanAcl(fa, as->parms[0].items->data);
+    fa = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
+    if (!fa) {
+        fprintf(stderr,
+                 "%s: %s: invalid acl data returned from VIOCGETAL\n",
+                 pn, as->parms[0].items->data);
+        return 1;
+    }
+    code = GetCell(as->parms[0].items->data, cell, sizeof(cell));
+    if (code) {
+        fprintf(stderr,
+                "%s: %s: unable to obtain cell name\n",
+                pn, as->parms[0].items->data);
+        return 1;
+    }
+    CleanAcl(fa, cell);
     for (ti=as->parms[1].items; ti;ti=ti->next) {
-       blob.out_size = MAXSIZE;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = idf;
        blob.in = blob.out = space;
-       code = pioctl(ti->data, VIOCGETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
            error = 1;
             continue;
        }
         if (ta)
             ZapAcl(ta);
-       if (clear) 
+       if (clear)
             ta = EmptyAcl(space);
-       else 
-            ta = ParseAcl(space);
-       CleanAcl(ta, ti->data);
+       else
+            ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
+        if (!ta) {
+            fprintf(stderr,
+                    "%s: %s: invalid acl data returned from VIOCGETAL\n",
+                     pn, ti->data);
+            error = 1;
+            continue;
+        }
+        code = GetCell(ti->data, cell, sizeof(cell));
+        if (code) {
+            fprintf(stderr,
+                    "%s: %s: unable to obtain cell name\n",
+                     pn, ti->data);
+            error = 1;
+            continue;
+        }
+       CleanAcl(ta, cell);
        if (ta->dfs != fa->dfs) {
-           fprintf(stderr, 
-                    "%s: incompatible file system types: acl not copied to %s; aborted\n", 
+           fprintf(stderr,
+                    "%s: incompatible file system types: acl not copied to %s; aborted\n",
                     pn, ti->data);
            error = 1;
             continue;
        }
        if (ta->dfs) {
            if (! clear && strcmp(ta->cell, fa->cell) != 0) {
-               fprintf(stderr, 
-                        "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", 
+               fprintf(stderr,
+                        "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
                         pn, ti->data);
                 error = 1;
                continue;
            }
-           strcpy(ta->cell, fa->cell);
+           if( FAILED(StringCbCopy(ta->cell, sizeof(ta->cell), fa->cell))) {
+               fprintf (stderr, "cell - not enough space");
+                exit(1);
+           }
        }
-       for (tp = fa->pluslist;tp;tp=tp->next) 
-           ChangeList(ta, 1, tp->name, tp->rights);
-       for (tp = fa->minuslist;tp;tp=tp->next) 
-           ChangeList(ta, 0, tp->name, tp->rights);
+       for (tp = fa->pluslist;tp;tp=tp->next)
+           ChangeList(ta, 1, tp->name, tp->rights, NULL);
+       for (tp = fa->minuslist;tp;tp=tp->next)
+           ChangeList(ta, 0, tp->name, tp->rights, NULL);
        blob.in = AclToString(ta);
        blob.out_size=0;
-       blob.in_size = 1+strlen(blob.in);
-       code = pioctl(ti->data, VIOCSETAL, &blob, 1);
+       if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
+           fprintf (stderr, "StringCbLength failure on blob.in");
+           exit(1);
+       }
+       blob.in_size = 1+(long)len;
+       code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
        if (code) {
            if (errno == EINVAL) {
                fprintf(stderr,
                         "%s: Invalid argument, possible reasons include:\n", pn);
                fprintf(stderr,"\t-File not in AFS\n");
            } else {
-               Die(errno, ti->data);
+               fs_Die(errno, ti->data);
            }
             error = 1;
        }
-    } 
+    }
     if (ta)
        ZapAcl(ta);
     ZapAcl(fa);
     return error;
 }
 
-/* pioctl() call to get the cellname of a pathname */
+/* pioctl_utf8() call to get the cellname of a pathname */
 static afs_int32
-GetCell(char *fname, char *cellname)
+GetCell(char *fname, char *cellname, size_t cell_len)
 {
     afs_int32 code;
     struct ViceIoctl blob;
 
     blob.in_size = 0;
-    blob.out_size = MAXCELLCHARS;
+    blob.out_size = cell_len;
     blob.out = cellname;
 
-    code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
-    return code ? errno : 0;
-}
-
-/* Check if a username is valid: If it contains only digits (or a
- * negative sign), then it might be bad.  We then query the ptserver
- * to see.
- */
-static int
-BadName(char *aname, char *fname)
-{
-    afs_int32 tc, code, id;
-    char *nm;
-    char cell[MAXCELLCHARS];
-
-    for ( nm = aname; tc = *nm; nm++) {
-       /* all must be '-' or digit to be bad */
-       if (tc != '-' && (tc < '0' || tc > '9'))
-            return 0;
-    }
-
-    /* Go to the PRDB and see if this all number username is valid */
-    code = GetCell(fname, cell);
-    if (code)
-        return 0;
-
-    pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
-    code = pr_SNameToId(aname, &id);
-    pr_End();
-
-    /* 1=>Not-valid; 0=>Valid */
-    return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
-}
-
-
-/* clean up an access control list of its bad entries; return 1 if we made
-   any changes to the list, and 0 otherwise */
-static int 
-CleanAcl(struct Acl *aa, char *fname)
-{
-    struct AclEntry *te, **le, *ne;
-    int changes;
-
-    /* Don't correct DFS ACL's for now */
-    if (aa->dfs)
-       return 0;
-
-    /* prune out bad entries */
-    changes = 0;           /* count deleted entries */
-    le = &aa->pluslist;
-    for(te = aa->pluslist; te; te=ne) {
-       ne = te->next;
-       if (BadName(te->name, fname)) {
-           /* zap this dude */
-           *le = te->next;
-           aa->nplus--;
-           free(te);
-           changes++;
-       } else {
-           le = &te->next;
-       }
-    }
-    le = &aa->minuslist;
-    for(te = aa->minuslist; te; te=ne) {
-       ne = te->next;
-       if (BadName(te->name, fname)) {
-           /* zap this dude */
-           *le = te->next;
-           aa->nminus--;
-           free(te);
-           changes++;
-       } else {
-           le = &te->next;
-       }
-    }
-    return changes;
+    code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
+    if (code == 0)
+        cellname[blob.out_size - 1] = '\0';
+    return code;
 }
 
-
 /* clean up an acl to not have bogus entries */
-static int 
-CleanACLCmd(struct cmd_syndesc *as, char *arock)
+static int
+CleanACLCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct Acl *ta = 0;
@@ -1143,22 +743,29 @@ CleanACLCmd(struct cmd_syndesc *as, char *arock)
     struct cmd_item *ti;
     struct AclEntry *te;
     int error = 0;
+    size_t len;
 
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
-       blob.out_size = MAXSIZE;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = 0;
        blob.out = space;
-       code = pioctl(ti->data, VIOCGETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
             error = 1;
            continue;
        }
         if (ta)
             ZapAcl(ta);
-       ta = ParseAcl(space);
-
+       ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
+        if (!ta) {
+            fprintf(stderr,
+                    "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                     ti->data);
+            error = 1;
+            continue;
+        }
        if (ta->dfs) {
            fprintf(stderr,
                    "%s: cleanacl is not supported for DFS access lists.\n",
@@ -1172,20 +779,24 @@ CleanACLCmd(struct cmd_syndesc *as, char *arock)
        if (changes) {
            /* now set the acl */
            blob.in=AclToString(ta);
-           blob.in_size = strlen(blob.in)+1;
+           if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
+               fprintf (stderr, "StringCbLength failure on blob.in");
+               exit(1);
+           }
+           blob.in_size = (long)len+1;
            blob.out_size = 0;
-           code = pioctl(ti->data, VIOCSETAL, &blob, 1);
+           code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
            if (code) {
                if (errno == EINVAL) {
                    fprintf(stderr,
-                            "%s: Invalid argument, possible reasons include\n", 
+                            "%s: Invalid argument, possible reasons include\n",
                              pn);
                    fprintf(stderr,"%s: File not in vice or\n", pn);
                    fprintf(stderr,
-                            "%s: Too many users on access control list or\n", 
+                            "%s: Too many users on access control list or\n",
                             pn);
                } else {
-                   Die(errno, ti->data);
+                   fs_Die(errno, ti->data);
                }
                 error = 1;
                 continue;
@@ -1194,7 +805,7 @@ CleanACLCmd(struct cmd_syndesc *as, char *arock)
            /* now list the updated acl */
            printf("Access list for %s is now\n", ti->data);
            if (ta->nplus > 0) {
-               if (!ta->dfs) 
+               if (!ta->dfs)
                     printf("Normal rights:\n");
                for(te = ta->pluslist;te;te=te->next) {
                    printf("  %s ", te->name);
@@ -1210,7 +821,7 @@ CleanACLCmd(struct cmd_syndesc *as, char *arock)
                    printf("\n");
                }
            }
-           if (ti->next) 
+           if (ti->next)
                 printf("\n");
        } else
            printf("Access list for %s is fine.\n", ti->data);
@@ -1220,8 +831,8 @@ CleanACLCmd(struct cmd_syndesc *as, char *arock)
     return error;
 }
 
-static int 
-ListACLCmd(struct cmd_syndesc *as, char *arock) 
+static int
+ListACLCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct Acl *ta = 0;
@@ -1234,60 +845,108 @@ ListACLCmd(struct cmd_syndesc *as, char *arock)
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        char separator;
-       blob.out_size = MAXSIZE;
+
+        if ( fs_IsFreelanceRoot(ti->data) ) {
+            fprintf(stderr,"%s: ACLs are not set on the Freelance root.afs volume.\n", pn);
+            error = 1;
+            continue;
+        }
+
+        blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = idf;
        blob.in = blob.out = space;
-       code = pioctl(ti->data, VIOCGETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
             error = 1;
            continue;
        }
-       ta = ParseAcl(space);
-       switch (ta->dfs) {
-         case 0:
-           printf("Access list for %s is\n", ti->data);
-           break;
-         case 1:
-           printf("DFS access list for %s is\n", ti->data);
-           break;
-         case 2:
-           printf("DFS initial directory access list of %s is\n", ti->data);
-           break;
-         case 3:
-           printf("DFS initial file access list of %s is\n", ti->data);
-           break;
-       }
-       if (ta->dfs) {
-           printf("  Default cell = %s\n", ta->cell);
-       }
-       separator = ta->dfs? DFS_SEPARATOR : ' ';
-       if (ta->nplus > 0) {
-           if (!ta->dfs) 
-                printf("Normal rights:\n");
-           for(te = ta->pluslist;te;te=te->next) {
-               printf("  %s%c", te->name, separator);
-               PRights(te->rights, ta->dfs);
-               printf("\n");
-           }
-       }
-       if (ta->nminus > 0) {
-           printf("Negative rights:\n");
-           for(te = ta->minuslist;te;te=te->next) {
-               printf("  %s ", te->name);
-               PRights(te->rights, ta->dfs);
-               printf("\n");
-           }
-       }
-       if (ti->next) 
+       ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
+        if (!ta) {
+            fprintf(stderr,
+                    "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                     ti->data);
+            error = 1;
+            continue;
+        }
+        if (as->parms[3].items) {                       /* -cmd */
+            printf("fs setacl -dir %s -acl ", ti->data);
+            if (ta->nplus > 0) {
+                for (te = ta->pluslist; te; te = te->next) {
+                    printf("  %s ", te->name);
+                    PRights(te->rights, ta->dfs);
+                }
+            }
             printf("\n");
+            if (ta->nminus > 0) {
+                printf("fs setacl -dir %s -acl ", ti->data);
+                for (te = ta->minuslist; te; te = te->next) {
+                    printf("  %s ", te->name);
+                    PRights(te->rights, ta->dfs);
+                }
+                printf(" -negative\n");
+            }
+        } else {
+            switch (ta->dfs) {
+            case 0:
+                printf("Access list for %s is\n", ti->data);
+                break;
+            case 1:
+                printf("DFS access list for %s is\n", ti->data);
+                break;
+            case 2:
+                printf("DFS initial directory access list of %s is\n", ti->data);
+                break;
+            case 3:
+                printf("DFS initial file access list of %s is\n", ti->data);
+                break;
+            }
+            if (ta->dfs) {
+                printf("  Default cell = %s\n", ta->cell);
+            }
+            separator = ta->dfs? DFS_SEPARATOR : ' ';
+            if (ta->nplus > 0) {
+                if (!ta->dfs)
+                    printf("Normal rights:\n");
+                for(te = ta->pluslist;te;te=te->next) {
+                    printf("  %s%c", te->name, separator);
+                    PRights(te->rights, ta->dfs);
+                    printf("\n");
+                }
+            }
+            if (ta->nminus > 0) {
+                printf("Negative rights:\n");
+                for(te = ta->minuslist;te;te=te->next) {
+                    printf("  %s ", te->name);
+                    PRights(te->rights, ta->dfs);
+                    printf("\n");
+                }
+            }
+            if (ti->next)
+                printf("\n");
+        }
         ZapAcl(ta);
     }
     return error;
 }
 
 static int
-FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
+FlushAllCmd(struct cmd_syndesc *as, void *arock)
+{
+    afs_int32 code;
+    struct ViceIoctl blob;
+
+    blob.in_size = blob.out_size = 0;
+    code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
+    if (code) {
+       fprintf(stderr, "Error flushing all ");
+       return 1;
+    }
+    return 0;
+}
+
+static int
+FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -1297,7 +956,7 @@ FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        blob.in_size = blob.out_size = 0;
-       code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
+       code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
        if (code) {
            fprintf(stderr, "Error flushing volume ");
             perror(ti->data);
@@ -1308,21 +967,33 @@ FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
     return error;
 }
 
-static int 
-FlushCmd(struct cmd_syndesc *as, char *arock) 
+static int
+FlushCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
     struct cmd_item *ti;
-
     int error = 0;
+    int literal = 0;
+    cm_ioctlQueryOptions_t options;
+
+    if (as->parms[1].items)
+        literal = 1;
 
     for(ti=as->parms[0].items; ti; ti=ti->next) {
-       blob.in_size = blob.out_size = 0;
-       code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
+        /* once per file */
+        memset(&options, 0, sizeof(options));
+        options.size = sizeof(options);
+        options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
+        options.literal = literal;
+       blob.in_size = options.size;    /* no variable length data */
+        blob.in = &options;
+
+       blob.out_size = 0;
+       code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
        if (code) {
            if (errno == EMFILE) {
-               fprintf(stderr, "%s: Can't flush active file %s\n", pn, 
+               fprintf(stderr, "%s: Can't flush active file %s\n", pn,
                         ti->data);
            } else {
                fprintf(stderr, "%s: Error flushing file ", pn);
@@ -1337,27 +1008,38 @@ FlushCmd(struct cmd_syndesc *as, char *arock)
 
 /* all this command does is repackage its args and call SetVolCmd */
 static int
-SetQuotaCmd(struct cmd_syndesc *as, char *arock) {
+SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
     struct cmd_syndesc ts;
-
+    errno_t err;
     /* copy useful stuff from our command slot; we may later have to reorder */
-    memcpy(&ts, as, sizeof(ts));       /* copy whole thing */
+#if _MSC_VER < 1400
+    memcpy(&ts, as, sizeof(ts));    /* copy whole thing */
+#else
+    err = memcpy_s(&ts, sizeof(ts), as, sizeof(ts));  /* copy whole thing */
+    if ( err ) {
+        fprintf (stderr, "memcpy_s failure on ts");
+        exit(1);
+    }
+#endif
     return SetVolCmd(&ts, arock);
 }
 
 static int
-SetVolCmd(struct cmd_syndesc *as, char *arock) {
+SetVolCmd(struct cmd_syndesc *as, void *arock) {
     afs_int32 code;
     struct ViceIoctl blob;
     struct cmd_item *ti;
     struct VolumeStatus *status;
-    char *motd, *offmsg, *input;
+    char *motd, *offmsg, *input, *destEnd;
+    size_t destRemaining;
     int error = 0;
+    size_t len;
 
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        /* once per file */
-       blob.out_size = MAXSIZE;
+        destRemaining = sizeof(space);
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = sizeof(*status) + 3;     /* for the three terminating nulls */
        blob.out = space;
        blob.in = space;
@@ -1365,63 +1047,66 @@ SetVolCmd(struct cmd_syndesc *as, char *arock) {
        status->MinQuota = status->MaxQuota = -1;
        motd = offmsg = NULL;
        if (as->parms[1].items) {
-           code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
+           code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
            if (code) {
                fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
                error = 1;
                 continue;
            }
        }
-       if (as->parms[2].items) 
+       if (as->parms[2].items)
             motd = as->parms[2].items->data;
-       if (as->parms[3].items) 
+       if (as->parms[3].items)
             offmsg = as->parms[3].items->data;
        input = (char *)status + sizeof(*status);
        *(input++) = '\0';      /* never set name: this call doesn't change vldb */
+        destRemaining -= sizeof(*status) + 1;
        if(offmsg) {
-            if (strlen(offmsg) >= VMSGSIZE) {
-                fprintf(stderr,"%s: message must be shorter than %d characters\n",
+            if( FAILED(StringCbLength(offmsg, VMSGSIZE, &len))) {
+               fprintf(stderr,"%s: message must be shorter than %d characters\n",
                          pn, VMSGSIZE);
                 error = 1;
                 continue;
-            }
-           strcpy(input,offmsg);
-           blob.in_size += strlen(offmsg);
-           input += strlen(offmsg) + 1;
-       } else 
-            *(input++) = '\0';
+           }
+            if( FAILED(StringCbCopyEx(input, destRemaining, offmsg, &destEnd, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
+               fprintf (stderr, "input - not enough space");
+                exit(1);
+           }
+           blob.in_size += destEnd - input;
+           input = destEnd + 1;
+           destRemaining -= sizeof(char);
+       } else {
+            *(input++) = '\0';
+            destRemaining -= sizeof(char);
+        }
        if(motd) {
-            if (strlen(motd) >= VMSGSIZE) {
-                fprintf(stderr,"%s: message must be shorter than %d characters\n",
-                         pn, VMSGSIZE);
+            if( FAILED(StringCbLength(motd, VMSGSIZE, &len))) {
+               fprintf(stderr,"%s: message must be shorter than %d characters\n",
+                    pn, VMSGSIZE);
                 return code;
-            }
-           strcpy(input,motd);
-           blob.in_size += strlen(motd);
-           input += strlen(motd) + 1;
-       } else 
+           }
+           if( FAILED(StringCbCopyEx(input, destRemaining, motd, &destEnd, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
+                fprintf (stderr, "input - not enough space");
+                exit(1);
+           }
+           blob.in_size += (long)(destEnd - input);
+           input = destEnd + 1;
+           destRemaining -= sizeof(char);
+       } else {
             *(input++) = '\0';
-       code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
+            destRemaining -= sizeof(char);
+        }
+       code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
        if (code) {
+           fs_Die(errno, ti->data);
            error = 1;
        }
     }
     return error;
 }
 
-#ifndef WIN32
-/* 
- * Why is VenusFid declared in the kernel-only section of afs.h, 
- * if it's the exported interface of the (UNIX) cache manager?
- */
-struct VenusFid {
-    afs_int32 Cell;
-    AFSFid Fid;
-};
-#endif /* WIN32 */
-
-static int 
-ExamineCmd(struct cmd_syndesc *as, char *arock)
+static int
+ExamineCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -1429,43 +1114,136 @@ ExamineCmd(struct cmd_syndesc *as, char *arock)
     struct VolumeStatus *status;
     char *name, *offmsg, *motd;
     int error = 0;
-    
+    int literal = 0;
+    cm_ioctlQueryOptions_t options;
+    size_t len;
+
+    if (as->parms[1].items)
+        literal = 1;
+
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
-#ifndef WIN32
-        struct VenusFid vfid;
-#endif /* WIN32 */
-       /* once per file */
-       blob.out_size = MAXSIZE;
-       blob.in_size = 0;
-       blob.out = space;
-       code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
-       if (code) {
-           Die(errno, ti->data);
+        cm_fid_t fid;
+        afs_uint32 filetype;
+       afs_int32 owner[2];
+        afs_uint32 unixModeBits;
+       char cell[CELL_MAXNAMELEN];
+
+        /* once per file */
+        memset(&fid, 0, sizeof(fid));
+        memset(&options, 0, sizeof(options));
+        filetype = 0;
+        options.size = sizeof(options);
+        options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
+        options.literal = literal;
+       blob.in_size = options.size;    /* no variable length data */
+        blob.in = &options;
+
+        blob.out_size = sizeof(cm_fid_t);
+        blob.out = (char *) &fid;
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
+            blob.out_size == sizeof(cm_fid_t)) {
+            options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
+            options.fid = fid;
+        } else {
+           fs_Die(errno, ti->data);
            error = 1;
            continue;
-       }
-       status = (VolumeStatus *)space;
-       name = (char *)status + sizeof(*status);
-       offmsg = name + strlen(name) + 1;
-       motd = offmsg + strlen(offmsg) + 1;
+        }
 
-#ifndef WIN32
-        blob.out_size = sizeof(struct VenusFid);
-        blob.out = (char *) &vfid;
-        if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
-            printf("File %s (%u.%u.%u) contained in volume %u\n",
-                    ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
-                    vfid.Fid.Volume);
+        blob.out_size = sizeof(filetype);
+        blob.out = &filetype;
+
+        code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
+        if (code || blob.out_size != sizeof(filetype)) {
+           fs_Die(errno, ti->data);
+           error = 1;
+           continue;
         }
-#endif /* WIN32 */
-       PrintStatus(status, name, motd, offmsg);
+
+        blob.out_size = CELL_MAXNAMELEN;
+        blob.out = cell;
+
+        code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
+        if (code == 0)
+            cell[blob.out_size-1] = '\0';
+        printf("%s %s (%u.%u.%u) contained in cell %s\n",
+                fs_filetypestr(filetype),
+                ti->data, fid.volume, fid.vnode, fid.unique,
+                code ? "unknown-cell" : cell);
+
+       blob.out_size = 2 * sizeof(afs_uint32);
+        blob.out = (char *) &owner;
+       if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1) &&
+            blob.out_size == 2 * sizeof(afs_uint32)) {
+           char oname[PR_MAXNAMELEN] = "(unknown)";
+           char gname[PR_MAXNAMELEN] = "(unknown)";
+            char confDir[257];
+
+           /* Go to the PRDB and see if this all number username is valid */
+            cm_GetConfigDir(confDir, sizeof(confDir));
+
+            pr_Initialize(1, confDir, cell);
+           pr_SIdToName(owner[0], oname);
+           pr_SIdToName(owner[1], gname);
+           printf("Owner %s (%d) Group %s (%d)\n", oname, owner[0], gname, owner[1]);
+        }
+
+       blob.out_size = sizeof(afs_uint32);
+        blob.out = (char *) &unixModeBits;
+       if (0 == pioctl_utf8(ti->data, VIOC_GETUNIXMODE, &blob, 1) &&
+            blob.out_size == sizeof(afs_uint32)) {
+           printf("UNIX mode 0%o\n", unixModeBits);
+        }
+
+       blob.out = space;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
+       code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
+       if (code == 0) {
+            space[blob.out_size - 1] = '\0';
+            status = (VolumeStatus *)space;
+            name = (char *)status + sizeof(*status);
+            if( FAILED(StringCbLength(name, sizeof(space) - (name - space), &len))) {
+               fprintf (stderr, "StringCbLength failure on name");
+               exit(1);
+           }
+            offmsg = name + len + 1;
+            if( FAILED(StringCbLength(offmsg, sizeof(space) - (offmsg - space), &len))) {
+               fprintf (stderr, "StringCbLength failure on offmsg");
+               exit(1);
+           }
+            motd = offmsg + len + 1;
+            PrintStatus(status, name, motd, offmsg);
+        } else {
+            fs_Die(errno, ti->data);
+        }
+
+        errno = 0;
+        code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
+        switch (errno) {
+        case 0:
+            printf("Volume is online\n");
+            break;
+        case ENXIO:
+            printf("Volume is offline\n");
+            break;
+        case ENOSYS:
+            printf("All Volume servers are down\n");
+            break;
+        case EBUSY:
+            printf("All volume servers are busy\n");
+            break;
+        default:
+            printf("Unknown volume state\n");
+            fs_Die(errno, ti->data);
+        }
+        printf("\n");
     }
     return error;
 }
 
 static int
-ListQuotaCmd(struct cmd_syndesc *as, char *arock) 
+ListQuotaCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -1474,21 +1252,22 @@ ListQuotaCmd(struct cmd_syndesc *as, char *arock)
     char *name;
 
     int error = 0;
-    
-    printf("%-25s%-10s%-10s%-7s%-13s\n", 
-           "Volume Name", "     Quota", "      Used", "  %Used", "    Partition");
+
+    printf("%-25s%-11s%-11s%-7s%-13s\n", "Volume Name", "      Quota",
+          "       Used", "  %Used", "    Partition");
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        /* once per file */
-       blob.out_size = MAXSIZE;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = 0;
        blob.out = space;
-       code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
             error = 1;
            continue;
        }
+        space[blob.out_size - 1] = '\0';
        status = (VolumeStatus *)space;
        name = (char *)status + sizeof(*status);
        QuickPrintStatus(status, name);
@@ -1497,7 +1276,7 @@ ListQuotaCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-WhereIsCmd(struct cmd_syndesc *as, char *arock)
+WhereIsCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -1506,25 +1285,64 @@ WhereIsCmd(struct cmd_syndesc *as, char *arock)
     afs_int32 *hosts;
     char *tp;
     int error = 0;
-    
+    int literal = 0;
+    cm_ioctlQueryOptions_t options;
+
+    if (as->parms[1].items)
+        literal = 1;
+
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
-       /* once per file */
-       blob.out_size = MAXSIZE;
-       blob.in_size = 0;
+        cm_fid_t fid;
+        afs_uint32 filetype;
+
+        /* once per file */
+        memset(&fid, 0, sizeof(fid));
+        memset(&options, 0, sizeof(options));
+        filetype = 0;
+        options.size = sizeof(options);
+        options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
+        options.literal = literal;
+       blob.in_size = options.size;    /* no variable length data */
+        blob.in = &options;
+
+        blob.out_size = sizeof(cm_fid_t);
+        blob.out = (char *) &fid;
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
+            blob.out_size == sizeof(cm_fid_t)) {
+            options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
+            options.fid = fid;
+        } else {
+           fs_Die(errno, ti->data);
+           error = 1;
+           continue;
+        }
+
+        blob.out_size = sizeof(filetype);
+        blob.out = &filetype;
+
+        code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
+        if (code || blob.out_size != sizeof(filetype)) {
+           fs_Die(errno, ti->data);
+            error = 1;
+           continue;
+        }
+        blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.out = space;
        memset(space, 0, sizeof(space));
-       code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
             error = 1;
            continue;
        }
-       hosts = (afs_int32 *) space;
-       printf("File %s is on host%s ", ti->data, 
+        hosts = (afs_int32 *) space;
+       printf("%s %s is on host%s ",
+                fs_filetypestr(filetype),
+                ti->data,
                 (hosts[0] && !hosts[1]) ? "": "s");
-       for(j=0; j<MAXHOSTS; j++) {
-           if (hosts[j] == 0) 
+       for(j=0; j<AFS_MAXHOSTS; j++) {
+           if (hosts[j] == 0)
                 break;
            tp = hostutil_GetNameByINet(hosts[j]);
            printf("%s ", tp);
@@ -1536,7 +1354,7 @@ WhereIsCmd(struct cmd_syndesc *as, char *arock)
 
 
 static int
-DiskFreeCmd(struct cmd_syndesc *as, char *arock)
+DiskFreeCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -1544,21 +1362,22 @@ DiskFreeCmd(struct cmd_syndesc *as, char *arock)
     char *name;
     struct VolumeStatus *status;
     int error = 0;
-    
+
     printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", "    kbytes",
           "      used", "     avail", " %used");
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        /* once per file */
-       blob.out_size = MAXSIZE;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = 0;
        blob.out = space;
-       code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
             error = 1;
            continue;
        }
+        space[blob.out_size - 1] = '\0';
        status = (VolumeStatus *)space;
        name = (char *)status + sizeof(*status);
        QuickPrintSpace(status, name);
@@ -1567,7 +1386,7 @@ DiskFreeCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-QuotaCmd(struct cmd_syndesc *as, char *arock)
+QuotaCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -1575,23 +1394,27 @@ QuotaCmd(struct cmd_syndesc *as, char *arock)
     double quotaPct;
     struct VolumeStatus *status;
     int error = 0;
-    
+
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        /* once per file */
-       blob.out_size = MAXSIZE;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = 0;
        blob.out = space;
-       code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
-       if (code) {
-           Die(errno, ti->data);
+       code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
+        /*
+         * The response is VolumeStatus, volume name, offline message, and motd
+         */
+       if (code || blob.out_size < sizeof(*status)) {
+           fs_Die(errno, ti->data);
             error = 1;
            continue;
        }
-       status = (VolumeStatus *)space;
-       if (status->MaxQuota) 
+
+        status = (VolumeStatus *)space;
+       if (status->MaxQuota)
             quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
-       else 
+       else
             quotaPct = 0.0;
        printf("%2.0f%% of quota used.\n", quotaPct);
     }
@@ -1599,7 +1422,7 @@ QuotaCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-ListMountCmd(struct cmd_syndesc *as, char *arock)
+ListMountCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -1608,6 +1431,8 @@ ListMountCmd(struct cmd_syndesc *as, char *arock)
     char true_name[1024];              /*``True'' dirname (e.g., symlink target)*/
     char parent_dir[1024];             /*Parent directory of true name*/
     char *last_component;      /*Last component of true name*/
+    size_t len;
+
 #ifndef WIN32
     struct stat statbuff;              /*Buffer for status info*/
 #endif /* not WIN32 */
@@ -1615,17 +1440,24 @@ ListMountCmd(struct cmd_syndesc *as, char *arock)
     int link_chars_read;               /*Num chars read in readlink()*/
 #endif /* not WIN32 */
     int        thru_symlink;                   /*Did we get to a mount point via a symlink?*/
-    
+
     int error = 0;
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        /* once per file */
        thru_symlink = 0;
 #ifdef WIN32
-       strcpy(orig_name, ti->data);
+    if( FAILED(StringCbCopy(orig_name, sizeof(orig_name), ti->data))) {
+        fprintf (stderr, "orig_name - not enough space");
+        exit(1);
+    }
 #else /* not WIN32 */
-       sprintf(orig_name, "%s%s",
-               (ti->data[0] == '/') ? "" : "./",
-               ti->data);
+
+    if( FAILED(StringCbPrintf(orig_name, sizeof(orig_name), "%s%s",
+        (ti->data[0] == '/') ? "" : "./",
+        ti->data))) {
+        fprintf (stderr, "orig_name - cannot be populated");
+        exit(1);
+    }
 #endif /* not WIN32 */
 
 #ifndef WIN32
@@ -1666,14 +1498,27 @@ ListMountCmd(struct cmd_syndesc *as, char *arock)
             * name (we know there is one) and splice in the symlink value.
             */
            if (true_name[0] != '\\') {
-               last_component = (char *) strrchr(orig_name, '\\');
-               strcpy(++last_component, true_name);
-               strcpy(true_name, orig_name);
+               last_component = (char *) strrchr(orig_name, '\\');
+               if( FAILED(StringCbCopy(++last_component, sizeof(orig_name) - (last_component - orig_name) * sizeof(char), true_name))) {
+                   fprintf (stderr, "last_component - not enough space");
+                    exit(1);
+               }
+               if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
+                   fprintf (stderr, "true_name - not enough space");
+                    exit(1);
+               }
            }
-       } else
-           strcpy(true_name, orig_name);
+       } else {
+           if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
+               fprintf (stderr, "true_name - not enough space");
+                exit(1);
+            }
+       }
 #else  /* WIN32 */
-       strcpy(true_name, orig_name);
+       if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
+           fprintf (stderr, "true_name - not enough space");
+            exit(1);
+        }
 #endif /* WIN32 */
 
        /*
@@ -1689,16 +1534,41 @@ ListMountCmd(struct cmd_syndesc *as, char *arock)
             * Found it.  Designate everything before it as the parent directory,
             * everything after it as the final component.
             */
-           strncpy(parent_dir, true_name, last_component - true_name + 1);
+           if( FAILED(StringCchCopyN(parent_dir, sizeof(parent_dir) / sizeof(char), true_name, last_component - true_name + 1))) {
+                fprintf (stderr, "parent_dir - not enough space");
+                exit(1);
+           }
            parent_dir[last_component - true_name + 1] = 0;
            last_component++;   /*Skip the slash*/
+#ifdef WIN32
+           if (!fs_InAFS(parent_dir)) {
+               const char * nbname = fs_NetbiosName();
+               if( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
+                   fprintf (stderr, "StringCbLength failure on nbname");
+                   exit(1);
+               }
+               if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
+                   parent_dir[len+2] == '\\' &&
+                   parent_dir[len+3] == '\0' &&
+                   !strnicmp(nbname,&parent_dir[2],len))
+               {
+                   if( FAILED(StringCbPrintf(parent_dir, sizeof(parent_dir),"\\\\%s\\all\\", nbname))) {
+                       fprintf (stderr, "parent_dir - cannot be populated");
+                        exit(1);
+                   }
+               }
+           }
+#endif
        } else {
            /*
             * No slash appears in the given file name.  Set parent_dir to the current
             * directory, and the last component as the given name.
             */
            fs_ExtractDriveLetter(true_name, parent_dir);
-           strcat(parent_dir, ".");
+           if( FAILED(StringCbCat(parent_dir, sizeof(parent_dir), "."))) {
+               fprintf (stderr, "parent_dir - not enough space");
+                exit(1);
+           }
            last_component = true_name;
             fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
        }
@@ -1711,24 +1581,29 @@ ListMountCmd(struct cmd_syndesc *as, char *arock)
        }
 
        blob.in = last_component;
-       blob.in_size = strlen(last_component)+1;
-       blob.out_size = MAXSIZE;
+       if( FAILED(StringCchLength(last_component, sizeof(true_name) / sizeof(char) - (last_component - true_name), &len))) {
+           fprintf (stderr, "StringCbLength failure on last_component");
+           exit(1);
+       }
+       blob.in_size = (long)len+1;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.out = space;
-       memset(space, 0, MAXSIZE);
+       memset(space, 0, AFS_PIOCTL_MAXSIZE);
 
-       code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
+       code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
 
        if (code == 0) {
-           printf("'%s' is a %smount point for volume '%s'\n",
+           printf("'%s' is a %smount point for volume '%.*s'\n",
                   ti->data,
                   (thru_symlink ? "symbolic link, leading to a " : ""),
-                  space);
+                   blob.out_size,
+                   space);
 
        } else {
            if (errno == EINVAL) {
                fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
            } else {
-               Die(errno, (ti->data ? ti->data : parent_dir));
+               fs_Die(errno, (ti->data ? ti->data : parent_dir));
            }
            error = 1;
        }
@@ -1737,36 +1612,29 @@ ListMountCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-MakeMountCmd(struct cmd_syndesc *as, char *arock)
+MakeMountCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     char *cellName, *volName, *tmpName;
 #ifdef WIN32
-    char localCellName[1000];
-#else /* not WIN32 */
+    char localCellName[128];
+#endif
+    char path[1024] = "";
     struct afsconf_cell info;
     struct vldbentry vldbEntry;
-#endif /* not WIN32 */
     struct ViceIoctl blob;
+    char * parent;
+    size_t len;
 
-    /*
-
-    defect #3069
-
-    if (as->parms[5].items && !as->parms[2].items) {
-       fprintf(stderr,"%s: must provide cell when creating cellular mount point.\n", pn);
-       return 1;
-    }
-    */
+    memset(&info, 0, sizeof(info));
 
     if (as->parms[2].items)    /* cell name specified */
        cellName = as->parms[2].items->data;
     else
        cellName = NULL;
     volName = as->parms[1].items->data;
-
-    if (strlen(volName) >= 64) {
-       fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
+    if( FAILED(StringCbLength(volName, VL_MAXNAMELEN, &len))) {
+        fprintf(stderr,"%s: volume name too long (length must be <= 64 characters)\n", pn);
        return 1;
     }
 
@@ -1784,21 +1652,71 @@ MakeMountCmd(struct cmd_syndesc *as, char *arock)
         volName = ++tmpName;
     }
 
-    if (!InAFS(Parent(as->parms[0].items->data))) {
-       fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
-       return 1;
+    parent = fs_GetParent(as->parms[0].items->data);
+    if (!fs_InAFS(parent)) {
+#ifdef WIN32
+       const char * nbname = fs_NetbiosName();
+       if ( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
+           fprintf (stderr, "StringCbLength failure on nbname");
+           exit(1);
+       }
+       if (parent[0] == '\\' && parent[1] == '\\' &&
+           (parent[len+2] == '\\' && parent[len+3] == '\0' || parent[len+2] == '\0') &&
+           !strnicmp(nbname,&parent[2],len))
+       {
+           if( FAILED(StringCbPrintf(path, sizeof(path),"%s%sall%s", parent,
+                                      parent[len+2]?"":"\\",
+                                      &as->parms[0].items->data[len+2]))) {
+               fprintf (stderr, "path - cannot be populated");
+                exit(1);
+            }
+           parent = fs_GetParent(path);
+           if (!fs_InAFS(parent)) {
+               fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
+               return 1;
+           }
+       } else
+#endif
+       {
+           fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
+           return 1;
+       }
     }
 
-    if (!cellName) {
-       blob.in_size = 0;
-       blob.out_size = MAXSIZE;
-       blob.out = space;
-       code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
+    if( FAILED(StringCbLength(path, sizeof(path), &len))) {
+        fprintf (stderr, "StringCbLength failure on path");
+        exit(1);
+    }
+    if ( len == 0 ) {
+       if( FAILED(StringCbCopy(path, sizeof(path), as->parms[0].items->data))) {
+           fprintf (stderr, "path - not enough space");
+            exit(1);
+       }
+    }
+    if ( fs_IsFreelanceRoot(parent) ) {
+       if ( !fs_IsAdmin() ) {
+           fprintf(stderr,"%s: Only AFS Client Administrators may alter the Freelance root.afs volume\n", pn);
+           return 1;
+       }
+
+       if (!cellName) {
+           blob.in_size = 0;
+           blob.out_size = sizeof(localCellName);
+           blob.out = localCellName;
+           code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
+           if (!code) {
+                localCellName[sizeof(localCellName) - 1] = '\0';
+               cellName = localCellName;
+            }
+       }
+    } else {
+       if (!cellName) {
+           code = GetCell(parent, space, sizeof(space));
+            if (code)
+                return 1;
+        }
     }
 
-#ifdef WIN32
-    strcpy(localCellName, (cellName? cellName : space));
-#else /* not win32 */
     code = GetCellName(cellName?cellName:space, &info);
     if (code) {
        return 1;
@@ -1811,44 +1729,66 @@ MakeMountCmd(struct cmd_syndesc *as, char *arock)
        code = VLDBInit(1, &info);
       if (code == 0) {
          /* make the check.  Don't complain if there are problems with init */
-         code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
+         code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
          if (code == VL_NOENT) {
              fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
                      pn, volName, cellName ? cellName : space);
          }
       }
     }
-#endif /* not WIN32 */
 
-    if (as->parms[3].items)    /* if -rw specified */
-       strcpy(space, "%");
-    else
-       strcpy(space, "#");
+    if (as->parms[3].items) {  /* if -rw specified */
+       if( FAILED(StringCbCopy(space, sizeof(space), "%"))) {
+           fprintf (stderr, "space arr - not enough space");
+            exit(1);
+       }
+       } else {
+           if( FAILED(StringCbCopy(space, sizeof(space), "#"))) {
+              fprintf (stderr, "space arr - not enough space");
+               exit(1);
+           }
+       }
     if (cellName) {
        /* cellular mount point, prepend cell prefix */
-#ifdef WIN32
-       strcat(space, localCellName);
-#else /* not WIN32 */
-       strcat(space, info.name);
-#endif /* not WIN32 */
-       strcat(space, ":");
+       if( FAILED(StringCbCat(space, sizeof(space), info.name))) {
+           fprintf (stderr, "space arr - not enough space");
+            exit(1);
+       }
+       if( FAILED(StringCbCat(space, sizeof(space), ":"))) {
+           fprintf (stderr, "space arr - not enough space");
+            exit(1);
+       }
+    }
+    if( FAILED(StringCbCat(space, sizeof(space), volName))) {    /* append volume name */
+        fprintf (stderr, "space arr - not enough space");
+        exit(1);
+    }
+    if( FAILED(StringCbCat(space, sizeof(space), "."))) {    /* stupid convention; these end with a period */
+        fprintf (stderr, "space arr - not enough space");
+        exit(1);
     }
-    strcat(space, volName);    /* append volume name */
-    strcat(space, ".");                /* stupid convention; these end with a period */
 #ifdef WIN32
     /* create symlink with a special pioctl for Windows NT, since it doesn't
      * have a symlink system call.
      */
     blob.out_size = 0;
-    blob.in_size = 1 + strlen(space);
+    if( FAILED(StringCbLength(space, sizeof(space), &len))) {
+        fprintf (stderr, "StringCbLength failure on space");
+        exit(1);
+    }
+    blob.in_size = 1 + (long)len;
     blob.in = space;
     blob.out = NULL;
-    code = pioctl(as->parms[0].items->data, VIOC_AFS_CREATE_MT_PT, &blob, 0);
+    code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
 #else /* not WIN32 */
-    code = symlink(space, as->parms[0].items->data);
+    code = symlink(space, path);
 #endif /* not WIN32 */
+
+    if (info.linkedCell)
+        free(info.linkedCell);
+
     if (code) {
-       Die(errno, as->parms[0].items->data);
+       fs_Die(errno, path);
        return 1;
     }
     return 0;
@@ -1861,7 +1801,7 @@ MakeMountCmd(struct cmd_syndesc *as, char *arock)
  *      tp: Set to point to the actual name of the mount point to nuke.
  */
 static int
-RemoveMountCmd(struct cmd_syndesc *as, char *arock) {
+RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
     afs_int32 code=0;
     struct ViceIoctl blob;
     struct cmd_item *ti;
@@ -1869,42 +1809,84 @@ RemoveMountCmd(struct cmd_syndesc *as, char *arock) {
     char lsbuffer[1024];
     char *tp;
     int error = 0;
-    
+    size_t len;
+
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        /* once per file */
        tp = (char *) strrchr(ti->data, '\\');
        if (!tp)
            tp = (char *) strrchr(ti->data, '/');
        if (tp) {
-           strncpy(tbuffer, ti->data, code=tp-ti->data+1);  /* the dir name */
-            tbuffer[code] = 0;
+            if( FAILED(StringCchCopyN(tbuffer, sizeof(tbuffer) / sizeof(char), ti->data, code=(afs_int32)(tp-ti->data+1)))) {    /* the dir name */
+               fprintf (stderr, "tbuffer - not enough space");
+                exit(1);
+            }
            tp++;   /* skip the slash */
+
+#ifdef WIN32
+           if (!fs_InAFS(tbuffer)) {
+               const char * nbname = fs_NetbiosName();
+               if( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
+                   fprintf (stderr, "StringCbLength failure on nbname");
+                   exit(1);
+               }
+
+               if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
+                   tbuffer[len+2] == '\\' &&
+                   tbuffer[len+3] == '\0' &&
+                   !strnicmp(nbname,&tbuffer[2],len))
+               {
+                   if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer),"\\\\%s\\all\\", nbname))) {
+                       fprintf (stderr, "tbuffer - cannot be populated");
+                        exit(1);
+                   }
+               }
+           }
+#endif
        } else {
            fs_ExtractDriveLetter(ti->data, tbuffer);
-           strcat(tbuffer, ".");
+           if( FAILED(StringCbCat(tbuffer, sizeof(tbuffer), "."))) {
+               fprintf (stderr, "tbuffer - not enough space");
+                exit(1);
+           }
            tp = ti->data;
-            fs_StripDriveLetter(tp, tp, 0);
+            fs_StripDriveLetter(tp, tp, strlen(tp) + 1);
        }
        blob.in = tp;
-       blob.in_size = strlen(tp)+1;
+       if( FAILED(StringCbLength(tp, AFS_PIOCTL_MAXSIZE, &len))) {
+           fprintf (stderr, "StringCbLength failure on tp");
+           exit(1);
+       }
+       blob.in_size = (long)len+1;
        blob.out = lsbuffer;
        blob.out_size = sizeof(lsbuffer);
-       code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
+       code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
        if (code) {
            if (errno == EINVAL) {
                fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
             } else {
-               Die(errno, ti->data);
+               fs_Die(errno, ti->data);
            }
             error = 1;
            continue;   /* don't bother trying */
        }
-       blob.out_size = 0;
+
+        if ( fs_IsFreelanceRoot(tbuffer) && !fs_IsAdmin() ) {
+            fprintf(stderr,"%s: Only AFS Client Administrators may alter the Freelance root.afs volume\n", pn);
+            error = 1;
+            continue;   /* skip */
+        }
+
+        blob.out_size = 0;
        blob.in = tp;
-       blob.in_size = strlen(tp)+1;
-       code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
+       if( FAILED(StringCbLength(tp, AFS_PIOCTL_MAXSIZE, &len))) {
+           fprintf (stderr, "StringCbLength failure on tp");
+           exit(1);
+       }
+       blob.in_size = (long)len+1;
+       code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
             error = 1;
        }
     }
@@ -1915,7 +1897,7 @@ RemoveMountCmd(struct cmd_syndesc *as, char *arock) {
 */
 
 static int
-CheckServersCmd(struct cmd_syndesc *as, char *arock)
+CheckServersCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -1924,22 +1906,25 @@ CheckServersCmd(struct cmd_syndesc *as, char *arock)
     char *tp;
     struct afsconf_cell info;
     struct chservinfo checkserv;
+    errno_t err;
+    size_t len;
 
+    memset(&info, 0, sizeof(info));
     memset(&checkserv, 0, sizeof(struct chservinfo));
     blob.in_size=sizeof(struct chservinfo);
     blob.in=(caddr_t)&checkserv;
 
-    blob.out_size = MAXSIZE;
+    blob.out_size = AFS_PIOCTL_MAXSIZE;
     blob.out = space;
     memset(space, 0, sizeof(afs_int32));       /* so we assure zero when nothing is copied back */
 
     /* prepare flags for checkservers command */
     temp = 2;  /* default to checking local cell only */
-    if (as->parms[2].items) 
+    if (as->parms[2].items)
         temp |= 1;     /* set fast flag */
-    if (as->parms[1].items) 
+    if (as->parms[1].items)
         temp &= ~2;    /* turn off local cell check */
-    
+
     checkserv.magic = 0x12345678;      /* XXX */
     checkserv.tflags=temp;
 
@@ -1949,10 +1934,22 @@ CheckServersCmd(struct cmd_syndesc *as, char *arock)
        if (code) {
            return 1;
        }
-       strcpy(checkserv.tbuffer,info.name);
-       checkserv.tsize=strlen(info.name)+1;
+       if( FAILED(StringCbCopy(checkserv.tbuffer, sizeof(checkserv.tbuffer), info.name))) {
+           fprintf (stderr, "tbuffer - not enough space");
+            exit(1);
+       }
+       if( FAILED(StringCbLength(info.name, sizeof(info.name), &len))) {
+           fprintf (stderr, "StringCbLength failure on info.name");
+           exit(1);
+       }
+       checkserv.tsize=(int)len+1;
+        if (info.linkedCell)
+            free(info.linkedCell);
     } else {
-        strcpy(checkserv.tbuffer,"\0");
+       if( FAILED(StringCbCopy(checkserv.tbuffer, sizeof(checkserv.tbuffer),"\0"))) {
+           fprintf (stderr, "tbuffer - not enough space");
+            exit(1);
+       }
         checkserv.tsize=0;
     }
 
@@ -1962,18 +1959,18 @@ CheckServersCmd(struct cmd_syndesc *as, char *arock)
         /* sanity check */
         if(checkserv.tinterval<0) {
             printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
-            checkserv.tinterval=0;
+            checkserv.tinterval=-1;
         } else if(checkserv.tinterval> 600) {
             printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
             checkserv.tinterval=600;   /* 10 min max interval */
-        }       
+        }
     } else {
         checkserv.tinterval = -1;      /* don't change current interval */
     }
 
-    if ( checkserv.tinterval != 0 ) {
+    if ( checkserv.tinterval >= 0 ) {
 #ifdef WIN32
-        if ( !IsAdmin() ) {
+        if ( !fs_IsAdmin() ) {
             fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
             return EACCES;
         }
@@ -1985,21 +1982,30 @@ CheckServersCmd(struct cmd_syndesc *as, char *arock)
 #endif /* WIN32 */
     }
 
-    code = pioctl(0, VIOCCKSERV, &blob, 1);
+    code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
     if (code) {
        if ((errno == EACCES) && (checkserv.tinterval > 0)) {
            printf("Must be root to change -interval\n");
            return code;
        }
-       Die(errno, 0);
+       fs_Die(errno, 0);
         return 1;
     }
+#if _MSC_VER < 1400
     memcpy(&temp, space, sizeof(afs_int32));
+#else
+    err = memcpy_s(&temp, sizeof(temp), space, sizeof(afs_int32));
+    if ( err ) {
+        fprintf (stderr, "memcpy_s failure on temp");
+        exit(1);
+    }
+#endif
+
     if (checkserv.tinterval >= 0) {
-       if (checkserv.tinterval > 0) 
-           printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n", 
+       if (checkserv.tinterval > 0)
+           printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
                   checkserv.tinterval, temp);
-       else 
+       else
            printf("The current down server probe interval is %d secs\n", temp);
        return 0;
     }
@@ -2007,9 +2013,18 @@ CheckServersCmd(struct cmd_syndesc *as, char *arock)
        printf("All servers are running.\n");
     } else {
        printf("These servers unavailable due to network or server problems: ");
-       for(j=0; j < MAXHOSTS; j++) {
-           memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
-           if (temp == 0) 
+       for(j=0; j < AFS_MAXHOSTS; j++) {
+#if _MSC_VER < 1400
+            memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
+#else
+            err = memcpy_s(&temp, sizeof(temp), space + j*sizeof(afs_int32), sizeof(afs_int32));
+           if ( err ) {
+                fprintf (stderr, "memcpy_s failure on temp");
+                exit(1);
+            }
+#endif
+
+           if (temp == 0)
                 break;
            tp = hostutil_GetNameByINet(temp);
            printf(" %s", tp);
@@ -2021,17 +2036,17 @@ CheckServersCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-MessagesCmd(struct cmd_syndesc *as, char *arock)
+MessagesCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code=0;
     struct ViceIoctl blob;
     struct gaginfo gagflags;
     struct cmd_item *show;
-    
+
     memset(&gagflags, 0, sizeof(struct gaginfo));
     blob.in_size = sizeof(struct gaginfo);
     blob.in = (caddr_t ) &gagflags;
-    blob.out_size = MAXSIZE;
+    blob.out_size = AFS_PIOCTL_MAXSIZE;
     blob.out = space;
     memset(space, 0, sizeof(afs_int32));       /* so we assure zero when nothing is copied back */
 
@@ -2045,51 +2060,51 @@ MessagesCmd(struct cmd_syndesc *as, char *arock)
         else if (!strcasecmp (show->data, "none"))
             /* do nothing */ ;
         else {
-            fprintf(stderr, 
-                     "unrecognized flag %s: must be in {user,console,all,none}\n", 
+            fprintf(stderr,
+                     "unrecognized flag %s: must be in {user,console,all,none}\n",
                      show->data);
             code = EINVAL;
         }
     }
+
     if (code)
         return 1;
 
-    code = pioctl(0, VIOC_GAG, &blob, 1);
+    code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
     if (code) {
-       Die(errno, 0);
+       fs_Die(errno, 0);
         return 1;
     }
     return 0;
 }
 
 static int
-CheckVolumesCmd(struct cmd_syndesc *as, char *arock)
+CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
-    
+
     blob.in_size = 0;
     blob.out_size = 0;
-    code = pioctl(0, VIOCCKBACK, &blob, 1);
+    code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
     if (code) {
-       Die(errno, 0);
+       fs_Die(errno, 0);
        return 1;
     }
     printf("All volumeID/name mappings checked.\n");
-    
+
     return 0;
 }
 
 static int
-SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
+SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
     afs_int32 temp;
-    
+
 #ifdef WIN32
-    if ( !IsAdmin() ) {
+    if ( !fs_IsAdmin() ) {
         fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
         return EACCES;
     }
@@ -2105,7 +2120,7 @@ SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
        return 1;
     }
     if (as->parms[0].items) {
-       code = util_GetInt32(as->parms[0].items->data, &temp);
+       code = util_GetHumanInt32(as->parms[0].items->data, &temp);
        if (code) {
            fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
            return 1;
@@ -2115,92 +2130,118 @@ SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
     blob.in = (char *) &temp;
     blob.in_size = sizeof(afs_int32);
     blob.out_size = 0;
-    code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
+    code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
     if (code) {
-       Die(errno, (char *) 0);
+       fs_Die(errno, (char *) 0);
         return 1;
-    } 
-      
+    }
+
     printf("New cache size set.\n");
     return 0;
 }
 
-#define MAXGCSIZE      16
 static int
-GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
+GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
-    afs_int32 parms[MAXGCSIZE];
+    cm_cacheParms_t parms;
 
-    memset(parms, 0, sizeof(parms));
+    memset(&parms, 0, sizeof(parms));
     blob.in = NULL;
     blob.in_size = 0;
     blob.out_size = sizeof(parms);
-    blob.out = (char *) parms;
-    code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
-    if (code) {
-       Die(errno, NULL);
+    blob.out = (char *) &parms;
+    code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
+    if (code || blob.out_size != sizeof(parms)) {
+       fs_Die(errno, NULL);
         return 1;
     }
-     
-    printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
-           parms[1], parms[0]);
-    if (parms[1] > parms[0])
+
+    printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
+           parms.parms[1], parms.parms[0]);
+    if (parms.parms[1] > parms.parms[0])
         printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
     return 0;
 }
 
 static int
-ListCellsCmd(struct cmd_syndesc *as, char *arock)
+ListCellsCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     afs_int32 i, j, *lp, magic, size;
     char *tp;
-    afs_int32 addr, maxa = OMAXHOSTS;
+    afs_int32 addr, maxa = AFS_OMAXHOSTS;
     struct ViceIoctl blob;
     int resolve;
+    errno_t err;
 
     resolve = !(as->parms[0].items);    /* -numeric */
-    
+
     for(i=0;i<1000;i++) {
        tp = space;
-       memcpy(tp, &i, sizeof(afs_int32));
+#if _MSC_VER < 1400
+        memcpy(tp, &i, sizeof(afs_int32));
+#else
+        err = memcpy_s(tp, sizeof(space), &i, sizeof(afs_int32));
+       if ( err ) {
+            fprintf (stderr, "memcpy_s failure on tp");
+            exit(1);
+        }
+#endif
        tp = (char *)(space + sizeof(afs_int32));
        lp = (afs_int32 *)tp;
        *lp++ = 0x12345678;
        size = sizeof(afs_int32) + sizeof(afs_int32);
-       blob.out_size = MAXSIZE;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = sizeof(afs_int32);
        blob.in = space;
        blob.out = space;
-       code = pioctl(0, VIOCGETCELL, &blob, 1);
+       code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
        if (code < 0) {
-           if (errno == EDOM) 
+           if (errno == EDOM)
                 break; /* done with the list */
-            Die(errno, 0);
+            fs_Die(errno, 0);
             return 1;
-       }       
+       }
        tp = space;
-       memcpy(&magic, tp, sizeof(afs_int32));  
+#if _MSC_VER < 1400
+        memcpy(&magic, tp, sizeof(afs_int32));
+#else
+        err = memcpy_s(&magic, sizeof(magic), tp, sizeof(afs_int32));
+       if ( err ) {
+            fprintf (stderr, "memcpy_s failure on magic");
+            exit(1);
+        }
+#endif
        if (magic == 0x12345678) {
-           maxa = MAXHOSTS;
+           maxa = AFS_MAXHOSTS;
            tp += sizeof(afs_int32);
        }
        printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
-       for(j=0; j < maxa; j++) {
+       for(j=0; j < maxa && j*sizeof(afs_int32) < AFS_PIOCTL_MAXSIZE; j++) {
             char *name, tbuffer[20];
-
-           memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
-           if (addr == 0) 
+#if _MSC_VER < 1400
+            memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
+#else
+            err = memcpy_s(&addr, sizeof(addr), tp + j*sizeof(afs_int32), sizeof(afs_int32));
+            if ( err ) {
+                fprintf (stderr, "memcpy_s failure on addr");
+                exit(1);
+           }
+#endif
+           if (addr == 0)
                 break;
 
             if (resolve) {
                 name = hostutil_GetNameByINet(addr);
             } else {
                 addr = ntohl(addr);
-                sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
-                         (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
+               if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
+                         (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
+                   fprintf (stderr, "tbuffer - cannot be populated");
+                    exit(1);
+               }
                 name = tbuffer;
             }
            printf(" %s", name);
@@ -2212,29 +2253,44 @@ ListCellsCmd(struct cmd_syndesc *as, char *arock)
 
 #ifndef WIN32
 static int
-ListAliasesCmd(struct cmd_syndesc *as, char *arock)
+ListAliasesCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code, i;
     char *tp, *aliasName, *realName;
     struct ViceIoctl blob;
+    errno_t err;
+    size_t len;
 
     for (i = 0;; i++) {
        tp = space;
-       memcpy(tp, &i, sizeof(afs_int32));
-       blob.out_size = MAXSIZE;
+#if _MSC_VER < 1400
+        memcpy(tp, &i, sizeof(afs_int32));
+#else
+        err = memcpy_s(tp, sizeof(space), &i, sizeof(afs_int32));
+       if ( err ) {
+            fprintf (stderr, "memcpy_s failure on tp");
+            exit(1);
+       }
+#endif
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
        blob.in_size = sizeof(afs_int32);
        blob.in = space;
        blob.out = space;
-       code = pioctl(0, VIOC_GETALIAS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
        if (code < 0) {
            if (errno == EDOM)
                break;          /* done with the list */
-           Die(errno, 0);
+           fs_Die(errno, 0);
            return 1;
        }
+        space[blob.out_size - 1] = '\0';
        tp = space;
        aliasName = tp;
-       tp += strlen(aliasName) + 1;
+       if( FAILED(StringCbLength(aliasName, sizeof(space), &len))) {
+           fprintf (stderr, "StringCbLength failure on aliasName");
+           exit(1);
+       }
+       tp += len + 1;
        realName = tp;
        printf("Alias %s for cell %s\n", aliasName, realName);
     }
@@ -2242,7 +2298,7 @@ ListAliasesCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
+CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -2251,7 +2307,7 @@ CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
     struct hostent *thp;
     char *tp;
     int setp;
-    
+
     ti = as->parms[0].items;
     setp = 1;
     if (ti) {
@@ -2259,22 +2315,30 @@ CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
        if (!thp) {
            fprintf(stderr, "host %s not found in host table.\n", ti->data);
            return 1;
-       }
-       else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
+       } else {
+#if _MSC_VER < 1400
+            memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
+#else
+            err = memcpy_s(&hostAddr, sizeof(hostAddr), thp->h_addr, sizeof(afs_int32));
+           if ( err ) {
+                fprintf (stderr, "memcpy_s failure on hostAddr");
+                exit(1);
+            }
+#endif
     } else {
         hostAddr = 0;   /* means don't set host */
        setp = 0;       /* aren't setting host */
     }
-    
+
     /* now do operation */
     blob.in_size = sizeof(afs_int32);
     blob.out_size = sizeof(afs_int32);
     blob.in = (char *) &hostAddr;
     blob.out = (char *) &hostAddr;
-    
-    code = pioctl(0, VIOC_CBADDR, &blob, 1);
+
+    code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
     if (code < 0) {
-       Die(errno, 0);
+       fs_Die(errno, 0);
        return 1;
     }
     return 0;
@@ -2282,131 +2346,225 @@ CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
 #endif /* WIN32 */
 
 static int
-NewCellCmd(struct cmd_syndesc *as, char *arock)
+NewCellCmd(struct cmd_syndesc *as, void *arock)
 {
-#ifndef WIN32
-    afs_int32 code, linkedstate=0, size=0, *lp;
+    afs_uint32 code, linkedstate=0, size=0, count=0, *lp;
+    afs_uint32 usedns=0, useregistry=0;
     struct ViceIoctl blob;
     struct cmd_item *ti;
-    char *tp, *cellname=0;
-    struct hostent *thp;
-    afs_int32 fsport = 0, vlport = 0;
+    char *tp, *cellname=0, *linked_cellname=0;
+    afs_uint32 fsport = 0, vlport = 0;
+    size_t destRemaining;
 
-    memset(space, 0, MAXHOSTS * sizeof(afs_int32));
-    tp = space;
-    lp = (afs_int32 *)tp;
-    *lp++ = 0x12345678;
-    tp += sizeof(afs_int32);
-    for(ti=as->parms[1].items; ti; ti=ti->next) {
-       thp = hostutil_GetHostByName(ti->data);
-       if (!thp) {
-           fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
-                  pn, ti->data);
-       }
-       else {
-           memcpy(tp, thp->h_addr, sizeof(afs_int32));
-           tp += sizeof(afs_int32);
-       }
+    if ( !fs_IsAdmin() ) {
+        fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
+        return EACCES;
+    }
+
+    /* if there is no cell specified, use old Windows behavior */
+    if (as->parms[0].items == NULL) {
+        blob.in_size = 0;
+        blob.in = (char *) 0;
+        blob.out_size = AFS_PIOCTL_MAXSIZE;
+        blob.out = space;
+
+        code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
+
+        if (code) {
+            fs_Die(errno, (char *) 0);
+            return 1;
+        }
+
+        printf("Cell servers information refreshed\n");
+        return 0;
+    } else {
+        cellname = as->parms[0].items->data;
     }
+
     if (as->parms[2].items) {
        /*
         * Link the cell, for the purposes of volume location, to the specified
         * cell.
         */
-       cellname = as->parms[2].items->data;
+       linked_cellname = as->parms[2].items->data;
        linkedstate = 1;
     }
-#ifdef FS_ENABLE_SERVER_DEBUG_PORTS
+
     if (as->parms[3].items) {
-       code = util_GetInt32(as->parms[3].items->data, &vlport);
+       code = util_GetInt32(as->parms[2].items->data, &vlport);
        if (code) {
            fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
            return code;
        }
     }
     if (as->parms[4].items) {
-       code = util_GetInt32(as->parms[4].items->data, &fsport);
+       code = util_GetInt32(as->parms[3].items->data, &fsport);
        if (code) {
            fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
            return code;
        }
     }
-#endif
-    tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
-    lp = (afs_int32 *)tp;    
-    *lp++ = fsport;
-    *lp++ = vlport;
-    *lp = linkedstate;
-    strcpy(space +  ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
-    size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
-    tp = (char *)(space + size);
-    if (linkedstate) {
-       strcpy(tp, cellname);
-       size += strlen(cellname) + 1;
-    }
-    blob.in_size = size;
-    blob.in = space;
-    blob.out_size = 0;
-    code = pioctl(0, VIOCNEWCELL, &blob, 1);
-    if (code < 0)
-       Die(errno, 0);
-    return 0;
-#else /* WIN32 */
-    afs_int32 code;
-    struct ViceIoctl blob;
-    
-    if ( !IsAdmin() ) {
-        fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
-        return EACCES;
+
+    if (as->parms[5].items) {
+        useregistry = 1;
     }
 
-    blob.in_size = 0;
-    blob.in = (char *) 0;
-    blob.out_size = MAXSIZE;
-    blob.out = space;
+    if (as->parms[6].items) {
+        usedns = 1;
+    }
 
-    code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
+    /* Count the number of hostnames */
+    for (ti=as->parms[1].items; ti && count < AFS_MAXHOSTS; ti=ti->next, count++);
 
-    if (code) {
-        Die(errno, (char *) 0);
-        return 1;
+    if (!usedns && count == 0) {
+        fprintf( stderr, "fs: at least one vldb server must be specified.");
+        exit(1);
     }
-    
-    printf("Cell servers information refreshed\n");
-    return 0;
-#endif /* WIN32 */
-}
 
-#ifndef WIN32
-static int
-NewAliasCmd(struct cmd_syndesc *as, char *arock)
-{
+    if (count > AFS_MAXHOSTS) {
+        fprintf( stderr, "fs: at most %u servers may be specified.", AFS_MAXHOSTS);
+        exit(1);
+    }
+
+    /*
+     * The pioctl data buffer consists of the following structure:
+     *
+     *  afs_uint32 flags
+     *  afs_uint32 alternative fs port
+     *  afs_uint32 alternative vl port
+     *  afs_uint32 count of vldb servers
+     *  char[]     cellname
+     *  char[]     linkedcell
+     *  n * char[] hostnames
+     */
+
+    memset(space, 0, sizeof(space));
+    tp = space;
+    lp = (afs_uint32 *)tp;
+
+    /* flags */
+    if (usedns)
+        *lp |= VIOC_NEWCELL2_FLAG_USEDNS;
+
+    if (useregistry)
+        *lp |= VIOC_NEWCELL2_FLAG_USEREG;
+
+    if (linkedstate)
+        *lp |= VIOC_NEWCELL2_FLAG_LINKED;
+    lp++;
+
+    /* alt fs port */
+    *lp++ = fsport;
+
+    /* alt vl port */
+    *lp++ = vlport;
+
+    /* count of server names */
+    *lp++ = count;
+
+    /* Switch back to char pointer */
+    tp = (char *)lp;
+
+    /* Add nul-terminated cellname */
+    destRemaining = sizeof(space) - (tp - space);
+    if( FAILED(StringCbCopyEx( tp,
+                               destRemaining,
+                               as->parms[0].items->data,
+                               &tp,
+                               &destRemaining,
+                               STRSAFE_FILL_ON_FAILURE))) {
+        fprintf (stderr, " not enough space for cellname");
+        exit(1);
+    }
+    /* Move beyond the terminating nul */
+    tp++;
+    destRemaining -= sizeof(char);
+
+    /* Add nul-terminated linkname */
+    if( FAILED(StringCbCopyEx( tp,
+                               destRemaining,
+                               linkedstate ? linked_cellname : "",
+                               &tp,
+                               &destRemaining,
+                               STRSAFE_FILL_ON_FAILURE))) {
+        fprintf (stderr, " not enough space for linked cellname");
+        exit(1);
+    }
+    /* Move beyond the terminating nul */
+    tp++;
+    destRemaining -= sizeof(char);
+
+    /* Add the servers */
+    for (ti=as->parms[1].items; ti; ti=ti->next) {
+        if( FAILED(StringCbCopyEx( tp,
+                                   destRemaining,
+                                   ti->data,
+                                   &tp,
+                                   &destRemaining,
+                                   STRSAFE_FILL_ON_FAILURE))) {
+            fprintf (stderr, " not enough space for server %s", ti->data);
+            exit(1);
+        }
+        /* Move beyond the terminating nul */
+        tp++;
+        destRemaining -= sizeof(char);
+    }
+
+    blob.in_size = (tp - space);
+    blob.in = space;
+    blob.out_size = 0;
+    blob.out = space;
+    code = pioctl_utf8(NULL, VIOCNEWCELL2, &blob, 1);
+
+    if (code) {
+        fs_Die(errno, as->parms[0].items->data);
+        return 1;
+    }
+
+    printf("Cell servers information for %s added or updated.\n",
+           as->parms[0].items->data);
+    return 0;
+}
+
+#ifndef WIN32
+static int
+NewAliasCmd(struct cmd_syndesc *as, void *arock)
+{
     afs_int32 code;
     struct ViceIoctl blob;
     char *tp;
     char *aliasName, *realName;
+    size_t destRemaining = sizeof(space);
 
     /* Setup and do the NEWALIAS pioctl call */
     aliasName = as->parms[0].items->data;
     realName = as->parms[1].items->data;
     tp = space;
-    strcpy(tp, aliasName);
-    tp += strlen(aliasName) + 1;
-    strcpy(tp, realName);
-    tp += strlen(realName) + 1;
+    if( FAILED(StringCbCopyEx(tp, destRemaining, aliasName, &tp, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
+        fprintf (stderr, "tp - not enough space");
+        exit(1);
+    }
+    tp++;
+    destRemaining -= sizeof(char);
+    if( FAILED(StringCbCopyEx(tp, destRemaining, realName, &tp, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
+        fprintf (stderr, "tp - not enough space");
+        exit(1);
+    }
+    tp++;
+    destRemaining -= sizeof(char);
 
     blob.in_size = tp - space;
     blob.in = space;
     blob.out_size = 0;
     blob.out = space;
-    code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
+    code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
     if (code < 0) {
        if (errno == EEXIST) {
            fprintf(stderr,
                    "%s: cell name `%s' in use by an existing cell.\n", pn,
                    aliasName);
        } else {
-           Die(errno, 0);
+           fs_Die(errno, 0);
        }
        return 1;
     }
@@ -2415,62 +2573,109 @@ NewAliasCmd(struct cmd_syndesc *as, char *arock)
 #endif /* WIN32 */
 
 static int
-WhichCellCmd(struct cmd_syndesc *as, char *arock)
+WhichCellCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct cmd_item *ti;
+    struct ViceIoctl blob;
     int error = 0;
-    char cell[MAXCELLCHARS];
-    
+    int literal = 0;
+    cm_ioctlQueryOptions_t options;
+
+    if (as->parms[1].items)
+        literal = 1;
+
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
-        code = GetCell(ti->data, cell);
+        cm_fid_t fid;
+        afs_uint32 filetype;
+       char cell[CELL_MAXNAMELEN];
+
+        /* once per file */
+        memset(&fid, 0, sizeof(fid));
+        memset(&options, 0, sizeof(options));
+        filetype = 0;
+        options.size = sizeof(options);
+        options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
+        options.literal = literal;
+       blob.in_size = options.size;    /* no variable length data */
+        blob.in = &options;
+
+        blob.out_size = sizeof(cm_fid_t);
+        blob.out = (char *) &fid;
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
+            blob.out_size == sizeof(cm_fid_t)) {
+            options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
+            options.fid = fid;
+        } else {
+           fs_Die(errno, ti->data);
+           error = 1;
+           continue;
+        }
+
+        blob.out_size = sizeof(filetype);
+        blob.out = &filetype;
+
+        code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
+        if (code || blob.out_size != sizeof(filetype)) {
+           fs_Die(errno, ti->data);
+           error = 1;
+           continue;
+        }
+        blob.out_size = CELL_MAXNAMELEN;
+        blob.out = cell;
+
+        code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
        if (code) {
            if (errno == ENOENT)
                fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
            else
-               Die(errno, ti->data);
+               fs_Die(errno, ti->data);
            error = 1;
            continue;
        }
-        printf("File %s lives in cell '%s'\n", ti->data, cell);
+        cell[CELL_MAXNAMELEN - 1] = '\0';
+        printf("%s %s lives in cell '%s'\n",
+                fs_filetypestr(filetype),
+                ti->data, cell);
     }
     return error;
 }
 
 static int
-WSCellCmd(struct cmd_syndesc *as, char *arock)
+WSCellCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
-    
+
     blob.in_size = 0;
     blob.in = NULL;
-    blob.out_size = MAXSIZE;
+    blob.out_size = AFS_PIOCTL_MAXSIZE;
     blob.out = space;
 
-    code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
 
     if (code) {
-       Die(errno, NULL);
+       fs_Die(errno, NULL);
         return 1;
     }
-
+    space[AFS_PIOCTL_MAXSIZE - 1] = '\0';
     printf("This workstation belongs to cell '%s'\n", space);
     return 0;
 }
 
 /*
 static int
-PrimaryCellCmd(struct cmd_syndesc *as, char *arock)
+PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
 {
     fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
     return 0;
 }
 */
 
+#ifndef AFS_NT40_ENV
 static int
-MonitorCmd(struct cmd_syndesc *as, char *arock)
+MonitorCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -2479,7 +2684,8 @@ MonitorCmd(struct cmd_syndesc *as, char *arock)
     struct hostent *thp;
     char *tp;
     int setp;
-    
+    errno_t err;
+
     ti = as->parms[0].items;
     setp = 1;
     if (ti) {
@@ -2497,8 +2703,16 @@ MonitorCmd(struct cmd_syndesc *as, char *arock)
                    return 1;
                }
            } else {
+#if _MSC_VER < 1400
                 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
-            }
+#else
+                err = memcpy_s(&hostAddr, sizeof(hostAddr), thp->h_addr, sizeof(afs_int32));
+               if ( err ) {
+                    fprintf (stderr, "memcpy_s failure on hostAddr");
+                    exit(1);
+                }
+#endif
+        }
        }
     } else {
        hostAddr = 0;   /* means don't set host */
@@ -2510,9 +2724,9 @@ MonitorCmd(struct cmd_syndesc *as, char *arock)
     blob.out_size = sizeof(afs_int32);
     blob.in = (char *) &hostAddr;
     blob.out = (char *) &hostAddr;
-    code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
-    if (code) {
-       Die(errno, 0);
+    code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
+    if (code || blob.out_size != sizeof(afs_int32)) {
+       fs_Die(errno, 0);
        return 1;
     }
     if (setp) {
@@ -2528,20 +2742,24 @@ MonitorCmd(struct cmd_syndesc *as, char *arock)
     }
     return 0;
 }
+#endif /* AFS_NT40_ENV */
 
 static int
-SysNameCmd(struct cmd_syndesc *as, char *arock)
+SysNameCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
     struct cmd_item *ti;
     char *input = space;
     afs_int32 setp = 0;
-    
+    errno_t err;
+    size_t destRemaining = sizeof(space);
+    size_t len;
+
     ti = as->parms[0].items;
     if (ti) {
 #ifdef WIN32
-    if ( !IsAdmin() ) {
+    if ( !fs_IsAdmin() ) {
         fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
         return EACCES;
     }
@@ -2555,61 +2773,91 @@ SysNameCmd(struct cmd_syndesc *as, char *arock)
 
     blob.in = space;
     blob.out = space;
-    blob.out_size = MAXSIZE;
+    blob.out_size = AFS_PIOCTL_MAXSIZE;
     blob.in_size = sizeof(afs_int32);
+#if _MSC_VER < 1400
     memcpy(input, &setp, sizeof(afs_int32));
+#else
+    err = memcpy_s(input, destRemaining, &setp, sizeof(afs_int32));
+    if ( err ) {
+        fprintf (stderr, "memcpy_s failure on input");
+        exit(1);
+    }
+#endif
     input += sizeof(afs_int32);
+    destRemaining -= sizeof(afs_int32);
     for (; ti; ti = ti->next) {
         setp++;
-        blob.in_size += strlen(ti->data) + 1;
-        if (blob.in_size > MAXSIZE) {
+        if( FAILED(StringCbCopyEx(input, destRemaining, ti->data, &input, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
             fprintf(stderr, "%s: sysname%s too long.\n", pn,
                      setp > 1 ? "s" : "");
             return 1;
         }
-        strcpy(input, ti->data);
-        input += strlen(ti->data);
-        *(input++) = '\0';
+        input++;
+        destRemaining -= sizeof(char);
     }
+    blob.in_size = (input - space) * sizeof(char);
+#if _MSC_VER < 1400
     memcpy(space, &setp, sizeof(afs_int32));
-    code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
+#else
+    err = memcpy_s(space, sizeof(space), &setp, sizeof(afs_int32));
+    if ( err ) {
+        fprintf (stderr, "memcpy_s failure on space");
+        exit(1);
+    }
+#endif
+
+    code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
     if (code) {
-        Die(errno, 0);
+        fs_Die(errno, 0);
         return 1;
-    }    
+    }
     if (setp) {
         printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
         return 0;
     }
 
     input = space;
+#if _MSC_VER < 1400
     memcpy(&setp, input, sizeof(afs_int32));
+#else
+    err = memcpy_s(&setp, sizeof(setp), input, sizeof(afs_int32));
+    if ( err ) {
+        fprintf (stderr, "memcpy_s failure on setp");
+        exit(1);
+    }
+#endif
     input += sizeof(afs_int32);
     if (!setp) {
         fprintf(stderr,"No sysname name value was found\n");
         return 1;
-    } 
-    
+    }
+    space[blob.out_size - 1] = '\0';
     printf("Current sysname%s is", setp > 1 ? " list" : "");
     for (; setp > 0; --setp ) {
         printf(" \'%s\'", input);
-        input += strlen(input) + 1;
+        if( FAILED(StringCbLength(input, sizeof(space) - (input - space), &len))) {
+            fprintf (stderr, "StringCbLength failure on input");
+            exit(1);
+        }
+        input += len + 1;
     }
     printf("\n");
     return 0;
 }
 
+#ifndef AFS_NT40_ENV
 static char *exported_types[] = {"null", "nfs", ""};
-static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
+static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
     struct cmd_item *ti;
     int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
     int exportcall, pwsync = 0, smounts = 0;
-    
+
 #ifdef WIN32
-    if ( !IsAdmin() ) {
+    if ( !fs_IsAdmin() ) {
         fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
         return EACCES;
     }
@@ -2621,7 +2869,7 @@ static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
 #endif /* WIN32 */
 
     ti = as->parms[0].items;
-    if (strcmp(ti->data, "nfs")        == 0) 
+    if (strcmp(ti->data, "nfs")        == 0)
         type = 0x71; /* NFS */
     else {
        fprintf(stderr,
@@ -2630,9 +2878,9 @@ static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
     }
     ti = as->parms[1].items;
     if (ti) {
-       if (strcmp(ti->data, "on") == 0) 
+       if (strcmp(ti->data, "on") == 0)
             export = 3;
-       else if (strcmp(ti->data, "off") == 0) 
+       else if (strcmp(ti->data, "off") == 0)
             export = 2;
        else {
            fprintf(stderr, "Illegal argument %s\n", ti->data);
@@ -2641,9 +2889,9 @@ static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
        exp = 1;
     }
     if (ti = as->parms[2].items) {     /* -noconvert */
-       if (strcmp(ti->data, "on") == 0) 
+       if (strcmp(ti->data, "on") == 0)
             mode = 2;
-       else if (strcmp(ti->data, "off") == 0) 
+       else if (strcmp(ti->data, "off") == 0)
             mode = 3;
        else {
            fprintf(stderr, "Illegal argument %s\n", ti->data);
@@ -2651,9 +2899,9 @@ static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
        }
     }
     if (ti = as->parms[3].items) {     /* -uidcheck */
-       if (strcmp(ti->data, "on") == 0) 
+       if (strcmp(ti->data, "on") == 0)
             pwsync = 3;
-       else if (strcmp(ti->data, "off") == 0) 
+       else if (strcmp(ti->data, "off") == 0)
             pwsync = 2;
        else {
            fprintf(stderr, "Illegal argument %s\n", ti->data);
@@ -2661,9 +2909,9 @@ static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
        }
     }
     if (ti = as->parms[4].items) {     /* -submounts */
-       if (strcmp(ti->data, "on") == 0) 
+       if (strcmp(ti->data, "on") == 0)
             smounts = 3;
-       else if (strcmp(ti->data, "off") == 0) 
+       else if (strcmp(ti->data, "off") == 0)
             smounts = 2;
        else {
            fprintf(stderr, "Illegal argument %s\n", ti->data);
@@ -2677,19 +2925,19 @@ static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
     blob.in_size = sizeof(afs_int32);
     blob.out = (char *) &exportcall;
     blob.out_size = sizeof(afs_int32);
-    code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
+    code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
     if (code) {
        if (errno == ENODEV) {
            fprintf(stderr,
                     "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
        } else {
-           Die(errno, 0);
+           fs_Die(errno, 0);
        }
         return 1;
     } else {
        if (!gstat) {
            if (exportcall & 1) {
-               printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n", 
+               printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
                       exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
                       (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
                       (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
@@ -2700,10 +2948,10 @@ static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
     }
     return 0;
 }
-
+#endif
 
 static int
-GetCellCmd(struct cmd_syndesc *as, char *arock)
+GetCellCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -2714,7 +2962,9 @@ GetCellCmd(struct cmd_syndesc *as, char *arock)
        afs_int32 junk;
     } args;
     int error = 0;
+    size_t len;
 
+    memset(&info, 0, sizeof(info));
     memset(&args, 0, sizeof(args));      /* avoid Purify UMR error */
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        /* once per cell */
@@ -2725,34 +2975,40 @@ GetCellCmd(struct cmd_syndesc *as, char *arock)
             error = 1;
            continue;
        }
-       blob.in_size = 1+strlen(info.name);
+        if (info.linkedCell)
+            free(info.linkedCell);
+        if( FAILED(StringCbLength(info.name, sizeof(info.name), &len))) {
+           fprintf (stderr, "StringCbLength failure on info.name");
+           exit(1);
+       }
+       blob.in_size = 1+(long)len;
        blob.in = info.name;
-       code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
        if (code) {
            if (errno == ENOENT)
                fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
            else
-               Die(errno, info.name);
+               fs_Die(errno, info.name);
            error = 1;
             continue;
        }
        printf("Cell %s status: ", info.name);
 #ifdef notdef
-       if (args.stat & 1) 
+       if (args.stat & 1)
             printf("primary ");
 #endif
-       if (args.stat & 2) 
+       if (args.stat & 2)
             printf("no setuid allowed");
-       else 
+       else
             printf("setuid allowed");
-       if (args.stat & 4) 
+       if (args.stat & 4)
             printf(", using old VLDB");
        printf("\n");
     }
     return error;
 }
 
-static int SetCellCmd(struct cmd_syndesc *as, char *arock)
+static int SetCellCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -2765,6 +3021,8 @@ static int SetCellCmd(struct cmd_syndesc *as, char *arock)
     } args;
     int error = 0;
 
+    memset(&info, 0, sizeof(info));
+
     /* Check arguments. */
     if (as->parms[1].items && as->parms[2].items) {
         fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
@@ -2776,7 +3034,7 @@ static int SetCellCmd(struct cmd_syndesc *as, char *arock)
     args.junk = 0;
 
 #ifdef WIN32
-    if ( !IsAdmin() ) {
+    if ( !fs_IsAdmin() ) {
         fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
         return EACCES;
     }
@@ -2787,7 +3045,7 @@ static int SetCellCmd(struct cmd_syndesc *as, char *arock)
     }
 #endif /* WIN32 */
 
-    if (! as->parms[1].items) 
+    if (! as->parms[1].items)
         args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
 
     /* set stat for all listed cells */
@@ -2798,77 +3056,55 @@ static int SetCellCmd(struct cmd_syndesc *as, char *arock)
             error = 1;
            continue;
        }
-       strcpy(args.cname, info.name);
+        if (info.linkedCell)
+            free(info.linkedCell);
+       if( FAILED(StringCbCopy(args.cname, sizeof(args.cname), info.name))) {
+           fprintf (stderr, "cname - not enough space");
+            exit(1);
+       }
        blob.in_size = sizeof(args);
        blob.in = (caddr_t) &args;
        blob.out_size = 0;
        blob.out = (caddr_t) 0;
-       code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
        if (code) {
-           Die(errno, info.name);      /* XXX added cell name to Die() call */
+           fs_Die(errno, info.name);      /* XXX added cell name to fs_Die() call */
             error = 1;
        }
     }
     return error;
 }
 
-#ifdef WIN32
 static int
 GetCellName(char *cellNamep, struct afsconf_cell *infop)
 {
-    strcpy(infop->name, cellNamep);
-    return 0;
-}
-
-static int
-VLDBInit(int noAuthFlag, struct afsconf_cell *infop)
-{
-    return 0;
-}
-#else /* not WIN32 */
-static int
-GetCellName(char *cellName, struct afsconf_cell *info)
-{
-    struct afsconf_dir *tdir;
-    int code;
-
-    tdir = afsconf_Open(AFSDIR_CLIENT_ETC_CLIENTNAME);
-    if (!tdir) {
-       fprintf(stderr,
-                "Could not process files in configuration directory (%s).\n",
-                 AFSDIR_CLIENT_ETC_CLIENTNAME);
-       return -1;
-    }
-
-    code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
-    if (code) {
-       fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName, 
-                AFSDIR_CLIENT_ETC_CLIENTNAME);
-       return code;
+    if( FAILED(StringCbCopy(infop->name, sizeof(infop->name), cellNamep))) {
+        fprintf (stderr, "name - not enough space");
+        exit(1);
     }
-
     return 0;
 }
 
-
 static int
 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
 {
     afs_int32 code;
+    char confDir[257];
 
-    code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH, 
-                          info->name, 0, &uclient, 
+    cm_GetConfigDir(confDir, sizeof(confDir));
+
+    code = ugen_ClientInit(noAuthFlag, confDir,
+                          info->name, 0, &uclient,
                            NULL, pn, rxkad_clear,
                            VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
                            0, 0, USER_SERVICE_ID);
     rxInitDone = 1;
     return code;
 }
-#endif /* not WIN32 */
 
 static struct ViceIoctl gblob;
 static int debug = 0;
-/* 
+/*
  * here follow some routines in suport of the setserverprefs and
  * getserverprefs commands.  They are:
  * SetPrefCmd  "top-level" routine
@@ -2880,15 +3116,15 @@ static int debug = 0;
  */
 
 #ifdef WIN32
-static int 
+static int
 pokeServers(void)
 {
     int code;
     cm_SSetPref_t *ssp;
-    code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
+    code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
 
     ssp = (cm_SSetPref_t *)space;
-    gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
+    gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
     gblob.in = space;
     return code;
 }
@@ -2903,14 +3139,14 @@ pokeServers(void)
 {
     int code;
 
-    code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
+    code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
     if (code && (errno == EINVAL)) {
        struct setspref *ssp;
        ssp = (struct setspref *)gblob.in;
        if (!(ssp->flags & DBservers)) {
            gblob.in = (void *)&(ssp->servers[0]);
            gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
-           code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
+           code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
            return code ? errno : 0;
        }
        fprintf(stderr,
@@ -2925,11 +3161,12 @@ pokeServers(void)
 #ifdef WIN32
 static int
 addServer(char *name, unsigned short rank)
-{  
+{
     int code;
     cm_SSetPref_t *ssp;
     cm_SPref_t *sp;
     struct hostent *thostent;
+    errno_t err;
 
 #ifndef MAXUSHORT
 #ifdef MAXSHORT
@@ -2954,7 +3191,16 @@ addServer(char *name, unsigned short rank)
     }
 
     sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
+#if _MSC_VER < 1400
     memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
+#else
+    err = memcpy_s (&(sp->host.s_addr), sizeof(afs_uint32), thostent->h_addr, sizeof(afs_uint32));
+    if ( err ) {
+        fprintf (stderr, "memcpy_s failure on sp->host.s_addr");
+        exit(1);
+    }
+#endif
+
     sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
     gblob.in_size += sizeof(cm_SPref_t);
     ssp->num_servers++;
@@ -2978,6 +3224,7 @@ addServer(char *name, afs_int32 rank)
     struct hostent *thostent;
     afs_uint32 addr;
     int error = 0;
+    errno_t err;
 
 #ifndef MAXUSHORT
 #ifdef MAXSHORT
@@ -3004,8 +3251,18 @@ addServer(char *name, afs_int32 rank)
        }
 
        sp = (struct spref *)(gblob.in + gblob.in_size);
-       memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
+#if _MSC_VER < 1400
+        memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
               sizeof(afs_uint32));
+#else
+        err = memcpy_s(&(sp->server.s_addr), sizeof(afs_uint32), thostent->h_addr_list[t],
+              sizeof(afs_uint32));
+        if ( err ) {
+            fprintf (stderr, "memcpy_s failure on sp->server.s_addr");
+            exit(1);
+        }
+#endif
+
        sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
        gblob.in_size += sizeof(struct spref);
        ssp->num_servers++;
@@ -3046,7 +3303,7 @@ static BOOL IsWindowsNT (void)
 
 #ifdef WIN32
 static int
-SetPrefCmd(struct cmd_syndesc *as, char * arock)
+SetPrefCmd(struct cmd_syndesc *as, void * arock)
 {
     FILE *infd;
     afs_int32 code;
@@ -3054,16 +3311,16 @@ SetPrefCmd(struct cmd_syndesc *as, char * arock)
     char name[80];
     afs_int32 rank;
     cm_SSetPref_t *ssp;
-    
+
     ssp = (cm_SSetPref_t *)space;
     ssp->flags = 0;
     ssp->num_servers = 0;
-    gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
+    gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
     gblob.in = space;
     gblob.out = space;
-    gblob.out_size = MAXSIZE;
+    gblob.out_size = AFS_PIOCTL_MAXSIZE;
 
-    if ( !IsAdmin() ) {
+    if ( !fs_IsAdmin() ) {
         fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
         return EACCES;
     }
@@ -3075,19 +3332,32 @@ SetPrefCmd(struct cmd_syndesc *as, char * arock)
         if (debug) fprintf(stderr,"opening file %s\n",ti->data);
         if (!(infd = fopen(ti->data,"r" ))) {
             code = errno;
-            Die(errno,ti->data);
-        }
-        else
+            fs_Die(errno,ti->data);
+        } else {
+#if _MSC_VER < 1400
             while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
                 code = addServer (name, (unsigned short) rank);
             }
+#else
+            while ( fscanf_s(infd, "%79s%ld", name, sizeof(name), &rank) != EOF) {
+                code = addServer (name, (unsigned short) rank);
+            }
+#endif
+        }
     }
 
+
     ti = as->parms[3].items;  /* -stdin */
     if (ti) {
-        while ( scanf("%79s%ld", name, &rank) != EOF) {
+#if _MSC_VER < 1400
+    while ( scanf("%79s%ld", name, &rank) != EOF) {
             code = addServer (name, (unsigned short) rank);
         }
+#else
+    while ( scanf_s("%79s%ld", name, sizeof(name), &rank) != EOF) {
+            code = addServer (name, (unsigned short) rank);
+        }
+#endif
     }
 
     for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
@@ -3102,11 +3372,11 @@ SetPrefCmd(struct cmd_syndesc *as, char * arock)
         }
     }
     code = pokeServers();
-    if (debug) 
+    if (debug)
         printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
 
     ssp = (cm_SSetPref_t *)space;
-    gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
+    gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
     gblob.in = space;
     ssp->flags = CM_SPREF_VLONLY;
     ssp->num_servers = 0;
@@ -3117,26 +3387,26 @@ SetPrefCmd(struct cmd_syndesc *as, char * arock)
                 break;
             }
             code = addServer (ti->data, (unsigned short) atol(ti->next->data));
-            if (debug) 
+            if (debug)
                 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
             ti=ti->next;
         }
     }
 
     if (as->parms[1].items) {
-        if (debug) 
+        if (debug)
             printf("now poking vlservers\n");
         code = pokeServers();
     }
 
-    if (code) 
-        Die(errno,0);
+    if (code)
+        fs_Die(errno,0);
 
     return code;
 }
 #else
 static int
-SetPrefCmd(struct cmd_syndesc *as, char *arock)
+SetPrefCmd(struct cmd_syndesc *as, void *arock)
 {
     FILE *infd;
     afs_int32 code;
@@ -3153,7 +3423,7 @@ SetPrefCmd(struct cmd_syndesc *as, char *arock)
     gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
     gblob.in = space;
     gblob.out = space;
-    gblob.out_size = MAXSIZE;
+    gblob.out_size = AFS_PIOCTL_MAXSIZE;
 
 
     if (geteuid()) {
@@ -3169,21 +3439,38 @@ SetPrefCmd(struct cmd_syndesc *as, char *arock)
            perror(ti->data);
            error = -1;
        } else {
-           while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
+#if _MSC_VER < 1400
+            while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
+               code = addServer(name, (unsigned short)rank);
+               if (code)
+                   error = code;
+           }
+#else
+            while (fscanf_s(infd, "%79s%ld", name, sizeof(name), &rank) != EOF) {
                code = addServer(name, (unsigned short)rank);
                if (code)
                    error = code;
            }
+#endif
+
        }
     }
 
     ti = as->parms[3].items;   /* -stdin */
     if (ti) {
+#if _MSC_VER < 1400
        while (scanf("%79s%ld", name, &rank) != EOF) {
            code = addServer(name, (unsigned short)rank);
            if (code)
                error = code;
        }
+#else
+        while (scanf_s("%79s%ld", name, sizeof(name), &rank) != EOF) {
+           code = addServer(name, (unsigned short)rank);
+           if (code)
+               error = code;
+       }
+#endif
     }
 
     for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
@@ -3234,15 +3521,15 @@ SetPrefCmd(struct cmd_syndesc *as, char *arock)
     }
 
     if (error > 0)
-       Die(error, 0);
+       fs_Die(error, 0);
 
     return error ? 1 : 0;
 }
 #endif /* WIN32 */
 
 #ifdef WIN32
-static int 
-GetPrefCmd(struct cmd_syndesc *as, char *arock)
+static int
+GetPrefCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct cmd_item *ti;
@@ -3255,13 +3542,13 @@ GetPrefCmd(struct cmd_syndesc *as, char *arock)
     struct cm_SPrefRequest *in;
     struct cm_SPrefInfo *out;
     int i;
-    
+
     code = 0;
     ti = as->parms[0].items;  /* -file */
     if (ti) {
         if (debug) fprintf(stderr,"opening file %s\n",ti->data);
         if (!(outfd = freopen(ti->data,"w",stdout))) {
-            Die(errno,ti->data);
+            fs_Die(errno,ti->data);
             return errno;
         }
     }
@@ -3279,15 +3566,15 @@ GetPrefCmd(struct cmd_syndesc *as, char *arock)
         blob.in_size=sizeof(struct cm_SPrefRequest);
         blob.in = (char *)in;
         blob.out = space;
-        blob.out_size = MAXSIZE;
+        blob.out_size = AFS_PIOCTL_MAXSIZE;
 
-        in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
-        in->flags = vlservers; 
+        in->num_servers = (AFS_PIOCTL_MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
+        in->flags = vlservers;
 
-        code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
+        code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
         if (code){
             perror("getserverprefs pioctl");
-            Die (errno,0);
+            fs_Die (errno,0);
         }
         else {
             out = (struct cm_SPrefInfo *) blob.out;
@@ -3298,11 +3585,14 @@ GetPrefCmd(struct cmd_syndesc *as, char *arock)
                 }
                 else {
                     addr = ntohl(out->servers[i].host.s_addr);
-                    sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
-                             (addr>>8) & 0xff, addr & 0xff);
+                   if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
+                        (addr>>8) & 0xff, addr & 0xff))) {
+                       fprintf (stderr, "tbuffer - cannot be populated");
+                        exit(1);
+                   }
                     name=tbuffer;
                 }
-                printf ("%-50s %5u\n",name,out->servers[i].rank);      
+                printf ("%-50s %5u\n",name,out->servers[i].rank);
             }
 
             in->offset = out->next_offset;
@@ -3313,7 +3603,7 @@ GetPrefCmd(struct cmd_syndesc *as, char *arock)
 }
 #else
 static int
-GetPrefCmd(struct cmd_syndesc *as, char *arock)
+GetPrefCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct cmd_item *ti;
@@ -3350,13 +3640,13 @@ GetPrefCmd(struct cmd_syndesc *as, char *arock)
        blob.in_size = sizeof(struct sprefrequest);
        blob.in = (char *)in;
        blob.out = space;
-       blob.out_size = MAXSIZE;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
 
        in->num_servers =
-           (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
+           (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
        in->flags = vlservers;
 
-       code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
        if (code) {
            perror("getserverprefs pioctl");
            return 1;
@@ -3369,8 +3659,11 @@ GetPrefCmd(struct cmd_syndesc *as, char *arock)
                name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
            } else {
                addr = ntohl(out->servers[i].server.s_addr);
-               sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
-                       (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
+               if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
+                   (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
+                   fprintf (stderr, "tbuffer - cannot be populated");
+                    exit(1);
+               }
                name = tbuffer;
            }
            printf("%-50s %5u\n", name, out->servers[i].rank);
@@ -3383,16 +3676,175 @@ GetPrefCmd(struct cmd_syndesc *as, char *arock)
 }
 #endif /* WIN32 */
 
+static afs_int32
+SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
+{
+    long inValue = 0;
+    long outValue = 0;
+    long code;
+
+    struct ViceIoctl blob;
+
+    if (asp->parms[0].items) {
+        /* On */
+
+        inValue = 3;
+    } else if (asp->parms[1].items) {
+        /* Off */
+
+        inValue = 2;
+    }
+
+    if (inValue != 0 && !fs_IsAdmin()) {
+        fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
+        return EACCES;
+    }
+
+    blob.in_size = sizeof(inValue);
+    blob.in = (char *) &inValue;
+    blob.out_size = sizeof(outValue);
+    blob.out = (char *) &outValue;
+
+    code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
+    if (code) {
+        fs_Die(errno, NULL);
+        return code;
+    }
+
+    if (outValue != 2) {
+        printf("Unicode support is %s%s.\n",
+               ((outValue != 0)? "enabled":"disabled"),
+               ((inValue != 0)? " for new SMB connections":""));
+    } else {
+        printf("Unicode support is absent in this installation of OpenAFS.\n");
+    }
+
+    return 0;
+}
+
 static int
-TraceCmd(struct cmd_syndesc *asp, char *arock)
+GetFidCmd(struct cmd_syndesc *as, void *arock)
+{
+    afs_int32 code;
+    struct ViceIoctl blob;
+    struct cmd_item *ti;
+    int error = 0;
+    int literal = 0;
+    cm_ioctlQueryOptions_t options;
+
+    if (as->parms[1].items)
+        literal = 1;
+
+    SetDotDefault(&as->parms[0].items);
+    for(ti=as->parms[0].items; ti; ti=ti->next) {
+        cm_fid_t fid;
+        afs_uint32 filetype;
+       char cell[CELL_MAXNAMELEN];
+
+        /* once per file */
+        memset(&fid, 0, sizeof(fid));
+        memset(&options, 0, sizeof(options));
+        filetype = 0;
+        options.size = sizeof(options);
+        options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
+        options.literal = literal;
+       blob.in_size = options.size;    /* no variable length data */
+        blob.in = &options;
+
+        blob.out_size = sizeof(cm_fid_t);
+        blob.out = (char *) &fid;
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
+            blob.out_size == sizeof(cm_fid_t)) {
+            options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
+            options.fid = fid;
+        } else {
+           fs_Die(errno, ti->data);
+           error = 1;
+           continue;
+        }
+
+        blob.out_size = sizeof(filetype);
+        blob.out = &filetype;
+
+        code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
+        if (code || blob.out_size != sizeof(filetype)) {
+           fs_Die(errno, ti->data);
+           error = 1;
+           continue;
+        }
+        blob.out_size = CELL_MAXNAMELEN;
+        blob.out = cell;
+
+        code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
+        if (code == 0)
+            cell[CELL_MAXNAMELEN - 1] = '\0';
+        printf("%s %s (%u.%u.%u) contained in cell %s\n",
+                fs_filetypestr(filetype),
+                ti->data, fid.volume, fid.vnode, fid.unique,
+                code ? "unknown-cell" : cell);
+    }
+    return error;
+}
+
+static int
+UuidCmd(struct cmd_syndesc *asp, void *arock)
+{
+    long code;
+    long inValue;
+    afsUUID outValue;
+    struct ViceIoctl blob;
+    char * uuidstring = NULL;
+
+    if (asp->parms[0].items) {
+#ifdef WIN32
+        if ( !fs_IsAdmin() ) {
+            fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
+            return EACCES;
+        }
+#else
+        if (geteuid()) {
+            fprintf (stderr, "Permission denied: requires root access.\n");
+            return EACCES;
+        }
+#endif
+        inValue = 1;            /* generate new UUID */
+    } else {
+        inValue = 0;            /* just show the current UUID */
+    }
+
+    blob.in_size = sizeof(inValue);
+    blob.in = (char *) &inValue;
+    blob.out_size = sizeof(outValue);
+    blob.out = (char *) &outValue;
+
+    code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
+    if (code || blob.out_size != sizeof(outValue)) {
+        fs_Die(errno, NULL);
+        return code;
+    }
+
+    UuidToString((UUID *) &outValue, &uuidstring);
+
+    printf("%sUUID: %s",
+           ((inValue == 1)?"New ":""),
+           uuidstring);
+
+    if (uuidstring)
+        RpcStringFree(&uuidstring);
+
+    return 0;
+}
+
+static int
+TraceCmd(struct cmd_syndesc *asp, void *arock)
 {
     long code;
     struct ViceIoctl blob;
     long inValue;
     long outValue;
-    
+
 #ifdef WIN32
-    if ( !IsAdmin() ) {
+    if ( !fs_IsAdmin() ) {
         fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
         return EACCES;
     }
@@ -3407,32 +3859,32 @@ TraceCmd(struct cmd_syndesc *asp, char *arock)
         fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
         return EINVAL;
     }
-        
+
     /* determine if we're turning this tracing on or off */
     inValue = 0;
     if (asp->parms[0].items)
         inValue = 3;           /* enable */
-    else if (asp->parms[1].items) 
+    else if (asp->parms[1].items)
         inValue = 2;   /* disable */
-    if (asp->parms[2].items) 
+    if (asp->parms[2].items)
         inValue |= 4;          /* do reset */
-    if (asp->parms[3].items) 
+    if (asp->parms[3].items)
         inValue |= 8;          /* dump */
-        
+
     blob.in_size = sizeof(long);
     blob.in = (char *) &inValue;
     blob.out_size = sizeof(long);
     blob.out = (char *) &outValue;
-        
-    code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
-    if (code) {
-        Die(errno, NULL);
+
+    code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
+    if (code || blob.out_size != sizeof(long)) {
+        fs_Die(errno, NULL);
         return code;
     }
 
-    if (outValue) 
+    if (outValue)
         printf("AFS tracing enabled.\n");
-    else 
+    else
         printf("AFS tracing disabled.\n");
 
     return 0;
@@ -3442,11 +3894,11 @@ static void sbusage(void)
 {
     fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
     fprintf(stderr, "               %s sb 50000 *.[ao] -default 10\n", pn);
-}       
+}
 
 /* fs sb -kbytes 9999 -files *.o -default 64 */
 static int
-StoreBehindCmd(struct cmd_syndesc *as, char *arock)
+StoreBehindCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code = 0;
     struct ViceIoctl blob;
@@ -3458,8 +3910,8 @@ StoreBehindCmd(struct cmd_syndesc *as, char *arock)
     int error = 0;
 
 #ifdef WIN32
-    if ( !IsAdmin() ) {
-        fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");  
+    if ( !fs_IsAdmin() ) {
+        fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
         return EACCES;
     }
 #endif /* WIN32 */
@@ -3473,7 +3925,11 @@ StoreBehindCmd(struct cmd_syndesc *as, char *arock)
            return 1;
        }
        tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
-       if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
+       if (errno == ERANGE) {
+           fprintf(stderr, "%s: ti->data must within long int range", pn);
+           return 1;
+       }
+       if ((tsb.sb_thisfile < 0) || (*t != '\0')) {
            fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
                    ti->data);
            return 1;
@@ -3484,7 +3940,11 @@ StoreBehindCmd(struct cmd_syndesc *as, char *arock)
     ti = as->parms[2].items;   /* -allfiles */
     if (ti) {
        allfiles = strtol(ti->data, &t, 10) * 1024;
-       if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
+       if (errno == ERANGE) {
+           fprintf(stderr, "%s: ti->data must within long int range", pn);
+           return 1;
+       }
+       if ((allfiles < 0) || (*t != '\0')) {
            fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
                    ti->data);
            return 1;
@@ -3505,16 +3965,16 @@ StoreBehindCmd(struct cmd_syndesc *as, char *arock)
     /* once per -file */
     for (ti = as->parms[1].items; ti; ti = ti->next) {
        /* Do this solely to see if the file is there */
-       code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
            error = 1;
            continue;
        }
 
-       code = pioctl(ti->data, VIOC_STOREBEHIND, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
        if (code) {
-           Die(errno, ti->data);
+           fs_Die(errno, ti->data);
            error = 1;
            continue;
        }
@@ -3536,9 +3996,9 @@ StoreBehindCmd(struct cmd_syndesc *as, char *arock)
      */
     if (!as->parms[1].items || (allfiles != -1)) {
        tsb.sb_default = allfiles;
-       code = pioctl(0, VIOC_STOREBEHIND, &blob, 1);
+       code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
        if (code) {
-           Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
+           fs_Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
            error = 1;
        }
     }
@@ -3552,15 +4012,15 @@ StoreBehindCmd(struct cmd_syndesc *as, char *arock)
     return error;
 }
 
-static afs_int32 
-SetCryptCmd(struct cmd_syndesc *as, char *arock)
+static afs_int32
+SetCryptCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code = 0, flag;
     struct ViceIoctl blob;
     char *tp;
+
 #ifdef WIN32
-    if ( !IsAdmin() ) {
+    if ( !fs_IsAdmin() ) {
         fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
         return EACCES;
     }
@@ -3571,41 +4031,55 @@ SetCryptCmd(struct cmd_syndesc *as, char *arock)
       flag = 1;
     else if (strcmp(tp, "off") == 0)
       flag = 0;
+    else if (strcmp(tp, "auth") == 0)
+      flag = 2;
     else {
-      fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
+      fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
       return EINVAL;
     }
 
     blob.in = (char *) &flag;
     blob.in_size = sizeof(flag);
     blob.out_size = 0;
-    code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
+    code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
     if (code)
-        Die(code, NULL);
+        fs_Die(code, NULL);
     return 0;
 }
 
-static afs_int32 
-GetCryptCmd(struct cmd_syndesc *as, char *arock)
+static afs_int32
+GetCryptCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code = 0, flag;
     struct ViceIoctl blob;
     char *tp;
+    errno_t err;
+
     blob.in = NULL;
     blob.in_size = 0;
     blob.out_size = sizeof(flag);
     blob.out = space;
 
-    code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
+    code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
 
-    if (code) 
-        Die(code, NULL);
+    if (code || blob.out_size != sizeof(flag))
+        fs_Die(code, NULL);
     else {
-      tp = space;
-      memcpy(&flag, tp, sizeof(afs_int32));
+        tp = space;
+#if _MSC_VER < 1400
+        memcpy(&flag, tp, sizeof(afs_int32));
+#else
+        err = memcpy_s(&flag, sizeof(flag), tp, sizeof(afs_int32));
+        if ( err ) {
+            fprintf (stderr, "memcpy_s failure on flag");
+            exit(1);
+        }
+#endif
+
       printf("Security level is currently ");
-      if (flag == 1)
+      if (flag == 2)
+          printf("auth (data integrity).\n");
+      else if (flag == 1)
         printf("crypt (data security).\n");
       else
         printf("clear.\n");
@@ -3614,48 +4088,103 @@ GetCryptCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-MemDumpCmd(struct cmd_syndesc *asp, char *arock)
+MemDumpCmd(struct cmd_syndesc *asp, void *arock)
 {
     long code;
     struct ViceIoctl blob;
-    long inValue;
+    long inValue = 0;
     long outValue;
-  
+
+    if ( !fs_IsAdmin() ) {
+        fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
+        return EACCES;
+    }
+
     if ((asp->parms[0].items && asp->parms[1].items)) {
         fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
         return EINVAL;
     }
-  
+
     /* determine if we're turning this tracing on or off */
-    inValue = 0;
     if (asp->parms[0].items)
         inValue = 1;            /* begin */
-    else if (asp->parms[1].items) 
+    else if (asp->parms[1].items)
         inValue = 0;            /* end */
-  
+
+
     blob.in_size = sizeof(long);
     blob.in = (char *) &inValue;
     blob.out_size = sizeof(long);
     blob.out = (char *) &outValue;
 
-    code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
-    if (code) {
-        Die(errno, NULL);
+    code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
+    if (code || blob.out_size != sizeof(long)) {
+        fs_Die(errno, NULL);
         return code;
     }
 
-    if (outValue) printf("AFS memdump begin.\n");
-    else printf("AFS memdump end.\n");
+    if (!outValue) {
+        printf("AFS memdump created.\n");
+        return 0;
+    } else {
+        printf("AFS memdump failed.\n");
+        return -1;
+    }
+}
+
+static int
+MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
+{
+    BOOL success = 0;
+    SERVICE_STATUS status;
+    SC_HANDLE hManager = NULL;
+    SC_HANDLE hService = NULL;
 
-    return 0;
+    if ( !fs_IsAdmin() ) {
+        fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
+        return EACCES;
+    }
+
+    hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
+    if (!hManager)
+        goto failure;
+
+    hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
+    if (!hService)
+        goto failure;
+
+    success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
+
+    if (success) {
+        CloseServiceHandle(hService);
+        CloseServiceHandle(hManager);
+
+        printf("AFS minidump generated.\n");
+        return 0;
+    }
+
+  failure:
+    if (hService)
+        CloseServiceHandle(hService);
+    if (hManager)
+        CloseServiceHandle(hManager);
+
+    printf("AFS minidump failed.\n");
+    return -1;
 }
 
 static int
-CSCPolicyCmd(struct cmd_syndesc *asp, char *arock)
+CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
 {
     struct cmd_item *ti;
     char *share = NULL;
     HKEY hkCSCPolicy;
+    size_t len;
+
+    if ( !fs_IsAdmin() ) {
+        fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
+        return EACCES;
+    }
 
     for(ti=asp->parms[0].items; ti;ti=ti->next) {
         share = ti->data;
@@ -3669,13 +4198,13 @@ CSCPolicyCmd(struct cmd_syndesc *asp, char *arock)
     {
         char *policy;
 
-        RegCreateKeyEx( HKEY_LOCAL_MACHINE, 
-                        "SOFTWARE\\OpenAFS\\Client\\CSCPolicy",
-                        0, 
-                        "AFS", 
+        RegCreateKeyEx( HKEY_LOCAL_MACHINE,
+                         AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
+                        0,
+                        "AFS",
                         REG_OPTION_NON_VOLATILE,
-                        KEY_WRITE,
-                        NULL, 
+                        (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
+                        NULL,
                         &hkCSCPolicy,
                         NULL );
 
@@ -3684,27 +4213,35 @@ CSCPolicyCmd(struct cmd_syndesc *asp, char *arock)
             return EACCES;
         }
 
-        if ( !IsAdmin() ) {
+        if ( !fs_IsAdmin() ) {
             fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
             RegCloseKey(hkCSCPolicy);
             return EACCES;
         }
 
         policy = "manual";
-               
-        if (asp->parms[1].items)
+        len = 6;
+
+        if (asp->parms[1].items) {
             policy = "manual";
-        if (asp->parms[2].items)
+            len = 6;
+        }
+        if (asp->parms[2].items) {
             policy = "programs";
-        if (asp->parms[3].items)
+            len = 8;
+        }
+        if (asp->parms[3].items) {
             policy = "documents";
-        if (asp->parms[4].items)
+            len = 9;
+        }
+        if (asp->parms[4].items) {
             policy = "disable";
-               
-        RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, strlen(policy)+1);
-               
+            len = 7;
+        }
+        RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)len+1);
+
         printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
-        printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n"); 
+        printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
     }
     else
     {
@@ -3717,13 +4254,13 @@ CSCPolicyCmd(struct cmd_syndesc *asp, char *arock)
 
         /* list current csc policies */
 
-        RegCreateKeyEx( HKEY_LOCAL_MACHINE, 
-                        "SOFTWARE\\OpenAFS\\Client\\CSCPolicy",
-                        0, 
-                        "AFS", 
+        RegCreateKeyEx( HKEY_LOCAL_MACHINE,
+                        AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
+                        0,
+                        "AFS",
                         REG_OPTION_NON_VOLATILE,
-                        KEY_READ|KEY_QUERY_VALUE,
-                        NULL, 
+                        (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
+                        NULL,
                         &hkCSCPolicy,
                         NULL );
 
@@ -3740,7 +4277,7 @@ CSCPolicyCmd(struct cmd_syndesc *asp, char *arock)
                          NULL,  /* lpcbSecurityDescriptor */
                          NULL   /* lpftLastWriteTime */
                          );
-               
+
         printf("Current CSC policies:\n");
         for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
 
@@ -3760,7 +4297,7 @@ CSCPolicyCmd(struct cmd_syndesc *asp, char *arock)
 #ifndef WIN32
 /* get clients interface addresses */
 static int
-GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
+GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct cmd_item *ti;
@@ -3776,12 +4313,12 @@ GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
        blob.in_size = sizeof(struct sprefrequest);
        blob.in = (char *)in;
        blob.out = space;
-       blob.out_size = MAXSIZE;
+       blob.out_size = AFS_PIOCTL_MAXSIZE;
 
        in->num_servers =
-           (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
+           (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
        /* returns addr in network byte order */
-       code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
        if (code) {
            perror("getClientInterfaceAddr pioctl");
            return 1;
@@ -3794,8 +4331,11 @@ GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
                afs_int32 addr;
                char tbuffer[32];
                addr = ntohl(out->servers[i].server.s_addr);
-               sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
-                       (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
+               if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
+                   (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
+                   fprintf (stderr, "tbuffer - cannot be populated");
+                    exit(1);
+               }
                printf("%-50s\n", tbuffer);
            }
            in->offset = out->next_offset;
@@ -3806,7 +4346,7 @@ GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
+SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code, addr;
     struct cmd_item *ti;
@@ -3822,7 +4362,7 @@ SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
     ssp->num_servers = 0;
     blob.in = space;
     blob.out = space;
-    blob.out_size = MAXSIZE;
+    blob.out_size = AFS_PIOCTL_MAXSIZE;
 
     if (geteuid()) {
        fprintf(stderr, "Permission denied: requires root access.\n");
@@ -3870,9 +4410,9 @@ SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
     }
     blob.in_size = sizeUsed - sizeof(struct spref);
 
-    code = pioctl(0, VIOC_SETCPREFS, &blob, 1);        /* network order */
+    code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1);   /* network order */
     if (code) {
-       Die(errno, 0);
+       fs_Die(errno, 0);
        error = 1;
     }
 
@@ -3880,7 +4420,7 @@ SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-FlushMountCmd(struct cmd_syndesc *as, char *arock)
+FlushMountCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     struct ViceIoctl blob;
@@ -3893,12 +4433,16 @@ FlushMountCmd(struct cmd_syndesc *as, char *arock)
     int link_chars_read;       /*Num chars read in readlink() */
     int thru_symlink;          /*Did we get to a mount point via a symlink? */
     int error = 0;
+    size_t len;
 
     for (ti = as->parms[0].items; ti; ti = ti->next) {
        /* once per file */
        thru_symlink = 0;
-       sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
-               ti->data);
+       if( FAILED(StringCbPrintf(orig_name, sizeof(orig_name), "%s%s", (ti->data[0] == '/') ? "" : "./",
+           ti->data))) {
+           fprintf (stderr, "orig_name - cannot be populated");
+            exit(1);
+       }
 
        if (lstat(orig_name, &statbuff) < 0) {
            /* if lstat fails, we should still try the pioctl, since it
@@ -3938,12 +4482,21 @@ FlushMountCmd(struct cmd_syndesc *as, char *arock)
             */
            if (true_name[0] != '/') {
                last_component = (char *)strrchr(orig_name, '/');
-               strcpy(++last_component, true_name);
-               strcpy(true_name, orig_name);
+               if( FAILED(StringCbCopy(++last_component, sizeof(orig_name) - (last_component - orig_name) * sizeof(char), true_name))) {
+                   fprintf (stderr, "last_component - not enough space");
+                    exit(1);
+               }
+               if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
+                   fprintf (stderr, "true_name - not enough space");
+                    exit(1);
+               }
            }
-       } else
-           strcpy(true_name, orig_name);
-
+       } else {
+           if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
+               fprintf (stderr, "true_name - not enough space");
+                exit(1);
+           }
+       }
        /*
         * Find rightmost slash, if any.
         */
@@ -3953,7 +4506,10 @@ FlushMountCmd(struct cmd_syndesc *as, char *arock)
             * Found it.  Designate everything before it as the parent directory,
             * everything after it as the final component.
             */
-           strncpy(parent_dir, true_name, last_component - true_name);
+           if( FAILED(StringCchCopyN(parent_dir, sizeof(parent_dir) / sizeof(char), true_name, last_component - true_name))) {
+               fprintf (stderr, "parent_dir - not enough space");
+                exit(1);
+           }
            parent_dir[last_component - true_name] = 0;
            last_component++;   /*Skip the slash */
        } else {
@@ -3961,7 +4517,10 @@ FlushMountCmd(struct cmd_syndesc *as, char *arock)
             * No slash appears in the given file name.  Set parent_dir to the current
             * directory, and the last component as the given name.
             */
-           strcpy(parent_dir, ".");
+           if( FAILED(StringCbCopy(parent_dir, sizeof(parent_dir), "."))) {
+               fprintf (stderr, "parent_dir - not enough space");
+                exit(1);
+           }
            last_component = true_name;
        }
 
@@ -3977,31 +4536,35 @@ FlushMountCmd(struct cmd_syndesc *as, char *arock)
        }
 
        blob.in = last_component;
-       blob.in_size = strlen(last_component) + 1;
+       if( FAILED(StringCbLength(last_component, sizeof(true_name) - (last_component - true_name), &len))) {
+           fprintf (stderr, "StringCbLength failure on last_component");
+           exit(1);
+       }
+       blob.in_size = len + 1;
        blob.out_size = 0;
-       memset(space, 0, MAXSIZE);
+       memset(space, 0, AFS_PIOCTL_MAXSIZE);
 
-       code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
+       code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
 
        if (code != 0) {
            if (errno == EINVAL) {
                fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
            } else {
-               Die(errno, (ti->data ? ti->data : parent_dir));
+               fs_Die(errno, (ti->data ? ti->data : parent_dir));
            }
            error = 1;
        }
     }
     return error;
 }
+#endif /* WIN32 */
 
 static int
-RxStatProcCmd(struct cmd_syndesc *as, char *arock)
+RxStatProcCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     afs_int32 flags = 0;
     struct ViceIoctl blob;
-    struct cmd_item *ti;
 
     if (as->parms[0].items) {  /* -enable */
        flags |= AFSCALL_RXSTATS_ENABLE;
@@ -4021,9 +4584,9 @@ RxStatProcCmd(struct cmd_syndesc *as, char *arock)
     blob.in_size = sizeof(afs_int32);
     blob.out_size = 0;
 
-    code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
     if (code != 0) {
-       Die(errno, NULL);
+       fs_Die(errno, NULL);
        return 1;
     }
 
@@ -4031,12 +4594,11 @@ RxStatProcCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
-RxStatPeerCmd(struct cmd_syndesc *as, char *arock)
+RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
     afs_int32 flags = 0;
     struct ViceIoctl blob;
-    struct cmd_item *ti;
 
     if (as->parms[0].items) {  /* -enable */
        flags |= AFSCALL_RXSTATS_ENABLE;
@@ -4056,34 +4618,413 @@ RxStatPeerCmd(struct cmd_syndesc *as, char *arock)
     blob.in_size = sizeof(afs_int32);
     blob.out_size = 0;
 
-    code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
     if (code != 0) {
-       Die(errno, NULL);
+       fs_Die(errno, NULL);
        return 1;
     }
 
     return 0;
 }
-#endif /* WIN32 */
+
+static int
+TestVolStatCmd(struct cmd_syndesc *as, void *arock)
+{
+    afs_int32 code;
+    struct VolStatTest test;
+    struct ViceIoctl blob;
+    char * tp;
+    afs_uint32 n;
+
+    memset(&test, 0, sizeof(test));
+
+    if (as->parms[0].items) {  /* -network */
+        tp = as->parms[0].items->data;
+        if (strcmp(tp, "up") == 0)
+            test.flags |= VOLSTAT_TEST_NETWORK_UP;
+        else if (strcmp(tp, "down") == 0)
+            test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
+        else {
+            fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
+            return EINVAL;
+        }
+    }
+    if (as->parms[1].items) {  /* check */
+        test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
+    }
+    if (as->parms[2].items) {  /* cell */
+        tp = as->parms[2].items->data;
+        n = atoi(tp);
+        if (n != 0)
+            test.fid.cell = n;
+        else {
+            if( FAILED(StringCbCopy(test.cellname, sizeof(test.cellname), tp))) {
+               fprintf (stderr, "cellname - not enough space");
+                exit(1);
+           }
+            test.cellname[sizeof(test.cellname)-1] = '\0';
+        }
+    }
+    if (as->parms[3].items) {  /* volume */
+        tp = as->parms[3].items->data;
+        n = atoi(tp);
+        if (n != 0)
+            test.fid.volume = n;
+        else {
+            if( FAILED(StringCbCopy(test.volname, sizeof(test.volname), tp))) {
+               fprintf (stderr, "volname - not enough space");
+                exit(1);
+           }
+            test.volname[sizeof(test.volname)-1] = '\0';
+        }
+    }
+    if (as->parms[4].items) {   /* state */
+        tp = as->parms[4].items->data;
+        if (strcmp(tp, "online") == 0)
+            test.state = vl_online;
+        else if (strcmp(tp, "busy") == 0)
+            test.state = vl_busy;
+        else if (strcmp(tp, "offline") == 0)
+            test.state = vl_offline;
+        else if (strcmp(tp, "down") == 0)
+            test.state = vl_alldown;
+        else {
+            fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
+            return EINVAL;
+        }
+    }
+
+    if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
+         !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
+        fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
+        return EINVAL;
+    }
+
+    blob.in = (char *)&test;
+    blob.in_size = sizeof(test);
+    blob.out_size = 0;
+
+    code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
+    if (code != 0) {
+       fs_Die(errno, NULL);
+       return 1;
+    }
+
+    return 0;
+}
+
+static int
+ChOwnCmd(struct cmd_syndesc *as, void *arock)
+{
+    afs_int32 code;
+    struct ViceIoctl blob;
+    struct cmd_item *ti;
+    int error = 0;
+    int literal = 0;
+    struct {
+        cm_ioctlQueryOptions_t options;
+        afs_uint32 owner;
+    } inData;
+    afs_uint32 ownerId;
+    char * ownerStr;
+    char confDir[257];
+
+    cm_GetConfigDir(confDir, sizeof(confDir));
+
+    if (as->parms[2].items)
+        literal = 1;
+
+    ownerStr = as->parms[0].items->data;
+    ownerId = atoi(ownerStr);
+
+    SetDotDefault(&as->parms[1].items);
+    for(ti=as->parms[1].items; ti; ti=ti->next) {
+        cm_fid_t fid;
+        afs_uint32 filetype;
+       char cell[CELL_MAXNAMELEN];
+
+        /* once per file */
+        memset(&fid, 0, sizeof(fid));
+        memset(&inData, 0, sizeof(inData));
+        filetype = 0;
+        inData.options.size = sizeof(inData.options);
+        inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
+        inData.options.literal = literal;
+       blob.in_size = inData.options.size;    /* no variable length data */
+        blob.in = &inData;
+
+        blob.out_size = sizeof(cm_fid_t);
+        blob.out = (char *) &fid;
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
+            blob.out_size == sizeof(cm_fid_t)) {
+            inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
+            inData.options.fid = fid;
+        } else {
+           fs_Die(errno, ti->data);
+           error = 1;
+           continue;
+        }
+
+        /*
+         * if the owner was specified as a numeric value,
+         * then we can just use it.  Otherwise, we need
+         * to know the cell of the path to determine which
+         * ptserver to contact in order to convert the name
+         * to a numeric value.
+         */
+        if (ownerId == 0) {
+            blob.out_size = CELL_MAXNAMELEN;
+            blob.out = cell;
+
+            code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
+            if (code) {
+                fs_Die(errno, ti->data);
+                error = 1;
+                continue;
+            }
+            cell[CELL_MAXNAMELEN - 1] = '\0';
+            /*
+             * We now know the cell for the target and we need to
+             * convert the ownerStr to the Id for this user
+             */
+            pr_Initialize(1, confDir, cell);
+            code = pr_SNameToId(ownerStr, &inData.owner);
+            pr_End();
+
+            if (code || inData.owner == ANONYMOUSID ) {
+                fs_Die(ECHILD, ti->data);
+                error = 1;
+                continue;
+            }
+        } else {
+            inData.owner = ownerId;
+        }
+
+        blob.in_size = sizeof(inData);
+       blob.out = NULL;
+       blob.out_size = 0;
+       code = pioctl_utf8(ti->data, VIOC_SETOWNER, &blob, 1);
+       if (code) {
+            fs_Die(errno, ti->data);
+        }
+    }
+    return error;
+}
+
+static int
+ChGrpCmd(struct cmd_syndesc *as, void *arock)
+{
+    afs_int32 code;
+    struct ViceIoctl blob;
+    struct cmd_item *ti;
+    int error = 0;
+    int literal = 0;
+    struct {
+        cm_ioctlQueryOptions_t options;
+        afs_uint32 group;
+    } inData;
+    afs_uint32 groupId;
+    char * groupStr;
+    char confDir[257];
+
+    cm_GetConfigDir(confDir, sizeof(confDir));
+
+    if (as->parms[2].items)
+        literal = 1;
+
+    groupStr = as->parms[0].items->data;
+    groupId = atoi(groupStr);
+
+    SetDotDefault(&as->parms[1].items);
+    for(ti=as->parms[1].items; ti; ti=ti->next) {
+        cm_fid_t fid;
+        afs_uint32 filetype;
+       char cell[CELL_MAXNAMELEN];
+
+        /* once per file */
+        memset(&fid, 0, sizeof(fid));
+        memset(&inData, 0, sizeof(inData));
+        filetype = 0;
+        inData.options.size = sizeof(inData.options);
+        inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
+        inData.options.literal = literal;
+       blob.in_size = inData.options.size;    /* no variable length data */
+        blob.in = &inData;
+
+        blob.out_size = sizeof(cm_fid_t);
+        blob.out = (char *) &fid;
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
+            blob.out_size == sizeof(cm_fid_t)) {
+            inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
+            inData.options.fid = fid;
+        } else {
+           fs_Die(errno, ti->data);
+           error = 1;
+           continue;
+        }
+
+        /*
+         * if the group was specified as a numeric value,
+         * then we can just use it.  Otherwise, we need
+         * to know the cell of the path to determine which
+         * ptserver to contact in order to convert the name
+         * to a numeric value.
+         */
+        if (groupId == 0) {
+            blob.out_size = CELL_MAXNAMELEN;
+            blob.out = cell;
+
+            code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
+            if (code) {
+                fs_Die(errno, ti->data);
+                error = 1;
+                continue;
+            }
+            cell[CELL_MAXNAMELEN - 1] = '\0';
+            /*
+             * We now know the cell for the target and we need to
+             * convert the groupStr to the Id for this user
+             */
+            pr_Initialize(1, confDir, cell);
+            code = pr_SNameToId(groupStr, &inData.group);
+            pr_End();
+
+            if (code || inData.group == ANONYMOUSID ) {
+                fs_Die(ECHILD, ti->data);
+                error = 1;
+                continue;
+            }
+        } else {
+            inData.group = groupId;
+        }
+
+        blob.in_size = sizeof(inData);
+       blob.out = NULL;
+       blob.out_size = 0;
+       code = pioctl_utf8(ti->data, VIOC_SETGROUP, &blob, 1);
+       if (code) {
+            fs_Die(errno, ti->data);
+        }
+    }
+    return error;
+}
+
+
+
+static int
+ChModCmd(struct cmd_syndesc *as, void *arock)
+{
+    afs_int32 code;
+    struct ViceIoctl blob;
+    struct cmd_item *ti;
+    int error = 0;
+    int literal = 0;
+    struct {
+        cm_ioctlQueryOptions_t options;
+        afs_uint32 unixModeBits;
+    } inData;
+    afs_uint32 unixModeBits;
+    afs_int32  absolute = 0;
+    char * unixModeStr;
+    char confDir[257];
+
+    cm_GetConfigDir(confDir, sizeof(confDir));
+
+    if (as->parms[2].items)
+        literal = 1;
+
+    unixModeStr = as->parms[0].items->data;
+    if (*unixModeStr >= '0' && *unixModeStr <= '7') {
+        unixModeBits = 0;
+        absolute = 1;
+        while (*unixModeStr >= '0' && *unixModeStr <= '7')
+            unixModeBits = (unixModeBits << 3) | (*unixModeStr++ & 07);
+        if (*unixModeStr) {
+            fs_Die(EINVAL, "invalid mode");
+            return(1);
+        }
+        unixModeBits &= ALL_MODES;
+    }
+
+    SetDotDefault(&as->parms[1].items);
+    for(ti=as->parms[1].items; ti; ti=ti->next) {
+        cm_fid_t fid;
+        afs_uint32 filetype;
+
+        /* once per file */
+        memset(&fid, 0, sizeof(fid));
+        memset(&inData, 0, sizeof(inData));
+        filetype = 0;
+        inData.options.size = sizeof(inData.options);
+        inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
+        inData.options.literal = literal;
+       blob.in_size = inData.options.size;    /* no variable length data */
+        blob.in = &inData;
+
+        blob.out_size = sizeof(cm_fid_t);
+        blob.out = (char *) &fid;
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
+            blob.out_size == sizeof(cm_fid_t)) {
+            inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
+            inData.options.fid = fid;
+        } else {
+           fs_Die(errno, ti->data);
+           error = 1;
+           continue;
+        }
+
+        /*
+         * if the mode was specified as an absolute numeric,
+         * value we can simply apply it to all of the listed
+         * file paths.  Otherwise, we must obtain the old mode
+         * value in order to compute the new value from the
+         * symbolic representation.
+         */
+        if (!absolute) {
+            blob.in_size = 0;
+            blob.out_size = sizeof(afs_uint32);
+            blob.out = (char *)&unixModeBits;
+            if (pioctl_utf8(ti->data, VIOC_GETUNIXMODE, &blob, 1) != 0)
+            {
+                fs_Die(errno, ti->data);
+                error = 1;
+                continue;
+            }
+            inData.unixModeBits = parsemode(unixModeStr, unixModeBits);
+        } else {
+            inData.unixModeBits = unixModeBits;
+        }
+
+        blob.in_size = sizeof(inData);
+       blob.out = NULL;
+       blob.out_size = 0;
+       code = pioctl_utf8(ti->data, VIOC_SETUNIXMODE, &blob, 1);
+       if (code) {
+            fs_Die(errno, ti->data);
+        }
+    }
+    return error;
+}
 
 #ifndef WIN32
 #include "AFS_component_version_number.c"
 #endif
 
-main(int argc, char **argv)
+int wmain(int argc, wchar_t **wargv)
 {
     afs_int32 code;
     struct cmd_syndesc *ts;
+    char ** argv;
 
 #ifdef AFS_AIX32_ENV
     /*
-     * The following signal action for AIX is necessary so that in case of a 
-     * crash (i.e. core is generated) we can include the user's data section 
+     * The following signal action for AIX is necessary so that in case of a
+     * crash (i.e. core is generated) we can include the user's data section
      * in the core dump. Unfortunately, by default, only a partial core is
      * generated which, in many cases, isn't too useful.
      */
     struct sigaction nsa;
-    
+
     sigemptyset(&nsa.sa_mask);
     nsa.sa_handler = SIG_DFL;
     nsa.sa_flags = SA_FULLDUMP;
@@ -4095,36 +5036,40 @@ main(int argc, char **argv)
     WSAStartup(0x0101, &WSAjunk);
 #endif /* WIN32 */
 
+    fs_SetProcessName(pn);
+
+    argv = fs_MakeUtf8Cmdline(argc, wargv);
+
     /* try to find volume location information */
     osi_Init();
 
 #ifndef WIN32
-    ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0,
+    ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
                          "get client network interface addresses");
     cmd_CreateAlias(ts, "gc");
 
-    ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0,
+    ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
                          "set client network interface addresses");
     cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
                 "client network interfaces");
     cmd_CreateAlias(ts, "sc");
 #endif /* WIN32 */
 
-    ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
+    ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
     cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
     cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
     cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
     cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
     cmd_CreateAlias(ts, "sp");
 
-    ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
+    ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
     cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
     cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
     cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
     /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
     cmd_CreateAlias(ts, "gp");
 
-    ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
+    ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
     cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
     cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
     cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
@@ -4133,37 +5078,39 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
     cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
     cmd_CreateAlias(ts, "sa");
-    
-    ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
+
+    ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
     parm_listacl_id = ts->nParms;
     cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
     cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
+    cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
     cmd_CreateAlias(ts, "la");
-    
-    ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
+
+    ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
-    
-    ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
+
+    ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
     cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
     cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
     cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
     parm_copyacl_id = ts->nParms;
     cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
     cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
-    
+
     cmd_CreateAlias(ts, "ca");
 
-    ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
+    ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
-    
+    cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
+
 #ifndef WIN32
-    ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0,
+    ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
                            "flush mount symlink from cache");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
 #endif
 
-    ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
+    ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
     cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
 #ifdef notdef
@@ -4172,30 +5119,31 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
     cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
     cmd_CreateAlias(ts, "sv");
-    
-    ts = cmd_CreateSyntax("messages", MessagesCmd, 0, "control Cache Manager messages");
+
+    ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
     cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
 
-    ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status");
+    ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+    cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
     cmd_CreateAlias(ts, "lv");
     cmd_CreateAlias(ts, "listvol");
-    
-    ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
+
+    ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
     cmd_CreateAlias(ts, "lq");
-    
-    ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
+
+    ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
     cmd_CreateAlias(ts, "df");
-    
-    ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
+
+    ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
-    
-    ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");    
+
+    ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
     cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
-    
-    ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
+
+    ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
     cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
     cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
     cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
@@ -4205,36 +5153,36 @@ main(int argc, char **argv)
     /*
      *
      * defect 3069
-     * 
+     *
     cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
     */
 
-    
-    ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
+
+    ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
     cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
-    
-    ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
+
+    ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
     cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
     cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
     cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
-       cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
-    
-    ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
+    cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
+
+    ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
     cmd_CreateAlias(ts, "checkbackups");
 
-    
-    ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
+
+    ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
     cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
     cmd_CreateAlias(ts, "cachesize");
 
     cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
-    
-    ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
 
-    ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
+    ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
+
+    ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
     cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
-    
-    ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
+
+    ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
     cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
     cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
 #ifdef notdef
@@ -4242,13 +5190,11 @@ main(int argc, char **argv)
 #endif
     cmd_CreateAlias(ts, "sq");
 
-    ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
-#ifndef WIN32
-    cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
-    cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
+    ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
+    cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "cell name");
+    cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL, "primary servers");
     cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
 
-#ifdef FS_ENABLE_SERVER_DEBUG_PORTS
     /*
      * Turn this on only if you wish to be able to talk to a server which is listening
      * on alternative ports. This is not intended for general use and may not be
@@ -4257,162 +5203,150 @@ main(int argc, char **argv)
      */
     cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
     cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
-#endif
+    cmd_AddParm(ts, "-registry", CMD_FLAG, CMD_OPTIONAL, "add cell info to registry cellservdb");
+    cmd_AddParm(ts, "-dns",    CMD_FLAG, CMD_OPTIONAL,   "force use of dns");
 
-    ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0,
+#ifndef WIN32
+    ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
                          "configure new cell alias");
     cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
     cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
 #endif
 
-    ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
+    ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+    cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
 
-    ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
+    ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+    cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
+
+    ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
 
-    ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
-    
     /*
      ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
      */
-    
-    ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address");
+
+#ifndef AFS_NT40_ENV
+    ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
     cmd_CreateAlias(ts, "mariner");
-    
-   
-    ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
+#endif
+
+    ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
     cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
-    
-    ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
+
+    ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
     cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
     cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
     cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
-    
-    ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
+
+    ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
+
+    ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
 
-    ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
+    ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
     cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
 
-    ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
+#ifndef AFS_NT40_ENV
+    ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
     cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
     cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
     cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
     cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
     cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
+#endif
 
-
-    ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0, 
+    ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
                          "store to server after file close");
     cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
     cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
     cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
     cmd_CreateAlias(ts, "sb");
 
-    ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
+    ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
     cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
 
-    ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag");
+    ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
 
-#ifndef WIN32
-    ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
+    ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
                          "Manage per process RX statistics");
     cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
     cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
     cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
 
-    ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
+    ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
                          "Manage per peer RX statistics");
     cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
     cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
     cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
 
-    ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
+#ifndef WIN32
+    ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
     cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
 #endif
 
-    ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing");
+    ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
     cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
     cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
     cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
     cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
     cmd_CreateAlias(ts, "tr");
 
-    ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds");
+    ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
+    cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
+
+    ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
     cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
     cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
-    
-    ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, 0, "change client side caching policy for AFS shares");
+
+    ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
     cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
     cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
     cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
     cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
     cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
 
+    ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
+
+    ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
+    cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
+    cmd_AddParm(ts, "-check",   CMD_FLAG,   CMD_OPTIONAL, "check state of offline volumes");
+    cmd_AddParm(ts, "-cell",    CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
+    cmd_AddParm(ts, "-volume",  CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
+    cmd_AddParm(ts, "-state",   CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
+
+    ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
+    cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
+    cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
+
+    ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL, "get file id for object(s) in afs");
+    cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+    cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
+
+    ts = cmd_CreateSyntax("chown", ChOwnCmd, NULL, "set owner for object(s) in afs");
+    cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "user name or id");
+    cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+    cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
+
+    ts = cmd_CreateSyntax("chgrp", ChGrpCmd, NULL, "set owner for object(s) in afs");
+    cmd_AddParm(ts, "-group", CMD_SINGLE, 0, "user/group name or id");
+    cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+    cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
+
+    ts = cmd_CreateSyntax("chmod", ChModCmd, NULL, "set UNIX mode for object(s) in afs");
+    cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "UNIX mode bits");
+    cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+    cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
+
     code = cmd_Dispatch(argc, argv);
 
-#ifndef WIN32
-    if (rxInitDone) 
+    if (rxInitDone)
         rx_Finalize();
-#endif /* not WIN32 */
-    
+
+    fs_FreeUtf8CmdLine(argc, argv);
+
     return code;
 }
 
-static void 
-Die(int code, char *filename)
-{ /*Die*/
-
-    if (code == EINVAL) {
-       if (filename)
-           fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
-       else 
-            fprintf(stderr,"%s: Invalid argument.\n", pn);
-    }
-    else if (code == ENOENT) {
-       if (filename) 
-            fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
-       else 
-            fprintf(stderr,"%s: no such file returned\n", pn);
-    }
-    else if (code == EROFS)  
-        fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
-    else if (code == EACCES || code == EPERM) {
-       if (filename) 
-            fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
-       else 
-            fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
-    }
-    else if (code == ENODEV) {
-       fprintf(stderr,"%s: AFS service may not have started.\n", pn);
-    }
-    else if (code == ESRCH) {
-       fprintf(stderr,"%s: Cell name not recognized.\n", pn);
-    }
-    else if (code == EPIPE) {
-       fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
-    }
-    else if (code == EFBIG) {
-       fprintf(stderr,"%s: Cache size too large.\n", pn);
-    }
-    else if (code == ETIMEDOUT) {
-       if (filename)
-           fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
-       else
-           fprintf(stderr,"%s: Connection timed out", pn);
-    }
-    else {
-       if (filename) 
-            fprintf(stderr,"%s:'%s'", pn, filename);
-       else 
-            fprintf(stderr,"%s", pn);
-#ifdef WIN32
-       fprintf(stderr, ": code 0x%x\n", code);
-#else /* not WIN32 */
-       fprintf(stderr,": %s\n", error_message(code));
-#endif /* not WIN32 */
-    }
-} /*Die*/
-