2 * Copyright (c) 1997-2004 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.
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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
41 * $Id: am_utils.h,v 1.11.2.13 2004/01/06 03:15:24 ezk Exp $
46 * Definitions that are specific to the am-utils package.
53 /**************************************************************************/
55 /**************************************************************************/
62 #endif /* not FALSE */
67 # define MAX(a, b) ((a) > (b) ? (a) : (b))
70 # define MIN(a, b) ((a) < (b) ? (a) : (b))
73 #define ONE_HOUR (60 * 60) /* One hour in seconds */
75 #ifndef MAXHOSTNAMELEN
77 # define MAXHOSTNAMELEN HOSTNAMESZ
78 # else /* not HOSTNAMESZ */
79 # define MAXHOSTNAMELEN 256
80 # endif /* not HOSTNAMESZ */
81 #endif /* not MAXHOSTNAMELEN */
84 * for hlfsd, and amd for detecting uid/gid
87 /* this is also defined in include/am_utils.h */
88 # define INVALIDID (((unsigned short) ~0) - 3)
89 #endif /* not INVALIDID */
92 * String comparison macros
94 #define STREQ(s1, s2) (strcmp((s1), (s2)) == 0)
95 #define STRCEQ(s1, s2) (strcasecmp((s1), (s2)) == 0)
96 #define NSTREQ(s1, s2, n) (strncmp((s1), (s2), (n)) == 0)
97 #define NSTRCEQ(s1, s2, n) (strncasecmp((s1), (s2), (n)) == 0)
98 #define FSTREQ(s1, s2) ((*(s1) == *(s2)) && STREQ((s1),(s2)))
101 * Logging options/flags
103 #define XLOG_FATAL 0x0001
104 #define XLOG_ERROR 0x0002
105 #define XLOG_USER 0x0004
106 #define XLOG_WARNING 0x0008
107 #define XLOG_INFO 0x0010
108 #define XLOG_DEBUG 0x0020
109 #define XLOG_MAP 0x0040
110 #define XLOG_STATS 0x0080
111 #define XLOG_DEFSTR "all,nomap,nostats" /* Default log options */
112 #define XLOG_ALL (XLOG_FATAL|XLOG_ERROR|XLOG_USER|XLOG_WARNING|XLOG_INFO|XLOG_MAP|XLOG_STATS)
114 #define clocktime() (clock_valid ? clock_valid : time(&clock_valid))
117 # define ROOT_MAP "\"root\""
118 #endif /* not ROOT_MAP */
120 #define NO_SUBNET "notknown" /* default subnet name for no subnet */
121 #define NEXP_AP (1022) /* gdmr: was 254 */
122 #define NEXP_AP_MARGIN (128)
123 #define MAX_READDIR_ENTRIES 16
128 #define AM_FIRST(ty, q) ((ty *) ((q)->q_forw))
129 #define AM_LAST(ty, q) ((ty *) ((q)->q_back))
130 #define NEXT(ty, q) ((ty *) (((qelem *) q)->q_forw))
131 #define PREV(ty, q) ((ty *) (((qelem *) q)->q_back))
132 #define HEAD(ty, q) ((ty *) q)
133 #define ITER(v, ty, q) \
134 for ((v) = AM_FIRST(ty,(q)); (v) != HEAD(ty,(q)); (v) = NEXT(ty,(v)))
136 /* allocate anything of type ty */
137 #define ALLOC(ty) ((ty *) xmalloc(sizeof(ty)))
138 #define CALLOC(ty) ((ty *) xcalloc(1, sizeof(ty)))
139 /* simply allocate b bytes */
140 #define SALLOC(b) xmalloc((b))
142 /* converting am-filehandles to mount-points */
143 #define fh_to_mp2(fhp, rp) fh_to_mp3(fhp, rp, VLOOK_CREATE)
146 * Systems which have the mount table in a file need to read it before
147 * they can perform an unmount() system call.
149 #define UMOUNT_FS(dir, mtb_name) umount_fs(dir, mtb_name)
150 /* imported via $srcdir/conf/umount/umount_*.c */
151 extern int umount_fs(char *fs_name, const char *mnttabname);
154 * macros for automounter vfs/vnode operations.
156 #define VLOOK_CREATE 0x1
157 #define VLOOK_DELETE 0x2
158 #define FS_DIRECTORY 0x0001 /* This looks like a dir, not a link */
159 #define FS_MBACKGROUND 0x0002 /* Should background this mount */
160 #define FS_NOTIMEOUT 0x0004 /* Don't bother with timeouts */
161 #define FS_MKMNT 0x0008 /* Need to make the mount point */
162 #define FS_UBACKGROUND 0x0010 /* Unmount in background */
163 #define FS_BACKGROUND (FS_MBACKGROUND|FS_UBACKGROUND)
164 #define FS_DISCARD 0x0020 /* Discard immediately on last reference */
165 #define FS_AMQINFO 0x0040 /* Amq is interested in this fs type */
168 * macros for struct fserver.
170 #define FSF_VALID 0x0001 /* Valid information available */
171 #define FSF_DOWN 0x0002 /* This fileserver is thought to be down */
172 #define FSF_ERROR 0x0004 /* Permanent error has occurred */
173 #define FSF_WANT 0x0008 /* Want a wakeup call */
174 #define FSF_PINGING 0x0010 /* Already doing pings */
175 #define FSRV_ISDOWN(fs) (((fs)->fs_flags & (FSF_DOWN|FSF_VALID)) == (FSF_DOWN|FSF_VALID))
176 #define FSRV_ISUP(fs) (((fs)->fs_flags & (FSF_DOWN|FSF_VALID)) == (FSF_VALID))
179 * macros for struct mntfs (list of mounted filesystems)
181 #define MFF_MOUNTED 0x0001 /* Node is mounted */
182 #define MFF_MOUNTING 0x0002 /* Mount is in progress */
183 #define MFF_UNMOUNTING 0x0004 /* Unmount is in progress */
184 #define MFF_RESTART 0x0008 /* Restarted node */
185 #define MFF_MKMNT 0x0010 /* Delete this node's am_mount */
186 #define MFF_ERROR 0x0020 /* This node failed to mount */
187 #define MFF_LOGDOWN 0x0040 /* Logged that this mount is down */
188 #define MFF_RSTKEEP 0x0080 /* Don't timeout this filesystem - restarted */
189 #define MFF_WANTTIMO 0x0100 /* Need a timeout call when not busy */
190 #ifdef HAVE_AMU_FS_NFSL
191 # define MFF_NFSLINK 0x0200 /* nfsl type, and deemed a link */
192 #endif /* HAVE_AMU_FS_NFSL */
195 * macros for struct am_node (map of auto-mount points).
197 #define AMF_NOTIMEOUT 0x0001 /* This node never times out */
198 #define AMF_ROOT 0x0002 /* This is a root node */
199 #define AMF_AUTOFS 0x0004 /* This node is of type autofs -- not yet supported */
202 * The following values can be tuned...
204 #define ALLOWED_MOUNT_TIME 40 /* 40s for a mount */
205 #define AM_TTL (5 * 60) /* Default cache period */
206 #define AM_TTL_W (2 * 60) /* Default unmount interval */
207 #define AM_PINGER 30 /* NFS ping interval for live systems */
208 #define AMFS_AUTO_TIMEO 8 /* Default amfs_auto timeout - .8s */
211 * default amfs_auto retrans - 1/10th seconds
213 #define AMFS_AUTO_RETRANS ((ALLOWED_MOUNT_TIME*10+5*gopt.amfs_auto_timeo)/gopt.amfs_auto_timeo * 2)
216 * RPC-related macros.
218 #define RPC_XID_PORTMAP 0
219 #define RPC_XID_MOUNTD 1
220 #define RPC_XID_NFSPING 2
221 #define RPC_XID_MASK (0x0f) /* 16 id's for now */
222 #define MK_RPC_XID(type_id, uniq) ((type_id) | ((uniq) << 4))
225 * What level of AMD are we backward compatible with?
226 * This only applies to externally visible characteristics.
227 * Rev.Minor.Branch.Patch (2 digits each)
229 #define AMD_COMPAT 5000000 /* 5.0 */
232 * Error to return if remote host is not available.
233 * Try, in order, "host down", "host unreachable", "invalid argument".
236 # define AM_ERRNO_HOST_DOWN EHOSTDOWN
237 # else /* not EHOSTDOWN */
239 # define AM_ERRNO_HOST_DOWN EHOSTUNREACH
240 # else /* not EHOSTUNREACH */
241 # define AM_ERRNO_HOST_DOWN EINVAL
242 # endif /* not EHOSTUNREACH */
243 #endif /* not EHOSTDOWN */
246 /**************************************************************************/
247 /*** STRUCTURES AND TYPEDEFS ***/
248 /**************************************************************************/
250 /* some typedefs must come first */
251 typedef char *amq_string;
252 typedef struct mntfs mntfs;
253 typedef struct am_opts am_opts;
254 typedef struct am_ops am_ops;
255 typedef struct am_node am_node;
256 typedef struct _qelem qelem;
257 typedef struct mntlist mntlist;
258 typedef struct fserver fserver;
262 * (the name 'struct qelem' conflicts with linux's unistd.h)
292 char *fs_glob; /* Smashed copy of global options */
293 char *fs_local; /* Expanded copy of local options */
294 char *fs_mtab; /* Mount table entry */
295 /* Other options ... */
312 char *opt_maptype; /* map type: file, nis, hesiod, etc. */
313 char *opt_cachedir; /* cache directory */
314 char *opt_addopts; /* options to add to opt_opts */
318 * List of mounted filesystems
321 qelem mf_q; /* List of mounted filesystems */
322 am_ops *mf_ops; /* Operations on this mountpoint */
323 am_opts *mf_fo; /* File opts */
324 char *mf_mount; /* "/a/kiska/home/kiska" */
325 char *mf_info; /* Mount info */
326 char *mf_auto; /* Automount opts */
327 char *mf_mopts; /* FS mount opts */
328 char *mf_remopts; /* Remote FS mount opts */
329 fserver *mf_server; /* File server */
330 int mf_flags; /* Flags MFF_* */
331 int mf_error; /* Error code from background mount */
332 int mf_refc; /* Number of references to this node */
333 int mf_cid; /* Callout id */
334 void (*mf_prfree) (voidp); /* Free private space */
335 voidp mf_private; /* Private - per-fs data */
341 * This is interpreted by indexing the exported array
344 * The whole structure is mapped onto a standard fhandle_t
348 int fhh_pid; /* process id */
349 int fhh_id; /* map id */
350 int fhh_gen; /* generation number */
354 * Multi-protocol NFS file handle
356 union am_nfs_handle {
357 /* placeholder for V4 file handle */
359 struct mountres3 v3; /* NFS version 3 handle */
360 #endif /* HAVE_FS_NFS3 */
361 struct fhstatus v2; /* NFS version 2 handle */
363 typedef union am_nfs_handle am_nfs_handle_t;
366 * automounter vfs/vnode operations.
368 typedef char *(*vfs_match) (am_opts *);
369 typedef int (*vfs_init) (mntfs *);
370 typedef int (*vmount_fs) (am_node *);
371 typedef int (*vfmount_fs) (mntfs *);
372 typedef int (*vumount_fs) (am_node *);
373 typedef int (*vfumount_fs) (mntfs *);
374 typedef am_node *(*vlookuppn) (am_node *, char *, int *, int);
375 typedef int (*vreaddir) (am_node *, nfscookie, nfsdirlist *, nfsentry *, int);
376 typedef am_node *(*vreadlink) (am_node *, int *);
377 typedef void (*vmounted) (mntfs *);
378 typedef void (*vumounted) (am_node *);
379 typedef fserver *(*vffserver) (mntfs *);
382 char *fs_type; /* type of filesystems "nfsx" */
383 vfs_match fs_match; /* fxn: match */
384 vfs_init fs_init; /* fxn: initialization */
385 vmount_fs mount_fs; /* fxn: mount vnode */
386 vfmount_fs fmount_fs; /* fxn: mount VFS */
387 vumount_fs umount_fs; /* fxn: unmount vnode */
388 vfumount_fs fumount_fs; /* fxn: unmount VFS */
389 vlookuppn lookuppn; /* fxn: lookup path-name */
390 vreaddir readdir; /* fxn: read directory */
391 vreadlink readlink; /* fxn: read link */
392 vmounted mounted; /* fxn: after-mount extra actions */
393 vumounted umounted; /* fxn: after-umount extra actions */
394 vffserver ffserver; /* fxn: find a file server */
395 int fs_flags; /* filesystem flags FS_* */
398 typedef int (*task_fun) (voidp);
399 typedef void (*cb_fun) (int, int, voidp);
400 typedef void (*fwd_fun) P((voidp, int, struct sockaddr_in *,
401 struct sockaddr_in *, voidp, int));
404 * List of mount table entries
407 struct mntlist *mnext;
414 typedef struct mnt_map mnt_map;
417 * Per-mountpoint statistics
420 time_t s_mtime; /* Mount time */
421 u_short s_uid; /* Uid of mounter */
422 int s_getattr; /* Count of getattrs */
423 int s_lookup; /* Count of lookups */
424 int s_readdir; /* Count of readdirs */
425 int s_readlink; /* Count of readlinks */
426 int s_statfs; /* Count of statfs */
428 typedef struct am_stats am_stats;
434 int d_drops; /* Dropped requests */
435 int d_stale; /* Stale NFS handles */
436 int d_mok; /* Successful mounts */
437 int d_merr; /* Failed mounts */
438 int d_uerr; /* Failed unmounts */
440 extern struct amd_stats amd_stats;
443 * List of fileservers
446 qelem fs_q; /* List of fileservers */
447 int fs_refc; /* Number of references to this node */
448 char *fs_host; /* Normalized hostname of server */
449 struct sockaddr_in *fs_ip; /* Network address of server */
450 int fs_cid; /* Callout id */
451 int fs_pinger; /* Ping (keepalive) interval */
452 int fs_flags; /* Flags */
453 char *fs_type; /* File server type */
454 u_long fs_version; /* NFS version of server (2, 3, etc.)*/
455 char *fs_proto; /* NFS protocol of server (tcp, udp, etc.) */
456 voidp fs_private; /* Private data */
457 void (*fs_prfree) (voidp); /* Free private data */
461 * Map of auto-mount points.
464 int am_mapno; /* Map number */
465 mntfs *am_mnt; /* Mounted filesystem */
466 char *am_name; /* "kiska": name of this node */
467 char *am_path; /* "/home/kiska": path of this node's mount point */
468 char *am_link; /* "/a/kiska/home/kiska/this/that": link to sub-dir */
469 am_node *am_parent; /* Parent of this node */
470 am_node *am_ysib; /* Younger sibling of this node */
471 am_node *am_osib; /* Older sibling of this node */
472 am_node *am_child; /* First child of this node */
473 nfsattrstat am_attr; /* File attributes */
474 #define am_fattr am_attr.ns_u.ns_attr_u
475 int am_flags; /* Boolean flags AMF_* */
476 int am_error; /* Specific mount error */
477 time_t am_ttl; /* Time to live */
478 int am_timeo_w; /* Wait interval */
479 int am_timeo; /* Timeout interval */
480 u_int am_gen; /* Generation number */
481 char *am_pref; /* Mount info prefix */
482 am_stats am_stats; /* Statistics gathering */
483 SVCXPRT *am_transp; /* Info for quick reply */
487 /**************************************************************************/
489 /**************************************************************************/
494 extern char *mnttab_file_name; /* Mount table */
495 extern char *cpu; /* "CPU type" */
496 extern char *endian; /* "big" */
497 extern char *hostdomain; /* "southseas.nz" */
498 extern char copyright[]; /* Copyright info */
499 extern char hostd[]; /* "kiska.southseas.nz" */
500 extern char pid_fsname[]; /* kiska.southseas.nz:(pid%d) */
501 extern char version[]; /* Version info */
506 extern AUTH *nfs_auth; /* Dummy authorization for remote servers */
507 extern FILE *logfp; /* Log file */
508 extern SVCXPRT *nfsxprt;
509 extern am_node **exported_ap; /* List of nodes */
510 extern am_node *root_node; /* Node for "root" */
511 extern char *PrimNetName; /* Name of primary connected network */
512 extern char *PrimNetNum; /* Name of primary connected network */
513 extern char *SubsNetName; /* Name of subsidiary connected network */
514 extern char *SubsNetNum; /* Name of subsidiary connected network */
516 extern void am_set_progname(char *pn); /* "amd" */
517 extern const char *am_get_progname(void); /* "amd" */
518 extern void am_set_hostname(char *hn);
519 extern const char *am_get_hostname(void);
520 extern pid_t am_set_mypid(void);
521 extern pid_t am_mypid;
523 extern int first_free_map; /* First free node */
524 extern int foreground; /* Foreground process */
525 extern int immediate_abort; /* Should close-down unmounts be retried */
526 extern int last_used_map; /* Last map being used for mounts */
527 extern int orig_umask; /* umask() on startup */
528 extern int task_notify_todo; /* Task notifier needs running */
529 extern int xlog_level; /* Logging level */
530 extern int xlog_level_init;
531 extern serv_state amd_state; /* Should we go now */
532 extern struct in_addr myipaddr; /* (An) IP address of this host */
533 extern struct opt_tab xlog_opt[];
534 extern time_t clock_valid; /* Clock needs recalculating */
535 extern time_t do_mapc_reload; /* Flush & reload mount map cache */
536 extern time_t next_softclock; /* Time to call softclock() */
537 extern u_short nfs_port; /* Our NFS service port */
542 extern CLIENT *get_mount_client(char *unused_host, struct sockaddr_in *sin, struct timeval *tv, int *sock, u_long mnt_version);
543 extern RETSIGTYPE sigchld(int);
544 extern am_node *efs_lookuppn(am_node *, char *, int *, int);
545 extern am_node *exported_ap_alloc(void);
546 extern am_node *fh_to_mp(am_nfs_fh *);
547 extern am_node *fh_to_mp3(am_nfs_fh *, int *, int);
548 extern am_node *find_mf(mntfs *);
549 extern am_node *next_map(int *);
550 extern am_node *root_ap(char *, int);
551 extern am_ops *ops_match(am_opts *, char *, char *, char *, char *, char *);
552 extern bool_t xdr_amq_string(XDR *xdrs, amq_string *objp);
553 extern bool_t xdr_dirpath(XDR *xdrs, dirpath *objp);
554 extern char **strsplit(char *, int, int);
555 extern char *expand_key(char *);
556 extern char *get_version_string(void);
557 extern char *inet_dquad(char *, u_long);
558 extern char *print_wires(void);
559 extern char *str3cat(char *, char *, char *, char *);
560 extern char *strealloc(char *, char *);
561 extern char *strip_selectors(char *, char *);
562 extern char *strnsave(const char *, int);
563 extern fserver *dup_srvr(fserver *);
564 extern int amu_close(int fd);
565 extern int background(void);
566 extern int bind_resv_port(int, u_short *);
567 extern int cmdoption(char *, struct opt_tab *, int *);
568 extern int compute_automounter_mount_flags(mntent_t *);
569 extern int compute_mount_flags(mntent_t *);
570 extern int efs_readdir(am_node *, nfscookie, nfsdirlist *, nfsentry *, int);
571 extern int eval_fs_opts(am_opts *, char *, char *, char *, char *, char *);
572 extern int fwd_init(void);
573 extern int fwd_packet(int, voidp, int, struct sockaddr_in *, struct sockaddr_in *, voidp, fwd_fun);
574 extern int get_amd_program_number(void);
575 extern int getcreds(struct svc_req *, uid_t *, gid_t *, SVCXPRT *);
576 extern int hasmntval(mntent_t *, char *);
577 extern char *hasmnteq(mntent_t *, char *);
578 extern char *haseq(char *);
579 extern int is_network_member(const char *net);
580 extern int islocalnet(u_long);
581 extern int make_nfs_auth(void);
582 extern int make_rpc_packet(char *, int, u_long, struct rpc_msg *, voidp, XDRPROC_T_TYPE, AUTH *);
583 extern int mapc_keyiter(mnt_map *, void(*)(char *, voidp), voidp);
584 extern int mapc_search(mnt_map *, char *, char **);
585 extern int mapc_type_exists(const char *type);
586 extern int mkdirs(char *, int);
587 extern int mount_auto_node(char *, voidp);
588 extern int mount_automounter(int);
589 extern int mount_exported(void);
590 extern int mount_fs(mntent_t *, int, caddr_t, int, MTYPE_TYPE, u_long, const char *, const char *);
591 extern int mount_node(am_node *);
592 extern int nfs_srvr_port(fserver *, u_short *, voidp);
593 extern int pickup_rpc_reply(voidp, int, voidp, XDRPROC_T_TYPE);
594 extern int root_keyiter(void(*)(char *, voidp), voidp);
595 extern int softclock(void);
596 extern int switch_option(char *);
597 extern int switch_to_logfile(char *logfile, int orig_umask);
598 extern int timeout(u_int, void (*fn)(voidp), voidp);
599 extern int valid_key(char *);
600 extern mnt_map *mapc_find(char *, char *, const char *);
601 extern mntfs *dup_mntfs(mntfs *);
602 extern mntfs *find_mntfs(am_ops *, am_opts *, char *, char *, char *, char *, char *);
603 extern mntfs *new_mntfs(void);
604 extern mntfs *realloc_mntfs(mntfs *, am_ops *, am_opts *, char *, char *, char *, char *, char *);
605 extern mntlist *read_mtab(char *, const char *);
606 extern struct sockaddr_in *amu_svc_getcaller(SVCXPRT *xprt);
607 extern time_t time(time_t *);
608 extern void am_mounted(am_node *);
609 extern void am_unmounted(am_node *);
610 extern void amq_program_1(struct svc_req *rqstp, SVCXPRT *transp);
611 extern void amu_get_myaddress(struct in_addr *iap);
612 extern void amu_release_controlling_tty(void);
613 extern void compute_automounter_nfs_args(nfs_args_t *nap, mntent_t *mntp);
614 extern void deslashify(char *);
615 extern void discard_mntlist(mntlist *mp);
616 extern void do_task_notify(void);
617 extern void flush_mntfs(void);
618 extern void flush_nfs_fhandle_cache(fserver *);
619 extern void forcibly_timeout_mp(am_node *);
620 extern void free_map(am_node *);
621 extern void free_mntfs(voidp);
622 extern void free_mntlist(mntlist *);
623 extern void free_opts(am_opts *);
624 extern void free_srvr(fserver *);
625 extern void fwd_reply(void);
626 extern void get_args(int argc, char *argv[]);
627 extern void getwire(char **name1, char **number1);
628 extern void going_down(int);
629 extern void host_normalize(char **);
630 extern void init_map(am_node *, char *);
631 extern void ins_que(qelem *, qelem *);
632 extern void insert_am(am_node *, am_node *);
633 extern void make_root_node(void);
634 extern void map_flush_srvr(fserver *);
635 extern void mapc_add_kv(mnt_map *, char *, char *);
636 extern void mapc_free(voidp);
637 extern void mapc_reload(void);
638 extern void mapc_showtypes(char *buf);
639 extern void mk_fattr(am_node *, nfsftype);
640 extern void mnt_free(mntent_t *);
641 extern void mp_to_fh(am_node *, am_nfs_fh *);
642 extern void new_ttl(am_node *);
643 extern void nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp);
644 extern void normalize_slash(char *);
645 extern void ops_showamfstypes(char *buf);
646 extern void ops_showfstypes(char *outbuf);
647 extern void plog(int, const char *,...)
648 __attribute__ ((__format__ (__printf__, 2, 3)));
649 extern void rem_que(qelem *);
650 extern void reschedule_timeout_mp(void);
651 extern void restart(void);
652 extern void rmdirs(char *);
653 extern void rpc_msg_init(struct rpc_msg *, u_long, u_long, u_long);
654 extern void run_task(task_fun, voidp, cb_fun, voidp);
655 extern void sched_task(cb_fun, voidp, voidp);
656 extern void set_amd_program_number(int program);
657 extern void show_opts(int ch, struct opt_tab *);
658 extern void show_rcs_info(const char *, char *);
659 extern void srvrlog(fserver *, char *);
660 extern void timeout_mp(voidp);
661 extern void umount_exported(void);
662 extern void unregister_amq(void);
663 extern void untimeout(int);
664 extern void wakeup(voidp);
665 extern void wakeup_srvr(fserver *);
666 extern void wakeup_task(int, int, voidp);
667 extern voidp xmalloc(int);
668 extern voidp xrealloc(voidp, int);
669 extern voidp xzalloc(int);
670 extern u_long get_nfs_version(char *host, struct sockaddr_in *sin, u_long nfs_version, const char *proto);
673 #ifdef MOUNT_TABLE_ON_FILE
674 extern void rewrite_mtab(mntlist *, const char *);
675 extern void unlock_mntlist(void);
676 extern void write_mntent(mntent_t *, const char *);
677 #endif /* MOUNT_TABLE_ON_FILE */
679 #if defined(HAVE_SYSLOG_H) || defined(HAVE_SYS_SYSLOG_H)
680 extern int syslogging;
681 #endif /* defined(HAVE_SYSLOG_H) || defined(HAVE_SYS_SYSLOG_H) */
683 #ifdef HAVE_TRANSPORT_TYPE_TLI
685 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);
686 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);
687 extern int create_nfs_service(int *soNFSp, u_short *nfs_portp, SVCXPRT **nfs_xprtp, void (*dispatch_fxn)(struct svc_req *rqstp, SVCXPRT *transp));
688 extern int get_knetconfig(struct knetconfig **kncpp, struct netconfig *in_ncp, char *nc_protoname);
689 extern struct netconfig *nfsncp;
690 extern void free_knetconfig(struct knetconfig *kncp);
692 #else /* not HAVE_TRANSPORT_TYPE_TLI */
694 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);
695 extern enum clnt_stat pmap_ping(struct sockaddr_in *address);
696 extern int create_amq_service(int *udp_soAMQp, SVCXPRT **udp_amqpp, int *tcp_soAMQp, SVCXPRT **tcp_amqpp);
697 extern int create_nfs_service(int *soNFSp, u_short *nfs_portp, SVCXPRT **nfs_xprtp, void (*dispatch_fxn)(struct svc_req *rqstp, SVCXPRT *transp));
699 #endif /* not HAVE_TRANSPORT_TYPE_TLI */
701 #ifndef HAVE_STRUCT_FHSTATUS_FHS_FH
702 # define fhs_fh fhstatus_u.fhs_fhandle
703 #endif /* not HAVE_STRUCT_FHSTATUS_FHS_FH */
706 /**************************************************************************/
707 /*** Generic file-system types, implemented as part of the native O/S. ***/
708 /**************************************************************************/
711 * Loopback File System
712 * Many systems can't support this, and in any case most of the
713 * functionality is available with Symlink FS.
716 extern am_ops lofs_ops;
717 #endif /* HAVE_FS_LOFS */
720 * CD-ROM File System (CD-ROM)
721 * (HSFS: High Sierra F/S on some machines)
722 * Many systems can't support this, and in any case most of the
723 * functionality is available with program FS.
726 extern am_ops cdfs_ops;
727 #endif /* HAVE_FS_CDFS */
730 * PC File System (MS-DOS)
731 * Many systems can't support this, and in any case most of the
732 * functionality is available with program FS.
735 extern am_ops pcfs_ops;
736 #endif /* HAVE_FS_PCFS */
739 * Caching File System (Solaris)
741 #ifdef HAVE_FS_CACHEFS
742 extern am_ops cachefs_ops;
743 #endif /* HAVE_FS_CACHEFS */
746 * Network File System
747 * Good, slow, NFS V.2.
750 extern am_ops nfs_ops; /* NFS */
751 extern fserver *find_nfs_srvr (mntfs *);
752 extern int nfs_fmount(mntfs *mf);
753 extern int nfs_fumount(mntfs *mf);
754 extern int nfs_init(mntfs *mf);
755 extern qelem nfs_srvr_list;
756 extern void nfs_umounted(am_node *mp);
757 #endif /* HAVE_FS_NFS */
761 * Network File System: the new generation
765 # ifndef NFS_VERSION3
766 # define NFS_VERSION3 ((u_int) 3)
767 # endif /* not NFS_VERSION3 */
768 #endif /* HAVE_FS_NFS3 */
772 * Normal local disk file system.
775 extern am_ops ufs_ops; /* Un*x file system */
776 #endif /* HAVE_FS_UFS */
779 /**************************************************************************/
780 /*** Automounter file-system types, implemented by amd. ***/
781 /**************************************************************************/
784 * Automount File System
786 #ifdef HAVE_AMU_FS_AUTO
787 extern am_ops amfs_auto_ops; /* Automount file system (this!) */
788 extern am_ops amfs_toplvl_ops; /* Top-level automount file system */
789 extern am_ops amfs_root_ops; /* Root file system */
790 extern qelem amfs_auto_srvr_list;
791 extern am_node *amfs_auto_lookuppn(am_node *mp, char *fname, int *error_return, int op);
792 extern am_node *next_nonerror_node(am_node *xp);
793 extern char *amfs_auto_match(am_opts *fo);
794 extern fserver *find_amfs_auto_srvr(mntfs *);
795 extern int amfs_auto_readdir(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, int count);
796 extern int amfs_auto_umount(am_node *mp);
797 extern int amfs_auto_fmount(am_node *mp);
798 extern int amfs_auto_fumount(am_node *mp);
799 #endif /* HAVE_AMU_FS_AUTO */
802 * Toplvl Automount File System
804 #ifdef HAVE_AMU_FS_TOPLVL
805 extern am_ops amfs_toplvl_ops; /* Toplvl Automount file system */
806 extern int amfs_toplvl_mount(am_node *mp);
807 extern int amfs_toplvl_umount(am_node *mp);
808 extern void amfs_toplvl_mounted(mntfs *mf);
809 #endif /* HAVE_AMU_FS_TOPLVL */
812 * Direct Automount File System
814 #ifdef HAVE_AMU_FS_DIRECT
815 extern am_ops amfs_direct_ops; /* Direct Automount file system (this too) */
816 #endif /* HAVE_AMU_FS_DIRECT */
821 #ifdef HAVE_AMU_FS_ERROR
822 extern am_ops amfs_error_ops; /* Error file system */
823 extern am_node *amfs_error_lookuppn(am_node *mp, char *fname, int *error_return, int op);
824 extern int amfs_error_readdir(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, int count);
825 #endif /* HAVE_AMU_FS_ERROR */
828 * Inheritance File System
830 #ifdef HAVE_AMU_FS_INHERIT
831 extern am_ops amfs_inherit_ops; /* Inheritance file system */
832 #endif /* HAVE_AMU_FS_INHERIT */
835 * NFS mounts with local existence check.
837 #ifdef HAVE_AMU_FS_NFSL
838 extern am_ops amfs_nfsl_ops; /* NFSL */
839 #endif /* HAVE_AMU_FS_NFSL */
844 #ifdef HAVE_AMU_FS_NFSX
845 extern am_ops amfs_nfsx_ops; /* NFSX */
846 #endif /* HAVE_AMU_FS_NFSX */
849 * NFS host - a whole tree.
851 #ifdef HAVE_AMU_FS_HOST
852 extern am_ops amfs_host_ops; /* NFS host */
853 #endif /* HAVE_AMU_FS_HOST */
856 * Program File System
857 * This is useful for things like RVD.
859 #ifdef HAVE_AMU_FS_PROGRAM
860 extern am_ops amfs_program_ops; /* Program File System */
861 #endif /* HAVE_AMU_FS_PROGRAM */
864 * Symbolic-link file system.
865 * A "filesystem" which is just a symbol link.
867 #ifdef HAVE_AMU_FS_LINK
868 extern am_ops amfs_link_ops; /* Symlink FS */
869 extern int amfs_link_fmount(mntfs *mf);
870 #endif /* HAVE_AMU_FS_LINK */
873 * Symbolic-link file system, which also checks that the target of
874 * the symlink exists.
875 * A "filesystem" which is just a symbol link.
877 #ifdef HAVE_AMU_FS_LINKX
878 extern am_ops amfs_linkx_ops; /* Symlink FS with existence check */
879 #endif /* HAVE_AMU_FS_LINKX */
884 #ifdef HAVE_AMU_FS_UNION
885 extern am_ops amfs_union_ops; /* Union FS */
886 #endif /* HAVE_AMU_FS_UNION */
889 /**************************************************************************/
891 /**************************************************************************/
899 # define D_DAEMON 0x0001 /* Enter daemon mode */
900 # define D_TRACE 0x0002 /* Do protocol trace */
901 # define D_FULL 0x0004 /* Do full trace */
902 # define D_MTAB 0x0008 /* Use local mtab */
903 # define D_AMQ 0x0010 /* Register amq program */
904 # define D_STR 0x0020 /* Debug string munging */
906 # define D_MEM 0x0040 /* Trace memory allocations */
907 # endif /* DEBUG_MEM */
908 # define D_FORK 0x0080 /* Fork server */
909 /* info service specific debugging (hesiod, nis, etc) */
910 # define D_INFO 0x0100
911 # define D_HRTIME 0x0200 /* Print high resolution time stamps */
912 # define D_XDRTRACE 0x0400 /* Trace xdr routines */
913 # define D_READDIR 0x0800 /* show browsable_dir progress */
916 * Normally, don't enter daemon mode, don't register amq, and don't trace xdr
919 # define D_TEST (~(D_DAEMON|D_MEM|D_STR|D_XDRTRACE))
920 # else /* not DEBUG_MEM */
921 # define D_TEST (~(D_DAEMON|D_STR|D_XDRTRACE))
922 # endif /* not DEBUG_MEM */
924 # define amuDebug(x) if (debug_flags & (x))
925 # define dlog amuDebug(D_FULL) dplog
926 # define amuDebugNo(x) if (!(debug_flags & (x)))
928 /* debugging mount-table file to use */
929 # ifndef DEBUG_MNTTAB
930 # define DEBUG_MNTTAB "./mnttab"
931 # endif /* not DEBUG_MNTTAB */
935 * If debugging memory, then call a special freeing function that logs
936 * more info, and resets the pointer to NULL so it cannot be used again.
938 # define XFREE(x) dxfree(__FILE__,__LINE__,x)
939 extern void dxfree(char *file, int line, voidp ptr);
940 extern void malloc_verify(void);
941 # else /* not DEBUG_MEM */
943 * If regular debugging, then free the pointer and reset to NULL.
944 * This should remain so for as long as am-utils is in alpha/beta testing.
946 # define XFREE(x) do { free((voidp)x); x = NULL;} while (0)
947 # endif /* not DEBUG_MEM */
949 /* functions that depend solely on debugging */
950 extern void print_nfs_args(const nfs_args_t *nap, u_long nfs_version);
951 extern int debug_option (char *opt);
953 #else /* not DEBUG */
956 * if not debugging, then simple perform free, and don't bother
957 * resetting the pointer.
959 # define XFREE(x) free(x)
961 #define amuDebug(x) if (0)
962 #define dlog if (0) dplog
963 #define amuDebugNo(x) if (0)
965 #define print_nfs_args(nap, nfs_version)
966 #define debug_option(x) (1)
968 #endif /* not DEBUG */
970 extern int debug_flags; /* Debug options */
971 extern struct opt_tab dbg_opt[];
972 extern void dplog(const char *fmt, ...)
973 __attribute__ ((__format__ (__printf__, 1, 2)));
975 /**************************************************************************/
976 /*** MISC (stuff left to autoconfiscate) ***/
977 /**************************************************************************/
979 #endif /* not _AM_UTILS_H */