| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/system/storagedrives.hpp" | ||
| 30 | |||
| 31 | namespace gate | ||
| 32 | { | ||
| 33 | namespace sys | ||
| 34 | { | ||
| 35 | 4 | StorageDrive::StorageDrive(gate_storagedrive_t const& drive) | |
| 36 | { | ||
| 37 | 4 | Mem::copy(this->impl, drive); | |
| 38 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | this->cached_path = String(this->impl.path); |
| 39 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | this->cached_name = String(this->impl.name); |
| 40 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | this->cached_uid = String(this->impl.uid); |
| 41 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | this->cached_device_path = String(this->impl.devicepath); |
| 42 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | this->cached_product_name = String(this->impl.productname); |
| 43 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | this->cached_vendor = String(this->impl.vendor); |
| 44 | 4 | } | |
| 45 | |||
| 46 | 1 | StorageDrive::StorageDrive(StorageDrive const& src) | |
| 47 | 1 | : cached_path(src.cached_path), | |
| 48 | 1 | cached_name(src.cached_name), | |
| 49 | 1 | cached_uid(src.cached_uid), | |
| 50 | 1 | cached_device_path(src.cached_device_path), | |
| 51 | 1 | cached_product_name(src.cached_product_name), | |
| 52 | 1 | cached_vendor(src.cached_vendor) | |
| 53 | { | ||
| 54 | 1 | Mem::copy(this->impl, src.impl); | |
| 55 | 1 | } | |
| 56 | ✗ | StorageDrive& StorageDrive::operator=(StorageDrive const& that) | |
| 57 | { | ||
| 58 | ✗ | if (this != &that) | |
| 59 | { | ||
| 60 | ✗ | Mem::copy(this->impl, that.impl); | |
| 61 | } | ||
| 62 | ✗ | return *this; | |
| 63 | } | ||
| 64 | 5 | StorageDrive::~StorageDrive() noexcept | |
| 65 | { | ||
| 66 | 5 | } | |
| 67 | |||
| 68 | 1 | String StorageDrive::Path() const | |
| 69 | { | ||
| 70 | 1 | return this->cached_path; | |
| 71 | } | ||
| 72 | 1 | String StorageDrive::Name() const | |
| 73 | { | ||
| 74 | 1 | return this->cached_name; | |
| 75 | } | ||
| 76 | 1 | String StorageDrive::Uid() const | |
| 77 | { | ||
| 78 | 1 | return this->cached_uid; | |
| 79 | } | ||
| 80 | ✗ | String StorageDrive::DevicePath() const | |
| 81 | { | ||
| 82 | ✗ | return this->cached_device_path; | |
| 83 | } | ||
| 84 | ✗ | String StorageDrive::ProductName() const | |
| 85 | { | ||
| 86 | ✗ | return this->cached_product_name; | |
| 87 | } | ||
| 88 | ✗ | String StorageDrive::Vendor() const | |
| 89 | { | ||
| 90 | ✗ | return this->cached_vendor; | |
| 91 | } | ||
| 92 | 1 | uint64_t StorageDrive::Size() const | |
| 93 | { | ||
| 94 | 1 | return this->impl.size; | |
| 95 | } | ||
| 96 | 1 | uint64_t StorageDrive::BlockCount() const | |
| 97 | { | ||
| 98 | 1 | return this->impl.blockcount; | |
| 99 | } | ||
| 100 | 1 | uint64_t StorageDrive::BlockSize() const | |
| 101 | { | ||
| 102 | 1 | return this->impl.blocksize; | |
| 103 | } | ||
| 104 | ✗ | uint32_t StorageDrive::DeviceIndex() const | |
| 105 | { | ||
| 106 | ✗ | return this->impl.deviceindex; | |
| 107 | } | ||
| 108 | 1 | StorageDrive::DriveTypeEnum StorageDrive::DriveType() const | |
| 109 | { | ||
| 110 | 1 | return static_cast<StorageDrive::DriveTypeEnum>(this->impl.drivetype); | |
| 111 | } | ||
| 112 | ✗ | enumint_t StorageDrive::Flags() const | |
| 113 | { | ||
| 114 | ✗ | return this->impl.flags; | |
| 115 | } | ||
| 116 | |||
| 117 | 1 | gate_storagedrive_t const* StorageDrive::c_impl() const | |
| 118 | { | ||
| 119 | 1 | return &this->impl; | |
| 120 | } | ||
| 121 | |||
| 122 | 1 | bool_t StorageDrive::findAllCallback(gate_storagedrive_t const* drive, void* user_param) | |
| 123 | { | ||
| 124 | 1 | ArrayList<StorageDrive>* ptrDrives = static_cast<ArrayList<StorageDrive>*>(user_param); | |
| 125 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if (ptrDrives && drive) |
| 126 | { | ||
| 127 | try | ||
| 128 | { | ||
| 129 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | StorageDrive driveObject(*drive); |
| 130 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ptrDrives->add(driveObject); |
| 131 | 1 | return true; | |
| 132 | } | ||
| 133 | ✗ | catch (...) | |
| 134 | { | ||
| 135 | } | ||
| 136 | } | ||
| 137 | ✗ | return false; | |
| 138 | } | ||
| 139 | |||
| 140 | 1 | Array<StorageDrive> StorageDrive::findAll(DriveTypeEnum driveType) | |
| 141 | { | ||
| 142 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ArrayList<StorageDrive> drives; |
| 143 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_result_t res = gate_storagedrive_enum(static_cast<uint32_t>(driveType), &StorageDrive::findAllCallback, &drives); |
| 144 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 145 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return drives.toArray(); |
| 146 | } | ||
| 147 | |||
| 148 | 1 | StorageDrive StorageDrive::findByPath(String const& path) | |
| 149 | { | ||
| 150 | gate_storagedrive_t drive; | ||
| 151 | 1 | Mem::clear(drive); | |
| 152 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t res = gate_storagedrive_find(path.c_impl(), GATE_STORAGEDRIVE_PATH, &drive); |
| 153 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 154 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return StorageDrive(drive); |
| 155 | } | ||
| 156 | 1 | StorageDrive StorageDrive::findByUid(String const& path) | |
| 157 | { | ||
| 158 | gate_storagedrive_t drive; | ||
| 159 | 1 | Mem::clear(drive); | |
| 160 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t res = gate_storagedrive_find(path.c_impl(), GATE_STORAGEDRIVE_UID, &drive); |
| 161 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 162 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return StorageDrive(drive); |
| 163 | } | ||
| 164 | 1 | StorageDrive StorageDrive::findByName(String const& path) | |
| 165 | { | ||
| 166 | gate_storagedrive_t drive; | ||
| 167 | 1 | Mem::clear(drive); | |
| 168 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t res = gate_storagedrive_find(path.c_impl(), GATE_STORAGEDRIVE_NAME, &drive); |
| 169 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 170 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return StorageDrive(drive); |
| 171 | } | ||
| 172 | ✗ | StorageDrive StorageDrive::findByDevicePath(String const& path) | |
| 173 | { | ||
| 174 | gate_storagedrive_t drive; | ||
| 175 | ✗ | Mem::clear(drive); | |
| 176 | ✗ | result_t res = gate_storagedrive_find(path.c_impl(), GATE_STORAGEDRIVE_DEVICEPATH, &drive); | |
| 177 | ✗ | GATEXX_CHECK_EXCEPTION(res); | |
| 178 | ✗ | return StorageDrive(drive); | |
| 179 | } | ||
| 180 | |||
| 181 | ✗ | ControlStream StorageDrive::openStream(enumint_t openFlags) | |
| 182 | { | ||
| 183 | ✗ | gate_controlstream_t* ptrStream = NULL; | |
| 184 | ✗ | result_t res = gate_storagedrive_openstream(&this->impl, openFlags, &ptrStream); | |
| 185 | ✗ | GATEXX_CHECK_EXCEPTION(res); | |
| 186 | ✗ | return ControlStream(ptrStream); | |
| 187 | } | ||
| 188 | |||
| 189 | } // end of namespace sys | ||
| 190 | } // end of namespace gate | ||
| 191 |