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

📄 scsi-changer-driver.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 5 页
字号:
        {          /*           EAAPage = NULL; */          /*           DeviceCapabilitiesPage = NULL; */          return(-1);	  /*NOTREACHED*/        }      length = length - (size_t)*buffer - 2;      buffer = buffer + (size_t)*buffer + 1;    }  return(0);}intDecodeSense(    RequestSense_T *	sense,    char *		pstring,    FILE *		out){  if (out == NULL)    {      return(0);      /*NOTREACHED*/    }  g_fprintf(out,_("##### START DecodeSense\n"));  g_fprintf(out,_("%sSense Keys\n"), pstring);  if (sense->ErrorCode == 0x70)    {    g_fprintf(out,_("\tExtended Sense                     \n"));    } else {      g_fprintf(out,_("\tErrorCode                     %02x\n"), sense->ErrorCode);      g_fprintf(out,_("\tValid                         %d\n"), sense->Valid);    }  g_fprintf(out,_("\tASC                           %02X\n"), sense->AdditionalSenseCode);  g_fprintf(out,_("\tASCQ                          %02X\n"), sense->AdditionalSenseCodeQualifier);  g_fprintf(out,_("\tSense key                     %02X\n"), sense->SenseKey);  switch (sense->SenseKey)    {    case 0:      g_fprintf(out,_("\t\tNo Sense\n"));      break;    case 1:      g_fprintf(out,_("\t\tRecoverd Error\n"));      break;    case 2:      g_fprintf(out,_("\t\tNot Ready\n"));      break;    case 3:      g_fprintf(out,_("\t\tMedium Error\n"));      break;    case 4:      g_fprintf(out,_("\t\tHardware Error\n"));      break;    case 5:      g_fprintf(out,_("\t\tIllegal Request\n"));      break;    case 6:      g_fprintf(out,_("\t\tUnit Attention\n"));      break;    case 7:      g_fprintf(out,_("\t\tData Protect\n"));      break;    case 8:      g_fprintf(out,_("\t\tBlank Check\n"));      break;    case 9:      g_fprintf(out,_("\t\tVendor uniq\n"));      break;    case 0xa:      g_fprintf(out,_("\t\tCopy Aborted\n"));      break;    case 0xb:      g_fprintf(out,_("\t\tAborted Command\n"));      break;    case 0xc:      g_fprintf(out,_("\t\tEqual\n"));      break;    case 0xd:      g_fprintf(out,_("\t\tVolume Overflow\n"));      break;    case 0xe:      g_fprintf(out,_("\t\tMiscompare\n"));      break;    case 0xf:      g_fprintf(out,_("\t\tReserved\n"));      break;    }  return(0);}intDecodeExtSense(    ExtendedRequestSense_T *	sense,    char *			pstring,    FILE *			out){  ExtendedRequestSense_T *p;  g_fprintf(out,_("##### START DecodeExtSense\n"));  p = sense;  g_fprintf(out,_("%sExtended Sense\n"), pstring);  DecodeSense((RequestSense_T *)p, pstring, out);  g_fprintf(out,_("\tLog Parameter Page Code         %02X\n"), sense->LogParameterPageCode);  g_fprintf(out,_("\tLog Parameter Code              %02X\n"), sense->LogParameterCode);  g_fprintf(out,_("\tUnderrun/Overrun Counter        %02X\n"), sense->UnderrunOverrunCounter);  g_fprintf(out,_("\tRead/Write Error Counter        %d\n"), V3((char *)sense->ReadWriteDataErrorCounter));  if (sense->AdditionalSenseLength > (u_char)sizeof(RequestSense_T))    {      if (sense->PF)        g_fprintf(out,_("\tPower Fail\n"));      if (sense->BPE)        g_fprintf(out,_("\tSCSI Bus Parity Error\n"));      if (sense->FPE)        g_fprintf(out,_("\tFormatted Buffer parity Error\n"));      if (sense->ME)        g_fprintf(out,_("\tMedia Error\n"));      if (sense->ECO)        g_fprintf(out,_("\tError Counter Overflow\n"));      if (sense->TME)        g_fprintf(out,_("\tTapeMotion Error\n"));      if (sense->TNP)        g_fprintf(out,_("\tTape Not Present\n"));      if (sense->LBOT)        g_fprintf(out,_("\tLogical Beginning of tape\n"));      if (sense->TMD)        g_fprintf(out,_("\tTape Mark Detect Error\n"));      if (sense->WP)        g_fprintf(out,_("\tWrite Protect\n"));      if (sense->FMKE)        g_fprintf(out,_("\tFilemark Error\n"));      if (sense->URE)        g_fprintf(out,_("\tUnder Run Error\n"));      if (sense->WEI)        g_fprintf(out,_("\tWrite Error 1\n"));      if (sense->SSE)        g_fprintf(out,_("\tServo System Error\n"));      if (sense->FE)        g_fprintf(out,_("\tFormatter Error\n"));      if (sense->UCLN)        g_fprintf(out,_("\tCleaning Cartridge is empty\n"));      if (sense->RRR)        g_fprintf(out,_("\tReverse Retries Required\n"));      if (sense->CLND)        g_fprintf(out,_("\tTape Drive has been cleaned\n"));      if (sense->CLN)        g_fprintf(out,_("\tTape Drive needs to be cleaned\n"));      if (sense->PEOT)        g_fprintf(out,_("\tPhysical End of Tape\n"));      if (sense->WSEB)        g_fprintf(out,_("\tWrite Splice Error\n"));      if (sense->WSEO)        g_fprintf(out,_("\tWrite Splice Error\n"));      g_fprintf(out,_("\tRemaing 1024 byte tape blocks   %d\n"), V3((char *)sense->RemainingTape));      g_fprintf(out,_("\tTracking Retry Counter          %02X\n"), sense->TrackingRetryCounter);      g_fprintf(out,_("\tRead/Write Retry Counter        %02X\n"), sense->ReadWriteRetryCounter);      g_fprintf(out,_("\tFault Sympton Code              %02X\n"), sense->FaultSymptomCode);    }  return(0);}intPrintInquiry(    SCSIInquiry_T *	SCSIInquiry){  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### START PrintInquiry\n"));  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %x\n"), "qualifier", SCSIInquiry->qualifier);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %x\n"), "type", SCSIInquiry->type);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %x\n"), "data_format", SCSIInquiry->data_format);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %X\n"), "ansi_version", SCSIInquiry->ansi_version);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %X\n"), "ecma_version", SCSIInquiry->ecma_version);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %X\n"), "iso_version", SCSIInquiry->iso_version);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %X\n"), "type_modifier", SCSIInquiry->type_modifier);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %x\n"), "removable", SCSIInquiry->removable);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %.8s\n"), "vendor_info", SCSIInquiry->vendor_info);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %.16s\n"), "prod_ident", SCSIInquiry->prod_ident);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %.4s\n"), "prod_version", SCSIInquiry->prod_version);  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("%-15s %.19s\n"), "vendor_specific", SCSIInquiry->vendor_specific);  return(0);}intDoNothing0(void){  dbprintf(_("##### START DoNothing\n"));  return(0);}intDoNothing1(    int		unused1){  (void)unused1;	/* Quiet unused parameter warning */  dbprintf(_("##### START DoNothing\n"));  return(0);}intDoNothing2(    int		unused1,    int		unused2){  (void)unused1;	/* Quiet unused parameter warning */  (void)unused2;	/* Quiet unused parameter warning */  dbprintf(_("##### START DoNothing\n"));  return(0);}intDoNothing3(    int		unused1,    int		unused2,    int		unused3){  (void)unused1;	/* Quiet unused parameter warning */  (void)unused2;	/* Quiet unused parameter warning */  (void)unused3;	/* Quiet unused parameter warning */  dbprintf(_("##### START DoNothing\n"));  return(0);}intGenericFree(void){  dbprintf(_("##### START GenericFree\n"));  return(0);}intGenericSearch(void){  dbprintf(_("##### START GenericSearch\n"));  return(0);}intTreeFrogBarCode(    int DeviceFD){  extern OpenFiles_T *pDev;  ModePageTreeFrogVendorUnique_T *pVendor;  dbprintf(_("##### START TreeFrogBarCode\n"));  if (pModePage == NULL)    {      pModePage = alloc(0xff);    }  if (SCSI_ModeSense(DeviceFD, pModePage, 0xff, 0x0, 0x3f) == 0)    {      DecodeModeSense(pModePage, 0, _("TreeFrogBarCode :"), 0, debug_file);      if (pVendorUnique == NULL)      {         dbprintf(_("TreeFrogBarCode : no pVendorUnique\n"));         return(0);	 /*NOTREACHED*/      }      pVendor = ( ModePageTreeFrogVendorUnique_T *)pVendorUnique;      dbprintf(_("TreeFrogBarCode : EBARCO %d\n"), pVendor->EBARCO);      dbprintf(_("TreeFrogCheckSum : CHKSUM  %d\n"), pVendor->CHKSUM);      dump_hex((u_char *)pDev[INDEX_CHANGER].inquiry, INQUIRY_SIZE, DEBUG_INFO, SECTION_ELEMENT);      return(pVendor->EBARCO);      /*NOTREACHED*/    }  return(0);}intEXB_BarCode(    int		DeviceFD){  extern OpenFiles_T *pDev;  ModePageEXB120VendorUnique_T *pVendor;  ModePageEXB120VendorUnique_T *pVendorWork;  DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("##### START EXB_BarCode\n"));  if (pModePage == NULL && LibModeSenseValid == 0)    {      pModePage = alloc(0xff);      if (SCSI_ModeSense(DeviceFD, pModePage, 0xff, 0x8, 0x3f) == 0)	{	  DecodeModeSense(pModePage, 0, _("EXB_BarCode :"), 0, debug_file);	  LibModeSenseValid = 1;	} else {	  LibModeSenseValid = -1;	}    }  if (LibModeSenseValid == 1)    {      if (pVendorUnique == NULL)	{         DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("EXB_BarCode : no pVendorUnique\n"));         return(0);	 /*NOTREACHED*/      }      pVendor = ( ModePageEXB120VendorUnique_T *)pVendorUnique;      DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("EXB_BarCode : NBL %d\n"), pVendor->NBL);      DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("EXB_BarCode : PS  %d\n"), pVendor->PS);      if (pVendor->NBL == 1 && pVendor->PS == 1 )        {          pVendorWork = alloc((size_t)pVendor->ParameterListLength + 2);          DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("EXB_BarCode : setting NBL to 1\n"));          memcpy(pVendorWork, pVendor, (size_t)pVendor->ParameterListLength + 2);          pVendorWork->NBL = 0;          pVendorWork->PS = 0;          pVendorWork->RSVD0 = 0;          if (SCSI_ModeSelect(DeviceFD, (u_char *)pVendorWork, (u_char)(pVendorWork->ParameterListLength + 2), 0, 1, 0) == 0)            {              DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("EXB_BarCode : SCSI_ModeSelect OK\n"));              /* Hack !!!!!!               */              pVendor->NBL = 0;              /* And now again !!!               */              GenericResetStatus(DeviceFD);            } else {              DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("EXB_BarCode : SCSI_ModeSelect failed\n"));            }            amfree(pVendorWork);        }      dump_hex((u_char *)pDev[INDEX_CHANGER].inquiry, INQUIRY_SIZE, DEBUG_INFO, SECTION_BARCODE);      DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("EXB_BarCode : vendor_specific[19] %x\n"),		 pDev[INDEX_CHANGER].inquiry->vendor_specific[19]);    }  return(1);}intNoBarCode(    int DeviceFD){  (void)DeviceFD;	/* Quiet unused parameter warning */  DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("##### START NoBarCode\n"));  DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("##### STOP  NoBarCode\n"));  return(0);}intGenericBarCode(    int		DeviceFD){  (void)DeviceFD;	/* Quiet unused parameter warning */  DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("##### START GenericBarCode\n"));  if ( changer->havebarcode  >= 1)    {      DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("##### STOP GenericBarCode (havebarcode) => %d\n"),changer->havebarcode);      return(1);      /*NOTREACHED*/    }  DebugPrint(DEBUG_INFO, SECTION_BARCODE,_("##### STOP GenericBarCode => 0\n"));  return(0);}intSenseHandler(    int			DeviceFD,    u_char		flag,    u_char		SenseKey,    u_char		AdditionalSenseCode,    u_char		AdditionalSenseCodeQualifier,    RequestSense_T *	buffer){  extern OpenFiles_T *pDev;  int ret = 0;  dbprintf(_("##### START SenseHandler\n"));  if (pDev[DeviceFD].inqdone == 1)    {      dbprintf(_("Ident = [%s], function = [%s]\n"), pDev[DeviceFD].ident,		pDev[DeviceFD].functions->ident);      ret = pDev[DeviceFD].functions->function_error(DeviceFD, flag, SenseKey, AdditionalSenseCode, AdditionalSenseCodeQualifier, buffer);    } else {      dbprintf(_("    Ups no sense\n"));    }  dbprintf(_("#### STOP SenseHandler\n"));  return(ret);}/* * Try to get information about the tape, * Tape loaded ? Online etc * Use the mtio ioctl to get the information if no SCSI Path * to the tape drive is available. * * TODO: * Pass an parameter to identify which unit to use * if there are more than one * Implement the SCSI path if available*/intTapeStatus(void){  extern OpenFiles_T *pDev;  int ret;  int done;  int cnt;  RequestSense_T *pRequestSense;  DebugPrint(DEBUG_INFO, SECTION_TAPE,_("##### START TapeStatus\n"));  /*   * If it is an device which understand SCSI commands the   * normal ioctl (MTIOCGET for example) may fail   * So try an Inquiry   */  if (pDev[INDEX_TAPECTL].SCSI == 1)    {      pRequestSense = alloc(SIZEOF(RequestSense_T));      memset(pRequestSense, 0, SIZEOF(RequestSense_T));      for (done = 0, cnt = 0; !done && (cnt < 60); cnt++)	{	  ret = SCSI_TestUnitReady(INDEX_TAPECTL, pRequestSense);	  DebugPrint(DEBUG_INFO, SECTION_SCSI, _("TapeStatus TestUnitReady ret %d\n"),ret);	  switch (ret)	    {	    case SCSI_OK:	    case SCSI_SENSE:	      switch (SenseHandler(INDEX_TAPECTL, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, pRequestSense))		{		case SENSE_IGNORE:		case SENSE_NO:		  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("TapeStatus (TestUnitReady) SENSE_NO\n"));		  pDTE[0].status = 'F';		  DebugPrint(DEBUG_INFO, SECTION_TAPE,_("##### FULL\n"));		  done = 1;		  break;		case SENSE_TAPE_NOT_ONLINE:		  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("TapeStatus (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n"));		  pDTE[0].status = 'E';		  DebugPrint(DEBUG_INFO, SECTION_TAPE,_("##### EMPTY\n"));		  done = 1;		  break;		case SENSE_ABORT:		  DebugPrint(DEBUG_ERROR, SECTION_SCSI,_("TapeStatus (TestUnitReady) SENSE_ABORT\n"));		  done = 1;		  break;		case SENSE_RETRY:		  DebugPrint(DEBUG_INFO, SECTION_SCSI,_("T

⌨️ 快捷键说明

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