~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to shlibs/mount/src/mountP.h

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * mountP.h - private library header file
3
 
 *
4
 
 * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
5
 
 *
6
 
 * This file may be redistributed under the terms of the
7
 
 * GNU Lesser General Public License.
8
 
 */
9
 
 
10
 
#ifndef _LIBMOUNT_PRIVATE_H
11
 
#define _LIBMOUNT_PRIVATE_H
12
 
 
13
 
#include <sys/types.h>
14
 
#include <errno.h>
15
 
#include "c.h"
16
 
 
17
 
#define USE_UNSTABLE_LIBMOUNT_API
18
 
 
19
 
#include "libmount.h"
20
 
#include "list.h"
21
 
 
22
 
/* features */
23
 
#define CONFIG_LIBMOUNT_ASSERT
24
 
#define CONFIG_LIBMOUNT_DEBUG
25
 
 
26
 
#ifdef CONFIG_LIBMOUNT_ASSERT
27
 
#include <assert.h>
28
 
#endif
29
 
 
30
 
/*
31
 
 * Debug
32
 
 */
33
 
#if defined(TEST_PROGRAM) && !defined(LIBMOUNT_DEBUG)
34
 
#define CONFIG_LIBMOUNT_DEBUG
35
 
#endif
36
 
 
37
 
#define MNT_DEBUG_INIT          (1 << 1)
38
 
#define MNT_DEBUG_CACHE         (1 << 2)
39
 
#define MNT_DEBUG_OPTIONS       (1 << 3)
40
 
#define MNT_DEBUG_LOCKS         (1 << 4)
41
 
#define MNT_DEBUG_TAB           (1 << 5)
42
 
#define MNT_DEBUG_FS            (1 << 6)
43
 
#define MNT_DEBUG_OPTS          (1 << 7)
44
 
#define MNT_DEBUG_UPDATE        (1 << 8)
45
 
#define MNT_DEBUG_UTILS         (1 << 9)
46
 
#define MNT_DEBUG_CXT           (1 << 10)
47
 
#define MNT_DEBUG_ALL           0xFFFF
48
 
 
49
 
#ifdef CONFIG_LIBMOUNT_DEBUG
50
 
# include <stdio.h>
51
 
# include <stdarg.h>
52
 
 
53
 
# define DBG(m,x)       do { \
54
 
                                if ((MNT_DEBUG_ ## m) & libmount_debug_mask) {\
55
 
                                        fprintf(stderr, "libmount: %8s: ", # m); \
56
 
                                        x; \
57
 
                                } \
58
 
                        } while(0)
59
 
 
60
 
# define DBG_FLUSH      do { fflush(stderr); } while(0)
61
 
 
62
 
extern int libmount_debug_mask;
63
 
 
64
 
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
65
 
mnt_debug(const char *mesg, ...)
66
 
{
67
 
        va_list ap;
68
 
        va_start(ap, mesg);
69
 
        vfprintf(stderr, mesg, ap);
70
 
        va_end(ap);
71
 
        fputc('\n', stderr);
72
 
}
73
 
 
74
 
static inline void __attribute__ ((__format__ (__printf__, 2, 3)))
75
 
mnt_debug_h(void *handler, const char *mesg, ...)
76
 
{
77
 
        va_list ap;
78
 
 
79
 
        fprintf(stderr, "[%p]: ", handler);
80
 
        va_start(ap, mesg);
81
 
        vfprintf(stderr, mesg, ap);
82
 
        va_end(ap);
83
 
        fputc('\n', stderr);
84
 
}
85
 
 
86
 
#else /* !CONFIG_LIBMOUNT_DEBUG */
87
 
# define DBG(m,x) do { ; } while(0)
88
 
# define DBG_FLUSH do { ; } while(0)
89
 
#endif
90
 
 
91
 
/* extension for files in the /etc/fstab.d directory */
92
 
#define MNT_MNTTABDIR_EXT       ".fstab"
93
 
 
94
 
/* library private paths */
95
 
#define MNT_RUNTIME_TOPDIR      "/run"
96
 
#define MNT_RUNTIME_TOPDIR_OLD  "/dev"
97
 
 
98
 
#define MNT_PATH_UTAB           MNT_RUNTIME_TOPDIR "/mount/utab"
99
 
#define MNT_PATH_UTAB_OLD       MNT_RUNTIME_TOPDIR_OLD "/.mount/utab"
100
 
 
101
 
#define MNT_UTAB_HEADER "# libmount utab file\n"
102
 
 
103
 
#ifdef TEST_PROGRAM
104
 
struct libmnt_test {
105
 
        const char      *name;
106
 
        int             (*body)(struct libmnt_test *ts, int argc, char *argv[]);
107
 
        const char      *usage;
108
 
};
109
 
 
110
 
/* test.c */
111
 
extern int mnt_run_test(struct libmnt_test *tests, int argc, char *argv[]);
112
 
#endif
113
 
 
114
 
/* utils.c */
115
 
extern int endswith(const char *s, const char *sx);
116
 
extern int startswith(const char *s, const char *sx);
117
 
 
118
 
extern char *mnt_get_username(const uid_t uid);
119
 
extern int mnt_get_uid(const char *username, uid_t *uid);
120
 
extern int mnt_get_gid(const char *groupname, gid_t *gid);
121
 
extern int mnt_in_group(gid_t gid);
122
 
 
123
 
extern char *mnt_get_mountpoint(const char *path);
124
 
extern char *mnt_get_fs_root(const char *path, const char *mountpoint);
125
 
extern int mnt_open_uniq_filename(const char *filename, char **name);
126
 
extern int mnt_has_regular_utab(const char **utab, int *writable);
127
 
extern const char *mnt_get_utab_path(void);
128
 
 
129
 
extern int mnt_get_filesystems(char ***filesystems, const char *pattern);
130
 
extern void mnt_free_filesystems(char **filesystems);
131
 
 
132
 
/*
133
 
 * Generic iterator
134
 
 */
135
 
struct libmnt_iter {
136
 
        struct list_head        *p;             /* current position */
137
 
        struct list_head        *head;          /* start position */
138
 
        int                     direction;      /* MNT_ITER_{FOR,BACK}WARD */
139
 
};
140
 
 
141
 
#define IS_ITER_FORWARD(_i)     ((_i)->direction == MNT_ITER_FORWARD)
142
 
#define IS_ITER_BACKWARD(_i)    ((_i)->direction == MNT_ITER_BACKWARD)
143
 
 
144
 
#define MNT_ITER_INIT(itr, list) \
145
 
        do { \
146
 
                (itr)->p = IS_ITER_FORWARD(itr) ? \
147
 
                                (list)->next : (list)->prev; \
148
 
                (itr)->head = (list); \
149
 
        } while(0)
150
 
 
151
 
#define MNT_ITER_ITERATE(itr, res, restype, member) \
152
 
        do { \
153
 
                res = list_entry((itr)->p, restype, member); \
154
 
                (itr)->p = IS_ITER_FORWARD(itr) ? \
155
 
                                (itr)->p->next : (itr)->p->prev; \
156
 
        } while(0)
157
 
 
158
 
 
159
 
/*
160
 
 * This struct represents one entry in mtab/fstab/mountinfo file.
161
 
 * (note that fstab[1] means the first column from fstab, and so on...)
162
 
 */
163
 
struct libmnt_fs {
164
 
        struct list_head ents;
165
 
 
166
 
        int             id;             /* mountinfo[1]: ID */
167
 
        int             parent;         /* moutninfo[2]: parent */
168
 
        dev_t           devno;          /* moutninfo[3]: st_dev */
169
 
 
170
 
        char            *bindsrc;       /* utab, full path from fstab[1] for bind mounts */
171
 
 
172
 
        char            *source;        /* fstab[1], mountinfo[10]:
173
 
                                         * source dev, file, dir or TAG */
174
 
        char            *tagname;       /* fstab[1]: tag name - "LABEL", "UUID", ..*/
175
 
        char            *tagval;        /*           tag value */
176
 
 
177
 
        char            *root;          /* mountinfo[4]: root of the mount within the FS */
178
 
        char            *target;        /* mountinfo[5], fstab[2]: mountpoint */
179
 
        char            *fstype;        /* mountinfo[9], fstab[3]: filesystem type */
180
 
 
181
 
        char            *vfs_optstr;    /* mountinfo[6]: fs-independent (VFS) options */
182
 
        char            *fs_optstr;     /* mountinfo[11]: fs-depend options */
183
 
        char            *user_optstr;   /* userspace mount options */
184
 
        char            *attrs;         /* mount attributes */
185
 
 
186
 
        int             freq;           /* fstab[5]:  dump frequency in days */
187
 
        int             passno;         /* fstab[6]: pass number on parallel fsck */
188
 
 
189
 
        int             flags;          /* MNT_FS_* flags */
190
 
 
191
 
        void            *userdata;      /* library independent data */
192
 
};
193
 
 
194
 
/*
195
 
 * fs flags
196
 
 */
197
 
#define MNT_FS_PSEUDO   (1 << 1) /* pseudo filesystem */
198
 
#define MNT_FS_NET      (1 << 2) /* network filesystem */
199
 
#define MNT_FS_SWAP     (1 << 3) /* swap device */
200
 
#define MNT_FS_KERNEL   (1 << 4) /* data from /proc/{mounts,self/mountinfo} */
201
 
#define MNT_FS_MERGED   (1 << 5) /* already merged data from /run/mount/utab */
202
 
 
203
 
extern int __mnt_fs_get_flags(struct libmnt_fs *fs);
204
 
extern int __mnt_fs_set_flags(struct libmnt_fs *fs, int flags);
205
 
 
206
 
 
207
 
/*
208
 
 * mtab/fstab/mountinfo file
209
 
 */
210
 
struct libmnt_table {
211
 
        int             fmt;            /* MNT_FMT_* file format */
212
 
        int             nents;          /* number of valid entries */
213
 
 
214
 
        struct libmnt_cache *cache;             /* canonicalized paths/tags cache */
215
 
 
216
 
        int             (*errcb)(struct libmnt_table *tb,
217
 
                                 const char *filename, int line);
218
 
 
219
 
        struct list_head        ents;   /* list of entries (libmnt_fs) */
220
 
};
221
 
 
222
 
extern struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt);
223
 
 
224
 
/*
225
 
 * Tab file format
226
 
 */
227
 
enum {
228
 
        MNT_FMT_GUESS,
229
 
        MNT_FMT_FSTAB,                  /* /etc/{fs,m}tab */
230
 
        MNT_FMT_MTAB = MNT_FMT_FSTAB,   /* alias */
231
 
        MNT_FMT_MOUNTINFO,              /* /proc/#/mountinfo */
232
 
        MNT_FMT_UTAB                    /* /dev/.mount/utab */
233
 
};
234
 
 
235
 
 
236
 
/*
237
 
 * Mount context -- high-level API
238
 
 */
239
 
struct libmnt_context
240
 
{
241
 
        int     action;         /* MNT_ACT_{MOUNT,UMOUNT} */
242
 
        int     restricted;     /* root or not? */
243
 
 
244
 
        char    *fstype_pattern;        /* for mnt_match_fstype() */
245
 
        char    *optstr_pattern;        /* for mnt_match_options() */
246
 
 
247
 
        struct libmnt_fs *fs;           /* filesystem description (type, mountpopint, device, ...) */
248
 
 
249
 
        struct libmnt_table *fstab;     /* fstab (or mtab for some remounts) entires */
250
 
        struct libmnt_table *mtab;      /* mtab entries */
251
 
 
252
 
        int     optsmode;       /* fstab optstr mode MNT_OPTSMODE_{AUTO,FORCE,IGNORE} */
253
 
 
254
 
        unsigned long   mountflags;     /* final mount(2) flags */
255
 
        const void      *mountdata;     /* final mount(2) data, string or binary data */
256
 
 
257
 
        unsigned long   user_mountflags;        /* MNT_MS_* (loop=, user=, ...) */
258
 
 
259
 
        struct libmnt_cache     *cache; /* paths cache */
260
 
        struct libmnt_lock      *lock;  /* mtab lock */
261
 
        struct libmnt_update    *update;/* mtab/utab update */
262
 
 
263
 
        const char      *mtab_path; /* writable mtab */
264
 
        int             mtab_writable; /* ismtab writeable */
265
 
 
266
 
        const char      *utab_path; /* writable mtab */
267
 
        int             utab_writable; /* ismtab writeable */
268
 
 
269
 
        int     flags;          /* private context flags */
270
 
        int     ambi;           /* libblkid returns ambivalent result */
271
 
 
272
 
        char    *helper;        /* name of the used /sbin/[u]mount.<type> helper */
273
 
        int     helper_status;  /* helper wait(2) status */
274
 
        int     helper_exec_status; /* 1: not called yet, 0: success, <0: -errno */
275
 
 
276
 
        char    *orig_user;     /* original (non-fixed) user= option */
277
 
 
278
 
        int     syscall_status; /* 1: not called yet, 0: success, <0: -errno */
279
 
};
280
 
 
281
 
/* flags */
282
 
#define MNT_FL_NOMTAB           (1 << 1)
283
 
#define MNT_FL_FAKE             (1 << 2)
284
 
#define MNT_FL_SLOPPY           (1 << 3)
285
 
#define MNT_FL_VERBOSE          (1 << 4)
286
 
#define MNT_FL_NOHELPERS        (1 << 5)
287
 
#define MNT_FL_LOOPDEL          (1 << 6)
288
 
#define MNT_FL_LAZY             (1 << 7)
289
 
#define MNT_FL_FORCE            (1 << 8)
290
 
#define MNT_FL_NOCANONICALIZE   (1 << 9)
291
 
#define MNT_FL_RDONLY_UMOUNT    (1 << 11)       /* remount,ro after EBUSY umount(2) */
292
 
 
293
 
#define MNT_FL_EXTERN_FS        (1 << 15)       /* cxt->fs is not private */
294
 
#define MNT_FL_EXTERN_FSTAB     (1 << 16)       /* cxt->fstab is not private */
295
 
#define MNT_FL_EXTERN_CACHE     (1 << 17)       /* cxt->cache is not private */
296
 
 
297
 
#define MNT_FL_MOUNTDATA        (1 << 20)
298
 
#define MNT_FL_TAB_APPLIED      (1 << 21)       /* mtab/fstab merged to cxt->fs */
299
 
#define MNT_FL_MOUNTFLAGS_MERGED (1 << 22)      /* MS_* flags was read from optstr */
300
 
#define MNT_FL_SAVED_USER       (1 << 23)
301
 
#define MNT_FL_PREPARED         (1 << 24)
302
 
#define MNT_FL_HELPER           (1 << 25)       /* [u]mount.<type> */
303
 
 
304
 
/* default flags */
305
 
#define MNT_FL_DEFAULT          0
306
 
 
307
 
/* optmap.c */
308
 
extern const struct libmnt_optmap *mnt_optmap_get_entry(
309
 
                             struct libmnt_optmap const **maps,
310
 
                             int nmaps, const char *name,
311
 
                             size_t namelen,
312
 
                             const struct libmnt_optmap **mapent);
313
 
 
314
 
/* optstr.c */
315
 
extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end);
316
 
extern int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next);
317
 
extern int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next);
318
 
extern int mnt_optstr_fix_secontext(char **optstr, char *value, size_t valsz, char **next);
319
 
extern int mnt_optstr_fix_user(char **optstr);
320
 
 
321
 
/* fs.c */
322
 
extern struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs);
323
 
extern int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source);
324
 
extern int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype);
325
 
 
326
 
/* context.c */
327
 
extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
328
 
extern int mnt_context_prepare_target(struct libmnt_context *cxt);
329
 
extern int mnt_context_guess_fstype(struct libmnt_context *cxt);
330
 
extern int mnt_context_prepare_helper(struct libmnt_context *cxt,
331
 
                                      const char *name, const char *type);
332
 
extern int mnt_context_prepare_update(struct libmnt_context *cxt);
333
 
extern struct libmnt_fs *mnt_context_get_fs(struct libmnt_context *cxt);
334
 
extern int mnt_context_merge_mflags(struct libmnt_context *cxt);
335
 
extern int mnt_context_update_tabs(struct libmnt_context *cxt);
336
 
 
337
 
extern int mnt_context_umount_setopt(struct libmnt_context *cxt, int c, char *arg);
338
 
extern int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg);
339
 
 
340
 
/* tab_update.c */
341
 
extern struct libmnt_fs *mnt_update_get_fs(struct libmnt_update *upd);
342
 
extern int mnt_update_set_filename(struct libmnt_update *upd,
343
 
                                   const char *filename, int userspace_only);
344
 
 
345
 
#endif /* _LIBMOUNT_PRIVATE_H */