if (!cxt)
return -EINVAL;
+ if (cxt->fs == fs)
+ return 0;
+
DBG(CXT, ul_debugobj(cxt, "setting new FS"));
- mnt_ref_fs(fs); /* new */
- mnt_unref_fs(cxt->fs); /* old */
+
+ /* new */
+ if (fs) {
+ struct libmnt_optlist *ol = mnt_context_get_optlist(cxt);
+
+ if (!ol)
+ return -ENOMEM;
+
+ mnt_ref_fs(fs);
+
+ mnt_optlist_set_optstr(ol, mnt_fs_get_options(fs), NULL);
+ mnt_fs_follow_optlist(fs, ol);
+ }
+
+ /* old */
+ if (cxt->fs)
+ mnt_fs_follow_optlist(cxt->fs, NULL);
+ mnt_unref_fs(cxt->fs);
+
cxt->fs = fs;
return 0;
}
{
if (!cxt)
return NULL;
- if (!cxt->fs)
+ if (!cxt->fs) {
+ struct libmnt_optlist *ol = mnt_context_get_optlist(cxt);
+
+ if (!ol)
+ return NULL;
cxt->fs = mnt_new_fs();
+ if (!cxt->fs)
+ return NULL;
+
+ mnt_fs_follow_optlist(cxt->fs, ol);
+ }
return cxt->fs;
}
return rc;
}
+static int test_cxtsync(struct libmnt_test *ts, int argc, char *argv[])
+{
+ struct libmnt_context *cxt;
+ struct libmnt_fs *fs;
+ unsigned long flags = 0;
+ int rc;
+
+ if (argc != 4)
+ return -EINVAL;
+
+ fs = mnt_new_fs();
+ if (!fs)
+ return -ENOMEM;
+
+ rc = mnt_fs_set_options(fs, argv[1]);
+ if (rc)
+ return rc;
+
+ cxt = mnt_new_context();
+ if (!cxt)
+ return -ENOMEM;
+
+ rc = mnt_context_set_fs(cxt, fs);
+ if (rc)
+ return rc;
+
+ rc = mnt_context_append_options(cxt, argv[2]);
+ if (rc)
+ return rc;
+
+ rc = mnt_fs_append_options(fs, argv[3]);
+ if (rc)
+ return rc;
+
+ mnt_context_get_mflags(cxt, &flags);
+
+ printf(" fs options: %s\n", mnt_fs_get_options(fs));
+ printf("context options: %s\n", mnt_context_get_options(cxt));
+ printf(" context mflags: %08lx\n", flags);
+
+ mnt_free_context(cxt);
+ return 0;
+}
+
static int test_mountall(struct libmnt_test *ts, int argc, char *argv[])
{
struct libmnt_context *cxt;
return 0;
}
+
+
int main(int argc, char *argv[])
{
struct libmnt_test tss[] = {
{ "--umount", test_umount, "[-t <type>] [-f][-l][-r] <src>|<target>" },
{ "--mount-all", test_mountall, "[-O <pattern>] [-t <pattern] mount all filesystems from fstab" },
{ "--flags", test_flags, "[-o <opts>] <spec>" },
+ { "--cxtsync", test_cxtsync, "<fsopts> <cxtopts> <fsopts>" },
{ "--search-helper", test_search_helper, "<fstype>" },
{ NULL }};
if (fs->optlist == ol)
return 0;
+ if (fs->optlist)
+ mnt_unref_optlist(fs->optlist);
fs->opts_age = 0;
fs->optlist = ol;
- mnt_ref_optlist(ol);
+
+ if (ol)
+ mnt_ref_optlist(ol);
return 0;
}
if (!fs)
return -EINVAL;
- fs->opts_age = 0;
+
+ if (fs->optlist) {
+ fs->opts_age = 0;
+ return mnt_optlist_set_optstr(fs->optlist, optstr, NULL);
+ }
if (optstr) {
int rc = mnt_split_optstr(optstr, &u, &v, &f, 0, 0);
return -EINVAL;
if (!optstr)
return 0;
-
- fs->opts_age = 0;
+ if (fs->optlist) {
+ fs->opts_age = 0;
+ return mnt_optlist_append_optstr(fs->optlist, optstr, NULL);
+ }
rc = mnt_split_optstr(optstr, &u, &v, &f, 0, 0);
if (rc)
if (!optstr)
return 0;
- fs->opts_age = 0;
+ if (fs->optlist) {
+ fs->opts_age = 0;
+ return mnt_optlist_prepend_optstr(fs->optlist, optstr, NULL);
+ }
rc = mnt_split_optstr(optstr, &u, &v, &f, 0, 0);
if (rc)