From: Karel Zak Date: Fri, 26 Aug 2022 09:29:02 +0000 (+0200) Subject: libmount: (optlist) fix ro/rw use X-Git-Tag: v2.39-rc1~273 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=54652e48ac278650c53613844e58d6d37e041797;p=thirdparty%2Futil-linux.git libmount: (optlist) fix ro/rw use Signed-off-by: Karel Zak --- diff --git a/libmount/src/optlist.c b/libmount/src/optlist.c index 3afe946391..1bcf9641ed 100644 --- a/libmount/src/optlist.c +++ b/libmount/src/optlist.c @@ -744,19 +744,20 @@ int mnt_optlist_strdup_optstr(struct libmnt_optlist *ls, char **optstr, struct libmnt_opt *opt; struct ul_buffer buf = UL_INIT_BUFFER; char *str = NULL; - int rc = 0; + int rc = 0, is_rdonly = 0, xx_wanted = 0; if (!ls || !optstr) return -EINVAL; *optstr = NULL; - /* For generic options stings ro/rw is expected at the begining */ - if (!map && (what == MNT_OL_FLTR_DFLT || what == MNT_OL_FLTR_ALL)) { - opt = mnt_optlist_get_opt(ls, MS_RDONLY, ls->linux_map); - rc = mnt_buffer_append_option(&buf, opt ? "ro" : "rw", 2, NULL, 0); + /* For generic options srings ro/rw is expected at the begining */ + if ((!map || map == ls->linux_map) + && (what == MNT_OL_FLTR_DFLT || what == MNT_OL_FLTR_ALL)) { + rc = mnt_buffer_append_option(&buf, "rw", 2, NULL, 0); if (rc) goto fail; + xx_wanted = 1; } mnt_reset_iter(&itr, MNT_ITER_FORWARD); @@ -764,8 +765,10 @@ int mnt_optlist_strdup_optstr(struct libmnt_optlist *ls, char **optstr, while (mnt_optlist_next_opt(ls, &itr, &opt) == 0) { if (!opt->name) continue; - if (opt->map == ls->linux_map && opt->ent->id == MS_RDONLY) + if (opt->map == ls->linux_map && opt->ent->id == MS_RDONLY) { + is_rdonly = opt->ent->mask & MNT_INVERT ? 0 : 1; continue; + } if (!is_wanted_opt(opt, map, what)) continue; rc = mnt_buffer_append_option(&buf, @@ -777,6 +780,14 @@ int mnt_optlist_strdup_optstr(struct libmnt_optlist *ls, char **optstr, } str = ul_buffer_get_data(&buf, NULL, NULL); + + /* convert 'rw' at the beginning to 'ro' if necessary */ + if (str && is_rdonly && xx_wanted + && (what == MNT_OL_FLTR_DFLT || what == MNT_OL_FLTR_ALL)) { + str[0] = 'r'; + str[1] = 'o'; + } + if (optstr) *optstr = str; return 0;