]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/t.c
ebl update fake tape driver
[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    /* rewind */
49    mt_com.mt_count = 1;
50    mt_com.mt_op = MTREW;
51    r1 = ioctl(fd, MTIOCTOP, &mt_com);
52    printf("rewind\n");
53
54    /* read something with error */
55    errno=0;
56    r1 = read(fd, c, 2);
57    c[r1] = 0;
58    printf("read c=%s len=%i errno=%i\n", c, r1, errno);
59    perror("");
60    print_pos();
61
62    /* read something */
63    errno=0;
64    r1 = read(fd, c, 200);
65    c[r1] = 0;
66    printf("read c=%s len=%i\n", c, r1);
67    print_pos();
68
69    /* write something */
70    printf("write something\n");
71    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
72    print_pos();
73    
74    /* rewind */
75    mt_com.mt_count = 1;
76    mt_com.mt_op = MTREW;
77    r1 = ioctl(fd, MTIOCTOP, &mt_com);
78    r1 = read(fd, c, 200);
79    c[r1] = '\0';
80    printf("read c=%s len=%i\n", c, r1);
81    r1 = read(fd, c, 200);
82    c[r1] = '\0';
83    printf("read c=%s len=%i\n", c, r1);
84  
85    /* write EOF */
86    printf("WEOF\n");
87    mt_com.mt_op = MTWEOF;
88    mt_com.mt_count = 1;
89    r1 = ioctl(fd, MTIOCTOP, &mt_com);
90    print_pos();
91
92    /* FSF */
93    mt_com.mt_op = MTFSF;
94    mt_com.mt_count = 1;
95    r1 = ioctl(fd, MTIOCTOP, &mt_com);
96    printf("fsf r=%i\n", r1);
97    print_pos();
98
99    /* write something */
100    printf("write something\n");
101    write(fd, "abcdefghijklmnopqrstuvwyz", strlen("abcdefghijklmnopqrstuvwyz")+1);
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    /* WEOF */
112    mt_com.mt_op = MTWEOF;
113    mt_com.mt_count = 3;
114    r1 = ioctl(fd, MTIOCTOP, &mt_com);
115    printf("weof 3 r=%i\n", r1);
116    print_pos();
117
118    /* rewind */
119    mt_com.mt_count = 1;
120    mt_com.mt_op = MTREW;
121    r1 = ioctl(fd, MTIOCTOP, &mt_com);
122    printf("rewind\n");
123    print_pos();
124
125    /* FSR */
126    mt_com.mt_op = MTFSR;
127    mt_com.mt_count = 10;
128    r1 = ioctl(fd, MTIOCTOP, &mt_com);
129    printf("fsr r=%i\n", r1);
130    print_pos();
131
132    /* eom */
133    mt_com.mt_count = 1;
134    mt_com.mt_op = MTEOM;
135    r1 = ioctl(fd, MTIOCTOP, &mt_com);
136    printf("goto eom\n");
137    print_pos();
138    
139    close(fd);
140    return(0);
141 }