extern int mnt_fstype_is_pseudofs(const char *type);
extern int mnt_match_fstype(const char *type, const char *pattern);
extern int mnt_match_options(const char *optstr, const char *pattern);
+extern const char *mnt_get_writable_mtab_path(void);
/* cache.c */
extern mnt_cache *mnt_new_cache(void);
extern int mnt_optls_print_debug(mnt_optls *ls, FILE *file);
/* lock.c */
-extern mnt_lock *mnt_new_lock(const char *lockfile, pid_t id);
+extern mnt_lock *mnt_new_lock(const char *lockname, pid_t id);
extern void mnt_free_lock(mnt_lock *ml);
+
extern const char *mnt_lock_get_lockfile(mnt_lock *ml);
extern const char *mnt_lock_get_linkfile(mnt_lock *ml);
+
extern void mnt_unlock_file(mnt_lock *ml);
extern int mnt_lock_file(mnt_lock *ml);
return 0;
}
+/**
+ * mnt_get_writable_mtab_path:
+ *
+ * Returns: pointer to the static string with path to the file with userspace
+ * mount options (classic /etc/mtab or /var/run/mount/mountinfo)
+ */
+const char *mnt_get_writable_mtab_path(void)
+{
+ struct stat mst, ist;
+ int mtab, info;
+
+ mtab = !lstat(_PATH_MOUNTED, &mst);
+ info = !stat(MNT_PATH_RUNDIR, &ist);
+
+ /* A) mtab is symlink, /var/run/mount is available */
+ if (mtab && S_ISLNK(mst.st_mode) && info) {
+ int fd = open(MNT_PATH_MOUNTINFO, O_RDWR | O_CREAT, 0644);
+ if (fd >= 0) {
+ close(fd);
+ return MNT_PATH_MOUNTINFO;
+ }
+ return NULL; /* probably EACCES */
+ }
+
+ /* B) classis system with /etc/mtab */
+ if (mtab && S_ISREG(mst.st_mode)) {
+ int fd = open(_PATH_MOUNTED, O_RDWR, 0644);
+ if (fd >= 0) {
+ close(fd);
+ return _PATH_MOUNTED;
+ }
+ return NULL; /* probably EACCES */
+ }
+
+ return NULL;
+}
+
#ifdef TEST_PROGRAM
int test_match_fstype(struct mtest *ts, int argc, char *argv[])
{