예제 #1
0
파일: sim.c 프로젝트: bmiro/EmoFS
int main() {
	int i;
	/* mi_mount */
	emofs_sem_init(&mutex);
	bmount();

	init_fs();
	signal(SIGCHLD, reaper);
	for(i = 0; i < PROCESS_NUMBER; i++) {
		if (fork() == 0) {
			sim_work();
			exit(0);
		} else {
			usleep(NEXT_CHILDREN_WAIT);
		}
	}
	while (ENDED_CHILDREN < PROCESS_NUMBER) {
		pause();
	}
	show_work();
	puts("Simulació acabada");

	/* mi_umount */
	bumount();

	emofs_sem_get(&mutex);
	emofs_sem_del(mutex);

	return 0;
}
예제 #2
0
파일: fsio.c 프로젝트: UIKit0/proftpd
static void set_up(void) {
  if (p == NULL) {
    p = permanent_pool = make_sub_pool(NULL);
  }

  init_fs();
}
예제 #3
0
int main() {
    init_fs();
    int c = nondet_int();
    int d1 = open_dir(c, "test");
    //assert(d1 < 0);
    return 0;
}
예제 #4
0
파일: kernel.c 프로젝트: CrazyTeaFs/papaya
void kernel_c(){
	//init basic data&struct
	heap_init();
	proc_init();
	init_fs();
	mem_entity[0]='G';
	mem_entity[1]='M';
	mem_entity[2]='K';
	mem_entity[3]='B';
	k_screen_reset();
	detect_cpu();
	oprintf("detecting cpu...cpu identify:%s\n",cpu_string);
//	oprintf("mm init..\nring0_pgdir:%x,ring0_pgtbl:%x,base_proc_pgdir:%x,addr_kernel_info:%x,pages:%x\n",RING0_PGDIR,RING0_PGTBL,BASE_PROC_PGDIR,ADDR_KERNEL_INFO,PAGES);
	global_equal_map();
	__asm__("mov $0x101000,%eax\t\n"
			"mov %eax,%cr3\t\n"
			"mov %cr0,%eax\t\n"
			"or $0x80000000,%eax\t\n"
			"mov %eax,%cr0\t\n"
			);
	oprintf("global page-mapping for kernel built..open MMU\n");
	create_kernel_process((int)&idle,9,0xffff,"idle",0);	//pid must =0
	create_kernel_process((int)hs,2,0xffff,"hs",1);//hs的时间片要非常多,保证在下一轮时间片重置之前不会被挂起 ERR:pid must =1
	create_kernel_process((int)fs_ext,4,10,"fs_ext",1);//pid must =2

	create_kernel_process((int)mm,3,10,"mm",1);//ERR mm has great prio,because it shall run and prepare condition for other process
	create_kernel_process((int)tty,5,10,"tty",1);
	create_kernel_process((int)&p1,8,10,"p1",1);
//	ofork(t1,9,15,"t1",1);
//	ofork(t2,9,5,"t2",1);
//	ofork((int)&p2,7,5,"p2",3);
	oprintf("basic process ofork done..now open IRQ,proc-dispatch begin\n");
	__asm__("sti");
	while(1);//内核陷入死循环,等待第一次时钟中断
}
예제 #5
0
void setup()
{
#ifdef DEBUG_FS
    Serial.begin(115200);
#endif
    if (init_fs()) {
#ifdef DEBUG_FS
        Serial.println("Error initialising filesystem");
#endif
        return;
    }

    random_init();
    sound_setup();

    /* set the pins and pull them up */
    pinMode(INPUT0_PIN, INPUT);
    digitalWrite(INPUT0_PIN, HIGH);
    pinMode(INPUT1_PIN, INPUT);
    digitalWrite(INPUT1_PIN, HIGH);
    pinMode(INPUT2_PIN, INPUT);
    digitalWrite(INPUT2_PIN, HIGH);
    pinMode(INPUT3_PIN, INPUT);
    digitalWrite(INPUT3_PIN, HIGH);
    /* input4 is analog because we ran out of pins */

    pinMode(LED0_PIN, OUTPUT);
    pinMode(LED1_PIN, OUTPUT);
    pinMode(LED2_PIN, OUTPUT);
#ifndef DEBUG_FS
    /* pins 0 and 1 are used for serial debugging */
    pinMode(LED3_PIN, OUTPUT);
    pinMode(LED4_PIN, OUTPUT);
#endif
}
예제 #6
0
static int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	const char *filename = "/";
	int dev;
	unsigned long part = 1;
	char *ep;
	struct ext_filesystem *fs;
	int part_length;

	if (argc < 3)
		return cmd_usage(cmdtp);

	dev = (int)simple_strtoul(argv[2], &ep, 16);
	ext4_dev_desc = get_dev(argv[1], dev);

	if (ext4_dev_desc == NULL) {
		printf("\n** Block device %s %d not supported\n", argv[1], dev);
		return 1;
	}

	if (init_fs(ext4_dev_desc))
		return 1;

	fs = get_fs();
	if (*ep) {
		if (*ep != ':') {
			puts("\n** Invalid boot device, use `dev[:part]' **\n");
			return 1;
		}
		part = simple_strtoul(++ep, NULL, 16);
	}

	if (argc == 4)
		filename = argv[3];

	part_length = ext4fs_set_blk_dev(fs->dev_desc, part);
	if (part_length == 0) {
		printf("** Bad partition - %s %d:%lu **\n", argv[1], dev, part);
		ext4fs_close();
		return 1;
	}

	if (!ext4fs_mount(part_length)) {
		printf("** Bad ext2 partition or disk - %s %d:%lu **\n",
		       argv[1], dev, part);
		ext4fs_close();
		return 1;
	}
	if (ext4fs_ls(filename)) {
		printf("** Error ext2fs_ls() **\n");
		ext4fs_close();
		return 1;
	};

	ext4fs_close();
	deinit_fs(fs->dev_desc);

	return 0;
}
예제 #7
0
int main(){
  int d1;
  int n = nondet_int();
  init_fs();
  __CPROVER_assume(0 <= n && n < MAX_DIRS);
  d1=open_dir(n,"test");
  assert(d1<0); 
}
예제 #8
0
파일: fs.c 프로젝트: 565407548/micro_os
void task_fs(){
#ifdef DEBUG_FS
    printl("in task_fs\n");
#endif
    init_fs();
    MESSAGE message;
    memset(&message,0,sizeof(message));
    while(TRUE){
        send_receive(RECEIVE,ANY,&message);
        
        int source_pid=message.source_pid;
        int fd;
	
        switch(message.type){
        case INFO_FS_CREATE:
            message.res_bool=do_create(&message);
            break;
        case INFO_FS_UNLINK:
            message.res_bool=do_unlink(&message);
            break;
        case INFO_FS_LS:
            message.res_int=do_ls(&message);
            break;
        case INFO_FS_OPEN:
            fd=do_open(&message);
            message.fd=fd;
            break;
        case INFO_FS_READ:
            do_read(&message);
            break;
        case INFO_FS_WRITE:
            do_write(&message);
            break;
        case INFO_FS_SEEK:
            do_seek(&message);
            break;
        case INFO_FS_CLOSE:
            message.res_int=do_close(&message);
            break;
        default:
            printl("\n\n\nunknown message type:%d\n",message.type);
            assert(FALSE,"unknown message type!");
        }
        if(message.type!=INFO_SUSPEND_PROCESS){
            send_receive(SEND,source_pid,&message);
        }else{
            printl("inof_suspend_process\n");
        }
    }
#ifndef _FS_H_
#define _FS_H_
    
#endif /* _FS_H_ */
    while(1)
        ;
    spin("never here");
}
예제 #9
0
static void set_up(void) {
  if (p == NULL) {
    p = permanent_pool = make_sub_pool(NULL);
  }

  init_fs();
  pr_fs_statcache_set_policy(PR_TUNABLE_FS_STATCACHE_SIZE,
    PR_TUNABLE_FS_STATCACHE_MAX_AGE, 0);
}
예제 #10
0
파일: fs.c 프로젝트: qinpan1003/linux_drv
//--------------------------------------------------------------------------------------------------*/
// 文件系统主循环任务
void task_fs(void * pdata)
{
	MSG 	msg;
	FS_MSG* 	p_fs_msg;
	pdata = pdata;
	int src;
	init_fs();
	while(1)
	{
//--------------------------------------------------------------------------------------------------*/
//
		assert(recv(ANY,&msg) == 0);
		assert(	msg.type == FS_MSG_UNION	);
		src	= msg.sender;
		p_fs_msg	= &msg.msg_union.fs_msg;
		switch(p_fs_msg->para)
		{
			case FS_OPEN:
				p_fs_msg->fd = fs_open(p_fs_msg->pathname,p_fs_msg->flags,task_table + msg.sender);
				break;
			case FS_WRITE:
				p_fs_msg->count = fs_write(p_fs_msg->fd,p_fs_msg->buf,p_fs_msg->offset,p_fs_msg->count,task_table + msg.sender);
  				break;
			case FS_READ:
				p_fs_msg->count = fs_read(p_fs_msg->fd,p_fs_msg->buf,p_fs_msg->offset,p_fs_msg->count,task_table + msg.sender);
           			break;
			case FS_CLOSE:
				p_fs_msg->para = fs_close(p_fs_msg->fd,task_table + msg.sender);
				break;
			case FS_DEL:
				p_fs_msg->para = fs_delete(va2pa((task_table + msg.sender)->pdb,p_fs_msg->pathname),p_fs_msg->flags);
				break;
			case FS_RESUME:
				src = p_fs_msg->flags;	// 待解除阻塞的进程ID(利用了flags这个成员返回PID)
				assert(0 <= src && src < NR_TOTAL);
				break;			// p_fs_msg->count:-1 请求失败(有其他进程正在请求输入),其他值表示输入字节数
			case FS_FORK:
				p_fs_msg->para	= fs_do_fork(p_fs_msg->flags);
				break;
			case FS_EXIT:
				fs_do_exit(p_fs_msg->flags);
				break;
			case FS_LSEEK:
				p_fs_msg->para	= fs_do_lseek(p_fs_msg->fd,p_fs_msg->offset,p_fs_msg->flags,task_table + msg.sender);
				break;
			default:	break;
		}
		if(no_answer == 1)
			no_answer = 0;			// 解除下一个tty请求的阻塞
		else
			send(src,&msg);
//--------------------------------------------------------------------------------------------------*/
	}
}
예제 #11
0
파일: sage_main.c 프로젝트: taysom/tau
int main (int argc, char *argv[])
{
	debugenv();
	setprogname(argv[0]);
FN;
	init_net();

	init_fs();
	init_tau();

	tag_loop();

	return 0;
}
예제 #12
0
파일: fs.c 프로젝트: qpig/sfs
void task_fs()
{
	printk("Task FS begins.\n");

	init_buffer( 0x300000 );
	init_fs();

	MESSAGE msg;

	while(1)
	{
		send_recv( RECEIVE, ANY, &msg );
		int src = msg.source;
		switch(msg.type)
		{
			case OPEN:
				msg.FD = do_open( &msg );
				break;
			case CLOSE:
				msg.RETVAL = do_close( &msg );
				break;
			case READ:
			case WRITE:
				msg.CNT = do_rdwr( &msg );
				break;
			case RESUME_PROC:
				src = msg.PROC_NR;
				break;
			case FORK:
				msg.RETVAL = fs_fork( &msg );
				break;
			case EXIT:
				msg.RETVAL = fs_exit( &msg );
				break;
			default:
				dump_msg("FS:unknow message:", &msg );
				assert(0);
				break;
		}

		if( msg.type != SUSPEND_PROC )
		{
			msg.type = SYSCALL_RET;
			send_recv( SEND, src, &msg );
		}
	}
	spin("FS");
}
예제 #13
0
void
check_control_socket(void)
{
	int c, r;
	struct lfs_cleanerd_cmd cmd;
	struct clfs **nfsp;

	if (control_socket < 0)
		return;

	while(1) {
		ioctl(control_socket, FIONREAD, &c);
		if (c <= 0)
			return;
		read(control_socket, (char *)&cmd, sizeof(cmd));

		switch(cmd.cmd) {
		    case 'C': /* Add filesystem for cleaning */
			++nfss;
			nfsp = (struct clfs **)realloc(fsp,
						       nfss * sizeof(*fsp));
			if (nfsp == NULL) {
				--nfss;
				break;
			}
			fsp = nfsp;

			fsp[nfss - 1] = (struct clfs *)malloc(sizeof(**fsp));
			if (fsp[nfss - 1] == NULL) {
				syslog(LOG_ERR, "%s: couldn't alloc memory: %m"
				       cmd.data);
				--nfsp;
				break;
			}
				
			if ((r = init_fs(fsp[nfss - 1], cmd.data)) < 0) {
				syslog(LOG_ERR, "%s: couldn't init: "
				       "error code %d", cmd.data, r);
				handle_error(fsp, nfss - 1);
			}
			break;
		    default:
			syslog(LOG_NOTICE, "unknown message type %d", cmd.cmd);
			break;
		}
	}
}
예제 #14
0
파일: main.c 프로젝트: wtaysom/tau
int main (int argc, char *argv[])
{
	char	*dev = ".btree";

//	debugoff();
	debugon();
FN;
	if (argc > 1) {
		dev = argv[1];
	}
	unlink(dev);	/* Development only */
	binit(20);
	init_fs(dev);
	init_shell(NULL);
	init_cmd();
	return shell();
}
예제 #15
0
파일: display.c 프로젝트: Nakor78/proftpd
static void set_up(void) {
  (void) unlink(display_test_file);

  if (p == NULL) {
    p = session.pool = permanent_pool = make_sub_pool(NULL);
  }

  init_dirtree();
  init_fs();
  init_netio();
  init_inet();

  if (getenv("TEST_VERBOSE") != NULL) {
    pr_trace_set_levels("netio", 1, 20);
    pr_trace_set_levels("response", 1, 20);
  }
}
예제 #16
0
파일: kernel.c 프로젝트: asmodz/ganjax
void kmain(void)
{

    setup_interrupts();
    init_terminal();
    if((rc = init_fs()) > 0)
        puts("[KERNEL] FS INIT ERROR\r\n");
    
    while(1)
    {       
        puts_attrib("$", color_entry(COLOR_GREEN, COLOR_BLACK));
        get_string(buffer, 30, true);
        if(strcmp(buffer, "ls") == 0){
            print_files();
            continue;
        }
        if(strcmp(buffer, "kk") == 0){
            //int8_t r;
            //get_string(buffer, 11, false);
            //r = create_file(buffer, 0, strlen(msg) );
            //if(r != DISK_OP_OK)
            //  print_int(r, 10, 0);
            continue;
            
        }
        if(strcmp(buffer, "dd") == 0){
            int8_t r;
            get_string(buffer, 11, false);
            r = delete_file(buffer);
            if(r != DISK_OP_OK){
                print_int(r, 10, 0);
            }
            continue;
        }
        if(strcmp(buffer, "run") == 0)
        {
            if((rc = run_program("RAW.BIN")) != EXEC_OP_OK){
                puts("Exec error c:"); print_int(rc, 10, 0); eol();
            }
        }
        
        
        puts("\r\n");
    }
    
}
예제 #17
0
파일: misc.c 프로젝트: predever/proftpd
static void set_up(void) {
  (void) unlink(misc_test_shutmsg);

  if (p == NULL) {
    p = permanent_pool = make_sub_pool(NULL);
  }

  init_fs();
  pr_fs_statcache_set_policy(PR_TUNABLE_FS_STATCACHE_SIZE,
    PR_TUNABLE_FS_STATCACHE_MAX_AGE, 0);

  if (getenv("TEST_VERBOSE") != NULL) {
    pr_trace_set_levels("fsio", 1, 20);
    pr_trace_set_levels("fs.statcache", 1, 20);
  }

  schedule_called = 0;
}
예제 #18
0
파일: dir_main.c 프로젝트: taysom/tau
int main (int argc, char *argv[])
{
	int	rc;

	debugenv();
FN;
	setprogname(argv[0]);

	rc = init_fs();
	if (rc) return rc;

	rc = init_net();
	if (rc) return rc;

	tag_loop();

	return 0;
}
예제 #19
0
파일: main.c 프로젝트: uping/prettyos
//init process pid = 0;
static void start_kernel()
{
//	init_trap();// define in kernel/start.c

	init_clock(); //clock interrupt init

	main_memory_end = (1<<20) + (EXT_MEM_K << 10);
	main_memory_end &= 0xfffff000;

	if(main_memory_end > 12 * 1024 * 1024)	//内存大于6M时
	{
		buffer_memory_start = 3 * 1024 * 1024;
		buffer_memory_end = 4 * 1024 * 1024;
	}
	else 
	{
		buffer_memory_start = 3 * 1024 * 1024 - 512 * 1024;
		buffer_memory_end = 3 * 1024 * 1024;
	}

	main_memory_start = buffer_memory_end;		//主内存的起始地址 = 缓冲区末端
	main_memory_start &= 0xfffff000;
	printk("start memroy = %d\t end memory = %d\n",main_memory_start,main_memory_end);
	
//	buffer_memory_end = (buffer_memory_end + BUFFER_SIZE) & (~BUFFER_SIZE)- 1;  //align BUFFER_SIZE 
	init_buffer(buffer_memory_start,buffer_memory_end); //buffer init
	paging_init(main_memory_start,main_memory_end);

	init_mem(main_memory_start,main_memory_end); //memeory management init

	init_hd(); //hard disk init

	init_fs(); //filesystem init


//	init_sock();

	move_to_user_mode();

	while(1){}

}
예제 #20
0
파일: main.c 프로젝트: liangbizhi/bzOS
/**************************************************************************************************
 * 					task_fs
 **************************************************************************************************
 * <Ring 1> Main loop of Task FS.
 *************************************************************************************************/
PUBLIC void task_fs(){
	init_fs();

	while(TRUE){
		send_recv(RECEIVE, ANY, &fs_msg);
		int src	= fs_msg.source;
		pcaller	= &proc_table[src];

		switch(fs_msg.type){
			case OPEN:
			fs_msg.FD	= do_open();
			break;
		case CLOSE:
			fs_msg.RETVAL	= do_close();
			break;
		case READ:
		case WRITE:
			fs_msg.CNT	= do_rdwt();
			break;
		case UNLINK:
			fs_msg.RETVAL	= do_unlink();
			break;
		case RESUME_PROC:
			src = fs_msg.PROC_NR;
			break;
		case FORK:
			fs_msg.RETVAL	= fs_fork();
			break;
		default:
			dump_msg("FS::unkown message:", &fs_msg);
			assert(0);
			break;
		}
		/* reply */
		if(fs_msg.type != SUSPEND_PROC){
			fs_msg.type	= SYSCALL_RET;
			send_recv(SEND, src, &fs_msg);
		}
	}
	spin("FS");
}
예제 #21
0
static void start_kernel()
{
    init_clock(); //clock interrupt init

    get_memsize(&main_memory_end);
    main_memory_end &= 0xfffff000;

    paging_init();
    init_mem(); //memeory management init
    buffer_init();
    /* scheduler init */
    init_sched(); 

    init_hd(); //hard disk init

    init_fs(); //filesystem init

    init_task();

    /*init_sock();*/

}
예제 #22
0
int main(){
  int d1,n,n_file;
  n = nondet_int(); //non_d directory
  init_fs(); //Init sample file-system

  //Assume to be in the allowed directory range
  __CPROVER_assume(n >= 0 && n < MAX_DIRS);
  // d1 = open_dir(n,"test");
  // assert(d1<0);


  ////////////////////////////////////////////////////////
  //A file can only be read or written when it is open  //
  ////////////////////////////////////////////////////////
  n_file = open_file(0, "test"); //open file
  assert(n_file == 0);
  // n_file = open_file(1, "test"); //open file
  // assert(n_file > 0);
  // n_file = open_file(2, "test"); //open file
  // assert(n_file > 0);
  // n_file = open_file(3, "test"); //open file
  // assert(n_file > 0);
  
  // if((file_status[n_file] & ENTRY_USED)){ //check if file is open
  //     int w1 = write_file(n_file, 0, 11, "hello world"); //write
  //     assert(w1 == 11); //Write should success file is open
  // }else{
  //     int w1 = write_file(n_file, 0, 11, "hello world"); //write
  //     assert(w1<0); //Write should fail file is closed
  // }
  // assert((dir_status[n] & ENTRY_USED) == (file_status[n] & ENTRY_USED)); //file is open

  //Assume to be in the allowed file range
  __CPROVER_assume(n_file >= 0 && n_file < MAX_FILES);

   perform_action(2);
  
}
예제 #23
0
int main(int argc, char *argv[]){   
    int fuserc;
    struct newfs_state *state;

    state = malloc(sizeof(struct newfs_state));
    state->logfile = init_log_file();

    write_log("--------------------\n");
 
    // Initialise the file system. This is being done outside of fuse for ease of debugging.
    init_fs();

    fuserc = fuse_main(argc, argv, &newfs_oper, state);
    
    // Shutdown the file system.
    shutdown_fs();

    close_log_file();

    free(state);

    return fuserc;
}
예제 #24
0
/**
 * <Ring 1> The main loop of TASK FS.
 * 
 *****************************************************************************/
PUBLIC void task_fs()
{
	printl("{FS} Task FS begins.\n");

	init_fs();

	while (1) {
		send_recv(RECEIVE, ANY, &fs_msg);

		int msgtype = fs_msg.type;
		int src = fs_msg.source;
		pcaller = &proc_table[src];

		switch (msgtype) {
		case OPEN:
			fs_msg.FD = do_open();
			break;
		case CLOSE:
			fs_msg.RETVAL = do_close();
			break;
		case READ:
		case WRITE:
			fs_msg.CNT = do_rdwt();
			break;
		case UNLINK:
			fs_msg.RETVAL = do_unlink();
			break;
		case RESUME_PROC:
			src = fs_msg.PROC_NR;
			break;
		case FORK:
			fs_msg.RETVAL = fs_fork();
			break;
		case EXIT:
			fs_msg.RETVAL = fs_exit();
			break;
		/* case LSEEK: */
		/* 	fs_msg.OFFSET = do_lseek(); */
		/* 	break; */
		case STAT:
			fs_msg.RETVAL = do_stat();
			break;
		default:
			dump_msg("FS::unknown message:", &fs_msg);
			assert(0);
			break;
		}

#ifdef ENABLE_DISK_LOG
		char * msg_name[128];
		msg_name[OPEN]   = "OPEN";
		msg_name[CLOSE]  = "CLOSE";
		msg_name[READ]   = "READ";
		msg_name[WRITE]  = "WRITE";
		msg_name[LSEEK]  = "LSEEK";
		msg_name[UNLINK] = "UNLINK";
		/* msg_name[FORK]   = "FORK"; */
		/* msg_name[EXIT]   = "EXIT"; */
		/* msg_name[STAT]   = "STAT"; */

		switch (msgtype) {
		case UNLINK:
			dump_fd_graph("%s just finished. (pid:%d)",
				      msg_name[msgtype], src);
			//panic("");
		case OPEN:
		case CLOSE:
		case READ:
		case WRITE:
		case FORK:
		case EXIT:
		/* case LSEEK: */
		case STAT:
			break;
		case RESUME_PROC:
			break;
		default:
			assert(0);
		}
#endif

		/* reply */
		if (fs_msg.type != SUSPEND_PROC) {
			fs_msg.type = SYSCALL_RET;
			send_recv(SEND, src, &fs_msg);
		}
	}
}
예제 #25
0
/* Check if MAGIC is valid and print the Multiboot information structure
   pointed by ADDR. */
void
entry (unsigned long magic, unsigned long addr)
{
	multiboot_info_t *mbi;

	/* Clear the screen. */
	clear();

	/* Am I booted by a Multiboot-compliant boot loader? */
	if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
	{
		printf ("Invalid magic number: 0x%#x\n", (unsigned) magic);
		return;
	}

	/* Set MBI to the address of the Multiboot information structure. */
	mbi = (multiboot_info_t *) addr;

	/* Print out the flags. */
	printf ("flags = 0x%#x\n", (unsigned) mbi->flags);

	/* Are mem_* valid? */
	if (CHECK_FLAG (mbi->flags, 0))
		printf ("mem_lower = %uKB, mem_upper = %uKB\n",
				(unsigned) mbi->mem_lower, (unsigned) mbi->mem_upper);

	/* Is boot_device valid? */
	if (CHECK_FLAG (mbi->flags, 1))
		printf ("boot_device = 0x%#x\n", (unsigned) mbi->boot_device);

	/* Is the command line passed? */
	if (CHECK_FLAG (mbi->flags, 2))
		printf ("cmdline = %s\n", (char *) mbi->cmdline);

	if (CHECK_FLAG (mbi->flags, 3)) {
		int mod_count = 0;
		int i;
		module_t* mod = (module_t*)mbi->mods_addr;
		
		while(mod_count < mbi->mods_count) {
			printf("Module %d loaded at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_start);
			printf("Module %d ends at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_end);
			printf("First few bytes of module:\n");
			
			BOOT_BLOCK_PTR = (uint32_t *)mod->mod_start;
			for(i = 0; i<16; i++) {
				printf("0x%x ", *((char*)(mod->mod_start+i)));
			}
			printf("\n");
			mod_count++;
			mod++;
		}
	}
	/* Bits 4 and 5 are mutually exclusive! */
	if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5))
	{
		printf ("Both bits 4 and 5 are set.\n");
		return;
	}

	/* Is the section header table of ELF valid? */
	if (CHECK_FLAG (mbi->flags, 5))
	{
		elf_section_header_table_t *elf_sec = &(mbi->elf_sec);

		printf ("elf_sec: num = %u, size = 0x%#x,"
				" addr = 0x%#x, shndx = 0x%#x\n",
				(unsigned) elf_sec->num, (unsigned) elf_sec->size,
				(unsigned) elf_sec->addr, (unsigned) elf_sec->shndx);
	}

	/* Are mmap_* valid? */
	if (CHECK_FLAG (mbi->flags, 6))
	{
		memory_map_t *mmap;

		printf ("mmap_addr = 0x%#x, mmap_length = 0x%x\n",
				(unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length);
		for (mmap = (memory_map_t *) mbi->mmap_addr;
				(unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length;
				mmap = (memory_map_t *) ((unsigned long) mmap
					+ mmap->size + sizeof (mmap->size)))
			printf (" size = 0x%x,     base_addr = 0x%#x%#x\n"
					"     type = 0x%x,  length    = 0x%#x%#x\n",
					(unsigned) mmap->size,
					(unsigned) mmap->base_addr_high,
					(unsigned) mmap->base_addr_low,
					(unsigned) mmap->type,
					(unsigned) mmap->length_high,
					(unsigned) mmap->length_low);
	}

	/* Construct an LDT entry in the GDT */
	{
		seg_desc_t the_ldt_desc;
		the_ldt_desc.granularity    = 0;
		the_ldt_desc.opsize         = 1;
		the_ldt_desc.reserved       = 0;
		the_ldt_desc.avail          = 0;
		the_ldt_desc.present        = 1;
		the_ldt_desc.dpl            = 0x0;
		the_ldt_desc.sys            = 0;
		the_ldt_desc.type           = 0x2;

		SET_LDT_PARAMS(the_ldt_desc, &ldt, ldt_size);
		ldt_desc_ptr = the_ldt_desc;
		lldt(KERNEL_LDT);
	}

	/* Construct a TSS entry in the GDT */
	{
		seg_desc_t the_tss_desc;
		the_tss_desc.granularity    = 0;
		the_tss_desc.opsize         = 0;
		the_tss_desc.reserved       = 0;
		the_tss_desc.avail          = 0;
		the_tss_desc.seg_lim_19_16  = TSS_SIZE & 0x000F0000;
		the_tss_desc.present        = 1;
		the_tss_desc.dpl            = 0x0;
		the_tss_desc.sys            = 0;
		the_tss_desc.type           = 0x9;
		the_tss_desc.seg_lim_15_00  = TSS_SIZE & 0x0000FFFF;

		SET_TSS_PARAMS(the_tss_desc, &tss, tss_size);

		tss_desc_ptr = the_tss_desc;

		tss.ldt_segment_selector = KERNEL_LDT;
		tss.ss0 = KERNEL_DS;
		tss.esp0 = 0x800000;
		ltr(KERNEL_TSS);
	}
	/* disable all interrupts on PIC */

	/* Init the PIC */
	i8259_init();
	
	init_idt();
	int i;
	for(i = 0; i < 16; i++)
	{
		disable_irq(i);
	}

	/* Initialize devices, memory, filesystem, enable device interrupts on the
	 * PIC, any other initialization stuff... */\
	paging_init();
	rtc_init();
	init_fs();
	enable_irq(PIC_1);
	terminal_open(0);
	clear();

	/* Enable interrupts */
	/* Do not enable the following until after you have set up your
	 * IDT correctly otherwise QEMU will triple fault and simple close
	 * without showing you any output */
	/*printf("Enabling Interrupts\n");*/
	sti();
	//write(1, "abcdefghijklmnopqrstuvwxyz", 26);
	/*
	printf("testing terminal \n");*/

	/*
	unsigned char buf[4000] = "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n";
	write(1, buf, 4000);
	*/
	/*unsigned char buf2[4000] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\n";
	terminal_write(1, buf2, 4000);
	terminal_read(0, buf, 4000);
	terminal_write(1, buf, 4000);
	printf("done testing terminal \n");
	//clear(); // Clears the screen before test_interrupts
	//int x = 1/0;
	
	*/
	 
	// Tests for RTC
	/*
	for(i = 0; i < 1000000000; i++);
	rtc_read();
	int j = 1024;
	rtc_write(&j,4);
	for(i = 0; i < 1000000000; i++);
	rtc_read();
	*/


	/*testing open and read file*/
	
	/*uint8_t filename[] = "verylargetxtwithverylongname.tx";
	uint8_t buffer[3000];
	int res;
	res = filesystem_open(filename);
	if(res == -1)
		terminal_write((const uint8_t *)"not able to open the file", 200);
	else
	{
		filesystem_read(0, buffer, 3000);
			terminal_write(buffer, 3000);
    }*/
	
	
	/*testing read directory*/
	//dirread();
	
	/* Execute the first program (`shell') ... */

	 uint8_t filename[] = "shell";	
	 execute(filename);
	 /*execute(filename);
	 execute(filename);
	 execute(filename);
	 execute(filename);*/
	 

	/* Spin (nicely, so we don't chew up cycles) */
	asm volatile(".1: hlt; jmp .1;");
}
예제 #26
0
int main(int argc, char *argv[]) {
  pool *p;
  const char *remote_name;
  pr_netaddr_t *remote_addr;
  conn_t *client_conn, *ctrl_conn, *data_conn;
  unsigned int connect_timeout, remote_port;
  struct proxy_ftp_client *ftp;
  int res, timerno;
  char buf[1024];

  /* Seed the random number generator. */
  /* XXX Use random(3) in the future? */
  srand((unsigned int) (time(NULL) * getpid()));

  init_pools();
  init_privs();
  init_log();
  init_regexp();
  init_inet();
  init_netio();
  init_netaddr();
  init_fs();
  init_class();
  init_config();
  init_stash();

  pr_log_setdebuglevel(10);
  log_stderr(TRUE);
  pr_trace_use_stderr(TRUE);
  pr_trace_set_levels("DEFAULT", 1, 20);

  p = make_sub_pool(permanent_pool);
  pr_pool_tag(p, "FTP Client Pool");

  remote_name = "ftp.proftpd.org";

  remote_addr = pr_netaddr_get_addr(p, remote_name, NULL);
  if (remote_addr == NULL) {
    fprintf(stderr, "Failed to get addr for '%s': %s\n", remote_name,
      strerror(errno));
    destroy_pool(p);
    return 1;
  } 

  fprintf(stdout, "Resolved name '%s' to IP address '%s'\n", remote_name,
    pr_netaddr_get_ipstr(remote_addr));

  remote_port = 21;
  connect_timeout = 5;
  ftp = proxy_ftp_connect(p, remote_addr, remote_port, connect_timeout, NULL);
  if (ftp == NULL) {
    fprintf(stderr, "Error connecting to FTP server: %s\n", strerror(errno));
    destroy_pool(p);
    return 1;
  }

  fprintf(stdout, "Successfully connected to %s:%d from %s:%d\n", remote_name,
    remote_port, pr_netaddr_get_ipstr(client_conn->local_addr),
    ntohs(pr_netaddr_get_port(client_conn->local_addr)));

  res = proxy_ftp_disconnect(ftp);
  if (res < 0) {
    fprintf(stderr, "Error disconnecting from FTP server: %s\n",
      strerror(errno));
    destroy_pool(p);
    return 1;
  }

  ctrl_conn = pr_inet_openrw(p, client_conn, NULL, PR_NETIO_STRM_OTHR,
    -1, -1, -1, FALSE);
  if (ctrl_conn == NULL) {
    fprintf(stderr, "Error opening control connection: %s\n", strerror(errno));

    pr_inet_close(p, client_conn);
    destroy_pool(p);
    return 1;
  }

  fprintf(stdout, "Reading response from %s:%d\n", remote_name, remote_port);

  /* Read the response */
  memset(buf, '\0', sizeof(buf));

  /* XXX We need to write our own version of netio_telnet_gets(), with
   * the buffering to handle reassembly of a full FTP response out of
   * multiple TCP packets.  Not sure why the existing netio_telnet_gets()
   * is not sufficient.  But we don't need the handling of Telnet codes
   * in our reading.  But DO generate the 'core.ctrl-read' event, so that
   * any event listeners get a chance to process the data we've received.
   * (Or maybe use 'mod_proxy.server-read', and differentiate between
   * client and server reads/writes?)
   */
  if (pr_netio_read(ctrl_conn->instrm, buf, sizeof(buf)-1, 5) < 0) {
    fprintf(stderr, "Error reading response from server: %s\n",
      strerror(errno));

  } else {
    fprintf(stdout, "Response: \"%s\"\n", buf);
  }

  /* Disconnect */
  res = pr_netio_printf(ctrl_conn->outstrm, "%s\r\n", C_QUIT);
  if (res < 0) {
    fprintf(stderr, "Error writing command to server: %s", strerror(errno));
  }

  pr_inet_close(p, ctrl_conn);
  pr_inet_close(p, client_conn);
  destroy_pool(p);
  return 0;
}
예제 #27
0
파일: pyuv.c 프로젝트: benoitc/pyuv
/* Module */
PyObject*
init_pyuv(void)
{
    /* Modules */
    PyObject *pyuv;
    PyObject *errno_module;
    PyObject *error_module;
    PyObject *fs_module;
    PyObject *util_module;

    /* Initialize GIL */
    PyEval_InitThreads();

#ifdef PYUV_WINDOWS
    if (pyuv_setmaxstdio()) {
        return NULL;
    }
#endif

    /* Main module */
#ifdef PYUV_PYTHON3
    pyuv = PyModule_Create(&pyuv_module);
#else
    pyuv = Py_InitModule("pyuv", NULL);
#endif

    /* Errno module */
    errno_module = init_errno();
    if (errno_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "errno", errno_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_errno_module.m_name, errno_module);
    Py_DECREF(errno_module);
#endif

    /* Error module */
    error_module = init_error();
    if (error_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "error", error_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_error_module.m_name, error_module);
    Py_DECREF(error_module);
#endif

    /* FS module */
    fs_module = init_fs();
    if (fs_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "fs", fs_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_fs_module.m_name, fs_module);
    Py_DECREF(fs_module);
#endif

    /* Util module */
    util_module = init_util();
    if (util_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "util", util_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_util_module.m_name, util_module);
    Py_DECREF(util_module);
#endif

    /* Types */
    AsyncType.tp_base = &HandleType;
    TimerType.tp_base = &HandleType;
    PrepareType.tp_base = &HandleType;
    IdleType.tp_base = &HandleType;
    CheckType.tp_base = &HandleType;
    SignalType.tp_base = &HandleType;
    UDPType.tp_base = &HandleType;
    PollType.tp_base = &HandleType;
    ProcessType.tp_base = &HandleType;

    StreamType.tp_base = &HandleType;
    TCPType.tp_base = &StreamType;
    PipeType.tp_base = &StreamType;
    TTYType.tp_base = &StreamType;

    PyUVModule_AddType(pyuv, "Loop", &LoopType);
    PyUVModule_AddType(pyuv, "Async", &AsyncType);
    PyUVModule_AddType(pyuv, "Timer", &TimerType);
    PyUVModule_AddType(pyuv, "Prepare", &PrepareType);
    PyUVModule_AddType(pyuv, "Idle", &IdleType);
    PyUVModule_AddType(pyuv, "Check", &CheckType);
    PyUVModule_AddType(pyuv, "Signal", &SignalType);
    PyUVModule_AddType(pyuv, "TCP", &TCPType);
    PyUVModule_AddType(pyuv, "Pipe", &PipeType);
    PyUVModule_AddType(pyuv, "TTY", &TTYType);
    PyUVModule_AddType(pyuv, "UDP", &UDPType);
    PyUVModule_AddType(pyuv, "Poll", &PollType);
    PyUVModule_AddType(pyuv, "StdIO", &StdIOType);
    PyUVModule_AddType(pyuv, "Process", &ProcessType);
    PyUVModule_AddType(pyuv, "ThreadPool", &ThreadPoolType);
    PyUVModule_AddType(pyuv, "SignalChecker", &SignalCheckerType);

    /* UDP constants */
    PyModule_AddIntMacro(pyuv, UV_JOIN_GROUP);
    PyModule_AddIntMacro(pyuv, UV_LEAVE_GROUP);

    /* Process constants */
    PyModule_AddIntMacro(pyuv, UV_PROCESS_SETUID);
    PyModule_AddIntMacro(pyuv, UV_PROCESS_SETGID);
    PyModule_AddIntMacro(pyuv, UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS);
    PyModule_AddIntMacro(pyuv, UV_PROCESS_DETACHED);
    PyModule_AddIntMacro(pyuv, UV_IGNORE);
    PyModule_AddIntMacro(pyuv, UV_CREATE_PIPE);
    PyModule_AddIntMacro(pyuv, UV_READABLE_PIPE);
    PyModule_AddIntMacro(pyuv, UV_WRITABLE_PIPE);
    PyModule_AddIntMacro(pyuv, UV_INHERIT_FD);
    PyModule_AddIntMacro(pyuv, UV_INHERIT_STREAM);

    /* Poll constants */
    PyModule_AddIntMacro(pyuv, UV_READABLE);
    PyModule_AddIntMacro(pyuv, UV_WRITABLE);

    /* Handle types */
    PyModule_AddIntMacro(pyuv, UV_UNKNOWN_HANDLE);
#define XX(uc, lc) PyModule_AddIntMacro(pyuv, UV_##uc);
    UV_HANDLE_TYPE_MAP(XX)
#undef XX

    /* Module version (the MODULE_VERSION macro is defined by setup.py) */
    PyModule_AddStringConstant(pyuv, "__version__", __MSTR(MODULE_VERSION));

    /* libuv version */
    PyModule_AddStringConstant(pyuv, "LIBUV_VERSION", __MSTR(LIBUV_VERSION));

    return pyuv;

fail:
#ifdef PYUV_PYTHON3
    Py_DECREF(pyuv);
#endif
    return NULL;

}
예제 #28
0
int main () {
    
    // INIT FS HERE
    init_fs();
    
  int retval, i;
  int fd;
  int index_node_number;

  /* Some arbitrary data for our files */
  memset (data1, '1', sizeof (data1));
  memset (data2, '2', sizeof (data2));
  memset (data3, '3', sizeof (data3));


#ifdef TEST1
	kmkdir("/home");
	kcreat("/home/file");
  /* ****TEST 1: MAXIMUM file creation**** */

  /* Assumes the pre-existence of a root directory file "/"
     that is neither created nor deleted in this test sequence */

  /* Generate MAXIMUM regular files */
  for (i = 0; i < MAX_FILES + 1; i++) { // go beyond the limit
    sprintf (pathname, "/file%d", i);
    
    retval = kcreat (pathname);
    
    if (retval < 0) {
      fprintf (stderr, "kcreate: File creation error! status: %d\n", 
	       retval);
      
      if (i != MAX_FILES)
	exit (1);
    }
    
    memset (pathname, 0, 80);
  }   

  /* Delete all the files created */
  for (i = 0; i < MAX_FILES; i++) { 
    sprintf (pathname, "/file%d", i);
    
    retval = kunlink (pathname);
    
    if (retval < 0) {
      fprintf (stderr, "kunlink: File deletion error! status: %d\n", 
	       retval);
      
      exit (1);
    }
    
    memset (pathname, 0, 80);
  }

#endif // TEST1
  
#ifdef TEST2

  /* ****TEST 2: LARGEST file size**** */

  
  /* Generate one LARGEST file */
  retval = kcreat ("/bigfile");

  if (retval < 0) {
    fprintf (stderr, "kcreat: File creation error! status: %d\n", 
	     retval);

    exit (1);
  }

    printf("kcreat succesful\n");
    
  retval =  kopen ("/bigfile"); /* Open file to write to it */
  
  if (retval < 0) {
    fprintf (stderr, "kopen: File open error! status: %d\n", 
	     retval);

    exit (1);
  }

    printf("kopen succesful\n");
  fd = retval;			/* Assign valid fd */

  /* Try writing to all direct data blocks */
  retval = kwrite (fd, data1, sizeof(data1));
  
  if (retval < 0) {
    fprintf (stderr, "kwrite: File write STAGE1 error! status: %d\n", 
	     retval);

    exit (1);
  }

    printf("kwrite direct succesful\n");
#ifdef TEST_SINGLE_INDIRECT
  
  /* Try writing to all single-indirect data blocks */
  retval = kwrite (fd, data2, sizeof(data2));
    
  if (retval < 0) {
    fprintf (stderr, "kwrite: File write STAGE2 error! status: %d\n", 
	     retval);

    exit (1);
  }

    printf("kwrite 1 indirect succesful\n");
#ifdef TEST_DOUBLE_INDIRECT

  /* Try writing to all double-indirect data blocks */
  retval = kwrite (fd, data3, sizeof(data3));
  printf("kwrite 2 actually writes = %d, suppose to write = %ld\n", retval, sizeof(data3));
  if (retval < 0) {
    fprintf (stderr, "kwrite: File write STAGE3 error! status: %d\n", 
	     retval);

    exit (1);
  }
    
    printf("PASSED TEST2\n");

#endif // TEST_DOUBLE_INDIRECT

#endif // TEST_SINGLE_INDIRECT

#endif // TEST2

#ifdef TEST3

  /* ****TEST 3: Seek and Read file test**** */
  retval = klseek (fd, 0);	/* Go back to the beginning of your file */
  if (retval < 0) {
    fprintf (stderr, "klseek: File seek error! status: %d\n", 
	     retval);

    exit (1);
  }

  /* Try reading from all direct data blocks */
  retval = kread (fd, addr, sizeof(data1));
  
  if (retval < 0) {
    fprintf (stderr, "kread: File read STAGE1 error! status: %d\n", 
	     retval);

    exit (1);
  }
  /* Should be all 1s here... */
  printf ("Data at addr: %s\n", addr);
    
    printf("PASSED TEST3-Direct Block read\n");
    
#ifdef TEST_SINGLE_INDIRECT

  /* Try reading from all single-indirect data blocks */
  retval = kread (fd, addr, sizeof(data2));
  
  if (retval < 0) {
    fprintf (stderr, "kread: File read STAGE2 error! status: %d\n", 
	     retval);

    exit (1);
  }
  /* Should be all 2s here... */
  printf ("Data at addr: %s\n", addr);
    
    printf("PASSED TEST3-1 Redirect Block read\n");
#ifdef TEST_DOUBLE_INDIRECT

  /* Try reading from all double-indirect data blocks */
  retval = kread (fd, addr, sizeof(data3));
  
  if (retval < 0) {
    fprintf (stderr, "kread: File read STAGE3 error! status: %d\n", 
	     retval);

    exit (1);
  }
  /* Should be all 3s here... */
  printf ("Data at addr: %s\n", addr);
printf("PASSED TEST3-2 Redirect Block read\n");
#endif // TEST_DOUBLE_INDIRECT

#endif // TEST_SINGLE_INDIRECT

  /* Close the bigfile */
  retval = kclose (fd);
  
  if (retval < 0) {
    fprintf (stderr, "kclose: File close error! status: %d\n", 
	     retval);

    exit (1);
  }

  /* Remove the biggest file */

  retval = kunlink ("/bigfile");
	
  if (retval < 0) {
    fprintf (stderr, "kunlink: /bigfile file deletion error! status: %d\n", 
	     retval);
    
    exit (1);
  }

#endif // TEST3

#ifdef TEST4
  
  /* ****TEST 4: Make directory and read directory entries**** */
  retval = kmkdir ("/dir1");
    
  if (retval < 0) {
    fprintf (stderr, "kmkdir: Directory 1 creation error! status: %d\n", 
	     retval);

    exit (1);
  }

  retval = kmkdir ("/dir1/dir2");
    
  if (retval < 0) {
    fprintf (stderr, "kmkdir: Directory 2 creation error! status: %d\n", 
	     retval);

    exit (1);
  }

  retval = kmkdir ("/dir1/dir3");
    
  if (retval < 0) {
    fprintf (stderr, "kmkdir: Directory 3 creation error! status: %d\n", 
	     retval);

    exit (1);
  }

  retval =  kopen ("/dir1"); /* Open directory file to read its entries */
  
  if (retval < 0) {
    fprintf (stderr, "kopen: Directory open error! status: %d\n", 
	     retval);

    exit (1);
  }

  fd = retval;			/* Assign valid fd */

  memset (addr, 0, sizeof(addr)); /* Clear scratchpad memory */

  while ((retval = kreaddir (fd, addr))) { /* 0 indicates end-of-file */

    if (retval < 0) {
      fprintf (stderr, "kreaddir: Directory read error! status: %d\n", 
	       retval);
      
      exit (1);
    }
      /*
      printf("user\n");
      int zz = 0;
      for (zz; zz < 16; zz++) {
          printf("%d ", *((unsigned char *)addr + zz));
      }
      printf("\n");
       */
    index_node_number = atoi(&addr[14]);
    printf ("Contents at addr: [%s,%d]\n", addr, index_node_number);
  }

#endif // TEST4

#ifdef TEST5

  /* ****TEST 5: 2 process test**** */
  
  if((retval = fork())) {

    if(retval == -1) {
      fprintf(stderr, "Failed to fork\n");
      
      exit(1);
    }

    /* Generate 300 regular files */
    for (i = 0; i < 300; i++) { 
      sprintf (pathname, "/file_p_%d", i);
      
      retval = kcreat (pathname);
      
      if (retval < 0) {
	fprintf (stderr, "(Parent) kcreate: File creation error! status: %d\n", 
		 retval);

	exit(1);
      }
    
      memset (pathname, 0, 80);
    }
    
  }
  else {
    /* Generate 300 regular files */
    for (i = 0; i < 300; i++) { 
      sprintf (pathname, "/file_c_%d", i);
      
      retval = kcreat (pathname);
      
      if (retval < 0) {
	fprintf (stderr, "(Child) kcreate: File creation error! status: %d\n", 
		 retval);

	exit(1);
      }
    
      memset (pathname, 0, 80);
    }
  }

#endif // TEST5


  fprintf(stdout, "Congratulations,  you have passed all tests!!\n");

  return 0;
}
예제 #29
0
파일: myfs.c 프로젝트: anxolerd/myfs
// RUN:
int main(int argc, char *argv[]) { 
  init_fs();
  return fuse_main(argc, argv, &myfs2_oper, NULL);
}
예제 #30
0
/**
 * Main request handling loop
 *
 * @return 0 on success, err code on failure
 */
int go(void) {
    int i;
    int res;
    uint32_t tmp = 0;
    uint32_t *seed;
    char *resend;
    size_t tosend;
    size_t offset;
    uint32_t *f;

    init_fs();
    debug("fs init complete\n");

    if (!READDATATIMEOUT(conf)) {
        debug("failed to recv conf\n");
        res = 0;
        SENDDATA(res);
        return 3;
    }

    if (conf.min_ver > VERSION || conf.max_ver < VERSION) {
        debug("version mismatch\n");
        res = 0;
        SENDDATA(res);
        return 5;
    }
    //send success ack
    res = 1;
    SENDDATA(res);

    //seed our PRNG
    //because of how it works, seeding with 0's == no encryption
    seed = (uint32_t*)(FLAG_PAGE + (8*sizeof(uint32_t)));

    f = malloc(8*sizeof(uint32_t));

    if (!f)
        return 1;

    cgc_memcpy(f, seed, 8*sizeof(uint32_t));

    if (!conf.encrypt)
        seed = calloc(8*sizeof(uint32_t));

    srand(seed);

    //inform client of seed
    for (i = 0; i < 8; i+=2) {
        if (conf.encrypt)
            tmp = f[i]^f[i+1];
        SENDDATA(tmp);
    }

#ifdef PATCHED_1
    cgc_memset(f, '\0', 8*sizeof(uint32_t));
#endif
    debug("flag data: @h\n",f);

    free(f);


    while (1) {
        res = process_req();
        if (res == ERR || res == EXIT) {
            break;
        } else if (res == DISCON && conf.allow_reconnect && last) {
            debug("disconnected, retrying\n");
            if (!READDATATIMEOUT(conf)) {
                debug("failed to recv conf\n");
                return 3;
            }

            if (!last)
                continue;

            debug("Allocating resend buffer of @h bytes.\n",conf.buf_size+sizeof(resp_t));
#ifdef PATCHED_1
            resend = calloc(conf.buf_size+sizeof(resp_t));
#else
            resend = malloc(conf.buf_size+sizeof(resp_t));
#endif
            debug("resend data: @h\n",resend);

            if (!READDATA(offset)) {
                debug("failed to recv offset\n");
                return 4;
            }

            tosend = sizeof(resp_t)-offset;
            tosend = tosend > sizeof(resp_t) ? sizeof(resp_t) : tosend;

            if (offset > conf.buf_size || offset > sizeof(resp_t)
#ifdef PATCHED_1
                    || tosend > (conf.buf_size+sizeof(resp_t))
#endif
               ) {
                debug("failed to validate offset.\n");
                return 1;
            } else {
                debug("copying last out\n");
                cgc_memcpy(resend, last+offset, sizeof(resp_t)-offset);
            }

#ifdef PATCHED_1
            if (tosend != esendall(stdout, resend, tosend))
#else
            if (tosend != esendall(stdout, resend, sizeof(resp_t)))
#endif
                return 4;
            debug("Resent all, should be back!\n");

            free(resend);
            free(last);
            last = NULL;
        }
    }
    return 0;
}