@@ -3,8 +3,8 @@ libtracefs(3)
NAME
----
-tracefs_get_tracing_file, tracefs_put_tracing_file, tracefs_tracing_dir, tracefs_debug_dir, tracefs_set_tracing_dir -
-Find and set locations of trace directory and files.
+tracefs_get_tracing_file, tracefs_put_tracing_file, tracefs_tracing_dir, tracefs_debug_dir, tracefs_set_tracing_dir,
+tracefs_tracing_dir_is_mounted - Find and set locations of trace directory and files.
SYNOPSIS
--------
@@ -17,6 +17,7 @@ void *tracefs_put_tracing_file*(char pass:[*]_name_);
const char pass:[*]*tracefs_tracing_dir*(void);
const char pass:[*]*tracefs_debug_dir*(void);
int *tracefs_set_tracing_dir*(char pass:[*]_tracing_dir_)
+int *tracefs_tracing_dir_is_mounted*(bool _mount_, const char pass:[**]_path_);
--
DESCRIPTION
@@ -52,6 +53,12 @@ that it will return where the debugfs file system is mounted. If it
is not mounted it will try to mount it. The return string must _not_
be freed.
+*tracefs_tracing_dir_is_mounted()* returns 1 if the tracing directory is
+already mounted and 0 if it is not. If _mount_ is true, it will try to
+mount it if it is not, and returns 0 if it succesfully mounted it and -1
+if it did not. If _path_ is set, it will be assigned to the path where it
+mounted it. _path_ is internal and should not be freed.
+
RETURN VALUE
------------
The *tracefs_set_tracing_dir()* function returns 0 on success, -1 otherwise.
@@ -65,6 +72,9 @@ in case of an error. The returned string must _not_ be freed.
The *tracefs_debug_dir()* function returns a constant string or NULL
in case of an error. The returned string must _not_ be freed.
+The *tracefs_tracing_dir_is_mounted()* returns 1 if the tracing directory
+is already mounted, 0 if it is not, and -1 on error.
+
EXAMPLE
-------
[source,c]
@@ -17,6 +17,7 @@ Locations of tracing files and directories:
const char pass:[*]*tracefs_tracing_dir*(void);
const char pass:[*]*tracefs_debug_dir*(void);
int *tracefs_set_tracing_dir*(char pass:[*]_tracing_dir_)
+ int *tracefs_tracing_dir_is_mounted*(bool _mount_, const char pass:[**]_path_);
Trace instances:
struct tracefs_instance pass:[*]*tracefs_instance_create*(const char pass:[*]_name_);
@@ -17,6 +17,7 @@ void tracefs_put_tracing_file(char *name);
const char *tracefs_tracing_dir(void);
const char *tracefs_debug_dir(void);
int tracefs_set_tracing_dir(char *tracing_dir);
+int tracefs_tracing_dir_is_mounted(bool mount, const char **path);
/* ftrace instances */
struct tracefs_instance;
@@ -85,14 +85,7 @@ static int mount_debugfs(void)
return ret;
}
-/**
- * trace_find_tracing_dir - Find tracing directory
- * @debugfs: Boolean to just return the debugfs directory
- *
- * Returns string containing the full path to the system's tracing directory.
- * The string must be freed by free()
- */
-__hidden char *trace_find_tracing_dir(bool debugfs)
+static char *find_tracing_dir(bool debugfs, bool mount)
{
char *debug_str = NULL;
char fspath[PATH_MAX+1];
@@ -127,18 +120,19 @@ __hidden char *trace_find_tracing_dir(bool debugfs)
if (debugfs) {
if (strcmp(type, "debugfs") != 0) {
- if (mount_debugfs() < 0)
+ if (!mount || mount_debugfs() < 0)
return NULL;
strcpy(fspath, DEBUGFS_PATH);
}
} else if (strcmp(type, "tracefs") != 0) {
- if (mount_tracefs() < 0) {
+ if (!mount || mount_tracefs() < 0) {
if (debug_str) {
strncpy(fspath, debug_str, PATH_MAX);
fspath[PATH_MAX] = 0;
} else {
- if (mount_debugfs() < 0) {
- tracefs_warning("debugfs not mounted, please mount");
+ if (!mount || mount_debugfs() < 0) {
+ if (mount)
+ tracefs_warning("debugfs not mounted, please mount");
free(debug_str);
return NULL;
}
@@ -165,6 +159,50 @@ __hidden char *trace_find_tracing_dir(bool debugfs)
return tracing_dir;
}
+/**
+ * tracefs_tracing_dir_is_mounted - test if the tracing dir is already mounted
+ * @mount: Mount it if it is not already mounted
+ * @path: the path to the tracing directory if mounted or was mounted
+ *
+ * Returns 1 if the tracing directory is already mounted and 0 if it is not.
+ * If @mount is set and it fails to mount, it returns -1.
+ *
+ * If path is not NULL, and the tracing directory is or was mounted, it holds
+ * the path to the tracing directory. It must not be freed.
+ */
+int tracefs_tracing_dir_is_mounted(bool mount, const char **path)
+{
+ const char *dir;
+
+ dir = find_tracing_dir(false, false);
+ if (dir) {
+ if (path)
+ *path = dir;
+ return 1;
+ }
+ if (!mount)
+ return 0;
+
+ dir = find_tracing_dir(false, mount);
+ if (!dir)
+ return -1;
+ if (path)
+ *path = dir;
+ return 0;
+}
+
+/**
+ * trace_find_tracing_dir - Find tracing directory
+ * @debugfs: Boolean to just return the debugfs directory
+ *
+ * Returns string containing the full path to the system's tracing directory.
+ * The string must be freed by free()
+ */
+__hidden char *trace_find_tracing_dir(bool debugfs)
+{
+ return find_tracing_dir(debugfs, false);
+}
+
/**
* tracefs_set_tracing_dir - Set location of the tracing directory
* @tracing_dir: full path to the system's tracing directory mount point.