Esempio n. 1
0
int main(int argc, char * argv[])
{
	fc_file_t * file = NULL;

	if(argc < 4){
		usage();
		return -1;
	}
	FILE* from = NULL;
	
	if(initlib(argv[1])<0){
		perror("initlib error\n");
		return -1;
	}

	file = fc_open(argv[3], SCSI_FILE_OPEN_WRITE,0);
	if(file == NULL){
		perror("cannot open file");
		return -1;
	}

	from = open(argv[2],O_RDONLY);

	if(from <0){
		perror("open localfile to read error");
	}
	
	char buff[256*1024];
	int writesize=0;
	int read_size=0;
	
	lseek(from,0,SEEK_SET);
	read_size=read(from, buff, sizeof(buff));
	while(read_size>0){
		writesize = fc_write(file, buff, read_size);
		if(writesize <=0){
			fprintf(stderr,"fc_write writesize=%d \n",writesize);
			break;
		}
	read_size=read(from, buff, sizeof(buff));
	}
	
	print_fc_file(file);
	close(from);

	return fc_close(file);
}
Esempio n. 2
0
int
setup_inouterr(struct fd_table *fdt)
{
    int err;
    struct vnode *v_stdin, *v_stdout, *v_stderr;
    struct file_ctxt *fc_stdin, *fc_stdout, *fc_stderr;
    
    char path[5];
    strcpy(path, "con:");
    
    // open console vnode three times
    // we have to reset the path every time because
    // vfs_open() messes with the contents of the string
    if ((err = vfs_open(path, O_RDONLY, 0, &v_stdin)))
    {
        return err;
    }
    strcpy(path, "con:");
    if ((err = vfs_open(path, O_WRONLY, 0, &v_stdout)))
    {
        vfs_close(v_stdin);
        return err;
    }
    strcpy(path, "con:");
    if ((err = vfs_open(path, O_WRONLY, 0, &v_stderr)))
    {
        vfs_close(v_stdin);
        vfs_close(v_stdout);
        return err;
    }
    
    // create file contexts
    if((fc_stdin = fc_create(v_stdin)) == NULL)
    {
        vfs_close(v_stdin);
        vfs_close(v_stdout);
        vfs_close(v_stderr);
        return ENOMEM;
    }
    if ((fc_stdout = fc_create(v_stdout)) == NULL)
    {
        fc_close(fc_stdin);
        vfs_close(v_stdout);
        vfs_close(v_stderr);
        return ENOMEM;
    }
    if ((fc_stderr = fc_create(v_stderr)) == NULL)
    {
        fc_close(fc_stdin);
        fc_close(fc_stdout);
        vfs_close(v_stderr);
        return ENOMEM;
    }
    
    // Insert file contexts
    fdt_replace(fdt, STDIN_FILENO, fc_stdin);
    fdt_replace(fdt, STDOUT_FILENO, fc_stdout);
    fdt_replace(fdt, STDERR_FILENO, fc_stderr);
    
    return 0;
}