src/dird/ua_label.c
static void label_from_barcodes(UAContext *ua, int drive)
{
   STORE *store = ua->jcr->wstore;
   POOL_DBR pr;
   MEDIA_DBR mr, omr;
   vol_list_t *vl, *vol_list = NULL;
   bool media_record_exists;
   char *slot_list;
   int max_slots;


   max_slots = get_num_slots_from_SD(ua);
   if (max_slots <= 0) {
      ua->warning_msg(_("No slots in changer to scan.\n"));
      return;
   }
   slot_list = (char *)malloc(max_slots+1);
   if (!get_user_slot_list(ua, slot_list, max_slots)) {
      goto bail_out;
   }

   vol_list = get_vol_list_from_SD(ua, false /*no scan*/);

   if (!vol_list) {
      ua->warning_msg(_("No Volumes found to label, or no barcodes.\n"));
      goto bail_out;
   }

   /* Display list of Volumes and ask if he really wants to proceed */
   ua->send_msg(_("The following Volumes will be labeled:\n"
                  "Slot  Volume\n"
                  "==============\n"));
   for (vl=vol_list; vl; vl=vl->next) {
      if (!vl->VolName || !slot_list[vl->Slot]) {
         continue;
      }
      ua->send_msg("%4d  %s\n", vl->Slot, vl->VolName);
   }
   if (!get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) ||
       (ua->pint32_val == 0)) {
      goto bail_out;
   }
   /* Select a pool */
   memset(&pr, 0, sizeof(pr));
   if (!select_pool_dbr(ua, &pr)) {
      goto bail_out;
   }

   /* Fire off the label requests */
   for (vl=vol_list; vl; vl=vl->next) {
      if (!vl->VolName || !slot_list[vl->Slot]) {
         continue;
      }
      mr.clear();
      bstrncpy(mr.VolumeName, vl->VolName, sizeof(mr.VolumeName));
      media_record_exists = false;
      if (db_get_media_record(ua->jcr, ua->db, &mr)) {
          if (mr.VolBytes != 0) {
             ua->warning_msg(_("Media record for Slot %d Volume \"%s\" already exists.\n"),
                vl->Slot, mr.VolumeName);
             mr.Slot = vl->Slot;
             mr.InChanger = mr.Slot > 0;  /* if slot give assume in changer */
             set_storageid_in_mr(store, &mr);
             if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
                ua->error_msg(_("Error setting InChanger: ERR=%s"), db_strerror(ua->db));
             }
             continue;
          }
          media_record_exists = true;
      }
      mr.InChanger = mr.Slot > 0;  /* if slot give assume in changer */
      set_storageid_in_mr(store, &mr);
      /*
       * Deal with creating cleaning tape here. Normal tapes created in
       *  send_label_request() below
       */
      if (is_cleaning_tape(ua, &mr, &pr)) {
         if (media_record_exists) {      /* we update it */
            mr.VolBytes = 1;             /* any bytes to indicate it exists */
            bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
            mr.MediaType[0] = 0;
            set_storageid_in_mr(store, &mr);
            if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
                ua->error_msg("%s", db_strerror(ua->db));
            }
         } else {                        /* create the media record */
            if (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
               ua->error_msg(_("Maximum pool Volumes=%d reached.\n"), pr.MaxVols);
               goto bail_out;
            }
            set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
            bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
            mr.MediaType[0] = 0;
            set_storageid_in_mr(store, &mr);
            if (db_create_media_record(ua->jcr, ua->db, &mr)) {
               ua->send_msg(_("Catalog record for cleaning tape \"%s\" successfully created.\n"),
                  mr.VolumeName);
               pr.NumVols++;          /* this is a bit suspect */
               if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
                  ua->error_msg("%s", db_strerror(ua->db));
               }
            } else {
               ua->error_msg(_("Catalog error on cleaning tape: %s"), db_strerror(ua->db));
            }
         }
         continue;                    /* done, go handle next volume */
      }

      /* Not a cleaning tape */
      bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
      mr.Slot = vl->Slot;

      send_label_request(ua, &mr, &omr, &pr, 0, media_record_exists, drive);
   }


bail_out:
   free(slot_list);
   free_vol_list(vol_list);
   close_sd_bsock(ua);

   return;
}
/*
 * Request SD to send us the slot:barcodes, then wiffle
 *  through them all labeling them.
 */
Request SD to send us the slot:barcodes, then wiffle
through them all labeling them.
Request SD to send us the slot : barcodes then wiffle through them all labeling them .
static void label_from_barcodes(UAContext *ua, int drive)
{
   STORE *store = ua->jcr->wstore;
   POOL_DBR pr;
   MEDIA_DBR mr, omr;
   vol_list_t *vl, *vol_list = NULL;
   bool media_record_exists;
   char *slot_list;
   int max_slots;
   max_slots = get_num_slots_from_SD(ua);
   if (max_slots <= 0) {
      ua->warning_msg(_("No slots in changer to scan.\n"));
      return;
   }
   slot_list = (char *)malloc(max_slots+1);
   if (!get_user_slot_list(ua, slot_list, max_slots)) {
      goto bail_out;
   }
   vol_list = get_vol_list_from_SD(ua, false );
   if (!vol_list) {
      ua->warning_msg(_("No Volumes found to label, or no barcodes.\n"));
      goto bail_out;
   }
   ua->send_msg(_("The following Volumes will be labeled:\n"
                  "Slot  Volume\n"
                  "==============\n"));
   for (vl=vol_list; vl; vl=vl->next) {
      if (!vl->VolName || !slot_list[vl->Slot]) {
         continue;
      }
      ua->send_msg("%4d  %s\n", vl->Slot, vl->VolName);
   }
   if (!get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) ||
       (ua->pint32_val == 0)) {
      goto bail_out;
   }
   memset(&pr, 0, sizeof(pr));
   if (!select_pool_dbr(ua, &pr)) {
      goto bail_out;
   }
   for (vl=vol_list; vl; vl=vl->next) {
      if (!vl->VolName || !slot_list[vl->Slot]) {
         continue;
      }
      mr.clear();
      bstrncpy(mr.VolumeName, vl->VolName, sizeof(mr.VolumeName));
      media_record_exists = false;
      if (db_get_media_record(ua->jcr, ua->db, &mr)) {
          if (mr.VolBytes != 0) {
             ua->warning_msg(_("Media record for Slot %d Volume \"%s\" already exists.\n"),
                vl->Slot, mr.VolumeName);
             mr.Slot = vl->Slot;
             mr.InChanger = mr.Slot > 0;  
             set_storageid_in_mr(store, &mr);
             if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
                ua->error_msg(_("Error setting InChanger: ERR=%s"), db_strerror(ua->db));
             }
             continue;
          }
          media_record_exists = true;
      }
      mr.InChanger = mr.Slot > 0;  
      set_storageid_in_mr(store, &mr);
      if (is_cleaning_tape(ua, &mr, &pr)) {
         if (media_record_exists) {      
            mr.VolBytes = 1;             
            bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
            mr.MediaType[0] = 0;
            set_storageid_in_mr(store, &mr);
            if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
                ua->error_msg("%s", db_strerror(ua->db));
            }
         } else {                        
            if (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
               ua->error_msg(_("Maximum pool Volumes=%d reached.\n"), pr.MaxVols);
               goto bail_out;
            }
            set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
            bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
            mr.MediaType[0] = 0;
            set_storageid_in_mr(store, &mr);
            if (db_create_media_record(ua->jcr, ua->db, &mr)) {
               ua->send_msg(_("Catalog record for cleaning tape \"%s\" successfully created.\n"),
                  mr.VolumeName);
               pr.NumVols++;          
               if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
                  ua->error_msg("%s", db_strerror(ua->db));
               }
            } else {
               ua->error_msg(_("Catalog error on cleaning tape: %s"), db_strerror(ua->db));
            }
         }
         continue;                    
      }
      bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
      mr.Slot = vl->Slot;
      send_label_request(ua, &mr, &omr, &pr, 0, media_record_exists, drive);
   }
bail_out:
   free(slot_list);
   free_vol_list(vol_list);
   close_sd_bsock(ua);
   return;
}
static void label_from_barcodes ( UAContext * ua , int drive ) { STORE * store = ua -> jcr -> wstore ; POOL_DBR pr ; MEDIA_DBR mr , omr ; vol_list_t * vl , * vol_list = NULL ; bool media_record_exists ; char * slot_list ; int max_slots ; max_slots = get_num_slots_from_SD ( ua ) ; if ( max_slots <= 0 ) { ua -> warning_msg ( _ ( " \n " ) ) ; return ; } slot_list = ( char * ) malloc ( max_slots + 1 ) ; if ( ! get_user_slot_list ( ua , slot_list , max_slots ) ) { goto bail_out ; } vol_list = get_vol_list_from_SD ( ua , false ) ; if ( ! vol_list ) { ua -> warning_msg ( _ ( " \n " ) ) ; goto bail_out ; } ua -> send_msg ( _ ( " \n " " \n " " \n " ) ) ; for ( vl = vol_list ; vl ; vl = vl -> next ) { if ( ! vl -> VolName || ! slot_list [ vl -> Slot ] ) { continue ; } ua -> send_msg ( " \n " , vl -> Slot , vl -> VolName ) ; } if ( ! get_yesno ( ua , _ ( " " ) ) || ( ua -> pint32_val == 0 ) ) { goto bail_out ; } memset ( & pr , 0 , sizeof ( pr ) ) ; if ( ! select_pool_dbr ( ua , & pr ) ) { goto bail_out ; } for ( vl = vol_list ; vl ; vl = vl -> next ) { if ( ! vl -> VolName || ! slot_list [ vl -> Slot ] ) { continue ; } mr . clear ( ) ; bstrncpy ( mr . VolumeName , vl -> VolName , sizeof ( mr . VolumeName ) ) ; media_record_exists = false ; if ( db_get_media_record ( ua -> jcr , ua -> db , & mr ) ) { if ( mr . VolBytes != 0 ) { ua -> warning_msg ( _ ( " \" \" \n " ) , vl -> Slot , mr . VolumeName ) ; mr . Slot = vl -> Slot ; mr . InChanger = mr . Slot > 0 ; set_storageid_in_mr ( store , & mr ) ; if ( ! db_update_media_record ( ua -> jcr , ua -> db , & mr ) ) { ua -> error_msg ( _ ( " " ) , db_strerror ( ua -> db ) ) ; } continue ; } media_record_exists = true ; } mr . InChanger = mr . Slot > 0 ; set_storageid_in_mr ( store , & mr ) ; if ( is_cleaning_tape ( ua , & mr , & pr ) ) { if ( media_record_exists ) { mr . VolBytes = 1 ; bstrncpy ( mr . VolStatus , " " , sizeof ( mr . VolStatus ) ) ; mr . MediaType [ 0 ] = 0 ; set_storageid_in_mr ( store , & mr ) ; if ( ! db_update_media_record ( ua -> jcr , ua -> db , & mr ) ) { ua -> error_msg ( " " , db_strerror ( ua -> db ) ) ; } } else { if ( pr . MaxVols > 0 && pr . NumVols >= pr . MaxVols ) { ua -> error_msg ( _ ( " \n " ) , pr . MaxVols ) ; goto bail_out ; } set_pool_dbr_defaults_in_media_dbr ( & mr , & pr ) ; bstrncpy ( mr . VolStatus , " " , sizeof ( mr . VolStatus ) ) ; mr . MediaType [ 0 ] = 0 ; set_storageid_in_mr ( store , & mr ) ; if ( db_create_media_record ( ua -> jcr , ua -> db , & mr ) ) { ua -> send_msg ( _ ( " \" \" \n " ) , mr . VolumeName ) ; pr . NumVols ++ ; if ( ! db_update_pool_record ( ua -> jcr , ua -> db , & pr ) ) { ua -> error_msg ( " " , db_strerror ( ua -> db ) ) ; } } else { ua -> error_msg ( _ ( " " ) , db_strerror ( ua -> db ) ) ; } } continue ; } bstrncpy ( mr . MediaType , store -> media_type , sizeof ( mr . MediaType ) ) ; mr . Slot = vl -> Slot ; send_label_request ( ua , & mr , & omr , & pr , 0 , media_record_exists , drive ) ; } bail_out : free ( slot_list ) ; free_vol_list ( vol_list ) ; close_sd_bsock ( ua ) ; return ; }
Request SD to send us the slot:barcodes, then wiffle
  through them all labeling them.
Request SD to send us the slot : barcodes then wiffle through them all labeling them .
/*no scan*/ /* Display list of Volumes and ask if he really wants to proceed */ /* Select a pool */ /* Fire off the label requests */ /* if slot give assume in changer */ /* if slot give assume in changer */ /*
       * Deal with creating cleaning tape here. Normal tapes created in
       *  send_label_request() below
       */ /* we update it */ /* any bytes to indicate it exists */ /* create the media record */ /* this is a bit suspect */ /* done, go handle next volume */ /* Not a cleaning tape */