/** @file
Device Abstraction Utility Routines
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Depends upon: <kfile.h>
**/
#ifndef __DEV_UTILITY_H__
#define __DEV_UTILITY_H__
#define CON_COOKIE 0x62416F49 ///< 'IoAb'
typedef enum {
PathAbsolute = 0,
PathRelative,
PathMapping,
PathError
} PATH_CLASS;
typedef struct _Device_Node {
LIST_ENTRY DevList; ///< List of registered device abstractions
const CHAR16 *DevName;
const GUID *DevProto;
void *InstanceList; ///< Array of instances for this device
FO_OPEN OpenFunc;
UINT32 InstanceSize; ///< Size of each instance in the InstanceList
UINT32 NumInstances; ///< Number of instances in InstanceList
UINT32 OpModes; ///< Supported modes of operation
} DeviceNode;
__BEGIN_DECLS
extern LIST_ENTRY daDeviceList; ///< List of registered devices.
extern DeviceNode *daDefaultDevice; ///< Device to use if nothing else found
extern DeviceNode *daRootDevice; ///< Device containing the root file system
extern DeviceNode *daCurrentDevice; ///< Device currently being accessed
/** Add a new device to the device list.
@param DevName Name of the device to add.
@param DevProto Pointer to the GUID identifying the protocol associated with this device.
If DevProto is NULL, startup code will not try to find instances
of this device.
@param OpenFunc Pointer to the device's Open function.
@param InstanceList Optional pointer to the device's initialized instance list.
If InstanceList is NULL, the application startup code will
scan for instances of the protocol identified by DevProto and
populate the InstanceList in the order those protocols are found.
@param NumInstance Number of instances in InstanceList.
@param Modes Bit-mapped flags indicating operations (R, W, RW, ...) permitted to this device.
**/
DeviceNode * EFIAPI __DevRegister( const CHAR16 *DevName, GUID *DevProto, FO_OPEN OpenFunc,
void *InstanceList, int NumInstance, UINT32 InstanceSize, UINT32 Modes);
/** Find a DeviceNode matching DevName or DevProto, or both.
If DevName is NULL, then the device name is not used in the search.
If DevProto is NULL, then the protocol GUID is not used in the search.
If both are NULL, then INVALID_PARAMETER is returned.
If both DevName and DevProto are specified, then both must match.
If both are specified but only one matches, then DEVICE_ERROR is returned.
@param DevName Name of the Device Abstraction to find.
@param DevProto GUID of the Protocol associated with the Device Abstraction.
@param Node Pointer to the pointer to receive the found Device Node's address.
@retval RETURN_SUCCESS The desired Device Node was found.
@retval RETURN_INVALID_PARAMETER Both DevName and DevProto are NULL or Node is NULL.
@retval RETURN_DEVICE_ERROR One, but not both, of DevNode and DevProto matched.
**/
EFI_STATUS EFIAPI __DevSearch( CHAR16 *DevName, GUID *DevProto, DeviceNode **Node);
/** Identify the type of path pointed to by Path.
Paths are classified based upon their initial character sequences.
^\\ Absolute Path
^\. Relative Path
^[^:\\]: Mapping Path
.* Relative Path
Mapping paths are broken into two parts at the ':'. The part to the left of the ':'
is the Map Name, pointed to by Path, and the part to the right of the ':' is pointed
to by NewPath.
If Path was not a Mapping Path, then NewPath is set to Path.
@param[in] Path Pointer to the path to be classified.
@param[out] NewPath Pointer to the path portion of a mapping path.
@retval PathAbsolute Path is an absolute path. NewPath points to the first '\'.
@retval PathRelative Path is a relative path. NewPath = Path.
@retval PathMapping Path is a mapping path. NewPath points to the ':'.
@retval PathError Path is NULL.
**/
PATH_CLASS EFIAPI ClassifyPath(IN wchar_t *Path, OUT wchar_t **NewPath, int * const Length);
/* Normalize a narrow-character path and produce a wide-character path
that has forward slashes replaced with backslashes.
Backslashes are directory separators in UEFI File Paths.
It is the caller's responsibility to eventually free() the returned buffer.
@param[in] path A pointer to the narrow-character path to be normalized.
@return A pointer to a buffer containing the normalized, wide-character, path.
*/
wchar_t *
NormalizePath( const char *path);
/** Process a MBCS path returning the final absolute path and the target device.
@param path
@param FullPath
@param DevNode
@retval RETURN_SUCCESS
@retval RETURN_INVALID_PARAMETER
@retval RETURN_NOT_FOUND
**/
RETURN_STATUS
EFIAPI
ParsePath( const char *path, wchar_t **FullPath, DeviceNode **DevNode, int *Which, wchar_t **MapPath);
/** Process a wide character string representing a Mapping Path and extract the instance number.
The instance number is the sequence of decimal digits immediately to the left
of the ":" in the Map Name portion of a Mapping Path.
This function is called with a pointer to beginning of the Map Name.
Thus Path[Length] must be a ':' and Path[Length - 1] must be a decimal digit.
If either of these are not true, an instance value of 0 is returned.
If Path is NULL, an instance value of 0 is returned.
@param[in] Path Points to the beginning of a Mapping Path
@param[in] Length Number of valid characters to the left of the ':'
@return Returns either 0 or the value of the contiguous digits to the left of the ':'.
**/
int
EFIAPI
PathInstance( const wchar_t *Path, int length);
/** Transform a relative path into an absolute path.
If Path is NULL, return NULL.
Otherwise, pre-pend the CWD to Path then process the resulting path to:
- Replace "/./" with "/"
- Replace "/<dirname>/../" with "/"
- Do not allow one to back up past the root, "/"
Also sets the Current Working Device to the Root Device.
Path must be a previously allocated buffer. PathAdjust will
allocate a new buffer to hold the results of the transformation
then free Path. A pointer to the newly allocated buffer is returned.
@param[in] Path A pointer to the path to be transformed. This buffer
will always be freed.
@return A pointer to a buffer containing the transformed path.
**/
wchar_t *
EFIAPI
PathAdjust(wchar_t *Path);
/** Replace the leading portion of Path with any aliases.
Aliases are read from /etc/fstab. If there is an associated device, the
Current Working Device is set to that device.
Path must be a previously allocated buffer. PathAlias will
allocate a new buffer to hold the results of the transformation
then free Path. A pointer to the newly allocated buffer is returned.
@param[in] Path A pointer to the original, unaliased, path. This
buffer is always freed.
@param[out] Node Filled in with a pointer to the Device Node describing
the device abstraction associated with this path.
@return A pointer to a buffer containing the aliased path.
**/
wchar_t *
EFIAPI
PathAlias(wchar_t *Path, DeviceNode **Node);
/**
Parses a normalized wide character path and returns a pointer to the entry
following the last \. If a \ is not found in the path the return value will
be the same as the input value. All error conditions return NULL.
The behavior when passing in a path that has not been normalized is undefined.
@param Path - A pointer to a wide character string containing a path to a
directory or a file.
@return Pointer to the file name or terminal directory. NULL if an error is
detected.
**/
wchar_t *
EFIAPI
GetFileNameFromPath(
const wchar_t *Path
);
__END_DECLS
#endif /* __DEV_UTILITY_H__ */