src/stored/dircmd.c
static bool readlabel_cmd(JCR *jcr)
{
   POOL_MEM devname;
   BSOCK *dir = jcr->dir_bsock;
   DEVICE *dev;
   DCR *dcr;
   int32_t Slot, drive;

   if (sscanf(dir->msg, "readlabel %127s Slot=%d drive=%d", devname.c_str(),
       &Slot, &drive) == 3) {
      dcr = find_device(jcr, devname, NULL, drive);
      if (dcr) {
         dev = dcr->dev;
         dev->Lock();                 /* Use P to avoid indefinite block */
         if (!dev->is_open()) {
            read_volume_label(jcr, dcr, dev, Slot);
            dev->close(dcr);
         /* Under certain "safe" conditions, we can steal the lock */
         } else if (dev->can_obtain_block()) {
            read_volume_label(jcr, dcr, dev, Slot);
         } else if (dev->is_busy() || dev->is_blocked()) {
            send_dir_busy_message(dir, dev);
         } else {                     /* device not being used */
            read_volume_label(jcr, dcr, dev, Slot);
         }
         dev->Unlock();
         free_dcr(dcr);
      } else {
         dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), devname.c_str());
      }
   } else {
      pm_strcpy(jcr->errmsg, dir->msg);
      dir->fsend(_("3909 Error scanning readlabel command: %s\n"), jcr->errmsg);
   }
   dir->signal(BNET_EOD);
   return true;
}
/*
 * Read and return the Volume label
 */
Read and return the Volume label
Read and return the Volume label
static bool readlabel_cmd(JCR *jcr)
{
   POOL_MEM devname;
   BSOCK *dir = jcr->dir_bsock;
   DEVICE *dev;
   DCR *dcr;
   int32_t Slot, drive;
   if (sscanf(dir->msg, "readlabel %127s Slot=%d drive=%d", devname.c_str(),
       &Slot, &drive) == 3) {
      dcr = find_device(jcr, devname, NULL, drive);
      if (dcr) {
         dev = dcr->dev;
         dev->Lock();                 
         if (!dev->is_open()) {
            read_volume_label(jcr, dcr, dev, Slot);
            dev->close(dcr);
         } else if (dev->can_obtain_block()) {
            read_volume_label(jcr, dcr, dev, Slot);
         } else if (dev->is_busy() || dev->is_blocked()) {
            send_dir_busy_message(dir, dev);
         } else {                     
            read_volume_label(jcr, dcr, dev, Slot);
         }
         dev->Unlock();
         free_dcr(dcr);
      } else {
         dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), devname.c_str());
      }
   } else {
      pm_strcpy(jcr->errmsg, dir->msg);
      dir->fsend(_("3909 Error scanning readlabel command: %s\n"), jcr->errmsg);
   }
   dir->signal(BNET_EOD);
   return true;
}
static bool readlabel_cmd ( JCR * jcr ) { POOL_MEM devname ; BSOCK * dir = jcr -> dir_bsock ; DEVICE * dev ; DCR * dcr ; int32_t Slot , drive ; if ( sscanf ( dir -> msg , " " , devname . c_str ( ) , & Slot , & drive ) == 3 ) { dcr = find_device ( jcr , devname , NULL , drive ) ; if ( dcr ) { dev = dcr -> dev ; dev -> Lock ( ) ; if ( ! dev -> is_open ( ) ) { read_volume_label ( jcr , dcr , dev , Slot ) ; dev -> close ( dcr ) ; } else if ( dev -> can_obtain_block ( ) ) { read_volume_label ( jcr , dcr , dev , Slot ) ; } else if ( dev -> is_busy ( ) || dev -> is_blocked ( ) ) { send_dir_busy_message ( dir , dev ) ; } else { read_volume_label ( jcr , dcr , dev , Slot ) ; } dev -> Unlock ( ) ; free_dcr ( dcr ) ; } else { dir -> fsend ( _ ( " \" \" \n " ) , devname . c_str ( ) ) ; } } else { pm_strcpy ( jcr -> errmsg , dir -> msg ) ; dir -> fsend ( _ ( " \n " ) , jcr -> errmsg ) ; } dir -> signal ( BNET_EOD ) ; return true ; }
Read and return the Volume label
Read and return the Volume label
/* Use P to avoid indefinite block */ /* Under certain "safe" conditions, we can steal the lock */ /* device not being used */