From 614ad5209166721f3945421cbfc977f3a54ed3c5 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sun, 22 Mar 2020 09:54:54 -0700 Subject: [PATCH] All: Fix devices that attach files and have special meaning for -A switch The -A attach time switch implicitly means to open files in append mode. Some devices used -A to indicate ASCII data or AUTOSIZE of disk or fixed size tapes - DECtape. These devices are either read only devices (Paper tape readers or card readers), so explicit forcing of the attach to be -R avoids unexpected positioning errors. The random access Disk and fixed sized tapes buffer the container contents in memory so append mode isn't relevant, but care must be taken to assure that the buffer reading starts at the beginning of the file without regard to the explicit open mode. As reported in #821 --- H316/h316_stddev.c | 2 ++ LGP/lgp_stddev.c | 2 ++ PDP1/pdp1_dt.c | 1 + PDP1/pdp1_stddev.c | 1 + PDP10/kx10_dt.c | 1 + PDP10/pdp6_dtc.c | 1 + PDP11/pdp11_tc.c | 1 + PDP18B/pdp18b_dt.c | 1 + PDP18B/pdp18b_stddev.c | 1 + PDP8/pdp8_dt.c | 1 + PDP8/pdp8_td.c | 1 + 11 files changed, 13 insertions(+) diff --git a/H316/h316_stddev.c b/H316/h316_stddev.c index ac005af1..ffe2876a 100644 --- a/H316/h316_stddev.c +++ b/H316/h316_stddev.c @@ -424,6 +424,8 @@ t_stat r; if (!(uptr->flags & UNIT_ATTABLE)) /* not tti,tto */ return SCPE_NOFNC; +if (strcmp ("PTR", sim_uname (uptr)) == 0) /* PTR is read only */ + sim_switches |= SWMASK ('R'); if ((r = attach_unit (uptr, cptr))) return r; if (sim_switches & SWMASK ('A')) /* -a? ASCII */ diff --git a/LGP/lgp_stddev.c b/LGP/lgp_stddev.c index 278d3cf8..416fe183 100644 --- a/LGP/lgp_stddev.c +++ b/LGP/lgp_stddev.c @@ -618,6 +618,8 @@ t_stat tap_attach (UNIT *uptr, CONST char *cptr) { t_stat r; +if (strcmp ("PTR", sim_uname (uptr)) == 0) + sim_switches |= SWMASK ('R'); /* PTR is read only */ if ((r = attach_unit (uptr,cptr)) != SCPE_OK) return r; if ((sim_switches & SWMASK ('F')) || diff --git a/PDP1/pdp1_dt.c b/PDP1/pdp1_dt.c index 856c2393..39478e80 100644 --- a/PDP1/pdp1_dt.c +++ b/PDP1/pdp1_dt.c @@ -1023,6 +1023,7 @@ else if (uptr->flags & UNIT_11FMT) sim_printf ("16b format"); else sim_printf ("18b/36b format"); sim_printf (", buffering file in memory\n"); +sim_fseek (uptr->fileref, 0, SEEK_SET); /* start at the beginning of file */ if (uptr->flags & UNIT_8FMT) { /* 12b? */ for (ba = 0; ba < uptr->capac; ) { /* loop thru file */ k = fxread (pdp8b, sizeof (uint16), D8_NBSIZE, uptr->fileref); diff --git a/PDP1/pdp1_stddev.c b/PDP1/pdp1_stddev.c index 7af437be..f18eeea3 100644 --- a/PDP1/pdp1_stddev.c +++ b/PDP1/pdp1_stddev.c @@ -458,6 +458,7 @@ ptr_leader = PTR_LEADER; /* set up leader */ if (sim_switches & SWMASK ('A')) uptr->flags = uptr->flags | UNIT_ASCII; else uptr->flags = uptr->flags & ~UNIT_ASCII; +sim_switches |= SWMASK ('R'); return attach_unit (uptr, cptr); } diff --git a/PDP10/kx10_dt.c b/PDP10/kx10_dt.c index 449e7889..0e82c56d 100644 --- a/PDP10/kx10_dt.c +++ b/PDP10/kx10_dt.c @@ -1182,6 +1182,7 @@ t_stat dt_attach (UNIT *uptr, CONST char *cptr) sim_printf ("16b format"); else sim_printf ("18b/36b format"); sim_printf (", buffering file in memory\n"); + (void)sim_fseek (uptr->fileref, 0, SEEK_SET); /* start at the beginning of file */ uptr->io_flush = dt_flush; if (uptr->flags & UNIT_8FMT) { /* 12b? */ for (ba = 0; ba < uptr->capac; ) { /* loop thru file */ diff --git a/PDP10/pdp6_dtc.c b/PDP10/pdp6_dtc.c index c4e1567a..4ad93c93 100644 --- a/PDP10/pdp6_dtc.c +++ b/PDP10/pdp6_dtc.c @@ -1194,6 +1194,7 @@ dtc_attach (UNIT *uptr, CONST char *cptr) sim_printf ("16b format"); else sim_printf ("18b/36b format"); sim_printf (", buffering file in memory\n"); + (void)sim_fseek (uptr->fileref, 0, SEEK_SET); /* start at the beginning of file */ uptr->WRITTEN = 0; uptr->io_flush = dtc_flush; if (uptr->flags & UNIT_8FMT) { /* 12b? */ diff --git a/PDP11/pdp11_tc.c b/PDP11/pdp11_tc.c index 8012651a..5e27c756 100644 --- a/PDP11/pdp11_tc.c +++ b/PDP11/pdp11_tc.c @@ -1299,6 +1299,7 @@ else if (uptr->flags & UNIT_11FMT) sim_printf ("16b format"); else sim_printf ("18b/36b format"); sim_printf (", buffering file in memory\n"); +(void)sim_fseek (uptr->fileref, 0, SEEK_SET); /* start at the beginning of file */ uptr->io_flush = dt_flush; if (uptr->flags & UNIT_8FMT) { /* 12b? */ for (ba = 0; ba < uptr->capac; ) { /* loop thru file */ diff --git a/PDP18B/pdp18b_dt.c b/PDP18B/pdp18b_dt.c index 4b42a0ec..1c5922b1 100644 --- a/PDP18B/pdp18b_dt.c +++ b/PDP18B/pdp18b_dt.c @@ -1458,6 +1458,7 @@ else if (uptr->flags & UNIT_11FMT) sim_printf ("16b format"); else sim_printf ("18b/36b format"); sim_printf (", buffering file in memory\n"); +(void)sim_fseek (uptr->fileref, 0, SEEK_SET); /* start at the beginning of file */ uptr->io_flush = dt_flush; if (uptr->flags & UNIT_8FMT) { /* 12b? */ for (ba = 0; ba < uptr->capac; ) { /* loop thru file */ diff --git a/PDP18B/pdp18b_stddev.c b/PDP18B/pdp18b_stddev.c index 43dc3ce4..2dcc9f17 100644 --- a/PDP18B/pdp18b_stddev.c +++ b/PDP18B/pdp18b_stddev.c @@ -651,6 +651,7 @@ t_stat ptr_attach (UNIT *uptr, CONST char *cptr) { t_stat reason; +sim_switches |= SWMASK ('R'); reason = attach_unit (uptr, cptr); if (reason != SCPE_OK) return reason; diff --git a/PDP8/pdp8_dt.c b/PDP8/pdp8_dt.c index 7ac2330a..7d4f1e8c 100644 --- a/PDP8/pdp8_dt.c +++ b/PDP8/pdp8_dt.c @@ -1248,6 +1248,7 @@ else if (uptr->flags & UNIT_11FMT) sim_printf ("16b format"); else sim_printf ("18b/36b format"); sim_printf (", buffering file in memory\n"); +(void)sim_fseek (uptr->fileref, 0, SEEK_SET); /* start at the beginning of file */ uptr->io_flush = dt_flush; if (uptr->flags & UNIT_8FMT) /* 12b? */ uptr->hwmark = fxread (uptr->filebuf, sizeof (uint16), diff --git a/PDP8/pdp8_td.c b/PDP8/pdp8_td.c index 7ae902f0..e01daff8 100644 --- a/PDP8/pdp8_td.c +++ b/PDP8/pdp8_td.c @@ -808,6 +808,7 @@ else if (uptr->flags & UNIT_11FMT) sim_printf ("16b format"); else sim_printf ("18b/36b format"); sim_printf (", buffering file in memory\n"); +(void)sim_fseek (uptr->fileref, 0, SEEK_SET); /* start at the beginning of file */ uptr->io_flush = td_flush; if (uptr->flags & UNIT_8FMT) /* 12b? */ uptr->hwmark = fxread (uptr->filebuf, sizeof (uint16),