Пример #1
0
static int gp_port_usbdiskdirect_seek (GPPort *port, int offset, int whence)
{
	off_t ret;

	C_PARAMS (!port);

	/* The device needs to be opened for that operation */
	if (port->pl->fd == -1)
		CHECK (gp_port_usbdiskdirect_open (port))

	ret = lseek (port->pl->fd, offset, whence);
	if (ret == -1) {
		gp_port_set_error (port, _("Could not seek to offset: %x on "
			"'%s' (%m)."), offset,
			port->settings.usbdiskdirect.path);
		return GP_ERROR_IO;
	}

	return ret;
}
Пример #2
0
static int
gp_port_usbdiskdirect_read (GPPort *port, char *bytes, int size)
{
	int ret;

	C_PARAMS (port);

	/* The device needs to be opened for that operation */
	if (port->pl->fd == -1)
		CHECK (gp_port_usbdiskdirect_open (port))

	ret = read (port->pl->fd, bytes, size);
	if (ret < 0) {
		gp_port_set_error (port, _("Could not read from '%s' (%m)."),
				   port->settings.usbdiskdirect.path);
		return GP_ERROR_IO;
	}

	return ret;
}
Пример #3
0
static int
gp_port_usbdiskdirect_write (GPPort *port, const char *bytes, int size)
{
	int ret;

	if (!port)
		return GP_ERROR_BAD_PARAMETERS;

	/* The device needs to be opened for that operation */
	if (port->pl->fd == -1)
		CHECK (gp_port_usbdiskdirect_open (port))

	ret = write (port->pl->fd, bytes, size);
	if (ret < 0) {
		gp_port_set_error (port, _("Could not write to '%s' (%m)."),
				   port->settings.usbdiskdirect.path);
		return GP_ERROR_IO;
	}

	return ret;
}