summaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
authorSan Mehat <san@android.com>2009-10-12 14:51:52 -0700
committerSan Mehat <san@android.com>2009-10-12 15:03:14 -0700
commit3578c41ef138cb3edf38bb488cb9864921f55c79 (patch)
tree58601b18fe5cfedfe11d1f2879266d1a5b7f36de /main.cpp
parent59abc3c56b432089abfe868c04cdbc3b6d28aee2 (diff)
downloadandroid_system_vold-3578c41ef138cb3edf38bb488cb9864921f55c79.tar.gz
android_system_vold-3578c41ef138cb3edf38bb488cb9864921f55c79.tar.bz2
android_system_vold-3578c41ef138cb3edf38bb488cb9864921f55c79.zip
vold2: Add block device udev bootstrapping
Signed-off-by: San Mehat <san@android.com>
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
index 1ccd147..ba8c33d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -18,6 +18,11 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <fcntl.h>
+#include <dirent.h>
#define LOG_TAG "Vold"
@@ -29,6 +34,7 @@
#include "DeviceVolume.h"
static int process_config(VolumeManager *vm);
+static void coldboot(const char *path);
int main() {
@@ -68,6 +74,8 @@ int main() {
exit(1);
}
+ coldboot("/sys/block");
+
/*
* Now that we're up, we can respond to commands
*/
@@ -85,6 +93,51 @@ int main() {
exit(0);
}
+static void do_coldboot(DIR *d, int lvl)
+{
+ struct dirent *de;
+ int dfd, fd;
+
+ dfd = dirfd(d);
+
+ fd = openat(dfd, "uevent", O_WRONLY);
+ if(fd >= 0) {
+ write(fd, "add\n", 4);
+ close(fd);
+ }
+
+ while((de = readdir(d))) {
+ DIR *d2;
+
+ if (de->d_name[0] == '.')
+ continue;
+
+ if (de->d_type != DT_DIR && lvl > 0)
+ continue;
+
+ fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
+ if(fd < 0)
+ continue;
+
+ d2 = fdopendir(fd);
+ if(d2 == 0)
+ close(fd);
+ else {
+ do_coldboot(d2, lvl + 1);
+ closedir(d2);
+ }
+ }
+}
+
+static void coldboot(const char *path)
+{
+ DIR *d = opendir(path);
+ if(d) {
+ do_coldboot(d, 0);
+ closedir(d);
+ }
+}
+
static int process_config(VolumeManager *vm) {
FILE *fp;
int n = 0;