TianoCore EDK2 master
Loading...
Searching...
No Matches
Touch.c
Go to the documentation of this file.
1
11
12#include <Library/ShellLib.h>
13
24 IN SHELL_FILE_HANDLE Handle
25 )
26{
27 EFI_STATUS Status;
29
30 FileInfo = gEfiShellProtocol->GetFileInfo (Handle);
31 if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) != 0) {
32 return (EFI_ACCESS_DENIED);
33 }
34
35 Status = gRT->GetTime (&FileInfo->ModificationTime, NULL);
36 if (EFI_ERROR (Status)) {
37 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"gRT->GetTime", Status);
38 return (SHELL_DEVICE_ERROR);
39 }
40
42
43 Status = gEfiShellProtocol->SetFileInfo (Handle, FileInfo);
44
46
47 return (Status);
48}
49
63 IN CONST CHAR16 *Name,
64 IN CHAR16 *FS,
65 IN SHELL_FILE_HANDLE Handle,
66 IN BOOLEAN Rec
67 )
68{
69 EFI_STATUS Status;
70 EFI_SHELL_FILE_INFO *FileList;
71 EFI_SHELL_FILE_INFO *Walker;
72 CHAR16 *TempSpot;
73
74 Status = EFI_SUCCESS;
75 FileList = NULL;
76 Walker = NULL;
77
78 if (FS == NULL) {
79 FS = StrnCatGrow (&FS, NULL, Name, 0);
80 if (FS != NULL) {
81 TempSpot = StrStr (FS, L"\\");
82 if (TempSpot != NULL) {
83 *TempSpot = CHAR_NULL;
84 }
85 }
86 }
87
88 if (FS == NULL) {
89 return (EFI_INVALID_PARAMETER);
90 }
91
92 //
93 // do it
94 //
95 Status = TouchFileByHandle (Handle);
96 if (EFI_ERROR (Status)) {
97 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Name);
98 return (Status);
99 }
100
101 //
102 // if it's a directory recurse...
103 //
104 if ((FileHandleIsDirectory (Handle) == EFI_SUCCESS) && Rec) {
105 //
106 // get each file under this directory
107 //
108 if (EFI_ERROR (gEfiShellProtocol->FindFilesInDir (Handle, &FileList))) {
109 Status = EFI_INVALID_PARAMETER;
110 }
111
112 //
113 // recurse on each
114 //
115 for (Walker = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
116 ; FileList != NULL && !IsNull (&FileList->Link, &Walker->Link) && !EFI_ERROR (Status)
117 ; Walker = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Walker->Link)
118 )
119 {
120 if ( (StrCmp (Walker->FileName, L".") != 0)
121 && (StrCmp (Walker->FileName, L"..") != 0)
122 )
123 {
124 //
125 // Open the file since we need that handle.
126 //
127 Status = gEfiShellProtocol->OpenFileByName (Walker->FullName, &Walker->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);
128 if (EFI_ERROR (Status)) {
129 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Walker->FullName);
130 Status = EFI_ACCESS_DENIED;
131 } else {
132 Status = DoTouchByHandle (Walker->FullName, FS, Walker->Handle, TRUE);
133 gEfiShellProtocol->CloseFile (Walker->Handle);
134 Walker->Handle = NULL;
135 }
136 }
137 }
138
139 //
140 // free stuff
141 //
142 if ((FileList != NULL) && EFI_ERROR (gEfiShellProtocol->FreeFileList (&FileList))) {
143 Status = EFI_INVALID_PARAMETER;
144 }
145 }
146
147 return (Status);
148}
149
150STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
151 { L"-r", TypeFlag },
152 { NULL, TypeMax }
153};
154
162EFIAPI
164 IN EFI_HANDLE ImageHandle,
165 IN EFI_SYSTEM_TABLE *SystemTable
166 )
167{
168 EFI_STATUS Status;
169 LIST_ENTRY *Package;
170 CHAR16 *ProblemParam;
171 CONST CHAR16 *Param;
172 SHELL_STATUS ShellStatus;
173 UINTN ParamCount;
174 EFI_SHELL_FILE_INFO *FileList;
176
177 ProblemParam = NULL;
178 ShellStatus = SHELL_SUCCESS;
179 ParamCount = 0;
180 FileList = NULL;
181
182 //
183 // initialize the shell lib (we must be in non-auto-init...)
184 //
185 Status = ShellInitialize ();
186 ASSERT_EFI_ERROR (Status);
187
188 Status = CommandInit ();
189 ASSERT_EFI_ERROR (Status);
190
191 //
192 // parse the command line
193 //
194 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
195 if (EFI_ERROR (Status)) {
196 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
197 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"touch", ProblemParam);
198 FreePool (ProblemParam);
199 ShellStatus = SHELL_INVALID_PARAMETER;
200 } else {
201 ASSERT (FALSE);
202 }
203 } else {
204 //
205 // check for "-?"
206 //
207 if (ShellCommandLineGetFlag (Package, L"-?")) {
208 ASSERT (FALSE);
209 }
210
211 if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
212 //
213 // we insufficient parameters
214 //
215 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle, L"touch");
216 ShellStatus = SHELL_INVALID_PARAMETER;
217 } else {
218 //
219 // get a list with each file specified by parameters
220 // if parameter is a directory then add all the files below it to the list
221 //
222 for ( ParamCount = 1, Param = ShellCommandLineGetRawValue (Package, ParamCount)
223 ; Param != NULL
224 ; ParamCount++, Param = ShellCommandLineGetRawValue (Package, ParamCount)
225 )
226 {
227 Status = ShellOpenFileMetaArg ((CHAR16 *)Param, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, &FileList);
228 if (EFI_ERROR (Status)) {
229 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"touch", (CHAR16 *)Param);
230 ShellStatus = SHELL_NOT_FOUND;
231 break;
232 }
233
234 //
235 // make sure we completed the param parsing successfully...
236 // Also make sure that any previous action was successful
237 //
238 if (ShellStatus == SHELL_SUCCESS) {
239 //
240 // check that we have at least 1 file
241 //
242 if ((FileList == NULL) || IsListEmpty (&FileList->Link)) {
243 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel3HiiHandle, L"touch", Param);
244 continue;
245 } else {
246 //
247 // loop through the list and make sure we are not aborting...
248 //
249 for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
250 ; !IsNull (&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag ()
251 ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link)
252 )
253 {
254 //
255 // make sure the file opened ok
256 //
257 if (EFI_ERROR (Node->Status)) {
258 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Node->FileName);
259 ShellStatus = SHELL_NOT_FOUND;
260 continue;
261 }
262
263 Status = DoTouchByHandle (Node->FullName, NULL, Node->Handle, ShellCommandLineGetFlag (Package, L"-r"));
264 if (EFI_ERROR (Status) && (Status != EFI_ACCESS_DENIED)) {
265 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Node->FileName);
266 ShellStatus = SHELL_NOT_FOUND;
267 }
268 }
269 }
270 }
271
272 //
273 // Free the fileList
274 //
275 if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) {
276 Status = ShellCloseFileMetaArg (&FileList);
277 ASSERT_EFI_ERROR (Status);
278 }
279
280 FileList = NULL;
281 }
282 }
283
284 //
285 // free the command line package
286 //
288 }
289
291 return (SHELL_ABORTED);
292 }
293
294 return (ShellStatus);
295}
UINT64 UINTN
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:443
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:333
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI FileHandleIsDirectory(IN EFI_FILE_HANDLE DirHandle)
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_ABORTED
Definition: Shell.h:128
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_DEVICE_ERROR
Definition: Shell.h:63
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_FILE_INFO * FileInfo(IN EFI_FILE_HANDLE FHand)
EFI_STATUS EFIAPI CommandInit(VOID)
BOOLEAN EFIAPI ShellGetExecutionBreakFlag(VOID)
EFI_STATUS EFIAPI ShellCloseFileMetaArg(IN OUT EFI_SHELL_FILE_INFO **ListHead)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
EFI_STATUS EFIAPI ShellOpenFileMetaArg(IN CHAR16 *Arg, IN UINT64 OpenMode, IN OUT EFI_SHELL_FILE_INFO **ListHead)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
EFI_STATUS TouchFileByHandle(IN SHELL_FILE_HANDLE Handle)
Definition: Touch.c:23
EFI_STATUS DoTouchByHandle(IN CONST CHAR16 *Name, IN CHAR16 *FS, IN SHELL_FILE_HANDLE Handle, IN BOOLEAN Rec)
Definition: Touch.c:62
SHELL_STATUS EFIAPI ShellCommandRunTouch(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Touch.c:163
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define STRING_TOKEN(t)
EFI_TIME ModificationTime
Definition: FileInfo.h:43
UINT64 Attribute
Definition: FileInfo.h:47
EFI_TIME LastAccessTime
Definition: FileInfo.h:39
LIST_ENTRY Link
Linked list members.
Definition: Shell.h:153
SHELL_FILE_HANDLE Handle
Handle for interacting with the opened file or NULL if closed.
Definition: Shell.h:157
EFI_STATUS Status
Status of opening the file. Valid only if Handle != NULL.
Definition: Shell.h:154
CONST CHAR16 * FullName
Fully qualified filename.
Definition: Shell.h:155
CONST CHAR16 * FileName
name of this file.
Definition: Shell.h:156