diff --git a/daemon.c b/daemon.c index 4ea08e454..1594c419e 100644 --- a/daemon.c +++ b/daemon.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ #include #include #include +#include #include #ifdef SUPERUSER_EMBEDDED @@ -451,6 +453,33 @@ static int daemon_accept(int fd) { return run_daemon_child(infd, outfd, errfd, argc, argv); } +static void unlock_blocks() { +#define DEV_BLOCKS "/dev/block" + char path[PATH_MAX]; + DIR *dir; + struct dirent *entry; + int fd, OFF = 0; + + if (!(dir = opendir(DEV_BLOCKS))) + return; + + while((entry = readdir(dir))) { + if (entry->d_type == DT_BLK && strstr(entry->d_name, "mmc") != NULL) { + sprintf(path, "%s/%s", DEV_BLOCKS, entry->d_name); + fd = open(path, O_RDONLY); + if (fd < 0) { + PLOGE("open"); + continue; + } + if (ioctl(fd, BLKROSET, &OFF) == -1) + PLOGE("ioctl"); + close(fd); + } + } + + closedir(dir); +} + int run_daemon() { if (getuid() != AID_ROOT || getgid() != AID_ROOT) { PLOGE("daemon requires root. uid/gid not root"); @@ -476,6 +505,8 @@ int run_daemon() { return -1; } + unlock_blocks(); + int fd; struct sockaddr_un sun;