mnt_free_fs(fs);
}
- tb->nents = 0;
return 0;
}
* Returns: number of valid entries in tab.
*/
int mnt_table_get_nents(struct libmnt_table *tb)
+{
+ struct list_head *p;
+ int i = 0;
+
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ if (list_empty(&tb->ents))
+ return 0;
+ list_for_each(p, &tb->ents)
+ i++;
+ return i;
+}
+
+/**
+ * mnt_table_is_empty:
+ * @tb: pointer to tab
+ *
+ * Returns: 1 if the table is without filesystems, or 0.
+ */
+int mnt_table_is_empty(struct libmnt_table *tb)
{
assert(tb);
- return tb ? tb->nents : 0;
+ return tb == NULL || list_empty(&tb->ents) ? 1 : 0;
}
/**
DBG(TAB, mnt_debug_h(tb, "add entry: %s %s",
mnt_fs_get_source(fs), mnt_fs_get_target(fs)));
- tb->nents++;
return 0;
}
if (!tb || !fs)
return -EINVAL;
list_del(&fs->ents);
- tb->nents--;
return 0;
}
{
struct libmnt_iter itr;
struct libmnt_fs *fs = NULL;
- int ntags = 0;
+ int ntags = 0, nents;
char *cn;
const char *p;
DBG(TAB, mnt_debug_h(tb, "lookup canonical SRCPATH: '%s'", cn));
+ nents = mnt_table_get_nents(tb);
+
/* canonicalized paths in struct libmnt_table */
- if (ntags < mnt_table_get_nents(tb)) {
+ if (ntags < nents) {
mnt_reset_iter(&itr, direction);
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
if (mnt_fs_streq_srcpath(fs, cn))
}
/* non-canonicalized paths in struct libmnt_table */
- if (ntags <= mnt_table_get_nents(tb)) {
+ if (ntags <= nents) {
mnt_reset_iter(&itr, direction);
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
if (mnt_fs_is_netfs(fs) || mnt_fs_is_pseudofs(fs))
DBG(FS, mnt_debug_h(fstab_fs, "is FS mounted? [target=%s]",
mnt_fs_get_target(fstab_fs)));
- if (mnt_fs_is_swaparea(fstab_fs) || mnt_table_get_nents(tb) == 0) {
+ if (mnt_fs_is_swaparea(fstab_fs) || mnt_table_is_empty(tb)) {
DBG(FS, mnt_debug_h(fstab_fs, "- ignore (swap or no data)"));
return 0;
}
if (!st)
return -1;
+ if (mnt_table_is_empty(st))
+ return 0;
+
itr = mnt_new_iter(MNT_ITER_FORWARD);
if (!itr)
err(EXIT_FAILURE, _("failed to initialize libmount iterator"));
- if (mnt_table_get_nents(st) > 0)
- printf(_("%s\t\t\t\tType\t\tSize\tUsed\tPriority\n"), _("Filename"));
+ printf(_("%s\t\t\t\tType\t\tSize\tUsed\tPriority\n"), _("Filename"));
while (mnt_table_next_fs(st, itr, &fs) == 0) {
printf("%-39s\t%s\t%jd\t%jd\t%d\n",