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