static int tar_isDirectory(mount_t *mnt, const char *filename) { mtar_header_t h; int err = tar_find(mnt, filename, &h); if (err) { return 0; } return h.type == MTAR_TDIR; }
static void* tar_read(mount_t *mnt, const char *filename, int *size) { mtar_t *tar = mnt->udata; int err; mtar_header_t h; /* Find and load header for file */ err = tar_find(mnt, filename, &h); if (err) { return 0; } /* Allocate and read data, set size and return */ char *p = dmt_malloc(h.size); err = mtar_read_data(tar, p, h.size); if (err) { dmt_free(p); return NULL; } *size = h.size; return p; }
int main() { struct tar_file *boot_image, *file; char const **argv; uint64_t temp, temp1, temp2; argv = malloc(sizeof(char*) * 4); /* Boot Image */ boot_image = tar_parse((void*) BOOT_IMAGE); /* Dynamic Linker */ file = tar_find(boot_image, "lib/dl.so"); dl_load(file->start); /* Initial Root Filesystem / Device Filesystem / System Filesystem (tmpfs) */ argv[0] = "tmpfs"; argv[1] = NULL; file = tar_find(boot_image, "sbin/tmpfs"); fs_root = start(file, argv); io_cons("/dev", RP_TYPE_DIR); io_cons("/sys", RP_TYPE_DIR); /* Logfile */ io_cons("/dev/stderr", RP_TYPE_FILE); /* Init control file */ io_link("/sys/init", RP_CONS(getpid(), 1)); /* Keyboard Driver */ argv[0] = "kbd"; argv[1] = NULL; file = tar_find(boot_image, "sbin/kbd"); temp = start(file, argv); /* Terminal Driver */ argv[0] = "tty"; argv[1] = NULL; file = tar_find(boot_image, "sbin/tty"); temp = start(file, argv); io_link("/dev/tty", temp); /* Splash */ stdin = stderr = stdout = fopen("/dev/tty", "w"); printf(splash); /* Initrd */ initrd_init(); io_link("/dev/initrd", RP_CONS(getpid(), 0)); /* Root filesystem (tarfs) */ argv[0] = "tarfs"; argv[1] = "/dev/initrd"; argv[2] = NULL; file = tar_find(boot_image, "sbin/tarfs"); temp = start(file, argv); /* Link /dev and /sys and change root */ temp1 = io_find("/dev"); temp2 = io_find("/sys"); fs_root = temp; io_link("/dev", temp1); io_link("/sys", temp2); /* Temporary filesystem */ argv[0] = "tmpfs"; argv[1] = NULL; file = tar_find(boot_image, "sbin/tmpfs"); io_link("/tmp", start(file, argv)); /* Time Driver */ argv[0] = "time"; argv[1] = NULL; file = tar_find(boot_image, "sbin/time"); io_link("/dev/time", start(file, argv)); /* Serial Driver */ argv[0] = "serial"; argv[1] = NULL; file = tar_find(boot_image, "sbin/serial"); io_link("/dev/serial", start(file, argv)); /* Path */ setenv("PATH", "/bin"); /* Flux Init Shell */ argv[0] = "fish"; argv[1] = NULL; file = tar_find(boot_image, "bin/fish"); if (!file) { printf("critical error: no init shell found\n"); for(;;); } if (fork() < 0) { // setcuser(1); execiv(file->start, file->size, argv); } setenv("NAME", "init"); mwait(PORT_CHILD, 0); printf("INIT PANIC: system daemon died\n"); for(;;); return 0; }
static int tar_exists(mount_t *mnt, const char *filename) { mtar_header_t h; return tar_find(mnt, filename, &h) == FILESYSTEM_ESUCCESS; }
int main() { struct tar_file *boot_image, *file; char const **argv; uint64_t temp, temp1, temp2; argv = malloc(sizeof(char*) * 4); /* Boot Image */ boot_image = tar_parse((void*) BOOT_IMAGE); /* Dynamic Linker */ file = tar_find(boot_image, "lib/dl.so"); dl_load(file->start); /* Initial Root Filesystem / Device Filesystem / System Filesystem (tmpfs) */ argv[0] = "tmpfs"; argv[1] = NULL; file = tar_find(boot_image, "sbin/tmpfs"); fs_root = start(file, argv); fs_cons("/dev", "dir"); fs_cons("/sys", "dir"); /* Serial Driver */ argv[0] = "serial"; argv[1] = NULL; file = tar_find(boot_image, "sbin/serial"); fs_plink("/dev/serial", start(file, argv), NULL); ropen(1, fs_find("/dev/serial"), STAT_WRITER); ropen(2, fs_find("/dev/serial"), STAT_WRITER); stdout = fdopen(1, "w"); stderr = fdopen(2, "w"); fs_plink("/dev/stderr", fs_find("/dev/serial"), NULL); /* Keyboard Driver */ argv[0] = "kbd"; argv[1] = NULL; file = tar_find(boot_image, "sbin/kbd"); temp = start(file, argv); /* Graphics Driver */ argv[0] = "svga"; argv[1] = NULL; file = tar_find(boot_image, "sbin/svga"); start(file, argv); /* Init control file */ fs_plink("/sys/init", RP_CONS(getpid(), 0), NULL); /* Initrd */ initrd_init(); fs_plink("/dev/initrd", RP_CONS(getpid(), 1), NULL); /* Root filesystem (tarfs) */ argv[0] = "tarfs"; argv[1] = "/dev/initrd"; argv[2] = NULL; file = tar_find(boot_image, "sbin/tarfs"); temp = start(file, argv); /* Link /dev and /sys and change root */ temp1 = fs_find("/dev"); temp2 = fs_find("/sys"); fs_root = temp; fs_plink("/dev", temp1, NULL); fs_plink("/sys", temp2, NULL); /* Terminal Driver */ argv[0] = "biterm"; argv[1] = "/dev/kbd"; argv[2] = "/dev/svga0"; argv[3] = NULL; file = tar_find(boot_image, "sbin/biterm"); fs_plink("/dev/tty", start(file, argv), NULL); /* Temporary filesystem */ argv[0] = "tmpfs"; argv[1] = NULL; file = tar_find(boot_image, "sbin/tmpfs"); fs_plink("/tmp", start(file, argv), NULL); /* Time Driver */ argv[0] = "time"; argv[1] = NULL; file = tar_find(boot_image, "sbin/time"); fs_plink("/dev/time", start(file, argv), NULL); /* Pipe Driver */ argv[0] = "pipe"; argv[1] = NULL; file = tar_find(boot_image, "sbin/pipe"); fs_plink("/sys/pipe", start(file, argv), NULL); setname("init"); mwait(PORT_CHILD, 0); printf("INIT PANIC: system daemon died\n"); for(;;); return 0; }