Beispiel #1
0
static void cmd_get_function_info(int fd, int fid, int pid, int sock) {
	struct mapiipcbuf buf;
	mapidrv *drv = get_drv(fd);
	mapid_funct_info_t *info;
	mapi_function_info_t i;

	mapidrv_get_flow_functions = get_drv_funct(drv->handle,
			"mapidrv_get_flow_functions");
	info = mapidrv_get_flow_functions(drv->devid, fd);

	//Find correct function
	while (info != NULL)
		if (info->fid != fid)
			info = info->next;
		else
			break;

	if (info != NULL) {
		i.fid = fid;
		strncpy(i.name, info->name, MAPI_STR_LENGTH);
		strncpy(i.libname, info->libname, MAPI_STR_LENGTH);
		strncpy(i.devtype, info->devtype, MAPI_STR_LENGTH);
		i.pkts = *info->pkts;
		i.passed_pkts = *info->passed_pkts;
		memcpy(buf.data, &i, sizeof(mapi_function_info_t));
		buf.cmd = GET_FUNCTION_INFO_ACK;
	} else
		buf.cmd = GET_FUNCTION_INFO_NACK;

	buf.mtype = pid;
	buf.fd = fd;
	mapiipc_daemon_write(&buf, sock);
}
Beispiel #2
0
/* Get error from mapidlib */
static int mapid_get_errno(int fd) {
	mapidrv *drv;
	drv = get_drv(fd);
	if (drv == NULL)
		return MAPI_INVALID_FLOW;
	mapidrv_get_errno = get_drv_funct(drv->handle, "mapidrv_get_errno");
	return mapidrv_get_errno(drv->devid, fd);
}
Beispiel #3
0
/* OBS! For fsrouter to work it must be initialized from globals.c:init_globals() */
int io_load_file33(const char * filename, void ** addr, unsigned long * size) {

  static l4_threadid_t        fs_drvc_id;
  l4_threadid_t        dm_id;
  l4dm_dataspace_t     ds;
  CORBA_Environment   _env = dice_default_environment;
  char drv = get_drv(filename);

  if(drv == '\0') {
    //io_printf("io.c Warning, no drive in filename, assume c: for now.\n");
    drv = 'c';
  }
  /* How to find the working directory? From this thread ( l4thread_myself() ) find the thread's 
     process (our own prcess structure) and lookup the working directory there.
     L4 has a task- and thread number, as seen in output by [x.y] */
  
  struct I_Fs_srv *target_fs_srv = FSRouter_route(&fsrouter, drv );
  //io_printf("io_load_file: '%s'\n", filename);
  
  if(target_fs_srv) {
      if (!names_waitfor_name(target_fs_srv->server, &fs_drvc_id, 10000))
      {
        io_printf("File provider %s doesn't answer\n", target_fs_srv->mountpoint);
        return 2;
      };

      dm_id = l4env_get_default_dsm();

     if (l4_is_invalid_id(dm_id))
      {
        io_printf("Bad dataspace!\n");
        return 1;
      }
      int f_status = l4fprov_file_open_call(&fs_drvc_id,
                           filename, /* OBS! Ta bort enheten från sökvägen! */
                           &dm_id,
                           0, &ds, size, &_env);
      if(f_status)
        return 2;
      f_status=l4rm_attach(&ds, *size, 0,
                  L4DM_RO | L4RM_MAP, addr);
      if(f_status)
      {
        io_printf("error %s\n", l4env_errstr(f_status));
        return 2;
      }
      //io_printf("io_load_file(: '%s', 0x%x, %d )\n", filename, *addr, *size);
      return 0;
  } else {
    io_printf("target_fs_srv: 0x%x\n", target_fs_srv);
    return 2; /* ERROR_FILE_NOT_FOUND; */
  }
Beispiel #4
0
static void cmd_get_next_function_info(int fd, int fid, int pid, int sock) {
	struct mapiipcbuf buf;
	mapidrv *drv = get_drv(fd);
	mapid_funct_info_t *info, *in;
	mapi_function_info_t i;

	if (drv != NULL)
		mapidrv_get_flow_functions = get_drv_funct(drv->handle,
				"mapidrv_get_flow_functions");
	else {
		buf.remote_errorcode=MAPID_NO_DRIVER;
		buf.cmd = GET_FUNCTION_INFO_NACK;
		buf.mtype = pid;
		buf.fd = fd;
		mapiipc_daemon_write(&buf, sock);
		return;
	}
	in = mapidrv_get_flow_functions(drv->devid, fd);
	info = NULL;

	//Find correct function
	while (in != NULL) {
		if (in->fid > fid)
			if (info == NULL || info->fid > in->fid)
				info = in;
		in = in->next;
	}

	if (info != NULL) {
		i.fid = info->fid;
		strncpy(i.name, info->name, MAPI_STR_LENGTH);
		strncpy(i.libname, info->libname, MAPI_STR_LENGTH);
		strncpy(i.devtype, info->devtype, MAPI_STR_LENGTH);
		i.pkts = *info->pkts;
		i.passed_pkts = *info->passed_pkts;
		memcpy(buf.data, &i, sizeof(mapi_function_info_t));
		buf.cmd = GET_FUNCTION_INFO_ACK;
	} else
		buf.cmd = GET_FUNCTION_INFO_NACK;

	buf.mtype = pid;
	buf.fd = fd;
	mapiipc_daemon_write(&buf, sock);
}
Beispiel #5
0
static void cmd_read_results(int fd, int fid, int pid, int sock)
//Read results from a function
//fd = flow descriptor
//fid = function ID
{
	mapidrv *drv = get_drv(fd);
	mapid_result_t *result;
	struct mapiipcbuf buf;
	int err;
	char *p = (char *)buf.data;

	if (drv == NULL) {
		/* driver not found(should be handled in create_flow), or invalid flow id */
		DEBUG_CMD(Debug_Message("cmd_read_results: no driver found"));
		report_error(MAPI_INVALID_FLOW, pid, sock);
		return;
	}
	mapidrv_read_results = get_drv_funct(drv->handle, "mapidrv_read_results");
	err = mapidrv_read_results(drv->devid, fd, fid, &result);
	if (err != 0) {
		report_error(err, pid, sock);
		return;
	}
	buf.mtype = get_id(fd);
	buf.cmd = READ_RESULT_ACK;
	buf.fd = fd;

	//Copy result data 
	if (result->funct_res_size + 2*sizeof(mapid_shm_t) < DATA_SIZE) {
		memcpy(p, &result->shm, sizeof(mapid_shm_t));
		p += sizeof (result->shm);
		memcpy(p, &result->shm_spinlock, sizeof(mapid_shm_t));
		if (result->funct_res_size > 0) {
			p += sizeof (result->shm);
			memcpy(p, result->funct_res, result->funct_res_size);
		}
		buf.size = result->funct_res_size + 2*sizeof(mapid_shm_t);
	} else {
		//TODO: Return proper error message
	}

	mapiipc_daemon_write(&buf, sock);

}
Beispiel #6
0
static void cmd_connect(int fd, int pid, int sock)
//Connect to flow
//fd = flow descriptor
{
	struct mapiipcbuf buf;
	int err = 0;
	mapidrv *drv = get_drv(fd);
	long file_size;

	if (drv == NULL) {
		/* driver not found(should be handled in create_flow), or invalid flow id */
		DEBUG_CMD(Debug_Message("cmd_connect: no driver found"));
		report_error(MAPI_INVALID_FLOW, pid, sock);
		return;
	}

	if (err == 0) {
		mapidrv_connect = get_drv_funct(drv->handle, "mapidrv_connect");
		err = mapidrv_connect(drv->devid, fd);
	}
	if (err != 0) {
		report_error(err, pid, sock);
		return;
	}

	buf.cmd = CONNECT_ACK;
	buf.mtype = get_id(fd); /* should be == pid */
	buf.fd = fd;

	if (log_to_file) {
		file_size = acquire_write_lock(log_fd_info);
		write_to_file(log_fd_info, "MAPID: connect to flow %d at ", fd);
		write_date(log_fd_info);
		write_newline(log_fd_info, "\n");
		release_write_lock(log_fd_info, file_size);
	}
	if (log_to_syslog)
		log_message("connect to flow %d", fd);

	mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock);
}
Beispiel #7
0
static void cmd_get_flow_info(int fd, int pid, int sock) {
	mapi_flow_info_t info;
	struct mapiipcbuf buf;
	struct flow *f;
	mapidrv *drv = get_drv(fd);

	f=(struct flow*)flist_get(flowlist, fd);

	mapidrv_get_flow_info = get_drv_funct(drv->handle, "mapidrv_get_flow_info");
	mapidrv_get_flow_info(drv->devid, fd, &info);
	info.uid = f->uid;
	info.devid = drv->devid;
	strcpy(info.device, f->drv->device);

	memcpy(buf.data, &info, sizeof(mapi_flow_info_t));

	buf.mtype = pid;
	buf.fd = fd;
	buf.cmd = GET_FLOW_INFO_ACK;
	mapiipc_daemon_write(&buf, sock);
}
Beispiel #8
0
char * os2_fname_to_vfs_fname(const char *filename) 
{
  char * newfilename;
  char * newdirectory;
  struct dirent *diren;

  char drv = get_drv(filename);

  if(drv == '\0') 
  {
    return NULL; 
  }

  char * directory = get_directory(filename);
  if (directory==NULL)
  {
    return NULL;
  }
  char * name = get_name(filename);

  DosNameConversion(directory);
  DosNameConversion(name);

  struct I_Fs_srv *target_fs_srv = FSRouter_route(&fsrouter, drv);

  newfilename=malloc(strlen(target_fs_srv->mountpoint)+
                     strlen(directory)+
                     strlen(name)+1);
  newdirectory=malloc(strlen(target_fs_srv->mountpoint)+
                     strlen(directory)+1);
  strcpy(newdirectory, target_fs_srv->mountpoint);
  newdirectory=strcat(newdirectory, directory);
  strcpy(newfilename, newdirectory);
  newfilename=strcat(newfilename, name);

  return newfilename;
}
Beispiel #9
0
int io_load_file(const char * filename, void ** addr, unsigned long * size)
{
  char ch;
  FILE *f=0;
  char * newfilename;
  char * newdirectory;
  struct dirent *diren;
  char buf[256];
  int  len, i;

  LOG("filename=%s", filename);
  char drv = get_drv(filename);

  LOG("drv=%c:", drv);

  if(drv == '\0') 
  {
    return 2; /* ERROR_FILE_NOT_FOUND */
  }

  char * directory = get_directory(filename);
  LOG("directory=%s", directory);
  if (directory==NULL)
  {
    return 2; /* ERROR_FILE_NOT_FOUND */
  }
  char * name = get_name(filename);
  LOG("name=%s", name);

  DosNameConversion(directory);
  DosNameConversion(name);

  LOG("directory=%s", directory);
  LOG("name=%s", name);
#if 0
  LOG("srv_num_=%d", fsrouter.srv_num_);
  for(i=0; i< fsrouter.srv_num_; i++)
  {
    I_Fs_srv_t *srv = fsrouter.fs_srv_arr_[i];
    if (srv)
    {
      LOG("srv->drive=%s, srv->mountpoint=%s", srv->drive, srv->mountpoint);
    }
  }    
#endif
  struct I_Fs_srv *target_fs_srv = FSRouter_route(&fsrouter, drv);

  LOG("-1");
  newfilename=malloc(strlen(target_fs_srv->mountpoint)+
                     strlen(directory)+
                     strlen(name)+1);
  LOG("0");
  newdirectory=malloc(strlen(target_fs_srv->mountpoint)+
                     strlen(directory)+1);
  LOG("1");
  strcpy(newdirectory, target_fs_srv->mountpoint);
  newdirectory=strcat(newdirectory, directory);
  strcpy(newfilename, newdirectory);
  newfilename=strcat(newfilename, name);
  LOG("2");

//  LOG("%s => %s", filename, newfilename);

  //if (newdirectory[strlen(newdirectory) - 1] == '/')
  //  newdirectory[strlen(newdirectory) - 1] = '\0';

  //LOG("%s", newdirectory); // If I remove this then next line return NULL. Why?
  //enter_kdebug("stop"); // break into debugger
  DIR *dir = opendir(newdirectory);
  LOG("3");

  if (dir==NULL)
  {
    LOG("Error opening directory");
    return 2; /* ERROR_FILE_NOT_FOUND */
  }
  else
    LOG("opendir() successful");


  LOG("name=%s", name);
  while(diren = readdir(dir)) 
  {
        len = strlen(name);
        strncpy(buf, diren->d_name, len);
	buf[len] = '\0';
        LOG("diren->d_name=%s", diren->d_name);
	LOG("buf=%s", buf);
        if(!diren)
            break;
        if(strcasecmp(buf, name)==0) {
            break;
        }
  }
  
  if (!diren)
  {
    LOG("diren=0");
    closedir(dir);
    return 2;
  }
 
  //LOG("directory read");
  //LOG("newdirectory=%s", newdirectory);
  //LOG("diren->d_name=%s", diren->d_name);
  strcpy(newfilename, newdirectory);
  newfilename=strcat(newfilename, buf);

  closedir(dir);

  //LOG("newfilename=%s", newfilename);
  f = fopen(newfilename, "rb");
  LOG("file opened");
  if(f) {
     fseek(f, 0, SEEK_END);
     *size = ftell(f);  /* Extract the size of the file and reads it into a buffer.*/
     rewind(f);
     *addr = (void *)malloc(*size+1);
     fread(*addr, *size, 1, f);
     fclose(f);
     LOG("successful return");
     return 0; /*NO_ERROR;*/
  }

  return 2; /* ERROR_FILE_NOT_FOUND; */
}
Beispiel #10
0
static void cmd_apply_function(struct mapiipcbuf *qbuf, int pid, int sock)
//Apply function to flow
//qbuf = IPC buffer
//(this function should be changed so that it becomes IPC independent)
{
	int functionid;
	int fd;
	mapidrv *drv;
	mapiFunctArg *args = qbuf->data;
	char *argdescr = (char *)qbuf->argdescr;
	char *function;
	long file_size;

	while (strlen(argdescr) > 0) {
		switch (*argdescr) {
		case 's':
			args += strlen((char *)args) + 1;
			break;
		case 'S': // reference to flows and functions (e.g RES2FILE)
			args += strlen((char *)args) + 1;
			break;
		case 'i':
			args += sizeof(int);
			break;
		case 'r': // reference to a flow
			args += sizeof(int);
			break;
		case 'f': // reference to a fuction
			args += sizeof(int);
			break;
		case 'c':
			args += sizeof(char);
			break;
		case 'l':
			args += sizeof(unsigned long long);
			break;
		case 'u':
			args += sizeof(int);
			break;
		case 'p':
			args += strlen((char *)args) + 1;
			break;
		case 'w':
			qbuf->mtype = get_id(qbuf->fd);
			qbuf->cmd = SEND_FD;
			mapiipc_daemon_write((struct mapiipcbuf *) qbuf, sock);
			fd = mapiipc_read_fd(sock);
			addarg(&args, &fd, INT);
			break;

		default:
			break;
		}
		argdescr++; // move to the next arg
	}

	drv = get_drv(qbuf->fd);
	if (drv == NULL) {
		DEBUG_CMD(Debug_Message(
				"cmd_apply_function: no driver found for fd=%d", qbuf->fd));
		report_error(MAPI_INVALID_FLOW, pid, sock);
		return;
	}
	mapidrv_apply_function = get_drv_funct(drv->handle,
			"mapidrv_apply_function");

	function = strdup(qbuf->function);

	functionid = mapidrv_apply_function(drv->devid, qbuf->fd, APPLY_NORMAL,
			qbuf->function, qbuf->data);

	if (functionid == -1) {
		/* error in mapid */
		report_error(mapid_get_errno(qbuf->fd), pid, sock);
		return;
	}
	qbuf->mtype = get_id(qbuf->fd);
	qbuf->cmd = APPLY_FUNCTION_ACK;
	qbuf->fid = functionid;

	if (log_to_file) {
		file_size = acquire_write_lock(log_fd_info);
		write_to_file(log_fd_info,
				"MAPID: function %s was applyed to flow %d ( fid: %d ) at ",
				function, qbuf->fd, qbuf->fid);
		write_date(log_fd_info);
		write_newline(log_fd_info, "\n");
		release_write_lock(log_fd_info, file_size);
	}
	if (log_to_syslog)
		log_message("function %s was applyed to flow %d ( fid: %d )", function,
				qbuf->fd, qbuf->fid);

	free(function);
	mapiipc_daemon_write((struct mapiipcbuf *) qbuf, sock);
}
Beispiel #11
0
int
pathconv(char **converted, char *fname)
{
  struct I_Fs_srv *fsrv;
  char drv;
  char *directory;
  char *name;
  char *newfilename;
  char *newdirectory;

  drv = tolower(get_drv(fname));
  LOG("drv=%c:", drv);

  if(drv == '\0') 
  {
    return 1;
  }

  directory = get_directory(fname);
  LOG("directory=%s", directory);
  
  if (directory==NULL)
  {
    return 1;
  }
  
  name = get_name(fname);
  LOG("name=%s", name);

  DosNameConversion(directory);
  DosNameConversion(name);

  LOG("directory=%s", directory);
  LOG("name=%s", name);
  
  if (drv >= 'c' && drv <= 'z')
  { 
    fsrv = FSRouter_route(&fsrouter, drv);

    newdirectory=malloc(strlen(fsrv->mountpoint)+
                          strlen(directory)+1);

    strcpy(newdirectory, fsrv->mountpoint);
    newdirectory=strcat(newdirectory, directory);
  }
  else
  {
    newdirectory = malloc(strlen(directory) + 1);
    strcpy(newdirectory, directory);
  }

  newfilename=malloc(strlen(newdirectory)+
                     strlen(name)+1);

  strcpy(newfilename, newdirectory);
  newfilename=strcat(newfilename, name);

  LOG("newfilename=%s", newfilename);
  *converted = newfilename;

  return 0;
}