]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/label.c
14c15b7f09ed81124a4958ba471a2e5ba3b07d4d
[bacula/bacula] / bacula / src / stored / label.c
1 /*
2  *
3  *  label.c  Bacula routines to handle labels 
4  *
5  *   Kern Sibbald, MM
6  *                            
7  *
8  *   Version $Id$
9  */
10 /*
11    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
12
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.
17
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.
22
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,
26    MA 02111-1307, USA.
27
28  */
29
30 #include "bacula.h"                   /* pull in global headers */
31 #include "stored.h"                   /* pull in Storage Deamon headers */
32
33 /* Forward referenced functions */
34 static int create_volume_label(DEVICE *dev, char *VolName);
35 static void create_volume_label_record(JCR *jcr, DEVICE *dev, DEV_RECORD *rec);
36
37 extern char my_name[];
38 extern int debug_level;
39
40 char BaculaId[] =  "Bacula 0.9 mortal\n";
41 unsigned int BaculaTapeVersion = 10;
42 unsigned int OldCompatableBaculaTapeVersion = 9;
43
44
45 /*
46  * Read the volume label
47  *
48  *  If jcr->VolumeName == NULL, we accept any Bacula Volume
49  *  If jcr->VolumeName[0] == 0, we accept any Bacula Volume
50  *  otherwise jcr->VolumeName must match the Volume.
51  *
52  *  If VolName given, ensure that it matches   
53  *
54  *  Returns VOL_  code as defined in record.h
55  *    VOL_NOT_READ
56  *    VOL_OK
57  *    VOL_NO_LABEL
58  *    VOL_IO_ERROR
59  *    VOL_NAME_ERROR
60  *    VOL_CREATE_ERROR
61  *    VOL_VERSION_ERROR
62  *    VOL_LABEL_ERROR
63  */  
64 int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
65 {
66    char *VolName = jcr->VolumeName;
67    DEV_RECORD *record;
68
69    Dmsg2(30, "Enter read_volume_label device=%s vol=%s\n", 
70       dev_name(dev), VolName);
71
72    if (dev->state & ST_LABEL) {       /* did we already read label? */
73       /* Compare Volume Names */
74       if (VolName && *VolName && strcmp(dev->VolHdr.VolName, VolName) != 0) {
75          Mmsg(&jcr->errmsg, _("Volume name mismatch on device %s: Wanted %s got %s\n"),
76             dev_name(dev), VolName, dev->VolHdr.VolName);
77          /*
78           * Cancel Job if too many label errors
79           *  => we are in a loop
80           */
81          if (jcr->label_errors > 100) {
82             jcr->JobStatus = JS_Cancelled;
83             Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg);
84          }
85          return jcr->label_status = VOL_NAME_ERROR;
86       }
87       Dmsg0(30, "Leave read_volume_label() VOL_OK\n");
88       return jcr->label_status = VOL_OK;       /* label already read */
89    }
90
91    dev->state &= ~(ST_LABEL|ST_APPEND|ST_READ);  /* set no label, no append */
92
93    if (!rewind_dev(dev)) {
94       Mmsg(&jcr->errmsg, _("Couldn't rewind device %s ERR=%s\n"), dev_name(dev),
95          strerror_dev(dev));
96       return jcr->label_status = VOL_IO_ERROR;
97    }
98    strcpy(dev->VolHdr.Id, "**error**");
99
100    /* Read the device label block */
101    record = new_record();
102    Dmsg0(90, "Big if statement in read_volume_label\n");
103    if (!read_block_from_dev(dev, block) || 
104        !read_record_from_block(block, record) ||
105        !unser_volume_label(dev, record) || 
106         strcmp(dev->VolHdr.Id, BaculaId) != 0) {
107
108       Mmsg(&jcr->errmsg, _("Volume on %s is not a Bacula labeled Volume, \
109 because:\n   %s"), dev_name(dev), strerror_dev(dev));
110       free_record(record);
111       empty_block(block);
112       rewind_dev(dev);
113       return jcr->label_status = VOL_NO_LABEL;
114    }
115
116    free_record(record);
117    empty_block(block);
118    rewind_dev(dev);
119
120    if (dev->VolHdr.VerNum != BaculaTapeVersion && 
121        dev->VolHdr.VerNum != OldCompatableBaculaTapeVersion) {
122       Mmsg(&jcr->errmsg, _("Volume on %s has wrong Bacula version. Wanted %d got %d\n"),
123          dev_name(dev), BaculaTapeVersion, dev->VolHdr.VerNum);
124       return jcr->label_status = VOL_VERSION_ERROR;
125    }
126
127    /* Compare Volume Names */
128    Dmsg2(30, "Compare Vol names: VolName=%s hdr=%s\n", VolName?VolName:"*", dev->VolHdr.VolName);
129    if (VolName && *VolName && strcmp(dev->VolHdr.VolName, VolName) != 0) {
130       Mmsg(&jcr->errmsg, _("Volume name mismatch. Wanted %s got %s\n"),
131          VolName, dev->VolHdr.VolName);
132       /*
133        * Cancel Job if too many label errors
134        *  => we are in a loop
135        */
136       if (jcr->label_errors > 100) {
137          jcr->JobStatus = JS_Cancelled;
138          Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg);
139       }
140       return jcr->label_status = VOL_NAME_ERROR;
141    }
142    Dmsg1(30, "Copy vol_name=%s\n", dev->VolHdr.VolName);
143
144    /* We are looking for either an unused Bacula tape (PRE_LABEL) or
145     * a Bacula volume label (VOL_LABEL)
146     */
147    if (dev->VolHdr.LabelType != PRE_LABEL && dev->VolHdr.LabelType != VOL_LABEL) {
148       Mmsg(&jcr->errmsg, _("Volume on %s has bad Bacula label type: %x\n"), 
149           dev_name(dev), dev->VolHdr.LabelType);
150       return jcr->label_status = VOL_LABEL_ERROR;
151    }
152
153    dev->state |= ST_LABEL;            /* set has Bacula label */
154    if (debug_level >= 10) {
155       dump_volume_label(dev);
156    }
157    Dmsg0(30, "Leave read_volume_label() VOL_OK\n");
158    return jcr->label_status = VOL_OK;
159 }
160
161 /*  unser_volume_label 
162  *  
163  * Unserialize the Volume label into the device Volume_Label
164  * structure.
165  *
166  * Assumes that the record is already read.
167  *
168  * Returns: 0 on error
169  *          1 on success
170 */
171
172 int unser_volume_label(DEVICE *dev, DEV_RECORD *rec)
173 {
174    ser_declare;
175
176    if (rec->FileIndex != VOL_LABEL && rec->FileIndex != PRE_LABEL) {
177       Mmsg3(&dev->errmsg, _("Expecting Volume Label, got FI=%s Stream=%s len=%d\n"), 
178               FI_to_ascii(rec->FileIndex), stream_to_ascii(rec->Stream), 
179               rec->data_len);
180       return 0;
181    }
182
183    dev->VolHdr.LabelType = rec->FileIndex;
184    dev->VolHdr.LabelSize = rec->data_len;
185
186
187   /* Unserialize the record into the Volume Header */
188   ser_begin(rec->data, SER_LENGTH_Volume_Label);
189 #define Fld(x)  (dev->VolHdr.x)
190    unser_string(Fld(Id));
191
192    unser_uint32(Fld(VerNum));
193
194    unser_float64(Fld(label_date));
195    unser_float64(Fld(label_time));
196    unser_float64(Fld(write_date));
197    unser_float64(Fld(write_time));
198
199    unser_string(Fld(VolName));
200    unser_string(Fld(PrevVolName));
201    unser_string(Fld(PoolName));
202    unser_string(Fld(PoolType));
203    unser_string(Fld(MediaType));
204
205    unser_string(Fld(HostName));
206    unser_string(Fld(LabelProg));
207    unser_string(Fld(ProgVersion));
208    unser_string(Fld(ProgDate));
209
210    ser_end(rec->data, SER_LENGTH_Volume_Label);
211 #undef Fld
212    Dmsg0(90, "ser_read_vol\n");
213    if (debug_level >= 90) {
214       dump_volume_label(dev);      
215    }
216    return 1;
217 }
218
219 /*
220  * Put a volume label into the block
221  *
222  *  Returns: 0 on failure
223  *           1 on success
224  */
225 int write_volume_label_to_block(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
226 {
227    DEV_RECORD rec;
228
229    Dmsg0(20, "write Label in write_volume_label_to_block()\n");
230    memset(&rec, 0, sizeof(rec));
231    rec.data = get_memory(SER_LENGTH_Volume_Label);
232
233    create_volume_label_record(jcr, dev, &rec);
234
235    empty_block(block);                /* Volume label always at beginning */
236    if (!write_record_to_block(block, &rec)) {
237       free_pool_memory(rec.data);
238       Jmsg1(jcr, M_FATAL, 0, _("Cannot write Volume label to block for device %s\n"),
239          dev_name(dev));
240       return 0;
241    } else {
242       Dmsg1(90, "Wrote label of %d bytes to block\n", rec.data_len);
243    }
244    free_pool_memory(rec.data);
245    return 1;
246 }
247
248 /* 
249  *  create_volume_label_record
250  *   Serialize label (from dev->VolHdr structure) into device record.
251  *   Assumes that the dev->VolHdr structure is properly 
252  *   initialized.
253 */
254 static void create_volume_label_record(JCR *jcr, DEVICE *dev, DEV_RECORD *rec)
255 {
256    ser_declare;
257    struct date_time dt;
258
259    /* Serialize the label into the device record. */
260
261    ser_begin(rec->data, SER_LENGTH_Volume_Label);
262 #define Fld(x)  (dev->VolHdr.x)
263    ser_string(Fld(Id));
264
265    ser_uint32(Fld(VerNum));
266
267    ser_float64(Fld(label_date));
268    ser_float64(Fld(label_time));
269
270    get_current_time(&dt);
271    Fld(write_date) = dt.julian_day_number;
272    Fld(write_time) = dt.julian_day_fraction;
273
274    ser_float64(Fld(write_date));
275    ser_float64(Fld(write_time));
276
277    ser_string(Fld(VolName));
278    ser_string(Fld(PrevVolName));
279    ser_string(Fld(PoolName));
280    ser_string(Fld(PoolType));
281    ser_string(Fld(MediaType));
282
283    ser_string(Fld(HostName));
284    ser_string(Fld(LabelProg));
285    ser_string(Fld(ProgVersion));
286    ser_string(Fld(ProgDate));
287
288    ser_end(rec->data, SER_LENGTH_Volume_Label);
289    rec->data_len = ser_length(rec->data);
290    rec->FileIndex = Fld(LabelType);
291    rec->VolSessionId = jcr->VolSessionId;
292    rec->VolSessionTime = jcr->VolSessionTime;
293    rec->Stream = jcr->NumVolumes;
294    Dmsg2(100, "Created Vol label rec: FI=%s len=%d\n", FI_to_ascii(rec->FileIndex),
295       rec->data_len);
296 #undef Fld
297 }     
298
299
300 /*
301  * Create a volume label in memory
302  *  Returns: 0 on error
303  *           1 on success
304  */
305 static int create_volume_label(DEVICE *dev, char *VolName)
306 {
307    struct date_time dt;
308    DEVRES *device = (DEVRES *)dev->device;
309
310    Dmsg0(90, "Start create_volume_label()\n");
311
312    ASSERT(dev != NULL);
313
314    memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
315
316    /* ***FIXME*** we really need to get the volume name,    
317     * pool name, and pool type from the database.
318     * We also need to pickup the MediaType.
319     */
320    strcpy(dev->VolHdr.Id, BaculaId);
321    dev->VolHdr.VerNum = BaculaTapeVersion;
322    dev->VolHdr.LabelType = PRE_LABEL;  /* Mark tape as unused */
323    strcpy(dev->VolHdr.VolName, VolName);
324    strcpy(dev->VolHdr.PoolName, "Default");
325    strcpy(dev->VolHdr.MediaType, device->media_type);
326    strcpy(dev->VolHdr.PoolType, "Backup");
327
328    /* Put label time/date in header */
329    get_current_time(&dt);
330    dev->VolHdr.label_date = dt.julian_day_number;
331    dev->VolHdr.label_time = dt.julian_day_fraction;
332
333    strcpy(dev->VolHdr.LabelProg, my_name);
334    sprintf(dev->VolHdr.ProgVersion, "Ver. %s %s", VERSION, DATE);
335    sprintf(dev->VolHdr.ProgDate, "Build %s %s", __DATE__, __TIME__);
336    dev->state |= ST_LABEL;            /* set has Bacula label */
337    if (debug_level >= 90) {
338       dump_volume_label(dev);
339    }
340    return 1;
341 }
342
343 /*
344  * Write a Volume Label
345  *  !!! Note, this is ONLY used for writing
346  *            a fresh volume label.  Any data
347  *            after the label will be destroyed,
348  *            in fact, we write the label 5 times !!!!
349  * 
350  *  This routine expects that open_device() was previously called.
351  *
352  *  This routine should be used only when labeling a blank tape.
353  */
354 int write_volume_label_to_dev(JCR *jcr, DEVRES *device, char *VolName, char *PoolName)
355 {
356    DEVICE *dev = device->dev;
357    DEV_RECORD rec;   
358    DEV_BLOCK *block;
359    int stat = 1;
360
361
362    Dmsg0(99, "write_volume_label()\n");
363    if (!create_volume_label(dev, VolName)) {
364       return 0;
365    }
366    strcpy(dev->VolHdr.MediaType, device->media_type);
367    strcpy(dev->VolHdr.VolName, VolName);
368    strcpy(dev->VolHdr.PoolName, PoolName);
369
370    if (!rewind_dev(dev)) {
371       Dmsg2(30, "Bad status on %s from rewind. ERR=%s\n", dev_name(dev), strerror_dev(dev));
372       return 0;
373    }
374
375    block = new_block(dev);
376    memset(&rec, 0, sizeof(rec));
377    rec.data = (char *) get_memory(SER_LENGTH_Volume_Label);
378    create_volume_label_record(jcr, dev, &rec);
379    rec.Stream = 0;
380
381    if (!write_record_to_block(block, &rec)) {
382       Dmsg2(30, "Bad Label write on %s. ERR=%s\n", dev_name(dev), strerror_dev(dev));
383       free_block(block);
384       free_pool_memory(rec.data);
385       return 0;
386    } else {
387       Dmsg2(30, "Wrote label of %d bytes to %s\n", rec.data_len, dev_name(dev));
388    }
389    free_pool_memory(rec.data);
390       
391    Dmsg0(99, "Call write_block_to_device()\n");
392    if (!write_block_to_dev(dev, block)) {
393       Dmsg2(30, "Bad Label write on %s. ERR=%s\n", dev_name(dev), strerror_dev(dev));
394       stat = 9;
395    }
396    Dmsg0(99, " Wrote block to device\n");
397      
398    flush_dev(dev);
399    weof_dev(dev, 1);
400    dev->state |= ST_LABEL;
401
402    if (debug_level >= 20)  {
403       dump_volume_label(dev);
404    }
405    free_block(block);
406    return stat;
407 }     
408
409
410 /*
411  * Create session label
412  *  The pool memory must be released by the calling program
413  */
414 void create_session_label(JCR *jcr, DEV_RECORD *rec, int label)
415 {
416    ser_declare;
417    struct date_time dt;
418
419    rec->sync           = 1;         /* wait for completion */
420    rec->VolSessionId   = jcr->VolSessionId;
421    rec->VolSessionTime = jcr->VolSessionTime;
422    rec->Stream         = jcr->JobId;
423
424    ser_begin(rec->data, SER_LENGTH_Session_Label);
425    ser_string(BaculaId);
426    ser_uint32(BaculaTapeVersion);
427
428    ser_uint32(jcr->JobId);
429
430    get_current_time(&dt);
431    ser_float64(dt.julian_day_number);
432    ser_float64(dt.julian_day_fraction);
433
434    ser_string(jcr->pool_name);
435    ser_string(jcr->pool_type);
436    ser_string(jcr->job_name);         /* base Job name */
437    ser_string(jcr->client_name);
438    /* Added in VerNum 10 */
439    ser_string(jcr->Job);              /* Unique name of this Job */
440    ser_string(jcr->fileset_name);
441    ser_uint32(jcr->JobType);
442    ser_uint32(jcr->JobLevel);
443
444    if (label == EOS_LABEL) {
445       ser_uint32(jcr->JobFiles);
446       ser_uint64(jcr->JobBytes);
447       ser_uint32(jcr->start_block);
448       ser_uint32(jcr->end_block);
449       ser_uint32(jcr->start_file);
450       ser_uint32(jcr->end_file);
451       ser_uint32(jcr->JobErrors);
452    }
453    ser_end(rec->data, SER_LENGTH_Session_Label);
454    rec->data_len = ser_length(rec->data);
455 }
456
457 /* Write session label
458  *  Returns: 0 on failure
459  *           1 on success 
460  */
461 int write_session_label(JCR *jcr, DEV_BLOCK *block, int label)
462 {
463    DEVICE *dev = jcr->device->dev;
464    DEV_RECORD *rec;
465
466    rec = new_record();
467    Dmsg1(90, "session_label record=%x\n", rec);
468    switch (label) {
469       case SOS_LABEL:
470          jcr->start_block = dev->block_num;
471          jcr->start_file  = dev->file;
472          break;
473       case EOS_LABEL:
474          jcr->end_block = dev->block_num;
475          jcr->end_file = dev->file;
476          break;
477       default:
478          Jmsg1(jcr, M_ABORT, 0, _("Bad session label = %d\n"), label);
479          break;
480    }
481    create_session_label(jcr, rec, label);
482    rec->FileIndex = label;
483
484    /* 
485     * We guarantee that the session record can totally fit
486     *  into a block. If not, write the block, and put it in
487     *  the next block. Having the sesssion record totally in
488     *  one block makes reading them much easier (no need to
489     *  read the next block).
490     */
491    if (!can_write_record_to_block(block, rec)) {
492       if (!write_block_to_device(jcr, dev, block)) {
493          Dmsg0(90, "Got session label write_block_to_dev error.\n");
494          Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"), 
495                            dev_vol_name(dev), strerror(errno));
496          free_record(rec);
497          return 0;
498       }
499    }
500    write_record_to_block(block, rec);
501
502    Dmsg6(20, "Write sesson_label record JobId=%d FI=%s SessId=%d Strm=%s len=%d\n\
503 remainder=%d\n", jcr->JobId,
504       FI_to_ascii(rec->FileIndex), rec->VolSessionId, 
505       stream_to_ascii(rec->Stream), rec->data_len,
506       rec->remainder);
507
508    free_record(rec);
509    Dmsg2(20, "Leave write_session_label Block=%d File=%d\n", 
510       dev->block_num, dev->file);
511    return 1;
512 }
513
514 void dump_volume_label(DEVICE *dev)
515 {
516    int dbl;
517    uint32_t File;
518    char *LabelType, buf[30];
519    struct tm tm;
520    struct date_time dt;
521
522    File = dev->file;
523    switch (dev->VolHdr.LabelType) {
524       case PRE_LABEL:
525          LabelType = "PRE_LABEL";
526          break;
527       case VOL_LABEL:
528          LabelType = "VOL_LABEL";
529          break;
530       case EOM_LABEL:
531          LabelType = "EOM_LABEL";
532          break;
533       case SOS_LABEL:
534          LabelType = "SOS_LABEL";
535          break;
536       case EOS_LABEL:
537          LabelType = "EOS_LABEL";
538          break;
539       default:
540          LabelType = buf;
541          sprintf(buf, "Unknown %d", dev->VolHdr.LabelType);
542          break;
543    }
544               
545    
546    dbl = debug_level;
547    debug_level = 1;
548    Pmsg11(-1, "\nVolume Label:\n\
549 Id                : %s\
550 VerNo             : %d\n\
551 VolName           : %s\n\
552 PrevVolName       : %s\n\
553 VolFile           : %d\n\
554 LabelType         : %s\n\
555 LabelSize         : %d\n\
556 PoolName          : %s\n\
557 MediaType         : %s\n\
558 PoolType          : %s\n\
559 HostName          : %s\n\
560 ",
561              dev->VolHdr.Id, dev->VolHdr.VerNum,
562              dev->VolHdr.VolName, dev->VolHdr.PrevVolName,
563              File, LabelType, dev->VolHdr.LabelSize, 
564              dev->VolHdr.PoolName, dev->VolHdr.MediaType, 
565              dev->VolHdr.PoolType, dev->VolHdr.HostName);
566
567    dt.julian_day_number   = dev->VolHdr.label_date;
568    dt.julian_day_fraction = dev->VolHdr.label_time;
569    tm_decode(&dt, &tm);
570    Pmsg5(-1, "\
571 Date label written: %04d-%02d-%02d at %02d:%02d\n", 
572       tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
573    debug_level = dbl;
574 }
575
576 int unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec) 
577 {
578    ser_declare;
579
580    unser_begin(rec->data, SER_LENGTH_Session_Label);
581    unser_string(label->Id);
582    unser_uint32(label->VerNum);
583    unser_uint32(label->JobId);
584    unser_float64(label->write_date);
585    unser_float64(label->write_time);
586    unser_string(label->PoolName);
587    unser_string(label->PoolType);
588    unser_string(label->JobName);
589    unser_string(label->ClientName);
590    if (label->VerNum > 9) {
591       unser_string(label->Job);          /* Unique name of this Job */
592       unser_string(label->FileSetName);
593       unser_uint32(label->JobType);
594       unser_uint32(label->JobLevel);
595    }
596    if (rec->FileIndex == EOS_LABEL) {
597       unser_uint32(label->JobFiles);
598       unser_uint64(label->JobBytes);
599       unser_uint32(label->start_block);
600       unser_uint32(label->end_block);
601       unser_uint32(label->start_file);
602       unser_uint32(label->end_file);
603       unser_uint32(label->JobErrors);
604    }      
605    return 1;
606 }
607
608
609 static void dump_session_label(DEV_RECORD *rec, char *type)
610 {
611    int dbl;
612    struct date_time dt;
613    struct tm tm;
614    SESSION_LABEL label;
615    char ec1[30], ec2[30], ec3[30], ec4[30], ec5[30], ec6[30], ec7[30];
616
617
618    unser_session_label(&label, rec);
619    dbl = debug_level;
620    debug_level = 1;
621    Pmsg6(-1, "\n%s Record:\n\
622 JobId             : %d\n\
623 PoolName          : %s\n\
624 PoolType          : %s\n\
625 JobName           : %s\n\
626 ClientName        : %s\n\
627 ",    type, 
628       label.JobId, label.PoolName, label.PoolType,
629       label.JobName, label.ClientName);
630
631    if (label.VerNum >= 10) {
632       Pmsg4(-1, "\
633 Job (unique name) : %s\n\
634 FileSet           : %s\n\
635 JobType           : %c\n\
636 JobLevel          : %c\n\
637 ", label.Job, label.FileSetName, label.JobType, label.JobLevel);
638    }
639
640    if (rec->FileIndex == EOS_LABEL) {
641       Pmsg7(-1, "\
642 JobFiles          : %s\n\
643 JobBytes          : %s\n\
644 StartBlock        : %s\n\
645 EndBlock          : %s\n\
646 StartFile         : %s\n\
647 EndFile           : %s\n\
648 JobErrors         : %s\n\
649 ",
650          edit_uint64_with_commas(label.JobFiles, ec1),
651          edit_uint64_with_commas(label.JobBytes, ec2),
652          edit_uint64_with_commas(label.start_block, ec3),
653          edit_uint64_with_commas(label.end_block, ec4),
654          edit_uint64_with_commas(label.start_file, ec5),
655          edit_uint64_with_commas(label.end_file, ec6),
656          edit_uint64_with_commas(label.JobErrors, ec7));
657    }
658    dt.julian_day_number   = label.write_date;
659    dt.julian_day_fraction = label.write_time;
660    tm_decode(&dt, &tm);
661    Pmsg5(-1, "\
662 Date written      : %04d-%02d-%02d at %02d:%02d\n", 
663       tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
664
665    debug_level = dbl;
666 }
667
668 void dump_label_record(DEVICE *dev, DEV_RECORD *rec, int verbose)
669 {
670    char *type;
671    int dbl;
672
673    dbl = debug_level;
674    debug_level = 1;
675    switch (rec->FileIndex) {
676       case PRE_LABEL:
677          type = "Fresh Volume";   
678          break;
679       case VOL_LABEL:
680          type = "Volume";
681          break;
682       case SOS_LABEL:
683          type = "Begin Session";
684          break;
685       case EOS_LABEL:
686          type = "End Session";
687          break;
688       case EOM_LABEL:
689          type = "End of Media";
690          break;
691       default:
692          type = "Unknown";
693          break;
694    }
695    if (verbose) {
696       switch (rec->FileIndex) {
697          case PRE_LABEL:
698          case VOL_LABEL:
699             unser_volume_label(dev, rec);
700             dump_volume_label(dev);
701             break;
702          case SOS_LABEL:
703             dump_session_label(rec, type);
704             break;
705          case EOS_LABEL:
706             dump_session_label(rec, type);
707             break;
708          case EOM_LABEL:
709             Pmsg5(-1, "%s Record: VSessId=%d VSessTime=%d JobId=%d DataLen=%d\n",
710                type, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
711             break;
712          default:
713             Pmsg5(-1, "%s Record: VSessId=%d VSessTime=%d JobId=%d DataLen=%d\n",
714                type, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
715             break;
716       }
717    } else {
718       Pmsg5(-1, "%s Record: VSessId=%d VSessTime=%d JobId=%d DataLen=%d\n",
719          type, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
720    }
721    debug_level = dbl;
722 }