Esempio n. 1
0
int main(int argc, char **argv) {
    uint64_t fobj;
    char *path;
    const char *type;

    if (argc < 2) {
        fprintf(stderr, "%s: missing file operand\n", argv[0]);
        return 1;
    }

    if (argc > 2) {

        if (argv[1][0] == '-') {
            switch (argv[1][1]) {
            case 'd':
                type = "dir";
                break;
            case 'f':
                type = "file";
                break;
            case 'l':
                type = "link";
                break;
            default:
                fprintf(stderr, "%s: unknown type %c\n", argv[0], argv[1][1]);
                return 1;
                break;
            }
        }
        else {
            type = argv[1];
        }

        path = path_simplify(argv[2]);
    }
    else {
        type = "file";
        path = path_simplify(argv[1]);
    }

    fobj = fs_cons(path, type);

    if (!fobj) {
        fprintf(stderr, "%s: cannot construct %s: ", argv[0], path);
        perror(NULL);
    }

    return 0;
}
Esempio n. 2
0
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;
}