}
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
+#include <boost/function.hpp>
#ifdef DCPOMATIC_DISK
#include <boost/dll/runtime_symbol_info.hpp>
#endif
using std::runtime_error;
using boost::shared_ptr;
using boost::optional;
+using boost::function;
/** @param s Number of seconds to sleep for */
void
return false;
}
+
+static
vector<pair<string, string> >
get_mounts (string prefix)
{
vector<string> bits;
boost::algorithm::split (bits, line, boost::is_any_of(" "));
if (bits.size() > 1 && boost::algorithm::starts_with(bits[0], prefix)) {
+ boost::algorithm::replace_all (bits[1], "\\040", " ");
mounts.push_back(make_pair(bits[0], bits[1]));
LOG_DISK("Found mounted device %1 from prefix %2", bits[0], prefix);
}
return mounts;
}
+
vector<Drive>
-get_drives ()
+Drive::get ()
{
vector<Drive> drives;
if (size == 0) {
continue;
}
- bool mounted = false;
optional<string> vendor;
try {
vendor = dcp::file_to_string("/sys/block/" + name + "/device/vendor");
model = dcp::file_to_string("/sys/block/" + name + "/device/model");
boost::trim(*model);
} catch (...) {}
+ vector<boost::filesystem::path> mount_points;
for (vector<pair<string, string> >::const_iterator j = mounted_devices.begin(); j != mounted_devices.end(); ++j) {
if (boost::algorithm::starts_with(j->first, "/dev/" + name)) {
- mounted = true;
+ mount_points.push_back (j->second);
}
}
- drives.push_back(Drive("/dev/" + i->path().filename().string(), size, mounted, vendor, model));
- LOG_DISK("Block device %1 size %2 %3 vendor %4 model %5", name, size, mounted ? "mounted" : "not mounted", vendor.get_value_or("[none]"), model.get_value_or("[none]"));
+ drives.push_back(Drive("/dev/" + name, mount_points, size, vendor, model));
+ LOG_DISK_NC(drives.back().log_summary());
}
}
return drives;
}
+
+bool
+Drive::unmount ()
+{
+ BOOST_FOREACH (boost::filesystem::path i, _mount_points) {
+ int const r = umount(i.string().c_str());
+ LOG_DISK("Tried to unmount %1 and got %2 and %3", i.string(), r, errno);
+ if (r == -1) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
void
unprivileged ()
{
return p;
}
-bool
-unmount_drive (string drive)
+
+void
+disk_write_finished ()
{
- vector<pair<string, string> > mounts = get_mounts (drive);
- for (vector<pair<string, string> >::const_iterator i = mounts.begin(); i != mounts.end(); ++i) {
- int const r = umount(i->second.c_str());
- LOG_DISK("Tried to unmount %1 and got %2 and %3", i->second, r, errno);
- if (r == -1) {
- return false;
- }
- }
- return true;
+
}