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