]> git.proxmox.com Git - mirror_edk2.git/commitdiff
StdLib: Add isDirSep character classification macro and function. Implement several...
authordarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 Nov 2011 00:52:45 +0000 (00:52 +0000)
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 Nov 2011 00:52:45 +0000 (00:52 +0000)
Include/ctype.h:             Function declaration and Macro definition of isDirSep
Include/unistd.h:            Declarations added from EfiSysCall.h
Include/utime.h:             New file.  For the Posix utime() function.
Include/sys/_ctype.h:        Update character class bit maps.
Include/sys/EfiSysCall.h:    Move declarations to unistd.h
Include/sys/fcntl.h:         Improve comments.  Add UEFI-specific macros.
Include/sys/filio.h:         Remove declarations for unsupported file ioctls.
Include/sys/stat.h:          Fix flags.  Add macros and declarations.
Include/sys/time.h:          Add declarations for new functions Tm2Efi() and Time2Efi().
Include/sys/types.h:         Use EFI-specific instead of BSD-specific definitions for typedefs.
Include/sys/unistd.h:        Delete inappropriate content.  Guard macro definitions.

LibC/Locale/setlocale.c
LibC/Stdio/{fdopen.c, findfp.c, fopen.c, freopen.c, gettemp.c, makebuf.c, mktemp.c,
            remove.c, stdio.c, tempnam.c, tmpfile.c, tmpnam.c}
LibC/Time/{itimer.c, ZoneProc.c}
LibC/Uefi/SysCalls.c
LibC/Uefi/Devices/Console/daConsole.c
LibC/Uefi/Devices/UefiShell/daShell.c
PosixLib/Gen/readdir.c
                             Include unistd.h instead of EfiSysCall.h

LibC/Ctype/CClass.c:         Character classification function implementation for isDirSep.
LibC/Ctype/iCtype.c:         Update character classification and case conversion tables.
LibC/Time/TimeEfi.c:         Improve comments.  Implement new functions Tm2Efi() and Time2Efi().
LibC/Uefi/StubFunctions.c:   Add missing include.  Cosmetic changes to declarations.
LibC/Uefi/SysCalls.c:        Add support function for utime().
LibC/Uefi/Uefi.inf:          Add LibGen library class dependency.
LibC/Uefi/Xform.c:           Enhance Omode2EFI().
LibC/Uefi/Devices/UefiShell/daShell.c:    Enhance da_ShellMkdir.  Implement da_ShellIoctl to set file times.
PosixLib/Gen/access.c:       New file.  Implement the access() function.
PosixLib/Gen/dirname.c:      Enhance to use isDirSep and differentiate between the device, path, and filename components of UEFI Shell-style paths.
PosixLib/Gen/utime.c:        New file.  Implement the utime() function.
PosixLib/Gen/LibGen.inf:     Change MODULE_TYPE.  Add new files.

Signed-off-by: darylm503
Reviewed-by: geekboy15a
Reviewed-by: jljusten
Reviewed-by: Rahul Khana
Reviewed-by: leegrosenbaum
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12800 6f19259b-4bc3-4df7-8a09-765794883524

40 files changed:
StdLib/Include/ctype.h
StdLib/Include/sys/EfiSysCall.h
StdLib/Include/sys/_ctype.h
StdLib/Include/sys/fcntl.h
StdLib/Include/sys/filio.h
StdLib/Include/sys/stat.h
StdLib/Include/sys/time.h
StdLib/Include/sys/types.h
StdLib/Include/sys/unistd.h
StdLib/Include/unistd.h
StdLib/Include/utime.h [new file with mode: 0644]
StdLib/LibC/Ctype/CClass.c
StdLib/LibC/Ctype/iCtype.c
StdLib/LibC/Locale/setlocale.c
StdLib/LibC/Stdio/fdopen.c
StdLib/LibC/Stdio/findfp.c
StdLib/LibC/Stdio/fopen.c
StdLib/LibC/Stdio/freopen.c
StdLib/LibC/Stdio/gettemp.c
StdLib/LibC/Stdio/makebuf.c
StdLib/LibC/Stdio/mktemp.c
StdLib/LibC/Stdio/remove.c
StdLib/LibC/Stdio/stdio.c
StdLib/LibC/Stdio/tempnam.c
StdLib/LibC/Stdio/tmpfile.c
StdLib/LibC/Stdio/tmpnam.c
StdLib/LibC/Time/TimeEfi.c
StdLib/LibC/Time/ZoneProc.c
StdLib/LibC/Time/itimer.c
StdLib/LibC/Uefi/Devices/Console/daConsole.c
StdLib/LibC/Uefi/Devices/UefiShell/daShell.c
StdLib/LibC/Uefi/StubFunctions.c
StdLib/LibC/Uefi/SysCalls.c
StdLib/LibC/Uefi/Uefi.inf
StdLib/LibC/Uefi/Xform.c
StdLib/PosixLib/Gen/LibGen.inf
StdLib/PosixLib/Gen/access.c [new file with mode: 0644]
StdLib/PosixLib/Gen/dirname.c
StdLib/PosixLib/Gen/readdir.c
StdLib/PosixLib/Gen/utime.c [new file with mode: 0644]

index fb0e2fd7d346fa481c4fbb054a516dfda308b04d..d35367f52055b57eb8d5d04cb5242617029e0493 100644 (file)
@@ -171,6 +171,20 @@ int isxdigit(int c);
 **/\r
 int isascii(int c);\r
 \r
+/** Test whether a character is one of the characters used as a separator\r
+    between directory elements in a path.\r
+\r
+    Characters are '/', '\\'\r
+\r
+    This non-standard function is unique to this implementation.\r
+\r
+    @param[in]    c   The character to be tested.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the parameter c\r
+              can be classified as specified in the description of the function.\r
+**/\r
+int isDirSep(int c);\r
+\r
 /** The tolower function converts an uppercase letter to a corresponding\r
     lowercase letter.\r
 \r
@@ -218,6 +232,7 @@ __END_DECLS
   #define isspace(c)    (__isCClass( (int)c, (_CW)))\r
   #define isupper(c)    (__isCClass( (int)c, (_CU)))\r
   #define isxdigit(c)   (__isCClass( (int)c, (_CD | _CX)))\r
+  #define isDirSep(c)   (__isCClass( (int)c, (_C0)))\r
   #define tolower(c)    (__toLower((int)c))\r
   #define toupper(c)    (__toUpper((int)c))\r
 #endif  /* NO_CTYPE_MACROS */\r
index 1d013286091c6d580b5d3a29f8d8fd4824d7edf2..cbaf1d1397e9b1da10f60afbc061f3186701e49b 100644 (file)
@@ -6,10 +6,6 @@
       STDIN_FILENO      0     standard input file descriptor\r
       STDOUT_FILENO     1     standard output file descriptor\r
       STDERR_FILENO     2     standard error file descriptor\r
-      F_OK              0     test for existence of file\r
-      X_OK           0x01     test for execute or search permission\r
-      W_OK           0x02     test for write permission\r
-      R_OK           0x04     test for read permission\r
       SEEK_SET          0     set file offset to offset\r
       SEEK_CUR          1     set file offset to current plus offset\r
       SEEK_END          2     set file offset to EOF plus offset\r
       int       DeleteOnClose (int fd);    Mark an open file to be deleted when closed.\r
       int       FindFreeFD    (int MinFd);\r
       BOOLEAN   ValidateFD    (int fd, int IsOpen);\r
-\r
-      ###############  Functions added for compatibility.\r
-      char     *getcwd    (char *, size_t);\r
-      int       chdir     (const char *);\r
 @endverbatim\r
 \r
   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
@@ -82,12 +74,6 @@ struct stat;  /* Structure declared in <sys/stat.h> */
 #define STDOUT_FILENO 1 /**< standard output file descriptor */\r
 #define STDERR_FILENO 2 /**< standard error file descriptor */\r
 \r
-/* access function */\r
-#define F_OK       0  /**< test for existence of file */\r
-#define X_OK    0x01  /**< test for execute or search permission */\r
-#define W_OK    0x02  /**< test for write permission */\r
-#define R_OK    0x04  /**< test for read permission */\r
-\r
 /* whence values for lseek(2)\r
    Always ensure that these are consistent with <stdio.h> and <unistd.h>!\r
 */\r
@@ -238,115 +224,100 @@ __BEGIN_DECLS
         - stdout:       Standard Output       (from the System Table)\r
         - stderr:       Standard Error Output (from the System Table)\r
 \r
-    @param[in]  name\r
-    @param[in]  oflags\r
-    @param[in]  mode\r
+    @param[in]  name      Name of file to open.\r
+    @param[in]  oflags    Flags as defined in fcntl.h.\r
+    @param[in]  mode      Access mode to use if creating the file.\r
 \r
-    @return\r
+    @return   Returns -1 on failure, otherwise the file descriptor for the open file.\r
   **/\r
   int     open      (const char *name, int oflags, int mode);\r
 \r
-  /**\r
-    @param[in]\r
+  /** Create a new file or rewrite an existing one.\r
+\r
+      The creat() function behaves as if it is implemented as follows:\r
 \r
-    @return\r
+        int creat(const char *path, mode_t mode)\r
+        {\r
+            return open(path, O_WRONLY|O_CREAT|O_TRUNC, mode);\r
+        }\r
+\r
+    @param[in]    Path    The name of the file to create.\r
+    @param[in]    Mode    Access mode (permissions) for the new file.\r
+\r
+    @return   Returns -1 on failure, otherwise the file descriptor for the open file.\r
   **/\r
-  int     creat     (const char *, mode_t);\r
+  int     creat     (const char *Path, mode_t Mode);\r
+\r
+  /** File control\r
 \r
-  /**\r
-    @param[in]\r
+      This function performs the operations described below and defined in <fcntl.h>.\r
 \r
-    @return\r
+        - F_DUPFD: Return the lowest numbered file descriptor available that is >= the third argument.\r
+                   The new file descriptor refers to the same open file as Fd.\r
+\r
+        - F_SETFD: Set the file descriptor flags to the value specified by the third argument.\r
+        - F_GETFD: Get the file descriptor flags associated with Fd.\r
+        - F_SETFL: Set the file status flags based upon the value of the third argument.\r
+        - F_GETFL: Get the file status flags and access modes for file Fd.\r
+\r
+    @param[in]  Fd      File descriptor associated with the file to be controlled.\r
+    @param[in]  Cmd     Command to execute.\r
+    @param[in]  ...     Additional arguments, as needed by Cmd.\r
+\r
+    @return   A -1 is returned to indicate failure, otherwise the value\r
+              returned is positive and depends upon Cmd as follows:\r
+                - F_DUPFD: A new file descriptor.\r
+                - F_SETFD: files previous file descriptor flags.\r
+                - F_GETFD: The files file descriptor flags.\r
+                - F_SETFL: The old status flags and access mode of the file.\r
+                - F_GETFL: The status flags and access mode of the file.\r
   **/\r
-  int     fcntl     (int, int, ...);\r
+  int     fcntl     (int Fd, int Cmd, ...);\r
 #endif  // __FCNTL_SYSCALLS_DECLARED\r
 \r
 /* These system calls are also declared in stat.h */\r
 #ifndef __STAT_SYSCALLS_DECLARED\r
   #define __STAT_SYSCALLS_DECLARED\r
 \r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
   int     mkdir     (const char *, mode_t);\r
-\r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
   int     fstat     (int, struct stat *);\r
-\r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
   int     lstat     (const char *, struct stat *);\r
-\r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
   int     stat      (const char *, struct stat *);\r
-\r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
   int     chmod     (const char *, mode_t);\r
+  mode_t  umask     (mode_t cmask);\r
+\r
 #endif  // __STAT_SYSCALLS_DECLARED\r
 \r
 // These are also declared in sys/types.h\r
 #ifndef __OFF_T_SYSCALLS_DECLARED\r
   #define __OFF_T_SYSCALLS_DECLARED\r
-\r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
   off_t   lseek     (int, off_t, int);\r
-\r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
   int     truncate  (const char *, off_t);\r
-\r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
   int     ftruncate (int, off_t);   //  IEEE Std 1003.1b-93\r
 #endif /* __OFF_T_SYSCALLS_DECLARED */\r
 \r
 /* EFI-specific Functions. */\r
 \r
-  /**\r
-    @param[in]\r
+  /** Mark an open file to be deleted when it is closed.\r
+\r
+    @param[in]  fd    File descriptor for the open file.\r
 \r
-    @return\r
+    @retval   0   The flag was set successfully.\r
+    @retval  -1   An invalid fd was specified.\r
   **/\r
-  int       DeleteOnClose(int fd);    /* Mark an open file to be deleted when closed. */\r
+  int       DeleteOnClose(int fd);\r
 \r
-/* Find and reserve a free File Descriptor.\r
+  /** Find and reserve a free File Descriptor.\r
 \r
   Returns the first free File Descriptor greater than or equal to the,\r
   already validated, fd specified by Minfd.\r
 \r
   @return   Returns -1 if there are no free FDs.  Otherwise returns the\r
             found fd.\r
-*/\r
+  */\r
   int       FindFreeFD  (int MinFd);\r
 \r
-/*  Validate that fd refers to a valid file descriptor.\r
+  /** Validate that fd refers to a valid file descriptor.\r
     IsOpen is interpreted as follows:\r
       - Positive  fd must be OPEN\r
       - Zero      fd must be CLOSED\r
@@ -354,26 +325,11 @@ __BEGIN_DECLS
 \r
     @retval TRUE  fd is VALID\r
     @retval FALSE fd is INVALID\r
-*/\r
+  */\r
   BOOLEAN   ValidateFD (int fd, int IsOpen);\r
 \r
 \r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
-  char     *getcwd    (char *, size_t);\r
-\r
-  /**\r
-    @param[in]\r
-\r
-    @return\r
-  **/\r
-  int       chdir     (const char *);\r
-\r
 /* These system calls don't YET have EFI implementations. */\r
-  int       access    (const char *path, int amode);\r
   int       reboot    (int, char *);\r
 __END_DECLS\r
 \r
index 6c2b3274116acb9738521f80079151803a958925..cb06ec09dd22d0f55c947ee68c47c20bfcf56b7e 100644 (file)
@@ -26,8 +26,8 @@ extern  int  __isCClass( int _c, unsigned int mask);   ///< Internal character c
 __END_DECLS\r
 \r
 \r
-/** Character Class bit masks.\r
-@{\r
+/** @{\r
+Character Class bit masks.\r
 **/\r
 #define _CC   0x0001U     ///< Control Characters\r
 #define _CW   0x0002U     ///< White Space\r
@@ -36,7 +36,7 @@ __END_DECLS
 #define _CU   0x0010U     ///< Uppercase Letter [A-Z]\r
 #define _CL   0x0020U     ///< Lowercase Letter [a-z]\r
 #define _CX   0x0040U     ///< Hexadecimal Digits [A-Fa-f]\r
-#define _C0   0x0080U\r
+#define _C0   0x0080U     ///< Path Separator Characters, '/' and '\\'\r
 #define _CS   0x0100U     ///< Space Characters, ' ' in C locale\r
 #define _CG   0x0200U     ///< Graphic Characters\r
 #define _CB   0x0400U     ///< Blank Characters, ' ' and '\t' in C locale\r
index d41af5ce11219e6e269b6b33d215be6c99c1b88b..b91792f9f7aa550c81c44fe992170a07eea5e91a 100644 (file)
 \r
 #include <sys/stat.h>\r
 \r
-/** File status flags used by open(2), fcntl(2).\r
+/** @{\r
+    File status flags used by open(2), fcntl(2).\r
     They are also used (indirectly) in the kernel file structure f_flags,\r
     which is a superset of the open/fcntl flags.\r
     Open/fcntl flags begin with O_; kernel-internal flags begin with F.\r
-@{\r
 **/\r
 /* open-only flags */\r
 #define O_RDONLY    0x00000000  ///< open for reading only\r
 #define O_CREAT     0x00000200  ///< create if nonexistent\r
 #define O_TRUNC     0x00000400  ///< truncate to zero length\r
 #define O_EXCL      0x00000800  ///< error if already exists\r
+\r
+/* UEFI-specific open-only flags. */\r
+#define O_HIDDEN    0x00010000  ///< Hidden file attribute\r
+#define O_SYSTEM    0x00020000  ///< System file attribute\r
+#define O_ARCHIVE   0x00040000  ///< Archive file attribute\r
 /// @}\r
 \r
 //#define O_DIRECT    0x00080000  /* direct I/O hint */\r
@@ -81,7 +86,7 @@
  * Constants used for fcntl(2)\r
  */\r
 \r
-/** command values. @{ **/\r
+/** @{ command values used for fcntl(2). **/\r
 #define F_DUPFD      0  ///< duplicate file descriptor\r
 #define F_GETFD      1  ///< get file descriptor flags\r
 #define F_SETFD      2  ///< set file descriptor flags\r
 /** file descriptor flags (F_GETFD, F_SETFD). **/\r
 #define FD_CLOEXEC  1   ///< close-on-exec flag\r
 \r
-/** record locking flags (F_GETLK, F_SETLK, F_SETLKW). @{ **/\r
+/** @{ record locking flags (F_GETLK, F_SETLK, F_SETLKW). **/\r
 #define F_RDLCK     1   ///< shared or read lock\r
 #define F_UNLCK     2   ///< unlock\r
 #define F_WRLCK     3   ///< exclusive or write lock\r
 /// @}\r
 \r
-/** Constants for fcntl's passed to the underlying fs - like ioctl's. @{ **/\r
+/** @{ Constants for fcntl's passed to the underlying fs - like ioctl's. **/\r
 #define F_PARAM_MASK    0xfff\r
 #define F_PARAM_LEN(x)  (((x) >> 16) & F_PARAM_MASK)\r
 #define F_PARAM_MAX     4095\r
index 65f34bcb5c476e4cff37605d2a21100de5d9ebf5..e514c267a7b4998a99ae93fe504234019f4a2b4d 100644 (file)
@@ -1,8 +1,16 @@
-/*     $NetBSD: filio.h,v 1.10 2005/12/11 12:25:20 christos Exp $      */\r
+/** @file\r
+\r
+  Copyright (c) 2011, 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.\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
  * Copyright (c) 1982, 1986, 1990, 1993, 1994\r
- *     The Regents of the University of California.  All rights reserved.\r
+ *  The Regents of the University of California.  All rights reserved.\r
  * (c) UNIX System Laboratories, Inc.\r
  * All or some portions of this file are derived from material licensed\r
  * to the University of California by American Telephone and Telegraph\r
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
  * SUCH DAMAGE.\r
  *\r
- *     @(#)filio.h     8.1 (Berkeley) 3/28/94\r
+ *  @(#)filio.h 8.1 (Berkeley) 3/28/94\r
+    NetBSD: filio.h,v 1.10 2005/12/11 12:25:20 christos Exp\r
  */\r
 \r
-#ifndef        _SYS_FILIO_H_\r
-#define        _SYS_FILIO_H_\r
+#ifndef _SYS_FILIO_H_\r
+#define _SYS_FILIO_H_\r
 \r
 #include <sys/ioccom.h>\r
 \r
-/* Generic file-descriptor ioctl's. */\r
-#define        FIOCLEX          _IO('f', 1)            /* set close on exec on fd */\r
-#define        FIONCLEX         _IO('f', 2)            /* remove close on exec */\r
-#define        FIONREAD        _IOR('f', 127, int)     /* get # bytes to read */\r
-#define        FIONBIO         _IOW('f', 126, int)     /* set/clear non-blocking i/o */\r
-#define        FIOASYNC        _IOW('f', 125, int)     /* set/clear async i/o */\r
-#define        FIOSETOWN       _IOW('f', 124, int)     /* set owner */\r
-#define        FIOGETOWN       _IOR('f', 123, int)     /* get owner */\r
-#define        OFIOGETBMAP     _IOWR('f', 122, uint32_t) /* get underlying block no. */\r
-#define        FIOGETBMAP      _IOWR('f', 122, daddr_t) /* get underlying block no. */\r
-#define        FIONWRITE       _IOR('f', 121, int)     /* get # bytes outstanding\r
-                                                * in send queue. */\r
-#define        FIONSPACE       _IOR('f', 120, int)     /* get space in send queue. */\r
-\r
-\r
-/* Ugly symbol for compatibility with other operating systems */\r
-#define        FIBMAP          FIOGETBMAP\r
+typedef const struct timeval*    ptimeval_t;\r
+\r
+/* File-descriptor ioctl's. */\r
+\r
+#define FIODLEX       _IO   ('f', 1)                  /* set Delete-on-Close */\r
+#define FIONDLEX      _IO   ('f', 2)                  /* clear Delete-on-Close */\r
+#define FIOSETIME     _IOW  ('f', 127, ptimeval_t)    /* Set access and modification times */\r
 \r
 #endif /* !_SYS_FILIO_H_ */\r
index f95385877a30749e98b8412966639827008141e9..6c5d5a80783c87a7b4e52c044967401c639a7f50 100644 (file)
@@ -113,7 +113,7 @@ struct stat {
 #define S_IARCHIVE    0x02000000    // Archive Bit\r
 #define S_IROFS       0x08000000   ///< Read Only File System\r
 \r
-#define S_EFIONLY     0xF0000000  ///< Flags only used by the EFI system calls.\r
+#define S_EFIONLY     0xFFF00000  ///< Flags only used by the EFI system calls.\r
 \r
 #define S_EFISHIFT    20            // LS bit of the UEFI attributes\r
 \r
@@ -142,6 +142,10 @@ struct stat {
 #define ALLPERMS  (S_IRWXU|S_IRWXG|S_IRWXO)       ///< 0777\r
 #define DEFFILEMODE (S_IRWXU|S_IRWXG|S_IRWXO)     ///< 0777\r
 \r
+#define READ_PERMS  (S_IRUSR | S_IRGRP | S_IROTH)   ///< 0444\r
+#define WRITE_PERMS (S_IWUSR | S_IWGRP | S_IWOTH)   ///< 0222\r
+#define EXEC_PERMS  (S_IXUSR | S_IXGRP | S_IXOTH)   ///< 0111\r
+\r
 #define S_BLKSIZE 512   ///< block size used in the stat struct\r
 \r
 /*\r
@@ -169,25 +173,29 @@ __BEGIN_DECLS
 #ifndef __STAT_SYSCALLS_DECLARED\r
   #define __STAT_SYSCALLS_DECLARED\r
 \r
-/**\r
-**/\r
-  extern int      mkdir     (const char *, mode_t);\r
+  /**\r
+  **/\r
+  mode_t  umask (mode_t);\r
+\r
+  /**\r
+  **/\r
+  int     mkdir (const char *, mode_t);\r
 \r
   /**\r
   **/\r
-  extern int      fstat     (int, struct stat *);\r
+  int     fstat (int, struct stat *);\r
 \r
   /**\r
   **/\r
-  extern int      lstat     (const char *, struct stat *);\r
+  int     lstat (const char *, struct stat *);\r
 \r
   /**\r
   **/\r
-  extern int      stat      (const char *, struct stat *);\r
+  int     stat  (const char *, struct stat *);\r
 \r
   /**\r
   **/\r
-  extern int      chmod     (const char *, mode_t);\r
+  int     chmod (const char *, mode_t);\r
 #endif  // __STAT_SYSCALLS_DECLARED\r
 __END_DECLS\r
 \r
index b8957f4c4171d0b21fd27b5949447759ec91eeeb..2b05b116b70541ce0b2c6dcb95f05e1d109e0ecf 100644 (file)
@@ -59,12 +59,10 @@ struct timeval {
 /*\r
  * Structure defined by POSIX.1b to be like a timeval.\r
  * This works within EFI since the times really are time_t.\r
- * Note that this is not exactly POSIX compliant since tv_nsec\r
- * is a UINT32 instead of the compliant long.\r
  */\r
 struct timespec {\r
   time_t  tv_sec;   /* seconds */\r
-  UINT32  tv_nsec;  /* and nanoseconds */\r
+  LONG32  tv_nsec;  /* and nanoseconds */\r
 };\r
 \r
 #define TIMEVAL_TO_TIMESPEC(tv, ts) do {        \\r
@@ -182,10 +180,14 @@ __BEGIN_DECLS
 /* Convert an EFI_TIME structure into a time_t value. */\r
 time_t  Efi2Time( EFI_TIME *EfiBDtime);\r
 \r
+/* Convert a time_t value into an EFI_TIME structure.\r
+    It is the caller's responsibility to free the returned structure.\r
+*/\r
+EFI_TIME *  Time2Efi(time_t OTime);\r
+\r
 /* Convert an EFI_TIME structure into a C Standard tm structure. */\r
 void    Efi2Tm( EFI_TIME *EfiBDtime, struct tm *NewTime);\r
-\r
-__END_DECLS\r
+void    Tm2Efi( struct tm *BdTime, EFI_TIME *ETime);\r
 \r
 /* BSD compatibility functions */\r
 int gettimeofday (struct timeval *tp, void *ignore);\r
@@ -193,4 +195,6 @@ int gettimeofday (struct timeval *tp, void *ignore);
 int getitimer (int which, struct itimerval *value);\r
 int setitimer (int which, const struct itimerval *value, struct itimerval *ovalue);\r
 \r
+__END_DECLS\r
+\r
 #endif /* !_SYS_TIME_H_ */\r
index 408d74391a9623d2f0db71eca0592f4ab8acc9f8..54ae00836f686b94c51c71ca1d46f0850162e16c 100644 (file)
@@ -238,7 +238,7 @@ typedef int64_t   dtime_t;  /* on-disk time_t */
 #endif\r
 \r
 #if   defined(_BSD_CLOCK_T_) && defined(_EFI_CLOCK_T)\r
-  typedef _BSD_CLOCK_T_     clock_t;\r
+  typedef _EFI_CLOCK_T      clock_t;\r
   #undef  _BSD_CLOCK_T_\r
   #undef  _EFI_CLOCK_T\r
 #endif\r
@@ -256,7 +256,7 @@ typedef int64_t   dtime_t;  /* on-disk time_t */
 #endif\r
 \r
 #if   defined(_BSD_TIME_T_) && defined(_EFI_TIME_T)\r
-  typedef _BSD_TIME_T_    time_t;\r
+  typedef _EFI_TIME_T     time_t;\r
   #undef  _BSD_TIME_T_\r
   #undef  _EFI_TIME_T\r
 #endif\r
index a63d88df55ea8756d199a03b70ce1e301ad32428..274e29f0963d17f2a9d66e4f399cf955e3c1a096 100644 (file)
@@ -1,6 +1,14 @@
-/*  $NetBSD: unistd.h,v 1.35 2006/08/14 18:17:48 rpaulo Exp $ */\r
+/** @file\r
+\r
+  Copyright (c) 2011, 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.\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
  * Copyright (c) 1989, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\r
  * SUCH DAMAGE.\r
  *\r
  *  @(#)unistd.h  8.2 (Berkeley) 1/7/94\r
- */\r
-\r
+    NetBSD: unistd.h,v 1.35 2006/08/14 18:17:48 rpaulo Exp\r
+**/\r
 #ifndef _SYS_UNISTD_H_\r
 #define _SYS_UNISTD_H_\r
 \r
 #include <sys/featuretest.h>\r
 \r
 /* compile-time symbolic constants */\r
-//#define _POSIX_JOB_CONTROL  /* implementation supports job control */\r
 \r
 /*\r
  * According to POSIX 1003.1:\r
 #define _POSIX2_VERSION   199212L\r
 \r
 /* execution-time symbolic constants */\r
-        /* chown requires appropriate privileges */\r
-//#define _POSIX_CHOWN_RESTRICTED 1\r
-//        /* clock selection */\r
-//#define _POSIX_CLOCK_SELECTION  -1\r
-//        /* too-long path components generate errors */\r
-//#define _POSIX_NO_TRUNC   1\r
-//        /* may disable terminal special characters */\r
-//#define _POSIX_VDISABLE   ((unsigned char)'\377')\r
-//        /* file synchronization is available */\r
-//#define _POSIX_FSYNC    1\r
-//        /* synchronized I/O is available */\r
-//#define _POSIX_SYNCHRONIZED_IO  1\r
-//        /* memory mapped files */\r
-//#define _POSIX_MAPPED_FILES 1\r
-//        /* memory locking of whole address space */\r
-//#define _POSIX_MEMLOCK    1\r
-//        /* memory locking address ranges */\r
-//#define _POSIX_MEMLOCK_RANGE  1\r
-//        /* memory access protections */\r
-//#define _POSIX_MEMORY_PROTECTION 1\r
-//        /* monotonic clock */\r
-//#define _POSIX_MONOTONIC_CLOCK  200112L\r
-//        /* threads */\r
-//#define _POSIX_THREADS    200112L\r
-//        /* semaphores */\r
-//#define _POSIX_SEMAPHORES 0\r
-//        /* barriers */\r
-//#define _POSIX_BARRIERS   200112L\r
         /* timers */\r
 #define _POSIX_TIMERS   200112L\r
-        /* spin locks */\r
-//#define _POSIX_SPIN_LOCKS 200112L\r
-//        /* read/write locks */\r
-//#define _POSIX_READER_WRITER_LOCKS  200112L\r
-//        /* XPG4.2 shared memory */\r
-//#define _XOPEN_SHM    0\r
+\r
+/* Always ensure that these are consistent with <fcntl.h>!\r
+   whence values for lseek(2).\r
+*/\r
+#ifndef SEEK_SET\r
+#define SEEK_SET  0 /**< set file offset to offset */\r
+#endif\r
+#ifndef SEEK_CUR\r
+#define SEEK_CUR  1 /**< set file offset to current plus offset */\r
+#endif\r
+#ifndef SEEK_END\r
+#define SEEK_END  2 /**< set file offset to EOF plus offset */\r
+#endif\r
 \r
 /* whence values for lseek(2); renamed by POSIX 1003.1 */\r
 #define L_SET   SEEK_SET\r
 #define L_INCR    SEEK_CUR\r
 #define L_XTND    SEEK_END\r
 \r
-/*\r
- * fsync_range values.\r
- *\r
- * Note the following flag values were chosen to not overlap\r
- * values for SEEK_XXX flags.  While not currently implemented,\r
- * it is possible to extend this call to respect SEEK_CUR and\r
- * SEEK_END offset addressing modes.\r
- */\r
-#define FDATASYNC 0x0010  /* sync data and minimal metadata */\r
-#define FFILESYNC 0x0020  /* sync data and metadata */\r
-#define FDISKSYNC 0x0040  /* flush disk caches after sync */\r
-\r
-/* configurable pathname variables; use as argument to pathconf(3) */\r
-#define _PC_LINK_MAX     1\r
-#define _PC_MAX_CANON    2\r
-#define _PC_MAX_INPUT    3\r
-#define _PC_NAME_MAX     4\r
-#define _PC_PATH_MAX     5\r
-#define _PC_PIPE_BUF     6\r
-#define _PC_CHOWN_RESTRICTED   7\r
-#define _PC_NO_TRUNC     8\r
-#define _PC_VDISABLE     9\r
-#define _PC_SYNC_IO   10\r
-#define _PC_FILESIZEBITS  11\r
-\r
-/* configurable system variables; use as argument to sysconf(3) */\r
-/*\r
- * XXX The value of _SC_CLK_TCK is embedded in <time.h>.\r
- * XXX The value of _SC_PAGESIZE is embedded in <sys/shm.h>.\r
- */\r
-#define _SC_ARG_MAX    1\r
-#define _SC_CHILD_MAX    2\r
-#define _O_SC_CLK_TCK    3 /* Old version, always 100 */\r
-#define _SC_NGROUPS_MAX    4\r
-#define _SC_OPEN_MAX     5\r
-#define _SC_JOB_CONTROL    6\r
-#define _SC_SAVED_IDS    7\r
-#define _SC_VERSION    8\r
-#define _SC_BC_BASE_MAX    9\r
-#define _SC_BC_DIM_MAX    10\r
-#define _SC_BC_SCALE_MAX  11\r
-#define _SC_BC_STRING_MAX 12\r
-#define _SC_COLL_WEIGHTS_MAX  13\r
-#define _SC_EXPR_NEST_MAX 14\r
-#define _SC_LINE_MAX    15\r
-#define _SC_RE_DUP_MAX    16\r
-#define _SC_2_VERSION   17\r
-#define _SC_2_C_BIND    18\r
-#define _SC_2_C_DEV   19\r
-#define _SC_2_CHAR_TERM   20\r
-#define _SC_2_FORT_DEV    21\r
-#define _SC_2_FORT_RUN    22\r
-#define _SC_2_LOCALEDEF   23\r
-#define _SC_2_SW_DEV    24\r
-#define _SC_2_UPE   25\r
-#define _SC_STREAM_MAX    26\r
-#define _SC_TZNAME_MAX    27\r
-#define _SC_PAGESIZE    28\r
-#define _SC_PAGE_SIZE   _SC_PAGESIZE  /* 1170 compatibility */\r
-#define _SC_FSYNC   29\r
-#define _SC_XOPEN_SHM   30\r
-#define _SC_SYNCHRONIZED_IO 31\r
-#define _SC_IOV_MAX   32\r
-#define _SC_MAPPED_FILES  33\r
-#define _SC_MEMLOCK   34\r
-#define _SC_MEMLOCK_RANGE 35\r
-#define _SC_MEMORY_PROTECTION 36\r
-#define _SC_LOGIN_NAME_MAX  37\r
-#define _SC_MONOTONIC_CLOCK 38\r
-#define _SC_CLK_TCK   39 /* New, variable version */\r
-#define _SC_ATEXIT_MAX    40\r
-#define _SC_THREADS   41\r
-#define _SC_SEMAPHORES    42\r
-#define _SC_BARRIERS    43\r
-#define _SC_TIMERS    44\r
-#define _SC_SPIN_LOCKS    45\r
-#define _SC_READER_WRITER_LOCKS 46\r
-#define _SC_GETGR_R_SIZE_MAX  47\r
-#define _SC_GETPW_R_SIZE_MAX  48\r
-#define _SC_CLOCK_SELECTION 49\r
-\r
 /* configurable system strings */\r
 #define _CS_PATH     1\r
 \r
index 4d738c64b61656df9e4e1995ed2df1a1f7db3e30..b2fd92358a401d745e28a4b59ede33088ef08a8a 100644 (file)
 #define F_TLOCK   2\r
 #define F_TEST    3\r
 \r
+/* access function */\r
+#define F_OK      0     /* test for existence of file */\r
+#define X_OK      0x01  /* test for execute or search permission */\r
+#define W_OK      0x02  /* test for write permission */\r
+#define R_OK      0x04  /* test for read permission */\r
+\r
 \r
 __BEGIN_DECLS\r
 int             dup(int);\r
@@ -41,6 +47,65 @@ int             usleep(useconds_t);
 unsigned int    sleep(unsigned int);\r
 char           *basename(char *path);\r
 \r
+#ifndef GETCWD_DECLARED\r
+  /** Gets the current working directory.\r
+\r
+  The getcwd() function shall place an absolute pathname of the current\r
+  working directory in the array pointed to by buf, and return buf. The\r
+  pathname copied to the array shall contain no components that are\r
+  symbolic links. The size argument is the size in bytes of the character\r
+  array pointed to by the buf argument.\r
+\r
+  @param[in,out] Buf        The buffer to fill.\r
+  @param[in]     BufSize    The number of bytes in buffer.\r
+\r
+  @retval NULL          The function failed.\r
+  @retval NULL          Buf was NULL.\r
+  @retval NULL          Size was 0.\r
+  @return buf           The function completed successfully. See errno for info.\r
+  **/\r
+  char           *getcwd(char *Buf, size_t BufSize);\r
+  #define GETCWD_DECLARED\r
+#endif\r
+\r
+#ifndef CHDIR_DECLARED\r
+  /** Change the current working directory.\r
+\r
+  The chdir() function shall cause the directory named by the pathname\r
+  pointed to by the path argument to become the current working directory;\r
+  that is, the starting point for path searches for pathnames not beginning\r
+  with '/'.\r
+\r
+  @param[in] Path   The new path to set.\r
+\r
+  @todo Add non-shell CWD changing.\r
+  **/\r
+  int       chdir(const char *Path);\r
+#define CHDIR_DECLARED\r
+#endif\r
+\r
+/** Determine accessibility of a file.\r
+    The access() function checks the file, named by the pathname pointed to by\r
+    the Path argument, for accessibility according to the bit pattern contained\r
+    in Mode.\r
+\r
+    The value of Mode is either the bitwise-inclusive OR of the access\r
+    permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).\r
+\r
+    If Path ends in '/' or '\\', the target must be a directory, otherwise it doesn't matter.\r
+    A file is executable if it is NOT a directory and it ends in ".efi".\r
+\r
+    @param[in]    Path    Path or name of the file to be checked.\r
+    @param[in]    Mode    Access permissions to check for.\r
+\r
+    @retval   0   Successful completion.\r
+    @retval  -1   File is not accessible with the given Mode.  The error condition\r
+                  is indicated by errno.  Values of errno specific to the access\r
+                  function include: EACCES, ENOENT, ENOTDIR, ENAMETOOLONG\r
+**/\r
+int             access(const char *Path, int Mode);\r
+pid_t           getpid(void);\r
+\r
 // Networking\r
 long            gethostid(void);\r
 int             gethostname(char *, size_t);\r
@@ -77,7 +142,6 @@ gid_t           getegid(void);
 uid_t           geteuid(void);\r
 gid_t           getgid(void);\r
 int             getgroups(int, gid_t []);\r
-pid_t           getpid(void);\r
 pid_t           getppid(void);\r
 int             link(const char *, const char *);\r
 long            pathconf(const char *, int);\r
diff --git a/StdLib/Include/utime.h b/StdLib/Include/utime.h
new file mode 100644 (file)
index 0000000..744881c
--- /dev/null
@@ -0,0 +1,66 @@
+/** @file\r
+\r
+  Copyright (c) 2011, 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.\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) 1990, 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
+ *  @(#)utime.h 8.1 (Berkeley) 6/2/93\r
+    NetBSD: utime.h,v 1.8 2005/02/03 04:39:32 perry Exp\r
+ */\r
+\r
+#ifndef _UTIME_H_\r
+#define _UTIME_H_\r
+\r
+#include <sys/cdefs.h>\r
+#include <machine/ansi.h>\r
+#include  <sys/time.h>\r
+\r
+#if   defined(_BSD_TIME_T_) && defined(_EFI_TIME_T)\r
+typedef _EFI_TIME_T     time_t;\r
+#undef  _BSD_TIME_T_\r
+#undef  _EFI_TIME_T\r
+#endif\r
+\r
+struct utimbuf {\r
+  time_t actime;    /* Access time */\r
+  time_t modtime;   /* Modification time */\r
+};\r
+\r
+__BEGIN_DECLS\r
+  int utime   (const char *path, const struct utimbuf *times);\r
+  int utimes  (const char *path, const struct timeval *times);\r
+__END_DECLS\r
+\r
+#endif /* !_UTIME_H_ */\r
index 1e1e0fdccbfb2ef53082f33d1bf31c458ceb6b27..b9658441ae32d868a201be993e2776029734783b 100644 (file)
@@ -234,7 +234,7 @@ isblank(
   IN  int c\r
   )\r
 {\r
-  return (__isCClass( c, _CB));\r
+  return (__isCClass( c, (_CB)));\r
 }\r
 \r
 /** The isascii function tests that a character is one of the 128 7-bit ASCII characters.\r
@@ -251,3 +251,21 @@ isascii(
 {\r
   return ((c >= 0) && (c < 128));\r
 }\r
+\r
+/** Test whether a character is one of the characters used as a separator\r
+    between directory elements in a path.\r
+\r
+    Characters are '/', '\\'\r
+\r
+    This non-standard function is unique to this implementation.\r
+\r
+    @param[in]    c   The character to be tested.\r
+\r
+    @return   Returns nonzero (true) if and only if the value of the parameter c\r
+              can be classified as specified in the description of the function.\r
+**/\r
+int\r
+isDirSep(int c)\r
+{\r
+  return (__isCClass( c, (_C0)));\r
+}\r
index 6b289bf2f29fd78de9fa02f348880168a372c258..b40a65d1ffaf74e50c4eb2cca3a4ffae0530702c 100644 (file)
@@ -57,7 +57,7 @@ const UINT16  _C_CharClassTable[128] = {
   /* 24 '$' */    ( _CP | _CG  ),\r
   /* 25 '%' */    ( _CP | _CG  ),\r
   /* 26 '&' */    ( _CP | _CG  ),\r
-  /* 27 '\''*/    ( _CP | _CG  ),\r
+  /* 27 '\''*/    ( _CP | _CG | _C0  ),\r
   /* 28 '(' */    ( _CP | _CG  ),\r
   /* 29 ')' */    ( _CP | _CG  ),\r
   /* 2A '*' */    ( _CP | _CG  ),\r
@@ -65,7 +65,7 @@ const UINT16  _C_CharClassTable[128] = {
   /* 2C ',' */    ( _CP | _CG  ),\r
   /* 2D '-' */    ( _CP | _CG  ),\r
   /* 2E '.' */    ( _CP | _CG  ),\r
-  /* 2F '/' */    ( _CP | _CG  ),\r
+  /* 2F '/' */    ( _CP | _CG | _C0  ),\r
   /* 30 '0' */    ( _CD | _CG  ),\r
   /* 31 '1' */    ( _CD | _CG  ),\r
   /* 32 '2' */    ( _CD | _CG  ),\r
index 4d617d21da8f50ec9bab9a12aaf616b8630d5560..2012f3c564c1d61270cf613d3ebb30519709b6c4 100644 (file)
@@ -66,7 +66,7 @@
 #include  <stdio.h>\r
 #include  <stdlib.h>\r
 #include  <string.h>\r
-#include  <sys/EfiSysCall.h>\r
+#include  <unistd.h>\r
 #include  "rune.h"\r
 #ifdef WITH_RUNE\r
   #include "rune_local.h"\r
index 3a728951f61253f7ea8dc516f00ddd993e53b4fd..4c6902396e8a03249f7b43b08130ff0c8e3eaa99 100644 (file)
@@ -1,6 +1,14 @@
-/*  $NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp $  */\r
+/** @file\r
+\r
+  Copyright (c) 2011, 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.\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
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\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
+\r
+    NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp\r
+    fdopen.c  8.1 (Berkeley) 6/4/93\r
+**/\r
 #include  <LibConfig.h>\r
 #include  <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)fdopen.c  8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include  "namespace.h"\r
 #include  <sys/types.h>\r
@@ -47,8 +51,8 @@ __RCSID("$NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp $");
 #include  <assert.h>\r
 #include  <errno.h>\r
 #include  <fcntl.h>\r
-#include  <sys/EfiSysCall.h>\r
 #include  <stdio.h>\r
+#include  <unistd.h>\r
 \r
 #include  "reentrant.h"\r
 #include  "local.h"\r
index b6495c3bcb9037f01b58fdcad799a4ca74e8a50f..bc8bfe3d29a41b722c839b96d1a443537d18e36a 100644 (file)
@@ -1,6 +1,14 @@
-/*  $NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp $  */\r
+/** @file\r
+\r
+  Copyright (c) 2011, 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.\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
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\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
+\r
+    NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp\r
+    findfp.c  8.2 (Berkeley) 1/4/94\r
+**/\r
 #include  <LibConfig.h>\r
 #include  <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)findfp.c  8.2 (Berkeley) 1/4/94";\r
-#else\r
-__RCSID("$NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include  "namespace.h"\r
 #include  <sys/param.h>\r
-#include  <sys/EfiSysCall.h>\r
 #include  <stdio.h>\r
 #include  <errno.h>\r
 #include  <stdlib.h>\r
 #include  <string.h>\r
+#include  <unistd.h>\r
 #include  "reentrant.h"\r
 #include  "local.h"\r
 #include  "glue.h"\r
index 4b3c14cd28ee937ecfb862caad0f2d9421d27a32..9fc0f6dd4cf38ef38160cf810514bfe16213e223 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
     Implementation of fopen as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\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 that accompanies this\r
     distribution.  The full text of the license may be found at\r
@@ -50,9 +50,9 @@
 #include  <sys/stat.h>\r
 #include  <assert.h>\r
 #include  <fcntl.h>\r
-#include  <sys/EfiSysCall.h>\r
 #include  <stdio.h>\r
 #include  <errno.h>\r
+#include  <unistd.h>\r
 #include  "reentrant.h"\r
 #include  "local.h"\r
 \r
index 75a086b84b2ea16d13e24d8c879327ac170a7420..58381e6d19d9938cccdb152bcc3f78d103734694 100644 (file)
 #include  <assert.h>\r
 #include  <errno.h>\r
 #include  <fcntl.h>\r
-#include  <sys/EfiSysCall.h>\r
 #include  <stdio.h>\r
 #include  <stdlib.h>\r
 #include  <wchar.h>\r
+#include  <unistd.h>\r
 #include  "reentrant.h"\r
 #include  "local.h"\r
 \r
index 7b1c564c9acd026be0ebd8e940c558908e66041a..0773340ad80cfd618ffcbb90eb40bd5d44065cb8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Internal function to generate temporary file name for tmpnam.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\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 that accompanies this\r
   distribution.  The full text of the license may be found at\r
@@ -37,6 +37,7 @@
   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
   SUCH DAMAGE.\r
 \r
+  mktemp.c  8.1 (Berkeley) 6/4/93\r
   NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp\r
 **/\r
 #include  <LibConfig.h>\r
 #if !defined(HAVE_NBTOOL_CONFIG_H) || !defined(HAVE_MKSTEMP) || !defined(HAVE_MKDTEMP)\r
 \r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)mktemp.c  8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include <sys/types.h>\r
 #include <sys/stat.h>\r
@@ -65,7 +59,7 @@ __RCSID("$NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp $");
 #include <fcntl.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
-#include <sys/EfiSysCall.h>\r
+#include  <unistd.h>\r
 \r
 #if HAVE_NBTOOL_CONFIG_H\r
 #define GETTEMP   gettemp\r
index 4e69be127579cfad9e57566787b48e91589cc9a7..1b5991489cf513f3646dd41deca7e11adb33d5cb 100644 (file)
@@ -52,7 +52,7 @@
 #include  <assert.h>\r
 #include  <stdio.h>\r
 #include  <stdlib.h>\r
-#include  <sys/EfiSysCall.h>\r
+#include  <unistd.h>\r
 #include  "reentrant.h"\r
 #include  "local.h"\r
 #include  <MainData.h>\r
index 4c9e4752ccd9db0dfa67d952a89789223af158a3..a20eddaf99893dfca975f8e273dc6745347a376a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Internal function for tmpnam.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\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 that accompanies this\r
   distribution.  The full text of the license may be found at\r
@@ -46,7 +46,7 @@ mktemp.c  8.1 (Berkeley) 6/4/93
 #include  <errno.h>\r
 #include  <stdio.h>\r
 #include  <stdlib.h>\r
-#include  <sys/EfiSysCall.h>\r
+#include  <unistd.h>\r
 #include  "reentrant.h"\r
 #include  "local.h"\r
 \r
index 826471cde5cceedb395f91d6eef94c6d82245ab3..7f53f95be17f8956052833638edcb3c7ecf4bfbd 100644 (file)
@@ -1,6 +1,14 @@
-/*  $NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $  */\r
+/** @file\r
+\r
+  Copyright (c) 2011, 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.\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
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\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
+\r
+    remove.c  8.1 (Berkeley) 6/4/93\r
+    NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp\r
+**/\r
 #include  <LibConfig.h>\r
 #include  <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)remove.c  8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include  <sys/types.h>\r
 #include  <sys/stat.h>\r
@@ -47,7 +51,7 @@ __RCSID("$NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $");
 #include  <assert.h>\r
 #include  <errno.h>\r
 #include  <stdio.h>\r
-#include  <sys/EfiSysCall.h>\r
+#include  <unistd.h>\r
 \r
 int\r
 remove(const char *file)\r
index de8963e57404f238463237c98f2510e8d2d8a5d4..7b5cc3862de4c7a42ed5d01f1465d7930521a413 100644 (file)
@@ -52,7 +52,7 @@
 #include  <errno.h>\r
 #include  <fcntl.h>\r
 #include  <stdio.h>\r
-#include  <sys/EfiSysCall.h>\r
+#include  <unistd.h>\r
 \r
 #include  "reentrant.h"\r
 #include  "local.h"\r
index f9df427c52df0a47b954d3116af00c83913852e5..94d2655c8a8f031895e7c1e2f02204fec7ff97d6 100644 (file)
@@ -1,6 +1,14 @@
-/*  $NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp $  */\r
+/** @file\r
+\r
+  Copyright (c) 2011, 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.\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
  * Copyright (c) 1988, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\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
+\r
+    tempnam.c 8.1 (Berkeley) 6/4/93\r
+    NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp\r
+**/\r
 #include  <LibConfig.h>\r
 #include  <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include  "namespace.h"\r
 #include  <sys/param.h>\r
@@ -44,7 +48,7 @@ __RCSID("$NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp $");
 #include  <stdio.h>\r
 #include  <stdlib.h>\r
 #include  <string.h>\r
-#include  <sys/EfiSysCall.h>\r
+#include  <unistd.h>\r
 #include  <paths.h>\r
 #include  "reentrant.h"\r
 #include  "local.h"\r
index 97040d58f210b82da2912aea1da931a62589e020..d93787684bb5c868bec4afd030c96cd524386ceb 100644 (file)
@@ -1,6 +1,14 @@
-/*  $NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp $ */\r
+/** @file\r
+\r
+  Copyright (c) 2011, 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.\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
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\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
+\r
+    tmpfile.c 8.1 (Berkeley) 6/4/93\r
+    NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp\r
+**/\r
 #include  <LibConfig.h>\r
 #include  <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include  "namespace.h"\r
 #include  <sys/types.h>\r
-#include  <sys/EfiSysCall.h>\r
 #include  <signal.h>\r
 #include  <errno.h>\r
 #include  <stdio.h>\r
 #include  <stdlib.h>\r
 #include  <string.h>\r
 #include  <paths.h>\r
+#include  <unistd.h>\r
 \r
 #define TRAILER "tmp.XXXX"\r
 \r
index 74dd77325a86578f2c39fef28933da3b84b707a5..95c6edd04b10b0e4c478b3b36e88288d0e44a44b 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of tmpnam as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\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 that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license\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
@@ -50,7 +50,7 @@
 #include  <sys/types.h>\r
 #include  <paths.h>\r
 #include  <stdio.h>\r
-#include  <sys/EfiSysCall.h>\r
+#include  <unistd.h>\r
 #include  "reentrant.h"\r
 #include  "local.h"\r
 \r
index 8c033fd7d96bd64694934ca3969a66bb707a130d..50f2deec057a326aad92814ba49bdfb255bc5063 100644 (file)
 #include  "tzfile.h"\r
 #include  <MainData.h>\r
 \r
-/* Convert an EFI_TIME structure into a C Standard tm structure. */\r
+/** Convert an EFI_TIME structure into a C Standard tm structure.\r
+\r
+    @param[in]    ET    Pointer to the EFI_TIME structure to convert.\r
+    @param[out]   BT    Pointer to the tm structure to receive the converted time.\r
+*/\r
 void\r
-Efi2Tm( EFI_TIME *ET, struct tm *BT)\r
+Efi2Tm(\r
+  IN      EFI_TIME  *ET,\r
+     OUT  struct tm *BT\r
+  )\r
 {\r
   // Convert EFI time to broken-down time.\r
   BT->tm_year = ET->Year - TM_YEAR_BASE;\r
@@ -36,11 +43,68 @@ Efi2Tm( EFI_TIME *ET, struct tm *BT)
   BT->tm_Nano = ET->Nanosecond;\r
 }\r
 \r
-/* Convert an EFI_TIME structure into a time_t value. */\r
+/** Convert an EFI_TIME structure into a time_t value.\r
+\r
+    @param[in]  EfiBDtime   Pointer to the EFI_TIME structure to convert.\r
+\r
+    @return   The EFI_TIME converted into a time_t value.\r
+*/\r
 time_t\r
-Efi2Time( EFI_TIME *EfiBDtime)\r
+Efi2Time(\r
+  IN  EFI_TIME *EfiBDtime\r
+  )\r
 {\r
   Efi2Tm( EfiBDtime, &gMD->BDTime);\r
 \r
   return mktime( &gMD->BDTime);\r
 }\r
+\r
+/** Convert a C Standard tm structure into an EFI_TIME structure.\r
+\r
+    @param[in]    BT    Pointer to the tm structure to convert.\r
+    @param[out]   ET    Pointer to an EFI_TIME structure to receive the converted time.\r
+*/\r
+void\r
+Tm2Efi(\r
+  IN      struct tm *BT,\r
+     OUT  EFI_TIME  *ET\r
+  )\r
+{\r
+  ET->Year        = (UINT16)BT->tm_year + TM_YEAR_BASE;\r
+  ET->Month       = (UINT8)BT->tm_mon + 1;\r
+  ET->Day         = (UINT8)BT->tm_mday;\r
+  ET->Hour        = (UINT8)BT->tm_hour;\r
+  ET->Minute      = (UINT8)BT->tm_min;\r
+  ET->Second      = (UINT8)BT->tm_sec;\r
+  ET->Nanosecond  = (UINT32)BT->tm_Nano;\r
+  ET->TimeZone    = (INT16)BT->tm_zoneoff;\r
+  ET->Daylight    = (UINT8)BT->tm_daylight;\r
+}\r
+\r
+/** Convert a time_t value into an EFI_TIME structure.\r
+\r
+    @param[in]    CalTime   Calendar time as a time_t value.\r
+\r
+    @return   Returns a newly malloced EFI_TIME structure containing\r
+              the converted calendar time.\r
+\r
+    @post     It is the responsibility of the caller to free the\r
+              returned structure before the application exits.\r
+*/\r
+EFI_TIME*\r
+Time2Efi(\r
+  IN  time_t CalTime\r
+  )\r
+{\r
+  struct tm *IT;\r
+  EFI_TIME  *ET   = NULL;\r
+\r
+  IT = gmtime(&CalTime);\r
+  if(IT != NULL) {\r
+    ET = malloc(sizeof(EFI_TIME));\r
+    if(ET != NULL) {\r
+      Tm2Efi(IT, ET);\r
+    }\r
+  }\r
+  return ET;\r
+}\r
index a7b589b7df720e933762d3a46b46c1741e70584d..309d7b352768156f9f5eea16dce147f0aa7c3306 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
     Time Zone processing.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, 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
@@ -19,7 +19,6 @@
   NetBSD: localtime.c,v 1.39 2006/03/22 14:01:30 christos Exp\r
 **/\r
 #include  <LibConfig.h>\r
-#include  <sys/EfiSysCall.h>\r
 \r
 #include  <ctype.h>\r
 #include  <fcntl.h>\r
@@ -27,6 +26,7 @@
 #include  <stdlib.h>\r
 #include  <string.h>\r
 #include  <time.h>\r
+#include  <unistd.h>\r
 #include  "tzfile.h"\r
 #include  "TimeVals.h"\r
 \r
index d6f6ab44c0fafd5eee5725ec8b44bd08189d30db..00712b824793bbe7ae1c9d52c04c97d4682a4a38 100644 (file)
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 **/\r
 #include <LibConfig.h>\r
-#include <sys/EfiSysCall.h>\r
 #include <sys/time.h>\r
 #include <time.h>\r
 #include <errno.h>\r
 #include <sys/signal.h>\r
 #include <signal.h>\r
+#include  <unistd.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/UefiLib.h>\r
@@ -274,4 +274,4 @@ int getitimer(
   }\r
 \r
   return 0;\r
-}
\ No newline at end of file
+}\r
index 600fb073c42e3b864aa7ab527b8a058c659c9fac..e9983e993399ca9aad6b2154cad85ad4c9e5393b 100644 (file)
 #include  <Protocol/SimpleTextOut.h>\r
 \r
 #include  <LibConfig.h>\r
-#include  <sys/EfiSysCall.h>\r
 \r
 #include  <errno.h>\r
 #include  <wctype.h>\r
 #include  <wchar.h>\r
 #include  <stdarg.h>\r
 #include  <sys/fcntl.h>\r
+#include  <unistd.h>\r
 #include  <kfile.h>\r
 #include  <Device/Device.h>\r
 #include  <MainData.h>\r
index de14ef31c57fe3a39c8c178ccd52d9f35eb75acf..861765e6bc34f7cf54dc73f0fe0e945842400fdc 100644 (file)
@@ -21,7 +21,6 @@
 #include  <Library/ShellLib.h>\r
 \r
 #include  <LibConfig.h>\r
-#include  <sys/EfiSysCall.h>\r
 \r
 #include  <errno.h>\r
 #include  <string.h>\r
 #include  <wctype.h>\r
 #include  <wchar.h>\r
 #include  <sys/fcntl.h>\r
+#include  <sys/filio.h>\r
 #include  <sys/syslimits.h>\r
+#include  <unistd.h>\r
 #include  <kfile.h>\r
 #include  <Device/Device.h>\r
 #include  <MainData.h>\r
 #include  <Efi/SysEfi.h>\r
 \r
+/** EFI Shell specific operations for close().\r
+\r
+    @param[in]    Fp    Pointer to a file descriptor structure.\r
+\r
+    @retval      0      Successful completion.\r
+    @retval     -1      Operation failed.  Further information is specified by errno.\r
+**/\r
 static\r
 int\r
 EFIAPI\r
@@ -50,6 +58,13 @@ da_ShellClose(
   return 0;\r
 }\r
 \r
+/** EFI Shell specific operations for deleting a file or directory.\r
+\r
+    @param[in]    filp    Pointer to a file descriptor structure.\r
+\r
+    @retval      0      Successful completion.\r
+    @retval     -1      Operation failed.  Further information is specified by errno.\r
+**/\r
 static\r
 int\r
 EFIAPI\r
@@ -68,6 +83,14 @@ da_ShellDelete(
   return 0;\r
 }\r
 \r
+/** EFI Shell specific operations for setting the position within a file.\r
+\r
+    @param[in]    filp    Pointer to a file descriptor structure.\r
+    @param[in]    offset  Relative position to move to.\r
+    @param[in]    whence  Specifies the location offset is relative to: Beginning, Current, End.\r
+\r
+    @return     Returns the new file position or EOF if the seek failed.\r
+**/\r
 static\r
 off_t\r
 EFIAPI\r
@@ -126,6 +149,9 @@ da_ShellSeek(
 \r
     The directory is closed after it is created.\r
 \r
+    @param[in]    path      The directory to be created.\r
+    @param[in]    perms     Access permissions for the new directory.\r
+\r
     @retval   0   The directory was created successfully.\r
     @retval  -1   An error occurred and an error code is stored in errno.\r
 **/\r
@@ -137,6 +163,7 @@ da_ShellMkdir(
   __mode_t      perms\r
   )\r
 {\r
+  UINT64            TempAttr;\r
   SHELL_FILE_HANDLE FileHandle;\r
   RETURN_STATUS     Status;\r
   EFI_FILE_INFO    *FileInfo;\r
@@ -152,7 +179,8 @@ da_ShellMkdir(
       FileInfo = ShellGetFileInfo( FileHandle);\r
       Status = RETURN_ABORTED;  // In case ShellGetFileInfo() failed\r
       if(FileInfo != NULL) {\r
-        FileInfo->Attribute = Omode2EFI(perms);\r
+        TempAttr  = FileInfo->Attribute & (EFI_FILE_RESERVED | EFI_FILE_DIRECTORY);\r
+        FileInfo->Attribute = TempAttr | Omode2EFI(perms);\r
         Status = ShellSetFileInfo( FileHandle, FileInfo);\r
         FreePool(FileInfo);\r
         if(Status == RETURN_SUCCESS) {\r
@@ -168,6 +196,16 @@ da_ShellMkdir(
   return retval;\r
 }\r
 \r
+/** EFI Shell specific operations for reading from a file.\r
+\r
+    @param[in]    filp        Pointer to a file descriptor structure.\r
+    @param[in]    offset      Offset into the file to begin reading at, or NULL.\r
+    @param[in]    BufferSize  Number of bytes in Buffer.  Max number of bytes to read.\r
+    @param[in]    Buffer      Pointer to a buffer to receive the read data.\r
+\r
+    @return     Returns the number of bytes successfully read,\r
+                or -1 if the operation failed.  Further information is specified by errno.\r
+**/\r
 static\r
 ssize_t\r
 EFIAPI\r
@@ -209,6 +247,16 @@ da_ShellRead(
   return BufSize;\r
 }\r
 \r
+/** EFI Shell specific operations for writing to a file.\r
+\r
+    @param[in]    filp        Pointer to a file descriptor structure.\r
+    @param[in]    offset      Offset into the file to begin writing at, or NULL.\r
+    @param[in]    BufferSize  Number of bytes in Buffer.  Max number of bytes to write.\r
+    @param[in]    Buffer      Pointer to a buffer containing the data to be written.\r
+\r
+    @return     Returns the number of bytes successfully written,\r
+                or -1 if the operation failed.  Further information is specified by errno.\r
+**/\r
 static\r
 ssize_t\r
 EFIAPI\r
@@ -261,6 +309,15 @@ da_ShellWrite(
   return BufSize;\r
 }\r
 \r
+/** EFI Shell specific operations for getting information about an open file.\r
+\r
+    @param[in]    filp        Pointer to a file descriptor structure.\r
+    @param[out]   statbuf     Buffer in which to store the file status.\r
+    @param[in]    Something   This parameter is not used by this device.\r
+\r
+    @retval      0      Successful completion.\r
+    @retval     -1      Operation failed.  Further information is specified by errno.\r
+**/\r
 static\r
 int\r
 EFIAPI\r
@@ -314,6 +371,15 @@ da_ShellStat(
   return (Status == RETURN_SUCCESS)? 0 : -1;\r
 }\r
 \r
+/** EFI Shell specific operations for low-level control of a file or device.\r
+\r
+    @param[in]      filp    Pointer to a file descriptor structure.\r
+    @param[in]      cmd     The command this ioctl is to perform.\r
+    @param[in,out]  argp    Zero or more arguments as needed by the command.\r
+\r
+    @retval      0      Successful completion.\r
+    @retval     -1      Operation failed.  Further information is specified by errno.\r
+**/\r
 static\r
 int\r
 EFIAPI\r
@@ -323,10 +389,70 @@ da_ShellIoctl(
   va_list             argp\r
   )\r
 {\r
-  return -EPERM;\r
+  EFI_FILE_INFO    *FileInfo      = NULL;\r
+  SHELL_FILE_HANDLE FileHandle;\r
+  RETURN_STATUS     Status        = RETURN_SUCCESS;\r
+  int               retval        = 0;\r
+\r
+  FileHandle = (SHELL_FILE_HANDLE)filp->devdata;\r
+\r
+  FileInfo = ShellGetFileInfo( FileHandle);\r
+\r
+  if(FileInfo != NULL) {\r
+    if( cmd == (ULONGN)FIOSETIME) {\r
+      struct timeval  *TV;\r
+      EFI_TIME        *ET;\r
+      int              mod = 0;\r
+\r
+      TV = va_arg(argp, struct timeval*);\r
+      if(TV[0].tv_sec != 0) {\r
+        ET = Time2Efi(TV[0].tv_sec);\r
+        if(ET != NULL) {\r
+          (void) memcpy(&FileInfo->LastAccessTime, ET, sizeof(EFI_TIME));\r
+          FileInfo->LastAccessTime.Nanosecond = TV[0].tv_usec * 1000;\r
+          free(ET);\r
+          ++mod;\r
+        }\r
+      }\r
+      if(TV[1].tv_sec != 0) {\r
+        ET = Time2Efi(TV[1].tv_sec);\r
+        if(ET != NULL) {\r
+          (void) memcpy(&FileInfo->ModificationTime, ET, sizeof(EFI_TIME));\r
+          FileInfo->ModificationTime.Nanosecond = TV[1].tv_usec * 1000;\r
+          free(ET);\r
+          ++mod;\r
+        }\r
+      }\r
+      /* Set access and modification times */\r
+      Status = ShellSetFileInfo(FileHandle, FileInfo);\r
+      errno = EFI2errno(Status);\r
+    }\r
+  }\r
+  else {\r
+    Status = RETURN_DEVICE_ERROR;\r
+    errno  = EIO;\r
+  }\r
+  if(RETURN_ERROR(Status)) {\r
+    retval = -1;\r
+  }\r
+  EFIerrno  = Status;\r
+\r
+  if(FileInfo != NULL) {\r
+    FreePool(FileInfo);     // Release the buffer allocated by the GetInfo function\r
+  }\r
+  return retval;\r
 }\r
 \r
-/** Open an abstract Shell File.\r
+/** EFI Shell specific operations for opening a file or directory.\r
+\r
+    @param[in]    DevNode   Pointer to a device descriptor\r
+    @param[in]    filp      Pointer to a file descriptor structure.\r
+    @param[in]    DevInstance   Not used by this device.\r
+    @param[in]    Path          File-system path to the file or directory.\r
+    @param[in]    MPath         Device or Map name on which Path resides.\r
+\r
+    @return     Returns a file descriptor for the newly opened file,\r
+                or -1 if the Operation failed.  Further information is specified by errno.\r
 **/\r
 int\r
 EFIAPI\r
@@ -447,14 +573,19 @@ da_ShellOpen(
 }\r
 \r
 #include  <sys/poll.h>\r
-/*  Returns a bit mask describing which operations could be completed immediately.\r
+/** Returns a bit mask describing which operations could be completed immediately.\r
 \r
     For now, assume the file system, via the shell, is always ready.\r
 \r
     (POLLIN | POLLRDNORM)   The file system is ready to be read.\r
     (POLLOUT)               The file system is ready for output.\r
 \r
-*/\r
+    @param[in]    filp    Pointer to a file descriptor structure.\r
+    @param[in]    events  Bit mask describing which operations to check.\r
+\r
+    @return     The returned value is a bit mask describing which operations\r
+                could be completed immediately, without blocking.\r
+**/\r
 static\r
 short\r
 EFIAPI\r
@@ -488,6 +619,14 @@ da_ShellPoll(
   return (retval & (events | POLL_RETONLY));\r
 }\r
 \r
+/** EFI Shell specific operations for renaming a file.\r
+\r
+    @param[in]    from    Name of the file to be renamed.\r
+    @param[in]    to      New name for the file.\r
+\r
+    @retval      0      Successful completion.\r
+    @retval     -1      Operation failed.  Further information is specified by errno.\r
+**/\r
 static\r
 int\r
 EFIAPI\r
@@ -553,6 +692,13 @@ da_ShellRename(
   return -1;\r
 }\r
 \r
+/** EFI Shell specific operations for deleting directories.\r
+\r
+    @param[in]    filp    Pointer to a file descriptor structure.\r
+\r
+    @retval      0      Successful completion.\r
+    @retval     -1      Operation failed.  Further information is specified by errno.\r
+**/\r
 static\r
 int\r
 EFIAPI\r
@@ -562,10 +708,12 @@ da_ShellRmdir(
 {\r
   SHELL_FILE_HANDLE FileHandle;\r
   RETURN_STATUS     Status = RETURN_SUCCESS;\r
-  EFI_FILE_INFO     *FileInfo = NULL;\r
+  EFI_FILE_INFO     *FileInfo;\r
+  int               OldErrno;\r
   int               Count = 0;\r
   BOOLEAN           NoFile = FALSE;\r
 \r
+  OldErrno  = errno;  // Save the original value\r
   errno = 0;    // Make it easier to see if we have an error later\r
 \r
   FileHandle = (SHELL_FILE_HANDLE)filp->devdata;\r
@@ -576,8 +724,8 @@ da_ShellRmdir(
       errno = ENOTDIR;\r
     }\r
     else {\r
-      // See if the directory has any entries other than ".." and ".".\r
       FreePool(FileInfo);  // Free up the buffer from ShellGetFileInfo()\r
+      // See if the directory has any entries other than ".." and ".".\r
       Status = ShellFindFirstFile( FileHandle, &FileInfo);\r
       if(Status == RETURN_SUCCESS) {\r
         ++Count;\r
@@ -593,15 +741,22 @@ da_ShellRmdir(
             Count = 99;\r
           }\r
         }\r
-        FreePool(FileInfo);   // Free buffer from ShellFindFirstFile()\r
+        /*  Count == 99 and FileInfo is allocated if ShellFindNextFile failed.\r
+            ShellFindNextFile has freed FileInfo itself if it sets NoFile TRUE.\r
+        */\r
+        if((! NoFile) || (Count == 99)) {\r
+          free(FileInfo);   // Free buffer from ShellFindFirstFile()\r
+        }\r
         if(Count < 3) {\r
           // Directory is empty\r
           Status = ShellDeleteFile( &FileHandle);\r
           if(Status == RETURN_SUCCESS) {\r
             EFIerrno = RETURN_SUCCESS;\r
+            errno    = OldErrno;    // Restore the original value\r
             return 0;\r
             /* ######## SUCCESSFUL RETURN ######## */\r
           }\r
+          /*  FileInfo is freed and FileHandle closed. */\r
         }\r
         else {\r
           if(Count == 99) {\r
@@ -617,6 +772,7 @@ da_ShellRmdir(
   else {\r
     errno = EIO;\r
   }\r
+  ShellCloseFile( &FileHandle);\r
   EFIerrno = Status;\r
   if(errno == 0) {\r
     errno = EFI2errno( Status );\r
@@ -628,6 +784,13 @@ da_ShellRmdir(
 \r
     Allocate the instance structure and populate it with the information for\r
     the device.\r
+\r
+    @param[in]    ImageHandle   This application's image handle.\r
+    @param[in]    SystemTable   Pointer to the UEFI System Table.\r
+\r
+    @retval     RETURN_SUCCESS            Successful completion.\r
+    @retval     RETURN_OUT_OF_RESOURCES   Failed to allocate memory for new device.\r
+    @retval     RETURN_INVALID_PARAMETER  A default device has already been created.\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -669,6 +832,13 @@ __ctor_DevShell(
   return  Status;\r
 }\r
 \r
+/** Destructor for previously constructed EFI Shell device instances.\r
+\r
+    @param[in]    ImageHandle   This application's image handle.\r
+    @param[in]    SystemTable   Pointer to the UEFI System Table.\r
+\r
+    @retval      0      Successful completion is always returned.\r
+**/\r
 RETURN_STATUS\r
 EFIAPI\r
 __dtor_DevShell(\r
index 1462c3ff38f301a3ce587a3281f6c48d73b0f08a..806cf4ac2b7a4c270626d176df8c49c98210055b 100644 (file)
@@ -11,6 +11,7 @@
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
+#include  <LibConfig.h>\r
 #include  <sys/EfiCdefs.h>\r
 #include  <sys/featuretest.h>\r
 #include  <namespace.h>\r
@@ -25,7 +26,8 @@ getpwuid (uid_t uid)
   return NULL;\r
 }\r
 \r
-char *getlogin (void)\r
+char *\r
+getlogin (void)\r
 {\r
   errno = EPERM;\r
   return NULL;\r
@@ -38,40 +40,53 @@ getpwnam (const char *name)
   return NULL;\r
 }\r
 \r
-uid_t getuid (void)\r
+uid_t\r
+getuid (void)\r
 {\r
   return 0;\r
 }\r
 \r
-pid_t fork (void)\r
+pid_t\r
+getpid(void)\r
+{\r
+  return 0;\r
+}\r
+\r
+pid_t\r
+fork (void)\r
 {\r
   errno = EPERM;\r
   return (-1);\r
 }\r
 \r
-int chmod (const char *c, mode_t m)\r
+int\r
+chmod (const char *c, mode_t m)\r
 {\r
   errno = EPERM;\r
   return (-1);\r
 }\r
 \r
-pid_t   wait(int *stat_loc) {\r
+pid_t\r
+wait(int *stat_loc) {\r
   return 0;\r
 }\r
 \r
-FILE *popen (const char *cmd, const char *type)\r
+FILE *\r
+popen (const char *cmd, const char *type)\r
 {\r
   errno = EPERM;\r
   return NULL;\r
 }\r
 \r
-int pclose (FILE *stream)\r
+int\r
+pclose (FILE *stream)\r
 {\r
   errno = EPERM;\r
   return -1;\r
 }\r
 \r
-int access (const char *path, int amode)\r
+mode_t\r
+umask(mode_t cmask)\r
 {\r
-  return 0;\r
+  return (mode_t)0;\r
 }\r
index b5079e2c3a0d2e4dcd76314b6d47383bcc077fc6..90d7277f86cdc852af5808336c82e2f738d4454c 100644 (file)
 #include  <sys/fcntl.h>\r
 #include  <sys/stat.h>\r
 #include  <sys/syslimits.h>\r
+#include  <sys/filio.h>\r
 #include  <Efi/SysEfi.h>\r
+#include  <unistd.h>\r
 #include  <kfile.h>\r
 #include  <Device/Device.h>\r
 #include  <MainData.h>\r
-#include  <extern.h>      // Library/include/extern.h: Private to implementation\r
-#include  <sys/EfiSysCall.h>\r
+#include  <extern.h>\r
 \r
 /* EFI versions of BSD system calls used in stdio */\r
 \r
@@ -136,6 +137,13 @@ isatty  (int fd)
   return retval;\r
 }\r
 \r
+/** Determine if file descriptor fd is a duplicate of some other fd.\r
+\r
+    @param[in]    fd    The file descriptor to check.\r
+\r
+    @retval   TRUE    fd is a duplicate of another fd.\r
+    @retval   FALSE   fd is unique.\r
+**/\r
 static BOOLEAN\r
 IsDupFd( int fd)\r
 {\r
@@ -161,6 +169,14 @@ IsDupFd( int fd)
   return Ret;\r
 }\r
 \r
+/** Close a file and set its fd to the specified state.\r
+\r
+    @param[in]    fd          The file descriptor to close.\r
+    @param[in]    NewState    State to set the fd to after the file is closed.\r
+\r
+    @retval    0    The operation completed successfully.\r
+    @retval   -1    The operation failed.  Further information is in errno.\r
+**/\r
 static int\r
 _closeX  (int fd, int NewState)\r
 {\r
@@ -199,19 +215,18 @@ _closeX  (int fd, int NewState)
   return retval;\r
 }\r
 \r
-/** The close() function shall deallocate the file descriptor indicated by fd.\r
+/** The close() function deallocates the file descriptor indicated by fd.\r
     To deallocate means to make the file descriptor available for return by\r
     subsequent calls to open() or other functions that allocate file\r
     descriptors. All outstanding record locks owned by the process on the file\r
-    associated with the file descriptor shall be removed (that is, unlocked).\r
+    associated with the file descriptor are removed (that is, unlocked).\r
 \r
-    @return   Upon successful completion, 0 shall be returned; otherwise,\r
-              -1 shall be returned and errno set to indicate the error.\r
+    @retval   0     Successful completion.\r
+    @retval   -1    An error occurred and errno is set to identify the error.\r
 **/\r
 int\r
 close  (int fd)\r
 {\r
-  //Print(L"Closing fd %d\n", fd);\r
   return _closeX(fd, 0);\r
 }\r
 \r
@@ -348,7 +363,7 @@ fcntl     (int fildes, int cmd, ...)
           errno = EINVAL;\r
         }\r
         break;\r
-      //case F_SETFD:\r
+\r
       case F_SETFL:\r
         retval = MyFd->Oflags;        // Get original value\r
         temp = va_arg(p3, int);\r
@@ -356,7 +371,7 @@ fcntl     (int fildes, int cmd, ...)
         temp |= retval & O_SETMASK;\r
         MyFd->Oflags = temp;          // Set new value\r
         break;\r
-      //case F_SETFL:\r
+\r
       case F_SETFD:\r
         retval = MyFd->f_iflags;\r
         break;\r
@@ -365,11 +380,9 @@ fcntl     (int fildes, int cmd, ...)
       //  MyFd->SocProc = va_arg(p3, int);\r
       //  break;\r
       case F_GETFD:\r
-        //retval = MyFd->Oflags;\r
         retval = MyFd->f_iflags;\r
         break;\r
       case F_GETFL:\r
-        //retval = MyFd->f_iflags;\r
         retval = MyFd->Oflags;\r
         break;\r
       //case F_GETOWN:\r
@@ -520,7 +533,7 @@ mkdir (const char *path, __mode_t perms)
   wchar_t            *NewPath;\r
   DeviceNode         *Node;\r
   char               *GenI;\r
-  RETURN_STATUS     Status;\r
+  RETURN_STATUS       Status;\r
   int                 Instance  = 0;\r
   int                 retval = 0;\r
 \r
@@ -860,6 +873,8 @@ rmdir(
     filp = &gMD->fdarray[fd];\r
 \r
     retval = filp->f_ops->fo_rmdir(filp);\r
+    filp->f_iflags = 0;           // Close this FD\r
+    filp->RefCount = 0;           // No one using this FD\r
       }\r
   return retval;\r
 }\r
@@ -962,8 +977,22 @@ ioctl(
 \r
   if(ValidateFD( fd, VALID_OPEN)) {\r
     filp = &gMD->fdarray[fd];\r
+\r
+    if(request == FIODLEX) {\r
+      /* set Delete-on-Close */\r
+      filp->f_iflags |= FIF_DELCLOSE;\r
+      retval = 0;\r
+    }\r
+    else if(request == FIONDLEX) {\r
+      /* clear Delete-on-Close */\r
+      filp->f_iflags &= ~FIF_DELCLOSE;\r
+      retval = 0;\r
+    }\r
+    else {\r
+      /* All other requests. */\r
     retval = filp->f_ops->fo_ioctl(filp, request, argp);\r
   }\r
+  }\r
   else {\r
     errno   =  EBADF;\r
   }\r
@@ -1101,18 +1130,21 @@ write  (int fd, const void *buf, size_t nbyte)
 /** Gets the current working directory.\r
 \r
   The getcwd() function shall place an absolute pathname of the current\r
-  working directory in the array pointed to by buf, and return buf. The\r
-  pathname copied to the array shall contain no components that are\r
-  symbolic links. The size argument is the size in bytes of the character\r
-  array pointed to by the buf argument.\r
+  working directory in the array pointed to by buf, and return buf.The\r
+  size argument is the size in bytes of the character array pointed to\r
+  by the buf argument.\r
 \r
   @param[in,out] buf    The buffer to fill.\r
   @param[in]     size   The number of bytes in buffer.\r
 \r
-  @retval NULL          The function failed.\r
-  @retval NULL          Buf was NULL.\r
-  @retval NULL          Size was 0.\r
-  @return buf           The function completed successfully. See errno for info.\r
+  @retval NULL          The function failed.  The value in errno provides\r
+                        further information about the cause of the failure.\r
+                        Values for errno are:\r
+                          - EINVAL: buf is NULL or size is zero.\r
+                          - ENOENT: directory does not exist.\r
+                          - ERANGE: buf size is too small to hold CWD\r
+\r
+  @retval buf           The function completed successfully.\r
 **/\r
 char\r
 *getcwd (char *buf, size_t size)\r
@@ -1126,14 +1158,13 @@ char
 \r
   Cwd = ShellGetCurrentDir(NULL);\r
   if (Cwd == NULL) {\r
-    errno = EACCES;\r
+    errno = ENOENT;\r
     return NULL;\r
   }\r
   if (size < ((StrLen (Cwd) + 1) * sizeof (CHAR8))) {\r
     errno = ERANGE;\r
     return (NULL);\r
   }\r
-\r
   return (UnicodeStrToAsciiStr(Cwd, buf));\r
 }\r
 \r
@@ -1146,7 +1177,14 @@ char
 \r
   @param[in] path   The new path to set.\r
 \r
-  @todo Add non-shell CWD changing.\r
+  @retval   0   Operation completed successfully.\r
+  @retval  -1   Function failed.  The value in errno provides more\r
+                information on the cause of failure:\r
+                  - EPERM: Operation not supported with this Shell version.\r
+                  - ENOMEM: Unable to allocate memory.\r
+                  - ENOENT: Target directory does not exist.\r
+\r
+  @todo Add non-NEW-shell CWD changing.\r
 **/\r
 int\r
 chdir (const char *path)\r
@@ -1155,6 +1193,8 @@ chdir (const char *path)
   EFI_STATUS   Status;\r
   CHAR16       *UnicodePath;\r
 \r
+  /* Old Shell does not support Set Current Dir. */\r
+  if(gEfiShellProtocol != NULL) {\r
   Cwd = ShellGetCurrentDir(NULL);\r
   if (Cwd != NULL) {\r
     /* We have shell support */\r
@@ -1167,15 +1207,15 @@ chdir (const char *path)
     Status = gEfiShellProtocol->SetCurDir(NULL, UnicodePath);\r
     FreePool(UnicodePath);\r
     if (EFI_ERROR(Status)) {\r
-      errno = EACCES;\r
+        errno = ENOENT;\r
       return -1;\r
     } else {\r
       return 0;\r
     }\r
   }\r
-\r
+  }\r
   /* Add here for non-shell */\r
-  errno = EACCES;\r
+  errno = EPERM;\r
   return -1;\r
 }\r
 \r
@@ -1189,3 +1229,33 @@ pid_t getpgrp(void)
   return ((pid_t)(UINTN)(gImageHandle));\r
 }\r
 \r
+/** Set file access and modification times.\r
+\r
+    @param[in]  path\r
+    @param[in]  times\r
+\r
+    @return\r
+**/\r
+int\r
+utimes(\r
+  const char *path,\r
+  const struct timeval *times\r
+  )\r
+{\r
+  struct __filedes   *filp;\r
+  va_list             ap;\r
+  int                 fd;\r
+  int                 retval  = -1;\r
+\r
+  va_start(ap, path);\r
+  fd = open(path, O_RDWR, 0);\r
+  if(fd >= 0) {\r
+    filp = &gMD->fdarray[fd];\r
+    retval = filp->f_ops->fo_ioctl( filp, FIOSETIME, ap);\r
+    close(fd);\r
+  }\r
+  va_end(ap);\r
+  return retval;\r
+\r
+}\r
+\r
index f17a26eea2224ce38657963f169aaab47372d4a4..71bcb37f028e97d9f360e4288cdd1ec3b58b3aee 100644 (file)
@@ -52,4 +52,5 @@
   LibLocale\r
   LibString\r
   LibTime\r
+  LibGen\r
   DevUtility\r
index 6b15da356318117159993a688c9147898e58164b..ecf51d6b0f39cd4b3d91f91a07804cc117dd9c9a 100644 (file)
@@ -57,8 +57,9 @@ Oflags2EFI( int oflags )
   return flags;\r
 }\r
 \r
-/*  Transform the permissions flags from the open() call into the\r
-    Attributes bits needed by UEFI.\r
+/*  Transform the permissions flags into their equivalent UEFI File Attribute bits.\r
+    This transformation is most frequently used when translating attributes for use\r
+    by the UEFI EFI_FILE_PROTOCOL.SetInfo() function.\r
 \r
     The UEFI File attributes are:\r
       // ******************************************************\r
@@ -72,27 +73,40 @@ Oflags2EFI( int oflags )
       #define EFI_FILE_ARCHIVE           0x0000000000000020\r
       #define EFI_FILE_VALID_ATTR        0x0000000000000037\r
 \r
-    The input permission flags consist of two groups:\r
-      ( S_IRUSR | S_IRGRP | S_IROTH ) -- S_ACC_READ\r
-      ( S_IWUSR | S_IWGRP | S_IWOTH ) -- S_ACC_WRITE\r
-\r
-    The only thing we can set, at this point, is whether or not\r
-    this is a SYSTEM file.  If the group and other bits are\r
-    zero and the user bits are non-zero then set SYSTEM.  Otherwise\r
-    the attributes are zero.\r
-\r
-    The attributes can be set later using fcntl().\r
+    The input permission flags consist of the following flags:\r
+      O_RDONLY    -- open for reading only\r
+      O_WRONLY    -- open for writing only\r
+      O_RDWR      -- open for reading and writing\r
+      O_ACCMODE   -- mask for above modes\r
+      O_NONBLOCK  -- no delay\r
+      O_APPEND    -- set append mode\r
+      O_CREAT     -- create if nonexistent\r
+      O_TRUNC     -- truncate to zero length\r
+      O_EXCL      -- error if already exists\r
+      O_HIDDEN    -- Hidden file attribute\r
+      O_SYSTEM    -- System file attribute\r
+      O_ARCHIVE   -- Archive file attribute\r
 */\r
 UINT64\r
 Omode2EFI( int mode)\r
 {\r
   UINT64  flags = 0;\r
 \r
-  if((mode & (S_IRWXG | S_IRWXO)) == 0) {\r
-    if((mode & S_IRWXU) != 0) {\r
-      // Only user permissions so set system\r
-      flags = EFI_FILE_SYSTEM;\r
+  /* File is Read-Only. */\r
+  if((mode & O_ACCMODE) == 0) {\r
+    flags = EFI_FILE_READ_ONLY;\r
+  }\r
+  /* Set the Hidden attribute. */\r
+  if((mode & O_HIDDEN) != 0) {\r
+    flags |= EFI_FILE_HIDDEN;\r
+  }\r
+  /* Set the System attribute. */\r
+  if((mode & O_SYSTEM) != 0) {\r
+    flags |= EFI_FILE_SYSTEM;\r
     }\r
+  /* Set the Archive attribute. */\r
+  if((mode & O_ARCHIVE) != 0) {\r
+    flags |= EFI_FILE_ARCHIVE;\r
   }\r
   return flags;\r
 }\r
index 0a2ab188fde092145ad58c3979a05eb88ae2093a..5a54686f6ec02249e2fa6dece6836a2cf926a074 100644 (file)
@@ -31,6 +31,8 @@
   opendir.c\r
   closedir.c\r
   readdir.c\r
+  access.c\r
+  utime.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
diff --git a/StdLib/PosixLib/Gen/access.c b/StdLib/PosixLib/Gen/access.c
new file mode 100644 (file)
index 0000000..3031e4f
--- /dev/null
@@ -0,0 +1,118 @@
+/** @file\r
+  Implementation of the Posix access() function.\r
+\r
+  Copyright (c) 2011, 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.\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  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include  <ctype.h>\r
+#include  <errno.h>\r
+#include  <sys/stat.h>\r
+#include  <string.h>\r
+#include  <unistd.h>\r
+#include  <sys/syslimits.h>\r
+\r
+/** Save some typing later on. */\r
+#define GOOD_MODE   (F_OK | X_OK | W_OK | R_OK)\r
+\r
+/** Determine accessibility of a file.\r
+    The access() function checks the file, named by the pathname pointed to by\r
+    the Path argument, for accessibility according to the bit pattern contained\r
+    in Mode.\r
+\r
+    The value of Mode is either the bitwise-inclusive OR of the access\r
+    permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).\r
+\r
+    If Path ends in '/' or '\\', the target must be a directory, otherwise it doesn't matter.\r
+    A file is executable if it is NOT a directory and it ends in ".efi".\r
+\r
+    @param[in]    Path    Path or name of the file to be checked.\r
+    @param[in]    Mode    Access permissions to check for.\r
+\r
+    @retval   0   Successful completion.\r
+    @retval  -1   File is not accessible with the given Mode.  The error condition\r
+                  is indicated by errno.  Values of errno specific to the access\r
+                  function include: EACCES, ENOENT, ENOTDIR, ENAMETOOLONG\r
+**/\r
+int\r
+access(\r
+  const char *Path,\r
+  int         Mode\r
+  )\r
+{\r
+  struct stat     FileStat;\r
+  int             retval      = -1;\r
+  size_t          PLength;\r
+  uint32_t        WantDir;\r
+  uint32_t        DirMatch;\r
+\r
+  if((Path == NULL) || ((Mode & ~GOOD_MODE) != 0)) {\r
+    errno = EINVAL;\r
+  }\r
+  else {\r
+    PLength = strlen(Path);\r
+    if(PLength > PATH_MAX) {\r
+      errno = ENAMETOOLONG;\r
+    }\r
+    else {\r
+      retval = stat(Path, &FileStat);\r
+      if(retval == 0) {\r
+        /* Path exists.  FileStat now holds valid information. */\r
+        WantDir   = isDirSep(Path[PLength - 1]);   // Does Path end in '/' or '\\' ?\r
+        DirMatch = (! WantDir && (! S_ISDIR(FileStat.st_mode)));\r
+\r
+        /* Test each permission individually.  */\r
+        do {\r
+          if(Mode == F_OK) {  /* Existence test. */\r
+            if(DirMatch) {    /* This is a directory or file as desired. */\r
+              retval = 0;\r
+            }\r
+            else {\r
+              /* Indicate why we failed the test. */\r
+              errno = (WantDir) ? ENOTDIR : EISDIR;\r
+            }\r
+            break;  /* F_OK does not combine with any other tests. */\r
+          }\r
+          if(Mode & R_OK) {\r
+            if((FileStat.st_mode & READ_PERMS) == 0) {\r
+              /* No read permissions.\r
+                 For UEFI, everything should have READ permissions.\r
+              */\r
+              errno = EDOOFUS;  /* Programming Error. */\r
+              break;\r
+            }\r
+          }\r
+          if(Mode & W_OK) {\r
+            if((FileStat.st_mode & WRITE_PERMS) == 0) {\r
+              /* No write permissions. */\r
+              errno = EACCES;  /* Writing is not OK. */\r
+              break;\r
+            }\r
+          }\r
+          if(Mode & X_OK) {\r
+            /* In EDK II, executable files end in ".efi" */\r
+            if(strcmp(&Path[PLength-4], ".efi") != 0) {\r
+              /* File is not an executable. */\r
+              errno = EACCES;\r
+              break;\r
+            }\r
+          }\r
+          retval = 0;\r
+        } while(FALSE);\r
+      }\r
+      else {\r
+        /* File or path does not exist. */\r
+        errno = ENOENT;\r
+      }\r
+    }\r
+  }\r
+  return retval;\r
+}\r
index 7fb4d39a0f947c00463da62082b0f37009e65383..eb924d435c26c86f8bca942cbde80dd0cbdc1497 100644 (file)
@@ -1,5 +1,14 @@
 /** @file\r
 \r
+  Copyright (c) 2011, 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.\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) 1997, 2002 The NetBSD Foundation, Inc.\r
  * All rights reserved.\r
  *\r
     NetBSD: dirname.c,v 1.10 2008/05/10 22:39:40 christos Exp\r
  */\r
 #include  <LibConfig.h>\r
-\r
 #include <sys/cdefs.h>\r
 \r
-//#include "namespace.h"\r
-//#include <libgen.h>\r
 #include <limits.h>\r
+#include  <ctype.h>\r
 #include <string.h>\r
 \r
 #ifdef __weak_alias\r
 __weak_alias(dirname,_dirname)\r
 #endif\r
 \r
-#if !HAVE_DIRNAME\r
+#ifdef HAVE_DIRNAME\r
 char *\r
 dirname(char *path)\r
 {\r
@@ -60,24 +67,34 @@ dirname(char *path)
 \r
   /* Strip trailing slashes, if any. */\r
   lastp = path + strlen(path) - 1;\r
-  while (lastp != path && *lastp == '/')\r
+  while (lastp != path && isDirSep(*lastp))\r
     lastp--;\r
 \r
   /* Terminate path at the last occurence of '/'. */\r
   do {\r
-    if (*lastp == '/') {\r
+    if (isDirSep(*lastp)) {\r
       /* Strip trailing slashes, if any. */\r
-      while (lastp != path && *lastp == '/')\r
+      while (lastp != path && isDirSep(*lastp))\r
         lastp--;\r
 \r
-      /* ...and copy the result into the result buffer. */\r
+      /* ...and copy the result into the result buffer.\r
+        We make sure that there will be room for the terminating NUL\r
+        and for a final '/', if necessary.\r
+      */\r
       len = (lastp - path) + 1 /* last char */;\r
-      if (len > (PATH_MAX - 1))\r
-        len = PATH_MAX - 1;\r
+      if (len > (PATH_MAX - 2))\r
+        len = PATH_MAX - 2;\r
 \r
       memcpy(result, path, len);\r
+      if(*lastp == ':') {   /* Have we stripped off all except the Volume name? */\r
+        if(isDirSep(lastp[1])) { /* Was ...":/"... so we want the root of the volume. */\r
+          result[len++] = '/';\r
+        }\r
+        else {\r
+          result[len++] = '.';\r
+        }\r
+      }\r
       result[len] = '\0';\r
-\r
       return (result);\r
     }\r
   } while (--lastp >= path);\r
index b8ad0af2a30102408712a4c35dd8cbf3666c3f0b..13c4eaec07179c23373dd7a0c646712696ba3198 100644 (file)
@@ -54,8 +54,6 @@
 #include <string.h>\r
 #include <unistd.h>\r
 \r
-#include  <sys/EfiSysCall.h>\r
-\r
 /*\r
  * get next entry in a directory.\r
  */\r
diff --git a/StdLib/PosixLib/Gen/utime.c b/StdLib/PosixLib/Gen/utime.c
new file mode 100644 (file)
index 0000000..9cb8b5b
--- /dev/null
@@ -0,0 +1,73 @@
+/** @file\r
+    Set file access and modification times.\r
+\r
+  Copyright (c) 2010 - 2011, 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.\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) 1990, 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
+    NetBSD: utime.c,v 1.12 2003/08/07 16:42:59 agc Exp\r
+    utime.c 8.1 (Berkeley) 6/4/93\r
+ */\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiCdefs.h>\r
+\r
+#include "namespace.h"\r
+#include <sys/time.h>\r
+\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include <stddef.h>\r
+#include <utime.h>\r
+\r
+int\r
+utime(\r
+  const char            *path,\r
+  const struct utimbuf  *times\r
+  )\r
+{\r
+  struct timeval tv[2], *tvp;\r
+\r
+  _DIAGASSERT(path != NULL);\r
+\r
+  if (times == (struct utimbuf *) NULL)\r
+    tvp = NULL;\r
+  else {\r
+    tv[0].tv_sec = times->actime;\r
+    tv[1].tv_sec = times->modtime;\r
+    tv[0].tv_usec = tv[1].tv_usec = 0;\r
+    tvp = tv;\r
+  }\r
+  return (utimes(path, tvp));\r
+}\r