Coverage Report

Created: 2025-08-26 06:38

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