X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=changer-src%2Fscsi-cam.c;h=d01d2d489f216e49e5cdc4a2f6f1c42494acd49b;hb=fd48f3e498442f0cbff5f3606c7c403d0566150e;hp=d4a2eb00c05a22acd753cf8e765599b76fb01086;hpb=3ab887b9bc819a846c75dd7f2ee5d41fac22b19f;p=debian%2Famanda diff --git a/changer-src/scsi-cam.c b/changer-src/scsi-cam.c index d4a2eb0..d01d2d4 100644 --- a/changer-src/scsi-cam.c +++ b/changer-src/scsi-cam.c @@ -24,7 +24,7 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: scsi-cam.c,v 1.10.4.1.2.4 2004/04/29 20:47:40 martinea Exp $ + * $Id: scsi-cam.c,v 1.15 2006/05/25 01:47:07 johnfranks Exp $ * * Interface to execute SCSI commands on an system with cam support * Current support is for FreeBSD 4.x @@ -33,26 +33,7 @@ */ -#include - -#ifdef HAVE_CAM_LIKE_SCSI - -/* -#ifdef HAVE_STDIO_H -*/ -#include -/* -#endif -*/ -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif +#include "amanda.h" #ifdef HAVE_CAMLIB_H # include @@ -75,7 +56,7 @@ extern FILE *debug_file; void SCSI_OS_Version() { #ifndef lint - static char rcsid[] = "$Id: scsi-cam.c,v 1.10.4.1.2.4 2004/04/29 20:47:40 martinea Exp $"; + static char rcsid[] = "$Id: scsi-cam.c,v 1.15 2006/05/25 01:47:07 johnfranks Exp $"; DebugPrint(DEBUG_INFO, SECTION_INFO, "scsi-os-layer: %s\n",rcsid); #endif } @@ -94,18 +75,33 @@ int parse_btl(char *DeviceName, return 0; p = strtok(DeviceName, ":"); - sscanf(p,"%d", path); + if (sscanf(p,"%d", path) != 1) { + free(DeviceName); + ChgExit("SCSI_OpenDevice", + _("Path conversion error. Digits expected"), FATAL); + } if ((p = strtok(NULL,":")) == NULL) { free(DeviceName); - ChgExit("SCSI_OpenDevice", "target in Device Name not found", FATAL); + ChgExit("SCSI_OpenDevice", _("target in Device Name not found"), FATAL); + } + + if (sscanf(p,"%d", target) != 1) { + free(DeviceName); + ChgExit("SCSI_OpenDevice", + _("Target conversion error. Digits expected"), FATAL); } - sscanf(p,"%d", target); + if ((p = strtok(NULL,":")) == NULL) { free(DeviceName); - ChgExit("SCSI_OpenDevice", "lun in Device Name not found", FATAL); + ChgExit("SCSI_OpenDevice", _("lun in Device Name not found"), FATAL); + } + if (sscanf(p,"%d", lun) != 1) { + free(DeviceName); + ChgExit("SCSI_OpenDevice", + _("LUN conversion error. Digits expected"), FATAL); } - sscanf(p,"%d", lun); + return 1; } @@ -176,25 +172,23 @@ int SCSI_OpenDevice(int ip) return(1); } } else { /* Device open failed */ - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_OpenDevice open failed\n"); - return(0); - } - } else { - if (parse_btl(DeviceName, &path, &target, &lun)) - pDev[ip].curdev = cam_open_btl(path, target, lun, O_RDWR, NULL); - else - pDev[ip].curdev = cam_open_device(DeviceName, O_RDWR); - - free(DeviceName); - - if (pDev[ip].curdev) { - pDev[ip].devopen = 1; - return(1); - } else { + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### STOP SCSI_OpenDevice open failed\n")); return(0); } } - return(0); + if (parse_btl(DeviceName, &path, &target, &lun)) + pDev[ip].curdev = cam_open_btl(path, target, lun, O_RDWR, NULL); + else + pDev[ip].curdev = cam_open_device(DeviceName, O_RDWR); + + free(DeviceName); + + if (pDev[ip].curdev) { + pDev[ip].devopen = 1; + return(1); + } else { + return(0); + } } int SCSI_CloseDevice(int DeviceFD) @@ -215,19 +209,26 @@ int SCSI_CloseDevice(int DeviceFD) int SCSI_ExecuteCommand(int DeviceFD, Direction_T Direction, CDB_T CDB, - int CDB_Length, + size_t CDB_Length, void *DataBuffer, - int DataBufferLength, - char *pRequestSense, - int RequestSenseLength) + size_t DataBufferLength, + RequestSense_T *pRequestSense, + size_t RequestSenseLength) { ExtendedRequestSense_T ExtendedRequestSense; extern OpenFiles_T *pDev; union ccb *ccb; int ret; - uint32_t ccb_flags; + guint32 ccb_flags; OpenFiles_T *pwork = NULL; + /* Basic sanity checks */ + assert(CDB_Length <= UCHAR_MAX); + assert(RequestSenseLength <= UCHAR_MAX); + + /* Clear buffer for cases where sense is not returned */ + memset(pRequestSense, 0, RequestSenseLength); + if (pDev[DeviceFD].avail == 0) { return(SCSI_ERROR); @@ -243,7 +244,7 @@ int SCSI_ExecuteCommand(int DeviceFD, ccb = cam_getccb(pDev[DeviceFD].curdev); /* Build the CCB */ - bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_scsiio)); + bzero(&(&ccb->ccb_h)[1], SIZEOF(struct ccb_scsiio)); bcopy(&CDB[0], &ccb->csio.cdb_io.cdb_bytes, CDB_Length); switch (Direction) @@ -274,7 +275,7 @@ int SCSI_ExecuteCommand(int DeviceFD, /* cbfncp */ NULL, /* flags */ ccb_flags, /* tag_action */ MSG_SIMPLE_Q_TAG, - /* data_ptr */ (u_int8_t*)DataBuffer, + /* data_ptr */ (guint8*)DataBuffer, /* dxfer_len */ DataBufferLength, /* sense_len */ SSD_FULL_SIZE, /* cdb_len */ CDB_Length, @@ -283,7 +284,11 @@ int SCSI_ExecuteCommand(int DeviceFD, if (pDev[DeviceFD].devopen == 0) { - SCSI_OpenDevice(DeviceFD); + if (SCSI_OpenDevice(DeviceFD) == 0) + { + cam_freeccb(ccb); + return(SCSI_ERROR); + } } ret = cam_send_ccb(pDev[DeviceFD].curdev, ccb); @@ -303,7 +308,7 @@ int SCSI_ExecuteCommand(int DeviceFD, /* ToDo add error handling */ if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { - dbprintf(("SCSI_ExecuteCommand return %d\n", (ccb->ccb_h.status & CAM_STATUS_MASK))); + dbprintf(_("SCSI_ExecuteCommand return %d\n"), (ccb->ccb_h.status & CAM_STATUS_MASK)); return(SCSI_ERROR); } @@ -322,9 +327,8 @@ int Tape_Ioctl( int DeviceFD, int command) int ret = 0; if (pDev[DeviceFD].devopen == 0) - { - SCSI_OpenDevice(DeviceFD); - } + if (SCSI_OpenDevice(DeviceFD) == 0) + return(-1); switch (command) { @@ -338,7 +342,7 @@ int Tape_Ioctl( int DeviceFD, int command) if (ioctl(pDev[DeviceFD].fd , MTIOCTOP, &mtop) != 0) { - dbprintf(("Tape_Ioctl error ioctl %d\n",errno)); + dbprintf(_("Tape_Ioctl error ioctl %s\n"), strerror(errno)); SCSI_CloseDevice(DeviceFD); return(-1); } @@ -354,19 +358,18 @@ int Tape_Status( int DeviceFD) int ret = 0; if (pDev[DeviceFD].devopen == 0) - { - SCSI_OpenDevice(DeviceFD); - } + if (SCSI_OpenDevice(DeviceFD) == 0) + return(-1); if (ioctl(pDev[DeviceFD].fd , MTIOCGET, &mtget) != 0) { - dbprintf(("Tape_Status error ioctl %d\n",errno)); + dbprintf(_("Tape_Status error ioctl %s\n"), strerror(errno)); SCSI_CloseDevice(DeviceFD); return(-1); } - dbprintf(("ioctl -> mtget.mt_dsreg %lX\n",mtget.mt_dsreg)); - dbprintf(("ioctl -> mtget.mt_erreg %lX\n",mtget.mt_erreg)); + dbprintf("ioctl -> mtget.mt_dsreg %lX\n",mtget.mt_dsreg); + dbprintf("ioctl -> mtget.mt_erreg %lX\n",mtget.mt_erreg); /* * I have no idea what is the meaning of the bits in mt_erreg @@ -404,7 +407,7 @@ int ScanBus(int print) { for (lun = 0; lun < 8; lun++) { - sprintf(pDev[count].dev, "%d:%d:%d", bus, target, lun); + g_sprintf(pDev[count].dev, "%d:%d:%d", bus, target, lun); pDev[count].inqdone = 0; if (OpenDevice(count, pDev[count].dev, "Scan", NULL)) { @@ -416,54 +419,54 @@ int ScanBus(int print) } else { if (print) { - printf("bus:target:lun -> %s == ",pDev[count].dev); + g_printf(_("bus:target:lun -> %s == "),pDev[count].dev); switch (pDev[count].inquiry->type) { case TYPE_DISK: - printf("Disk"); + g_printf(_("Disk")); break; case TYPE_TAPE: - printf("Tape"); + g_printf(_("Tape")); break; case TYPE_PRINTER: - printf("Printer"); + g_printf(_("Printer")); break; case TYPE_PROCESSOR: - printf("Processor"); + g_printf(_("Processor")); break; case TYPE_WORM: - printf("Worm"); + g_printf(_("Worm")); break; case TYPE_CDROM: - printf("Cdrom"); + g_printf(_("Cdrom")); break; case TYPE_SCANNER: - printf("Scanner"); + g_printf(_("Scanner")); break; case TYPE_OPTICAL: - printf("Optical"); + g_printf(_("Optical")); break; case TYPE_CHANGER: - printf("Changer"); + g_printf(_("Changer")); break; case TYPE_COMM: - printf("Comm"); + g_printf(_("Comm")); break; default: - printf("unknown %d",pDev[count].inquiry->type); + g_printf(_("unknown %d"),pDev[count].inquiry->type); break; } - printf("\n"); + g_printf("\n"); } } } } } } + return 0; } -#endif /* * Local variables: * indent-tabs-mode: nil