summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--shlibs/mount/src/mount.h.in6
-rw-r--r--shlibs/mount/src/mountP.h1
-rw-r--r--shlibs/mount/src/tab.c63
-rw-r--r--shlibs/mount/src/tab_parse.c48
4 files changed, 48 insertions, 70 deletions
diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in
index d3a577a11..8f1ecaad8 100644
--- a/shlibs/mount/src/mount.h.in
+++ b/shlibs/mount/src/mount.h.in
@@ -265,12 +265,12 @@ extern int mnt_fs_print_debug(mnt_fs *ent, FILE *file);
/* tab-parse.c */
extern mnt_tab *mnt_new_tab_from_file(const char *filename);
-extern int mnt_tab_parse_file(mnt_tab *tb);
+extern int mnt_tab_parse_file(mnt_tab *tb, const char *filename);
extern int mnt_tab_set_parser_errcb(mnt_tab *tb,
int (*cb)(mnt_tab *tb, const char *filename, int line, int flag));
/* tab.c */
-extern mnt_tab *mnt_new_tab(const char *filename);
+extern mnt_tab *mnt_new_tab(void);
extern void mnt_free_tab(mnt_tab *tb);
extern int mnt_tab_get_nents(mnt_tab *tb);
extern int mnt_tab_set_cache(mnt_tab *tb, mnt_cache *mpc);
@@ -295,7 +295,7 @@ extern int mnt_tab_find_next_fs(mnt_tab *tb, mnt_iter *itr,
mnt_fs **fs);
extern int mnt_tab_fprintf(mnt_tab *tb, FILE *f, const char *fmt);
-extern int mnt_tab_update_file(mnt_tab *tb);
+extern int mnt_tab_update_file(mnt_tab *tb, const char *filename);
/*
diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h
index 16f66cb4a..c804b5de4 100644
--- a/shlibs/mount/src/mountP.h
+++ b/shlibs/mount/src/mountP.h
@@ -164,7 +164,6 @@ enum {
* mtab/fstab/mountinfo file
*/
struct _mnt_tab {
- char *filename; /* file name or NULL */
int fmt; /* MNT_FMT_* file format */
int nents; /* number of valid entries */
diff --git a/shlibs/mount/src/tab.c b/shlibs/mount/src/tab.c
index 4c06d8beb..45e52e1b6 100644
--- a/shlibs/mount/src/tab.c
+++ b/shlibs/mount/src/tab.c
@@ -59,34 +59,26 @@
/**
* mnt_new_tab:
- * @filename: file name or NULL
*
* The tab is a container for mnt_fs entries that usually represents a fstab,
* mtab or mountinfo file from your system.
*
- * Note that this function does not parse the file. See also
- * mnt_tab_parse_file().
+ * See also mnt_tab_parse_file().
*
* Returns: newly allocated tab struct.
*/
-mnt_tab *mnt_new_tab(const char *filename)
+mnt_tab *mnt_new_tab(void)
{
mnt_tab *tb = NULL;
tb = calloc(1, sizeof(struct _mnt_tab));
if (!tb)
- goto err;
+ return NULL;
+
+ DBG(DEBUG_TAB, fprintf(stderr, "libmount: new tab %p\n", tb));
- if (filename) {
- tb->filename = strdup(filename);
- if (!tb->filename)
- goto err;
- }
INIT_LIST_HEAD(&tb->ents);
return tb;
-err:
- free(tb);
- return NULL;
}
/**
@@ -99,7 +91,6 @@ void mnt_free_tab(mnt_tab *tb)
{
if (!tb)
return;
- free(tb->filename);
while (!list_empty(&tb->ents)) {
mnt_fs *fs = list_entry(tb->ents.next, mnt_fs, ents);
@@ -159,18 +150,6 @@ mnt_cache *mnt_tab_get_cache(mnt_tab *tb)
}
/**
- * mnt_tab_get_name:
- * @tb: tab pointer
- *
- * Returns: tab filename or NULL.
- */
-const char *mnt_tab_get_name(mnt_tab *tb)
-{
- assert(tb);
- return tb ? tb->filename : NULL;
-}
-
-/**
* mnt_tab_add_fs:
* @tb: tab pointer
* @fs: new entry
@@ -190,8 +169,8 @@ int mnt_tab_add_fs(mnt_tab *tb, mnt_fs *fs)
list_add_tail(&fs->ents, &tb->ents);
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s: add entry: %s %s\n",
- tb->filename, mnt_fs_get_source(fs),
+ "libmount: tab %p: add entry: %s %s\n",
+ tb, mnt_fs_get_source(fs),
mnt_fs_get_target(fs)));
tb->nents++;
@@ -238,8 +217,7 @@ int mnt_tab_get_root_fs(mnt_tab *tb, mnt_fs **root)
if (!tb || !root)
return -1;
- DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s: lookup root fs\n", tb->filename));
+ DBG(DEBUG_TAB, fprintf(stderr, "libmount: tab %p: lookup root fs\n", tb));
mnt_reset_iter(&itr, MNT_ITER_FORWARD);
while(mnt_tab_next_fs(tb, &itr, &fs) == 0) {
@@ -278,8 +256,8 @@ int mnt_tab_next_child_fs(mnt_tab *tb, mnt_iter *itr,
return -1;
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s: lookup next child of %s\n",
- tb->filename, mnt_fs_get_target(parent)));
+ "libmount: tab %p: lookup next child of %s\n",
+ tb, mnt_fs_get_target(parent)));
parent_id = mnt_fs_get_id(parent);
if (!parent_id)
@@ -384,7 +362,7 @@ int mnt_tab_find_next_fs(mnt_tab *tb, mnt_iter *itr,
return -1;
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s: lookup next fs\n", tb->filename));
+ "libmount: tab %p: lookup next fs\n", tb));
if (!itr->head)
MNT_ITER_INIT(itr, &tb->ents);
@@ -451,7 +429,7 @@ mnt_fs *mnt_tab_find_target(mnt_tab *tb, const char *path, int direction)
assert(path);
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s: lookup target: %s\n", tb->filename, path));
+ "libmount: tab %p: lookup target: %s\n", tb, path));
/* native @target */
mnt_reset_iter(&itr, direction);
@@ -509,7 +487,7 @@ mnt_fs *mnt_tab_find_srcpath(mnt_tab *tb, const char *path, int direction)
assert(path);
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s: lookup srcpath: %s\n", tb->filename, path));
+ "libmount: tab %p: lookup srcpath: %s\n", tb, path));
/* native paths */
mnt_reset_iter(&itr, direction);
@@ -611,7 +589,7 @@ mnt_fs *mnt_tab_find_tag(mnt_tab *tb, const char *tag,
return NULL;
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s: lookup by TAG: %s %s\n", tb->filename, tag, val));
+ "libmount: tab %p: lookup by TAG: %s %s\n", tb, tag, val));
/* look up by TAG */
mnt_reset_iter(&itr, direction);
@@ -654,7 +632,7 @@ mnt_fs *mnt_tab_find_source(mnt_tab *tb, const char *source, int direction)
return NULL;
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s: lookup SOURCE: %s\n", tb->filename, source));
+ "libmount: tab %p: lookup SOURCE: %s\n", tb, source));
if (strchr(source, '=')) {
char *tag, *val;
@@ -710,11 +688,10 @@ int mnt_tab_fprintf(mnt_tab *tb, FILE *f, const char *fmt)
*
* Returns: 0 on success, -1 in case of error.
*/
-int mnt_tab_update_file(mnt_tab *tb)
+int mnt_tab_update_file(mnt_tab *tb, const char *filename)
{
FILE *f = NULL;
char tmpname[PATH_MAX];
- const char *filename;
struct stat st;
int fd;
@@ -722,10 +699,6 @@ int mnt_tab_update_file(mnt_tab *tb)
if (!tb)
goto error;
- filename = mnt_tab_get_name(tb);
- if (!filename)
- goto error;
-
if (snprintf(tmpname, sizeof(tmpname), "%s.tmp", filename)
>= sizeof(tmpname))
goto error;
@@ -775,13 +748,13 @@ mnt_tab *create_tab(const char *file)
if (!file)
return NULL;
- tb = mnt_new_tab(file);
+ tb = mnt_new_tab();
if (!tb)
goto err;
mnt_tab_set_parser_errcb(tb, parser_errcb);
- if (mnt_tab_parse_file(tb) != 0)
+ if (mnt_tab_parse_file(tb, file) != 0)
goto err;
return tb;
err:
diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c
index d7cb1b77a..69443ca7a 100644
--- a/shlibs/mount/src/tab_parse.c
+++ b/shlibs/mount/src/tab_parse.c
@@ -284,7 +284,8 @@ 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, int *nlines)
+static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs,
+ const char *filename, int *nlines)
{
char buf[BUFSIZ];
char *s;
@@ -305,12 +306,12 @@ static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs, int *nlines)
if (feof(f)) {
DBG(DEBUG_TAB, fprintf(stderr,
"libmount: WARNING: no final newline at the end of %s\n",
- tb->filename));
+ filename));
s = index (buf, '\0');
} else {
DBG(DEBUG_TAB, fprintf(stderr,
"libmount: %s: %d: missing newline at line\n",
- tb->filename, *nlines));
+ filename, *nlines));
goto err;
}
}
@@ -321,7 +322,7 @@ static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs, int *nlines)
} while (*s == '\0' || *s == '#');
DBG(DEBUG_TAB, fprintf(stderr, "libmount: %s:%d: %s\n",
- tb->filename, *nlines, s));
+ filename, *nlines, s));
if (!tb->fmt)
tb->fmt = detect_fmt(s);
@@ -345,18 +346,18 @@ static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs, int *nlines)
}
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s:%d: SOURCE:%s, MNTPOINT:%s, TYPE:%s, "
+ "libmount: tab %p: %s:%d: SOURCE:%s, MNTPOINT:%s, TYPE:%s, "
"OPTS:%s, FREQ:%d, PASSNO:%d\n",
- tb->filename, *nlines,
+ tb, filename, *nlines,
fs->source, fs->target, fs->fstype,
fs->optstr, fs->freq, fs->passno));
return 0;
err:
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s:%d: parse error\n", tb->filename, *nlines));
+ "libmount: tab %p: %s:%d: parse error\n", tb, filename, *nlines));
- if (tb->errcb && tb->errcb(tb, tb->filename, *nlines, 0))
+ if (tb->errcb && tb->errcb(tb, filename, *nlines, 0))
return -1; /* fatal error */
return 1; /* recoverable error */
@@ -365,20 +366,18 @@ err:
/**
* mnt_tab_parse_file:
* @tb: tab pointer
+ * @filename: file
*
* Parses whole table (e.g. /etc/fstab).
*
* <informalexample>
* <programlisting>
- * mnt_tab *tb = mnt_new_tab("/etc/fstab");
+ * mnt_tab *tb = mnt_new_tab();
* int rc;
*
- * rc = mnt_tab_parse_file(tb);
- * if (rc)
- * perror(mnt_tab_get_name(tb)); / * system error * /
- * else
+ * rc = mnt_tab_parse_file(tb, "/etc/fstab");
+ * if (!rc)
* mnt_fprintf_tab(tb, stdout, NULL);
- *
* mnt_free_tab(tb);
* </programlisting>
* </informalexample>
@@ -388,21 +387,24 @@ err:
*
* Returns: 0 on success, -1 in case of error.
*/
-int mnt_tab_parse_file(mnt_tab *tb)
+int mnt_tab_parse_file(mnt_tab *tb, const char *filename)
{
FILE *f;
int nlines = 0;
assert(tb);
- assert(tb->filename);
+ assert(filename);
- if (!tb->filename)
+ if (!filename)
return -1;
- f = fopen(tb->filename, "r");
+ f = fopen(filename, "r");
if (!f)
return -1;
+ DBG(DEBUG_TAB,
+ fprintf(stderr, "libmount: tab %p: start parsing %s\n", tb, filename));
+
while (!feof(f)) {
int rc;
mnt_fs *fs = mnt_new_fs();
@@ -410,7 +412,7 @@ int mnt_tab_parse_file(mnt_tab *tb)
if (!fs)
goto error;
- rc = mnt_tab_parse_next(tb, f, fs, &nlines);
+ rc = mnt_tab_parse_next(tb, f, fs, filename, &nlines);
if (!rc)
rc = mnt_tab_add_fs(tb, fs);
if (rc) {
@@ -423,9 +425,13 @@ int mnt_tab_parse_file(mnt_tab *tb)
}
}
+ DBG(DEBUG_TAB,
+ fprintf(stderr, "libmount: tab %p: stop parsing %s\n", tb, filename));
fclose(f);
return 0;
error:
+ DBG(DEBUG_TAB,
+ fprintf(stderr, "libmount: tab %p: error parsing %s\n", tb, filename));
fclose(f);
return -1;
}
@@ -448,8 +454,8 @@ mnt_tab *mnt_new_tab_from_file(const char *filename)
if (!filename)
return NULL;
- tb = mnt_new_tab(filename);
- if (tb && mnt_tab_parse_file(tb) != 0) {
+ tb = mnt_new_tab();
+ if (tb && mnt_tab_parse_file(tb, filename) != 0) {
mnt_free_tab(tb);
tb = NULL;
}