summaryrefslogtreecommitdiff
path: root/StdLibPrivateInternalFiles/Include/Device/Device.h
blob: 68eade05239d487af6eed4b436441369ea2eba90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/** @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);

/** 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);

__END_DECLS

#endif  /* __DEV_UTILITY_H__ */