From: Karel Zak Date: Mon, 21 Jun 2010 20:47:48 +0000 (+0200) Subject: libmount: remove mnt_tab_strerr() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=911238af459a224a24d6a7e11222e0788afd99fa;p=util-linux libmount: remove mnt_tab_strerr() Signed-off-by: Karel Zak --- diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 2b3a50b3..1754da1d 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -321,12 +321,6 @@ static mnt_tab *parse_tabfile(const char *path) warn(_("can't read: %s"), path); return NULL; } - if (mnt_tab_get_nerrs(tb)) { - char buf[BUFSIZ]; - mnt_tab_strerror(tb, buf, sizeof(buf)); - warnx(_("%s: parse error: %s"), path, buf); - } - return tb; } diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in index b1d66074..d3a577a1 100644 --- a/shlibs/mount/src/mount.h.in +++ b/shlibs/mount/src/mount.h.in @@ -268,7 +268,6 @@ extern mnt_tab *mnt_new_tab_from_file(const char *filename); extern int mnt_tab_parse_file(mnt_tab *tb); extern int mnt_tab_set_parser_errcb(mnt_tab *tb, int (*cb)(mnt_tab *tb, const char *filename, int line, int flag)); -extern int mnt_tab_get_nerrs(mnt_tab *tb); /* tab.c */ extern mnt_tab *mnt_new_tab(const char *filename); diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym index f6035e4b..7cd79498 100644 --- a/shlibs/mount/src/mount.sym +++ b/shlibs/mount/src/mount.sym @@ -117,7 +117,6 @@ global: mnt_tab_get_cache; mnt_tab_get_name; mnt_tab_get_nents; - mnt_tab_get_nerrs; mnt_tab_get_root_fs; mnt_tab_next_child_fs; mnt_tab_next_fs; @@ -126,7 +125,6 @@ global: mnt_tab_set_cache; mnt_tab_set_parser_errcb; mnt_tab_set_iter; - mnt_tab_strerror; mnt_tab_update_file; mnt_unlock_file; mnt_init_debug; diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h index 63997544..16f66cb4 100644 --- a/shlibs/mount/src/mountP.h +++ b/shlibs/mount/src/mountP.h @@ -142,7 +142,6 @@ struct _mnt_fs { int passno; /* fstab[6]: pass number on parallel fsck */ int flags; /* MNT_FS_* flags */ - int lineno; /* line number in the parental file */ void *userdata; /* library independent data */ }; @@ -150,9 +149,8 @@ struct _mnt_fs { /* * fs flags */ -#define MNT_FS_ERROR (1 << 1) /* broken entry */ -#define MNT_FS_PSEUDO (1 << 2) /* pseudo filesystem */ -#define MNT_FS_NET (1 << 3) /* network filesystem */ +#define MNT_FS_PSEUDO (1 << 1) /* pseudo filesystem */ +#define MNT_FS_NET (1 << 2) /* network filesystem */ /* * File format @@ -168,10 +166,7 @@ enum { struct _mnt_tab { char *filename; /* file name or NULL */ int fmt; /* MNT_FMT_* file format */ - - int nlines; /* number of lines in the file (include commentrys) */ int nents; /* number of valid entries */ - int nerrs; /* number of broken entries (parse errors) */ mnt_cache *cache; /* canonicalized paths/tags cache */ diff --git a/shlibs/mount/src/tab.c b/shlibs/mount/src/tab.c index cb6a91d3..c7665ee4 100644 --- a/shlibs/mount/src/tab.c +++ b/shlibs/mount/src/tab.c @@ -194,10 +194,7 @@ int mnt_tab_add_fs(mnt_tab *tb, mnt_fs *fs) tb->filename, mnt_fs_get_source(fs), mnt_fs_get_target(fs))); - if (fs->flags & MNT_FS_ERROR) - tb->nerrs++; - else - tb->nents++; + tb->nents++; return 0; } @@ -218,10 +215,7 @@ int mnt_tab_remove_fs(mnt_tab *tb, mnt_fs *fs) list_del(&fs->ents); - if (fs->flags & MNT_FS_ERROR) - tb->nerrs--; - else - tb->nents--; + tb->nents--; return 0; } @@ -359,7 +353,6 @@ int mnt_tab_next_fs(mnt_tab *tb, mnt_iter *itr, mnt_fs **fs) if (!tb || !itr || !fs) return -1; -again: rc = 1; if (!itr->head) MNT_ITER_INIT(itr, &tb->ents); @@ -368,10 +361,6 @@ again: rc = 0; } - /* ignore broken entries */ - if (*fs && ((*fs)->flags & MNT_FS_ERROR)) - goto again; - return rc; } @@ -406,8 +395,6 @@ int mnt_tab_find_next_fs(mnt_tab *tb, mnt_iter *itr, else break; /* end */ - if ((*fs)->flags & MNT_FS_ERROR) - continue; if (match_func(*fs, userdata)) return 0; } while(1); @@ -775,40 +762,6 @@ error: } #ifdef TEST_PROGRAM -int test_strerr(struct mtest *ts, int argc, char *argv[]) -{ - char buf[BUFSIZ]; - mnt_tab *tb; - int i; - - tb = mnt_new_tab("-test-"); - if (!tb) - goto err; - - for (i = 0; i < 10; i++) { - mnt_fs *fs = mnt_new_fs(); - if (!fs) - goto err; - if (i % 2) - fs->flags |= MNT_FS_ERROR; /* mark entry as broken */ - fs->lineno = i+1; - mnt_tab_add_fs(tb, fs); - } - - printf("\tadded %d valid lines\n", mnt_tab_get_nents(tb)); - printf("\tadded %d broken lines\n", mnt_tab_get_nerrs(tb)); - - if (!mnt_tab_get_nerrs(tb)) /* report broken entries */ - goto err; - mnt_tab_strerror(tb, buf, sizeof(buf)); - printf("\t%s\n", buf); - - mnt_free_tab(tb); - return 0; -err: - return -1; -} - mnt_tab *create_tab(const char *file) { mnt_tab *tb; @@ -820,12 +773,6 @@ mnt_tab *create_tab(const char *file) goto err; if (mnt_tab_parse_file(tb) != 0) goto err; - if (mnt_tab_get_nerrs(tb)) { - char buf[BUFSIZ]; - mnt_tab_strerror(tb, buf, sizeof(buf)); - fprintf(stderr, "%s\n", buf); - goto err; - } return tb; err: mnt_free_tab(tb); @@ -916,7 +863,6 @@ int test_find_fw(struct mtest *ts, int argc, char *argv[]) int main(int argc, char *argv[]) { struct mtest tss[] = { - { "--strerror", test_strerr, " test tab error reporting" }, { "--parse", test_parse, " parse and print tab" }, { "--find-forward", test_find_fw, " " }, { "--find-backward", test_find_bw, " " }, diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c index 0c4059da..4942692a 100644 --- a/shlibs/mount/src/tab_parse.c +++ b/shlibs/mount/src/tab_parse.c @@ -284,7 +284,7 @@ static char *merge_optstr(const char *vfs, const char *fs) /* * Read and parse the next line from {fs,m}tab or mountinfo */ -static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs) +static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs, int *nlines) { char buf[BUFSIZ]; char *s; @@ -297,7 +297,7 @@ static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs) do { if (fgets(buf, sizeof(buf), f) == NULL) return -1; - tb->nlines++; + ++*nlines; s = index (buf, '\n'); if (!s) { /* Missing final newline? Otherwise extremely */ @@ -310,7 +310,7 @@ static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs) } else { DBG(DEBUG_TAB, fprintf(stderr, "libmount: %s: %d: missing newline at line\n", - tb->filename, tb->nlines)); + tb->filename, *nlines)); goto err; } } @@ -321,7 +321,7 @@ static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs) } while (*s == '\0' || *s == '#'); DBG(DEBUG_TAB, fprintf(stderr, "libmount: %s:%d: %s\n", - tb->filename, tb->nlines, s)); + tb->filename, *nlines, s)); if (!tb->fmt) tb->fmt = detect_fmt(s); @@ -343,25 +343,18 @@ static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs) goto err; } - fs->lineno = tb->nlines; - DBG(DEBUG_TAB, fprintf(stderr, "libmount: %s: %d: SOURCE:%s, MNTPOINT:%s, TYPE:%s, " "OPTS:%s, FREQ:%d, PASSNO:%d\n", - tb->filename, fs->lineno, + tb->filename, *nlines, fs->source, fs->target, fs->fstype, fs->optstr, fs->freq, fs->passno)); return 0; err: if (tb->errcb) - return tb->errcb(tb, NULL, tb->nlines, 0); + return tb->errcb(tb, NULL, *nlines, 0); - /* we don't report parse errors to caller; caller has to check - * errors by mnt_tab_get_nerrs() or internaly by MNT_ENTRY_ERR flag - */ - fs->lineno = tb->nlines; - fs->flags |= MNT_FS_ERROR; return 0; } @@ -394,6 +387,7 @@ err: int mnt_tab_parse_file(mnt_tab *tb) { FILE *f; + int nlines = 0; assert(tb); assert(tb->filename); @@ -411,7 +405,7 @@ int mnt_tab_parse_file(mnt_tab *tb) if (!fs) goto error; - rc = mnt_tab_parse_next(tb, f, fs); + rc = mnt_tab_parse_next(tb, f, fs, &nlines); if (!rc) rc = mnt_tab_add_fs(tb, fs); else if (feof(f)) { @@ -476,72 +470,3 @@ int mnt_tab_set_parser_errcb(mnt_tab *tb, return 0; } -/** - * mnt_tab_get_nerrs: - * @tb: pointer to table - * - * Returns: number of broken (parse error) entries in the table. - */ -int mnt_tab_get_nerrs(mnt_tab *tb) -{ - assert(tb); - return tb->nerrs; -} - -/** - * mnt_tab_strerror: - * @tb: pointer to table - * @buf: buffer to return error message - * @buflen: lenght of the buf - * - * Returns: error message for table (file) parse errors. For example: - * - * "/etc/fstab: parse error at line(s): 1, 2 and 3." - */ -char *mnt_tab_strerror(mnt_tab *tb, char *buf, size_t buflen) -{ - struct list_head *p; - int last = -1; - char *b = buf; - char *end = buf + buflen - 1; - - assert(tb); - assert(buf); - assert(buflen); - - if (!tb || !tb->nerrs || !buf || buflen <=0) - return NULL; - - if (tb->filename) { - snprintf(b, end - b, "%s: ", tb->filename); - b += strnlen(b, end - b); - } - - if (tb->nerrs > 1) - strncpy(b, _("parse error at lines: "), end - b); - else - strncpy(b, _("parse error at line: "), end - b); - b += strnlen(b, end - b); - *b = '\0'; - - list_for_each(p, &tb->ents) { - mnt_fs *fs = list_entry(p, mnt_fs, ents); - if (b == end) - goto done; - if (fs->flags & MNT_FS_ERROR) { - if (last != -1) { - snprintf(b, end - b, "%d, ", last); - b += strnlen(b, end - b); - } - last = fs->lineno; - } - } - - if (tb->nerrs == 1) - snprintf(b, end - b, "%d.", last); - else - snprintf(b - 1, end - b, _(" and %d."), last); -done: - return buf; -} -