예제 #1
0
파일: dev.c 프로젝트: prelegalwonder/bacula
/*
 * Close the device
 */
bool DEVICE::close()
{
   bool ok = true;

   Dmsg4(40, "close_dev vol=%s fd=%d dev=%p dev=%s\n",
      VolHdr.VolumeName, m_fd, this, print_name());
   offline_or_rewind();

   if (!is_open()) {
      Dmsg2(200, "device %s already closed vol=%s\n", print_name(),
         VolHdr.VolumeName);
      return true;                    /* already closed */
   }

   switch (dev_type) {
   case B_VTL_DEV:
   case B_VTAPE_DEV:
   case B_TAPE_DEV:
      unlock_door();
      /* Fall through wanted */
   default:
      if (d_close(m_fd) != 0) {
         berrno be;
         dev_errno = errno;
         Mmsg2(errmsg, _("Error closing device %s. ERR=%s.\n"),
               print_name(), be.bstrerror());
         ok = false;
      }
      break; 
   }

   unmount(1);                       /* do unmount if required */
 
   /* Clean up device packet so it can be reused */
   clear_opened();

   /*
    * Be careful not to clear items needed by the DVD driver
    *    when it is closing a single part.
    */
   state &= ~(ST_LABEL|ST_READ|ST_APPEND|ST_EOT|ST_WEOT|ST_EOF|
              ST_NOSPACE|ST_MOUNTED|ST_MEDIA|ST_SHORT);
   label_type = B_BACULA_LABEL;
   file = block_num = 0;
   file_size = 0;
   file_addr = 0;
   EndFile = EndBlock = 0;
   openmode = 0;
   clear_volhdr();
   memset(&VolCatInfo, 0, sizeof(VolCatInfo));
   if (tid) {
      stop_thread_timer(tid);
      tid = 0;
   }
   return ok;
}
/*
 * Rewind device and put it offline
 *
 * Returns: true  on success
 *          false on failure
 */
bool generic_tape_device::offline()
{
   struct mtop mt_com;

   state &= ~(ST_APPENDREADY | ST_READREADY | ST_EOT | ST_EOF | ST_WEOT);  /* remove EOF/EOT flags */
   block_num = file = 0;
   file_size = 0;
   file_addr = 0;
   unlock_door();
   mt_com.mt_op = MTOFFL;
   mt_com.mt_count = 1;

   if (d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) {
      berrno be;
      dev_errno = errno;
      Mmsg2(errmsg, _("ioctl MTOFFL error on %s. ERR=%s.\n"), prt_name, be.bstrerror());
      return false;
   }
   Dmsg1(100, "Offlined device %s\n", prt_name);

   return true;
}
예제 #3
0
int do_open (string str)
{
  unlock_door ("east");
  open_door   ("east");
  return 1;
}
예제 #4
0
파일: dev.c 프로젝트: dl5rcw/bareos
/*
 * Close the device.
 */
bool DEVICE::close(DCR *dcr)
{
   bool retval = true;
   int status;
   Dmsg1(100, "close_dev %s\n", print_name());

   if (!is_open()) {
      Dmsg2(100, "device %s already closed vol=%s\n", print_name(), VolHdr.VolumeName);
      goto bail_out;                  /* already closed */
   }

   if (!norewindonclose) {
      offline_or_rewind();
   }

   switch (dev_type) {
   case B_VTL_DEV:
   case B_TAPE_DEV:
      unlock_door();
      /*
       * Fall through wanted
       */
   default:
      status = d_close(m_fd);
      if (status < 0) {
         berrno be;

         Mmsg2(errmsg, _("Unable to close device %s. ERR=%s\n"),
               print_name(), be.bstrerror());
         dev_errno = errno;
         retval = false;
      }
      break;
   }

   unmount(dcr, 1);                   /* do unmount if required */

   /*
    * Clean up device packet so it can be reused.
    */
   clear_opened();

   clear_bit(ST_LABEL, state);
   clear_bit(ST_READREADY, state);
   clear_bit(ST_APPENDREADY, state);
   clear_bit(ST_EOT, state);
   clear_bit(ST_WEOT, state);
   clear_bit(ST_EOF, state);
   clear_bit(ST_MOUNTED, state);
   clear_bit(ST_MEDIA, state);
   clear_bit(ST_SHORT, state);

   label_type = B_BAREOS_LABEL;
   file = block_num = 0;
   file_size = 0;
   file_addr = 0;
   EndFile = EndBlock = 0;
   open_mode = 0;
   clear_volhdr();
   memset(&VolCatInfo, 0, sizeof(VolCatInfo));
   if (tid) {
      stop_thread_timer(tid);
      tid = 0;
   }

   /*
    * We closed the device so let any plugin know we did.
    */
   if (dcr) {
      generate_plugin_event(dcr->jcr, bsdEventDeviceClose, dcr);
   }

bail_out:
   return retval;
}
예제 #5
0
void do_unlock( char_data* ch, char* argument )
{
  obj_data*         key;
  exit_data*       door;
  obj_data*         obj;
  oprog_data*     oprog;
  thing_data*     thing;

  if( ( thing = one_thing( ch, argument, "unlock",
    (thing_array*) &ch->in_room->exits, ch->array,
    &ch->contents ) ) == NULL )
    return;
   
  if( ( obj = object( thing ) ) != NULL ) {
    if( obj->pIndexData->item_type != ITEM_CONTAINER ) {
      send( ch, "%s isn't a container.\n\r", obj );
      return;
      }
    if( !is_set( &obj->value[1], CONT_CLOSED ) ) {
      send( ch, "%s isn't closed.\n\r", obj );
      return;
      }
    if( obj->pIndexData->value[2] < 0 ) {
      send( ch, "%s can't be unlocked.\n\r", obj );
      return;
      }
    if( ( key = has_key( ch, obj->pIndexData->value[2] ) ) == NULL ) {
      send( ch, "You lack the key.\n\r" );
      return;
      }
    if( !is_set( &obj->value[1], CONT_LOCKED ) ) {
      send( ch, "%s is already unlocked.\n\r", obj );
      return;
      }

    for( oprog = obj->pIndexData->oprog; oprog != NULL;
      oprog = oprog->next )
      if( oprog->trigger == OPROG_TRIGGER_UNLOCK ) {
        var_ch        = ch;
        var_room      = ch->in_room;
        var_obj       = key;
        var_container = obj;
        execute( oprog );
        break;
        }

    act( ch, prog_msg( oprog, unlock_msg[0], unlock_msg[1] ),
      obj, key );
    act_notchar( prog_msg( oprog, unlock_msg[2], unlock_msg[3] ),
      ch, obj, key );
    remove_bit( &obj->value[1], CONT_LOCKED );

    return;
    }

  if( ( door = exit( thing ) ) != NULL ) {
    unlock_door( ch, door );
    return;
    }

  send( ch, "%s isn't unlockable.\n\r", thing );
}