]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/t.c
ebl update
[bacula/bacula] / bacula / patches / testing / t.c
1 #include <sys/mtio.h>
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <errno.h>
7
8 #ifndef FTAPE
9 #include "faketape.h"
10
11 #define write   faketape_write
12 #define open    faketape_open
13 #define read    faketape_read
14 #define close   faketape_close
15 #define ioctl   faketape_ioctl
16 #define debug(x) faketape_debug(x)
17 #else
18 #define debug(x) 
19 #endif
20
21 static int fd;
22 void print_pos()
23 {
24    struct mtget mt_get;
25    ioctl(fd, MTIOCGET, &mt_get);
26    printf("*** file:block %i:%i BOT=%u EOD=%u EOF=%u\n", 
27           mt_get.mt_fileno, mt_get.mt_blkno, 
28           GMT_BOT(mt_get.mt_gstat) != 0,
29           GMT_EOD(mt_get.mt_gstat) != 0,
30           GMT_EOF(mt_get.mt_gstat) != 0
31       );
32 }
33
34 int main(int argc, char **argv)
35 {
36    int r1;
37    char c[200];
38    struct mtop mt_com;
39    
40    if (argc > 1) {
41       debug(atoi(argv[1]));
42    }
43
44    fd  = open("/dev/lto2", O_CREAT | O_RDWR, 0700);
45    if (fd < 0) {
46       perror("Can't open fd");
47       exit(1);
48    }
49
50    print_pos();
51
52    /* rewind */
53    printf("\n*** rewind\n");
54    mt_com.mt_count = 1;
55    mt_com.mt_op = MTREW;
56    r1 = ioctl(fd, MTIOCTOP, &mt_com);
57    print_pos();
58
59    /* write something */
60    printf("\n*** write something (3 writes)\n");
61    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
62    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
63    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
64    print_pos();
65
66    /* write EOF */
67    printf("\n*** WEOF\n");
68    mt_com.mt_op = MTWEOF;
69    mt_com.mt_count = 1;
70    r1 = ioctl(fd, MTIOCTOP, &mt_com);
71    print_pos();
72
73    /* write a second file */
74    printf("\n*** write something\n");
75    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
76    print_pos();
77
78    /* rewind */
79    printf("\n*** rewind\n");
80    mt_com.mt_count = 1;
81    mt_com.mt_op = MTREW;
82    r1 = ioctl(fd, MTIOCTOP, &mt_com);
83
84    /* read something with error */
85    printf("\n*** read c=%s len=%i\n", c, r1);
86    errno=0;
87    r1 = read(fd, c, 2);
88    c[r1] = 0;
89    perror("");
90    print_pos();
91
92    /* read something */
93    printf("\n*** read c=%s len=%i\n", c, r1);
94    errno=0;
95    r1 = read(fd, c, 200);
96    c[r1] = 0;
97    print_pos();
98
99    /* write something */
100    printf("\n*** write something\n");
101    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
102    print_pos();
103    
104    /* rewind */
105    printf("\n*** rewind\n");
106    mt_com.mt_count = 1;
107    mt_com.mt_op = MTREW;
108    r1 = ioctl(fd, MTIOCTOP, &mt_com);
109    r1 = read(fd, c, 200);
110    c[r1] = '\0';
111    printf("\n*** read c=%s len=%i\n", c, r1);
112    r1 = read(fd, c, 200);
113    c[r1] = '\0';
114    printf("\n*** read c=%s len=%i\n", c, r1);
115  
116    /* write EOF */
117    printf("\n*** WEOF");
118    mt_com.mt_op = MTWEOF;
119    mt_com.mt_count = 1;
120    r1 = ioctl(fd, MTIOCTOP, &mt_com);
121    printf(" r=%i\n", r1);
122    print_pos();
123
124    /* FSF */
125    printf("\n*** fsf x1");
126    mt_com.mt_op = MTFSF;
127    mt_com.mt_count = 1;
128    r1 = ioctl(fd, MTIOCTOP, &mt_com);
129    printf(" r=%i\n", r1);
130    print_pos();
131
132    /* write something */
133    printf("\n*** write something\n");
134    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
135    print_pos();
136
137    /* FSF */
138    printf("\n*** fsf");
139    mt_com.mt_op = MTFSF;
140    mt_com.mt_count = 1;
141    r1 = ioctl(fd, MTIOCTOP, &mt_com);
142    printf(" r=%i\n", r1);
143    print_pos();
144
145    /* WEOF */
146    printf("\n*** weof 3");
147    mt_com.mt_op = MTWEOF;
148    mt_com.mt_count = 3;
149    r1 = ioctl(fd, MTIOCTOP, &mt_com);
150    printf(" r=%i\n", r1);
151    print_pos();
152
153    /* rewind */
154    printf("\n*** rewind\n");
155    mt_com.mt_count = 1;
156    mt_com.mt_op = MTREW;
157    r1 = ioctl(fd, MTIOCTOP, &mt_com);
158    print_pos();
159
160    /* FSR */
161    printf("\n*** fsr x10");
162    mt_com.mt_op = MTFSR;
163    mt_com.mt_count = 10;
164    r1 = ioctl(fd, MTIOCTOP, &mt_com);
165    printf(" r=%i\n", r1);
166    print_pos();
167
168    /* eom */
169    printf("\n*** goto eom");
170    mt_com.mt_count = 1;
171    mt_com.mt_op = MTEOM;
172    r1 = ioctl(fd, MTIOCTOP, &mt_com);
173    printf(" r=%i\n", r1);
174    print_pos();
175
176    /* fsr */
177    printf("\n*** fsr");
178    mt_com.mt_count = 1;
179    mt_com.mt_op = MTFSR;
180    r1 = ioctl(fd, MTIOCTOP, &mt_com);
181    printf(" r=%i\n", r1);
182    print_pos();
183
184    /* write something */
185    printf("\n*** write something\n");
186    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
187    print_pos();
188    
189    /* rewind */
190    printf("\n*** rewind");
191    mt_com.mt_count = 1;
192    mt_com.mt_op = MTREW;
193    r1 = ioctl(fd, MTIOCTOP, &mt_com);
194    printf(" r=%i\n", r1);
195
196    /* FSF */
197    printf("\n*** fsf x2");
198    mt_com.mt_op = MTFSF;
199    mt_com.mt_count = 2;
200    r1 = ioctl(fd, MTIOCTOP, &mt_com);
201    printf(" r=%i\n", r1);
202    print_pos();
203
204    printf("\n*** fsr");
205    mt_com.mt_op = MTFSR;
206    mt_com.mt_count = 1;
207    r1 = ioctl(fd, MTIOCTOP, &mt_com);
208    printf(" r=%i\n", r1);
209    print_pos();
210
211    /* write something */
212    printf("\n*** write something\n");
213    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
214    print_pos();
215
216    printf("\n*** bsf x2");
217    mt_com.mt_op = MTBSF;
218    mt_com.mt_count = 2;
219    r1 = ioctl(fd, MTIOCTOP, &mt_com);
220    printf(" r=%i\n", r1);
221    print_pos();
222
223    printf("\n*** bsf x10");
224    mt_com.mt_op = MTBSF;
225    mt_com.mt_count = 10;
226    r1 = ioctl(fd, MTIOCTOP, &mt_com);
227    printf(" r=%i\n", r1);
228    print_pos();
229
230    printf("\n*** eom");
231    mt_com.mt_op = MTEOM;
232    mt_com.mt_count = 1;
233    r1 = ioctl(fd, MTIOCTOP, &mt_com);
234    printf(" r=%i\n", r1);
235    print_pos();
236
237    printf("\n*** bsr x10");
238    mt_com.mt_op = MTBSR;
239    mt_com.mt_count = 10;
240    r1 = ioctl(fd, MTIOCTOP, &mt_com);
241    printf(" r=%i\n", r1);
242    print_pos();
243
244    printf("\n*** eom");
245    mt_com.mt_op = MTEOM;
246    mt_com.mt_count = 1;
247    r1 = ioctl(fd, MTIOCTOP, &mt_com);
248    printf(" r=%i\n", r1);
249    print_pos();
250    
251    printf("\n*** fsr");
252    mt_com.mt_op = MTFSR;
253    mt_com.mt_count = 1;
254    r1 = ioctl(fd, MTIOCTOP, &mt_com);
255    printf(" r=%i\n", r1);
256    print_pos();
257
258    close(fd);
259    return(0);
260 }