#include <wctype.h>\r
#include <wchar.h>\r
#include <sys/fcntl.h>\r
+#include <sys/syslimits.h>\r
#include <kfile.h>\r
#include <Device/Device.h>\r
#include <MainData.h>\r
void *argp ///< May be a pointer or a value\r
)\r
{\r
- return 0;\r
+ return -EPERM;\r
}\r
\r
/** Open an abstract Shell File.\r
int\r
EFIAPI\r
da_ShellOpen(\r
+ DeviceNode *DevNode,\r
struct __filedes *filp,\r
- void *DevInstance,\r
+ int DevInstance, /* Not used by Shell */\r
wchar_t *Path,\r
- wchar_t *Flags\r
+ wchar_t *MPath\r
)\r
{\r
UINT64 OpenMode;\r
SHELL_FILE_HANDLE FileHandle;\r
GenericInstance *Gip;\r
char *NPath;\r
+ wchar_t *WPath;\r
RETURN_STATUS Status;\r
int oflags;\r
+ int retval;\r
\r
EFIerrno = RETURN_SUCCESS;\r
\r
return -1;\r
}\r
\r
+ /* Re-create the full mapped path for the shell. */\r
+ if(MPath != NULL) {\r
+ WPath = AllocateZeroPool(PATH_MAX * sizeof(wchar_t) + 1);\r
+ if(WPath == NULL) {\r
+ errno = ENOMEM;\r
+ EFIerrno = RETURN_OUT_OF_RESOURCES;\r
+ return -1;\r
+ }\r
+ wcsncpy(WPath, MPath, NAME_MAX); /* Get the Map Name */\r
+ wcsncat(WPath, Path, (PATH_MAX - NAME_MAX)); /* Append the path */\r
+ }\r
+ else {\r
+ WPath = Path;\r
+ }\r
+\r
+ retval = -1; /* Initially assume failure. */\r
+\r
/* Do we care if the file already exists?\r
If O_TRUNC, then delete the file. It will be created anew subsequently.\r
If O_EXCL, then error if the file exists and O_CREAT is set.\r
!!!!!!!!! Change this to use ShellSetFileInfo() to actually truncate the file\r
!!!!!!!!! instead of deleting and re-creating it.\r
*/\r
+ do { /* Do fake exception handling */\r
if((oflags & O_TRUNC) || ((oflags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) {\r
- Status = ShellIsFile( Path );\r
+ Status = ShellIsFile( WPath );\r
if(Status == RETURN_SUCCESS) {\r
// The file exists\r
if(oflags & O_TRUNC) {\r
- NPath = AllocateZeroPool(1024);\r
+ NPath = AllocateZeroPool(PATH_MAX);\r
if(NPath == NULL) {\r
errno = ENOMEM;\r
EFIerrno = RETURN_OUT_OF_RESOURCES;\r
- return -1;\r
+ break;\r
}\r
- wcstombs(NPath, Path, 1024);\r
+ wcstombs(NPath, WPath, PATH_MAX);\r
// We do a truncate by deleting the existing file and creating a new one.\r
if(unlink(NPath) != 0) {\r
filp->f_iflags = 0; // Release our reservation on this FD\r
FreePool(NPath);\r
- return -1; // errno and EFIerrno are already set.\r
+ break;\r
}\r
FreePool(NPath);\r
}\r
errno = EEXIST;\r
EFIerrno = RETURN_ACCESS_DENIED;\r
filp->f_iflags = 0; // Release our reservation on this FD\r
- return -1;\r
+ break;\r
}\r
}\r
}\r
\r
// Call the EFI Shell's Open function\r
- Status = ShellOpenFileByName( Path, &FileHandle, OpenMode, Attributes);\r
+ Status = ShellOpenFileByName( WPath, &FileHandle, OpenMode, Attributes);\r
if(RETURN_ERROR(Status)) {\r
filp->f_iflags = 0; // Release our reservation on this FD\r
// Set errno based upon Status\r
errno = EFI2errno(Status);\r
EFIerrno = Status;\r
- return -1;\r
+ break;\r
}\r
+ retval = 0;\r
// Successfully got a regular File\r
filp->f_iflags |= S_IFREG;\r
\r
// Update the info in the fd\r
filp->devdata = (void *)FileHandle;\r
\r
- Gip = (GenericInstance *)DevInstance;\r
+ Gip = (GenericInstance *)DevNode->InstanceList;\r
filp->f_offset = 0;\r
filp->f_ops = &Gip->Abstraction;\r
-// filp->devdata = FileHandle;\r
+ // filp->devdata = FileHandle;\r
+ } while(FALSE);\r
\r
- return 0;\r
+ /* If we get this far, WPath is not NULL.\r
+ If MPath is not NULL, then WPath was allocated so we need to free it.\r
+ */\r
+ if(MPath != NULL) {\r
+ FreePool(WPath);\r
+ }\r
+ return retval;\r
}\r
\r
#include <sys/poll.h>\r
RETURN_STATUS Status;\r
EFI_FILE_INFO *NewFileInfo;\r
EFI_FILE_INFO *OldFileInfo;\r
- char *NewFn;\r
+ wchar_t *NewFn;\r
int OldFd;\r
SHELL_FILE_HANDLE FileHandle;\r
+ wchar_t *NormalizedPath;\r
\r
// Open old file\r
OldFd = open(from, O_RDWR, 0);\r
OldFileInfo = ShellGetFileInfo( FileHandle);\r
if(OldFileInfo != NULL) {\r
// Copy the Old file info into our new buffer, and free the old.\r
- memcpy(OldFileInfo, NewFileInfo, sizeof(EFI_FILE_INFO));\r
+ memcpy(NewFileInfo, OldFileInfo, sizeof(EFI_FILE_INFO));\r
FreePool(OldFileInfo);\r
+ // Normalize path and convert to WCS.\r
+ NormalizedPath = NormalizePath(to);\r
+ if (NormalizedPath != NULL) {\r
// Strip off all but the file name portion of new\r
- NewFn = strrchr(to, '/');\r
- if(NewFn == NULL) {\r
- NewFn = strrchr(to, '\\');\r
- if(NewFn == NULL) {\r
- NewFn = (char *)to;\r
- }\r
- }\r
- // Convert new name from MBCS to WCS\r
- (void)AsciiStrToUnicodeStr( NewFn, gMD->UString);\r
+ NewFn = GetFileNameFromPath(NormalizedPath);\r
// Copy the new file name into our new file info buffer\r
- wcsncpy(NewFileInfo->FileName, gMD->UString, wcslen(gMD->UString)+1);\r
+ wcsncpy(NewFileInfo->FileName, NewFn, wcslen(NewFn) + 1);\r
+ // Update the size of the structure.\r
+ NewFileInfo->Size = sizeof(EFI_FILE_INFO) + StrSize(NewFn);\r
// Apply the new file name\r
Status = ShellSetFileInfo(FileHandle, NewFileInfo);\r
+ free(NormalizedPath);\r
free(NewFileInfo);\r
if(Status == EFI_SUCCESS) {\r
// File has been successfully renamed. We are DONE!\r
EFIerrno = Status;\r
}\r
else {\r
+ free(NewFileInfo);\r
+ errno = ENOMEM;\r
+ }\r
+ }\r
+ else {\r
+ free(NewFileInfo);\r
errno = EIO;\r
}\r
}\r
Stream->Abstraction.fo_poll = &da_ShellPoll;\r
Stream->Abstraction.fo_flush = &fnullop_flush;\r
Stream->Abstraction.fo_stat = &da_ShellStat;\r
- Stream->Abstraction.fo_ioctl = &fbadop_ioctl;\r
+ Stream->Abstraction.fo_ioctl = &da_ShellIoctl;\r
Stream->Abstraction.fo_delete = &da_ShellDelete;\r
Stream->Abstraction.fo_rmdir = &da_ShellRmdir;\r
Stream->Abstraction.fo_mkdir = &da_ShellMkdir;\r