StdLib: Add isDirSep character classification macro and function. Implement several Posix functions and clean up EfiSysCall.h. Align file mode handling with UEFI file protocol flags.
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
This commit is contained in:
@@ -21,13 +21,13 @@
|
||||
#include <Protocol/SimpleTextOut.h>
|
||||
|
||||
#include <LibConfig.h>
|
||||
#include <sys/EfiSysCall.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <wctype.h>
|
||||
#include <wchar.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <kfile.h>
|
||||
#include <Device/Device.h>
|
||||
#include <MainData.h>
|
||||
|
@@ -21,7 +21,6 @@
|
||||
#include <Library/ShellLib.h>
|
||||
|
||||
#include <LibConfig.h>
|
||||
#include <sys/EfiSysCall.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
@@ -30,12 +29,21 @@
|
||||
#include <wctype.h>
|
||||
#include <wchar.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/filio.h>
|
||||
#include <sys/syslimits.h>
|
||||
#include <unistd.h>
|
||||
#include <kfile.h>
|
||||
#include <Device/Device.h>
|
||||
#include <MainData.h>
|
||||
#include <Efi/SysEfi.h>
|
||||
|
||||
/** EFI Shell specific operations for close().
|
||||
|
||||
@param[in] Fp Pointer to a file descriptor structure.
|
||||
|
||||
@retval 0 Successful completion.
|
||||
@retval -1 Operation failed. Further information is specified by errno.
|
||||
**/
|
||||
static
|
||||
int
|
||||
EFIAPI
|
||||
@@ -50,6 +58,13 @@ da_ShellClose(
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** EFI Shell specific operations for deleting a file or directory.
|
||||
|
||||
@param[in] filp Pointer to a file descriptor structure.
|
||||
|
||||
@retval 0 Successful completion.
|
||||
@retval -1 Operation failed. Further information is specified by errno.
|
||||
**/
|
||||
static
|
||||
int
|
||||
EFIAPI
|
||||
@@ -68,6 +83,14 @@ da_ShellDelete(
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** EFI Shell specific operations for setting the position within a file.
|
||||
|
||||
@param[in] filp Pointer to a file descriptor structure.
|
||||
@param[in] offset Relative position to move to.
|
||||
@param[in] whence Specifies the location offset is relative to: Beginning, Current, End.
|
||||
|
||||
@return Returns the new file position or EOF if the seek failed.
|
||||
**/
|
||||
static
|
||||
off_t
|
||||
EFIAPI
|
||||
@@ -126,6 +149,9 @@ da_ShellSeek(
|
||||
|
||||
The directory is closed after it is created.
|
||||
|
||||
@param[in] path The directory to be created.
|
||||
@param[in] perms Access permissions for the new directory.
|
||||
|
||||
@retval 0 The directory was created successfully.
|
||||
@retval -1 An error occurred and an error code is stored in errno.
|
||||
**/
|
||||
@@ -137,6 +163,7 @@ da_ShellMkdir(
|
||||
__mode_t perms
|
||||
)
|
||||
{
|
||||
UINT64 TempAttr;
|
||||
SHELL_FILE_HANDLE FileHandle;
|
||||
RETURN_STATUS Status;
|
||||
EFI_FILE_INFO *FileInfo;
|
||||
@@ -152,7 +179,8 @@ da_ShellMkdir(
|
||||
FileInfo = ShellGetFileInfo( FileHandle);
|
||||
Status = RETURN_ABORTED; // In case ShellGetFileInfo() failed
|
||||
if(FileInfo != NULL) {
|
||||
FileInfo->Attribute = Omode2EFI(perms);
|
||||
TempAttr = FileInfo->Attribute & (EFI_FILE_RESERVED | EFI_FILE_DIRECTORY);
|
||||
FileInfo->Attribute = TempAttr | Omode2EFI(perms);
|
||||
Status = ShellSetFileInfo( FileHandle, FileInfo);
|
||||
FreePool(FileInfo);
|
||||
if(Status == RETURN_SUCCESS) {
|
||||
@@ -168,6 +196,16 @@ da_ShellMkdir(
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** EFI Shell specific operations for reading from a file.
|
||||
|
||||
@param[in] filp Pointer to a file descriptor structure.
|
||||
@param[in] offset Offset into the file to begin reading at, or NULL.
|
||||
@param[in] BufferSize Number of bytes in Buffer. Max number of bytes to read.
|
||||
@param[in] Buffer Pointer to a buffer to receive the read data.
|
||||
|
||||
@return Returns the number of bytes successfully read,
|
||||
or -1 if the operation failed. Further information is specified by errno.
|
||||
**/
|
||||
static
|
||||
ssize_t
|
||||
EFIAPI
|
||||
@@ -209,6 +247,16 @@ da_ShellRead(
|
||||
return BufSize;
|
||||
}
|
||||
|
||||
/** EFI Shell specific operations for writing to a file.
|
||||
|
||||
@param[in] filp Pointer to a file descriptor structure.
|
||||
@param[in] offset Offset into the file to begin writing at, or NULL.
|
||||
@param[in] BufferSize Number of bytes in Buffer. Max number of bytes to write.
|
||||
@param[in] Buffer Pointer to a buffer containing the data to be written.
|
||||
|
||||
@return Returns the number of bytes successfully written,
|
||||
or -1 if the operation failed. Further information is specified by errno.
|
||||
**/
|
||||
static
|
||||
ssize_t
|
||||
EFIAPI
|
||||
@@ -261,6 +309,15 @@ da_ShellWrite(
|
||||
return BufSize;
|
||||
}
|
||||
|
||||
/** EFI Shell specific operations for getting information about an open file.
|
||||
|
||||
@param[in] filp Pointer to a file descriptor structure.
|
||||
@param[out] statbuf Buffer in which to store the file status.
|
||||
@param[in] Something This parameter is not used by this device.
|
||||
|
||||
@retval 0 Successful completion.
|
||||
@retval -1 Operation failed. Further information is specified by errno.
|
||||
**/
|
||||
static
|
||||
int
|
||||
EFIAPI
|
||||
@@ -314,6 +371,15 @@ da_ShellStat(
|
||||
return (Status == RETURN_SUCCESS)? 0 : -1;
|
||||
}
|
||||
|
||||
/** EFI Shell specific operations for low-level control of a file or device.
|
||||
|
||||
@param[in] filp Pointer to a file descriptor structure.
|
||||
@param[in] cmd The command this ioctl is to perform.
|
||||
@param[in,out] argp Zero or more arguments as needed by the command.
|
||||
|
||||
@retval 0 Successful completion.
|
||||
@retval -1 Operation failed. Further information is specified by errno.
|
||||
**/
|
||||
static
|
||||
int
|
||||
EFIAPI
|
||||
@@ -323,10 +389,70 @@ da_ShellIoctl(
|
||||
va_list argp
|
||||
)
|
||||
{
|
||||
return -EPERM;
|
||||
EFI_FILE_INFO *FileInfo = NULL;
|
||||
SHELL_FILE_HANDLE FileHandle;
|
||||
RETURN_STATUS Status = RETURN_SUCCESS;
|
||||
int retval = 0;
|
||||
|
||||
FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
|
||||
|
||||
FileInfo = ShellGetFileInfo( FileHandle);
|
||||
|
||||
if(FileInfo != NULL) {
|
||||
if( cmd == (ULONGN)FIOSETIME) {
|
||||
struct timeval *TV;
|
||||
EFI_TIME *ET;
|
||||
int mod = 0;
|
||||
|
||||
TV = va_arg(argp, struct timeval*);
|
||||
if(TV[0].tv_sec != 0) {
|
||||
ET = Time2Efi(TV[0].tv_sec);
|
||||
if(ET != NULL) {
|
||||
(void) memcpy(&FileInfo->LastAccessTime, ET, sizeof(EFI_TIME));
|
||||
FileInfo->LastAccessTime.Nanosecond = TV[0].tv_usec * 1000;
|
||||
free(ET);
|
||||
++mod;
|
||||
}
|
||||
}
|
||||
if(TV[1].tv_sec != 0) {
|
||||
ET = Time2Efi(TV[1].tv_sec);
|
||||
if(ET != NULL) {
|
||||
(void) memcpy(&FileInfo->ModificationTime, ET, sizeof(EFI_TIME));
|
||||
FileInfo->ModificationTime.Nanosecond = TV[1].tv_usec * 1000;
|
||||
free(ET);
|
||||
++mod;
|
||||
}
|
||||
}
|
||||
/* Set access and modification times */
|
||||
Status = ShellSetFileInfo(FileHandle, FileInfo);
|
||||
errno = EFI2errno(Status);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Status = RETURN_DEVICE_ERROR;
|
||||
errno = EIO;
|
||||
}
|
||||
if(RETURN_ERROR(Status)) {
|
||||
retval = -1;
|
||||
}
|
||||
EFIerrno = Status;
|
||||
|
||||
if(FileInfo != NULL) {
|
||||
FreePool(FileInfo); // Release the buffer allocated by the GetInfo function
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** Open an abstract Shell File.
|
||||
/** EFI Shell specific operations for opening a file or directory.
|
||||
|
||||
@param[in] DevNode Pointer to a device descriptor
|
||||
@param[in] filp Pointer to a file descriptor structure.
|
||||
@param[in] DevInstance Not used by this device.
|
||||
@param[in] Path File-system path to the file or directory.
|
||||
@param[in] MPath Device or Map name on which Path resides.
|
||||
|
||||
@return Returns a file descriptor for the newly opened file,
|
||||
or -1 if the Operation failed. Further information is specified by errno.
|
||||
**/
|
||||
int
|
||||
EFIAPI
|
||||
@@ -447,14 +573,19 @@ da_ShellOpen(
|
||||
}
|
||||
|
||||
#include <sys/poll.h>
|
||||
/* Returns a bit mask describing which operations could be completed immediately.
|
||||
/** Returns a bit mask describing which operations could be completed immediately.
|
||||
|
||||
For now, assume the file system, via the shell, is always ready.
|
||||
|
||||
(POLLIN | POLLRDNORM) The file system is ready to be read.
|
||||
(POLLOUT) The file system is ready for output.
|
||||
|
||||
*/
|
||||
@param[in] filp Pointer to a file descriptor structure.
|
||||
@param[in] events Bit mask describing which operations to check.
|
||||
|
||||
@return The returned value is a bit mask describing which operations
|
||||
could be completed immediately, without blocking.
|
||||
**/
|
||||
static
|
||||
short
|
||||
EFIAPI
|
||||
@@ -488,6 +619,14 @@ da_ShellPoll(
|
||||
return (retval & (events | POLL_RETONLY));
|
||||
}
|
||||
|
||||
/** EFI Shell specific operations for renaming a file.
|
||||
|
||||
@param[in] from Name of the file to be renamed.
|
||||
@param[in] to New name for the file.
|
||||
|
||||
@retval 0 Successful completion.
|
||||
@retval -1 Operation failed. Further information is specified by errno.
|
||||
**/
|
||||
static
|
||||
int
|
||||
EFIAPI
|
||||
@@ -553,6 +692,13 @@ da_ShellRename(
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** EFI Shell specific operations for deleting directories.
|
||||
|
||||
@param[in] filp Pointer to a file descriptor structure.
|
||||
|
||||
@retval 0 Successful completion.
|
||||
@retval -1 Operation failed. Further information is specified by errno.
|
||||
**/
|
||||
static
|
||||
int
|
||||
EFIAPI
|
||||
@@ -562,10 +708,12 @@ da_ShellRmdir(
|
||||
{
|
||||
SHELL_FILE_HANDLE FileHandle;
|
||||
RETURN_STATUS Status = RETURN_SUCCESS;
|
||||
EFI_FILE_INFO *FileInfo = NULL;
|
||||
EFI_FILE_INFO *FileInfo;
|
||||
int OldErrno;
|
||||
int Count = 0;
|
||||
BOOLEAN NoFile = FALSE;
|
||||
|
||||
OldErrno = errno; // Save the original value
|
||||
errno = 0; // Make it easier to see if we have an error later
|
||||
|
||||
FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
|
||||
@@ -576,8 +724,8 @@ da_ShellRmdir(
|
||||
errno = ENOTDIR;
|
||||
}
|
||||
else {
|
||||
// See if the directory has any entries other than ".." and ".".
|
||||
FreePool(FileInfo); // Free up the buffer from ShellGetFileInfo()
|
||||
// See if the directory has any entries other than ".." and ".".
|
||||
Status = ShellFindFirstFile( FileHandle, &FileInfo);
|
||||
if(Status == RETURN_SUCCESS) {
|
||||
++Count;
|
||||
@@ -593,15 +741,22 @@ da_ShellRmdir(
|
||||
Count = 99;
|
||||
}
|
||||
}
|
||||
FreePool(FileInfo); // Free buffer from ShellFindFirstFile()
|
||||
/* Count == 99 and FileInfo is allocated if ShellFindNextFile failed.
|
||||
ShellFindNextFile has freed FileInfo itself if it sets NoFile TRUE.
|
||||
*/
|
||||
if((! NoFile) || (Count == 99)) {
|
||||
free(FileInfo); // Free buffer from ShellFindFirstFile()
|
||||
}
|
||||
if(Count < 3) {
|
||||
// Directory is empty
|
||||
Status = ShellDeleteFile( &FileHandle);
|
||||
if(Status == RETURN_SUCCESS) {
|
||||
EFIerrno = RETURN_SUCCESS;
|
||||
errno = OldErrno; // Restore the original value
|
||||
return 0;
|
||||
/* ######## SUCCESSFUL RETURN ######## */
|
||||
}
|
||||
/* FileInfo is freed and FileHandle closed. */
|
||||
}
|
||||
else {
|
||||
if(Count == 99) {
|
||||
@@ -617,6 +772,7 @@ da_ShellRmdir(
|
||||
else {
|
||||
errno = EIO;
|
||||
}
|
||||
ShellCloseFile( &FileHandle);
|
||||
EFIerrno = Status;
|
||||
if(errno == 0) {
|
||||
errno = EFI2errno( Status );
|
||||
@@ -628,6 +784,13 @@ da_ShellRmdir(
|
||||
|
||||
Allocate the instance structure and populate it with the information for
|
||||
the device.
|
||||
|
||||
@param[in] ImageHandle This application's image handle.
|
||||
@param[in] SystemTable Pointer to the UEFI System Table.
|
||||
|
||||
@retval RETURN_SUCCESS Successful completion.
|
||||
@retval RETURN_OUT_OF_RESOURCES Failed to allocate memory for new device.
|
||||
@retval RETURN_INVALID_PARAMETER A default device has already been created.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
@@ -669,6 +832,13 @@ __ctor_DevShell(
|
||||
return Status;
|
||||
}
|
||||
|
||||
/** Destructor for previously constructed EFI Shell device instances.
|
||||
|
||||
@param[in] ImageHandle This application's image handle.
|
||||
@param[in] SystemTable Pointer to the UEFI System Table.
|
||||
|
||||
@retval 0 Successful completion is always returned.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
__dtor_DevShell(
|
||||
|
@@ -11,6 +11,7 @@
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
#include <LibConfig.h>
|
||||
#include <sys/EfiCdefs.h>
|
||||
#include <sys/featuretest.h>
|
||||
#include <namespace.h>
|
||||
@@ -25,7 +26,8 @@ getpwuid (uid_t uid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *getlogin (void)
|
||||
char *
|
||||
getlogin (void)
|
||||
{
|
||||
errno = EPERM;
|
||||
return NULL;
|
||||
@@ -38,40 +40,53 @@ getpwnam (const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uid_t getuid (void)
|
||||
uid_t
|
||||
getuid (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t fork (void)
|
||||
pid_t
|
||||
getpid(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t
|
||||
fork (void)
|
||||
{
|
||||
errno = EPERM;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int chmod (const char *c, mode_t m)
|
||||
int
|
||||
chmod (const char *c, mode_t m)
|
||||
{
|
||||
errno = EPERM;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
pid_t wait(int *stat_loc) {
|
||||
pid_t
|
||||
wait(int *stat_loc) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *popen (const char *cmd, const char *type)
|
||||
FILE *
|
||||
popen (const char *cmd, const char *type)
|
||||
{
|
||||
errno = EPERM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int pclose (FILE *stream)
|
||||
int
|
||||
pclose (FILE *stream)
|
||||
{
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int access (const char *path, int amode)
|
||||
mode_t
|
||||
umask(mode_t cmask)
|
||||
{
|
||||
return 0;
|
||||
return (mode_t)0;
|
||||
}
|
||||
|
@@ -31,12 +31,13 @@
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syslimits.h>
|
||||
#include <sys/filio.h>
|
||||
#include <Efi/SysEfi.h>
|
||||
#include <unistd.h>
|
||||
#include <kfile.h>
|
||||
#include <Device/Device.h>
|
||||
#include <MainData.h>
|
||||
#include <extern.h> // Library/include/extern.h: Private to implementation
|
||||
#include <sys/EfiSysCall.h>
|
||||
#include <extern.h>
|
||||
|
||||
/* EFI versions of BSD system calls used in stdio */
|
||||
|
||||
@@ -136,6 +137,13 @@ isatty (int fd)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** Determine if file descriptor fd is a duplicate of some other fd.
|
||||
|
||||
@param[in] fd The file descriptor to check.
|
||||
|
||||
@retval TRUE fd is a duplicate of another fd.
|
||||
@retval FALSE fd is unique.
|
||||
**/
|
||||
static BOOLEAN
|
||||
IsDupFd( int fd)
|
||||
{
|
||||
@@ -161,6 +169,14 @@ IsDupFd( int fd)
|
||||
return Ret;
|
||||
}
|
||||
|
||||
/** Close a file and set its fd to the specified state.
|
||||
|
||||
@param[in] fd The file descriptor to close.
|
||||
@param[in] NewState State to set the fd to after the file is closed.
|
||||
|
||||
@retval 0 The operation completed successfully.
|
||||
@retval -1 The operation failed. Further information is in errno.
|
||||
**/
|
||||
static int
|
||||
_closeX (int fd, int NewState)
|
||||
{
|
||||
@@ -199,19 +215,18 @@ _closeX (int fd, int NewState)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** The close() function shall deallocate the file descriptor indicated by fd.
|
||||
/** The close() function deallocates the file descriptor indicated by fd.
|
||||
To deallocate means to make the file descriptor available for return by
|
||||
subsequent calls to open() or other functions that allocate file
|
||||
descriptors. All outstanding record locks owned by the process on the file
|
||||
associated with the file descriptor shall be removed (that is, unlocked).
|
||||
associated with the file descriptor are removed (that is, unlocked).
|
||||
|
||||
@return Upon successful completion, 0 shall be returned; otherwise,
|
||||
-1 shall be returned and errno set to indicate the error.
|
||||
@retval 0 Successful completion.
|
||||
@retval -1 An error occurred and errno is set to identify the error.
|
||||
**/
|
||||
int
|
||||
close (int fd)
|
||||
{
|
||||
//Print(L"Closing fd %d\n", fd);
|
||||
return _closeX(fd, 0);
|
||||
}
|
||||
|
||||
@@ -348,7 +363,7 @@ fcntl (int fildes, int cmd, ...)
|
||||
errno = EINVAL;
|
||||
}
|
||||
break;
|
||||
//case F_SETFD:
|
||||
|
||||
case F_SETFL:
|
||||
retval = MyFd->Oflags; // Get original value
|
||||
temp = va_arg(p3, int);
|
||||
@@ -356,7 +371,7 @@ fcntl (int fildes, int cmd, ...)
|
||||
temp |= retval & O_SETMASK;
|
||||
MyFd->Oflags = temp; // Set new value
|
||||
break;
|
||||
//case F_SETFL:
|
||||
|
||||
case F_SETFD:
|
||||
retval = MyFd->f_iflags;
|
||||
break;
|
||||
@@ -365,11 +380,9 @@ fcntl (int fildes, int cmd, ...)
|
||||
// MyFd->SocProc = va_arg(p3, int);
|
||||
// break;
|
||||
case F_GETFD:
|
||||
//retval = MyFd->Oflags;
|
||||
retval = MyFd->f_iflags;
|
||||
break;
|
||||
case F_GETFL:
|
||||
//retval = MyFd->f_iflags;
|
||||
retval = MyFd->Oflags;
|
||||
break;
|
||||
//case F_GETOWN:
|
||||
@@ -520,7 +533,7 @@ mkdir (const char *path, __mode_t perms)
|
||||
wchar_t *NewPath;
|
||||
DeviceNode *Node;
|
||||
char *GenI;
|
||||
RETURN_STATUS Status;
|
||||
RETURN_STATUS Status;
|
||||
int Instance = 0;
|
||||
int retval = 0;
|
||||
|
||||
@@ -860,6 +873,8 @@ rmdir(
|
||||
filp = &gMD->fdarray[fd];
|
||||
|
||||
retval = filp->f_ops->fo_rmdir(filp);
|
||||
filp->f_iflags = 0; // Close this FD
|
||||
filp->RefCount = 0; // No one using this FD
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -962,8 +977,22 @@ ioctl(
|
||||
|
||||
if(ValidateFD( fd, VALID_OPEN)) {
|
||||
filp = &gMD->fdarray[fd];
|
||||
|
||||
if(request == FIODLEX) {
|
||||
/* set Delete-on-Close */
|
||||
filp->f_iflags |= FIF_DELCLOSE;
|
||||
retval = 0;
|
||||
}
|
||||
else if(request == FIONDLEX) {
|
||||
/* clear Delete-on-Close */
|
||||
filp->f_iflags &= ~FIF_DELCLOSE;
|
||||
retval = 0;
|
||||
}
|
||||
else {
|
||||
/* All other requests. */
|
||||
retval = filp->f_ops->fo_ioctl(filp, request, argp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
errno = EBADF;
|
||||
}
|
||||
@@ -1101,18 +1130,21 @@ write (int fd, const void *buf, size_t nbyte)
|
||||
/** Gets the current working directory.
|
||||
|
||||
The getcwd() function shall place an absolute pathname of the current
|
||||
working directory in the array pointed to by buf, and return buf. The
|
||||
pathname copied to the array shall contain no components that are
|
||||
symbolic links. The size argument is the size in bytes of the character
|
||||
array pointed to by the buf argument.
|
||||
working directory in the array pointed to by buf, and return buf.The
|
||||
size argument is the size in bytes of the character array pointed to
|
||||
by the buf argument.
|
||||
|
||||
@param[in,out] buf The buffer to fill.
|
||||
@param[in] size The number of bytes in buffer.
|
||||
|
||||
@retval NULL The function failed.
|
||||
@retval NULL Buf was NULL.
|
||||
@retval NULL Size was 0.
|
||||
@return buf The function completed successfully. See errno for info.
|
||||
@retval NULL The function failed. The value in errno provides
|
||||
further information about the cause of the failure.
|
||||
Values for errno are:
|
||||
- EINVAL: buf is NULL or size is zero.
|
||||
- ENOENT: directory does not exist.
|
||||
- ERANGE: buf size is too small to hold CWD
|
||||
|
||||
@retval buf The function completed successfully.
|
||||
**/
|
||||
char
|
||||
*getcwd (char *buf, size_t size)
|
||||
@@ -1126,14 +1158,13 @@ char
|
||||
|
||||
Cwd = ShellGetCurrentDir(NULL);
|
||||
if (Cwd == NULL) {
|
||||
errno = EACCES;
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
if (size < ((StrLen (Cwd) + 1) * sizeof (CHAR8))) {
|
||||
errno = ERANGE;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (UnicodeStrToAsciiStr(Cwd, buf));
|
||||
}
|
||||
|
||||
@@ -1146,7 +1177,14 @@ char
|
||||
|
||||
@param[in] path The new path to set.
|
||||
|
||||
@todo Add non-shell CWD changing.
|
||||
@retval 0 Operation completed successfully.
|
||||
@retval -1 Function failed. The value in errno provides more
|
||||
information on the cause of failure:
|
||||
- EPERM: Operation not supported with this Shell version.
|
||||
- ENOMEM: Unable to allocate memory.
|
||||
- ENOENT: Target directory does not exist.
|
||||
|
||||
@todo Add non-NEW-shell CWD changing.
|
||||
**/
|
||||
int
|
||||
chdir (const char *path)
|
||||
@@ -1155,6 +1193,8 @@ chdir (const char *path)
|
||||
EFI_STATUS Status;
|
||||
CHAR16 *UnicodePath;
|
||||
|
||||
/* Old Shell does not support Set Current Dir. */
|
||||
if(gEfiShellProtocol != NULL) {
|
||||
Cwd = ShellGetCurrentDir(NULL);
|
||||
if (Cwd != NULL) {
|
||||
/* We have shell support */
|
||||
@@ -1167,15 +1207,15 @@ chdir (const char *path)
|
||||
Status = gEfiShellProtocol->SetCurDir(NULL, UnicodePath);
|
||||
FreePool(UnicodePath);
|
||||
if (EFI_ERROR(Status)) {
|
||||
errno = EACCES;
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* Add here for non-shell */
|
||||
errno = EACCES;
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1189,3 +1229,33 @@ pid_t getpgrp(void)
|
||||
return ((pid_t)(UINTN)(gImageHandle));
|
||||
}
|
||||
|
||||
/** Set file access and modification times.
|
||||
|
||||
@param[in] path
|
||||
@param[in] times
|
||||
|
||||
@return
|
||||
**/
|
||||
int
|
||||
utimes(
|
||||
const char *path,
|
||||
const struct timeval *times
|
||||
)
|
||||
{
|
||||
struct __filedes *filp;
|
||||
va_list ap;
|
||||
int fd;
|
||||
int retval = -1;
|
||||
|
||||
va_start(ap, path);
|
||||
fd = open(path, O_RDWR, 0);
|
||||
if(fd >= 0) {
|
||||
filp = &gMD->fdarray[fd];
|
||||
retval = filp->f_ops->fo_ioctl( filp, FIOSETIME, ap);
|
||||
close(fd);
|
||||
}
|
||||
va_end(ap);
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -52,4 +52,5 @@
|
||||
LibLocale
|
||||
LibString
|
||||
LibTime
|
||||
LibGen
|
||||
DevUtility
|
||||
|
@@ -57,8 +57,9 @@ Oflags2EFI( int oflags )
|
||||
return flags;
|
||||
}
|
||||
|
||||
/* Transform the permissions flags from the open() call into the
|
||||
Attributes bits needed by UEFI.
|
||||
/* Transform the permissions flags into their equivalent UEFI File Attribute bits.
|
||||
This transformation is most frequently used when translating attributes for use
|
||||
by the UEFI EFI_FILE_PROTOCOL.SetInfo() function.
|
||||
|
||||
The UEFI File attributes are:
|
||||
// ******************************************************
|
||||
@@ -72,27 +73,40 @@ Oflags2EFI( int oflags )
|
||||
#define EFI_FILE_ARCHIVE 0x0000000000000020
|
||||
#define EFI_FILE_VALID_ATTR 0x0000000000000037
|
||||
|
||||
The input permission flags consist of two groups:
|
||||
( S_IRUSR | S_IRGRP | S_IROTH ) -- S_ACC_READ
|
||||
( S_IWUSR | S_IWGRP | S_IWOTH ) -- S_ACC_WRITE
|
||||
|
||||
The only thing we can set, at this point, is whether or not
|
||||
this is a SYSTEM file. If the group and other bits are
|
||||
zero and the user bits are non-zero then set SYSTEM. Otherwise
|
||||
the attributes are zero.
|
||||
|
||||
The attributes can be set later using fcntl().
|
||||
The input permission flags consist of the following flags:
|
||||
O_RDONLY -- open for reading only
|
||||
O_WRONLY -- open for writing only
|
||||
O_RDWR -- open for reading and writing
|
||||
O_ACCMODE -- mask for above modes
|
||||
O_NONBLOCK -- no delay
|
||||
O_APPEND -- set append mode
|
||||
O_CREAT -- create if nonexistent
|
||||
O_TRUNC -- truncate to zero length
|
||||
O_EXCL -- error if already exists
|
||||
O_HIDDEN -- Hidden file attribute
|
||||
O_SYSTEM -- System file attribute
|
||||
O_ARCHIVE -- Archive file attribute
|
||||
*/
|
||||
UINT64
|
||||
Omode2EFI( int mode)
|
||||
{
|
||||
UINT64 flags = 0;
|
||||
|
||||
if((mode & (S_IRWXG | S_IRWXO)) == 0) {
|
||||
if((mode & S_IRWXU) != 0) {
|
||||
// Only user permissions so set system
|
||||
flags = EFI_FILE_SYSTEM;
|
||||
/* File is Read-Only. */
|
||||
if((mode & O_ACCMODE) == 0) {
|
||||
flags = EFI_FILE_READ_ONLY;
|
||||
}
|
||||
/* Set the Hidden attribute. */
|
||||
if((mode & O_HIDDEN) != 0) {
|
||||
flags |= EFI_FILE_HIDDEN;
|
||||
}
|
||||
/* Set the System attribute. */
|
||||
if((mode & O_SYSTEM) != 0) {
|
||||
flags |= EFI_FILE_SYSTEM;
|
||||
}
|
||||
/* Set the Archive attribute. */
|
||||
if((mode & O_ARCHIVE) != 0) {
|
||||
flags |= EFI_FILE_ARCHIVE;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
Reference in New Issue
Block a user