Add new function mnt_fs_get_tid() to get task ID for the given filesystem.
Signed-off-by: Karel Zak <kzak@redhat.com>
dest->id = src->id;
dest->parent = src->parent;
dest->devno = src->devno;
+ dest->tid = src->tid;
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, source)))
goto err;
return fs ? fs->devno : 0;
}
+/**
+ * mnt_fs_get_tid:
+ * @fs: /proc/<tid>/mountinfo entry
+ *
+ * Returns: TID (task ID) for filesystems read from mountinfo file
+ */
+pid_t mnt_fs_get_tid(struct libmnt_fs *fs)
+{
+ assert(fs);
+ return fs ? fs->tid : 0;
+}
+
/**
* mnt_fs_get_option:
* @fs: fstab/mtab/mountinfo entry pointer
fprintf(file, "parent: %d\n", mnt_fs_get_parent_id(fs));
if (mnt_fs_get_devno(fs))
fprintf(file, "devno: %d:%d\n", major(mnt_fs_get_devno(fs)),
- minor(mnt_fs_get_devno(fs)));
+ minor(mnt_fs_get_devno(fs)));
+ if (mnt_fs_get_tid(fs))
+ fprintf(file, "tid: %d\n", mnt_fs_get_tid(fs));
+
return 0;
}
extern int mnt_fs_get_id(struct libmnt_fs *fs);
extern int mnt_fs_get_parent_id(struct libmnt_fs *fs);
extern dev_t mnt_fs_get_devno(struct libmnt_fs *fs);
+extern pid_t mnt_fs_get_tid(struct libmnt_fs *fs);
extern const char *mnt_fs_get_swaptype(struct libmnt_fs *fs);
extern off_t mnt_fs_get_size(struct libmnt_fs *fs);
mnt_table_parse_swaps;
mnt_get_mountpoint;
mnt_get_swaps_path;
- mnt_fs_get_swaptype;
+ mnt_fs_get_priority;
mnt_fs_get_size;
+ mnt_fs_get_swaptype;
+ mnt_fs_get_tid;
mnt_fs_get_usedsize;
- mnt_fs_get_priority;
} MOUNT_2.21;
int priority; /* swaps[5]: swap priority */
int flags; /* MNT_FS_* flags */
+ pid_t tid; /* /proc/<tid>/mountinfo otherwise zero */
void *userdata; /* library independent data */
};
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
int nlines = 0;
int rc = -1;
int flags = 0;
+ pid_t tid = -1;
assert(tb);
assert(f);
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);