3 * label.c Bacula routines to handle labels
11 Copyright (C) 2000-2005 Kern Sibbald
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of
16 the License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public
24 License along with this program; if not, write to the Free
25 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 #include "bacula.h" /* pull in global headers */
31 #include "stored.h" /* pull in Storage Deamon headers */
33 /* Forward referenced functions */
34 static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec);
36 extern char my_name[];
37 extern int debug_level;
40 * Read the volume label
42 * If dcr->VolumeName == NULL, we accept any Bacula Volume
43 * If dcr->VolumeName[0] == 0, we accept any Bacula Volume
44 * otherwise dcr->VolumeName must match the Volume.
46 * If VolName given, ensure that it matches
48 * Returns VOL_ code as defined in record.h
59 int read_dev_volume_label(DCR *dcr)
62 DEVICE *dev = dcr->dev;
63 char *VolName = dcr->VolumeName;
66 DEV_BLOCK *block = dcr->block;
68 Dmsg3(100, "Enter read_volume_label device=%s vol=%s dev_Vol=%s\n",
69 dev_name(dev), VolName, dev->VolHdr.VolName);
71 if (dev_state(dev, ST_LABEL)) { /* did we already read label? */
72 /* Compare Volume Names allow special wild card */
73 if (VolName && *VolName && *VolName != '*' && strcmp(dev->VolHdr.VolName, VolName) != 0) {
74 Mmsg(jcr->errmsg, _("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
75 dev_name(dev), VolName, dev->VolHdr.VolName);
77 * Cancel Job if too many label errors
80 if (!dev->poll && jcr->label_errors++ > 100) {
81 Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
83 return VOL_NAME_ERROR;
85 Dmsg0(30, "Leave read_volume_label() VOL_OK\n");
86 return VOL_OK; /* label already read */
89 dev->state &= ~(ST_LABEL|ST_APPEND|ST_READ); /* set no label, no append */
91 if (!rewind_dev(dev)) {
92 Mmsg(jcr->errmsg, _("Couldn't rewind device %s ERR=%s\n"), dev_name(dev),
94 Dmsg1(30, "%s", jcr->errmsg);
97 bstrncpy(dev->VolHdr.Id, "**error**", sizeof(dev->VolHdr.Id));
99 /* Read the Volume label block */
100 record = new_record();
102 Dmsg0(90, "Big if statement in read_volume_label\n");
103 if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
104 Mmsg(jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula "
105 "labeled Volume, because: ERR=%s"), NPRT(VolName), dev_name(dev),
107 Dmsg1(30, "%s", jcr->errmsg);
108 } else if (!read_record_from_block(block, record)) {
109 Mmsg(jcr->errmsg, _("Could not read Volume label from block.\n"));
110 Dmsg1(30, "%s", jcr->errmsg);
111 } else if (!unser_volume_label(dev, record)) {
112 Mmsg(jcr->errmsg, _("Could not unserialize Volume label: ERR=%s\n"),
114 Dmsg1(30, "%s", jcr->errmsg);
115 } else if (strcmp(dev->VolHdr.Id, BaculaId) != 0 &&
116 strcmp(dev->VolHdr.Id, OldBaculaId) != 0) {
117 Mmsg(jcr->errmsg, _("Volume Header Id bad: %s\n"), dev->VolHdr.Id);
118 Dmsg1(30, "%s", jcr->errmsg);
124 if (forge_on || jcr->ignore_label_errors) {
125 dev->state |= ST_LABEL; /* set has Bacula label */
126 Jmsg(jcr, M_ERROR, 0, "%s", jcr->errmsg);
135 /* If we are a streaming device, we only get one chance to read */
136 if (!dev_cap(dev, CAP_STREAM)) {
141 if (dev->VolHdr.VerNum != BaculaTapeVersion &&
142 dev->VolHdr.VerNum != OldCompatibleBaculaTapeVersion1 &&
143 dev->VolHdr.VerNum != OldCompatibleBaculaTapeVersion2) {
144 Mmsg(jcr->errmsg, _("Volume on %s has wrong Bacula version. Wanted %d got %d\n"),
145 dev_name(dev), BaculaTapeVersion, dev->VolHdr.VerNum);
146 Dmsg1(30, "%s", jcr->errmsg);
147 return VOL_VERSION_ERROR;
150 /* We are looking for either an unused Bacula tape (PRE_LABEL) or
151 * a Bacula volume label (VOL_LABEL)
153 if (dev->VolHdr.LabelType != PRE_LABEL && dev->VolHdr.LabelType != VOL_LABEL) {
154 Mmsg(jcr->errmsg, _("Volume on %s has bad Bacula label type: %x\n"),
155 dev_name(dev), dev->VolHdr.LabelType);
156 Dmsg1(30, "%s", jcr->errmsg);
157 return VOL_LABEL_ERROR;
160 dev->state |= ST_LABEL; /* set has Bacula label */
162 /* Compare Volume Names */
163 Dmsg2(30, "Compare Vol names: VolName=%s hdr=%s\n", VolName?VolName:"*", dev->VolHdr.VolName);
164 if (VolName && *VolName && *VolName != '*' && strcmp(dev->VolHdr.VolName, VolName) != 0) {
165 Mmsg(jcr->errmsg, _("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
166 dev_name(dev), VolName, dev->VolHdr.VolName);
167 Dmsg1(30, "%s", jcr->errmsg);
169 * Cancel Job if too many label errors
170 * => we are in a loop
172 if (!dev->poll && jcr->label_errors++ > 100) {
173 Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
175 return VOL_NAME_ERROR;
177 Dmsg1(30, "Copy vol_name=%s\n", dev->VolHdr.VolName);
179 if (debug_level >= 10) {
180 dump_volume_label(dev);
182 Dmsg0(30, "Leave read_volume_label() VOL_OK\n");
186 /* Read the volume label by guessing the volume name. (only for mounted devices)
187 * write is true if we are reading the label before writing to the device.
189 * If the volume name cannot be guessed :
190 * Writing : returns the label of the current file (on the harddisk).
191 * Reading : returns an error
193 int read_dev_volume_label_guess(DCR *dcr, bool write) {
194 int vol_label_status;
195 Dmsg3(100, "Enter read_dev_volume_label_guess device=%s vol=%s dev_Vol=%s\n",
196 dev_name(dcr->dev), dcr->VolumeName, dcr->dev->VolHdr.VolName);
198 if (!dev_cap(dcr->dev, CAP_REQMOUNT)) {
199 Dmsg0(100, "Leave read_dev_volume_label_guess !CAP_REQMOUNT\n");
200 return read_dev_volume_label(dcr);
203 if (!write && (dcr->VolCatInfo.VolCatParts == 0)) {
204 Dmsg0(100, "Leave read_dev_volume_label_guess !writing, and VolCatParts == 0\n");
205 return read_dev_volume_label(dcr);
208 /* For mounted devices, tries to guess the volume name, and read the label if possible.
210 if (open_guess_name_dev(dcr->dev) < 0) {
211 if ((!write) || (dcr->VolCatInfo.VolCatParts > 0)) {
212 Mmsg2(dcr->jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula labeled Volume."),
213 dev_name(dcr->dev), dcr->VolumeName);
214 Dmsg0(100, "Leave read_dev_volume_label_guess VOL_IO_ERROR (!open_guess_name_dev)\n");
218 if (write && (dcr->dev->free_space_errno < 0)) {
219 Dmsg0(100, "Leave read_dev_volume_label_guess !free_space VOL_NO_MEDIA\n");
220 Mmsg2(dcr->jcr->errmsg, _("free_space error on %s. The current medium is probably not writable. ERR=%s.\n"),
221 dcr->dev->dev_name, dcr->dev->errmsg);
225 /* If we can't guess the name, and we are writing, just reopen the right file with open_first_part. */
226 if (open_first_part(dcr->dev) < 0) {
228 Mmsg2(dcr->jcr->errmsg, _("open_first_part error on %s. ERR=%s.\n"),
229 dcr->dev->dev_name, be.strerror());
230 Dmsg0(100, "Leave read_dev_volume_label_guess VOL_IO_ERROR (!open_guess_name_dev && !open_first_part)\n");
234 Dmsg0(100, "Leave read_dev_volume_label_guess !open_guess_name_dev\n");
235 return read_dev_volume_label(dcr);
238 if (write && (dcr->dev->free_space_errno < 0)) {
239 Dmsg0(100, "Leave read_dev_volume_label_guess !free_space VOL_NO_MEDIA\n");
240 Mmsg2(dcr->jcr->errmsg, _("free_space error on %s. The current medium is probably not writable. ERR=%s.\n"),
241 dcr->dev->dev_name, dcr->dev->errmsg);
245 vol_label_status = read_dev_volume_label(dcr);
247 if ((!write) || (dcr->VolCatInfo.VolCatParts > 0)) {
248 Dmsg0(100, "Leave read_dev_volume_label_guess (open_guess_name_dev && (!write || dcr->VolCatInfo.VolCatParts > 0))\n");
249 return vol_label_status;
252 if (open_first_part(dcr->dev) < 0) {
254 Mmsg2(dcr->jcr->errmsg, _("open_first_part error on %s. ERR=%s.\n"),
255 dcr->dev->dev_name, be.strerror());
256 Dmsg0(100, "Leave read_dev_volume_label_guess VOL_IO_ERROR (open_guess_name_dev && !open_first_part)\n");
260 /* When writing, if the guessed volume name is no the right volume name,
261 * report the error, otherwise, just continue with the right file.
263 if (vol_label_status != VOL_NAME_ERROR) {
264 Dmsg0(100, "Leave read_dev_volume_label_guess (open_guess_name_dev && !VOL_NAME_ERROR)\n");
265 dcr->dev->state &= ~ST_LABEL;
266 return read_dev_volume_label(dcr);
269 Dmsg0(100, "Leave read_dev_volume_label_guess (open_guess_name_dev && VOL_NAME_ERROR)\n");
270 return vol_label_status;
275 /* unser_volume_label
277 * Unserialize the Volume label into the device Volume_Label
280 * Assumes that the record is already read.
282 * Returns: false on error
286 bool unser_volume_label(DEVICE *dev, DEV_RECORD *rec)
290 if (rec->FileIndex != VOL_LABEL && rec->FileIndex != PRE_LABEL) {
291 Mmsg3(dev->errmsg, _("Expecting Volume Label, got FI=%s Stream=%s len=%d\n"),
292 FI_to_ascii(rec->FileIndex),
293 stream_to_ascii(rec->Stream, rec->FileIndex),
300 dev->VolHdr.LabelType = rec->FileIndex;
301 dev->VolHdr.LabelSize = rec->data_len;
304 /* Unserialize the record into the Volume Header */
305 rec->data = check_pool_memory_size(rec->data, SER_LENGTH_Volume_Label);
306 ser_begin(rec->data, SER_LENGTH_Volume_Label);
307 unser_string(dev->VolHdr.Id);
308 unser_uint32(dev->VolHdr.VerNum);
310 if (dev->VolHdr.VerNum >= 11) {
311 unser_btime(dev->VolHdr.label_btime);
312 unser_btime(dev->VolHdr.write_btime);
313 } else { /* old way */
314 unser_float64(dev->VolHdr.label_date);
315 unser_float64(dev->VolHdr.label_time);
317 unser_float64(dev->VolHdr.write_date); /* Unused with VerNum >= 11 */
318 unser_float64(dev->VolHdr.write_time); /* Unused with VerNum >= 11 */
320 unser_string(dev->VolHdr.VolName);
321 unser_string(dev->VolHdr.PrevVolName);
322 unser_string(dev->VolHdr.PoolName);
323 unser_string(dev->VolHdr.PoolType);
324 unser_string(dev->VolHdr.MediaType);
326 unser_string(dev->VolHdr.HostName);
327 unser_string(dev->VolHdr.LabelProg);
328 unser_string(dev->VolHdr.ProgVersion);
329 unser_string(dev->VolHdr.ProgDate);
331 ser_end(rec->data, SER_LENGTH_Volume_Label);
332 Dmsg0(90, "ser_read_vol\n");
333 if (debug_level >= 90) {
334 dump_volume_label(dev);
340 * Put a volume label into the block
342 * Returns: false on failure
345 bool write_volume_label_to_block(DCR *dcr)
348 DEVICE *dev = dcr->dev;
350 DEV_BLOCK *block = dcr->block;
352 Dmsg0(20, "write Label in write_volume_label_to_block()\n");
353 memset(&rec, 0, sizeof(rec));
354 rec.data = get_memory(SER_LENGTH_Volume_Label);
355 empty_block(block); /* Volume label always at beginning */
357 create_volume_label_record(dcr, &rec);
359 block->BlockNumber = 0;
360 if (!write_record_to_block(block, &rec)) {
361 free_pool_memory(rec.data);
362 Jmsg1(jcr, M_FATAL, 0, _("Cannot write Volume label to block for device %s\n"),
366 Dmsg1(90, "Wrote label of %d bytes to block\n", rec.data_len);
368 free_pool_memory(rec.data);
373 * create_volume_label_record
374 * Serialize label (from dev->VolHdr structure) into device record.
375 * Assumes that the dev->VolHdr structure is properly
378 static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec)
382 DEVICE *dev = dcr->dev;
385 /* Serialize the label into the device record. */
387 rec->data = check_pool_memory_size(rec->data, SER_LENGTH_Volume_Label);
388 ser_begin(rec->data, SER_LENGTH_Volume_Label);
389 ser_string(dev->VolHdr.Id);
391 ser_uint32(dev->VolHdr.VerNum);
393 if (dev->VolHdr.VerNum >= 11) {
394 ser_btime(dev->VolHdr.label_btime);
395 dev->VolHdr.write_btime = get_current_btime();
396 ser_btime(dev->VolHdr.write_btime);
397 dev->VolHdr.write_date = 0;
398 dev->VolHdr.write_time = 0;
400 /* OLD WAY DEPRECATED */
401 ser_float64(dev->VolHdr.label_date);
402 ser_float64(dev->VolHdr.label_time);
403 get_current_time(&dt);
404 dev->VolHdr.write_date = dt.julian_day_number;
405 dev->VolHdr.write_time = dt.julian_day_fraction;
407 ser_float64(dev->VolHdr.write_date); /* 0 if VerNum >= 11 */
408 ser_float64(dev->VolHdr.write_time); /* 0 if VerNum >= 11 */
410 ser_string(dev->VolHdr.VolName);
411 ser_string(dev->VolHdr.PrevVolName);
412 ser_string(dev->VolHdr.PoolName);
413 ser_string(dev->VolHdr.PoolType);
414 ser_string(dev->VolHdr.MediaType);
416 ser_string(dev->VolHdr.HostName);
417 ser_string(dev->VolHdr.LabelProg);
418 ser_string(dev->VolHdr.ProgVersion);
419 ser_string(dev->VolHdr.ProgDate);
421 ser_end(rec->data, SER_LENGTH_Volume_Label);
422 rec->data_len = ser_length(rec->data);
423 rec->FileIndex = dev->VolHdr.LabelType;
424 rec->VolSessionId = jcr->VolSessionId;
425 rec->VolSessionTime = jcr->VolSessionTime;
426 rec->Stream = jcr->NumVolumes;
427 Dmsg2(100, "Created Vol label rec: FI=%s len=%d\n", FI_to_ascii(rec->FileIndex),
433 * Create a volume label in memory
435 void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName)
437 DEVRES *device = (DEVRES *)dev->device;
439 Dmsg0(90, "Start create_volume_label()\n");
443 memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
445 bstrncpy(dev->VolHdr.Id, BaculaId, sizeof(dev->VolHdr.Id));
446 dev->VolHdr.VerNum = BaculaTapeVersion;
447 dev->VolHdr.LabelType = PRE_LABEL; /* Mark tape as unused */
448 bstrncpy(dev->VolHdr.VolName, VolName, sizeof(dev->VolHdr.VolName));
449 bstrncpy(dev->VolHdr.PoolName, PoolName, sizeof(dev->VolHdr.PoolName));
450 bstrncpy(dev->VolHdr.MediaType, device->media_type, sizeof(dev->VolHdr.MediaType));
452 bstrncpy(dev->VolHdr.PoolType, "Backup", sizeof(dev->VolHdr.PoolType));
454 dev->VolHdr.label_btime = get_current_btime();
455 dev->VolHdr.label_date = 0;
456 dev->VolHdr.label_time = 0;
458 if (gethostname(dev->VolHdr.HostName, sizeof(dev->VolHdr.HostName)) != 0) {
459 dev->VolHdr.HostName[0] = 0;
461 bstrncpy(dev->VolHdr.LabelProg, my_name, sizeof(dev->VolHdr.LabelProg));
462 sprintf(dev->VolHdr.ProgVersion, "Ver. %s %s", VERSION, BDATE);
463 sprintf(dev->VolHdr.ProgDate, "Build %s %s", __DATE__, __TIME__);
464 dev->state |= ST_LABEL; /* set has Bacula label */
465 if (debug_level >= 90) {
466 dump_volume_label(dev);
471 * Write a Volume Label
472 * !!! Note, this is ONLY used for writing
473 * a fresh volume label. Any data
474 * after the label will be destroyed,
475 * in fact, we write the label 5 times !!!!
477 * This routine expects that open_device() was previously called.
479 * This routine should be used only when labeling a blank tape.
481 bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *PoolName)
484 DEVICE *dev = dcr->dev;
487 Dmsg0(99, "write_volume_label()\n");
488 empty_block(dcr->block);
489 /* Create PRE_LABEL */
490 create_volume_label(dev, VolName, PoolName);
492 if (!rewind_dev(dev)) {
493 memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
494 Dmsg2(30, "Bad status on %s from rewind. ERR=%s\n", dev_name(dev), strerror_dev(dev));
500 create_volume_label_record(dcr, dcr->rec);
501 dcr->rec->Stream = 0;
503 /* Temporarily mark in append state to enable writing */
504 dev->state |= ST_APPEND;
505 if (!write_record_to_block(dcr->block, dcr->rec)) {
506 Dmsg2(30, "Bad Label write on %s. ERR=%s\n", dev_name(dev), strerror_dev(dev));
507 memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
510 Dmsg2(30, "Wrote label of %d bytes to %s\n", dcr->rec->data_len, dev_name(dev));
513 Dmsg0(99, "Call write_block_to_dev()\n");
514 if (!write_block_to_dev(dcr)) {
515 memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
516 Dmsg2(30, "Bad Label write on %s. ERR=%s\n", dev_name(dev), strerror_dev(dev));
519 Dmsg0(99, " Wrote block to device\n");
521 if (weof_dev(dev, 1) == 0) {
522 dev->state |= ST_LABEL;
526 if (debug_level >= 20) {
527 dump_volume_label(dev);
531 dev->state &= ~ST_APPEND; /* remove append since this is PRE_LABEL */
537 * Create session label
538 * The pool memory must be released by the calling program
540 void create_session_label(DCR *dcr, DEV_RECORD *rec, int label)
545 rec->VolSessionId = jcr->VolSessionId;
546 rec->VolSessionTime = jcr->VolSessionTime;
547 rec->Stream = jcr->JobId;
549 rec->data = check_pool_memory_size(rec->data, SER_LENGTH_Session_Label);
550 ser_begin(rec->data, SER_LENGTH_Session_Label);
551 ser_string(BaculaId);
552 ser_uint32(BaculaTapeVersion);
554 ser_uint32(jcr->JobId);
556 /* Changed in VerNum 11 */
557 ser_btime(get_current_btime());
560 ser_string(dcr->pool_name);
561 ser_string(dcr->pool_type);
562 ser_string(jcr->job_name); /* base Job name */
563 ser_string(jcr->client_name);
565 /* Added in VerNum 10 */
566 ser_string(jcr->Job); /* Unique name of this Job */
567 ser_string(jcr->fileset_name);
568 ser_uint32(jcr->JobType);
569 ser_uint32(jcr->JobLevel);
570 /* Added in VerNum 11 */
571 ser_string(jcr->fileset_md5);
573 if (label == EOS_LABEL) {
574 ser_uint32(jcr->JobFiles);
575 ser_uint64(jcr->JobBytes);
576 ser_uint32(dcr->StartBlock);
577 ser_uint32(dcr->EndBlock);
578 ser_uint32(dcr->StartFile);
579 ser_uint32(dcr->EndFile);
580 ser_uint32(jcr->JobErrors);
582 /* Added in VerNum 11 */
583 ser_uint32(jcr->JobStatus);
585 ser_end(rec->data, SER_LENGTH_Session_Label);
586 rec->data_len = ser_length(rec->data);
589 /* Write session label
590 * Returns: false on failure
593 bool write_session_label(DCR *dcr, int label)
596 DEVICE *dev = dcr->dev;
598 DEV_BLOCK *block = dcr->block;
601 Dmsg1(90, "session_label record=%x\n", rec);
604 if (dev->state & ST_TAPE) {
605 dcr->StartBlock = dev->block_num;
606 dcr->StartFile = dev->file;
608 dcr->StartBlock = (uint32_t)dev->file_addr;
609 dcr->StartFile = (uint32_t)(dev->file_addr >> 32);
613 if (dev->state & ST_TAPE) {
614 dcr->EndBlock = dev->EndBlock;
615 dcr->EndFile = dev->EndFile;
617 dcr->EndBlock = (uint32_t)dev->file_addr;
618 dcr->EndFile = (uint32_t)(dev->file_addr >> 32);
622 Jmsg1(jcr, M_ABORT, 0, _("Bad session label = %d\n"), label);
625 create_session_label(dcr, rec, label);
626 rec->FileIndex = label;
629 * We guarantee that the session record can totally fit
630 * into a block. If not, write the block, and put it in
631 * the next block. Having the sesssion record totally in
632 * one block makes reading them much easier (no need to
633 * read the next block).
635 if (!can_write_record_to_block(block, rec)) {
636 Dmsg0(100, "Cannot write session label to block.\n");
637 if (!write_block_to_device(dcr)) {
638 Dmsg0(90, "Got session label write_block_to_dev error.\n");
639 /* ****FIXME***** errno is not set here */
640 Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"),
641 dev_vol_name(dev), strerror(errno));
646 if (!write_record_to_block(block, rec)) {
647 Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"),
648 dev_vol_name(dev), strerror(errno));
653 Dmsg6(20, "Write sesson_label record JobId=%d FI=%s SessId=%d Strm=%s len=%d "
654 "remainder=%d\n", jcr->JobId,
655 FI_to_ascii(rec->FileIndex), rec->VolSessionId,
656 stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len,
660 Dmsg2(20, "Leave write_session_label Block=%d File=%d\n",
661 dev->block_num, dev->file);
665 void dump_volume_label(DEVICE *dev)
667 int dbl = debug_level;
669 const char *LabelType;
676 switch (dev->VolHdr.LabelType) {
678 LabelType = "PRE_LABEL";
681 LabelType = "VOL_LABEL";
684 LabelType = "EOM_LABEL";
687 LabelType = "SOS_LABEL";
690 LabelType = "EOS_LABEL";
696 sprintf(buf, "Unknown %d", dev->VolHdr.LabelType);
701 Pmsg11(-1, "\nVolume Label:\n"
714 dev->VolHdr.Id, dev->VolHdr.VerNum,
715 dev->VolHdr.VolName, dev->VolHdr.PrevVolName,
716 File, LabelType, dev->VolHdr.LabelSize,
717 dev->VolHdr.PoolName, dev->VolHdr.MediaType,
718 dev->VolHdr.PoolType, dev->VolHdr.HostName);
720 if (dev->VolHdr.VerNum >= 11) {
722 bstrftime(dt, sizeof(dt), btime_to_unix(dev->VolHdr.label_btime));
723 Pmsg1(-1, "Date label written: %s\n", dt);
725 dt.julian_day_number = dev->VolHdr.label_date;
726 dt.julian_day_fraction = dev->VolHdr.label_time;
729 "Date label written: %04d-%02d-%02d at %02d:%02d\n",
730 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
737 bool unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec)
741 rec->data = check_pool_memory_size(rec->data, SER_LENGTH_Session_Label);
742 unser_begin(rec->data, SER_LENGTH_Session_Label);
743 unser_string(label->Id);
744 unser_uint32(label->VerNum);
745 unser_uint32(label->JobId);
746 if (label->VerNum >= 11) {
747 unser_btime(label->write_btime);
749 unser_float64(label->write_date);
751 unser_float64(label->write_time);
752 unser_string(label->PoolName);
753 unser_string(label->PoolType);
754 unser_string(label->JobName);
755 unser_string(label->ClientName);
756 if (label->VerNum >= 10) {
757 unser_string(label->Job); /* Unique name of this Job */
758 unser_string(label->FileSetName);
759 unser_uint32(label->JobType);
760 unser_uint32(label->JobLevel);
762 if (label->VerNum >= 11) {
763 unser_string(label->FileSetMD5);
765 label->FileSetMD5[0] = 0;
767 if (rec->FileIndex == EOS_LABEL) {
768 unser_uint32(label->JobFiles);
769 unser_uint64(label->JobBytes);
770 unser_uint32(label->StartBlock);
771 unser_uint32(label->EndBlock);
772 unser_uint32(label->StartFile);
773 unser_uint32(label->EndFile);
774 unser_uint32(label->JobErrors);
775 if (label->VerNum >= 11) {
776 unser_uint32(label->JobStatus);
778 label->JobStatus = JS_Terminated; /* kludge */
785 static void dump_session_label(DEV_RECORD *rec, const char *type)
791 char ec1[30], ec2[30], ec3[30], ec4[30], ec5[30], ec6[30], ec7[30];
793 unser_session_label(&label, rec);
796 Pmsg7(-1, "\n%s Record:\n"
803 "", type, label.JobId, label.VerNum,
804 label.PoolName, label.PoolType,
805 label.JobName, label.ClientName);
807 if (label.VerNum >= 10) {
809 "Job (unique name) : %s\n"
813 "", label.Job, label.FileSetName, label.JobType, label.JobLevel);
816 if (rec->FileIndex == EOS_LABEL) {
827 edit_uint64_with_commas(label.JobFiles, ec1),
828 edit_uint64_with_commas(label.JobBytes, ec2),
829 edit_uint64_with_commas(label.StartBlock, ec3),
830 edit_uint64_with_commas(label.EndBlock, ec4),
831 edit_uint64_with_commas(label.StartFile, ec5),
832 edit_uint64_with_commas(label.EndFile, ec6),
833 edit_uint64_with_commas(label.JobErrors, ec7),
836 if (label.VerNum >= 11) {
838 bstrftime(dt, sizeof(dt), btime_to_unix(label.write_btime));
839 Pmsg1(-1, _("Date written : %s\n"), dt);
841 dt.julian_day_number = label.write_date;
842 dt.julian_day_fraction = label.write_time;
845 "Date written : %04d-%02d-%02d at %02d:%02d\n"),
846 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
852 void dump_label_record(DEVICE *dev, DEV_RECORD *rec, int verbose)
859 switch (rec->FileIndex) {
861 type = _("Fresh Volume");
867 type = _("Begin Job Session");
870 type = _("End Job Session");
873 type = _("End of Media");
876 type = ("End of Tape");
883 switch (rec->FileIndex) {
886 unser_volume_label(dev, rec);
887 dump_volume_label(dev);
890 dump_session_label(rec, type);
893 dump_session_label(rec, type);
896 Pmsg5(-1, "%s Record: SessId=%d SessTime=%d JobId=%d DataLen=%d\n",
897 type, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
900 Pmsg0(-1, _("End of physical tape.\n"));
903 Pmsg5(-1, "%s Record: SessId=%d SessTime=%d JobId=%d DataLen=%d\n",
904 type, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
909 switch (rec->FileIndex) {
911 unser_session_label(&label, rec);
912 Pmsg6(-1, "%s Record: SessId=%d SessTime=%d JobId=%d Level=%c Type=%c\n",
913 type, rec->VolSessionId, rec->VolSessionTime, rec->Stream,
914 label.JobLevel, label.JobType);
917 char ed1[30], ed2[30];
918 unser_session_label(&label, rec);
919 Pmsg6(-1, "%s Record: SessId=%d SessTime=%d JobId=%d Level=%c Type=%c\n",
920 type, rec->VolSessionId, rec->VolSessionTime, rec->Stream,
921 label.JobLevel, label.JobType);
922 Pmsg4(-1, " Files=%s Bytes=%s Errors=%d Status=%c\n",
923 edit_uint64_with_commas(label.JobFiles, ed1),
924 edit_uint64_with_commas(label.JobBytes, ed2),
925 label.JobErrors, (char)label.JobStatus);
931 Pmsg5(-1, "%s Record: SessId=%d SessTime=%d JobId=%d DataLen=%d\n",
932 type, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);