📄 chg-scsi.c
字号:
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; /* * Inventory does an scan of the library and updates the mapping in the label DB */ case COM_INVENTORY: do_inventory = 1; /* Tell the label check not to exit on label errors */ if (loaded) { oldtarget = get_current_slot(slot_file); if (oldtarget < 0) { 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); } if (need_eject) { eject_tape(scsitapedevice, need_eject); } else { if (pDev[INDEX_TAPECTL].avail == 1 && pDev[INDEX_TAPE].avail == 1) { LogSense(INDEX_TAPE); } } (void)unload(fd, drive_num, oldtarget); if (ask_clean(scsitapedevice)) clean_tape(fd,tape_device,clean_file,drive_num, clean_slot, maxclean, time_file); } 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; /* * Search for the tape, the index is the volume label */ case COM_SEARCH: /* * If we have an barcode reader use * this way */ if (BarCode(fd) == 1 && emubarcode != 1) { dbprintf(_("search : look for %s\n"), com.parameter); pbarcoderes->action = BARCODE_VOL; pbarcoderes->data.slot = -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 * so leave the program */ if (pbarcoderes->data.slot == -1 && pbarcoderes->data.barcode == NULL) { g_printf(_("Label %s not found (1)\n"),com.parameter); endstatus = 2; close(fd); break; } /* * Let's see, if we got an barcode check if it is * in the current inventory */ if (pbarcoderes->data.barcode != NULL) { for (x = 0; x < (int)STE; x++) { if (strcmp(pSTE[x].VolTag, pbarcoderes->data.barcode) == 0) { dbprintf(_("search : found slot %d\n"), x); target = x; } } /* * Not found in the STE slots * my be in the DTE (tape) * If we find it check if it is in the right drive * if we have more than one drive. */ for (x = 0; x < (int)DTE; x++) { if (strcmp(pDTE[x].VolTag, pbarcoderes->data.barcode) == 0) { dbprintf(_("search : found in tape %d\n"), x); /* */ if (x == drive_num) { oldtarget = get_current_slot(slot_file); g_printf("%d %s\n", oldtarget - slot_offset, tape_device); return(0); } else { g_printf(_("LABEL in wrong tape Unit\n")); return(2); } } } /* * not found, so do an exit... */ if (target == -1) { g_printf(_("Label %s not found (2) \n"),com.parameter); close(fd); endstatus = 2; break; } } /* if barcode[0] != 0 */ /* * If we didn't find anything we will try the info * from the DB. A reason for not finding anything in the inventory * might be an unreadable barcode label */ if (target == -1 && pbarcoderes->data.slot != -1) { target = pbarcoderes->data.slot; } /* * OK, if target is still -1 do the exit */ if (target == -1) { g_printf(_("Label %s not found (3)\n"),com.parameter); close(fd); endstatus = 2; break; } } } /* * And now if we have emubarcode set and no barcode reader * use this one */ if (emubarcode == 1 && BarCode(fd) != 1) { dbprintf(_("search : look for %s\n"), com.parameter); pbarcoderes->action = FIND_SLOT; pbarcoderes->data.slot = -1; strncpy(pbarcoderes->data.voltag, com.parameter, SIZEOF(pbarcoderes->data.voltag)); if (MapBarCode(changer->labelfile, pbarcoderes) == 1) { if (pbarcoderes->data.valid == 1) { target = pbarcoderes->data.slot; } else { g_printf(_("Barcode DB out of sync \n")); close(fd); endstatus=2; break; } } else { g_printf(_("Label %s not found \n"),com.parameter); close(fd); endstatus = 2; break; } } /* * The slot changing command */ case COM_SLOT: if (target == -1) { if (is_positive_number(com.parameter)) { if ((target = atoi(com.parameter))>=use_slots) { g_printf(_("<none> no slot `%d'\n"),target); close(fd); endstatus = 2; break; } else { target = target + slot_offset; } } else { param_index=0; 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)); } } if (loaded) { oldtarget = get_current_slot(slot_file); if (oldtarget < 0) { 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); } /* * TODO check if the request slot for the unload is empty */ if ((oldtarget)!=target) { if (need_eject) { eject_tape(scsitapedevice, need_eject); } else { /* * If we have an SCSI path to the tape and an raw io path * try to read the Error Counter and the label */ if (pDev[INDEX_TAPECTL].avail == 1 && pDev[INDEX_TAPE].avail == 1) { LogSense(INDEX_TAPE); } } (void)unload(fd, drive_num, oldtarget); if (ask_clean(scsitapedevice)) 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)) { 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); if (load(fd, drive_num, target) != 0) { g_printf(_("%d slot %d move failed\n"),target - slot_offset, target - slot_offset); close(fd); endstatus = 2; break; } } if (need_sleep) { if (pDev[INDEX_TAPECTL].inqdone == 1) { if (Tape_Ready(INDEX_TAPECTL, need_sleep) == -1) { g_printf(_("tape not ready\n")); endstatus = 2; break; } } else { if (Tape_Ready(INDEX_TAPECTL, need_sleep) == -1) { g_printf(_("tape not ready\n")); endstatus = 2; break; } } } g_printf("%d %s\n", target - slot_offset, tape_device); break; case COM_INFO: loaded = (int)get_current_slot(slot_file); if (loaded < 0) { loaded = find_empty(fd, slot_offset, use_slots); } loaded = loaded - (int)slot_offset; g_printf("%d %d 1", loaded, use_slots); if (BarCode(fd) == 1 || emubarcode == 1) { g_printf(" 1\n"); } else { g_printf(" 0\n"); } break; case COM_RESET: target=get_current_slot(slot_file); 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); } if (loaded) { if (!isempty(fd, target)) target = find_empty(fd, slot_offset, use_slots); if (need_eject) { eject_tape(scsitapedevice, need_eject); } else { /* * If we have an SCSI path to the tape and an raw io path * try to read the Error Counter and the label */ if (pDev[INDEX_TAPECTL].avail == 1 && pDev[INDEX_TAPE].avail == 1) { LogSense(INDEX_TAPE); } } (void)unload(fd, drive_num, target); if (ask_clean(scsitapedevice)) clean_tape(fd,tape_device, clean_file, drive_num, clean_slot, maxclean, time_file); } if (isempty(fd, slot_offset)) { g_printf(_("0 slot 0 is empty\n")); close(fd); endstatus = 1; break; } if (load(fd, drive_num, slot_offset) != 0) { g_printf(_("%d slot %d move failed\n"), drive_num, slot_offset); close(fd); put_current_slot(slot_file, slot_offset); endstatus = 2; break; } put_current_slot(slot_file, slot_offset); if (need_sleep) { if (pDev[INDEX_TAPECTL].inqdone == 1) { if (Tape_Ready(INDEX_TAPECTL, need_sleep) == -1) { g_printf(_("tape not ready\n")); endstatus = 2; break; } } else { if (Tape_Ready(INDEX_TAPECTL, need_sleep) == -1) { g_printf(_("tape not ready\n")); endstatus = 2; break; } } } g_printf(_("%d %s\n"), slot_offset, tape_device); break; case COM_EJECT: if (loaded) { target = get_current_slot(slot_file); if (target < 0) { 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); } if (need_eject) { eject_tape(scsitapedevice, need_eject); } else { if (pDev[INDEX_TAPECTL].avail == 1 && pDev[INDEX_TAPE].avail == 1) { LogSense(INDEX_TAPE); } } (void)unload(fd, drive_num, target); if (ask_clean(scsitapedevice)) clean_tape(fd, tape_device, clean_file, drive_num, clean_slot, maxclean, time_file); g_printf("%d %s\n", target, tape_device); } else { g_printf(_("%d drive was not loaded\n"), target); endstatus = 1; } break; case COM_CLEAN: if (loaded) { target = get_current_slot(slot_file); if (target < 0) { 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); } if (need_eject) { eject_tape(scsitapedevice, need_eject); } else { if (pDev[INDEX_TAPECTL].avail == 1 && pDev[INDEX_TAPE].avail == 1) { LogSense(INDEX_TAPE); } } (void)unload(fd, drive_num, target); } 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 */ /* if (pChangerDev != NULL) *//* close(pChangerDev->fd); */ /* if (pTapeDev != NULL) *//* close(pTapeDev->fd); *//* if (pTapeDevCtl != NULL) *//* close(pTapeDevCtl->fd); */#endif if (do_inventory == 1 && endstatus == 0 && changer->labelfile != NULL) { if (changer->autoinv == 1) { 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)); pbarcoderes->action = RESET_VALID; MapBarCode(changer->labelfile,pbarcoderes); } } DebugPrint(DEBUG_INFO,SECTION_INFO,_("Exit status -> %d\n"), endstatus); dbclose(); return endstatus;}/* * Local variables: * indent-tabs-mode: nil * tab-width: 4 * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -