1 /**@file 2 3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> 4 This program and the accompanying materials 5 are licensed and made available under the terms and conditions of the BSD License 6 which accompanies this 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 Module Name: 13 14 ComponentName.c 15 16 Abstract: 17 18 **/ 19 // 20 // The package level header files this module uses 21 // 22 #include <Uefi.h> 23 #include <WinNtDxe.h> 24 // 25 // The protocols, PPI and GUID defintions for this module 26 // 27 #include <Guid/FileSystemVolumeLabelInfo.h> 28 #include <Protocol/WinNtIo.h> 29 #include <Protocol/ComponentName.h> 30 #include <Guid/FileInfo.h> 31 #include <Protocol/DriverBinding.h> 32 #include <Guid/FileSystemInfo.h> 33 #include <Protocol/SimpleFileSystem.h> 34 // 35 // The Library classes this module consumes 36 // 37 #include <Library/DebugLib.h> 38 #include <Library/BaseLib.h> 39 #include <Library/UefiDriverEntryPoint.h> 40 #include <Library/UefiLib.h> 41 #include <Library/BaseMemoryLib.h> 42 #include <Library/UefiBootServicesTableLib.h> 43 #include <Library/MemoryAllocationLib.h> 44 45 #include "WinNtSimpleFileSystem.h" 46 47 // 48 // EFI Component Name Functions 49 // 50 /** 51 Retrieves a Unicode string that is the user readable name of the driver. 52 53 This function retrieves the user readable name of a driver in the form of a 54 Unicode string. If the driver specified by This has a user readable name in 55 the language specified by Language, then a pointer to the driver name is 56 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 57 by This does not support the language specified by Language, 58 then EFI_UNSUPPORTED is returned. 59 60 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 61 EFI_COMPONENT_NAME_PROTOCOL instance. 62 63 @param Language[in] A pointer to a Null-terminated ASCII string 64 array indicating the language. This is the 65 language of the driver name that the caller is 66 requesting, and it must match one of the 67 languages specified in SupportedLanguages. The 68 number of languages supported by a driver is up 69 to the driver writer. Language is specified 70 in RFC 4646 or ISO 639-2 language code format. 71 72 @param DriverName[out] A pointer to the Unicode string to return. 73 This Unicode string is the name of the 74 driver specified by This in the language 75 specified by Language. 76 77 @retval EFI_SUCCESS The Unicode string for the Driver specified by 78 This and the language specified by Language was 79 returned in DriverName. 80 81 @retval EFI_INVALID_PARAMETER Language is NULL. 82 83 @retval EFI_INVALID_PARAMETER DriverName is NULL. 84 85 @retval EFI_UNSUPPORTED The driver specified by This does not support 86 the language specified by Language. 87 88 **/ 89 EFI_STATUS 90 EFIAPI 91 WinNtSimpleFileSystemComponentNameGetDriverName ( 92 IN EFI_COMPONENT_NAME_PROTOCOL *This, 93 IN CHAR8 *Language, 94 OUT CHAR16 **DriverName 95 ); 96 97 98 /** 99 Retrieves a Unicode string that is the user readable name of the controller 100 that is being managed by a driver. 101 102 This function retrieves the user readable name of the controller specified by 103 ControllerHandle and ChildHandle in the form of a Unicode string. If the 104 driver specified by This has a user readable name in the language specified by 105 Language, then a pointer to the controller name is returned in ControllerName, 106 and EFI_SUCCESS is returned. If the driver specified by This is not currently 107 managing the controller specified by ControllerHandle and ChildHandle, 108 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 109 support the language specified by Language, then EFI_UNSUPPORTED is returned. 110 111 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 112 EFI_COMPONENT_NAME_PROTOCOL instance. 113 114 @param ControllerHandle[in] The handle of a controller that the driver 115 specified by This is managing. This handle 116 specifies the controller whose name is to be 117 returned. 118 119 @param ChildHandle[in] The handle of the child controller to retrieve 120 the name of. This is an optional parameter that 121 may be NULL. It will be NULL for device 122 drivers. It will also be NULL for a bus drivers 123 that wish to retrieve the name of the bus 124 controller. It will not be NULL for a bus 125 driver that wishes to retrieve the name of a 126 child controller. 127 128 @param Language[in] A pointer to a Null-terminated ASCII string 129 array indicating the language. This is the 130 language of the driver name that the caller is 131 requesting, and it must match one of the 132 languages specified in SupportedLanguages. The 133 number of languages supported by a driver is up 134 to the driver writer. Language is specified in 135 RFC 4646 or ISO 639-2 language code format. 136 137 @param ControllerName[out] A pointer to the Unicode string to return. 138 This Unicode string is the name of the 139 controller specified by ControllerHandle and 140 ChildHandle in the language specified by 141 Language from the point of view of the driver 142 specified by This. 143 144 @retval EFI_SUCCESS The Unicode string for the user readable name in 145 the language specified by Language for the 146 driver specified by This was returned in 147 DriverName. 148 149 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE. 150 151 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 152 EFI_HANDLE. 153 154 @retval EFI_INVALID_PARAMETER Language is NULL. 155 156 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 157 158 @retval EFI_UNSUPPORTED The driver specified by This is not currently 159 managing the controller specified by 160 ControllerHandle and ChildHandle. 161 162 @retval EFI_UNSUPPORTED The driver specified by This does not support 163 the language specified by Language. 164 165 **/ 166 EFI_STATUS 167 EFIAPI 168 WinNtSimpleFileSystemComponentNameGetControllerName ( 169 IN EFI_COMPONENT_NAME_PROTOCOL *This, 170 IN EFI_HANDLE ControllerHandle, 171 IN EFI_HANDLE ChildHandle OPTIONAL, 172 IN CHAR8 *Language, 173 OUT CHAR16 **ControllerName 174 ); 175 176 177 // 178 // EFI Component Name Protocol 179 // 180 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gWinNtSimpleFileSystemComponentName = { 181 WinNtSimpleFileSystemComponentNameGetDriverName, 182 WinNtSimpleFileSystemComponentNameGetControllerName, 183 "eng" 184 }; 185 186 // 187 // EFI Component Name 2 Protocol 188 // 189 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gWinNtSimpleFileSystemComponentName2 = { 190 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) WinNtSimpleFileSystemComponentNameGetDriverName, 191 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) WinNtSimpleFileSystemComponentNameGetControllerName, 192 "en" 193 }; 194 195 196 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mWinNtSimpleFileSystemDriverNameTable[] = { 197 { 198 "eng;en", 199 L"Windows Simple File System Driver" 200 }, 201 { 202 NULL, 203 NULL 204 } 205 }; 206 207 /** 208 Retrieves a Unicode string that is the user readable name of the driver. 209 210 This function retrieves the user readable name of a driver in the form of a 211 Unicode string. If the driver specified by This has a user readable name in 212 the language specified by Language, then a pointer to the driver name is 213 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 214 by This does not support the language specified by Language, 215 then EFI_UNSUPPORTED is returned. 216 217 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 218 EFI_COMPONENT_NAME_PROTOCOL instance. 219 220 @param Language[in] A pointer to a Null-terminated ASCII string 221 array indicating the language. This is the 222 language of the driver name that the caller is 223 requesting, and it must match one of the 224 languages specified in SupportedLanguages. The 225 number of languages supported by a driver is up 226 to the driver writer. Language is specified 227 in RFC 4646 or ISO 639-2 language code format. 228 229 @param DriverName[out] A pointer to the Unicode string to return. 230 This Unicode string is the name of the 231 driver specified by This in the language 232 specified by Language. 233 234 @retval EFI_SUCCESS The Unicode string for the Driver specified by 235 This and the language specified by Language was 236 returned in DriverName. 237 238 @retval EFI_INVALID_PARAMETER Language is NULL. 239 240 @retval EFI_INVALID_PARAMETER DriverName is NULL. 241 242 @retval EFI_UNSUPPORTED The driver specified by This does not support 243 the language specified by Language. 244 245 **/ 246 EFI_STATUS 247 EFIAPI 248 WinNtSimpleFileSystemComponentNameGetDriverName ( 249 IN EFI_COMPONENT_NAME_PROTOCOL *This, 250 IN CHAR8 *Language, 251 OUT CHAR16 **DriverName 252 ) 253 { 254 return LookupUnicodeString2 ( 255 Language, 256 This->SupportedLanguages, 257 mWinNtSimpleFileSystemDriverNameTable, 258 DriverName, 259 (BOOLEAN)(This == &gWinNtSimpleFileSystemComponentName) 260 ); 261 } 262 263 /** 264 Retrieves a Unicode string that is the user readable name of the controller 265 that is being managed by a driver. 266 267 This function retrieves the user readable name of the controller specified by 268 ControllerHandle and ChildHandle in the form of a Unicode string. If the 269 driver specified by This has a user readable name in the language specified by 270 Language, then a pointer to the controller name is returned in ControllerName, 271 and EFI_SUCCESS is returned. If the driver specified by This is not currently 272 managing the controller specified by ControllerHandle and ChildHandle, 273 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 274 support the language specified by Language, then EFI_UNSUPPORTED is returned. 275 276 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 277 EFI_COMPONENT_NAME_PROTOCOL instance. 278 279 @param ControllerHandle[in] The handle of a controller that the driver 280 specified by This is managing. This handle 281 specifies the controller whose name is to be 282 returned. 283 284 @param ChildHandle[in] The handle of the child controller to retrieve 285 the name of. This is an optional parameter that 286 may be NULL. It will be NULL for device 287 drivers. It will also be NULL for a bus drivers 288 that wish to retrieve the name of the bus 289 controller. It will not be NULL for a bus 290 driver that wishes to retrieve the name of a 291 child controller. 292 293 @param Language[in] A pointer to a Null-terminated ASCII string 294 array indicating the language. This is the 295 language of the driver name that the caller is 296 requesting, and it must match one of the 297 languages specified in SupportedLanguages. The 298 number of languages supported by a driver is up 299 to the driver writer. Language is specified in 300 RFC 4646 or ISO 639-2 language code format. 301 302 @param ControllerName[out] A pointer to the Unicode string to return. 303 This Unicode string is the name of the 304 controller specified by ControllerHandle and 305 ChildHandle in the language specified by 306 Language from the point of view of the driver 307 specified by This. 308 309 @retval EFI_SUCCESS The Unicode string for the user readable name in 310 the language specified by Language for the 311 driver specified by This was returned in 312 DriverName. 313 314 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE. 315 316 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 317 EFI_HANDLE. 318 319 @retval EFI_INVALID_PARAMETER Language is NULL. 320 321 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 322 323 @retval EFI_UNSUPPORTED The driver specified by This is not currently 324 managing the controller specified by 325 ControllerHandle and ChildHandle. 326 327 @retval EFI_UNSUPPORTED The driver specified by This does not support 328 the language specified by Language. 329 330 **/ 331 EFI_STATUS 332 EFIAPI 333 WinNtSimpleFileSystemComponentNameGetControllerName ( 334 IN EFI_COMPONENT_NAME_PROTOCOL *This, 335 IN EFI_HANDLE ControllerHandle, 336 IN EFI_HANDLE ChildHandle OPTIONAL, 337 IN CHAR8 *Language, 338 OUT CHAR16 **ControllerName 339 ) 340 { 341 EFI_STATUS Status; 342 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem; 343 WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *Private; 344 345 // 346 // This is a device driver, so ChildHandle must be NULL. 347 // 348 if (ChildHandle != NULL) { 349 return EFI_UNSUPPORTED; 350 } 351 352 // 353 // Make sure this driver is currently managing ControllerHandle 354 // 355 Status = EfiTestManagedDevice ( 356 ControllerHandle, 357 gWinNtSimpleFileSystemDriverBinding.DriverBindingHandle, 358 &gEfiWinNtIoProtocolGuid 359 ); 360 if (EFI_ERROR (Status)) { 361 return EFI_UNSUPPORTED; 362 } 363 // 364 // Get our context back 365 // 366 Status = gBS->OpenProtocol ( 367 ControllerHandle, 368 &gEfiSimpleFileSystemProtocolGuid, 369 (VOID **) &SimpleFileSystem, 370 gWinNtSimpleFileSystemDriverBinding.DriverBindingHandle, 371 ControllerHandle, 372 EFI_OPEN_PROTOCOL_GET_PROTOCOL 373 ); 374 if (EFI_ERROR (Status)) { 375 return EFI_UNSUPPORTED; 376 } 377 378 Private = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem); 379 380 return LookupUnicodeString2 ( 381 Language, 382 This->SupportedLanguages, 383 Private->ControllerNameTable, 384 ControllerName, 385 (BOOLEAN)(This == &gWinNtSimpleFileSystemComponentName) 386 ); 387 } 388