Skip to content

Instantly share code, notes, and snippets.

@kangear
Created December 7, 2014 08:29
Show Gist options
  • Save kangear/b9abfe5712c61fbe55ff to your computer and use it in GitHub Desktop.
Save kangear/b9abfe5712c61fbe55ff to your computer and use it in GitHub Desktop.
coldboot from android tree.
#include <stdio.h>
#include <dirent.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
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);
}
}
int main(int argc, char** argv)
{
printf("coldboot path:%s ...", argv[1]);
coldboot(argv[1]);
printf("done!\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment