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
|
/* fhandler_tape.cc. See fhandler.h for a description of the fhandler
classes.
Copyright 1999, 2000, 2001, 2002 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <sys/termios.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mtio.h>
#include "cygerrno.h"
#include "perprocess.h"
#include "security.h"
#include "fhandler.h"
#include "path.h"
#include "dtable.h"
#include "cygheap.h"
/**********************************************************************/
/* fhandler_dev_tape */
void
fhandler_dev_tape::clear (void)
{
lasterr = 0;
fhandler_dev_raw::clear ();
}
int
fhandler_dev_tape::is_eom (int win_error)
{
int ret = ((win_error == ERROR_END_OF_MEDIA)
|| (win_error == ERROR_EOM_OVERFLOW)
|| (win_error == ERROR_NO_DATA_DETECTED));
if (ret)
debug_printf ("end of medium");
return ret;
}
int
fhandler_dev_tape::is_eof (int win_error)
{
int ret = ((win_error == ERROR_FILEMARK_DETECTED)
|| (win_error == ERROR_SETMARK_DETECTED));
if (ret)
debug_printf ("end of file");
return ret;
}
fhandler_dev_tape::fhandler_dev_tape (int unit)
: fhandler_dev_raw (FH_TAPE, unit)
{
debug_printf ("unit: %d", unit);
}
int
fhandler_dev_tape::open (path_conv *real_path, int flags, mode_t)
{
int ret;
devbufsiz = 1L;
ret = fhandler_dev_raw::open (real_path, flags);
if (ret)
{
struct mtget get;
struct mtop op;
struct mtpos pos;
if (!ioctl (MTIOCGET, &get))
/* Tape drive supports and is set to variable block size. */
if (get.mt_dsreg == 0)
devbufsiz = get.mt_maxblksize;
else
devbufsiz = get.mt_dsreg;
varblkop = get.mt_dsreg == 0;
if (devbufsiz > 1L)
devbuf = new char [devbufsiz];
/* The following rewind in position 0 solves a problem which appears
* in case of multi volume archives: The last ReadFile on first medium
* returns ERROR_NO_DATA_DETECTED. After media change, all subsequent
* ReadFile calls return ERROR_NO_DATA_DETECTED, too.
* The call to tape_set_pos seems to reset some internal flags. */
if ((! ioctl (MTIOCPOS, &pos)) && (! pos.mt_blkno))
{
op.mt_op = MTREW;
ioctl (MTIOCTOP, &op);
}
if (flags & O_APPEND)
{
/* In append mode, seek to beginning of next filemark */
op.mt_op = MTFSFM;
op.mt_count = 1;
ioctl (MTIOCTOP, &op);
}
}
return ret;
}
int
fhandler_dev_tape::close (void)
{
struct mtop op;
int ret = 0;
if (is_writing)
{
ret = writebuf ();
if ((has_written) && (! eom_detected))
{
/* if last operation was writing, write a filemark */
debug_printf ("writing filemark\n");
op.mt_op = MTWEOF;
op.mt_count = 1;
ioctl (MTIOCTOP, &op);
}
}
// To protected reads on signaling (e.g. Ctrl-C)
eof_detected = 1;
if (is_rewind_device ())
{
debug_printf ("rewinding\n");
op.mt_op = MTREW;
ioctl (MTIOCTOP, &op);
}
if (ret)
{
fhandler_dev_raw::close ();
return ret;
}
return fhandler_dev_raw::close ();
}
int
fhandler_dev_tape::fstat (struct __stat64 *buf, path_conv *pc)
{
int ret;
if (!(ret = fhandler_base::fstat (buf, pc)))
{
struct mtget get;
if (!ioctl (MTIOCGET, &get))
buf->st_blocks = get.mt_capacity / buf->st_blksize;
}
return ret;
}
__off64_t
fhandler_dev_tape::lseek (__off64_t offset, int whence)
{
struct mtop op;
struct mtpos pos;
debug_printf ("lseek (%s, %d, %d)\n", get_name (), offset, whence);
writebuf ();
eom_detected = eof_detected = 0;
lastblk_to_read = 0;
devbufstart = devbufend = 0;
if (ioctl (MTIOCPOS, &pos))
{
return ILLEGAL_SEEK;
}
switch (whence)
{
case SEEK_END:
op.mt_op = MTFSF;
op.mt_count = 1;
if (ioctl (MTIOCTOP, &op))
return -1;
break;
case SEEK_SET:
if (whence == SEEK_SET && offset < 0)
{
set_errno (EINVAL);
return -1;
}
break;
case SEEK_CUR:
break;
default:
set_errno (EINVAL);
return -1;
}
op.mt_op = MTFSR;
op.mt_count = offset / devbufsiz
- (whence == SEEK_SET ? pos.mt_blkno : 0);
if (op.mt_count < 0)
{
op.mt_op = MTBSR;
op.mt_count = -op.mt_count;
}
if (ioctl (MTIOCTOP, &op) || ioctl (MTIOCPOS, &pos))
return -1;
return (pos.mt_blkno * devbufsiz);
}
int
fhandler_dev_tape::dup (fhandler_base *child)
{
fhandler_dev_tape *fhc = (fhandler_dev_tape *) child;
fhc->lasterr = lasterr;
return fhandler_dev_raw::dup (child);
}
int
fhandler_dev_tape::ioctl (unsigned int cmd, void *buf)
{
int ret = NO_ERROR;
unsigned long block;
if (cmd == MTIOCTOP)
{
struct mtop *op = (struct mtop *) buf;
if (! op)
ret = ERROR_INVALID_PARAMETER;
else
switch (op->mt_op)
{
case MTRESET:
break;
case MTFSF:
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, op->mt_count);
break;
case MTBSF:
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, -op->mt_count);
break;
case MTFSR:
ret = tape_set_pos (TAPE_SPACE_RELATIVE_BLOCKS, op->mt_count);
break;
case MTBSR:
ret = tape_set_pos (TAPE_SPACE_RELATIVE_BLOCKS, -op->mt_count);
break;
case MTWEOF:
if (tape_get_feature (TAPE_DRIVE_WRITE_FILEMARKS))
ret = tape_write_marks (TAPE_FILEMARKS, op->mt_count);
else if (tape_get_feature (TAPE_DRIVE_WRITE_LONG_FMKS))
ret = tape_write_marks (TAPE_LONG_FILEMARKS, op->mt_count);
else
ret = tape_write_marks (TAPE_SHORT_FILEMARKS, op->mt_count);
break;
case MTREW:
ret = tape_set_pos (TAPE_REWIND, 0);
break;
case MTOFFL:
ret = tape_prepare (TAPE_UNLOAD);
break;
case MTNOP:
break;
case MTRETEN:
if (! tape_get_feature (TAPE_DRIVE_END_OF_DATA))
ret = ERROR_INVALID_PARAMETER;
else if (! (ret = tape_set_pos (TAPE_REWIND, 0, FALSE)))
ret = tape_prepare (TAPE_TENSION);
break;
case MTBSFM:
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, -op->mt_count, TRUE);
break;
case MTFSFM:
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, op->mt_count, TRUE);
break;
case MTEOM:
if (tape_get_feature (TAPE_DRIVE_END_OF_DATA))
ret = tape_set_pos (TAPE_SPACE_END_OF_DATA, 0);
else
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, 32767);
break;
case MTERASE:
ret = tape_erase (TAPE_ERASE_SHORT);
break;
case MTRAS1:
case MTRAS2:
case MTRAS3:
ret = ERROR_INVALID_PARAMETER;
break;
case MTSETBLK:
{
long min, max;
if (! tape_get_feature (TAPE_DRIVE_SET_BLOCK_SIZE))
{
ret = ERROR_INVALID_PARAMETER;
break;
}
ret = tape_get_blocksize (&min, NULL, &max, NULL);
if (ret)
break;
if (devbuf && (size_t) op->mt_count == devbufsiz && !varblkop)
{
ret = 0;
break;
}
if ((op->mt_count == 0
&& !tape_get_feature (TAPE_DRIVE_VARIABLE_BLOCK))
|| (op->mt_count > 0
&& (op->mt_count < min || op->mt_count > max)))
{
ret = ERROR_INVALID_PARAMETER;
break;
}
if (devbuf && op->mt_count > 0
&& (size_t) op->mt_count < devbufend - devbufstart)
{
ret = ERROR_MORE_DATA;
break;
}
if (! (ret = tape_set_blocksize (op->mt_count)))
{
size_t size = 0;
if (op->mt_count == 0)
{
struct mtget get;
if ((ret = tape_status (&get)) != NO_ERROR)
break;
size = get.mt_maxblksize;
ret = NO_ERROR;
}
char *buf = NULL;
if (size > 1L && !(buf = new char [size]))
{
ret = ERROR_OUTOFMEMORY;
break;
}
if (devbufsiz > 1L && size > 1L)
{
memcpy(buf, devbuf + devbufstart,
devbufend - devbufstart);
devbufend -= devbufstart;
}
else
devbufend = 0;
if (devbufsiz > 1L)
delete [] devbuf;
devbufstart = 0;
devbuf = buf;
devbufsiz = size;
varblkop = op->mt_count == 0;
}
}
break;
case MTSETDENSITY:
ret = ERROR_INVALID_PARAMETER;
break;
case MTSEEK:
if (tape_get_feature (TAPE_DRIVE_ABSOLUTE_BLK))
{
ret = tape_set_pos (TAPE_ABSOLUTE_BLOCK, op->mt_count);
break;
}
if (! (ret = tape_get_pos (&block)))
{
ret = tape_set_pos (TAPE_SPACE_RELATIVE_BLOCKS,
op->mt_count - block);
}
break;
case MTTELL:
if (! (ret = tape_get_pos (&block)))
op->mt_count = block;
break;
case MTSETDRVBUFFER:
ret = ERROR_INVALID_PARAMETER;
break;
case MTFSS:
ret = tape_set_pos (TAPE_SPACE_SETMARKS, op->mt_count);
break;
case MTBSS:
ret = tape_set_pos (TAPE_SPACE_SETMARKS, -op->mt_count);
break;
case MTWSM:
ret = tape_write_marks (TAPE_SETMARKS, op->mt_count);
break;
case MTLOCK:
ret = tape_prepare (TAPE_LOCK);
break;
case MTUNLOCK:
ret = tape_prepare (TAPE_UNLOCK);
break;
case MTLOAD:
ret = tape_prepare (TAPE_LOAD);
break;
case MTUNLOAD:
ret = tape_prepare (TAPE_UNLOAD);
break;
case MTCOMPRESSION:
ret = tape_compression (op->mt_count);
break;
case MTSETPART:
case MTMKPART:
default:
ret = ERROR_INVALID_PARAMETER;
break;
}
}
else if (cmd == MTIOCGET)
ret = tape_status ((struct mtget *) buf);
else if (cmd == MTIOCPOS)
{
ret = ERROR_INVALID_PARAMETER;
if (buf && (ret = tape_get_pos (&block)))
((struct mtpos *) buf)->mt_blkno = block;
}
else
return fhandler_dev_raw::ioctl (cmd, buf);
if (ret != NO_ERROR)
{
SetLastError (ret);
__seterrno ();
return -1;
}
return 0;
}
/* ------------------------------------------------------------------ */
/* Private functions used by `ioctl' */
/* ------------------------------------------------------------------ */
static int
tape_error (DWORD lasterr, const char *txt)
{
if (lasterr)
debug_printf ("%s: error: %d\n", txt, lasterr);
return lasterr;
}
int
fhandler_dev_tape::tape_write_marks (int marktype, DWORD len)
{
syscall_printf ("write_tapemark\n");
while (((lasterr = WriteTapemark (get_handle (),
marktype,
len,
FALSE)) == ERROR_MEDIA_CHANGED)
|| (lasterr == ERROR_BUS_RESET))
;
return tape_error (lasterr, "tape_write_marks");
}
int
fhandler_dev_tape::tape_get_pos (unsigned long *ret)
{
DWORD part, low, high;
while (((lasterr = GetTapePosition (get_handle (),
TAPE_ABSOLUTE_POSITION,
&part,
&low,
&high)) == ERROR_MEDIA_CHANGED)
|| (lasterr == ERROR_BUS_RESET))
;
if (! tape_error (lasterr, "tape_get_pos") && ret)
*ret = low;
return lasterr;
}
static int _tape_set_pos (HANDLE hTape, int mode, long count)
{
int err;
while (((err = SetTapePosition (hTape,
mode,
1,
count,
count < 0 ? -1 : 0,
FALSE)) == ERROR_MEDIA_CHANGED)
|| (err == ERROR_BUS_RESET))
;
return err;
}
int
fhandler_dev_tape::tape_set_pos (int mode, long count, BOOLEAN sfm_func)
{
unsigned long pos, tgtpos;
switch (mode)
{
case TAPE_SPACE_RELATIVE_BLOCKS:
lasterr = tape_get_pos (&pos);
if (lasterr)
return lasterr;
tgtpos = pos + count;
while (((lasterr = _tape_set_pos (get_handle (),
mode,
count)) == ERROR_FILEMARK_DETECTED)
|| (lasterr == ERROR_SETMARK_DETECTED))
{
lasterr = tape_get_pos (&pos);
if (lasterr)
return lasterr;
count = tgtpos - pos;
}
if (lasterr == ERROR_BEGINNING_OF_MEDIA && ! tgtpos)
lasterr = NO_ERROR;
break;
case TAPE_SPACE_FILEMARKS:
if (count < 0)
{
if (pos > 0)
{
if ((! _tape_set_pos (get_handle (),
TAPE_SPACE_RELATIVE_BLOCKS,
-1))
|| (sfm_func))
++count;
_tape_set_pos (get_handle (), TAPE_SPACE_RELATIVE_BLOCKS, 1);
}
while (! (lasterr = _tape_set_pos (get_handle (), mode, -1))
&& count++ < 0)
;
if (lasterr == ERROR_BEGINNING_OF_MEDIA)
{
if (! count)
lasterr = NO_ERROR;
}
else if (! sfm_func)
lasterr = _tape_set_pos (get_handle (), mode, 1);
}
else
{
if (sfm_func)
{
if (_tape_set_pos (get_handle (),
TAPE_SPACE_RELATIVE_BLOCKS,
1) == ERROR_FILEMARK_DETECTED)
++count;
_tape_set_pos (get_handle (), TAPE_SPACE_RELATIVE_BLOCKS, -1);
}
if (! (lasterr = _tape_set_pos (get_handle (), mode, count))
&& sfm_func)
lasterr = _tape_set_pos (get_handle (), mode, -1);
}
break;
case TAPE_SPACE_SETMARKS:
case TAPE_ABSOLUTE_BLOCK:
case TAPE_SPACE_END_OF_DATA:
case TAPE_REWIND:
lasterr = _tape_set_pos (get_handle (), mode, count);
break;
}
return tape_error (lasterr, "tape_set_pos");
}
int
fhandler_dev_tape::tape_erase (int mode)
{
DWORD varlen;
TAPE_GET_DRIVE_PARAMETERS dp;
while (((lasterr = GetTapeParameters (get_handle (),
GET_TAPE_DRIVE_INFORMATION,
(varlen = sizeof dp, &varlen),
&dp)) == ERROR_MEDIA_CHANGED)
|| (lasterr == ERROR_BUS_RESET))
;
switch (mode)
{
case TAPE_ERASE_SHORT:
if (! lasterr && ! (dp.FeaturesLow & TAPE_DRIVE_ERASE_SHORT))
mode = TAPE_ERASE_LONG;
break;
case TAPE_ERASE_LONG:
if (! lasterr && ! (dp.FeaturesLow & TAPE_DRIVE_ERASE_LONG))
mode = TAPE_ERASE_SHORT;
break;
}
return tape_error (EraseTape (get_handle (), mode, FALSE), "tape_erase");
}
int
fhandler_dev_tape::tape_prepare (int action)
{
while (((lasterr = PrepareTape (get_handle (),
action,
FALSE)) == ERROR_MEDIA_CHANGED)
|| (lasterr == ERROR_BUS_RESET))
;
return tape_error (lasterr, "tape_prepare");
}
BOOLEAN
fhandler_dev_tape::tape_get_feature (DWORD parm)
{
DWORD varlen;
TAPE_GET_DRIVE_PARAMETERS dp;
while (((lasterr = GetTapeParameters (get_handle (),
GET_TAPE_DRIVE_INFORMATION,
(varlen = sizeof dp, &varlen),
&dp)) == ERROR_MEDIA_CHANGED)
|| (lasterr == ERROR_BUS_RESET))
;
if (lasterr)
return FALSE;
return ((parm & TAPE_DRIVE_HIGH_FEATURES)
? ((dp.FeaturesHigh & parm) != 0)
: ((dp.FeaturesLow & parm) != 0));
}
int
fhandler_dev_tape::tape_get_blocksize (long *min, long *def, long *max, long *cur)
{
DWORD varlen;
TAPE_GET_DRIVE_PARAMETERS dp;
TAPE_GET_MEDIA_PARAMETERS mp;
while (((lasterr = GetTapeParameters (get_handle (),
GET_TAPE_DRIVE_INFORMATION,
(varlen = sizeof dp, &varlen),
&dp)) == ERROR_MEDIA_CHANGED)
|| (lasterr == ERROR_BUS_RESET))
;
if (lasterr)
return tape_error (lasterr, "tape_get_blocksize");
while (((lasterr = GetTapeParameters (get_handle (),
GET_TAPE_MEDIA_INFORMATION,
(varlen = sizeof dp, &varlen),
&mp)) == ERROR_MEDIA_CHANGED)
|| (lasterr == ERROR_BUS_RESET))
;
if (lasterr)
return tape_error (lasterr, "tape_get_blocksize");
if (min)
*min = (long) dp.MinimumBlockSize;
if (def)
*def = (long) dp.DefaultBlockSize;
if (max)
*max = (long) dp.MaximumBlockSize;
if (cur)
*cur = (long) mp.BlockSize;
return tape_error (lasterr, "tape_get_blocksize");
}
int
fhandler_dev_tape::tape_set_blocksize (long count)
{
long min, max;
TAPE_SET_MEDIA_PARAMETERS mp;
lasterr = tape_get_blocksize (&min, NULL, &max, NULL);
if (lasterr)
return lasterr;
if (count != 0 && (count < min || count > max))
return tape_error (ERROR_INVALID_PARAMETER, "tape_set_blocksize");
mp.BlockSize = count;
return tape_error (SetTapeParameters (get_handle (),
SET_TAPE_MEDIA_INFORMATION,
&mp),
"tape_set_blocksize");
}
static long long
get_ll (PLARGE_INTEGER i)
{
long long l = 0;
l = i->HighPart;
l <<= 32;
l |= i->LowPart;
return l;
}
int
fhandler_dev_tape::tape_status (struct mtget *get)
{
DWORD varlen;
TAPE_GET_DRIVE_PARAMETERS dp;
TAPE_GET_MEDIA_PARAMETERS mp;
int notape = 0;
if (! get)
return ERROR_INVALID_PARAMETER;
while (((lasterr = GetTapeParameters (get_handle (),
GET_TAPE_DRIVE_INFORMATION,
(varlen = sizeof dp, &varlen),
&dp)) == ERROR_MEDIA_CHANGED)
|| (lasterr == ERROR_BUS_RESET))
;
/* Setting varlen to sizeof DP is by intention, actually! Never set
it to sizeof MP which seems to be more correct but results in a
ERROR_MORE_DATA error at least on W2K. */
if ((lasterr) || (lasterr = GetTapeParameters (get_handle (),
GET_TAPE_MEDIA_INFORMATION,
(varlen = sizeof dp, &varlen),
&mp)))
notape = 1;
memset (get, 0, sizeof *get);
get->mt_type = MT_ISUNKNOWN;
if (! notape && (dp.FeaturesLow & TAPE_DRIVE_TAPE_REMAINING))
{
get->mt_remaining = get_ll (&mp.Remaining);
get->mt_resid = get->mt_remaining >> 10;
}
if ((dp.FeaturesHigh & TAPE_DRIVE_SET_BLOCK_SIZE) && ! notape)
get->mt_dsreg = mp.BlockSize;
else
get->mt_dsreg = dp.DefaultBlockSize;
if (notape)
get->mt_gstat |= GMT_DR_OPEN (-1);
if (! notape)
{
if (dp.FeaturesLow & TAPE_DRIVE_GET_ABSOLUTE_BLK)
tape_get_pos ((unsigned long *) &get->mt_blkno);
if (! get->mt_blkno)
get->mt_gstat |= GMT_BOT (-1);
get->mt_gstat |= GMT_ONLINE (-1);
if ((dp.FeaturesLow & TAPE_DRIVE_WRITE_PROTECT) && mp.WriteProtected)
get->mt_gstat |= GMT_WR_PROT (-1);
if (dp.FeaturesLow & TAPE_DRIVE_TAPE_CAPACITY)
get->mt_capacity = get_ll (&mp.Capacity);
}
if ((dp.FeaturesLow & TAPE_DRIVE_COMPRESSION) && dp.Compression)
get->mt_gstat |= GMT_HW_COMP (-1);
if ((dp.FeaturesLow & TAPE_DRIVE_ECC) && dp.ECC)
get->mt_gstat |= GMT_HW_ECC (-1);
if ((dp.FeaturesLow & TAPE_DRIVE_PADDING) && dp.DataPadding)
get->mt_gstat |= GMT_PADDING (-1);
if ((dp.FeaturesLow & TAPE_DRIVE_REPORT_SMKS) && dp.ReportSetmarks)
get->mt_gstat |= GMT_IM_REP_EN (-1);
get->mt_erreg = lasterr;
get->mt_minblksize = dp.MinimumBlockSize;
get->mt_maxblksize = dp.MaximumBlockSize;
get->mt_defblksize = dp.DefaultBlockSize;
get->mt_featureslow = dp.FeaturesLow;
get->mt_featureshigh = dp.FeaturesHigh;
get->mt_eotwarningzonesize = dp.EOTWarningZoneSize;
return 0;
}
int
fhandler_dev_tape::tape_compression (long count)
{
DWORD varlen;
TAPE_GET_DRIVE_PARAMETERS dpg;
TAPE_SET_DRIVE_PARAMETERS dps;
while (((lasterr = GetTapeParameters (get_handle (),
GET_TAPE_DRIVE_INFORMATION,
(varlen = sizeof dpg, &varlen),
&dpg)) == ERROR_MEDIA_CHANGED)
|| (lasterr == ERROR_BUS_RESET))
;
if (lasterr)
return tape_error (lasterr, "tape_compression");
if (! (dpg.FeaturesLow & TAPE_DRIVE_COMPRESSION))
return ERROR_INVALID_PARAMETER;
if (count)
{
dps.ECC = dpg.ECC;
dps.Compression = count ? TRUE : FALSE;
dps.DataPadding = dpg.DataPadding;
dps.ReportSetmarks = dpg.ReportSetmarks;
dps.EOTWarningZoneSize = dpg.EOTWarningZoneSize;
lasterr = SetTapeParameters (get_handle (),
SET_TAPE_DRIVE_INFORMATION,
&dps);
if (lasterr)
return tape_error (lasterr, "tape_compression");
dpg.Compression = dps.Compression;
}
return 0;
}
|