From 3578c41ef138cb3edf38bb488cb9864921f55c79 Mon Sep 17 00:00:00 2001 From: San Mehat Date: Mon, 12 Oct 2009 14:51:52 -0700 Subject: [PATCH] vold2: Add block device udev bootstrapping Signed-off-by: San Mehat --- main.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/main.cpp b/main.cpp index 1ccd147..ba8c33d 100644 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,11 @@ #include #include #include +#include +#include + +#include +#include #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;