← Documents Documentation/admin-guide/binderfs.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / IPC

The Android binderfs Filesystem

독립적인 BinderFS instance를 mount하고 binder device를 ioctl로 할당·unlink로 삭제하며 feature file로 지원 여부를 확인합니다.

Source pathDocumentation/admin-guide/binderfs.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

Mount and isolation

binderfs.rst:1-27

Mount마다 private binder device namespace와 binder-control을 만듭니다.

Mount options

binderfs.rst:28-41

Instance별 max와 initial-user-namespace 전용 global statistics를 설명합니다.

Device allocation

binderfs.rst:42-63

BINDER_CTL_ADD ioctl과 struct binder_device로 이름·major/minor를 교환합니다.

Device deletion

binderfs.rst:64-75

일반 node는 unlink할 수 있지만 binder-control은 mount 수명과 함께합니다.

Feature probing

binderfs.rst:76-87

features directory의 file 존재와 값으로 driver capability를 확인합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 The Android binderfs Filesystem
4 ===============================
5
6 Android binderfs is a filesystem for the Android binder IPC mechanism. It
7 allows to dynamically add and remove binder devices at runtime. Binder devices
8 located in a new binderfs instance are independent of binder devices located in
9 other binderfs instances. Mounting a new binderfs instance makes it possible
10 to get a set of private binder devices.
11
12 Mounting binderfs
13 -----------------
14
15 Android binderfs can be mounted with::
16
17 mkdir /dev/binderfs
18 mount -t binder binder /dev/binderfs
19
20 at which point a new instance of binderfs will show up at ``/dev/binderfs``.
21 In a fresh instance of binderfs no binder devices will be present. There will
22 only be a ``binder-control`` device which serves as the request handler for
23 binderfs. Mounting another binderfs instance at a different location will
24 create a new and separate instance from all other binderfs mounts. This is
25 identical to the behavior of e.g. ``devpts`` and ``tmpfs``. The Android
26 binderfs filesystem can be mounted in user namespaces.
27
28 Options
29 -------
30 max
31 binderfs instances can be mounted with a limit on the number of binder
32 devices that can be allocated. The ``max=<count>`` mount option serves as
33 a per-instance limit. If ``max=<count>`` is set then only ``<count>`` number
34 of binder devices can be allocated in this binderfs instance.
35
36 stats
37 Using ``stats=global`` enables global binder statistics.
38 ``stats=global`` is only available for a binderfs instance mounted in the
39 initial user namespace. An attempt to use the option to mount a binderfs
40 instance in another user namespace will return a permission error.
41
42 Allocating binder Devices
43 -------------------------
44
45 .. _ioctl: http://man7.org/linux/man-pages/man2/ioctl.2.html
46
47 To allocate a new binder device in a binderfs instance a request needs to be
48 sent through the ``binder-control`` device node. A request is sent in the form
49 of an `ioctl() <ioctl_>`_.
50
51 What a program needs to do is to open the ``binder-control`` device node and
52 send a ``BINDER_CTL_ADD`` request to the kernel. Users of binderfs need to
53 tell the kernel which name the new binder device should get. By default a name
54 can only contain up to ``BINDERFS_MAX_NAME`` chars including the terminating
55 zero byte.
56
57 Once the request is made via an `ioctl() <ioctl_>`_ passing a ``struct
58 binder_device`` with the name to the kernel it will allocate a new binder
59 device and return the major and minor number of the new device in the struct
60 (This is necessary because binderfs allocates a major device number
61 dynamically.). After the `ioctl() <ioctl_>`_ returns there will be a new
62 binder device located under /dev/binderfs with the chosen name.
63
64 Deleting binder Devices
65 -----------------------
66
67 .. _unlink: http://man7.org/linux/man-pages/man2/unlink.2.html
68 .. _rm: http://man7.org/linux/man-pages/man1/rm.1.html
69
70 Binderfs binder devices can be deleted via `unlink() <unlink_>`_. This means
71 that the `rm() <rm_>`_ tool can be used to delete them. Note that the
72 ``binder-control`` device cannot be deleted since this would make the binderfs
73 instance unusable. The ``binder-control`` device will be deleted when the
74 binderfs instance is unmounted and all references to it have been dropped.
75
76 Binder features
77 ---------------
78
79 Assuming an instance of binderfs has been mounted at ``/dev/binderfs``, the
80 features supported by the binder driver can be located under
81 ``/dev/binderfs/features/``. The presence of individual files can be tested
82 to determine whether a particular feature is supported by the driver.
83
84 Example::
85
86 cat /dev/binderfs/features/oneway_spam_detection
87 1
88

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

BinderFS 개요와 mount

1-27

이 GPL-2.0 문서는 Android binder IPC mechanism을 위한 BinderFS filesystem을 설명합니다. Runtime에 binder device를 동적으로 추가·제거할 수 있고, 새 BinderFS instance의 device는 다른 instance의 device와 독립적입니다. 따라서 새 instance를 mount하면 private binder-device set을 얻을 수 있습니다.

BinderFS는 다음처럼 `/dev/binderfs`에 mount합니다.

Android binderfs can be mounted with::

  mkdir /dev/binderfs
  mount -t binder binder /dev/binderfs

새 instance에는 일반 binder device가 없고 BinderFS request handler인 `binder-control`만 있습니다. 다른 위치에 mount하면 `devpts`, `tmpfs`처럼 다른 mount와 분리된 새 instance가 생깁니다. BinderFS는 user namespace 안에서도 mount할 수 있습니다.

Private BinderFS instance
Mount binder filesystemCreate fresh instanceExpose binder-controlAllocate private binder devices
Mount at another path or user namespaceCreate separate independent device set

Mount마다 독립된 binder-control과 device namespace를 만듭니다.

BinderFS mount option

28-41
BinderFS mount options
OptionMeaningConstraint
max=<count>이 instance에서 할당할 binder device 최대 수Per-instance
stats=globalGlobal binder statistics 활성화Initial user namespace에서만 허용

Instance별 device limit와 global statistic 접근 범위입니다.

`stats=global`을 다른 user namespace의 BinderFS mount에 사용하면 permission error를 반환합니다.

Binder device 할당

42-63

새 binder device를 할당하려면 `binder-control` device node를 통해 `ioctl()` request를 보냅니다. Program은 node를 open하고 kernel에 `BINDER_CTL_ADD` request를 보내며 새 device의 이름을 전달합니다. 이름은 terminating zero byte를 포함해 기본적으로 `BINDERFS_MAX_NAME` characters까지 가능합니다.

이름을 담은 `struct binder_device`를 `ioctl()`로 넘기면 kernel이 새 binder device를 할당하고, BinderFS가 major device number를 동적으로 할당하므로 새 device의 major/minor number를 같은 struct에 반환합니다. `ioctl()`이 끝나면 선택한 이름의 device가 `/dev/binderfs` 아래에 나타납니다.

Allocate a binder device
Open binder-controlFill struct binder_device nameIssue BINDER_CTL_ADD ioctlKernel allocates major/minorNamed node appears under /dev/binderfs

Control node request와 동적 device-number 반환 순서입니다.

Binder device 삭제

64-75

BinderFS의 binder device는 `unlink()`로 삭제할 수 있으므로 `rm` tool도 사용할 수 있습니다. 그러나 `binder-control`을 삭제하면 instance를 사용할 수 없게 되므로 삭제할 수 없습니다.

`binder-control`은 BinderFS instance를 unmount하고 모든 reference가 사라질 때 삭제됩니다.

Binder-device deletion
Named binder deviceunlink() or rmDevice node removed
binder-controlUnmount BinderFSDrop all referencesControl node removed

일반 device와 control node의 수명 규칙이 다릅니다.

Binder feature 탐지

76-87

`/dev/binderfs`에 mount했다고 가정하면 binder driver가 지원하는 feature는 `/dev/binderfs/features/` 아래에서 확인합니다. 개별 file의 존재 여부로 특정 feature 지원을 판정할 수 있습니다.

Example::

        cat /dev/binderfs/features/oneway_spam_detection
        1
Binder feature probe
PathObserved valueInterpretation
/dev/binderfs/features/oneway_spam_detection1oneway spam detection supported

Feature file이 존재하고 1을 반환하는 예입니다.