52e11edc5acc7472d6f9ce0251d7ff76c05d0e39
[debian/amanda] / device-src / tape-uware.c
1 /*
2  * Copyright (c) 2005-2008 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., 465 S Mathlida Ave, Suite 300
18  * Sunnyvale, CA 94086, 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
41 struct blklen {
42     int min_blen, max_blen;
43 };
44
45  --- */
46
47 gboolean tape_rewind(int fd) {
48     return 0 == ioctl(fd, T_RWD);
49 }
50
51 gboolean tape_fsf(int fd, guint count) {
52     return 0 == ioctl(fd, T_SFF, count);
53 }
54
55 gboolean tape_bsf(int fd, guint count) {
56     return 0 == ioctl(fd, T_SFB, count);
57 }
58
59 gboolean tape_fsr(int fd, guint count) {
60     return 0 == ioctl(fd, T_SBF, count);
61 }
62
63 gboolean tape_bsr(int fd, guint count) {
64     return 0 == ioctl(fd, T_SBB, count);
65 }
66
67 gint tape_eod(int fd G_GNUC_UNUSED) {
68     g_assert_not_reached();
69     return TAPE_OP_ERROR;
70 }
71
72 gboolean tape_weof(int fd, guint8 count) {
73     return 0 == ioctl(fd, T_WRFILEM, count);
74 }
75
76 gboolean tape_setcompression(int fd, gboolean on) {
77     int cmd;
78     if (on) {
79         cmd = 3;
80     } else {
81         cmd = 2;
82     }
83
84     return 0 == ioctl(fd, T_SETCOMP, cmd);
85 }
86
87 DeviceStatusFlags tape_is_tape_device(int fd) {
88     /* If we can read block information, it's probably a tape device. */
89     struct blklen result;
90     if (0 == ioctl(fd, T_RDBLKLEN, &result)) {
91         return DEVICE_STATUS_SUCCESS;
92     } else {
93         return DEVICE_STATUS_DEVICE_ERROR;
94     }
95 }
96
97 DeviceStatusFlags tape_is_ready(int fd G_GNUC_UNUSED, TapeDevice *t_self G_GNUC_UNUSED) {
98     /* No good way to determine this, so assume it's ready */
99     return DEVICE_STATUS_SUCCESS;
100 }
101
102 void tape_device_detect_capabilities(TapeDevice * t_self) {
103     tape_device_set_capabilities(t_self,
104         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf*/
105         DEFAULT_FSF_AFTER_FILEMARK, PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf_after_filemark*/
106         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* bsf*/
107         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsr*/
108         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* bsr*/
109         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* eom*/
110         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* bsf_after_eom*/
111         2,     PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT  /* final_filemarks*/
112         );
113 }