More elaborate error messages from VFS IO driver and debugging.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 15 Oct 2013 11:35:28 +0000 (13:35 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 15 Oct 2013 11:35:28 +0000 (13:35 +0200)
src/VfsIO.cpp
src/VfsIO.h

index 7ca5295..1bbd7e6 100644 (file)
@@ -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");
 }
 
 
index 3b1aa7a..0f1abc8 100644 (file)
@@ -51,6 +51,9 @@ namespace dmlite {
     int  fd_;
     bool eof_;
     long pos_;
+
+  private:
+    std::string getImplId() const throw();
   };
 
 };