コード例 #1
0
ファイル: ndma_ctst_tape.c プロジェクト: B-Rich/amanda
int
ndmca_test_tape_read (struct ndm_session *sess, ndmp9_error expect_err,
  char *buf, unsigned count)
{
	struct ndmconn *	conn = sess->plumb.tape;
	int			rc;

	/* close previous test if there is one */
	ndmca_test_close (sess);

	rc = ndmca_tape_read (sess, buf, count);

	rc = ndmca_test_check_expect (conn, rc, expect_err);

	return rc;
}
コード例 #2
0
ファイル: ndma_ctrl_media.c プロジェクト: tuxmux/bareos
int
ndmca_media_read_label (struct ndm_session *sess, char labbuf[])
{
	char		tape_read_buf[512];
	int		rc;
	char *		p;
	char *		q;

	ndmalogf (sess, 0, 2, "Reading label");

	*labbuf = 0;

	rc = ndmca_tape_read (sess, tape_read_buf, 512);

	if (rc == 0) {
		p = tape_read_buf;
		if (strncmp (p, "##ndmjob -m ", 12) == 0) {
			p += 12;
			rc = 'm';
		} else if (strncmp (p, "##ndmjob -V ", 12) == 0) {
			p += 12;
			rc = 'V';
		} else {
			rc = '?';
			p = 0;
		}
		if (p) {
			q = labbuf;
			while (*p && *p != '\n'
			 && q < &labbuf[NDMMEDIA_LABEL_MAX-1]) {
				*q++ = *p++;
			}
			*q = 0;
		}
	} else {
		rc = -1;
	}

	return rc;
}
コード例 #3
0
ファイル: ndma_ctst_tape.c プロジェクト: B-Rich/amanda
/*
 * Assumes tt_write() passed
 */
int
ndmca_tt_mtio (struct ndm_session *sess)
{
	int		rc;
	unsigned	n_rec;
	unsigned	recsize;
	unsigned	fileno, recno;
	u_long		count, resid;
	char *		what;
	char		note[128];
	char		pbuf[64*1024];
	char		buf[64*1024];

	ndmca_test_phase (sess, "T-MTIO", "Tape MTIO");

	rc = ndmca_test_tape_open(sess,NDMP9_NO_ERR,0,NDMP9_TAPE_READ_MODE);
	if (rc) return rc;

	rc = ndmca_test_tape_mtio (sess, NDMP9_NO_ERR, NDMP9_MTIO_REW, 1, 0);
	if (rc) return rc;

	for (fileno = 0; tt_series[fileno].n_rec > 0; fileno++) {
		n_rec = tt_series[fileno].n_rec;
		recsize = tt_series[fileno].recsize;

		sprintf (note, "Seek around tape file %d", fileno+1);
		ndmca_test_open (sess, note, 0);

		sprintf (note, "file #%d, %d records, %d bytes/rec",
				fileno+1, n_rec, recsize);
		ndmca_test_log_note (sess, 2, note);

		what = "rew";
		count = 1;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_REW, count, &resid);
		if (rc) goto fail;

		what = "rew resid";
		if (resid != 0)
			goto fail;

		CHECK_FILENO_RECNO ("rew", 0, 0);


		what = "fsf(n)";
		count = fileno;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSF, count, &resid);
		if (rc) goto fail;

		what = "fsf(n) resid";
		if (resid != 0)
			goto fail;

		CHECK_FILENO_RECNO ("fsf", fileno, 0);


		what = "fsr(1m)";
		count = 1000000;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSR, count, &resid);
		if (rc) goto fail;

		what = "fsr(1m) resid";
		if (n_rec + resid != count)
			goto fail;

		if (sess->plumb.tape->protocol_version < 4) {
		    CHECK_FILENO_RECNO ("fsr(1m)", fileno + 1, 0);

		    what = "bsf 1 after fsr(1m)";
		    count = 1;
		    rc = ndmca_tape_mtio (sess, NDMP9_MTIO_BSF, count, 0);
		    if (rc) goto fail;

		    CHECK_FILENO_RECNO (what, fileno, -1);

		    recno = n_rec;
		} else {
		    /* EOT side of EOF marker */
		    recno = n_rec;
		    CHECK_FILENO_RECNO ("fsr(1m)", fileno, recno);
		}

		what = "bsr(1m)";
		count = 1000000;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_BSR, count, &resid);
		if (rc) goto fail;

		what = "bsr(1m) resid";
		if (n_rec + resid != count)
			goto fail;

		if ((fileno > 0) && (sess->plumb.tape->protocol_version < 4)) {
		    /* at BOT side of EOF marker (not BOT) */
		    CHECK_FILENO_RECNO ("bsr(1m)", fileno - 1, -1);

		    what = "fsf 1 after bsr(1m)";
		    count = 1;
		    rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSF, count, 0);
		    if (rc) goto fail;
		}

		recno = 0;
		CHECK_FILENO_RECNO ("bsr(1m)", fileno, recno);

		what = "fsr(0)";
		count = 0;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSR, count, &resid);
		if (rc) goto fail;

		what = "fsr(0) resid";
		if (resid != 0)
			goto fail;

		recno = 0;
		CHECK_FILENO_RECNO ("fsr(0)", fileno, recno);


		what = "fsr(x)";
		count = n_rec / 2;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSR, count, &resid);
		if (rc) goto fail;

		what = "fsr(x) resid";
		if (resid != 0)
			goto fail;

		recno = n_rec / 2;
		CHECK_FILENO_RECNO ("fsr(x)", fileno, recno);

		what = "fsr(x) read";
		rc = ndmca_tape_read (sess, buf, recsize);
		if (rc) goto fail;

		what = "fsr(x) compare";
		ndmca_test_fill_data (pbuf, recsize, recno, fileno);
		if (bcmp (buf, pbuf, recsize) != 0)
			goto fail;

		recno++;	/* caused by tape_read */

		if (recno > 1) {
			what = "bsr(2)";
			count = 2;
			rc = ndmca_tape_mtio (sess, NDMP9_MTIO_BSR,
						count, &resid);
			if (rc) goto fail;

			what = "bsr(2) resid";
			if (resid != 0)
				goto fail;

			recno -= count;
			CHECK_FILENO_RECNO ("bsr(2)", fileno, recno);

			what = "bsr(2) read";
			rc = ndmca_tape_read (sess, buf, recsize);
			if (rc) goto fail;

			what = "bsr(2) compare";
			ndmca_test_fill_data (pbuf, recsize, recno, fileno);
			if (bcmp (buf, pbuf, recsize) != 0)
				goto fail;
		}

		sprintf (buf, "Passed %s", note);
		ndmca_test_log_step (sess, 2, buf);
	}

	rc = ndmca_test_tape_close (sess, NDMP9_NO_ERR);
	if (rc) return rc;

	return 0;

  fail:
	sprintf (buf, "Failed %s: %s", what, note);
	ndmca_test_fail (sess, buf);
	return -1;
}
コード例 #4
0
ファイル: ndma_ctst_tape.c プロジェクト: B-Rich/amanda
/*
 * Assumes tt_write() passed
 */
int
ndmca_tt_read (struct ndm_session *sess)
{
	int		rc;
	unsigned	n_rec;
	unsigned	recsize;
	unsigned	fileno, recno;
	char *		what;
	char		note[128];
	char		pbuf[64*1024];
	char		buf[64*1024];

	ndmca_test_phase (sess, "T-READ", "Tape Read Series");

	rc = ndmca_test_tape_open(sess,NDMP9_NO_ERR,0,NDMP9_TAPE_READ_MODE);
	if (rc) return rc;

	for (fileno = 0; tt_series[fileno].n_rec > 0; fileno++) {
		n_rec = tt_series[fileno].n_rec;
		recsize = tt_series[fileno].recsize;

		sprintf (note, "Read tape file %d", fileno+1);
		ndmca_test_open (sess, note, 0);

		sprintf (note, "file #%d, %d records, %d bytes/rec",
				fileno+1, n_rec, recsize);
		ndmca_test_log_note (sess, 2, note);

		for (recno = 0; recno < n_rec; recno++) {
			ndmca_test_fill_data (pbuf, recsize, recno, fileno);

			what = "read";
			rc = ndmca_tape_read (sess, buf, recsize);
			if (rc) goto fail;

			CHECK_FILENO_RECNO ("read", fileno, recno+1);

			what = "compare";
#if 0
			if (bcmp (buf, pbuf, recsize) != 0)
				goto fail;
#else
			if (bcmp (buf, pbuf, recsize) != 0) {
				unsigned char *expect_p = (unsigned char *)pbuf;
				unsigned char *got_p = (unsigned char *)buf;
				unsigned int i, f;
				for(f = i = 0;
				    f < 64 && i < recsize;
				    i++, expect_p++, got_p++) {
				    if (*expect_p != *got_p) {
					char tmp[80];
					sprintf (tmp,
						 "%d: 0x%x => 0x%x",
						 i, *expect_p, *got_p);
					ndmalogf (sess, "DATA", 6, tmp);
					f++;
				    }
				}
				goto fail;
			}
#endif
		}

		what = "eof read";
		rc = ndmca_test_tape_read (sess, NDMP9_EOF_ERR, buf, recsize);
		if (rc) goto fail;

		if (sess->plumb.tape->protocol_version > 3) {
		    CHECK_FILENO_RECNO ("eof", fileno, -1);

		    what = "skip filemark";
		    rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSF, 1, 0);
		    if (rc) goto fail;

		    CHECK_FILENO_RECNO ("skip", fileno+1, 0);
		} else {
		    CHECK_FILENO_RECNO ("eof", fileno+1, 0);
		}

		sprintf (buf, "Passed tape read %s", note);
		ndmca_test_log_step (sess, 2, buf);
	}

	rc = ndmca_test_tape_mtio (sess, NDMP9_NO_ERR, NDMP9_MTIO_REW, 1, 0);
	if (rc) return rc;

	rc = ndmca_test_tape_close (sess, NDMP9_NO_ERR);
	if (rc) return rc;

	return 0;

  fail:
	sprintf (buf, "Failed %s recno=%d; %s", what, recno, note);
	ndmca_test_fail (sess, buf);
	return -1;
}
コード例 #5
0
ファイル: ndma_ctst_tape.c プロジェクト: B-Rich/amanda
int
ndmca_tt_basic_read (struct ndm_session *sess)
{
	int		rc, ix;
	char		buf[2048];
	ndmp9_error	expect_errs[5];

	ndmca_test_phase (sess, "T-BR", "Tape Read Basics");

	rc = ndmca_test_tape_read (sess, NDMP9_DEV_NOT_OPEN_ERR, buf, 1024);
	if (rc) return rc;


	/*
	 * Read w/ bogus lengths -- mode=READ_MODE
	 */
	rc = ndmca_test_tape_open(sess,NDMP9_NO_ERR,0,NDMP9_TAPE_READ_MODE);
	if (rc) return rc;

	/* read/len=0 MUST be NDMP[23]_NO_ERR or NDMP[23]_ILLEGAL_ARGS */
	/* read/len=0 MUST be NDMP4_NO_ERR */
	ix = 0;
	if (sess->plumb.tape->protocol_version < 4) {
		expect_errs[ix++] = NDMP9_ILLEGAL_ARGS_ERR;
	}
	expect_errs[ix++] = NDMP9_NO_ERR;
	expect_errs[ix++] = -1;

	rc = ndmca_tape_read (sess, buf, 0);

	rc = ndmca_test_check_expect_errs (sess->plumb.tape, rc, expect_errs);
	if (rc) return rc;

	rc = ndmca_test_tape_read(sess,NDMP9_ILLEGAL_ARGS_ERR,buf,0x80000000);
	if (rc) return rc;

	rc = ndmca_test_tape_mtio (sess, NDMP9_NO_ERR, NDMP9_MTIO_REW, 1, 0);
	if (rc) return rc;

	rc = ndmca_test_tape_close (sess, NDMP9_NO_ERR);
	if (rc) return rc;

	/*
	 * Read works -- mode=WRITE_MODE (just to mix it up)
	 */
	rc = ndmca_test_tape_open(sess,NDMP9_NO_ERR,0,NDMP9_TAPE_RDWR_MODE);
	if (rc) return rc;

	rc = ndmca_test_tape_read (sess, NDMP9_NO_ERR, buf, 1024);
	if (rc) return rc;

	rc = ndmca_test_tape_read (sess, NDMP9_EOF_ERR, buf, 1024);
	if (rc) return rc;

	rc = ndmca_test_tape_mtio (sess, NDMP9_NO_ERR, NDMP9_MTIO_REW, 1, 0);
	if (rc) return rc;

	rc = ndmca_test_tape_close (sess, NDMP9_NO_ERR);
	if (rc) return rc;


	/*
	 * Read works w/ oversize -- mode=READ_MODE (just to mix it up)
	 */
	rc = ndmca_test_tape_open(sess,NDMP9_NO_ERR,0,NDMP9_TAPE_READ_MODE);
	if (rc) return rc;

	rc = ndmca_test_tape_read_2cnt (sess, NDMP9_NO_ERR, buf, 2048, 1024);
	if (rc) return rc;

	rc = ndmca_test_tape_read_2cnt (sess, NDMP9_EOF_ERR, buf, 2048, 1024);
	if (rc) return rc;

	rc = ndmca_test_tape_mtio (sess, NDMP9_NO_ERR, NDMP9_MTIO_REW, 1, 0);
	if (rc) return rc;

	rc = ndmca_test_tape_close (sess, NDMP9_NO_ERR);
	if (rc) return rc;


	/*
	 * Read works w/ undersize -- mode=READ_MODE (just to mix it up)
	 */
	rc = ndmca_test_tape_open(sess,NDMP9_NO_ERR,0,NDMP9_TAPE_READ_MODE);
	if (rc) return rc;

	rc = ndmca_test_tape_read_2cnt (sess, NDMP9_NO_ERR, buf, 512, 512);
	if (rc) return rc;

	rc = ndmca_test_tape_read_2cnt (sess, NDMP9_EOF_ERR, buf, 512, 512);
	if (rc) return rc;

	rc = ndmca_test_tape_mtio (sess, NDMP9_NO_ERR, NDMP9_MTIO_REW, 1, 0);
	if (rc) return rc;

	rc = ndmca_test_tape_close (sess, NDMP9_NO_ERR);
	if (rc) return rc;

	return 0;	/* pass */
}