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