Imported Upstream version 3.1.0
[debian/amanda] / device-src / tape-xenix.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 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_fileno(int fd) {
68     return TAPE_POSITION_UNKNOWN;
69 }
70
71 gint tape_eod(int fd G_GNUC_UNUSED) {
72     g_assert_not_reached();
73     return TAPE_OP_ERROR;
74 }
75
76 gboolean tape_weof(int fd, guint8 count) {
77     while (count-- > 0) {
78         if (0 != ioctl(fd, T_WFM))
79             return FALSE;
80     } 
81
82     return TRUE;
83 }
84
85 gboolean tape_setcompression(int fd G_GNUC_UNUSED, gboolean on G_GNUC_UNUSED) {
86     return FALSE;
87 }
88
89 gboolean tape_offl(int fd) {
90     /* return 0 == ioctl(fd, MT_OFFL); */
91     /* return 0 == ioctl(fd, T_UNLOAD); */
92     return TRUE;
93 }
94
95 DeviceStatusFlags tape_is_tape_device(int fd) {
96     struct tape_info result;
97     if (0 == ioctl(fd, MT_STATUS, &result)) {
98         return DEVICE_STATUS_SUCCESS;
99     } else {
100         return DEVICE_STATUS_DEVICE_ERROR;
101     }
102 }
103
104 DeviceStatusFlags tape_is_ready(int fd G_GNUC_UNUSED, TapeDevice *t_self G_GNUC_UNUSED) {
105     /* We can probably do better. */
106     return DEVICE_STATUS_SUCCESS;
107 }
108
109 void tape_device_detect_capabilities(TapeDevice * t_self) {
110     tape_device_set_capabilities(t_self,
111         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf*/
112         DEFAULT_FSF_AFTER_FILEMARK, PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf_after_filemark*/
113         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* bsf*/
114         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* fsr*/
115         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* bsr*/
116         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* eom*/
117         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* bsf_after_eom*/
118         2,     PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT  /* final_filemarks*/
119         );
120 }