return NULL;
}
+/**
+ * mnt_copy_mtab_fs:
+ * @fs: filesystem
+ *
+ * This function copies all @fs description except information that does not
+ * belong to /etc/mtab (e.g. VFS and userspace mount options with MNT_NOMTAB
+ * mask).
+ *
+ * Returns: copy of @fs.
+ */
+mnt_fs *mnt_copy_mtab_fs(const mnt_fs *fs)
+{
+ mnt_fs *n = mnt_new_fs();
+
+ if (!n)
+ return NULL;
+
+ if (cpy_str_at_offset(n, fs, offsetof(struct _mnt_fs, source)))
+ goto err;
+ if (cpy_str_at_offset(n, fs, offsetof(struct _mnt_fs, target)))
+ goto err;
+ if (cpy_str_at_offset(n, fs, offsetof(struct _mnt_fs, fstype)))
+ goto err;
+
+ if (fs->vfs_optstr) {
+ char *p = NULL;
+ mnt_optstr_get_options(fs->vfs_optstr, &p,
+ mnt_get_builtin_optmap(MNT_LINUX_MAP),
+ MNT_NOMTAB);
+ n->vfs_optstr = p;
+ }
+
+ if (fs->user_optstr) {
+ char *p = NULL;
+ mnt_optstr_get_options(fs->user_optstr, &p,
+ mnt_get_builtin_optmap(MNT_USERSPACE_MAP),
+ MNT_NOMTAB);
+ n->user_optstr = p;
+ }
+
+ if (cpy_str_at_offset(n, fs, offsetof(struct _mnt_fs, fs_optstr)))
+ goto err;
+
+ n->freq = fs->freq;
+ n->passno = fs->passno;
+ n->flags = fs->flags;
+
+ return n;
+err:
+ mnt_free_fs(n);
+ return NULL;
+
+}
+
/**
* mnt_fs_get_userdata:
* @fs: mnt_file instance
{
const char *name; /* option name[=%<type>] (e.g. "loop[=%s]") */
int id; /* option ID or MS_* flags (e.g MS_RDONLY) */
- int mask; /* MNT_{MFLAG,MDATA,INVMASK,...} mask */
+ int mask; /* MNT_{NOMTAB,INVERT,...} mask */
};
/*
char **user, char **vfs, char **fs,
int ifnore_user, int ignore_vfs);
+extern int mnt_optstr_get_options(const char *optstr, char **subset,
+ const struct mnt_optmap *map, int ignore);
+
extern int mnt_optstr_get_flags(const char *optstr, unsigned long *flags,
const struct mnt_optmap *map);
extern int mnt_optstr_apply_flags(char **optstr, unsigned long flags,
extern mnt_fs *mnt_new_fs(void);
extern void mnt_free_fs(mnt_fs *ent);
extern mnt_fs *mnt_copy_fs(const mnt_fs *fs);
+extern mnt_fs *mnt_copy_mtab_fs(const mnt_fs *fs);
extern void *mnt_fs_get_userdata(mnt_fs *fs);
extern int mnt_fs_set_userdata(mnt_fs *fs, void *data);
extern const char *mnt_fs_get_source(mnt_fs *ent);
extern unsigned long mnt_update_get_mountflags(mnt_update *upd);
extern int mnt_update_force_rdonly(mnt_update *upd, int rdonly);
extern const char *mnt_update_get_filename(mnt_update *upd);
+extern mnt_fs *mnt_update_get_fs(mnt_update *upd);
/* context.c */
mnt_update_get_mountflags;
mnt_update_force_rdonly;
mnt_update_get_filename;
-
+ mnt_update_get_fs;
local:
*;
};
}
#else /* !CONFIG_LIBMOUNT_DEBUG */
-# define DBG(m,x)
-# define DBG_FLUSH
+# define DBG(m,x) do { ; } while(0)
+# define DBG_FLUSH do { ; } while(0)
#endif
/* extension for files in the /etc/fstab.d directory */
{ "async", MS_SYNCHRONOUS, MNT_INVERT },/* asynchronous I/O */
{ "dirsync", MS_DIRSYNC }, /* synchronous directory modifications */
- { "remount", MS_REMOUNT }, /* Alter flags of mounted FS */
+ { "remount", MS_REMOUNT, MNT_NOMTAB }, /* alter flags of mounted FS */
{ "bind", MS_BIND }, /* Remount part of tree elsewhere */
{ "rbind", MS_BIND | MS_REC }, /* Idem, plus mounted subtrees */
#ifdef MS_NOSUB
}
} while(1);
- DBG(OPTIONS, mnt_debug("can't found '%s' option", name));
return rc;
}
return 0;
}
+/**
+ * mnt_optstr_get_options
+ * @optstr: string with comma separated list of options
+ * @subset: returns newly allocated string with options
+ * @map: options map
+ * @ignore: mask of the options that should be ignored
+ *
+ * Extracts options from @optstr that belongs to the @map, for example:
+ *
+ * mnt_split_optstr_by_map(optstr, &p,
+ * mnt_get_builtin_optmap(MNT_LINUX_MAP),
+ * MNT_NOMTAB);
+ *
+ * returns all VFS options, the options that does not belong to mtab
+ * are ignored.
+ *
+ * Returns: 0 on success, or negative number in case of error.
+ */
+int mnt_optstr_get_options(const char *optstr, char **subset,
+ const struct mnt_optmap *map, int ignore)
+{
+ struct mnt_optmap const *maps[1];
+ char *name, *val, *str = (char *) optstr;
+ size_t namesz, valsz;
+
+ if (!optstr || !subset)
+ return -EINVAL;
+
+ maps[0] = map;
+ *subset = NULL;
+
+ while(!mnt_optstr_next_option(&str, &name, &namesz, &val, &valsz)) {
+ int rc = 0;
+ const struct mnt_optmap *ent;
+
+ mnt_optmap_get_entry(maps, 1, name, namesz, &ent);
+
+ if (!ent || !ent->id)
+ continue; /* ignore undefined options (comments) */
+
+ if (ignore && (ent->mask & ignore))
+ continue;
+ rc = __mnt_optstr_append_option(subset, name, namesz, val, valsz);
+ if (rc) {
+ free(*subset);
+ return rc;
+ }
+ }
+
+ return 0;
+}
+
+
/**
* mnt_optstr_get_flags:
* @optstr: string with comma separated list of options
if (!filename)
return NULL;
- if (stat(filename, &st) || st.st_size == 0)
+ if (stat(filename, &st))
return NULL;
tb = mnt_new_tab();
if (tb) {
if (rc)
return rc;
} else {
- upd->fs = mnt_copy_fs(fs);
+ upd->fs = mnt_copy_mtab_fs(fs);
if (!upd->fs)
return -ENOMEM;
+
}
}
}
/**
- * Returns update filesystem or NULL
+ * mnt_update_get_fs:
+ * @upd: update
+ *
+ * Returns: update filesystem entry or NULL
*/
mnt_fs *mnt_update_get_fs(mnt_update *upd)
{
{
int rc = 0;
const char *o = NULL, *a = NULL;
+ char *u = NULL;
assert(fs);
assert(ent);
o = mnt_fs_get_userspace_options(fs);
a = mnt_fs_get_attributes(fs);
- if (!o && !a)
- return 1; /* don't have mount options */
+ if (o) {
+ /* remove non-mtab options */
+ rc = mnt_optstr_get_options(o, &u,
+ mnt_get_builtin_optmap(MNT_USERSPACE_MAP),
+ MNT_NOMTAB);
+ if (rc)
+ goto err;
+ }
+
+ if (!u && !a) {
+ DBG(UPDATE, mnt_debug("utab entry unnecessary (no options)"));
+ return 1;
+ }
/* allocate the entry */
*ent = mnt_copy_fs(fs);
goto err;
}
- rc = mnt_fs_set_userspace_options(*ent, o);
+ rc = mnt_fs_set_userspace_options(*ent, u);
if (rc)
goto err;
rc = mnt_fs_set_attributes(*ent, a);
goto err;
}
+ free(u);
DBG(UPDATE, mnt_debug("utab entry OK"));
return 0;
err:
mnt_free_fs(*ent);
+ free(u);
*ent = NULL;
return rc;
}
const char *src, *src_root;
mnt_fs *src_fs;
+ DBG(UPDATE, mnt_debug("setting FS root: bind"));
+
src = mnt_fs_get_srcpath(fs);
if (src) {
rc = mnt_fs_set_bindsrc(result, src);
root = mnt_get_fs_root(src, mnt);
tb = __mnt_new_tab_from_file(_PATH_PROC_MOUNTINFO, MNT_FMT_MOUNTINFO);
- if (!tb)
+ if (!tb) {
+ DBG(UPDATE, mnt_debug("failed to parse mountinfo -- using default"));
goto dflt;
+ }
src_fs = mnt_tab_find_target(tb, mnt, MNT_ITER_BACKWARD);
- if (!src_fs)
+ if (!src_fs) {
+ DBG(UPDATE, mnt_debug("not found '%s' in mountinfo -- using default", mnt));
goto dflt;
+ }
/* set device name and fs */
src = mnt_fs_get_srcpath(src_fs);
if (mnt_fs_get_option(fs, "subvol", &vol, &volsz))
goto dflt;
+ DBG(UPDATE, mnt_debug("setting FS root: btrfs subvol"));
+
sz = volsz;
if (*vol != '/')
sz++;
return 0;
DBG(UPDATE, mnt_debug_h(upd, "%s: update tab", upd->filename));
- DBG(UPDATE, mnt_fs_print_debug(upd->fs, stderr));
+ if (upd->fs) {
+ DBG(UPDATE, mnt_fs_print_debug(upd->fs, stderr));
+ }
if (!upd->fs && upd->target)
rc = update_remove_entry(upd, lc); /* umount */
memcpy(mnt, "/", 2);
done:
- DBG(UTILS, mnt_debug("fs-root for %s is %s", path, mnt));
+ DBG(UTILS, mnt_debug("%s mountpoint is %s", path, mnt));
return mnt;
err:
free(mnt);
char *mnt_get_fs_root(const char *path, const char *mnt)
{
- char *m = (char *) mnt;
+ char *m = (char *) mnt, *res;
const char *p;
size_t sz;
if (m != mnt)
free(m);
- return *p ? strdup(p) : strdup("/");
+ res = *p ? strdup(p) : strdup("/");
+ DBG(UTILS, mnt_debug("%s fs-root is %s", path, res));
+ return res;
}
#ifdef TEST_PROGRAM