+static void do_actions_on_purge(UAContext *ua, MEDIA_DBR *mr)
+{
+ BSOCK *sd;
+ POOL_DBR pr;
+ bool ok=false;
+ int dvd;
+ uint64_t VolBytes = 0;
+ char dev_name[MAX_NAME_LENGTH];
+
+ if (mr->ActionOnPurge & AOP_TRUNCATE) {
+ /* Send the command to truncate the volume after purge. If this feature
+ * is disabled for the specific device, this will be a no-op.
+ */
+
+ if ((sd=open_sd_bsock(ua)) != NULL) {
+ memset(&pr, 0, sizeof(POOL_DBR));
+
+ pr.PoolId = mr->PoolId;
+ strcpy(pr.Name, "Default"); /* We don't use the Pool in label */
+ bstrncpy(dev_name, ua->jcr->wstore->dev_name(), sizeof(dev_name));
+
+ /* Protect us from spaces */
+ bash_spaces(dev_name);
+ bash_spaces(mr->VolumeName);
+ bash_spaces(mr->MediaType);
+ bash_spaces(pr.Name);
+
+ /* We set drive=-1 to let the storage decide of which drive
+ * to use
+ */
+ sd->fsend("relabel %s OldName=%s NewName=%s PoolName=%s "
+ "MediaType=%s Slot=%d drive=%d\n",
+ dev_name,
+ mr->VolumeName, mr->VolumeName,
+ pr.Name, mr->MediaType, mr->Slot, -1);
+
+ unbash_spaces(mr->VolumeName);
+ unbash_spaces(mr->MediaType);
+ while (sd->recv() >= 0) {
+ ua->send_msg("%s", sd->msg);
+ if (sscanf(sd->msg, "3000 OK label. VolBytes=%llu DVD=%d ",
+ &VolBytes, &dvd) == 2)
+ {
+ ok = true;
+ }
+ }
+ sd->signal(BNET_TERMINATE);
+ sd->close();
+ ua->jcr->store_bsock = NULL;
+
+ } else {
+ ua->error_msg(_("Could not connect to storage daemon"));
+ }
+
+ if (ok) {
+ mr->VolBytes = VolBytes;
+ mr->VolFiles = 0;
+ if (!db_update_media_record(ua->jcr, ua->db, mr)) {
+ ua->error_msg(_("Can't update volume size in the catalog\n"));
+ }
+ ua->send_msg(_("The volume has been truncated\n"));
+ } else {
+ ua->warning_msg(_("Unable to truncate the volume\n"));
+ }
+ }
+}
+