~ubuntu-branches/debian/wheezy/autofs/wheezy

« back to all changes in this revision

Viewing changes to include/automount.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2008-03-08 01:36:09 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080308013609-cvs4f2ecoyoism02
Tags: 4.1.4+debian-2.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Add -DLDAP_DEPRECATED to CFLAGS, to fix compatibility with OpenLDAP
  2.4 on 64-bit architectures.  Closes: #463419.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ident "$Id: automount.h,v 1.15 2005/01/26 13:03:02 raven Exp $"
 
2
/*
 
3
 * automount.h
 
4
 *
 
5
 * Header file for automounter modules
 
6
 *
 
7
 */
 
8
 
 
9
#ifndef AUTOMOUNT_H
 
10
#define AUTOMOUNT_H
 
11
 
 
12
#include <sys/types.h>
 
13
#include <paths.h>
 
14
#include <limits.h>
 
15
#include <time.h>
 
16
#include "config.h"
 
17
 
 
18
/* We MUST have the paths to mount(8) and umount(8) */
 
19
#ifndef HAVE_MOUNT
 
20
#error Failed to locate mount(8)!
 
21
#endif
 
22
 
 
23
#ifndef HAVE_UMOUNT
 
24
#error Failed to locate umount(8)!
 
25
#endif
 
26
 
 
27
/* The -s (sloppy) option to mount is good, if we have it... */
 
28
 
 
29
#ifdef HAVE_SLOPPY_MOUNT
 
30
#define SLOPPYOPT "-s",         /* For use in spawnl() lists */
 
31
#define SLOPPY    "-s "         /* For use in strings */
 
32
#else
 
33
#define SLOPPYOPT
 
34
#define SLOPPY
 
35
#endif
 
36
 
 
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 */
 
42
 
 
43
/* Constants for lookup modules */
 
44
 
 
45
#define LKP_FAIL        0x0001
 
46
 
 
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
 
54
 
 
55
#define LKP_LOOKUP      0x0100
 
56
#define LKP_GHOST       0x0200
 
57
#define LKP_REREAD      0x0400
 
58
 
 
59
#define LKP_ERR_FORMAT  0x1000
 
60
#define LKP_ERR_MOUNT   0x2000
 
61
#define LKP_NOTSUP      0x4000
 
62
 
 
63
#ifdef DEBUG
 
64
#define DB(x)           do { x; } while(0)
 
65
#else
 
66
#define DB(x)           do { } while(0)
 
67
#endif
 
68
 
 
69
/*
 
70
 * State machine for daemon
 
71
 * 
 
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
 
78
 *
 
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.
 
81
 */
 
82
enum states {
 
83
        ST_INVAL = -1,
 
84
        ST_INIT,
 
85
        ST_READY,
 
86
        ST_EXPIRE,
 
87
        ST_PRUNE,
 
88
        ST_READMAP,
 
89
        ST_SHUTDOWN_PENDING,
 
90
        ST_SHUTDOWN,
 
91
};
 
92
 
 
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;
 
97
};
 
98
 
 
99
struct autofs_point {
 
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 */
 
112
        enum states state;
 
113
        int state_pipe[2];
 
114
        unsigned dir_created;           /* Was a directory created for this
 
115
                                           mount? */
 
116
};
 
117
 
 
118
extern struct autofs_point ap; 
 
119
 
 
120
/* Standard function used by daemon or modules */
 
121
 
 
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);
 
135
 
 
136
/* Prototype for module functions */
 
137
 
 
138
/* lookup module */
 
139
 
 
140
#define AUTOFS_LOOKUP_VERSION 4
 
141
 
 
142
#define KEY_MAX_LEN    NAME_MAX
 
143
#define MAPENT_MAX_LEN 4095
 
144
 
 
145
#ifdef MODULE_LOOKUP
 
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 *);
 
150
#endif
 
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 *);
 
155
 
 
156
struct lookup_mod {
 
157
        lookup_init_t lookup_init;
 
158
        lookup_ghost_t lookup_ghost;
 
159
        lookup_mount_t lookup_mount;
 
160
        lookup_done_t lookup_done;
 
161
        void *dlhandle;
 
162
        void *context;
 
163
};
 
164
 
 
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 *);
 
168
 
 
169
/* parse module */
 
170
 
 
171
#define AUTOFS_PARSE_VERSION 3
 
172
 
 
173
#ifdef MODULE_PARSE
 
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 *);
 
178
#endif
 
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 *);
 
182
 
 
183
struct parse_mod {
 
184
        parse_init_t parse_init;
 
185
        parse_mount_t parse_mount;
 
186
        parse_done_t parse_done;
 
187
        void *dlhandle;
 
188
        void *context;
 
189
};
 
190
 
 
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 *);
 
194
 
 
195
/* mount module */
 
196
 
 
197
#define AUTOFS_MOUNT_VERSION 4
 
198
 
 
199
#ifdef MODULE_MOUNT
 
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);
 
204
#endif
 
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 *);
 
209
 
 
210
struct mount_mod {
 
211
        mount_init_t mount_init;
 
212
        mount_mount_t mount_mount;
 
213
        mount_done_t mount_done;
 
214
        void *dlhandle;
 
215
        void *context;
 
216
};
 
217
 
 
218
struct mount_mod *open_mount(const char *name, const char *err_prefix);
 
219
int close_mount(struct mount_mod *);
 
220
 
 
221
/* mapent cache definition */
 
222
 
 
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
 
228
 
 
229
struct mapent_cache {
 
230
        struct mapent_cache *next;
 
231
        char *key;
 
232
        char *mapent;
 
233
        time_t age;
 
234
};
 
235
 
 
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);
 
248
 
 
249
/* buffer management */
 
250
 
 
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);
 
255
 
 
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
 
262
 
 
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);
 
267
 
 
268
/* mount table utilities */
 
269
struct mnt_list {
 
270
        char *path;
 
271
        char *fs_type;
 
272
        pid_t pid;
 
273
        time_t last_access;
 
274
        struct mnt_list *next;
 
275
};
 
276
 
 
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 *);
 
284
 
 
285
/* log notification */
 
286
extern int do_verbose;
 
287
extern int do_debug;
 
288
 
 
289
#define info(msg, args...)              \
 
290
if (do_verbose || do_debug)             \
 
291
        syslog(LOG_INFO, msg, ##args);
 
292
 
 
293
#define warn(msg, args...)                      \
 
294
if (do_verbose || do_debug)             \
 
295
        syslog(LOG_WARNING, msg, ##args);
 
296
 
 
297
#define error(msg, args...)     syslog(LOG_ERR, msg, ##args);
 
298
 
 
299
#define crit(msg, args...)      syslog(LOG_CRIT, msg, ##args);
 
300
 
 
301
#define debug(msg, args...)             \
 
302
if (do_debug)                           \
 
303
        syslog(LOG_DEBUG, msg, ##args);
 
304
 
 
305
#endif
 
306