162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ciThe Android binderfs Filesystem 462306a36Sopenharmony_ci=============================== 562306a36Sopenharmony_ci 662306a36Sopenharmony_ciAndroid binderfs is a filesystem for the Android binder IPC mechanism. It 762306a36Sopenharmony_ciallows to dynamically add and remove binder devices at runtime. Binder devices 862306a36Sopenharmony_cilocated in a new binderfs instance are independent of binder devices located in 962306a36Sopenharmony_ciother binderfs instances. Mounting a new binderfs instance makes it possible 1062306a36Sopenharmony_cito get a set of private binder devices. 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ciMounting binderfs 1362306a36Sopenharmony_ci----------------- 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciAndroid binderfs can be mounted with:: 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci mkdir /dev/binderfs 1862306a36Sopenharmony_ci mount -t binder binder /dev/binderfs 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ciat which point a new instance of binderfs will show up at ``/dev/binderfs``. 2162306a36Sopenharmony_ciIn a fresh instance of binderfs no binder devices will be present. There will 2262306a36Sopenharmony_cionly be a ``binder-control`` device which serves as the request handler for 2362306a36Sopenharmony_cibinderfs. Mounting another binderfs instance at a different location will 2462306a36Sopenharmony_cicreate a new and separate instance from all other binderfs mounts. This is 2562306a36Sopenharmony_ciidentical to the behavior of e.g. ``devpts`` and ``tmpfs``. The Android 2662306a36Sopenharmony_cibinderfs filesystem can be mounted in user namespaces. 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciOptions 2962306a36Sopenharmony_ci------- 3062306a36Sopenharmony_cimax 3162306a36Sopenharmony_ci binderfs instances can be mounted with a limit on the number of binder 3262306a36Sopenharmony_ci devices that can be allocated. The ``max=<count>`` mount option serves as 3362306a36Sopenharmony_ci a per-instance limit. If ``max=<count>`` is set then only ``<count>`` number 3462306a36Sopenharmony_ci of binder devices can be allocated in this binderfs instance. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cistats 3762306a36Sopenharmony_ci Using ``stats=global`` enables global binder statistics. 3862306a36Sopenharmony_ci ``stats=global`` is only available for a binderfs instance mounted in the 3962306a36Sopenharmony_ci initial user namespace. An attempt to use the option to mount a binderfs 4062306a36Sopenharmony_ci instance in another user namespace will return a permission error. 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ciAllocating binder Devices 4362306a36Sopenharmony_ci------------------------- 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci.. _ioctl: http://man7.org/linux/man-pages/man2/ioctl.2.html 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciTo allocate a new binder device in a binderfs instance a request needs to be 4862306a36Sopenharmony_cisent through the ``binder-control`` device node. A request is sent in the form 4962306a36Sopenharmony_ciof an `ioctl() <ioctl_>`_. 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ciWhat a program needs to do is to open the ``binder-control`` device node and 5262306a36Sopenharmony_cisend a ``BINDER_CTL_ADD`` request to the kernel. Users of binderfs need to 5362306a36Sopenharmony_citell the kernel which name the new binder device should get. By default a name 5462306a36Sopenharmony_cican only contain up to ``BINDERFS_MAX_NAME`` chars including the terminating 5562306a36Sopenharmony_cizero byte. 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ciOnce the request is made via an `ioctl() <ioctl_>`_ passing a ``struct 5862306a36Sopenharmony_cibinder_device`` with the name to the kernel it will allocate a new binder 5962306a36Sopenharmony_cidevice and return the major and minor number of the new device in the struct 6062306a36Sopenharmony_ci(This is necessary because binderfs allocates a major device number 6162306a36Sopenharmony_cidynamically.). After the `ioctl() <ioctl_>`_ returns there will be a new 6262306a36Sopenharmony_cibinder device located under /dev/binderfs with the chosen name. 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ciDeleting binder Devices 6562306a36Sopenharmony_ci----------------------- 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci.. _unlink: http://man7.org/linux/man-pages/man2/unlink.2.html 6862306a36Sopenharmony_ci.. _rm: http://man7.org/linux/man-pages/man1/rm.1.html 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ciBinderfs binder devices can be deleted via `unlink() <unlink_>`_. This means 7162306a36Sopenharmony_cithat the `rm() <rm_>`_ tool can be used to delete them. Note that the 7262306a36Sopenharmony_ci``binder-control`` device cannot be deleted since this would make the binderfs 7362306a36Sopenharmony_ciinstance unusable. The ``binder-control`` device will be deleted when the 7462306a36Sopenharmony_cibinderfs instance is unmounted and all references to it have been dropped. 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ciBinder features 7762306a36Sopenharmony_ci--------------- 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciAssuming an instance of binderfs has been mounted at ``/dev/binderfs``, the 8062306a36Sopenharmony_cifeatures supported by the binder driver can be located under 8162306a36Sopenharmony_ci``/dev/binderfs/features/``. The presence of individual files can be tested 8262306a36Sopenharmony_cito determine whether a particular feature is supported by the driver. 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ciExample:: 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci cat /dev/binderfs/features/oneway_spam_detection 8762306a36Sopenharmony_ci 1 88