/* theses function will replace open/read/write/close/ioctl
* in bacula core
*/
-int faketape_open(const char *pathname, int flags)
+int faketape_open(const char *pathname, int flags, ...)
{
ASSERT(pathname != NULL);
current_file = 0;
current_block = -1;
- max_block = 2*1024*100; /* 100MB */
+ max_block = 2*1024*2048; /* 2GB */
}
faketape::~faketape()
return -1;
}
- if (!inplace) {
- seek_file();
- }
+ check_inplace();
if (!atEOD) { /* if not at the end of the data */
truncate_file();
return -1;
}
needEOF = false;
- truncate_file(); /* nothing after this point */
- /* TODO: check this */
- current_file += count;
- current_block = 0;
+ check_inplace();
+ truncate_file(); /* nothing after this point */
uint32_t c=0;
- seek_file();
::write(fd, &c, sizeof(uint32_t));
+
+ current_file += count;
+ current_block = 0;
seek_file();
+ c=0;
+ ::write(fd, &c, sizeof(uint32_t));
+ lseek(fd, lseek(fd, 0, SEEK_CUR) - sizeof(uint32_t), SEEK_SET);
+
atEOD = false;
atBOT = false;
atEOF = true;
/*
* 1 0 -> fsf -> 2 0 -> fsf -> 2 -1
*/
+ check_inplace();
check_eof();
int ret;
- if (atEOT) {
+ if (atEOT || atEOD) {
+ errno = EIO;
current_block = -1;
return -1;
}
ret = 0;
} else {
Dmsg0(dbglevel, "Try to FSF after EOT\n");
+ errno = EIO;
current_file = last_file ;
current_block = -1;
atEOD=true;
uint32_t s;
Dmsg3(dbglevel, "fsr %i:%i count=%i\n", current_file,current_block, count);
+ check_inplace();
check_eof();
if (atEOT) {
ASSERT(count == 1);
ASSERT(fd >= 0);
+ check_inplace();
check_eof();
if (!count) {
int orig_f = current_file;
int orig_b = current_block;
+ /* begin of tape, do nothing */
+ if (atBOT) {
+ errno = EIO;
+ return -1;
+ }
+
+ if (atEOF) {
+ if (!current_block) {
+ if (current_file > 0) {
+ current_file--;
+ }
+ current_block=-1;
+ errno = EIO;
+ return -1;
+
+ } else {
+ atEOF=false;
+ }
+ }
+
current_block=0;
seek_file();
}
Dmsg2(dbglevel, "bsr %i:%i\n", current_file, current_block);
+ errno=0;
atEOT = atEOF = atEOD = false;
+ atBOT = (current_block == 0 && current_file == 0);
+
+ current_block = -1;
return 0;
}
Dmsg3(dbglevel, "bsf %i:%i count=%i\n", current_file, current_block, count);
int ret = 0;
+ check_inplace();
check_eof();
+
atBOT = atEOF = atEOT = atEOD = false;
if (current_file - count < 0) {
atBOT = false; /* Begin of tape */
online = false;
- file_size = 0;
+ file_block = 0;
current_file = -1;
current_block = -1;
last_file = -1;
Dmsg2(dbglevel, "read %i:%i\n", current_file, current_block);
if (atEOT || atEOD) {
- return 0;
+ errno = EIO;
+ return -1;
}
if (atEOF) {
- current_file++;
- current_block=0;
- inplace = false;
- atEOF = false;
+ if (current_file >= last_file) {
+ atEOD = true;
+ atEOF = false;
+ current_block=-1;
+ return 0;
+ }
+ atEOF=false;
}
- if (!inplace) {
- seek_file();
- }
+ check_inplace();
+ check_eof();
atEOD = atBOT = false;
- current_block++;
+ /* reading size of data */
nb = ::read(fd, &s, sizeof(uint32_t));
if (nb <= 0) {
- atEOF = true;
+ atEOF = true; /* TODO: check this */
return 0;
}
+
if (s > count) { /* not enough buffer to read block */
Dmsg2(dbglevel, "Need more buffer to read next block %i > %i\n",s,count);
lseek(fd, s, SEEK_CUR);
errno = ENOMEM;
return -1;
}
+
if (!s) { /* EOF */
atEOF = true;
- lseek(fd, lseek(fd, 0, SEEK_CUR) - sizeof(uint32_t), SEEK_SET);
+ if (current_file < last_file) { /* move to next file if possible */
+ current_file++;
+ current_block = 0;
+ inplace=false;
+ }
return 0;
}
+
+ /* reading data itself */
nb = ::read(fd, buffer, s);
- if (s != nb) {
- atEOF = true;
- if (current_file == last_file) {
- atEOD = true;
- current_block = -1;
- }
- Dmsg0(dbglevel, "EOF during reading\n");
+ if (s != nb) { /* read error */
+ errno=EIO;
+ atEOT = true;
+ current_block = -1;
+ Dmsg0(dbglevel, "EOT during reading\n");
+ return -1;
+ } /* read ok */
+
+ if (current_block >= 0) {
+ current_block++;
}
+
return nb;
}
file_block = statp.st_blocks;
}
+ Dmsg1(dbglevel+1, "update_pos=%i\n", file_block);
+
if (file_block > max_block) {
atEOT = true;
} else {
ASSERT(online);
ASSERT(current_file >= 0);
Dmsg2(dbglevel, "seek_file %i:%i\n", current_file, current_block);
+ inplace = true;
off_t pos = ((off_t)current_file)<<FILE_OFFSET;
if(lseek(fd, pos, SEEK_SET) == -1) {
return -1;
}
+
last_file = MAX(last_file, current_file);
if (current_block > 0) {
fsr(current_block);
}
- inplace = true;
return 0;
}