]> 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 #endif
17
18 static int fd;
19 void print_pos()
20 {
21    struct mtget mt_get;
22    ioctl(fd, MTIOCGET, &mt_get);
23    printf("file:block %i:%i\n", mt_get.mt_fileno, mt_get.mt_blkno);
24 }
25
26 int main()
27 {
28    int r1, r2;
29    char c[200];
30    struct mtop mt_com;
31
32    fd  = open("/dev/lto2", O_CREAT | O_RDWR, 0700);
33
34    /* rewind */
35    mt_com.mt_count = 1;
36    mt_com.mt_op = MTREW;
37    r1 = ioctl(fd, MTIOCTOP, &mt_com);
38    printf("rewind\n");
39    print_pos();
40
41    /* write something */
42    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
43    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
44    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
45    printf("write something (3 writes)\n");
46    print_pos();
47
48    /* write EOF */
49    printf("WEOF\n");
50    mt_com.mt_op = MTWEOF;
51    mt_com.mt_count = 1;
52    r1 = ioctl(fd, MTIOCTOP, &mt_com);
53    print_pos();
54
55    /* write a second file */
56    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
57    printf("write something\n");
58    print_pos();
59
60    /* rewind */
61    mt_com.mt_count = 1;
62    mt_com.mt_op = MTREW;
63    r1 = ioctl(fd, MTIOCTOP, &mt_com);
64    printf("rewind\n");
65
66    /* read something with error */
67    errno=0;
68    r1 = read(fd, c, 2);
69    c[r1] = 0;
70    printf("read c=%s len=%i errno=%i\n", c, r1, errno);
71    perror("");
72    print_pos();
73
74    /* read something */
75    errno=0;
76    r1 = read(fd, c, 200);
77    c[r1] = 0;
78    printf("read c=%s len=%i\n", c, r1);
79    print_pos();
80
81    /* write something */
82    printf("write something\n");
83    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
84    print_pos();
85    
86    /* rewind */
87    mt_com.mt_count = 1;
88    mt_com.mt_op = MTREW;
89    r1 = ioctl(fd, MTIOCTOP, &mt_com);
90    r1 = read(fd, c, 200);
91    c[r1] = '\0';
92    printf("read c=%s len=%i\n", c, r1);
93    r1 = read(fd, c, 200);
94    c[r1] = '\0';
95    printf("read c=%s len=%i\n", c, r1);
96  
97    /* write EOF */
98    printf("WEOF\n");
99    mt_com.mt_op = MTWEOF;
100    mt_com.mt_count = 1;
101    r1 = ioctl(fd, MTIOCTOP, &mt_com);
102    print_pos();
103
104    /* FSF */
105    mt_com.mt_op = MTFSF;
106    mt_com.mt_count = 1;
107    r1 = ioctl(fd, MTIOCTOP, &mt_com);
108    printf("fsf r=%i\n", r1);
109    print_pos();
110
111    /* write something */
112    printf("write something\n");
113    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
114    print_pos();
115
116    /* FSF */
117    mt_com.mt_op = MTFSF;
118    mt_com.mt_count = 1;
119    r1 = ioctl(fd, MTIOCTOP, &mt_com);
120    printf("fsf r=%i\n", r1);
121    print_pos();
122
123    /* WEOF */
124    mt_com.mt_op = MTWEOF;
125    mt_com.mt_count = 3;
126    r1 = ioctl(fd, MTIOCTOP, &mt_com);
127    printf("weof 3 r=%i\n", r1);
128    print_pos();
129
130    /* rewind */
131    mt_com.mt_count = 1;
132    mt_com.mt_op = MTREW;
133    r1 = ioctl(fd, MTIOCTOP, &mt_com);
134    printf("rewind\n");
135    print_pos();
136
137    /* FSR */
138    mt_com.mt_op = MTFSR;
139    mt_com.mt_count = 10;
140    r1 = ioctl(fd, MTIOCTOP, &mt_com);
141    printf("fsr r=%i\n", r1);
142    print_pos();
143
144    /* eom */
145    mt_com.mt_count = 1;
146    mt_com.mt_op = MTEOM;
147    r1 = ioctl(fd, MTIOCTOP, &mt_com);
148    printf("goto eom\n");
149    print_pos();
150
151    /* write something */
152    printf("write something\n");
153    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
154    print_pos();
155
156    close(fd);
157    return(0);
158 }