Blame include/automount.h

Packit Service a4b2a9
/*
Packit Service a4b2a9
 * automount.h
Packit Service a4b2a9
 *
Packit Service a4b2a9
 * Header file for automounter modules
Packit Service a4b2a9
 *
Packit Service a4b2a9
 */
Packit Service a4b2a9
Packit Service a4b2a9
#ifndef AUTOMOUNT_H
Packit Service a4b2a9
#define AUTOMOUNT_H
Packit Service a4b2a9
Packit Service a4b2a9
#include <stdio.h>
Packit Service a4b2a9
#include <paths.h>
Packit Service a4b2a9
#include <limits.h>
Packit Service a4b2a9
#include <time.h>
Packit Service a4b2a9
#include <syslog.h>
Packit Service a4b2a9
#include <sys/types.h>
Packit Service a4b2a9
#include <pthread.h>
Packit Service a4b2a9
#include <sched.h>
Packit Service a4b2a9
#include <errno.h>
Packit Service a4b2a9
#include <unistd.h>
Packit Service a4b2a9
#include <fcntl.h>
Packit Service a4b2a9
#include <mntent.h>
Packit Service a4b2a9
#include "config.h"
Packit Service a4b2a9
#include "list.h"
Packit Service a4b2a9
Packit Service a4b2a9
#include <linux/auto_fs4.h>
Packit Service a4b2a9
Packit Service a4b2a9
#include "defaults.h"
Packit Service a4b2a9
#include "state.h"
Packit Service a4b2a9
#include "master.h"
Packit Service a4b2a9
#include "macros.h"
Packit Service a4b2a9
#include "log.h"
Packit Service a4b2a9
#include "rpc_subs.h"
Packit Service a4b2a9
#include "mounts.h"
Packit Service a4b2a9
#include "parse_subs.h"
Packit Service a4b2a9
#include "mounts.h"
Packit Service a4b2a9
#include "dev-ioctl-lib.h"
Packit Service a4b2a9
#include "parse_amd.h"
Packit Service a4b2a9
Packit Service a4b2a9
#ifdef WITH_DMALLOC
Packit Service a4b2a9
#include <dmalloc.h>
Packit Service a4b2a9
#endif
Packit Service a4b2a9
Packit Service a4b2a9
#define ENABLE_CORES	1
Packit Service a4b2a9
Packit Service a4b2a9
/* We MUST have the paths to mount(8) and umount(8) */
Packit Service a4b2a9
#ifndef HAVE_MOUNT
Packit Service a4b2a9
#error Failed to locate mount(8)!
Packit Service a4b2a9
#endif
Packit Service a4b2a9
Packit Service a4b2a9
#ifndef HAVE_UMOUNT
Packit Service a4b2a9
#error Failed to locate umount(8)!
Packit Service a4b2a9
#endif
Packit Service a4b2a9
Packit Service a4b2a9
#ifndef HAVE_LINUX_PROCFS
Packit Service a4b2a9
#error Failed to verify existence of procfs filesystem!
Packit Service a4b2a9
#endif
Packit Service a4b2a9
Packit Service a4b2a9
/* The -s (sloppy) option to mount is good, if we have it... */
Packit Service a4b2a9
Packit Service a4b2a9
#ifdef HAVE_SLOPPY_MOUNT
Packit Service a4b2a9
#define SLOPPYOPT "-s",		/* For use in spawnl() lists */
Packit Service a4b2a9
#define SLOPPY    "-s "		/* For use in strings */
Packit Service a4b2a9
#else
Packit Service a4b2a9
#define SLOPPYOPT
Packit Service a4b2a9
#define SLOPPY
Packit Service a4b2a9
#endif
Packit Service a4b2a9
Packit Service 0700ee
#define DAEMON_FLAGS_FOREGROUND			0x0001
Packit Service 59e6d5
#define DAEMON_FLAGS_SYSTEMD_SERVICE		0x0002
Packit Service 0700ee
#define DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS	0x0004
Packit Service 0700ee
#define DAEMON_FLAGS_GHOST			0x0008
Packit Service 0700ee
#define DAEMON_FLAGS_CHECK_DAEMON		0x0010
Packit Service 0700ee
#define DAEMON_FLAGS_DUMP_MAPS			0x0020
Packit Service 0700ee
Packit Service a4b2a9
#define AUTOFS_SUPER_MAGIC 0x00000187L
Packit Service a4b2a9
#define SMB_SUPER_MAGIC    0x0000517BL
Packit Service a4b2a9
#define CIFS_MAGIC_NUMBER  0xFF534D42L
Packit Service a4b2a9
#define NCP_SUPER_MAGIC    0x0000564CL
Packit Service a4b2a9
#define NFS_SUPER_MAGIC    0x00006969L
Packit Service a4b2a9
Packit Service a4b2a9
#define ATTEMPT_ID_SIZE 24
Packit Service a4b2a9
Packit Service a4b2a9
/* This sould be enough for at least 20 host aliases */
Packit Service a4b2a9
#define HOST_ENT_BUF_SIZE	2048
Packit Service a4b2a9
Packit Service a4b2a9
#define CHECK_RATIO	4			/* exp_runfreq = exp_timeout/CHECK_RATIO */
Packit Service a4b2a9
#define AUTOFS_LOCK	"/var/lock/autofs"	/* To serialize access to mount */
Packit Service a4b2a9
#define MOUNTED_LOCK	_PATH_MOUNTED "~"	/* mounts' lock file */
Packit Service a4b2a9
#define MTAB_NOTUPDATED 0x1000			/* mtab succeded but not updated */
Packit Service a4b2a9
#define NOT_MOUNTED     0x0100			/* path notmounted */
Packit Service a4b2a9
#define MNT_FORCE_FAIL	-1
Packit Service a4b2a9
#define _PROC_MOUNTS		"/proc/mounts"
Packit Service a4b2a9
#define _PROC_SELF_MOUNTS	"/proc/self/mounts"
Packit Service a4b2a9
Packit Service a4b2a9
/* Constants for lookup modules */
Packit Service a4b2a9
Packit Service a4b2a9
#define LKP_FAIL	0x0001
Packit Service a4b2a9
Packit Service a4b2a9
#define LKP_INDIRECT	0x0002
Packit Service a4b2a9
#define LKP_DIRECT	0x0004
Packit Service a4b2a9
#define LKP_MULTI	0x0008
Packit Service a4b2a9
#define LKP_NOMATCH	0x0010
Packit Service a4b2a9
#define LKP_MATCH	0x0020
Packit Service a4b2a9
#define LKP_NEXT	0x0040
Packit Service a4b2a9
#define LKP_MOUNT	0x0080
Packit Service a4b2a9
#define LKP_WILD	0x0100
Packit Service a4b2a9
#define LKP_LOOKUP	0x0200
Packit Service a4b2a9
#define LKP_GHOST	0x0400
Packit Service a4b2a9
#define LKP_REREAD	0x0800
Packit Service a4b2a9
#define LKP_NORMAL	0x1000
Packit Service a4b2a9
#define LKP_DISTINCT	0x2000
Packit Service a4b2a9
#define LKP_ERR_MOUNT	0x4000
Packit Service a4b2a9
#define LKP_NOTSUP	0x8000
Packit Service a4b2a9
Packit Service a4b2a9
#define MAX_ERR_BUF	128
Packit Service a4b2a9
Packit Service a4b2a9
#ifdef DEBUG
Packit Service a4b2a9
#define DB(x)           do { x; } while(0)
Packit Service a4b2a9
#else
Packit Service a4b2a9
#define DB(x)           do { } while(0)
Packit Service a4b2a9
#endif
Packit Service a4b2a9
Packit Service a4b2a9
#define min(a, b)	(a <= b ? a : b)
Packit Service a4b2a9
Packit Service a4b2a9
/* Forward declaraion */
Packit Service a4b2a9
struct autofs_point; 
Packit Service a4b2a9
Packit Service a4b2a9
/* mapent cache definition */
Packit Service a4b2a9
Packit Service a4b2a9
#define CHE_FAIL	0x0000
Packit Service a4b2a9
#define CHE_OK		0x0001
Packit Service a4b2a9
#define CHE_UPDATED	0x0002
Packit Service a4b2a9
#define CHE_RMPATH	0x0004
Packit Service a4b2a9
#define CHE_MISSING	0x0008
Packit Service a4b2a9
#define CHE_COMPLETED	0x0010
Packit Service a4b2a9
#define CHE_DUPLICATE	0x0020
Packit Service a4b2a9
#define CHE_UNAVAIL	0x0040
Packit Service a4b2a9
Packit Service a4b2a9
#define NULL_MAP_HASHSIZE	64
Packit Service a4b2a9
#define NEGATIVE_TIMEOUT	10
Packit Service a4b2a9
#define UMOUNT_RETRIES		8
Packit Service a4b2a9
#define EXPIRE_RETRIES		3
Packit Service a4b2a9
Packit Service a4b2a9
static u_int32_t inline hash(const char *key, unsigned int size)
Packit Service a4b2a9
{
Packit Service a4b2a9
	u_int32_t hashval;
Packit Service a4b2a9
	char *s = (char *) key;
Packit Service a4b2a9
Packit Service a4b2a9
	for (hashval = 0; *s != '\0';) {
Packit Service a4b2a9
		hashval += (unsigned char) *s++;
Packit Service a4b2a9
		hashval += (hashval << 10);
Packit Service a4b2a9
		hashval ^= (hashval >> 6);
Packit Service a4b2a9
	}
Packit Service a4b2a9
Packit Service a4b2a9
	hashval += (hashval << 3);
Packit Service a4b2a9
	hashval ^= (hashval >> 11);
Packit Service a4b2a9
	hashval += (hashval << 15);
Packit Service a4b2a9
Packit Service a4b2a9
	return hashval % size;
Packit Service a4b2a9
}
Packit Service a4b2a9
Packit Service a4b2a9
struct mapent_cache {
Packit Service a4b2a9
	pthread_rwlock_t rwlock;
Packit Service a4b2a9
	unsigned int size;
Packit Service a4b2a9
	pthread_mutex_t ino_index_mutex;
Packit Service a4b2a9
	struct list_head *ino_index;
Packit Service a4b2a9
	struct autofs_point *ap;
Packit Service a4b2a9
	struct map_source *map;
Packit Service a4b2a9
	struct mapent **hash;
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
struct stack {
Packit Service a4b2a9
	char *mapent;
Packit Service a4b2a9
	time_t age;
Packit Service a4b2a9
	struct stack *next;
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
struct mapent {
Packit Service a4b2a9
	struct mapent *next;
Packit Service a4b2a9
	struct list_head ino_index;
Packit Service a4b2a9
	pthread_rwlock_t multi_rwlock;
Packit Service a4b2a9
	struct list_head multi_list;
Packit Service a4b2a9
	struct mapent_cache *mc;
Packit Service a4b2a9
	struct map_source *source;
Packit Service a4b2a9
	/* Need to know owner if we're a multi-mount */
Packit Service a4b2a9
	struct mapent *multi;
Packit Service a4b2a9
	/* Parent nesting point within multi-mount */
Packit Service a4b2a9
	struct mapent *parent;
Packit Service a4b2a9
	char *key;
Packit Service a4b2a9
	char *mapent;
Packit Service a4b2a9
	struct stack *stack;
Packit Service a4b2a9
	time_t age;
Packit Service a4b2a9
	/* Time of last mount fail */
Packit Service a4b2a9
	time_t status;
Packit Service a4b2a9
	/* For direct mounts per entry context is kept here */
Packit Service a4b2a9
	int flags;
Packit Service a4b2a9
	/* File descriptor for ioctls */
Packit Service a4b2a9
	int ioctlfd;
Packit Service a4b2a9
	dev_t dev;
Packit Service a4b2a9
	ino_t ino;
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
void cache_lock_cleanup(void *arg);
Packit Service a4b2a9
void cache_readlock(struct mapent_cache *mc);
Packit Service a4b2a9
void cache_writelock(struct mapent_cache *mc);
Packit Service a4b2a9
int cache_try_writelock(struct mapent_cache *mc);
Packit Service a4b2a9
void cache_unlock(struct mapent_cache *mc);
Packit Service a4b2a9
int cache_push_mapent(struct mapent *me, char *mapent);
Packit Service a4b2a9
int cache_pop_mapent(struct mapent *me);
Packit Service a4b2a9
struct mapent_cache *cache_init(struct autofs_point *ap, struct map_source *map);
Packit Service a4b2a9
struct mapent_cache *cache_init_null_cache(struct master *master);
Packit Service a4b2a9
int cache_set_ino_index(struct mapent_cache *mc, const char *key, dev_t dev, ino_t ino);
Packit Service a4b2a9
/* void cache_set_ino(struct mapent *me, dev_t dev, ino_t ino); */
Packit Service a4b2a9
struct mapent *cache_lookup_ino(struct mapent_cache *mc, dev_t dev, ino_t ino);
Packit Service a4b2a9
struct mapent *cache_lookup_first(struct mapent_cache *mc);
Packit Service a4b2a9
struct mapent *cache_lookup_next(struct mapent_cache *mc, struct mapent *me);
Packit Service a4b2a9
struct mapent *cache_lookup_key_next(struct mapent *me);
Packit Service a4b2a9
struct mapent *cache_lookup(struct mapent_cache *mc, const char *key);
Packit Service a4b2a9
struct mapent *cache_lookup_distinct(struct mapent_cache *mc, const char *key);
Packit Service a4b2a9
struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int start, struct list_head *head);
Packit Service a4b2a9
struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix);
Packit Service a4b2a9
struct mapent *cache_partial_match_wild(struct mapent_cache *mc, const char *prefix);
Packit Service a4b2a9
int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
Packit Service a4b2a9
int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age);
Packit Service a4b2a9
void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout);
Packit Service a4b2a9
int cache_set_parents(struct mapent *mm);
Packit Service a4b2a9
int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
Packit Service a4b2a9
int cache_delete(struct mapent_cache *mc, const char *key);
Packit Service a4b2a9
int cache_delete_offset(struct mapent_cache *mc, const char *key);
Packit Service a4b2a9
void cache_multi_readlock(struct mapent *me);
Packit Service a4b2a9
void cache_multi_writelock(struct mapent *me);
Packit Service a4b2a9
void cache_multi_unlock(struct mapent *me);
Packit Service a4b2a9
int cache_delete_offset_list(struct mapent_cache *mc, const char *key);
Packit Service a4b2a9
void cache_release(struct map_source *map);
Packit Service a4b2a9
void cache_clean_null_cache(struct mapent_cache *mc);
Packit Service a4b2a9
void cache_release_null_cache(struct master *master);
Packit Service a4b2a9
struct mapent *cache_enumerate(struct mapent_cache *mc, struct mapent *me);
Packit Service a4b2a9
char *cache_get_offset(const char *prefix, char *offset, int start, struct list_head *head, struct list_head **pos);
Packit Service a4b2a9
Packit Service a4b2a9
/* Utility functions */
Packit Service a4b2a9
Packit Service a4b2a9
char **add_argv(int argc, char **argv, char *str);
Packit Service a4b2a9
char **append_argv(int argc1, char **argv1, int argc2, char **argv2);
Packit Service a4b2a9
const char **copy_argv(int argc, const char **argv);
Packit Service a4b2a9
int compare_argv(int argc1, const char **argv1, int argc2, const char **argv2);
Packit Service a4b2a9
int free_argv(int argc, const char **argv);
Packit Service a4b2a9
Packit Service a4b2a9
struct pending_args;
Packit Service a4b2a9
void set_thread_mount_request_log_id(struct pending_args *mt);
Packit Service a4b2a9
Packit Service a4b2a9
void dump_core(void);
Packit Service a4b2a9
int aquire_lock(void);
Packit Service a4b2a9
void release_lock(void);
Packit Service a4b2a9
int spawnl(unsigned logopt, const char *prog, ...);
Packit Service a4b2a9
int spawnv(unsigned logopt, const char *prog, const char *const *argv);
Packit Service a4b2a9
int spawn_mount(unsigned logopt, ...);
Packit Service a4b2a9
int spawn_bind_mount(unsigned logopt, ...);
Packit Service a4b2a9
int spawn_umount(unsigned logopt, ...);
Packit Service a4b2a9
void open_mutex_lock(void);
Packit Service a4b2a9
void open_mutex_unlock(void);
Packit Service a4b2a9
int open_fd(const char *, int);
Packit Service a4b2a9
int open_fd_mode(const char *, int, int);
Packit Service a4b2a9
int open_pipe(int[2]);
Packit Service a4b2a9
int open_sock(int, int, int);
Packit Service a4b2a9
FILE *open_fopen_r(const char *);
Packit Service a4b2a9
FILE *open_setmntent_r(const char *);
Packit Service a4b2a9
void reset_signals(void);
Packit Service a4b2a9
int do_mount(struct autofs_point *ap, const char *root, const char *name,
Packit Service a4b2a9
	     int name_len, const char *what, const char *fstype,
Packit Service a4b2a9
	     const char *options);
Packit Service 15cf98
extern unsigned int mp_mode;
Packit Service a4b2a9
int mkdir_path(const char *path, mode_t mode);
Packit Service a4b2a9
int rmdir_path(struct autofs_point *ap, const char *path, dev_t dev);
Packit Service a4b2a9
Packit Service a4b2a9
/* Prototype for module functions */
Packit Service a4b2a9
Packit Service a4b2a9
/* lookup module */
Packit Service a4b2a9
Packit Service a4b2a9
#define AUTOFS_LOOKUP_VERSION 5
Packit Service a4b2a9
Packit Service a4b2a9
#define KEY_MAX_LEN    NAME_MAX
Packit Service a4b2a9
#define MAPENT_MAX_LEN 16384
Packit Service a4b2a9
#define PARSE_MAX_BUF	KEY_MAX_LEN + MAPENT_MAX_LEN + 2
Packit Service a4b2a9
Packit Service a4b2a9
int lookup_nss_read_master(struct master *master, time_t age);
Packit Service a4b2a9
int lookup_nss_read_map(struct autofs_point *ap, struct map_source *source, time_t age);
Packit Service a4b2a9
int lookup_enumerate(struct autofs_point *ap,
Packit Service a4b2a9
	int (*fn)(struct autofs_point *,struct mapent *, int), time_t now);
Packit Service a4b2a9
int lookup_ghost(struct autofs_point *ap, const char *root);
Packit Service a4b2a9
int lookup_nss_mount(struct autofs_point *ap, struct map_source *source, const char *name, int name_len);
Packit Service a4b2a9
void lookup_close_lookup(struct autofs_point *ap);
Packit Service a4b2a9
void lookup_prune_one_cache(struct autofs_point *ap, struct mapent_cache *mc, time_t age);
Packit Service a4b2a9
int lookup_prune_cache(struct autofs_point *ap, time_t age);
Packit Service a4b2a9
struct mapent *lookup_source_valid_mapent(struct autofs_point *ap, const char *key, unsigned int type);
Packit Service a4b2a9
struct mapent *lookup_source_mapent(struct autofs_point *ap, const char *key, unsigned int type);
Packit Service a4b2a9
int lookup_source_close_ioctlfd(struct autofs_point *ap, const char *key);
Packit Service a4b2a9
Packit Service a4b2a9
#ifdef MODULE_LOOKUP
Packit Service a4b2a9
int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context);
Packit Service a4b2a9
int lookup_reinit(const char *mapfmt, int argc, const char *const *argv, void **context);
Packit Service a4b2a9
int lookup_read_master(struct master *master, time_t age, void *context);
Packit Service a4b2a9
int lookup_read_map(struct autofs_point *, time_t, void *context);
Packit Service a4b2a9
int lookup_mount(struct autofs_point *, const char *, int, void *);
Packit Service a4b2a9
int lookup_done(void *);
Packit Service a4b2a9
#endif
Packit Service a4b2a9
typedef int (*lookup_init_t) (const char *, int, const char *const *, void **);
Packit Service a4b2a9
typedef int (*lookup_reinit_t) (const char *, int, const char *const *, void **);
Packit Service a4b2a9
typedef int (*lookup_read_master_t) (struct master *master, time_t, void *);
Packit Service a4b2a9
typedef int (*lookup_read_map_t) (struct autofs_point *, time_t, void *);
Packit Service a4b2a9
typedef int (*lookup_mount_t) (struct autofs_point *, const char *, int, void *);
Packit Service a4b2a9
typedef int (*lookup_done_t) (void *);
Packit Service a4b2a9
Packit Service a4b2a9
struct lookup_mod {
Packit Service a4b2a9
	lookup_init_t lookup_init;
Packit Service a4b2a9
	lookup_reinit_t lookup_reinit;
Packit Service a4b2a9
	lookup_read_master_t lookup_read_master;
Packit Service a4b2a9
	lookup_read_map_t lookup_read_map;
Packit Service a4b2a9
	lookup_mount_t lookup_mount;
Packit Service a4b2a9
	lookup_done_t lookup_done;
Packit Service a4b2a9
	char *type;
Packit Service a4b2a9
	void *dlhandle;
Packit Service a4b2a9
	void *context;
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
int open_lookup(const char *name, const char *err_prefix, const char *mapfmt,
Packit Service a4b2a9
		int argc, const char *const *argv, struct lookup_mod **lookup);
Packit Service a4b2a9
int reinit_lookup(struct lookup_mod *mod, const char *name,
Packit Service a4b2a9
		  const char *err_prefix, const char *mapfmt,
Packit Service a4b2a9
		  int argc, const char *const *argv);
Packit Service a4b2a9
int close_lookup(struct lookup_mod *);
Packit Service a4b2a9
Packit Service a4b2a9
/* parse module */
Packit Service a4b2a9
Packit Service a4b2a9
#define AUTOFS_PARSE_VERSION 5
Packit Service a4b2a9
Packit Service a4b2a9
#ifdef MODULE_PARSE
Packit Service a4b2a9
int parse_init(int argc, const char *const *argv, void **context);
Packit Service a4b2a9
int parse_reinit(int argc, const char *const *argv, void **context);
Packit Service a4b2a9
int parse_mount(struct autofs_point *ap, const char *name,
Packit Service a4b2a9
		int name_len, const char *mapent, void *context);
Packit Service a4b2a9
int parse_done(void *);
Packit Service a4b2a9
#endif
Packit Service a4b2a9
typedef int (*parse_init_t) (int, const char *const *, void **);
Packit Service a4b2a9
typedef int (*parse_reinit_t) (int, const char *const *, void **);
Packit Service a4b2a9
typedef int (*parse_mount_t) (struct autofs_point *, const char *, int, const char *, void *);
Packit Service a4b2a9
typedef int (*parse_done_t) (void *);
Packit Service a4b2a9
Packit Service a4b2a9
struct parse_mod {
Packit Service a4b2a9
	parse_init_t parse_init;
Packit Service a4b2a9
	parse_reinit_t parse_reinit;
Packit Service a4b2a9
	parse_mount_t parse_mount;
Packit Service a4b2a9
	parse_done_t parse_done;
Packit Service a4b2a9
	void *dlhandle;
Packit Service a4b2a9
	void *context;
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
struct parse_mod *open_parse(const char *name, const char *err_prefix,
Packit Service a4b2a9
			     int argc, const char *const *argv);
Packit Service a4b2a9
int reinit_parse(struct parse_mod *, const char *name,
Packit Service a4b2a9
		 const char *err_prefix, int argc, const char *const *argv);
Packit Service a4b2a9
int close_parse(struct parse_mod *);
Packit Service a4b2a9
Packit Service a4b2a9
/* mount module */
Packit Service a4b2a9
Packit Service a4b2a9
#define AUTOFS_MOUNT_VERSION 4
Packit Service a4b2a9
Packit Service a4b2a9
#ifdef MODULE_MOUNT
Packit Service a4b2a9
int mount_init(void **context);
Packit Service a4b2a9
int mount_reinit(void **context);
Packit Service a4b2a9
int mount_mount(struct autofs_point *ap, const char *root, const char *name, int name_len,
Packit Service a4b2a9
		const char *what, const char *fstype, const char *options, void *context);
Packit Service a4b2a9
int mount_done(void *context);
Packit Service a4b2a9
#endif
Packit Service a4b2a9
typedef int (*mount_init_t) (void **);
Packit Service a4b2a9
typedef int (*mount_reinit_t) (void **);
Packit Service a4b2a9
typedef int (*mount_mount_t) (struct autofs_point *, const char *, const char *, int,
Packit Service a4b2a9
				const char *, const char *, const char *, void *);
Packit Service a4b2a9
typedef int (*mount_done_t) (void *);
Packit Service a4b2a9
Packit Service a4b2a9
struct mount_mod {
Packit Service a4b2a9
	mount_init_t mount_init;
Packit Service a4b2a9
	mount_reinit_t mount_reinit;
Packit Service a4b2a9
	mount_mount_t mount_mount;
Packit Service a4b2a9
	mount_done_t mount_done;
Packit Service a4b2a9
	void *dlhandle;
Packit Service a4b2a9
	void *context;
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
struct mount_mod *open_mount(const char *name, const char *err_prefix);
Packit Service a4b2a9
int reinit_mount(struct mount_mod *mod, const char *name, const char *err_prefix);
Packit Service a4b2a9
int close_mount(struct mount_mod *);
Packit Service a4b2a9
Packit Service a4b2a9
/* buffer management */
Packit Service a4b2a9
Packit Service a4b2a9
size_t _strlen(const char *str, size_t max);
Packit Service a4b2a9
int cat_path(char *buf, size_t len, const char *dir, const char *base);
Packit Service a4b2a9
int ncat_path(char *buf, size_t len,
Packit Service a4b2a9
              const char *dir, const char *base, size_t blen);
Packit Service a4b2a9
int _strncmp(const char *s1, const char *s2, size_t n);
Packit Service a4b2a9
Packit Service a4b2a9
/* Core automount definitions */
Packit Service a4b2a9
Packit Service a4b2a9
#ifndef MNT_DETACH
Packit Service a4b2a9
#define MNT_DETACH	0x00000002	/* Just detach from the tree */
Packit Service a4b2a9
#endif
Packit Service a4b2a9
Packit Service a4b2a9
struct startup_cond {
Packit Service a4b2a9
	pthread_mutex_t mutex;
Packit Service a4b2a9
	pthread_cond_t  cond;
Packit Service a4b2a9
	struct autofs_point *ap;
Packit Service a4b2a9
	char *root;
Packit Service a4b2a9
	unsigned int done;
Packit Service a4b2a9
	unsigned int status;
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
int handle_mounts_startup_cond_init(struct startup_cond *suc);
Packit Service a4b2a9
void handle_mounts_startup_cond_destroy(void *arg);
Packit Service a4b2a9
Packit Service a4b2a9
struct master_readmap_cond {
Packit Service a4b2a9
	pthread_mutex_t mutex;
Packit Service a4b2a9
	pthread_cond_t  cond;
Packit Service a4b2a9
	pthread_t thid;		 /* map reader thread id */
Packit Service a4b2a9
	struct master *master;
Packit Service a4b2a9
	time_t age;		 /* Last time read */
Packit Service a4b2a9
	enum states state;	 /* Next state */
Packit Service a4b2a9
	unsigned int signaled;   /* Condition has been signaled */
Packit Service a4b2a9
	unsigned int busy;	 /* Map read in progress. */
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
struct pending_args {
Packit Service a4b2a9
	pthread_mutex_t mutex;
Packit Service a4b2a9
	pthread_cond_t  cond;
Packit Service a4b2a9
	unsigned int signaled;		/* Condition has been signaled */
Packit Service a4b2a9
	struct autofs_point *ap;	/* autofs mount we are working on */
Packit Service a4b2a9
	int status;			/* Return status */
Packit Service a4b2a9
	int type;			/* Type of packet */
Packit Service a4b2a9
	int ioctlfd;			/* Mount ioctl fd */
Packit Service a4b2a9
	struct mapent_cache *mc;	/* Cache Containing entry */
Packit Service a4b2a9
	char name[PATH_MAX];		/* Name field of the request */
Packit Service a4b2a9
	dev_t dev;			/* device number of mount */
Packit Service a4b2a9
	unsigned int len;		/* Name field len */
Packit Service a4b2a9
	uid_t uid;			/* uid of requester */
Packit Service a4b2a9
	gid_t gid;			/* gid of requester */
Packit Service a4b2a9
	pid_t pid;			/* pid of requestor */
Packit Service a4b2a9
	unsigned long wait_queue_token;	/* Associated kernel wait token */
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
#ifdef INCLUDE_PENDING_FUNCTIONS
Packit Service a4b2a9
static void pending_cond_init(void *arg)
Packit Service a4b2a9
{
Packit Service a4b2a9
	struct pending_args *mt = (struct pending_args *) arg;
Packit Service a4b2a9
	pthread_condattr_t condattrs;
Packit Service a4b2a9
	int status;
Packit Service a4b2a9
Packit Service a4b2a9
	status = pthread_condattr_init(&condattrs);
Packit Service a4b2a9
	if (status)
Packit Service a4b2a9
		fatal(status);
Packit Service a4b2a9
Packit Service a4b2a9
	status = pthread_condattr_setclock(&condattrs, CLOCK_MONOTONIC);
Packit Service a4b2a9
	if (status)
Packit Service a4b2a9
		fatal(status);
Packit Service a4b2a9
Packit Service a4b2a9
	status = pthread_cond_init(&mt->cond, &condattrs);
Packit Service a4b2a9
	if (status)
Packit Service a4b2a9
		fatal(status);
Packit Service a4b2a9
Packit Service a4b2a9
	pthread_condattr_destroy(&condattrs);
Packit Service a4b2a9
}
Packit Service a4b2a9
Packit Service a4b2a9
static void pending_cond_destroy(void *arg)
Packit Service a4b2a9
{
Packit Service a4b2a9
	struct pending_args *mt = (struct pending_args *) arg;
Packit Service a4b2a9
	int status;
Packit Service a4b2a9
	status = pthread_cond_destroy(&mt->cond);
Packit Service a4b2a9
	if (status)
Packit Service a4b2a9
		fatal(status);
Packit Service a4b2a9
}
Packit Service a4b2a9
Packit Service a4b2a9
static void pending_mutex_destroy(void *arg)
Packit Service a4b2a9
{
Packit Service a4b2a9
	struct pending_args *mt = (struct pending_args *) arg;
Packit Service a4b2a9
	int status = pthread_mutex_destroy(&mt->mutex);
Packit Service a4b2a9
	if (status)
Packit Service a4b2a9
		fatal(status);
Packit Service a4b2a9
}
Packit Service a4b2a9
Packit Service a4b2a9
static void free_pending_args(void *arg)
Packit Service a4b2a9
{
Packit Service a4b2a9
	struct pending_args *mt = (struct pending_args *) arg;
Packit Service a4b2a9
	free(mt);
Packit Service a4b2a9
}
Packit Service a4b2a9
Packit Service a4b2a9
static void pending_mutex_lock(void *arg)
Packit Service a4b2a9
{
Packit Service a4b2a9
        struct pending_args *mt = (struct pending_args *) arg;
Packit Service a4b2a9
        int status = pthread_mutex_lock(&mt->mutex);
Packit Service a4b2a9
        if (status)
Packit Service a4b2a9
                fatal(status);
Packit Service a4b2a9
}
Packit Service a4b2a9
Packit Service a4b2a9
static void pending_mutex_unlock(void *arg)
Packit Service a4b2a9
{
Packit Service a4b2a9
        struct pending_args *mt = (struct pending_args *) arg;
Packit Service a4b2a9
        int status = pthread_mutex_unlock(&mt->mutex);
Packit Service a4b2a9
        if (status)
Packit Service a4b2a9
                fatal(status);
Packit Service a4b2a9
}
Packit Service a4b2a9
#endif
Packit Service a4b2a9
Packit Service a4b2a9
struct thread_stdenv_vars {
Packit Service a4b2a9
	uid_t uid;
Packit Service a4b2a9
	gid_t gid;
Packit Service a4b2a9
	char *user;
Packit Service a4b2a9
	char *group;
Packit Service a4b2a9
	char *home;
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
extern pthread_key_t key_thread_stdenv_vars;
Packit Service a4b2a9
Packit Service a4b2a9
extern pthread_key_t key_thread_attempt_id;
Packit Service a4b2a9
Packit Service a4b2a9
struct kernel_mod_version {
Packit Service a4b2a9
	unsigned int major;
Packit Service a4b2a9
	unsigned int minor;
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
/* Enable/disable ghosted directories */
Packit Service a4b2a9
#define MOUNT_FLAG_GHOST		0x0001
Packit Service a4b2a9
Packit Service a4b2a9
/* Directory created for this mount? */
Packit Service a4b2a9
#define MOUNT_FLAG_DIR_CREATED		0x0002
Packit Service a4b2a9
Packit Service a4b2a9
/* Use random policy when selecting a host from which to mount */
Packit Service a4b2a9
#define MOUNT_FLAG_RANDOM_SELECT	0x0004
Packit Service a4b2a9
Packit Service a4b2a9
/* Mount being re-mounted */
Packit Service a4b2a9
#define MOUNT_FLAG_REMOUNT		0x0008
Packit Service a4b2a9
Packit Service a4b2a9
/* Use server weight only for selection */
Packit Service a4b2a9
#define MOUNT_FLAG_USE_WEIGHT_ONLY	0x0010
Packit Service a4b2a9
Packit Service a4b2a9
/* Don't use bind mounts even when system supports them */
Packit Service a4b2a9
#define MOUNT_FLAG_NOBIND		0x0020
Packit Service a4b2a9
Packit Service a4b2a9
/* Use symlinks instead of bind mounting local mounts */
Packit Service a4b2a9
#define MOUNT_FLAG_SYMLINK		0x0040
Packit Service a4b2a9
Packit Service a4b2a9
/* Read amd map even if it's not to be ghosted (browsable) */
Packit Service a4b2a9
#define MOUNT_FLAG_AMD_CACHE_ALL	0x0080
Packit Service a4b2a9
Packit Service 10deab
/* Set mount propagation for bind mounts */
Packit Service 10deab
#define MOUNT_FLAG_SLAVE		0x0100
Packit Service 10deab
#define MOUNT_FLAG_PRIVATE		0x0200
Packit Service 10deab
Packit Service 3ba11c
/* Use strict expire semantics if requested and kernel supports it */
Packit Service 3ba11c
#define MOUNT_FLAG_STRICTEXPIRE		0x0400
Packit Service 3ba11c
Packit Service 4ae89f
/* Indicator for applications to ignore the mount entry */
Packit Service 4ae89f
#define MOUNT_FLAG_IGNORE		0x0800
Packit Service 4ae89f
Packit Service a4b2a9
struct autofs_point {
Packit Service a4b2a9
	pthread_t thid;
Packit Service a4b2a9
	char *path;			/* Mount point name */
Packit Service a4b2a9
	mode_t mode;			/* Mount point mode */
Packit Service a4b2a9
	char *pref;			/* amd prefix */
Packit Service a4b2a9
	int pipefd;			/* File descriptor for pipe */
Packit Service a4b2a9
	int kpipefd;			/* Kernel end descriptor for pipe */
Packit Service a4b2a9
	int ioctlfd;			/* File descriptor for ioctls */
Packit Service a4b2a9
	int logpri_fifo;		/* FIFO used for changing log levels */
Packit Service a4b2a9
	dev_t dev;			/* "Device" number assigned by kernel */
Packit Service a4b2a9
	struct master_mapent *entry;	/* Master map entry for this mount */
Packit Service a4b2a9
	unsigned int type;		/* Type of map direct or indirect */
Packit Service a4b2a9
	time_t exp_timeout;		/* Indirect mount expire timeout */
Packit Service a4b2a9
	time_t exp_runfreq;		/* Frequency for polling for timeouts */
Packit Service a4b2a9
	time_t negative_timeout;	/* timeout in secs for failed mounts */
Packit Service a4b2a9
	unsigned int flags;		/* autofs mount flags */
Packit Service a4b2a9
	unsigned int logopt;		/* Per map logging */
Packit Service a4b2a9
	pthread_t exp_thread;		/* Thread that is expiring */
Packit Service a4b2a9
	pthread_t readmap_thread;	/* Thread that is reading maps */
Packit Service a4b2a9
	enum states state;		/* Current state */
Packit Service a4b2a9
	int state_pipe[2];		/* State change router pipe */
Packit Service a4b2a9
	struct autofs_point *parent;	/* Owner of mounts list for submount */
Packit Service a4b2a9
	pthread_mutex_t mounts_mutex;	/* Protect mount lists */
Packit Service a4b2a9
	struct list_head mounts;	/* List of autofs mounts at current level */
Packit Service a4b2a9
	struct list_head amdmounts;	/* List of non submount amd mounts */
Packit Service a4b2a9
	unsigned int submount;		/* Is this a submount */
Packit Service a4b2a9
	unsigned int shutdown;		/* Shutdown notification */
Packit Service a4b2a9
	unsigned int submnt_count;	/* Number of submounts */
Packit Service a4b2a9
	struct list_head submounts;	/* List of child submounts */
Packit Service a4b2a9
};
Packit Service a4b2a9
Packit Service a4b2a9
/* Foreably unlink existing mounts at startup. */
Packit Service a4b2a9
extern int do_force_unlink;
Packit Service a4b2a9
Packit Service a4b2a9
/* Standard functions used by daemon or modules */
Packit Service a4b2a9
Packit Service a4b2a9
#define	MOUNT_OFFSET_OK		0
Packit Service a4b2a9
#define	MOUNT_OFFSET_FAIL	-1
Packit Service a4b2a9
#define MOUNT_OFFSET_IGNORE	-2
Packit Service a4b2a9
Packit Service a4b2a9
void *handle_mounts(void *arg);
Packit Service a4b2a9
int umount_multi(struct autofs_point *ap, const char *path, int incl);
Packit Service a4b2a9
int do_expire(struct autofs_point *ap, const char *name, int namelen);
Packit Service a4b2a9
void *expire_proc_indirect(void *);
Packit Service a4b2a9
void *expire_proc_direct(void *);
Packit Service a4b2a9
int expire_offsets_direct(struct autofs_point *ap, struct mapent *me, int now);
Packit Service a4b2a9
int mount_autofs_indirect(struct autofs_point *ap, const char *root);
Packit Service c5705c
int do_mount_autofs_direct(struct autofs_point *ap, struct mapent *me, time_t timeout);
Packit Service a4b2a9
int mount_autofs_direct(struct autofs_point *ap);
Packit Service a4b2a9
int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, const char *root, const char *offset);
Packit Service a4b2a9
void submount_signal_parent(struct autofs_point *ap, unsigned int success);
Packit Service a4b2a9
void close_mount_fds(struct autofs_point *ap);
Packit Service a4b2a9
int umount_autofs(struct autofs_point *ap, const char *root, int force);
Packit Service a4b2a9
int umount_autofs_indirect(struct autofs_point *ap, const char *root);
Packit Service 909613
int do_umount_autofs_direct(struct autofs_point *ap, struct mapent *me);
Packit Service a4b2a9
int umount_autofs_direct(struct autofs_point *ap);
Packit Service a4b2a9
int umount_autofs_offset(struct autofs_point *ap, struct mapent *me);
Packit Service a4b2a9
int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_indirect_t *pkt);
Packit Service a4b2a9
int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_direct_t *pkt);
Packit Service a4b2a9
int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missing_indirect_t *pkt);
Packit Service a4b2a9
int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_direct_t *pkt);
Packit Service a4b2a9
void rm_unwanted(struct autofs_point *ap, const char *path, int incl);
Packit Service a4b2a9
int count_mounts(struct autofs_point *ap, const char *path, dev_t dev);
Packit Service a4b2a9
Packit Service a4b2a9
#define mounts_mutex_lock(ap) \
Packit Service a4b2a9
do { \
Packit Service a4b2a9
	int _m_lock = pthread_mutex_lock(&ap->mounts_mutex); \
Packit Service a4b2a9
	if (_m_lock) \
Packit Service a4b2a9
		fatal(_m_lock); \
Packit Service a4b2a9
} while (0)
Packit Service a4b2a9
Packit Service a4b2a9
#define mounts_mutex_unlock(ap) \
Packit Service a4b2a9
do { \
Packit Service a4b2a9
	int _m_unlock = pthread_mutex_unlock(&ap->mounts_mutex); \
Packit Service a4b2a9
	if (_m_unlock) \
Packit Service a4b2a9
		fatal(_m_unlock); \
Packit Service a4b2a9
} while(0)
Packit Service a4b2a9
Packit Service a4b2a9
static inline time_t monotonic_time(time_t *t)
Packit Service a4b2a9
{
Packit Service a4b2a9
	struct timespec ts;
Packit Service a4b2a9
Packit Service a4b2a9
	clock_gettime(CLOCK_MONOTONIC, &ts);
Packit Service a4b2a9
	if (t)
Packit Service a4b2a9
		*t = (time_t) ts.tv_sec;
Packit Service a4b2a9
	return (time_t) ts.tv_sec;
Packit Service a4b2a9
}
Packit Service a4b2a9
Packit Service a4b2a9
/* Expire alarm handling routines */
Packit Service a4b2a9
int alarm_start_handler(void);
Packit Service a4b2a9
int alarm_add(struct autofs_point *ap, time_t seconds);
Packit Service a4b2a9
void alarm_delete(struct autofs_point *ap);
Packit Service a4b2a9
Packit Service a4b2a9
#endif
Packit Service a4b2a9