void data_string(uint8_t** nextbuf, ujstring* str)
{
	uint16_t len = htoj16(str->length);
	movebytes( &((*nextbuf)[2]), str->data, str->length );
	movebytes( *nextbuf, (uint8_t*)&len, 2);
	(*nextbuf) += 2 + str->length;
}
void data_int64(uint8_t** nextbuf, int64_t val)
{
	val = htoj64(val);
	movebytes( *nextbuf, (uint8_t*)&val, 8 );
	(*nextbuf) += 8;
}
void data_int32(uint8_t** nextbuf, int32_t val)
{
	val = htoj32(val);
	movebytes( *nextbuf, (uint8_t*)&val, 4 );
	(*nextbuf) += 4;
}
void data_int16(uint8_t** nextbuf, int16_t val)
{
	val = htoj16(val);
	movebytes( *nextbuf, (uint8_t*)&val, 2 );
	(*nextbuf) += 2;
}
static void _data_size(uint8_t* buf, uint16_t val)
{
	val = htoj16(val);
	movebytes(buf, (uint8_t*)&val, 2);
}
void data_double(uint8_t** nextbuf, double val)
{
	val = htojd(val);
	movebytes( *nextbuf, (uint8_t*)&val, 8 );
	(*nextbuf) += 8;
}
void data_float(uint8_t** nextbuf, float val)
{
	val = htojf(val);
	movebytes( *nextbuf, (uint8_t*)&val, 4 );
	(*nextbuf) += 4;
}
Beispiel #8
0
static int
usalo_send(SCSI *usalp)
{
	struct usal_cmd	*sp = usalp->scmd;
	ULONG	rc;				/* return value */
static	SRB	SRBlock;			/* XXX makes it non reentrant */
	Ulong	cbreturn;
	Ulong	cbParam;
	UCHAR*	ptr;

	if (usalp->fd < 0) {			/* Set in usalo_open() */
		sp->error = SCG_FATAL;
		return (0);
	}

	if (sp->cdb_len > sizeof (SRBlock.u.cmd.cdb_st)) { /* commandsize too big */
		sp->error = SCG_FATAL;
		sp->ux_errno = EINVAL;
		fprintf((FILE *)usalp->errfile,
			"sp->cdb_len > SRBlock.u.cmd.cdb_st. Fatal error in usalo_send, exiting...\n");
		return (-1);
	}

	/* clear command block */
	fillbytes((caddr_t)&SRBlock.u.cmd.cdb_st, sizeof (SRBlock.u.cmd.cdb_st), '\0');
	/* copy cdrecord command into SRB */
	movebytes(&sp->cdb, &SRBlock.u.cmd.cdb_st, sp->cdb_len);

	/* Build SRB command block */
	SRBlock.cmd = SRB_Command;
	SRBlock.ha_num = usal_scsibus(usalp);	/* host adapter number */

	SRBlock.flags = SRB_Post;		/* flags */

	SRBlock.u.cmd.target	= usal_target(usalp); /* Target SCSI ID */
	SRBlock.u.cmd.lun	= usal_lun(usalp); /* Target SCSI LUN */
	SRBlock.u.cmd.data_len	= sp->size;	/* # of bytes transferred */
	SRBlock.u.cmd.data_ptr	= 0;		/* pointer to data buffer */
	SRBlock.u.cmd.sense_len	= sp->sense_len; /* length of sense buffer */

	SRBlock.u.cmd.link_ptr	= 0;		/* pointer to next SRB */
	SRBlock.u.cmd.cdb_len	= sp->cdb_len;	/* SCSI command length */

	/* Specify direction */
	if (sp->flags & SCG_RECV_DATA) {
		SRBlock.flags |= SRB_Read;
	} else {
		if (sp->size > 0) {
			SRBlock.flags |= SRB_Write;
			if (usalp->bufbase != sp->addr) { /* Copy only if data not in ASPI-Mem */
				movebytes(sp->addr, usalp->bufbase, sp->size);
			}
		} else {
			SRBlock.flags |= SRB_NoTransfer;
		}
	}
	sp->error	= SCG_NO_ERROR;
	sp->sense_count	= 0;
	sp->u_scb.cmd_scb[0] = 0;
	sp->resid	= 0;

	/* execute SCSI	command */
	rc = DosDevIOCtl(driver_handle, 0x92, 0x02,
			(void*) &SRBlock, sizeof (SRB), &cbParam,
			(void*) &SRBlock, sizeof (SRB), &cbreturn);

	if (rc) {		/* An error occured */
		fprintf((FILE *)usalp->errfile,
				"DosDevIOCtl() in sendCommand failed.\n");
		sp->error = SCG_FATAL;
		sp->ux_errno = EIO;	/* Später vielleicht errno einsetzen */
		return (rc);
	} else {
		/* Wait until the command is processed */
		rc = wait_post(sp->timeout*1000);
		if (rc) {	/* An error occured */
			if (rc == 640) {
				/* Timeout */
				sp->error = SCG_TIMEOUT;
				sp->ux_errno = EIO;
				fprintf((FILE *)usalp->errfile,
						"Timeout during SCSI-Command.\n");
				return (1);
			}
			sp->error = SCG_FATAL;
			sp->ux_errno = EIO;
			fprintf((FILE *)usalp->errfile,
					"Fatal Error during DosWaitEventSem().\n");
			return (1);
		}

		/* The command is processed */
		if (SRBlock.status == SRB_Done) {	/* succesful completion */
#ifdef DEBUG
			fprintf((FILE *)usalp->errfile,
				"Command successful finished. SRBlock.status=0x%x\n\n", SRBlock.status);
#endif
			sp->sense_count = 0;
			sp->resid = 0;
			if (sp->flags & SCG_RECV_DATA) {	/* We read data */
				if (sp->addr && sp->size) {
					if (usalp->bufbase != sp->addr)	/* Copy only if data not in ASPI-Mem */
						movebytes(usalp->bufbase, sp->addr, SRBlock.u.cmd.data_len);
					ptr = (UCHAR*)sp->addr;
					sp->resid = sp->size - SRBlock.u.cmd.data_len; /*nicht übertragene bytes. Korrekt berechnet???*/
				}
			}	/* end of if (sp->flags & SCG_RECV_DATA) */
			if (SRBlock.u.cmd.target_status == SRB_CheckStatus) { /* Sense data valid */
				sp->sense_count	= (int)SRBlock.u.cmd.sense_len;
				if (sp->sense_count > sp->sense_len)
					sp->sense_count = sp->sense_len;

				ptr = (UCHAR*)&SRBlock.u.cmd.cdb_st;
				ptr += SRBlock.u.cmd.cdb_len;

				fillbytes(&sp->u_sense.Sense, sizeof (sp->u_sense.Sense), '\0');
				movebytes(ptr, &sp->u_sense.Sense, sp->sense_len);

				sp->u_scb.cmd_scb[0] = SRBlock.u.cmd.target_status;
				sp->ux_errno = EIO;	/* Später differenzieren? */
			}
			return (0);
		}
		/* SCSI-Error occured */
		set_error(&SRBlock, sp);

		if (SRBlock.u.cmd.target_status == SRB_CheckStatus) {	/* Sense data valid */
			sp->sense_count	= (int)SRBlock.u.cmd.sense_len;
			if (sp->sense_count > sp->sense_len)
				sp->sense_count = sp->sense_len;

			ptr = (UCHAR*)&SRBlock.u.cmd.cdb_st;
			ptr += SRBlock.u.cmd.cdb_len;

			fillbytes(&sp->u_sense.Sense, sizeof (sp->u_sense.Sense), '\0');
			movebytes(ptr, &sp->u_sense.Sense, sp->sense_len);

			sp->u_scb.cmd_scb[0] = SRBlock.u.cmd.target_status;
		}
		if (sp->flags & SCG_RECV_DATA) {
			if (sp->addr && sp->size) {
				if (usalp->bufbase != sp->addr)	/* Copy only if data not in ASPI-Mem */
					movebytes(usalp->bufbase, sp->addr, SRBlock.u.cmd.data_len);
			}
		}
#ifdef	really
		sp->resid	= SRBlock.u.cmd.data_len; /* XXXXX Got no Data ????? */
#else
		sp->resid	= sp->size - SRBlock.u.cmd.data_len;
#endif
		return (1);
	}
}
Beispiel #9
0
LOCAL void
reset_tty()
{
#ifdef USE_V7_TTY
	if (ioctl(STDIN_FILENO, TIOCSETN, &savetty) == -1) {
#else
#ifdef TCSANOW
	if (tcsetattr(STDIN_FILENO, TCSANOW, &savetty) == -1) {
#else
	if (ioctl(STDIN_FILENO, TCSETAF, &savetty) == -1) {
#endif
#endif
		printf("Cannot put tty into normal mode\n");
		exit(1);
	}
}

LOCAL void
set_tty()
{
#ifdef USE_V7_TTY
	if (ioctl(STDIN_FILENO, TIOCSETN, &newtty) == -1) {
#else
#ifdef TCSANOW
	if (tcsetattr(STDIN_FILENO, TCSANOW, &newtty) == -1) {
#else
	if (ioctl(STDIN_FILENO, TCSETAF, &newtty) == -1) {
#endif
#endif
		printf("Cannot put tty into raw mode\n");
		exit(1);
	}
}


/*
 * Come here when we get a suspend signal from the terminal
 */
LOCAL void
onsusp(sig)
	int	sig;
{
#ifdef	SIGTTOU
	/* ignore SIGTTOU so we don't get stopped if csh grabs the tty */
	signal(SIGTTOU, SIG_IGN);
#endif
	reset_tty();
	fflush(stdout);
#ifdef	SIGTTOU
	signal(SIGTTOU, SIG_DFL);
	/* Send the TSTP signal to suspend our process group */
	signal(SIGTSTP, SIG_DFL);
	/*    sigsetmask(0);*/
	kill(0, SIGTSTP);
	/* Pause for station break */

	/* We're back */
	signal(SIGTSTP, onsusp);
#endif
	set_tty();
}


LOCAL void
crsr2(row, col)
	int	row;
	int	col;
{
	printf("\033[%d;%dH", row, col);
}

LOCAL void
readblock()
{
	off_t	dpos = file_addr - sec_addr;

	if (sec_addr < 0 ||
	    dpos < 0 || (dpos + sizeof (buffer)) > sizeof (sector)) {
		sec_addr = file_addr & ~2047;
#ifdef	USE_SCG
		readsecs(sec_addr/2048, sector, ISO_BLOCKS(sizeof (sector)));
#else
		lseek(fileno(infile), sec_addr, SEEK_SET);
		read(fileno(infile), sector, sizeof (sector));
#endif
		dpos = file_addr - sec_addr;
	}
	movebytes(&sector[dpos], buffer, sizeof (buffer));
}

LOCAL void
showblock(flag)
	int	flag;
{
	unsigned int	k;
	int		i;
	int		j;

	readblock();
	if (flag) {
		for (i = 0; i < 16; i++) {
			crsr2(i+3, 1);
			if (sizeof (file_addr) > sizeof (long)) {
				printf("%16.16llx ", (Llong)file_addr+(i<<4));
			} else {
				printf("%8.8lx ", (long)file_addr+(i<<4));
			}
			for (j = 15; j >= 0; j--) {
				printf("%2.2x", buffer[(i<<4)+j]);
				if (!(j & 0x3))
					printf(" ");
			}
			for (j = 0; j < 16; j++) {
				k = buffer[(i << 4) + j];
				if (k >= ' ' && k < 0x80)
					printf("%c", k);
				else
					printf(".");
			}
		}
	}
	crsr2(20, 1);
	if (sizeof (file_addr) > sizeof (long)) {
		printf(" Zone, zone offset: %14llx %12.12llx  ",
			(Llong)file_addr>>11, (Llong)file_addr & 0x7ff);
	} else {
		printf(" Zone, zone offset: %6lx %4.4lx  ",
			(long)(file_addr>>11), (long)(file_addr & 0x7ff));
	}
	fflush(stdout);
}

LOCAL int
getbyte()
{
	char	c1;

	c1 = buffer[file_addr & (PAGE-1)];
	file_addr++;
	if ((file_addr & (PAGE-1)) == 0)
		showblock(0);
	return (c1);
}