1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "fs_dm_mock.h"
16
17 #ifdef __cplusplus
18 #if __cplusplus
19 extern "C" {
20 #endif
21 #endif
22
23 // start wrap FsDmInitDmDev
24 static FsdminitdmdevFunc g_FsDmInitDmDev = NULL;
UpdateFsdminitdmdevFunc(FsdminitdmdevFunc func)25 void UpdateFsdminitdmdevFunc(FsdminitdmdevFunc func)
26 {
27 g_FsDmInitDmDev = func;
28 }
29
__wrap_FsDmInitDmDev(char * devPath,bool useSocket)30 int __wrap_FsDmInitDmDev(char *devPath, bool useSocket)
31 {
32 if (g_FsDmInitDmDev) {
33 return g_FsDmInitDmDev(devPath, useSocket);
34 } else {
35 return __real_FsDmInitDmDev(devPath, useSocket);
36 }
37 }
38
39 // start wrap FsDmCreateDevice
40 static FsdmcreatedeviceFunc g_FsDmCreateDevice = NULL;
UpdateFsdmcreatedeviceFunc(FsdmcreatedeviceFunc func)41 void UpdateFsdmcreatedeviceFunc(FsdmcreatedeviceFunc func)
42 {
43 g_FsDmCreateDevice = func;
44 }
45
__wrap_FsDmCreateDevice(char ** dmDevPath,const char * devName,DmVerityTarget * target)46 int __wrap_FsDmCreateDevice(char **dmDevPath, const char *devName, DmVerityTarget *target)
47 {
48 if (g_FsDmCreateDevice) {
49 return g_FsDmCreateDevice(dmDevPath, devName, target);
50 } else {
51 return __real_FsDmCreateDevice(dmDevPath, devName, target);
52 }
53 }
54
55 // start wrap FsDmRemoveDevice
56 static FsdmremovedeviceFunc g_FsDmRemoveDevice = NULL;
UpdateFsdmremovedeviceFunc(FsdmremovedeviceFunc func)57 void UpdateFsdmremovedeviceFunc(FsdmremovedeviceFunc func)
58 {
59 g_FsDmRemoveDevice = func;
60 }
61
__wrap_FsDmRemoveDevice(const char * devName)62 int __wrap_FsDmRemoveDevice(const char *devName)
63 {
64 if (g_FsDmRemoveDevice) {
65 return g_FsDmRemoveDevice(devName);
66 } else {
67 return __real_FsDmRemoveDevice(devName);
68 }
69 }
70
71 // start wrap LoadDmDeviceTable
72 static LoaddmdevicetableFunc g_LoadDmDeviceTable = NULL;
UpdateLoaddmdevicetableFunc(LoaddmdevicetableFunc func)73 void UpdateLoaddmdevicetableFunc(LoaddmdevicetableFunc func)
74 {
75 g_LoadDmDeviceTable = func;
76 }
77
__wrap_LoadDmDeviceTable(int fd,const char * devName,DmVerityTarget * target,int dmType)78 int __wrap_LoadDmDeviceTable(int fd, const char *devName, DmVerityTarget *target, int dmType)
79 {
80 if (g_LoadDmDeviceTable) {
81 return g_LoadDmDeviceTable(fd, devName, target, dmType);
82 } else {
83 return __real_LoadDmDeviceTable(fd, devName, target, dmType);
84 }
85 }
86
87 // start wrap DmGetDeviceName
88 static DmgetdevicenameFunc g_DmGetDeviceName = NULL;
UpdateDmgetdevicenameFunc(DmgetdevicenameFunc func)89 void UpdateDmgetdevicenameFunc(DmgetdevicenameFunc func)
90 {
91 g_DmGetDeviceName = func;
92 }
93
__wrap_DmGetDeviceName(int fd,const char * devName,char * outDevName,const uint64_t outDevNameLen)94 int __wrap_DmGetDeviceName(int fd, const char *devName, char *outDevName, const uint64_t outDevNameLen)
95 {
96 if (g_DmGetDeviceName) {
97 return g_DmGetDeviceName(fd, devName, outDevName, outDevNameLen);
98 } else {
99 return __real_DmGetDeviceName(fd, devName, outDevName, outDevNameLen);
100 }
101 }
102
103 // start wrap ActiveDmDevice
104 static ActivedmdeviceFunc g_ActiveDmDevice = NULL;
UpdateActivedmdeviceFunc(ActivedmdeviceFunc func)105 void UpdateActivedmdeviceFunc(ActivedmdeviceFunc func)
106 {
107 g_ActiveDmDevice = func;
108 }
109
__wrap_ActiveDmDevice(int fd,const char * devName)110 int __wrap_ActiveDmDevice(int fd, const char *devName)
111 {
112 if (g_ActiveDmDevice) {
113 return g_ActiveDmDevice(fd, devName);
114 } else {
115 return __real_ActiveDmDevice(fd, devName);
116 }
117 }
118
119 // start wrap InitDmIo
120 static InitdmioFunc g_InitDmIo = NULL;
UpdateInitdmioFunc(InitdmioFunc func)121 void UpdateInitdmioFunc(InitdmioFunc func)
122 {
123 g_InitDmIo = func;
124 }
125
__wrap_InitDmIo(struct dm_ioctl * io,const char * devName)126 int __wrap_InitDmIo(struct dm_ioctl *io, const char *devName)
127 {
128 if (g_InitDmIo) {
129 return g_InitDmIo(io, devName);
130 } else {
131 return __real_InitDmIo(io, devName);
132 }
133 }
134
135 // start wrap CreateDmDev
136 static CreatedmdevFunc g_CreateDmDev = NULL;
UpdateCreatedmdevFunc(CreatedmdevFunc func)137 void UpdateCreatedmdevFunc(CreatedmdevFunc func)
138 {
139 g_CreateDmDev = func;
140 }
141
__wrap_CreateDmDev(int fd,const char * devName)142 int __wrap_CreateDmDev(int fd, const char *devName)
143 {
144 if (g_CreateDmDev) {
145 return g_CreateDmDev(fd, devName);
146 } else {
147 return __real_CreateDmDev(fd, devName);
148 }
149 }
150
151 // start wrap GetDmDevPath
152 static GetdmdevpathFunc g_GetDmDevPath = NULL;
UpdateGetdmdevpathFunc(GetdmdevpathFunc func)153 void UpdateGetdmdevpathFunc(GetdmdevpathFunc func)
154 {
155 g_GetDmDevPath = func;
156 }
157
__wrap_GetDmDevPath(int fd,char ** dmDevPath,const char * devName)158 int __wrap_GetDmDevPath(int fd, char **dmDevPath, const char *devName)
159 {
160 if (g_GetDmDevPath) {
161 return g_GetDmDevPath(fd, dmDevPath, devName);
162 } else {
163 return __real_GetDmDevPath(fd, dmDevPath, devName);
164 }
165 }
166
167 // start wrap GetDmStatusInfo
168 static GetdmstatusinfoFunc g_GetDmStatusInfo = NULL;
UpdateGetdmstatusinfoFunc(GetdmstatusinfoFunc func)169 void UpdateGetdmstatusinfoFunc(GetdmstatusinfoFunc func)
170 {
171 g_GetDmStatusInfo = func;
172 }
173
__wrap_GetDmStatusInfo(const char * name,struct dm_ioctl * io)174 bool __wrap_GetDmStatusInfo(const char *name, struct dm_ioctl *io)
175 {
176 if (g_GetDmStatusInfo) {
177 return g_GetDmStatusInfo(name, io);
178 } else {
179 return __real_GetDmStatusInfo(name, io);
180 }
181 }
182
183 #ifdef __cplusplus
184 #if __cplusplus
185 }
186 #endif
187 #endif
188