📄 label_tape.c
字号:
fprintf(stderr, T_("Error: Cannot determine location of cartridge %d after" " requesting manual interaction.\n"), (int) cartnum); return(i); } if(j != sourcetype){ /* user moved the tape manually to a slot */ if(j == LOC_SLOT) /* and told us about it */ free_slot = sourcenum; } if(sourcetype == LOC_EXTERNAL || sourcetype == LOC_UNKNOWN){ if(targettype != LOC_EXTERNAL && targettype != LOC_LOADPORT){ if(cartmove_cmds[LOC_LOADPORT][targettype] && free_loadport > 0){ ER__(genmove(cartnum, LOC_LOADPORT, free_loadport, tgt_changer_or_text, targettype, targetnum, tgt_changer_or_text), i); } else if(targettype == LOC_DRIVE && cartmove_cmds[LOC_SLOT][targettype] && free_slot > 0){ ER__(genmove(cartnum, LOC_SLOT, free_slot, tgt_changer_or_text, targettype, targetnum, tgt_changer_or_text), i); } } } return(0); } cptr = cartmove_cmds[sourcetype][targettype]; if(!cptr){ if(interactive){ fp = stderr; } else{ fp = tmp_fp(NULL); } fprintf(fp, T_("Error: No command configured to perform the " "requested cartridge move from %s to %s.\n"), T_(loc_strings[sourcetype]), T_(loc_strings[targettype])); if(!interactive) message_to_operator(fp, YES); return(22); } EM__(cptr = repl_substring(cptr, "%d", devicename)); EM__(cmd = repl_substring(cptr, "%D", changername)); free(cptr); sprintf(nbuf, "%d", (int) sourcenum - 1); EM__(cptr = repl_substring(cmd, "%m", nbuf)); free(cmd); sprintf(nbuf, "%d", (int) sourcenum); EM__(cmd = repl_substring(cptr, "%n", nbuf)); free(cptr); sprintf(nbuf, "%d", (int) targetnum - 1); EM__(cptr = repl_substring(cmd, "%M", nbuf)); free(cmd); sprintf(nbuf, "%d", (int) targetnum); EM__(cmd = repl_substring(cptr, "%N", nbuf)); free(cptr); i = poll_changer_cmd(cmd, !interactive, NO); if(!i && cartnum > 0) i = set_location(cartnum, targettype, tgt_changer_or_text, targetnum); return(i);}static Int32 /* genmove with lock on streamer, if necessary */genmove_drlock( Int32 cartnum, /* this is just to inform a maintainer */ Int32 sourcetype, Int32 sourcenum, UChar *src_changer_or_text, Int32 targettype, Int32 targetnum, UChar *tgt_changer_or_text){ Int32 i; Flag dr; dr = (sourcetype == LOC_DRIVE || targettype == LOC_DRIVE); if(dr){ i = set_lock(&devicelock, forced); if(i != BU_GOT_LOCK && !forced){ report_problem("%s: %s.\n", T_("Error"), T_("An application using the device seems to be running")); return(19); } } i = genmove(cartnum, sourcetype, sourcenum, src_changer_or_text, targettype, targetnum, tgt_changer_or_text); if(dr) release_lock(&devicelock); return(i);}Int32cart_in_location( Int32 ltype, Int32 num, UChar *changer){ KeyValuePair *list = NULL; UChar *word = NULL, *locstr, *cptr; Int32 i, n, r = 0; int i1; if(ltype == LOC_EXTERNAL || ltype == LOC_UNKNOWN){ errno = EINVAL; return(-1); } locstr = loc_strings[ltype]; list = kfile_getall(cartloc_file, &n, KFILE_LOCKED); if(!list) return(0); for(i = 0; i < n; i++){ if(word_count(list[i].value) != 3) continue; word = ZRENEWP(word, UChar, strlen(list[i].value) + 1); if(!word) CLEANUPR(-2); cptr = sscanword(list[i].value, word); if(strcmp(word, changer)) continue; cptr = sscanword(cptr, word); if(strcmp(word, locstr)) continue; sscanf(cptr, "%d", &i1); if(i1 == num){ if(sscanf(list[i].key, "%d", &i1) < 1) continue; r = i1; break; } } cleanup: ZFREE(word); kfile_freeall(list, n); return(r);}static Int32 /* we assume, that cart is in drive, it is not checked here */unload_cart_to_free_slot(Int32 cart, UChar * changer){ Int32 first_free_slot; first_free_slot = get_first_free_slot(changer); if(first_free_slot < 1){ report_problem(T_("Error: No free slot found to unload drive.\n")); return(-4); } return(move_cartridge_to(cart, LOC_SLOT, changer, first_free_slot));}static Int32move_cartridge_to( Int32 cartnum, Int32 tgttype, UChar *tgt_changer_or_text, Int32 tgtnum){ Int32 i; UChar *src_changer_or_text; Int32 srctype; Int32 srcnum; ER__(get_location(cartnum, &srctype, &src_changer_or_text, &srcnum), i); if(srctype == tgttype && (srcnum == tgtnum || srctype == LOC_EXTERNAL || srctype == LOC_UNKNOWN) && !strcmp(src_changer_or_text, tgt_changer_or_text)) return(0); if(set_lock_msg(&changerlock, forced, !interactive) != BU_GOT_LOCK && !forced) return(-3); if(tgttype == LOC_DRIVE){ i = cart_in_location(tgttype, tgtnum, tgt_changer_or_text); if(i > 0){ ER__(unload_cart_to_free_slot(i, tgt_changer_or_text), i); } } if(tgttype == LOC_LOADPORT || tgttype == LOC_SLOT){ i = cart_in_location(tgttype, tgtnum, tgt_changer_or_text); if(i > 0){ report_problem(T_("Error: Target location %s %d is not empty.\n"), T_(loc_strings[tgttype]), (int) tgtnum); return(-2); } } i = genmove_drlock(cartnum, srctype, srcnum, src_changer_or_text, tgttype, tgtnum, tgt_changer_or_text); if(i){ if(tgttype == LOC_EXTERNAL) report_problem(T_("Error: Moving cartridge %d to location `%s' failed with status %d\n"), (int) cartnum, tgt_changer_or_text, (int) i); else report_problem(T_("Error: Moving cartridge %d to %s %d in %s failed with status %d\n"), (int) cartnum, T_(loc_strings[tgttype]), (int) tgtnum, changername, (int) i); } if(!i){ forever{ i = cart_in_location(tgttype, tgtnum, tgt_changer_or_text); if(i == cartnum || i <= 0) break; /* This happens, when some bad guy modifies */ /* the database manually during our move */ report_problem(T_("Warning: The location of the cartridge %d is set to %s.\n"), (int) i, T_("unknown")); set_location_msg(i, LOC_UNKNOWN, NULL, 0); } i = set_location_msg(cartnum, tgttype, tgt_changer_or_text, tgtnum); } return(i);}static intcart_ctl(Int32 argc, UChar ** argv){ Int32 i, j, n, cart; Int32 tgtnum, res; Int32 tgtrange; /* uninitialized OK */ Int32 tgttype; UChar *cptr; Uns32Range *targets, *overset, *free_slots; KeyValuePair *cartlocs; int i1, n1; if(given_changer){ ZFREE(changername); changername = given_changer; } if(changerconffile) /* read configuration */ if(empty_string(changerconffile)) ZFREE(changerconffile); if(changerconffile) massage_string(changerconffile); if(!changerconffile){ fprintf(stderr, T_("Error: No changer configuration file configured.\n")); return(20); } EEM__(repl_dirs(&changerconffile)); if(access(changerconffile, R_OK)){ fprintf(stderr, T_("Error: Cannot read changer configuration file `%s'.\n"), changerconffile); return(21); } n = NUM_PRESET_CHCF_ENTRIES; for(i = 0; i < 3; i++){ /* prepare commands entry data to be read */ for(j = 0; j < 3; j++){ sprintf(tmpbuf, "[Mm][Oo][Vv][Ee][-_ \t]*%s[-_ \t]*[Tt][Oo]" "[-_ \t]*%s[-_ \t]*[Cc][Oo]?[Mm][Mm]?[Aa]?[Nn]?[Dd]:?[ \t]*", loc_re_strings[i], loc_re_strings[j]); SETZERO(changerconf[n]); changerconf[n].entry_ptr = &(cartmove_cmds[i][j]); EM__(changerconf[n].pattern = strdup(tmpbuf)); changerconf[n].type = TypeUCharPTR; cartmove_cmds[i][j] = NULL; n++; } } if(n != NUM_CHCF_ENTRIES){ perror("Internal Error: Implementation of changerconfig-entries"); return(2); } /* read configuration file */ i = read_param_file(changerconffile, changerconf, NUM_CHCF_ENTRIES, NULL, NULL); if(i){ fprintf(stderr, T_("Error: Cannot read changer configuration file `%s'.\n"), changerconffile); return(3); } /* check configuration consistency */ if(!changername){ fprintf(stderr, T_("Error: No media changer is configured in `%s'.\n"), configfile); return(27); } if(access(changername, F_OK)){ fprintf(stderr, T_("Error: The media changer device `%s' does not exist.\n"), changername); return(28); } if(num_changer_loadports > 0){ if(!freeloadports_cmd){ fprintf(stderr, T_("Error: No command configured in `%s' to determine the free loadports.\n"), changerconffile); return(35); } else{ EM__(cptr = repl_substring(freeloadports_cmd, "%D", changername)); free(freeloadports_cmd); freeloadports_cmd = cptr; } } if(!freeslots_cmd){ fprintf(stderr, T_("Error: No command configured in `%s' to determine the free slots.\n"), changerconffile); return(29); } else{ EM__(cptr = repl_substring(freeslots_cmd, "%D", changername)); free(freeslots_cmd); freeslots_cmd = cptr; } /* convert argument strings to data */ if(cartstr){ EM__(cartridges = sscan_Uns32Ranges_(cartstr, 1, num_cartridges, NULL, NULL)); n_cartridges = num_Uns32Ranges(cartridges); } if(have_drive_arg > 0 && drivestr){ EM__(drives = sscan_Uns32Ranges_(drivestr, 1, MAXINT, NULL, NULL)); n_drives = num_Uns32Ranges(drives); if(n_drives < 1){ massage_string(drivestr); if(!strcmp(drivestr, devicename)){ ZFREE(drives); have_drive_arg = 0; /* this makes the next if being true */ } else{ fprintf(stderr, T_("Error: The argument to specify the drives could not be evaluated.\n")); return(30); } } } if(have_drive_arg == 0){ EM__(drives = add_to_Uns32Ranges(drives, 1, 1)); /* evtl eject all */ n_drives = 1; } if(have_slot_arg > 0 && slotstr){ EM__(slots = sscan_Uns32Ranges_(slotstr, 1, num_changer_slots, NULL, NULL)); n_slots = num_Uns32Ranges(slots); } if(have_slot_arg == 0 && cctl_move){ slots = get_free_slots(changername); i = num_Uns32Ranges(slots); if(n_cartridges > i){ fprintf(stderr, T_("Error: Not enough free slots found.\n")); return(38); } while(num_Uns32Ranges(slots) > n_cartridges){ EM__(slots = del_one_from_Uns32Ranges(slots, prev_in_Uns32Ranges(slots, 1, YES))); } n_slots = n_cartridges; } if(have_loadp_arg > 0 && loadportstr){ EM__(loadports = sscan_Uns32Ranges_(loadportstr, 1, MAXINT, NULL, NULL)); n_loadports = num_Uns32Ranges(loadports); } if(have_loadp_arg == 0){ if(cctl_move){ loadports = get_free_loadports(changername); i = num_Uns32Ranges(loadports); if(n_cartridges > i){ fprintf(stderr, T_("Error: Not enough free loadports found.\n")); return(38); } while(num_Uns32Ranges(loadports) > n_cartridges){ EM__(loadports = del_one_from_Uns32Ranges(loadports, prev_in_Uns32Ranges(loadports, 1, YES))); } n_loadports = n_cartridges; } else{ if(!cctl_list){ EM__(loadports = add_to_Uns32Ranges(loadports, 1, 1)); n_loadports = 1; } } } if(changerlock.lockfile) if(empty_string(changerlock.lockfile)) changerlock.lockfile = NULL; if(changerlock.lockfile) massage_string(changerlock.lockfile); if(!changerlock.lockfile) changerlock.lockfile = select_lockfile(DEFAULT_CHANGERLOCKFILE); EEM__(repl_dirs(&changerlock.lockfile)); /* check command semantics */ if(cctl_move + cctl_inventory + cctl_label + cctl_list + cctl_eject < 1 && have_loc_arg < 0){ fprintf(stderr, T_("Error: At least one of the following flags must be supplied: ilmPte\n")); usage(argv[0], mode); } if(cctl_inventory && cctl_label){ fprintf(stderr, T_("Error: The flags -t and -i are not allowed together.\n")); usage(argv[0], mode); } if(cctl_eject){ if(cartstr){ fprintf(stderr, T_("Error: The flags -e and -C are not allowed together.\n")); usage(argv[0], mode); } cctl_move = YES; /* just set up the parameters to do moves */ if(!drives){ EM__(drives = add_to_Uns32Ranges(drives, 1, 1)); n_drives = num_Uns32Ranges(drives); } /* later: all drives */ cartridges = NULL; for(i = 0; drives[i].first <= drives[i].last; i++){ for(j = drives[i].first; j <= drives[i].last; j++){ n = cart_in_location(LOC_DRIVE, j, changername); if(n > 0) EM__(cartridges = add_to_Uns32Ranges(cartridges, n, n)); } } if((n_cartridges = num_Uns32Ranges(cartridges)) < 1) return(0); /* all drives empty */ if(!slots){ slots = get_free_slots(changername); while((n_slots = num_Uns32Ranges(slots)) > n_cartridges){ EM__(slots = del_one_from_Uns32Ranges(slots, prev_in_Uns32Ranges(slots, 1, YES))); } if(n_slots < n_cartridges){ fprintf(stderr, T_("Error: Not enough free slots found.\n")); return(40); } } } if(have_loadp_arg >= 0 && num_changer_loadports < 1){ fprintf(stderr, "Error: Changer does not have any loadport.\n"); return(34); } if(cctl_move || have_loc_arg >= 0){ if(!n_slots && !n_loadports && !n_drives && have_loc_arg < 0){ fprintf(stderr, T_("Error: Targets to move the cartridges to must be given using one of the flags: DLSP\n")); usage(argv[0], mode); } } if(cctl_move || have_loc_arg >= 0){ if(!cartridges){ fprintf(stderr, T_("Error: The cartridges must be specified using the flag -C\n")); usage(argv[0], mode); } if(slots && n_cartridges != n_slots){ fprintf(stderr, T_("Error: Number of given slots (%d) is unequal to the number of given cartridges (%d).\n"), (int) n_slots, (int) n_cartridges); return(26); } } if(cctl_move || have_loc_arg >= 0){ if(drives && n_cartridges != n_drives){ fprintf(stderr, T_("Error: Number of given drives (%d) is unequal to the number of given cartridges (%d).\n"), (int) n_drives, (int) n_cartridges); return(26); } if(loadports && n_cartridges != n_loadports){ fprintf(stderr, T_("Error: Number of given loadports (%d) is unequal to the number of given cartridges (%d).\n"), (int) n_loadports, (int) n_cartridges); return(26); } } if(cctl_label){ if(!n_slots && !n_cartridges){ fprintf(stderr, T_("Error: The slots or cartridges must be given using the -S or -C option.\n")); usage(argv[0], mode); } if(!n_slots){ ZFREE(slots); for(i = 0; i < len_Uns32Ranges(cartridges); i++){ for(j = cartridges[i].first; j <= cartridges[i].last; j++){ get_location(j, &tgttype, NULL, &tgtnum); if(tgttype != LOC_SLOT){ fprintf(stderr, T_("Error: Cartridge %d is not in any media changer slot.\n"), (int) j); return(36); } EM__(slots = add_to_Uns32Ranges(slots, tgtnum, tgtnum)); pack_Uns32Ranges(slots, &n_slots); } } } if(!n_cartridges){ ZFREE(cartridges); for(i = 0; i < len_Uns32Ranges(slots); i++){ for(j = slots[i].first; j <= slots[i].last; j++){ tgtnum = cart_in_location(LOC_SLOT, j, changername);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -