GCC Code Coverage Report


Directory: src/gate/
File: src/gate/system/cxx_storagedrives.cpp
Date: 2026-03-20 22:56:14
Exec Total Coverage
Lines: 60 85 70.6%
Functions: 16 24 66.7%
Branches: 23 72 31.9%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2026, 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
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 GATEXX_TRY_IGNORE({
128 StorageDrive driveObject(*drive);
129 ptrDrives->add(driveObject);
130 return true;
131 });
132 }
133 return false;
134 }
135
136 1 Array<StorageDrive> StorageDrive::findAll(DriveTypeEnum driveType)
137 {
138
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 ArrayList<StorageDrive> drives;
139
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);
140
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(res);
141
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return drives.toArray();
142 }
143
144 1 StorageDrive StorageDrive::findByPath(String const& path)
145 {
146 gate_storagedrive_t drive;
147 1 Mem::clear(drive);
148
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);
149
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(res);
150
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return StorageDrive(drive);
151 }
152 1 StorageDrive StorageDrive::findByUid(String const& path)
153 {
154 gate_storagedrive_t drive;
155 1 Mem::clear(drive);
156
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);
157
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(res);
158
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return StorageDrive(drive);
159 }
160 1 StorageDrive StorageDrive::findByName(String const& path)
161 {
162 gate_storagedrive_t drive;
163 1 Mem::clear(drive);
164
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);
165
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(res);
166
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return StorageDrive(drive);
167 }
168 StorageDrive StorageDrive::findByDevicePath(String const& path)
169 {
170 gate_storagedrive_t drive;
171 Mem::clear(drive);
172 result_t res = gate_storagedrive_find(path.c_impl(), GATE_STORAGEDRIVE_DEVICEPATH, &drive);
173 GATEXX_CHECK_EXCEPTION(res);
174 return StorageDrive(drive);
175 }
176
177 ControlStream StorageDrive::openStream(enumint_t openFlags)
178 {
179 gate_controlstream_t* ptrStream = NULL;
180 result_t res = gate_storagedrive_openstream(&this->impl, openFlags, &ptrStream);
181 GATEXX_CHECK_EXCEPTION(res);
182 return ControlStream(ptrStream);
183 }
184
185 } // end of namespace sys
186 } // end of namespace gate
187