namei: Abstract out OGM functions a bit more
[openafs.git] / src / vol / namei_ops.c
index 8d7585a..a02600d 100644 (file)
 
 #include <roken.h>
 
+
 #ifdef AFS_NAMEI_ENV
-#include <stdio.h>
-#include <stdlib.h>
-#ifndef AFS_NT40_ENV
-#include <unistd.h>
-#else
+
+#ifdef HAVE_SYS_FILE_H
+# include <sys/file.h>
+#endif
+
+#ifdef AFS_NT40_ENV
 #define DELETE_ZLC
-#include <io.h>
 #include <windows.h>
 #include <winnt.h>
 #include <winbase.h>
-#include <winsock2.h>
-#endif
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#ifdef AFS_NT40_ENV
 #include <direct.h>
-#else
-#include <sys/file.h>
-#include <sys/param.h>
 #endif
-#include <dirent.h>
-#include <afs/afs_assert.h>
-#include <string.h>
+
 #include <lock.h>
 #include <afs/afsutil.h>
 #include <lwp.h>
@@ -54,6 +44,7 @@
 #include "volume_inline.h"
 #include "common.h"
 #include <afs/errors.h>
+
 #ifdef AFS_NT40_ENV
 #include <afs/errmap_nt.h>
 #endif
 #include <vol/vol-salvage.h>
 #endif
 
-#if !defined(HAVE_FLOCK) && !defined(AFS_NT40_ENV)
-#include <fcntl.h>
-
-/*
- * This function emulates a subset of flock()
- */
-int
-emul_flock(int fd, int cmd)
-{    struct flock f;
-
-    memset(&f, 0, sizeof (f));
-
-    if (cmd & LOCK_UN)
-        f.l_type = F_UNLCK;
-    if (cmd & LOCK_SH)
-        f.l_type = F_RDLCK;
-    if (cmd & LOCK_EX)
-        f.l_type = F_WRLCK;
-
-    return fcntl(fd, (cmd & LOCK_NB) ? F_SETLK : F_SETLKW, &f);
-}
-
-#define flock(f,c)      emul_flock(f,c)
-#endif
-
 int Testing=0;
 
 
@@ -111,7 +77,10 @@ namei_iread(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size)
        return -1;
 
     nBytes = FDH_PREAD(fdP, buf, size, offset);
-    FDH_CLOSE(fdP);
+    if (nBytes < 0)
+       FDH_REALLYCLOSE(fdP);
+    else
+       FDH_CLOSE(fdP);
     return nBytes;
 }
 
@@ -126,7 +95,10 @@ namei_iwrite(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size)
        return -1;
 
     nBytes = FDH_PWRITE(fdP, buf, size, offset);
-    FDH_CLOSE(fdP);
+    if (nBytes < 0)
+       FDH_REALLYCLOSE(fdP);
+    else
+       FDH_CLOSE(fdP);
     return nBytes;
 }
 
@@ -351,12 +323,13 @@ namei_ViceREADME(char *partition)
     int fd;
 
     /* Create the inode directory if we're starting for the first time */
-    (void)afs_snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s", partition,
-                      INODEDIR);
+    snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s", partition,
+            INODEDIR);
     mkdir(filename, 0700);
 
-    (void)afs_snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s" OS_DIRSEP "README",
-                       partition, INODEDIR);
+    snprintf(filename, sizeof filename,
+            "%s" OS_DIRSEP "%s" OS_DIRSEP "README",
+             partition, INODEDIR);
     fd = OS_OPEN(filename, O_WRONLY | O_CREAT | O_TRUNC, 0444);
     if (fd != INVALID_FD) {
        (void)OS_WRITE(fd, VICE_README, strlen(VICE_README));
@@ -380,7 +353,7 @@ namei_CreateDataDirectories(namei_t * name, int *created)
     int i;
 
     *created = 0;
-    afs_snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir);
+    snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir);
 
     if (mkdir(tmp) < 0) {
         if (errno != EEXIST)
@@ -538,7 +511,7 @@ namei_RemoveDataDirectories(namei_t * name)
     char tmp[256];
     int i;
 
-    afs_snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir);
+    snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir);
 
     path = tmp;
     path += strlen(path);
@@ -645,24 +618,49 @@ SetOGM(FD_t fd, int parm, int tag)
 }
 
 static int
-CheckOGM(namei_t *name, FdHandle_t *fdP, int p1)
+SetWinOGM(FD_t fd, int p1, int p2)
 {
-    WIN32_FIND_DATA info;
-    HANDLE dirH;
+    BOOL code;
+    FILETIME ftime;
 
-    dirH =
-       FindFirstFileEx(name->n_path, FindExInfoStandard, &info,
-                       FindExSearchNameMatch, NULL,
-                       FIND_FIRST_EX_CASE_SENSITIVE);
+    ftime.dwHighDateTime = p1;
+    ftime.dwLowDateTime = p2;
 
-    if (!dirH)
-       return -1;          /* Can't get info, leave alone */
+    code = SetFileTime(fd, &ftime, NULL /*access*/, NULL /*write*/);
+    if (!code)
+       return -1;
+    return 0;
+}
 
-    FindClose(dirH);
+static int
+GetWinOGM(FD_t fd, int *p1, int *p2)
+{
+    BOOL code;
+    FILETIME ftime;
 
-    if (info.ftCreationTime.dwHighDateTime != (unsigned int)p1)
+    code = GetFileTime(fd, &ftime, NULL /*access*/, NULL /*write*/);
+    if (!code)
        return -1;
 
+    *p1 = ftime.dwHighDateTime;
+    *p2 = ftime.dwLowDateTime;
+
+    return 0;
+}
+
+static int
+CheckOGM(FdHandle_t *fdP, int p1)
+{
+    int ogm_p1, ogm_p2;
+
+    if (GetWinOGM(fdP->fd_fd, &ogm_p1, &ogm_p2)) {
+       return -1;
+    }
+
+    if (ogm_p1 != p1) {
+       return -1;
+    }
+
     return 0;
 }
 #else /* AFS_NT40_ENV */
@@ -691,7 +689,7 @@ SetOGM(FD_t fd, int parm, int tag)
 
 /* GetOGM - get parm and tag from owner, group and mode bits. */
 static void
-GetOGMFromStat(struct afs_stat *status, int *parm, int *tag)
+GetOGMFromStat(struct afs_stat_st *status, int *parm, int *tag)
 {
     *parm = status->st_uid | (status->st_gid << 15);
     *parm |= (status->st_mode & 0x18) << 27;
@@ -699,14 +697,22 @@ GetOGMFromStat(struct afs_stat *status, int *parm, int *tag)
 }
 
 static int
-CheckOGM(namei_t *name, FdHandle_t *fdP, int p1)
+GetOGM(FdHandle_t *fdP, int *parm, int *tag)
 {
-    struct afs_stat status;
-    int parm, tag;
+    struct afs_stat_st status;
     if (afs_fstat(fdP->fd_fd, &status) < 0)
        return -1;
+    GetOGMFromStat(&status, parm, tag);
+    return 0;
+}
 
-    GetOGMFromStat(&status, &parm, &tag);
+static int
+CheckOGM(FdHandle_t *fdP, int p1)
+{
+    int parm, tag;
+
+    if (GetOGM(fdP, &parm, &tag) < 0)
+       return -1;
     if (parm != p1)
        return -1;
 
@@ -731,7 +737,7 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint
     FdHandle_t *fdP;
     FdHandle_t tfd;
     int type, tag;
-    FILETIME ftime;
+    int ogm_p1, ogm_p2;
     char *p;
     b32_string_t str1;
 
@@ -751,8 +757,8 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint
         * p3 - type
         * p4 - parent volume id
         */
-        ftime.dwHighDateTime = p1;
-        ftime.dwLowDateTime = p2;
+        ogm_p1 = p1;
+        ogm_p2 = p2;
        type = p3;
        tmp.ih_vid = p4;        /* Use parent volume id, where this file will be. */
        tmp.ih_ino = namei_MakeSpecIno(p1, p3);
@@ -773,8 +779,8 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint
 
        tmp.ih_vid = p1;
        tmp.ih_ino = (Inode) p2;
-       ftime.dwHighDateTime = p3;
-        ftime.dwLowDateTime = p4;
+       ogm_p1 = p3;
+        ogm_p2 = p4;
     }
 
     namei_HandleToName(&name, &tmp);
@@ -782,11 +788,11 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint
     p++;
     for (tag = 0; tag < NAMEI_MAXVOLS; tag++) {
         *p = *int_to_base32(str1, tag);
-        fd = OS_OPEN((char *)&name.n_path, O_CREAT | O_RDWR | O_TRUNC | O_EXCL, 0666);
+        fd = OS_OPEN((char *)&name.n_path, O_CREAT | O_RDWR | O_EXCL, 0666);
         if (fd == INVALID_FD) {
             if (errno == ENOTDIR || errno == ENOENT) {
                 if (namei_CreateDataDirectories(&name, &created_dir) == 0)
-                    fd = OS_OPEN((char *)&name.n_path, O_CREAT | O_RDWR | O_TRUNC | O_EXCL, 0666);
+                    fd = OS_OPEN((char *)&name.n_path, O_CREAT | O_RDWR | O_EXCL, 0666);
             }
         }
 
@@ -803,7 +809,7 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint
     tmp.ih_ino |= (((Inode) tag) << NAMEI_TAGSHIFT);
 
     if (!code) {
-        if (!SetFileTime((HANDLE) fd, &ftime, NULL, NULL)) {
+        if (SetWinOGM(fd, ogm_p1, ogm_p2)) {
            errno = OS_ERROR(EBADF);
             code = -1;
         }
@@ -918,12 +924,12 @@ namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint
     }
 
     namei_HandleToName(&name, &tmp);
-    fd = OS_OPEN(name.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0);
+    fd = OS_OPEN(name.n_path, O_CREAT | O_EXCL | O_RDWR, 0);
     if (fd == INVALID_FD) {
        if (errno == ENOTDIR || errno == ENOENT) {
            if (namei_CreateDataDirectories(&name, &created_dir) < 0)
                goto bad;
-           fd = OS_OPEN(name.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR,
+           fd = OS_OPEN(name.n_path, O_CREAT | O_EXCL | O_RDWR,
                          0);
            if (fd == INVALID_FD)
                goto bad;
@@ -1004,7 +1010,7 @@ namei_dec(IHandle_t * ih, Inode ino, int p1)
            return -1;
        }
 
-       if (CheckOGM(&name, fdP, p1) < 0) {
+       if (CheckOGM(fdP, p1) < 0) {
            FDH_REALLYCLOSE(fdP);
            IH_RELEASE(tmp);
            errno = OS_ERROR(EINVAL);
@@ -1028,7 +1034,7 @@ namei_dec(IHandle_t * ih, Inode ino, int p1)
            }
 
            if (count > 0) {
-               FDH_REALLYCLOSE(fdP);
+               FDH_CLOSE(fdP);
                IH_RELEASE(tmp);
                return 0;
            }
@@ -1039,6 +1045,11 @@ namei_dec(IHandle_t * ih, Inode ino, int p1)
                /* Try to remove directory. If it fails, that's ok.
                 * Salvage will clean up.
                 */
+               char *slash = strrchr(name.n_path, OS_DIRSEPC);
+               if (slash) {
+                   /* avoid an rmdir() on the file we just unlinked */
+                   *slash = '\0';
+               }
                (void)namei_RemoveDataDirectories(&name);
            }
        }
@@ -1065,7 +1076,7 @@ namei_dec(IHandle_t * ih, Inode ino, int p1)
        } else {
            IHandle_t *th;
            IH_INIT(th, ih->ih_dev, ih->ih_vid, ino);
-           Log("Warning: Lost ref on ihandle dev %d vid %d ino %" AFS_INT64_FMT "\n",
+           Log("Warning: Lost ref on ihandle dev %d vid %d ino %lld\n",
                th->ih_dev, th->ih_vid, (afs_int64)th->ih_ino);
            IH_RELEASE(th);
 
@@ -1154,7 +1165,7 @@ namei_copy_on_write(IHandle_t *h)
     FD_t fd;
     namei_t name;
     FdHandle_t *fdP;
-    struct afs_stat tstat;
+    struct afs_stat_st tstat;
     afs_foff_t offset;
 
     namei_HandleToName(&name, h);
@@ -1169,8 +1180,8 @@ namei_copy_on_write(IHandle_t *h)
        fdP = IH_OPEN(h);
        if (!fdP)
            return EIO;
-       afs_snprintf(path, sizeof(path), "%s-tmp", name.n_path);
-       fd = OS_OPEN(path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0);
+       snprintf(path, sizeof(path), "%s-tmp", name.n_path);
+       fd = OS_OPEN(path, O_CREAT | O_EXCL | O_RDWR, 0);
        if (fd == INVALID_FD) {
            FDH_CLOSE(fdP);
            return EIO;
@@ -1399,6 +1410,9 @@ namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit, int fixup, int nowrite
     }
 
     rc = FDH_PREAD(h, (char*)&row, sizeof(row), offset);
+    if (rc == -1)
+       goto bad_getLinkByte;
+
     if ((rc == 0 || !((row >> index) & NAMEI_TAGMASK)) && fixup && nowrite)
         return 1;
     if (rc == 0 && fixup) {
@@ -1502,9 +1516,9 @@ GetFreeTag(IHandle_t * ih, int vno)
     if (FDH_PWRITE(fdP, (char *)&row, sizeof(row), offset) != sizeof(row)) {
        goto badGetFreeTag;
     }
-    FDH_SYNC(fdP);
+    (void)FDH_SYNC(fdP);
     FDH_UNLOCKFILE(fdP, offset);
-    FDH_REALLYCLOSE(fdP);
+    FDH_CLOSE(fdP);
     return col;
 
   badGetFreeTag:
@@ -1554,7 +1568,7 @@ namei_SetLinkCount(FdHandle_t * fdP, Inode ino, int count, int locked)
        errno = OS_ERROR(EBADF);
        goto bad_SetLinkCount;
     }
-    FDH_SYNC(fdP);
+    (void)FDH_SYNC(fdP);
 
     nBytes = 0;
 
@@ -1572,9 +1586,9 @@ static int DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info,
                       unsigned int volid);
 static int DecodeVolumeName(char *name, unsigned int *vid);
 static int namei_ListAFSSubDirs(IHandle_t * dirIH,
-                               int (*write_fun) (FILE *,
+                               int (*write_fun) (FD_t,
                                                  struct ViceInodeInfo *,
-                                                 char *, char *), FILE * fp,
+                                                 char *, char *), FD_t fp,
                                int (*judgeFun) (struct ViceInodeInfo *,
                                                 afs_uint32 vid, void *),
                                afs_uint32 singleVolumeNumber, void *rock);
@@ -1590,11 +1604,11 @@ static int namei_ListAFSSubDirs(IHandle_t * dirIH,
  * can use the same inode reading code.
  */
 static int
-WriteInodeInfo(FILE * fp, struct ViceInodeInfo *info, char *dir, char *name)
+WriteInodeInfo(FD_t fp, struct ViceInodeInfo *info, char *dir, char *name)
 {
     size_t n;
-    n = fwrite(info, sizeof(*info), 1, fp);
-    return (n == 1) ? 0 : -2;
+    n = OS_WRITE(fp, info, sizeof(*info));
+    return (n == sizeof(*info)) ? 0 : -2;
 }
 
 
@@ -1602,7 +1616,7 @@ int mode_errors;          /* Number of errors found in mode bits on directories. */
 void
 VerifyDirPerms(char *path)
 {
-    struct afs_stat status;
+    struct afs_stat_st status;
 
     if (afs_stat(path, &status) < 0) {
        Log("Unable to stat %s. Please manually verify mode bits for this"
@@ -1640,13 +1654,12 @@ VerifyDirPerms(char *path)
  *                for this.
  */
 int
-ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile,
+ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile,
               int (*judgeInode) (struct ViceInodeInfo * info, afs_uint32 vid, void *rock),
               afs_uint32 singleVolumeNumber, int *forcep, int forceR, char *wpath,
               void *rock)
 {
     int ninodes;
-    struct afs_stat status;
 
     *forcep = 0; /* no need to salvage until further notice */
 
@@ -1658,18 +1671,14 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile,
        namei_ListAFSFiles(mountedOn, WriteInodeInfo, inodeFile, judgeInode,
                           singleVolumeNumber, rock);
 
-    if (!inodeFile)
+    if (inodeFile == INVALID_FD)
        return ninodes;
 
     if (ninodes < 0) {
        return ninodes;
     }
 
-    if (fflush(inodeFile) == EOF) {
-       Log("Unable to successfully flush inode file for %s\n", mountedOn);
-       return -2;
-    }
-    if (fsync(fileno(inodeFile)) == -1) {
+    if (OS_SYNC(inodeFile) == -1) {
        Log("Unable to successfully fsync inode file for %s\n", mountedOn);
        return -2;
     }
@@ -1677,13 +1686,9 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile,
     /*
      * Paranoia:  check that the file is really the right size
      */
-    if (afs_fstat(fileno(inodeFile), &status) == -1) {
-       Log("Unable to successfully stat inode file for %s\n", mountedOn);
-       return -2;
-    }
-    if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) {
+    if (OS_SIZE(inodeFile) != ninodes * sizeof(struct ViceInodeInfo)) {
        Log("Wrong size (%d instead of %lu) in inode file for %s\n",
-           (int) status.st_size,
+           (int) OS_SIZE(inodeFile),
            (long unsigned int) ninodes * sizeof(struct ViceInodeInfo),
            mountedOn);
        return -2;
@@ -1714,9 +1719,9 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile,
  */
 int
 namei_ListAFSFiles(char *dev,
-                  int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
+                  int (*writeFun) (FD_t, struct ViceInodeInfo *, char *,
                                    char *),
-                  FILE * fp,
+                  FD_t fp,
                   int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *),
                   afs_uint32 singleVolumeNumber, void *rock)
 {
@@ -1767,8 +1772,8 @@ namei_ListAFSFiles(char *dev,
 #else
            if (*dp1->d_name == '.')
                continue;
-           afs_snprintf(path2, sizeof(path2), "%s" OS_DIRSEP "%s", name.n_path,
-                        dp1->d_name);
+           snprintf(path2, sizeof(path2), "%s" OS_DIRSEP "%s", name.n_path,
+                    dp1->d_name);
            dirp2 = opendir(path2);
            if (dirp2) {
                while ((dp2 = readdir(dirp2))) {
@@ -1831,9 +1836,9 @@ _namei_examine_special(char * path1,
                       char * dname,
                       IHandle_t * myIH,
                       FdHandle_t * linkHandle,
-                      int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
+                      int (*writeFun) (FD_t, struct ViceInodeInfo *, char *,
                                        char *),
-                      FILE * fp,
+                      FD_t fp,
                       int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *),
                       int singleVolumeNumber,
                       void *rock)
@@ -1868,8 +1873,8 @@ _namei_examine_special(char * path1,
     } else {
        char path2[512];
        /* Open this handle */
-       (void)afs_snprintf(path2, sizeof(path2),
-                          "%s" OS_DIRSEP "%s", path1, dname);
+       snprintf(path2, sizeof(path2),
+                "%s" OS_DIRSEP "%s", path1, dname);
        linkHandle->fd_fd = OS_OPEN(path2, Testing ? O_RDONLY : O_RDWR, 0666);
        info.linkCount =
            namei_GetLinkCount(linkHandle, (Inode) 0, 1, 1, Testing);
@@ -1877,9 +1882,12 @@ _namei_examine_special(char * path1,
 
     if (!judgeFun ||
        (*judgeFun) (&info, singleVolumeNumber, rock)) {
-       ret = 1;
-        if ((*writeFun) (fp, &info, path1, dname) < 0) {
+       ret = (*writeFun) (fp, &info, path1, dname);
+       if (ret < 0) {
+           Log("_namei_examine_special: writeFun returned %d\n", ret);
            ret = -1;
+       } else {
+           ret = 1;
        }
     }
 
@@ -1920,9 +1928,9 @@ _namei_examine_reg(char * path3,
                   char * dname,
                   IHandle_t * myIH,
                   FdHandle_t * linkHandle,
-                  int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
+                  int (*writeFun) (FD_t, struct ViceInodeInfo *, char *,
                                    char *),
-                  FILE * fp,
+                  FD_t fp,
                   int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *),
                   int singleVolumeNumber,
                   void *rock)
@@ -1959,9 +1967,12 @@ _namei_examine_reg(char * path3,
 
     if (!judgeFun ||
        (*judgeFun) (&info, singleVolumeNumber, rock)) {
-       ret = 1;
-        if ((*writeFun) (fp, &info, path3, dname) < 0) {
+       ret = (*writeFun) (fp, &info, path3, dname);
+       if (ret < 0) {
+           Log("_namei_examine_reg: writeFun returned %d\n", ret);
            ret = -1;
+       } else {
+           ret = 1;
        }
     }
 
@@ -1985,10 +1996,10 @@ struct listsubdirs_work_node {
                                          *   inode, this will be pointed at the
                                          *   link table
                                          */
-    FILE * fp;                          /**< file pointer for writeFun */
+    FD_t fp;                            /**< file pointer for writeFun */
 
     /** function which will write inode metadata to fp */
-    int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, char *);
+    int (*writeFun) (FD_t, struct ViceInodeInfo *, char *, char *);
 
     /** inode filter function */
     int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *);
@@ -2315,9 +2326,9 @@ _namei_examine_file_spawn(const struct listsubdirs_work_node *work,
  */
 static int
 namei_ListAFSSubDirs(IHandle_t * dirIH,
-                    int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
+                    int (*writeFun) (FD_t, struct ViceInodeInfo *, char *,
                                      char *),
-                    FILE * fp,
+                    FD_t fp,
                     int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *),
                     afs_uint32 singleVolumeNumber, void *rock)
 {
@@ -2445,7 +2456,8 @@ namei_ListAFSSubDirs(IHandle_t * dirIH,
 
 #ifndef AFS_NT40_ENV /* This level missing on Windows */
            /* Now we've got a next level subdir. */
-           afs_snprintf(path2, sizeof(path2), "%s" OS_DIRSEP "%s", path1, dp1->d_name);
+           snprintf(path2, sizeof(path2), "%s" OS_DIRSEP "%s",
+                    path1, dp1->d_name);
            dirp2 = opendir(path2);
            if (dirp2) {
                while ((dp2 = readdir(dirp2))) {
@@ -2453,12 +2465,12 @@ namei_ListAFSSubDirs(IHandle_t * dirIH,
                        continue;
 
                    /* Now we've got to the actual data */
-                   afs_snprintf(path3, sizeof(path3), "%s" OS_DIRSEP "%s", path2,
-                                dp2->d_name);
+                   snprintf(path3, sizeof(path3), "%s" OS_DIRSEP "%s",
+                            path2, dp2->d_name);
 #else
                    /* Now we've got to the actual data */
-                   afs_snprintf(path3, sizeof(path3), "%s" OS_DIRSEP "%s", path1,
-                                dp1->d_name);
+                   snprintf(path3, sizeof(path3), "%s" OS_DIRSEP "%s",
+                            path1, dp1->d_name);
 #endif
                    dirp3 = opendir(path3);
                    if (dirp3) {
@@ -2599,7 +2611,7 @@ DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info,
     FdHandle_t linkHandle;
     char dirl;
 
-    afs_snprintf(fpath, sizeof(fpath), "%s" OS_DIRSEP "%s", dpath, name);
+    snprintf(fpath, sizeof(fpath), "%s" OS_DIRSEP "%s", dpath, name);
 
     dirH = FindFirstFileEx(fpath, FindExInfoStandard, &data,
                           FindExSearchNameMatch, NULL,
@@ -2667,11 +2679,11 @@ DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info,
            unsigned int volid)
 {
     char fpath[512];
-    struct afs_stat status;
+    struct afs_stat_st status;
     int parm, tag;
     lb64_string_t check;
 
-    afs_snprintf(fpath, sizeof(fpath), "%s" OS_DIRSEP "%s", dpath, name);
+    snprintf(fpath, sizeof(fpath), "%s" OS_DIRSEP "%s", dpath, name);
 
     if (afs_stat(fpath, &status) < 0) {
        return -1;
@@ -2914,8 +2926,8 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId)
     t_ih.ih_dev = ih->ih_dev;
     t_ih.ih_vid = ih->ih_vid;
 
-    (void)afs_snprintf(oldpath, sizeof oldpath, "%s" OS_DIRSEP "%s", dir_name,
-                      infoName);
+    snprintf(oldpath, sizeof oldpath, "%s" OS_DIRSEP "%s", dir_name,
+            infoName);
     fd = OS_OPEN(oldpath, O_RDWR, 0);
     if (fd == INVALID_FD) {
        Log("1 namei_ConvertROtoRWvolume: could not open RO info file: %s\n",
@@ -2925,7 +2937,7 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId)
     }
     t_ih.ih_ino = namei_MakeSpecIno(ih->ih_vid, VI_VOLINFO);
     namei_HandleToName(&n, &t_ih);
-    fd2 = OS_OPEN(n.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0);
+    fd2 = OS_OPEN(n.n_path, O_CREAT | O_EXCL | O_RDWR, 0);
     if (fd2 == INVALID_FD) {
        Log("1 namei_ConvertROtoRWvolume: could not create RW info file: %s\n", n.n_path);
        OS_CLOSE(fd);
@@ -2945,8 +2957,8 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId)
 
     t_ih.ih_ino = namei_MakeSpecIno(ih->ih_vid, VI_SMALLINDEX);
     namei_HandleToName(&n, &t_ih);
-    (void)afs_snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name,
-                      smallName);
+    snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name,
+            smallName);
     fd = OS_OPEN(newpath, O_RDWR, 0);
     if (fd == INVALID_FD) {
        Log("1 namei_ConvertROtoRWvolume: could not open SmallIndex file: %s\n", newpath);
@@ -2964,8 +2976,8 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId)
 
     t_ih.ih_ino = namei_MakeSpecIno(ih->ih_vid, VI_LARGEINDEX);
     namei_HandleToName(&n, &t_ih);
-    (void)afs_snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name,
-                      largeName);
+    snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name,
+            largeName);
     fd = OS_OPEN(newpath, O_RDWR, 0);
     if (fd == INVALID_FD) {
        Log("1 namei_ConvertROtoRWvolume: could not open LargeIndex file: %s\n", newpath);
@@ -3026,7 +3038,7 @@ PrintInode(char *s, Inode ino)
     if (!s)
        s = result;
 
-    (void)afs_snprintf(s, sizeof(afs_ino_str_t), "%" AFS_UINT64_FMT, (afs_uintmax_t) ino);
+    snprintf(s, sizeof(afs_ino_str_t), "%llu", (afs_uintmax_t) ino);
 
     return s;
 }