if BUILD_LSLOCKS
usrbin_exec_PROGRAMS += lslocks
dist_man_MANS += misc-utils/lslocks.8
-lslocks_LDADD = $(LDADD) libcommon.la
+lslocks_LDADD = $(LDADD) libcommon.la libmount.la
lslocks_SOURCES = misc-utils/lslocks.c
+lslocks_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir)
endif
if BUILD_LSBLK
#include <sys/stat.h>
#include <sys/types.h>
+#include <libmount.h>
+
#include "pathnames.h"
#include "canonicalize.h"
#include "nls.h"
static int columns[NCOLS], ncolumns;
static pid_t pid = 0;
+static struct libmnt_table *tab; /* /proc/self/mountinfo */
+
struct lock {
struct list_head locks;
*/
static char *get_fallback_filename(dev_t dev)
{
- char buf[BUFSIZ], target[PATH_MAX], *ret = NULL;
- int maj, min;
- FILE *fp;
+ struct libmnt_fs *fs;
- if (!(fp = fopen(_PATH_PROC_MOUNTINFO, "r")))
- return NULL;
-
- while (fgets(buf, sizeof(buf), fp)) {
- sscanf(buf, "%*u %*u %u:%u %*s %s",
- &maj, &min, target);
+ if (!tab) {
+ tab = mnt_new_table_from_file(_PATH_PROC_MOUNTINFO);
+ if (!tab)
+ return NULL;
+ }
- if (dev == makedev(maj, min)) {
- ret = xstrdup(target);
- goto out;
+ fs = mnt_table_find_devno(tab, dev, MNT_ITER_BACKWARD);
+ if (!fs)
+ return NULL;
- }
- }
-out:
- fclose(fp);
- return ret;
+ return xstrdup(mnt_fs_get_target(fs));
}
/*
if (!rc && !list_empty(&locks))
rc = show_locks(&locks, tt_flags);
+ mnt_free_table(tab);
return rc;
}