Ejemplo n.º 1
0
void stage1(void) {
	DIR *dp;
	struct dirent *dt;
	calculate_mem();
	fprintf_stdout("* Creating Mybox filesystem (%d kB) on shared memory...\n",RAMSIZE);
	xsystem("mount -t tmpfs -o \"rw,size=%dk\" virtual /ramd",RAMSIZE);
	chmod("/ramd",S_IREAD | S_IWRITE | S_IEXEC);
	chdir("/ramd");
	if((dp=opendir("/")) == NULL) {
		perror("opendir");
		exit(1);
        }
	while((dt=readdir(dp))!=NULL) {
		if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..") ||
			!strcmp(dt->d_name,"lost+found") || 
			!strcmp(dt->d_name,"ramd") || 
			!strcmp(dt->d_name,"proc") || 
			!strcmp(dt->d_name,"dev") || 
			!strcmp(dt->d_name,"sys")) continue;
			xsystem("cp -dpR /%s /ramd/",dt->d_name);
	}
	closedir(dp);
	xmkdir("dev/pts");
	xmkdir("initrd");
	umount("/proc");
	umount("/sys");
}
Ejemplo n.º 2
0
void buff_abstract::reset(bool soft_reset)
{
    _top_offset = _size = 0;

    if (!soft_reset) {
        _reserved = calculate_mem(_basic_block_size);
        _cdata = static_cast<char *>(realloc(_cdata, _reserved));
    }
    when_reseted();
}
Ejemplo n.º 3
0
void buff_abstract::release(size_t size)
{
    if (size < size_avail())
        return;

    size_t _reserved_free = _reserved - _top_offset;

    if (_reserved_free <= size) {

        if (_top_offset + size > max_buff_size)
            throw std::out_of_range("Buffer overflow. Max - " + std::to_string(max_buff_size/1000) + "Kb");

        _reserved = std::min(calculate_mem(size), max_buff_size);
        _cdata = static_cast<char *>(realloc(_cdata, _reserved));
    }
    _size = _top_offset + size;
}
Ejemplo n.º 4
0
buff_abstract::buff_abstract()
    : _reserved(calculate_mem(_basic_block_size))
{
    // Allocate first memory block.
    _cdata = static_cast<char *>(malloc(_reserved));
}
Ejemplo n.º 5
0
int bootup_main(int argc, char **argv) {
    FILE *fp;
    DIR *dp;
    struct dirent *dt;
    int t=0, rc;
    char cmd[1024], buf[1024], name[1024];
    time_t curtime;
    struct tm *loctime;
    signal(SIGINT,SIG_IGN);
    putenv("PATH=/bin");
    putenv("TERM=linux");
    umask(0770);
    chdir("/");
    putchar('\n');
    print_banner();
    putchar('\n');
    xsystem("mount -t proc -o ro virtual /proc");
    xsystem("mount -t sysfs -o ro virtual /sys");

    // STAGE 1
    calculate_mem();
    fprintf_stdout("* Creating Mybox filesystem (%d kB) on shared memory...\n",RAMSIZE);
    xsystem("mount -t tmpfs -o \"rw,size=%dk\" virtual /ramd",RAMSIZE);
    chmod("/ramd",S_IREAD | S_IWRITE | S_IEXEC);
    chdir("/ramd");
    if((dp=opendir("/")) == NULL) {
        perror("opendir");
        exit(1);
    }
    while((dt=readdir(dp))!=NULL) {
        if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..") ||
                !strcmp(dt->d_name,"lost+found") ||
                !strcmp(dt->d_name,"ramd") ||
                !strcmp(dt->d_name,"proc") ||
                !strcmp(dt->d_name,"dev") ||
                !strcmp(dt->d_name,"sys")) continue;
        xsystem("cp -dpR /%s /ramd/",dt->d_name);
    }
    closedir(dp);
    xmkdir("dev/pts");
    xmkdir("initrd");
    umount("/proc");
    umount("/sys");

    // STAGE 2
    rc=pivot_root(".","initrd");
    if(rc==-1) {
        fprintf_stdout("#### ERROR: Change root file system failed!\n");
        exit(1);
    }
    chdir("/");
    xmkdir("proc");
    xmkdir("sys");
    xsystem("mount -t proc -o rw virtual /proc");
    xsystem("mount -t sysfs -o rw virtual /sys");
    save_to_file("/proc/sys/kernel/printk","0 0 0 0\n");
    if((dp=opendir("/tmp")) == NULL) {
        perror("opendir");
        exit(1);
    }
    fprintf_stdout("-> Extracting base tools: ");
    while((dt=readdir(dp))!=NULL) {
        if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..")) continue;
        if(strstr(dt->d_name,".mpk")) {
            fprintf_stdout("#");
            xsystem("tar -C / -axf /tmp/%s",dt->d_name);
        }
    }
    free(dt);
    closedir(dp);
    fprintf_stdout("\r* Extracting base tools. Done.%s\n",SPACE);
    save_to_file("/proc/sys/kernel/modprobe","/bin/modprobe\n");
    xsystem("depmod -a");

    // STAGE 3
    chdir("/");
    xsystem("mdev -s");
    xsystem("mount -t devpts /dev/devpts /dev/pts -o \"rw,gid=0,mode=620\"");
    rename("/dev/random","/dev/random-block");
    symlink("/dev/urandom","/dev/random");
    xsystem("chmod 700 *");
    if((fp=fopen("/etc/inittab","w"))!=NULL) {
        fprintf(fp,"::sysinit:/etc/init.boot/rc.init\n");
        fprintf(fp,"tty1::respawn:/bin/getty -h -n -L tty1 115200 linux\n");
        fprintf(fp,"ttyS0::respawn:/bin/getty -h -n -L ttyS0 115200 vt100\n");
        fprintf(fp,"tty7::respawn:/bin/chkprog\n");
        fprintf(fp,"tty8::respawn:/bin/trafficd\n");
        fprintf(fp,"::restart:/bin/init\n");
        fprintf(fp,"::ctrlaltdel:/bin/bootdown\n");
        fprintf(fp,"::ctrlaltdel:/bin/reset\n");
        fprintf(fp,"::ctrlaltdel:/bin/reboot\n");
        fprintf(fp,"::shutdown:/bin/bootdown\n");
        fclose(fp);
    }
    curtime=time(NULL);
    loctime=localtime(&curtime);
    strftime(cmd, sizeof(cmd), "[%d/%m/%Y %T] TYPE=INFO MSG=****** SYSTEM LOADING ******\n",loctime);
    append_to_file("/tmp/bootup",cmd);
    if(file_exists("/bin/getkey")) {
        if(system("getkey -c 3 -m \"-> Starting Init: %d\" R")==0) {
            fprintf_stdout("\r#### WARNING: LOGIN DISABLED\n");
            xtouch("/etc/noconsole");
        } else {
            fprintf_stdout("\r* Starting Init. Done.\n");
        }
    }
    memset(buf,0x0,sizeof(buf));
    snprintf(buf,sizeof(buf),"%s\n","/bin/mdev");
    save_to_file("/proc/sys/kernel/hotplug",buf);
    do_chroot();
    signal(SIGINT,SIG_DFL);
    fprintf_stdout("#### ERROR: Failed to boot file system!\n");
    fprintf_stdout("#### ERROR: Press Ctrl+Alt+Del or switch off/on for reboot.\n");
    while(1);
    exit(0);
}