X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcross_linux.cc;h=36683a0cd1cac9551a74935b32c4895b906ea99d;hb=8902a7adb63e2dac24e877ed1035bf344397c260;hp=14a7e5b4748c50be8d7c8db8259fd765745aad0e;hpb=350afcbc40fffd8c8780180e153a2ee91088f562;p=dcpomatic.git diff --git a/src/lib/cross_linux.cc b/src/lib/cross_linux.cc index 14a7e5b47..36683a0cd 100644 --- a/src/lib/cross_linux.cc +++ b/src/lib/cross_linux.cc @@ -32,6 +32,7 @@ extern "C" { } #include #include +#include #ifdef DCPOMATIC_DISK #include #endif @@ -58,6 +59,7 @@ using std::cout; using std::runtime_error; using boost::shared_ptr; using boost::optional; +using boost::function; /** @param s Number of seconds to sleep for */ void @@ -258,6 +260,8 @@ running_32_on_64 () return false; } + +static vector > get_mounts (string prefix) { @@ -278,8 +282,9 @@ get_mounts (string prefix) return mounts; } + vector -get_drives () +Drive::get () { vector drives; @@ -300,7 +305,6 @@ get_drives () if (size == 0) { continue; } - bool mounted = false; optional vendor; try { vendor = dcp::file_to_string("/sys/block/" + name + "/device/vendor"); @@ -311,19 +315,35 @@ get_drives () model = dcp::file_to_string("/sys/block/" + name + "/device/model"); boost::trim(*model); } catch (...) {} + vector mount_points; for (vector >::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 () { @@ -354,17 +374,10 @@ config_path () return p; } -bool -unmount_drive (string drive) + +void +disk_write_finished () { - vector > mounts = get_mounts (drive); - for (vector >::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; + }