diff options
Diffstat (limited to 'tools/lib/api/fs/debugfs.c')
| -rw-r--r-- | tools/lib/api/fs/debugfs.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c index 86ea2d7b8845..d2b18e887071 100644 --- a/tools/lib/api/fs/debugfs.c +++ b/tools/lib/api/fs/debugfs.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 1 | #include <errno.h> | 2 | #include <errno.h> |
| 2 | #include <stdio.h> | 3 | #include <stdio.h> |
| 3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
| @@ -98,3 +99,45 @@ char *debugfs_mount(const char *mountpoint) | |||
| 98 | out: | 99 | out: |
| 99 | return debugfs_mountpoint; | 100 | return debugfs_mountpoint; |
| 100 | } | 101 | } |
| 102 | |||
| 103 | int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename) | ||
| 104 | { | ||
| 105 | char sbuf[128]; | ||
| 106 | |||
| 107 | switch (err) { | ||
| 108 | case ENOENT: | ||
| 109 | if (debugfs_found) { | ||
| 110 | snprintf(buf, size, | ||
| 111 | "Error:\tFile %s/%s not found.\n" | ||
| 112 | "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n", | ||
| 113 | debugfs_mountpoint, filename); | ||
| 114 | break; | ||
| 115 | } | ||
| 116 | snprintf(buf, size, "%s", | ||
| 117 | "Error:\tUnable to find debugfs\n" | ||
| 118 | "Hint:\tWas your kernel compiled with debugfs support?\n" | ||
| 119 | "Hint:\tIs the debugfs filesystem mounted?\n" | ||
| 120 | "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'"); | ||
| 121 | break; | ||
| 122 | case EACCES: | ||
| 123 | snprintf(buf, size, | ||
| 124 | "Error:\tNo permissions to read %s/%s\n" | ||
| 125 | "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n", | ||
| 126 | debugfs_mountpoint, filename, debugfs_mountpoint); | ||
| 127 | break; | ||
| 128 | default: | ||
| 129 | snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf))); | ||
| 130 | break; | ||
| 131 | } | ||
| 132 | |||
| 133 | return 0; | ||
| 134 | } | ||
| 135 | |||
| 136 | int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name) | ||
| 137 | { | ||
| 138 | char path[PATH_MAX]; | ||
| 139 | |||
| 140 | snprintf(path, PATH_MAX, "tracing/events/%s/%s", sys, name ?: "*"); | ||
| 141 | |||
| 142 | return debugfs__strerror_open(err, buf, size, path); | ||
| 143 | } | ||
