X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=changer-src%2Fscsi-chio.c;h=32c3dbb9d5d4d8160fd7c58c143aaf8f6a3568a7;hb=fd48f3e498442f0cbff5f3606c7c403d0566150e;hp=8ac7ffa88c707ce2ccf341060a091f30e705e026;hpb=3ab887b9bc819a846c75dd7f2ee5d41fac22b19f;p=debian%2Famanda diff --git a/changer-src/scsi-chio.c b/changer-src/scsi-chio.c index 8ac7ffa..32c3dbb 100644 --- a/changer-src/scsi-chio.c +++ b/changer-src/scsi-chio.c @@ -1,5 +1,5 @@ /* - * $Id: scsi-chio.c,v 1.5.4.8 1999/06/17 18:33:19 th Exp $ + * $Id: scsi-chio.c,v 1.14 2006/05/25 01:47:07 johnfranks Exp $ * * scsi-chio.c -- library routines to handle the changer * support for chio based systems @@ -7,15 +7,13 @@ * Author: Eric Schnoebelen, eric@cirr.com * based on work by: Larry Pyeatt, pyeatt@cs.colostate.edu * Copyright: 1997, 1998 Eric Schnoebelen - * + * + * Patch: Michael Enkelis, michaele@mxim.com) */ #include "config.h" #include "amanda.h" -#if (defined(HAVE_CHIO_H) || defined(HAVE_SYS_CHIO_H)) \ - && !defined(HAVE_CAMLIB_H) - #include #include #include @@ -26,11 +24,15 @@ * and possibly change all the ioctl() calls in this program. */ -#if defined(HAVE_CHIO_H) -# include -#else /* HAVE_SYS_CHIO_H must be defined */ -# include -#endif +#if defined(HAVE_LINUX_CHIO_H) +# include +#else +# if defined(HAVE_CHIO_H) +# include +# else /* HAVE_SYS_CHIO_H must be defined */ +# include +# endif /* HAVE_CHIO_H */ +#endif /* HAVE_LINUX_CHIO_H */ char *modname = "@(#)" __FILE__ ": SCSI support library for the chio(2) interface @(#)"; @@ -40,8 +42,22 @@ char *modname = "@(#)" __FILE__ */ static struct changer_params changer_info; static int changer_info_init = 0; - -static int get_changer_info(fd) +int GetCurrentSlot(int fd, int drive); +int GetDeviceStatus (char *tapedev); +int OpenDevice (char *tapedev); +int CloseDevice (char *device, int DeviceFD); +int Tape_Ready1 ( char *tapedev , int wait); +int isempty(int fd, int slot); +int find_empty(int fd, int start, int count); +int get_clean_state(char *tapedev); +int get_slot_count(int fd); +int get_drive_count(int fd); +int eject_tape(char *tapedev); +int drive_loaded(int fd, int drivenum); +int unload(int fd, int drive, int slot); +int load(int fd, int drive, int slot); + +static int get_changer_info(int fd) { int rc = 0; @@ -63,6 +79,8 @@ int GetCurrentSlot(int fd, int drive) int slot; int i, rc; + (void)drive; + get_changer_info(fd); ces.ces_type = CHET_ST; @@ -70,35 +88,40 @@ int GetCurrentSlot(int fd, int drive) rc = ioctl(fd, CHIOGSTATUS, &ces); if (rc) { - dbprintf(("%s: changer status query failed: 0x%x %s\n", - get_pname(), rc,strerror(errno))); + dbprintf(_("changer status query failed: 0x%x %s\n"), rc, strerror(errno)); return -1; } for (slot = 0; slot < changer_info.cp_nslots; slot++) { i = ces.ces_data[slot] & CESTATUS_FULL; - dbprintf(("\tGetCurrentSlot slot %d = %d\n", slot, i)); + dbprintf(_("\tGetCurrentSlot slot %d = %d\n"), slot, i); if (!i) return(slot); } - - + return -1; } -int get_clean_state(int changerfd, char *changerdev, char *dev) +int get_clean_state(char *tapedev) { - return 0; - +int rc; +#if defined(BUILTIN) + rc = 0; +#else +#define GMT_CLN(x) ((x) & 0x00008000) + rc = ( GMT_CLN(GetDeviceStatus(tapedev)) ); +#endif /* BUILTIN */ + return rc; } -void eject_tape(char *tape) + +int eject_tape(char *tapedev) /* This function ejects the tape from the drive */ { int mtfd; struct mtop mt_com; - if ((mtfd = open(tape, O_RDWR)) < 0) { - dbprintf(("eject_tape : failed\n")); - perror(tape); + if ( (mtfd = OpenDevice(tapedev) ) < 0) { + dbprintf(_("eject_tape : failed\n")); + perror(tapedev); exit(2); } mt_com.mt_op = MTOFFL; @@ -108,11 +131,11 @@ struct mtop mt_com; If the drive already ejected the tape due an error, or because it was a cleaning tape, threre can be an error, which we should ignore - perror(tape); + perror(tapedev); exit(2); */ } - close(mtfd); + return(CloseDevice(tapedev, mtfd)); } @@ -132,8 +155,7 @@ int type=CHET_ST; rc = ioctl(fd, CHIOGSTATUS, &ces); if (rc) { - dbprintf(("%s: changer status query failed: 0x%x %s\n", - get_pname(), rc,strerror(errno))); + dbprintf(_("changer status query failed: 0x%x %s\n"), rc,strerror(errno)); return -1; } @@ -152,6 +174,9 @@ struct changer_element_status ces; int i,rc; int type=CHET_ST; + (void)start; + (void)count; + get_changer_info(fd); ces.ces_type = type; @@ -159,8 +184,7 @@ int type=CHET_ST; rc = ioctl(fd,CHIOGSTATUS,&ces); if (rc) { - dbprintf(("%s: changer status query failed: 0x%x %s\n", - get_pname(), rc, strerror(errno))); + dbprintf(_("changer status query failed: 0x%x %s\n"), rc, strerror(errno)); return -1; } @@ -187,8 +211,7 @@ int type=CHET_DT; rc = ioctl(fd, CHIOGSTATUS, &ces); if (rc) { - dbprintf(("%s: drive status query failed: 0x%x %s\n", - get_pname(), rc, strerror(errno))); + dbprintf(_("drive status query failed: 0x%x %s\n"), rc, strerror(errno)); return -1; } @@ -207,7 +230,7 @@ int unload(int fd, int drive, int slot) struct changer_move move; int rc; - dbprintf(("unload : fd = %d, drive = %d, slot =%d\n",fd, drive, slot)); + dbprintf(_("unload : fd = %d, drive = %d, slot =%d\n"),fd, drive, slot); move.cm_fromtype = CHET_DT; move.cm_fromunit = drive; @@ -217,8 +240,7 @@ int rc; rc = ioctl(fd, CHIOMOVE, &move); if (rc){ - dbprintf(("%s: drive unload failed (MOVE): 0x%x %s\n", - get_pname(), rc, strerror(errno))); + dbprintf(_("drive unload failed (MOVE): 0x%x %s\n"), rc, strerror(errno)); return(-2); } return 0; @@ -233,7 +255,7 @@ int load(int fd, int drive, int slot) struct changer_move move; int rc; - dbprintf(("load : fd = %d, drive = %d, slot =%d\n",fd, drive, slot)); + dbprintf(_("load : fd = %d, drive = %d, slot =%d\n"),fd, drive, slot); move.cm_fromtype = CHET_ST; move.cm_fromunit = slot; @@ -243,8 +265,7 @@ int rc; rc = ioctl(fd,CHIOMOVE,&move); if (rc){ - dbprintf(("%s: drive load failed (MOVE): 0x%x %s\n", - get_pname(), rc, strerror(errno))); + dbprintf(_("drive load failed (MOVE): 0x%x %s\n"), rc, strerror(errno)); return(-2); } return(0); @@ -256,8 +277,7 @@ int rc; rc = get_changer_info(fd); if (rc) { - dbprintf(("%s: slot count query failed: 0x%x %s\n", - get_pname(), rc, strerror(errno))); + dbprintf(_("slot count query failed: 0x%x %s\n"), rc, strerror(errno)); return -1; } @@ -270,8 +290,7 @@ int rc; rc = get_changer_info(fd); if (rc) { - dbprintf(("%s: drive count query failed: 0x%x %s\n", - get_pname(), rc, strerror(errno))); + dbprintf(_("drive count query failed: 0x%x %s\n"), rc, strerror(errno)); return -1; } @@ -279,7 +298,8 @@ int rc; } /* This function should ask the drive if it is ready */ -int Tape_Ready ( char *tapedev , int wait) +int Tape_Ready1 ( char *tapedev , int wait) +#if defined(BUILTIN) { FILE *out=NULL; int cnt=0; @@ -293,24 +313,60 @@ int Tape_Ready ( char *tapedev , int wait) return 0; } +#else +{ + int cnt=0; + + dbprintf(_("Tape_Ready1 : wait for BOT : max %d seconds\n"),wait); + /* loop on status BOT */ + while ((cnt < wait)) { + if ( GMT_BOT(GetDeviceStatus(tapedev)) ) { + break; + } + /* dbprintf(("Tape_Ready1 : cnt %d\n",cnt)); */ + cnt++; + sleep(1); + } + if (cnt >= wait) { + dbprintf(_("Tape_Ready1 : BOT not found : %d seconds\n"),cnt); + return(-1); + } else { + dbprintf(_("Tape_Ready1 : BOT : %d seconds\n"),cnt); + return 0; + } +} +#endif /* BUILTIN */ + +int GetDeviceStatus (char *tapedev) +{ + struct mtget status; + int mtfd, rc; + + mtfd = OpenDevice(tapedev); + ioctl (mtfd, MTIOCGET, (char *)&status); + CloseDevice(tapedev, mtfd); + rc = status.mt_gstat; + return rc; +} + int OpenDevice (char *tapedev) { int DeviceFD; DeviceFD = open(tapedev, O_RDWR); - return(DeviceFD); + return DeviceFD; } int CloseDevice (char *device, int DeviceFD) { - int ret; + int rc; - ret = close(DeviceFD); + dbprintf(_("CloseDevice(%s)\n"), device); + rc = close(DeviceFD); - return ret; + return rc; } -#endif /* * Local variables: * indent-tabs-mode: nil