summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab_parse.c
diff options
context:
space:
mode:
authorKarel Zak2012-06-28 15:40:16 +0200
committerKarel Zak2012-06-28 15:40:16 +0200
commitf7f29b564073831c9d1a8cdf9deaf039c0bcb1b6 (patch)
treeb63b6c298626fea30d2461832cec42e48f56bc11 /libmount/src/tab_parse.c
parentfindmnt: add --task <tid> option (diff)
downloadkernel-qcow2-util-linux-f7f29b564073831c9d1a8cdf9deaf039c0bcb1b6.tar.gz
kernel-qcow2-util-linux-f7f29b564073831c9d1a8cdf9deaf039c0bcb1b6.tar.xz
kernel-qcow2-util-linux-f7f29b564073831c9d1a8cdf9deaf039c0bcb1b6.zip
libmount: save task ID for mountinfo tiles
Add new function mnt_fs_get_tid() to get task ID for the given filesystem. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab_parse.c')
-rw-r--r--libmount/src/tab_parse.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c
index 73a7f83c8..ab5d51acd 100644
--- a/libmount/src/tab_parse.c
+++ b/libmount/src/tab_parse.c
@@ -423,6 +423,35 @@ err:
return tb->errcb ? tb->errcb(tb, filename, *nlines) : 1;
}
+static pid_t path_to_tid(const char *filename)
+{
+ char *path = mnt_resolve_path(filename, NULL);
+ char *p, *end = NULL;
+ pid_t tid = 0;
+
+ if (!path)
+ goto done;
+ p = strrchr(path, '/');
+ if (!p)
+ goto done;
+ *p = '\0';
+ p = strrchr(path, '/');
+ if (!p)
+ goto done;
+ p++;
+
+ errno = 0;
+ tid = strtol(p, &end, 10);
+ if (errno || p == end || (end && *end)) {
+ tid = 0;
+ goto done;
+ }
+ DBG(TAB, mnt_debug("TID for %s is %d", filename, tid));
+done:
+ free(path);
+ return tid;
+}
+
/**
* mnt_table_parse_stream:
* @tb: tab pointer
@@ -436,6 +465,7 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam
int nlines = 0;
int rc = -1;
int flags = 0;
+ pid_t tid = -1;
assert(tb);
assert(f);
@@ -460,6 +490,11 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam
if (!rc) {
rc = mnt_table_add_fs(tb, fs);
fs->flags |= flags;
+ if (tb->fmt == MNT_FMT_MOUNTINFO && filename) {
+ if (tid == -1)
+ tid = path_to_tid(filename);
+ fs->tid = tid;
+ }
}
if (rc) {
mnt_free_fs(fs);