2 ===================================================================
3 --- src/baconfig.h (révision 7044)
4 +++ src/baconfig.h (copie de travail)
6 #define tape_read win32_tape_read
7 #define tape_write win32_tape_write
8 #define tape_close win32_tape_close
9 -#define IS_TAPE(x) S_ISCHR(x)
15 #define OSDependentInit()
17 -#if defined(USE_FAKETAPE)
18 -# define tape_open faketape_open
19 -# define tape_ioctl faketape_ioctl
20 -# define tape_read faketape_read
21 -# define tape_write faketape_write
22 -# define tape_close faketape_close
23 -# define IS_TAPE(x) S_ISREG(x)
24 -#else /* UNIX && !FAKETAPE */
25 -# define tape_open ::open
26 -# define tape_ioctl ::ioctl
27 -# define tape_read ::read
28 -# define tape_write ::write
29 -# define tape_close ::close
30 -# define IS_TAPE(x) S_ISCHR(x)
32 +#define tape_open ::open
33 +#define tape_ioctl ::ioctl
34 +#define tape_read ::read
35 +#define tape_write ::write
36 +#define tape_close ::close
38 #endif /* HAVE_WIN32 */
40 Index: src/stored/stored_conf.c
41 ===================================================================
42 --- src/stored/stored_conf.c (révision 7044)
43 +++ src/stored/stored_conf.c (copie de travail)
48 + {"faketape", B_FAKETAPE_DEV},
52 Index: src/stored/dev.c
53 ===================================================================
54 --- src/stored/dev.c (révision 7044)
55 +++ src/stored/dev.c (copie de travail)
58 if (S_ISDIR(statp.st_mode)) {
59 device->dev_type = B_FILE_DEV;
60 - } else if (IS_TAPE(statp.st_mode)) { /* char device or fake tape */
61 + } else if (S_ISCHR(statp.st_mode)) {
62 device->dev_type = B_TAPE_DEV;
63 } else if (S_ISFIFO(statp.st_mode)) {
64 device->dev_type = B_FIFO_DEV;
66 + /* must set DeviceType = Faketape
67 + * in normal mode, autodetection is disabled
69 + } else if (S_ISREG(statp.st_mode)) {
70 + device->dev_type = B_FAKETAPE_DEV;
72 } else if (!(device->cap_bits & CAP_REQMOUNT)) {
73 Jmsg2(jcr, M_ERROR, 0, _("%s is an unknown device type. Must be tape or directory\n"
74 " or have RequiresMount=yes for DVD. st_mode=%x\n"),
76 dev->drive_index = device->drive_index;
77 dev->autoselect = device->autoselect;
78 dev->dev_type = device->dev_type;
79 + dev->init_backend();
80 if (dev->is_tape()) { /* No parts on tapes */
81 dev->max_part_size = 0;
87 +void DEVICE::init_backend()
91 + /* in this mode, force FAKETAPE driver */
92 + dev_type = (dev_type == B_TAPE_DEV)?B_FAKETAPE_DEV:dev_type;
95 + if (is_faketape()) {
96 + d_open = faketape_open;
97 + d_write = faketape_write;
98 + d_close = faketape_close;
99 + d_ioctl = faketape_ioctl;
100 + d_read = faketape_read;
101 + dev_type = B_TAPE_DEV; /* do exactly as real tape */
103 + } else if (is_tape()) {
104 + d_open = tape_open;
105 + d_write = tape_write;
106 + d_close = tape_close;
107 + d_ioctl = tape_ioctl;
108 + d_read = tape_read;
120 * Open the device with the operating system and
121 * initialize buffer pointers.
123 if (openmode == omode) {
133 Dmsg0(100, "Close fd for mode change.\n");
134 preserve = state & (ST_LABEL|ST_APPEND|ST_READ);
136 #if defined(HAVE_WIN32)
139 - if ((m_fd = tape_open(dev_name, mode)) < 0) {
140 + if ((m_fd = d_open(dev_name, mode)) < 0) {
145 /* If busy retry each second for max_open_wait seconds */
147 /* Try non-blocking open */
148 - m_fd = tape_open(dev_name, mode+O_NONBLOCK);
149 + m_fd = d_open(dev_name, mode+O_NONBLOCK);
153 @@ -391,10 +427,10 @@
154 mt_com.mt_op = MTREW;
156 /* rewind only if dev is a tape */
157 - if (is_tape() && (tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0)) {
158 + if (is_tape() && (d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0)) {
160 dev_errno = errno; /* set error status from rewind */
164 Dmsg2(100, "Rewind error on %s close: ERR=%s\n", print_name(),
165 be.bstrerror(dev_errno));
169 /* Got fd and rewind worked, so we must have medium in drive */
171 - m_fd = tape_open(dev_name, mode); /* open normally */
173 + m_fd = d_open(dev_name, mode); /* open normally */
179 Dmsg1(100, "open failed: %s", errmsg);
180 /* Use system close() */
185 part_size = filestat.st_size;
187 * retrying every 5 seconds.
189 for (i=max_rewind_wait; ; i -= 5) {
190 - if (tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) {
191 + if (d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) {
194 if (i == max_rewind_wait) {
198 int open_mode = openmode;
202 open(dcr, open_mode);
208 - if (tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) {
209 + if (d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) {
211 clrerror(mt_com.mt_op);
212 Dmsg1(50, "ioctl error: %s\n", be.bstrerror());
213 @@ -1031,7 +1067,7 @@
215 Pmsg0(-20,_(" Bacula status:"));
216 Pmsg2(-20,_(" file=%d block=%d\n"), dev->file, dev->block_num);
217 - if (tape_ioctl(dev->fd(), MTIOCGET, (char *)&mt_stat) < 0) {
218 + if (dev->d_ioctl(dev->fd(), MTIOCGET, (char *)&mt_stat) < 0) {
220 dev->dev_errno = errno;
221 Mmsg2(dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"),
222 @@ -1158,7 +1194,7 @@
224 mt_com.mt_op = MTLOAD;
226 - if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
227 + if (dev->d_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
229 dev->dev_errno = errno;
230 Mmsg2(dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"),
231 @@ -1189,7 +1225,7 @@
233 mt_com.mt_op = MTOFFL;
235 - if (tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) {
236 + if (d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) {
239 Mmsg2(errmsg, _("ioctl MTOFFL error on %s. ERR=%s.\n"),
240 @@ -1264,7 +1300,7 @@
242 mt_com.mt_op = MTFSF;
243 mt_com.mt_count = num;
244 - stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
245 + stat = d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
247 my_errno = errno; /* save errno */
248 } else if ((os_file=get_os_tape_file()) < 0) {
249 @@ -1345,7 +1381,7 @@
252 Dmsg0(100, "Doing MTFSF\n");
253 - stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
254 + stat = d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
255 if (stat < 0) { /* error => EOT */
258 @@ -1419,7 +1455,7 @@
260 mt_com.mt_op = MTBSF;
261 mt_com.mt_count = num;
262 - stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
263 + stat = d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
267 @@ -1459,7 +1495,7 @@
268 Dmsg1(100, "fsr %d\n", num);
269 mt_com.mt_op = MTFSR;
270 mt_com.mt_count = num;
271 - stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
272 + stat = d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
276 @@ -1518,7 +1554,7 @@
278 mt_com.mt_op = MTBSR;
279 mt_com.mt_count = num;
280 - stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
281 + stat = d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
285 @@ -1534,7 +1570,7 @@
287 mt_com.mt_op = MTLOCK;
289 - tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
290 + d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
294 @@ -1544,7 +1580,7 @@
296 mt_com.mt_op = MTUNLOCK;
298 - tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
299 + d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
303 @@ -1656,7 +1692,7 @@
305 mt_com.mt_op = MTWEOF;
306 mt_com.mt_count = num;
307 - stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
308 + stat = d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
312 @@ -1787,7 +1823,7 @@
313 /* Found on Solaris */
316 - tape_ioctl(m_fd, MTIOCLRERR);
317 + d_ioctl(m_fd, MTIOCLRERR);
318 Dmsg0(200, "Did MTIOCLRERR\n");
321 @@ -1800,7 +1836,7 @@
322 union mterrstat mt_errstat;
323 Dmsg2(200, "Doing MTIOCERRSTAT errno=%d ERR=%s\n", dev_errno,
324 be.bstrerror(dev_errno));
325 - tape_ioctl(m_fd, MTIOCERRSTAT, (char *)&mt_errstat);
326 + d_ioctl(m_fd, MTIOCERRSTAT, (char *)&mt_errstat);
330 @@ -1811,7 +1847,7 @@
331 mt_com.mt_op = MTCSE;
333 /* Clear any error condition on the tape */
334 - tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
335 + d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
336 Dmsg0(200, "Did MTCSE\n");
339 @@ -1848,10 +1884,8 @@
350 /* Clean up device packet so it can be reused */
351 @@ -2251,11 +2285,7 @@
355 - if (this->is_tape()) {
356 - read_len = tape_read(m_fd, buf, len);
358 - read_len = ::read(m_fd, buf, len);
360 + read_len = d_read(m_fd, buf, len);
362 last_tick = get_timer_count();
364 @@ -2276,11 +2306,7 @@
368 - if (this->is_tape()) {
369 - write_len = tape_write(m_fd, buf, len);
371 - write_len = ::write(m_fd, buf, len);
373 + write_len = d_write(m_fd, buf, len);
375 last_tick = get_timer_count();
377 @@ -2306,7 +2332,7 @@
378 struct mtget mt_stat;
380 if (has_cap(CAP_MTIOCGET) &&
381 - tape_ioctl(m_fd, MTIOCGET, (char *)&mt_stat) == 0) {
382 + d_ioctl(m_fd, MTIOCGET, (char *)&mt_stat) == 0) {
383 return mt_stat.mt_fileno;
386 @@ -2431,7 +2457,7 @@
387 mt_com.mt_op = MTSETBLK;
389 Dmsg0(100, "Set block size to zero\n");
390 - if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
391 + if (dev->d_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
392 dev->clrerror(MTSETBLK);
395 @@ -2447,7 +2473,7 @@
396 mt_com.mt_count |= MT_ST_FAST_MTEOM;
398 Dmsg0(100, "MTSETDRVBUFFER\n");
399 - if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
400 + if (dev->d_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
401 dev->clrerror(MTSETDRVBUFFER);
404 @@ -2461,13 +2487,13 @@
405 dev->min_block_size == 0) { /* variable block mode */
406 mt_com.mt_op = MTSETBSIZ;
408 - if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
409 + if (dev->d_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
410 dev->clrerror(MTSETBSIZ);
412 /* Get notified at logical end of tape */
413 mt_com.mt_op = MTEWARN;
415 - if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
416 + if (dev->d_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
417 dev->clrerror(MTEWARN);
420 @@ -2480,7 +2506,7 @@
421 dev->min_block_size == 0) { /* variable block mode */
422 mt_com.mt_op = MTSETBSIZ;
424 - if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
425 + if (dev->d_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
426 dev->clrerror(MTSETBSIZ);
429 @@ -2491,7 +2517,7 @@
433 - if (tape_ioctl(dev->fd(), MTIOCSETEOTMODEL, (caddr_t)&neof) < 0) {
434 + if (dev->d_ioctl(dev->fd(), MTIOCSETEOTMODEL, (caddr_t)&neof) < 0) {
436 dev->dev_errno = errno; /* save errno */
437 Mmsg2(dev->errmsg, _("Unable to set eotmodel on device %s: ERR=%s\n"),
438 @@ -2508,7 +2534,7 @@
439 dev->min_block_size == 0) { /* variable block mode */
440 mt_com.mt_op = MTSRSZ;
442 - if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
443 + if (dev->d_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) {
444 dev->clrerror(MTSRSZ);
447 @@ -2520,7 +2546,7 @@
449 Dmsg0(100, "dev_get_os_pos\n");
450 return dev->has_cap(CAP_MTIOCGET) &&
451 - tape_ioctl(dev->fd(), MTIOCGET, (char *)mt_stat) == 0 &&
452 + dev->d_ioctl(dev->fd(), MTIOCGET, (char *)mt_stat) == 0 &&
453 mt_stat->mt_fileno >= 0;
456 Index: src/stored/faketape.c
457 ===================================================================
458 --- src/stored/faketape.c (révision 7044)
459 +++ src/stored/faketape.c (copie de travail)
461 /* theses function will replace open/read/write/close/ioctl
464 -int faketape_open(const char *pathname, int flags)
465 +int faketape_open(const char *pathname, int flags, ...)
467 ASSERT(pathname != NULL);
469 Index: src/stored/dev.h
470 ===================================================================
471 --- src/stored/dev.h (révision 7044)
472 +++ src/stored/dev.h (copie de travail)
478 + B_FAKETAPE_DEV, /* change to B_TAPE_DEV after init */
482 /* Generic status bits returned from status_dev() */
484 int is_fifo() const { return dev_type == B_FIFO_DEV; }
485 int is_dvd() const { return dev_type == B_DVD_DEV; }
486 int is_vtl() const { return dev_type == B_VTL_DEV; }
487 + int is_faketape() const { return dev_type == B_FAKETAPE_DEV; }
488 int is_open() const { return m_fd >= 0; }
489 int is_offline() const { return state & ST_OFFLINE; }
490 int is_labeled() const { return state & ST_LABEL; }
492 uint32_t get_block_num() const { return block_num; };
493 int fd() const { return m_fd; };
495 + /* low level operations */
496 + void init_backend();
497 + int (*d_open)(const char *pathname, int flags, ...);
498 + int (*d_read)(int fd, void *buffer, unsigned int count);
499 + int (*d_write)(int fd, const void *buffer, unsigned int count);
500 + int (*d_close)(int fd);
501 + int (*d_ioctl)(int fd, unsigned long int request, ...);
504 * Locking and blocking calls
506 Index: src/stored/faketape.h
507 ===================================================================
508 --- src/stored/faketape.h (révision 7044)
509 +++ src/stored/faketape.h (copie de travail)
512 * Theses functions will replace open/read/write
514 -int faketape_open(const char *pathname, int flags);
515 +int faketape_open(const char *pathname, int flags, ...);
516 int faketape_read(int fd, void *buffer, unsigned int count);
517 int faketape_write(int fd, const void *buffer, unsigned int count);
518 int faketape_close(int fd);