venus: Tidy up header includes
[openafs.git] / src / venus / up.c
index af2e18f..522dc08 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
-/* missing type from C language */
-
-#include <errno.h>
-#ifdef AFS_AIX32_ENV
-#include <signal.h>
-#undef _NONSTD_TYPES
-#endif
-#include <stdio.h>
 #include <afs/afs_args.h>
-#include <sys/param.h>
-#ifdef AFS_SUN5_ENV
-#include <fcntl.h>
-#endif
-#include <sys/file.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <sys/time.h>
 #define VIRTUE
 #define VICE
-#include <sys/ioctl.h>
 #include <afs/vice.h>
 #undef VIRTUE
 #undef VICE
-#include <sys/ioctl.h>
-#include <netdb.h>
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-
 #include <afs/venus.h>
+#include <afs/sys_prototypes.h>
+#include <afs/afsutil.h>
+#include <afs/afs_consts.h>
 
 /* ************************************************************* */
 
@@ -63,13 +34,11 @@ short preserveDate = 1;
 short preserveMountPoints = 0;
 short forceOverwrite = 0;
 
-int pageSize;
 short setacl = 1;
 short oldAcl = 0;
 char file1[MAXPATHLEN], file2[MAXPATHLEN];
 
-#define        MAXSIZE 2048
-static char space[MAXSIZE];
+static char space[AFS_PIOCTL_MAXSIZE];
 
 struct OldAcl {
     int nplus;
@@ -97,8 +66,8 @@ main(int argc, 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.
      */
@@ -109,9 +78,6 @@ main(int argc, char *argv[])
     nsa.sa_flags = SA_FULLDUMP;
     sigaction(SIGSEGV, &nsa, NULL);
 #endif
-#if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
-    pageSize = getpagesize();
-#endif
     ScanArgs(argc, argv);
 
     /* now read each line of the CopyList */
@@ -133,6 +99,10 @@ ScanArgs(int argc, char *argv[])
     while (argc > 0 && *argv[0] == '-') {
        char *cp = *argv;
 
+       if (strlen(cp) > 2) {
+           goto badoption;
+       }
+
        switch (*++cp) {
        case 'v':
            verbose = 1;
@@ -159,7 +129,10 @@ ScanArgs(int argc, char *argv[])
            break;
 
        default:
-           fprintf(stderr, "Unknown option: '%c'\n", *cp);
+           cp--;
+
+ badoption:
+           fprintf(stderr, "Unknown option: '%s'\n", cp);
            fprintf(stderr, USAGE);
            exit(1);
        }
@@ -278,7 +251,7 @@ Copy(char *file1, char *file2, short recursive, int level)
 
            if (verbose) {
                printf("  Copy file %s to %s (%u Bytes)\n", file1, file2,
-                      s1.st_size);
+                      (unsigned int) s1.st_size);
                fflush(stdout);
            }
 
@@ -361,7 +334,8 @@ Copy(char *file1, char *file2, short recursive, int level)
            if (s1.st_size != s2.st_size) {
                fprintf(stderr,
                        "WARNING: New file %s is %u bytes long; should be %u\n",
-                       file2, s2.st_size, s1.st_size);
+                       file2, (unsigned int) s2.st_size,
+                       (unsigned int) s1.st_size);
            }
        }
 
@@ -511,6 +485,7 @@ Copy(char *file1, char *file2, short recursive, int level)
        char f1[MAXPATHLEN], f2[MAXPATHLEN];
        char *p1, *p2;
        struct dirent *d;
+       struct timeval tv[2];
 
        if (verbose) {
            printf("Level %d: Directory %s to %s\n", level, file1, file2);
@@ -698,6 +673,15 @@ Copy(char *file1, char *file2, short recursive, int level)
                printf("Not setting acls\n");
            }
        }
+
+        /* preserve access and modification times: ("-x" disables) */
+        if (preserveDate) {
+            tv[0].tv_sec = s1.st_atime;
+            tv[0].tv_usec = 0;
+            tv[1].tv_sec = s1.st_mtime;
+            tv[1].tv_usec = 0;
+            utimes(file2, tv);
+        }
     }
 
     return rcode;
@@ -744,9 +728,9 @@ isMountPoint(char *name, struct ViceIoctl *blob)
 
     blob->in = last_component;
     blob->in_size = strlen(last_component) + 1;
-    blob->out_size = MAXSIZE;
+    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, 0);
 
@@ -768,5 +752,4 @@ isMountPoint(char *name, struct ViceIoctl *blob)
             */
        }
     }
-    return 4;
 }