GCC Code Coverage Report


Directory: src/gate/
File: src/gate/system/cxx_storagedrives.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 88 0.0%
Functions: 0 24 0.0%
Branches: 0 72 0.0%

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 StorageDrive::StorageDrive(gate_storagedrive_t const& drive)
36 {
37 Mem::copy(this->impl, drive);
38 this->cached_path = String(this->impl.path);
39 this->cached_name = String(this->impl.name);
40 this->cached_uid = String(this->impl.uid);
41 this->cached_device_path = String(this->impl.devicepath);
42 this->cached_product_name = String(this->impl.productname);
43 this->cached_vendor = String(this->impl.vendor);
44 }
45
46 StorageDrive::StorageDrive(StorageDrive const& src)
47 : cached_path(src.cached_path),
48 cached_name(src.cached_name),
49 cached_uid(src.cached_uid),
50 cached_device_path(src.cached_device_path),
51 cached_product_name(src.cached_product_name),
52 cached_vendor(src.cached_vendor)
53 {
54 Mem::copy(this->impl, src.impl);
55 }
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 StorageDrive::~StorageDrive() noexcept
65 {
66 }
67
68 String StorageDrive::Path() const
69 {
70 return this->cached_path;
71 }
72 String StorageDrive::Name() const
73 {
74 return this->cached_name;
75 }
76 String StorageDrive::Uid() const
77 {
78 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 uint64_t StorageDrive::Size() const
93 {
94 return this->impl.size;
95 }
96 uint64_t StorageDrive::BlockCount() const
97 {
98 return this->impl.blockcount;
99 }
100 uint64_t StorageDrive::BlockSize() const
101 {
102 return this->impl.blocksize;
103 }
104 uint32_t StorageDrive::DeviceIndex() const
105 {
106 return this->impl.deviceindex;
107 }
108 StorageDrive::DriveTypeEnum StorageDrive::DriveType() const
109 {
110 return static_cast<StorageDrive::DriveTypeEnum>(this->impl.drivetype);
111 }
112 enumint_t StorageDrive::Flags() const
113 {
114 return this->impl.flags;
115 }
116
117 gate_storagedrive_t const* StorageDrive::c_impl() const
118 {
119 return &this->impl;
120 }
121
122 bool_t StorageDrive::findAllCallback(gate_storagedrive_t const* drive, void* user_param)
123 {
124 ArrayList<StorageDrive>* ptrDrives = static_cast<ArrayList<StorageDrive>*>(user_param);
125 if (ptrDrives && drive)
126 {
127 try
128 {
129 StorageDrive driveObject(*drive);
130 ptrDrives->add(driveObject);
131 return true;
132 }
133 catch (...)
134 {
135 }
136 }
137 return false;
138 }
139
140 Array<StorageDrive> StorageDrive::findAll(DriveTypeEnum driveType)
141 {
142 ArrayList<StorageDrive> drives;
143 gate_result_t res = gate_storagedrive_enum(static_cast<uint32_t>(driveType), &StorageDrive::findAllCallback, &drives);
144 GATEXX_CHECK_EXCEPTION(res);
145 return drives.toArray();
146 }
147
148 StorageDrive StorageDrive::findByPath(String const& path)
149 {
150 gate_storagedrive_t drive;
151 Mem::clear(drive);
152 result_t res = gate_storagedrive_find(path.c_impl(), GATE_STORAGEDRIVE_PATH, &drive);
153 GATEXX_CHECK_EXCEPTION(res);
154 return StorageDrive(drive);
155 }
156 StorageDrive StorageDrive::findByUid(String const& path)
157 {
158 gate_storagedrive_t drive;
159 Mem::clear(drive);
160 result_t res = gate_storagedrive_find(path.c_impl(), GATE_STORAGEDRIVE_UID, &drive);
161 GATEXX_CHECK_EXCEPTION(res);
162 return StorageDrive(drive);
163 }
164 StorageDrive StorageDrive::findByName(String const& path)
165 {
166 gate_storagedrive_t drive;
167 Mem::clear(drive);
168 result_t res = gate_storagedrive_find(path.c_impl(), GATE_STORAGEDRIVE_NAME, &drive);
169 GATEXX_CHECK_EXCEPTION(res);
170 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