0b86761ec5c9c56ce925a12e77540030afc95289
[debian/amanda] / device-src / tape-uware.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 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
27 /* Uncomment to test on non-SYSV4 systems. */
28 /* ---
29 #undef MTIOCTOP
30 #define T_RWD 0
31 #define T_SFF 0
32 #define T_SFB 0
33 #define T_SBF 0
34 #define T_SBB 0
35 #define T_WRFILEM 0
36 #define T_RDBLKLEN 0
37 #define T_WRBLKLEN 0
38 #define T_SETCOMP 0
39
40 struct blklen {
41     int min_blen, max_blen;
42 };
43
44  --- */
45
46 gboolean tape_rewind(int fd) {
47     return 0 == ioctl(fd, T_RWD);
48 }
49
50 gboolean tape_fsf(int fd, guint count) {
51     return 0 == ioctl(fd, T_SFF, count);
52 }
53
54 gboolean tape_bsf(int fd, guint count) {
55     return 0 == ioctl(fd, T_SFB, count);
56 }
57
58 gboolean tape_fsr(int fd, guint count) {
59     return 0 == ioctl(fd, T_SBF, count);
60 }
61
62 gboolean tape_bsr(int fd, guint count) {
63     return 0 == ioctl(fd, T_SBB, count);
64 }
65
66 int 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     return 0 == ioctl(fd, T_WRFILEM, count);
73 }
74
75 gboolean tape_setcompression(int fd, gboolean on) {
76     int cmd;
77     if (on) {
78         cmd = 3;
79     } else {
80         cmd = 2;
81     }
82
83     return 0 == ioctl(fd, T_SETCOMP, cmd);
84 }
85
86 ReadLabelStatusFlags tape_is_tape_device(int fd) {
87     /* If we can read block information, it's probably a tape device. */
88     struct blklen result;
89     if (0 == ioctl(fd, T_RDBLKLEN, &result)) {
90         return READ_LABEL_STATUS_SUCCESS;
91     } else {
92         dbprintf("tape_is_tape_device: ioctl(MTIOCTOP/MTNOP) failed: %s",
93                  strerror(errno));
94         return READ_LABEL_STATUS_DEVICE_ERROR;
95     }
96 }
97
98 TapeCheckResult tape_is_tape_ready(int fd) {
99     return TAPE_CHECK_UNKNOWN;
100 }
101
102 void tape_device_discover_capabilities(TapeDevice * t_self) {
103     Device * self;
104     GValue val;
105
106     self = DEVICE(t_self);
107     g_return_if_fail(self != NULL);
108
109     bzero(&val, sizeof(val));
110     g_value_init(&val, FEATURE_SUPPORT_FLAGS_TYPE);
111
112     g_value_set_flags(&val,
113                       FEATURE_STATUS_ENABLED | FEATURE_SURETY_BAD |
114                       FEATURE_SOURCE_DEFAULT);
115     device_property_set(self, PROPERTY_FSF, &val);
116     
117     g_value_set_flags(&val,
118                       FEATURE_STATUS_ENABLED | FEATURE_SURETY_BAD |
119                       FEATURE_SOURCE_DEFAULT);
120     device_property_set(self, PROPERTY_BSF, &val);
121     
122     g_value_set_flags(&val,
123                       FEATURE_STATUS_ENABLED | FEATURE_SURETY_BAD |
124                       FEATURE_SOURCE_DEFAULT);
125     device_property_set(self, PROPERTY_FSR, &val);
126     
127     g_value_set_flags(&val,
128                       FEATURE_STATUS_ENABLED | FEATURE_SURETY_BAD |
129                       FEATURE_SOURCE_DEFAULT);
130     device_property_set(self, PROPERTY_BSR, &val);
131     
132     g_value_set_flags(&val,
133                       FEATURE_STATUS_DISABLED | FEATURE_SURETY_GOOD |
134                       FEATURE_SOURCE_DEFAULT);
135     device_property_set(self, PROPERTY_EOM, &val);
136
137     g_value_unset_init(&val, G_TYPE_UINT);
138     g_value_set_uint(&val, 2);
139     device_property_set(self, PROPERTY_FINAL_FILEMARKS, &val);
140 }