dir: Prototype and function name cleanup
[openafs.git] / src / volser / volprocs.c
index 0d5271f..e55a5a2 100644 (file)
 
 #include <roken.h>
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <string.h>
-#include <errno.h>
-#ifdef AFS_NT40_ENV
-#include <stdlib.h>
-#include <fcntl.h>
-#include <winsock2.h>
-#else
-#include <sys/file.h>
-#include <netinet/in.h>
-#include <unistd.h>
-#endif
-
-#include <dirent.h>
-#include <sys/stat.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <rx/rxkad.h>
 #include <afs/afsint.h>
-#include <signal.h>
 #include <afs/afs_assert.h>
 #include <afs/prs_fs.h>
 #include <afs/nfs.h>
@@ -58,6 +41,7 @@
 #include "afs/audit.h"
 #include <afs/dir.h>
 #include <afs/afsutil.h>
+#include <afs/com_err.h>
 #include <afs/vol_prototypes.h>
 #include <afs/errors.h>
 
@@ -136,7 +120,7 @@ VPFullUnlock_r(void)
     struct DiskPartition64 *tp;
     for (tp = DiskPartitionList; tp; tp = tp->next) {
        if (tp->lock_fd != INVALID_FD) {
-           close(tp->lock_fd); /* releases flock held on this partition */
+            OS_CLOSE(tp->lock_fd);
            tp->lock_fd = INVALID_FD;
        }
     }
@@ -197,7 +181,7 @@ ConvertVolume(afs_uint32 avol, char *aname, afs_int32 asize)
     if (asize < 18)
        return -1;
     /* It's better using the Generic VFORMAT since otherwise we have to make changes to too many places... The 14 char limitation in names hits us again in AIX; print in field of 9 digits (still 10 for the rest), right justified with 0 padding */
-    (void)afs_snprintf(aname, asize, VFORMAT, (unsigned long)avol);
+    snprintf(aname, asize, VFORMAT, (unsigned long)avol);
     return 0;
 }
 
@@ -321,7 +305,7 @@ XAttachVolume(afs_int32 *error, afs_uint32 avolid, afs_int32 apartid, int amode)
 }
 
 /* Adapted from the file server; create a root directory for this volume */
-static int
+static Error
 ViceCreateRoot(Volume *vp)
 {
     DirHandle dir;
@@ -345,17 +329,21 @@ ViceCreateRoot(Volume *vp)
        IH_CREATE(V_linkHandle(vp), V_device(vp),
                  VPartitionPath(V_partition(vp)), nearInode, V_parentId(vp),
                  1, 1, 0);
-    osi_Assert(VALID_INO(inodeNumber));
+    if (!VALID_INO(inodeNumber)) {
+       Log("ViceCreateRoot: IH_CREATE: %s\n", afs_error_message(errno));
+       free(vnode);
+       return EIO;
+    }
 
     SetSalvageDirHandle(&dir, V_parentId(vp), vp->device, inodeNumber);
     did.Volume = V_id(vp);
     did.Vnode = (VnodeId) 1;
     did.Unique = 1;
 
-    osi_Assert(!(MakeDir(&dir, (afs_int32 *)&did, (afs_int32 *)&did)));
+    osi_Assert(!(afs_dir_MakeDir(&dir, (afs_int32 *)&did, (afs_int32 *)&did)));
     DFlush();                  /* flush all modified dir buffers out */
-    DZap((afs_int32 *)&dir);                   /* Remove all buffers for this dir */
-    length = Length(&dir);     /* Remember size of this directory */
+    DZap(&dir);                        /* Remove all buffers for this dir */
+    length = afs_dir_Length(&dir);     /* Remember size of this directory */
 
     FidZap(&dir);              /* Done with the dir handle obtained via SetSalvageDirHandle() */
 
@@ -401,7 +389,7 @@ ViceCreateRoot(Volume *vp)
     V_diskused(vp) = nBlocks(length);
 
     free(vnode);
-    return 1;
+    return 0;
 }
 
 afs_int32
@@ -577,8 +565,17 @@ VolCreateVolume(struct rx_call *acid, afs_int32 apart, char *aname,
     V_inService(vp) = V_blessed(vp) = 1;
     V_type(vp) = atype;
     AssignVolumeName(&V_disk(vp), aname, 0);
-    if (doCreateRoot)
-       ViceCreateRoot(vp);
+    if (doCreateRoot) {
+       error = ViceCreateRoot(vp);
+       if (error) {
+           Log("1 Volser: CreateVolume: Unable to create volume root dir; "
+               "error code %u\n", (unsigned)error);
+           DeleteTrans(tt, 1);
+           V_needsSalvaged(vp) = 1;
+           VDetachVolume(&junk, vp);
+           return EIO;
+       }
+    }
     V_destroyMe(vp) = DESTROY_ME;
     V_inService(vp) = 0;
     V_maxquota(vp) = 5000;     /* set a quota of 5000 at init time */
@@ -852,8 +849,7 @@ VolClone(struct rx_call *acid, afs_int32 atrans, afs_uint32 purgeId,
        DeleteTrans(ttc, 1);
 #ifdef AFS_DEMAND_ATTACH_FS
     if (salv_vp && error != VVOLEXISTS && error != EXDEV) {
-       Error salv_error;
-       VRequestSalvage_r(&salv_error, salv_vp, FSYNC_SALVAGE, 0);
+       V_needsSalvaged(salv_vp) = 1;
     }
 #endif /* AFS_DEMAND_ATTACH_FS */
     return error;
@@ -1238,7 +1234,7 @@ SAFSVolForward(struct rx_call *acid, afs_int32 fromTrans, afs_int32 fromDate,
     code =
        VolForward(acid, fromTrans, fromDate, destination, destTrans, cookie);
     osi_auditU(acid, VS_ForwardEvent, code, AUD_LONG, fromTrans, AUD_HOST,
-              destination->destHost, AUD_LONG, destTrans, AUD_END);
+              htonl(destination->destHost), AUD_LONG, destTrans, AUD_END);
     return code;
 }
 
@@ -1441,7 +1437,7 @@ SAFSVolForwardMultiple(struct rx_call *acid, afs_int32 fromTrans, afs_int32
        }
 
        osi_auditU(acid, VS_ForwardEvent, (code ? code : codes[i]), AUD_LONG,
-                  fromTrans, AUD_HOST, dest->server.destHost, AUD_LONG,
+                  fromTrans, AUD_HOST, htonl(dest->server.destHost), AUD_LONG,
                   dest->trans, AUD_END);
     }
     free(tcons);
@@ -1591,7 +1587,7 @@ SAFSVolSetForwarding(struct rx_call *acid, afs_int32 atid, afs_int32 anewsite)
 
     code = VolSetForwarding(acid, atid, anewsite);
     osi_auditU(acid, VS_SetForwEvent, code, AUD_LONG, atid, AUD_HOST,
-              anewsite, AUD_END);
+              htonl(anewsite), AUD_END);
     return code;
 }
 
@@ -2229,7 +2225,10 @@ GetVolInfo(afs_uint32 partId,
     }
 
     /* Get volume from volserver */
-    tv = VAttachVolumeByName_retry(&error, pname, volname, V_PEEK);
+    if (mode == VOL_INFO_LIST_MULTIPLE)
+       tv = VAttachVolumeByName(&error, pname, volname, V_PEEK);
+    else
+       tv = VAttachVolumeByName_retry(&error, pname, volname, V_PEEK);
     if (error) {
        Log("1 Volser: GetVolInfo: Could not attach volume %u (%s:%s) error=%d\n",
            volumeId, pname, volname, error);