#include "bacula.h" /* define 64bit file usage */
#include "stored.h"
-#include "faketape.h"
+#include "vtape.h"
static int dbglevel = 100;
#define FILE_OFFSET 30
-faketape *ftape_list[FTAPE_MAX_DRIVE];
+vtape *ftape_list[FTAPE_MAX_DRIVE];
-static faketape *get_tape(int fd)
+static vtape *get_tape(int fd)
{
ASSERT(fd >= 0);
return ftape_list[fd];
}
-static bool put_tape(faketape *ftape)
+static bool put_tape(vtape *ftape)
{
ASSERT(ftape != NULL);
return true;
}
-void faketape_debug(int level)
+void vtape_debug(int level)
{
dbglevel = level;
}
/* theses function will replace open/read/write/close/ioctl
* in bacula core
*/
-int faketape_open(const char *pathname, int flags, ...)
+int vtape_open(const char *pathname, int flags, ...)
{
ASSERT(pathname != NULL);
int fd;
- faketape *tape = new faketape();
+ vtape *tape = new vtape();
fd = tape->open(pathname, flags);
if (fd > 0) {
put_tape(tape);
return fd;
}
-int faketape_read(int fd, void *buffer, unsigned int count)
+int vtape_read(int fd, void *buffer, unsigned int count)
{
- faketape *tape = get_tape(fd);
+ vtape *tape = get_tape(fd);
ASSERT(tape != NULL);
return tape->read(buffer, count);
}
-int faketape_write(int fd, const void *buffer, unsigned int count)
+int vtape_write(int fd, const void *buffer, unsigned int count)
{
- faketape *tape = get_tape(fd);
+ vtape *tape = get_tape(fd);
ASSERT(tape != NULL);
return tape->write(buffer, count);
}
-int faketape_close(int fd)
+int vtape_close(int fd)
{
- faketape *tape = get_tape(fd);
+ vtape *tape = get_tape(fd);
ASSERT(tape != NULL);
tape->close();
delete tape;
return 0;
}
-int faketape_ioctl(int fd, unsigned long int request, ...)
+int vtape_ioctl(int fd, unsigned long int request, ...)
{
va_list argp;
int result=0;
- faketape *t = get_tape(fd);
+ vtape *t = get_tape(fd);
if (!t) {
errno = EBADF;
return -1;
/****************************************************************/
-int faketape::tape_op(struct mtop *mt_com)
+int vtape::tape_op(struct mtop *mt_com)
{
int result=0;
int count = mt_com->mt_count;
break;
case MTREW: /* Rewind. */
- Dmsg0(dbglevel, "rewind faketape\n");
+ Dmsg0(dbglevel, "rewind vtape\n");
check_eof();
atEOF = atEOD = false;
atBOT = true;
current_file = 0;
current_block = 0;
lseek(fd, 0, SEEK_SET);
- result = !read_fm(FT_READ_EOF);
+ result = !read_fm(VT_READ_EOF);
break;
case MTOFFL: /* put tape offline */
case MTEOM:/* Go to the end of the recorded media (for appending files). */
while (next_FM) {
lseek(fd, next_FM, SEEK_SET);
- if (read_fm(FT_READ_EOF)) {
+ if (read_fm(VT_READ_EOF)) {
current_file++;
}
}
current_file = 0;
current_block = -1;
lseek(fd, 0, SEEK_SET);
- read_fm(FT_READ_EOF);
+ read_fm(VT_READ_EOF);
truncate_file();
break;
return result == 0 ? 0 : -1;
}
-int faketape::tape_get(struct mtget *mt_get)
+int vtape::tape_get(struct mtget *mt_get)
{
int density = 1;
int block_size = 1024;
return 0;
}
-int faketape::tape_pos(struct mtpos *mt_pos)
+int vtape::tape_pos(struct mtpos *mt_pos)
{
if (current_block >= 0) {
mt_pos->mt_blkno = current_block;
* of a tape. When you wrote something, data after the
* current position are discarded.
*/
-int faketape::truncate_file()
+int vtape::truncate_file()
{
Dmsg2(dbglevel, "truncate %i:%i\n", current_file, current_block);
ftruncate(fd, lseek(fd, 0, SEEK_CUR));
return 0;
}
-faketape::faketape()
+vtape::vtape()
{
fd = -1;
max_block = 2*1024*2048; /* 2GB */
}
-faketape::~faketape()
+vtape::~vtape()
{
}
-int faketape::get_fd()
+int vtape::get_fd()
{
return this->fd;
}
/*
* TODO: check if after a write op, and other tape op put a EOF
*/
-int faketape::write(const void *buffer, unsigned int count)
+int vtape::write(const void *buffer, unsigned int count)
{
ASSERT(online);
ASSERT(current_file >= 0);
* N : Next FileMark offset
* C : Current FileMark Offset
*/
-int faketape::weof()
+int vtape::weof()
{
ASSERT(online);
ASSERT(current_file >= 0);
/*
* Go to next FM
*/
-int faketape::fsf()
+int vtape::fsf()
{
ASSERT(online);
ASSERT(current_file >= 0);
if (next_FM > cur_FM) { /* not the last file */
lseek(fd, next_FM, SEEK_SET);
- read_fm(FT_READ_EOF);
+ read_fm(VT_READ_EOF);
current_file++;
atEOF = true;
ret = 0;
* +---+------+---+---------------+-+
*/
-bool faketape::read_fm(FT_READ_FM_MODE read_all)
+bool vtape::read_fm(VT_READ_FM_MODE read_all)
{
int ret;
uint32_t c;
- if (read_all == FT_READ_EOF) {
+ if (read_all == VT_READ_EOF) {
::read(fd, &c, sizeof(c));
if (c != 0) {
lseek(fd, cur_FM, SEEK_SET);
/*
* TODO: Check fsr with EOF
*/
-int faketape::fsr(int count)
+int vtape::fsr(int count)
{
ASSERT(online);
ASSERT(current_file >= 0);
ret = -1;
if (next_FM) {
current_file++;
- read_fm(FT_SKIP_EOF);
+ read_fm(VT_SKIP_EOF);
}
atEOF = true; /* stop the loop */
}
* BSR + BSR + EOF => last block
* current_block = -1
*/
-int faketape::bsr(int count)
+int vtape::bsr(int count)
{
ASSERT(online);
ASSERT(current_file >= 0);
lseek(fd, cur_FM, SEEK_SET);
}
- ret = read_fm(FT_READ_EOF);
+ ret = read_fm(VT_READ_EOF);
do {
if (!atEOF) {
* EOF + BSF => just before EOF
* file 0 + BSF => BOT + errno
*/
-int faketape::bsf()
+int vtape::bsf()
{
ASSERT(online);
ASSERT(current_file >= 0);
if (current_file == 0) {/* BOT + errno */
lseek(fd, 0, SEEK_SET);
- read_fm(FT_READ_EOF);
+ read_fm(VT_READ_EOF);
current_file = 0;
current_block = 0;
atBOT = true;
}
/*
- * Put faketape in offline mode
+ * Put vtape in offline mode
*/
-int faketape::offline()
+int vtape::offline()
{
close();
/* A filemark is automatically written to tape if the last tape operation
* before close was a write.
*/
-int faketape::close()
+int vtape::close()
{
check_eof();
::close(fd);
* naled by returning zero bytes for two consecutive read calls. The third
* read returns an error.
*/
-int faketape::read(void *buffer, unsigned int count)
+int vtape::read(void *buffer, unsigned int count)
{
ASSERT(online);
ASSERT(current_file >= 0);
if (!s) { /* EOF */
atEOF = true;
- if (read_fm(FT_SKIP_EOF)) {
+ if (read_fm(VT_SKIP_EOF)) {
current_file++;
}
return nb;
}
-int faketape::open(const char *pathname, int uflags)
+int vtape::open(const char *pathname, int uflags)
{
- Dmsg2(dbglevel, "faketape::open(%s, %i)\n", pathname, uflags);
+ Dmsg2(dbglevel, "vtape::open(%s, %i)\n", pathname, uflags);
online = true; /* assume that drive contains a tape */
atBOT = true;
atEOT = atEOD = false;
- /* If the faketape is empty, start by writing a EOF */
- if (online && !read_fm(FT_READ_EOF)) {
+ /* If the vtape is empty, start by writing a EOF */
+ if (online && !read_fm(VT_READ_EOF)) {
weof();
last_file = current_file=0;
}
}
/* use this to track file usage */
-void faketape::update_pos()
+void vtape::update_pos()
{
ASSERT(online);
struct stat statp;
}
}
-void faketape::dump()
+void vtape::dump()
{
Dmsg0(dbglevel+1, "===================\n");
Dmsg2(dbglevel, "file:block = %i:%i\n", current_file, current_block);
Switzerland, email:ftf@fsfeurope.org.
*/
/*
- * faketape.h - Emulate the Linux st (scsi tape) driver on file.
+ * vtape.h - Emulate the Linux st (scsi tape) driver on file.
* for regression and bug hunting purpose
*
*/
-#ifndef FAKETAPE_H
-#define FAKETAPE_H
+#ifndef VTAPE_H
+#define VTAPE_H
#include <stdarg.h>
#include <stddef.h>
/*
* Theses functions will replace open/read/write
*/
-int faketape_open(const char *pathname, int flags, ...);
-int faketape_read(int fd, void *buffer, unsigned int count);
-int faketape_write(int fd, const void *buffer, unsigned int count);
-int faketape_close(int fd);
-int faketape_ioctl(int fd, unsigned long int request, ...);
-void faketape_debug(int level);
+int vtape_open(const char *pathname, int flags, ...);
+int vtape_read(int fd, void *buffer, unsigned int count);
+int vtape_write(int fd, const void *buffer, unsigned int count);
+int vtape_close(int fd);
+int vtape_ioctl(int fd, unsigned long int request, ...);
+void vtape_debug(int level);
typedef enum {
- FT_READ_EOF, /* Need to read the entire EOF struct */
- FT_SKIP_EOF /* Have already read the EOF byte */
-} FT_READ_FM_MODE;
+ VT_READ_EOF, /* Need to read the entire EOF struct */
+ VT_SKIP_EOF /* Have already read the EOF byte */
+} VT_READ_FM_MODE;
-class faketape {
+class vtape {
private:
int fd; /* Our file descriptor */
int truncate_file();
void check_eof() { if(needEOF) weof();};
void update_pos();
- bool read_fm(FT_READ_FM_MODE readfirst);
+ bool read_fm(VT_READ_FM_MODE readfirst);
public:
int fsf();
int bsf();
int bsr(int count);
- faketape();
- ~faketape();
+ vtape();
+ ~vtape();
int get_fd();
void dump();
int tape_pos(struct mtpos *mt_com);
};
-#endif /* !FAKETAPE_H */
+#endif /* !VTAPE_H */