src/dird/ua_cmds.c
static int add_cmd(UAContext *ua, const char *cmd)
{
   POOL_DBR pr;
   MEDIA_DBR mr;
   int num, i, max, startnum;
   char name[MAX_NAME_LENGTH];
   STORE *store;
   int Slot = 0, InChanger = 0;

   ua->send_msg(_(
"You probably don't want to be using this command since it\n"
"creates database records without labeling the Volumes.\n"
"You probably want to use the \"label\" command.\n\n"));

   if (!open_client_db(ua)) {
      return 1;
   }

   memset(&pr, 0, sizeof(pr));

   if (!get_pool_dbr(ua, &pr)) {
      return 1;
   }

   Dmsg4(120, "id=%d Num=%d Max=%d type=%s\n", pr.PoolId, pr.NumVols,
      pr.MaxVols, pr.PoolType);

   while (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
      ua->warning_msg(_("Pool already has maximum volumes=%d\n"), pr.MaxVols);
      if (!get_pint(ua, _("Enter new maximum (zero for unlimited): "))) {
         return 1;
      }
      pr.MaxVols = ua->pint32_val;
   }

   /* Get media type */
   if ((store = get_storage_resource(ua, false/*no default*/)) != NULL) {
      bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
   } else if (!get_media_type(ua, mr.MediaType, sizeof(mr.MediaType))) {
      return 1;
   }

   if (pr.MaxVols == 0) {
      max = 1000;
   } else {
      max = pr.MaxVols - pr.NumVols;
   }
   for (;;) {
      char buf[100];
      bsnprintf(buf, sizeof(buf), _("Enter number of Volumes to create. 0=>fixed name. Max=%d: "), max);
      if (!get_pint(ua, buf)) {
         return 1;
      }
      num = ua->pint32_val;
      if (num < 0 || num > max) {
         ua->warning_msg(_("The number must be between 0 and %d\n"), max);
         continue;
      }
      break;
   }

   for (;;) {
      if (num == 0) {
         if (!get_cmd(ua, _("Enter Volume name: "))) {
            return 1;
         }
      } else {
         if (!get_cmd(ua, _("Enter base volume name: "))) {
            return 1;
         }
      }
      /* Don't allow | in Volume name because it is the volume separator character */
      if (!is_volume_name_legal(ua, ua->cmd)) {
         continue;
      }
      if (strlen(ua->cmd) >= MAX_NAME_LENGTH-10) {
         ua->warning_msg(_("Volume name too long.\n"));
         continue;
      }
      if (strlen(ua->cmd) == 0) {
         ua->warning_msg(_("Volume name must be at least one character long.\n"));
         continue;
      }
      break;
   }

   bstrncpy(name, ua->cmd, sizeof(name));
   if (num > 0) {
      bstrncat(name, "%04d", sizeof(name));

      for (;;) {
         if (!get_pint(ua, _("Enter the starting number: "))) {
            return 1;
         }
         startnum = ua->pint32_val;
         if (startnum < 1) {
            ua->warning_msg(_("Start number must be greater than zero.\n"));
            continue;
         }
         break;
      }
   } else {
      startnum = 1;
      num = 1;
   }

   if (store && store->autochanger) {
      if (!get_pint(ua, _("Enter slot (0 for none): "))) {
         return 1;
      }
      Slot = ua->pint32_val;
      if (!get_yesno(ua, _("InChanger? yes/no: "))) {
         return 1;
      }
      InChanger = ua->pint32_val;
   }

   set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
   for (i=startnum; i < num+startnum; i++) {
      bsnprintf(mr.VolumeName, sizeof(mr.VolumeName), name, i);
      mr.Slot = Slot++;
      mr.InChanger = InChanger;
      mr.Enabled = 1;
      set_storageid_in_mr(store, &mr);
      Dmsg1(200, "Create Volume %s\n", mr.VolumeName);
      if (!db_create_media_record(ua->jcr, ua->db, &mr)) {
         ua->error_msg("%s", db_strerror(ua->db));
         return 1;
      }
//    if (i == startnum) {
//       first_id = mr.PoolId;
//    }
   }
   pr.NumVols += num;
   Dmsg0(200, "Update pool record.\n");
   if (db_update_pool_record(ua->jcr, ua->db, &pr) != 1) {
      ua->warning_msg("%s", db_strerror(ua->db));
      return 1;
   }
   ua->send_msg(_("%d Volumes created in pool %s\n"), num, pr.Name);

   return 1;
}
/*
 *  Add Volumes to an existing Pool
 */
Add Volumes to an existing Pool
Add Volumes to an existing Pool
static int add_cmd(UAContext *ua, const char *cmd)
{
   POOL_DBR pr;
   MEDIA_DBR mr;
   int num, i, max, startnum;
   char name[MAX_NAME_LENGTH];
   STORE *store;
   int Slot = 0, InChanger = 0;
   ua->send_msg(_(
"You probably don't want to be using this command since it\n"
"creates database records without labeling the Volumes.\n"
"You probably want to use the \"label\" command.\n\n"));
   if (!open_client_db(ua)) {
      return 1;
   }
   memset(&pr, 0, sizeof(pr));
   if (!get_pool_dbr(ua, &pr)) {
      return 1;
   }
   Dmsg4(120, "id=%d Num=%d Max=%d type=%s\n", pr.PoolId, pr.NumVols,
      pr.MaxVols, pr.PoolType);
   while (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
      ua->warning_msg(_("Pool already has maximum volumes=%d\n"), pr.MaxVols);
      if (!get_pint(ua, _("Enter new maximum (zero for unlimited): "))) {
         return 1;
      }
      pr.MaxVols = ua->pint32_val;
   }
   if ((store = get_storage_resource(ua, false)) != NULL) {
      bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
   } else if (!get_media_type(ua, mr.MediaType, sizeof(mr.MediaType))) {
      return 1;
   }
   if (pr.MaxVols == 0) {
      max = 1000;
   } else {
      max = pr.MaxVols - pr.NumVols;
   }
   for (;;) {
      char buf[100];
      bsnprintf(buf, sizeof(buf), _("Enter number of Volumes to create. 0=>fixed name. Max=%d: "), max);
      if (!get_pint(ua, buf)) {
         return 1;
      }
      num = ua->pint32_val;
      if (num < 0 || num > max) {
         ua->warning_msg(_("The number must be between 0 and %d\n"), max);
         continue;
      }
      break;
   }
   for (;;) {
      if (num == 0) {
         if (!get_cmd(ua, _("Enter Volume name: "))) {
            return 1;
         }
      } else {
         if (!get_cmd(ua, _("Enter base volume name: "))) {
            return 1;
         }
      }
      if (!is_volume_name_legal(ua, ua->cmd)) {
         continue;
      }
      if (strlen(ua->cmd) >= MAX_NAME_LENGTH-10) {
         ua->warning_msg(_("Volume name too long.\n"));
         continue;
      }
      if (strlen(ua->cmd) == 0) {
         ua->warning_msg(_("Volume name must be at least one character long.\n"));
         continue;
      }
      break;
   }
   bstrncpy(name, ua->cmd, sizeof(name));
   if (num > 0) {
      bstrncat(name, "%04d", sizeof(name));
      for (;;) {
         if (!get_pint(ua, _("Enter the starting number: "))) {
            return 1;
         }
         startnum = ua->pint32_val;
         if (startnum < 1) {
            ua->warning_msg(_("Start number must be greater than zero.\n"));
            continue;
         }
         break;
      }
   } else {
      startnum = 1;
      num = 1;
   }
   if (store && store->autochanger) {
      if (!get_pint(ua, _("Enter slot (0 for none): "))) {
         return 1;
      }
      Slot = ua->pint32_val;
      if (!get_yesno(ua, _("InChanger? yes/no: "))) {
         return 1;
      }
      InChanger = ua->pint32_val;
   }
   set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
   for (i=startnum; i < num+startnum; i++) {
      bsnprintf(mr.VolumeName, sizeof(mr.VolumeName), name, i);
      mr.Slot = Slot++;
      mr.InChanger = InChanger;
      mr.Enabled = 1;
      set_storageid_in_mr(store, &mr);
      Dmsg1(200, "Create Volume %s\n", mr.VolumeName);
      if (!db_create_media_record(ua->jcr, ua->db, &mr)) {
         ua->error_msg("%s", db_strerror(ua->db));
         return 1;
      }
   }
   pr.NumVols += num;
   Dmsg0(200, "Update pool record.\n");
   if (db_update_pool_record(ua->jcr, ua->db, &pr) != 1) {
      ua->warning_msg("%s", db_strerror(ua->db));
      return 1;
   }
   ua->send_msg(_("%d Volumes created in pool %s\n"), num, pr.Name);
   return 1;
}
static int add_cmd ( UAContext * ua , const char * cmd ) { POOL_DBR pr ; MEDIA_DBR mr ; int num , i , max , startnum ; char name [ MAX_NAME_LENGTH ] ; STORE * store ; int Slot = 0 , InChanger = 0 ; ua -> send_msg ( _ ( " \n " " \n " " \" \" \n \n " ) ) ; if ( ! open_client_db ( ua ) ) { return 1 ; } memset ( & pr , 0 , sizeof ( pr ) ) ; if ( ! get_pool_dbr ( ua , & pr ) ) { return 1 ; } Dmsg4 ( 120 , " \n " , pr . PoolId , pr . NumVols , pr . MaxVols , pr . PoolType ) ; while ( pr . MaxVols > 0 && pr . NumVols >= pr . MaxVols ) { ua -> warning_msg ( _ ( " \n " ) , pr . MaxVols ) ; if ( ! get_pint ( ua , _ ( " " ) ) ) { return 1 ; } pr . MaxVols = ua -> pint32_val ; } if ( ( store = get_storage_resource ( ua , false ) ) != NULL ) { bstrncpy ( mr . MediaType , store -> media_type , sizeof ( mr . MediaType ) ) ; } else if ( ! get_media_type ( ua , mr . MediaType , sizeof ( mr . MediaType ) ) ) { return 1 ; } if ( pr . MaxVols == 0 ) { max = 1000 ; } else { max = pr . MaxVols - pr . NumVols ; } for ( ; ; ) { char buf [ 100 ] ; bsnprintf ( buf , sizeof ( buf ) , _ ( " " ) , max ) ; if ( ! get_pint ( ua , buf ) ) { return 1 ; } num = ua -> pint32_val ; if ( num < 0 || num > max ) { ua -> warning_msg ( _ ( " \n " ) , max ) ; continue ; } break ; } for ( ; ; ) { if ( num == 0 ) { if ( ! get_cmd ( ua , _ ( " " ) ) ) { return 1 ; } } else { if ( ! get_cmd ( ua , _ ( " " ) ) ) { return 1 ; } } if ( ! is_volume_name_legal ( ua , ua -> cmd ) ) { continue ; } if ( strlen ( ua -> cmd ) >= MAX_NAME_LENGTH - 10 ) { ua -> warning_msg ( _ ( " \n " ) ) ; continue ; } if ( strlen ( ua -> cmd ) == 0 ) { ua -> warning_msg ( _ ( " \n " ) ) ; continue ; } break ; } bstrncpy ( name , ua -> cmd , sizeof ( name ) ) ; if ( num > 0 ) { bstrncat ( name , " " , sizeof ( name ) ) ; for ( ; ; ) { if ( ! get_pint ( ua , _ ( " " ) ) ) { return 1 ; } startnum = ua -> pint32_val ; if ( startnum < 1 ) { ua -> warning_msg ( _ ( " \n " ) ) ; continue ; } break ; } } else { startnum = 1 ; num = 1 ; } if ( store && store -> autochanger ) { if ( ! get_pint ( ua , _ ( " " ) ) ) { return 1 ; } Slot = ua -> pint32_val ; if ( ! get_yesno ( ua , _ ( " " ) ) ) { return 1 ; } InChanger = ua -> pint32_val ; } set_pool_dbr_defaults_in_media_dbr ( & mr , & pr ) ; for ( i = startnum ; i < num + startnum ; i ++ ) { bsnprintf ( mr . VolumeName , sizeof ( mr . VolumeName ) , name , i ) ; mr . Slot = Slot ++ ; mr . InChanger = InChanger ; mr . Enabled = 1 ; set_storageid_in_mr ( store , & mr ) ; Dmsg1 ( 200 , " \n " , mr . VolumeName ) ; if ( ! db_create_media_record ( ua -> jcr , ua -> db , & mr ) ) { ua -> error_msg ( " " , db_strerror ( ua -> db ) ) ; return 1 ; } } pr . NumVols += num ; Dmsg0 ( 200 , " \n " ) ; if ( db_update_pool_record ( ua -> jcr , ua -> db , & pr ) != 1 ) { ua -> warning_msg ( " " , db_strerror ( ua -> db ) ) ; return 1 ; } ua -> send_msg ( _ ( " \n " ) , num , pr . Name ) ; return 1 ; }
Add Volumes to an existing Pool
Add Volumes to an existing Pool
/* Get media type */ /*no default*/ /* Don't allow | in Volume name because it is the volume separator character */ //    if (i == startnum) { //       first_id = mr.PoolId; //    }