PDP11/VAX: Use semi-unique drive serial numbers when writing BAD144 bad block info to newly created disk images

The 32 bit drive serial number is determined by hashing the newly create filename.
This commit is contained in:
Mark Pizzolato 2013-09-09 03:39:00 -07:00
parent e18d7e86e4
commit 786cda7c1b
2 changed files with 31 additions and 2 deletions

View file

@ -35,6 +35,7 @@
#endif #endif
#include "sim_sock.h" #include "sim_sock.h"
#include "sim_tmxr.h" #include "sim_tmxr.h"
#include "sim_ether.h"
extern int32 autcon_enb; extern int32 autcon_enb;
extern int32 int_vec[IPL_HLVL][32]; extern int32 int_vec[IPL_HLVL][32];
@ -754,7 +755,8 @@ t_stat pdp11_bad_block (UNIT *uptr, int32 sec, int32 wds)
int32 i; int32 i;
t_addr da; t_addr da;
uint16 *buf; uint16 *buf;
uint32 packid = (uint32)time(NULL); char *namebuf, *c;
uint32 packid;
if ((sec < 2) || (wds < 16)) if ((sec < 2) || (wds < 16))
return SCPE_ARG; return SCPE_ARG;
@ -769,6 +771,18 @@ if (sim_fseek (uptr->fileref, da, SEEK_SET))
return SCPE_IOERR; return SCPE_IOERR;
if ((buf = (uint16 *) malloc (wds * sizeof (uint16))) == NULL) if ((buf = (uint16 *) malloc (wds * sizeof (uint16))) == NULL)
return SCPE_MEM; return SCPE_MEM;
if ((namebuf = (char *) malloc (1 + strlen (uptr->filename))) == NULL) {
free (buf);
return SCPE_MEM;
}
strcpy (namebuf, uptr->filename);
if ((c = strrchr (namebuf, '/')))
strcpy (namebuf, c+1);
if ((c = strrchr (namebuf, '\\')))
strcpy (namebuf, c+1);
if ((c = strrchr (namebuf, ']')))
strcpy (namebuf, c+1);
packid = eth_crc32(0, namebuf, strlen (namebuf));
buf[0] = (uint16)packid; buf[0] = (uint16)packid;
buf[1] = (uint16)(packid >> 16); buf[1] = (uint16)(packid >> 16);
buf[2] = buf[3] = 0; buf[2] = buf[3] = 0;
@ -776,6 +790,7 @@ for (i = 4; i < wds; i++)
buf[i] = 0177777u; buf[i] = 0177777u;
for (i = 0; (i < sec) && (i < 10); i++) for (i = 0; (i < sec) && (i < 10); i++)
sim_fwrite (buf, sizeof (uint16), wds, uptr->fileref); sim_fwrite (buf, sizeof (uint16), wds, uptr->fileref);
free (namebuf);
free (buf); free (buf);
if (ferror (uptr->fileref)) if (ferror (uptr->fileref))
return SCPE_IOERR; return SCPE_IOERR;

View file

@ -74,6 +74,7 @@ Internal routines:
#include "sim_defs.h" #include "sim_defs.h"
#include "sim_disk.h" #include "sim_disk.h"
#include "sim_ether.h"
#include <ctype.h> #include <ctype.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -1404,7 +1405,8 @@ t_addr da;
int32 wds = ctx->sector_size/sizeof (uint16); int32 wds = ctx->sector_size/sizeof (uint16);
uint16 *buf; uint16 *buf;
DEVICE *dptr; DEVICE *dptr;
uint32 packid = (uint32)time(NULL); char *namebuf, *c;
uint32 packid;
if ((sec < 2) || (wds < 16)) if ((sec < 2) || (wds < 16))
return SCPE_ARG; return SCPE_ARG;
@ -1420,6 +1422,18 @@ if (!get_yn ("Overwrite last track? [N]", FALSE))
return SCPE_OK; return SCPE_OK;
if ((buf = (uint16 *) malloc (wds * sizeof (uint16))) == NULL) if ((buf = (uint16 *) malloc (wds * sizeof (uint16))) == NULL)
return SCPE_MEM; return SCPE_MEM;
if ((namebuf = (char *) malloc (1 + strlen (uptr->filename))) == NULL) {
free (buf);
return SCPE_MEM;
}
strcpy (namebuf, uptr->filename);
if ((c = strrchr (namebuf, '/')))
strcpy (namebuf, c+1);
if ((c = strrchr (namebuf, '\\')))
strcpy (namebuf, c+1);
if ((c = strrchr (namebuf, ']')))
strcpy (namebuf, c+1);
packid = eth_crc32(0, namebuf, strlen (namebuf));
buf[0] = (uint16)packid; buf[0] = (uint16)packid;
buf[1] = (uint16)(packid >> 16); buf[1] = (uint16)(packid >> 16);
buf[2] = buf[3] = 0; buf[2] = buf[3] = 0;