Example #1
0
int
rmtopen(char *tape, int mode)
{
	struct mtget mt;
	char buf[256];
	int fd;

	(void) snprintf(buf, sizeof (buf), "O%s\n%d\n", tape, mode);
	rmtstate = TS_OPEN;
	fd = rmtcall(tape, buf);
	if (fd != -1) {
		/* see if the rmt server supports the extended protocol */
		rmtversion = rmtioctl(-1, 0);

		/*
		 * Some rmt daemons apparently close the connection
		 * when they get a bogus ioctl.  See 1210852 (ignore
		 * the evaluation).  Make sure we can still talk to
		 * the device, re-opening it if necessary.
		 */
		if (rmtversion < 1) {
			if (rmtstatus(&mt) < 0) {
				rmtclose();
				rmtgetconn();
				rmtversion = 0;
			}
		}
	}
	return (fd);
}
Example #2
0
int
rmtread(char *buf, uint_t count)
{
	char line[30];
	int n, i, cc;

	(void) snprintf(line, sizeof (line), "R%d\n", count);
	n = rmtcall("read", line);
	if (n < 0) {
		return (-1);
	}
	if (n > count) {
		print(dgettext(domainname,
		    "rmtread: expected response size %d, got %d\n"),
		    count, n);
		print(dgettext(domainname,
		    "This means the remote rmt daemon is not compatible.\n"));
		rmtconnaborted(0);
	}
	i = 0;
	while (i < n) {
		cc = read(rmtape, buf+i, n - i);
		if (cc <= 0)
			rmtconnaborted(0);
		i += cc;
	}
	return (n);
}
Example #3
0
int
rmtstatus(struct mtget *mt)
{
	char *buf = (char *)mt;
	int n, i, cc;

	if (rmtversion > 0)
		return (rmtstatus_extended(mt));

	n = rmtcall("status", "S");
	if (n < 0) {
		return (-1);
	}
	if ((unsigned)n > sizeof (*mt)) {
		print(dgettext(domainname,
		    "rmtstatus: expected response size %d, got %d\n"),
		    sizeof (struct mtget), n);
		print(dgettext(domainname,
		    "This means the remote rmt daemon is not compatible.\n"));
		rmtconnaborted(0);
	}
	i = 0;
	while (i < n) {
		cc = read(rmtape, buf+i, n - i);
		if (cc <= 0)
			rmtconnaborted(0);
		i += cc;
	}
	return (n);
}
Example #4
0
static int
rmtioctl_extended(int cmd, long count)
{
	char buf[256];

	(void) snprintf(buf, sizeof (buf), "i%d\n%ld\n", cmd, count);
	return (rmtcall("ioctl", buf));
}
Example #5
0
int
rmtseek(int offset, int pos)
{
	char line[80];

	(void) snprintf(line, sizeof (line), "L%d\n%d\n", offset, pos);
	return (rmtcall("seek", line));
}
Example #6
0
rmtclose()
#endif
{
	if (rmtstate != TS_OPEN)
		return;
	(void) rmtcall("close", "C\n");
	rmtstate = TS_CLOSED;
}
Example #7
0
void
rmtclose(void)
{

	if (rmtstate != TS_OPEN)
		return;
	rmtcall("close", "C\n");
	rmtstate = TS_CLOSED;
}
Example #8
0
int
rmtopen(const char *tape, int mode)
{
	char buf[256];

	(void)snprintf(buf, sizeof (buf), "O%.226s\n%d\n", tape, mode);
	rmtstate = TS_OPEN;
	return (rmtcall(tape, buf));
}
Example #9
0
int
rmtioctl(int cmd, int count)
{
	char buf[256];

	if (count < 0)
		return (-1);
	(void)snprintf(buf, sizeof (buf), "I%d\n%d\n", cmd, count);
	return (rmtcall("ioctl", buf));
}
Example #10
0
static int
rmtstatus_extended(struct mtget *mt)
{
	if ((mt->mt_type = rmtcall("status", "sT")) == -1)
		return (-1);
	mt->mt_dsreg = rmtcall("status", "sD");
	mt->mt_erreg = rmtcall("status", "sE");
	mt->mt_resid = rmtcall("status", "sR");
	mt->mt_fileno = rmtcall("status", "sF");
	mt->mt_blkno = rmtcall("status", "sB");
	mt->mt_flags = rmtcall("status", "sf");
	mt->mt_bf = rmtcall("status", "sb");
	return (0);
}
Example #11
0
struct mtget *
rmtstatus(void)
{
	int i;
	char *cp;

	if (rmtstate != TS_OPEN)
		return (NULL);
	rmtcall("status", "S\n");
	for (i = 0, cp = (char *)&mts; i < sizeof(mts); i++)
		*cp++ = rmtgetb();
	return (&mts);
}
Example #12
0
int
rmtioctl(int cmd, long count)
{
	char buf[256];
	int xcmd;

	if (count < 0)
		return (-1);

	if ((xcmd = map_extended_ioctl(cmd)) != -1)
		return (rmtioctl_extended(xcmd, count));

	(void) snprintf(buf, sizeof (buf), "I%d\n%ld\n", cmd, count);
	return (rmtcall("ioctl", buf));
}
Example #13
0
int
rmtread(char *buf, int count)
{
	char line[30];
	int n, i, cc;

	(void)snprintf(line, sizeof (line), "R%d\n", count);
	n = rmtcall("read", line);
	if (n < 0)
		/* rmtcall() properly sets errno for us on errors. */
		return (n);
	for (i = 0; i < n; i += cc) {
		cc = read(rmtape, buf+i, n - i);
		if (cc <= 0)
			rmtconnaborted(0);
	}
	return (n);
}
Example #14
0
int
rmtread(char *buf, int count)
{
	char line[30];
	int n, i, cc;

	(void)snprintf(line, sizeof(line), "R%d\n", count);
	n = rmtcall("read", line);
	if (n < 0) {
		errno = n;
		return (-1);
	}
	for (i = 0; i < n; i += cc) {
		cc = read(rmtape, buf+i, n - i);
		if (cc <= 0) {
			rmtconnaborted(0);
		}
	}
	return (n);
}