xref: /netbsd/external/bsd/am-utils/dist/amd/amd.h (revision 31bdb48a)
1 /*	$NetBSD: amd.h,v 1.1.1.3 2015/01/17 16:34:15 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 1997-2014 Erez Zadok
5  * Copyright (c) 1990 Jan-Simon Pendry
6  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7  * Copyright (c) 1990 The Regents of the University of California.
8  * All rights reserved.
9  *
10  * This code is derived from software contributed to Berkeley by
11  * Jan-Simon Pendry at Imperial College, London.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *
38  * File: am-utils/amd/amd.h
39  *
40  */
41 
42 #ifndef _AMD_H
43 #define _AMD_H
44 
45 
46 /*
47  * MACROS:
48  */
49 
50 /*
51  * Define a default debug mtab path for systems
52  * that support mtab on file.
53  */
54 #ifdef MOUNT_TABLE_ON_FILE
55 # define DEBUG_MNTTAB_FILE		"/tmp/mtab"
56 #endif /* MOUNT_TABLE_ON_FILE */
57 
58 /* Max line length that info services can handle */
59 #define INFO_MAX_LINE_LEN		1500
60 
61 /* options for amd.conf */
62 #define CFM_BROWSABLE_DIRS		0x00000001
63 #define CFM_MOUNT_TYPE_AUTOFS		0x00000002 /* use kernel autofs support */
64 #define CFM_SELECTORS_IN_DEFAULTS	0x00000004
65 #define CFM_NORMALIZE_HOSTNAMES		0x00000008
66 #define CFM_PROCESS_LOCK		0x00000010
67 #define CFM_PRINT_PID			0x00000020
68 #define CFM_RESTART_EXISTING_MOUNTS	0x00000040
69 #define CFM_SHOW_STATFS_ENTRIES		0x00000080
70 #define CFM_FULLY_QUALIFIED_HOSTS	0x00000100
71 #define CFM_BROWSABLE_DIRS_FULL		0x00000200 /* allow '/' in readdir() */
72 #define CFM_UNMOUNT_ON_EXIT		0x00000400 /* when amd finishing */
73 #define CFM_USE_TCPWRAPPERS		0x00000800
74 #define CFM_AUTOFS_USE_LOFS		0x00001000
75 #define CFM_NFS_INSECURE_PORT		0x00002000
76 #define CFM_DOMAIN_STRIP		0x00004000
77 #define CFM_NORMALIZE_SLASHES		0x00008000 /* normalize slashes? */
78 #define CFM_FORCED_UNMOUNTS		0x00010000 /* forced unmounts? */
79 #define CFM_TRUNCATE_LOG		0x00020000 /* truncate log file? */
80 #define CFM_SUN_MAP_SYNTAX		0x00040000 /* Sun map syntax? */
81 #define CFM_NFS_ANY_INTERFACE		0x00080000 /* all interfaces are acceptable */
82 
83 /* defaults global flags: plock, tcpwrappers, and autofs/lofs */
84 #define CFM_DEFAULT_FLAGS	(CFM_PROCESS_LOCK|CFM_USE_TCPWRAPPERS|CFM_AUTOFS_USE_LOFS|CFM_DOMAIN_STRIP|CFM_NORMALIZE_SLASHES)
85 
86 /*
87  * macro definitions for automounter vfs/vnode operations.
88  */
89 #define	VLOOK_CREATE	0x1
90 #define	VLOOK_DELETE	0x2
91 #define VLOOK_LOOKUP	0x3
92 
93 /*
94  * macro definitions for automounter vfs capabilities
95  */
96 #define FS_DIRECTORY	0x0001	/* This looks like a dir, not a link */
97 #define	FS_MBACKGROUND	0x0002	/* Should background this mount */
98 #define	FS_NOTIMEOUT	0x0004	/* Don't bother with timeouts */
99 #define FS_MKMNT	0x0008	/* Need to make the mount point */
100 #define FS_UBACKGROUND	0x0010	/* Unmount in background */
101 #define	FS_BACKGROUND	(FS_MBACKGROUND|FS_UBACKGROUND)
102 #define	FS_DISCARD	0x0020	/* Discard immediately on last reference */
103 #define	FS_AMQINFO	0x0040	/* Amq is interested in this fs type */
104 #define FS_AUTOFS	0x0080	/* This filesystem can be an autofs f/s */
105 #define FS_DIRECT	0x0100	/* Direct mount */
106 #define FS_ON_AUTOFS	0x0200	/* This filesystem can be mounted directly
107 				   onto an autofs mountpoint */
108 
109 /*
110  * macros for struct am_node (map of auto-mount points).
111  */
112 #define	AMF_NOTIMEOUT	0x0001	/* This node never times out */
113 #define	AMF_ROOT	0x0002	/* This is a root node */
114 #define AMF_AUTOFS	0x0004	/* This node is part of an autofs filesystem */
115 #define AMF_REMOUNT	0x0008	/* This node needs to be remounted */
116 #define AMF_SOFTLOOKUP	0x0010	/* This node returns EIO if server is down */
117 
118 /*
119  * macros for struct mntfs (list of mounted filesystems)
120  */
121 #define	MFF_MOUNTED	0x0001	/* Node is mounted */
122 #define	MFF_MOUNTING	0x0002	/* Mount is in progress */
123 #define	MFF_UNMOUNTING	0x0004	/* Unmount is in progress */
124 #define	MFF_RESTART	0x0008	/* Restarted node */
125 #define MFF_MKMNT	0x0010	/* Delete this node's am_mount */
126 #define	MFF_ERROR	0x0020	/* This node failed to mount */
127 #define	MFF_LOGDOWN	0x0040	/* Logged that this mount is down */
128 #define	MFF_RSTKEEP	0x0080	/* Don't timeout this filesystem - restarted */
129 #define	MFF_WANTTIMO	0x0100	/* Need a timeout call when not busy */
130 #define MFF_NFSLINK	0x0200	/* nfsl type, and deemed a link */
131 #define MFF_IS_AUTOFS	0x0400	/* this filesystem is of type autofs */
132 #define MFF_NFS_SCALEDOWN 0x0800 /* the mount failed, retry with v2/UDP */
133 #define MFF_ON_AUTOFS	0x1000	/* autofs has a lofs/link to this f/s */
134 #define MFF_WEBNFS	0x2000	/* use public filehandle */
135 
136 /*
137  * macros for struct fserver.
138  */
139 #define	FSF_VALID	0x0001	/* Valid information available */
140 #define	FSF_DOWN	0x0002	/* This fileserver is thought to be down */
141 #define	FSF_ERROR	0x0004	/* Permanent error has occurred */
142 #define	FSF_WANT	0x0008	/* Want a wakeup call */
143 #define	FSF_PINGING	0x0010	/* Already doing pings */
144 #define	FSF_WEBNFS	0x0020	/* Don't try to contact portmapper */
145 #define FSF_PING_UNINIT	0x0040	/* ping values have not been initilized */
146 #define FSF_FORCE_UNMOUNT 0x0080 /* force umount of this fserver */
147 #define	FSRV_ERROR(fs)	((fs) && (((fs)->fs_flags & FSF_ERROR) == FSF_ERROR))
148 #define	FSRV_ISDOWN(fs)	((fs) && (((fs)->fs_flags & (FSF_DOWN|FSF_VALID)) == (FSF_DOWN|FSF_VALID)))
149 #define	FSRV_ISUP(fs)	(!(fs) || (((fs)->fs_flags & (FSF_DOWN|FSF_VALID)) == (FSF_VALID)))
150 
151 /* some systems (SunOS 4.x) neglect to define the mount null message */
152 #ifndef MOUNTPROC_NULL
153 # define MOUNTPROC_NULL ((u_long)(0))
154 #endif /* not MOUNTPROC_NULL */
155 
156 /*
157  * Error to return if remote host is not available.
158  * Try, in order, "host down", "host unreachable", "invalid argument".
159  */
160 #ifdef EHOSTDOWN
161 # define AM_ERRNO_HOST_DOWN	EHOSTDOWN
162 #else /* not EHOSTDOWN */
163 # ifdef EHOSTUNREACH
164 #  define AM_ERRNO_HOST_DOWN	EHOSTUNREACH
165 # else /* not EHOSTUNREACH */
166 #  define AM_ERRNO_HOST_DOWN	EINVAL
167 # endif /* not EHOSTUNREACH */
168 #endif /* not EHOSTDOWN */
169 
170 /* Hash table size */
171 #define NKVHASH (1 << 2)        /* Power of two */
172 
173 /* Max entries to return in one call */
174 #define	MAX_READDIR_ENTRIES	16
175 
176 /*
177  * default amfs_auto retrans - 1/10th seconds
178  */
179 #define	AMFS_AUTO_RETRANS(x)	((ALLOWED_MOUNT_TIME*10+5*gopt.amfs_auto_timeo[(x)])/gopt.amfs_auto_timeo[(x)] * 2)
180 
181 /*
182  * The following values can be tuned...
183  */
184 #define	AM_TTL			(300) /* Default cache period (5 min) */
185 #define	AM_TTL_W		(120) /* Default unmount interval (2 min) */
186 #define	AM_PINGER		30 /* NFS ping interval for live systems */
187 #define	AMFS_AUTO_TIMEO		8 /* Default amfs_auto timeout - .8s */
188 #define AMFS_EXEC_MAP_TIMEOUT	10 /* default 10sec exec map timeout */
189 
190 /* interval between forced retries of a mount */
191 #define RETRY_INTERVAL	2
192 
193 #ifndef ROOT_MAP
194 # define ROOT_MAP "\"root\""
195 #endif /* not ROOT_MAP */
196 
197 #define ereturn(x) do { *error_return = x; return 0; } while (0)
198 
199 #define NEVER (time_t) 0
200 
201 #if defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP)
202 # define AMD_SERVICE_NAME "amd"	/* for tcpwrappers */
203 #endif /* defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP) */
204 
205 /*
206  * TYPEDEFS:
207  */
208 
209 typedef struct cf_map cf_map_t;
210 typedef struct kv kv;
211 typedef struct am_node am_node;
212 typedef struct mntfs mntfs;
213 typedef struct am_loc am_loc;
214 typedef struct am_opts am_opts;
215 typedef struct am_ops am_ops;
216 typedef struct am_stats am_stats;
217 typedef struct fserver fserver;
218 
219 typedef voidp wchan_t;
220 typedef voidp opaque_t;
221 
222 /*
223  * Cache map operations
224  */
225 typedef void add_fn(mnt_map *, char *, char *);
226 typedef int init_fn(mnt_map *, char *, time_t *);
227 typedef int mtime_fn(mnt_map *, char *, time_t *);
228 typedef int isup_fn(mnt_map *, char *);
229 typedef int reload_fn(mnt_map *, char *, add_fn *);
230 typedef int search_fn(mnt_map *, char *, char *, char **, time_t *);
231 typedef int task_fun(opaque_t);
232 typedef void cb_fun(int, int, opaque_t);
233 typedef void fwd_fun(voidp, int, struct sockaddr_in *,
234 		     struct sockaddr_in *, opaque_t, int);
235 typedef int key_fun(char *, opaque_t);
236 typedef void callout_fun(opaque_t);
237 
238 /*
239  * automounter vfs/vnode operations.
240  */
241 typedef char *(*vfs_match) (am_opts *);
242 typedef int (*vfs_init) (mntfs *);
243 typedef int (*vmount_fs) (am_node *, mntfs *);
244 typedef int (*vumount_fs) (am_node *, mntfs *);
245 typedef am_node *(*vlookup_child) (am_node *, char *, int *, int);
246 typedef am_node *(*vmount_child) (am_node *, int *);
247 typedef int (*vreaddir) (am_node *, voidp, voidp, voidp, u_int);
248 typedef am_node *(*vreadlink) (am_node *, int *);
249 typedef void (*vmounted) (mntfs *);
250 typedef void (*vumounted) (mntfs *);
251 typedef fserver *(*vffserver) (mntfs *);
252 typedef wchan_t (*vget_wchan) (mntfs *);
253 
254 /*
255  * NFS progran dispatcher
256  */
257 typedef void (*dispatcher_t)(struct svc_req *rqstp, SVCXPRT *transp);
258 
259 
260 /*
261  * STRUCTURES:
262  */
263 
264 /* global amd options that are manipulated by conf.c */
265 struct amu_global_options {
266   char *arch;			/* name of current architecture */
267   char *auto_dir;		/* automounter temp dir */
268   int auto_attrcache;		/* attribute cache timeout for auto dirs */
269   char *cluster;		/* cluster name */
270   char *karch;			/* kernel architecture */
271   char *logfile;		/* amd log file */
272   char *op_sys;			/* operating system name ${os} */
273   char *op_sys_ver;		/* OS version ${osver} */
274   char *op_sys_full;		/* full OS name ${full_os} */
275   char *op_sys_vendor;		/* name of OS vendor ${vendor} */
276   char *pid_file;		/* PID file */
277   char *sub_domain;		/* local domain */
278   char *localhost_address;	/* localhost address (NULL means use 127.0.0.1) */
279   char *map_defaults;		/* global map /default options */
280   char *map_options;		/* global map options */
281   int map_reload_interval;	/* map reload interval */
282   char *map_type;		/* global map type */
283   char *search_path;		/* search path for maps */
284   char *mount_type;		/* mount type for map */
285   char *debug_mtab_file;        /* path for the mtab file during debug mode */
286   u_int flags;			/* various CFM_* flags */
287 
288 #define AMU_TYPE_NONE -1	/* for amfs_auto_{timeo,retrans,toplvl} */
289 #define AMU_TYPE_UDP 0		/* for amfs_auto_{timeo,retrans,toplvl} */
290 #define AMU_TYPE_TCP 1		/* for amfs_auto_{timeo,retrans,toplvl} */
291   /*
292    * Note: toplvl is only UDP, but we want to separate it from regular
293    * NFS mounts which Amd makes, because the toplvl mount is a localhost
294    * mount for which different timeo/retrans parameters may be desired.
295    */
296 #define AMU_TYPE_TOPLVL 2	/* for amfs_auto_{timeo,retrans,toplvl} */
297 #define AMU_TYPE_MAX 3		/* for amfs_auto_{timeo,retrans,toplvl} */
298   int amfs_auto_retrans[AMU_TYPE_MAX]; /* NFS retransmit counter */
299   int amfs_auto_timeo[AMU_TYPE_MAX]; /* NFS retry interval */
300 
301   int am_timeo;			/* cache duration */
302   int am_timeo_w;		/* dismount interval */
303   u_long portmap_program;	/* amd RPC program number */
304   u_short preferred_amq_port;	/* preferred amq service RPC port number (0 means "any") */
305 #ifdef HAVE_MAP_HESIOD
306   char *hesiod_base;		/* Hesiod rhs */
307 #endif /* HAVE_MAP_HESIOD */
308 #ifdef HAVE_MAP_LDAP
309   char *ldap_base;		/* LDAP base */
310   char *ldap_hostports;		/* LDAP host ports */
311   long ldap_cache_seconds; 	/* LDAP internal cache - keep seconds */
312   long ldap_cache_maxmem;	/* LDAP internal cache - max memory (bytes) */
313   long ldap_proto_version;	/* LDAP protocol version */
314 #endif /* HAVE_MAP_LDAP */
315 #ifdef HAVE_MAP_NIS
316   char *nis_domain;		/* YP domain name */
317 #endif /* HAVE_MAP_NIS */
318   char *nfs_proto;		/* NFS protocol (NULL, udp, tcp) */
319   int nfs_vers;			/* NFS version (0, 2, 3, 4) */
320   int nfs_vers_ping;		/* NFS rpc ping version (0, 2, 3, 4) */
321   u_int exec_map_timeout;	/* timeout (seconds) for executable maps */
322 };
323 
324 /* if you add anything here, update conf.c:reset_cf_map() */
325 struct cf_map {
326   char *cfm_dir;		/* /home, /u, /src */
327   char *cfm_name;		/* amd.home, /etc/amd.home ... */
328   char *cfm_type;		/* file, hesiod, ndbm, nis ... */
329   char *cfm_defaults;		/* map /defaults options in amd.conf */
330   char *cfm_opts;		/* -cache:=all, etc. */
331   char *cfm_search_path;	/* /etc/local:/etc/amdmaps:/misc/yp */
332   char *cfm_tag;		/* optional map tag for amd -T */
333   u_int cfm_flags;		/* browsable_dirs? mount_type? */
334   struct cf_map *cfm_next;	/* pointer to next in list (if any) */
335 };
336 
337 /*
338  * Key-value pair
339  */
340 struct kv {
341   kv *next;
342   char *key;
343 #ifdef HAVE_REGEXEC
344   regex_t re;                   /* store the regexp from regcomp() */
345 #endif /* HAVE_REGEXEC */
346   char *val;
347 };
348 
349 struct mnt_map {
350   qelem hdr;
351   int refc;                     /* Reference count */
352   short flags;                  /* Allocation flags */
353   short alloc;                  /* Allocation mode */
354   time_t modify;                /* Modify time of map */
355   u_int reloads;		/* Number of times map was reloaded */
356   u_int nentries;		/* Number of entries in the map */
357   char *map_name;               /* Name of this map */
358   char *wildcard;               /* Wildcard value */
359   reload_fn *reload;            /* Function to be used for reloads */
360   isup_fn *isup;		/* Is service up or not? (1=up, 0=down) */
361   search_fn *search;            /* Function to be used for searching */
362   mtime_fn *mtime;              /* Modify time function */
363   kv *kvhash[NKVHASH];          /* Cached data */
364   cf_map_t *cfm;		/* pointer to per-map amd.conf opts, if any */
365   void *map_data;               /* Map data black box */
366 };
367 
368 /*
369  * Options
370  */
371 struct am_opts {
372   char *fs_glob;		/* Smashed copy of global options */
373   char *fs_local;		/* Expanded copy of local options */
374   char *fs_mtab;		/* Mount table entry */
375   /* Other options ... */
376   char *opt_dev;
377   char *opt_delay;
378   char *opt_dir;
379   char *opt_fs;
380   char *opt_group;
381   char *opt_mount;
382   char *opt_opts;
383   char *opt_remopts;
384   char *opt_pref;
385   char *opt_cache;
386   char *opt_rfs;
387   char *opt_rhost;
388   char *opt_sublink;
389   char *opt_type;
390   char *opt_mount_type;		/* "nfs" or "autofs" */
391   char *opt_unmount;
392   char *opt_umount;		/* an "alias" for opt_unmount (type:=program) */
393   char *opt_user;
394   char *opt_maptype;		/* map type: file, nis, hesiod, etc. */
395   char *opt_cachedir;		/* cache directory */
396   char *opt_addopts;		/* options to add to opt_opts */
397 };
398 
399 struct am_ops {
400   char		*fs_type;	/* type of filesystems e.g. "nfsx" */
401   vfs_match	fs_match;	/* fxn: match */
402   vfs_init	fs_init;	/* fxn: initialization */
403   vmount_fs	mount_fs;	/* fxn: mount my own vnode */
404   vumount_fs	umount_fs;	/* fxn: unmount my own vnode */
405   vlookup_child	lookup_child;	/* fxn: lookup path-name */
406   vmount_child	mount_child;	/* fxn: mount path-name */
407   vreaddir	readdir;	/* fxn: read directory */
408   vreadlink	readlink;	/* fxn: read link */
409   vmounted	mounted;	/* fxn: after-mount extra actions */
410   vumounted	umounted;	/* fxn: after-umount extra actions */
411   vffserver	ffserver;	/* fxn: find a file server */
412   vget_wchan	get_wchan;	/* fxn: get the waiting channel */
413   int		nfs_fs_flags;	/* filesystem flags FS_* for nfs mounts */
414 #ifdef HAVE_FS_AUTOFS
415   int		autofs_fs_flags;/* filesystem flags FS_* for autofs mounts */
416 #endif /* HAVE_FS_AUTOFS */
417 };
418 
419 /*
420  * List of mounted filesystems
421  */
422 struct mntfs {
423   qelem mf_q;			/* List of mounted filesystems */
424   am_ops *mf_ops;		/* Operations on this mountpoint */
425   am_opts *mf_fo;		/* File opts */
426   char *mf_mount;		/* "/a/kiska/home/kiska" */
427   char *mf_info;		/* Mount info */
428   char *mf_auto;		/* Mount info */
429   char *mf_mopts;		/* FS mount opts */
430   char *mf_remopts;		/* Remote FS mount opts */
431   char *mf_loopdev;		/* loop device name for /dev/loop mounts */
432   fserver *mf_server;		/* File server */
433   int mf_fsflags;		/* Flags FS_* copied from mf_ops->*_fs_flags */
434   int mf_flags;			/* Flags MFF_* */
435   int mf_error;			/* Error code from background mount */
436   int mf_refc;			/* Number of references to this node */
437   int mf_cid;			/* Callout id */
438   void (*mf_prfree) (opaque_t);	/* Free private space */
439   opaque_t mf_private;		/* Private - per-fs data */
440 };
441 
442 /*
443  * Locations: bindings between keys and mntfs
444  */
445 struct am_loc {
446   am_opts *al_fo;
447   mntfs *al_mnt;
448   int al_refc;
449 };
450 
451 
452 /*
453  * List of fileservers
454  */
455 struct fserver {
456   qelem fs_q;			/* List of fileservers */
457   int fs_refc;			/* Number of references to this server */
458   char *fs_host;		/* Normalized hostname of server */
459   struct sockaddr_in *fs_ip;	/* Network address of server */
460   int fs_cid;			/* Callout id */
461   int fs_pinger;		/* Ping (keepalive) interval */
462   int fs_flags;			/* Flags */
463   char *fs_type;		/* File server type */
464   u_long fs_version;		/* NFS version of server (2, 3, etc.)*/
465   char *fs_proto;		/* NFS protocol of server (tcp, udp, etc.) */
466   opaque_t fs_private;		/* Private data */
467   void (*fs_prfree) (opaque_t);	/* Free private data */
468 };
469 
470 /*
471  * Per-mountpoint statistics
472  */
473 struct am_stats {
474   time_t s_mtime;		/* Mount time */
475   u_short s_uid;		/* Uid of mounter */
476   int s_getattr;		/* Count of getattrs */
477   int s_lookup;			/* Count of lookups */
478   int s_readdir;		/* Count of readdirs */
479   int s_readlink;		/* Count of readlinks */
480   int s_statfs;			/* Count of statfs */
481   int s_fsinfo;			/* Count of fsinfo */
482   int s_pathconf;		/* Count of pathconf */
483 };
484 
485 /*
486  * System statistics
487  */
488 struct amd_stats {
489   int d_drops;			/* Dropped requests */
490   int d_stale;			/* Stale NFS handles */
491   int d_mok;			/* Successful mounts */
492   int d_merr;			/* Failed mounts */
493   int d_uerr;			/* Failed unmounts */
494 };
495 extern struct amd_stats amd_stats;
496 
497 /*
498  * Map of auto-mount points.
499  */
500 struct am_node {
501   int am_mapno;		/* Map number */
502   am_loc *am_al;	/* Mounted filesystem */
503   am_loc **am_alarray;	/* Filesystem sources to try to mount */
504   char *am_name;	/* "kiska": name of this node */
505   char *am_path;	/* "/home/kiska": path of this node's mount point */
506   char *am_link;	/* "/a/kiska/home/kiska/this/that": link to sub-dir */
507   am_node *am_parent;	/* Parent of this node */
508   am_node *am_ysib;	/* Younger sibling of this node */
509   am_node *am_osib;	/* Older sibling of this node */
510   am_node *am_child;	/* First child of this node */
511   nfsattrstat am_attr;	/* File attributes */
512 #define am_fattr	am_attr.ns_u.ns_attr_u
513   int am_flags;		/* Boolean flags AMF_* */
514   int am_error;		/* Specific mount error */
515   time_t am_ttl;	/* Time to live */
516   int am_timeo_w;	/* Dismount wait interval */
517   int am_timeo;		/* Cache timeout interval */
518   u_int am_gen;		/* Generation number */
519   char *am_pref;	/* Mount info prefix */
520   am_stats am_stats;	/* Statistics gathering */
521   SVCXPRT *am_transp;	/* Info for quick reply */
522   dev_t am_dev;		/* Device number */
523   dev_t am_rdev;	/* Remote/real device number */
524 #ifdef HAVE_FS_AUTOFS
525   autofs_fh_t *am_autofs_fh;
526   time_t am_autofs_ttl;	/* Time to expire autofs nodes */
527 #endif /* HAVE_FS_AUTOFS */
528   int am_fd[2];		/* parent child pipe fd's for sync umount */
529 };
530 
531 /*
532  * EXTERNALS:
533  */
534 
535 /*
536  * Amq server global functions
537  */
538 extern amq_mount_info_list *amqproc_getmntfs_1_svc(voidp argp, struct svc_req *rqstp);
539 extern amq_mount_stats *amqproc_stats_1_svc(voidp argp, struct svc_req *rqstp);
540 extern amq_mount_tree_list *amqproc_export_1_svc(voidp argp, struct svc_req *rqstp);
541 extern amq_mount_tree_p *amqproc_mnttree_1_svc(voidp argp, struct svc_req *rqstp);
542 extern amq_string *amqproc_getvers_1_svc(voidp argp, struct svc_req *rqstp);
543 extern amq_string *amqproc_pawd_1_svc(voidp argp, struct svc_req *rqstp);
544 extern int *amqproc_getpid_1_svc(voidp argp, struct svc_req *rqstp);
545 extern int *amqproc_mount_1_svc(voidp argp, struct svc_req *rqstp);
546 extern int *amqproc_setopt_1_svc(voidp argp, struct svc_req *rqstp);
547 extern voidp amqproc_null_1_svc(voidp argp, struct svc_req *rqstp);
548 extern int *amqproc_umnt_1_svc(voidp argp, struct svc_req *rqstp);
549 extern int *amqproc_sync_umnt_1_svc_parent(voidp argp, struct svc_req *rqstp);
550 extern amq_sync_umnt *amqproc_sync_umnt_1_svc_child(voidp argp, struct svc_req *rqstp);
551 extern amq_sync_umnt *amqproc_sync_umnt_1_svc_async(voidp argp, struct svc_req *rqstp);
552 extern amq_map_info_list *amqproc_getmapinfo_1_svc(voidp argp, struct svc_req *rqstp);
553 
554 /* other external definitions */
555 extern am_nfs_handle_t *get_root_nfs_fh(char *dir, am_nfs_handle_t *nfh);
556 extern am_node *find_ap(char *);
557 extern am_node *get_ap_child(am_node *, char *);
558 extern bool_t xdr_amq_mount_info_qelem(XDR *xdrs, qelem *qhead);
559 extern bool_t xdr_amq_map_info_qelem(XDR *xdrs, qelem *qhead);
560 extern fserver *find_nfs_srvr(mntfs *mf);
561 extern int mount_nfs_fh(am_nfs_handle_t *fhp, char *mntdir, char *fs_name, mntfs *mf);
562 extern int process_all_regular_maps(void);
563 extern cf_map_t *find_cf_map(const char *name);
564 extern int set_conf_kv(const char *section, const char *k, const char *v);
565 extern int mount_node(opaque_t arg);
566 extern int unmount_mp(am_node *mp);
567 extern int conf_parse(void);	/* "yyparse" renamed */
568 extern FILE *conf_in;		/* "yyin" renamed */
569 
570 extern void amfs_mkcacheref(mntfs *mf);
571 extern int amfs_mount(am_node *mp, mntfs *mf, char *opts);
572 extern void assign_error_mntfs(am_node *mp);
573 extern am_node *next_nonerror_node(am_node *xp);
574 extern void flush_srvr_nfs_cache(fserver *fs);
575 extern void am_mounted(am_node *);
576 extern void mf_mounted(mntfs *mf, bool_t call_free_opts);
577 extern void am_unmounted(am_node *);
578 extern am_node *get_exported_ap(int index);
579 extern am_node *get_first_exported_ap(int *index);
580 extern am_node *get_next_exported_ap(int *index);
581 extern am_node *path_to_exported_ap(char *path);
582 extern am_node *exported_ap_alloc(void);
583 extern am_node *find_mf(mntfs *);
584 extern am_node *next_map(int *);
585 extern am_ops *ops_match(am_opts *, char *, char *, char *, char *, char *);
586 extern am_ops *ops_search(char *);
587 extern fserver *dup_srvr(fserver *);
588 extern void srvrlog(fserver *, char *);
589 extern int get_mountd_port(fserver *, u_short *, wchan_t);
590 extern void flush_nfs_fhandle_cache(fserver *);
591 
592 extern mntfs *dup_mntfs(mntfs *);
593 extern am_loc *dup_loc(am_loc *);
594 extern mntfs *find_mntfs(am_ops *, am_opts *, char *, char *, char *, char *, char *);
595 extern mntfs *locate_mntfs(am_ops *, am_opts *, char *, char *, char *, char *, char *);
596 extern am_loc *new_loc(void);
597 extern mntfs *new_mntfs(void);
598 extern mntfs *realloc_mntfs(mntfs *, am_ops *, am_opts *, char *, char *, char *, char *, char *);
599 extern void flush_mntfs(void);
600 extern void free_mntfs(voidp);
601 extern void free_loc(voidp);
602 
603 
604 extern void amq_program_1(struct svc_req *rqstp, SVCXPRT *transp);
605 extern int  background(void);
606 extern void deslashify(char *);
607 extern void do_task_notify(void);
608 extern int  eval_fs_opts(am_opts *, char *, char *, char *, char *, char *);
609 extern int  file_read_line(char *, int, FILE *);
610 extern void forcibly_timeout_mp(am_node *);
611 extern void free_map(am_node *);
612 extern void free_opts(am_opts *);
613 extern am_opts *copy_opts(am_opts *);
614 extern void free_srvr(fserver *);
615 extern int  fwd_init(void);
616 extern int  fwd_packet(int, char *, int, struct sockaddr_in *, struct sockaddr_in *, opaque_t, fwd_fun *);
617 extern void fwd_reply(void);
618 extern void get_args(int argc, char *argv[]);
619 extern wchan_t get_mntfs_wchan(mntfs *mf);
620 extern void host_normalize(char **);
621 extern void init_map(am_node *, char *);
622 extern void ins_que(qelem *, qelem *);
623 extern void insert_am(am_node *, am_node *);
624 extern int  make_nfs_auth(void);
625 extern void make_root_node(void);
626 extern void map_flush_srvr(fserver *);
627 extern void mapc_add_kv(mnt_map *, char *, char *);
628 extern mnt_map *mapc_find(char *, char *, const char *, const char *);
629 extern void mapc_free(opaque_t);
630 extern int  mapc_keyiter(mnt_map *, key_fun, opaque_t);
631 extern void mapc_reload(void);
632 extern int  mapc_search(mnt_map *, char *, char **);
633 extern void mapc_showtypes(char *buf, size_t l);
634 extern int  mapc_type_exists(const char *type);
635 extern void mk_fattr(nfsfattr *, nfsftype);
636 extern int  mount_auto_node(char *, opaque_t);
637 extern int  mount_automounter(int);
638 extern int  mount_exported(void);
639 extern void mp_to_fh(am_node *, am_nfs_fh *);
640 extern void mp_to_fh3(am_node *mp, am_nfs_fh3 *fhp);
641 extern void new_ttl(am_node *);
642 extern void nfs_quick_reply(am_node *mp, int error);
643 extern void normalize_slash(char *);
644 extern void notify_child(am_node *, au_etype, int, int);
645 extern void ops_showamfstypes(char *buf, size_t l);
646 extern void ops_showfstypes(char *outbuf, size_t l);
647 extern void rem_que(qelem *);
648 extern void reschedule_timeout_mp(void);
649 extern void restart(void);
650 extern void restart_automounter_nodes(void);
651 extern int  root_keyiter(key_fun *, opaque_t);
652 extern void root_newmap(const char *, const char *, const char *, const cf_map_t *);
653 extern void run_task(task_fun *, opaque_t, cb_fun *, opaque_t);
654 extern void sched_task(cb_fun *, opaque_t, wchan_t);
655 extern int  softclock(void);
656 extern int  timeout(u_int, void (*fn)(opaque_t), opaque_t);
657 extern void timeout_mp(opaque_t);
658 extern void untimeout(int);
659 extern void umount_exported(void);
660 extern int  valid_key(char *);
661 extern void wakeup(wchan_t);
662 extern void wakeup_srvr(fserver *);
663 extern void wakeup_task(int, int, wchan_t);
664 #define SIZEOF_PID_FSNAME	(16 + MAXHOSTNAMELEN)
665 extern char pid_fsname[SIZEOF_PID_FSNAME]; /* "kiska.southseas.nz:(pid%d)" */
666 #define SIZEOF_HOSTD (2 * MAXHOSTNAMELEN + 1)
667 extern char hostd[SIZEOF_HOSTD]; /* Host+domain */
668 #define SIZEOF_OPTS 256		/* used for char opts[] and preopts[] */
669 
670 /*
671  * Global variables.
672  */
673 extern SVCXPRT *current_transp; /* For nfs_quick_reply() */
674 extern dispatcher_t nfs_dispatcher;
675 extern char *conf_tag;
676 #define SIZEOF_UID_STR	12
677 #define SIZEOF_GID_STR	12
678 extern char *opt_gid, gid_str[SIZEOF_GID_STR];
679 extern char *opt_uid, uid_str[SIZEOF_UID_STR];
680 extern int NumChildren;
681 extern int fwd_sock;
682 extern int select_intr_valid;
683 extern int immediate_abort;	/* Should close-down unmounts be retried */
684 extern int usage;
685 extern int use_conf_file;	/* use amd configuration file */
686 extern int task_notify_todo;	/* Task notifier needs running */
687 extern jmp_buf select_intr;
688 extern qelem mfhead;
689 extern struct amu_global_options gopt; /* where global options are stored */
690 extern time_t do_mapc_reload;	/* Flush & reload mount map cache */
691 extern time_t next_softclock;	/* Time to call softclock() */
692 
693 #ifdef HAVE_SIGACTION
694 extern sigset_t masked_sigs;
695 #endif /* HAVE_SIGACTION */
696 
697 #if defined(HAVE_AMU_FS_LINK) || defined(HAVE_AMU_FS_LINKX)
698 extern char *amfs_link_match(am_opts *fo);
699 #endif /* defined(HAVE_AMU_FS_LINK) || defined(HAVE_AMU_FS_LINKX) */
700 
701 #ifdef HAVE_FS_AUTOFS
702 extern int amd_use_autofs;
703 
704 extern int autofs_get_fh(am_node *mp);
705 extern void autofs_release_fh(am_node *mp);
706 extern void autofs_get_mp(am_node *mp);
707 extern void autofs_release_mp(am_node *mp);
708 extern void autofs_add_fdset(fd_set *readfds);
709 extern int autofs_handle_fdset(fd_set *readfds, int nsel);
710 extern void autofs_mounted(am_node *mp);
711 extern void autofs_mount_succeeded(am_node *mp);
712 extern void autofs_mount_failed(am_node *mp);
713 extern int autofs_umount_succeeded(am_node *mp);
714 extern int autofs_umount_failed(am_node *mp);
715 extern int autofs_mount_fs(am_node *mp, mntfs *mf);
716 extern int autofs_umount_fs(am_node *mp, mntfs *mf);
717 extern void autofs_get_opts(char *opts, size_t l, autofs_fh_t *fh);
718 extern int autofs_compute_mount_flags(mntent_t *);
719 extern void autofs_timeout_mp(am_node *);
720 extern int create_autofs_service(void);
721 extern int destroy_autofs_service(void);
722 #endif /* HAVE_FS_AUTOFS */
723 
724 /**************************************************************************/
725 /*** Generic file-system types, implemented as part of the native O/S.	***/
726 /**************************************************************************/
727 
728 /*
729  * Loopback File System
730  * Many systems can't support this, and in any case most of the
731  * functionality is available with Symlink FS.
732  */
733 #ifdef HAVE_FS_LOFS
734 extern am_ops lofs_ops;
735 extern int mount_lofs(char *mntdir, char *fs_name, char *opts, int on_autofs);
736 #endif /* HAVE_FS_LOFS */
737 
738 /*
739  * CD-ROM File System (CD-ROM)
740  * (HSFS: High Sierra F/S on some machines)
741  * Many systems can't support this, and in any case most of the
742  * functionality is available with program FS.
743  */
744 #ifdef HAVE_FS_CDFS
745 extern am_ops cdfs_ops;
746 #endif /* HAVE_FS_CDFS */
747 
748 /*
749  * PC File System (MS-DOS)
750  * Many systems can't support this, and in any case most of the
751  * functionality is available with program FS.
752  */
753 #ifdef HAVE_FS_PCFS
754 extern am_ops pcfs_ops;
755 #endif /* HAVE_FS_PCFS */
756 
757 /*
758  * UDF File System
759  * Many systems can't support this, and in any case most of the
760  * functionality is available with program FS.
761  */
762 #ifdef HAVE_FS_UDF
763 extern am_ops udf_ops;
764 #endif /* HAVE_FS_UDF */
765 
766 #ifdef HAVE_FS_LUSTRE
767 extern am_ops lustre_ops;
768 #endif /* HAVE_FS_LUSTRE */
769 
770 /*
771  * Caching File System (Solaris)
772  */
773 #ifdef HAVE_FS_CACHEFS
774 extern am_ops cachefs_ops;
775 #endif /* HAVE_FS_CACHEFS */
776 
777 /*
778  * In memory /tmp filesystem (Linux, NetBSD)
779  */
780 #ifdef HAVE_FS_TMPFS
781 extern am_ops tmpfs_ops;
782 #endif /* HAVE_FS_TMPFS */
783 /*
784  * Network File System
785  * Good, slow, NFS V.2.
786  */
787 #ifdef HAVE_FS_NFS
788 extern am_ops nfs_ops;		/* NFS */
789 extern fserver *find_nfs_srvr (mntfs *);
790 extern qelem nfs_srvr_list;
791 #endif /* HAVE_FS_NFS */
792 
793 /*
794  * Un*x File System
795  * Normal local disk file system.
796  */
797 #ifdef HAVE_FS_UFS
798 extern am_ops ufs_ops;		/* Un*x file system */
799 #endif /* HAVE_FS_UFS */
800 
801 /* Unix file system (irix) */
802 #ifdef HAVE_FS_XFS
803 extern am_ops xfs_ops;		/* Un*x file system */
804 #endif /* HAVE_FS_XFS */
805 
806 /* Unix file system (ext*) */
807 #ifdef HAVE_FS_EXT
808 extern am_ops ext2_ops;		/* Un*x file system */
809 extern am_ops ext3_ops;		/* Un*x file system */
810 extern am_ops ext4_ops;		/* Un*x file system */
811 #endif /* HAVE_FS_EXT */
812 
813 /* Unix file system (irix) */
814 #ifdef HAVE_FS_EFS
815 extern am_ops efs_ops;		/* Un*x file system */
816 #endif /* HAVE_FS_EFS */
817 
818 /**************************************************************************/
819 /*** Automounter file-system types, implemented by amd.			***/
820 /**************************************************************************/
821 
822 /*
823  * Root AMD File System
824  */
825 extern am_ops amfs_root_ops;	/* Root file system */
826 
827 /*
828  * Generic amfs helper methods
829  */
830 extern am_node *amfs_generic_lookup_child(am_node *mp, char *fname, int *error_return, int op);
831 extern am_node *amfs_generic_mount_child(am_node *ap, int *error_return);
832 extern int amfs_generic_readdir(am_node *mp, voidp cookie, voidp dp, voidp ep, u_int count);
833 extern int amfs_generic_umount(am_node *mp, mntfs *mf);
834 extern void amfs_generic_mounted(mntfs *mf);
835 extern char *amfs_generic_match(am_opts *fo);
836 extern fserver *amfs_generic_find_srvr(mntfs *);
837 
838 /*
839  * Automount File System
840  */
841 #ifdef HAVE_AMU_FS_AUTO
842 extern am_ops amfs_auto_ops;	/* Automount file system (this!) */
843 #endif /* HAVE_AMU_FS_AUTO */
844 
845 /*
846  * Toplvl Automount File System
847  */
848 #ifdef HAVE_AMU_FS_TOPLVL
849 extern am_ops amfs_toplvl_ops;	/* Toplvl Automount file system */
850 extern int amfs_toplvl_mount(am_node *mp, mntfs *mf);
851 extern int amfs_toplvl_umount(am_node *mp, mntfs *mf);
852 #endif /* HAVE_AMU_FS_TOPLVL */
853 
854 /*
855  * Direct Automount File System
856  */
857 #ifdef HAVE_AMU_FS_DIRECT
858 extern am_ops amfs_direct_ops;	/* Direct Automount file system (this too) */
859 #endif /* HAVE_AMU_FS_DIRECT */
860 
861 /*
862  * Error File System
863  */
864 #ifdef HAVE_AMU_FS_ERROR
865 extern am_ops amfs_error_ops;	/* Error file system */
866 extern am_node *amfs_error_lookup_child(am_node *mp, char *fname, int *error_return, int op);
867 extern am_node *amfs_error_mount_child(am_node *ap, int *error_return);
868 extern int amfs_error_readdir(am_node *mp, voidp cookie, voidp dp, voidp ep, u_int count);
869 
870 #endif /* HAVE_AMU_FS_ERROR */
871 
872 /*
873  * NFS mounts with local existence check.
874  */
875 #ifdef HAVE_AMU_FS_NFSL
876 extern am_ops amfs_nfsl_ops;	/* NFSL */
877 #endif /* HAVE_AMU_FS_NFSL */
878 
879 /*
880  * Multi-nfs mounts.
881  */
882 #ifdef HAVE_AMU_FS_NFSX
883 extern am_ops amfs_nfsx_ops;	/* NFSX */
884 #endif /* HAVE_AMU_FS_NFSX */
885 
886 /*
887  * NFS host - a whole tree.
888  */
889 #ifdef HAVE_AMU_FS_HOST
890 extern am_ops amfs_host_ops;	/* NFS host */
891 #endif /* HAVE_AMU_FS_HOST */
892 
893 /*
894  * Program File System
895  * This is useful for things like RVD.
896  */
897 #ifdef HAVE_AMU_FS_PROGRAM
898 extern am_ops amfs_program_ops;	/* Program File System */
899 #endif /* HAVE_AMU_FS_PROGRAM */
900 
901 /*
902  * Symbolic-link file system.
903  * A "filesystem" which is just a symbol link.
904  */
905 #ifdef HAVE_AMU_FS_LINK
906 extern am_ops amfs_link_ops;	/* Symlink FS */
907 #endif /* HAVE_AMU_FS_LINK */
908 
909 /*
910  * Symbolic-link file system, which also checks that the target of
911  * the symlink exists.
912  * A "filesystem" which is just a symbol link.
913  */
914 #ifdef HAVE_AMU_FS_LINKX
915 extern am_ops amfs_linkx_ops;	/* Symlink FS with existence check */
916 #endif /* HAVE_AMU_FS_LINKX */
917 
918 /*
919  * Union file system
920  */
921 #ifdef HAVE_AMU_FS_UNION
922 extern am_ops amfs_union_ops;	/* Union FS */
923 #endif /* HAVE_AMU_FS_UNION */
924 
925 #endif /* not _AMD_H */
926