From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C3FB92194D3B9 for ; Wed, 24 Oct 2018 11:07:28 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Oct 2018 11:07:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,421,1534834800"; d="scan'208";a="84151931" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga008.jf.intel.com with ESMTP; 24 Oct 2018 11:07:28 -0700 Received: from fmsmsx155.amr.corp.intel.com (10.18.116.71) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 24 Oct 2018 11:07:27 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.16]) by FMSMSX155.amr.corp.intel.com ([169.254.5.155]) with mapi id 14.03.0319.002; Wed, 24 Oct 2018 11:07:27 -0700 From: "Carsey, Jaben" To: "Jim.Dailey@dell.com" , "edk2-devel@lists.01.org" CC: "Ni, Ruiyu" Thread-Topic: [edk2][PATCH 1/2] ShellPkg-Shell App: Provide fully-qualified path to shell scripts Thread-Index: AdRrt2dO57FC299ES2iPnMY7oYr17AADPGQw Date: Wed, 24 Oct 2018 18:07:26 +0000 Message-ID: References: <33689dc40acb404a909157fe967193a3@ausx13mps335.AMER.DELL.COM> In-Reply-To: <33689dc40acb404a909157fe967193a3@ausx13mps335.AMER.DELL.COM> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMWJjYmQwNjEtMmFhMS00MzE2LTgzOTQtZmI3ZTI2YjM0NzA0IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiTTlyR0ErN1U4N0hEaXBVYjVqTlVJU094ZmJERFUxOUNsNklLcEVlYlEwV0d4dUpieGRZZXpYMGZ0XC9RcDFiMXgifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.1.200.106] MIME-Version: 1.0 Subject: Re: [PATCH 1/2] ShellPkg-Shell App: Provide fully-qualified path to shell scripts X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2018 18:07:29 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jaben Carsey Ray? I can push this one also if you don't see an issue. > -----Original Message----- > From: Jim.Dailey@dell.com [mailto:Jim.Dailey@dell.com] > Sent: Wednesday, October 24, 2018 9:35 AM > To: edk2-devel@lists.01.org > Cc: Ni, Ruiyu ; Carsey, Jaben > Subject: [edk2][PATCH 1/2] ShellPkg-Shell App: Provide fully-qualified pa= th > to shell scripts > Importance: High >=20 > Add a function to return the fully-qualified version of some path. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jim Dailey > --- > ShellPkg/Include/Library/ShellLib.h | 40 +++++++++ > ShellPkg/Library/UefiShellLib/UefiShellLib.c | 93 +++++++++++++++++++- > 2 files changed, 132 insertions(+), 1 deletion(-) >=20 > diff --git a/ShellPkg/Include/Library/ShellLib.h > b/ShellPkg/Include/Library/ShellLib.h > index 92fddc50f5..cd7e9c47c3 100644 > --- a/ShellPkg/Include/Library/ShellLib.h > +++ b/ShellPkg/Include/Library/ShellLib.h > @@ -2,6 +2,7 @@ > Provides interface to shell functionality for shell commands and > applications. >=20 > Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
> + Copyright 2018 Dell Technologies.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -35,6 +36,45 @@ > extern EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol; > extern EFI_SHELL_PROTOCOL *gEfiShellProtocol; >=20 > +/** > + Return the fully-qualified version of a relative path or an absolute p= ath that > + does not include a file system reference. > + > + If ASSERTs are disabled, and if the input parameter is NULL or points = to > NULL, > + then NULL is returned. > + > + If the input path contains a ":", this function assumes that it is par= t of a > + reference to a file system (e.g. "FS0:"). In such a case, Path is cle= aned > + and returned. > + > + If there is no working directory or there is not enough memory availab= le to > + create the fully-qualified path, Path is cleaned and returned. > + > + Otherwise, the current file system or working directory (as appropriat= e) is > + prepended to Path. The input Path is freed and the resulting path is > cleaned, > + assigned to Path, and returned. > + > + NOTE: If the input path is an empty string, then the current working > directory > + (if it exists) is returned. In other words, an empty input path is tr= eated > + exactly the same as ".". > + > + @param[in, out] Path On input, a pointer to some file or directory pa= th. > On > + output, a pointer to the clean and possibly full= y- > + qualified version of the input path. The input = pointer > + may be freed and reassigned on output. > + > + @retval NULL The input pointer or the path itself was NULL. > + > + @return A pointer to the clean, fully-qualified version of Path. If m= emory > + allocation fails, or if there is no working directory, then a = pointer > + to the clean, but not necessarily fully-qualified version of P= ath. > +**/ > +CHAR16* > +EFIAPI > +FullyQualifyPath( > + IN OUT CHAR16 **Path > + ); > + > /** > This function will retrieve the information about the file for the han= dle > specified and store it in allocated pool memory. > diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c > b/ShellPkg/Library/UefiShellLib/UefiShellLib.c > index f04adbb63f..52ca3ce1b1 100644 > --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c > +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c > @@ -2,7 +2,7 @@ > Provides interface to shell functionality for shell commands and > applications. >=20 > (C) Copyright 2016 Hewlett Packard Enterprise Development LP
> - Copyright 2016 Dell Inc. > + Copyright 2016-2018 Dell Technologies.
> Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > @@ -36,6 +36,97 @@ EFI_HANDLE mEfiShellEnvironment2Han= dle; > FILE_HANDLE_FUNCTION_MAP FileFunctionMap; > EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationProtocol; >=20 > +/** > + Return the fully-qualified version of a relative path or an absolute p= ath that > + does not include a file system reference. > + > + If asserts are disabled, and if the input parameter is NULL or points = to > NULL, > + then NULL is returned. > + > + If the input path contains a ":", this function assumes that it is par= t of a > + reference to a file system (e.g. "FS0:"). In such a case, Path is cle= aned > + and returned. > + > + If there is no working directory or there is not enough memory availab= le to > + create the fully-qualified path, Path is cleaned and returned. > + > + Otherwise, the current file system or working directory (as appropriat= e) is > + prepended to Path. The input Path is freed and the resulting path is > cleaned, > + assigned to Path, and returned. > + > + NOTE: If the input path is an empty string, then the current working > directory > + (if it exists) is returned. In other words, an empty input path is tr= eated > + exactly the same as ".". > + > + @param[in, out] Path On input, a pointer to some file or directory pa= th. > On > + output, a pointer to the clean and possibly full= y- > + qualified version of the input path. The input = pointer > + may be freed and reassigned on output. > + > + @retval NULL The input pointer or the path itself was NULL. > + > + @return A pointer to the clean, fully-qualified version of Path. If m= emory > + allocation fails, or if there is no working directory, then a = pointer > + to the clean, but not necessarily fully-qualified version of P= ath. > +**/ > +CHAR16* > +EFIAPI > +FullyQualifyPath( > + IN OUT CHAR16 **Path > + ) > +{ > + CONST CHAR16 *WorkingPath; > + CHAR16 *FullyQualifiedPath; > + UINTN Size; > + > + ASSERT(Path !=3D NULL); > + ASSERT(*Path !=3D NULL); > + > + // > + // Handle erroneous input when asserts are disabled. > + // > + if (Path =3D=3D NULL || *Path =3D=3D NULL) { > + return NULL; > + } > + > + if (StrStr(*Path, L":") =3D=3D NULL) { > + WorkingPath =3D ShellGetEnvironmentVariable(L"cwd"); > + if (WorkingPath !=3D NULL) { > + // > + // Room for both strings plus one more character. > + // > + Size =3D StrSize(WorkingPath) + StrSize(*Path); > + FullyQualifiedPath =3D AllocateZeroPool(Size); > + if (FullyQualifiedPath !=3D NULL) { > + if (**Path =3D=3D L'\\' || **Path =3D=3D L'/') { > + // > + // Absolute path: start with the current working directory, th= en > + // truncate the new path after the file system part. > + // > + StrCpyS(FullyQualifiedPath, Size/sizeof(CHAR16), WorkingPath); > + *(StrStr(FullyQualifiedPath, L":") + 1) =3D CHAR_NULL; > + } else { > + // > + // Relative path: start with the working directory and append = "\". > + // > + StrCpyS(FullyQualifiedPath, Size/sizeof(CHAR16), WorkingPath); > + StrCatS(FullyQualifiedPath, Size/sizeof(CHAR16), L"\\"); > + } > + // > + // Now append the absolute or relative path. > + // > + StrCatS(FullyQualifiedPath, Size/sizeof(CHAR16), *Path); > + FreePool(*Path); > + *Path =3D FullyQualifiedPath; > + } > + } > + } > + > + PathCleanUpDirectories(*Path); > + > + return *Path; > +} > + > /** > Check if a Unicode character is a hexadecimal character. >=20 > -- > 2.17.0.windows.1