* Version $Id$
*/
/*
- Copyright (C) 2000-2005 Kern Sibbald
+ Copyright (C) 2002-2005 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
#include "stored.h" /* pull in Storage Deamon headers */
/* Forward referenced functions */
-static int get_autochanger_loaded_slot(DCR *dcr);
static void lock_changer(DCR *dcr);
static void unlock_changer(DCR *dcr);
slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0;
/*
* Handle autoloaders here. If we cannot autoload it, we
- * will return FALSE to ask the sysop.
+ * will return 0 so that the sysop will be asked to load it.
*/
- if (writing && dev_cap(dev, CAP_AUTOCHANGER) && slot <= 0) {
+ if (writing && dev->is_autochanger() && slot <= 0) {
if (dir) {
return 0; /* For user, bail out right now */
}
if (loaded != slot) {
offline_or_rewind_dev(dev);
/* We are going to load a new tape, so close the device */
- force_close_dev(dev);
+ force_close_device(dev);
lock_changer(dcr);
if (loaded != 0 && loaded != -1) { /* must unload drive */
Dmsg0(400, "Doing changer unload.\n");
Jmsg(jcr, M_FATAL, 0, _("3992 Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n"),
slot, drive, be.strerror());
goto bail_out;
+ } else {
+ dev->Slot = 0; /* nothing loaded now */
}
-
Dmsg1(400, "unload status=%d\n", status);
}
/*
if (status == 0) {
Jmsg(jcr, M_INFO, 0, _("3305 Autochanger \"load slot %d, drive %d\", status is OK.\n"),
slot, drive);
+ dev->Slot = slot; /* set currently loaded slot */
} else {
berrno be;
be.set_errno(status);
Dmsg2(400, "load slot %d status=%d\n", slot, status);
} else {
status = 0; /* we got what we want */
+ dev->Slot = slot; /* set currently loaded slot */
}
Dmsg1(400, "After changer, status=%d\n", status);
if (status == 0) { /* did we succeed? */
}
-static int get_autochanger_loaded_slot(DCR *dcr)
+/*
+ * Returns: -1 if error from changer command
+ * slot otherwise
+ */
+int get_autochanger_loaded_slot(DCR *dcr)
{
JCR *jcr = dcr->jcr;
POOLMEM *changer, *results;
int status, loaded;
uint32_t timeout = dcr->device->max_changer_wait;
- int drive = dcr->device->drive_index;
+ int drive = dcr->dev->drive_index;
results = get_pool_memory(PM_MESSAGE);
changer = get_pool_memory(PM_FNAME);
/* Find out what is loaded, zero means device is unloaded */
Jmsg(jcr, M_INFO, 0, _("3301 Issuing autochanger \"loaded drive %d\" command.\n"),
drive);
- changer = edit_device_codes(dcr, changer,
- dcr->device->changer_command, "loaded");
+ changer = edit_device_codes(dcr, changer, dcr->device->changer_command, "loaded");
+ *results = 0;
status = run_program(changer, timeout, results);
- Dmsg3(50, "run_prog: %s stat=%d result=%s", changer, status, results);
+ Dmsg3(50, "run_prog: %s stat=%d result=%s\n", changer, status, results);
if (status == 0) {
loaded = atoi(results);
if (loaded > 0) {
Jmsg(jcr, M_INFO, 0, _("3302 Autochanger \"loaded drive %d\", result is Slot %d.\n"),
drive, loaded);
+ dcr->dev->Slot = loaded;
} else {
Jmsg(jcr, M_INFO, 0, _("3302 Autochanger \"loaded drive %d\", result: nothing loaded.\n"),
drive);
+ dcr->dev->Slot = 0;
}
} else {
berrno be;
bool ok = false;
int stat;
- if (!dev_cap(dev, CAP_AUTOCHANGER) || !dcr->device->changer_name ||
+ if (!dev->is_autochanger() || !dcr->device->changer_name ||
!dcr->device->changer_command) {
- bnet_fsend(dir, _("3993 Not a autochanger device.\n"));
+ bnet_fsend(dir, _("3993 Device %s not an autochanger device.\n"),
+ dev->print_name());
return false;
}
/* Yes, to get a good listing, we unload any volumes */
offline_or_rewind_dev(dev);
/* We are going to load a new tape, so close the device */
- force_close_dev(dev);
+ force_close_device(dev);
/* First unload any tape */
loaded = get_autochanger_loaded_slot(dcr);
be.set_errno(stat);
Jmsg(jcr, M_INFO, 0, _("3995 Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n"),
slot, drive, be.strerror());
+ } else {
+ dev->Slot = 0; /* nothing loaded */
}
dcr->VolCatInfo.Slot = slot;
}
bpipe = open_bpipe(changer, timeout, "r");
if (!bpipe) {
unlock_changer(dcr);
- bnet_fsend(dir, _("3993 Open bpipe failed.\n"));
+ bnet_fsend(dir, _("3996 Open bpipe failed.\n"));
goto bail_out;
}
if (strcmp(cmd, "list") == 0) {