diff options
-rw-r--r-- | libmount/docs/libmount-sections.txt | 1 | ||||
-rw-r--r-- | libmount/src/libmount.h.in | 2 | ||||
-rw-r--r-- | libmount/src/libmount.sym | 1 | ||||
-rw-r--r-- | libmount/src/tab.c | 34 |
4 files changed, 38 insertions, 0 deletions
diff --git a/libmount/docs/libmount-sections.txt b/libmount/docs/libmount-sections.txt index c29232374..1b9597387 100644 --- a/libmount/docs/libmount-sections.txt +++ b/libmount/docs/libmount-sections.txt @@ -267,6 +267,7 @@ mnt_reset_table mnt_new_table_from_dir mnt_new_table_from_file mnt_table_add_fs +mnt_table_find_devno mnt_table_find_next_fs mnt_table_find_pair mnt_table_find_source diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in index c88722a9d..5c5edbba6 100644 --- a/libmount/src/libmount.h.in +++ b/libmount/src/libmount.h.in @@ -335,6 +335,8 @@ extern struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb, extern struct libmnt_fs *mnt_table_find_pair(struct libmnt_table *tb, const char *source, const char *target, int direction); +extern struct libmnt_fs *mnt_table_find_devno(struct libmnt_table *tb, + dev_t devno, int direction); extern int mnt_table_find_next_fs(struct libmnt_table *tb, struct libmnt_iter *itr, diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym index 4db8b12c6..ca7a305cc 100644 --- a/libmount/src/libmount.sym +++ b/libmount/src/libmount.sym @@ -235,6 +235,7 @@ global: mnt_context_is_loopdel; mnt_context_is_nocanonicalize; mnt_context_is_nohelpers; + mnt_table_find_devno; mnt_table_parse_swaps; mnt_get_swaps_path; mnt_fs_get_swaptype; diff --git a/libmount/src/tab.c b/libmount/src/tab.c index b2662d5ae..9c41c99a2 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -703,6 +703,40 @@ struct libmnt_fs *mnt_table_find_pair(struct libmnt_table *tb, const char *sourc return NULL; } +/** + * mnt_table_find_devno + * @tb: /proc/self/mountinfo + * @devno: device number + * @direction: MNT_ITER_{FORWARD,BACKWARD} + * + * Note that zero could be valid device number for root pseudo filesystem (e.g. + * tmpfs). + * + * Returns: a tab entry or NULL. + */ +struct libmnt_fs *mnt_table_find_devno(struct libmnt_table *tb, + dev_t devno, int direction) +{ + struct libmnt_fs *fs = NULL; + struct libmnt_iter itr; + + assert(tb); + + if (!tb) + return NULL; + + DBG(TAB, mnt_debug_h(tb, "lookup DEVNO: %d", (int) devno)); + + mnt_reset_iter(&itr, direction); + + while(mnt_table_next_fs(tb, &itr, &fs) == 0) { + if (mnt_fs_get_devno(fs) == devno) + return fs; + } + + return NULL; +} + /* * tb: /proc/self/mountinfo * fs: filesystem |