/** @file\r
Main file for attrib shell level 2 function.\r
\r
- Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
}\r
} else {\r
Param1Copy = CatSPrint(NULL, L"%s", Param1, NULL);\r
- Param1Copy = PathCleanUpDirectories(Param1Copy);\r
- if (StrCmp(Param1Copy, L".") == 0) {\r
- //\r
- // nothing to do... change to current directory\r
- //\r
- } else if (StrCmp(Param1Copy, L"..") == 0) {\r
- //\r
- // Change up one directory...\r
- //\r
- Directory = ShellGetCurrentDir(NULL);\r
- if (Directory == NULL) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
- ShellStatus = SHELL_NOT_FOUND;\r
- } else {\r
- Drive = GetFullyQualifiedPath(Directory);\r
- PathRemoveLastItem(Drive);\r
- }\r
- if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
+ if (Param1Copy != NULL) {\r
+ Param1Copy = PathCleanUpDirectories(Param1Copy);\r
+ }\r
+ if (Param1Copy != NULL) {\r
+ if (StrCmp(Param1Copy, L".") == 0) {\r
//\r
- // change directory on current drive letter\r
+ // nothing to do... change to current directory\r
//\r
- Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r
- if (Status == EFI_NOT_FOUND) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
- ShellStatus = SHELL_NOT_FOUND;\r
- }\r
- }\r
- } else if (StrCmp(Param1Copy, L"\\") == 0) {\r
- //\r
- // Move to root of current drive\r
- //\r
- Directory = ShellGetCurrentDir(NULL);\r
- if (Directory == NULL) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
- ShellStatus = SHELL_NOT_FOUND;\r
- } else {\r
- Drive = GetFullyQualifiedPath(Directory);\r
- while (PathRemoveLastItem(Drive)) ;\r
- }\r
- if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
+ } else if (StrCmp(Param1Copy, L"..") == 0) {\r
//\r
- // change directory on current drive letter\r
+ // Change up one directory...\r
//\r
- Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r
- if (Status == EFI_NOT_FOUND) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+ Directory = ShellGetCurrentDir(NULL);\r
+ if (Directory == NULL) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
ShellStatus = SHELL_NOT_FOUND;\r
- }\r
- }\r
- } else if (StrStr(Param1Copy, L":") == NULL) {\r
- if (ShellGetCurrentDir(NULL) == NULL) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
- ShellStatus = SHELL_NOT_FOUND;\r
- } else {\r
- ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));\r
- Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);\r
- if (*Param1Copy == L'\\') {\r
- while (PathRemoveLastItem(Drive)) ;\r
- Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy+1, 0);\r
} else {\r
- Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy, 0);\r
+ Drive = GetFullyQualifiedPath(Directory);\r
+ PathRemoveLastItem(Drive);\r
}\r
+ if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
+ //\r
+ // change directory on current drive letter\r
+ //\r
+ Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r
+ if (Status == EFI_NOT_FOUND) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+ ShellStatus = SHELL_NOT_FOUND;\r
+ }\r
+ }\r
+ } else if (StrCmp(Param1Copy, L"\\") == 0) {\r
//\r
- // Verify that this is a valid directory\r
+ // Move to root of current drive\r
//\r
- Status = gEfiShellProtocol->OpenFileByName(Drive, &Handle, EFI_FILE_MODE_READ);\r
- if (EFI_ERROR(Status)) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Drive);\r
- ShellStatus = SHELL_NOT_FOUND;\r
- } else if (EFI_ERROR(FileHandleIsDirectory(Handle))) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, Drive);\r
+ Directory = ShellGetCurrentDir(NULL);\r
+ if (Directory == NULL) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
ShellStatus = SHELL_NOT_FOUND;\r
+ } else {\r
+ Drive = GetFullyQualifiedPath(Directory);\r
+ while (PathRemoveLastItem(Drive)) ;\r
}\r
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
//\r
ShellStatus = SHELL_NOT_FOUND;\r
}\r
}\r
- if (Handle != NULL) {\r
- gEfiShellProtocol->CloseFile(Handle);\r
- DEBUG_CODE(Handle = NULL;);\r
+ } else if (StrStr(Param1Copy, L":") == NULL) {\r
+ //\r
+ // change directory without a drive identifier\r
+ //\r
+ if (ShellGetCurrentDir(NULL) == NULL) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
+ ShellStatus = SHELL_NOT_FOUND;\r
+ } else {\r
+ ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));\r
+ Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);\r
+ if (*Param1Copy == L'\\') {\r
+ while (PathRemoveLastItem(Drive)) ;\r
+ Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy+1, 0);\r
+ } else {\r
+ Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy, 0);\r
+ }\r
+ //\r
+ // Verify that this is a valid directory\r
+ //\r
+ Status = gEfiShellProtocol->OpenFileByName(Drive, &Handle, EFI_FILE_MODE_READ);\r
+ if (EFI_ERROR(Status)) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Drive);\r
+ ShellStatus = SHELL_NOT_FOUND;\r
+ } else if (EFI_ERROR(FileHandleIsDirectory(Handle))) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, Drive);\r
+ ShellStatus = SHELL_NOT_FOUND;\r
+ }\r
+ if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
+ //\r
+ // change directory on current drive letter\r
+ //\r
+ Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r
+ if (Status == EFI_NOT_FOUND) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+ ShellStatus = SHELL_NOT_FOUND;\r
+ }\r
+ }\r
+ if (Handle != NULL) {\r
+ gEfiShellProtocol->CloseFile(Handle);\r
+ DEBUG_CODE(Handle = NULL;);\r
+ }\r
}\r
- }\r
- } else {\r
- //\r
- // change directory on other drive letter\r
- //\r
- Drive = AllocateZeroPool(StrSize(Param1Copy));\r
- if (Drive == NULL) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
- ShellStatus = SHELL_OUT_OF_RESOURCES;\r
} else {\r
- Drive = StrCpy(Drive, Param1Copy);\r
- Path = StrStr(Drive, L":");\r
- ASSERT(Path != NULL);\r
- if (*(Path+1) == CHAR_NULL) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
- ShellStatus = SHELL_NOT_FOUND;\r
+ //\r
+ // change directory with a drive letter\r
+ //\r
+ Drive = AllocateZeroPool(StrSize(Param1Copy));\r
+ if (Drive == NULL) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
+ ShellStatus = SHELL_OUT_OF_RESOURCES;\r
} else {\r
- *(Path+1) = CHAR_NULL;\r
- if (Path == Drive + StrLen(Drive)) {\r
+ Drive = StrCpy(Drive, Param1Copy);\r
+ Path = StrStr(Drive, L":");\r
+ ASSERT(Path != NULL);\r
+ if (EFI_ERROR(ShellIsDirectory(Param1Copy))) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, Param1Copy);\r
+ ShellStatus = SHELL_NOT_FOUND;\r
+ } else if (*(Path+1) == CHAR_NULL) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
ShellStatus = SHELL_NOT_FOUND;\r
} else {\r
- Status = gEfiShellProtocol->SetCurDir(Drive, Path+2);\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, ShellGetCurrentDir(Drive));\r
+ *(Path+1) = CHAR_NULL;\r
+ if (Path == Drive + StrLen(Drive)) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+ ShellStatus = SHELL_NOT_FOUND;\r
+ } else {\r
+ Status = gEfiShellProtocol->SetCurDir(Drive, Path+2);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, ShellGetCurrentDir(Drive));\r
+ }\r
+ }\r
+ if (Status == EFI_NOT_FOUND) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+ Status = SHELL_NOT_FOUND;\r
+ } else if (EFI_ERROR(Status)) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1Copy);\r
+ Status = SHELL_NOT_FOUND;\r
}\r
- }\r
- if (Status == EFI_NOT_FOUND) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
- Status = SHELL_NOT_FOUND;\r
- } else if (EFI_ERROR(Status)) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1Copy);\r
- Status = SHELL_NOT_FOUND;\r
}\r
}\r
}\r