X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=changer-src%2Fscsi-linux.c;h=396e8979dacb04e631b12325a525cf43968c6129;hb=621a0076ec80b352e52ba6f05f1729e254bfa423;hp=750bd626cae3acee7fa1190903ac20afab224ccb;hpb=1194fb66aa28d9929c3f2bef3cc6c1c3f40a60a4;p=debian%2Famanda diff --git a/changer-src/scsi-linux.c b/changer-src/scsi-linux.c index 750bd62..396e897 100644 --- a/changer-src/scsi-linux.c +++ b/changer-src/scsi-linux.c @@ -24,7 +24,7 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: scsi-linux.c,v 1.28 2006/03/09 20:06:10 johnfranks Exp $ + * $Id: scsi-linux.c,v 1.30 2006/07/06 11:57:28 martinea Exp $ * * Interface to execute SCSI commands on Linux * @@ -32,40 +32,7 @@ */ -#include - -#ifdef HAVE_DMALLOC_H -#include -#endif - -#ifdef HAVE_LINUX_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 - -#ifdef HAVE_DIRENT_H -#include -#endif - -#include - -#ifdef HAVE_SCSI_SCSI_IOCTL_H -#include -#endif +#include "amanda.h" #ifdef HAVE_SCSI_SG_H #include @@ -78,18 +45,18 @@ #include +extern OpenFiles_T *pDev; -void SCSI_OS_Version() +void SCSI_OS_Version(void) { #ifndef lint - static char rcsid[] = "$Id: scsi-linux.c,v 1.28 2006/03/09 20:06:10 johnfranks Exp $"; + static char rcsid[] = "$Id: scsi-linux.c,v 1.30 2006/07/06 11:57:28 martinea Exp $"; DebugPrint(DEBUG_ERROR, SECTION_INFO, "scsi-os-layer: %s\n",rcsid); #endif } int SCSI_CloseDevice(int DeviceFD) { - extern OpenFiles_T *pDev; int ret = 0; if (pDev[DeviceFD].devopen == 1) @@ -114,7 +81,6 @@ int SCSI_CloseDevice(int DeviceFD) #ifdef LINUX_SG int SCSI_OpenDevice(int ip) { - extern OpenFiles_T *pDev; int DeviceFD; int i; int timeout; @@ -122,24 +88,24 @@ int SCSI_OpenDevice(int ip) char *buffer = NULL ; /* Will contain the device name after checking */ int openmode = O_RDONLY; - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START SCSI_OpenDevice\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### START SCSI_OpenDevice\n")); if (pDev[ip].inqdone == 0) { pDev[ip].inqdone = 1; if (strncmp("/dev/sg", pDev[ip].dev, 7) != 0) /* Check if no sg device for an link .... */ { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_OpenDevice : checking if %s is a sg device\n", pDev[ip].dev); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("SCSI_OpenDevice : checking if %s is a sg device\n"), pDev[ip].dev); if (lstat(pDev[ip].dev, &pstat) != -1) { if (S_ISLNK(pstat.st_mode) == 1) { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_OpenDevice : is a link, checking destination\n"); - if ((buffer = (char *)malloc(512)) == NULL) + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("SCSI_OpenDevice : is a link, checking destination\n")); + if ((buffer = (char *)malloc(513)) == NULL) { - DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_OpenDevice : malloc failed\n"); + DebugPrint(DEBUG_ERROR, SECTION_SCSI,_("SCSI_OpenDevice : malloc failed\n")); return(0); } - memset(buffer, 0, 512); + memset(buffer, 0, 513); if (( i = readlink(pDev[ip].dev, buffer, 512)) == -1) { if (errno == ENAMETOOLONG ) @@ -152,16 +118,16 @@ int SCSI_OpenDevice(int ip) { if (strncmp("/dev/sg", buffer, 7) == 0) { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_OpenDevice : link points to %s\n", buffer) ; + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("SCSI_OpenDevice : link points to %s\n"), buffer) ; pDev[ip].flags = 1; } } } else {/* S_ISLNK(pstat.st_mode) == 1 */ - DebugPrint(DEBUG_INFO, SECTION_SCSI,"No link %s\n", pDev[ip].dev) ; + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("No link %s\n"), pDev[ip].dev) ; buffer = stralloc(pDev[ip].dev); } } else {/* lstat(DeviceName, &pstat) != -1 */ - DebugPrint(DEBUG_ERROR, SECTION_SCSI,"can't stat device %s\n", pDev[ip].dev); + DebugPrint(DEBUG_ERROR, SECTION_SCSI,_("can't stat device %s\n"), pDev[ip].dev); return(0); } } else { @@ -174,19 +140,19 @@ int SCSI_OpenDevice(int ip) openmode = O_RDWR; } - DebugPrint(DEBUG_INFO, SECTION_SCSI,"Try to open %s\n", buffer); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("Try to open %s\n"), buffer); if ((DeviceFD = open(buffer, openmode)) >= 0) { pDev[ip].avail = 1; pDev[ip].devopen = 1; pDev[ip].fd = DeviceFD; } else { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_OpenDevice open failed\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### STOP SCSI_OpenDevice open failed\n")); amfree(buffer); return(0); } - DebugPrint(DEBUG_INFO, SECTION_SCSI,"done\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("done\n")); if ( pDev[ip].flags == 1) { pDev[ip].SCSI = 1; @@ -195,18 +161,18 @@ int SCSI_OpenDevice(int ip) pDev[ip].dev = buffer; if (pDev[ip].SCSI == 1) { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_OpenDevice : use SG interface\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("SCSI_OpenDevice : use SG interface\n")); if ((timeout = ioctl(pDev[ip].fd, SG_GET_TIMEOUT)) > 0) { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_OpenDevice : current timeout %d\n", timeout); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("SCSI_OpenDevice : current timeout %d\n"), timeout); timeout = 60000; if (ioctl(pDev[ip].fd, SG_SET_TIMEOUT, &timeout) == 0) { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_OpenDevice : timeout set to %d\n", timeout); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("SCSI_OpenDevice : timeout set to %d\n"), timeout); } } pDev[ip].inquiry = (SCSIInquiry_T *)malloc(INQUIRY_SIZE); - if (SCSI_Inquiry(ip, pDev[ip].inquiry, INQUIRY_SIZE) == 0) + if (SCSI_Inquiry(ip, pDev[ip].inquiry, (u_char)INQUIRY_SIZE) == 0) { if (pDev[ip].inquiry->type == TYPE_TAPE || pDev[ip].inquiry->type == TYPE_CHANGER) { @@ -229,12 +195,12 @@ int SCSI_OpenDevice(int ip) } PrintInquiry(pDev[ip].inquiry); - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_OpenDevice (1)\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### STOP SCSI_OpenDevice (1)\n")); return(1); } else { close(DeviceFD); amfree(pDev[ip].inquiry); - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_OpenDevice (0)\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### STOP SCSI_OpenDevice (0)\n")); return(0); } } else { @@ -243,15 +209,15 @@ int SCSI_OpenDevice(int ip) close(DeviceFD); amfree(pDev[ip].inquiry); pDev[ip].inquiry = NULL; - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_OpenDevice (1)\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### STOP SCSI_OpenDevice (1)\n")); return(1); } } else /* if (pDev[ip].SCSI == 1) */ { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"Device not capable for SCSI commands\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("Device not capable for SCSI commands\n")); pDev[ip].SCSI = 0; pDev[ip].devopen = 0; close(DeviceFD); - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_OpenDevice (1)\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### STOP SCSI_OpenDevice (1)\n")); return(1); } } else { /* if (pDev[ip].inqdone == 0) */ @@ -269,40 +235,46 @@ int SCSI_OpenDevice(int ip) { if ((timeout = ioctl(pDev[ip].fd, SG_GET_TIMEOUT)) > 0) { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_OpenDevice : current timeout %d\n", timeout); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("SCSI_OpenDevice : current timeout %d\n"), timeout); timeout = 60000; if (ioctl(pDev[ip].fd, SG_SET_TIMEOUT, &timeout) == 0) { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_OpenDevice : timeout set to %d\n", timeout); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("SCSI_OpenDevice : timeout set to %d\n"), timeout); } } } - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_OpenDevice (1)\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### STOP SCSI_OpenDevice (1)\n")); return(1); } else { - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_OpenDevice open failed\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### STOP SCSI_OpenDevice open failed\n")); return(0); } } - DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_OpenDevice should not happen !!\n"); + DebugPrint(DEBUG_INFO, SECTION_SCSI,_("##### STOP SCSI_OpenDevice should not happen !!\n")); return(0); } -#define SCSI_OFF sizeof(struct sg_header) +#define SCSI_OFF SIZEOF(struct sg_header) 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) { - extern OpenFiles_T *pDev; struct sg_header *psg_header; char *buffer; - int osize = 0; - int status; + size_t osize = 0; + ssize_t status; + + /* 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) { @@ -322,7 +294,7 @@ int SCSI_ExecuteCommand(int DeviceFD, buffer = (char *)malloc(SCSI_OFF + CDB_Length + DataBufferLength); if (buffer == NULL) { - dbprintf(("SCSI_ExecuteCommand memory allocation failure.\n")); + dbprintf(_("SCSI_ExecuteCommand memory allocation failure.\n")); SCSI_CloseDevice(DeviceFD); return(-1); } @@ -337,7 +309,7 @@ int SCSI_ExecuteCommand(int DeviceFD, psg_header->twelve_byte = 0; } psg_header->result = 0; - psg_header->reply_len = SCSI_OFF + DataBufferLength; + psg_header->reply_len = (int)(SCSI_OFF + DataBufferLength); switch (Direction) { @@ -352,10 +324,11 @@ int SCSI_ExecuteCommand(int DeviceFD, DecodeSCSI(CDB, "SCSI_ExecuteCommand : "); status = write(pDev[DeviceFD].fd, buffer, SCSI_OFF + CDB_Length + osize); - if ( status < 0 || status != SCSI_OFF + CDB_Length + osize || - psg_header->result ) + if ( (status < (ssize_t)0) || + (status != (ssize_t)(SCSI_OFF + CDB_Length + osize)) || + (psg_header->result != 0)) { - dbprintf(("SCSI_ExecuteCommand error send \n")); + dbprintf(_("SCSI_ExecuteCommand error send \n")); SCSI_CloseDevice(DeviceFD); amfree(buffer); return(SCSI_ERROR); @@ -366,11 +339,12 @@ int SCSI_ExecuteCommand(int DeviceFD, memset(pRequestSense, 0, RequestSenseLength); memcpy(pRequestSense, psg_header->sense_buffer, 16); - if ( status < 0 || status != SCSI_OFF + DataBufferLength || - psg_header->result ) + if ( (status < 0) || + (status != (ssize_t)(SCSI_OFF + DataBufferLength)) || + (psg_header->result != 0)) { - dbprintf(("SCSI_ExecuteCommand error read \n")); - dbprintf(("Status %d (%d) %2X\n", status, SCSI_OFF + DataBufferLength,psg_header->result )); + dbprintf(_("SCSI_ExecuteCommand error read \n")); + dbprintf(_("Status %zd (%zd) %2X\n"), status, SCSI_OFF + DataBufferLength,psg_header->result ); SCSI_CloseDevice(DeviceFD); amfree(buffer); return(SCSI_ERROR); @@ -401,7 +375,6 @@ static inline int max(int x, int y) int SCSI_OpenDevice(int ip) { - extern OpenFiles_T *pDev; int DeviceFD; int i; @@ -414,8 +387,8 @@ int SCSI_OpenDevice(int ip) pDev[ip].fd = DeviceFD; pDev[ip].SCSI = 0; pDev[ip].inquiry = (SCSIInquiry_T *)malloc(INQUIRY_SIZE); - dbprintf(("SCSI_OpenDevice : use ioctl interface\n")); - if (SCSI_Inquiry(ip, pDev[ip].inquiry, INQUIRY_SIZE) == 0) + dbprintf(_("SCSI_OpenDevice : use ioctl interface\n")); + if (SCSI_Inquiry(ip, pDev[ip].inquiry, (u_char)INQUIRY_SIZE) == 0) { if (pDev[ip].inquiry->type == TYPE_TAPE || pDev[ip].inquiry->type == TYPE_CHANGER) { @@ -457,10 +430,9 @@ int SCSI_ExecuteCommand(int DeviceFD, int CDB_Length, void *DataBuffer, int DataBufferLength, - char *pRequestSense, + RequestSense_T *pRequestSense, int RequestSenseLength) { - extern OpenFiles_T *pDev; unsigned char *Command; int Zero = 0, Result; @@ -523,7 +495,6 @@ int SCSI_ExecuteCommand(int DeviceFD, */ int Tape_Ioctl( int DeviceFD, int command) { - extern OpenFiles_T *pDev; struct mtop mtop; int ret = 0; @@ -545,7 +516,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); } @@ -556,10 +527,10 @@ int Tape_Ioctl( int DeviceFD, int command) int Tape_Status( int DeviceFD) { - extern OpenFiles_T *pDev; struct mtget mtget; int ret = 0; + memset(&mtget, 0, SIZEOF(mtget)); if (pDev[DeviceFD].devopen == 0) { if (SCSI_OpenDevice(DeviceFD) == 0) @@ -568,12 +539,13 @@ int Tape_Status( int DeviceFD) if (ioctl(pDev[DeviceFD].fd , MTIOCGET, &mtget) != 0) { - DebugPrint(DEBUG_ERROR, SECTION_TAPE,"Tape_Status error ioctl %d\n",errno); + DebugPrint(DEBUG_ERROR, SECTION_TAPE,_("Tape_Status error ioctl %s\n"), + strerror(errno)); SCSI_CloseDevice(DeviceFD); return(-1); } - DebugPrint(DEBUG_INFO, SECTION_TAPE,"ioctl -> mtget.mt_gstat %lX\n",mtget.mt_gstat); + DebugPrint(DEBUG_INFO, SECTION_TAPE,_("ioctl -> mtget.mt_gstat %lX\n"),mtget.mt_gstat); if (GMT_ONLINE(mtget.mt_gstat)) { ret = TAPE_ONLINE; @@ -612,13 +584,11 @@ int ScanBus(int print) { DIR *dir; struct dirent *dirent; - extern OpenFiles_T *pDev; - extern int errno; int count = 0; if ((dir = opendir("/dev/")) == NULL) { - dbprintf(("/dev/ error: %s", strerror(errno))); + dbprintf(_("/dev/ error: %s"), strerror(errno)); return 0; } @@ -628,7 +598,8 @@ int ScanBus(int print) { pDev[count].dev = malloc(10); pDev[count].inqdone = 0; - sprintf(pDev[count].dev,"/dev/%s", dirent->d_name); + g_snprintf(pDev[count].dev, SIZEOF(pDev[count].dev), + "/dev/%s", dirent->d_name); if (OpenDevice(count,pDev[count].dev, "Scan", NULL )) { SCSI_CloseDevice(count); @@ -636,48 +607,48 @@ int ScanBus(int print) if (print) { - printf("name /dev/%s ", dirent->d_name); + g_printf(_("name /dev/%s "), dirent->d_name); 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"); } count++; - printf("Count %d\n",count); + g_printf(_("Count %d\n"),count); } else { amfree(pDev[count].dev); pDev[count].dev=NULL; @@ -686,7 +657,6 @@ int ScanBus(int print) } return 0; } -#endif /* * Local variables: * indent-tabs-mode: nil