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

source code of include/libmount/libmount.h