fmt.c (schily-2021-08-14.tar.bz2) | : | fmt.c (schily-2021-09-18.tar.bz2) | ||
---|---|---|---|---|
/* @(#)fmt.c 1.99 18/02/21 Copyright 1986-1991, 93-97, 2000-2018 J. Schilling */ | /* @(#)fmt.c 1.100 21/08/20 Copyright 1986-1991, 93-97, 2000-2021 J. Schilling */ | |||
#include <schily/mconfig.h> | #include <schily/mconfig.h> | |||
#ifndef lint | #ifndef lint | |||
static UConst char sccsid[] = | static UConst char sccsid[] = | |||
"@(#)fmt.c 1.99 18/02/21 Copyright 1986-1991, 93-97, 2000-2018 J. Sc hilling"; | "@(#)fmt.c 1.100 21/08/20 Copyright 1986-1991, 93-97, 2000-2021 J. S chilling"; | |||
#endif | #endif | |||
/* | /* | |||
* Format & check/repair SCSI disks | * Format & check/repair SCSI disks | |||
* | * | |||
* Copyright (c) 1986-1991, 93-97, 2000-2018 J. Schilling | * Copyright (c) 1986-1991, 93-97, 2000-2021 J. Schilling | |||
*/ | */ | |||
/* | /* | |||
* The contents of this file are subject to the terms of the | * The contents of this file are subject to the terms of the | |||
* Common Development and Distribution License, Version 1.0 only | * Common Development and Distribution License, Version 1.0 only | |||
* (the "License"). You may not use this file except in compliance | * (the "License"). You may not use this file except in compliance | |||
* with the License. | * with the License. | |||
* | * | |||
* See the file CDDL.Schily.txt in this distribution for details. | * See the file CDDL.Schily.txt in this distribution for details. | |||
* A copy of the CDDL is also available via the Internet at | * A copy of the CDDL is also available via the Internet at | |||
* http://www.opensource.org/licenses/cddl1.txt | * http://www.opensource.org/licenses/cddl1.txt | |||
skipping to change at line 34 | skipping to change at line 34 | |||
*/ | */ | |||
#include <schily/stdio.h> | #include <schily/stdio.h> | |||
#include <schily/standard.h> | #include <schily/standard.h> | |||
#include <schily/signal.h> | #include <schily/signal.h> | |||
#include <schily/stdlib.h> | #include <schily/stdlib.h> | |||
#include <schily/unistd.h> | #include <schily/unistd.h> | |||
#include <schily/string.h> | #include <schily/string.h> | |||
#include <schily/time.h> | #include <schily/time.h> | |||
#include <schily/errno.h> | #include <schily/errno.h> | |||
#define GT_COMERR /* #define comerr gtcomerr */ | ||||
#define GT_ERROR /* #define error gterror */ | ||||
#include <schily/schily.h> | #include <schily/schily.h> | |||
#include <schily/libport.h> | #include <schily/libport.h> | |||
#include <schily/nlsdefs.h> | ||||
#include <scg/scgcmd.h> | #include <scg/scgcmd.h> | |||
#include <scg/scsireg.h> | #include <scg/scsireg.h> | |||
#include <scg/scsidefs.h> | #include <scg/scsidefs.h> | |||
#include <scg/scsitransp.h> | #include <scg/scsitransp.h> | |||
#include "defect.h" | #include "defect.h" | |||
#include "scsicmds.h" | #include "scsicmds.h" | |||
#include "fmt.h" | #include "fmt.h" | |||
skipping to change at line 273 | skipping to change at line 276 | |||
int silent = 0; | int silent = 0; | |||
int verbose = 0; | int verbose = 0; | |||
int kdebug = 0; | int kdebug = 0; | |||
int noparity = 0; | int noparity = 0; | |||
SCSI *scgp; | SCSI *scgp; | |||
char *dev = NULL; | char *dev = NULL; | |||
char *scgopts = NULL; | char *scgopts = NULL; | |||
save_args(ac, av); | save_args(ac, av); | |||
(void) setlocale(LC_ALL, ""); | ||||
#ifdef USE_NLS | ||||
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ | ||||
#define TEXT_DOMAIN "sformat" /* Use this only if it weren't */ | ||||
#endif | ||||
{ char *dir; | ||||
dir = searchfileinpath("share/locale", F_OK, | ||||
SIP_ANY_FILE|SIP_NO_PATH, NULL); | ||||
if (dir) | ||||
(void) bindtextdomain(TEXT_DOMAIN, dir); | ||||
else | ||||
#if defined(PROTOTYPES) && defined(INS_BASE) | ||||
(void) bindtextdomain(TEXT_DOMAIN, INS_BASE "/share/locale"); | ||||
#else | ||||
(void) bindtextdomain(TEXT_DOMAIN, "/usr/share/locale"); | ||||
#endif | ||||
(void) textdomain(TEXT_DOMAIN); | ||||
} | ||||
#endif /* USE_NLS */ | ||||
disk_null(&cur_disk, 1); | disk_null(&cur_disk, 1); | |||
disk_null(&alt_disk, 1); | disk_null(&alt_disk, 1); | |||
cac = --ac; | cac = --ac; | |||
cav = ++av; | cav = ++av; | |||
if (getallargs(&cac, &cav, opts, | if (getallargs(&cac, &cav, opts, | |||
#ifndef lint /* lint kann leider nur 52 args !!! */ | #ifndef lint /* lint kann leider nur 52 args !!! */ | |||
&prvers, &dev, &scgopts, | &prvers, &dev, &scgopts, | |||
&kdebug, &kdebug, &xdebug, &xdebug, &debug, &debug, | &kdebug, &kdebug, &xdebug, &xdebug, &debug, &debug, | |||
skipping to change at line 345 | skipping to change at line 368 | |||
#endif | #endif | |||
0) < 0) { | 0) < 0) { | |||
errmsgno(EX_BAD, "Bad flag: %s.\n", cav[0]); | errmsgno(EX_BAD, "Bad flag: %s.\n", cav[0]); | |||
usage(EX_BAD); | usage(EX_BAD); | |||
} | } | |||
if (help) | if (help) | |||
usage(0); | usage(0); | |||
else if (xhelp) | else if (xhelp) | |||
xusage(0); | xusage(0); | |||
if (prvers) { | if (prvers) { | |||
printf("sformat %s (%s-%s-%s)\n\n", fmt_version, HOST_CPU, HOST_V | gtprintf("sformat %s (%s-%s-%s)\n\n", fmt_version, HOST_CPU, HOST | |||
ENDOR, HOST_OS); | _VENDOR, HOST_OS); | |||
printf("Copyright (C) 1986-1991, 93-97, 2000-2018 Jörg Schilling\ | gtprintf("Copyright (C) 1986-1991, 93-97, 2000-2021 %s\n", _("Jör | |||
n"); | g Schilling")); | |||
printf("This is free software; see the source for copying conditi | gtprintf("This is free software; see the source for copying condi | |||
ons. There is NO\n"); | tions. There is NO\n"); | |||
printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A P | gtprintf("warranty; not even for MERCHANTABILITY or FITNESS FOR A | |||
ARTICULAR PURPOSE.\n"); | PARTICULAR PURPOSE.\n"); | |||
exit(0); | exit(0); | |||
} | } | |||
if (Sstart && Sstop) | if (Sstart && Sstop) | |||
comerrno(EX_BAD, "Only one of start/stop\n"); | comerrno(EX_BAD, "Only one of start/stop\n"); | |||
if (getenv("FMT_SILENT")) | if (getenv("FMT_SILENT")) | |||
silent = TRUE; | silent = TRUE; | |||
if (getenv("FMT_AUTO")) | if (getenv("FMT_AUTO")) | |||
autoformat = TRUE; | autoformat = TRUE; | |||
skipping to change at line 493 | skipping to change at line 516 | |||
if (CWveri > (Sbufsize/MIN_SECSIZE)) | if (CWveri > (Sbufsize/MIN_SECSIZE)) | |||
comerrno(EX_BAD, "Too many Sectors/Write-Verify\n"); | comerrno(EX_BAD, "Too many Sectors/Write-Verify\n"); | |||
if ((datfile_present = opendatfile(datafile)) == TRUE) | if ((datfile_present = opendatfile(datafile)) == TRUE) | |||
datfile_chk = datfile_chksum(); | datfile_chk = datfile_chksum(); | |||
if (!autoformat) { | if (!autoformat) { | |||
/* signal(SIGINT, sighandler);*/ | /* signal(SIGINT, sighandler);*/ | |||
} | } | |||
printf("sformat SCSI format/analysis/repair utilities\n"); | gtprintf("sformat SCSI format/analysis/repair utilities\n"); | |||
printf("Release %s, Copyright J. Schilling\n\n", fmt_version); | gtprintf("Release %s, Copyright J. Schilling\n\n", fmt_version); | |||
if (!datfile_chk) { | if (!datfile_chk) { | |||
if (datfile_present) | if (datfile_present) | |||
error( | error( | |||
"Disk database '%s' contains uncertified data.\n", | "Disk database '%s' contains uncertified data.\n", | |||
datfilename()); | datfilename()); | |||
if (autoformat) { | if (autoformat) { | |||
error("Datenbasis ist zerstoert.\n"); | error("Datenbasis ist zerstoert.\n"); | |||
exit(EX_BAD); | exit(EX_BAD); | |||
} | } | |||
skipping to change at line 712 | skipping to change at line 735 | |||
LOCAL int | LOCAL int | |||
format_one(scgp) | format_one(scgp) | |||
SCSI *scgp; | SCSI *scgp; | |||
{ | { | |||
struct disk *dp = &cur_disk; | struct disk *dp = &cur_disk; | |||
int ret = 0; | int ret = 0; | |||
int i; | int i; | |||
printf("scsibus%d target %d lun %d\n", scg_scsibus(scgp), scg_target(scgp ), scg_lun(scgp)); | printf("scsibus%d target %d lun %d\n", scg_scsibus(scgp), scg_target(scgp ), scg_lun(scgp)); | |||
if (checkmount(scg_scsibus(scgp), scg_target(scgp), scg_lun(scgp), -1L, 0 L)) { | if (checkmount(scg_scsibus(scgp), scg_target(scgp), scg_lun(scgp), -1L, 0 L)) { | |||
printf("WARNING: Disk has mounted partitions. "); | gtprintf("WARNING: Disk has mounted partitions. "); | |||
if (!yes("Continue? ")) | if (!yes("Continue? ")) | |||
exit(EX_BAD); | exit(EX_BAD); | |||
} | } | |||
if (do_inq) | if (do_inq) | |||
scgp->silent++; | scgp->silent++; | |||
getdev(scgp, TRUE); | getdev(scgp, TRUE); | |||
if (scgp->scmd->error == SCG_FATAL) | if (scgp->scmd->error == SCG_FATAL) | |||
comerrno(EX_BAD, "Cannot select Drive.\n"); | comerrno(EX_BAD, "Cannot select Drive.\n"); | |||
if (!do_inq) | if (!do_inq) | |||
printdev(scgp); | printdev(scgp); | |||
skipping to change at line 808 | skipping to change at line 831 | |||
return (0); | return (0); | |||
} else if (veri || repair) { | } else if (veri || repair) { | |||
int nbad = 0; | int nbad = 0; | |||
verify_disk(scgp, dp, 0, Vstart, Vend, MAXbad); | verify_disk(scgp, dp, 0, Vstart, Vend, MAXbad); | |||
nbad = print_bad(); | nbad = print_bad(); | |||
if (!is_ccs(scgp->dev)) { /* XXX Adaptec ?? */ | if (!is_ccs(scgp->dev)) { /* XXX Adaptec ?? */ | |||
/* Only print them */ | /* Only print them */ | |||
(void) bad_to_def(scgp); | (void) bad_to_def(scgp); | |||
} else if (repair && nbad > 0) { | } else if (repair && nbad > 0) { | |||
printf("WARNING: Repair may change data on disk.\n"); | gtprintf("WARNING: Repair may change data on disk.\n"); | |||
if (yes("Do you want to continue? ")) | if (yes("Do you want to continue? ")) | |||
repair_found_blocks(scgp, nbad); | repair_found_blocks(scgp, nbad); | |||
} | } | |||
return (0); | return (0); | |||
} else if (modesel) { | } else if (modesel) { | |||
do_modes(scgp); | do_modes(scgp); | |||
/* NOTREACHED */ | /* NOTREACHED */ | |||
} else if (randv) { | } else if (randv) { | |||
return (random_v_test(scgp, Vstart, Vend)); | return (random_v_test(scgp, Vstart, Vend)); | |||
} else if (randrw) { | } else if (randrw) { | |||
printf("WARNING: Random read/write-test may destroy data.\n"); | gtprintf("WARNING: Random read/write-test may destroy data.\n"); | |||
if (yes("Do you want to continue? ")) | if (yes("Do you want to continue? ")) | |||
return (random_rw_test(scgp, Vstart, Vend)); | return (random_rw_test(scgp, Vstart, Vend)); | |||
return (0); | return (0); | |||
} | } | |||
else if (ESDI) | else if (ESDI) | |||
esdi_command(scgp); | esdi_command(scgp); | |||
else if (clearnull) | else if (clearnull) | |||
clear_phys_null(scgp); | clear_phys_null(scgp); | |||
else if (readnull) | else if (readnull) | |||
read_phys_null(scgp, scgp->dev != DEV_MD21 && scgp->dev != DEV_MD 23); | read_phys_null(scgp, scgp->dev != DEV_MD21 && scgp->dev != DEV_MD 23); | |||
skipping to change at line 858 | skipping to change at line 881 | |||
end = scgp->cap->c_baddr; | end = scgp->cap->c_baddr; | |||
if (start < 0 || start > end) | if (start < 0 || start > end) | |||
start = 0L; | start = 0L; | |||
if (Vend > 0 && Vend < end) | if (Vend > 0 && Vend < end) | |||
end = Vend; | end = Vend; | |||
amount = end - start + 1; | amount = end - start + 1; | |||
printf("start: %ld end: %ld amount: %ld last baddr: %ld\n", | printf("start: %ld end: %ld amount: %ld last baddr: %ld\n", | |||
start, end, amount, (long)scgp->cap->c_ba ddr); | start, end, amount, (long)scgp->cap->c_ba ddr); | |||
printf("Select full stroke or random seeks:\n"); | gtprintf("Select full stroke or random seeks:\n"); | |||
if (yes("Full stroke seek? ")) for (;;) { | if (yes("Full stroke seek? ")) for (;;) { | |||
if (i == 0) | if (i == 0) | |||
getstarttime(); | getstarttime(); | |||
i++; | i++; | |||
if (read_scsi(scgp, Sbuf, start, 1) < 0) | if (read_scsi(scgp, Sbuf, start, 1) < 0) | |||
err++; | err++; | |||
if (read_scsi(scgp, Sbuf, end, 1) < 0) | if (read_scsi(scgp, Sbuf, end, 1) < 0) | |||
err++; | err++; | |||
if (i% 1000 == 0) { | if (i% 1000 == 0) { | |||
getstoptime(); | getstoptime(); | |||
printf("Total: %d errs: %d %ld.%03ldms/seek\n", | gtprintf("Total: %d errs: %d %ld.%03ldms/seek\n", | |||
i, err, | i, err, | |||
gettimediff(0)/(i/1000), | gettimediff(0)/(i/1000), | |||
gettimediff(0)%1000); | gettimediff(0)%1000); | |||
} | } | |||
} else for (;;) { | } else for (;;) { | |||
if (i == 0) | if (i == 0) | |||
getstarttime(); | getstarttime(); | |||
i++; | i++; | |||
#ifdef HAVE_DRAND48 | #ifdef HAVE_DRAND48 | |||
if (read_scsi(scgp, Sbuf, | if (read_scsi(scgp, Sbuf, | |||
start + drand48() * amount, 1) < 0) { | start + drand48() * amount, 1) < 0) { | |||
#else | #else | |||
if (read_scsi(scgp, Sbuf, | if (read_scsi(scgp, Sbuf, | |||
start + rand() % amount, 1) < 0) { | start + rand() % amount, 1) < 0) { | |||
#endif | #endif | |||
err++; | err++; | |||
printf("Gesamt: %d errs: %d\n", i, err); | gtprintf("Gesamt: %d errs: %d\n", i, err); | |||
} | } | |||
if (i% 1000 == 0) { | if (i% 1000 == 0) { | |||
getstoptime(); | getstoptime(); | |||
printf("Total: %d errs: %d %ld.%03ldms/seek\n", | gtprintf("Total: %d errs: %d %ld.%03ldms/seek\n", | |||
i, err, | i, err, | |||
gettimediff(0)/(i/1000), | gettimediff(0)/(i/1000), | |||
gettimediff(0)%1000); | gettimediff(0)%1000); | |||
} | } | |||
} | } | |||
} | } | |||
scgp->silent++; | scgp->silent++; | |||
if (read_capacity(scgp) >= 0) /* Adaptec 40x0 reagiert uebel, w enn*/ | if (read_capacity(scgp) >= 0) /* Adaptec 40x0 reagiert uebel, w enn*/ | |||
(void) seek_scsi(scgp, 0L); /* die Platte nicht formatiert is t */ | (void) seek_scsi(scgp, 0L); /* die Platte nicht formatiert is t */ | |||
skipping to change at line 1136 | skipping to change at line 1159 | |||
printf("Vendor_info : '%.8s'\n", inq->inq_vendor_info); | printf("Vendor_info : '%.8s'\n", inq->inq_vendor_info); | |||
printf("Identifikation : '%.16s'\n", inq->inq_prod_ident); | printf("Identifikation : '%.16s'\n", inq->inq_prod_ident); | |||
printf("Revision : '%.4s'\n", inq->inq_prod_revision); | printf("Revision : '%.4s'\n", inq->inq_prod_revision); | |||
} | } | |||
} | } | |||
LOCAL void | LOCAL void | |||
printdev(scgp) | printdev(scgp) | |||
SCSI *scgp; | SCSI *scgp; | |||
{ | { | |||
printf("Device seems to be: "); | gtprintf("Device seems to be: "); | |||
switch (scgp->dev) { | switch (scgp->dev) { | |||
case DEV_UNKNOWN: printf("unknown"); break; | case DEV_UNKNOWN: printf("unknown"); break; | |||
case DEV_ACB40X0: printf("Adaptec 4000/4010/4070"); break; | case DEV_ACB40X0: printf("Adaptec 4000/4010/4070"); break; | |||
case DEV_ACB4000: printf("Adaptec 4000"); break; | case DEV_ACB4000: printf("Adaptec 4000"); break; | |||
case DEV_ACB4010: printf("Adaptec 4010"); break; | case DEV_ACB4010: printf("Adaptec 4010"); break; | |||
case DEV_ACB4070: printf("Adaptec 4070"); break; | case DEV_ACB4070: printf("Adaptec 4070"); break; | |||
case DEV_ACB5500: printf("Adaptec 5500"); break; | case DEV_ACB5500: printf("Adaptec 5500"); break; | |||
case DEV_ACB4520A: printf("Adaptec 4520A"); break; | case DEV_ACB4520A: printf("Adaptec 4520A"); break; | |||
skipping to change at line 1301 | skipping to change at line 1324 | |||
dp->veri_time = estimate_format_time(dp, | dp->veri_time = estimate_format_time(dp, | |||
(int)(dp->interleave < 1 ? 1 : | (int)(dp->interleave < 1 ? 1 : | |||
dp->interleave)); | dp->interleave)); | |||
} | } | |||
EXPORT void | EXPORT void | |||
print_fmt_time(dp) | print_fmt_time(dp) | |||
struct disk *dp; | struct disk *dp; | |||
{ | { | |||
if (dp->fmt_time > 0) { | if (dp->fmt_time > 0) { | |||
printf("Estimated time: %ld minutes%s\n", | gtprintf("Estimated time: %ld minutes%s\n", | |||
(dp->fmt_time+30)/60, | (dp->fmt_time+30)/60, | |||
dp->flags & D_FTIME_FOUND?" (known)":""); | dp->flags & D_FTIME_FOUND?" (known)":""); | |||
} | } | |||
} | } | |||
EXPORT void | EXPORT void | |||
print_fmt_timeout(dp) | print_fmt_timeout(dp) | |||
struct disk *dp; | struct disk *dp; | |||
{ | { | |||
if (dp->fmt_timeout > 0) { | if (dp->fmt_timeout > 0) { | |||
printf("Format timeout: %ld minutes\n", | gtprintf("Format timeout: %ld minutes\n", | |||
(dp->fmt_timeout+30)/60); | (dp->fmt_timeout+30)/60); | |||
} | } | |||
} | } | |||
EXPORT char * | EXPORT char * | |||
datestr() | datestr() | |||
{ | { | |||
time_t clck; | time_t clck; | |||
clck = time((time_t *)0); | clck = time((time_t *)0); | |||
skipping to change at line 1380 | skipping to change at line 1403 | |||
EXPORT long | EXPORT long | |||
prstats() | prstats() | |||
{ | { | |||
long sec; | long sec; | |||
struct timeval tv; | struct timeval tv; | |||
getstoptime(); | getstoptime(); | |||
sec = gettimediff(&tv); | sec = gettimediff(&tv); | |||
printf("Time total: %ld.%03ldsec\n", (long)tv.tv_sec, (long)tv.tv_usec/10 00); | gtprintf("Time total: %ld.%03ldsec\n", (long)tv.tv_sec, (long)tv.tv_usec/ 1000); | |||
return (sec); | return (sec); | |||
} | } | |||
EXPORT void | EXPORT void | |||
helpexit() | helpexit() | |||
{ | { | |||
comerrno(EX_BAD, "Help.............\n"); | comerrno(EX_BAD, "Help.............\n"); | |||
/* NOTREACHED */ | /* NOTREACHED */ | |||
} | } | |||
End of changes. 19 change blocks. | ||||
24 lines changed or deleted | 47 lines changed or added |