mirror of
				https://github.com/acidanthera/audk.git
				synced 2025-10-25 17:23:53 +02:00 
			
		
		
		
	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
		
	
			
		
			
				
	
	
		
			119 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			119 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /** @file
 | |
|   Implementation of the Posix access() function.
 | |
| 
 | |
|   Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
 | |
|   This program and the accompanying materials are licensed and made available under
 | |
|   the terms and conditions of the BSD License that accompanies this distribution.
 | |
|   The full text of the license may be found at
 | |
|   http://opensource.org/licenses/bsd-license.
 | |
| 
 | |
|   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 | |
|   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 | |
| **/
 | |
| #include  <LibConfig.h>
 | |
| #include  <sys/EfiCdefs.h>
 | |
| 
 | |
| #include  <ctype.h>
 | |
| #include  <errno.h>
 | |
| #include  <sys/stat.h>
 | |
| #include  <string.h>
 | |
| #include  <unistd.h>
 | |
| #include  <sys/syslimits.h>
 | |
| 
 | |
| /** Save some typing later on. */
 | |
| #define GOOD_MODE   (F_OK | X_OK | W_OK | R_OK)
 | |
| 
 | |
| /** Determine accessibility of a file.
 | |
|     The access() function checks the file, named by the pathname pointed to by
 | |
|     the Path argument, for accessibility according to the bit pattern contained
 | |
|     in Mode.
 | |
| 
 | |
|     The value of Mode is either the bitwise-inclusive OR of the access
 | |
|     permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).
 | |
| 
 | |
|     If Path ends in '/' or '\\', the target must be a directory, otherwise it doesn't matter.
 | |
|     A file is executable if it is NOT a directory and it ends in ".efi".
 | |
| 
 | |
|     @param[in]    Path    Path or name of the file to be checked.
 | |
|     @param[in]    Mode    Access permissions to check for.
 | |
| 
 | |
|     @retval   0   Successful completion.
 | |
|     @retval  -1   File is not accessible with the given Mode.  The error condition
 | |
|                   is indicated by errno.  Values of errno specific to the access
 | |
|                   function include: EACCES, ENOENT, ENOTDIR, ENAMETOOLONG
 | |
| **/
 | |
| int
 | |
| access(
 | |
|   const char *Path,
 | |
|   int         Mode
 | |
|   )
 | |
| {
 | |
|   struct stat     FileStat;
 | |
|   int             retval      = -1;
 | |
|   size_t          PLength;
 | |
|   uint32_t        WantDir;
 | |
|   uint32_t        DirMatch;
 | |
| 
 | |
|   if((Path == NULL) || ((Mode & ~GOOD_MODE) != 0)) {
 | |
|     errno = EINVAL;
 | |
|   }
 | |
|   else {
 | |
|     PLength = strlen(Path);
 | |
|     if(PLength > PATH_MAX) {
 | |
|       errno = ENAMETOOLONG;
 | |
|     }
 | |
|     else {
 | |
|       retval = stat(Path, &FileStat);
 | |
|       if(retval == 0) {
 | |
|         /* Path exists.  FileStat now holds valid information. */
 | |
|         WantDir   = isDirSep(Path[PLength - 1]);   // Does Path end in '/' or '\\' ?
 | |
|         DirMatch = (! WantDir && (! S_ISDIR(FileStat.st_mode)));
 | |
| 
 | |
|         /* Test each permission individually.  */
 | |
|         do {
 | |
|           if(Mode == F_OK) {  /* Existence test. */
 | |
|             if(DirMatch) {    /* This is a directory or file as desired. */
 | |
|               retval = 0;
 | |
|             }
 | |
|             else {
 | |
|               /* Indicate why we failed the test. */
 | |
|               errno = (WantDir) ? ENOTDIR : EISDIR;
 | |
|             }
 | |
|             break;  /* F_OK does not combine with any other tests. */
 | |
|           }
 | |
|           if(Mode & R_OK) {
 | |
|             if((FileStat.st_mode & READ_PERMS) == 0) {
 | |
|               /* No read permissions.
 | |
|                  For UEFI, everything should have READ permissions.
 | |
|               */
 | |
|               errno = EDOOFUS;  /* Programming Error. */
 | |
|               break;
 | |
|             }
 | |
|           }
 | |
|           if(Mode & W_OK) {
 | |
|             if((FileStat.st_mode & WRITE_PERMS) == 0) {
 | |
|               /* No write permissions. */
 | |
|               errno = EACCES;  /* Writing is not OK. */
 | |
|               break;
 | |
|             }
 | |
|           }
 | |
|           if(Mode & X_OK) {
 | |
|             /* In EDK II, executable files end in ".efi" */
 | |
|             if(strcmp(&Path[PLength-4], ".efi") != 0) {
 | |
|               /* File is not an executable. */
 | |
|               errno = EACCES;
 | |
|               break;
 | |
|             }
 | |
|           }
 | |
|           retval = 0;
 | |
|         } while(FALSE);
 | |
|       }
 | |
|       else {
 | |
|         /* File or path does not exist. */
 | |
|         errno = ENOENT;
 | |
|       }
 | |
|     }
 | |
|   }
 | |
|   return retval;
 | |
| }
 |