-#ifndef lint
-static char rcsid[] = "$Id: chg-scsi.c,v 1.44 2006/03/09 20:06:10 johnfranks Exp $";
-#endif
+static char rcsid[] = "$Id: chg-scsi.c,v 1.52 2006/07/25 18:18:46 martinea Exp $";
/*
*
*
* The device dependent part is handled by scsi-changer-driver.c
* The SCSI OS interface is handled by scsi-ostype.c
*
- * Original copyrigths:
+ * Original copyrights:
*
* This program provides a driver to control generic
* SCSI changers, no matter what platform. The host/OS
#include "config.h"
-
-
#include "amanda.h"
-
-#ifdef HAVE_DMALLOC_H
-#include <dmalloc.h>
-#endif
-
-
#include "conffile.h"
#include "libscsi.h"
#include "scsi-defs.h"
-#include "tapeio.h"
char *tapestatfile = NULL;
FILE *debug_file = NULL;
extern ElementInfo_T *pSTE; /*Storage Element */
extern ElementInfo_T *pIEE; /*Import Export Element */
extern ElementInfo_T *pDTE; /*Data Transfer Element */
-extern int MTE; /*Counter for the above element types */
-extern int STE;
-extern int IEE;
-extern int DTE;
-
-changer_t chg;
+extern size_t MTE; /*Counter for the above element types */
+extern size_t STE;
+extern size_t IEE;
+extern size_t DTE;
int do_inventory = 0; /* Set if load/unload functions thinks an inventory should be done */
int clean_slot = -1;
typedef struct {
char *word;
- int token;
+ token_t token;
} tokentable_t;
-tokentable_t t_table[]={
- { "number_configs",NUMDRIVE},
- { "autoinv", AUTOINV},
- { "eject",EJECT},
- { "sleep",SLEEP},
- { "cleanmax",CLEANMAX},
- { "config",DRIVE},
- { "startuse",START},
- { "enduse",END},
- { "cleancart",CLEAN},
- { "dev",DEVICE},
- { "statfile",STATFILE},
- { "cleanfile",CLEANFILE},
- { "drivenum",DRIVENUM},
- { "changerdev",CHANGERDEV},
- { "usagecount",USAGECOUNT},
- { "scsitapedev", SCSITAPEDEV},
- { "tapestatus", TAPESTATFILE},
- { "labelfile", LABELFILE},
- { "changerident" , CHANGERIDENT},
- { "tapeident", TAPEIDENT},
- { "emubarcode", EMUBARCODE},
- { "havebarcode", HAVEBARCODE},
- { "debuglevel", DEBUGLEVEL},
- { NULL,-1 }
+tokentable_t t_table[] = {
+ { "number_configs", NUMDRIVE},
+ { "autoinv", AUTOINV},
+ { "eject", EJECT},
+ { "sleep", SLEEP},
+ { "cleanmax", CLEANMAX},
+ { "config", DRIVE},
+ { "startuse", START},
+ { "enduse", END},
+ { "cleancart", CLEAN},
+ { "dev", DEVICE},
+ { "statfile", STATFILE},
+ { "cleanfile", CLEANFILE},
+ { "drivenum", DRIVENUM},
+ { "changerdev", CHANGERDEV},
+ { "usagecount", USAGECOUNT},
+ { "scsitapedev", SCSITAPEDEV},
+ { "tapestatus", TAPESTATFILE},
+ { "labelfile", LABELFILE},
+ { "changerident", CHANGERIDENT},
+ { "tapeident", TAPEIDENT},
+ { "emubarcode", EMUBARCODE},
+ { "havebarcode", HAVEBARCODE},
+ { "debuglevel", DEBUGLEVEL},
+ { NULL, -1 }
};
-
-void init_changer_struct(changer_t *chg,int number_of_config)
- /* Initialize datasructures with default values */
+changer_t *changer;
+int ask_clean(char *tapedev);
+int get_current_slot(char *count_file);
+int get_relative_target(int fd, int nslots, char *parameter,
+ int param_index, int loaded, char *slot_file,
+ int slot_offset, int maxslot);
+int is_positive_number(char *tmp);
+int MapBarCode(char *labelfile, MBC_T *result);
+int read_config(char *configfile, changer_t *chg);
+void clean_tape(int fd, char *tapedev, char *cnt_file, int drivenum,
+ int cleancart, int maxclean, char *usagetime);
+void dump_changer_struct(changer_t *chg);
+void free_changer_struct(changer_t **chg);
+void init_changer_struct(changer_t *chg, int number_of_config);
+void parse_line(char *linebuffer, int *token,char **value);
+void put_current_slot(char *count_file, int slot);
+void usage(char *argv[]);
+
+int main(int argc, char *argv[]);
+
+
+/* Initialize data structures with default values */
+void
+init_changer_struct(
+ changer_t *chg,
+ int number_of_config)
{
int i;
+ memset(chg, 0, SIZEOF(*chg));
chg->number_of_configs = number_of_config;
chg->eject = 1;
- chg->sleep = 0;
- chg->autoinv = 0;
- chg->cleanmax = 0;
- chg->havebarcode = 0;
- chg->emubarcode = 0;
- chg->device = NULL;
- chg->labelfile = NULL;
- chg->debuglevel = NULL;
- chg->conf = malloc(sizeof(config_t)*number_of_config);
- if (chg->conf != NULL){
- for (i=0; i < number_of_config; i++){
- chg->conf[i].drivenum = 0;
- chg->conf[i].start = -1;
- chg->conf[i].end = -1;
- chg->conf[i].cleanslot = -1;
- chg->conf[i].device = NULL;
- chg->conf[i].slotfile = NULL;
- chg->conf[i].cleanfile = NULL;
- chg->conf[i].timefile = NULL;
- chg->conf[i].scsitapedev = NULL;
- chg->conf[i].tapestatfile = NULL;
- chg->conf[i].changerident = NULL;
- chg->conf[i].tapeident = NULL;
- }
- } else {
- fprintf(stderr,"init_changer_struct malloc failed\n");
+ chg->conf = alloc(SIZEOF(config_t) * (size_t)number_of_config);
+ for (i=0; i < number_of_config; i++){
+ chg->conf[i].drivenum = 0;
+ chg->conf[i].start = -1;
+ chg->conf[i].end = -1;
+ chg->conf[i].cleanslot = -1;
+ chg->conf[i].device = NULL;
+ chg->conf[i].slotfile = NULL;
+ chg->conf[i].cleanfile = NULL;
+ chg->conf[i].timefile = NULL;
+ chg->conf[i].scsitapedev = NULL;
+ chg->conf[i].tapestatfile = NULL;
+ chg->conf[i].changerident = NULL;
+ chg->conf[i].tapeident = NULL;
}
}
-void dump_changer_struct(changer_t chg)
- /* Dump of information for debug */
+/* Dump of information for debug */
+void
+dump_changer_struct(
+ changer_t *chg)
{
int i;
- dbprintf(("Number of configurations: %d\n",chg.number_of_configs));
- dbprintf(("Tapes need eject: %s\n",(chg.eject>0?"Yes":"No")));
- dbprintf (("\traw: %d\n",chg.eject));
- dbprintf(("Inv. auto update: %s\n",(chg.autoinv>0?"Yes":"No")));
- dbprintf (("\traw: %d\n",chg.autoinv));
- dbprintf(("barcode reader : %s\n",(chg.havebarcode>0?"Yes":"No")));
- dbprintf (("\traw: %d\n",chg.havebarcode));
- dbprintf(("Emulate Barcode : %s\n",(chg.emubarcode>0?"Yes":"No")));
- dbprintf (("\traw: %d\n",chg.emubarcode));
- if (chg.debuglevel != NULL)
- dbprintf(("debug level : %s\n", chg.debuglevel));
- dbprintf(("Tapes need sleep: %d seconds\n",chg.sleep));
- dbprintf(("Cleancycles : %d\n",chg.cleanmax));
- dbprintf(("Changerdevice : %s\n",chg.device));
- if (chg.labelfile != NULL)
- dbprintf(("Labelfile : %s\n", chg.labelfile));
- for (i=0; i<chg.number_of_configs; i++){
- dbprintf(("Tapeconfig Nr: %d\n",i));
- dbprintf((" Drivenumber : %d\n",chg.conf[i].drivenum));
- dbprintf((" Startslot : %d\n",chg.conf[i].start));
- dbprintf((" Endslot : %d\n",chg.conf[i].end));
- dbprintf((" Cleanslot : %d\n",chg.conf[i].cleanslot));
-
- if (chg.conf[i].device != NULL)
- dbprintf((" Devicename : %s\n",chg.conf[i].device));
+ dbprintf(_("Number of configurations: %d\n"), chg->number_of_configs);
+ dbprintf(_("Tapes need eject: %s\n"), (chg->eject>0 ? _("Yes") : _("No")));
+ dbprintf (_("\traw: %d\n"),chg->eject);
+ dbprintf(_("Inv. auto update: %s\n"), (chg->autoinv>0 ? _("Yes") : _("No")));
+ dbprintf (_("\traw: %d\n"),chg->autoinv);
+ dbprintf(_("barcode reader : %s\n"), (chg->havebarcode>0 ? _("Yes") : _("No")));
+ dbprintf (_("\traw: %d\n"),chg->havebarcode);
+ dbprintf(_("Emulate Barcode : %s\n"), (chg->emubarcode>0 ? _("Yes") : _("No")));
+ dbprintf (_("\traw: %d\n"),chg->emubarcode);
+ if (chg->debuglevel != NULL)
+ dbprintf(_("debug level : %s\n"), chg->debuglevel);
+ dbprintf(_("Tapes need sleep: %ld seconds\n"), (long int)chg->sleep);
+ dbprintf(_("Clean cycles : %d\n"), chg->cleanmax);
+ dbprintf(_("Changer device : %s\n"), chg->device);
+ if (chg->labelfile != NULL)
+ dbprintf(_("Label file : %s\n"), chg->labelfile);
+ for (i=0; i<chg->number_of_configs; i++){
+ dbprintf(_("Tape config Nr: %d\n"), i);
+ dbprintf(_(" Drive number : %d\n"), chg->conf[i].drivenum);
+ dbprintf(_(" Start slot : %d\n"), chg->conf[i].start);
+ dbprintf(_(" End slot : %d\n"), chg->conf[i].end);
+ dbprintf(_(" Clean slot : %d\n"), chg->conf[i].cleanslot);
+
+ if (chg->conf[i].device != NULL)
+ dbprintf(_(" Device name : %s\n"), chg->conf[i].device);
else
- dbprintf((" Devicename : none\n"));
+ dbprintf(_(" Device name : none\n"));
- if (chg.conf[i].changerident != NULL)
- dbprintf((" changerident : %s\n",chg.conf[i].changerident));
+ if (chg->conf[i].changerident != NULL)
+ dbprintf(_(" changer ident : %s\n"), chg->conf[i].changerident);
else
- dbprintf((" changerident : none\n"));
+ dbprintf(_(" changer ident : none\n"));
- if (chg.conf[i].scsitapedev != NULL)
- dbprintf((" SCSITapedev : %s\n",chg.conf[i].scsitapedev));
+ if (chg->conf[i].scsitapedev != NULL)
+ dbprintf(_(" SCSI Tape dev : %s\n"), chg->conf[i].scsitapedev);
else
- dbprintf((" SCSITapedev : none\n"));
+ dbprintf(_(" SCSI Tape dev : none\n"));
- if (chg.conf[i].tapeident != NULL)
- dbprintf((" tapeident : %s\n",chg.conf[i].tapeident));
+ if (chg->conf[i].tapeident != NULL)
+ dbprintf(_(" tape ident : %s\n"), chg->conf[i].tapeident);
else
- dbprintf((" tapeident : none\n"));
+ dbprintf(_(" tape ident : none\n"));
- if (chg.conf[i].tapestatfile != NULL)
- dbprintf((" statfile : %s\n", chg.conf[i].tapestatfile));
+ if (chg->conf[i].tapestatfile != NULL)
+ dbprintf(_(" stat file : %s\n"), chg->conf[i].tapestatfile);
else
- dbprintf((" statfile : none\n"));
+ dbprintf(_(" stat file : none\n"));
- if (chg.conf[i].slotfile != NULL)
- dbprintf((" Slotfile : %s\n",chg.conf[i].slotfile));
+ if (chg->conf[i].slotfile != NULL)
+ dbprintf(_(" Slot file : %s\n"), chg->conf[i].slotfile);
else
- dbprintf((" Slotfile : none\n"));
+ dbprintf(_(" Slot file : none\n"));
- if (chg.conf[i].cleanfile != NULL)
- dbprintf((" Cleanfile : %s\n",chg.conf[i].cleanfile));
+ if (chg->conf[i].cleanfile != NULL)
+ dbprintf(_(" Clean file : %s\n"), chg->conf[i].cleanfile);
else
- dbprintf((" Cleanfile : none\n"));
+ dbprintf(_(" Clean file : none\n"));
- if (chg.conf[i].timefile != NULL)
- dbprintf((" Usagecount : %s\n",chg.conf[i].timefile));
+ if (chg->conf[i].timefile != NULL)
+ dbprintf(_(" Usage count : %s\n"), chg->conf[i].timefile);
else
- dbprintf((" Usagecount : none\n"));
+ dbprintf(_(" Usage count : none\n"));
}
}
-void free_changer_struct(changer_t *chg)
- /* Free all allocated memory */
+/* Free all allocated memory */
+void
+free_changer_struct(
+ changer_t **changer)
{
+ changer_t *chg;
int i;
+ chg = *changer;
if (chg->device != NULL)
- free(chg->device);
- for (i=0; i<chg->number_of_configs; i++){
+ amfree(chg->device);
+ for (i = 0; i < chg->number_of_configs; i++){
if (chg->conf[i].device != NULL)
- free(chg->conf[i].device);
+ amfree(chg->conf[i].device);
if (chg->conf[i].slotfile != NULL)
- free(chg->conf[i].slotfile);
+ amfree(chg->conf[i].slotfile);
if (chg->conf[i].cleanfile != NULL)
- free(chg->conf[i].cleanfile);
+ amfree(chg->conf[i].cleanfile);
if (chg->conf[i].timefile != NULL)
- free(chg->conf[i].timefile);
+ amfree(chg->conf[i].timefile);
}
if (chg->conf != NULL)
- free(chg->conf);
+ amfree(chg->conf);
chg->conf = NULL;
chg->device = NULL;
+ amfree(*changer);
}
-void parse_line(char *linebuffer,int *token,char **value)
- /* This function parses a line, and returns a token and value */
+/* This function parses a line, and returns a token and value */
+void
+parse_line(
+ char *linebuffer,
+ int *token,
+ char **value)
{
char *tok;
int i;
}
tok=strtok(NULL," \t\n");
}
- return;
}
-int read_config(char *configfile, changer_t *chg)
- /* This function reads the specified configfile and fills the structure */
+/* This function reads the specified configfile and fills the structure */
+int
+read_config(
+ char *configfile,
+ changer_t *chg)
{
int numconf;
FILE *file;
int init_flag = 0;
int drivenum=0;
- char *linebuffer = NULL;
+ char *linebuffer;
int token;
char *value;
char *p;
numconf = 1; /* At least one configuration is assumed */
/* If there are more, it should be the first entry in the configurationfile */
-
- if (NULL==(file=fopen(configfile,"r"))){
+ assert(chg != NULL);
+ if ((file=fopen(configfile,"r")) == NULL) {
return (-1);
}
- amfree(linebuffer);
- while ((NULL!=(linebuffer=agets(file)))) {
- parse_line(linebuffer,&token,&value);
+ while ((NULL != (linebuffer = agets(file)))) {
+ if (linebuffer[0] == '\0') {
+ amfree(linebuffer);
+ continue;
+ }
+ parse_line(linebuffer, &token, &value);
if (token != -1){
- if (0==init_flag) {
+ if (value == NULL)
+ value = "0";
+
+ if (init_flag == 0) {
if (token != NUMDRIVE){
- init_changer_struct(chg,numconf);
+ init_changer_struct(chg, numconf);
} else {
numconf = atoi(value);
- init_changer_struct(chg,numconf);
+ if (numconf < 1 || numconf > 100) {
+ g_fprintf(stderr,_("numconf %d is bad\n"), numconf);
+ numconf = 1;
+ }
+ init_changer_struct(chg, numconf);
}
init_flag=1;
}
- switch (token){
+ switch (token) {
case NUMDRIVE: if (atoi(value) != numconf)
- fprintf(stderr,"Error: number_drives at wrong place, should be "\
- "first in file\n");
+ g_fprintf(stderr,_("Error: number_drives at wrong place, should be "
+ "first in file\n"));
break;
case AUTOINV:
chg->autoinv = 1;
chg->emubarcode = 1;
break;
case DEBUGLEVEL:
+ if (chg->debuglevel != NULL) {
+ g_fprintf(stderr,_("Error: debuglevel is specified twice "
+ "(%s then %s).\n"), chg->debuglevel, value);
+ amfree(chg->debuglevel);
+ }
chg->debuglevel = stralloc(value);
break;
case EJECT:
chg->havebarcode = atoi(value);
break;
case SLEEP:
- chg->sleep = atoi(value);
+ chg->sleep = (unsigned)atoi(value);
break;
case LABELFILE:
+ if (chg->labelfile != NULL) {
+ g_fprintf(stderr,_("Error: labelfile is specified twice "
+ "(%s then %s).\n"), chg->labelfile, value);
+ amfree(chg->labelfile);
+ }
chg->labelfile = stralloc(value);
break;
case CHANGERDEV:
+ if (chg->device != NULL) {
+ g_fprintf(stderr,_("Error: changerdev is specified twice "
+ "(%s then %s).\n"), chg->device, value);
+ amfree(chg->device);
+ }
chg->device = stralloc(value);
break;
case SCSITAPEDEV:
break;
case CHANGERIDENT:
chg->conf[drivenum].changerident = stralloc(value);
- p = chg->conf[drivenum].changerident;
- while (*p != '\0')
- {
- if (*p == '_')
+ if (drivenum < 0 || drivenum > 100) {
+ g_fprintf(stderr,_("drivenum %d is bad\n"), drivenum);
+ drivenum = 0;
+ }
+ if (strcmp(chg->conf[drivenum].changerident,"generic_changer") != 0) {
+ p = chg->conf[drivenum].changerident;
+ while (*p != '\0')
{
- *p=' ';
+ if (*p == '_')
+ {
+ *p=' ';
+ }
+ p++;
}
- p++;
- }
+ }
break;
case TAPEIDENT:
chg->conf[drivenum].tapeident = stralloc(value);
break;
case DRIVE:
drivenum = atoi(value);
- if(drivenum >= numconf){
- fprintf(stderr,"Error: drive must be less than number_drives\n");
+ if (drivenum < 0) {
+ g_fprintf(stderr,_("Error: drive must be >= 0\n"));
+ drivenum = 0;
+ } else if (drivenum >= numconf) {
+ g_fprintf(stderr,_("Error: drive must be less than number_drives\n"));
+ drivenum = numconf;
}
break;
case DRIVENUM:
if (drivenum < numconf){
chg->conf[drivenum].drivenum = atoi(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " drivenum ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " drivenum ignored\n"));
}
break;
case START:
if (drivenum < numconf){
chg->conf[drivenum].start = atoi(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " startuse ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " startuse ignored\n"));
}
break;
case END:
if (drivenum < numconf){
chg->conf[drivenum].end = atoi(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " enduse ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " enduse ignored\n"));
}
break;
case CLEAN:
if (drivenum < numconf){
chg->conf[drivenum].cleanslot = atoi(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " cleanslot ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " cleanslot ignored\n"));
}
break;
case DEVICE:
if (drivenum < numconf){
chg->conf[drivenum].device = stralloc(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " device ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " device ignored\n"));
}
break;
case STATFILE:
if (drivenum < numconf){
chg->conf[drivenum].slotfile = stralloc(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " slotfile ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " slotfile ignored\n"));
}
break;
case CLEANFILE:
if (drivenum < numconf){
chg->conf[drivenum].cleanfile = stralloc(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " cleanfile ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " cleanfile ignored\n"));
}
break;
case USAGECOUNT:
if (drivenum < numconf){
chg->conf[drivenum].timefile = stralloc(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " usagecount ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " usagecount ignored\n"));
}
break;
default:
- fprintf(stderr,"Error: Unknown token\n");
+ g_fprintf(stderr,_("Error: Unknown token\n"));
break;
}
}
* we use a file to store the current slot. It is not ideal
* but it gets the job done
*/
-int get_current_slot(char *count_file)
+int
+get_current_slot(
+ char *count_file)
{
FILE *inf;
- int retval;
+ int retval = -1;
int ret; /* return value for the fscanf function */
if ((inf=fopen(count_file,"r")) == NULL) {
- fprintf(stderr, "%s: unable to open (%s)\n",
+ g_fprintf(stderr, _("%s: unable to open (%s)\n"),
get_pname(), count_file);
exit(2);
}
+
ret = fscanf(inf,"%d",&retval);
fclose(inf);
retval = -1;
}
+ if (retval < 0 || retval > 10000) {
+ retval = -1;
+ }
return retval;
}
-void put_current_slot(char *count_file,int slot)
+void
+put_current_slot(
+ char *count_file,
+ int slot)
{
FILE *inf;
+ if (!count_file)
+ return;
+
if ((inf=fopen(count_file,"w")) == NULL) {
- fprintf(stderr, "%s: unable to open current slot file (%s)\n",
+ g_fprintf(stderr, _("%s: unable to open current slot file (%s)\n"),
get_pname(), count_file);
exit(2);
}
- fprintf(inf, "%d\n", slot);
+ g_fprintf(inf, "%d\n", slot);
fclose(inf);
}
* The passed struct MBC_T will hold the found entry in the DB
*/
-int MapBarCode(char *labelfile, MBC_T *result)
+int
+MapBarCode(
+ char *labelfile,
+ MBC_T *result)
{
FILE *fp;
int version;
LabelV2_T *plabelv2;
- int unusedpos = 0;
+ long unusedpos= 0;
int unusedrec = 0;
- int pos = 0;
- int record = 0;
- int volseen = 0;
- int loop = 1;
- int rsize = 0;
-
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : Parameter\n");
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"labelfile -> %s, vol -> %s, barcode -> %s, action -> %c, slot -> %d, from -> %d\n",
+ int record = 0;
+ int loop = 1;
+ size_t rsize;
+ long pos;
+ int rc;
+
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : Parameter\n"));
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("labelfile -> %s, vol -> %s, barcode -> %s, action -> %c, slot -> %d, from -> %d\n"),
labelfile,
result->data.voltag,
result->data.barcode,
if (labelfile == NULL)
{
- DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE,"Got empty labelfile (NULL)\n");
- ChgExit("MapBarCode", "MapBarCode name of labelfile is not set\n",FATAL);
+ DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE,_("Got empty labelfile (NULL)\n"));
+ ChgExit("MapBarCode", _("MapBarCode name of labelfile is not set\n"),FATAL);
+ /*NOTREACHED*/
}
if (access(labelfile, F_OK) == -1)
{
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE, "MapBarCode : creating %s", labelfile);
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE, _("MapBarCode : creating %s"), labelfile);
if ((fp = fopen(labelfile, "w+")) == NULL)
{
- DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE," failed\n");
- ChgExit("MapBarCode", "MapBarCode, creating labelfile failed\n", FATAL);
+ DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE,_(" failed\n"));
+ ChgExit("MapBarCode", _("MapBarCode, creating labelfile failed\n"), FATAL);
+ /*NOTREACHED*/
}
- fprintf(fp,":%d:", LABEL_DB_VERSION);
+ g_fprintf(fp,":%d:", LABEL_DB_VERSION);
fclose(fp);
}
if ((fp = fopen(labelfile, "r+")) == NULL)
{
- DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE,"MapBarCode : failed to open %s\n", labelfile);
- ChgExit("MapBarCode", "MapBarCode, opening labelfile for read/write failed\n", FATAL);
+ DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE,_("MapBarCode : failed to open %s\n"), labelfile);
+ ChgExit("MapBarCode", _("MapBarCode, opening labelfile for read/write failed\n"), FATAL);
+ /*NOTREACHED*/
}
- fscanf(fp,":%d:", &version);
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : DB version %d\n", version);
+ if (fscanf(fp,":%d:", &version) != 1) {
+ ChgExit("MapBarCode", _("MapBarCode, DB Version unreadable.\n"), FATAL);
+ /*NOTREACHED*/
+ }
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : DB version %d\n"), version);
pos = ftell(fp);
if (version != LABEL_DB_VERSION)
{
- ChgExit("MapBarCode", "MapBarCode, DB Version does not match\n", FATAL);
+ ChgExit("MapBarCode", _("MapBarCode, DB Version does not match\n"), FATAL);
+ /*NOTREACHED*/
}
- if (( plabelv2 = (LabelV2_T *)malloc(sizeof(LabelV2_T))) == NULL)
+ if (( plabelv2 = (LabelV2_T *)alloc(SIZEOF(LabelV2_T))) == NULL)
{
- DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE,"MapBarCode : malloc failed\n");
- ChgExit("MapBarCode", "MapBarCode malloc failed\n", FATAL);
+ DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE,_("MapBarCode : alloc failed\n"));
+ ChgExit("MapBarCode", _("MapBarCode alloc failed\n"), FATAL);
+ /*NOTREACHED*/
}
- memset(plabelv2, 0, sizeof(LabelV2_T));
+ memset(plabelv2, 0, SIZEOF(LabelV2_T));
while(feof(fp) == 0 && loop == 1)
{
- rsize = fread(plabelv2, 1, sizeof(LabelV2_T), fp);
- if (rsize == sizeof(LabelV2_T))
+ rsize = fread(plabelv2, 1, SIZEOF(LabelV2_T), fp);
+ if (rsize == SIZEOF(LabelV2_T))
{
record++;
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : (%d) VolTag \"%s\", BarCode %s, inuse %d, slot %d, from %d, loadcount %d\n",record,
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : (%d) VolTag \"%s\", BarCode %s, inuse %d, slot %d, from %d, loadcount %d\n"),record,
plabelv2->voltag,
plabelv2->barcode,
plabelv2->valid,
* Only dump the info
*/
case BARCODE_DUMP:
- printf("Slot -> %d, from -> %d, valid -> %d, Tag -> %s, Barcode -> %s, Loadcount %d\n",
+ g_printf(_("Slot -> %d, from -> %d, valid -> %d, Tag -> %s, Barcode -> %s, Loadcount %u\n"),
plabelv2->slot,
plabelv2->from,
plabelv2->valid,
* Set all the record to invalid, used by the Inventory function
*/
case RESET_VALID:
- fseek(fp, pos, SEEK_SET);
plabelv2->valid = 0;
- fwrite(plabelv2, 1, sizeof(LabelV2_T), fp);
+ if (fseek(fp, pos, SEEK_SET) == -1) {
+ fclose(fp);
+ amfree(plabelv2);
+ return 0; /* Fail */
+ }
+ if (fwrite(plabelv2, 1, SIZEOF(LabelV2_T), fp) < SIZEOF(LabelV2_T)) {
+ fclose(fp);
+ amfree(plabelv2);
+ return 0; /* Fail */
+ }
break;
/*
* Add an entry
unusedrec = record;
}
- /*
- * Hmm whats that ?
- */
- if (strcmp(plabelv2->voltag, result->data.voltag) == 0)
- {
- volseen = record;
- }
-
/*
* OK this record matches the barcode label
* so use/update it
*/
if (strcmp(plabelv2->barcode, result->data.barcode) == 0)
{
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : update entry\n");
- fseek(fp, pos, SEEK_SET);
+
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : update entry\n"));
+ if (fseek(fp, pos, SEEK_SET) == -1) {
+ fclose(fp);
+ amfree(plabelv2);
+ return 0; /* Fail */
+ }
plabelv2->valid = 1;
plabelv2->from = result->data.from;
plabelv2->slot = result->data.slot;
plabelv2->LoadCount = plabelv2->LoadCount + result->data.LoadCount;
- strcpy(plabelv2->voltag, result->data.voltag);
- strcpy(plabelv2->barcode, result->data.barcode);
- fwrite(plabelv2, 1, sizeof(LabelV2_T), fp);
+ strncpy(plabelv2->voltag, result->data.voltag,
+ SIZEOF(plabelv2->voltag));
+ strncpy(plabelv2->barcode, result->data.barcode,
+ SIZEOF(plabelv2->barcode));
+ rc = (fwrite(plabelv2, 1, SIZEOF(LabelV2_T), fp) < SIZEOF(LabelV2_T));
fclose(fp);
- free(plabelv2);
- return(1);
+ amfree(plabelv2);
+ return(rc);
}
break;
/*
case FIND_SLOT:
if (strcmp(plabelv2->voltag, result->data.voltag) == 0)
{
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode FIND_SLOT : \n");
- memcpy(&(result->data), plabelv2, sizeof(LabelV2_T));
- free(plabelv2);
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode FIND_SLOT : \n"));
+ memcpy(&(result->data), plabelv2, SIZEOF(LabelV2_T));
+ amfree(plabelv2);
return(1);
}
break;
case UPDATE_SLOT:
if (strcmp(plabelv2->voltag, result->data.voltag) == 0)
{
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode UPDATE_SLOT : update entry\n");
- fseek(fp, pos, SEEK_SET);
- strcpy(plabelv2->voltag, result->data.voltag);
- strcpy(plabelv2->barcode, result->data.barcode);
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode UPDATE_SLOT : update entry\n"));
+ if (fseek(fp, pos, SEEK_SET) == -1) {
+ fclose(fp);
+ amfree(plabelv2);
+ return 0; /* Fail */
+ }
+ strncpy(plabelv2->voltag, result->data.voltag,
+ SIZEOF(plabelv2->voltag));
+ strncpy(plabelv2->barcode, result->data.barcode,
+ SIZEOF(plabelv2->barcode));
plabelv2->valid = 1;
plabelv2->slot = result->data.slot;
plabelv2->from = result->data.from;
plabelv2->LoadCount = plabelv2->LoadCount + result->data.LoadCount;
- fwrite(plabelv2, 1, sizeof(LabelV2_T), fp);
+ rc = (fwrite(plabelv2, 1, SIZEOF(LabelV2_T), fp) < SIZEOF(LabelV2_T));
fclose(fp);
- free(plabelv2);
- return(1);
+ amfree(plabelv2);
+ return(rc);
}
break;
/*
*/
case BARCODE_VOL:
/*
- * DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode: (%d) inside BARCODE_VOL\n", record);
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"file value: %s, searched for value: %s\n", plabelv2->voltag, result->data.voltag);
+ * DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode: (%d) inside BARCODE_VOL\n"), record);
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("file value: %s, searched for value: %s\n"), plabelv2->voltag, result->data.voltag);
*/
if (strcmp(plabelv2->voltag, result->data.voltag) == 0)
{
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : VOL %s match\n", result->data.voltag);
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : VOL %s match\n"), result->data.voltag);
fclose(fp);
- memcpy(&(result->data), plabelv2, sizeof(LabelV2_T));
- free(plabelv2);
+ memcpy(&(result->data), plabelv2, SIZEOF(LabelV2_T));
+ amfree(plabelv2);
return(1);
}
break;
case BARCODE_BARCODE:
if (strcmp(plabelv2->barcode, result->data.barcode) == 0)
{
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : BARCODE %s match\n", result->data.barcode);
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : BARCODE %s match\n"), result->data.barcode);
fclose(fp);
- memcpy(&(result->data), plabelv2, sizeof(LabelV2_T));
- free(plabelv2);
+ memcpy(&(result->data), plabelv2, SIZEOF(LabelV2_T));
+ amfree(plabelv2);
return(1);
}
break;
default:
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : unknown action\n");
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : unknown action\n"));
break;
}
pos = ftell(fp);
} else {
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : feof (%d)\n", feof(fp));
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : error in read record expect %d, got %d\n",sizeof(LabelV2_T), rsize);
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : feof (%d)\n"), feof(fp));
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : error in read record expect %d, got %d\n"),SIZEOF(LabelV2_T), rsize);
loop=0;
}
}
*/
if (unusedpos != 0)
{
- DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,"MapBarCode : reuse record %d\n", unusedrec);
- fseek(fp, unusedpos, SEEK_SET);
+ DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE,_("MapBarCode : reuse record %d\n"), unusedrec);
+ if (fseek(fp, unusedpos, SEEK_SET) == -1) {
+ fclose(fp);
+ amfree(plabelv2);
+ return 0; /* Fail */
+ }
}
/*
* Set all values to zero
*/
- memset(plabelv2, 0, sizeof(LabelV2_T));
+ memset(plabelv2, 0, SIZEOF(LabelV2_T));
- strcpy(plabelv2->voltag, result->data.voltag);
- strncpy(plabelv2->barcode, result->data.barcode, TAG_SIZE);
+ strncpy(plabelv2->voltag, result->data.voltag,
+ SIZEOF(plabelv2->voltag));
+ strncpy(plabelv2->barcode, result->data.barcode,
+ SIZEOF(plabelv2->barcode));
plabelv2->valid = 1;
plabelv2->from = result->data.from;
plabelv2->slot = result->data.slot;
- fwrite(plabelv2, 1, sizeof(LabelV2_T), fp);
+ rc = (fwrite(plabelv2, 1, SIZEOF(LabelV2_T), fp) < SIZEOF(LabelV2_T));
fclose(fp);
- free(plabelv2);
- return(1);
+ amfree(plabelv2);
+ return(rc);
}
/*
* found, so return an 0
*/
fclose(fp);
- free(plabelv2);
+ amfree(plabelv2);
return(0);
}
char *parameter;
} command;
+void parse_args(int argc, char *argv[],command *rval);
/* major command line args */
#define COMCOUNT 13
{"last",SLOT_LAST,0},
{"advance",SLOT_ADVANCE,0},
};
-#define SLOTCOUNT (sizeof(slotdefs) / sizeof(slotdefs[0]))
+#define SLOTCOUNT (int)(sizeof(slotdefs) / sizeof(slotdefs[0]))
-int is_positive_number(char *tmp) /* is the string a valid positive int? */
+/* is the string a valid positive int? */
+int
+is_positive_number(
+ char *tmp)
{
int i=0;
if ((tmp==NULL)||(tmp[0]==0))
return 0;
}
-void usage(char *argv[])
+void
+usage(
+ char *argv[])
{
int cnt;
- printf("%s: Usage error.\n", argv[0]);
+ g_printf(_("%s: Usage error.\n"), argv[0]);
for (cnt=0; cnt < COMCOUNT; cnt++){
- printf(" %s %s",argv[0],argdefs[cnt].str);
+ g_printf(" %s %s",argv[0],argdefs[cnt].str);
if (argdefs[cnt].takesparam)
- printf(" <param>\n");
+ g_printf(" <param>\n");
else
- printf("\n");
+ g_printf("\n");
}
exit(2);
}
-void parse_args(int argc, char *argv[],command *rval)
+void
+parse_args(
+ int argc,
+ char *argv[],
+ command *rval)
{
- int i=0;
+ int i;
+
for (i=0; i < argc; i++)
- dbprintf(("ARG [%d] : %s\n", i, argv[i]));
+ dbprintf(_("ARG [%d] : %s\n"), i, argv[i]);
i = 0;
if ((argc<2)||(argc>3))
usage(argv);
}
/* used to find actual slot number from keywords next, prev, first, etc */
-int get_relative_target(int fd,int nslots,char *parameter,int param_index,
- int loaded,char *slot_file,
- int slot_offset,int maxslot)
+int
+get_relative_target(
+ int fd,
+ int nslots,
+ char *parameter,
+ int param_index,
+ int loaded,
+ char *slot_file,
+ int slot_offset,
+ int maxslot)
{
int current_slot;
+ (void)loaded; /* Quiet unused parameter warning */
+
current_slot = get_current_slot(slot_file);
- if (current_slot > maxslot){
+ if (current_slot > maxslot) {
current_slot = slot_offset;
}
- if (current_slot < slot_offset){
+ if (current_slot < slot_offset) {
current_slot = slot_offset;
}
switch(param_index) {
case SLOT_CUR:
return current_slot;
- break;
+
case SLOT_NEXT:
case SLOT_ADVANCE:
if (++current_slot==nslots+slot_offset)
return slot_offset;
- else
- return current_slot;
- break;
+ return current_slot;
+
case SLOT_PREV:
if (--current_slot<slot_offset)
return maxslot;
- else
- return current_slot;
- break;
+ return current_slot;
+
case SLOT_FIRST:
return slot_offset;
- break;
+
case SLOT_LAST:
return maxslot;
- break;
+
default:
- printf("<none> no slot `%s'\n",parameter);
- close(fd);
- exit(2);
break;
- };
- return(-1); /* never executed */
+ }
+ g_printf(_("<none> no slot `%s'\n"),parameter);
+ close(fd);
+ exit(2);
+ /*NOTREACHED*/
}
-int ask_clean(char *tapedev)
- /* This function should ask the drive if it wants to be cleaned */
+/* This function should ask the drive if it wants to be cleaned */
+int
+ask_clean(
+ char *tapedev)
{
int ret;
return ret;
}
-void clean_tape(int fd,char *tapedev,char *cnt_file, int drivenum,
- int cleancart, int maxclean,char *usagetime)
- /* This function should move the cleaning cartridge into the drive */
+/* This function should move the cleaning cartridge into the drive */
+void
+clean_tape(
+ int fd,
+ char *tapedev,
+ char *cnt_file,
+ int drivenum,
+ int cleancart,
+ int maxclean,
+ char *usagetime)
{
- int counter=-1;
+ int counter;
+ char *mailer;
+
if (cleancart == -1 ){
return;
}
+
/* Now we should increment the counter */
if (cnt_file != NULL){
+ mailer = getconf_str(CNF_MAILER);
counter = get_current_slot(cnt_file);
counter++;
if (counter>=maxclean){
/* Now we should inform the administrator */
- char *mail_cmd;
- FILE *mailf;
- mail_cmd = vstralloc(MAILER,
- " -s", " \"", "AMANDA PROBLEM: PLEASE FIX", "\"",
- " ", getconf_str(CNF_MAILTO),
- NULL);
- if((mailf = popen(mail_cmd, "w")) == NULL){
- error("could not open pipe to \"%s\": %s",
- mail_cmd, strerror(errno));
- printf("Mail failed\n");
- return;
+ char *mail_cmd = NULL;
+ FILE *mailf = NULL;
+ int mail_pipe_opened = 1;
+ if (mailer && *mailer != '\0') {
+ if (getconf_seen(CNF_MAILTO) && strlen(getconf_str(CNF_MAILTO)) > 0 &&
+ validate_mailto(getconf_str(CNF_MAILTO))) {
+ mail_cmd = vstralloc(mailer,
+ " -s", " \"", _("AMANDA PROBLEM: PLEASE FIX"), "\"",
+ " ", getconf_str(CNF_MAILTO),
+ NULL);
+ if ((mailf = popen(mail_cmd, "w")) == NULL) {
+ g_printf(_("Mail failed\n"));
+ error(_("could not open pipe to \"%s\": %s"),
+ mail_cmd, strerror(errno));
+ /*NOTREACHED*/
+ }
+ } else {
+ mail_pipe_opened = 0;
+ mailf = stderr;
+ g_fprintf(mailf, _("\nNo mail recipient specified, output redirected to stderr"));
+ }
+ } else {
+ mail_pipe_opened = 0;
+ mailf = stderr;
+ g_fprintf(mailf, _("\nNo mailer specified; output redirected to stderr"));
}
- fprintf(mailf,"\nThe usage count of your cleaning tape in slot %d",
+ g_fprintf(mailf,_("\nThe usage count of your cleaning tape in slot %d"),
cleancart);
- fprintf(mailf,"\nis more than %d. (cleanmax)",maxclean);
- fprintf(mailf,"\nTapedrive %s needs to be cleaned",tapedev);
- fprintf(mailf,"\nPlease insert a new cleaning tape and reset");
- fprintf(mailf,"\nthe countingfile %s",cnt_file);
-
- if(pclose(mailf) != 0)
- error("mail command failed: %s", mail_cmd);
-
+ g_fprintf(mailf,_("\nis more than %d. (cleanmax)"),maxclean);
+ g_fprintf(mailf,_("\nTapedrive %s needs to be cleaned"),tapedev);
+ g_fprintf(mailf,_("\nPlease insert a new cleaning tape and reset"));
+ g_fprintf(mailf,_("\nthe countingfile %s"),cnt_file);
+
+ if(mail_pipe_opened == 1 && pclose(mailf) != 0) {
+ error(_("mail command failed: %s"), mail_cmd);
+ /*NOTREACHED*/
+ }
return;
}
- put_current_slot(cnt_file,counter);
+ put_current_slot(cnt_file, counter);
}
load(fd,drivenum,cleancart);
/*
sleep(60);
if (drive_loaded(fd, drivenum))
- unload(fd,drivenum,cleancart);
- unlink(usagetime);
+ unload(fd, drivenum, cleancart);
+ if (usagetime)
+ unlink(usagetime);
}
/* ----------------------------------------------------------------------*/
-int main(int argc, char *argv[])
+int
+main(
+ int argc,
+ char ** argv)
{
- int loaded,target,oldtarget;
+ int loaded;
+ int target, oldtarget;
command com; /* a little DOS joke */
int x;
-
- MBC_T *pbarcoderes = malloc(sizeof(MBC_T));
+ MBC_T *pbarcoderes;
/*
* drive_num really should be something from the config file, but..
* for now, it is set to zero, since most of the common changers
* used by amanda only have one drive ( until someone wants to
* use an EXB60/120, or a Breece Hill Q45.. )
*/
- unsigned char emubarcode = 0;
- int drive_num = 0;
- int need_eject = 0; /* Does the drive need an eject command ? */
- int need_sleep = 0; /* How many seconds to wait for the drive to get ready */
+ unsigned char emubarcode;
+ int drive_num;
+ int need_eject; /* Does the drive need an eject command ? */
+ time_t need_sleep; /* How many seconds to wait for the drive to get ready */
- int maxclean = 0;
- char *clean_file=NULL;
- char *time_file=NULL;
+ int maxclean;
+ char *clean_file;
+ char *time_file;
/*
* For the emubarcode stuff
int slot_offset;
int confnum;
- int fd, slotcnt, drivecnt;
+ int fd;
+ int slotcnt;
+ int drivecnt;
int endstatus = 0;
- char *changer_dev = NULL;
- char *tape_device = NULL;
- char *chg_scsi_conf = NULL; /* The config file for us */
- char *slot_file = NULL; /* Where we will place the info which
+ char *changer_dev;
+ char *tape_device;
+ char *chg_scsi_conf; /* The config file for us */
+ char *slot_file; /* Where we will place the info which
* slot is loaded
*/
- char *scsitapedevice = NULL;
+ char *scsitapedevice;
int param_index = 0;
- memset(pbarcoderes, 0 , sizeof(MBC_T));
- chg.number_of_configs = 0;
- chg.eject = 0;
- chg.sleep = 0;
- chg.cleanmax = 0;
- chg.device = NULL;
- chg.labelfile = NULL;
- chg.conf = NULL;
+ /*
+ * Configure program for internationalization:
+ * 1) Only set the message locale for now.
+ * 2) Set textdomain for all amanda related programs to "amanda"
+ * We don't want to be forced to support dozens of message catalogs.
+ */
+ setlocale(LC_MESSAGES, "C");
+ textdomain("amanda");
+
+ changer = alloc(SIZEOF(changer_t));
+ pbarcoderes = alloc(SIZEOF(MBC_T));
+
+ memset(pbarcoderes, 0 , SIZEOF(MBC_T));
+ changer->number_of_configs = 0;
+ changer->eject = 0;
+ changer->sleep = 0;
+ changer->cleanmax = 0;
+ changer->device = NULL;
+ changer->labelfile = NULL;
+ changer->conf = NULL;
#ifdef CHG_SCSI_STANDALONE
- printf("Ups standalone\n");
+ g_printf(_("Ups standalone\n"));
#else
set_pname("chg-scsi");
/* Don't die when child closes pipe */
signal(SIGPIPE, SIG_IGN);
- dbopen();
+ dbopen(DBG_SUBDIR_SERVER);
- dbprintf(("chg-scsi: %s\n",rcsid));
+ dbprintf("chg-scsi: %s\n", rcsid);
ChangerDriverVersion();
if (debug_file == NULL)
parse_args(argc,argv,&com);
- pDev = (OpenFiles_T *)malloc(sizeof(OpenFiles_T) * CHG_MAXDEV);
- memset(pDev, 0, sizeof(OpenFiles_T) * CHG_MAXDEV );
+ pDev = (OpenFiles_T *)alloc(SIZEOF(OpenFiles_T) * CHG_MAXDEV);
+ memset(pDev, 0, SIZEOF(OpenFiles_T) * CHG_MAXDEV );
switch(com.command_code)
case COM_SCAN:
ScanBus(1);
return(0);
- break;
+
case COM_GEN_CONF:
ScanBus(0);
PrintConf();
return(0);
- break;
+
default:
break;
}
- if(read_conffile(CONFFILE_NAME)) {
- perror(CONFFILE_NAME);
- exit(1);
+ config_init(CONFIG_INIT_USE_CWD, NULL);
+
+ if (config_errors(NULL) >= CFGERR_WARNINGS) {
+ config_print_errors();
+ if (config_errors(NULL) >= CFGERR_ERRORS) {
+ g_critical(_("errors processing config file"));
+ }
}
- chg_scsi_conf = getconf_str(CNF_CHNGRFILE);
+ chg_scsi_conf = getconf_str(CNF_CHANGERFILE);
tape_device = getconf_str(CNF_TAPEDEV);
/* Get the configuration parameters */
/* Attention, this will not support more than 10 tape devices 0-9 */
/* */
if (strlen(tape_device)==1){
- if (read_config(chg_scsi_conf,&chg) == -1)
+ if (read_config(chg_scsi_conf, changer) == -1)
{
- fprintf(stderr, "%s open: of %s failed\n", get_pname(), chg_scsi_conf);
- return 2;
+ g_fprintf(stderr, _("%s open: of %s failed\n"), get_pname(), chg_scsi_conf);
+ return (2);
}
confnum=atoi(tape_device);
- if (chg.number_of_configs == 0)
+ if (changer->number_of_configs == 0)
{
- fprintf(stderr,"%s: chg.conf[%d] == NULL\n",get_pname(), confnum);
- return(2);
+ g_fprintf(stderr,_("%s: changer->conf[%d] == NULL\n"),
+ get_pname(), confnum);
+ return (2);
+ }
+ if (confnum >= changer->number_of_configs) {
+ g_fprintf(stderr,_("%s: Configuration %s config # out of range (%d >= %d)\n"),
+ get_pname(), chg_scsi_conf,
+ confnum,
+ changer->number_of_configs);
+ return (2);
}
- use_slots = chg.conf[confnum].end-chg.conf[confnum].start+1;
- slot_offset = chg.conf[confnum].start;
- drive_num = chg.conf[confnum].drivenum;
- need_eject = chg.eject;
- need_sleep = chg.sleep;
-
- if ( NULL != chg.conf[confnum].cleanfile)
- clean_file = stralloc(chg.conf[confnum].cleanfile);
+
+ use_slots = changer->conf[confnum].end-changer->conf[confnum].start+1;
+ slot_offset = changer->conf[confnum].start;
+ drive_num = changer->conf[confnum].drivenum;
+ need_eject = changer->eject;
+ need_sleep = changer->sleep;
+
+ if ( NULL != changer->conf[confnum].cleanfile)
+ clean_file = stralloc(changer->conf[confnum].cleanfile);
else
clean_file = NULL;
- clean_slot = chg.conf[confnum].cleanslot;
- maxclean = chg.cleanmax;
- emubarcode = chg.emubarcode;
- if (NULL != chg.conf[confnum].timefile)
- time_file = stralloc(chg.conf[confnum].timefile);
+ clean_slot = changer->conf[confnum].cleanslot;
+ maxclean = changer->cleanmax;
+ emubarcode = changer->emubarcode;
+ if (NULL != changer->conf[confnum].timefile)
+ time_file = stralloc(changer->conf[confnum].timefile);
+ else
+ time_file = NULL;
- if (NULL != chg.conf[confnum].slotfile)
- slot_file = stralloc(chg.conf[confnum].slotfile);
+ if (NULL != changer->conf[confnum].slotfile)
+ slot_file = stralloc(changer->conf[confnum].slotfile);
else
slot_file = NULL;
- if (NULL != chg.conf[confnum].device)
- tape_device = stralloc(chg.conf[confnum].device);
+ if (NULL != changer->conf[confnum].device)
+ tape_device = stralloc(changer->conf[confnum].device);
+ else
+ tape_device = NULL;
- if (NULL != chg.device)
- changer_dev = stralloc(chg.device);
+ if (NULL != changer->device)
+ changer_dev = stralloc(changer->device);
+ else
+ changer_dev = NULL;
- if (NULL != chg.conf[confnum].scsitapedev)
- scsitapedevice = stralloc(chg.conf[confnum].scsitapedev);
+ if (NULL != changer->conf[confnum].scsitapedev)
+ scsitapedevice = stralloc(changer->conf[confnum].scsitapedev);
+ else
+ scsitapedevice = NULL;
- if (NULL != chg.conf[confnum].tapestatfile)
- tapestatfile = stralloc(chg.conf[confnum].tapestatfile);
- dump_changer_struct(chg);
+ if (NULL != changer->conf[confnum].tapestatfile)
+ tapestatfile = stralloc(changer->conf[confnum].tapestatfile);
+ else
+ tapestatfile = NULL;
+ dump_changer_struct(changer);
* If we can't open it fail with a message
*/
- if (OpenDevice(INDEX_CHANGER , changer_dev, "changer_dev", chg.conf[confnum].changerident) == 0)
+ if (OpenDevice(INDEX_CHANGER , changer_dev, "changer_dev", changer->conf[confnum].changerident) == 0)
{
int localerr = errno;
- fprintf(stderr, "%s: open: %s: %s\n", get_pname(),
+ g_fprintf(stderr, _("%s: open: %s: %s\n"), get_pname(),
changer_dev, strerror(localerr));
- printf("%s open: %s: %s\n", "<none>", changer_dev, strerror(localerr));
- dbprintf(("%s: open: %s: %s\n", get_pname(),
- changer_dev, strerror(localerr)));
+ g_printf(_("%s open: %s: %s\n"), _("<none>"), changer_dev, strerror(localerr));
+ dbprintf(_("open: %s: %s\n"), changer_dev, strerror(localerr));
return 2;
}
*/
if (tape_device != NULL)
{
- if (OpenDevice(INDEX_TAPE, tape_device, "tape_device", chg.conf[confnum].tapeident) == 0)
+ if (OpenDevice(INDEX_TAPE, tape_device, "tape_device", changer->conf[confnum].tapeident) == 0)
{
- dbprintf(("warning open of %s: failed\n", tape_device));
+ dbprintf(_("warning open of %s: failed\n"), tape_device);
}
}
*/
if (scsitapedevice != NULL)
{
- if (OpenDevice(INDEX_TAPECTL, scsitapedevice, "scsitapedevice", chg.conf[confnum].tapeident) == 0)
+ if (OpenDevice(INDEX_TAPECTL, scsitapedevice, "scsitapedevice", changer->conf[confnum].tapeident) == 0)
{
- dbprintf(("warning open of %s: failed\n", scsitapedevice));
+ dbprintf(_("warning open of %s: failed\n"), scsitapedevice);
}
}
{
if (pDev[INDEX_TAPE].avail == 0 && pDev[INDEX_TAPECTL].avail == 0)
{
- printf("No device found for tape eject");
+ g_printf(_("No device found for tape eject"));
return(2);
}
}
- if ((chg.conf[confnum].end == -1) || (chg.conf[confnum].start == -1)){
+ if ((changer->conf[confnum].end == -1) || (changer->conf[confnum].start == -1)){
slotcnt = get_slot_count(fd);
use_slots = slotcnt;
slot_offset = 0;
* we need an label file
*/
- if ( chg.emubarcode == 1 || BarCode(INDEX_CHANGER) == 1)
+ if ( changer->emubarcode == 1 || BarCode(INDEX_CHANGER) == 1)
{
- if (chg.labelfile == NULL)
+ if (changer->labelfile == NULL)
{
- printf("labelfile param not set in your config\n");
+ g_printf(_("labelfile param not set in your config\n"));
return(2);
}
}
if (slot_file == NULL)
{
- printf("slotfile param. not set in your config\n");
+ g_printf(_("slotfile param. not set in your config\n"));
return(2);
}
if (access(slot_file,R_OK|W_OK) != 0)
{
- printf("slotfile %s does not exsist or is not read/write\n", slot_file);
+ g_printf(_("slotfile %s does not exsist or is not read/write\n"), slot_file);
return(2);
}
} else { /* if (strlen(tape_device)==1) */
- printf("please check your config and use a config file for chg-scsi\n");
+ g_printf(_("please check your config and use a config file for chg-scsi\n"));
return(2);
}
drivecnt = get_drive_count(fd);
if (drive_num > drivecnt) {
- printf("%s drive number error (%d > %d)\n", "<none>",
+ g_printf(_("%s drive number error (%d > %d)\n"), _("<none>"),
drive_num, drivecnt);
- fprintf(stderr, "%s: requested drive number (%d) greater than "
- "number of supported drives (%d)\n", get_pname(),
+ g_fprintf(stderr, _("%s: requested drive number (%d) greater than "
+ "number of supported drives (%d)\n"), get_pname(),
drive_num, drivecnt);
- dbprintf(("%s: requested drive number (%d) greater than "
- "number of supported drives (%d)\n", get_pname(),
- drive_num, drivecnt));
+ dbprintf(_("requested drive number (%d) is greater than "
+ "number of supported drives (%d)\n"), drive_num, drivecnt);
return 2;
}
- loaded = drive_loaded(fd, drive_num);
+ loaded = (int)drive_loaded(fd, drive_num);
target = -1;
switch(com.command_code) {
*/
case COM_DUMPDB:
pbarcoderes->action = BARCODE_DUMP;
- MapBarCode(chg.labelfile, pbarcoderes);
+ MapBarCode(changer->labelfile, pbarcoderes);
break;
case COM_STATUS:
- ChangerStatus(com.parameter, chg.labelfile, BarCode(fd),slot_file, changer_dev, tape_device);
+ ChangerStatus(com.parameter, changer->labelfile,
+ BarCode(fd), slot_file, changer_dev, tape_device);
break;
case COM_LABEL: /* Update BarCode/Label mapping file */
pbarcoderes->action = BARCODE_PUT;
- strcpy(pbarcoderes->data.voltag, com.parameter);
- strcpy( pbarcoderes->data.barcode, pDTE[drive_num].VolTag);
- MapBarCode(chg.labelfile, pbarcoderes);
- printf("0 0 0\n");
+ strncpy(pbarcoderes->data.voltag, com.parameter,
+ SIZEOF(pbarcoderes->data.voltag));
+ strncpy(pbarcoderes->data.barcode, pDTE[drive_num].VolTag,
+ SIZEOF(pbarcoderes->data.barcode));
+ MapBarCode(changer->labelfile, pbarcoderes);
+ g_printf("0 0 0\n");
break;
/*
oldtarget = get_current_slot(slot_file);
if (oldtarget < 0)
{
- dbprintf(("COM_INVENTORY: get_current_slot %d\n", oldtarget));
+ dbprintf(_("COM_INVENTORY: get_current_slot %d\n"), oldtarget);
oldtarget = find_empty(fd, slot_offset, use_slots);
- dbprintf(("COM_INVENTORY: find_empty %d\n", oldtarget));
+ dbprintf(_("COM_INVENTORY: find_empty %d\n"), oldtarget);
}
if (need_eject)
(void)unload(fd, drive_num, oldtarget);
if (ask_clean(scsitapedevice))
clean_tape(fd,tape_device,clean_file,drive_num,
- clean_slot,maxclean,time_file);
+ clean_slot, maxclean, time_file);
}
- Inventory(chg.labelfile, drive_num, need_eject, 0, 0, clean_slot);
+ Inventory(changer->labelfile, drive_num, need_eject, 0, 0, clean_slot);
do_inventory = 0; /* If set on exit the labeldb will be set to invalid ..... */
break;
*/
if (BarCode(fd) == 1 && emubarcode != 1)
{
- dbprintf(("search : look for %s\n", com.parameter));
+ dbprintf(_("search : look for %s\n"), com.parameter);
pbarcoderes->action = BARCODE_VOL;
pbarcoderes->data.slot = -1;
- strcpy(pbarcoderes->data.voltag, com.parameter);
- if (MapBarCode(chg.labelfile, pbarcoderes) == 1)
+ strncpy(pbarcoderes->data.voltag, com.parameter,
+ SIZEOF(pbarcoderes->data.voltag));
+ if (MapBarCode(changer->labelfile, pbarcoderes) == 1)
{
/*
* If both values are unset we have an problem
*/
if (pbarcoderes->data.slot == -1 && pbarcoderes->data.barcode == NULL)
{
- printf("Label %s not found (1)\n",com.parameter);
+ g_printf(_("Label %s not found (1)\n"),com.parameter);
endstatus = 2;
close(fd);
break;
if (pbarcoderes->data.barcode != NULL)
{
- for (x = 0; x < STE; x++)
+ for (x = 0; x < (int)STE; x++)
{
if (strcmp(pSTE[x].VolTag, pbarcoderes->data.barcode) == 0)
{
- dbprintf(("search : found slot %d\n", x));
+ dbprintf(_("search : found slot %d\n"), x);
target = x;
}
}
* If we find it check if it is in the right drive
* if we have more than one drive.
*/
- for (x = 0; x < DTE; x++)
+ for (x = 0; x < (int)DTE; x++)
{
if (strcmp(pDTE[x].VolTag, pbarcoderes->data.barcode) == 0)
{
- dbprintf(("search : found in tape %d\n", x));
+ dbprintf(_("search : found in tape %d\n"), x);
/*
*/
if (x == drive_num) {
oldtarget = get_current_slot(slot_file);
- printf("%d %s\n", oldtarget- slot_offset, tape_device);
+ g_printf("%d %s\n", oldtarget - slot_offset, tape_device);
return(0);
} else {
- printf("LABEL in wrong tape Unit\n");
+ g_printf(_("LABEL in wrong tape Unit\n"));
return(2);
}
}
*/
if (target == -1)
{
- printf("Label %s not found (2) \n",com.parameter);
+ g_printf(_("Label %s not found (2) \n"),com.parameter);
close(fd);
endstatus = 2;
break;
*/
if (target == -1)
{
- printf("Label %s not found (3)\n",com.parameter);
+ g_printf(_("Label %s not found (3)\n"),com.parameter);
close(fd);
endstatus = 2;
break;
*/
if (emubarcode == 1 && BarCode(fd) != 1)
{
- dbprintf(("search : look for %s\n", com.parameter));
+ dbprintf(_("search : look for %s\n"), com.parameter);
pbarcoderes->action = FIND_SLOT;
pbarcoderes->data.slot = -1;
- strcpy(pbarcoderes->data.voltag, com.parameter);
+ strncpy(pbarcoderes->data.voltag, com.parameter,
+ SIZEOF(pbarcoderes->data.voltag));
- if (MapBarCode(chg.labelfile, pbarcoderes) == 1)
+ if (MapBarCode(changer->labelfile, pbarcoderes) == 1)
{
if (pbarcoderes->data.valid == 1)
{
target = pbarcoderes->data.slot;
} else {
- printf("Barcode DB out of sync \n");
+ g_printf(_("Barcode DB out of sync \n"));
close(fd);
endstatus=2;
break;
}
} else {
- printf("Label %s not found \n",com.parameter);
+ g_printf(_("Label %s not found \n"),com.parameter);
close(fd);
endstatus = 2;
break;
{
if (is_positive_number(com.parameter)) {
if ((target = atoi(com.parameter))>=use_slots) {
- printf("<none> no slot `%d'\n",target);
+ g_printf(_("<none> no slot `%d'\n"),target);
close(fd);
endstatus = 2;
break;
} else {
- target = target+slot_offset;
+ target = target + slot_offset;
}
} else {
param_index=0;
- while((param_index<SLOTCOUNT)
- &&(strcmp(slotdefs[param_index].str,com.parameter))) {
+ while((param_index < SLOTCOUNT) &&
+ (strcmp(slotdefs[param_index].str,com.parameter))) {
param_index++;
}
target=get_relative_target(fd, use_slots,
com.parameter,param_index,
loaded,
slot_file,
- slot_offset,slot_offset+use_slots-1);
+ slot_offset,
+ (slot_offset + use_slots - 1));
}
}
oldtarget = get_current_slot(slot_file);
if (oldtarget < 0)
{
- dbprintf(("COM_SLOT: get_current_slot %d\n", oldtarget));
+ dbprintf(_("COM_SLOT: get_current_slot %d\n"), oldtarget);
oldtarget = find_empty(fd, slot_offset, use_slots);
- dbprintf(("COM_SLOT: find_empty %d\n", oldtarget));
+ dbprintf(_("COM_SLOT: find_empty %d\n"), oldtarget);
}
/*
(void)unload(fd, drive_num, oldtarget);
if (ask_clean(scsitapedevice))
- clean_tape(fd,tape_device,clean_file,drive_num,
- clean_slot,maxclean,time_file);
+ clean_tape(fd, tape_device, clean_file, drive_num,
+ clean_slot, maxclean, time_file);
loaded=0;
}
}
put_current_slot(slot_file, target);
if (!loaded && isempty(fd, target)) {
- printf("%d slot %d is empty\n",target-slot_offset,
- target-slot_offset);
+ g_printf(_("%d slot %d is empty\n"),target - slot_offset,
+ target - slot_offset);
close(fd);
endstatus = 1;
break;
if (!loaded && param_index != SLOT_ADVANCE)
{
if (ask_clean(scsitapedevice))
- clean_tape(fd,tape_device,clean_file,drive_num,
- clean_slot,maxclean,time_file);
+ clean_tape(fd, tape_device, clean_file, drive_num,
+ clean_slot, maxclean, time_file);
if (load(fd, drive_num, target) != 0) {
- printf("%d slot %d move failed\n",target-slot_offset,
- target-slot_offset);
+ g_printf(_("%d slot %d move failed\n"),target - slot_offset,
+ target - slot_offset);
close(fd);
endstatus = 2;
break;
{
if (Tape_Ready(INDEX_TAPECTL, need_sleep) == -1)
{
- printf("tape not ready\n");
+ g_printf(_("tape not ready\n"));
endstatus = 2;
break;
}
} else {
if (Tape_Ready(INDEX_TAPECTL, need_sleep) == -1)
{
- printf("tape not ready\n");
+ g_printf(_("tape not ready\n"));
endstatus = 2;
break;
}
}
}
- printf("%d %s\n", target-slot_offset, tape_device);
+ g_printf("%d %s\n", target - slot_offset, tape_device);
break;
case COM_INFO:
- loaded = get_current_slot(slot_file);
+ loaded = (int)get_current_slot(slot_file);
if (loaded < 0)
{
loaded = find_empty(fd, slot_offset, use_slots);
}
- loaded = loaded - slot_offset;
+ loaded = loaded - (int)slot_offset;
- printf("%d %d 1", loaded, use_slots);
+ g_printf("%d %d 1", loaded, use_slots);
if (BarCode(fd) == 1 || emubarcode == 1)
{
- printf(" 1\n");
+ g_printf(" 1\n");
} else {
- printf(" 0\n");
+ g_printf(" 0\n");
}
break;
if (target < 0)
{
- dbprintf(("COM_RESET: get_current_slot %d\n", target));
- target=find_empty(fd, slot_offset, use_slots);
- dbprintf(("COM_RESET: find_empty %d\n", target));
+ dbprintf(_("COM_RESET: get_current_slot %d\n"), target);
+ target = find_empty(fd, slot_offset, use_slots);
+ dbprintf(_("COM_RESET: find_empty %d\n"), target);
}
if (loaded) {
if (!isempty(fd, target))
- target=find_empty(fd, slot_offset, use_slots);
+ target = find_empty(fd, slot_offset, use_slots);
if (need_eject)
{
(void)unload(fd, drive_num, target);
if (ask_clean(scsitapedevice))
- clean_tape(fd,tape_device,clean_file,drive_num,clean_slot,
- maxclean,time_file);
+ clean_tape(fd,tape_device, clean_file, drive_num, clean_slot,
+ maxclean, time_file);
}
if (isempty(fd, slot_offset)) {
- printf("0 slot 0 is empty\n");
+ g_printf(_("0 slot 0 is empty\n"));
close(fd);
endstatus = 1;
break;
}
if (load(fd, drive_num, slot_offset) != 0) {
- printf("%d slot %d move failed\n",drive_num,
- slot_offset);
+ g_printf(_("%d slot %d move failed\n"),
+ drive_num, slot_offset);
close(fd);
put_current_slot(slot_file, slot_offset);
endstatus = 2;
{
if (Tape_Ready(INDEX_TAPECTL, need_sleep) == -1)
{
- printf("tape not ready\n");
+ g_printf(_("tape not ready\n"));
endstatus = 2;
break;
}
} else {
if (Tape_Ready(INDEX_TAPECTL, need_sleep) == -1)
{
- printf("tape not ready\n");
+ g_printf(_("tape not ready\n"));
endstatus = 2;
break;
}
}
}
- printf("%d %s\n", slot_offset, tape_device);
+ g_printf(_("%d %s\n"), slot_offset, tape_device);
break;
case COM_EJECT:
if (loaded) {
- target=get_current_slot(slot_file);
+ target = get_current_slot(slot_file);
if (target < 0)
{
- dbprintf(("COM_EJECT: get_current_slot %d\n", target));
+ dbprintf(_("COM_EJECT: get_current_slot %d\n"), target);
target = find_empty(fd, slot_offset, use_slots);
- dbprintf(("COM_EJECT: find_empty %d\n", target));
+ dbprintf(_("COM_EJECT: find_empty %d\n"), target);
}
if (need_eject)
(void)unload(fd, drive_num, target);
if (ask_clean(scsitapedevice))
- clean_tape(fd,tape_device,clean_file,drive_num,clean_slot,
- maxclean,time_file);
- printf("%d %s\n", target, tape_device);
+ clean_tape(fd, tape_device, clean_file, drive_num, clean_slot,
+ maxclean, time_file);
+ g_printf("%d %s\n", target, tape_device);
} else {
- printf("%d %s\n", target, "drive was not loaded");
+ g_printf(_("%d drive was not loaded\n"), target);
endstatus = 1;
}
break;
case COM_CLEAN:
if (loaded) {
- target=get_current_slot(slot_file);
+ target = get_current_slot(slot_file);
if (target < 0)
{
- dbprintf(("COM_CLEAN: get_current_slot %d\n", target));
+ dbprintf(_("COM_CLEAN: get_current_slot %d\n"), target);
target = find_empty(fd, slot_offset, use_slots);
- dbprintf(("COM_CLEAN: find_empty %d\n",target));
+ dbprintf(_("COM_CLEAN: find_empty %d\n"),target);
}
if (need_eject)
(void)unload(fd, drive_num, target);
}
- clean_tape(fd,tape_device,clean_file,drive_num,clean_slot,
- maxclean,time_file);
- printf("%s cleaned\n", tape_device);
+ clean_tape(fd, tape_device, clean_file, drive_num, clean_slot,
+ maxclean, time_file);
+ g_printf(_("%s cleaned\n"), tape_device);
break;
};
- /* FIX ME, should be an function to close the device */
+/* FIX ME, should be an function to close the device */
/* if (pChangerDev != NULL) */
/* close(pChangerDev->fd); */
#endif
- if (do_inventory == 1 && endstatus == 0 && chg.labelfile != NULL)
+ if (do_inventory == 1 && endstatus == 0 && changer->labelfile != NULL)
{
- if ( chg.autoinv == 1)
+ if (changer->autoinv == 1)
{
- DebugPrint(DEBUG_INFO,SECTION_INFO, "Do an inventory \n");
- Inventory(chg.labelfile, drive_num , chg.eject, 0, 0, clean_slot);
+ DebugPrint(DEBUG_INFO,SECTION_INFO, _("Do an inventory \n"));
+ Inventory(changer->labelfile, drive_num, changer->eject,
+ 0, 0, clean_slot);
} else {
- DebugPrint(DEBUG_INFO,SECTION_INFO, "Set all entrys in DB to invalid\n");
- memset(pbarcoderes, 0 , sizeof(MBC_T));
+ DebugPrint(DEBUG_INFO,SECTION_INFO, _("Set all entrys in DB to invalid\n"));
+ memset(pbarcoderes, 0 , SIZEOF(MBC_T));
pbarcoderes->action = RESET_VALID;
- MapBarCode(chg.labelfile,pbarcoderes);
+ MapBarCode(changer->labelfile,pbarcoderes);
}
}
- DebugPrint(DEBUG_INFO,SECTION_INFO,"Exit status -> %d\n", endstatus);
+ DebugPrint(DEBUG_INFO,SECTION_INFO,_("Exit status -> %d\n"), endstatus);
dbclose();
return endstatus;
}
* tab-width: 4
* End:
*/
-