--- /dev/null
+/** @file\r
+ Declarations and macros for the console abstraction.\r
+\r
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ Depends on <kfile.h>, <Device/Device.h>, <Protocol/SimpleTextIn.h>, <Uefi/UefiBaseType.h>\r
+**/\r
+#ifndef _DEVICE_UEFI_CONSOLE_H\r
+#define _DEVICE_UEFI_CONSOLE_H\r
+\r
+#include <kfile.h>\r
+#include <Device/Device.h>\r
+\r
+typedef struct {\r
+ UINT32 Column;\r
+ UINT32 Row;\r
+} CursorXY;\r
+\r
+typedef union {\r
+ UINT64 Offset;\r
+ CursorXY XYpos;\r
+} XYoffset;\r
+\r
+/* The members Cookie through Abstraction, inclusive, are the same type and order\r
+ for all instance structures.\r
+\r
+ All instance structures must be a multiple of sizeof(UINTN) bytes long\r
+*/\r
+typedef struct {\r
+ UINT32 Cookie; ///< Special value identifying this as a valid ConInstance\r
+ UINT32 InstanceNum; ///< Which instance is this? Zero-based.\r
+ EFI_HANDLE Dev; ///< Pointer to either Input or Output Protocol.\r
+ DeviceNode *Parent; ///< Points to the parent Device Node.\r
+ struct fileops Abstraction; ///< Pointers to functions implementing this device's abstraction.\r
+ UINTN Reserved_1; // Ensure that next member starts on an 8-byte boundary\r
+ UINT64 NumRead; ///< Number of characters Read.\r
+ UINT64 NumWritten; ///< Number of characters Written.\r
+ EFI_INPUT_KEY UnGetKey; ///< One-key pushback, for poll().\r
+ UINT32 Reserved_2; // Force the struct to be a multiple of 8-bytes long\r
+} ConInstance;\r
+\r
+__BEGIN_DECLS\r
+\r
+int\r
+EFIAPI\r
+da_ConOpen(\r
+ IN struct __filedes *filp,\r
+ IN void *DevInstance,\r
+ IN CHAR16 *Path,\r
+ IN CHAR16 *Flags\r
+);\r
+\r
+__END_DECLS\r
+\r
+#endif /* _DEVICE_UEFI_CONSOLE_H */\r
--- /dev/null
+/** @file\r
+ Device Abstraction Utility Routines\r
+\r
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ Depends upon: <kfile.h>\r
+**/\r
+#ifndef __DEV_UTILITY_H__\r
+#define __DEV_UTILITY_H__\r
+\r
+#define CON_COOKIE 0x62416F49 ///< 'IoAb'\r
+\r
+typedef enum {\r
+ PathAbsolute = 0,\r
+ PathRelative,\r
+ PathMapping,\r
+ PathError\r
+} PATH_CLASS;\r
+\r
+typedef struct _Device_Node {\r
+ LIST_ENTRY DevList; ///< List of registered device abstractions\r
+ const CHAR16 *DevName;\r
+ const GUID *DevProto;\r
+ void *InstanceList; ///< Array of instances for this device\r
+ FO_OPEN OpenFunc;\r
+ UINT32 InstanceSize; ///< Size of each instance in the InstanceList\r
+ UINT32 NumInstances; ///< Number of instances in InstanceList\r
+ UINT32 OpModes; ///< Supported modes of operation\r
+} DeviceNode;\r
+\r
+__BEGIN_DECLS\r
+\r
+extern LIST_ENTRY daDeviceList; ///< List of registered devices.\r
+extern DeviceNode *daDefaultDevice; ///< Device to use if nothing else found\r
+extern DeviceNode *daRootDevice; ///< Device containing the root file system\r
+extern DeviceNode *daCurrentDevice; ///< Device currently being accessed\r
+\r
+/** Add a new device to the device list.\r
+\r
+ @param DevName Name of the device to add.\r
+ @param DevProto Pointer to the GUID identifying the protocol associated with this device.\r
+ If DevProto is NULL, startup code will not try to find instances\r
+ of this device.\r
+ @param OpenFunc Pointer to the device's Open function.\r
+ @param InstanceList Optional pointer to the device's initialized instance list.\r
+ If InstanceList is NULL, the application startup code will\r
+ scan for instances of the protocol identified by DevProto and\r
+ populate the InstanceList in the order those protocols are found.\r
+ @param NumInstance Number of instances in InstanceList.\r
+ @param Modes Bit-mapped flags indicating operations (R, W, RW, ...) permitted to this device.\r
+\r
+**/\r
+DeviceNode * EFIAPI __DevRegister( const CHAR16 *DevName, GUID *DevProto, FO_OPEN OpenFunc,\r
+ void *InstanceList, int NumInstance, UINT32 InstanceSize, UINT32 Modes);\r
+\r
+/** Find a DeviceNode matching DevName or DevProto, or both.\r
+\r
+ If DevName is NULL, then the device name is not used in the search.\r
+ If DevProto is NULL, then the protocol GUID is not used in the search.\r
+ If both are NULL, then INVALID_PARAMETER is returned.\r
+ If both DevName and DevProto are specified, then both must match.\r
+ If both are specified but only one matches, then DEVICE_ERROR is returned.\r
+\r
+ @param DevName Name of the Device Abstraction to find.\r
+ @param DevProto GUID of the Protocol associated with the Device Abstraction.\r
+ @param Node Pointer to the pointer to receive the found Device Node's address.\r
+\r
+ @retval RETURN_SUCCESS The desired Device Node was found.\r
+ @retval RETURN_INVALID_PARAMETER Both DevName and DevProto are NULL or Node is NULL.\r
+ @retval RETURN_DEVICE_ERROR One, but not both, of DevNode and DevProto matched.\r
+**/\r
+EFI_STATUS EFIAPI __DevSearch( CHAR16 *DevName, GUID *DevProto, DeviceNode **Node);\r
+\r
+/** Identify the type of path pointed to by Path.\r
+\r
+ Paths are classified based upon their initial character sequences.\r
+ ^\\ Absolute Path\r
+ ^\. Relative Path\r
+ ^[^:\\]: Mapping Path\r
+ .* Relative Path\r
+\r
+ Mapping paths are broken into two parts at the ':'. The part to the left of the ':'\r
+ is the Map Name, pointed to by Path, and the part to the right of the ':' is pointed\r
+ to by NewPath.\r
+\r
+ If Path was not a Mapping Path, then NewPath is set to Path.\r
+\r
+ @param[in] Path Pointer to the path to be classified.\r
+ @param[out] NewPath Pointer to the path portion of a mapping path.\r
+\r
+ @retval PathAbsolute Path is an absolute path. NewPath points to the first '\'.\r
+ @retval PathRelative Path is a relative path. NewPath = Path.\r
+ @retval PathMapping Path is a mapping path. NewPath points to the ':'.\r
+ @retval PathError Path is NULL.\r
+**/\r
+PATH_CLASS EFIAPI ClassifyPath(IN wchar_t *Path, OUT wchar_t **NewPath, int * const Length);\r
+\r
+/* Normalize a narrow-character path and produce a wide-character path\r
+ that has forward slashes replaced with backslashes.\r
+ Backslashes are directory separators in UEFI File Paths.\r
+\r
+ It is the caller's responsibility to eventually free() the returned buffer.\r
+\r
+ @param[in] path A pointer to the narrow-character path to be normalized.\r
+\r
+ @return A pointer to a buffer containing the normalized, wide-character, path.\r
+*/\r
+wchar_t *\r
+NormalizePath( const char *path);\r
+\r
+/** Process a MBCS path returning the final absolute path and the target device.\r
+\r
+ @param path\r
+ @param FullPath\r
+ @param DevNode\r
+\r
+ @retval RETURN_SUCCESS\r
+ @retval RETURN_INVALID_PARAMETER\r
+ @retval RETURN_NOT_FOUND\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+ParsePath( const char *path, wchar_t **FullPath, DeviceNode **DevNode, int *Which);\r
+\r
+/** Process a wide character string representing a Mapping Path and extract the instance number.\r
+\r
+ The instance number is the sequence of decimal digits immediately to the left\r
+ of the ":" in the Map Name portion of a Mapping Path.\r
+\r
+ This function is called with a pointer to beginning of the Map Name.\r
+ Thus Path[Length] must be a ':' and Path[Length - 1] must be a decimal digit.\r
+ If either of these are not true, an instance value of 0 is returned.\r
+\r
+ If Path is NULL, an instance value of 0 is returned.\r
+\r
+ @param[in] Path Points to the beginning of a Mapping Path\r
+ @param[in] Length Number of valid characters to the left of the ':'\r
+\r
+ @return Returns either 0 or the value of the contiguous digits to the left of the ':'.\r
+**/\r
+int\r
+EFIAPI\r
+PathInstance( const wchar_t *Path, int length);\r
+\r
+/** Transform a relative path into an absolute path.\r
+\r
+ If Path is NULL, return NULL.\r
+ Otherwise, pre-pend the CWD to Path then process the resulting path to:\r
+ - Replace "/./" with "/"\r
+ - Replace "/<dirname>/../" with "/"\r
+ - Do not allow one to back up past the root, "/"\r
+\r
+ Also sets the Current Working Device to the Root Device.\r
+\r
+ Path must be a previously allocated buffer. PathAdjust will\r
+ allocate a new buffer to hold the results of the transformation\r
+ then free Path. A pointer to the newly allocated buffer is returned.\r
+\r
+ @param[in] Path A pointer to the path to be transformed. This buffer\r
+ will always be freed.\r
+\r
+ @return A pointer to a buffer containing the transformed path.\r
+**/\r
+wchar_t *\r
+EFIAPI\r
+PathAdjust(wchar_t *Path);\r
+\r
+/** Replace the leading portion of Path with any aliases.\r
+\r
+ Aliases are read from /etc/fstab. If there is an associated device, the\r
+ Current Working Device is set to that device.\r
+\r
+ Path must be a previously allocated buffer. PathAlias will\r
+ allocate a new buffer to hold the results of the transformation\r
+ then free Path. A pointer to the newly allocated buffer is returned.\r
+\r
+ @param[in] Path A pointer to the original, unaliased, path. This\r
+ buffer is always freed.\r
+ @param[out] Node Filled in with a pointer to the Device Node describing\r
+ the device abstraction associated with this path.\r
+\r
+ @return A pointer to a buffer containing the aliased path.\r
+**/\r
+wchar_t *\r
+EFIAPI\r
+PathAlias(wchar_t *Path, DeviceNode **Node);\r
+\r
+__END_DECLS\r
+\r
+#endif /* __DEV_UTILITY_H__ */\r
+++ /dev/null
-/** @file\r
- Declarations and macros for the console abstraction.\r
-\r
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials are licensed and made available under\r
- the terms and conditions of the BSD License that accompanies this distribution.\r
- The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php.\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-#ifndef _LIBRARY_UEFI_CONSOLE_H\r
-#define _LIBRARY_UEFI_CONSOLE_H\r
-#include <Protocol/SimpleTextOut.h>\r
-#include <Protocol/SimpleFileSystem.h>\r
-\r
-/* The number of "special" character stream devices.\r
- These include:\r
- stdin, stdout, stderr\r
-*/\r
-#define NUM_SPECIAL 3\r
-\r
-typedef struct {\r
- UINT32 Column;\r
- UINT32 Row;\r
-} CursorXY;\r
-\r
-typedef union {\r
- UINT64 Offset;\r
- CursorXY XYpos;\r
-} XYoffset;\r
-\r
-/**\r
- In support of the "everything is a file" paradigm of the Standard C Library,\r
- the UEFI Console support is abstracted as an instance of EFI_FILE_PROTOCOL.\r
- The member functions of the protocol translate as:\r
- Open Associates a stream with one of the pseudo-devices: stdin,\r
- stdout, or stderr; as defined by the UEFI System Table.\r
- Close The stream is marked closed and released for use by a\r
- subsequent Open().\r
- Delete Returns RETURN_UNSUPPORTED. Does Nothing.\r
- Read Blocks reading BufferSize characters using the\r
- EFI_SIMPLE_TEXT_INPUT_PROTOCOL::ReadKeyStroke() function.\r
- Write Sends BufferSize characters to the console for display. The\r
- output is examined for new line characters, '\n', which are then\r
- translated into a Return + New Line, '\r' '\n', sequence.\r
- GetPosition Returns the number of characters input or output to this\r
- stream. Return, '\r', characters inserted due to line ending\r
- translation are not counted.\r
- SetPosition Only valid for Stdout or Stderr. Offset is interpreted as a\r
- CursorXY structure and is used to position the console cursor\r
- using the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL::SetCursorPosition()\r
- call.\r
- GetInfo Populates an EFI_FILE_INFO Buffer with no useful information.\r
- SetInfo Returns RETURN_UNSUPPORTED. Does Nothing.\r
- Flush Returns RETURN_SUCCESS. Does Nothing.\r
-\r
-**/\r
-typedef struct {\r
- UINT32 Cookie;\r
- UINT32 ConOutMode; // Only valid for stdout & stderr\r
- UINT64 NumRead;\r
- UINT64 NumWritten;\r
- XYoffset MaxConXY; // Only valid for stdout & stderr\r
- EFI_HANDLE Dev; // Could be either Input or Output\r
- EFI_FILE_PROTOCOL Abstraction;\r
-} ConInstance;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-ConOpen(\r
- IN EFI_FILE_PROTOCOL *This,\r
- OUT EFI_FILE_PROTOCOL **NewHandle,\r
- IN CHAR16 *FileName,\r
- IN UINT64 OpenMode,\r
- IN UINT64 Attributes\r
-);\r
-\r
-#endif /* _LIBRARY_UEFI_CONSOLE_H */\r
--- /dev/null
+/** @file\r
+ Declarations local to the Uefi SysCalls module of the Standard C Library.\r
+\r
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials are licensed and made available under\r
+ the terms and conditions of the BSD License that accompanies this distribution.\r
+ The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _SYSEFI_H\r
+#define _SYSEFI_H\r
+#include <Protocol/SimpleFileSystem.h>\r
+\r
+#define EFI_FILE_MODE_MASK ( EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE )\r
+#define OMODE_MASK 0xFFFF00UL\r
+#define OMODE_SHIFT 8\r
+\r
+#define S_ACC_READ ( S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH )\r
+#define S_ACC_WRITE ( S_IWUSR | S_IWGRP | S_IWOTH )\r
+#define S_ACC_MASK ( S_IRWXU | S_IRWXG | S_IRWXO )\r
+\r
+UINT64\r
+Oflags2EFI( int oflags);\r
+\r
+UINT64\r
+Omode2EFI( int mode);\r
+\r
+/* Converts the first several EFI status values into the appropriate errno value.\r
+*/\r
+int\r
+EFI2errno( RETURN_STATUS Status);\r
+\r
+#endif /* _SYSEFI_H */\r
/** @file\r
Global data for the program environment.\r
\r
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials are licensed and made available under\r
- the terms and conditions of the BSD License that accompanies this distribution.\r
- The full text of the license may be found at\r
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ distribution. The full text of the license may be found at\r
http://opensource.org/licenses/bsd-license.php.\r
\r
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
**/\r
#include <Uefi.h>\r
-#include <Library/ShellLib.h>\r
\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <sys/types.h>\r
#include <limits.h>\r
#include <signal.h>\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
#include <time.h>\r
-#include "Efi/Console.h"\r
+\r
+#include <kfile.h>\r
+#include <Device/Device.h>\r
+\r
+#include "Device/Console.h"\r
\r
/* ################## Type Declarations ################################# */\r
\r
** three explicit spaces, two explicit colons, a newline,\r
** and a trailing ASCII nul).\r
*/\r
-#define ASCTIME_BUFLEN (3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + 3 + 2 + 1 + 1)\r
-\r
-struct __filedes {\r
- EFI_FILE_HANDLE FileHandle;\r
- UINT32 State; // In use if non-zero\r
- int Oflags; // From the open call\r
- int Omode; // From the open call\r
- int RefCount; // Reference count of opens\r
- int SocProc; // Placeholder: socket owner process or process group.\r
- UINT16 MyFD; // Which FD this is.\r
-};\r
+#define ASCTIME_BUFLEN ((2 * 3) + (5 * INT_STRLEN_MAXIMUM(int)) + 3 + 2 + 1 + 1)\r
+\r
+struct __filedes; /* Forward Reference */\r
+struct stat; /* Forward Reference so I don't have to include <stat.h> */\r
\r
struct __MainData {\r
// File descriptors\r
struct __filedes fdarray[OPEN_MAX];\r
// Low-level File abstractions for the stdin, stdout, stderr streams\r
- ConInstance StdIo[3];\r
+ ConInstance *StdIo[3];\r
\r
// Signal Handlers\r
__sighandler_t *sigarray[SIG_LAST]; // Pointers to signal handlers\r
\r
- void (*cleanup)(void); // Cleanup Function Pointer\r
+ char *NArgV[ARGC_MAX]; // Narrow character argv array\r
+ char *NCmdLine; // Narrow character version of command line arguments.\r
+\r
+ void (*cleanup)(void); // Stdio Cleanup Function Pointer\r
+ void (*FinalCleanup)(void); // Function to free this structure and cleanup before exit.\r
\r
__xithandler_t *atexit_handler[ATEXIT_MAX]; // Array of handlers for atexit.\r
clock_t AppStartTime; // Set in Main.c and used for time.h\r
int num_atexit; ///< Number of registered atexit handlers.\r
\r
CHAR16 UString[UNICODE_STRING_MAX];\r
+ CHAR16 UString2[UNICODE_STRING_MAX];\r
struct tm BDTime; // Broken-down time structure for localtime.\r
EFI_TIME TimeBuffer; // Used by <time.h>mk\r
char ASgetenv[ASCII_STRING_MAX]; // Only modified by getenv\r
--- /dev/null
+/** @file\r
+ The EFI kernel's interpretation of a "file".\r
+\r
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1982, 1986, 1989, 1993\r
+ * The Regents of the University of California. All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ * may be used to endorse or promote products derived from this software\r
+ * without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * file.h 8.3 (Berkeley) 1/9/95\r
+ NetBSD: file.h,v 1.56 2006/05/14 21:38:18 elad Exp\r
+**/\r
+#ifndef _PIF_KFILE_H_\r
+#define _PIF_KFILE_H_\r
+\r
+#include <Uefi.h>\r
+#include <Protocol/SimpleTextOut.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+\r
+#include <wchar.h>\r
+#include <sys/fcntl.h>\r
+#include <sys/unistd.h>\r
+\r
+struct stat;\r
+struct fileops;\r
+struct _Device_Node;\r
+\r
+/* The number of "special" character stream devices.\r
+ These include:\r
+ stdin, stdout, stderr\r
+*/\r
+#define NUM_SPECIAL 3\r
+\r
+/* Organization of the f_iflags member of the __filedes structure. */\r
+#define DTYPE_MASK 0x00000007 ///< Device Type\r
+#define DTYPE_VNODE 1 /* file */\r
+#define DTYPE_SOCKET 2 /* communications endpoint */\r
+#define DTYPE_PIPE 3 /* pipe */\r
+#define DTYPE_KQUEUE 4 /* event queue */\r
+#define DTYPE_MISC 5 /* misc file descriptor type */\r
+#define DTYPE_CRYPTO 6 /* crypto */\r
+#define DTYPE_NAMES "0", "file", "socket", "pipe", "kqueue", "misc", "crypto"\r
+\r
+#define FIF_WANTCLOSE 0x10000000 /* a close is waiting for usecount */\r
+#define FIF_DELCLOSE 0x20000000 /* Delete on close. */\r
+#define FIF_LARVAL 0x80000000 /* not fully constructed; don't use */\r
+\r
+/*\r
+ This structure must be a multiple of 8 bytes in length.\r
+*/\r
+struct __filedes {\r
+ const struct fileops *f_ops;\r
+ void *devdata; /* Device-specific data */\r
+ off_t f_offset; /* current position in file */\r
+ UINT32 f_flag; /* see fcntl.h */\r
+ UINT32 f_iflags; // In use if non-zero\r
+ int Oflags; // From the open call\r
+ int Omode; // From the open call\r
+ int RefCount; // Reference count of opens\r
+ UINT16 MyFD; // Which FD this is.\r
+ UINT16 Reserved_1; // Force this structure to be a multiple of 8-bytes in length\r
+};\r
+\r
+struct fileops {\r
+ /* These functions must always be implemented. */\r
+ int (EFIAPI *fo_close) (struct __filedes *filp);\r
+ ssize_t (EFIAPI *fo_read) (struct __filedes *filp, off_t *Offset, size_t Len, void *Buf);\r
+ ssize_t (EFIAPI *fo_write) (struct __filedes *filp, off_t *Offset, size_t Len, const void *Buf);\r
+\r
+ /* Call the fnullop_* version of these functions if not implemented by the device. */\r
+ int (EFIAPI *fo_fcntl) (struct __filedes *filp, UINT32 Cmd, void *p3, void *p4);\r
+ short (EFIAPI *fo_poll) (struct __filedes *filp, short Events);\r
+ int (EFIAPI *fo_flush) (struct __filedes *filp);\r
+\r
+ /* Call the fbadop_* version of these functions if not implemented by the device. */\r
+ int (EFIAPI *fo_stat) (struct __filedes *filp, struct stat *StatBuf, void *Buf);\r
+ int (EFIAPI *fo_ioctl) (struct __filedes *filp, ULONGN Cmd, void *argp);\r
+ int (EFIAPI *fo_delete) (struct __filedes *filp);\r
+ int (EFIAPI *fo_rmdir) (struct __filedes *filp);\r
+ int (EFIAPI *fo_mkdir) (const char *path, __mode_t perms);\r
+ int (EFIAPI *fo_rename) (const char *from, const char *to);\r
+\r
+ /* Use a NULL if this function has not been implemented by the device. */\r
+ off_t (EFIAPI *fo_lseek) (struct __filedes *filp, off_t, int);\r
+};\r
+\r
+/* A generic instance structure which is valid for\r
+ for all device instance structures.\r
+\r
+ All device instance structures MUST be a multiple of 8-bytes in length.\r
+*/\r
+typedef struct {\r
+ UINT32 Cookie; ///< Special value identifying this as a valid Instance\r
+ UINT32 InstanceNum; ///< Which instance is this? Zero-based.\r
+ EFI_HANDLE Dev; ///< Pointer to either Input or Output Protocol.\r
+ struct _Device_Node *Parent; ///< Points to the parent Device Node.\r
+ struct fileops Abstraction; ///< Pointers to functions implementing this device's abstraction.\r
+ UINTN Reserved_1; // Force this to always be a multiple of 8-bytes in length\r
+} GenericInstance;\r
+\r
+/* Type of all Device-specific handler's open routines. */\r
+typedef\r
+ int (EFIAPI *FO_OPEN) (struct __filedes *FD, void *IP, wchar_t *Path, wchar_t *Flags);\r
+\r
+#define FILE_IS_USABLE(fp) (((fp)->f_iflags & \\r
+ (FIF_WANTCLOSE|FIF_LARVAL)) == 0)\r
+\r
+#define FILE_SET_MATURE(fp) \\r
+do { \\r
+ (fp)->f_iflags &= ~FIF_LARVAL; \\r
+} while (/*CONSTCOND*/0)\r
+\r
+/*\r
+ * Flags for fo_read and fo_write.\r
+ */\r
+#define FOF_UPDATE_OFFSET 0x01 /* update the file offset */\r
+\r
+__BEGIN_DECLS\r
+\r
+int fdcreate (CHAR16 *, UINT32, UINT32, BOOLEAN, VOID *, const struct fileops *);\r
+\r
+/* Commonly used fileops\r
+ fnullop_* Does nothing and returns success.\r
+ fbadop_* Does nothing and returns EPERM\r
+*/\r
+int fnullop_fcntl (struct __filedes *filp, UINT32 Cmd, void *p3, void *p4);\r
+short fnullop_poll (struct __filedes *filp, short Events);\r
+int fnullop_flush (struct __filedes *filp);\r
+\r
+int fbadop_stat (struct __filedes *filp, struct stat *StatBuf, void *Buf);\r
+int fbadop_ioctl (struct __filedes *filp, ULONGN Cmd, void *argp);\r
+int fbadop_delete (struct __filedes *filp);\r
+int fbadop_rmdir (struct __filedes *filp);\r
+int fbadop_mkdir (const char *path, __mode_t perms);\r
+int fbadop_rename (const char *from, const char *to);\r
+\r
+__END_DECLS\r
+\r
+/* From the original file... */\r
+#if 0\r
+\r
+//struct proc;\r
+//struct lwp;\r
+//struct uio;\r
+//struct iovec;\r
+//struct knote;\r
+\r
+//LIST_HEAD(filelist, file);\r
+//extern struct filelist filehead; /* head of list of open files */\r
+//extern int maxfiles; /* kernel limit on # of open files */\r
+//extern int nfiles; /* actual number of open files */\r
+\r
+//extern const struct fileops vnops; /* vnode operations for files */\r
+\r
+struct fileops {\r
+ int (*fo_read) (struct file *, off_t *, struct uio *, kauth_cred_t, int);\r
+ int (*fo_write) (struct file *, off_t *, struct uio *, kauth_cred_t, int);\r
+ int (*fo_ioctl) (struct file *, u_long, void *, struct lwp *);\r
+ int (*fo_fcntl) (struct file *, u_int, void *, struct lwp *);\r
+ int (*fo_poll) (struct file *, int, struct lwp *);\r
+ int (*fo_stat) (struct file *, struct stat *, struct lwp *);\r
+ int (*fo_close) (struct file *, struct lwp *);\r
+};\r
+\r
+/*\r
+ * Kernel descriptor table.\r
+ * One entry for each open kernel vnode and socket.\r
+ */\r
+struct file {\r
+ LIST_ENTRY(file) f_list; /* list of active files */\r
+ void *f_data; /* descriptor data, e.g. vnode/socket */\r
+ const struct fileops *f_ops;\r
+ void *f_DevDesc; /* Device Descriptor pointer */\r
+ EFI_FILE_HANDLE FileHandle;\r
+ EFI_HANDLE Handle;\r
+ off_t f_offset; /* current position in file */\r
+ int f_flag; /* see fcntl.h */\r
+ UINT32 f_iflags; /* internal flags; FIF_* */\r
+ int f_advice; /* access pattern hint; UVM_ADV_* */\r
+ int f_type; /* descriptor type */\r
+ int f_usecount; /* number active users */\r
+ u_int f_count; /* reference count */\r
+ u_int f_msgcount; /* references from message queue */\r
+// kauth_cred_t f_cred; /* creds associated with descriptor */\r
+ struct simplelock f_slock;\r
+ UINT16 MyFD; /* Which FD this is. */\r
+};\r
+\r
+#ifdef DIAGNOSTIC\r
+#define FILE_USE_CHECK(fp, str) \\r
+ do { \\r
+ if ((fp)->f_usecount < 0) \\r
+ panic(str); \\r
+} while (/* CONSTCOND */ 0)\r
+#else\r
+#define FILE_USE_CHECK(fp, str) /* nothing */\r
+#endif\r
+\r
+ /*\r
+ * FILE_USE() must be called with the file lock held.\r
+ * (Typical usage is: `fp = fd_getfile(..); FILE_USE(fp);'\r
+ * and fd_getfile() returns the file locked)\r
+ *\r
+ * fp is a pointer to a __filedes structure.\r
+ */\r
+#define FILE_USE(fp) \\r
+ do { \\r
+ (fp)->f_usecount++; \\r
+ FILE_USE_CHECK((fp), "f_usecount overflow"); \\r
+ simple_unlock(&(fp)->f_slock); \\r
+ } while (/* CONSTCOND */ 0)\r
+\r
+#define FILE_UNUSE_WLOCK(fp, l, havelock) \\r
+ do { \\r
+ if (!(havelock)) \\r
+ simple_lock(&(fp)->f_slock); \\r
+ if ((fp)->f_iflags & FIF_WANTCLOSE) { \\r
+ simple_unlock(&(fp)->f_slock); \\r
+ /* Will drop usecount */ \\r
+ (void) closef((fp), (l)); \\r
+ break; \\r
+ } else { \\r
+ (fp)->f_usecount--; \\r
+ FILE_USE_CHECK((fp), "f_usecount underflow"); \\r
+ } \\r
+ simple_unlock(&(fp)->f_slock); \\r
+ } while (/* CONSTCOND */ 0)\r
+\r
+#define FILE_UNUSE(fp, l) FILE_UNUSE_WLOCK(fp, l, 0)\r
+#define FILE_UNUSE_HAVELOCK(fp, l) FILE_UNUSE_WLOCK(fp, l, 1)\r
+\r
+__BEGIN_DECLS\r
+//int dofileread (struct lwp *, int, struct file *, void *, size_t, off_t *, int, register_t *);\r
+//int dofilewrite (struct lwp *, int, struct file *, const void *, size_t, off_t *, int, register_t *);\r
+\r
+//int dofilereadv (struct lwp *, int, struct file *, const struct iovec *, int, off_t *, int, register_t *);\r
+//int dofilewritev(struct lwp *, int, struct file *, const struct iovec *, int, off_t *, int, register_t *);\r
+\r
+//int fsetown (struct proc *, pid_t *, int, const void *);\r
+//int fgetown (struct proc *, pid_t, int, void *);\r
+//void fownsignal (pid_t, int, int, int, void *);\r
+\r
+//int fdclone (struct lwp *, struct file *, int, int, const struct fileops *, void *);\r
+\r
+/* Commonly used fileops\r
+ fnullop_* Does nothing and returns success.\r
+ fbadop_* Does nothing and returns EPERM\r
+*/\r
+//int fnullop_fcntl (struct file *, u_int, void *, struct lwp *);\r
+//int fnullop_poll (struct file *, int, struct lwp *);\r
+//int fnullop_kqfilter(struct file *, struct knote *);\r
+//int fbadop_stat (struct file *, struct stat *, struct lwp *);\r
+//int fbadop_ioctl (struct file *, u_long, void *, struct lwp *);\r
+__END_DECLS\r
+\r
+#endif\r
+\r
+#endif /* _PIF_KFILE_H_ */\r