1
#ident "$Id: automount.h,v 1.15 2005/01/26 13:03:02 raven Exp $"
5
* Header file for automounter modules
12
#include <sys/types.h>
18
/* We MUST have the paths to mount(8) and umount(8) */
20
#error Failed to locate mount(8)!
24
#error Failed to locate umount(8)!
27
/* The -s (sloppy) option to mount is good, if we have it... */
29
#ifdef HAVE_SLOPPY_MOUNT
30
#define SLOPPYOPT "-s", /* For use in spawnl() lists */
31
#define SLOPPY "-s " /* For use in strings */
37
#define DEFAULT_TIMEOUT (5*60) /* 5 minutes */
38
#define AUTOFS_LOCK "/var/lock/autofs" /* To serialize access to mount */
39
#define MOUNTED_LOCK _PATH_MOUNTED "~" /* mounts' lock file */
40
#define MTAB_NOTUPDATED 0x1000 /* mtab succeded but not updated */
41
#define NOT_MOUNTED 0x0100 /* path notmounted */
43
/* Constants for lookup modules */
45
#define LKP_FAIL 0x0001
47
#define LKP_INDIRECT 0x0002
48
#define LKP_DIRECT 0x0004
49
#define LKP_NOMATCH 0x0008
50
#define LKP_MATCH 0x0010
51
#define LKP_NEXT 0x0020
52
#define LKP_MOUNT 0x0040
53
#define LKP_WILD 0x0080
55
#define LKP_LOOKUP 0x0100
56
#define LKP_GHOST 0x0200
57
#define LKP_REREAD 0x0400
59
#define LKP_ERR_FORMAT 0x1000
60
#define LKP_ERR_MOUNT 0x2000
61
#define LKP_NOTSUP 0x4000
64
#define DB(x) do { x; } while(0)
66
#define DB(x) do { } while(0)
70
* State machine for daemon
72
* READY - reads from pipe; performs mount/umount operations
73
* PRUNE - generates prune events in subprocess; reads from pipe
74
* READMAP - read read map for maps taht use cache
75
* EXPIRE - generates expire events in subprocess; reads from pipe
76
* SHUTDOWN_PENDING - as prune, but goes to SHUTDOWN when done
77
* SHUTDOWN - unmount autofs, exit
79
* Signals TERM, USR1, USR2, HUP and ALRM are blocked in all states except
80
* READY. SIGCHLD is blocked when protecting the manipulating mount list.
93
struct pending_mount {
94
pid_t pid; /* Which process is mounting for us */
95
unsigned long wait_queue_token; /* Associated kernel wait token */
96
volatile struct pending_mount *next;
100
char *path; /* Mount point name */
101
int pipefd; /* File descriptor for pipe */
102
int ioctlfd; /* File descriptor for ioctls */
103
dev_t dev; /* "Device" number assigned by kernel */
104
char *maptype; /* Type of map "file", "NIS", etc */
105
unsigned int type; /* Type of map direct or indirect */
106
time_t exp_timeout; /* Timeout for expiring mounts */
107
time_t exp_runfreq; /* Frequency for polling for timeouts */
108
unsigned ghost; /* Enable/disable gohsted directories */
109
volatile pid_t exp_process; /* Process that is currently expiring */
110
volatile struct pending_mount *mounts; /* Pending mount queue */
111
struct lookup_mod *lookup; /* Lookup module */
114
unsigned dir_created; /* Was a directory created for this
118
extern struct autofs_point ap;
120
/* Standard function used by daemon or modules */
122
int aquire_lock(void);
123
void release_lock(void);
124
int spawnll(int logpri, const char *prog, ...);
125
int spawnl(int logpri, const char *prog, ...);
126
int spawnv(int logpri, const char *prog, const char *const *argv);
127
void reset_signals(void);
128
void ignore_signals(void);
129
void discard_pending(int sig);
130
int signal_children(int sig);
131
int do_mount(const char *root, const char *name, int name_len,
132
const char *what, const char *fstype, const char *options);
133
int mkdir_path(const char *path, mode_t mode);
134
int rmdir_path(const char *path);
136
/* Prototype for module functions */
140
#define AUTOFS_LOOKUP_VERSION 4
142
#define KEY_MAX_LEN NAME_MAX
143
#define MAPENT_MAX_LEN 4095
146
int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context);
147
int lookup_ghost(const char *, int, time_t, void *);
148
int lookup_mount(const char *, const char *, int, void *);
149
int lookup_done(void *);
151
typedef int (*lookup_init_t) (const char *, int, const char *const *, void **);
152
typedef int (*lookup_ghost_t) (const char *, int, time_t, void *);
153
typedef int (*lookup_mount_t) (const char *, const char *, int, void *);
154
typedef int (*lookup_done_t) (void *);
157
lookup_init_t lookup_init;
158
lookup_ghost_t lookup_ghost;
159
lookup_mount_t lookup_mount;
160
lookup_done_t lookup_done;
165
struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
166
const char *mapfmt, int argc, const char *const *argv);
167
int close_lookup(struct lookup_mod *);
171
#define AUTOFS_PARSE_VERSION 3
174
int parse_init(int argc, const char *const *argv, void **context);
175
int parse_mount(const char *root, const char *name,
176
int name_len, const char *mapent, void *context);
177
int parse_done(void *);
179
typedef int (*parse_init_t) (int, const char *const *, void **);
180
typedef int (*parse_mount_t) (const char *, const char *, int, const char *, void *);
181
typedef int (*parse_done_t) (void *);
184
parse_init_t parse_init;
185
parse_mount_t parse_mount;
186
parse_done_t parse_done;
191
struct parse_mod *open_parse(const char *name, const char *err_prefix,
192
int argc, const char *const *argv);
193
int close_parse(struct parse_mod *);
197
#define AUTOFS_MOUNT_VERSION 4
200
int mount_init(void **context);
201
int mount_mount(const char *root, const char *name, int name_len,
202
const char *what, const char *fstype, const char *options, void *context);
203
int mount_done(void *context);
205
typedef int (*mount_init_t) (void **);
206
typedef int (*mount_mount_t) (const char *, const char *, int, const char *, const char *,
207
const char *, void *);
208
typedef int (*mount_done_t) (void *);
211
mount_init_t mount_init;
212
mount_mount_t mount_mount;
213
mount_done_t mount_done;
218
struct mount_mod *open_mount(const char *name, const char *err_prefix);
219
int close_mount(struct mount_mod *);
221
/* mapent cache definition */
223
#define CHE_FAIL 0x0000
224
#define CHE_OK 0x0001
225
#define CHE_UPDATED 0x0002
226
#define CHE_RMPATH 0x0004
227
#define CHE_MISSING 0x0008
229
struct mapent_cache {
230
struct mapent_cache *next;
236
void cache_init(void);
237
struct mapent_cache *cache_lookup(const char *key);
238
struct mapent_cache *cache_lookup_next(struct mapent_cache *me);
239
struct mapent_cache *cache_lookup_first(void);
240
struct mapent_cache *cache_partial_match(const char *prefix);
241
int cache_add(const char *root, const char *key, const char *mapent, time_t age);
242
int cache_update(const char *root, const char *key, const char *mapent, time_t age);
243
int cache_delete(const char *root, const char *key, int rmpath);
244
void cache_clean(const char *root, time_t age);
245
void cache_release(void);
246
int cache_ghost(const char *root, int is_ghosted,
247
const char *map, const char *type, struct parse_mod *parse);
249
/* buffer management */
251
int _strlen(const char *str, size_t max);
252
int cat_path(char *buf, size_t len, const char *dir, const char *base);
253
int ncat_path(char *buf, size_t len,
254
const char *dir, const char *base, size_t blen);
256
/* rpc helper subs */
257
#define RPC_PING_FAIL 0x0000
258
#define RPC_PING_V2 NFS2_VERSION
259
#define RPC_PING_V3 NFS3_VERSION
260
#define RPC_PING_UDP 0x0100
261
#define RPC_PING_TCP 0x0200
263
unsigned int rpc_ping(const char *host, long seconds, long micros);
264
int rpc_time(const char *host,
265
unsigned int ping_vers, unsigned int ping_proto,
266
long seconds, long micros, double *result);
268
/* mount table utilities */
274
struct mnt_list *next;
277
struct mnt_list *get_mnt_list(const char *table, const char *path, int include);
278
struct mnt_list *reverse_mnt_list(struct mnt_list *list);
279
struct mnt_list *get_base_mnt_list(struct mnt_list *list);
280
void free_mnt_list(struct mnt_list *list);
281
int is_mounted(const char *table, const char *path);
282
int has_fstab_option(const char *path, const char *opt);
283
int allow_owner_mount(const char *);
285
/* log notification */
286
extern int do_verbose;
289
#define info(msg, args...) \
290
if (do_verbose || do_debug) \
291
syslog(LOG_INFO, msg, ##args);
293
#define warn(msg, args...) \
294
if (do_verbose || do_debug) \
295
syslog(LOG_WARNING, msg, ##args);
297
#define error(msg, args...) syslog(LOG_ERR, msg, ##args);
299
#define crit(msg, args...) syslog(LOG_CRIT, msg, ##args);
301
#define debug(msg, args...) \
303
syslog(LOG_DEBUG, msg, ##args);