The patch also removes obsolete test program from tab_parse.c.
Signed-off-by: Karel Zak <kzak@redhat.com>
/**
* mnt_fs_get_vfs_optstr:
- * @fs: fstab/mtab/mountinfo entry pointer
+ * @fs: fstab/mtab entry pointer
*
* This function works for "mountinfo" files only.
*
/**
* mnt_fs_set_freq:
- * @fs: fstab/mtab/mountinfo entry pointer
+ * @fs: fstab/mtab entry pointer
* @freq: dump frequency in days
*
* Returns 0 on success or -1 in case of error.
int mnt_fs_set_freq(mnt_fs *fs, int freq)
{
assert(fs);
-
if (!fs)
return -1;
fs->freq = freq;
/**
* mnt_fs_get_passno:
- * @fs: fstab/mtab/mountinfo entry pointer
+ * @fs: fstab/mtab entry pointer
*
* Returns "pass number on parallel fsck".
*/
/**
* mnt_fs_set_passno:
- * @fs: fstab/mtab/mountinfo entry pointer
+ * @fs: fstab/mtab entry pointer
* @passno: pass number
*
* Returns 0 on success or -1 in case of error.
int mnt_fs_set_passno(mnt_fs *fs, int passno)
{
assert(fs);
-
if (!fs)
return -1;
fs->passno = passno;
return 0;
}
+/**
+ * mnt_fs_get_id:
+ * @fs: /proc/self/mountinfo entry
+ *
+ * Returns: mount ID (unique identifier of the mount) or -1 if ID undefined
+ * (for example if @fs is not mountinfo entry).
+ */
+int mnt_fs_get_id(mnt_fs *fs)
+{
+ assert(fs);
+ return fs ? fs->id : -1;
+}
+
+/**
+ * mnt_fs_get_parent_id:
+ * @fs: /proc/self/mountinfo entry
+ *
+ * Returns: parent mount ID or -1 if ID undefined (for example if @fs is not
+ * mountinfo entry).
+ */
+int mnt_fs_get_parent_id(mnt_fs *fs)
+{
+ assert(fs);
+ return fs ? fs->parent : -1;
+}
+
+/**
+ * mnt_fs_get_devno:
+ * @fs: /proc/self/mountinfo
+ *
+ * Returns: value of st_dev for files on filesystem or 0 in case of error.
+ */
+dev_t mnt_fs_get_devno(mnt_fs *fs)
+{
+ assert(fs);
+ return fs ? fs->devno : 0;
+}
+
/**
* mnt_fs_get_option:
* @fs: fstab/mtab/mountinfo entry pointer
return optstr ? mnt_optstr_get_option(optstr, name, value, valsz) : 1;
}
-
/**
* mnt_fs_match_target:
* @fs: filesystem
fprintf(file, "optstr: %s\n", mnt_fs_get_optstr(fs));
fprintf(file, "freq: %d\n", mnt_fs_get_freq(fs));
fprintf(file, "pass: %d\n", mnt_fs_get_passno(fs));
+ fprintf(file, "id: %d\n", mnt_fs_get_id(fs));
+ fprintf(file, "parent: %d\n", mnt_fs_get_parent_id(fs));
+ fprintf(file, "devno: %d:%d\n", major(mnt_fs_get_devno(fs)),
+ minor(mnt_fs_get_devno(fs)));
+
return 0;
}
extern int mnt_fs_set_freq(mnt_fs *ent, int freq);
extern int mnt_fs_get_passno(mnt_fs *ent);
extern int mnt_fs_set_passno(mnt_fs *ent, int passno);
+extern int mnt_fs_get_id(mnt_fs *fs);
+extern int mnt_fs_get_parent_id(mnt_fs *fs);
+extern dev_t mnt_fs_get_devno(mnt_fs *fs);
extern int mnt_fs_get_option(mnt_fs *ent, const char *name,
char **value, size_t *valsz);
mnt_free_optls;
mnt_free_tab;
mnt_fs_fprintf;
+ mnt_fs_get_devno;
mnt_fs_get_freq;
mnt_fs_get_fstype;
+ mnt_fs_get_id;
mnt_fs_get_optfs;
mnt_fs_get_option;
mnt_fs_get_optstr;
mnt_fs_get_optvfs;
+ mnt_fs_get_parent_id;
mnt_fs_get_passno;
mnt_fs_get_source;
mnt_fs_get_srcpath;
int id; /* mountinfo[1]: ID */
int parent; /* moutninfo[2]: parent */
+ dev_t devno; /* moutninfo[3]: st_dev */
char *source; /* fstab[1]: mountinfo[10]:
* source dev, file, dir or TAG */
int test_parse(struct mtest *ts, int argc, char *argv[])
{
mnt_tab *tb;
+ mnt_iter *itr;
+ mnt_fs *fs;
tb = create_tab(argv[1]);
if (!tb)
return -1;
- mnt_tab_fprintf(tb, stdout, MNT_MFILE_PRINTFMT);
+ itr = mnt_new_iter(MNT_ITER_FORWARD);
+ if (!itr)
+ goto err;
+ while(mnt_tab_next_fs(tb, itr, &fs) == 0)
+ mnt_fs_print_debug(fs, stdout);
+err:
+ mnt_free_iter(itr);
mnt_free_tab(tb);
return 0;
}
*/
static int mnt_parse_mountinfo_line(mnt_fs *fs, char *s)
{
+ unsigned int maj, min;
+
/* ID */
if (next_number(&s, &fs->id) != 0)
return 1;
if (next_number(&s, &fs->parent) != 0)
return 1;
- /* <maj>:<min> (ignore) */
- if (next_word_skip(&s) != 0)
+ /* <maj>:<min> */
+ s = skip_spaces(s);
+ if (!*s || sscanf(s, "%u:%u", &maj, &min) != 2)
return 1;
+ fs->devno = makedev(maj, min);
+ next_word_skip(&s);
/* MOUNTROOT */
fs->mntroot = next_word(&s);
return buf;
}
-#ifdef LIBMOUNT_TEST_PROGRAM
-int test_parse(struct mtest *ts, int argc, char *argv[])
-{
- mnt_tab *tb;
- mnt_fs *fs;
- mnt_iter *itr;
-
- if (argc != 2)
- goto err;
-
- tb = mnt_new_tab(argv[1]);
- if (!tb)
- 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));
- printf("\t%s\n", buf);
- goto err;
- }
-
- itr = mnt_new_iter(MNT_ITER_FORWARD);
- if (!itr)
- goto err;
- while(mnt_tab_next_fs(tb, itr, &fs) == 0) {
- const char *tg, *vl;
-
- if (mnt_fs_get_tag(fs, &tg, &vl) == 0)
- printf("%s=%s", tg, vl);
- else
- printf("%s", mnt_fs_get_srcpath(fs));
-
- printf("|%s|%s|%s|%d|%d|\n",
- mnt_fs_get_target(fs),
- mnt_fs_get_fstype(fs),
- mnt_fs_get_optstr(fs),
- mnt_fs_get_freq(fs),
- mnt_fs_get_passno(fs));
- }
- mnt_free_tab(tb);
- mnt_free_iter(itr);
-
- return 0;
-err:
- return -1;
-}
-
-int main(int argc, char *argv[])
-{
- struct mtest tss[] = {
- { "--parse", test_parse, "<file> parse the {fs,m}tab or mountinfo file" },
- { NULL }
- };
- return mnt_run_test(tss, argc, argv);
-}
-
-#endif /* LIBMOUNT_TEST_PROGRAM */