@@ -44,50 +44,17 @@ namespace android {
44
44
namespace init {
45
45
namespace {
46
46
47
- static bool BindMount (const std::string& source, const std::string& mount_point,
48
- bool recursive = false ) {
49
- unsigned long mountflags = MS_BIND;
50
- if (recursive) {
51
- mountflags |= MS_REC;
52
- }
53
- if (mount (source.c_str (), mount_point.c_str (), nullptr , mountflags, nullptr ) == -1 ) {
47
+ static bool BindMount (const std::string& source, const std::string& mount_point) {
48
+ if (mount (source.c_str (), mount_point.c_str (), nullptr , MS_BIND | MS_REC, nullptr ) == -1 ) {
54
49
PLOG (ERROR) << " Failed to bind mount " << source;
55
50
return false ;
56
51
}
57
52
return true ;
58
53
}
59
54
60
- static bool MakeShared (const std::string& mount_point, bool recursive = false ) {
61
- unsigned long mountflags = MS_SHARED;
62
- if (recursive) {
63
- mountflags |= MS_REC;
64
- }
65
- if (mount (nullptr , mount_point.c_str (), nullptr , mountflags, nullptr ) == -1 ) {
66
- PLOG (ERROR) << " Failed to change propagation type to shared" ;
67
- return false ;
68
- }
69
- return true ;
70
- }
71
-
72
- static bool MakeSlave (const std::string& mount_point, bool recursive = false ) {
73
- unsigned long mountflags = MS_SLAVE;
74
- if (recursive) {
75
- mountflags |= MS_REC;
76
- }
77
- if (mount (nullptr , mount_point.c_str (), nullptr , mountflags, nullptr ) == -1 ) {
78
- PLOG (ERROR) << " Failed to change propagation type to slave" ;
79
- return false ;
80
- }
81
- return true ;
82
- }
83
-
84
- static bool MakePrivate (const std::string& mount_point, bool recursive = false ) {
85
- unsigned long mountflags = MS_PRIVATE;
86
- if (recursive) {
87
- mountflags |= MS_REC;
88
- }
55
+ static bool ChangeMount (const std::string& mount_point, unsigned long mountflags) {
89
56
if (mount (nullptr , mount_point.c_str (), nullptr , mountflags, nullptr ) == -1 ) {
90
- PLOG (ERROR) << " Failed to change propagation type to private " ;
57
+ PLOG (ERROR) << " Failed to remount " << mount_point << " as " << std::hex << mountflags ;
91
58
return false ;
92
59
}
93
60
return true ;
@@ -225,17 +192,17 @@ bool SetupMountNamespaces() {
225
192
// needed for /foo/bar, then we will make /foo/bar as a mount point (by
226
193
// bind-mounting by to itself) and set the propagation type of the mount
227
194
// point to private.
228
- if (!MakeShared (" /" , true /* recursive */ )) return false ;
195
+ if (!ChangeMount (" /" , MS_SHARED | MS_REC )) return false ;
229
196
230
197
// /apex is a private mountpoint to give different sets of APEXes for
231
198
// the bootstrap and default mount namespaces. The processes running with
232
199
// the bootstrap namespace get APEXes from the read-only partition.
233
- if (!(MakePrivate (" /apex" ))) return false ;
200
+ if (!(ChangeMount (" /apex" , MS_PRIVATE ))) return false ;
234
201
235
202
// /linkerconfig is a private mountpoint to give a different linker configuration
236
203
// based on the mount namespace. Subdirectory will be bind-mounted based on current mount
237
204
// namespace
238
- if (!(MakePrivate (" /linkerconfig" ))) return false ;
205
+ if (!(ChangeMount (" /linkerconfig" , MS_PRIVATE ))) return false ;
239
206
240
207
// The two mount namespaces present challenges for scoped storage, because
241
208
// vold, which is responsible for most of the mounting, lives in the
@@ -266,15 +233,15 @@ bool SetupMountNamespaces() {
266
233
if (!mkdir_recursive (" /mnt/user" , 0755 )) return false ;
267
234
if (!mkdir_recursive (" /mnt/installer" , 0755 )) return false ;
268
235
if (!mkdir_recursive (" /mnt/androidwritable" , 0755 )) return false ;
269
- if (!(BindMount (" /mnt/user" , " /mnt/installer" , true ))) return false ;
270
- if (!(BindMount (" /mnt/user" , " /mnt/androidwritable" , true ))) return false ;
236
+ if (!(BindMount (" /mnt/user" , " /mnt/installer" ))) return false ;
237
+ if (!(BindMount (" /mnt/user" , " /mnt/androidwritable" ))) return false ;
271
238
// First, make /mnt/installer and /mnt/androidwritable a slave bind mount
272
- if (!(MakeSlave (" /mnt/installer" ))) return false ;
273
- if (!(MakeSlave (" /mnt/androidwritable" ))) return false ;
239
+ if (!(ChangeMount (" /mnt/installer" , MS_SLAVE ))) return false ;
240
+ if (!(ChangeMount (" /mnt/androidwritable" , MS_SLAVE ))) return false ;
274
241
// Then, make it shared again - effectively creating a new peer group, that
275
242
// will be inherited by new mount namespaces.
276
- if (!(MakeShared (" /mnt/installer" ))) return false ;
277
- if (!(MakeShared (" /mnt/androidwritable" ))) return false ;
243
+ if (!(ChangeMount (" /mnt/installer" , MS_SHARED ))) return false ;
244
+ if (!(ChangeMount (" /mnt/androidwritable" , MS_SHARED ))) return false ;
278
245
279
246
bootstrap_ns_fd.reset (OpenMountNamespace ());
280
247
bootstrap_ns_id = GetMountNamespaceId ();
0 commit comments