Imported Upstream version 3.1.0
[debian/amanda] / device-src / tape-uware.c
1 /*
2  * Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16  *
17  * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 /* Tape operations for SVR4 systems. Most of this stuff is based on
22    documentation from http://docsrv.sco.com/cgi-bin/man/man?sdi+7 */
23
24 #include <amanda.h>
25 #include <tape-ops.h>
26 #include "glib-util.h"
27
28 /* Uncomment to test on non-SYSV4 systems. */
29 /* ---
30 #undef MTIOCTOP
31 #define T_RWD 0
32 #define T_SFF 0
33 #define T_SFB 0
34 #define T_SBF 0
35 #define T_SBB 0
36 #define T_WRFILEM 0
37 #define T_RDBLKLEN 0
38 #define T_WRBLKLEN 0
39 #define T_SETCOMP 0
40 #define T_UNLOAD 0
41
42 struct blklen {
43     int min_blen, max_blen;
44 };
45
46  --- */
47
48 gboolean tape_rewind(int fd) {
49     return 0 == ioctl(fd, T_RWD);
50 }
51
52 gboolean tape_fsf(int fd, guint count) {
53     return 0 == ioctl(fd, T_SFF, count);
54 }
55
56 gboolean tape_bsf(int fd, guint count) {
57     return 0 == ioctl(fd, T_SFB, count);
58 }
59
60 gboolean tape_fsr(int fd, guint count) {
61     return 0 == ioctl(fd, T_SBF, count);
62 }
63
64 gboolean tape_bsr(int fd, guint count) {
65     return 0 == ioctl(fd, T_SBB, count);
66 }
67
68 gint tape_fileno(int fd) {
69     return TAPE_POSITION_UNKNOWN;
70 }
71
72 gint tape_eod(int fd G_GNUC_UNUSED) {
73     g_assert_not_reached();
74     return TAPE_OP_ERROR;
75 }
76
77 gboolean tape_weof(int fd, guint8 count) {
78     return 0 == ioctl(fd, T_WRFILEM, count);
79 }
80
81 gboolean tape_offl(int fd) {
82     return 0 == ioctl(fd, T_UNLOAD);
83 }
84
85 gboolean tape_setcompression(int fd, gboolean on) {
86     int cmd;
87     if (on) {
88         cmd = 3;
89     } else {
90         cmd = 2;
91     }
92
93     return 0 == ioctl(fd, T_SETCOMP, cmd);
94 }
95
96 DeviceStatusFlags tape_is_tape_device(int fd) {
97     /* If we can read block information, it's probably a tape device. */
98     struct blklen result;
99     if (0 == ioctl(fd, T_RDBLKLEN, &result)) {
100         return DEVICE_STATUS_SUCCESS;
101     } else {
102         return DEVICE_STATUS_DEVICE_ERROR;
103     }
104 }
105
106 DeviceStatusFlags tape_is_ready(int fd G_GNUC_UNUSED, TapeDevice *t_self G_GNUC_UNUSED) {
107     /* No good way to determine this, so assume it's ready */
108     return DEVICE_STATUS_SUCCESS;
109 }
110
111 void tape_device_detect_capabilities(TapeDevice * t_self) {
112     tape_device_set_capabilities(t_self,
113         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf*/
114         DEFAULT_FSF_AFTER_FILEMARK, PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf_after_filemark*/
115         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* bsf*/
116         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsr*/
117         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* bsr*/
118         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* eom*/
119         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* bsf_after_eom*/
120         2,     PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT  /* final_filemarks*/
121         );
122 }