xref: /aosp_15_r20/build/make/tools/fs_config/README.md (revision 9e94795a3d4ef5c1d47486f9a02bb378756cea8a)
1*9e94795aSAndroid Build Coastguard Worker# FS Config Generator
2*9e94795aSAndroid Build Coastguard Worker
3*9e94795aSAndroid Build Coastguard WorkerThe `fs_config_generator.py` tool uses the platform `android_filesystem_config.h` and the
4*9e94795aSAndroid Build Coastguard Worker`TARGET_FS_CONFIG_GEN` files to generate the following:
5*9e94795aSAndroid Build Coastguard Worker* `fs_config_dirs` and `fs_config_files` files for each partition
6*9e94795aSAndroid Build Coastguard Worker* `passwd` and `group` files for each partition
7*9e94795aSAndroid Build Coastguard Worker* The `generated_oem_aid.h` header
8*9e94795aSAndroid Build Coastguard Worker
9*9e94795aSAndroid Build Coastguard Worker## Outputs
10*9e94795aSAndroid Build Coastguard Worker
11*9e94795aSAndroid Build Coastguard Worker### `fs_config_dirs` and `fs_config_files`
12*9e94795aSAndroid Build Coastguard Worker
13*9e94795aSAndroid Build Coastguard WorkerThe `fs_config_dirs` and `fs_config_files` binary files are interpreted by the libcutils
14*9e94795aSAndroid Build Coastguard Worker`fs_config()` function, along with the built-in defaults, to serve as overrides to complete the
15*9e94795aSAndroid Build Coastguard Workerresults. The Target files are used by filesystem and adb tools to ensure that the file and directory
16*9e94795aSAndroid Build Coastguard Workerproperties are preserved during runtime operations. The host files in the `$OUT` directory are used
17*9e94795aSAndroid Build Coastguard Workerin the final stages when building the filesystem images to set the file and directory properties.
18*9e94795aSAndroid Build Coastguard Worker
19*9e94795aSAndroid Build Coastguard WorkerSee `./fs_config_generator.py fsconfig --help` for how these files are generated.
20*9e94795aSAndroid Build Coastguard Worker
21*9e94795aSAndroid Build Coastguard Worker### `passwd` and `group` files
22*9e94795aSAndroid Build Coastguard Worker
23*9e94795aSAndroid Build Coastguard WorkerThe `passwd` and `group` files are formatted as documented in man pages passwd(5) and group(5) and
24*9e94795aSAndroid Build Coastguard Workerused by bionic for implementing `getpwnam()` and related functions.
25*9e94795aSAndroid Build Coastguard Worker
26*9e94795aSAndroid Build Coastguard WorkerSee `./fs_config_generator.py passwd --help` and `./fs_config_generator.py group --help` for how
27*9e94795aSAndroid Build Coastguard Workerthese files are generated.
28*9e94795aSAndroid Build Coastguard Worker
29*9e94795aSAndroid Build Coastguard Worker### The `generated_oem_aid.h` header
30*9e94795aSAndroid Build Coastguard Worker
31*9e94795aSAndroid Build Coastguard WorkerThe `generated_oem_aid.h` creates identifiers for non-platform AIDs for developers wishing to use
32*9e94795aSAndroid Build Coastguard Workerthem in their native code.  To do so, include the `oemaids_headers` header library in the
33*9e94795aSAndroid Build Coastguard Workercorresponding makefile and `#include "generated_oem_aid.h"` in the code wishing to use these
34*9e94795aSAndroid Build Coastguard Workeridentifiers.
35*9e94795aSAndroid Build Coastguard Worker
36*9e94795aSAndroid Build Coastguard WorkerSee `./fs_config_generator.py oemaid --help` for how this file is generated.
37*9e94795aSAndroid Build Coastguard Worker
38*9e94795aSAndroid Build Coastguard Worker## Parsing
39*9e94795aSAndroid Build Coastguard Worker
40*9e94795aSAndroid Build Coastguard WorkerSee the documentation on [source.android.com](https://source.android.com/devices/tech/config/filesystem#configuring-aids) for details and examples.
41*9e94795aSAndroid Build Coastguard Worker
42*9e94795aSAndroid Build Coastguard Worker
43*9e94795aSAndroid Build Coastguard Worker## Ordering
44*9e94795aSAndroid Build Coastguard Worker
45*9e94795aSAndroid Build Coastguard WorkerOrdering within the `TARGET_FS_CONFIG_GEN` files is not relevant. The paths for files are sorted
46*9e94795aSAndroid Build Coastguard Workerlike so within their respective array definition:
47*9e94795aSAndroid Build Coastguard Worker * specified path before prefix match
48*9e94795aSAndroid Build Coastguard Worker   * for example: foo before f*
49*9e94795aSAndroid Build Coastguard Worker * lexicographical less than before other
50*9e94795aSAndroid Build Coastguard Worker   * for example: boo before foo
51*9e94795aSAndroid Build Coastguard Worker
52*9e94795aSAndroid Build Coastguard WorkerGiven these paths:
53*9e94795aSAndroid Build Coastguard Worker
54*9e94795aSAndroid Build Coastguard Worker    paths=['ac', 'a', 'acd', 'an', 'a*', 'aa', 'ac*']
55*9e94795aSAndroid Build Coastguard Worker
56*9e94795aSAndroid Build Coastguard WorkerThe sort order would be:
57*9e94795aSAndroid Build Coastguard Worker
58*9e94795aSAndroid Build Coastguard Worker    paths=['a', 'aa', 'ac', 'acd', 'an', 'ac*', 'a*']
59*9e94795aSAndroid Build Coastguard Worker
60*9e94795aSAndroid Build Coastguard WorkerThus the `fs_config` tools will match on specified paths before attempting prefix, and match on the
61*9e94795aSAndroid Build Coastguard Workerlongest matching prefix.
62*9e94795aSAndroid Build Coastguard Worker
63*9e94795aSAndroid Build Coastguard WorkerThe declared AIDs are sorted in ascending numerical order based on the option "value". The string
64*9e94795aSAndroid Build Coastguard Workerrepresentation of value is preserved. Both choices were made for maximum readability of the
65*9e94795aSAndroid Build Coastguard Workergenerated file and to line up files. Sync lines are placed with the source file as comments in the
66*9e94795aSAndroid Build Coastguard Workergenerated header file.
67*9e94795aSAndroid Build Coastguard Worker
68*9e94795aSAndroid Build Coastguard Worker## Unit Tests
69*9e94795aSAndroid Build Coastguard Worker
70*9e94795aSAndroid Build Coastguard WorkerFrom within the `fs_config` directory, unit tests can be executed like so:
71*9e94795aSAndroid Build Coastguard Worker
72*9e94795aSAndroid Build Coastguard Worker    $ python test_fs_config_generator.py
73*9e94795aSAndroid Build Coastguard Worker    ................
74*9e94795aSAndroid Build Coastguard Worker    ----------------------------------------------------------------------
75*9e94795aSAndroid Build Coastguard Worker    Ran 16 tests in 0.004s
76*9e94795aSAndroid Build Coastguard Worker    OK
77*9e94795aSAndroid Build Coastguard Worker
78*9e94795aSAndroid Build Coastguard Worker
79*9e94795aSAndroid Build Coastguard WorkerOne could also use nose if they would like:
80*9e94795aSAndroid Build Coastguard Worker
81*9e94795aSAndroid Build Coastguard Worker    $ nose2
82*9e94795aSAndroid Build Coastguard Worker
83*9e94795aSAndroid Build Coastguard WorkerTo add new tests, simply add a `test_<xxx>` method to the test class. It will automatically
84*9e94795aSAndroid Build Coastguard Workerget picked up and added to the test suite.
85