| 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/storagevolumes.hpp" | ||
| 30 | |||
| 31 | namespace gate | ||
| 32 | { | ||
| 33 | namespace sys | ||
| 34 | { | ||
| 35 | |||
| 36 | enumint_t const StorageVolume::Flag_Online = GATE_STORAGEVOLUME_FLAG_ONLINE; | ||
| 37 | enumint_t const StorageVolume::Flag_ReadOnly = GATE_STORAGEVOLUME_FLAG_READONLY; | ||
| 38 | |||
| 39 | 7 | StorageVolume::StorageVolume(StorageVolume const& src) | |
| 40 | 7 | : cached_path(src.cached_path), | |
| 41 | 7 | cached_name(src.cached_name), | |
| 42 | 7 | cached_uid(src.cached_uid), | |
| 43 | 7 | cached_device_path(src.cached_device_path), | |
| 44 | 7 | cached_serial(src.cached_serial), | |
| 45 | 7 | cached_device_name(src.cached_device_name), | |
| 46 | 7 | cached_fs_name(src.cached_fs_name) | |
| 47 | { | ||
| 48 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | gate_mem_copy(&this->impl, &src.impl, sizeof(this->impl)); |
| 49 | 7 | } | |
| 50 | ✗ | StorageVolume& StorageVolume::operator=(StorageVolume const& src) | |
| 51 | { | ||
| 52 | ✗ | if (this != &src) | |
| 53 | { | ||
| 54 | ✗ | gate_mem_copy(&this->impl, &src.impl, sizeof(this->impl)); | |
| 55 | ✗ | this->cached_path = src.cached_path; | |
| 56 | ✗ | this->cached_name = src.cached_name; | |
| 57 | ✗ | this->cached_uid = src.cached_uid; | |
| 58 | ✗ | this->cached_device_path = src.cached_device_path; | |
| 59 | ✗ | this->cached_serial = src.cached_serial; | |
| 60 | ✗ | this->cached_device_name = src.cached_device_name; | |
| 61 | ✗ | this->cached_fs_name = src.cached_fs_name; | |
| 62 | } | ||
| 63 | ✗ | return *this; | |
| 64 | } | ||
| 65 | 27 | StorageVolume::~StorageVolume() noexcept | |
| 66 | { | ||
| 67 | 27 | } | |
| 68 | ✗ | ControlStream StorageVolume::openStream(enumint_t openFlags) | |
| 69 | { | ||
| 70 | ✗ | gate_controlstream_t* ptr_stream = NULL; | |
| 71 | ✗ | result_t res = gate_storagevolume_openstream(&this->impl, openFlags, &ptr_stream); | |
| 72 | ✗ | GATEXX_CHECK_EXCEPTION(res); | |
| 73 | ✗ | ControlStream strm(ptr_stream); | |
| 74 | ✗ | return strm; | |
| 75 | } | ||
| 76 | |||
| 77 | 20 | StorageVolume::StorageVolume(gate_storagevolume_t const& impl) | |
| 78 | 20 | : cached_path(impl.path), | |
| 79 | 20 | cached_name(impl.name), | |
| 80 | 20 | cached_uid(impl.uid), | |
| 81 | 20 | cached_device_path(impl.devicepath), | |
| 82 | 20 | cached_serial(impl.serial), | |
| 83 | 20 | cached_device_name(impl.devicename), | |
| 84 |
6/12✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 20 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 20 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 20 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 20 times.
✗ Branch 18 not taken.
|
20 | cached_fs_name(impl.fsname) |
| 85 | { | ||
| 86 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | gate_mem_copy(&this->impl, &impl, sizeof(impl)); |
| 87 | 20 | } | |
| 88 | |||
| 89 | 5 | String StorageVolume::Path() const | |
| 90 | { | ||
| 91 | 5 | return this->cached_path; | |
| 92 | } | ||
| 93 | 5 | String StorageVolume::Name() const | |
| 94 | { | ||
| 95 | 5 | return this->cached_name; | |
| 96 | } | ||
| 97 | 5 | String StorageVolume::Uid() const | |
| 98 | { | ||
| 99 | 5 | return this->cached_uid; | |
| 100 | } | ||
| 101 | ✗ | String StorageVolume::DevicePath() const | |
| 102 | { | ||
| 103 | ✗ | return this->cached_device_path; | |
| 104 | } | ||
| 105 | 5 | String StorageVolume::Serial() const | |
| 106 | { | ||
| 107 | 5 | return this->cached_serial; | |
| 108 | } | ||
| 109 | ✗ | String StorageVolume::DeviceName() const | |
| 110 | { | ||
| 111 | ✗ | return this->cached_device_name; | |
| 112 | } | ||
| 113 | 5 | String StorageVolume::FileSystemName() const | |
| 114 | { | ||
| 115 | 5 | return this->cached_fs_name; | |
| 116 | } | ||
| 117 | 5 | uint64_t StorageVolume::Size() const | |
| 118 | { | ||
| 119 | 5 | return this->impl.size; | |
| 120 | } | ||
| 121 | ✗ | uint64_t StorageVolume::SizeUsed() const | |
| 122 | { | ||
| 123 | ✗ | return this->impl.sizeused; | |
| 124 | } | ||
| 125 | ✗ | uint64_t StorageVolume::SizeFree() const | |
| 126 | { | ||
| 127 | ✗ | return this->impl.sizefree; | |
| 128 | } | ||
| 129 | 5 | StorageVolume::TypeEnum StorageVolume::VolumeType() const | |
| 130 | { | ||
| 131 | 5 | return (TypeEnum)this->impl.volumetype; | |
| 132 | } | ||
| 133 | ✗ | enumint_t StorageVolume::Flags() const | |
| 134 | { | ||
| 135 | ✗ | return this->impl.flags; | |
| 136 | } | ||
| 137 | |||
| 138 | 5 | gate_storagevolume_t const* StorageVolume::c_impl() const | |
| 139 | { | ||
| 140 | 5 | return &this->impl; | |
| 141 | } | ||
| 142 | |||
| 143 | 5 | gate_bool_t StorageVolume::findAllCallback(gate_storagevolume_t const* volume, void* user_param) | |
| 144 | { | ||
| 145 | 5 | ArrayList<StorageVolume>* vol_list = static_cast<ArrayList<StorageVolume>*>(user_param); | |
| 146 | try | ||
| 147 | { | ||
| 148 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
10 | StorageVolume vol(*volume); |
| 149 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | vol_list->add(vol); |
| 150 | } | ||
| 151 | ✗ | catch (...) | |
| 152 | { | ||
| 153 | } | ||
| 154 | 5 | return true; | |
| 155 | } | ||
| 156 | |||
| 157 | 1 | Array<StorageVolume> StorageVolume::findAll() | |
| 158 | { | ||
| 159 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ArrayList<StorageVolume> vol_list; |
| 160 | |||
| 161 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t res = gate_storagevolume_enum(&StorageVolume::findAllCallback, &vol_list); |
| 162 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 163 | |||
| 164 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return vol_list.toArray(); |
| 165 | } | ||
| 166 | |||
| 167 | 5 | StorageVolume StorageVolume::findByPath(String const& path) | |
| 168 | { | ||
| 169 | gate_storagevolume_t vol; | ||
| 170 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | result_t res = gate_storagevolume_find(path.c_impl(), GATE_STORAGEVOLUME_PATH, &vol); |
| 171 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
5 | GATEXX_CHECK_EXCEPTION(res); |
| 172 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
10 | return StorageVolume(vol); |
| 173 | } | ||
| 174 | 5 | StorageVolume StorageVolume::findByUid(String const& path) | |
| 175 | { | ||
| 176 | gate_storagevolume_t vol; | ||
| 177 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | result_t res = gate_storagevolume_find(path.c_impl(), GATE_STORAGEVOLUME_UID, &vol); |
| 178 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
5 | GATEXX_CHECK_EXCEPTION(res); |
| 179 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
10 | return StorageVolume(vol); |
| 180 | } | ||
| 181 | 5 | StorageVolume StorageVolume::findByName(String const& path) | |
| 182 | { | ||
| 183 | gate_storagevolume_t vol; | ||
| 184 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | result_t res = gate_storagevolume_find(path.c_impl(), GATE_STORAGEVOLUME_NAME, &vol); |
| 185 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
5 | GATEXX_CHECK_EXCEPTION(res); |
| 186 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
10 | return StorageVolume(vol); |
| 187 | } | ||
| 188 | |||
| 189 | } // end of namespace sys | ||
| 190 | } // end of namespace gate | ||
| 191 |