Esempio n. 1
0
  error_t parse_opt (int key, char *arg, struct argp_state *state)
    {
      switch (key)
	{
	case 'f': use_file_io = 1; break;
	case 'b': block_size = atoi (arg); break;

	case ARGP_KEY_ARG:
	  if (! store)
	    {
	      error_t err;
	      file_t source = file_name_lookup (arg, O_READ, 0);
	      if (errno)
		error (2, errno, "%s", arg);
	      if (use_file_io)
		if (block_size)
		  {
		    struct stat stat;
		    err = io_stat (source, &stat);
		    if (! err)
		      {
			struct store_run run = {0, stat.st_size / block_size};
			err = _store_file_create (source, 0, block_size, &run, 1,
						  &store);
		      }
		  }
		else
		  err = store_file_create (source, 0, &store);
	      else
		err = store_create (source, 0, 0, &store);
	      if (err)
		error (3, err, "%s", arg);
	    }
	  else if (addr < 0)
	    addr = atoll (arg);
	  else
	    {
	      dump (addr, atoi (arg));
	      dumped = 1;
	      addr = -1;
	    }
	  break;

	case ARGP_KEY_END:
	  if (!store)
	    argp_usage (state);

	  if (addr >= 0)
	    dump (addr, -1);
	  else if (! dumped)
	    dump (0, -1);
	  break;

	case ARGP_KEY_NO_ARGS:
	default:
	  return ARGP_ERR_UNKNOWN;
	}
      return 0;
    }
Esempio n. 2
0
static int
_stat(struct request *r, char *path, struct stat *p_st)
{
	if (io_stat(path, p_st)) {
		char buf[MSG_SIZE];

		if (errno == ENOENT)
			return ENOENT;
		snprintf(buf, sizeof buf, "stat(%s) failed: %s", path,
							strerror(errno));
		_panic(r, buf);
	}
	return 0;
}
Esempio n. 3
0
// sglee int __stdcall WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
int main_jpg ()
{
	double corr_th = 0.95;

    double scalefactor_vec[7] = {1, 11, 21, 31, 61, 121, 251};
    double psnr_ref_vec[7] = {48.259735, 45.054540, 42.609611, 41.129973, 38.749041, 36.768027, 34.591238};
    //double wl_set[7][4] = {{0,7,2,7}, {0,7,2,6}, {0,6,1,6}, {0,6,2,5}, {0,5,1,5}, {0,5,0,5}, {0,3,0,5}};
    double wl_set[7][4] = {{0,10,10,10}, {0,7,2,6}, {0,6,1,6}, {0,6,2,5}, {0,5,1,5}, {0,5,0,5}, {0,3,0,5}};

    scalefactor = scalefactor_vec[0];
    f1 = wl_set[0][0];
    f2 = wl_set[0][1];
    f3 = wl_set[0][2];
    f4 = wl_set[0][3];

    printf ("SGLEE LOOP CMP LV: %d, WL: %d,%d,%d,%d \n", scalefactor, f1,f2,f3,f4);

    // Create a jpg from a bmp
	SaveJpgFile("image/lena_ref.bmp", "image/lena_ref.jpg");

	// Create a bmp from a jpg
	ConvertJpgFile("image/lena_ref.jpg", "image/lena_float.bmp");
	ConvertJpgFile_ac("image/lena_ref.jpg", "image/lena_fixed.bmp");

	vector<io_stat> s0m_corr(64, io_stat(16, 2));
	vector<io_stat> s1m_corr(64, io_stat(16, 2));
	vector<io_stat> s0a_corr(64, io_stat(16, 1));

	for (int i=0;i<64;i++) {
		s0m_corr[i].gen_stat(vec_y[i], corr_th);
		//s0m_corr[i].gen_stat(vec_y[i], corr_th);
		s1m_corr[i].gen_stat(vec_y2[i], corr_th);
		//s0a_corr[i].gen_stat(vec_y_s0a[i], vec_y_s0a[i], corr_th, corr_th);
	}

//	io_stat s0a_corr(32, 1, vec_s0a_lump, vec_s0a_lump, corr_th, corr_th);
//	io_stat s1m_corr(16, 2, vec_y_lump2, vec_coef1, corr_th, corr_th);
//	io_stat s1a_corr(32, 1, vec_s1a_lump, vec_s1a_lump, corr_th, corr_th);

	s0m_corr[0].print_io_stat();

    /*
    int m;
    double elem_pwr_sum[64];
    double elem_pwr_sum2[64];
    double elem_noise_sum[64];
    double elem_snr[64];

    for (m=0;m<64;m++) {
      elem_pwr_sum[m] = 0;
      elem_pwr_sum2[m] = 0;
      elem_noise_sum[m] = 0;
    }

    for (m=0;m<64*4096;m++) {
      elem_pwr_sum[m%64] += elem_pwr_y1[m]*elem_pwr_y1[m]+elem_pwr_cr1[m]*elem_pwr_cr1[m]+elem_pwr_cb1[m]*elem_pwr_cb1[m];
      elem_pwr_sum2[m%64] += elem_pwr_y2[m]*elem_pwr_y2[m]+elem_pwr_cr2[m]*elem_pwr_cr2[m]+elem_pwr_cb2[m]*elem_pwr_cb2[m];
      elem_noise_sum[m%64] += (elem_pwr_y1[m]-elem_pwr_y2[m])*(elem_pwr_y1[m]-elem_pwr_y2[m]) +
                             (elem_pwr_cr1[m]-elem_pwr_cr2[m])*(elem_pwr_cr1[m]-elem_pwr_cr2[m]) +
                             (elem_pwr_cb1[m]-elem_pwr_cb2[m])*(elem_pwr_cb1[m]-elem_pwr_cb2[m]);
    }

    for (m=0;m<64;m++) {
      elem_pwr_avg[m] = elem_pwr_sum[m]/(3*4096);
      elem_pwr_avg2[m] = elem_pwr_sum2[m]/(3*4096);
      elem_noise_avg[m] = elem_noise_sum[m]/(3*4096);
      printf ("SGLEE ELEM PWR: %f, ELEM PWR+NOISE: %f, ELEM NOISE: %f, SNR(dB): %f at IDX: %d \n", elem_pwr_avg[m], elem_pwr_avg2[m], elem_noise_avg[m], 10 * log10( 255.0*255.0 / elem_noise_avg[m]), m);
    }
    */

    comparebmp("image/lena_ref.bmp", "image/lena_float.bmp");
    comparebmp("image/lena_ref.bmp", "image/lena_fixed.bmp");

	return 0;
}// End WinMain(..)
Esempio n. 4
0
File: node.c Progetto: scolobb/nsmux
/*Initializes the port to the underlying filesystem for the root node*/
error_t node_init_root (node_t * node	/*the root node */
  )
{
  error_t err = 0;

  /*Acquire a lock for operations on the underlying filesystem */
  mutex_lock (&ulfs_lock);

  /*Open the port to the directory specified in `dir` */
  node->nn->port = file_name_lookup (dir, O_READ | O_DIRECTORY, 0);

  /*If the directory could not be opened */
  if (node->nn->port == MACH_PORT_NULL)
    {
      /*set the error code accordingly */
      err = errno;
      LOG_MSG ("node_init_root: Could not open the port for %s.", dir);

      /*release the lock and stop */
      mutex_unlock (&ulfs_lock);
      return err;
    }

  LOG_MSG ("node_init_root: Port for %s opened successfully.", dir);
  LOG_MSG ("\tPort: 0x%lX", (unsigned long) node->nn->port);

  /*Stat the root node */
  err = io_stat (node->nn->port, &node->nn_stat);
  if (err)
    {
      /*deallocate the port */
      PORT_DEALLOC (node->nn->port);

      LOG_MSG ("node_init_root: Could not stat the root node.");

      /*unlock the mutex and exit */
      mutex_unlock (&ulfs_lock);
      return err;
    }

  /*Set the path to the corresponding lnode to `dir` */
  node->nn->lnode->path = strdup (dir);
  if (!node->nn->lnode->path)
    {
      /*deallocate the port */
      PORT_DEALLOC (node->nn->port);

      /*unlock the mutex */
      mutex_unlock (&ulfs_lock);

      LOG_MSG ("node_init_root: Could not strdup the directory.");
      return ENOMEM;
    }

  /*The current position in dir */
  char *p = dir + strlen (dir);

  /*Go through the path from end to beginning */
  for (; p >= dir; --p)
    {
      /*If the current character is a '/' */
      if (*p == '/')
	{
	  /*If p is not the first character */
	  if (p > dir)
	    {
	      /*if this slash is escaped, skip it */
	      if (*(p - 1) == '\\')
		continue;
	    }

	  /*advance the pointer to the first character after the slash */
	  ++p;

	  /*stop */
	  break;
	}
    }

  LOG_MSG ("node_init_root: The name of root node is %s.", p);

  /*Set the name of the lnode to the last element in the path to dir */
  node->nn->lnode->name = strdup (p);
  /*If the name of the node could not be duplicated */
  if (!node->nn->lnode->name)
    {
      /*free the name of the path to the node and deallocate teh port */
      free (node->nn->lnode->path);
      PORT_DEALLOC (node->nn->port);

      /*unlock the mutex */
      mutex_unlock (&ulfs_lock);

      LOG_MSG ("node_init_root: Could not strdup the name of the root node.");
      return ENOMEM;
    }

  /*Compute the length of the name of the root node */
  node->nn->lnode->name_len = strlen (p);

  /*Release the lock for operations on the undelying filesystem */
  mutex_unlock (&ulfs_lock);

  /*Return the result of operations */
  return err;
}				/*node_init_root */
Esempio n. 5
0
int
main (int argc,
      char **argv)
{
    error_t err;
    mach_port_t bootstrap;
    struct stat st;
    pthread_t thread;

    pfinet_bucket = ports_create_bucket ();
    addrport_class = ports_create_class (clean_addrport, 0);
    socketport_class = ports_create_class (clean_socketport, 0);
    mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
                        &fsys_identity);

    /* Generic initialization */

    init_time ();
    ethernet_initialize ();
    err = pthread_create (&thread, NULL, net_bh_worker, NULL);
    if (!err)
        pthread_detach (thread);
    else
    {
        errno = err;
        perror ("pthread_create");
    }

    pthread_mutex_lock (&global_lock);

    prepare_current (1);		/* Set up to call into Linux initialization. */

    sk_init ();
#ifdef SLAB_SKB
    skb_init ();
#endif
    inet_proto_init (0);

    /* This initializes the Linux network device layer, including
       initializing each device on the `dev_base' list.  For us,
       that means just loopback_dev, which will get fully initialized now.
       After this, we can use `register_netdevice' for new interfaces.  */
    net_dev_init ();

    /* ifconfig lo up 127.0.0.1 netmask 0xff000000 */
    configure_device (&loopback_dev,
                      htonl (INADDR_LOOPBACK), htonl (IN_CLASSA_NET),
                      htonl (INADDR_NONE), htonl (INADDR_NONE));

    pthread_mutex_unlock (&global_lock);

    /* Parse options.  When successful, this configures the interfaces
       before returning; to do so, it will acquire the global_lock.
       (And when not successful, it never returns.)  */
    argp_parse (&pfinet_argp, argc, argv, 0,0,0);

    task_get_bootstrap_port (mach_task_self (), &bootstrap);

    pfinet_owner = pfinet_group = 0;

    if (bootstrap != MACH_PORT_NULL) {
        /* Create portclass to install on the bootstrap port. */
        if(pfinet_protid_portclasses[pfinet_bootstrap_portclass]
                != MACH_PORT_NULL)
            error(1, 0, "No portclass left to assign to bootstrap port");

#ifdef CONFIG_IPV6
        if (pfinet_bootstrap_portclass == PORTCLASS_INET6)
            pfinet_activate_ipv6 ();
#endif

        err = trivfs_add_protid_port_class (
                  &pfinet_protid_portclasses[pfinet_bootstrap_portclass]);
        if (err)
            error (1, 0, "error creating control port class");

        err = trivfs_add_control_port_class (
                  &pfinet_cntl_portclasses[pfinet_bootstrap_portclass]);
        if (err)
            error (1, 0, "error creating control port class");

        /* Talk to parent and link us in.  */
        err = trivfs_startup (bootstrap, 0,
                              pfinet_cntl_portclasses[pfinet_bootstrap_portclass],
                              pfinet_bucket,
                              pfinet_protid_portclasses[pfinet_bootstrap_portclass],
                              pfinet_bucket,
                              &pfinetctl);

        if (err)
            error (1, err, "contacting parent");

        /* Initialize status from underlying node.  */
        err = io_stat (pfinetctl->underlying, &st);
        if (! err)
        {
            pfinet_owner = st.st_uid;
            pfinet_group = st.st_gid;
        }
    }
    else { /* no bootstrap port. */
        int i;
        /* Check that at least one portclass has been bound,
           error out otherwise. */
        for (i = 0; i < ARRAY_SIZE (pfinet_protid_portclasses); i++)
            if (pfinet_protid_portclasses[i] != MACH_PORT_NULL)
                break;

        if (i == ARRAY_SIZE (pfinet_protid_portclasses))
            error (1, 0, "should be started as a translator.\n");
    }

    /* Ask init to tell us when the system is going down,
       so we can try to be friendly to our correspondents on the network.  */
    arrange_shutdown_notification ();

    /* Launch */
    ports_manage_port_operations_multithread (pfinet_bucket,
            pfinet_demuxer,
            30 * 1000, 2 * 60 * 1000, 0);
    return 0;
}