aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/api/fs/debugfs.c
diff options
context:
space:
mode:
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>2015-02-02 14:35:03 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-02-07 07:51:34 -0500
commitcde164aee9e0343831467035eb96dd5506742648 (patch)
tree8353fdc346aa319d7b88990ea007b22be9a372f3 /tools/lib/api/fs/debugfs.c
parent5693c92660970851e95f769ff27397f5098a6296 (diff)
tools lib fs: Add helper to find mounted file systems
In preparation for adding tracefs for perf to use, create a findfs helper utility that find_debugfs uses instead of hard coding the search in the code. This will allow for a find_tracefs to be used as well. Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/r/20150202193552.735023362@goodmis.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/api/fs/debugfs.c')
-rw-r--r--tools/lib/api/fs/debugfs.c51
1 files changed, 7 insertions, 44 deletions
diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index d21d4d6b4fd2..91e1668348ce 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -20,58 +20,21 @@ static const char * const debugfs_known_mountpoints[] = {
20 20
21static bool debugfs_found; 21static bool debugfs_found;
22 22
23/* verify that a mountpoint is actually a debugfs instance */
24
25static int debugfs_valid_mountpoint(const char *debugfs)
26{
27 struct statfs st_fs;
28
29 if (statfs(debugfs, &st_fs) < 0)
30 return -ENOENT;
31 else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
32 return -ENOENT;
33
34 return 0;
35}
36
37/* find the path to the mounted debugfs */ 23/* find the path to the mounted debugfs */
38const char *debugfs_find_mountpoint(void) 24const char *debugfs_find_mountpoint(void)
39{ 25{
40 const char * const *ptr; 26 const char *ret;
41 char type[100];
42 FILE *fp;
43 27
44 if (debugfs_found) 28 if (debugfs_found)
45 return (const char *)debugfs_mountpoint; 29 return (const char *)debugfs_mountpoint;
46 30
47 ptr = debugfs_known_mountpoints; 31 ret = find_mountpoint("debugfs", (long) DEBUGFS_MAGIC,
48 while (*ptr) { 32 debugfs_mountpoint, PATH_MAX + 1,
49 if (debugfs_valid_mountpoint(*ptr) == 0) { 33 debugfs_known_mountpoints);
50 debugfs_found = true; 34 if (ret)
51 strcpy(debugfs_mountpoint, *ptr); 35 debugfs_found = true;
52 return debugfs_mountpoint;
53 }
54 ptr++;
55 }
56 36
57 /* give up and parse /proc/mounts */ 37 return ret;
58 fp = fopen("/proc/mounts", "r");
59 if (fp == NULL)
60 return NULL;
61
62 while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
63 debugfs_mountpoint, type) == 2) {
64 if (strcmp(type, "debugfs") == 0)
65 break;
66 }
67 fclose(fp);
68
69 if (strcmp(type, "debugfs") != 0)
70 return NULL;
71
72 debugfs_found = true;
73
74 return debugfs_mountpoint;
75} 38}
76 39
77/* mount the debugfs somewhere if it's not mounted */ 40/* mount the debugfs somewhere if it's not mounted */