-FILE *errf;
-
-int scan_init(rc, ns, bk)
-int rc, ns, bk;
-{
- if(rc)
- error("could not get changer info: %s", changer_resultstr);
-
- nslots = ns;
- backwards = bk;
-
- return 0;
-}
-
-int taperscan_slot(rc, slotstr, device)
-int rc;
-char *slotstr;
-char *device;
-{
- char *errstr;
-
- if(rc == 2) {
- fprintf(errf, "%s: fatal slot %s: %s\n",
- get_pname(), slotstr, changer_resultstr);
- return 1;
- }
- else if(rc == 1) {
- fprintf(errf, "%s: slot %s: %s\n",
- get_pname(), slotstr, changer_resultstr);
- return 0;
- }
- else {
- if((errstr = tape_rdlabel(device, &datestamp, &label)) != NULL) {
- fprintf(errf, "%s: slot %s: %s\n", get_pname(), slotstr, errstr);
- } else {
- /* got an amanda tape */
- fprintf(errf, "%s: slot %s: date %-8s label %s",
- get_pname(), slotstr, datestamp, label);
- if(searchlabel != NULL
- && (strcmp(label, FAKE_LABEL) == 0
- || strcmp(label, searchlabel) == 0)) {
- /* it's the one we are looking for, stop here */
- fprintf(errf, " (exact label match)\n");
- found_device = newstralloc(found_device, device);
- found = 1;
- return 1;
- }
- else if(!match(labelstr, label))
- fprintf(errf, " (no match)\n");
- else {
- /* not an exact label match, but a labelstr match */
- /* check against tape list */
- tp = lookup_tapelabel(label);
- if(tp == NULL)
- fprintf(errf, " (Not in tapelist)\n");
- else if(!reusable_tape(tp))
- fprintf(errf, " (active tape)\n");
- else if(got_match == 0 && tp->datestamp == 0) {
- got_match = 1;
- first_match = newstralloc(first_match, slotstr);
- first_match_label = newstralloc(first_match_label, label);
- fprintf(errf, " (new tape)\n");
- found = 3;
- found_device = newstralloc(found_device, device);
- return 1;
- }
- else if(got_match)
- fprintf(errf, " (labelstr match)\n");
- else {
- got_match = 1;
- first_match = newstralloc(first_match, slotstr);
- first_match_label = newstralloc(first_match_label, label);
- fprintf(errf, " (first labelstr match)\n");
- if(!backwards || !searchlabel) {
- found = 2;
- found_device = newstralloc(found_device, device);
- return 1;
- }
- }
- }
- }
- }
- return 0;
-}
-
-char *taper_scan()
-{
- char *outslot = NULL;
-
- if((tp = lookup_last_reusable_tape(0)) == NULL)
- searchlabel = NULL;
- else
- searchlabel = tp->label;
-
- found = 0;
- got_match = 0;
-
- changer_find(scan_init, taperscan_slot, searchlabel);
-
- if(found == 2 || found == 3)
- searchlabel = first_match_label;
- else if(!found && got_match) {
- searchlabel = first_match_label;
- amfree(found_device);
- if(changer_loadslot(first_match, &outslot, &found_device) == 0) {
- found = 1;
- }
- } else if(!found) {
- if(searchlabel) {
- changer_resultstr = newvstralloc(changer_resultstr,
- "label ", searchlabel,
- " or new tape not found in rack",
- NULL);
- } else {
- changer_resultstr = newstralloc(changer_resultstr,
- "new tape not found in rack");
- }
- }
- amfree(outslot);
-
- return found ? found_device : NULL;
-}
-
-int test_server_pgm(outf, dir, pgm, suid, dumpuid)
-FILE *outf;
-char *dir;
-char *pgm;
-int suid;
-uid_t dumpuid;