libmount.h 31 KB

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