Commit 98f97e6f authored by Eric Cano's avatar Eric Cano
Browse files

Added possibility to find a SCSI device in the list by following a symlink

parent 44420e9e
......@@ -60,6 +60,20 @@ SCSI::DeviceVector::DeviceVector(System::virtualWrapper& sysWrapper) : m_sysWrap
sysWrapper.closedir(dirp);
}
SCSI::DeviceInfo & SCSI::DeviceVector::findBySymlink(std::string path) {
struct stat sbuff;
castor::exception::Errnum::throwOnMinusOne(
m_sysWrapper.stat(path.c_str(), &sbuff),
std::string("Could not stat path: ")+path);
for(std::vector<DeviceInfo>::iterator i = begin(); i!= end(); i++) {
if (i->nst == sbuff || i->st == sbuff) {
return *i;
}
}
throw SCSI::DeviceVector::NotFound(
std::string("Could not find tape device pointed to by ") + path);
}
std::string SCSI::DeviceVector::readfile(std::string path) {
int fd;
castor::exception::Errnum::throwOnMinusOne(
......
......@@ -23,7 +23,8 @@
*****************************************************************************/
#pragma once
#include <string>
#include <vector>
#include <regex.h>
#include <sys/types.h>
......@@ -32,6 +33,7 @@
#include "../exception/Exception.hpp"
#include "../utils/Regex.hpp"
#include "Constants.hpp"
#include <string>
namespace castor {
namespace tape {
......@@ -54,12 +56,16 @@ namespace SCSI {
major = -1;
minor = -1;
}
int major;
int minor;
unsigned int major;
unsigned int minor;
bool operator !=(const DeviceFile& b) const {
return major != b.major || minor != b.minor;
}
bool operator ==(const struct stat & sbuff) const {
return major == major(sbuff.st_rdev) && minor == minor(sbuff.st_rdev);
}
};
DeviceFile sg;
DeviceFile st;
......@@ -83,6 +89,21 @@ namespace SCSI {
* (all code using templates must be in the header file)
*/
DeviceVector(castor::tape::System::virtualWrapper & sysWrapper);
/**
* Find an array element that shares the same device files as one pointed
* to as a path. This is designed to be used with a symlink like:
* /dev/tape_T10D6116 -> /dev/nst0
*/
DeviceInfo & findBySymlink(std::string path);
/**
* Exception for previous function
*/
class NotFound: public castor::tape::Exception {
public:
NotFound(const std::string& what): castor::tape::Exception(what) {}
};
private:
castor::tape::System::virtualWrapper & m_sysWrapper;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment