50 fFd(
"Rw11VirtTapeTap::fFd."),
63 if (!
fUrl.
Set(url,
"|wpro|e11|cap=|",
"tap", emsg))
return false;
69 unsigned long capacity=0;
71 if (str_cap.length() > 0) {
72 unsigned long scale = 1;
73 string str_conv = str_cap;
74 char clast = str_cap[str_cap.length()-1];
77 if (! (clast >=
'0' && clast <=
'9') ) {
78 str_conv = str_cap.substr(0,str_cap.length()-1);
79 switch(str_cap[str_cap.length()-1]) {
98 emsg.
Init(
"Rw11VirtTapeTap::Open()",
99 string(
"bad capacity option '")+str_cap+
"'");
107 S_IRUSR|S_IWUSR|S_IRGRP, emsg))
return false;
115 if ((sbuf.st_mode & S_IWUSR) == 0)
fWProt =
true;
117 fSize = sbuf.st_size;
153 if (!
Read(
sizeof(metabeg),
reinterpret_cast<uint8_t*
>(&metabeg),
165 if (!
Seek(
sizeof(metabeg), -1, emsg))
return SetBad();
179 ndone = (rlen <= nbyt) ? rlen : nbyt;
180 if (!
Read(ndone, data, emsg))
return SetBad();
181 if (ndone < rlenpad) {
182 if (!
Seek(rlenpad, +1, emsg))
return SetBad();
186 if (!
Read(
sizeof(metaend),
reinterpret_cast<uint8_t*
>(&metaend),
189 if (metabeg != metaend) {
190 emsg.
Init(
"Rw11VirtTapeTap::ReadRecord",
"metabeg metaend mismatch");
225 uint32_t meta = nbyt;
228 if (!
Write(
sizeof(meta),
reinterpret_cast<uint8_t*
>(&meta),
229 false, emsg))
return SetBad();
231 if (!
Write(nbyt, data,
232 false, emsg))
return SetBad();
234 if (!
Write(
sizeof(zero), &zero,
false, emsg))
return SetBad();
237 if (!
Write(
sizeof(meta),
reinterpret_cast<uint8_t*
>(&meta),
238 false, emsg))
return SetBad();
240 true, emsg))
return SetBad();
260 false, emsg))
return SetBad();
262 true, emsg))
return SetBad();
293 if (!
Read(
sizeof(metabeg),
reinterpret_cast<uint8_t*
>(&metabeg),
304 if (!
Seek(
sizeof(metabeg), -1, emsg))
return SetBad();
315 if (!
CheckSizeForw(
sizeof(metabeg)+rlenpad,
"missed data or metaend", emsg))
317 if (!
Seek(
sizeof(metabeg)+rlenpad, +1, emsg))
return SetBad();
356 if (!
Seek(
sizeof(metaend), -1, emsg))
return SetBad();
357 if (!
Read(
sizeof(metaend),
reinterpret_cast<uint8_t*
>(&metaend),
361 if (!
Seek(
sizeof(metaend), -1, emsg))
return SetBad();
369 emsg.
Init(
"Rw11VirtTapeTap::SpaceBack()",
"unexpected EOM marker");
379 "missed data or metabeg", emsg))
return SetBad();
380 if (!
Seek(2*
sizeof(metaend)+rlenpad, -1, emsg))
return SetBad();
421 os << bl << (text?text:
"--") <<
"Rw11VirtTapeTap @ " <<
this << endl;
423 os << bl <<
" fFd: " <<
fFd.
Fd() << endl;
424 os << bl <<
" fSize: " <<
fSize << endl;
425 os << bl <<
" fPos: " <<
fPos << endl;
438 off_t offset = seekpos;
439 int whence = SEEK_SET;
442 }
else if (dir < 0) {
446 if (!
fFd.
Seek(offset, whence, emsg))
return false;
458 ssize_t irc =
fFd.
Read(data, nbyt, emsg);
459 if (irc < 0)
return false;
481 if (!
Seek(nbyt, -1, emsg))
return false;
494 emsg.
Init(
"Rw11VirtTapeTap::CheckSizeForw()", text);
504 if (nbyt <=
fPos)
return true;
505 emsg.
Init(
"Rw11VirtTapeTap::CheckSizeBack()", text);
516 }
else if (dir > 0) {
537 emsg.
Init(
"Rw11VirtTapeTap::ParseMeta",
"bad meta tag");
548 emsg.
Init(
string(
"Rw11VirtTapeTap::")+meth,
"bad tape format");
void Init(const std::string &meth, const std::string &text)
FIXME_docs.
int Fd() const
FIXME_docs.
bool WriteAll(const void *buf, size_t count, RerrMsg &emsg)
FIXME_docs.
ssize_t Read(void *buf, size_t count, RerrMsg &emsg)
FIXME_docs.
bool Stat(struct stat *sbuf, RerrMsg &emsg)
FIXME_docs.
off_t Seek(off_t offset, int whence, RerrMsg &emsg)
FIXME_docs.
bool Open(const char *fname, int flags, RerrMsg &emsg)
FIXME_docs.
bool Truncate(off_t length, RerrMsg &emsg)
FIXME_docs.
I/O appicator to generate fill characters.
bool FindOpt(const std::string &name) const
FIXME_docs.
bool Set(const std::string &url, const std::string &optlist, RerrMsg &emsg)
FIXME_docs.
const std::string & Path() const
FIXME_docs.
void Inc(size_t ind, double val=1.)
FIXME_docs.
virtual bool Open(const std::string &url, RerrMsg &emsg)
FIXME_docs.
static const uint32_t kMeta_M_Perr
virtual bool SpaceForw(size_t nrec, size_t &ndone, int &opcode, RerrMsg &emsg)
FIXME_docs.
static const uint32_t kMetaEom
EOM marker.
bool Write(size_t nbyt, const uint8_t *data, bool back, RerrMsg &emsg)
FIXME_docs.
static const uint32_t kMeta_B_Rlen
bool CheckSizeForw(size_t nbyt, const char *text, RerrMsg &emsg)
FIXME_docs.
static const uint32_t kMetaEof
EOF marker.
virtual bool WriteRecord(size_t nbyt, const uint8_t *data, int &opcode, RerrMsg &emsg)
FIXME_docs.
virtual bool Rewind(int &opcode, RerrMsg &emsg)
FIXME_docs.
bool CheckSizeBack(size_t nbyt, const char *text, RerrMsg &emsg)
FIXME_docs.
bool BadTapeMsg(const char *meth, RerrMsg &emsg)
FIXME_docs.
bool Seek(size_t seekpos, int dir, RerrMsg &emsg)
FIXME_docs.
virtual bool WriteEof(RerrMsg &emsg)
FIXME_docs.
Rw11VirtTapeTap(Rw11Unit *punit)
Default constructor.
bool Read(size_t nbyt, uint8_t *data, RerrMsg &emsg)
FIXME_docs.
bool ParseMeta(uint32_t meta, size_t &rlen, bool &perr, RerrMsg &emsg)
FIXME_docs.
bool fBad
BAD file format flag.
static const uint32_t kMeta_M_Mbz
virtual bool ReadRecord(size_t nbyt, uint8_t *data, size_t &ndone, int &opcode, RerrMsg &emsg)
FIXME_docs.
bool fPadOdd
do odd byte padding
bool fTruncPend
truncate on next write
void IncPosRecord(int delta)
FIXME_docs.
virtual bool SpaceBack(size_t nrec, size_t &ndone, int &opcode, RerrMsg &emsg)
FIXME_docs.
void UpdatePos(size_t nbyt, int dir)
FIXME_docs.
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
size_t BytePadding(size_t rlen)
FIXME_docs.
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
@ kOpCodeRecLenErr
record length error
@ kOpCodeBadFormat
file format error
@ kOpCodeBadParity
record with parity error
int fPosRecord
tape pos: #record (-1=unknown)
size_t fCapacity
capacity in byte (0=unlimited)
bool fEom
tape beyond medium
int fPosFile
tape pos: #files (-1=unknown)
bool fWProt
write protected
RosPrintfS< bool > RosPrintf(bool value, const char *form=0, int width=0, int prec=0)
Creates a print object for the formatted output of a bool value.
Declaration of class ReventLoop.