1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #ifndef _NFSGEN_H
  28 #define _NFSGEN_H
  29 
  30 #ifdef  __cplusplus
  31 extern "C" {
  32 #endif
  33 
  34 /* include for common C functions */
  35 
  36 #include <errno.h>
  37 #include <stdio.h>
  38 #include <stdlib.h>
  39 #include <signal.h>
  40 #include <string.h>
  41 #include <strings.h>
  42 #include <math.h>
  43 #include <stdarg.h>
  44 #include <fcntl.h>
  45 #include <unistd.h>
  46 #include <sys/wait.h>
  47 #include <sys/param.h>
  48 #include <sys/types.h>
  49 #include <sys/mman.h>
  50 #include <sys/stat.h>
  51 #include <sys/time.h>
  52 #include <sys/times.h>
  53 #include <sys/stat.h>
  54 #include <sys/utsname.h>
  55 #include <nfs/nfs.h>
  56 #include <nfs/export.h>
  57 #include <nfs/nfssys.h>
  58 
  59 #include <stf.h>
  60 
  61 /* Constants */
  62 /* lock functions' mandatory values */
  63 #define MAND_NO         0       /* No mandatory locking */
  64 #define MAND_YES        1       /* Non-blocking mandatory locking */
  65 #define MANDW_YES       2       /* Blocking mandatory locking */
  66 
  67 /* to use in locks */
  68 #define TO_EOF  0
  69 
  70 /* used in pipes */
  71 #define CHILD   'C'
  72 #define PARENT  'P'
  73 
  74 /* general status */
  75 #define OK              STF_PASS
  76 #define NOOK            STF_FAIL
  77 #define UNTESTED        STF_UNTESTED
  78 
  79 /* admerrors commands */
  80 #define TOTALS          0
  81 #define TOTERROR        1
  82 #define TOTSTEPS        2
  83 #define TOTASSERT       3
  84 #define ASSERT          4
  85 #define TOTDB           5
  86 #define SCENARIO        6
  87 
  88 /* mmap read/write flag */
  89 #define MMREAD          1
  90 #define MMWRITE         2
  91 
  92 /* Macros */
  93 
  94 #define IS64BIT_OFF_T   sizeof (off_t) > sizeof (long)
  95 
  96 #define read_lock(fd, mand, offset, whence, len) \
  97         lock_reg(fd, mand, F_RDLCK, offset, whence, len)
  98 
  99 #define write_lock(fd, mand, offset, whence, len) \
 100         lock_reg(fd, mand, F_WRLCK, offset, whence, len)
 101 
 102 #define un_lock(fd, mand, offset, whence, len) \
 103         lock_reg(fd, mand, F_UNLCK, offset, whence, len)
 104 
 105 /* Globals */
 106 
 107 extern int      me;                     /* current process (PARENT or CHILD) */
 108 extern pid_t    PidParent, PidChild;    /* Pids */
 109 extern int      NBlocks;                /* flag to avoid mandatory locks */
 110                                         /*   from waiting */
 111 extern int      SYNCWRITE;              /* force access to file (server) by */
 112                                         /*   invalidating mem copy */
 113 extern int      mmflag;                 /* flag to use mmap on read/writes */
 114 extern int      debug;                  /* debug flag */
 115 extern int      showerror;              /* display error messages flag */
 116 extern int      expecterr;              /* Expected return value for open & */
 117                                         /* friends: OK, errno, NOOK->unknown */
 118 extern int      errflag;                /* Number of errors */
 119 extern int      tsflag;                 /* Number of tresults failed */
 120 extern int      tsprev;                 /* Previous value for tsflag */
 121 extern int      aflag;                  /* Number of assertions failed */
 122 extern int      tspflag;                /* Number of succesful tresults */
 123 extern int      apflag;                 /* Number of successful assertions */
 124 extern int      byeflag;                /* insert atexit() notification once */
 125 extern char     *GLOBdata;              /* temp storage used for verifying */
 126                                         /*      reads */
 127 extern int      Glob_status;            /* global status to control */
 128                                         /*      say_bye() msg */
 129 extern struct timeval   tpstart;        /* Time sttructure for event's */
 130                                         /*      starting time */
 131 extern struct timeval   tpend;          /* Time sttructure for event's ending */
 132                                         /*      time */
 133 extern struct stat      Stat;           /* file stat output */
 134 
 135 extern int      errtoout;               /* make stderr same as sdtout */
 136 extern char     odir[512];              /* original directory */
 137 extern char     cwd[512];               /* test direcory */
 138 extern char     *Testname;              /* this process name */
 139 extern int      renew;                  /* lease period */
 140 
 141 extern char     *scen;                  /* scenario name */
 142 extern int      scen_mode;              /* mode for testscenarios */
 143 extern int      scen_flag;              /* flags for test scenarios */
 144 
 145 extern char     lfilename[512];         /* local machine path/filename for */
 146                                         /* testfile */
 147 extern int      lperms;                 /* testfile permissions */
 148 extern int      lflags;                 /* testfile flags */
 149 extern int      delay;                  /* time delay in seconds */
 150 extern int      srv_local;              /* flag to signal this process is */
 151                                         /*   running locally on the server */
 152 
 153 extern uid_t    uid;                    /* first user test uid */
 154 extern uid_t    uid2;                   /* second test uid */
 155 extern gid_t    gid;                    /* first user test gid */
 156 extern gid_t    gid2;                   /* second user test gid */
 157 
 158 extern int      skip_getdeleg;          /* call get_deleg_type() or not */
 159 
 160                 /* The next 4 vars are for per scenario instance stats */
 161 extern int      serrflag;       /* Number of errors scenario */
 162 extern int      stsflag;        /* Number of tresults failed scenario */
 163 extern int      saflag;         /* Number of assertions failed scenario */
 164 extern int      stspflag;       /* Number of succesful tresults scenario */
 165 extern int      sapflag;        /* Number of successful assertions scenario */
 166 
 167 /* Functions */
 168 
 169 extern void     print(char *, ...);
 170 extern void     dprint(char *, ...);
 171 extern void     eprint(char *, ...);
 172 extern void     Perror(const char *);
 173 extern char     *errtostr(int);
 174 extern char     *sigtostr(int);
 175 extern char     *mandtostr(int);
 176 extern char     *whencetostr(int);
 177 extern char     *cmdtostr(int);
 178 extern char     *typetostr(int);
 179 extern char     *pidtostr(pid_t);
 180 extern char     *oflagstr(int);
 181 extern char     *mmtypetostr(int);
 182 extern int      tresult(int, int);
 183 extern void     assertion(char *, char *, char *);
 184 extern int      admerrors(int);
 185 extern char     *Whoami(void);
 186 extern int      lock_reg(int, int, int, off_t, int, off_t);
 187 extern pid_t    lock_test(int, int, off_t, int, off_t);
 188 extern int      create_test_data_file(char *, int);
 189 extern int      create_10K_test_data_file(char *, int);
 190 extern off_t    pos_file(int, off_t);
 191 extern int      open_file(char *, int, int);
 192 extern int      close_file(int, char *);
 193 extern int      chmod_file(int, char *, mode_t);
 194 extern int      link_file(char *, char *);
 195 extern int      unlink_file(char *);
 196 extern ssize_t  nfsgenRead(int, void*, size_t);
 197 extern ssize_t  nfsgenWrite(int, void*, size_t);
 198 extern int      write_file(int, char *, char *, off_t, unsigned);
 199 extern int      read_file(int, char *, char *, off_t, unsigned);
 200 extern char     *strbackup(char *);
 201 extern int      dupfile(int);
 202 extern int      Seteuid(uid_t);
 203 extern int      Setegid(gid_t);
 204 extern int      Setgroups(int, gid_t *);
 205 extern int      truncatefile(int, char *, off_t);
 206 extern int      statfile(int, char *);
 207 extern int      mmapfile(int, char **, off_t, off_t *, int);
 208 extern int      munmapfile(char *, off_t);
 209 extern int      dirtyfile(int, char *, size_t);
 210 extern int      _nfssys(int, void *);
 211 extern int      get_deleg(int, char *);
 212 extern void     exit_test(int);
 213 extern void     kill_child(int);
 214 extern void     encode_errors(void);
 215 extern void     decode_errors(void);
 216 extern void     notify_parent(int);
 217 extern void     notify_child(int);
 218 extern void     childisdead(int);
 219 extern void     say_bye(void);
 220 extern void     insert_bye(void);
 221 extern void     initialize(void);
 222 extern void     init_comm(void);
 223 extern void     sendintp(int);
 224 extern int      getintp(void);
 225 extern void     contch(void);
 226 extern void     waitch(void);
 227 extern void     contp(void);
 228 extern void     waitp(void);
 229 extern void     clientinfo(void);
 230 extern void     starttime(char *);
 231 extern void     endtime(char *);
 232 extern int      rsh_cmd(char *, char *, char *, char *);
 233 extern void     cd_to_odir(void);
 234 extern void     Usage(void);
 235 extern void     parse_args(int, char **);
 236 extern int      wait_get_cresult(void);
 237 extern int      wait_send_cresult(void);
 238 
 239 #ifdef  __cplusplus
 240 }
 241 #endif
 242 
 243 #endif  /* _NFSGEN_H */