From 8da0014369f55db5cf0e8ee143c0c8648588d382 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Tue, 15 Oct 2013 13:35:28 +0200 Subject: [PATCH] More elaborate error messages from VFS IO driver and debugging. --- src/VfsIO.cpp | 33 +++++++++++++++++++++++++++------ src/VfsIO.h | 3 +++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/VfsIO.cpp b/src/VfsIO.cpp index 7ca5295..1bbd7e6 100644 --- a/src/VfsIO.cpp +++ b/src/VfsIO.cpp @@ -87,13 +87,14 @@ VfsIOHandler::VfsIOHandler(const std::string& path, std::string real; if (path.compare(0, 5, "/vfs/") != 0) - throw DmException(EINVAL, "File not on the /vfs/ namespace"); + vfsThrow(EINVAL, "file not on the /vfs/ namespace"); real = path.substr(4); this->fd_ = ::open(real.c_str(), flags, mode); + syslog(LOG_DEBUG, "%s: open('%s', flags=%04X, mode=%04o) = %d", __func__, real.c_str(), flags, mode, this->fd_); if (this->fd_ == -1) - throw DmException(errno, "Could not open %s", path.c_str()); + vfsThrowErrno("could not open %s)", path.c_str()); } @@ -106,6 +107,14 @@ VfsIOHandler::~VfsIOHandler() +std::string VfsIOHandler::getImplId() const throw() +{ + return "VfsIOHandler"; + +} + + + void VfsIOHandler::close() throw (DmException) { ::close(this->fd_); @@ -116,8 +125,15 @@ void VfsIOHandler::close() throw (DmException) size_t VfsIOHandler::read(char* buffer, size_t count) throw (DmException) { - size_t nbytes = ::read(this->fd_, buffer, count); - + ssize_t ret; + size_t nbytes; + + ret = ::read(this->fd_, buffer, count); + + if (ret < 0) + vfsThrowErrno("error during reading"); + + nbytes = ret; eof_ = (nbytes < count); return nbytes; @@ -127,7 +143,12 @@ size_t VfsIOHandler::read(char* buffer, size_t count) throw (DmException) size_t VfsIOHandler::write(const char* buffer, size_t count) throw (DmException) { - return ::write(this->fd_, buffer, count); + ssize_t nbytes = ::write(this->fd_, buffer, count); + + if (nbytes < 0) + vfsThrowErrno("error during writing"); + + return nbytes; } @@ -135,7 +156,7 @@ size_t VfsIOHandler::write(const char* buffer, size_t count) throw (DmException) void VfsIOHandler::seek(off_t offset, Whence whence) throw (DmException) { if ((pos_ = ::lseek(this->fd_, offset, whence)) == ((off_t) - 1)) - throw DmException(errno, "Could not seek (%d)", errno); + vfsThrowErrno("could not seek"); } diff --git a/src/VfsIO.h b/src/VfsIO.h index 3b1aa7a..0f1abc8 100644 --- a/src/VfsIO.h +++ b/src/VfsIO.h @@ -51,6 +51,9 @@ namespace dmlite { int fd_; bool eof_; long pos_; + + private: + std::string getImplId() const throw(); }; }; -- 1.8.2.3