(root)/
util-linux-2.39/
libmount/
src/
mountP.h
       1  /* SPDX-License-Identifier: LGPL-2.1-or-later */
       2  /*
       3   * mountP.h - private library header file
       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   * libmount is free software; you can redistribute it and/or modify it
      10   * under the terms of the GNU Lesser General Public License as published by
      11   * the Free Software Foundation; either version 2.1 of the License, or
      12   * (at your option) any later version.
      13   */
      14  #ifndef _LIBMOUNT_PRIVATE_H
      15  #define _LIBMOUNT_PRIVATE_H
      16  
      17  #include <errno.h>
      18  #include <stdlib.h>
      19  #include <string.h>
      20  #include <sys/stat.h>
      21  #include <sys/types.h>
      22  #include <sys/vfs.h>
      23  #include <unistd.h>
      24  #include <stdio.h>
      25  #include <stdarg.h>
      26  
      27  #include "c.h"
      28  #include "list.h"
      29  #include "debug.h"
      30  #include "buffer.h"
      31  #include "libmount.h"
      32  
      33  /*
      34   * Debug
      35   */
      36  #define MNT_DEBUG_HELP		(1 << 0)
      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_UPDATE	(1 << 7)
      44  #define MNT_DEBUG_UTILS		(1 << 8)
      45  #define MNT_DEBUG_CXT		(1 << 9)
      46  #define MNT_DEBUG_DIFF		(1 << 10)
      47  #define MNT_DEBUG_MONITOR	(1 << 11)
      48  #define MNT_DEBUG_BTRFS		(1 << 12)
      49  #define MNT_DEBUG_LOOP		(1 << 13)
      50  #define MNT_DEBUG_VERITY	(1 << 14)
      51  #define MNT_DEBUG_HOOK		(1 << 15)
      52  #define MNT_DEBUG_OPTLIST	(1 << 16)
      53  
      54  #define MNT_DEBUG_ALL		0xFFFFFF
      55  
      56  UL_DEBUG_DECLARE_MASK(libmount);
      57  #define DBG(m, x)	__UL_DBG(libmount, MNT_DEBUG_, m, x)
      58  #define ON_DBG(m, x)	__UL_DBG_CALL(libmount, MNT_DEBUG_, m, x)
      59  #define DBG_FLUSH	__UL_DBG_FLUSH(libmount, MNT_DEBUG_)
      60  
      61  #define UL_DEBUG_CURRENT_MASK	UL_DEBUG_MASK(libmount)
      62  #include "debugobj.h"
      63  
      64  /*
      65   * NLS -- the library has to be independent on main program, so define
      66   * UL_TEXTDOMAIN_EXPLICIT before you include nls.h.
      67   *
      68   * Now we use util-linux.po (=PACKAGE), rather than maintain the texts
      69   * in the separate libmount.po file.
      70   */
      71  #define LIBMOUNT_TEXTDOMAIN	PACKAGE
      72  #define UL_TEXTDOMAIN_EXPLICIT	LIBMOUNT_TEXTDOMAIN
      73  #include "nls.h"
      74  
      75  
      76  /* extension for files in the directory */
      77  #define MNT_MNTTABDIR_EXT	".fstab"
      78  
      79  /* library private paths */
      80  #define MNT_RUNTIME_TOPDIR	"/run"
      81  /* private userspace mount table */
      82  #define MNT_PATH_UTAB		MNT_RUNTIME_TOPDIR "/mount/utab"
      83  /* temporary mount target */
      84  #define MNT_PATH_TMPTGT		MNT_RUNTIME_TOPDIR "/mount/tmptgt"
      85  
      86  #define MNT_UTAB_HEADER	"# libmount utab file\n"
      87  
      88  #ifdef TEST_PROGRAM
      89  struct libmnt_test {
      90  	const char	*name;
      91  	int		(*body)(struct libmnt_test *ts, int argc, char *argv[]);
      92  	const char	*usage;
      93  };
      94  
      95  /* test.c */
      96  extern int mnt_run_test(struct libmnt_test *tests, int argc, char *argv[]);
      97  #endif
      98  
      99  /* utils.c */
     100  extern int mnt_valid_tagname(const char *tagname);
     101  
     102  extern const char *mnt_statfs_get_fstype(struct statfs *vfs);
     103  extern int is_file_empty(const char *name);
     104  
     105  extern int mnt_is_readonly(const char *path)
     106  			__attribute__((nonnull));
     107  
     108  extern int mnt_parse_offset(const char *str, size_t len, uintmax_t *res);
     109  
     110  extern int mnt_chdir_to_parent(const char *target, char **filename);
     111  
     112  extern char *mnt_get_username(const uid_t uid);
     113  extern int mnt_get_uid(const char *username, uid_t *uid);
     114  extern int mnt_get_gid(const char *groupname, gid_t *gid);
     115  extern int mnt_parse_uid(const char *user, size_t user_len, uid_t *gid);
     116  extern int mnt_parse_gid(const char *group, size_t group_len, gid_t *gid);
     117  extern int mnt_parse_mode(const char *mode, size_t mode_len, mode_t *gid);
     118  extern int mnt_in_group(gid_t gid);
     119  
     120  extern int mnt_open_uniq_filename(const char *filename, char **name);
     121  
     122  extern int mnt_has_regular_utab(const char **utab, int *writable);
     123  extern const char *mnt_get_utab_path(void);
     124  
     125  extern int mnt_get_filesystems(char ***filesystems, const char *pattern);
     126  extern void mnt_free_filesystems(char **filesystems);
     127  
     128  extern char *mnt_get_kernel_cmdline_option(const char *name);
     129  
     130  extern int mnt_safe_stat(const char *target, struct stat *st);
     131  extern int mnt_safe_lstat(const char *target, struct stat *st);
     132  extern int mnt_is_path(const char *target);
     133  
     134  extern int mnt_tmptgt_unshare(int *old_ns_fd);
     135  extern int mnt_tmptgt_cleanup(int old_ns_fd);
     136  
     137  /* tab.c */
     138  extern int is_mountinfo(struct libmnt_table *tb);
     139  extern int mnt_table_set_parser_fltrcb(	struct libmnt_table *tb,
     140  					int (*cb)(struct libmnt_fs *, void *),
     141  					void *data);
     142  
     143  extern int __mnt_table_parse_mountinfo(struct libmnt_table *tb,
     144  					const char *filename,
     145  					struct libmnt_table *u_tb);
     146  
     147  extern struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
     148  					struct libmnt_fs *fs,
     149  					unsigned long mountflags,
     150  					char **fsroot);
     151  
     152  extern int __mnt_table_is_fs_mounted(	struct libmnt_table *tb,
     153  					struct libmnt_fs *fstab_fs,
     154  					const char *tgt_prefix);
     155  
     156  extern int mnt_table_enable_noautofs(struct libmnt_table *tb, int ignore);
     157  extern int mnt_table_is_noautofs(struct libmnt_table *tb);
     158  
     159  /*
     160   * Generic iterator
     161   */
     162  struct libmnt_iter {
     163          struct list_head        *p;		/* current position */
     164          struct list_head        *head;		/* start position */
     165  	int			direction;	/* MNT_ITER_{FOR,BACK}WARD */
     166  };
     167  
     168  #define IS_ITER_FORWARD(_i)	((_i)->direction == MNT_ITER_FORWARD)
     169  #define IS_ITER_BACKWARD(_i)	((_i)->direction == MNT_ITER_BACKWARD)
     170  
     171  #define MNT_ITER_INIT(itr, list) \
     172  	do { \
     173  		(itr)->p = IS_ITER_FORWARD(itr) ? \
     174  				(list)->next : (list)->prev; \
     175  		(itr)->head = (list); \
     176  	} while(0)
     177  
     178  #define MNT_ITER_GET_ENTRY(itr, restype, member) \
     179  		list_entry((itr)->p, restype, member)
     180  
     181  #define MNT_ITER_ITERATE(itr) \
     182  	do { \
     183  		(itr)->p = IS_ITER_FORWARD(itr) ? \
     184  				(itr)->p->next : (itr)->p->prev; \
     185  	} while(0)
     186  
     187  
     188  /*
     189   * This struct represents one entry in a fstab/mountinfo file.
     190   * (note that fstab[1] means the first column from fstab, and so on...)
     191   */
     192  struct libmnt_fs {
     193  	struct list_head ents;
     194  	struct libmnt_table *tab;
     195  
     196  	int		refcount;	/* reference counter */
     197  
     198  	unsigned int	opts_age;	/* to sync with optlist */
     199  	struct libmnt_optlist *optlist;
     200  
     201  	int		id;		/* mountinfo[1]: ID */
     202  	int		parent;		/* mountinfo[2]: parent */
     203  	dev_t		devno;		/* mountinfo[3]: st_dev */
     204  
     205  	char		*bindsrc;	/* utab, full path from fstab[1] for bind mounts */
     206  
     207  	char		*source;	/* fstab[1], mountinfo[10], swaps[1]:
     208                                           * source dev, file, dir or TAG */
     209  	char		*tagname;	/* fstab[1]: tag name - "LABEL", "UUID", ..*/
     210  	char		*tagval;	/*           tag value */
     211  
     212  	char		*root;		/* mountinfo[4]: root of the mount within the FS */
     213  	char		*target;	/* mountinfo[5], fstab[2]: mountpoint */
     214  	char		*fstype;	/* mountinfo[9], fstab[3]: filesystem type */
     215  
     216  	char		*optstr;	/* fstab[4], merged options */
     217  	char		*vfs_optstr;	/* mountinfo[6]: fs-independent (VFS) options */
     218  	char		*opt_fields;	/* mountinfo[7]: optional fields */
     219  	char		*fs_optstr;	/* mountinfo[11]: fs-dependent options */
     220  	char		*user_optstr;	/* userspace mount options */
     221  	char		*attrs;		/* mount attributes */
     222  
     223  	int		freq;		/* fstab[5]: dump frequency in days */
     224  	int		passno;		/* fstab[6]: pass number on parallel fsck */
     225  
     226  	/* /proc/swaps */
     227  	char		*swaptype;	/* swaps[2]: device type (partition, file, ...) */
     228  	off_t		size;		/* swaps[3]: swaparea size */
     229  	off_t		usedsize;	/* swaps[4]: used size */
     230  	int		priority;	/* swaps[5]: swap priority */
     231  
     232  	int		flags;		/* MNT_FS_* flags */
     233  	pid_t		tid;		/* /proc/<tid>/mountinfo otherwise zero */
     234  
     235  	char		*comment;	/* fstab comment */
     236  
     237  	void		*userdata;	/* library independent data */
     238  };
     239  
     240  /*
     241   * fs flags
     242   */
     243  #define MNT_FS_PSEUDO	(1 << 1) /* pseudo filesystem */
     244  #define MNT_FS_NET	(1 << 2) /* network filesystem */
     245  #define MNT_FS_SWAP	(1 << 3) /* swap device */
     246  #define MNT_FS_KERNEL	(1 << 4) /* data from /proc/{mounts,self/mountinfo} */
     247  #define MNT_FS_MERGED	(1 << 5) /* already merged data from /run/mount/utab */
     248  
     249  /*
     250   * fstab/mountinfo file
     251   */
     252  struct libmnt_table {
     253  	int		fmt;		/* MNT_FMT_* file format */
     254  	int		nents;		/* number of entries */
     255  	int		refcount;	/* reference counter */
     256  	int		comms;		/* enable/disable comment parsing */
     257  	char		*comm_intro;	/* First comment in file */
     258  	char		*comm_tail;	/* Last comment in file */
     259  
     260  	struct libmnt_cache *cache;		/* canonicalized paths/tags cache */
     261  
     262          int		(*errcb)(struct libmnt_table *tb,
     263  				 const char *filename, int line);
     264  
     265  	int		(*fltrcb)(struct libmnt_fs *fs, void *data);
     266  	void		*fltrcb_data;
     267  
     268  	int		noautofs;	/* ignore autofs mounts */
     269  
     270  	struct list_head	ents;	/* list of entries (libmnt_fs) */
     271  	void		*userdata;
     272  };
     273  
     274  extern struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt, int empty_for_enoent);
     275  
     276  /*
     277   * Tab file format
     278   */
     279  enum {
     280  	MNT_FMT_GUESS,
     281  	MNT_FMT_FSTAB,			/* /etc/{fs,m}tab */
     282  	MNT_FMT_MTAB = MNT_FMT_FSTAB,	/* alias */
     283  	MNT_FMT_MOUNTINFO,		/* /proc/#/mountinfo */
     284  	MNT_FMT_UTAB,			/* /run/mount/utab */
     285  	MNT_FMT_SWAPS			/* /proc/swaps */
     286  };
     287  
     288  /*
     289   * Context hooks
     290   *
     291   * TODO: this will be public one day when libmount will support modules for
     292   * stuff like veritydev.c.
     293   */
     294  enum {
     295  	MNT_STAGE_PREP_SOURCE = 1,	/* mount source preparation */
     296  	MNT_STAGE_PREP_TARGET,		/* mount target preparation */
     297  	MNT_STAGE_PREP_OPTIONS,		/* mount options preparation */
     298  	MNT_STAGE_PREP,			/* all prepared */
     299  
     300  	MNT_STAGE_MOUNT_PRE = 100,	/* before mount */
     301  	MNT_STAGE_MOUNT,		/* mount(2) or fsmount(2) or tree-clone */
     302  	MNT_STAGE_MOUNT_POST,		/* after mount */
     303  
     304  	MNT_STAGE_POST = 200		/* all is done */
     305  };
     306  
     307  struct libmnt_hookset {
     308  	const char *name;				/* hook set name */
     309  
     310  	int firststage;
     311  	int (*firstcall)(struct libmnt_context *, const struct libmnt_hookset *, void *);
     312  
     313  	int (*deinit)(struct libmnt_context *, const struct libmnt_hookset *);	/* cleanup function */
     314  };
     315  
     316  /* built-in hooks */
     317  extern const struct libmnt_hookset hookset_mount_legacy;
     318  extern const struct libmnt_hookset hookset_mount;
     319  extern const struct libmnt_hookset hookset_mkdir;
     320  extern const struct libmnt_hookset hookset_subdir;
     321  extern const struct libmnt_hookset hookset_owner;
     322  extern const struct libmnt_hookset hookset_idmap;
     323  extern const struct libmnt_hookset hookset_loopdev;
     324  #ifdef HAVE_CRYPTSETUP
     325  extern const struct libmnt_hookset hookset_veritydev;
     326  #endif
     327  #ifdef HAVE_LIBSELINUX
     328  extern const struct libmnt_hookset hookset_selinux;
     329  #endif
     330  
     331  extern int mnt_context_deinit_hooksets(struct libmnt_context *cxt);
     332  extern const struct libmnt_hookset *mnt_context_get_hookset(struct libmnt_context *cxt, const char *name);
     333  
     334  extern int mnt_context_set_hookset_data(struct libmnt_context *cxt,
     335  			const struct libmnt_hookset *hs,
     336  			void *data);
     337  
     338  extern void *mnt_context_get_hookset_data(struct libmnt_context *cxt,
     339  			const struct libmnt_hookset *hs);
     340  
     341  extern int mnt_context_has_hook(struct libmnt_context *cxt,
     342                           const struct libmnt_hookset *hs,
     343                           int stage,
     344                           void *data);
     345  
     346  extern int mnt_context_append_hook(struct libmnt_context *cxt,
     347  			const struct libmnt_hookset *hs,
     348  			int stage,
     349  			void *data,
     350  			int (*func)(struct libmnt_context *,
     351  				const struct libmnt_hookset *,
     352  				void *));
     353  extern int mnt_context_insert_hook(struct libmnt_context *cxt,
     354  			const char *after,
     355  			const struct libmnt_hookset *hs,
     356  			int stage,
     357  			void *data,
     358  			int (*func)(struct libmnt_context *,
     359  				const struct libmnt_hookset *,
     360  				void *));
     361  
     362  extern int mnt_context_remove_hook(struct libmnt_context *cxt,
     363  			const struct libmnt_hookset *hs,
     364  			int stage,
     365  			void **data);
     366  extern int mnt_context_call_hooks(struct libmnt_context *cxt, int stage);
     367  
     368  /*
     369   * Namespace
     370   */
     371  struct libmnt_ns {
     372  	int fd;				/* file descriptor of namespace, -1 when inactive */
     373  	struct libmnt_cache *cache;	/* paths cache associated with NS */
     374  };
     375  
     376  /*
     377   * Mount context -- high-level API
     378   */
     379  struct libmnt_context
     380  {
     381  	int	action;		/* MNT_ACT_{MOUNT,UMOUNT} */
     382  	int	restricted;	/* root or not? */
     383  
     384  	char	*fstype_pattern;	/* for mnt_match_fstype() */
     385  	char	*optstr_pattern;	/* for mnt_match_options() */
     386  
     387  	struct libmnt_fs *fs;		/* filesystem description (type, mountpoint, device, ...) */
     388  
     389  	struct libmnt_table *fstab;	/* fstab entries */
     390  	struct libmnt_table *mountinfo;	/* already mounted filesystems */
     391  	struct libmnt_table *utab;	/* rarely used by umount only */
     392  
     393  	int	(*table_errcb)(struct libmnt_table *tb,	/* callback for libmnt_table structs */
     394  			 const char *filename, int line);
     395  
     396  	int	(*table_fltrcb)(struct libmnt_fs *fs, void *data);	/* callback for libmnt_table structs */
     397  	void	*table_fltrcb_data;
     398  
     399  	char	*(*pwd_get_cb)(struct libmnt_context *);		/* get encryption password */
     400  	void	(*pwd_release_cb)(struct libmnt_context *, char *);	/* release password */
     401  
     402  	int	optsmode;	/* fstab optstr mode MNT_OPTSMODE_{AUTO,FORCE,IGNORE} */
     403  
     404  	const void	*mountdata;	/* final mount(2) data, string or binary data */
     405  
     406  	struct libmnt_cache	*cache;		/* paths cache */
     407  	struct libmnt_lock	*lock;		/* utab lock */
     408  	struct libmnt_update	*update;	/* utab update */
     409  
     410  	struct libmnt_optlist	*optlist;	/* parsed mount options */
     411  	struct libmnt_optlist	*optlist_saved;	/* save/apply context template */
     412  
     413  	const struct libmnt_optmap *map_linux;		/* system options map */
     414  	const struct libmnt_optmap *map_userspace;	/* userspace options map */
     415  
     416  	const char	*mountinfo_path; /* usualy /proc/self/moutinfo */
     417  
     418  	const char	*utab_path; /* path to utab */
     419  	int		utab_writable; /* is utab writable */
     420  
     421  	char		*tgt_prefix;	/* path used for all targets */
     422  
     423  	int	flags;		/* private context flags */
     424  
     425  	char	*helper;	/* name of the used /sbin/[u]mount.<type> helper */
     426  	int	helper_status;	/* helper wait(2) status */
     427  	int	helper_exec_status; /* 1: not called yet, 0: success, <0: -errno */
     428  
     429  	pid_t	*children;	/* "mount -a --fork" PIDs */
     430  	int	nchildren;	/* number of children */
     431  	pid_t	pid;		/* 0=parent; PID=child */
     432  
     433  	int	syscall_status;	/* 1: not called yet, 0: success, <0: -errno */
     434  	const char *syscall_name;	/* failed syscall name */
     435  
     436  	struct libmnt_ns	ns_orig;	/* original namespace */
     437  	struct libmnt_ns	ns_tgt;		/* target namespace */
     438  	struct libmnt_ns	*ns_cur;	/* pointer to current namespace */
     439  
     440  	unsigned int	enabled_textdomain : 1;	/* bindtextdomain() called */
     441  	unsigned int	noautofs : 1;		/* ignore autofs mounts */
     442  	unsigned int	has_selinux_opt : 1;	/* temporary for broken fsconfig() syscall */
     443  	unsigned int    force_clone : 1;	/* OPEN_TREE_CLONE */
     444  
     445  	struct list_head	hooksets_datas;	/* global hooksets data */
     446  	struct list_head	hooksets_hooks;	/* global hooksets data */
     447  };
     448  
     449  /* flags */
     450  #define MNT_FL_NOMTAB		(1 << 1)
     451  #define MNT_FL_FAKE		(1 << 2)
     452  #define MNT_FL_SLOPPY		(1 << 3)
     453  #define MNT_FL_VERBOSE		(1 << 4)
     454  #define MNT_FL_NOHELPERS	(1 << 5)
     455  #define MNT_FL_LOOPDEL		(1 << 6)
     456  #define MNT_FL_LAZY		(1 << 7)
     457  #define MNT_FL_FORCE		(1 << 8)
     458  #define MNT_FL_NOCANONICALIZE	(1 << 9)
     459  #define MNT_FL_RDONLY_UMOUNT	(1 << 11)	/* remount,ro after EBUSY umount(2) */
     460  #define MNT_FL_FORK		(1 << 12)
     461  #define MNT_FL_NOSWAPMATCH	(1 << 13)
     462  #define MNT_FL_RWONLY_MOUNT	(1 << 14)	/* explicit mount -w; never try read-only  */
     463  #define MNT_FL_ONLYONCE		(1 << 15)
     464  
     465  #define MNT_FL_MOUNTDATA	(1 << 20)
     466  #define MNT_FL_TAB_APPLIED	(1 << 21)	/* fstab merged to cxt->fs */
     467  #define MNT_FL_MOUNTFLAGS_MERGED (1 << 22)	/* MS_* flags was read from optstr */
     468  #define MNT_FL_SAVED_USER	(1 << 23)
     469  #define MNT_FL_PREPARED		(1 << 24)
     470  #define MNT_FL_HELPER		(1 << 25)	/* [u]mount.<type> */
     471  #define MNT_FL_MOUNTOPTS_FIXED  (1 << 27)
     472  #define MNT_FL_TABPATHS_CHECKED	(1 << 28)
     473  #define MNT_FL_FORCED_RDONLY	(1 << 29)	/* mounted read-only on write-protected device */
     474  #define MNT_FL_VERITYDEV_READY	(1 << 30)	/* /dev/mapper/<FOO> initialized by the library */
     475  
     476  /* default flags */
     477  #define MNT_FL_DEFAULT		0
     478  
     479  /* Flags usable with MS_BIND|MS_REMOUNT */
     480  #define MNT_BIND_SETTABLE	(MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOATIME|MS_NODIRATIME|MS_RELATIME|MS_RDONLY|MS_NOSYMFOLLOW)
     481  
     482  #define set_syscall_status(_cxt, _name, _x) __extension__ ({ \
     483  		if (!(_x)) { \
     484  			DBG(CXT, ul_debug("syscall '%s' [%m]", _name)); \
     485  			(_cxt)->syscall_status = -errno; \
     486  			(_cxt)->syscall_name = (_name); \
     487  		} else { \
     488  			DBG(CXT, ul_debug("syscall '%s' [success]", _name)); \
     489  			(_cxt)->syscall_status = 0; \
     490  		} \
     491  	})
     492  
     493  #define reset_syscall_status(_cxt)	__extension__ ({ \
     494  		DBG(CXT, ul_debug("reset syscall status")); \
     495  		(_cxt)->syscall_status = 0; \
     496  		(_cxt)->syscall_name = NULL; \
     497  	})
     498  
     499  /* optmap.c */
     500  extern const struct libmnt_optmap *mnt_optmap_get_entry(
     501  			     struct libmnt_optmap const **maps,
     502                               int nmaps,
     503  			     const char *name,
     504                               size_t namelen,
     505  			     const struct libmnt_optmap **mapent);
     506  
     507  /* optstr.c */
     508  extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end);
     509  
     510  extern int mnt_buffer_append_option(struct ul_buffer *buf,
     511                          const char *name, size_t namesz,
     512                          const char *val, size_t valsz, int quoted);
     513  
     514  /* optlist.h */
     515  struct libmnt_opt;
     516  struct libmnt_optlist;
     517  
     518  extern struct libmnt_optlist *mnt_new_optlist(void);
     519  extern void mnt_ref_optlist(struct libmnt_optlist *ls);
     520  extern void mnt_unref_optlist(struct libmnt_optlist *ls);
     521  extern struct libmnt_optlist *mnt_copy_optlist(struct libmnt_optlist *ls);
     522  extern int mnt_optlist_is_empty(struct libmnt_optlist *ls);
     523  extern unsigned int mnt_optlist_get_age(struct libmnt_optlist *ls);
     524  extern int mnt_optlist_register_map(struct libmnt_optlist *ls, const struct libmnt_optmap *map);
     525  extern int mnt_optlist_remove_opt(struct libmnt_optlist *ls, struct libmnt_opt *opt);
     526  extern int mnt_optlist_remove_named(struct libmnt_optlist *ls, const char *name,
     527                               const struct libmnt_optmap *map);
     528  extern int mnt_optlist_remove_flags(struct libmnt_optlist *ls, unsigned long flags,
     529                          const struct libmnt_optmap *map);
     530  extern int mnt_optlist_next_opt(struct libmnt_optlist *ls,
     531                          struct libmnt_iter *itr, struct libmnt_opt **opt);
     532  extern struct libmnt_opt *mnt_optlist_get_opt(struct libmnt_optlist *ls,
     533                          unsigned long id, const struct libmnt_optmap *map);
     534  extern struct libmnt_opt *mnt_optlist_get_named(struct libmnt_optlist *ls,
     535                            const char *name, const struct libmnt_optmap *map);
     536  extern int mnt_optlist_set_optstr(struct libmnt_optlist *ls, const char *optstr,
     537                            const struct libmnt_optmap *map);
     538  extern int mnt_optlist_append_optstr(struct libmnt_optlist *ls, const char *optstr,
     539                          const struct libmnt_optmap *map);
     540  extern int mnt_optlist_prepend_optstr(struct libmnt_optlist *ls, const char *optstr,
     541                          const struct libmnt_optmap *map);
     542  extern int mnt_optlist_append_flags(struct libmnt_optlist *ls, unsigned long flags,
     543                            const struct libmnt_optmap *map);
     544  extern int mnt_optlist_set_flags(struct libmnt_optlist *ls, unsigned long flags,
     545                            const struct libmnt_optmap *map);
     546  extern int mnt_optlist_insert_flags(struct libmnt_optlist *ls, unsigned long flags,
     547                          const struct libmnt_optmap *map,
     548                          unsigned long after,
     549                          const struct libmnt_optmap *after_map);
     550  /* "what" argument */
     551  enum {
     552  	/* Default -- if @map specified then returns all options for the map, otherwise
     553  	 *            returns all options including uknonwn options, exclude external options  */
     554  	MNT_OL_FLTR_DFLT = 0,
     555  	/* Options as expected by mount.<type> helpers */
     556  	MNT_OL_FLTR_HELPERS,
     557  	/* Options as expected in mtab */
     558  	MNT_OL_FLTR_MTAB,
     559  	/* All options -- include mapped, unknown and external options */
     560  	MNT_OL_FLTR_ALL,
     561  	/* All unknown options -- exclude external (usually FS specific options) */
     562  	MNT_OL_FLTR_UNKNOWN,
     563  
     564  	__MNT_OL_FLTR_COUNT	/* keep it last */
     565  };
     566  
     567  
     568  extern int mnt_optlist_get_flags(struct libmnt_optlist *ls, unsigned long *flags,
     569                            const struct libmnt_optmap *map, unsigned int what);
     570  
     571  /* recursive status for mnt_optlist_get_attrs() */
     572  #define MNT_OL_REC	1
     573  #define MNT_OL_NOREC	2
     574  
     575  extern int mnt_optlist_get_attrs(struct libmnt_optlist *ls, uint64_t *set, uint64_t *clr, int rec);
     576  
     577  extern int mnt_optlist_get_optstr(struct libmnt_optlist *ol, const char **optstr,
     578                          const struct libmnt_optmap *map, unsigned int what);
     579  extern int mnt_optlist_strdup_optstr(struct libmnt_optlist *ls, char **optstr,
     580                          const struct libmnt_optmap *map, unsigned int what);
     581  
     582  extern int mnt_optlist_get_propagation(struct libmnt_optlist *ls);
     583  extern int mnt_optlist_is_propagation_only(struct libmnt_optlist *ls);
     584  extern int mnt_optlist_is_remount(struct libmnt_optlist *ls);
     585  extern int mnt_optlist_is_recursive(struct libmnt_optlist *ls);
     586  extern int mnt_optlist_is_bind(struct libmnt_optlist *ls);
     587  extern int mnt_optlist_is_rbind(struct libmnt_optlist *ls);
     588  extern int mnt_optlist_is_move(struct libmnt_optlist *ls);
     589  extern int mnt_optlist_is_rdonly(struct libmnt_optlist *ls);
     590  extern int mnt_optlist_is_silent(struct libmnt_optlist *ls);
     591  
     592  extern int mnt_optlist_merge_opts(struct libmnt_optlist *ls);
     593  
     594  extern int mnt_opt_has_value(struct libmnt_opt *opt);
     595  extern const char *mnt_opt_get_value(struct libmnt_opt *opt);
     596  extern const char *mnt_opt_get_name(struct libmnt_opt *opt);
     597  extern const struct libmnt_optmap *mnt_opt_get_map(struct libmnt_opt *opt);
     598  extern const struct libmnt_optmap *mnt_opt_get_mapent(struct libmnt_opt *opt);
     599  extern int mnt_opt_set_external(struct libmnt_opt *opt, int enable);
     600  extern int mnt_opt_set_value(struct libmnt_opt *opt, const char *str);
     601  extern int mnt_opt_set_u64value(struct libmnt_opt *opt, uint64_t num);
     602  extern int mnt_opt_set_quoted_value(struct libmnt_opt *opt, const char *str);
     603  extern int mnt_opt_is_external(struct libmnt_opt *opt);
     604  
     605  /* fs.c */
     606  extern int mnt_fs_follow_optlist(struct libmnt_fs *fs, struct libmnt_optlist *ol);
     607  extern struct libmnt_fs *mnt_copy_mtab_fs(struct libmnt_fs *fs);
     608  extern int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source)
     609  			__attribute__((nonnull(1)));
     610  extern int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype)
     611  			__attribute__((nonnull(1)));
     612  extern int __mnt_fs_set_target_ptr(struct libmnt_fs *fs, char *tgt)
     613  			__attribute__((nonnull(1)));
     614  
     615  /* context.c */
     616  extern struct libmnt_context *mnt_copy_context(struct libmnt_context *o);
     617  extern int mnt_context_utab_writable(struct libmnt_context *cxt);
     618  extern const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt);
     619  
     620  extern int mnt_context_get_mountinfo(struct libmnt_context *cxt, struct libmnt_table **tb);
     621  extern int mnt_context_get_mountinfo_for_target(struct libmnt_context *cxt,
     622  				    struct libmnt_table **mountinfo, const char *tgt);
     623  
     624  extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
     625  extern int mnt_context_guess_srcpath_fstype(struct libmnt_context *cxt, char **type);
     626  extern int mnt_context_guess_fstype(struct libmnt_context *cxt);
     627  extern int mnt_context_prepare_helper(struct libmnt_context *cxt,
     628  				      const char *name, const char *type);
     629  extern int mnt_context_prepare_update(struct libmnt_context *cxt);
     630  extern int mnt_context_merge_mflags(struct libmnt_context *cxt);
     631  extern int mnt_context_update_tabs(struct libmnt_context *cxt);
     632  
     633  extern int mnt_context_umount_setopt(struct libmnt_context *cxt, int c, char *arg);
     634  extern int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg);
     635  
     636  extern int mnt_context_propagation_only(struct libmnt_context *cxt)
     637  			__attribute__((nonnull));
     638  
     639  extern int mnt_context_delete_loopdev(struct libmnt_context *cxt);
     640  
     641  extern int mnt_fork_context(struct libmnt_context *cxt);
     642  
     643  extern int mnt_context_set_tabfilter(struct libmnt_context *cxt,
     644  				     int (*fltr)(struct libmnt_fs *, void *),
     645  				     void *data);
     646  
     647  extern int mnt_context_get_generic_excode(int rc, char *buf, size_t bufsz, const char *fmt, ...)
     648  				__attribute__ ((__format__ (__printf__, 4, 5)));
     649  extern int mnt_context_get_mount_excode(struct libmnt_context *cxt, int mntrc, char *buf, size_t bufsz);
     650  extern int mnt_context_get_umount_excode(struct libmnt_context *cxt, int mntrc, char *buf, size_t bufsz);
     651  
     652  extern int mnt_context_has_template(struct libmnt_context *cxt);
     653  extern int mnt_context_apply_template(struct libmnt_context *cxt);
     654  extern int mnt_context_save_template(struct libmnt_context *cxt);
     655  
     656  extern int mnt_context_apply_fs(struct libmnt_context *cxt, struct libmnt_fs *fs);
     657  
     658  extern struct libmnt_optlist *mnt_context_get_optlist(struct libmnt_context *cxt);
     659  
     660  /* tab_update.c */
     661  extern int mnt_update_set_filename(struct libmnt_update *upd, const char *filename);
     662  extern int mnt_update_already_done(struct libmnt_update *upd,
     663  				   struct libmnt_lock *lc);
     664  
     665  #if __linux__
     666  /* btrfs.c */
     667  extern uint64_t btrfs_get_default_subvol_id(const char *path);
     668  #endif
     669  
     670  #ifdef USE_LIBMOUNT_MOUNTFD_SUPPORT
     671  /* fsconfig/fsopen based stuff */
     672  struct libmnt_sysapi {
     673  	int	fd_fs;		/* FD from fsopen() or fspick() */
     674  	int	fd_tree;	/* FD from fsmount() or open_tree() */
     675  
     676  	unsigned int is_new_fs : 1 ;	/* fd_fs comes from fsopen() */
     677  };
     678  
     679  static inline struct libmnt_sysapi *mnt_context_get_sysapi(struct libmnt_context *cxt)
     680  {
     681  	return mnt_context_get_hookset_data(cxt, &hookset_mount);
     682  }
     683  #endif
     684  
     685  #endif /* _LIBMOUNT_PRIVATE_H */