Exemple #1
0
int io_close_file(void *address)
{
  int rc;
  l4dm_dataspace_t ds;
  l4_addr_t addr;
  l4_size_t size;
  l4_offs_t offset;
  l4_threadid_t pager;
  
  rc = l4rm_lookup_region(address, &addr, &size, &ds,
                          &offset, &pager);

  if (rc < 0)
    return -rc;

  if (rc == L4RM_REGION_DATASPACE)
  {  
    l4rm_detach(addr);
    l4dm_close(&ds);
  }

  return 0;
}
Exemple #2
0
static void get_fb(void)
{
  l4_addr_t fpage_addr;
  l4_size_t fpage_size;
  l4dm_dataspace_t ds;
  CORBA_Environment env = dice_default_environment;
  int i, pages, error;
  struct stat st;

  /* check if we're running under L4Linux */
  if (stat("/proc/l4", &st) == -1) {
    fprintf(stderr, "Error: /proc/l4 doesn't exist, not running on L4Linux?!\n");
    exit(1);
  }

  /* ask for 'con' (timeout = 5000 ms) */
  if (names_waitfor_name(CON_NAMES_STR, &con_l4id, 5000) == 0) {
    fprintf(stderr, "PANIC: %s not registered at names", CON_NAMES_STR);
    exit(1);
  }
  INFO("Found my console through names, it's at "l4util_idfmt".\n",
       l4util_idstr(con_l4id));

  PRINT("Screenshot'ing, please smile... ;-)\n");
  /* get screenshot */
  if (con_if_screenshot_call(&con_l4id, get_vc, &ds, 
			&xres, &yres, &bpp, &env)) {
    fprintf(stderr, "Could not get screenshot\n");
    exit(1);
  }
  INFO("Got screenshot: res: %dx%d, bpp: %d\n", xres, yres, bpp);

  if (l4dm_mem_size(&ds, &fb_size)) {
    fprintf(stderr, "Couldn't get size of data space\n");
    exit(1);
  }
  INFO("Size of data space: %d\n", fb_size);

  if ((fb_mem = malloc(fb_size)) == NULL) {
    fprintf(stderr, "Couldn't malloc %d Bytes of memory!\n", fb_size);
    exit(1);
  }
  raw_pic_size = xres*yres*3;
  if ((raw_pic_mem = malloc(raw_pic_size)) == NULL) {
    fprintf(stderr, "Couldn't malloc %d bytes of memory!\n", raw_pic_size);
    exit(1);
  }
  
  pages = fb_size / L4_PAGESIZE; // size is always a multiple of L4_PAGESIZE?
  for (i = 0; i < pages; i++) {
    /* unmap memory */
    l4_fpage_unmap(l4_fpage((l4_umword_t)map_page, L4_LOG2_PAGESIZE,
	  	   L4_FPAGE_RW, L4_MAP_ITEM_MAP),
                   L4_FP_FLUSH_PAGE|L4_FP_ALL_SPACES);

    /* page in L4 page */
    if ((error = l4dm_map_pages(&ds, i*L4_PAGESIZE, L4_PAGESIZE,
			        (l4_addr_t)map_page, L4_LOG2_PAGESIZE,
				0, L4DM_RO, &fpage_addr,&fpage_size)) < 0) {
      fprintf(stderr, "Error %d requesting ds %d at ds_manager "
	      l4util_idfmt"\n",
	  error, ds.id, l4util_idstr(ds.manager));
      l4dm_close(&ds);
      exit(error);
    }

    memcpy(fb_mem + i*L4_PAGESIZE, map_page, L4_PAGESIZE);
  }

  if (l4dm_close(&ds)) {
    fprintf(stderr, "Error on closing dataspace, expect memory leakage...\n");
  }
}
Exemple #3
0
unsigned int find_path(const char *name, char *full_path_name)
{
  CORBA_Environment env = dice_default_environment;
  l4dm_dataspace_t ds;
  l4_size_t size;
  int  rc;

  //FILE *f;
  char *p;
  #define buf_size 4096
  char buf[buf_size+1];
  char *path = (char *) &buf;
  STR_SAVED_TOKENS st;
  char * p_buf = full_path_name;
  char *sep="\\";
  char *psep=";";

  /* query default dataspace manager id */
  if (l4_is_invalid_id(dsm))
    dsm = l4env_get_default_dsm();

  if (l4_is_invalid_id(dsm))
  {
    LOG("No dataspace manager found\n");
    return 2;
  }

  LOG("name=%s", name);
  LOG("full_path_name=%s", full_path_name);

  cfg_Getenv("PATH", &path);
  LOG("PATH: %s", path);

  p = path - 1;

  StrTokSave(&st);
  LOG("0");
  if((p = StrTokenize((char*)path, psep)) != 0) do if(*p)
  {
    LOG("1");
    p_buf = full_path_name;
    p_buf[0] = 0;
    LOG(p);
    if (!strcmp(p,"."))
    {
      strcat(p_buf, options.bootdrive);
      strcat(p_buf, "\\"); // For OS2Server current directory is always root
    } else {
      strcat(p_buf, p);
      strcat(p_buf, sep);
    }
    strcat(p_buf, name);
    LOG("2");
    LOG("p_buf=%s", p_buf);
    //f = fopen(os2_fname_to_vfs_fname(p_buf), "rb"); /* Tries to open the file, if it works f is a valid pointer.*/
    //if(f)
    /* try opening a file from a file provider */
    LOG("call fprov");
    LOG("fs: %x.%x", fs.id.task, fs.id.lthread);
    rc = l4fprov_file_open_call(&fs, p_buf, &dsm, 0,
                       &ds, &size, &env);
    LOG("called, rc=%d", rc);
    LOG("3");
    if(!rc)
    {
      LOG("30");
      l4dm_close(&ds);
      LOG("31");
      StrTokStop();
      LOG("32");
      return 0; /* NO_ERROR */
    }
    LOG("4");
  } while((p = StrTokenize(0, psep)) != 0);
  StrTokRestore(&st);

  LOG("5");
  return 2/*ERROR_FILE_NOT_FOUND*/;
}
Exemple #4
0
unsigned int find_module_path(const char * name, char * full_path_name)
{
  CORBA_Environment env = dice_default_environment;
  l4dm_dataspace_t ds;
  l4_size_t size;
  int  rc;

  /* query default dataspace manager id */
  if (l4_is_invalid_id(dsm))
    dsm = l4env_get_default_dsm();

  if (l4_is_invalid_id(dsm))
  {
    LOG("No dataspace manager found\n");
    return 2;
  }
  //FILE *f;
  char *p = options.libpath - 1;
  STR_SAVED_TOKENS st;
  char * p_buf = full_path_name;
  char *sep="\\";
#ifdef __LINUX__
  char *hostsep="/";
#else
  char *hostsep="\\";
#endif
  char *psep=";";

  StrTokSave(&st);
  if((p = StrTokenize((char*)options.libpath, psep)) != 0)
  do if(*p)
  {
    int B_LEN = 250;
    char buf[251];
    char *str_buf=(char*) &buf;
    char buf2[251];
    char * file_to_find=(char*) &buf2;
    long i=0;

    p_buf = full_path_name;
    p_buf[0] = '\0';
    while (p[i]!='\0')
    {
      if (p[i]=='\\') p[i]=*hostsep; ++i;
    }

    strcat(p_buf, p);
    if (p[strlen(p)-1]!=*hostsep)
    {
      strcat(p_buf, hostsep);
    }

    strcat(p_buf, name);

    buf[0] = '\0';
    buf2[0] = '\0';
    strcat(file_to_find, name);
    #ifndef L4API_l4v2
      if(find_case_file(file_to_find, p, str_buf, B_LEN))
      {
        p_buf[0] = 0;
        strcat(p_buf, p);
        strcat(p_buf, hostsep);
        strcat(p_buf, str_buf); /* Case corrected for file, Needed on Linux. */
      }
    #endif

    LOG(p_buf);
    //LOG(os2_fname_to_vfs_fname(p_buf));

    //f = fopen(os2_fname_to_vfs_fname(p_buf), "rb"); /* Tries to open the file, if it works f is a valid pointer.*/
    /* try opening a file from a file provider */
    rc = l4fprov_file_open_call(&fs, p_buf, &dsm, 0,
                       &ds, &size, &env);
    
    if(!rc)
    {
      l4dm_close(&ds);
      StrTokStop();
      return 0; /* NO_ERROR */
    }
  } while((p = StrTokenize(0, psep)) != 0);
  StrTokRestore(&st);

  return 2 /*ERROR_FILE_NOT_FOUND*/;
}
Exemple #5
0
long DICE_CV
l4fprov_file_open_component (CORBA_Object _dice_corba_obj,
                      const char* fname /* in */,
                      const l4_threadid_t *dm /* in */,
                      unsigned long flags /* in */,
                      l4dm_dataspace_t *ds /* out */,
                      l4_size_t *size /* out */,
                      CORBA_Server_Environment *_dice_corba_env)
{
  struct stat stat;
  l4_addr_t addr;
  char *newfilename;
  int  handle;
  int  rc;

  /* convert OS/2 path to PN path */
  if (pathconv(&newfilename, fname))
   return 2; /* ERROR_FILE_NOT_FOUND */

  handle = open(newfilename, O_RDONLY);

  if(handle == -1)
      return 2; /* ERROR_FILE_NOT_FOUND */

  LOG("file opened");
  
  rc = fstat(handle, &stat);

  /* get length */
  *size = stat.st_size;

  /* Create a dataspace of a given size */
  rc = l4dm_mem_open(*dm, *size, 0, L4DM_RW, "fprov dataspace", ds);

  if (rc < 0)
    return 8; /* ERROR_NOT_ENOUGH_MEMORY */

  /* attach the created dataspace to our address space */
  rc = l4rm_attach(ds, *size, 0, L4DM_RW, (void **)&addr);

  if (rc < 0)
    return 8; /* What to return? */

  read(handle, addr, *size);

  close(handle);

  l4rm_detach(addr);

  LOG("caller=%x.%x", _dice_corba_obj->id.task, _dice_corba_obj->id.lthread);  
  rc = l4dm_transfer(ds, *_dice_corba_obj);

  if (rc < 0)
  {
    LOG("error transferring ds");
    l4dm_close(ds);
    return 5; /* ERROR_ACCESS_DENIED */
  }

  LOG("successful return");

  return 0; /*NO_ERROR;*/
}