]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/vtape_dev.h
Backport from BEE
[bacula/bacula] / bacula / src / stored / vtape_dev.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2008-2014 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from many
7    others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    Bacula® is a registered trademark of Kern Sibbald.
15 */
16 /*
17  * vtape.h - Emulate the Linux st (scsi tape) driver on file.
18  * for regression and bug hunting purpose
19  *
20  */
21
22 #ifndef VTAPE_H
23 #define VTAPE_H
24
25 #include <stdarg.h>
26 #include <stddef.h>
27 #include "bacula.h"
28 #include "tape_dev.h"
29
30 void vtape_debug(int level);
31
32 #ifdef USE_VTAPE
33
34 #define FTAPE_MAX_DRIVE 50
35
36 #define VTAPE_MAX_BLOCK 20*1024*2048;      /* 20GB */
37
38 typedef enum {
39    VT_READ_EOF,                 /* Need to read the entire EOF struct */
40    VT_SKIP_EOF                  /* Have already read the EOF byte */
41 } VT_READ_FM_MODE;
42
43 class vtape: public tape_dev {
44 private:
45    int         fd;              /* Our file descriptor */
46    int         lockfd;          /* File descriptor for the lock file */
47
48    boffset_t   file_block;      /* size */
49    boffset_t   max_block;
50
51    boffset_t   last_FM;         /* last file mark (last file) */
52    boffset_t   next_FM;         /* next file mark (next file) */
53    boffset_t   cur_FM;          /* current file mark */
54
55    bool        atEOF;           /* End of file */
56    bool        atEOT;           /* End of media */
57    bool        atEOD;           /* End of data */
58    bool        atBOT;           /* Begin of tape */
59    bool        online;          /* volume online */
60    bool        needEOF;         /* check if last operation need eof */
61
62    int32_t     last_file;       /* last file of the volume */
63    int32_t     current_file;    /* current position */
64    int32_t     current_block;   /* current position */
65    char *      lockfile;        /* Name of the lock file */
66
67    void destroy();
68    int truncate_file();
69    void check_eof() { if(needEOF) weof();};
70    void update_pos();
71    bool read_fm(VT_READ_FM_MODE readfirst);
72
73 public:
74    int fsf();
75    int fsr(int count);
76    int weof();
77    int bsf();
78    int bsr(int count);
79
80    vtape();
81    ~vtape();
82    int get_fd();
83    void dump();
84
85    int tape_op(struct mtop *mt_com);
86    int tape_get(struct mtget *mt_com);
87    int tape_pos(struct mtpos *mt_com);
88
89    /* DEVICE virtual interfaces that we redefine */
90    int d_close(int);
91    int d_open(const char *pathname, int flags);
92    int d_ioctl(int fd, ioctl_req_t request, char *op=NULL);
93    ssize_t d_read(int, void *buffer, size_t count);
94    ssize_t d_write(int, const void *buffer, size_t count);
95    bool offline();
96
97    boffset_t lseek(DCR *dcr, off_t offset, int whence) { return -1; }
98    boffset_t lseek(int fd, off_t offset, int whence)
99       { return ::lseek(fd, offset, whence); }
100 };
101
102
103 #else  /*!USE_VTAPE */
104
105 class vtape: public DEVICE {
106 public:
107    int d_open(const char *pathname, int flags) { return -1; }
108    ssize_t d_read(void *buffer, size_t count) { return -1; }
109    ssize_t d_write(const void *buffer, size_t count) { return -1; }
110    int d_close(int) { return -1; }
111    int d_ioctl(int fd, ioctl_req_t request, char *mt=NULL) { return -1; }
112    boffset_t lseek(DCR *dcr, off_t offset, int whence) { return -1; }
113 };
114
115 #endif  /* USE_VTAPE */
116
117 #endif /* !VTAPE_H */