Imported Upstream version 2.6.0p2
[debian/amanda] / device-src / tape-xenix.c
1 /*
2  * Copyright (c) 2005 Zmanda, Inc.  All Rights Reserved.
3  * 
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2.1 as 
6  * published by the Free Software Foundation.
7  * 
8  * This library 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 Lesser General Public
11  * License for more details.
12  * 
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
16  * 
17  * Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 /* Tape operations for XENIX systems. Most of this stuff is based on
22    documentation from
23    http://www.ifthenfi.nl:8080/cgi-bin/ssl_getmanpage?tape+HW+XNX234+tape
24 */
25
26 #include <amanda.h>
27 #include <tape-ops.h>
28
29 /* Uncomment to test compilation on non-XENIX systems. */
30 /* --- 
31 #undef MTIOCTOP
32 #define MT_REWIND 0
33 #define MT_STATUS 0
34 #define T_RFM 0
35 #define T_WFM 0
36 struct tape_info {};
37   --- */
38
39 gboolean tape_rewind(int fd) {
40     return 0 == ioctl(fd, MT_REWIND);
41 }
42
43 gboolean tape_fsf(int fd, guint count) {
44     while (--count >= 0) {
45         if (0 != ioctl(fd, T_RFM))
46             return FALSE;
47     }
48     return TRUE;
49 }
50
51 gboolean tape_bsf(int fd, guint count) {
52     g_assert_not_reached();
53     return FALSE;
54 }
55
56 gboolean tape_fsr(int fd, guint count) {
57     g_assert_not_reached();
58     return FALSE;
59 }
60
61 gboolean tape_bsr(int fd, guint count) {
62     g_assert_not_reached();
63     return FALSE;
64 }
65
66 gint tape_eod(int fd) {
67     g_assert_not_reached();
68     return TAPE_OP_ERROR;
69 }
70
71 gboolean tape_weof(int fd, guint8 count) {
72     while (count -- > 0) {
73         if (0 != ioctl(fd, T_WFM))
74             return FALSE;
75     } 
76
77     return TRUE;
78 }
79
80 gboolean tape_setcompression(int fd, gboolean on) {
81     return FALSE;
82 }
83
84 ReadLabelStatusFlags tape_is_tape_device(int fd) {
85     struct tape_info result;
86     if (0 == ioctl(fd, MT_STATUS, &result)) {
87         return READ_LABEL_STATUS_SUCCESS;
88     } else {
89         dbprintf("tape_is_tape_device: ioctl(MTIOCTOP/MTNOP) failed: %s",
90                  strerror(errno));
91         return READ_LABEL_STATUS_DEVICE_ERROR;
92     }
93 }
94
95 TapeCheckResult tape_is_ready(int fd) {
96     /* We can probably do better. */
97     return TAPE_CHECK_UNKNOWN;
98 }
99
100 void tape_device_discover_capabilities(TapeDevice * t_self) {
101     Device * self;
102     GValue val;
103
104     self = DEVICE(t_self);
105     g_return_if_fail(self != NULL);
106
107     bzero(&val, sizeof(val));
108     g_value_init(&val, FEATURE_SUPPORT_FLAGS_TYPE);
109
110     g_value_set_flags(&val,
111                       FEATURE_STATUS_ENABLED | FEATURE_SURETY_BAD |
112                       FEATURE_SOURCE_DEFAULT);
113     device_property_set(self, PROPERTY_FSF, &val);
114     
115     g_value_set_flags(&val,
116                       FEATURE_STATUS_DISABLED | FEATURE_SURETY_GOOD |
117                       FEATURE_SOURCE_DEFAULT);
118     device_property_set(self, PROPERTY_BSF, &val);
119     
120     g_value_set_flags(&val,
121                       FEATURE_STATUS_DISABLED | FEATURE_SURETY_GOOD |
122                       FEATURE_SOURCE_DEFAULT);
123     device_property_set(self, PROPERTY_FSR, &val);
124     
125     g_value_set_flags(&val,
126                       FEATURE_STATUS_DISABLED | FEATURE_SURETY_GOOD |
127                       FEATURE_SOURCE_DEFAULT);
128     device_property_set(self, PROPERTY_BSR, &val);
129     
130     g_value_set_flags(&val,
131                       FEATURE_STATUS_DISABLED | FEATURE_SURETY_GOOD |
132                       FEATURE_SOURCE_DEFAULT);
133     device_property_set(self, PROPERTY_EOM, &val);
134
135     g_value_unset_init(&val, G_TYPE_UINT);
136     g_value_set_uint(&val, 2);
137     device_property_set(self, PROPERTY_FINAL_FILEMARKS, &val);
138 }