diff options
author | Krzysztof Richert <krzysztof.richert@intel.com> | 2021-10-27 15:07:45 +0300 |
---|---|---|
committer | Krzysztof Richert <krzysztof.richert@intel.com> | 2021-10-28 17:21:37 +0300 |
commit | 90e0e1648c3ee168deb7615450f3a2771c04b8eb (patch) | |
tree | 7d6297d9ca228b211467bf32c7d673911ef7e6e0 /src/system.hpp | |
parent | a5176f324cf5d9cbdb15fa57a6c3f54bcb6e6f48 (diff) | |
download | virtual-media-90e0e1648c3ee168deb7615450f3a2771c04b8eb.tar.xz |
Cleanup mounted resources after application crash.
On initial state application cleans mounted resources which
were allocated by user befor application crashed.
Without that busy slot is not avaialble anymore for user.
Tested:
1. Mount CIFS share.
2. Send terminate signal to virtual-media (kill -9).
3. Mount CIFS share on the same slot as during step 1.
Change-Id: I7088e94832fb7bec171a56f73bd66cd29e9b246f
Signed-off-by: Krzysztof Richert <krzysztof.richert@intel.com>
Diffstat (limited to 'src/system.hpp')
-rw-r--r-- | src/system.hpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/system.hpp b/src/system.hpp index cc8bdad..cd16802 100644 --- a/src/system.hpp +++ b/src/system.hpp @@ -490,6 +490,13 @@ struct UsbGadget return true; } + static const std::string getGadgetDirPrefix() + { + const std::string gadgetDirPrefix = + "/sys/kernel/config/usb_gadget/mass-storage-"; + return gadgetDirPrefix; + } + public: static int32_t configure(const std::string& name, const NBDDevice& nbd, StateChange change, const bool rw = false) @@ -511,8 +518,7 @@ struct UsbGadget return -1; } - const fs::path gadgetDir = - "/sys/kernel/config/usb_gadget/mass-storage-" + name; + const fs::path gadgetDir = getGadgetDirPrefix() + name; const fs::path funcMassStorageDir = gadgetDir / "functions/mass_storage.usb0"; const fs::path stringsDir = gadgetDir / "strings/0x409"; @@ -595,9 +601,8 @@ struct UsbGadget static std::optional<std::string> getStats(const std::string& name) { - const fs::path statsPath = - "/sys/kernel/config/usb_gadget/mass-storage-" + name + - "/functions/mass_storage.usb0/lun.0/stats"; + const fs::path statsPath = getGadgetDirPrefix() + name + + "/functions/mass_storage.usb0/lun.0/stats"; std::ifstream ifs(statsPath); if (!ifs.is_open()) @@ -609,4 +614,16 @@ struct UsbGadget return std::string{std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>()}; } + + static bool isConfigured(const std::string& name) + { + const fs::path gadgetDir = getGadgetDirPrefix() + name; + + if (!fs::exists(gadgetDir)) + { + return false; + } + + return true; + } }; |