-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvmsbackup.c
2971 lines (2326 loc) · 87.3 KB
/
vmsbackup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* Title:
* Backup
*
* Decription:
* Program to read VMS backup tape
*
* Author:
* John Douglas CAREY. (version 2.x, I think)
* Sven-Ove Westberg (version 3.0)
* See ChangeLog file for more recent authors.
*
* Net-addess (as of 1986 or so; it is highly unlikely these still work):
* john%monu1.oz@seismo.ARPA
* luthcad!sow@enea.UUCP
*
*
* Installation (again, as of 1986):
*
* Computer Centre
* Monash University
* Wellington Road
* Clayton
* Victoria 3168
* AUSTRALIA
*
*/
/*
// Portions Copyright (c) 2008 HoffmanLabs LLC
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// Except as contained in this notice, the name(s) of the above
// copyright holders shall not be used in advertising or otherwise
// to promote the sale, use or other dealings in this Software
// without prior written authorization.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
*/
/*
** Portions Copyright (c) 1983, 1989
** The Regents of the University of California. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. All advertising materials mentioning features or use of this software
** must display the following acknowledgement:
** This product includes software developed by the University of
** California, Berkeley and its contributors.
** 4. Neither the name of the University nor the names of its contributors
** may be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
*/
/*
// Port to Solaris C. Enhance VMS time support. Add extra tape mark
// skip to get past tape header. Add close statement for extracted files.
// Time stamp extracted files with original create and mod times.
// Add further documentation comments. First attempt to handle indexed
// files.
//
// 10/ 3/08 K. Clark CSC/STSci
*/
/*
// 05-May-2008, Stephen Hoffman, HoffmanLabs LLC
// incorporate contributed two gigabyte (longword) display fixes.
// (Thanks, Weiss.) Resolved various endian issues from the
// Solaris port; added BSD code for endian-ness from nameser.h.
*/
/* begin included (and reworked) BSD code (from nameser.h) */
#ifndef BYTE_ORDER
#if ((__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060))
# include <machine/endian.h>
#endif
#if (BSD >= 199103)
# include <machine/endian.h>
#endif
#ifdef linux
# include <endian.h>
#endif
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || defined(_M_IX86) || \
defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
defined(__alpha__) || defined(__alpha) || defined(__x86_64__) || defined(_M_X64) || \
(defined(__Lynx__) && defined(__x86__))
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
defined(apollo) || defined(__convex__) || defined(_CRAY) || \
defined(__hppa) || defined(__hp9000) || \
defined(__hp9000s300) || defined(__hp9000s700) || \
defined (BIT_ZERO_ON_LEFT) || defined(m68k)
#define BYTE_ORDER BIG_ENDIAN
#endif
#if (defined(__Lynx__) && (defined(__68k__) || defined(__sparc__) || defined(__powerpc__)))
#define BYTE_ORDER BIG_ENDIAN
#endif
#endif /* LITTLE_ENDIAN */
#endif /* BYTE_ORDER */
#if !defined(BYTE_ORDER) || \
(BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
BYTE_ORDER != PDP_ENDIAN)
/* you must determine what the correct bit order is for
* your compiler - the next line is an intentional error
* which will force your compiles to bomb until you fix
* the above macros.
*/
error "Undefined or invalid BYTE_ORDER";
#endif
/* end included (and reworked) BSD code (from nameser.h) */
/* Does this system have the magnetic tape ioctls? The answer is yes for
most unices, and I think it is yes for VMS 7.x with DECC 5.2 (needs
verification), but it is no for VMS 6.2. mtio.h was removed from
Mac OS X Snow Leopard (10.6). */
#if ((__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060))
# define HAVE_MT_IOCTLS 0
#endif
#ifndef HAVE_MT_IOCTLS
# define HAVE_MT_IOCTLS 1
#endif
#ifdef HAVE_UNIXIO_H
/* Declarations for read, write, etc. */
# include <unixio.h>
#else
# include <unistd.h>
# include <fcntl.h>
#endif
/*
* On VMS these are in unistd.h, which in build.com is not included
* as HAVE_UNIXIO_H is defined.
*/
#ifndef STDIN_FILENO
# define STDIN_FILENO 0 /* Standard input. */
# define STDOUT_FILENO 1 /* Standard output. */
# define STDERR_FILENO 2 /* Standard error output. */
#endif
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <utime.h>
#if HAVE_MT_IOCTLS
# include <sys/ioctl.h>
# include <sys/mtio.h>
#endif /* HAVE_MT_IOCTLS */
#ifdef REMOTE
# include <local/rmt.h>
# include <sys/stat.h>
#endif /* REMOTE */
#include <sys/file.h>
#include "vmsconstants.h"
#ifdef __VAXC
/* The help claims that mkdir is declared in stdlib.h but it doesn't
seem to be true. AXP/VMS 6.2, DECC ?.?. On the other hand, VAX/VMS 6.2
seems to declare it in a way which conflicts with this definition.
This is starting to sound like a bad dream. */
int mkdir ();
#endif /* __VAXC */
#include "vmsbackup.h"
// #include "sysdep.h"
// Dump raw data records.
static void debug_dump(const unsigned char* buffer,
unsigned short int dsize,
unsigned short int dtype);
int match ();
char *strlocase ();
/*
* Convert the OpenVMS epoch to the Unix epoch, punting on
* select special cases.
*/
time_t time_vms_to_unix(unsigned long long vms_time_ll);
/*
* Convert the OpenVMS epoch into text, selectively punting.
*/
time_t time_vms_to_unix_asc( unsigned char *vmstime, int vmstim_len,
char *date_text, int *date_text_len );
#define MAX_DATE_STR 24
#if BYTE_ORDER == LITTLE_ENDIAN
unsigned long long
getu64 (unsigned char *addr) {
return (*(unsigned long long int *) addr);
}
unsigned int
getu32 (unsigned char *addr) {
return *(unsigned int *) addr;
}
unsigned int
getu16 (unsigned char *addr) {
return *(unsigned short int *) addr;
}
#endif
#if BYTE_ORDER == BIG_ENDIAN
unsigned long long
getu64 (unsigned char *addr) {
long long big_endian;
unsigned char *dst = (unsigned char *)&big_endian;
unsigned char *src = (unsigned char *)addr;
dst [0] = src[7];
dst [1] = src[6];
dst [2] = src[5];
dst [3] = src[4];
dst [4] = src[3];
dst [5] = src[2];
dst [6] = src[1];
dst [7] = src[0];
return big_endian;
}
unsigned
getu32 (unsigned char *addr) {
return (((((unsigned)addr[3] << 8) | addr[2]) << 8)
| addr[1]) << 8 | addr[0];
}
unsigned int
getu16 (unsigned char *addr) {
return (addr[1] << 8) | addr[0];
}
#endif
// VMS backup block header.
struct bbhdef {
unsigned char bbh_dol_w_size[2]; // Size in bytes of block header.
unsigned char bbh_dol_w_opsys[2]; // Operating system ID.
unsigned char bbh_dol_w_subsys[2]; // Subsystem ID.
unsigned char bbh_dol_w_applic[2]; // Application ID.
unsigned char bbh_dol_l_number[4]; // Block sequence number.
char bbh_dol_t_spare_1[20]; // Reserved spare bits.
unsigned char bbh_dol_w_struclev[2]; // Block structure level.
unsigned char bbh_dol_w_volnum[2]; // Media volume number.
unsigned char bbh_dol_l_crc[4]; // Block CRC.
unsigned char bbh_dol_l_blocksize[4]; // Block size in bytes.
unsigned char bbh_dol_l_flags[4]; // Block flags.
char bbh_dol_t_ssname[32]; // Save set name (counted ASCII).
unsigned char bbh_dol_w_fid[3][2]; // Current file ID.
unsigned char bbh_dol_w_did[3][2]; // Current directory ID.
char bbh_dol_t_filename[128];// Current file name.
char bbh_dol_b_rtype; // Record type of current file.
char bbh_dol_b_rattrib; // Record attributes of current file.
unsigned char bbh_dol_w_rsize[2]; // Record size of current file.
char bbh_dol_b_bktsize; // Bucket size of current file.
char bbh_dol_b_vfcsize; // VFC area size of current file.
unsigned char bbh_dol_w_maxrec[2]; // Maximum record size of current file.
unsigned char bbh_dol_l_filesize[4]; // Allocation of current file.
char bbh_dol_t_spare_2[22]; // Reserved - spare bytes.
unsigned char bbh_dol_w_checksum[2]; // Header checksum.
} *ablock_header;
// VMS backup record header. This structure prefixes each record
// within a data block. It identifies the type and use of the record.
struct brhdef {
unsigned char brh_dol_w_rsize[2]; // Record size in bytes -
// unsigned short int
unsigned char brh_dol_w_rtype[2]; // Record type. -
// unsigned short int
unsigned char brh_dol_l_flags[4]; // Record flags. -
// unsigned int
unsigned char brh_dol_l_address[4]; // Address of data (e.g. VBN or LBN).
// unsigned int
unsigned char brh_dol_l_blockflags[4]; // Per block error mask & reserved?
// unsigned short int, unsigned short int
} *arecord_header;
/* Define VMS backup record types. */
#define brh_dol_k_null 0 /* null record */
#define brh_dol_k_summary 1 /* saveset summary record */
#define brh_dol_k_volume 2 /* volume summary */
#define brh_dol_k_file 3 /* file attributes */
#define brh_dol_k_vbn 4 /* file VBN */
#define brh_dol_k_physvol 5 /* disk volume attributes */
#define brh_dol_k_lbn 6 /* disk volume LBN */
#define brh_dol_k_fid 7 /* file identification */
#define brh_dol_k_file_ext 8 /* file extension record */
#define brh_dol_k_lbn_576 9 /* 576-byte LBN record */
#define brh_dol_k_rs_dirattr 10 /* RSTS directory attributes */
#define brh_dol_k_alias 11 /* file alias entry */
#define brh_dol_k_max_rtype 12 /* Maximum number of VMS record types. */
#define MAX_RETRYS 10 /* Maximum of I/O read retrys. */
/* VMS backup file attribute structure. */
struct bsa {
unsigned char bsa_dol_w_size[2]; // Size of attribute value.
unsigned char bsa_dol_w_type[2]; // Atribute code.
unsigned char bsa_dol_t_text[1]; // Attribute data.
}*data_item;
#ifdef STREAM
char *def_tapefile = "/dev/rts8";
#else
// char *def_tapefile = "/dev/rmt8";
char *def_tapefile = "/dev/rmt/1";
#endif
char filename[128];
char unix_filename[256];
time_t create_time;
time_t last_create_time;
time_t mod_time;
time_t last_mod_time;
unsigned long long int filesize;
unsigned long long int allocated_bytes_file_size;
// Breakout of VMS Record format bytes of a file attribute.
static struct vms_rec_type {
union {
unsigned char rec_format; // VMS record type.
struct {
unsigned char rtype : 4; // VMS record type subfield.
unsigned char fileorg : 4; // VMS file organization.
} rectype_bits;
} rec_type_word;
} rec_type;
char recatt; /* record attributes */
FILE *fptr_out = NULL;
/* Number of bytes we have read from the current file so far (or something
like that; see process_vbn). */
int file_byte_count;
short reclen;
short fix;
short recsize;
unsigned short int VFC_ctr_bytes = 0;
int needToSkipVFC = 0;
/* Number of files we have seen. */
unsigned int nfiles;
/* Number of blocks in those files. */
unsigned long nblocks;
#ifdef NEWD
FILE *lf;
#endif
int fd; /* tape file descriptor */
/* Entirely weird, but some savesets have several summary records.
* These seem to entirely replicate the contents of the tape; it
* might be triggered by a searchlist default when the BACKUP is
* created? BACKUP itself appears to ignore these, so we too
* ignore everything starting at the second summary record and
* onward. (This smells vaguely of a BACKUP bug.)
*/
/* No bug. This happened, when an XORBLOCK was processed as a DATABLOCK
* and a record type 1 == summary was found in the XOR data.
* For now, XORBLOCKS are skipped.
*/
int summary_seen = 0;
/* Command line stuff. */
/* The save set that we are listing or extracting. */
char *tapefile;
/* The output file we are extracting into. */
char *outfile;
/* We're going to say tflag indicates our best effort at the same
output format as VMS BACKUP/LIST. Previous versions of this
program used tflag for a briefer output format; if we want that
feature we'll have to figure out what option should control it. */
int tflag; // List files in saveset.
int cflag; // Retain complete filename.
int dflag; // Create subdirectories.
int eflag; // Extract all files.
int sflag; // Read saveset number.
int vflag; // List files as they are processed.
int wflag; // Confirm files before restoring.
int xflag; // Extract files.
int ehint; // Hint for using the eflag when one or more files were ignored
int debugflags;
#define D_BLKREC 0x1
#define D_FILE 0x2
#define D_VBN 0x4
#define D_IO 0x8
#define D_SUM 0x10
#define D_TIME 0x20
#define D_FILE_X 0x40
#define D_VBN_X 0x80
#define D_SUM_X 0x100
/* Extract files in binary mode. FIXME: Haven't tried to document
(here or in the manpage) exactly what that means. I think it probably
means (or should mean) to give us raw bits, the same as you would get
if you read the file in VMS directly using SYS$QIO or some such. But
I haven't carefully looked at whether that is what it currently does. */
int flag_binary;
int flag_full; // Full detail in listing.
/* Which save set are we reading? */
int selset;
/* These variables describe the files we will be operating on. GARGV is
a vector of GARGC elements, and the elements from GOPTIND to the end
are the names. */
char **gargv;
int goptind, gargc;
int setnr;
#define LABEL_SIZE 80
/* Default blocksize, as specified in -b option. */
int blocksize = 32256;
#if HAVE_MT_IOCTLS
struct mtop op;
#endif
int typecmp ();
FILE *
openfile(char *req_file_name, int struclev)
{
FILE *found_file_ftr = NULL;
char temp_name_buf[256];
char *output_unix_filename;
char *temp_unix_filename;
char s;
char *ext;
char ans[80];
int procf;
procf = 1;
// Copy the input requested file name to the output file name.
output_unix_filename = req_file_name;
// Allocate enough memory for the temporary unix file name.
temp_unix_filename = temp_name_buf;
/* Step through each character of the file name and convert it to
lower case.
*/
while (*output_unix_filename) {
/*
if (isupper(*output_unix_filename))
*temp_unix_filename = *output_unix_filename - 'A' + 'a';
else
*temp_unix_filename = *output_unix_filename;
*/
*temp_unix_filename = ( struclev == 2) ?
tolower( *output_unix_filename ) :
*output_unix_filename;
output_unix_filename++;
temp_unix_filename++;
}
// Terminate the lower case file name.
*temp_unix_filename = '\0';
// Copy the lower case file name to the output file name.
output_unix_filename = temp_name_buf;
temp_unix_filename = ++output_unix_filename;
// Convert the VMS directory path to Unix format.
while (*temp_unix_filename) {
if (*temp_unix_filename == '.' || *temp_unix_filename == ']') {
s = *temp_unix_filename;
*temp_unix_filename = '\0';
// Create an output directory if requested.
if (procf && dflag) {
mkdir(output_unix_filename, 0777);
}
*temp_unix_filename = '/';
if (s == ']') {
// Found the end of the directory path.
break;
}
}
temp_unix_filename++;
} // Convert the VMS directory path to Unix format.
// Position the pointer at the end of the file path.
temp_unix_filename++;
if (!dflag) {
// Write the output file to the current directory.
output_unix_filename = temp_unix_filename;
}
// Locate the start of the VMS version part of the file name
while (*temp_unix_filename && *temp_unix_filename != ';') {
if( *temp_unix_filename == '.') {
// Record the file name extension.
ext = temp_unix_filename;
}
temp_unix_filename++;
}
if (cflag) {
// Retain the version number after a ":" instead of a ";".
*temp_unix_filename = ':';
} else {
// Strip off the version number.
*temp_unix_filename = '\0';
}
if(!eflag && procf && !(goptind < gargc)) {
// Check if this file should be ignored, because it matches an entry
// on the extensions list,
// but only if there was no explicit FILE list on the command line
procf = typecmp(++ext);
if (!procf && vflag) {
printf("ignoring: %s\n", filename);
}
if (!procf && !ehint) {
ehint = 1;
printf("one or more files matching the extensions list are ignored,\n"
"consider using the -e/--extensions option\n");
if (!vflag)
printf("or the -v/--verbose option to have the ignored files listed\n");
}
}
if(procf && wflag) {
// Confirm file is to be extracted.
printf("extract %s [ny]: ",filename);
fflush(stdout);
fgets(ans, sizeof(ans), stdin);
if(*ans != 'y') {
procf = 0;
}
}
if(procf) {
/* Open the file for writing. */
if(outfile)
if(0==strcmp(outfile,"-"))
found_file_ftr = fdopen(STDOUT_FILENO,"w");
else
found_file_ftr = fopen(outfile, "w");
else
found_file_ftr = fopen(output_unix_filename, "w");
// Record the current file name and date.
strcpy (unix_filename, output_unix_filename);
last_create_time = create_time;
last_mod_time = mod_time;
} else {
found_file_ftr = NULL;
}
return (found_file_ftr);
}
/* Close the output file and set the file time stamps. */
int close_file (FILE *out_fptr, char output_filename[256],
time_t file_create_date, time_t file_mod_date) {
int status = 0;
struct utimbuf utb;
status = fclose(out_fptr);
if (debugflags & D_IO) {
fprintf (stderr, "Closing file: %s status %d\n", output_filename, status);
}
// Set the file access time and modification time if known.
// if ((file_create_date != NULL) & (file_mod_date != NULL)) {
if ( (file_create_date) && (file_mod_date) ) {
utb.actime = file_create_date;
utb.modtime = file_mod_date;
utime (output_filename, &utb);
if (debugflags & D_IO) {
fprintf (stderr, "Setting file %s create time to %d\n",
output_filename, (int) file_create_date);
fprintf (stderr, "Setting file mod time to %d\n",
(int) file_mod_date);
}
}
return status;
}
int
typecmp(register char *str)
/* Compare the filename type in str with our list of file type
to be ignored.
Return 0 if the file is to be ignored.
Return 1 if the file is to be included; if the file is not
in our list and should not be excluded.
*/
{
/* SORTED! */
static char *type[] = {
"dir", /* directory file */
"dmp", /* dump file */
"exe", /* executable image */
"hlb", /* help library */
"lib", /* vms object library */
"mlb", /* macro32 library */
"obj", /* object file */
"odl", /* rsx overlay description file */
"olb", /* rsx object library */
"pcsi", /* POLYCENTER Installation Kit */
"pcsi$compressed",
"pcsi-dcx_axpexe",
"pcsi-dcx_vaxexe",
"pmd", /* rsx post mortem dump */
"stb", /* symbol table */
"sys", /* bootable system image */
"tlb", /* text library */
"tlo", /* ? */
"tsk", /* rsx executable image */
"upd", /* ? */
"" /* null string terminates list */
};
register int i;
i = -1;
while (*type[++i]) {
int foo;
int str_len = strlen( str );
int typ_len = strlen( type[i] );
if ( !typ_len ) /* no more types in list? include the file */
return 1;
if ( str_len != typ_len ) /* length mismatch? skip the comparison */
continue;
foo = strncasecmp(str, type[i],typ_len);
if ( foo == 0 ) /* zero is a match; ignore the file */
return(0);
}
return 1; /* default to include file */
}
/* Process a VMS backup summary record. */
void
process_summary (unsigned char *buffer, unsigned short rsize)
{
unsigned short int dsize;
unsigned char *text;
int attr_ptr;
int type;
/* These are the various fields from the summary. */
unsigned long id = 0;
char *saveset = "";
size_t saveset_size = 0;
char *command = "";
size_t command_size = 0;
char *comment = "";
size_t comment_size = 0;
char *written_by = "";
size_t written_by_size = 0;
unsigned short grp = 0377;
unsigned short usr = 0377;
char *os = "<unknown OS>"; /* '\0' terminated. */
char *osversion = "unknown";
size_t osversion_size = 7;
char *nodename = "";
size_t nodename_size = 0;
char *written_on = "";
size_t written_on_size = 0;
char *backup_version = "unknown";
size_t backup_version_size = 7;
char *vol_set_name = "";
size_t vol_set_name_size = 0;
char date[MAX_DATE_STR];
int date_length = 0;
int num_files = 0;
unsigned long blksz = 0;
unsigned int grpsz = 0;
unsigned int bufcnt = 0;
unsigned int num_vols = 0;
unsigned int backup_size = 0;
if (!tflag) {
// No verbose mode requested.
return;
}
/* Check the header word - this should be a saveset summary record. */
if (buffer[0] != 1 || buffer[1] != 1) {
printf ("Cannot print summary; invalid data header\n");
return;
}
// Skip over the first two bytes which contain the record type.
attr_ptr = 2;
while (attr_ptr < rsize) {
// Get the size of the attribute value.
dsize = getu16 (((struct bsa *)&buffer[attr_ptr])->bsa_dol_w_size);
// Get the attribute type.
type = getu16 (((struct bsa *)&buffer[attr_ptr])->bsa_dol_w_type);
// Get the attribute value.
text = ((struct bsa *)&buffer[attr_ptr])->bsa_dol_t_text;
if ( debugflags & D_SUM ) {
fprintf (stderr, "\n--process_summary debug_dump\n");
debug_dump(text, dsize, type);
fprintf (stderr, "--Processing summary record %d type = %d size = %d\n",
attr_ptr, type, dsize);
}
if ( !dsize ) {
if ( debugflags & D_SUM ) {
fprintf (stderr, "\nnull dsize; slamming the record type code.\n");
}
type = 0;
}
switch (type) {
case 0:
/* This seems to be used for padding at the end
of the summary.
*/
//goto end_of_summary;
break;
case BSA_K_SSNAME:
// Store saveset name and its length.
saveset = (char *)text;
saveset_size = dsize;
break;
case BSA_K_COMMAND:
// Store the backup command line.
command = (char *)text;
command_size = dsize;
break;
case BSA_K_COMMENT:
// Store whatever the user included as a comment and its length.
comment = (char *)text;
comment_size = dsize;
break;
case BSA_K_USERNAME:
// Store the name of the user who created the backup.
written_by = (char *)text;
written_by_size = dsize;
break;
case BSA_K_USERUIC:
// Store the user's UIC.
if (dsize == 4) {
usr = getu16 (text);
grp = getu16 (text + 2);
}
break;
case BSA_K_DATE:
// Store the date the backup was made.
text = ((struct bsa *)&buffer[attr_ptr])->bsa_dol_t_text;
time_vms_to_unix_asc( text, dsize, date, &date_length );
break;
case BSA_K_OPSYS:
// Store the operating system name.
if (dsize == 2) {
unsigned short oscode;
oscode = getu16 (text);
// Convert the OS code name.
switch(oscode) {
case BACKUP_K_OPSYS_IA64:
os = "OpenVMS I64";
break;
case BACKUP_K_OPSYS_ALPHA:
os = "OpenVMS Alpha";
break;
case BACKUP_K_OPSYS_VAX:
os = "OpenVMS VAX";
break;
default:
if ( debugflags & D_SUM ) {
fprintf(stderr, "Unknown OS Code = %d\n", oscode );
}
os = "Unknown OS Code";
break;
}
}
break;
case BSA_K_SYSVER:
// Store the operating system version.
osversion = (char *)text;
osversion_size = dsize;
break;
case BSA_K_NODENAME:
// Store the node name the backup was run on.
nodename = (char *)text;
nodename_size = dsize;
break;
case BSA_K_SIR:
// Store the CPU systems ID register.
if (dsize >= 4) {
id = getu32 (text);
}
break;
case BSA_K_DRIVEID:
// Store the name of the drive used for the backup.
written_on = (char *)text;
written_on_size = dsize;
break;
case BSA_K_BACKVER:
// Store the backup utility's version number.
backup_version = (char *)text;
backup_version_size = dsize;
break;
case BSA_K_BLOCKSIZE:
// Store the block size of the saveset.
if (dsize >= 4) {
blksz = getu32 (text);
}
break;
case BSA_K_XORSIZE:
// Store the size of each XOR group.
if (dsize >= 2) {
grpsz = getu16 (text);
}
break;
case BSA_K_BUFFERS:
// Store the number of buffers used.
if (dsize >= 2) {
bufcnt = getu16 (text);
}
break;
case BSA_K_VOLSETNAM:
// Store the volume set name.
vol_set_name = (char *)text;
vol_set_name_size = dsize;
if (debugflags & D_SUM_X) {
fprintf(stderr, "BSA$K_VOLSETNAM: %s dsize = %d\n",
vol_set_name, dsize);
}
break;
case BSA_K_NVOLS:
// Get the number of volumes in the save set.
if (dsize >= 2) {
num_vols = getu16 (text);
}
if (debugflags & D_SUM_X) {
fprintf(stderr, "BSA$K_NVOLS: %d dsize = %d\n", num_vols, dsize);
}