summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-03-09 12:56:17 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2019-03-09 12:56:17 -0500
commit1a29e857507046e413ca7a4a7c9cd32fed9ea255 (patch)
tree5a46d9c4dcab39fc588a9ac2c9f5e4c866d41254 /samples
parentc4703acd6d4a58dc4b31ad2a8f8b14becb898d25 (diff)
parent4064174becc09a5a2385a27c8a6fd40888b0e13c (diff)
Merge tag 'docs-5.1' of git://git.lwn.net/linux
Pull documentation updates from Jonathan Corbet: "A fairly routine cycle for docs - lots of typo fixes, some new documents, and more translations. There's also some LICENSES adjustments from Thomas" * tag 'docs-5.1' of git://git.lwn.net/linux: (74 commits) docs: Bring some order to filesystem documentation Documentation/locking/lockdep: Drop last two chars of sample states doc: rcu: Suspicious RCU usage is a warning docs: driver-api: iio: fix errors in documentation Documentation/process/howto: Update for 4.x -> 5.x versioning docs: Explicitly state that the 'Fixes:' tag shouldn't split lines doc: security: Add kern-doc for lsm_hooks.h doc: sctp: Merge and clean up rst files Docs: Correct /proc/stat path scripts/spdxcheck.py: fix C++ comment style detection doc: fix typos in license-rules.rst Documentation: fix admin-guide/README.rst minimum gcc version requirement doc: process: complete removal of info about -git patches doc: translations: sync translations 'remove info about -git patches' perf-security: wrap paragraphs on 72 columns perf-security: elaborate on perf_events/Perf privileged users perf-security: document collected perf_events/Perf data categories perf-security: document perf_events/Perf resource control sysfs.txt: add note on available attribute macros docs: kernel-doc: typo "if ... if" -> "if ... is" ...
Diffstat (limited to 'samples')
-rw-r--r--samples/Kconfig7
-rw-r--r--samples/Makefile2
-rw-r--r--samples/binderfs/Makefile1
-rw-r--r--samples/binderfs/binderfs_example.c83
4 files changed, 92 insertions, 1 deletions
diff --git a/samples/Kconfig b/samples/Kconfig
index ad1ec7016d4c..d19754ccad08 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -147,6 +147,13 @@ config SAMPLE_VFIO_MDEV_MBOCHS
147 Specifically it does *not* include any legacy vga stuff. 147 Specifically it does *not* include any legacy vga stuff.
148 Device looks a lot like "qemu -device secondary-vga". 148 Device looks a lot like "qemu -device secondary-vga".
149 149
150config SAMPLE_ANDROID_BINDERFS
151 bool "Build Android binderfs example"
152 depends on CONFIG_ANDROID_BINDERFS
153 help
154 Builds a sample program to illustrate the use of the Android binderfs
155 filesystem.
156
150config SAMPLE_STATX 157config SAMPLE_STATX
151 bool "Build example extended-stat using code" 158 bool "Build example extended-stat using code"
152 depends on BROKEN 159 depends on BROKEN
diff --git a/samples/Makefile b/samples/Makefile
index bd601c038b86..b1142a958811 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -3,4 +3,4 @@
3obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \ 3obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \
4 hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \ 4 hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \
5 configfs/ connector/ v4l/ trace_printk/ \ 5 configfs/ connector/ v4l/ trace_printk/ \
6 vfio-mdev/ statx/ qmi/ 6 vfio-mdev/ statx/ qmi/ binderfs/
diff --git a/samples/binderfs/Makefile b/samples/binderfs/Makefile
new file mode 100644
index 000000000000..01ca9f2529a7
--- /dev/null
+++ b/samples/binderfs/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_SAMPLE_ANDROID_BINDERFS) += binderfs_example.o
diff --git a/samples/binderfs/binderfs_example.c b/samples/binderfs/binderfs_example.c
new file mode 100644
index 000000000000..5bbd2ebc0aea
--- /dev/null
+++ b/samples/binderfs/binderfs_example.c
@@ -0,0 +1,83 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#define _GNU_SOURCE
4#include <errno.h>
5#include <fcntl.h>
6#include <sched.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <sys/ioctl.h>
11#include <sys/mount.h>
12#include <sys/stat.h>
13#include <sys/types.h>
14#include <unistd.h>
15#include <linux/android/binder.h>
16#include <linux/android/binderfs.h>
17
18int main(int argc, char *argv[])
19{
20 int fd, ret, saved_errno;
21 size_t len;
22 struct binderfs_device device = { 0 };
23
24 ret = unshare(CLONE_NEWNS);
25 if (ret < 0) {
26 fprintf(stderr, "%s - Failed to unshare mount namespace\n",
27 strerror(errno));
28 exit(EXIT_FAILURE);
29 }
30
31 ret = mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
32 if (ret < 0) {
33 fprintf(stderr, "%s - Failed to mount / as private\n",
34 strerror(errno));
35 exit(EXIT_FAILURE);
36 }
37
38 ret = mkdir("/dev/binderfs", 0755);
39 if (ret < 0 && errno != EEXIST) {
40 fprintf(stderr, "%s - Failed to create binderfs mountpoint\n",
41 strerror(errno));
42 exit(EXIT_FAILURE);
43 }
44
45 ret = mount(NULL, "/dev/binderfs", "binder", 0, 0);
46 if (ret < 0) {
47 fprintf(stderr, "%s - Failed to mount binderfs\n",
48 strerror(errno));
49 exit(EXIT_FAILURE);
50 }
51
52 memcpy(device.name, "my-binder", strlen("my-binder"));
53
54 fd = open("/dev/binderfs/binder-control", O_RDONLY | O_CLOEXEC);
55 if (fd < 0) {
56 fprintf(stderr, "%s - Failed to open binder-control device\n",
57 strerror(errno));
58 exit(EXIT_FAILURE);
59 }
60
61 ret = ioctl(fd, BINDER_CTL_ADD, &device);
62 saved_errno = errno;
63 close(fd);
64 errno = saved_errno;
65 if (ret < 0) {
66 fprintf(stderr, "%s - Failed to allocate new binder device\n",
67 strerror(errno));
68 exit(EXIT_FAILURE);
69 }
70
71 printf("Allocated new binder device with major %d, minor %d, and name %s\n",
72 device.major, device.minor, device.name);
73
74 ret = unlink("/dev/binderfs/my-binder");
75 if (ret < 0) {
76 fprintf(stderr, "%s - Failed to delete binder device\n",
77 strerror(errno));
78 exit(EXIT_FAILURE);
79 }
80
81 /* Cleanup happens when the mount namespace dies. */
82 exit(EXIT_SUCCESS);
83}