summaryrefslogtreecommitdiffstats
path: root/private/utils/ntbackup/src/tfstuff.c
blob: a3ca63ec639eb8c1703148232a5a5274b184c999 (plain) (blame)
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
/**
Copyright(c) Conner Peripherals, Inc. 1993


     Name:          tfstuff.c

     Description:   This file contains functions formerly in tfgetnxt.c,
                    tfgtcfmt.c and tfgtcdev.c.

     $Log:   T:\logfiles\tfstuff.c_v  $

   Rev 1.3   17 Dec 1993 16:40:08   GREGG
Extended error reporting.

   Rev 1.2   30 Aug 1993 18:47:42   GREGG
Modified the way we control hardware compression from software to work around
a bug in Archive DAT DC firmware rev. 3.58 (we shipped a lot of them).
Files Modified: lw_data.c, lw_data.h, tfstuff.c, mtf10wdb.c, mtf10wt.c and
                drives.c

   Rev 1.1   23 Jun 1993 11:11:32   GREGG
Added cases I removed thinking they weren't needed in TF_GetNextTapeRequest.

   Rev 1.0   22 Jun 1993 18:26:18   GREGG
Combined tfgtcdev.c, tfgtcfmt.c and tfgetnxt.c, and added
TF_SetHWCompression.

**/

#include <memory.h>
#include "stdtypes.h"
#include "queues.h"
#include "drive.h"
#include "channel.h"
#include "lw_data.h"
#include "tfl_err.h"
#include "lwdefs.h"
#include "tflopen.h"
#include "lwprotos.h"
#include "tflproto.h"
#include "translat.h"
#include "retbuf.h"
#include "special.h"
#include "dilhwd.h"
#include "drvinf.h"
#include "generr.h"
#include "genfuncs.h"
#include "dil.h"
#include "be_debug.h"
#include "dddefs.h"


/**/
/**

     Name:          TF_GetCurrentDevice

     Description:   Gets the current device for the specified channel.

     Returns:       A THW ptr to the current hardware device.

     Notes:

**/

THW_PTR   TF_GetCurrentDevice( UINT16 channel_no )
{
     CHANNEL_PTR    channel = &lw_channels[channel_no] ;

     return( &channel->cur_drv->thw_inf ) ;
}


/**/
/**

     Name:          TF_GetTapeFormat

     Description:   Gets the current tape format desciptor for the specified.

     Returns:       An TFINF_PTR for the current format.

     Notes:

**/

TFINF_PTR TF_GetTapeFormat( UINT16 channel_no )
{
     CHANNEL_PTR    channel = &lw_channels[channel_no] ;

     return (channel->cur_fmt != UNKNOWN_FORMAT) ? ( &lw_fmtdescr[channel->cur_fmt] ) : NULL ;
}


/**/
/**

     Name:          TF_TapeFormatInfo

     Description:   Returns a pointer to the array of format descriptions.

     Returns:       A pointer to the first element, and the number of formats.

     Notes:

**/

TFINF_PTR TF_GetTapeFormatInfo( UINT16_PTR num_formats )
{
     if ( num_formats != NULL ) {
          *num_formats = lw_num_supported_fmts ;
     }

     return( &lw_fmtdescr[0] ) ;
}


/**/
/**
     Name:          TF_GetTapeFormatID

     Description:   Gets the current tape format ID for the specified channel.

     Returns:       TFGT_UNKNOWN_FORMAT if we don't know, else an ID.

     Notes:

**/

UINT16    TF_GetTapeFormatID( UINT16 channel_no )
{
     CHANNEL_PTR    channel = &lw_channels[channel_no] ;

     return (channel->cur_fmt != UNKNOWN_FORMAT)
          ? ( lw_fmtdescr[channel->cur_fmt].format_id )
          : TFGT_UNKNOWN_FORMAT ;
}


/**/
/**
     Name:          TF_GetTapeFormatFromID

     Description:   Gets the current tape format desciptor for the specified.

     Returns:       A TFINF_PTR for the specified format, or NULL.

     Notes:

**/

TFINF_PTR TF_GetTapeFormatFromID( UINT16 format_id )
{
     UINT16 format_index = FormatIndexFromID( format_id ) ;

     return ( format_index == UNKNOWN_FORMAT ) ? NULL : lw_fmtdescr + format_index ;
}


/**/
/**

     Name:          TF_GetNextTapeRequest

     Description:   Dispatches the loops IO request to the appropriate
                    handler.

     Returns:       A TFLE_xxx error code

     Notes:

**/

INT16 TF_GetNextTapeRequest( RR_PTR req )
{

     INT16         ret_val = TFLE_NO_ERR ;
     CHANNEL_PTR   channel = &lw_channels[req->channel] ;

     if( FatalError( channel ) ) {
          /* A fatal error has occurred. If they are calling us with any
             message other than an ABORT, fail the call. */
          if( req->lp_message != LRR_ABORT || req->lp_message != LRW_ABORT ) {
               BE_Zprintf( DEBUG_TAPE_FORMAT, RES_TF_GETNEXT_TAPE_REQUEST ) ;
               return( TFLE_NO_ERR ) ; /* can't happen... */
          } else {
               return( TFLE_NO_ERR ) ;
          }
     }

     switch( channel->mode ) {

     case TF_WRITE_CONTINUE:
     case TF_WRITE_OPERATION:
          ret_val = DoWrite( channel, req ) ;
          break ;

     case TF_READ_CONTINUE:
     case TF_READ_OPERATION:
     case TF_SCAN_CONTINUE:
     case TF_SCAN_OPERATION:
          /* Set up the correct filter */
          channel->loop_filter = req->filter_to_use ;
          ret_val = DoRead( channel, req ) ;
          break ;

     default:
          msassert( FALSE ) ;
          break ;
     }

     if( ret_val ) {
          BE_Zprintf( DEBUG_TAPE_FORMAT, RES_TF_GETNEXT_ERROR, ret_val  ) ;
          if ( ret_val != TFLE_USER_ABORT  &&  ret_val != TFLE_UNEXPECTED_EOS ) {
               SetChannelStatus( channel, CH_FATAL_ERR ) ;
          }
     }

     return( ret_val ) ;
}


/**/
/**

     Name:          TF_SetHWCompression

     Description:   This function used to make a TpSpecial Call to enable/
                    disable hardware compression.  Due to a firmware bug in
                    early Archive DAT DC drives, we have to keep the drive
                    in uncompressed mode until we actually start a compressed
                    backup, and set it back to uncompressed mode as soon as
                    we're done.  So we just set a tape format layer wide
                    global to indicate if the set is to be compressed.  This
                    is yet another violation of the multiple channel concept,
                    and will have to be addressed in a different manner if
                    we ever decide to allow multiple channels. 

     Returns:       A TFLE_xxx error code

     Notes:

**/

INT16 TF_SetHWCompression( THW_PTR thw, BOOLEAN enable )
{
     (void)thw ;

     lw_hw_comp = enable ;
     return( TFLE_NO_ERR ) ;
}


/**/
/**

     Name:          TF_GetLastDriveError

     Description:   This function calls the dil layer to get the function
                    id, gen_error and contents of the misc field of the
                    last function to report an error.

     Returns:       FALSE if there hasn't been an error since the last
                    time the function was called, or from the app start.
                    TRUE otherwise.

     Notes:

**/

BOOLEAN TF_GetLastDriveError(
     THW_PTR   thw,
     INT16_PTR gen_func,
     INT16_PTR gen_err,
     INT32_PTR gen_misc )
{
     RET_BUF   myret ;

     if( TpSpecial( ((DRIVE_PTR)thw)->drv_hdl, SS_GET_LAST_ERROR,
                    (UINT32)&myret ) == SUCCESS ) {

          *gen_func = myret.call_type ;
          *gen_err  = myret.gen_error ;
          *gen_misc = myret.misc ;
          return( TRUE ) ;
     }

     return( FALSE ) ;
}