📄 rzdisk.c
字号:
ms_page1.recovery_time); } byteptr += sizeof(ms_page1); } ms_page2 = *((struct page_code_2 *)byteptr); if(ms_page2.pgcode == 2) { if(!moreoutput()) return; printf("\nPage 2 disconnect/reconnect parameters:\n"); printf(" PS\t\t\t\t\t%d\n", ms_page2.ps); printf(" Page code\t\t\t\t%d\n", ms_page2.pgcode); printf(" Page length\t\t\t\t%d\n", ms_page2.pglength); if(page_control == CHANGED_VALUES) { printf(" Buffer full ratio\t\t\t0x%x\n", ms_page2.bus_fratio); printf(" Buffer empty ratio\t\t\t0x%x\n", ms_page2.bus_eratio); printf(" Bus inactivity limit\t\t\t0x%x\n", ((ms_page2.bus_inactive1<<8) + ms_page2.bus_inactive0)); printf(" Disconnect time limit\t\t\t0x%x\n", ((ms_page2.disconn_time1<<8) + ms_page2.disconn_time0)); printf(" Connect time limit\t\t\t0x%x\n", ((ms_page2.conn_time1<<8) + ms_page2.conn_time0)); } else { printf(" Buffer full ratio\t\t\t%d\n", ms_page2.bus_fratio); printf(" Buffer empty ratio\t\t\t%d\n", ms_page2.bus_eratio); printf(" Bus inactivity limit\t\t\t%d\n", ((ms_page2.bus_inactive1<<8) + ms_page2.bus_inactive0)); printf(" Disconnect time limit\t\t\t%d\n", ((ms_page2.disconn_time1<<8) + ms_page2.disconn_time0)); printf(" Connect time limit\t\t\t%d\n", ((ms_page2.conn_time1<<8) + ms_page2.conn_time0)); } byteptr += sizeof(ms_page2); } ms_page3 = *((struct page_code_3 *)byteptr); if(ms_page3.pgcode == 3) { if(!moreoutput()) return; printf("\nPage 3 direct-access device format parameters:\n"); printf(" PS\t\t\t\t\t%d\n", ms_page3.ps); printf(" Page code\t\t\t\t%d\n", ms_page3.pgcode); printf(" Page length\t\t\t\t%d\n", ms_page3.pglength); if(page_control == CHANGED_VALUES) { printf(" Tracks per zone\t\t\t0x%x\n", ((ms_page3.tpz1<<8) + ms_page3.tpz0)); printf(" Alternate sectors per zone\t\t0x%x\n", ((ms_page3.aspz1<<8) + ms_page3.aspz0)); printf(" Alternate tracks per zone\t\t0x%x\n", ((ms_page3.atpz1<<8) + ms_page3.atpz0)); printf(" Alternate tracks per volume\t\t0x%x\n", ((ms_page3.atpv1<<8) + ms_page3.atpv0)); printf(" Sectors per track\t\t\t0x%x\n", ((ms_page3.spt1<<8) + ms_page3.spt0)); printf(" Data bytes per phy sector\t\t0x%x\n", ((ms_page3.bps1<<8) + ms_page3.bps0)); printf(" Interleave\t\t\t\t0x%x\n", ((ms_page3.interleave1<<8) + ms_page3.interleave0)); printf(" Track skew\t\t\t\t0x%x\n", ((ms_page3.track_skew1<<8) + ms_page3.track_skew0)); printf(" Cylinder skew\t\t\t\t0x%x\n", ((ms_page3.cylinder_skew1<<8) + ms_page3.cylinder_skew0)); printf(" Flags\t\t\t\t\t0x%x\n", ms_page3.flags); } else { printf(" Tracks per zone\t\t\t%d\n", ((ms_page3.tpz1<<8) + ms_page3.tpz0)); printf(" Alternate sectors per zone\t\t%d\n", ((ms_page3.aspz1<<8) + ms_page3.aspz0)); printf(" Alternate tracks per zone\t\t%d\n", ((ms_page3.atpz1<<8) + ms_page3.atpz0)); printf(" Alternate tracks per volume\t\t%d\n", ((ms_page3.atpv1<<8) + ms_page3.atpv0)); printf(" Sectors per track\t\t\t%d\n", ((ms_page3.spt1<<8) + ms_page3.spt0)); printf(" Data bytes per phy sector\t\t%d\n", ((ms_page3.bps1<<8) + ms_page3.bps0)); printf(" Interleave\t\t\t\t%d\n", ((ms_page3.interleave1<<8) + ms_page3.interleave0)); printf(" Track skew\t\t\t\t%d\n", ((ms_page3.track_skew1<<8) + ms_page3.track_skew0)); printf(" Cylinder skew\t\t\t\t%d\n", ((ms_page3.cylinder_skew1<<8) + ms_page3.cylinder_skew0)); printf(" Flags\t\t\t\t\t0x%02x\n", ms_page3.flags); } byteptr += sizeof(ms_page3); } ms_page4 = *((struct page_code_4 *)byteptr); if(ms_page4.pgcode == 4) { if(!moreoutput()) return; printf("\nPage 4 rigid disk drive geometry parameters:\n"); printf(" PS\t\t\t\t\t%d\n", ms_page4.ps); printf(" Page code\t\t\t\t%d\n", ms_page4.pgcode); printf(" Page length\t\t\t\t%d\n", ms_page4.pglength); if(page_control == CHANGED_VALUES) { printf(" Maximum number of cylinders\t\t0x%x\n", ((ms_page4.ncyl2<<16) + (ms_page4.ncyl1<<8) + ms_page4.ncyl0)); printf(" Maximum number of heads\t\t0x%x\n", ms_page4.nheads); printf(" Write precompensation start\t\t0x%x\n", ((ms_page4.wprecomp2<<16) + (ms_page4.wprecomp1<<8) + ms_page4.wprecomp0)); printf(" Reduced write current start\t\t0x%x\n", ((ms_page4.rwc2<<16) + (ms_page4.rwc1<<8) + ms_page4.rwc0)); printf(" Drive step rate\t\t\t0x%x\n", ((ms_page4.dsr1<<8) + ms_page4.dsr0)); printf(" Landing zone cylinder\t\t\t0x%x\n", ((ms_page4.lzc2<<16) + (ms_page4.lzc1<<8) + ms_page4.lzc0)); } else { printf(" Maximum number of cylinders\t\t%d\n", ((ms_page4.ncyl2<<16) + (ms_page4.ncyl1<<8) + ms_page4.ncyl0)); printf(" Maximum number of heads\t\t%d\n", ms_page4.nheads); printf(" Write precompensation start\t\t%d\n", ((ms_page4.wprecomp2<<16) + (ms_page4.wprecomp1<<8) + ms_page4.wprecomp0)); printf(" Reduced write current start\t\t%d\n", ((ms_page4.rwc2<<16) + (ms_page4.rwc1<<8) + ms_page4.rwc0)); printf(" Drive step rate\t\t\t%d\n", ((ms_page4.dsr1<<8) + ms_page4.dsr0)); printf(" Landing zone cylinder\t\t\t%d\n", ((ms_page4.lzc2<<16) + (ms_page4.lzc1<<8) + ms_page4.lzc0)); } byteptr += sizeof(ms_page4); } ms_page37 = *((struct page_code_37 *)byteptr); if(ms_page37.pgcode == 37) { if(!moreoutput()) return; printf("\nPage 37 DEC unique parameters:\n"); printf(" PS\t\t\t\t\t%d\n", ms_page37.ps); printf(" Page code\t\t\t\t%d\n", ms_page37.pgcode); printf(" Page length\t\t\t\t%d\n", ms_page37.pglength); if(page_control == CHANGED_VALUES) { printf(" Spinup on power up\t\t\t0x%x\n", ms_page37.spinup); } else { printf(" Spinup on power up\t\t\t%d\n", ms_page37.spinup); } printf("\n"); }}execute_rzcmd(command, data)int command;char *data;{ int i; rzcom = command; if(ioctl(rzdev, command, data) == -1) return(ERROR); else return(SUCCESS);}char *rz_sense_key_str[] = { "no sense", /* 0x00 */ "soft error", /* 0x01 */ "not ready", /* 0x02 */ "medium error", /* 0x03 */ "hardware error", /* 0x04 */ "illegal request", /* 0x05 */ "unit attention", /* 0x06 */ "write protected", /* 0x07 */ "blank check", /* 0x08 */ "vendor unique", /* 0x09 */ "copy aborted", /* 0x0a */ "aborted command", /* 0x0b */ "equal error", /* 0x0c */ "volume overflow", /* 0x0d */ "miscompare error", /* 0x0e */ "reserved", /* 0x0f */ 0};#define MAX_SENSE_KEY_STR \ (sizeof(rz_sense_key_str)/sizeof(rz_sense_key_str[0]))char *rz_error_code_str[] = { "no sense", /* 0x00 */ "", /* 0x01 */ "no seek", /* 0x02 */ "write fault", /* 0x03 */ "drive not ready", /* 0x04 */ "drive not selected", /* 0x05 */ "no track zero found", /* 0x06 */ "", /* 0x07 */ "", /* 0x08 */ "", /* 0x09 */ "", /* 0x0a */ "", /* 0x0b */ "", /* 0x0c */ "", /* 0x0d */ "", /* 0x0e */ "", /* 0x0f */ "ID CRC or ECC error", /* 0x10 */ "unrecoverable read error", /* 0x11 */ "no address mark", /* 0x12 */ "no data field address mark", /* 0x13 */ "block not found", /* 0x14 */ "seek error", /* 0x15 */ "", /* 0x16 */ "recoverable read error", /* 0x17 */ "soft data error", /* 0x18 */ "defect list error", /* 0x19 */ "parameter overrun", /* 0x1a */ "", /* 0x1b */ "primary defect list not found",/* 0x1c */ "compare error", /* 0x1d */ "", /* 0x1e */ "", /* 0x1f */ "invalid command", /* 0x20 */ "illegal block address", /* 0x21 */ "illegal command", /* 0x22 */ "", /* 0x23 */ "invalid cdb", /* 0x24 */ "invalid lun", /* 0x25 */ "invalid field in param list", /* 0x26 */ "write protected", /* 0x27 */ "", /* 0x28 */ "reset", /* 0x29 */ "mode select changed", /* 0x2a */ "", /* 0x2b */ "", /* 0x2c */ "", /* 0x2d */ "", /* 0x2e */ "", /* 0x2f */ "", /* 0x30 */ "medium format corrupted", /* 0x31 */ "no defect spare location", /* 0x32 */ "", /* 0x33 */ "", /* 0x34 */ "", /* 0x35 */ "", /* 0x36 */ "", /* 0x37 */ "", /* 0x38 */ "", /* 0x39 */ "", /* 0x3a */ "", /* 0x3b */ "", /* 0x3c */ "", /* 0x3d */ "", /* 0x3e */ "", /* 0x3f */ "RAM failure", /* 0x40 */ "", /* 0x41 */ "", /* 0x42 */ "message reject error", /* 0x43 */ "internal controller error", /* 0x44 */ "select/reselect failed", /* 0x45 */ "", /* 0x46 */ "scsi interface parity error", /* 0x47 */ "initiator detected error", /* 0x48 */ "inappropriate illegal message",/* 0x49 */ 0};#define MAX_ERROR_CODE_STR \ (sizeof(rz_error_code_str)/sizeof(rz_error_code_str[0]))char *unknown_key = "unknown key";char *unknown_code = "unknown code";geterror(){ struct extended_sense sense; char *print_sense_key(); char *print_error_code(); u_char *p; char rzcomstr[40]; int i; rzcomstr[0] = NULL; switch(rzcom) { case SCSI_FORMAT_UNIT: strcat(rzcomstr,"Format Unit"); break; case SCSI_READ_DEFECT_DATA: strcat(rzcomstr,"Read Defect Data"); break; case SCSI_REASSIGN_BLOCK: strcat(rzcomstr,"Reassign Block"); break; case SCSI_VERIFY_DATA: strcat(rzcomstr,"Verify Data"); break; case SCSI_MODE_SENSE: strcat(rzcomstr,"Mode Sense"); break; case SCSI_MODE_SELECT: strcat(rzcomstr,"Mode Select"); break; case SCSI_GET_INQUIRY_DATA: strcat(rzcomstr,"Inquiry"); break; case DIOCGETPT: strcat(rzcomstr,"Get Partition Table"); break; default: strcat(rzcomstr,"Unknown Command"); break; } if(errno != EIO) { printf("\n*** ERROR OCCURRED DURING COMMAND (%s) ***\n\n", rzcomstr); perror(rzdisk); return; } if(ioctl(rzdev, SCSI_GET_SENSE, (char *)&sense) == -1) { printf("\n*** ERROR OCCURRED DURING COMMAND (%s) ***\n\n", rzcomstr); printf("\nCannot get sense info from device (%s).\n",rzdisk); return(FATAL_ERROR); } infobyte = ((sense.infobyte3 << 24) & 0xff000000); infobyte += ((sense.infobyte2 << 16) & 0xff0000); infobyte += ((sense.infobyte1 << 8) & 0xff00); infobyte += ((sense.infobyte0 << 0) & 0xff); if(rzcom == SCSI_VERIFY_DATA) { if(sense.snskey == SC_RECOVERR) { asc = sense.asc; return(SOFT_ERROR); } else if(sense.snskey == SC_MEDIUMERR) return(HARD_ERROR); } printf("\n*** ERROR OCCURRED DURING COMMAND (%s) ***\n\n",rzcomstr); printf("(%s) error: sense key (0x%x): %s.\n", rzdisk, sense.snskey, print_sense_key(sense.snskey)); printf("(%s) error: error code (0x%x): %s.\n", rzdisk, sense.asc, print_error_code(sense.asc)); printf("(%s) error: sense = ", rzdisk); p = (u_char *)&sense; for(i=0; i<sizeof(sense); i++) printf("%x ", *p++); printf("\n"); return(FATAL_ERROR);}char *print_sense_key(key)int key;{ if((key > MAX_SENSE_KEY_STR -1) || rz_sense_key_str[key] == NULL) return(unknown_key); else return(rz_sense_key_str[key]);}char *print_error_code(code)int code;{ if((code > MAX_ERROR_CODE_STR -1) || rz_error_code_str[code] == NULL) return(unknown_code); else return(rz_error_code_str[code]);}moreoutput(){ char buf[8]; printstr("\nMore output (y/n)? "); if(confirm()) return(1); else return(0);}confirm(){ char answer[20]; int nread;doconfirm: nread = read(0, answer, 20); if(answer[nread-1] != '\n') while(getchar() != '\n'); if(answer[0] == 'y' || answer[0] == 'Y' || answer[0] == '\n') return(1); else if(answer[0] == 'n' || answer[0] == 'N') return(0); else { printstr("\n***** Bad input please enter (y/n)? "); goto doconfirm; }}printstr(s)char *s;{ write(1, s, strlen(s));}getinteger(){ int value;getint: if(scanf("%d", &value) <= 0) { while(getchar() != '\n'); printstr("\n***** Bad input please enter (INTEGER NUMBER)? "); goto getint; } while(getchar() != '\n'); return(value);}gethexnum(){ int value;gethex: if(scanf("%x", &value) <= 0) { while(getchar() != '\n'); printstr("\n***** Bad input please enter (HEX NUMBER)? "); goto gethex; } while(getchar() != '\n'); return(value);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -