예제 #1
0
파일: zqs.c 프로젝트: JamesLinus/inferno
static long
unsqueezefd(int fd, void *v)
{
	uchar *wp, *out;
	ulong toptxt, topdat;
	long asis, nst, nsd;
	Sqhdr sqh;
	Exec ex;

	out = (uchar*)v;
	if(read(fd, &sqh, SQHDRLEN) != SQHDRLEN)
		return -1;
	if(GET4(sqh.magic) != SQMAGIC)
		return -1;
	if(read(fd, &ex, sizeof(Exec)) != sizeof(Exec))
		return -1;
	toptxt = GET4(sqh.toptxt);
	topdat = GET4(sqh.topdat);
	oldsum = GET4(sqh.sum);
	asis = GET4(sqh.asis);
	if(asis < 0)
		asis = 0;
	nst = GET4(sqh.text);
	nsd = GET4(sqh.data);
	switch(GET4((uchar*)&ex.magic)){
	case Q_MAGIC:
		if(qflag)
			fprint(2, "PowerPC mode\n");
		islittle = 0;
		break;
	case E_MAGIC:
	case 0xA0E1:	/* arm AIF */
		islittle = 1;
		qflag = 0;
		break;
	default:
		fprint(2, "Unknown magic: %8.8ux\n", GET4((uchar*)&ex.magic));
		qflag = 0;
		break;
	}
	memmove(out, &ex, sizeof(ex));
	wp = unsqzseg(fd, out + sizeof(ex), nst, toptxt);
	if(wp == nil)
		return -1;
	wp = unsqzseg(fd, wp, nsd, topdat);
	if(wp == nil)
		return -1;
	if(asis){
		if(read(fd, wp, asis) != asis)
			return -1;
		wp += asis;
	}
	return wp-out;
}
예제 #2
0
파일: smsc.c 프로젝트: grobe0ba/plan9front
static int
smscreceive(Dev *ep)
{
	Block *b;
	uint hd;
	int n;

	if(Doburst)
		b = allocb(Hsburst*512);
	else
		b = allocb(Maxpkt+4);
	if((n = read(ep->dfd, b->wp, b->lim - b->base)) < 0){
		freeb(b);
		return -1;
	}
	b->wp += n;
	while(BLEN(b) >= 4){
		hd = GET4(b->rp);
		b->rp += 4;
		n = hd >> 16;
		if(n > BLEN(b))
			break;
		if((hd & Rxerror) == 0){
			if(n == BLEN(b)){
				etheriq(b, 1);
				return 0;
			}
			etheriq(copyblock(b, n), 1);
		}
		b->rp += (n + 3) & ~3;
	}
	freeb(b);
	return 0;
}
예제 #3
0
파일: zftape-write.c 프로젝트: nhanh0/hah
static int zft_write_header_segments(__u8* buffer)
{
	int header_1_ok = 0;
	int header_2_ok = 0;
	unsigned int time_stamp;
	TRACE_FUN(ft_t_noise);
	
	TRACE_CATCH(ftape_abort_operation(),);
	ftape_seek_to_bot();    /* prevents extra rewind */
	if (GET4(buffer, 0) != FT_HSEG_MAGIC) {
		TRACE_ABORT(-EIO, ft_t_err,
			    "wrong header signature found, aborting");
	} 
	/*   Be optimistic: */
	PUT4(buffer, FT_SEG_CNT,
	     zft_written_segments + GET4(buffer, FT_SEG_CNT) + 2);
	if ((time_stamp = zft_get_time()) != 0) {
		PUT4(buffer, FT_WR_DATE, time_stamp);
		if (zft_label_changed) {
			PUT4(buffer, FT_LABEL_DATE, time_stamp);
		}
	}
	TRACE(ft_t_noise,
	      "writing first header segment %d", ft_header_segment_1);
	header_1_ok = zft_verify_write_segments(ft_header_segment_1, 
						buffer, FT_SEGMENT_SIZE,
						zft_deblock_buf) >= 0;
	TRACE(ft_t_noise,
	      "writing second header segment %d", ft_header_segment_2);
	header_2_ok = zft_verify_write_segments(ft_header_segment_2, 
						buffer, FT_SEGMENT_SIZE,
						zft_deblock_buf) >= 0;
	if (!header_1_ok) {
		TRACE(ft_t_warn, "Warning: "
		      "update of first header segment failed");
	}
	if (!header_2_ok) {
		TRACE(ft_t_warn, "Warning: "
		      "update of second header segment failed");
	}
	if (!header_1_ok && !header_2_ok) {
		TRACE_ABORT(-EIO, ft_t_err, "Error: "
		      "update of both header segments failed.");
	}
	TRACE_EXIT 0;
}
예제 #4
0
int update_header_segment(unsigned segment, byte * buffer)
{
    TRACE_FUN(5, "update_header_segment");
    int result = 0;
    int status;

    if (buffer == NULL) {
        TRACE(5, "no input buffer specified");
        buffer = deblock_buffer;
        result = read_segment(used_header_segment, buffer, &status, 0);
        if (bad_sector_map_changed) {
            store_bad_sector_map(buffer);
        }
        if (failed_sector_log_changed) {
            update_failed_sector_log(buffer);
        }
    }
    if (result >= 0 && GET4(buffer, 0) != 0xaa55aa55) {
        TRACE(1, "wrong header signature found, aborting");
        result = -EIO;
    }
    if (result >= 0) {
        result = _write_segment(segment, buffer, 0);
        if (result >= 0 && runner_status == idle) {
            /*  Force flush for single segment instead of relying on
             *  flush in read_segment for multiple segments.
             */
            result = start_writing(WRITE_SINGLE);
            if (result >= 0 && ftape_state == writing) {
                result = loop_until_writes_done();
                prevent_flush();
            }
        }
#ifdef VERIFY_HEADERS
        if (result >= 0) {	/* read back and verify */
            result = read_segment(segment, scratch_buffer, &status, 0);
            /*  Should retry if soft error during read !
             *  TO BE IMPLEMENTED
             */
            if (result >= 0) {
                if (memcmp(buffer, scratch_buffer, sizeof(buffer)) == 0) {
                    result = 0;	/* verified */
                    TRACE(5, "verified");
                } else {
                    result = -EIO;	/* verify failed */
                    TRACE(5, "verify failed");
                }
            }
        }
#endif
    }
    TRACE_EXIT;
    return result;
}
예제 #5
0
파일: smsc.c 프로젝트: grobe0ba/plan9front
int
smscinit(Dev *d)
{
	if(!doreset(d, Hwcfg, Lrst) || !doreset(d, Pmctrl, Phyrst))
		return -1;
	if(!setmac)
		if(eepromr(d, MACoffset, macaddr, 6) < 0)
			return -1;
	wr(d, Addrl, GET4(macaddr));
	wr(d, Addrh, GET2(macaddr+4));
	if(Doburst){
		wr(d, Hwcfg, (rr(d,Hwcfg)&~Rxdoff)|Bir|Mef|Bce);
		wr(d, Burstcap, Hsburst);
	}else{
		wr(d, Hwcfg, (rr(d,Hwcfg)&~(Rxdoff|Mef|Bce))|Bir);
		wr(d, Burstcap, 0);
	}
	wr(d, Bulkdelay, Defbulkdly);
	wr(d, Intsts, ~0);
	wr(d, Ledgpio, Ledspd|Ledlnk|Ledfdx);
	wr(d, Flow, 0);
	wr(d, Afccfg, Afcdefault);
	wr(d, Vlan1, Ethp8021q);
	wr(d, Coecr, rr(d,Coecr)&~(Txcoe|Rxcoe)); /* TODO could offload checksums? */

	wr(d, Hashh, 0);
	wr(d, Hashl, 0);
	wr(d, Maccr, rr(d,Maccr)&~(Prms|Mcpas|Hpfilt));

	phyinit(d);

	wr(d, Intepctl, rr(d, Intepctl)|Phyint);
	wr(d, Maccr, rr(d, Maccr)|Txen|Rxen);
	wr(d, Txcfg, Txon);

	eptransmit = smsctransmit;
	epreceive = smscreceive;
	return 0;
}
예제 #6
0
int zft_read_header_segments(void)
{
    TRACE_FUN(ft_t_flow);

    zft_header_read = 0;
    TRACE_CATCH(zft_vmalloc_once(&zft_hseg_buf, FT_SEGMENT_SIZE),);
    TRACE_CATCH(ftape_read_header_segment(zft_hseg_buf),);
    TRACE(ft_t_info, "Segments written since first format: %d",
          (int)GET4(zft_hseg_buf, FT_SEG_CNT));
    zft_qic113 = (ft_format_code != fmt_normal &&
                  ft_format_code != fmt_1100ft &&
                  ft_format_code != fmt_425ft);
    TRACE(ft_t_info, "ft_first_data_segment: %d, ft_last_data_segment: %d",
          ft_first_data_segment, ft_last_data_segment);
    zft_capacity = zft_get_capacity();
    zft_old_ftape = zft_ftape_validate_label(&zft_hseg_buf[FT_LABEL]);
    if (zft_old_ftape) {
        TRACE(ft_t_info,
              "Found old ftaped tape, emulating eof marks, entering read-only mode");
        zft_ftape_extract_file_marks(zft_hseg_buf);
        TRACE_CATCH(zft_fake_volume_headers(zft_eof_map,
                                            zft_nr_eof_marks),);
    } else {
예제 #7
0
파일: prolific.c 프로젝트: dalmonian/harvey
static int
plgetparam(Serialport *p)
{
	uint8_t buf[ParamReqSz];
	int res;
	Serial *ser;

	ser = p->s;


	res = usbcmd(ser->dev, Rd2h | Rclass | Riface, GetLineReq,
		0, 0, buf, sizeof buf);
	p->baud = GET4(buf);

	/*
	 * with the Pl9 interface it is not possible to set `1.5' as stop bits
	 * for the prologic:
	 *	0 is 1 stop bit
	 *	1 is 1.5 stop bits
	 *	2 is 2 stop bits
	 */
	if(buf[4] == 1)
		fprint(2, "warning, stop bit set to 1.5 unsupported");
	else if(buf[4] == 0)
		p->stop = 1;
	else if(buf[4] == 2)
		p->stop = 2;
	p->parity = buf[5];
	p->bits = buf[6];

	dsprint(2, "serial: getparam: ");
	if(serialdebug)
		dumpbuf(buf, sizeof buf);
	dsprint(2, "serial: getparam res: %d\n", res);
	return res;
}
예제 #8
0
doc to_doc(char *s)
{
  int a[9];
  doc ret;
  memset(&ret, 0, sizeof(ret));

  while (*s) switch (*s) {
  case 'l': GET1(a[0] >= 1 && a[0] <= 1000,
            new_line(&ret, ret.size, a[0])); EOL; break;
  case 'i': GET0(ret.size >= 1,
            new_item(&ret.l[ret.size-1], ret.l[ret.size-1].size));
            EOL; break;
  case 'c': GET3(ret.size >= 1 &&
                 ret.l[ret.size-1].size >= 1 &&
                 a[0] >= CLEF_SOL && a[0] <= CLEF_DO &&
                 a[1] >= 0 && a[1] < ret.l[ret.size-1].n &&
                 a[2] >= -100 && a[2] <= 100,
            new_vertical_item(&ret.l[ret.size-1].i[ret.l[ret.size-1].size-1],
                          ret.l[ret.size-1].i[ret.l[ret.size-1].size-1].size,
                              CLEF, a[0], a[1], a[2]));
            EOL; break;
  case 'a': GET3(ret.size >= 1 &&
                 ret.l[ret.size-1].size >= 1 &&
                 (a[0] == DIESE || a[0] == BEMOL) &&
                 a[1] >= 0 && a[1] < ret.l[ret.size-1].n &&
                 a[2] >= -100 && a[2] <= 100,
            new_vertical_item(&ret.l[ret.size-1].i[ret.l[ret.size-1].size-1],
                          ret.l[ret.size-1].i[ret.l[ret.size-1].size-1].size,
                              ARMATURE, a[0], a[1], a[2]));
            EOL; break;
  case 'n': GET9(ret.size >= 1 &&
                 ret.l[ret.size-1].size >= 1 &&
                 a[0] >= 0 && a[0] <= 16 &&
                 a[1] >= 0 && a[1] <= 4 &&
                 a[2] >= NO_ALTERATION && a[2] <= BECARRE &&
                 a[3] >= 0 && a[3] < ret.l[ret.size-1].n &&
                 a[4] >= -100 && a[4] <= 100 &&
                 a[5] >= STEM_UP && a[5] <= STEM_NONE
                 /* l, m, o may be whatever, no check */,
            new_vertical_item(&ret.l[ret.size-1].i[ret.l[ret.size-1].size-1],
                          ret.l[ret.size-1].i[ret.l[ret.size-1].size-1].size,
                              NOTE, a[0], a[1], a[2], a[3], a[4], a[5],
                              a[6], a[7], a[8]));
            EOL; break;
  case 's': GET4(ret.size >= 1 &&
                 ret.l[ret.size-1].size >= 1 &&
                 a[0] >= 0 && a[0] <= 16 &&
                 a[1] >= 0 && a[1] <= 4 &&
                 a[2] >= 0 && a[2] < ret.l[ret.size-1].n &&
                 a[3] >= -100 && a[3] <= 100,
            new_vertical_item(&ret.l[ret.size-1].i[ret.l[ret.size-1].size-1],
                          ret.l[ret.size-1].i[ret.l[ret.size-1].size-1].size,
                              SILENCE, a[0], a[1], a[2], a[3]));
            EOL; break;
  case 'b': GET0(ret.size >= 1 &&
                 ret.l[ret.size-1].size >= 1,
            new_vertical_item(&ret.l[ret.size-1].i[ret.l[ret.size-1].size-1],
                          ret.l[ret.size-1].i[ret.l[ret.size-1].size-1].size,
                              BAR));
            EOL; break;
  case 't': GET3(ret.size >= 1 &&
                 ret.l[ret.size-1].size >= 1 &&
                 a[2] > 0,
            do {
              int tlen;
              char *t = malloc(a[2]+1); if (t == NULL) abort();
              s++;
              /* not pretty */
              while (*s && *s != ' ') s++; if (*s == ' ') s++;
              while (*s && *s != ' ') s++; if (*s == ' ') s++;
              while (*s && *s != ' ') s++; if (*s == ' ') s++;
              while (*s && *s != ' ') s++; if (*s == ' ') s++;
              for (tlen = 0; *s && tlen < a[2]; tlen++, s++) t[tlen] = *s;
              t[tlen] = 0;
              new_text(&ret.l[ret.size-1].i[ret.l[ret.size-1].size-1],
                       t, a[0], a[1]);
              free(t);
            } while (0));
            EOL; break;
  case '#': EOL; break; /* why not deal with comments? only 1 line of code! */
  default: printf("error in string to doc, ignoring a line\n"); EOL; break;
  }

  return ret;
}