Exemplo n.º 1
0
int
check_big_enough(long long required_space)
{
    PedDevice *dev = NULL;
    ped_exception_fetch_all();
    ped_device_probe_all();

    bool big_enough = false;
    for (dev = NULL; NULL != (dev = ped_device_get_next(dev));)
    {
        long long dev_size = process_device(dev);
        if (dev_size >= required_space)
        {
            big_enough = true;
            break;
        }
    }

    // We would free the devices to release allocated memory,
    // but other modules might be using partman use well,
    // and they can hold pointers to libparted structures in
    // other threads.
    //
    // So prefer to leak memory, instead.
    //
    // ped_device_free_all();

    return big_enough;
}
static void monitor_cb(
        pa_mainloop_api*a,
        pa_io_event* e,
        int fd,
        pa_io_event_flags_t events,
        void *userdata) {

    struct userdata *u = userdata;
    struct udev_device *dev;

    pa_assert(a);

    if (!(dev = udev_monitor_receive_device(u->monitor))) {
        pa_log("Failed to get udev device object from monitor.");
        goto fail;
    }

    if (!path_get_card_id(udev_device_get_devpath(dev))) {
        udev_device_unref(dev);
        return;
    }

    process_device(u, dev);
    udev_device_unref(dev);
    return;

fail:
    a->io_free(u->udev_io);
    u->udev_io = NULL;
}
Exemplo n.º 3
0
static int
procfs_iterate(int sk)
{
	char buffer[1024];
	char *device, *dummy;
	FILE *fh;
	int status;
	int num_success;
	int num_fail;
	
	if ((fh = fopen ("/host_proc/net/dev", "r")) == NULL)
	{
		WARNING ("madwifi plugin: opening /host_proc/net/dev failed");
		return (-1);
	}

	num_success = 0;
	num_fail = 0;
	while (fgets (buffer, sizeof (buffer), fh) != NULL)
	{
		dummy = strchr(buffer, ':');
		if (dummy == NULL)
			continue;
		dummy[0] = 0;

		device = buffer;
		while (device[0] == ' ')
			device++;

		if (device[0] == 0)
			continue;

		if (ignorelist_match (ignorelist, device) != 0)
			continue;

		status = process_device (sk, device);
		if (status != 0)
		{
			ERROR ("madwifi plugin: Processing interface "
					"%s failed.", device);
			num_fail++;
		}
		else
		{
			num_success++;
		}
	} /* while (fgets) */

	fclose(fh);

	if ((num_success == 0) && (num_fail != 0))
		return (-1);
	return 0;
}
int
main(int argc, char *argv[])
{
	PedDevice *dev;
	ped_exception_fetch_all();
	ped_device_probe_all();
	if (argc > 1) {
		int i;
		for (i = 1; i < argc; ++i) {
			dev = ped_device_get(argv[i]);
			if (dev) {
				process_device(dev);
				ped_device_destroy(dev);
			}
		}
	} else {
		for (dev = NULL; NULL != (dev = ped_device_get_next(dev));)
			process_device(dev);
	}
	return 0;
}
static void process_path(struct userdata *u, const char *path) {
    struct udev_device *dev;

    if (!path_get_card_id(path))
        return;

    if (!(dev = udev_device_new_from_syspath(u->udev, path))) {
        pa_log("Failed to get udev device object from udev.");
        return;
    }

    process_device(u, dev);
    udev_device_unref(dev);
}
Exemplo n.º 6
0
static int
sysfs_iterate(int sk)
{
	struct dirent *de;
	DIR *nets;
	int status;
	int num_success;
	int num_fail;

	nets = opendir ("/sys/class/net/");
	if (nets == NULL)
	{
		WARNING ("madwifi plugin: opening /sys/class/net failed");
		return (-1);
	}

	num_success = 0;
	num_fail = 0;
	while ((de = readdir (nets)))
	{
		if (check_devname (de->d_name) == 0)
			continue;

		if (ignorelist_match (ignorelist, de->d_name) != 0)
			continue;

		status = process_device (sk, de->d_name);
		if (status != 0)
		{
			ERROR ("madwifi plugin: Processing interface "
					"%s failed.", de->d_name);
			num_fail++;
		}
		else
		{
			num_success++;
		}
	} /* while (readdir) */

	closedir(nets);

	if ((num_success == 0) && (num_fail != 0))
		return (-1);
	return (0);
}
Exemplo n.º 7
0
int main(int argc, char *argv[]) {  

  usb_init();
  if ( usb_find_busses() < 0 ) fatal("usb_find_busses");
  if ( usb_find_devices() < 0 ) fatal("usb_find_devices");
  struct usb_bus *busses = usb_get_busses();
  if ( ! busses ) fatal("usb_get_busses");

  int found = 0;

  struct usb_bus *bus;
  for ( bus=busses; bus; bus=bus->next ) {
    struct usb_device *dev;
    for ( dev=bus->devices; dev; dev=dev->next) {
      struct usb_config_descriptor *cfg;
      for ( cfg = dev->config;
	    cfg < dev->config + dev->descriptor.bNumConfigurations;
	    ++cfg ) {
	int itfnum;
	for ( itfnum=0; itfnum<cfg->bNumInterfaces; ++itfnum ) {
	  struct usb_interface *itf = &cfg->interface[itfnum];
	  struct usb_interface_descriptor *alt;
	  for ( alt = itf->altsetting;
		alt < itf->altsetting + itf->num_altsetting;
		++alt ) {
	    if ( dev->descriptor.idVendor == VENDOR &&
		 (dev->descriptor.idProduct == PRODUCT_SIXAXIS ||
		  dev->descriptor.idProduct == PRODUCT_NAVIGATION) &&
		 alt->bInterfaceClass == 3 ) {
	      process_device(argc, argv, dev, cfg, itfnum);
	      ++found;
	    }
	  }
	}
      }
    }
  }

  if ( ! found ) {
    printf("No controller found on USB busses. Please connect your joystick via USB.\n");
    return 1;
  }
  return 0;
}
Exemplo n.º 8
0
int
check_big_enough(long long required_space)
{
    PedDevice *dev;
    ped_exception_fetch_all();
    ped_device_probe_all();

    bool big_enough = false;
    for (dev = NULL; NULL != (dev = ped_device_get_next(dev));)
    {
        long long dev_size = process_device(dev);
        if (dev_size > required_space)
        {
            big_enough = true;
            break;
        }
    }
    ped_device_free_all();

    return big_enough;
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
  libusb_context* ctx = NULL;
  int ret = -1;
  int status;
  int i;

  if(read_file() < 0)
  {
    return -1;
  }

  if(libusb_init(&ctx))
  {
    fprintf(stderr, "Can't initialize libusb.\n");
    return -1;
  }

  //libusb_set_debug(ctx, 128);

  devh = libusb_open_device_with_vid_pid(ctx, VENDOR, PRODUCT);
  if(!devh)
  {
    fprintf(stderr, "No device found on USB busses.\n");
#ifdef WIN32
    Sleep(2000);
#else
    sleep(2);
#endif
    libusb_exit(ctx);
    return -1;
  }

#if defined(LIBUSB_API_VERSION) || defined(LIBUSBX_API_VERSION)
  libusb_set_auto_detach_kernel_driver(devh, 1);
#else
#ifndef WIN32
  ret = libusb_kernel_driver_active(devh, 0);
  if(ret > 0)
  {
    ret = libusb_detach_kernel_driver(devh, 0);
    if(ret < 0)
    {
      fprintf(stderr, "Can't detach kernel driver: %s.\n", libusb_strerror(ret));
      libusb_close(devh);
      libusb_exit(ctx);
      return -1;
    }
  }
#endif
#endif
  ret = libusb_claim_interface(devh, 0);
  if(ret < 0)
  {
    fprintf(stderr, "Can't claim interface: %s.\n", libusb_strerror(ret));
    libusb_close(devh);
    libusb_exit(ctx);
    return -1;
  }

  status = process_device(devh);

  process_transfer(&cleanup);

  ret = libusb_release_interface(devh, 0);
  if(ret < 0)
  {
    fprintf(stderr, "Can't release interface: %s.\n", libusb_strerror(ret));
  }

#if !defined(LIBUSB_API_VERSION) && !defined(LIBUSBX_API_VERSION)
#ifndef WIN32
  ret = libusb_attach_kernel_driver(devh, 0);
  if(ret < 0)
  {
    fprintf(stderr, "Can't attach kernel driver: %s.\n", libusb_strerror(ret));
  }
#endif
#endif

  free(transfers);

  libusb_close(devh);
  libusb_exit(ctx);

  return ret;

}