SCP: Normalize writelock/read only behavior

Setting a unit to write locked specifically allows only read access.
- If this is done while a unit is attached, it is up to device logic to
  limit write activity until it is detached.
- If this is done while a unit is not attached, a subsequent attach
  opens the container read only.
This commit is contained in:
Mark Pizzolato 2022-03-04 21:13:37 -08:00
parent 2fb741046d
commit a50dca0ff0

7
scp.c
View file

@ -8011,14 +8011,17 @@ t_stat set_writelock (UNIT *uptr, int32 val, CONST char *cptr, void *desc)
{ {
if (((uptr->flags & UNIT_WPRT) != 0) == val) /* Already set as desired? */ if (((uptr->flags & UNIT_WPRT) != 0) == val) /* Already set as desired? */
return SCPE_OK; /* Do nothing */ return SCPE_OK; /* Do nothing */
if (val) /* Lock? */ if (val) { /* Lock? */
uptr->flags |= UNIT_WLK; /* Do it. */ uptr->flags |= UNIT_WLK; /* Do it. */
if ((uptr->flags & UNIT_ATT) == 0)
uptr->flags |= UNIT_RO; /* Next attach will be Read-Only. */
}
else /* Unlock */ else /* Unlock */
if (((uptr->flags & UNIT_ATT) != 0) && /* Transition from Locked to Unlock while attached read-only? */ if (((uptr->flags & UNIT_ATT) != 0) && /* Transition from Locked to Unlock while attached read-only? */
((uptr->flags & UNIT_RO) != 0)) ((uptr->flags & UNIT_RO) != 0))
return sim_messagef (SCPE_ALATT, "%s: Can't enable write when attached read only\n", sim_uname (uptr)); return sim_messagef (SCPE_ALATT, "%s: Can't enable write when attached read only\n", sim_uname (uptr));
else else
uptr->flags &= ~UNIT_WLK; uptr->flags &= ~UNIT_WPRT;
return SCPE_OK; return SCPE_OK;
} }