From 53a8bad95d461e92f3791dabadfb7f95c9ddd3c1 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sun, 11 May 2008 09:53:00 +0000 Subject: [PATCH] ebl Add O_NONBLOCK option and ERNOMEDIUM git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6939 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/patches/testing/faketape.c | 31 +++++++++++++++++++++++++------ bacula/patches/testing/faketape.h | 26 +++++++++++++------------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/bacula/patches/testing/faketape.c b/bacula/patches/testing/faketape.c index 9284680b66..80acad6116 100644 --- a/bacula/patches/testing/faketape.c +++ b/bacula/patches/testing/faketape.c @@ -168,6 +168,11 @@ int faketape_ioctl(int fd, unsigned long int request, ...) int faketape::tape_op(struct mtop *mt_com) { int result=0; + + if (!online) { + errno = ENOMEDIUM; + return -1; + } switch (mt_com->mt_op) { @@ -424,6 +429,7 @@ int faketape::get_fd() */ int faketape::write(const void *buffer, unsigned int count) { + ASSERT(online); ASSERT(current_file >= 0); ASSERT(count > 0); ASSERT(buffer); @@ -481,6 +487,7 @@ int faketape::write(const void *buffer, unsigned int count) int faketape::weof(int count) { + ASSERT(online); ASSERT(current_file >= 0); Dmsg3(dbglevel, "Writing EOF %i:%i last=%i\n", current_file, current_block,last_file); @@ -510,6 +517,7 @@ int faketape::weof(int count) int faketape::fsf(int count) { + ASSERT(online); ASSERT(current_file >= 0); ASSERT(fd >= 0); /* @@ -543,6 +551,7 @@ int faketape::fsf(int count) int faketape::fsr(int count) { + ASSERT(online); ASSERT(current_file >= 0); ASSERT(fd >= 0); @@ -599,6 +608,7 @@ int faketape::bsr(int count) Dmsg2(dbglevel, "bsr current_block=%i count=%i\n", current_block, count); + ASSERT(online); ASSERT(current_file >= 0); ASSERT(count == 1); ASSERT(fd >= 0); @@ -661,6 +671,7 @@ int faketape::bsr(int count) int faketape::bsf(int count) { + ASSERT(online); ASSERT(current_file >= 0); Dmsg3(dbglevel, "bsf %i:%i count=%i\n", current_file, current_block, count); int ret = 0; @@ -696,6 +707,7 @@ int faketape::offline() atEOT = false; /* End of tape */ atEOD = false; /* End of data */ atBOT = false; /* Begin of tape */ + online = false; current_file = -1; current_block = -1; @@ -724,6 +736,7 @@ int faketape::close() int faketape::read(void *buffer, unsigned int count) { + ASSERT(online); ASSERT(current_file >= 0); unsigned int nb; uint32_t s; @@ -780,26 +793,31 @@ int faketape::open(const char *pathname, int uflags) { Dmsg2(dbglevel, "faketape::open(%s, %i)\n", pathname, uflags); + online = true; /* assume that drive contains a tape */ + struct stat statp; if (stat(pathname, &statp) != 0) { Dmsg1(dbglevel, "Can't stat on %s\n", pathname); - return -1; + if (uflags & O_NONBLOCK) { + online = false; + fd = ::open("/dev/null", O_CREAT | O_RDWR | O_LARGEFILE, 0600); + } + } else { + fd = ::open(pathname, O_CREAT | O_RDWR | O_LARGEFILE, 0600); } - fd = ::open(pathname, O_CREAT | O_RDWR | O_LARGEFILE, 0700); if (fd < 0) { + errno = ENOMEDIUM; return -1; } /* open volume descriptor and get this->fd */ - if (find_maxfile() < 0) { - return -1; - } + find_maxfile(); current_block = 0; current_file = 0; needEOF = false; - online = inplace = true; + inplace = true; atBOT = true; atEOT = atEOD = false; @@ -827,6 +845,7 @@ int faketape::find_maxfile() int faketape::seek_file() { + ASSERT(online); ASSERT(current_file >= 0); Dmsg2(dbglevel, "seek_file %i:%i\n", current_file, current_block); diff --git a/bacula/patches/testing/faketape.h b/bacula/patches/testing/faketape.h index 3aea2228ba..58411ce9bb 100644 --- a/bacula/patches/testing/faketape.h +++ b/bacula/patches/testing/faketape.h @@ -52,23 +52,23 @@ void faketape_debug(int level); class faketape { private: - int fd; /* Our file descriptor */ + int fd; /* Our file descriptor */ - off_t file_size; /* size */ + off_t file_size; /* size */ off_t max_block; - bool atEOF; /* End of file */ - bool atEOT; /* End of media */ - bool atEOD; /* End of data */ + bool atEOF; /* End of file */ + bool atEOT; /* End of media */ + bool atEOD; /* End of data */ bool atBOT; /* Begin of tape */ - bool online; /* volume online */ - bool inplace; /* have to seek before writing ? */ - bool needEOF; /* check if last operation need eof */ - - int32_t last_file; /* last file of the volume */ - int32_t current_file; /* max 65000 files */ - int32_t current_block; /* max 4G blocks of 1KB */ - off_t current_pos; /* current position in stream */ + bool online; /* volume online */ + bool inplace; /* have to seek before writing ? */ + bool needEOF; /* check if last operation need eof */ + + int32_t last_file; /* last file of the volume */ + int32_t current_file; /* max 65000 files */ + int32_t current_block; /* max 4G blocks of 1KB */ + off_t current_pos; /* current position in stream */ void destroy(); int find_maxfile(); -- 2.39.5