⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rzdisk.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifndef lintstatic char *sccsid = "@(#)rzdisk.c	2.1    ULTRIX  5/12/89";#endif lint/************************************************************************ *									* *			Copyright (c) 1984,86,87,88,89 by		* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any	other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived	from  software	received  from	the	* *   University    of	California,   Berkeley,   and	from   Bell	* *   Laboratories.  Use, duplication, or disclosure is	subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or	reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//************************************************************************ * * rzdisk.c	12-Sep-88 * * SCSI Disk Utility Source File * * Modification history: * * 06-Feb-89	Alan Frechette *	Added in page 8 support. * * 09-Jan-89	Fred Canter *	Minor comment change. * * 27-Dec-88	Alan Frechette *	Code cleanup changes. Added the routine "fix_mode_select_params()" *	to fix up the mode select parameters before issuing the MODE *	SELECT command. Fixed the routine "scan_for_bad_blocks()" to  *	print out the correct error message when the error code is not *	(UNRECOVERABLE, RECOVERABLE with RETRIES, or RECOVERABLE with ECC). *	Added comments throughout this code. * * 20-Dec-88	Alan Frechette *	Do not check for errors after issuing the inquiry command. *	If the sense key is (SC_NOSENSE) then return the error code *	(NO_ERROR) from routine "geterror()". Ignore all (SC_NOSENSE) *	errors. * *	Fixed displaying of CHANGEABLE parameters for RZ23/RZ22 disks. *	Fixed some bugs dealing with changing and getting parameters *	for the RZ23/RZ22 disks. * *	If MODE SENSE or MODE SELECT fails when trying to format a *	disk then skip it. * * 13-Dec-88	Alan Frechette *	Fixed a bug which caused a core dump when you type "rzdisk" *	with no parameters. Changed some error messages. Fixed the *	displaying of the menu. * * 09-Dec-88	Alan Frechette *	Reworked getting and changing disk drive parameters. Made  *	extensive changes to these routines to get it to work in  *	all cases. Added the option of getting the CHANGEABLE *	parameters from the disk drive. The CHANGEABLE parameters *	returns a bit pattern of the bits that can be changed *	within a particular field. * * 06-Dec-88	Alan Frechette *	Fixed "reassign_bad_block()" to retry the read of the bad  *	block upto 5 times. Also always write the data back to  *	the reassigned block even if the data is bad. The user *	may still be able to recover from this by running "fsck". * *	Fixed a bug in "disk_mounted()" when searching for mounted *	file systems. * * 12-Sep-88	Alan Frechette *	Created this utility for the maintainence of scsi disks. * * IMPORTANT NOTE: *	This utility supports only the DIGITAL supplied disks *	(RZ22, RZ23, RZ55, and RRD40). This utility must be modified *	and tested for each new DIGITAL supported disk drive. *	This utility is not guaranteed to work with non DIGITAL *	supplied disks, due to vendor dependent SCSI implementations. * ************************************************************************/#include <stdio.h>#include <signal.h>#include <sys/types.h>#include <sys/file.h>#include <sys/ioctl.h>#include <sys/wait.h>#include <sys/param.h>#include <sys/mount.h>#include <sys/errno.h>#include <ufs/fs.h>#include <vaxscsi/rzdisk.h>int	rzdev = -1;char	rzdisk[40];int 	rzcom;int 	infobyte;int	asc;struct 	read_defect_params		rdp;struct 	format_params			fp;struct 	reassign_params			rp;struct 	verify_params			vp;struct 	defect_descriptors		dd;struct 	mode_sel_sns_params 		ms;struct 	mode_sel_sns_params 		msc;struct	inquiry_info			inq;#define MSIZE (NMOUNT*sizeof(struct fs_data))#define NUMTITLES 9int fields[2*NUMTITLES] = {-12,12,-8,8,-8,8,-8,8,-6,6,-8,8,-8,8,-4,4,-8,8};int num_fields[2*NUMTITLES] = {-12,12,8,8,8,8,8,8,6,0,8,8,8,8,6,0,-8,8};	main(argc,argv)int argc;char *argv[];{	int lbn,length,i,j;	u_char defect_format;	int fmt_defect_lists;	int page_control;	if(argc == 1) {		print_help();		exit(0);	}	if(argv[1][0] != '-') {		printf("\nNo option specified, type \"rzdisk -h\" for help.\n");		exit(1);	}	switch(argv[1][1]) {	case 'h':		if(argc != 2) {		    printf("\nUsage: rzdisk -h.\n");		    exit(1);		}		print_help();		break;	case 'i':		if(argc != 3) {		    printf("\nUsage: rzdisk -i special.\n");		    exit(1);		}		open_special_file(argv[2]);		get_inquiry_info();		break;	case 'c':		if(argc != 3 && argc != 4 || 			(argc == 4 && strcmp(argv[2],"ask") != 0)) {		    printf("\nUsage: rzdisk -c [ask] special.\n");		    exit(1);		}		if(argc == 4) {		    open_special_file(argv[3]);		    change_drive_parameters(1);		} 		else {		    open_special_file(argv[2]);		    change_drive_parameters(0);		}		break;	case 'g':		if(argc != 4) {		    printf("\nUsage: rzdisk -g (current|saved|default|changeable) special.\n");		    exit(1);		}		if(strcmp(argv[2],"current") == 0)		    page_control = CURRENT_VALUES;		else if(strcmp(argv[2],"saved") == 0)		    page_control = SAVED_VALUES;		else if(strcmp(argv[2],"default") == 0)		    page_control = DEFAULT_VALUES;		else if(strcmp(argv[2],"changeable") == 0)		    page_control = CHANGED_VALUES;		else {		    printf("\nUsage: rzdisk -g (current|saved|default|changeable) special.\n");		    exit(1);		}		open_special_file(argv[3]);		get_drive_parameters(page_control);		break;	case 'f':		if(argc != 4) {		    printf("\nUsage: rzdisk -f (vendor|known) special.\n");		    exit(1);		}		if(strcmp(argv[2],"vendor") == 0)		    fmt_defect_lists = VENDOR_DEFECTS;		else if(strcmp(argv[2],"known") == 0)		    fmt_defect_lists = KNOWN_DEFECTS;		else {		    printf("\nUsage: rzdisk -f (vendor|known) special.\n");		    exit(1);		}		open_special_file(argv[3]);		if(rzdisk[strlen(rzdisk) - 1] != 'c') {		    printf("\nMust specify (c) partition for -f option.\n");		    exit(1);	        }		format_a_disk(fmt_defect_lists);		break;	case 'r':		if(argc != 4 || !isinteger(argv[2])) {		    printf("\nUsage: rzdisk -r LBN special.\n");		    exit(1);		}		lbn = atoi(argv[2]);		open_special_file(argv[3]);		if(rzdisk[strlen(rzdisk) - 1] != 'c') {		    printf("\nMust specify (c) partition for -r option.\n");		    exit(1);	        }		reassign_bad_block(lbn);		break;	case 's':		if(argc != 5 || !isinteger(argv[2]) || !isinteger(argv[3])) {		    printf("\nUsage: rzdisk -s LBN length special.\n");		    exit(1);		}		lbn = atoi(argv[2]);		length = atoi(argv[3]);		open_special_file(argv[4]);		scan_for_bad_blocks(lbn,length);		break;	case 'd':		if(argc != 4) {		    printf("\nUsage: rzdisk -d (bfi|sector|block) special.\n");		    exit(1);		}		if(strcmp(argv[2],"bfi") == 0)		    defect_format = BFI_FORMAT;		else if(strcmp(argv[2],"sector") == 0)		    defect_format = PHY_FORMAT;		else if(strcmp(argv[2],"block") == 0)		    defect_format = BLK_FORMAT;		else {		    printf("\nUsage: rzdisk -d (bfi|sector|block) special.\n");		    exit(1);		}		open_special_file(argv[3]);		read_defects(defect_format);		break;	default:		printf("\nBad option (-%c), type \"rzdisk -h\" for help.\n",				argv[1][1]);		exit(1);		break;	}}open_special_file(special)char *special;{	strcpy(rzdisk,special);	if(strncmp(special,"/dev/",5) == 0 &&		strncmp(special,"/dev/rr",7) != 0) {		printf("\nMust specify raw device special file.\n");		exit(1);	}	if(strncmp(special,"/dev/rrz",8) != 0) {		printf("\nMust specify special file of the form (/dev/rrz??).\n");		exit(1);	}	if((rzdev = open(rzdisk, O_RDWR)) == -1) {		printf("\nCannot open SCSI device (%s) exiting.\n",rzdisk);		exit(1);	}}isinteger(string)char *string;{	if(*string == '-' || *string == '+')		++string;	while(*string) {		if((*string >= '0' && *string <= '9') || 		   	(*string == '-') || (*string == '+'))			++string;		else			return(0);	}	return(1);}print_help(){	printf("\n\n");	printf("\t\t********************************\n");	printf("\t\t**** SCSI Disk Utility Menu ****\n");	printf("\t\t********************************\n");	printf("\n\tUsage: rzdisk -cdfghirs [LBN|command] [length] special.\n\n");	printf("rzdisk -f vendor /dev/rrz0c\tFormats disk with VENDOR only defects.\n");	printf("rzdisk -f known /dev/rrz0c\tFormats disk with all KNOWN defects.\n");	printf("rzdisk -r 1234 /dev/rrz0c\tReassigns bad block (1234).\n");	printf("rzdisk -s 0 -1 /dev/rrz0c\tScans the entire disk for bad blocks.\n");	printf("rzdisk -s 0 -1 /dev/rrz0g\tScans partition (g) for bad blocks.\n");	printf("rzdisk -i /dev/rrz0c\t\tPrints out the inquiry data info.\n");	printf("rzdisk -d bfi /dev/rrz0c\tReads defect list in BFI format.\n");	printf("rzdisk -d sector /dev/rrz0c\tReads defect list in SECTOR format.\n");	printf("rzdisk -d block /dev/rrz0c\tReads defect list in BLOCK format.\n");	printf("rzdisk -c /dev/rrz0c\t\tChanges disk parameters to DEFAULT VALUES.\n");	printf("rzdisk -c ask /dev/rrz0c\tChanges disk parameters interactively.\n");	printf("rzdisk -g current /dev/rrz0c\tGets CURRENT disk drive parameters.\n");	printf("rzdisk -g saved /dev/rrz0c\tGets SAVED disk drive parameters.\n");	printf("rzdisk -g default /dev/rrz0c\tGets DEFAULT disk drive parameters.\n");	printf("rzdisk -g changeable /dev/rrz0c\tGets CHANGEABLE disk drive parameters.\n");	printf("rzdisk -h\t\t\tPrints out this help menu.\n");}format_a_disk(fmt_defect_lists)int fmt_defect_lists;{	int pid, i;	long thetime;	char *ctime();	char prodid[17];	struct page_code_37 ms_page37;	u_char *byteptr;	bzero((char *)&inq, sizeof(inq));	execute_rzcmd(SCSI_GET_INQUIRY_DATA, (char *)&inq);	for(i=0; i<16; i++)		prodid[i] = inq.prodid[i];	prodid[i] = NULL;	/*	 * FORMAT UNIT not supported on RRD40 disk.	 */	if(strncmp(prodid,"RRD40",5) == 0) {	    	printf("\nFormat Unit unsupported on device (%s).\n", 			rzdisk);	    	return;	}	/*	 * Cannot FORMAT a disk that is mounted.	 */	if(disk_mounted())		return;	/*	 * Inform the user what's going on.	 */	printf("\nFORMATTING A DISK DESTROYS ALL DATA!!!\n");	printstr("\nARE YOU SURE (y/n)? ");	if(!confirm())		return;	printf("\nYOU ARE FORMATTING THE DEVICE (%s)!!!\n",rzdisk);	printstr("\nIS THIS CORRECT (y/n)? ");	if(!confirm())		return;	/*	 * Initialize the defect header and the defect list. Note  	 * that there is no defect list being sent and therefore 	 * the defect list length is set to zero (0).	 */	bzero((char *)&dd, sizeof(dd));	fp.fp_format = BLK_FORMAT;	fp.fp_interleave = 1;	fp.fp_pattern = 0;	fp.fp_defects = fmt_defect_lists;	fp.fp_length = 0;	dd.dd_header.fu_hdr.vu = 0;	dd.dd_header.fu_hdr.dcrt = 0;	dd.dd_header.fu_hdr.dpry = 0;	fp.fp_addr = (u_char *)&dd;	/*	 * Skip MODE SENSE/MODE SELECT for RZ22/RZ23 disks.	 */	if(strncmp(prodid,"RZ22",4) == 0 || strncmp(prodid,"RZ23",4) == 0) {	    	dd.dd_header.fu_hdr.fov = 0;	    	dd.dd_header.fu_hdr.stpf = 0;	    	goto start_format;	}	/*	 * Allow MODE SENSE/MODE SELECT for RZ55 disks. Why this 	 * is done remains to be a mystery. What we do is simply	 * read the DRIVE PARAMETERS and them write them back	 * before doing the FORMAT.	 */	else {		dd.dd_header.fu_hdr.fov = 1;		dd.dd_header.fu_hdr.stpf = 1;	}	/*	 * Read the DRIVE PARAMETERS using the MODE SENSE command.	 */	bzero((char *)&ms, sizeof(ms));	ms.ms_pgcode = 0x3f;	ms.ms_length = sizeof(ms) - 4;	ms.ms_pgctrl = SAVED_VALUES;	if(execute_rzcmd(SCSI_MODE_SENSE, (char *)&ms) != SUCCESS)		goto start_format;	bzero((char *)&msc, sizeof(msc));	msc.ms_pgcode = 0x3f;	msc.ms_length = sizeof(ms) - 4;	msc.ms_pgctrl = CHANGED_VALUES;	if(execute_rzcmd(SCSI_MODE_SENSE, (char *)&msc) != SUCCESS)		goto start_format;	ms.ms_hdr.sense_len = 0;	ms.ms_page1.ps = 0;	ms.ms_page2.ps = 0;	ms.ms_page3.ps = 0;	ms.ms_page4.ps = 0;	ms.ms_page8.ps = 0;	ms.ms_page37.ps = 0;	ms.ms_setps = 1;	ms.ms_length = sizeof(ms) - 4;	fix_mode_select_params();	/* Adjust the length if no page 8 */	if(ms.ms_page8.pgcode != 8) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -