Merge from vendor branch GCC:
[dragonfly.git] / contrib / amd / include / am_utils.h
1 /*
2  * Copyright (c) 1997-1999 Erez Zadok
3  * Copyright (c) 1990 Jan-Simon Pendry
4  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
5  * Copyright (c) 1990 The Regents of the University of California.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Jan-Simon Pendry at Imperial College, London.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgment:
21  *      This product includes software developed by the University of
22  *      California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *      %W% (Berkeley) %G%
40  *
41  * $Id: am_utils.h,v 1.6 1999/08/22 05:12:55 ezk Exp $
42  *
43  */
44
45 /*
46  * Definitions that are specific to the am-utils package.
47  */
48
49 #ifndef _AM_UTILS_H
50 #define _AM_UTILS_H
51
52
53 /**************************************************************************/
54 /*** MACROS                                                             ***/
55 /**************************************************************************/
56
57 /*
58  * General macros.
59  */
60 #ifndef FALSE
61 # define FALSE 0
62 #endif /* not FALSE */
63 #ifndef TRUE
64 # define TRUE 1
65 #endif /* not TRUE */
66 #ifndef MAX
67 # define MAX(a, b)      ((a) > (b) ? (a) : (b))
68 #endif /* not MAX */
69 #ifndef MIN
70 # define MIN(a, b)      ((a) < (b) ? (a) : (b))
71 #endif /* not MIN */
72
73 #define ONE_HOUR        (60 * 60)       /* One hour in seconds */
74
75 #ifndef MAXHOSTNAMELEN
76 # ifdef HOSTNAMESZ
77 #  define MAXHOSTNAMELEN HOSTNAMESZ
78 # else /* not HOSTNAMESZ */
79 #  define MAXHOSTNAMELEN 64
80 # endif /* not HOSTNAMESZ */
81 #endif /* not MAXHOSTNAMELEN */
82
83 /*
84  * String comparison macros
85  */
86 #define STREQ(s1, s2)           (strcmp((s1), (s2)) == 0)
87 #define STRCEQ(s1, s2)          (strcasecmp((s1), (s2)) == 0)
88 #define NSTREQ(s1, s2, n)       (strncmp((s1), (s2), (n)) == 0)
89 #define FSTREQ(s1, s2)          ((*(s1) == *(s2)) && STREQ((s1),(s2)))
90
91 /*
92  * Logging options/flags
93  */
94 #define XLOG_FATAL      0x0001
95 #define XLOG_ERROR      0x0002
96 #define XLOG_USER       0x0004
97 #define XLOG_WARNING    0x0008
98 #define XLOG_INFO       0x0010
99 #define XLOG_DEBUG      0x0020
100 #define XLOG_MAP        0x0040
101 #define XLOG_STATS      0x0080
102 #define XLOG_DEFSTR     "all,nomap,nostats"     /* Default log options */
103 #define XLOG_ALL        (XLOG_FATAL|XLOG_ERROR|XLOG_USER|XLOG_WARNING|XLOG_INFO|XLOG_MAP|XLOG_STATS)
104
105 #define clocktime() (clock_valid ? clock_valid : time(&clock_valid))
106
107 #ifndef ROOT_MAP
108 # define ROOT_MAP "\"root\""
109 #endif /* not ROOT_MAP */
110
111 #define NO_SUBNET       "notknown"      /* default subnet name for no subnet */
112 #define NEXP_AP         (1022)  /* gdmr: was 254 */
113 #define NEXP_AP_MARGIN  (128)
114 #define MAX_READDIR_ENTRIES     16
115
116 /*
117  * Linked list macros
118  */
119 #define AM_FIRST(ty, q) ((ty *) ((q)->q_forw))
120 #define AM_LAST(ty, q)  ((ty *) ((q)->q_back))
121 #define NEXT(ty, q)     ((ty *) (((qelem *) q)->q_forw))
122 #define PREV(ty, q)     ((ty *) (((qelem *) q)->q_back))
123 #define HEAD(ty, q)     ((ty *) q)
124 #define ITER(v, ty, q) \
125         for ((v) = AM_FIRST(ty,(q)); (v) != HEAD(ty,(q)); (v) = NEXT(ty,(v)))
126
127 /* allocate anything of type ty */
128 #define ALLOC(ty)       ((ty *) xmalloc(sizeof(ty)))
129 #define CALLOC(ty)      ((ty *) xcalloc(1, sizeof(ty)))
130 /* simply allocate b bytes */
131 #define SALLOC(b)       xmalloc((b))
132
133 /* converting am-filehandles to mount-points */
134 #define fh_to_mp2(fhp, rp) fh_to_mp3(fhp, rp, VLOOK_CREATE)
135
136 /*
137  * Systems which have the mount table in a file need to read it before
138  * they can perform an unmount() system call.
139  */
140 #define UMOUNT_FS(dir, mtb_name)        umount_fs(dir, mtb_name)
141 /* imported via $srcdir/conf/umount/umount_*.c */
142 extern int umount_fs(char *fs_name, const char *mnttabname);
143
144 /*
145  * macros for automounter vfs/vnode operations.
146  */
147 #define VLOOK_CREATE    0x1
148 #define VLOOK_DELETE    0x2
149 #define FS_DIRECTORY    0x0001  /* This looks like a dir, not a link */
150 #define FS_MBACKGROUND  0x0002  /* Should background this mount */
151 #define FS_NOTIMEOUT    0x0004  /* Don't bother with timeouts */
152 #define FS_MKMNT        0x0008  /* Need to make the mount point */
153 #define FS_UBACKGROUND  0x0010  /* Unmount in background */
154 #define FS_BACKGROUND   (FS_MBACKGROUND|FS_UBACKGROUND)
155 #define FS_DISCARD      0x0020  /* Discard immediately on last reference */
156 #define FS_AMQINFO      0x0040  /* Amq is interested in this fs type */
157
158 /*
159  * macros for struct fserver.
160  */
161 #define FSF_VALID       0x0001  /* Valid information available */
162 #define FSF_DOWN        0x0002  /* This fileserver is thought to be down */
163 #define FSF_ERROR       0x0004  /* Permanent error has occurred */
164 #define FSF_WANT        0x0008  /* Want a wakeup call */
165 #define FSF_PINGING     0x0010  /* Already doing pings */
166 #define FSRV_ISDOWN(fs) (((fs)->fs_flags & (FSF_DOWN|FSF_VALID)) == (FSF_DOWN|FSF_VALID))
167 #define FSRV_ISUP(fs)   (((fs)->fs_flags & (FSF_DOWN|FSF_VALID)) == (FSF_VALID))
168
169 /*
170  * macros for struct mntfs (list of mounted filesystems)
171  */
172 #define MFF_MOUNTED     0x0001  /* Node is mounted */
173 #define MFF_MOUNTING    0x0002  /* Mount is in progress */
174 #define MFF_UNMOUNTING  0x0004  /* Unmount is in progress */
175 #define MFF_RESTART     0x0008  /* Restarted node */
176 #define MFF_MKMNT       0x0010  /* Delete this node's am_mount */
177 #define MFF_ERROR       0x0020  /* This node failed to mount */
178 #define MFF_LOGDOWN     0x0040  /* Logged that this mount is down */
179 #define MFF_RSTKEEP     0x0080  /* Don't timeout this filesystem - restarted */
180 #define MFF_WANTTIMO    0x0100  /* Need a timeout call when not busy */
181 #ifdef HAVE_AM_FS_NFSL
182 # define MFF_NFSLINK    0x0200  /* nfsl type, and deemed a link */
183 #endif /* HAVE_AM_FS_NFSL */
184
185 /*
186  * macros for struct am_node (map of auto-mount points).
187  */
188 #define AMF_NOTIMEOUT   0x0001  /* This node never times out */
189 #define AMF_ROOT        0x0002  /* This is a root node */
190 #ifdef HAVE_FS_AUTOFS
191 # define AMF_AUTOFS     0x0004  /* this node is of type autofs */
192 #endif /* HAVE_FS_AUTOFS */
193
194 /*
195  * The following values can be tuned...
196  */
197 #define ALLOWED_MOUNT_TIME      40      /* 40s for a mount */
198 #define AM_TTL                  (5 * 60)        /* Default cache period */
199 #define AM_TTL_W                (2 * 60)        /* Default unmount interval */
200 #define AM_PINGER               30 /* NFS ping interval for live systems */
201 #define AMFS_AUTO_TIMEO         8 /* Default amfs_auto timeout - .8s */
202
203 /*
204  * default amfs_auto retrans - 1/10th seconds
205  */
206 #define AMFS_AUTO_RETRANS       ((ALLOWED_MOUNT_TIME*10+5*gopt.amfs_auto_timeo)/gopt.amfs_auto_timeo * 2)
207
208 /*
209  * RPC-related macros.
210  */
211 #define RPC_XID_PORTMAP         0
212 #define RPC_XID_MOUNTD          1
213 #define RPC_XID_NFSPING         2
214 #define RPC_XID_MASK            (0x0f)  /* 16 id's for now */
215 #define MK_RPC_XID(type_id, uniq)       ((type_id) | ((uniq) << 4))
216
217 /*
218  * What level of AMD are we backward compatible with?
219  * This only applies to externally visible characteristics.
220  * Rev.Minor.Branch.Patch (2 digits each)
221  */
222 #define AMD_COMPAT      5000000 /* 5.0 */
223
224 /*
225  * Error to return if remote host is not available.
226  * Try, in order, "host down", "host unreachable", "invalid argument".
227  */
228 #ifdef EHOSTDOWN
229 # define AM_ERRNO_HOST_DOWN     EHOSTDOWN
230 # else /* not EHOSTDOWN */
231 # ifdef EHOSTUNREACH
232 #  define AM_ERRNO_HOST_DOWN    EHOSTUNREACH
233 # else /* not EHOSTUNREACH */
234 #  define AM_ERRNO_HOST_DOWN    EINVAL
235 # endif /* not EHOSTUNREACH */
236 #endif /* not EHOSTDOWN */
237
238
239 /**************************************************************************/
240 /*** STRUCTURES AND TYPEDEFS                                            ***/
241 /**************************************************************************/
242
243 /* some typedefs must come first */
244 typedef char *amq_string;
245 typedef struct mntfs mntfs;
246 typedef struct am_opts am_opts;
247 typedef struct am_ops am_ops;
248 typedef struct am_node am_node;
249 typedef struct _qelem qelem;
250 typedef struct mntlist mntlist;
251 typedef struct fserver fserver;
252
253 /*
254  * Linked list
255  * (the name 'struct qelem' conflicts with linux's unistd.h)
256  */
257 struct _qelem {
258   qelem *q_forw;
259   qelem *q_back;
260 };
261
262 /*
263  * Option tables
264  */
265 struct opt_tab {
266   char *opt;
267   int flag;
268 };
269
270 /*
271  * Server states
272  */
273 typedef enum {
274   Start,
275   Run,
276   Finishing,
277   Quit,
278   Done
279 } serv_state;
280
281 /*
282  * Options
283  */
284 struct am_opts {
285   char *fs_glob;                /* Smashed copy of global options */
286   char *fs_local;               /* Expanded copy of local options */
287   char *fs_mtab;                /* Mount table entry */
288   /* Other options ... */
289   char *opt_dev;
290   char *opt_delay;
291   char *opt_dir;
292   char *opt_fs;
293   char *opt_group;
294   char *opt_mount;
295   char *opt_opts;
296   char *opt_remopts;
297   char *opt_pref;
298   char *opt_autopref;
299   char *opt_cache;
300   char *opt_rfs;
301   char *opt_rhost;
302   char *opt_sublink;
303   char *opt_type;
304   char *opt_unmount;
305   char *opt_user;
306   char *opt_maptype;            /* map type: file, nis, hesiod, etc. */
307   char *opt_cachedir;           /* cache directory */
308   char *opt_addopts;            /* options to add to opt_opts */
309 };
310
311 /*
312  * List of mounted filesystems
313  */
314 struct mntfs {
315   qelem mf_q;                   /* List of mounted filesystems */
316   am_ops *mf_ops;               /* Operations on this mountpoint */
317   am_opts *mf_fo;               /* File opts */
318   char *mf_mount;               /* "/a/kiska/home/kiska" */
319   char *mf_info;                /* Mount info */
320   char *mf_auto;                /* Automount opts */
321   char *mf_mopts;               /* FS mount opts */
322   char *mf_remopts;             /* Remote FS mount opts */
323   fserver *mf_server;           /* File server */
324   int mf_flags;                 /* Flags MFF_* */
325   int mf_error;                 /* Error code from background mount */
326   int mf_refc;                  /* Number of references to this node */
327   int mf_cid;                   /* Callout id */
328   void (*mf_prfree) (voidp);    /* Free private space */
329   voidp mf_private;             /* Private - per-fs data */
330 };
331
332 /*
333  * File Handle
334  *
335  * This is interpreted by indexing the exported array
336  * by fhh_id.
337  *
338  * The whole structure is mapped onto a standard fhandle_t
339  * when transmitted.
340  */
341 struct am_fh {
342   int fhh_pid;                  /* process id */
343   int fhh_id;                   /* map id */
344   int fhh_gen;                  /* generation number */
345 };
346
347 /*
348  * Multi-protocol NFS file handle
349  */
350 union am_nfs_handle {
351                                 /* placeholder for V4 file handle */
352 #ifdef HAVE_FS_NFS3
353   struct mountres3      v3;     /* NFS version 3 handle */
354 #endif /* HAVE_FS_NFS3 */
355   struct fhstatus       v2;     /* NFS version 2 handle */
356 };
357 typedef union am_nfs_handle am_nfs_handle_t;
358
359 /*
360  * automounter vfs/vnode operations.
361  */
362 typedef char *(*vfs_match) (am_opts *);
363 typedef int (*vfs_init) (mntfs *);
364 typedef int (*vmount_fs) (am_node *);
365 typedef int (*vfmount_fs) (mntfs *);
366 typedef int (*vumount_fs) (am_node *);
367 typedef int (*vfumount_fs) (mntfs *);
368 typedef am_node *(*vlookuppn) (am_node *, char *, int *, int);
369 typedef int (*vreaddir) (am_node *, nfscookie, nfsdirlist *, nfsentry *, int);
370 typedef am_node *(*vreadlink) (am_node *, int *);
371 typedef void (*vmounted) (mntfs *);
372 typedef void (*vumounted) (am_node *);
373 typedef fserver *(*vffserver) (mntfs *);
374
375 struct am_ops {
376   char          *fs_type;       /* type of filesystems "nfsx" */
377   vfs_match     fs_match;       /* fxn: match */
378   vfs_init      fs_init;        /* fxn: initialization */
379   vmount_fs     mount_fs;       /* fxn: mount vnode */
380   vfmount_fs    fmount_fs;      /* fxn: mount VFS */
381   vumount_fs    umount_fs;      /* fxn: unmount vnode */
382   vfumount_fs   fumount_fs;     /* fxn: unmount VFS */
383   vlookuppn     lookuppn;       /* fxn: lookup path-name */
384   vreaddir      readdir;        /* fxn: read directory */
385   vreadlink     readlink;       /* fxn: read link */
386   vmounted      mounted;        /* fxn: after-mount extra actions */
387   vumounted     umounted;       /* fxn: after-umount extra actions */
388   vffserver     ffserver;       /* fxn: find a file server */
389   int           fs_flags;       /* filesystem flags FS_* */
390 };
391
392 typedef int (*task_fun) (voidp);
393 typedef void (*cb_fun) (int, int, voidp);
394 typedef void (*fwd_fun) P((voidp, int, struct sockaddr_in *,
395                            struct sockaddr_in *, voidp, int));
396
397 /*
398  * List of mount table entries
399  */
400 struct mntlist {
401   struct mntlist *mnext;
402   mntent_t *mnt;
403 };
404
405 /*
406  * Mount map
407  */
408 typedef struct mnt_map mnt_map;
409
410 /*
411  * Per-mountpoint statistics
412  */
413 struct am_stats {
414   time_t s_mtime;               /* Mount time */
415   u_short s_uid;                /* Uid of mounter */
416   int s_getattr;                /* Count of getattrs */
417   int s_lookup;                 /* Count of lookups */
418   int s_readdir;                /* Count of readdirs */
419   int s_readlink;               /* Count of readlinks */
420   int s_statfs;                 /* Count of statfs */
421 };
422 typedef struct am_stats am_stats;
423
424 /*
425  * System statistics
426  */
427 struct amd_stats {
428   int d_drops;                  /* Dropped requests */
429   int d_stale;                  /* Stale NFS handles */
430   int d_mok;                    /* Successful mounts */
431   int d_merr;                   /* Failed mounts */
432   int d_uerr;                   /* Failed unmounts */
433 };
434 extern struct amd_stats amd_stats;
435
436 /*
437  * List of fileservers
438  */
439 struct fserver {
440   qelem fs_q;                   /* List of fileservers */
441   int fs_refc;                  /* Number of references to this node */
442   char *fs_host;                /* Normalized hostname of server */
443   struct sockaddr_in *fs_ip;    /* Network address of server */
444   int fs_cid;                   /* Callout id */
445   int fs_pinger;                /* Ping (keepalive) interval */
446   int fs_flags;                 /* Flags */
447   char *fs_type;                /* File server type */
448   u_long fs_version;            /* NFS version of server (2, 3, etc.)*/
449   char *fs_proto;               /* NFS protocol of server (tcp, udp, etc.) */
450   voidp fs_private;             /* Private data */
451   void (*fs_prfree) (voidp);    /* Free private data */
452 };
453
454 /*
455  * Map of auto-mount points.
456  */
457 struct am_node {
458   int am_mapno;         /* Map number */
459   mntfs *am_mnt;        /* Mounted filesystem */
460   char *am_name;        /* "kiska": name of this node */
461   char *am_path;        /* "/home/kiska": path of this node's mount point */
462   char *am_link;        /* "/a/kiska/home/kiska/this/that": link to sub-dir */
463   am_node *am_parent;   /* Parent of this node */
464   am_node *am_ysib;     /* Younger sibling of this node */
465   am_node *am_osib;     /* Older sibling of this node */
466   am_node *am_child;    /* First child of this node */
467   nfsattrstat am_attr;  /* File attributes */
468 #define am_fattr        am_attr.ns_u.ns_attr_u
469   int am_flags;         /* Boolean flags AMF_* */
470   int am_error;         /* Specific mount error */
471   time_t am_ttl;        /* Time to live */
472   int am_timeo_w;       /* Wait interval */
473   int am_timeo;         /* Timeout interval */
474   u_int am_gen;         /* Generation number */
475   char *am_pref;        /* Mount info prefix */
476   am_stats am_stats;    /* Statistics gathering */
477   SVCXPRT *am_transp;   /* Info for quick reply */
478 };
479
480
481 /**************************************************************************/
482 /*** EXTERNALS                                                          ***/
483 /**************************************************************************/
484
485 /*
486  * Useful constants
487  */
488 extern char *mnttab_file_name;  /* Mount table */
489 extern char *cpu;               /* "CPU type" */
490 extern char *endian;            /* "big" */
491 extern char *hostdomain;        /* "southseas.nz" */
492 extern char copyright[];        /* Copyright info */
493 extern char hostd[];            /* "kiska.southseas.nz" */
494 extern char pid_fsname[];       /* kiska.southseas.nz:(pid%d) */
495 extern char version[];          /* Version info */
496
497 /*
498  * Global variables.
499  */
500 extern AUTH *nfs_auth;          /* Dummy authorization for remote servers */
501 extern FILE *logfp;             /* Log file */
502 extern am_node **exported_ap;   /* List of nodes */
503 extern am_node *root_node;      /* Node for "root" */
504 extern char *PrimNetName;       /* Name of primary connected network */
505 extern char *PrimNetNum;        /* Name of primary connected network */
506 extern char *SubsNetName;       /* Name of subsidiary connected network */
507 extern char *SubsNetNum;        /* Name of subsidiary connected network */
508
509 #if 0
510 extern char *progname;          /* "amd" */
511 #endif
512 extern void am_set_progname(char *pn);  /* "amd" */
513 extern const char * am_get_progname(void); /* "amd" */
514 extern void am_set_hostname(char *hn);
515 extern const char * am_get_hostname(void);
516 extern pid_t am_set_mypid(void);
517 extern pid_t am_mypid;
518
519 #if 0
520 extern char hostname[];         /* "kiska" */
521 extern pid_t mypid;             /* Current process id */
522 #endif
523
524 extern int first_free_map;      /* First free node */
525 extern int foreground;          /* Foreground process */
526 extern int immediate_abort;     /* Should close-down unmounts be retried */
527 extern int last_used_map;       /* Last map being used for mounts */
528 extern int orig_umask;          /* umask() on startup */
529 extern int task_notify_todo;    /* Task notifier needs running */
530 extern int xlog_level;          /* Logging level */
531 extern int xlog_level_init;
532 extern serv_state amd_state;    /* Should we go now */
533 extern struct in_addr myipaddr; /* (An) IP address of this host */
534 extern struct opt_tab xlog_opt[];
535 extern time_t clock_valid;      /* Clock needs recalculating */
536 extern time_t do_mapc_reload;   /* Flush & reload mount map cache */
537 extern time_t next_softclock;   /* Time to call softclock() */
538 extern u_short nfs_port;        /* Our NFS service port */
539
540 /*
541  * Global routines
542  */
543 extern CLIENT *get_mount_client(char *unused_host, struct sockaddr_in *sin, struct timeval *tv, int *sock, u_long mnt_version);
544 extern RETSIGTYPE sigchld(int);
545 extern SVCXPRT *nfsxprt;
546 extern am_node *efs_lookuppn(am_node *, char *, int *, int);
547 extern am_node *exported_ap_alloc(void);
548 extern am_node *fh_to_mp(am_nfs_fh *);
549 extern am_node *fh_to_mp3(am_nfs_fh *, int *, int);
550 extern am_node *find_mf(mntfs *);
551 extern am_node *next_map(int *);
552 extern am_node *root_ap(char *, int);
553 extern am_ops *ops_match(am_opts *, char *, char *, char *, char *, char *);
554 extern bool_t xdr_amq_string(XDR *xdrs, amq_string *objp);
555 extern bool_t xdr_dirpath(XDR *xdrs, dirpath *objp);
556 extern char **strsplit(char *, int, int);
557 extern char *expand_key(char *);
558 extern char *get_version_string(void);
559 extern char *inet_dquad(char *, u_long);
560 extern char *print_wires(void);
561 extern char *str3cat(char *, char *, char *, char *);
562 extern char *strealloc(char *, char *);
563 extern char *strip_selectors(char *, char *);
564 extern char *strnsave(const char *, int);
565 extern fserver *dup_srvr(fserver *);
566 extern int amu_close(int fd);
567 extern int background(void);
568 extern int bind_resv_port(int, u_short *);
569 extern int cmdoption(char *, struct opt_tab *, int *);
570 extern int compute_automounter_mount_flags(mntent_t *);
571 extern int compute_mount_flags(mntent_t *);
572 extern int efs_readdir(am_node *, nfscookie, nfsdirlist *, nfsentry *, int);
573 extern int eval_fs_opts(am_opts *, char *, char *, char *, char *, char *);
574 extern int fwd_init(void);
575 extern int fwd_packet(int, voidp, int, struct sockaddr_in *, struct sockaddr_in *, voidp, fwd_fun);
576 extern int get_amd_program_number(void);
577 extern int hasmntval(mntent_t *, char *);
578 extern int is_network_member(const char *net);
579 extern int islocalnet(u_long);
580 extern int make_nfs_auth(void);
581 extern int make_rpc_packet(char *, int, u_long, struct rpc_msg *, voidp, XDRPROC_T_TYPE, AUTH *);
582 extern int mapc_keyiter(mnt_map *, void(*)(char *, voidp), voidp);
583 extern int mapc_search(mnt_map *, char *, char **);
584 extern int mapc_type_exists(const char *type);
585 extern int mkdirs(char *, int);
586 extern int mount_auto_node(char *, voidp);
587 extern int mount_automounter(int);
588 extern int mount_exported(void);
589 extern int mount_fs(mntent_t *, int, caddr_t, int, MTYPE_TYPE, u_long, const char *, const char *);
590 extern int mount_node(am_node *);
591 extern int nfs_srvr_port(fserver *, u_short *, voidp);
592 extern int pickup_rpc_reply(voidp, int, voidp, XDRPROC_T_TYPE);
593 extern int root_keyiter(void(*)(char *, voidp), voidp);
594 extern int softclock(void);
595 extern int switch_option(char *);
596 extern int switch_to_logfile(char *logfile, int orig_umask);
597 extern int timeout(u_int, void (*fn)(voidp), voidp);
598 extern int valid_key(char *);
599 extern mnt_map *mapc_find(char *, char *, const char *);
600 extern mntfs *dup_mntfs(mntfs *);
601 extern mntfs *find_mntfs(am_ops *, am_opts *, char *, char *, char *, char *, char *);
602 extern mntfs *new_mntfs(void);
603 extern mntfs *realloc_mntfs(mntfs *, am_ops *, am_opts *, char *, char *, char *, char *, char *);
604 extern mntlist *read_mtab(char *, const char *);
605 extern struct sockaddr_in *amu_svc_getcaller(SVCXPRT *xprt);
606 extern time_t time(time_t *);
607 extern void am_mounted(am_node *);
608 extern void am_unmounted(am_node *);
609 extern void amq_program_1(struct svc_req *rqstp, SVCXPRT * transp);
610 extern void amu_get_myaddress(struct in_addr *iap);
611 extern void amu_release_controlling_tty(void);
612 extern void compute_automounter_nfs_args(nfs_args_t *nap, mntent_t *mntp);
613 extern void deslashify(char *);
614 extern void discard_mntlist(mntlist *mp);
615 extern void do_task_notify(void);
616 extern void flush_mntfs(void);
617 extern void flush_nfs_fhandle_cache(fserver *);
618 extern void forcibly_timeout_mp(am_node *);
619 extern void free_map(am_node *);
620 extern void free_mntfs(voidp);
621 extern void free_mntlist(mntlist *);
622 extern void free_opts(am_opts *);
623 extern void free_srvr(fserver *);
624 extern void fwd_reply(void);
625 extern void get_args(int argc, char *argv[]);
626 extern void getwire(char **name1, char **number1);
627 extern void going_down(int);
628 extern void host_normalize(char **);
629 extern void init_map(am_node *, char *);
630 extern void ins_que(qelem *, qelem *);
631 extern void insert_am(am_node *, am_node *);
632 extern void make_root_node(void);
633 extern void map_flush_srvr(fserver *);
634 extern void mapc_add_kv(mnt_map *, char *, char *);
635 extern void mapc_free(voidp);
636 extern void mapc_reload(void);
637 extern void mapc_showtypes(char *buf);
638 extern void mk_fattr(am_node *, nfsftype);
639 extern void mnt_free(mntent_t *);
640 extern void mp_to_fh(am_node *, am_nfs_fh *);
641 extern void new_ttl(am_node *);
642 extern void nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp);
643 extern void normalize_slash(char *);
644 extern void ops_showamfstypes(char *buf);
645 extern void ops_showfstypes(char *outbuf);
646 extern void plog(int, char *,...)
647      __attribute__ ((__format__ (__printf__, 2, 3)));
648 extern void rem_que(qelem *);
649 extern void reschedule_timeout_mp(void);
650 extern void restart(void);
651 extern void rmdirs(char *);
652 extern void rpc_msg_init(struct rpc_msg *, u_long, u_long, u_long);
653 extern void run_task(task_fun, voidp, cb_fun, voidp);
654 extern void sched_task(cb_fun, voidp, voidp);
655 extern void set_amd_program_number(int program);
656 extern void show_opts(int ch, struct opt_tab *);
657 extern void show_rcs_info(const char *, char *);
658 extern void srvrlog(fserver *, char *);
659 extern void timeout_mp(voidp);
660 extern void umount_exported(void);
661 extern void unregister_amq(void);
662 extern void untimeout(int);
663 extern void wakeup(voidp);
664 extern void wakeup_srvr(fserver *);
665 extern void wakeup_task(int, int, voidp);
666 extern voidp xmalloc(int);
667 extern voidp xrealloc(voidp, int);
668 extern voidp xzalloc(int);
669 extern u_long get_nfs_version(char *host, struct sockaddr_in *sin, u_long nfs_version, const char *proto);
670
671
672 #ifdef MOUNT_TABLE_ON_FILE
673 extern void rewrite_mtab(mntlist *, const char *);
674 extern void unlock_mntlist(void);
675 extern void write_mntent(mntent_t *, const char *);
676 #endif /* MOUNT_TABLE_ON_FILE */
677
678 #if defined(HAVE_SYSLOG_H) || defined(HAVE_SYS_SYSLOG_H)
679 extern int syslogging;
680 #endif /* defined(HAVE_SYSLOG_H) || defined(HAVE_SYS_SYSLOG_H) */
681
682 #ifdef HAVE_TRANSPORT_TYPE_TLI
683
684 extern void compute_nfs_args(nfs_args_t *nap, mntent_t *mntp, int genflags, struct netconfig *nfsncp, struct sockaddr_in *ip_addr, u_long nfs_version, char *nfs_proto, am_nfs_handle_t *fhp, char *host_name, char *fs_name);
685 extern int create_amq_service(int *udp_soAMQp, SVCXPRT **udp_amqpp, struct netconfig **udp_amqncpp, int *tcp_soAMQp, SVCXPRT **tcp_amqpp, struct netconfig **tcp_amqncpp);
686 extern int create_nfs_service(int *soNFSp, u_short *nfs_portp, SVCXPRT **nfs_xprtp, void (*dispatch_fxn)(struct svc_req *rqstp, SVCXPRT *transp));
687 extern int get_knetconfig(struct knetconfig **kncpp, struct netconfig *in_ncp, char *nc_protoname);
688 extern struct netconfig *nfsncp;
689 extern void free_knetconfig(struct knetconfig *kncp);
690
691 #else /* not HAVE_TRANSPORT_TYPE_TLI */
692
693 extern void compute_nfs_args(nfs_args_t *nap, mntent_t *mntp, int genflags, struct sockaddr_in *ip_addr, u_long nfs_version, char *nfs_proto, am_nfs_handle_t *fhp, char *host_name, char *fs_name);
694 extern enum clnt_stat pmap_ping(struct sockaddr_in *address);
695 extern int create_amq_service(int *udp_soAMQp, SVCXPRT **udp_amqpp, int *tcp_soAMQp, SVCXPRT **tcp_amqpp);
696 extern int create_nfs_service(int *soNFSp, u_short *nfs_portp, SVCXPRT **nfs_xprtp, void (*dispatch_fxn)(struct svc_req *rqstp, SVCXPRT *transp));
697
698 #endif /* not HAVE_TRANSPORT_TYPE_TLI */
699
700 #ifndef HAVE_FIELD_STRUCT_FHSTATUS_FHS_FH
701 # define fhs_fh  fhstatus_u.fhs_fhandle
702 #endif /* not HAVE_FIELD_STRUCT_FHSTATUS_FHS_FH */
703
704
705 /**************************************************************************/
706 /*** Generic file-system types, implemented as part of the native O/S.  ***/
707 /**************************************************************************/
708
709 /*
710  * Loopback File System
711  * Many systems can't support this, and in any case most of the
712  * functionality is available with Symlink FS.
713  */
714 #ifdef HAVE_FS_LOFS
715 extern am_ops lofs_ops;
716 #endif /* HAVE_FS_LOFS */
717
718 /*
719  * CD-ROM File System (CD-ROM)
720  * (HSFS: High Sierra F/S on some machines)
721  * Many systems can't support this, and in any case most of the
722  * functionality is available with program FS.
723  */
724 #ifdef HAVE_FS_CDFS
725 extern am_ops cdfs_ops;
726 #endif /* HAVE_FS_CDFS */
727
728 /*
729  * PC File System (MS-DOS)
730  * Many systems can't support this, and in any case most of the
731  * functionality is available with program FS.
732  */
733 #ifdef HAVE_FS_PCFS
734 extern am_ops pcfs_ops;
735 #endif /* HAVE_FS_PCFS */
736
737 /*
738  * Caching File System (Solaris)
739  */
740 #ifdef HAVE_FS_CACHEFS
741 extern am_ops cachefs_ops;
742 #endif /* HAVE_FS_CACHEFS */
743
744 /*
745  * Network File System
746  * Good, slow, NFS V.2.
747  */
748 #ifdef HAVE_FS_NFS
749 extern am_ops nfs_ops;          /* NFS */
750 extern fserver *find_nfs_srvr (mntfs *);
751 extern int nfs_fmount(mntfs *mf);
752 extern int nfs_fumount(mntfs *mf);
753 extern int nfs_init(mntfs *mf);
754 extern qelem nfs_srvr_list;
755 extern void nfs_umounted(am_node *mp);
756 #endif /* HAVE_FS_NFS */
757
758
759 /*
760  * Network File System: the new generation
761  * NFS V.3
762  */
763 #ifdef HAVE_FS_NFS3
764 # ifndef NFS_VERSION3
765 #  define NFS_VERSION3 ((u_int) 3)
766 # endif /* not NFS_VERSION3 */
767 #endif /* HAVE_FS_NFS3 */
768
769 /*
770  * Un*x File System
771  * Normal local disk file system.
772  */
773 #ifdef HAVE_FS_UFS
774 extern am_ops ufs_ops;          /* Un*x file system */
775 #endif /* HAVE_FS_UFS */
776
777
778 /**************************************************************************/
779 /*** Automounter file-system types, implemented by amd.                 ***/
780 /**************************************************************************/
781
782 /*
783  * Automount File System
784  */
785 #ifdef HAVE_AM_FS_AUTO
786 extern am_ops amfs_auto_ops;    /* Automount file system (this!) */
787 extern am_ops amfs_toplvl_ops;  /* Top-level automount file system */
788 extern am_ops amfs_root_ops;    /* Root file system */
789 extern qelem amfs_auto_srvr_list;
790 extern am_node *amfs_auto_lookuppn(am_node *mp, char *fname, int *error_return, int op);
791 extern am_node *next_nonerror_node(am_node *xp);
792 extern char *amfs_auto_match(am_opts *fo);
793 extern fserver *find_amfs_auto_srvr(mntfs *);
794 extern int amfs_auto_readdir(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, int count);
795 extern int amfs_auto_umount(am_node *mp);
796 extern int amfs_auto_fmount(am_node *mp);
797 extern int amfs_auto_fumount(am_node *mp);
798 #endif /* HAVE_AM_FS_AUTO */
799
800 /*
801  * Toplvl Automount File System
802  */
803 #ifdef HAVE_AM_FS_TOPLVL
804 extern am_ops amfs_toplvl_ops;  /* Toplvl Automount file system */
805 extern int amfs_toplvl_mount(am_node *mp);
806 extern int amfs_toplvl_umount(am_node *mp);
807 extern void amfs_toplvl_mounted(mntfs *mf);
808 #endif /* HAVE_AM_FS_TOPLVL */
809
810 /*
811  * Direct Automount File System
812  */
813 #ifdef HAVE_AM_FS_DIRECT
814 extern am_ops amfs_direct_ops;  /* Direct Automount file system (this too) */
815 #endif /* HAVE_AM_FS_DIRECT */
816
817 /*
818  * Error File System
819  */
820 #ifdef HAVE_AM_FS_ERROR
821 extern am_ops amfs_error_ops;   /* Error file system */
822 extern am_node *amfs_error_lookuppn(am_node *mp, char *fname, int *error_return, int op);
823 extern int amfs_error_readdir(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, int count);
824 #endif /* HAVE_AM_FS_ERROR */
825
826 /*
827  * Inheritance File System
828  */
829 #ifdef HAVE_AM_FS_INHERIT
830 extern am_ops amfs_inherit_ops; /* Inheritance file system */
831 #endif /* HAVE_AM_FS_INHERIT */
832
833 /*
834  * NFS mounts with local existence check.
835  */
836 #ifdef HAVE_AM_FS_NFSL
837 extern am_ops amfs_nfsl_ops;    /* NFSL */
838 #endif /* HAVE_AM_FS_NFSL */
839
840 /*
841  * Multi-nfs mounts.
842  */
843 #ifdef HAVE_AM_FS_NFSX
844 extern am_ops amfs_nfsx_ops;    /* NFSX */
845 #endif /* HAVE_AM_FS_NFSX */
846
847 /*
848  * NFS host - a whole tree.
849  */
850 #ifdef HAVE_AM_FS_HOST
851 extern am_ops amfs_host_ops;    /* NFS host */
852 #endif /* HAVE_AM_FS_HOST */
853
854 /*
855  * Program File System
856  * This is useful for things like RVD.
857  */
858 #ifdef HAVE_AM_FS_PROGRAM
859 extern am_ops amfs_program_ops; /* Program File System */
860 #endif /* HAVE_AM_FS_PROGRAM */
861
862 /*
863  * Symbolic-link file system.
864  * A "filesystem" which is just a symbol link.
865  */
866 #ifdef HAVE_AM_FS_LINK
867 extern am_ops amfs_link_ops;    /* Symlink FS */
868 extern int amfs_link_fmount(mntfs *mf);
869 #endif /* HAVE_AM_FS_LINK */
870
871 /*
872  * Symbolic-link file system, which also checks that the target of
873  * the symlink exists.
874  * A "filesystem" which is just a symbol link.
875  */
876 #ifdef HAVE_AM_FS_LINKX
877 extern am_ops amfs_linkx_ops;   /* Symlink FS with existence check */
878 #endif /* HAVE_AM_FS_LINKX */
879
880 /*
881  * Union file system
882  */
883 #ifdef HAVE_AM_FS_UNION
884 extern am_ops amfs_union_ops;   /* Union FS */
885 #endif /* HAVE_AM_FS_UNION */
886
887 /*
888  * Autofs file system
889  */
890 #ifdef HAVE_FS_AUTOFS
891 extern am_ops autofs_ops;       /* (Sun) Autofs FS */
892 #endif /* HAVE_FS_AUTOFS */
893
894
895 /**************************************************************************/
896 /*** DEBUGGING                                                          ***/
897 /**************************************************************************/
898
899 /*
900  * DEBUGGING:
901  */
902 #ifdef DEBUG
903
904 # define        D_ALL           (~0)
905 # define        D_DAEMON        0x0001  /* Enter daemon mode */
906 # define        D_TRACE         0x0002  /* Do protocol trace */
907 # define        D_FULL          0x0004  /* Do full trace */
908 # define        D_MTAB          0x0008  /* Use local mtab */
909 # define        D_AMQ           0x0010  /* Register amq program */
910 # define        D_STR           0x0020  /* Debug string munging */
911 #  ifdef DEBUG_MEM
912 # define        D_MEM           0x0040  /* Trace memory allocations */
913 #  endif /* DEBUG_MEM */
914 # define        D_FORK          0x0080  /* Fork server */
915                 /* info service specific debugging (hesiod, nis, etc) */
916 # define        D_INFO          0x0100
917
918 /*
919  * Normally, don't enter daemon mode, and don't register amq
920  */
921 #  ifdef DEBUG_MEM
922 # define        D_TEST  (~(D_DAEMON|D_MEM|D_STR))
923 #  else /* not DEBUG_MEM */
924 # define        D_TEST  (~(D_DAEMON|D_STR))
925 #  endif /* not DEBUG_MEM */
926
927 # define        amuDebug(x)     if (debug_flags & (x))
928 # define        dlog            amuDebug(D_FULL) dplog
929 # define        amuDebugNo(x)   if (!(debug_flags & (x)))
930
931 /* debugging mount-table file to use */
932 # ifndef DEBUG_MNTTAB
933 #  define       DEBUG_MNTTAB    "./mnttab"
934 # endif /* not DEBUG_MNTTAB */
935
936 # ifdef DEBUG_MEM
937 /*
938  * If debugging memory, then call a special freeing function that logs
939  * more info, and resets the pointer to NULL so it cannot be used again.
940  */
941 #  define       XFREE(x) dxfree(__FILE__,__LINE__,x)
942 extern void dxfree(char *file, int line, voidp ptr);
943 extern void malloc_verify(void);
944 # else /* not DEBUG_MEM */
945 /*
946  * If regular debugging, then free the pointer and reset to NULL.
947  * This should remain so for as long as am-utils is in alpha/beta testing.
948  */
949 #  define       XFREE(x) do { free((voidp)x); x = NULL;} while (0)
950 # endif /* not DEBUG_MEM */
951
952 /* functions that depend solely on debugging */
953 extern void print_nfs_args(const nfs_args_t *nap, u_long nfs_version);
954
955 #else /* not DEBUG */
956
957 /*
958  * if not debugging, then simple perform free, and don't bother
959  * resetting the pointer.
960  */
961 #  define       XFREE(x) free(x)
962
963 #endif /* not DEBUG */
964
965 extern int debug_flags;         /* Debug options */
966 extern int debug_option (char *opt);
967 extern struct opt_tab dbg_opt[];
968 extern void dplog(char *fmt, ...)
969      __attribute__ ((__format__ (__printf__, 1, 2)));
970
971 /**************************************************************************/
972 /*** MISC (stuff left to autoconfiscate)                                ***/
973 /**************************************************************************/
974
975 #endif /* not _AM_UTILS_H */