add files
[idlebox.git] / init.c
blobb9d1e837a41dd224692e48d5e5012f0d76e0f689
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <sys/mount.h>
6 #include <string.h>
7 #include <ftw.h>
9 #include "log.h"
10 #include "device.h"
13 void open_devnull_stdio(void)
15 int fd;
16 static const char *name = "/dev/__null__";
17 if (mknod(name, S_IFCHR | 0600, (1 << 8) | 3) == 0) {
18 fd = open(name, O_RDWR);
19 unlink(name);
20 if (fd >= 0) {
21 dup2(fd, 0);
22 dup2(fd, 1);
23 dup2(fd, 2);
24 if (fd > 2) {
25 close(fd);
27 return;
30 exit(1);
34 int printfile(const char*fpath, const struct stat *sb, int typeflag) {
35 INFO("%s", fpath);
36 switch(typeflag) {
37 case FTW_F:
38 INFO("\n");
39 break;
40 case FTW_D:
41 INFO("/\n");
42 break;
43 case FTW_DNR:
44 case FTW_NS:
45 INFO("--SOME THING WRONG\n");
46 break;
48 return 0;
51 int main(int argc, char **argv)
53 printf("****************************init start****************************\n");
54 int device_fd = -1;
56 umask(0);
57 open_devnull_stdio();
58 log_init();
60 mkdir("/dev", 0755);
61 mkdir("/sys", 0755);
62 mount("sysfs", "/sys", "sysfs", 0, NULL);
64 mkdir("/proc", 0755);
66 mount("tmpfs", "/dev", "tmpfs", 0, "mode=0755");
67 mkdir("/dev/pts", 0755);
68 mkdir("/dev/socket", 0755);
69 mount("devpts", "/dev/pts", "devpts", 0, NULL);
70 mount("proc", "/proc", "proc", 0, NULL);
73 INFO("device init\n");
74 device_fd = device_init();
76 /*char buf[512];
77 memset(buf, 0, 512);
78 read(0, buf, 511);
79 printf(buf);*/
80 ftw("/dev", printfile, 1000);
82 INFO("****************************init start****************************\n");
83 sleep(5000000);
85 return 0;