static char *sccsid
= "@(#)bad144.c 4.2 (Berkeley) 81/05/11";
* This program prints and/or initializes a bad block record for a pack,
* in the format used by the DEC standard 144.
* Only reads/writes the first of the bad block record (sector 0
* of the last track of the disk); in fact, there are copies
* of the information in the first 5 even numbered sectors of this
* track, but UNIX uses only the first, and we don't bother with the
* It is preferable to write the bad information with a standard formatter,
* but this program will do in a pinch, e.g. if the bad information is
* accidentally wiped out this is a much faster way of restoring it than
* reformatting. To add a new bad sector the formatter must be used in
* general since UNIX doesn't have on-line formatters to write the BSE
* error in the header. The
char *di_type
; /* type name of disk */
int di_size
; /* size of entire volume in sectors */
int di_nsect
; /* sectors per track */
int di_ntrak
; /* tracks per cylinder */
"rm05", 32*19*823, 32, 19,
"rp06", 22*19*815, 22, 19,
"rm80", 31*14*559, 31, 14,
"rp05", 22*19*411, 22, 19,
"rp07", 50*32*630, 50, 32,
register struct diskinfo
*di
;
register struct bt_bad
*bt
;
int i
, f
, bad
, oldbad
, errs
;
fprintf(stderr
, "usage: bad type disk [ snum [ bn ... ] ]\n");
fprintf(stderr
, "e.g.: bad rk07 hk0\n");
for (di
= diskinfo
; di
->di_type
; di
++)
if (!strcmp(di
->di_type
, argv
[0]))
fprintf(stderr
, "%s: not a known disk type\n", argv
[0]);
fprintf(stderr
, "known types:");
for (di
= diskinfo
; di
->di_type
; di
++)
fprintf(stderr
, " %s", di
->di_type
);
sprintf(name
, "/dev/r%sc", argv
[1]);
lseek(f
, 512 * (di
->di_size
- di
->di_nsect
), 0);
printf("bad block information at 0x%x in %s:\n",
if (read(f
, &dkbad
, sizeof (struct dkbad
)) !=
fprintf("%s: can't read bad block info (wrong type disk?)\n");
printf("cartidge serial number: %d(10)\n", dkbad
.bt_csn
);
printf("alignment cartridge\n");
printf("bt_flag=%x(16)?\n", dkbad
.bt_flag
);
for (i
= 0; i
< 128; i
++) {
bad
= (bt
->bt_cyl
<<16) + bt
->bt_trksec
;
printf("sn=%d, cn=%d, tn=%d, sn=%d\n",
(bt
->bt_cyl
*di
->di_ntrak
+ (bt
->bt_trksec
>>8)) *
di
->di_nsect
+ (bt
->bt_trksec
&0xff),
bt
->bt_cyl
, bt
->bt_trksec
>>8, bt
->bt_trksec
&0xff);
dkbad
.bt_csn
= atoi(*argv
++);
if (argc
> 2 * di
->di_nsect
|| argc
> 126) {
printf("bad: too many bad sectors specified\n");
if (2 * di
->di_nsect
> 126)
printf("limited to 126 by information format\n");
printf("limited to %d (only 2 tracks of sectors)\n",
if (sn
< 0 || sn
>= di
->di_size
) {
printf("%d: out of range [0,%d) for %s\n",
sn
, di
->di_size
, di
->di_type
);
dkbad
.bt_bad
[i
].bt_cyl
= sn
/ (di
->di_nsect
*di
->di_ntrak
);
sn
%= (di
->di_nsect
*di
->di_ntrak
);
dkbad
.bt_bad
[i
].bt_trksec
=
((sn
/di
->di_nsect
) << 8) + (sn
%di
->di_nsect
);
dkbad
.bt_bad
[i
].bt_trksec
= -1;
dkbad
.bt_bad
[i
].bt_cyl
= -1;
lseek(f
, 512 * (di
->di_size
- di
->di_nsect
), 0);
if (write(f
, (caddr_t
)&dkbad
, sizeof (dkbad
)) != sizeof (dkbad
)) {