IODriver* VfsFactory::createIODriver(PluginManager*) throw (DmException)
{
syslog(LOG_DEBUG, "%s", __func__);
- return new VfsIODriver(this->tokenPasswd_, this->tokenUseIp_);
+ return new VfsIODriver(this->diskPrefix_, this->tokenPasswd_, this->tokenUseIp_);
}
-VfsIODriver::VfsIODriver(std::string passwd, bool useIp):
- si_(0), secCtx_(0), passwd_(passwd), useIp_(useIp)
+VfsIODriver::VfsIODriver(const std::string& prefix, std::string passwd, bool useIp):
+ si_(0), secCtx_(0), prefix_(prefix), passwd_(passwd), useIp_(useIp)
{
// Nothing
}
}
// Create
- return new VfsIOHandler(pfn, flags, mode);
+ return new VfsIOHandler(pfn, prefix_, flags, mode);
}
-VfsIOHandler::VfsIOHandler(const std::string& path,
+VfsIOHandler::VfsIOHandler(const std::string& path, const std::string& prefix,
int flags, mode_t mode) throw (DmException):
eof_(false), pos_(0)
{
if (path.compare(0, 5, "/vfs/") != 0)
vfsThrow(EINVAL, "file not on the /vfs/ namespace");
-
- real = path.substr(4);
+
+ this->prefix_ = prefix;
+
+ real = getLocalPath(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_);
{
return eof_;
}
+
+
+
+const std::string VfsIOHandler::getLocalPath(const std::string &path) {
+ if (path.empty())
+ return this->prefix_;
+
+ if (path[0] != '/')
+ return this->prefix_ + "/" + path;
+
+ return this->prefix_ + path;
+}
class VfsIODriver: public IODriver {
public:
- VfsIODriver(std::string passwd, bool useIp);
+ VfsIODriver(const std::string& prefix, std::string passwd, bool useIp);
~VfsIODriver();
std::string getImplId() const throw();
StackInstance* si_;
const SecurityContext* secCtx_;
+ const std::string prefix_;
std::string passwd_;
bool useIp_;
};
class VfsIOHandler: public IOHandler {
public:
- VfsIOHandler(const std::string& path,
+ VfsIOHandler(const std::string& path, const std::string& prefix,
int flags, mode_t mode) throw (DmException);
~VfsIOHandler();
int fd_;
bool eof_;
long pos_;
+ std::string prefix_;
private:
std::string getImplId() const throw();
+ const std::string getLocalPath(const std::string &path);
};
};