]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/faketape.h
ebl update
[bacula/bacula] / bacula / patches / testing / faketape.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation, which is
11    listed in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of John Walker.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * faketape.h - Emulate the Linux st (scsi tape) driver on file.
30  * for regression and bug hunting purpose
31  *
32  */
33
34 #ifndef FAKETAPE_H
35 #define FAKETAPE_H
36
37 #include <stdarg.h>
38 #include <stddef.h>
39 #include "bacula.h"
40
41 typedef struct
42 {
43    /* format infos */
44    int16_t     version;
45    int16_t     max_file_mark;
46    int16_t     block_size;
47    int32_t     block_max;
48 } FTAPE_FORMAT;
49
50 #define FTAPE_MAX_DRIVE 20
51
52 /* 
53  * Theses functions will replace open/read/write
54  */
55 int faketape_open(const char *pathname, int flags, int mode);
56 int faketape_read(int fd, void *buffer, unsigned int count);
57 int faketape_write(int fd, const void *buffer, unsigned int count);
58 int faketape_close(int fd);
59 int faketape_ioctl(int fd, unsigned long int request, ...);
60
61 class faketape {
62 private:
63    int         fd;              /* Our file descriptor */
64
65    int         cur_fd;          /* OS file descriptor (-1 if not open) */
66    off_t       size;            /* size */
67
68    bool        atEOF;           /* End of file */
69    bool        atEOT;           /* End of media */
70    bool        atEOD;           /* End of data */
71    bool        atBOT;           /* Begin of tape */
72    bool        online;          /* volume online */
73
74    POOLMEM     *volume;         /* volume name */
75    POOLMEM     *cur_info;       /* volume info */
76    POOLMEM     *cur_file;       /* current file name */
77
78    int16_t     last_file;       /* last file of the volume */
79    int16_t     current_file;    /* max 65000 files */
80    int32_t     current_block;   /* max 4G blocks of 1KB */
81    off_t       max_size;        /* max size of volume */
82
83    FTAPE_FORMAT tape_info;
84
85    void destroy();
86    int read_volinfo();               /* read current volume format */
87    int find_maxfile();
88    int open_file();
89    int delete_files(int startfile);
90    void check_file() { if (cur_fd == -1) open_file(); };
91    int offline();
92    int close_file();
93
94 public:
95    int fsf(int count);
96    int weof(int count);
97    int bsf(int count);
98
99    faketape();
100    ~faketape();
101
102    int get_fd();
103    void dump();
104    int open(const char *pathname, int flags, int mode);
105    int read(void *buffer, unsigned int count);
106    int write(const void *buffer, unsigned int count);
107    int close();
108
109    int tape_op(struct mtop *mt_com);
110    int tape_get(struct mtget *mt_com);
111    int tape_pos(struct mtpos *mt_com);
112 };
113
114 #endif /* !FAKETAPE_H */