]> git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/ComponentName.c
Fix a typo when checking the 16-bit alignment of Unicode String.
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / ComponentName.c
1 /*++
2
3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 ComponentName.c
16
17 Abstract:
18
19 --*/
20
21 #include "Fat.h"
22
23 //
24 // EFI Component Name Functions
25 //
26 /**
27 Retrieves a Unicode string that is the user readable name of the driver.
28
29 This function retrieves the user readable name of a driver in the form of a
30 Unicode string. If the driver specified by This has a user readable name in
31 the language specified by Language, then a pointer to the driver name is
32 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
33 by This does not support the language specified by Language,
34 then EFI_UNSUPPORTED is returned.
35
36 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
37 EFI_COMPONENT_NAME_PROTOCOL instance.
38
39 @param Language[in] A pointer to a Null-terminated ASCII string
40 array indicating the language. This is the
41 language of the driver name that the caller is
42 requesting, and it must match one of the
43 languages specified in SupportedLanguages. The
44 number of languages supported by a driver is up
45 to the driver writer. Language is specified
46 in RFC 3066 or ISO 639-2 language code format.
47
48 @param DriverName[out] A pointer to the Unicode string to return.
49 This Unicode string is the name of the
50 driver specified by This in the language
51 specified by Language.
52
53 @retval EFI_SUCCESS The Unicode string for the Driver specified by
54 This and the language specified by Language was
55 returned in DriverName.
56
57 @retval EFI_INVALID_PARAMETER Language is NULL.
58
59 @retval EFI_INVALID_PARAMETER DriverName is NULL.
60
61 @retval EFI_UNSUPPORTED The driver specified by This does not support
62 the language specified by Language.
63
64 **/
65 EFI_STATUS
66 EFIAPI
67 FatComponentNameGetDriverName (
68 IN EFI_COMPONENT_NAME_PROTOCOL *This,
69 IN CHAR8 *Language,
70 OUT CHAR16 **DriverName
71 );
72
73
74 /**
75 Retrieves a Unicode string that is the user readable name of the controller
76 that is being managed by a driver.
77
78 This function retrieves the user readable name of the controller specified by
79 ControllerHandle and ChildHandle in the form of a Unicode string. If the
80 driver specified by This has a user readable name in the language specified by
81 Language, then a pointer to the controller name is returned in ControllerName,
82 and EFI_SUCCESS is returned. If the driver specified by This is not currently
83 managing the controller specified by ControllerHandle and ChildHandle,
84 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
85 support the language specified by Language, then EFI_UNSUPPORTED is returned.
86
87 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
88 EFI_COMPONENT_NAME_PROTOCOL instance.
89
90 @param ControllerHandle[in] The handle of a controller that the driver
91 specified by This is managing. This handle
92 specifies the controller whose name is to be
93 returned.
94
95 @param ChildHandle[in] The handle of the child controller to retrieve
96 the name of. This is an optional parameter that
97 may be NULL. It will be NULL for device
98 drivers. It will also be NULL for a bus drivers
99 that wish to retrieve the name of the bus
100 controller. It will not be NULL for a bus
101 driver that wishes to retrieve the name of a
102 child controller.
103
104 @param Language[in] A pointer to a Null-terminated ASCII string
105 array indicating the language. This is the
106 language of the driver name that the caller is
107 requesting, and it must match one of the
108 languages specified in SupportedLanguages. The
109 number of languages supported by a driver is up
110 to the driver writer. Language is specified in
111 RFC 3066 or ISO 639-2 language code format.
112
113 @param ControllerName[out] A pointer to the Unicode string to return.
114 This Unicode string is the name of the
115 controller specified by ControllerHandle and
116 ChildHandle in the language specified by
117 Language from the point of view of the driver
118 specified by This.
119
120 @retval EFI_SUCCESS The Unicode string for the user readable name in
121 the language specified by Language for the
122 driver specified by This was returned in
123 DriverName.
124
125 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
126
127 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
128 EFI_HANDLE.
129
130 @retval EFI_INVALID_PARAMETER Language is NULL.
131
132 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
133
134 @retval EFI_UNSUPPORTED The driver specified by This is not currently
135 managing the controller specified by
136 ControllerHandle and ChildHandle.
137
138 @retval EFI_UNSUPPORTED The driver specified by This does not support
139 the language specified by Language.
140
141 **/
142 EFI_STATUS
143 EFIAPI
144 FatComponentNameGetControllerName (
145 IN EFI_COMPONENT_NAME_PROTOCOL *This,
146 IN EFI_HANDLE ControllerHandle,
147 IN EFI_HANDLE ChildHandle OPTIONAL,
148 IN CHAR8 *Language,
149 OUT CHAR16 **ControllerName
150 );
151
152 //
153 // EFI Component Name Protocol
154 //
155 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gFatComponentName = {
156 FatComponentNameGetDriverName,
157 FatComponentNameGetControllerName,
158 "eng"
159 };
160
161 //
162 // EFI Component Name 2 Protocol
163 //
164 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2 = {
165 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) FatComponentNameGetDriverName,
166 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) FatComponentNameGetControllerName,
167 "en"
168 };
169
170 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatDriverNameTable[] = {
171 {
172 "eng;en",
173 L"FAT File System Driver"
174 },
175 {
176 NULL,
177 NULL
178 }
179 };
180
181 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatControllerNameTable[] = {
182 {
183 "eng;en",
184 L"FAT File System"
185 },
186 {
187 NULL,
188 NULL
189 }
190 };
191
192
193 /**
194 Retrieves a Unicode string that is the user readable name of the driver.
195
196 This function retrieves the user readable name of a driver in the form of a
197 Unicode string. If the driver specified by This has a user readable name in
198 the language specified by Language, then a pointer to the driver name is
199 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
200 by This does not support the language specified by Language,
201 then EFI_UNSUPPORTED is returned.
202
203 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
204 EFI_COMPONENT_NAME_PROTOCOL instance.
205
206 @param Language[in] A pointer to a Null-terminated ASCII string
207 array indicating the language. This is the
208 language of the driver name that the caller is
209 requesting, and it must match one of the
210 languages specified in SupportedLanguages. The
211 number of languages supported by a driver is up
212 to the driver writer. Language is specified
213 in RFC 3066 or ISO 639-2 language code format.
214
215 @param DriverName[out] A pointer to the Unicode string to return.
216 This Unicode string is the name of the
217 driver specified by This in the language
218 specified by Language.
219
220 @retval EFI_SUCCESS The Unicode string for the Driver specified by
221 This and the language specified by Language was
222 returned in DriverName.
223
224 @retval EFI_INVALID_PARAMETER Language is NULL.
225
226 @retval EFI_INVALID_PARAMETER DriverName is NULL.
227
228 @retval EFI_UNSUPPORTED The driver specified by This does not support
229 the language specified by Language.
230
231 **/
232 EFI_STATUS
233 EFIAPI
234 FatComponentNameGetDriverName (
235 IN EFI_COMPONENT_NAME_PROTOCOL *This,
236 IN CHAR8 *Language,
237 OUT CHAR16 **DriverName
238 )
239 {
240 return LookupUnicodeString2 (
241 Language,
242 This->SupportedLanguages,
243 mFatDriverNameTable,
244 DriverName,
245 (BOOLEAN)(This == &gFatComponentName)
246 );
247 }
248
249 /**
250 Retrieves a Unicode string that is the user readable name of the controller
251 that is being managed by a driver.
252
253 This function retrieves the user readable name of the controller specified by
254 ControllerHandle and ChildHandle in the form of a Unicode string. If the
255 driver specified by This has a user readable name in the language specified by
256 Language, then a pointer to the controller name is returned in ControllerName,
257 and EFI_SUCCESS is returned. If the driver specified by This is not currently
258 managing the controller specified by ControllerHandle and ChildHandle,
259 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
260 support the language specified by Language, then EFI_UNSUPPORTED is returned.
261
262 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
263 EFI_COMPONENT_NAME_PROTOCOL instance.
264
265 @param ControllerHandle[in] The handle of a controller that the driver
266 specified by This is managing. This handle
267 specifies the controller whose name is to be
268 returned.
269
270 @param ChildHandle[in] The handle of the child controller to retrieve
271 the name of. This is an optional parameter that
272 may be NULL. It will be NULL for device
273 drivers. It will also be NULL for a bus drivers
274 that wish to retrieve the name of the bus
275 controller. It will not be NULL for a bus
276 driver that wishes to retrieve the name of a
277 child controller.
278
279 @param Language[in] A pointer to a Null-terminated ASCII string
280 array indicating the language. This is the
281 language of the driver name that the caller is
282 requesting, and it must match one of the
283 languages specified in SupportedLanguages. The
284 number of languages supported by a driver is up
285 to the driver writer. Language is specified in
286 RFC 3066 or ISO 639-2 language code format.
287
288 @param ControllerName[out] A pointer to the Unicode string to return.
289 This Unicode string is the name of the
290 controller specified by ControllerHandle and
291 ChildHandle in the language specified by
292 Language from the point of view of the driver
293 specified by This.
294
295 @retval EFI_SUCCESS The Unicode string for the user readable name in
296 the language specified by Language for the
297 driver specified by This was returned in
298 DriverName.
299
300 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
301
302 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
303 EFI_HANDLE.
304
305 @retval EFI_INVALID_PARAMETER Language is NULL.
306
307 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
308
309 @retval EFI_UNSUPPORTED The driver specified by This is not currently
310 managing the controller specified by
311 ControllerHandle and ChildHandle.
312
313 @retval EFI_UNSUPPORTED The driver specified by This does not support
314 the language specified by Language.
315
316 **/
317 EFI_STATUS
318 EFIAPI
319 FatComponentNameGetControllerName (
320 IN EFI_COMPONENT_NAME_PROTOCOL *This,
321 IN EFI_HANDLE ControllerHandle,
322 IN EFI_HANDLE ChildHandle OPTIONAL,
323 IN CHAR8 *Language,
324 OUT CHAR16 **ControllerName
325 )
326 {
327 EFI_STATUS Status;
328
329 //
330 // This is a device driver, so ChildHandle must be NULL.
331 //
332 if (ChildHandle != NULL) {
333 return EFI_UNSUPPORTED;
334 }
335
336 //
337 // Make sure this driver is currently managing ControllHandle
338 //
339 Status = EfiTestManagedDevice (
340 ControllerHandle,
341 gFatDriverBinding.DriverBindingHandle,
342 &gEfiDiskIoProtocolGuid
343 );
344 if (EFI_ERROR (Status)) {
345 return Status;
346 }
347
348 return LookupUnicodeString2 (
349 Language,
350 This->SupportedLanguages,
351 mFatControllerNameTable,
352 ControllerName,
353 (BOOLEAN)(This == &gFatComponentName)
354 );
355 }