1
0
mirror of https://github.com/simh/simh.git synced 2026-03-03 18:16:24 +00:00

TAPE: Make sure that all tape library APIs only work after sim_tape_attach

- Detects and fixes the problem reported in #345
This commit is contained in:
Mark Pizzolato
2016-10-20 13:32:51 -07:00
parent 8178816c3f
commit 17abb1223a
2 changed files with 50 additions and 2 deletions

Binary file not shown.

View File

@@ -163,6 +163,8 @@ struct tape_context {
#define AIO_CALLSETUP \
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx; \
\
if (ctx == NULL) \
return sim_messagef (SCPE_IERR, "Bad Attach\n"); \
if ((!callback) || !ctx->asynch_io)
#define AIO_CALL(op, _buf, _bc, _fc, _max, _vbc, _gaplen, _bpi, _obj, _callback)\
@@ -348,7 +350,9 @@ if (ctx) {
}
}
#else
#define AIO_CALLSETUP
#define AIO_CALLSETUP \
if (uptr->tape_ctx == NULL) \
return sim_messagef (SCPE_IERR, "Bad Attach\n");
#define AIO_CALL(op, _buf, _fc, _bc, _max, _vbc, _gaplen, _bpi, _obj, _callback) \
if (_callback) \
(_callback) (uptr, r);
@@ -522,7 +526,7 @@ uint32 f = MT_GET_FMT (uptr);
t_stat r;
t_bool auto_format = FALSE;
if ((uptr == NULL) || !(uptr->flags & UNIT_ATT))
if ((ctx == NULL) || (uptr == NULL) || !(uptr->flags & UNIT_ATT))
return SCPE_IERR;
if (uptr->io_flush)
@@ -586,6 +590,8 @@ static void sim_tape_data_trace(UNIT *uptr, const uint8 *data, size_t len, const
{
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
if (ctx == NULL)
return;
if (sim_deb && (ctx->dptr->dctrl & reason))
sim_data_trace(ctx->dptr, uptr, (detail ? data : NULL), "", len, txt, reason);
}
@@ -692,6 +698,8 @@ MT_CLR_PNU (uptr); /* clear the position-no
if ((uptr->flags & UNIT_ATT) == 0) /* if the unit is not attached */
return MTSE_UNATT; /* then quit with an error */
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_fseek (uptr->fileref, uptr->pos, SEEK_SET); /* set the initial tape position */
@@ -902,6 +910,8 @@ MT_CLR_PNU (uptr); /* clear the position-no
if ((uptr->flags & UNIT_ATT) == 0) /* if the unit is not attached */
return MTSE_UNATT; /* then quit with an error */
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
if (sim_tape_bot (uptr)) /* if the unit is positioned at the BOT */
return MTSE_BOT; /* then reading backward is not possible */
@@ -1065,6 +1075,8 @@ t_mtrlnt i, tbc, rbc;
t_addr opos;
t_stat st;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_rdrecf(unit=%d, buf=%p, max=%d)\n", (int)(uptr-ctx->dptr->units), buf, max);
opos = uptr->pos; /* old position */
@@ -1129,6 +1141,8 @@ uint32 f = MT_GET_FMT (uptr);
t_mtrlnt i, rbc, tbc;
t_stat st;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_rdrecr(unit=%d, buf=%p, max=%d)\n", (int)(uptr-ctx->dptr->units), buf, max);
if (MTSE_OK != (st = sim_tape_rdlntr (uptr, &tbc))) /* read rec lnt */
@@ -1179,6 +1193,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
uint32 f = MT_GET_FMT (uptr);
t_mtrlnt sbc;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wrrecf(unit=%d, buf=%p, bc=%d)\n", (int)(uptr-ctx->dptr->units), buf, bc);
sim_tape_data_trace(uptr, buf, bc, "Record Write", ctx->dptr->dctrl & MTSE_DBG_DAT, MTSE_DBG_STR);
@@ -1239,6 +1255,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
MT_CLR_PNU (uptr);
if ((uptr->flags & UNIT_ATT) == 0) /* not attached? */
return MTSE_UNATT;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
if (sim_tape_wrp (uptr)) /* write prot? */
return MTSE_WRP;
sim_fseek (uptr->fileref, uptr->pos, SEEK_SET); /* set pos */
@@ -1258,6 +1276,8 @@ t_stat sim_tape_wrtmk (UNIT *uptr)
{
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wrtmk(unit=%d)\n", (int)(uptr-ctx->dptr->units));
if (MT_GET_FMT (uptr) == MTUF_F_P7B) { /* P7B? */
uint8 buf = P7B_EOF; /* eof mark */
@@ -1282,6 +1302,8 @@ t_stat sim_tape_wreom (UNIT *uptr)
t_stat result;
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wreom(unit=%d)\n", (int)(uptr-ctx->dptr->units));
if (MT_GET_FMT (uptr) == MTUF_F_P7B) /* cant do P7B */
return MTSE_FMT;
@@ -1310,6 +1332,8 @@ t_stat sim_tape_wreomrw (UNIT *uptr)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat r;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wreomrw(unit=%d)\n", (int)(uptr-ctx->dptr->units));
if (MT_GET_FMT (uptr) == MTUF_F_P7B) /* cant do P7B */
return MTSE_FMT;
@@ -1442,6 +1466,8 @@ const uint32 format = MT_GET_FMT (uptr); /* tape format */
const uint32 meta_size = sizeof (t_mtrlnt); /* bytes per metadatum */
const uint32 min_rec_size = 2 + sizeof (t_mtrlnt) * 2; /* smallest data record size */
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wrgap(unit=%d, gaplen=%u)\n", (int)(uptr-ctx->dptr->units), gaplen);
MT_CLR_PNU (uptr);
@@ -1609,6 +1635,8 @@ t_stat sim_tape_sprecf (UNIT *uptr, t_mtrlnt *bc)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_sprecf(unit=%d)\n", (int)(uptr-ctx->dptr->units));
st = sim_tape_rdlntf (uptr, bc); /* get record length */
@@ -1650,6 +1678,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
t_mtrlnt tbc;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_sprecsf(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
*skipped = 0;
@@ -1695,6 +1725,8 @@ t_stat sim_tape_sprecr (UNIT *uptr, t_mtrlnt *bc)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_sprecr(unit=%d)\n", (int)(uptr-ctx->dptr->units));
if (MT_TST_PNU (uptr)) {
@@ -1742,6 +1774,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
t_mtrlnt tbc;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_sprecsr(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
*skipped = 0;
@@ -1791,6 +1825,8 @@ t_stat st;
t_bool last_tapemark = FALSE;
uint32 filerecsskipped;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_spfilebyrecf(unit=%d, count=%d, check_leot=%d)\n", (int)(uptr-ctx->dptr->units), count, check_leot);
if (check_leot) {
@@ -1859,6 +1895,8 @@ t_stat sim_tape_spfilef (UNIT *uptr, uint32 count, uint32 *skipped)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
uint32 totalrecsskipped;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_spfilef(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
return sim_tape_spfilebyrecf (uptr, count, skipped, &totalrecsskipped, FALSE);
@@ -1900,6 +1938,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
uint32 filerecsskipped;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_spfilebyrecr(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
*skipped = 0;
@@ -1953,6 +1993,8 @@ t_stat sim_tape_spfiler (UNIT *uptr, uint32 count, uint32 *skipped)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
uint32 totalrecsskipped;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_spfiler(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
return sim_tape_spfilebyrecr (uptr, count, skipped, &totalrecsskipped);
@@ -1974,6 +2016,8 @@ t_stat sim_tape_rewind (UNIT *uptr)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
if (uptr->flags & UNIT_ATT) {
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n");/* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_rewind(unit=%d)\n", (int)(uptr-ctx->dptr->units));
}
uptr->pos = 0;
@@ -1997,6 +2041,8 @@ t_stat sim_tape_position (UNIT *uptr, uint32 flags, uint32 recs, uint32 *recsski
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat r = MTSE_OK;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_position(unit=%d, flags=0x%X, recs=%d, files=%d)\n", (int)(uptr-ctx->dptr->units), flags, recs, files);
*recsskipped = *filesskipped = *objectsskipped = 0;
@@ -2061,6 +2107,8 @@ MT_CLR_PNU (uptr);
if (!(uptr->flags & UNIT_ATT)) /* attached? */
return SCPE_OK;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_reset(unit=%d)\n", (int)(uptr-ctx->dptr->units));
_sim_tape_io_flush(uptr);