From 1e8c936978f5467a50732a072084337653820bba Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 12 Jan 2012 16:52:32 +0100 Subject: libmount: make options in fstab optional .. to be compatible with old mount(8). Signed-off-by: Karel Zak --- libmount/src/tab_parse.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'libmount/src/tab_parse.c') diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 4ee590889..6cd66afeb 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -52,8 +52,8 @@ static int next_number(char **s, int *num) */ static int mnt_parse_table_line(struct libmnt_fs *fs, char *s) { - int rc, n = 0; - char *src, *fstype, *optstr; + int rc, n = 0, xrc; + char *src = NULL, *fstype = NULL, *optstr = NULL; rc = sscanf(s, UL_SCNsA" " /* (1) source */ UL_SCNsA" " /* (2) target */ @@ -66,17 +66,20 @@ static int mnt_parse_table_line(struct libmnt_fs *fs, char *s) &fstype, &optstr, &n); + xrc = rc; - if (rc == 4) { + if (rc == 3 || rc == 4) { /* options are optional */ unmangle_string(src); unmangle_string(fs->target); unmangle_string(fstype); - unmangle_string(optstr); + + if (optstr && *optstr) + unmangle_string(optstr); rc = __mnt_fs_set_source_ptr(fs, src); if (!rc) rc = __mnt_fs_set_fstype_ptr(fs, fstype); - if (!rc) + if (!rc && optstr) rc = mnt_fs_set_options(fs, optstr); free(optstr); } else { @@ -84,12 +87,16 @@ static int mnt_parse_table_line(struct libmnt_fs *fs, char *s) rc = -EINVAL; } - if (rc) + if (rc) { + DBG(TAB, mnt_debug("tab parse error: [set vars, rc=%d]\n", rc)); return rc; /* error */ + } fs->passno = fs->freq = 0; - s = skip_spaces(s + n); - if (*s) { + + if (xrc == 4 && n) + s = skip_spaces(s + n); + if (xrc == 4 && *s) { if (next_number(&s, &fs->freq) != 0) { if (*s) { DBG(TAB, mnt_debug("tab parse error: [freq]")); -- cgit v1.2.3-55-g7522