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