lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed,  4 Jul 2012 00:00:46 +0200
From:	Jiri Olsa <jolsa@...hat.com>
To:	acme@...hat.com, a.p.zijlstra@...llo.nl, mingo@...e.hu,
	paulus@...ba.org, cjashfor@...ux.vnet.ibm.com, fweisbec@...il.com,
	eranian@...gle.com
Cc:	linux-kernel@...r.kernel.org, Jiri Olsa <jolsa@...hat.com>
Subject: [PATCH 08/10] perf, tool: Add sysfs read file interface

Adding read file interface to access sysfs files data.

  int sysfs_read_file(const char *file, char *buf, size_t size)

The 'file' argument is file path relative to the sysfs mount.

Signed-off-by: Jiri Olsa <jolsa@...hat.com>
---
 tools/perf/util/sysfs.c |   19 +++++++++++++++++++
 tools/perf/util/sysfs.h |    1 +
 2 files changed, 20 insertions(+)

diff --git a/tools/perf/util/sysfs.c b/tools/perf/util/sysfs.c
index 48c6902..4ee886a 100644
--- a/tools/perf/util/sysfs.c
+++ b/tools/perf/util/sysfs.c
@@ -58,3 +58,22 @@ const char *sysfs_find_mountpoint(void)
 
 	return sysfs_found ? sysfs_mountpoint : NULL;
 }
+
+int sysfs_read_file(const char *file, char *buf, size_t size)
+{
+	char path[PATH_MAX];
+	FILE *fp;
+	int ret = 0;
+
+	snprintf(path, PATH_MAX, "%s/%s", sysfs_mountpoint, file);
+
+	fp = fopen(path, "r");
+	if (!fp)
+		return -errno;
+
+	if (fread(buf, 1, size, fp) == 0)
+		ret = -errno;
+
+	fclose(fp);
+	return ret;
+}
diff --git a/tools/perf/util/sysfs.h b/tools/perf/util/sysfs.h
index a813b72..5ce99e7 100644
--- a/tools/perf/util/sysfs.h
+++ b/tools/perf/util/sysfs.h
@@ -2,5 +2,6 @@
 #define __SYSFS_H__
 
 const char *sysfs_find_mountpoint(void);
+int sysfs_read_file(const char *file, char *buf, size_t size);
 
 #endif /* __DEBUGFS_H__ */
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ