31d7d7e5ff905e2d2318688da0fbc0e66210b182
[debian/amanda] / device-src / tape-xenix.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 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 #include "glib-util.h"
29
30 /* Uncomment to test compilation on non-XENIX systems. */
31 /* --- 
32 #undef MTIOCTOP
33 #define MT_REWIND 0
34 #define MT_STATUS 0
35 #define T_RFM 0
36 #define T_WFM 0
37 struct tape_info {};
38   --- */
39
40 gboolean tape_rewind(int fd) {
41     return 0 == ioctl(fd, MT_REWIND);
42 }
43
44 gboolean tape_fsf(int fd, guint count) {
45     while (count-- > 0) {
46         if (0 != ioctl(fd, T_RFM))
47             return FALSE;
48     }
49     return TRUE;
50 }
51
52 gboolean tape_bsf(int fd G_GNUC_UNUSED, guint count G_GNUC_UNUSED) {
53     g_assert_not_reached();
54     return FALSE;
55 }
56
57 gboolean tape_fsr(int fd G_GNUC_UNUSED, guint count G_GNUC_UNUSED) {
58     g_assert_not_reached();
59     return FALSE;
60 }
61
62 gboolean tape_bsr(int fd G_GNUC_UNUSED, guint count G_GNUC_UNUSED) {
63     g_assert_not_reached();
64     return FALSE;
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     while (count-- > 0) {
74         if (0 != ioctl(fd, T_WFM))
75             return FALSE;
76     } 
77
78     return TRUE;
79 }
80
81 gboolean tape_setcompression(int fd G_GNUC_UNUSED, gboolean on G_GNUC_UNUSED) {
82     return FALSE;
83 }
84
85 DeviceStatusFlags tape_is_tape_device(int fd) {
86     struct tape_info result;
87     if (0 == ioctl(fd, MT_STATUS, &result)) {
88         return DEVICE_STATUS_SUCCESS;
89     } else {
90         return DEVICE_STATUS_DEVICE_ERROR;
91     }
92 }
93
94 DeviceStatusFlags tape_is_ready(int fd G_GNUC_UNUSED, TapeDevice *t_self G_GNUC_UNUSED) {
95     /* We can probably do better. */
96     return DEVICE_STATUS_SUCCESS;
97 }
98
99 void tape_device_detect_capabilities(TapeDevice * t_self) {
100     tape_device_set_capabilities(t_self,
101         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf*/
102         DEFAULT_FSF_AFTER_FILEMARK, PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf_after_filemark*/
103         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* bsf*/
104         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* fsr*/
105         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* bsr*/
106         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* eom*/
107         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* bsf_after_eom*/
108         2,     PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT  /* final_filemarks*/
109         );
110 }