59c5946b27ada2e9b59b1ff75f605772b8efd662
[debian/amanda] / device-src / tape-aix.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 #include <amanda.h>
22 #include "glib-util.h"
23 #include "tape-ops.h"
24
25 /* Tape operations for AIX systems. Most of this stuff is based on
26    documentation from 
27    http://publibn.boulder.ibm.com/doc_link/Ja_JP/a_doc_lib/files/aixfiles/rmt.htm */
28
29 /* Uncomment to test compilation on non-AIX systems. */
30 /* ---
31 #undef MTIOCTOP
32 #define STIOCTOP 0
33 #define stop mtop
34 #define st_op mt_op
35 #define st_count mt_count
36 #define STREW MTREW
37 #define STFSF MTFSF
38 #define STRSF MTBSF
39 #define STFSR MTFSR
40 #define STRSR MTBSR
41 #define STWEOF MTWEOF
42 #define STOFFL MTOFFL
43 --- */
44
45 gboolean tape_rewind(int fd) {
46     struct stop st;
47     st.st_op = STREW;
48     st.st_count = 1;
49     return 0 == ioctl(fd, STIOCTOP, &st);
50 }
51
52 gboolean tape_fsf(int fd, guint count) {
53     struct stop st;
54     st.st_op = STFSF;
55     st.st_count = count;
56     return 0 == ioctl(fd, STIOCTOP, &st);
57 }
58
59 gboolean tape_bsf(int fd, guint count) {
60     struct stop st;
61     st.st_op = STRSF;
62     st.st_count = count;
63     return 0 == ioctl(fd, STIOCTOP, &st);
64 }
65
66 gboolean tape_fsr(int fd, guint count) {
67     struct stop st;
68     st.st_op = STFSR;
69     st.st_count = count;
70     return 0 == ioctl(fd, STIOCTOP, &st);
71 }
72
73 gboolean tape_bsr(int fd, guint count) {
74     struct stop st;
75     st.st_op = STRSR;
76     st.st_count = count;
77     return 0 == ioctl(fd, STIOCTOP, &st);
78 }
79
80 gint tape_fileno(int fd) {
81     return TAPE_POSITION_UNKNOWN;
82 }
83
84 gint tape_eod(int fd G_GNUC_UNUSED) {
85     g_assert_not_reached();
86     return TAPE_OP_ERROR;
87 }
88
89 gboolean tape_weof(int fd, guint8 count) {
90     struct stop st;
91     st.st_op = STWEOF;
92     st.st_count = count;
93     return 0 == ioctl(fd, STIOCTOP, &st);
94 }
95
96 gboolean tape_setcompression(int fd G_GNUC_UNUSED, gboolean on G_GNUC_UNUSED) {
97     return FALSE;
98 }
99
100 gboolean tape_offl(int fd) {
101     struct stop st;
102     st.st_op = STOFFL;
103     st.st_count = 1;
104     return 0 == ioctl(fd, STIOCTOP, &st);
105 }
106
107 DeviceStatusFlags tape_is_tape_device(int fd G_GNUC_UNUSED) {
108     /* AIX doesn't have a no-op, so we'll just assume this is a tape device */
109     return DEVICE_STATUS_SUCCESS;
110 }
111
112 DeviceStatusFlags tape_is_ready(int fd G_GNUC_UNUSED, TapeDevice *t_self G_GNUC_UNUSED) {
113     return DEVICE_STATUS_SUCCESS;
114 }
115
116 void tape_device_detect_capabilities(TapeDevice * t_self) {
117     tape_device_set_capabilities(t_self,
118         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf*/
119         DEFAULT_FSF_AFTER_FILEMARK, PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsf_after_filemark*/
120         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* bsf*/
121         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* fsr*/
122         TRUE,  PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT, /* bsr*/
123         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* eom*/
124         FALSE, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DEFAULT, /* bsf_after_eom*/
125         2,     PROPERTY_SURETY_BAD,  PROPERTY_SOURCE_DEFAULT  /* final_filemarks*/
126         );
127 }