1/*
2 * mount.h - libmount API
3 *
4 * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#ifndef _LIBMOUNT_MOUNT_H
22#define _LIBMOUNT_MOUNT_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#include <stdio.h>
29#include <mntent.h>
30#include <sys/types.h>
31
32#define LIBMOUNT_VERSION   "@LIBMOUNT_VERSION@"
33
34/**
35 * libmnt_cache:
36 *
37 * Stores canonicalized paths and evaluated tags
38 */
39struct libmnt_cache;
40
41/**
42 * libmnt_lock:
43 *
44 * Stores information about the locked file (e.g. /etc/mtab)
45 */
46struct libmnt_lock;
47
48/**
49 * libmnt_iter:
50 *
51 * Generic iterator (stores state about lists)
52 */
53struct libmnt_iter;
54
55/**
56 * libmnt_optmap:
57 *
58 * Mount options description (map)
59 */
60struct libmnt_optmap
61{
62	const char	*name;	 /* option name[=%<type>] (e.g. "loop[=%s]") */
63	int		id;	 /* option ID or MS_* flags (e.g MS_RDONLY) */
64	int		mask;	 /* MNT_{NOMTAB,INVERT,...} mask */
65};
66
67/*
68 * mount options map masks
69 */
70#define MNT_INVERT	(1 << 1) /* invert the mountflag */
71#define MNT_NOMTAB	(1 << 2) /* skip in the mtab option string */
72#define MNT_PREFIX	(1 << 3) /* prefix used for some options (e.g. "x-foo") */
73#define MNT_NOHLPS	(1 << 4) /* don't add the option to mount.<type> helpers command line */
74
75/**
76 * libmnt_fs:
77 *
78 * Parsed fstab/mtab/mountinfo entry
79 */
80struct libmnt_fs;
81
82/**
83 * libmnt_table:
84 *
85 * List of struct libmnt_fs entries (parsed fstab/mtab/mountinfo)
86 */
87struct libmnt_table;
88
89/**
90 * libmnt_update
91 *
92 * /etc/mtab or utab update description
93 */
94struct libmnt_update;
95
96/**
97 * libmnt_context
98 *
99 * Mount/umount status
100 */
101struct libmnt_context;
102
103/**
104 * libmnt_tabdiff:
105 *
106 * Stores mountinfo state
107 */
108struct libmnt_tabdiff;
109
110/*
111 * Actions
112 */
113enum {
114	MNT_ACT_MOUNT = 1,
115	MNT_ACT_UMOUNT
116};
117
118/*
119 * Errors -- by default libmount returns -errno for generic errors (ENOMEM,
120 * EINVAL, ...) and for mount(2) errors, but for some specific operations it
121 * returns private error codes. Note that maximum system errno value should be
122 * 4095 on UNIXes.
123 *
124 * See also mnt_context_get_syscall_errno() and mnt_context_get_helper_status().
125 */
126/**
127 * MNT_ERR_NOFSTAB:
128 *
129 * not found required entry in fstab
130 */
131#define MNT_ERR_NOFSTAB      5000
132/**
133 * MNT_ERR_NOFSTYPE:
134 *
135 * failed to detect filesystem type
136 */
137#define MNT_ERR_NOFSTYPE     5001
138/**
139 * MNT_ERR_NOSOURCE:
140 *
141 * required mount source undefined
142 */
143#define MNT_ERR_NOSOURCE     5002
144/**
145 * MNT_ERR_LOOPDEV:
146 *
147 * loopdev setup failed, errno set by libc
148 */
149#define MNT_ERR_LOOPDEV	     5003
150/**
151 * MNT_ERR_MOUNTOPT:
152 *
153 * failed to parse/use userspace mount options
154 */
155#define MNT_ERR_MOUNTOPT     5004
156/**
157 * MNT_ERR_APPLYFLAGS:
158 *
159 * failed to apply MS_PROPAGATION flags
160 */
161#define MNT_ERR_APPLYFLAGS   5005
162/**
163 * MNT_ERR_AMBIFS:
164 *
165 * libblkid detected more filesystems on the device
166 */
167#define MNT_ERR_AMBIFS       5006
168
169#ifndef __GNUC_PREREQ
170# if defined __GNUC__ && defined __GNUC_MINOR__
171#  define __GNUC_PREREQ(maj, min)  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
172# else
173#  define __GNUC_PREREQ(maj, min) 0
174# endif
175#endif
176
177#ifndef __ul_attribute__
178# if __GNUC_PREREQ (3, 4)
179#  define __ul_attribute__(_a_) __attribute__(_a_)
180# else
181#  define __ul_attribute__(_a_)
182# endif
183#endif
184
185
186/* init.c */
187extern void mnt_init_debug(int mask);
188
189/* version.c */
190extern int mnt_parse_version_string(const char *ver_string);
191extern int mnt_get_library_version(const char **ver_string);
192extern int mnt_get_library_features(const char ***features);
193
194/* utils.c */
195extern char *mnt_mangle(const char *str)
196			__ul_attribute__((warn_unused_result));
197extern char *mnt_unmangle(const char *str)
198			__ul_attribute__((warn_unused_result));
199
200extern int mnt_tag_is_valid(const char *tag);
201extern int mnt_fstype_is_netfs(const char *type);
202extern int mnt_fstype_is_pseudofs(const char *type);
203
204extern int mnt_match_fstype(const char *type, const char *pattern)
205			__ul_attribute__((warn_unused_result));
206extern int mnt_match_options(const char *optstr, const char *pattern)
207			__ul_attribute__((warn_unused_result));
208extern const char *mnt_get_fstab_path(void);
209extern const char *mnt_get_swaps_path(void);
210extern const char *mnt_get_mtab_path(void);
211extern int mnt_has_regular_mtab(const char **mtab, int *writable);
212extern char *mnt_get_mountpoint(const char *path)
213			__ul_attribute__((warn_unused_result));
214
215/* cache.c */
216extern struct libmnt_cache *mnt_new_cache(void)
217			__ul_attribute__((warn_unused_result));
218extern void mnt_free_cache(struct libmnt_cache *cache);
219
220extern void mnt_ref_cache(struct libmnt_cache *cache);
221extern void mnt_unref_cache(struct libmnt_cache *cache);
222
223extern int mnt_cache_set_targets(struct libmnt_cache *cache,
224				struct libmnt_table *mtab);
225extern int mnt_cache_read_tags(struct libmnt_cache *cache, const char *devname);
226
227extern int mnt_cache_device_has_tag(struct libmnt_cache *cache,
228				const char *devname,
229                                const char *token,
230				const char *value);
231
232extern char *mnt_cache_find_tag_value(struct libmnt_cache *cache,
233				const char *devname, const char *token);
234
235extern char *mnt_get_fstype(const char *devname, int *ambi,
236			    struct libmnt_cache *cache)
237			__ul_attribute__((warn_unused_result));
238extern char *mnt_resolve_path(const char *path, struct libmnt_cache *cache)
239			__ul_attribute__((warn_unused_result));
240extern char *mnt_resolve_target(const char *path, struct libmnt_cache *cache)
241			__ul_attribute__((warn_unused_result));
242extern char *mnt_resolve_tag(const char *token, const char *value,
243			     struct libmnt_cache *cache)
244			__ul_attribute__((warn_unused_result));
245extern char *mnt_resolve_spec(const char *spec, struct libmnt_cache *cache)
246			__ul_attribute__((warn_unused_result));
247extern char *mnt_pretty_path(const char *path, struct libmnt_cache *cache)
248			__ul_attribute__((warn_unused_result));
249
250/* optstr.c */
251extern int mnt_optstr_next_option(char **optstr, char **name, size_t *namesz,
252				char **value, size_t *valuesz);
253extern int mnt_optstr_append_option(char **optstr, const char *name,
254				const char *value);
255extern int mnt_optstr_prepend_option(char **optstr, const char *name,
256				const char *value);
257
258extern int mnt_optstr_get_option(const char *optstr, const char *name,
259				char **value, size_t *valsz);
260extern int mnt_optstr_set_option(char **optstr, const char *name,
261				const char *value);
262extern int mnt_optstr_remove_option(char **optstr, const char *name);
263extern int mnt_optstr_deduplicate_option(char **optstr, const char *name);
264
265extern int mnt_split_optstr(const char *optstr,
266			    char **user, char **vfs, char **fs,
267			    int ignore_user, int ignore_vfs);
268
269extern int mnt_optstr_get_options(const char *optstr, char **subset,
270                            const struct libmnt_optmap *map, int ignore);
271
272extern int mnt_optstr_get_flags(const char *optstr, unsigned long *flags,
273				const struct libmnt_optmap *map);
274
275extern int mnt_optstr_apply_flags(char **optstr, unsigned long flags,
276                                const struct libmnt_optmap *map);
277
278/* iter.c */
279enum {
280
281	MNT_ITER_FORWARD = 0,
282	MNT_ITER_BACKWARD
283};
284extern struct libmnt_iter *mnt_new_iter(int direction)
285			__ul_attribute__((warn_unused_result));
286extern void mnt_free_iter(struct libmnt_iter *itr);
287
288extern void mnt_reset_iter(struct libmnt_iter *itr, int direction)
289			__ul_attribute__((nonnull));
290extern int mnt_iter_get_direction(struct libmnt_iter *itr)
291			__ul_attribute__((nonnull));
292
293/* optmap.c */
294enum {
295	MNT_LINUX_MAP = 1,
296	MNT_USERSPACE_MAP
297};
298extern const struct libmnt_optmap *mnt_get_builtin_optmap(int id);
299
300/* lock.c */
301extern struct libmnt_lock *mnt_new_lock(const char *datafile, pid_t id)
302			__ul_attribute__((warn_unused_result));
303extern void mnt_free_lock(struct libmnt_lock *ml);
304
305extern void mnt_unlock_file(struct libmnt_lock *ml);
306extern int mnt_lock_file(struct libmnt_lock *ml);
307extern int mnt_lock_block_signals(struct libmnt_lock *ml, int enable);
308
309/* fs.c */
310extern struct libmnt_fs *mnt_new_fs(void)
311			__ul_attribute__((warn_unused_result));
312extern void mnt_free_fs(struct libmnt_fs *fs);
313extern void mnt_ref_fs(struct libmnt_fs *fs);
314extern void mnt_unref_fs(struct libmnt_fs *fs);
315
316extern void mnt_reset_fs(struct libmnt_fs *fs);
317extern struct libmnt_fs *mnt_copy_fs(struct libmnt_fs *dest,
318				     const struct libmnt_fs *src)
319			__ul_attribute__((warn_unused_result));
320extern void *mnt_fs_get_userdata(struct libmnt_fs *fs);
321extern int mnt_fs_set_userdata(struct libmnt_fs *fs, void *data);
322extern const char *mnt_fs_get_source(struct libmnt_fs *fs);
323extern int mnt_fs_set_source(struct libmnt_fs *fs, const char *source);
324extern const char *mnt_fs_get_srcpath(struct libmnt_fs *fs);
325
326extern int mnt_fs_get_tag(struct libmnt_fs *fs, const char **name,
327			  const char **value);
328extern const char *mnt_fs_get_target(struct libmnt_fs *fs);
329extern int mnt_fs_set_target(struct libmnt_fs *fs, const char *target);
330extern const char *mnt_fs_get_fstype(struct libmnt_fs *fs);
331extern int mnt_fs_set_fstype(struct libmnt_fs *fs, const char *fstype);
332
333extern int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path)
334			__ul_attribute__((warn_unused_result));
335extern int mnt_fs_streq_target(struct libmnt_fs *fs, const char *path)
336			__ul_attribute__((warn_unused_result));
337
338extern char *mnt_fs_strdup_options(struct libmnt_fs *fs)
339			__ul_attribute__((warn_unused_result));
340extern const char *mnt_fs_get_options(struct libmnt_fs *fs)
341			__ul_attribute__((warn_unused_result));
342extern const char *mnt_fs_get_optional_fields(struct libmnt_fs *fs)
343			__ul_attribute__((warn_unused_result));
344extern int mnt_fs_get_propagation(struct libmnt_fs *fs, unsigned long *flags);
345
346extern int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr);
347extern int mnt_fs_append_options(struct libmnt_fs *fs, const char *optstr);
348extern int mnt_fs_prepend_options(struct libmnt_fs *fs, const char *optstr);
349
350extern int mnt_fs_get_option(struct libmnt_fs *fs, const char *name,
351				char **value, size_t *valsz);
352
353extern const char *mnt_fs_get_fs_options(struct libmnt_fs *fs);
354extern const char *mnt_fs_get_vfs_options(struct libmnt_fs *fs);
355extern const char *mnt_fs_get_user_options(struct libmnt_fs *fs);
356
357extern const char *mnt_fs_get_attributes(struct libmnt_fs *fs);
358extern int mnt_fs_set_attributes(struct libmnt_fs *fs, const char *optstr);
359extern int mnt_fs_get_attribute(struct libmnt_fs *fs, const char *name,
360				char **value, size_t *valsz);
361extern int mnt_fs_append_attributes(struct libmnt_fs *fs, const char *optstr);
362extern int mnt_fs_prepend_attributes(struct libmnt_fs *fs, const char *optstr);
363
364extern int mnt_fs_get_freq(struct libmnt_fs *fs);
365extern int mnt_fs_set_freq(struct libmnt_fs *fs, int freq);
366extern int mnt_fs_get_passno(struct libmnt_fs *fs);
367extern int mnt_fs_set_passno(struct libmnt_fs *fs, int passno);
368extern const char *mnt_fs_get_root(struct libmnt_fs *fs);
369extern int mnt_fs_set_root(struct libmnt_fs *fs, const char *root);
370extern const char *mnt_fs_get_bindsrc(struct libmnt_fs *fs);
371extern int mnt_fs_set_bindsrc(struct libmnt_fs *fs, const char *src);
372extern int mnt_fs_get_id(struct libmnt_fs *fs);
373extern int mnt_fs_get_parent_id(struct libmnt_fs *fs);
374extern dev_t mnt_fs_get_devno(struct libmnt_fs *fs);
375extern pid_t mnt_fs_get_tid(struct libmnt_fs *fs);
376
377extern const char *mnt_fs_get_swaptype(struct libmnt_fs *fs);
378extern off_t mnt_fs_get_size(struct libmnt_fs *fs);
379extern off_t mnt_fs_get_usedsize(struct libmnt_fs *fs);
380extern int mnt_fs_get_priority(struct libmnt_fs *fs);
381
382extern const char *mnt_fs_get_comment(struct libmnt_fs *fs);
383extern int mnt_fs_set_comment(struct libmnt_fs *fs, const char *comm);
384extern int mnt_fs_append_comment(struct libmnt_fs *fs, const char *comm);
385
386extern int mnt_fs_match_target(struct libmnt_fs *fs, const char *target,
387			       struct libmnt_cache *cache);
388extern int mnt_fs_match_source(struct libmnt_fs *fs, const char *source,
389			       struct libmnt_cache *cache);
390extern int mnt_fs_match_fstype(struct libmnt_fs *fs, const char *types);
391extern int mnt_fs_match_options(struct libmnt_fs *fs, const char *options);
392extern int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file);
393
394extern int mnt_fs_is_kernel(struct libmnt_fs *fs);
395extern int mnt_fs_is_swaparea(struct libmnt_fs *fs);
396extern int mnt_fs_is_netfs(struct libmnt_fs *fs);
397extern int mnt_fs_is_pseudofs(struct libmnt_fs *fs);
398
399extern void mnt_free_mntent(struct mntent *mnt);
400extern int mnt_fs_to_mntent(struct libmnt_fs *fs, struct mntent **mnt);
401
402/* tab-parse.c */
403extern struct libmnt_table *mnt_new_table_from_file(const char *filename)
404			__ul_attribute__((warn_unused_result));
405extern struct libmnt_table *mnt_new_table_from_dir(const char *dirname)
406			__ul_attribute__((warn_unused_result));
407extern int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f,
408				  const char *filename);
409extern int mnt_table_parse_file(struct libmnt_table *tb, const char *filename);
410extern int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname);
411
412extern int mnt_table_parse_fstab(struct libmnt_table *tb, const char *filename);
413extern int mnt_table_parse_swaps(struct libmnt_table *tb, const char *filename);
414extern int mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename);
415extern int mnt_table_set_parser_errcb(struct libmnt_table *tb,
416                int (*cb)(struct libmnt_table *tb, const char *filename, int line));
417
418/* tab.c */
419extern struct libmnt_table *mnt_new_table(void)
420			__ul_attribute__((warn_unused_result));
421extern void mnt_free_table(struct libmnt_table *tb);
422
423extern void mnt_ref_table(struct libmnt_table *tb);
424extern void mnt_unref_table(struct libmnt_table *tb);
425
426extern int mnt_reset_table(struct libmnt_table *tb);
427extern int mnt_table_get_nents(struct libmnt_table *tb);
428extern int mnt_table_is_empty(struct libmnt_table *tb);
429
430extern int mnt_table_set_userdata(struct libmnt_table *tb, void *data);
431extern void *mnt_table_get_userdata(struct libmnt_table *tb);
432
433extern void mnt_table_enable_comments(struct libmnt_table *tb, int enable);
434extern int mnt_table_with_comments(struct libmnt_table *tb);
435extern const char *mnt_table_get_intro_comment(struct libmnt_table *tb);
436extern int mnt_table_set_intro_comment(struct libmnt_table *tb, const char *comm);
437extern int mnt_table_append_intro_comment(struct libmnt_table *tb, const char *comm);
438extern int mnt_table_set_trailing_comment(struct libmnt_table *tb, const char *comm);
439extern const char *mnt_table_get_trailing_comment(struct libmnt_table *tb);
440extern int mnt_table_append_trailing_comment(struct libmnt_table *tb, const char *comm);
441
442extern int mnt_table_set_cache(struct libmnt_table *tb, struct libmnt_cache *mpc);
443extern struct libmnt_cache *mnt_table_get_cache(struct libmnt_table *tb);
444extern int mnt_table_add_fs(struct libmnt_table *tb, struct libmnt_fs *fs);
445extern int mnt_table_remove_fs(struct libmnt_table *tb, struct libmnt_fs *fs);
446extern int mnt_table_first_fs(struct libmnt_table *tb, struct libmnt_fs **fs);
447extern int mnt_table_last_fs(struct libmnt_table *tb, struct libmnt_fs **fs);
448extern int mnt_table_next_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
449			     struct libmnt_fs **fs);
450extern int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
451	                        struct libmnt_fs *parent, struct libmnt_fs **chld);
452extern int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root);
453extern int mnt_table_set_iter(struct libmnt_table *tb, struct libmnt_iter *itr,
454			      struct libmnt_fs *fs);
455
456enum {
457	MNT_UNIQ_FORWARD  = (1 << 1),	/* default is backward */
458	MNT_UNIQ_KEEPTREE = (1 << 2)
459};
460extern int mnt_table_uniq_fs(struct libmnt_table *tb, int flags,
461				int (*cmp)(struct libmnt_table *,
462					   struct libmnt_fs *,
463					   struct libmnt_fs *));
464
465extern struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
466				const char *path, int direction);
467extern struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb,
468				const char *path, int direction);
469extern struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb,
470				const char *path, int direction);
471extern struct libmnt_fs *mnt_table_find_tag(struct libmnt_table *tb, const char *tag,
472				const char *val, int direction);
473extern struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb,
474				const char *source, int direction);
475extern struct libmnt_fs *mnt_table_find_pair(struct libmnt_table *tb,
476				const char *source,
477				const char *target, int direction);
478extern struct libmnt_fs *mnt_table_find_devno(struct libmnt_table *tb,
479				dev_t devno, int direction);
480
481extern int mnt_table_find_next_fs(struct libmnt_table *tb,
482			struct libmnt_iter *itr,
483			int (*match_func)(struct libmnt_fs *, void *),
484			void *userdata,
485		        struct libmnt_fs **fs);
486
487extern int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs);
488
489/* tab_update.c */
490extern struct libmnt_update *mnt_new_update(void)
491			__ul_attribute__((warn_unused_result));
492extern void mnt_free_update(struct libmnt_update *upd);
493
494extern int mnt_table_replace_file(struct libmnt_table *tb, const char *filename);
495extern int mnt_table_write_file(struct libmnt_table *tb, FILE *file);
496
497extern int mnt_update_is_ready(struct libmnt_update *upd);
498extern int mnt_update_set_fs(struct libmnt_update *upd, unsigned long mountflags,
499	                      const char *target, struct libmnt_fs *fs);
500extern int mnt_update_table(struct libmnt_update *upd, struct libmnt_lock *lc);
501extern unsigned long mnt_update_get_mflags(struct libmnt_update *upd);
502extern int mnt_update_force_rdonly(struct libmnt_update *upd, int rdonly);
503extern const char *mnt_update_get_filename(struct libmnt_update *upd);
504extern struct libmnt_fs *mnt_update_get_fs(struct libmnt_update *upd);
505
506/* tab_diff.c */
507enum {
508	MNT_TABDIFF_MOUNT = 1,
509	MNT_TABDIFF_UMOUNT,
510	MNT_TABDIFF_MOVE,
511	MNT_TABDIFF_REMOUNT,
512	MNT_TABDIFF_PROPAGATION,	/* not implemented yet (TODO) */
513};
514
515extern struct libmnt_tabdiff *mnt_new_tabdiff(void)
516			__ul_attribute__((warn_unused_result));
517extern void mnt_free_tabdiff(struct libmnt_tabdiff *df);
518
519extern int mnt_diff_tables(struct libmnt_tabdiff *df,
520			   struct libmnt_table *old_tab,
521			   struct libmnt_table *new_tab);
522
523extern int mnt_tabdiff_next_change(struct libmnt_tabdiff *df,
524				   struct libmnt_iter *itr,
525				   struct libmnt_fs **old_fs,
526				   struct libmnt_fs **new_fs,
527				   int *oper);
528
529/* context.c */
530
531/*
532 * Mode for mount options from fstab (or mtab), see mnt_context_set_optsmode().
533 */
534enum {
535	MNT_OMODE_IGNORE  = (1 << 1),	/* ignore mtab/fstab options */
536	MNT_OMODE_APPEND  = (1 << 2),	/* append mtab/fstab options to existing options */
537	MNT_OMODE_PREPEND = (1 << 3),	/* prepend mtab/fstab options to existing options */
538	MNT_OMODE_REPLACE = (1 << 4),	/* replace existing options with options from mtab/fstab */
539
540	MNT_OMODE_FORCE   = (1 << 5),   /* always read mtab/fstab options */
541
542	MNT_OMODE_FSTAB   = (1 << 10),	/* read from fstab */
543	MNT_OMODE_MTAB    = (1 << 11),	/* read from mtab if fstab not enabled or failed */
544	MNT_OMODE_NOTAB   = (1 << 12),	/* do not read fstab/mtab at all */
545
546	/* default */
547	MNT_OMODE_AUTO   = (MNT_OMODE_PREPEND | MNT_OMODE_FSTAB | MNT_OMODE_MTAB),
548	/* non-root users */
549	MNT_OMODE_USER   = (MNT_OMODE_REPLACE | MNT_OMODE_FORCE | MNT_OMODE_FSTAB)
550};
551
552extern struct libmnt_context *mnt_new_context(void)
553			__ul_attribute__((warn_unused_result));
554extern void mnt_free_context(struct libmnt_context *cxt);
555
556extern int mnt_reset_context(struct libmnt_context *cxt);
557extern int mnt_context_is_restricted(struct libmnt_context *cxt)
558			__ul_attribute__((nonnull));
559
560extern int mnt_context_init_helper(struct libmnt_context *cxt,
561				   int action, int flags);
562extern int mnt_context_helper_setopt(struct libmnt_context *cxt, int c, char *arg);
563
564extern int mnt_context_set_optsmode(struct libmnt_context *cxt, int mode);
565extern int mnt_context_disable_canonicalize(struct libmnt_context *cxt, int disable);
566extern int mnt_context_enable_lazy(struct libmnt_context *cxt, int enable);
567extern int mnt_context_enable_rdonly_umount(struct libmnt_context *cxt, int enable);
568extern int mnt_context_disable_helpers(struct libmnt_context *cxt, int disable);
569extern int mnt_context_enable_sloppy(struct libmnt_context *cxt, int enable);
570extern int mnt_context_enable_fake(struct libmnt_context *cxt, int enable);
571extern int mnt_context_disable_mtab(struct libmnt_context *cxt, int disable);
572extern int mnt_context_enable_force(struct libmnt_context *cxt, int enable);
573extern int mnt_context_enable_verbose(struct libmnt_context *cxt, int enable);
574extern int mnt_context_enable_loopdel(struct libmnt_context *cxt, int enable);
575extern int mnt_context_enable_fork(struct libmnt_context *cxt, int enable);
576extern int mnt_context_disable_swapmatch(struct libmnt_context *cxt, int disable);
577
578extern int mnt_context_get_optsmode(struct libmnt_context *cxt);
579
580extern int mnt_context_is_lazy(struct libmnt_context *cxt)
581			__ul_attribute__((nonnull));
582extern int mnt_context_is_rdonly_umount(struct libmnt_context *cxt)
583			__ul_attribute__((nonnull));
584extern int mnt_context_is_sloppy(struct libmnt_context *cxt)
585			__ul_attribute__((nonnull));
586extern int mnt_context_is_fake(struct libmnt_context *cxt)
587			__ul_attribute__((nonnull));
588extern int mnt_context_is_nomtab(struct libmnt_context *cxt)
589			__ul_attribute__((nonnull));
590extern int mnt_context_is_force(struct libmnt_context *cxt)
591			__ul_attribute__((nonnull));
592extern int mnt_context_is_verbose(struct libmnt_context *cxt)
593			__ul_attribute__((nonnull));
594extern int mnt_context_is_loopdel(struct libmnt_context *cxt)
595			__ul_attribute__((nonnull));
596extern int mnt_context_is_nohelpers(struct libmnt_context *cxt)
597			__ul_attribute__((nonnull));
598extern int mnt_context_is_nocanonicalize(struct libmnt_context *cxt)
599			__ul_attribute__((nonnull));
600extern int mnt_context_is_swapmatch(struct libmnt_context *cxt)
601			__ul_attribute__((nonnull));
602
603extern int mnt_context_is_fork(struct libmnt_context *cxt)
604			__ul_attribute__((nonnull));
605extern int mnt_context_is_parent(struct libmnt_context *cxt)
606			__ul_attribute__((nonnull));
607extern int mnt_context_is_child(struct libmnt_context *cxt)
608			__ul_attribute__((nonnull));
609
610extern int mnt_context_wait_for_children(struct libmnt_context *cxt,
611                                  int *nchildren, int *nerrs);
612
613extern int mnt_context_is_fs_mounted(struct libmnt_context *cxt,
614                              struct libmnt_fs *fs, int *mounted);
615extern int mnt_context_set_fs(struct libmnt_context *cxt, struct libmnt_fs *fs);
616extern struct libmnt_fs *mnt_context_get_fs(struct libmnt_context *cxt);
617
618extern int mnt_context_set_source(struct libmnt_context *cxt, const char *source);
619extern int mnt_context_set_target(struct libmnt_context *cxt, const char *target);
620extern int mnt_context_set_fstype(struct libmnt_context *cxt, const char *fstype);
621
622extern const char *mnt_context_get_source(struct libmnt_context *cxt);
623extern const char *mnt_context_get_target(struct libmnt_context *cxt);
624extern const char *mnt_context_get_fstype(struct libmnt_context *cxt);
625
626extern void *mnt_context_get_mtab_userdata(struct libmnt_context *cxt);
627extern void *mnt_context_get_fstab_userdata(struct libmnt_context *cxt);
628extern void *mnt_context_get_fs_userdata(struct libmnt_context *cxt);
629
630extern int mnt_context_set_options(struct libmnt_context *cxt, const char *optstr);
631extern int mnt_context_append_options(struct libmnt_context *cxt, const char *optstr);
632
633extern const char *mnt_context_get_options(struct libmnt_context *cxt);
634
635extern int mnt_context_set_fstype_pattern(struct libmnt_context *cxt, const char *pattern);
636extern int mnt_context_set_options_pattern(struct libmnt_context *cxt, const char *pattern);
637
638extern int mnt_context_set_passwd_cb(struct libmnt_context *cxt,
639			      char *(*get)(struct libmnt_context *),
640			      void (*release)(struct libmnt_context *, char *))
641			__ul_attribute__((deprecated));
642
643extern int mnt_context_set_tables_errcb(struct libmnt_context *cxt,
644        int (*cb)(struct libmnt_table *tb, const char *filename, int line));
645extern int mnt_context_set_fstab(struct libmnt_context *cxt,
646				 struct libmnt_table *tb);
647extern int mnt_context_get_fstab(struct libmnt_context *cxt,
648				 struct libmnt_table **tb);
649
650extern int mnt_context_get_mtab(struct libmnt_context *cxt,
651				struct libmnt_table **tb);
652extern int mnt_context_get_table(struct libmnt_context *cxt,
653				const char *filename,
654				struct libmnt_table **tb);
655extern int mnt_context_set_cache(struct libmnt_context *cxt,
656				 struct libmnt_cache *cache);
657extern struct libmnt_cache *mnt_context_get_cache(struct libmnt_context *cxt);
658extern struct libmnt_lock *mnt_context_get_lock(struct libmnt_context *cxt);
659extern int mnt_context_set_mflags(struct libmnt_context *cxt,
660				      unsigned long flags);
661extern int mnt_context_get_mflags(struct libmnt_context *cxt,
662				      unsigned long *flags);
663extern int mnt_context_set_user_mflags(struct libmnt_context *cxt,
664						unsigned long flags);
665extern int mnt_context_get_user_mflags(struct libmnt_context *cxt,
666						unsigned long *flags);
667
668extern int mnt_context_set_mountdata(struct libmnt_context *cxt, void *data);
669extern int mnt_context_apply_fstab(struct libmnt_context *cxt);
670
671extern int mnt_context_reset_status(struct libmnt_context *cxt);
672extern int mnt_context_get_status(struct libmnt_context *cxt);
673
674extern int mnt_context_helper_executed(struct libmnt_context *cxt);
675extern int mnt_context_get_helper_status(struct libmnt_context *cxt);
676
677extern int mnt_context_syscall_called(struct libmnt_context *cxt);
678
679extern int mnt_context_get_syscall_errno(struct libmnt_context *cxt);
680
681extern int mnt_context_strerror(struct libmnt_context *cxt, char *buf,
682				size_t bufsiz);
683
684/* context_mount.c */
685extern int mnt_context_mount(struct libmnt_context *cxt);
686extern int mnt_context_umount(struct libmnt_context *cxt);
687extern int mnt_context_next_mount(struct libmnt_context *cxt,
688				struct libmnt_iter *itr,
689				struct libmnt_fs **fs,
690				int *mntrc, int *ignored);
691
692extern int mnt_context_prepare_mount(struct libmnt_context *cxt)
693			__ul_attribute__((warn_unused_result));
694extern int mnt_context_do_mount(struct libmnt_context *cxt);
695extern int mnt_context_finalize_mount(struct libmnt_context *cxt);
696
697/* context_umount.c */
698extern int mnt_context_find_umount_fs(struct libmnt_context *cxt,
699			       const char *tgt,
700			       struct libmnt_fs **pfs);
701extern int mnt_context_next_umount(struct libmnt_context *cxt,
702				struct libmnt_iter *itr,
703				struct libmnt_fs **fs,
704				int *mntrc, int *ignored);
705
706extern int mnt_context_prepare_umount(struct libmnt_context *cxt)
707			__ul_attribute__((warn_unused_result));
708extern int mnt_context_do_umount(struct libmnt_context *cxt);
709extern int mnt_context_finalize_umount(struct libmnt_context *cxt);
710
711extern int mnt_context_tab_applied(struct libmnt_context *cxt);
712extern int mnt_context_set_syscall_status(struct libmnt_context *cxt, int status);
713
714/*
715 * mount(8) userspace options masks (MNT_MAP_USERSPACE map)
716 */
717#define MNT_MS_NOAUTO	(1 << 2)
718#define MNT_MS_USER	(1 << 3)
719#define MNT_MS_USERS	(1 << 4)
720#define MNT_MS_OWNER	(1 << 5)
721#define MNT_MS_GROUP	(1 << 6)
722#define MNT_MS_NETDEV	(1 << 7)
723#define MNT_MS_COMMENT  (1 << 8)
724#define MNT_MS_LOOP     (1 << 9)
725#define MNT_MS_NOFAIL   (1 << 10)
726#define MNT_MS_UHELPER  (1 << 11)
727#define MNT_MS_HELPER   (1 << 12)
728#define MNT_MS_XCOMMENT (1 << 13)
729#define MNT_MS_OFFSET   (1 << 14)
730#define MNT_MS_SIZELIMIT (1 << 15)
731#define MNT_MS_ENCRYPTION (1 << 16)
732
733/*
734 * mount(2) MS_* masks (MNT_MAP_LINUX map)
735 */
736#ifndef MS_RDONLY
737#define MS_RDONLY	 1	/* Mount read-only */
738#endif
739#ifndef MS_NOSUID
740#define MS_NOSUID	 2	/* Ignore suid and sgid bits */
741#endif
742#ifndef MS_NODEV
743#define MS_NODEV	 4	/* Disallow access to device special files */
744#endif
745#ifndef MS_NOEXEC
746#define MS_NOEXEC	 8	/* Disallow program execution */
747#endif
748#ifndef MS_SYNCHRONOUS
749#define MS_SYNCHRONOUS	16	/* Writes are synced at once */
750#endif
751#ifndef MS_REMOUNT
752#define MS_REMOUNT	32	/* Alter flags of a mounted FS */
753#endif
754#ifndef MS_MANDLOCK
755#define MS_MANDLOCK	64	/* Allow mandatory locks on an FS */
756#endif
757#ifndef MS_DIRSYNC
758#define MS_DIRSYNC	128	/* Directory modifications are synchronous */
759#endif
760#ifndef MS_NOATIME
761#define MS_NOATIME	0x400	/* 1024: Do not update access times. */
762#endif
763#ifndef MS_NODIRATIME
764#define MS_NODIRATIME   0x800	/* 2048: Don't update directory access times */
765#endif
766#ifndef MS_BIND
767#define	MS_BIND		0x1000	/* 4096: Mount existing tree elsewhere as well */
768#endif
769#ifndef MS_MOVE
770#define MS_MOVE		0x2000	/* 8192: Atomically move the tree */
771#endif
772#ifndef MS_REC
773#define MS_REC		0x4000	/* 16384: Recursive loopback */
774#endif
775#ifndef MS_SILENT
776#define MS_SILENT	0x8000	/* 32768: Don't emit certain kernel messages */
777#endif
778#ifndef MS_UNBINDABLE
779#define MS_UNBINDABLE	(1<<17)	/* 131072: Make unbindable */
780#endif
781#ifndef MS_PRIVATE
782#define MS_PRIVATE	(1<<18)	/* 262144: Make private */
783#endif
784#ifndef MS_SLAVE
785#define MS_SLAVE	(1<<19)	/* 524288: Make slave */
786#endif
787#ifndef MS_SHARED
788#define MS_SHARED	(1<<20)	/* 1048576: Make shared */
789#endif
790#ifndef MS_RELATIME
791#define MS_RELATIME	(1<<21) /* 2097152: Update atime relative to mtime/ctime */
792#endif
793#ifndef MS_I_VERSION
794#define MS_I_VERSION	(1<<23)	/* Update the inode I_version field */
795#endif
796#ifndef MS_STRICTATIME
797#define MS_STRICTATIME	(1<<24) /* Always perform atime updates */
798#endif
799
800/*
801 * Magic mount flag number. Had to be or-ed to the flag values.
802 */
803#ifndef MS_MGC_VAL
804#define MS_MGC_VAL 0xC0ED0000	/* magic flag number to indicate "new" flags */
805#endif
806#ifndef MS_MGC_MSK
807#define MS_MGC_MSK 0xffff0000	/* magic flag number mask */
808#endif
809
810
811/* Shared-subtree options */
812#define MS_PROPAGATION  (MS_SHARED|MS_SLAVE|MS_UNBINDABLE|MS_PRIVATE)
813
814/* Options that we make ordinary users have by default.  */
815#define MS_SECURE	(MS_NOEXEC|MS_NOSUID|MS_NODEV)
816
817/* Options that we make owner-mounted devices have by default */
818#define MS_OWNERSECURE	(MS_NOSUID|MS_NODEV)
819
820#ifdef __cplusplus
821}
822#endif
823
824#endif /* _LIBMOUNT_MOUNT_H */
825