]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c
Changes so that Argv points to narrow-character versions of the command-line arguments.
[mirror_edk2.git] / StdLib / LibC / Uefi / Devices / Utility / DevGenisis.c
CommitLineData
53e1e5c6 1/** @file\r
2 Device Abstraction: device creation utility functions.\r
3\r
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials are licensed and made available under\r
6 the terms and conditions of the BSD License that accompanies this distribution.\r
7 The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12**/\r
13#include <Uefi.h>\r
14#include <Library/BaseLib.h>\r
15#include <Library/MemoryAllocationLib.h>\r
16\r
17#include <LibConfig.h>\r
18\r
19#include <errno.h>\r
20#include <sys/poll.h>\r
21#include <kfile.h>\r
22#include <Device/Device.h>\r
23#include <MainData.h>\r
24\r
25LIST_ENTRY daDeviceList = INITIALIZE_LIST_HEAD_VARIABLE(daDeviceList);\r
26DeviceNode *daDefaultDevice = NULL; ///< Device to use if nothing else found\r
27DeviceNode *daRootDevice = NULL; ///< Device containing the root file system\r
28DeviceNode *daCurrentDevice = NULL; ///< Device currently being accessed\r
29\r
30/* Commonly used fileops\r
31 fnullop_* Does nothing and returns success.\r
32 fbadop_* Does nothing and returns EPERM\r
33*/\r
34int fnullop_fcntl (struct __filedes *filp, UINT32 Cmd, void *p3, void *p4)\r
35{ return 0; }\r
36\r
37short fnullop_poll (struct __filedes *filp, short Events)\r
38{\r
39 return ((POLLIN | POLLRDNORM | POLLOUT) & Events);\r
40}\r
41\r
42int fnullop_flush (struct __filedes *filp)\r
43{ return 0; }\r
44\r
45int fbadop_stat (struct __filedes *filp, struct stat *StatBuf, void *Buf)\r
46{ return -EPERM; }\r
47\r
48int fbadop_ioctl (struct __filedes *filp, ULONGN Cmd, void *argp)\r
49{ return -EPERM; }\r
50\r
51int fbadop_delete (struct __filedes *filp)\r
52{ return -EPERM; }\r
53\r
54int fbadop_mkdir (const char *path, __mode_t perms)\r
55{ return -EPERM; }\r
56\r
57int fbadop_rename (const char *from, const char *to)\r
58{ return -EPERM; }\r
59\r
60int fbadop_rmdir (struct __filedes *filp)\r
61{ return -EPERM; }\r
62\r
63/** Add a new device to the device list.\r
64 If both DevName and DevProto are NULL, register this as the Default device.\r
65\r
66 @param DevName Name of the device to add.\r
67 @param DevProto Pointer to the GUID identifying the protocol associated with this device.\r
68 If DevProto is NULL, startup code will not try to find instances\r
69 of this device.\r
70 @param OpenFunc Pointer to the device's Open function.\r
71 @param InstanceList Optional pointer to the device's initialized instance list.\r
72 If InstanceList is NULL, the application startup code will\r
73 scan for instances of the protocol identified by DevProto and\r
74 populate the InstanceList in the order those protocols are found.\r
75 @param NumInstance Number of instances in InstanceList.\r
76 @param Modes Bit-mapped flags indicating operations (R, W, RW, ...) permitted to this device.\r
77\r
78**/\r
79DeviceNode *\r
80EFIAPI\r
81__DevRegister(\r
82 IN const CHAR16 *DevName,\r
83 IN GUID *DevProto,\r
84 IN FO_OPEN OpenFunc,\r
85 IN void *InstanceList,\r
86 IN int NumInstance,\r
87 IN UINT32 InstanceSize,\r
88 IN UINT32 Modes\r
89 )\r
90{\r
91 DeviceNode *Node;\r
92 GenericInstance *GIp;\r
93 char *GenPtr;\r
94 int i;\r
95\r
96 /* Validate parameters */\r
97 if(((DevName == NULL) && (DevProto != NULL)) ||\r
98 (OpenFunc == NULL)) {\r
99 EFIerrno = RETURN_INVALID_PARAMETER;\r
100 return NULL;\r
101 }\r
102 Node = (DeviceNode *)AllocateZeroPool(sizeof(DeviceNode));\r
103 if(Node == NULL) {\r
104 EFIerrno = RETURN_OUT_OF_RESOURCES;\r
105 return NULL;\r
106 }\r
107\r
108 Node->DevName = DevName;\r
109 Node->DevProto = DevProto;\r
110 Node->InstanceList = InstanceList;\r
111 Node->OpenFunc = OpenFunc;\r
112 Node->InstanceSize = InstanceSize;\r
113 Node->NumInstances = NumInstance;\r
114 Node->OpModes = Modes;\r
115\r
116 /* Update the Parent member of each element of the InstanceList */\r
117 if(InstanceList != NULL) {\r
118 GenPtr = InstanceList;\r
119\r
120 for(i = 0; i < NumInstance; ++i) { // Iterate through each element of InstanceList\r
121 GIp = (GenericInstance *)GenPtr;\r
122 GIp->Parent = Node; // Initializing the Parent member & InstanceNum\r
123 //GIp->InstanceNum = i;\r
124 GenPtr += InstanceSize;\r
125 }\r
126 }\r
127 if(DevName == NULL) {\r
128 if(daDefaultDevice != NULL) {\r
129 EFIerrno = RETURN_INVALID_PARAMETER;\r
130 return NULL;\r
131 }\r
132 daDefaultDevice = Node;\r
133 }\r
134 else {\r
135 (void) InsertTailList(&daDeviceList, &Node->DevList);\r
136 }\r
137 EFIerrno = RETURN_SUCCESS;\r
138 return Node;\r
139}\r