Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60a1133a authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo
Browse files

tools lib api fs: Remove debugfs, tracefs and findfs objects



We have all the functionality in fs.c, let's remove unneeded
objects.

Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Raphael Beamonte <raphael.beamonte@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1441180605-24737-15-git-send-email-jolsa@kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 4605eab3
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
libapi-y += fs.o
libapi-y += tracing_path.o
libapi-y += debugfs.o
libapi-y += findfs.o
libapi-y += tracefs.o

tools/lib/api/fs/debugfs.c

deleted100644 → 0
+0 −77
Original line number Diff line number Diff line
#define _GNU_SOURCE
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/vfs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <linux/kernel.h>

#include "debugfs.h"
#include "tracefs.h"

#ifndef DEBUGFS_DEFAULT_PATH
#define DEBUGFS_DEFAULT_PATH		"/sys/kernel/debug"
#endif

char debugfs_mountpoint[PATH_MAX + 1] = DEBUGFS_DEFAULT_PATH;

static const char * const debugfs_known_mountpoints[] = {
	DEBUGFS_DEFAULT_PATH,
	"/debug",
	0,
};

static bool debugfs_found;

bool debugfs_configured(void)
{
	return debugfs_find_mountpoint() != NULL;
}

/* find the path to the mounted debugfs */
const char *debugfs_find_mountpoint(void)
{
	const char *ret;

	if (debugfs_found)
		return (const char *)debugfs_mountpoint;

	ret = find_mountpoint("debugfs", (long) DEBUGFS_MAGIC,
			      debugfs_mountpoint, PATH_MAX + 1,
			      debugfs_known_mountpoints);
	if (ret)
		debugfs_found = true;

	return ret;
}

/* mount the debugfs somewhere if it's not mounted */
char *debugfs_mount(const char *mountpoint)
{
	/* see if it's already mounted */
	if (debugfs_find_mountpoint())
		goto out;

	/* if not mounted and no argument */
	if (mountpoint == NULL) {
		/* see if environment variable set */
		mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT);
		/* if no environment variable, use default */
		if (mountpoint == NULL)
			mountpoint = DEBUGFS_DEFAULT_PATH;
	}

	if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0)
		return NULL;

	/* save the mountpoint */
	debugfs_found = true;
	strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint));
out:
	return debugfs_mountpoint;
}

tools/lib/api/fs/debugfs.h

deleted100644 → 0
+0 −23
Original line number Diff line number Diff line
#ifndef __API_DEBUGFS_H__
#define __API_DEBUGFS_H__

#include "findfs.h"

#ifndef DEBUGFS_MAGIC
#define DEBUGFS_MAGIC          0x64626720
#endif

#ifndef PERF_DEBUGFS_ENVIRONMENT
#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
#endif

bool debugfs_configured(void);
const char *debugfs_find_mountpoint(void);
char *debugfs_mount(const char *mountpoint);

extern char debugfs_mountpoint[];

int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename);
int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);

#endif /* __API_DEBUGFS_H__ */

tools/lib/api/fs/findfs.c

deleted100644 → 0
+0 −63
Original line number Diff line number Diff line
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <sys/vfs.h>

#include "findfs.h"

/* verify that a mountpoint is actually the type we want */

int valid_mountpoint(const char *mount, long magic)
{
	struct statfs st_fs;

	if (statfs(mount, &st_fs) < 0)
		return -ENOENT;
	else if ((long)st_fs.f_type != magic)
		return -ENOENT;

	return 0;
}

/* find the path to a mounted file system */
const char *find_mountpoint(const char *fstype, long magic,
			    char *mountpoint, int len,
			    const char * const *known_mountpoints)
{
	const char * const *ptr;
	char format[128];
	char type[100];
	FILE *fp;

	if (known_mountpoints) {
		ptr = known_mountpoints;
		while (*ptr) {
			if (valid_mountpoint(*ptr, magic) == 0) {
				strncpy(mountpoint, *ptr, len - 1);
				mountpoint[len-1] = 0;
				return mountpoint;
			}
			ptr++;
		}
	}

	/* give up and parse /proc/mounts */
	fp = fopen("/proc/mounts", "r");
	if (fp == NULL)
		return NULL;

	snprintf(format, 128, "%%*s %%%ds %%99s %%*s %%*d %%*d\n", len);

	while (fscanf(fp, format, mountpoint, type) == 2) {
		if (strcmp(type, fstype) == 0)
			break;
	}
	fclose(fp);

	if (strcmp(type, fstype) != 0)
		return NULL;

	return mountpoint;
}

tools/lib/api/fs/findfs.h

deleted100644 → 0
+0 −23
Original line number Diff line number Diff line
#ifndef __API_FINDFS_H__
#define __API_FINDFS_H__

#include <stdbool.h>

#define _STR(x) #x
#define STR(x) _STR(x)

/*
 * On most systems <limits.h> would have given us this, but  not on some systems
 * (e.g. GNU/Hurd).
 */
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif

const char *find_mountpoint(const char *fstype, long magic,
			    char *mountpoint, int len,
			    const char * const *known_mountpoints);

int valid_mountpoint(const char *mount, long magic);

#endif /* __API_FINDFS_H__ */
Loading