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