Line 1... |
Line 1... |
// $Id: Rw11VirtDiskFile.cpp 509 2013-04-21 20:46:20Z mueller $
|
// $Id: Rw11VirtDiskFile.cpp 516 2013-05-05 21:24:52Z mueller $
|
//
|
//
|
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
//
|
//
|
// This program is free software; you may redistribute and/or modify it under
|
// This program is free software; you may redistribute and/or modify it under
|
// the terms of the GNU General Public License as published by the Free
|
// the terms of the GNU General Public License as published by the Free
|
Line 17... |
Line 17... |
// 2013-02-13 488 0.1 First draft
|
// 2013-02-13 488 0.1 First draft
|
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
|
|
/*!
|
/*!
|
\file
|
\file
|
\version $Id: Rw11VirtDiskFile.cpp 509 2013-04-21 20:46:20Z mueller $
|
\version $Id: Rw11VirtDiskFile.cpp 516 2013-05-05 21:24:52Z mueller $
|
\brief Implemenation of Rw11VirtDiskFile.
|
\brief Implemenation of Rw11VirtDiskFile.
|
*/
|
*/
|
|
|
#include <sys/types.h>
|
#include <sys/types.h>
|
#include <sys/stat.h>
|
#include <sys/stat.h>
|
Line 68... |
Line 68... |
bool wpro = fUrl.FindOpt("wpro");
|
bool wpro = fUrl.FindOpt("wpro");
|
|
|
int fd = ::open(fUrl.Path().c_str(), wpro ? O_RDONLY : O_RDWR);
|
int fd = ::open(fUrl.Path().c_str(), wpro ? O_RDONLY : O_RDWR);
|
if (fd < 0) {
|
if (fd < 0) {
|
emsg.InitErrno("Rw11VirtDiskFile::Open()",
|
emsg.InitErrno("Rw11VirtDiskFile::Open()",
|
string("open() for '") + fUrl.Path() + string("' failed: "),
|
string("open() for '") + fUrl.Path() + "' failed: ", errno);
|
errno);
|
|
return false;
|
return false;
|
}
|
}
|
|
|
struct stat sbuf;
|
struct stat sbuf;
|
if (::fstat(fd, &sbuf) < 0) {
|
if (::fstat(fd, &sbuf) < 0) {
|
emsg.InitErrno("Rw11VirtDiskFile::Open()",
|
emsg.InitErrno("Rw11VirtDiskFile::Open()",
|
string("stat() for '") + fUrl.Path() + string("' failed: "),
|
string("stat() for '") + fUrl.Path() + "' failed: ", errno);
|
errno);
|
|
return false;
|
return false;
|
}
|
}
|
|
|
fFd = fd;
|
fFd = fd;
|
fSize = sbuf.st_size;
|
fSize = sbuf.st_size;
|
Line 136... |
Line 134... |
|
|
if (!Seek(seekpos, emsg)) return false;
|
if (!Seek(seekpos, emsg)) return false;
|
|
|
ssize_t irc = ::write(fFd, data, nbyt);
|
ssize_t irc = ::write(fFd, data, nbyt);
|
if (irc < ssize_t(nbyt)) {
|
if (irc < ssize_t(nbyt)) {
|
emsg.InitErrno("Rw11VirtDiskFile::Write()", string("write() failed: "),
|
emsg.InitErrno("Rw11VirtDiskFile::Write()", "write() failed: ", errno);
|
errno);
|
|
return false;
|
return false;
|
}
|
}
|
|
|
if (seekpos+nbyt > fSize) fSize = seekpos+nbyt;
|
if (seekpos+nbyt > fSize) fSize = seekpos+nbyt;
|
|
|
Line 152... |
Line 149... |
//! FIXME_docs
|
//! FIXME_docs
|
|
|
bool Rw11VirtDiskFile::Seek(size_t seekpos, RerrMsg& emsg)
|
bool Rw11VirtDiskFile::Seek(size_t seekpos, RerrMsg& emsg)
|
{
|
{
|
if (::lseek(fFd, seekpos, SEEK_SET) < 0) {
|
if (::lseek(fFd, seekpos, SEEK_SET) < 0) {
|
emsg.InitErrno("Rw11VirtDiskFile::Seek()", string("seek() failed: "),
|
emsg.InitErrno("Rw11VirtDiskFile::Seek()", "seek() failed: ", errno);
|
errno);
|
|
return false;
|
return false;
|
}
|
}
|
|
|
return true;
|
return true;
|
}
|
}
|