Exemplo n.º 1
0
/*
 * Remove an entry from the device configuration linked list.
 */
static struct virtio_net_config_ll *
rm_config_ll_entry(struct virtio_net_config_ll *ll_dev,
	struct virtio_net_config_ll *ll_dev_last)
{
	/* First remove the device and then clean it up. */
	if (ll_dev == ll_root) {
		ll_root = ll_dev->next;
		cleanup_device(&ll_dev->dev);
		free_device(ll_dev);
		return ll_root;
	} else {
		if (likely(ll_dev_last != NULL)) {
			ll_dev_last->next = ll_dev->next;
			cleanup_device(&ll_dev->dev);
			free_device(ll_dev);
			return ll_dev_last->next;
		} else {
			cleanup_device(&ll_dev->dev);
			free_device(ll_dev);
			RTE_LOG(ERR, VHOST_CONFIG,
				"Remove entry from config_ll failed\n");
			return NULL;
		}
	}
}
Exemplo n.º 2
0
static void sdev_free(struct device *dev)
{
	struct safe_device *sdev = dev_sdev(dev);

	if (sdev->sb_n > 0) {
		char *first_block = align_512(sdev->saved_blocks);
		char *block = first_block +
			((sdev->sb_n - 1) <<
			dev_get_block_order(sdev->shadow_dev));
		uint64_t *poffset = &sdev->sb_offsets[sdev->sb_n - 1];
		int block_size = dev_get_block_size(sdev->shadow_dev);

		/* Restore blocks in reverse order to cope with
		 * wraparound and chain drives.
		 */
		do {
			int rc = sdev->shadow_dev->write_block(
				sdev->shadow_dev, block, block_size, *poffset);
			if (rc) {
				/* Do not abort, try to recover all bocks. */
				warn("Failed to recover block at offset 0x%"
					PRIx64 " due to a write error",
					*poffset);
			}
			block -= block_size;
			poffset--;
		} while (block >= first_block);
	}

	free(sdev->sb_bitmap);
	free(sdev->sb_offsets);
	free(sdev->saved_blocks);
	free_device(sdev->shadow_dev);
}
Exemplo n.º 3
0
Arquivo: uhvm.c Projeto: mjessome/uhvm
static void
deinit(void)
{
    struct device_t *iter, *tmp;

    if (hal_ctx) {
        libhal_ctx_shutdown(hal_ctx, (DBusError *)NULL);
        libhal_ctx_free(hal_ctx);
    }

    dbus_connection_unref(dbus_conn);

    iter = head;

    while (iter) {
        tmp = iter;
        if (!is_mounted(iter))
            /* don't care to check the return values */
            do_umount(iter);
        rmdir(iter->mountp);
        if (iter->should_remove_entry)
            remove_fstab_entry(iter);
        iter = iter->next;
        free_device(tmp);
    }

    if (pid_fd >= 0)
        if (close(pid_fd) < 0) /* releases lock */
            syslog(LOG_ERR, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
    closelog();
}
Exemplo n.º 4
0
void del_all_devices()
{
	for(int j=0;j<number_of_devices;j++)
	{
		free_device(j);
	}
	number_of_devices=0;
};
Exemplo n.º 5
0
struct device *pdev_detach_and_free(struct device *dev)
{
	struct perf_device *pdev = dev_pdev(dev);
	struct device *shadow_dev = pdev->shadow_dev;
	pdev->shadow_dev = NULL;
	pdev->dev.free = NULL;
	free_device(&pdev->dev);
	return shadow_dev;
}
Exemplo n.º 6
0
void free_device(struct device **dev)
{
	if (*dev == NULL)
		return;

	struct device *next = (*dev)->next;
	struct device *child = (*dev)->child;
	struct info_tuple *info = (*dev)->info;

	free_device(&next);
	free_device(&child);
	free_info_tuple(&info);

	free_device_fields(*dev);

	free(*dev);
	*dev = NULL;
}
Exemplo n.º 7
0
int main(void) {
	struct device *dev = new_device("Plugin");
	get_info(dev);
	print_device_list(dev);

	free_device(&dev);

	return 0;
}
Exemplo n.º 8
0
void del_device(uint8_t idx)
{
	// handle index out of bounds?
	free_device(idx);

	number_of_devices--;
	for(int i = idx;i< number_of_devices;i++)
	{
		devices[i]=devices[i+1];
	}
}
Exemplo n.º 9
0
static void ensure_ws(const int ws_size)
{
	//printf("ws_size %i\n", ws_size);
	if(ws_size > fft_ws_size)
	{
		fft_ws_size = ws_size;
		if(fft_ws)
			free_device(fft_ws);
		malloc_device(&fft_ws, ws_size);
	}
}
Exemplo n.º 10
0
static int
usbhub_device_disconnect(struct usb_host *usbhc, u8 devadr, u64 port)
{
	struct usb_device *dev;

	dprintft(3, "HUB(%02x): HUB PORT(%d) status disconnect.\n",
				 devadr, (int)(port & USB_PORT_MASK));
	dev = get_device_by_port (usbhc, port);
	if (dev)
		free_device (usbhc, dev);
	return USB_HOOK_PASS;
}
Exemplo n.º 11
0
void iio_context_destroy(struct iio_context *ctx)
{
    unsigned int i;
    if (ctx->ops->shutdown)
        ctx->ops->shutdown(ctx);

    for (i = 0; i < ctx->nb_devices; i++)
        free_device(ctx->devices[i]);
    if (ctx->nb_devices)
        free(ctx->devices);
    if (ctx->xml)
        free(ctx->xml);
    if (ctx->description)
        free(ctx->description);
    free(ctx);
}
Exemplo n.º 12
0
/*
 * Function is called from the CUSE release function. This function will
 * cleanup the device and remove it from device configuration linked list.
 */
void
vhost_destroy_device(struct vhost_device_ctx ctx)
{
	struct virtio_net *dev = get_device(ctx);

	if (dev == NULL)
		return;

	if (dev->flags & VIRTIO_DEV_RUNNING)
		notify_ops->destroy_device(dev);

	cleanup_device(dev, 1);
	free_device(dev);

	vhost_devices[ctx.fh] = NULL;
}
Exemplo n.º 13
0
/*
 * Invoked when there is the vhost-user connection is broken (when
 * the virtio device is being detached).
 */
void
vhost_destroy_device(int vid)
{
	struct virtio_net *dev = get_device(vid);

	if (dev == NULL)
		return;

	if (dev->flags & VIRTIO_DEV_RUNNING) {
		dev->flags &= ~VIRTIO_DEV_RUNNING;
		dev->notify_ops->destroy_device(vid);
	}

	cleanup_device(dev, 1);
	free_device(dev);

	vhost_devices[vid] = NULL;
}
Exemplo n.º 14
0
static void
usbhub_clean_list (struct usb_device *hubdev)
{
	struct usb_device *dev;
	struct usb_host *usbhc;

	usbhc = hubdev->host;
	if (!usbhc) {
		dprintft (1, "hubdev->host NULL.\n");
		return;
	}
again:
	for (dev = usbhc->device; dev; dev = dev->next) {
		if (dev->parent == hubdev) {
			/* if dev is hub, dev->next may be freed
			 * during free_device() */
			free_device (usbhc, dev);
			goto again;
		}
	}
}
Exemplo n.º 15
0
int main()
{
    data_t data;

    printf("\n\tGestIC %s - Console Demo\n\n", gestic_version_str());

    /* Initialize data and the device */
    init_data(&data);
    init_device(&data);

    /* Update device and menu until quit */
    while(data.running)
    {
        update_device(&data);
        update_menu(&data);
        Sleep(10);
    }

    /* Do the cleanup work */
    free_device(&data);

    return 0;
}
Exemplo n.º 16
0
static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
{
	unsigned int i;
	xmlNode *root, *n;
	xmlAttr *attr;
	int err = ENOMEM;
	struct iio_context *ctx = calloc(1, sizeof(*ctx));
	if (!ctx)
		goto err_set_errno;

	ctx->name = "xml";
	ctx->ops = &xml_ops;

	root = xmlDocGetRootElement(doc);
	if (strcmp((char *) root->name, "context")) {
		ERROR("Unrecognized XML file\n");
		err = EINVAL;
		goto err_free_ctx;
	}

	for (attr = root->properties; attr; attr = attr->next) {
		if (!strcmp((char *) attr->name, "description"))
			ctx->description = _strdup(
					(char *) attr->children->content);
		else if (strcmp((char *) attr->name, "name"))
			WARNING("Unknown parameter \'%s\' in <context>\n",
					(char *) attr->children->content);
	}

	for (n = root->children; n; n = n->next) {
		struct iio_device **devs, *dev;

		if (strcmp((char *) n->name, "device")) {
			if (strcmp((char *) n->name, "text"))
				WARNING("Unknown children \'%s\' in "
						"<context>\n", n->name);
			continue;
		}

		dev = create_device(ctx, n);
		if (!dev) {
			ERROR("Unable to create device\n");
			goto err_free_devices;
		}

		devs = realloc(ctx->devices, (1 + ctx->nb_devices) *
				sizeof(struct iio_device *));
		if (!devs) {
			ERROR("Unable to allocate memory\n");
			free(dev);
			goto err_free_devices;
		}

		devs[ctx->nb_devices++] = dev;
		ctx->devices = devs;
	}

	err = iio_context_init(ctx);
	if (err)
		goto err_free_devices;

	return ctx;

err_free_devices:
	for (i = 0; i < ctx->nb_devices; i++)
		free_device(ctx->devices[i]);
	if (ctx->nb_devices)
		free(ctx->devices);
err_free_ctx:
	free(ctx);
err_set_errno:
	errno = err;
	return NULL;
}
Exemplo n.º 17
0
static struct iio_device * create_device(struct iio_context *ctx, xmlNode *n)
{
	xmlAttr *attr;
	struct iio_device *dev = calloc(1, sizeof(*dev));
	if (!dev)
		return NULL;

	dev->ctx = ctx;

	for (attr = n->properties; attr; attr = attr->next) {
		if (!strcmp((char *) attr->name, "name")) {
			dev->name = _strdup((char *) attr->children->content);
		} else if (!strcmp((char *) attr->name, "id")) {
			dev->id = _strdup((char *) attr->children->content);
		} else {
			WARNING("Unknown attribute \'%s\' in <device>\n",
					attr->name);
		}
	}

	if (!dev->id) {
		ERROR("Unable to read device ID\n");
		goto err_free_device;
	}

	for (n = n->children; n; n = n->next) {
		if (!strcmp((char *) n->name, "channel")) {
			struct iio_channel **chns,
					   *chn = create_channel(dev, n);
			if (!chn) {
				ERROR("Unable to create channel\n");
				goto err_free_device;
			}

			chns = realloc(dev->channels, (1 + dev->nb_channels) *
					sizeof(struct iio_channel *));
			if (!chns) {
				ERROR("Unable to allocate memory\n");
				free(chn);
				goto err_free_device;
			}

			chns[dev->nb_channels++] = chn;
			dev->channels = chns;
		} else if (!strcmp((char *) n->name, "attribute")) {
			if (add_attr_to_device(dev, n, false) < 0)
				goto err_free_device;
		} else if (!strcmp((char *) n->name, "debug-attribute")) {
			if (add_attr_to_device(dev, n, true) < 0)
				goto err_free_device;
		} else if (strcmp((char *) n->name, "text")) {
			WARNING("Unknown children \'%s\' in <device>\n",
					n->name);
			continue;
		}
	}

	dev->words = (dev->nb_channels + 31) / 32;
	if (dev->words) {
		dev->mask = calloc(dev->words, sizeof(*dev->mask));
		if (!dev->mask) {
			errno = ENOMEM;
			goto err_free_device;
		}
	}

	return dev;

err_free_device:
	free_device(dev);
	return NULL;
}
Exemplo n.º 18
0
static void pdev_free(struct device *dev)
{
	struct perf_device *pdev = dev_pdev(dev);
	free_device(pdev->shadow_dev);
}
Exemplo n.º 19
0
Arquivo: uhvm.c Projeto: mjessome/uhvm
/* Callback function, called when a new device has been inserted. */
static void
device_added(LibHalContext *context, const char *did)
{
    const char *dudi, *fstype;
    char *dev, *mountp, *mountable, *label, *locked_reason;
    LibHalVolume *volume;
    LibHalDrive *drive;
    struct device_t *device;

    if (libhal_device_property_exists(context, did, "info.locked",
                                      (DBusError *)NULL)
            && libhal_device_get_property_bool(context, did, "info.locked",
                                               (DBusError *)NULL)) {
        if (debug_mode_flag) {
            locked_reason = libhal_device_get_property_string(
                                context, did, "info.locked.reason",
                                (DBusError *)NULL);
            if (locked_reason) {
                if (debug_mode_flag)
                    printf("%s%d: %s\n", __FILE__, __LINE__, locked_reason);
                libhal_free_string(locked_reason);
            }
        }
        return;
    }

    if (!libhal_device_query_capability(context, did, "volume",
                                        (DBusError *)NULL))
        return;
    label = libhal_device_get_property_string(context, did, "volume.label",
                                              (DBusError *)NULL);
    if (!(mountable = libhal_device_get_property_string(
                          context, did, "volume.fsusage", (DBusError *)NULL))
            || strcmp(mountable, "filesystem"))
        goto out;
    if (!(volume = libhal_volume_from_udi(context, did)))
        goto out;
    if (!(dudi = libhal_volume_get_storage_device_udi(volume)))
        goto out;
    if (!(drive = libhal_drive_from_udi(context, dudi)))
        goto out;
    if (!libhal_drive_is_hotpluggable(drive)
            && !libhal_drive_uses_removable_media(drive))
        goto out;
    if (!(fstype = libhal_volume_get_fstype(volume)))
        goto out;
    if (!(dev = libhal_device_get_property_string(context, did, "block.device",
                                                  (DBusError *)NULL)))
        goto out;
    mountp = get_mount_point(dev, label);
    if (!mountp)
        goto out;
    device = get_device(mountp, did, dev, label, fstype, volume, drive);
    if(!is_mounted(device)) {
        free_device(device);
        goto out;
    }
    if (!device)
        goto out;
    consider_fstab(device);

    device->hook = malloc(2*sizeof(char*)); 
    if(!file_exists(HOOK_PATH)) {
        device->hook[0] = get_hook(device, "mount");
        device->hook[1] = get_hook(device, "umount");
    }
    else {
        device->hook[0] = NULL;
        device->hook[1] = NULL;
    }

    if (file_exists(device->mountp) < 0)
        mkdir(device->mountp, 0750);
    do_mount(device) < 0 ? free_device(device) : add_to_device_list(device);

    if (device) {
        if (!add_fstab_entry(device))
            device->should_remove_entry = 1;
        if (debug_mode_flag)
            debug_dump_device(device);
    }

    if (device->hook[0]) run_hook(0, device);

out:
    if (mountable)
        libhal_free_string(mountable);
    if (label)
        libhal_free_string(label);
}
Exemplo n.º 20
0
API_EXPORTED int usb_find_devices(void)
{
	struct usb_bus *bus;
	libusb_device **dev_list;
	int dev_list_len;
	int r;
	int changes = 0;

	/* libusb-1.0 initialization might have failed, but we can't indicate
	 * this with libusb-0.1, so trap that situation here */
	if (!ctx)
		return 0;

	usbi_dbg("");
	dev_list_len = libusb_get_device_list(ctx, &dev_list);
	if (dev_list_len < 0)
		return compat_err(dev_list_len);

	for (bus = usb_busses; bus; bus = bus->next) {
		struct usb_device *new_devices = NULL;
		struct usb_device *dev;

		r = find_devices(dev_list, dev_list_len, bus, &new_devices);
		if (r < 0) {
			libusb_free_device_list(dev_list, 1);
			return r;
		}

		/* walk through the devices we already know about, removing duplicates
		 * from the new list. if we do not find it in the new list, the device
		 * has been removed. */
		dev = bus->devices;
		while (dev) {
			int found = 0;
			struct usb_device *tdev = dev->next;
			struct usb_device *ndev = new_devices;

			while (ndev) {
				if (ndev->devnum == dev->devnum) {
					LIST_DEL(new_devices, ndev);
					free(ndev);
					found = 1;
					break;
				}
				ndev = ndev->next;
			}

			if (!found) {
				usbi_dbg("device %d.%d removed",
					dev->bus->location, dev->devnum);
				LIST_DEL(bus->devices, dev);
				free_device(dev);
				changes++;
			}

			dev = tdev;
		}

		/* anything left in new_devices is a new device */
		dev = new_devices;
		while (dev) {
			struct usb_device *tdev = dev->next;
			r = initialize_device(dev);	
			if (r < 0) {
				usbi_err("couldn't initialize device %d.%d (error %d)",
					dev->bus->location, dev->devnum, r);
				dev = tdev;
				continue;
			}
			usbi_dbg("device %d.%d added", dev->bus->location, dev->devnum);
			LIST_DEL(new_devices, dev);
			LIST_ADD(bus->devices, dev);
			changes++;
			dev = tdev;
		}
	}

	libusb_free_device_list(dev_list, 1);
	return changes;
}