1
2
3
4
5
6
7
8
9
10
11 backup_preattach: bpa: proc ();
12
13
14
15
16
17 dcl ap pointer;
18 dcl al fixed bin (21);
19 dcl arg char (al) based (ap);
20 dcl (nargs, argno) fixed bin;
21 dcl code fixed bin (35);
22 dcl open_mode fixed bin;
23 dcl attach_desc char (512) varying;
24 dcl iocbp pointer;
25 dcl stream_name char (32);
26
27 dcl com_err_ entry options (variable);
28 dcl cu_$arg_count entry (fixed bin, fixed bin (35));
29 dcl cu_$arg_ptr entry (fixed bin, pointer, fixed bin (21), fixed bin (35));
30 dcl iox_$attach_name entry (char (*), pointer, char (*), pointer, fixed bin (35));
31 dcl iox_$open entry (pointer, fixed bin, bit (1) aligned, fixed bin (35));
32 dcl iox_$close entry (pointer, fixed bin (35));
33 dcl iox_$detach_iocb entry (pointer, fixed bin (35));
34 dcl iox_$destroy_iocb entry (pointer, fixed bin (35));
35 dcl unique_chars_ entry (bit (*)) returns (char (15));
36
37 dcl bk_ss_$data_iocb pointer external static;
38 dcl bk_ss_$preattached bit (1) aligned external static;
39
40 dcl (error_table_$badopt,
41 error_table_$noarg) fixed bin (35) external static;
42
43 dcl WHOAMI char (32) internal static options (constant) init ("backup_preattach");
44
45 dcl (addr, substr, null) builtin;
46
47
48
49 call cu_$arg_count (nargs, code);
50 if code ^= 0 then do;
51 call com_err_ (code, WHOAMI);
52 MAIN_RETURN: return;
53 end;
54
55 if nargs = 0 then do;
56 call com_err_ (error_table_$noarg, WHOAMI,
57 "^/Usage:^-^a open_mode attach_desc^/^2x(or)^-^a -detach",
58 WHOAMI, WHOAMI);
59 goto MAIN_RETURN;
60 end;
61
62 if nargs = 1 then do;
63 call cu_$arg_ptr (1, ap, al, (0));
64 if (arg = "-close") | (arg = "-detach") then do;
65 if bk_ss_$preattached = "0"b then do;
66 NOT_PREATTACHED: call com_err_ (0, WHOAMI, "Backup I/O is not preattached.");
67 goto MAIN_RETURN;
68 end;
69
70 bk_ss_$preattached = "0"b;
71 if bk_ss_$data_iocb = null () then
72 goto NOT_PREATTACHED;
73
74 call iox_$close (bk_ss_$data_iocb, (0));
75 call iox_$detach_iocb (bk_ss_$data_iocb, (0));
76 call iox_$destroy_iocb (bk_ss_$data_iocb, (0));
77 goto MAIN_RETURN;
78 end;
79
80 else do;
81 call com_err_ (0, WHOAMI, "Unknown control function ^a.", arg);
82 goto MAIN_RETURN;
83 end;
84 end;
85
86 call cu_$arg_ptr (1, ap, al, (0));
87
88 if bk_ss_$preattached then do;
89 ALREADY_PREATTACHED:
90 call com_err_ (0, WHOAMI, "Backup I/O is already preattached. Use ^a -detach first.", WHOAMI);
91 goto MAIN_RETURN;
92 end;
93
94 if arg = "input" then
95 open_mode = Stream_input;
96 else if arg = "output" then
97 open_mode = Stream_output;
98 else do;
99 call com_err_ (0, WHOAMI, "Invalid opening mode ^a. Must be either ""input"" or ""output"".", arg);
100 goto MAIN_RETURN;
101 end;
102
103 attach_desc = "";
104 do argno = 2 to nargs;
105 call cu_$arg_ptr (argno, ap, al, (0));
106 if length (attach_desc) > 0 then
107 attach_desc = attach_desc || " ";
108 attach_desc = attach_desc || arg;
109 end;
110
111 stream_name = "backup." || unique_chars_ (""b);
112
113 call iox_$attach_name (stream_name, iocbp, (attach_desc), codeptr (backup_preattach), code);
114 if code ^= 0 then do;
115 call com_err_ (code, WHOAMI, "Cannot attach stream.");
116 goto MAIN_RETURN;
117 end;
118
119 call iox_$open (iocbp, open_mode, "0"b, code);
120 if code ^= 0 then do;
121 call com_err_ (code, WHOAMI, "Cannot open stream.");
122 return;
123 end;
124
125 bk_ss_$preattached = "1"b;
126 bk_ss_$data_iocb = iocbp;
127
128 return;
129
130 %page;
131 %include iox_modes;
132
133 end backup_preattach;