88 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3The Android binderfs Filesystem4===============================5 6Android binderfs is a filesystem for the Android binder IPC mechanism. It7allows to dynamically add and remove binder devices at runtime. Binder devices8located in a new binderfs instance are independent of binder devices located in9other binderfs instances. Mounting a new binderfs instance makes it possible10to get a set of private binder devices.11 12Mounting binderfs13-----------------14 15Android binderfs can be mounted with::16 17 mkdir /dev/binderfs18 mount -t binder binder /dev/binderfs19 20at which point a new instance of binderfs will show up at ``/dev/binderfs``.21In a fresh instance of binderfs no binder devices will be present. There will22only be a ``binder-control`` device which serves as the request handler for23binderfs. Mounting another binderfs instance at a different location will24create a new and separate instance from all other binderfs mounts. This is25identical to the behavior of e.g. ``devpts`` and ``tmpfs``. The Android26binderfs filesystem can be mounted in user namespaces.27 28Options29-------30max31 binderfs instances can be mounted with a limit on the number of binder32 devices that can be allocated. The ``max=<count>`` mount option serves as33 a per-instance limit. If ``max=<count>`` is set then only ``<count>`` number34 of binder devices can be allocated in this binderfs instance.35 36stats37 Using ``stats=global`` enables global binder statistics.38 ``stats=global`` is only available for a binderfs instance mounted in the39 initial user namespace. An attempt to use the option to mount a binderfs40 instance in another user namespace will return a permission error.41 42Allocating binder Devices43-------------------------44 45.. _ioctl: http://man7.org/linux/man-pages/man2/ioctl.2.html46 47To allocate a new binder device in a binderfs instance a request needs to be48sent through the ``binder-control`` device node. A request is sent in the form49of an `ioctl() <ioctl_>`_.50 51What a program needs to do is to open the ``binder-control`` device node and52send a ``BINDER_CTL_ADD`` request to the kernel. Users of binderfs need to53tell the kernel which name the new binder device should get. By default a name54can only contain up to ``BINDERFS_MAX_NAME`` chars including the terminating55zero byte.56 57Once the request is made via an `ioctl() <ioctl_>`_ passing a ``struct58binder_device`` with the name to the kernel it will allocate a new binder59device and return the major and minor number of the new device in the struct60(This is necessary because binderfs allocates a major device number61dynamically.). After the `ioctl() <ioctl_>`_ returns there will be a new62binder device located under /dev/binderfs with the chosen name.63 64Deleting binder Devices65-----------------------66 67.. _unlink: http://man7.org/linux/man-pages/man2/unlink.2.html68.. _rm: http://man7.org/linux/man-pages/man1/rm.1.html69 70Binderfs binder devices can be deleted via `unlink() <unlink_>`_. This means71that the `rm() <rm_>`_ tool can be used to delete them. Note that the72``binder-control`` device cannot be deleted since this would make the binderfs73instance unusable. The ``binder-control`` device will be deleted when the74binderfs instance is unmounted and all references to it have been dropped.75 76Binder features77---------------78 79Assuming an instance of binderfs has been mounted at ``/dev/binderfs``, the80features supported by the binder driver can be located under81``/dev/binderfs/features/``. The presence of individual files can be tested82to determine whether a particular feature is supported by the driver.83 84Example::85 86 cat /dev/binderfs/features/oneway_spam_detection87 188