int faketape::tape_op(struct mtop *mt_com)
{
int result=0;
+
+ if (!online) {
+ errno = ENOMEDIUM;
+ return -1;
+ }
switch (mt_com->mt_op)
{
*/
int faketape::write(const void *buffer, unsigned int count)
{
+ ASSERT(online);
ASSERT(current_file >= 0);
ASSERT(count > 0);
ASSERT(buffer);
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);
int faketape::fsf(int count)
{
+ ASSERT(online);
ASSERT(current_file >= 0);
ASSERT(fd >= 0);
/*
int faketape::fsr(int count)
{
+ ASSERT(online);
ASSERT(current_file >= 0);
ASSERT(fd >= 0);
Dmsg2(dbglevel, "bsr current_block=%i count=%i\n",
current_block, count);
+ ASSERT(online);
ASSERT(current_file >= 0);
ASSERT(count == 1);
ASSERT(fd >= 0);
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;
atEOT = false; /* End of tape */
atEOD = false; /* End of data */
atBOT = false; /* Begin of tape */
+ online = false;
current_file = -1;
current_block = -1;
int faketape::read(void *buffer, unsigned int count)
{
+ ASSERT(online);
ASSERT(current_file >= 0);
unsigned int nb;
uint32_t s;
{
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;
int faketape::seek_file()
{
+ ASSERT(online);
ASSERT(current_file >= 0);
Dmsg2(dbglevel, "seek_file %i:%i\n", current_file, current_block);
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();