From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8438F1A1DF5 for ; Tue, 27 Sep 2016 08:07:46 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 27 Sep 2016 08:07:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,405,1470726000"; d="scan'208";a="1046524906" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga001.fm.intel.com with ESMTP; 27 Sep 2016 08:07:38 -0700 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 27 Sep 2016 08:07:38 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.167]) by FMSMSX109.amr.corp.intel.com ([169.254.15.235]) with mapi id 14.03.0248.002; Tue, 27 Sep 2016 08:07:37 -0700 From: "Carsey, Jaben" To: GN Keshava , Laszlo Ersek CC: "edk2-devel@lists.01.org" , "Carsey, Jaben" Thread-Topic: [edk2] How to open a file by it's full path in UEFI Thread-Index: AQHSGJ4fznBgOczOmEaDTjh6fGOg06CNg7oAgAACgQCAAAavgIAAD/SAgAAIpYCAAAmuAP//vqRw Date: Tue, 27 Sep 2016 15:07:36 +0000 Message-ID: References: <765021a6-cea7-ba5f-58cf-5e8fce05bbf2@redhat.com> <87d54199-6065-47e4-b3f8-04fd6f93220f@redhat.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMzkzMGJhOWMtODg2Ny00ODM0LWE5MzUtZDUzZjBjY2U0NTZmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6Ik9hckNocHN5Z3RkSVwvSzl3aEcyU1wvZ1pBRjZkS1ZSZW5iNHhSeXJ2d2xjRT0ifQ== x-ctpclassification: CTP_IC x-originating-ip: [10.1.200.108] MIME-Version: 1.0 Subject: Re: How to open a file by it's full path in UEFI X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Sep 2016 15:07:46 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Apparently all the good threads happen at night for me... Kesheva, There are a few functions in the ShellLib that call into the UEFI Shell bin= ary to help you. Some of these are duplicates of what others suggested, but= I figured I would elaborate. ShellOpenFileMetaArg - open a file or group of files. can handle something= like "open *.txt" ShellOpenFileByName - open a single file. These functions in turn call into functions in the ShellProtocol that the U= EFI Shell produces during the time it is running. ShellOpenFileMetaArg calls into gEfiShellProtocol->OpenFileList ShellOpenFileByName calls into gEfiShellProtocol->OpenFileByName There is some examples of use of these functions in the files for the comma= nds "Touch" and "Type" and these are located in: ShellPkg\Library\UefiShell= Level3CommandsLib -Jaben > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > GN Keshava > Sent: Tuesday, September 27, 2016 4:52 AM > To: Laszlo Ersek > Cc: edk2-devel@lists.01.org > Subject: Re: [edk2] How to open a file by it's full path in UEFI >=20 > Thank you Laszlo. >=20 > I'll check it out. :) >=20 > Thanks again. > Regards, > Keshava >=20 > On Tue, 27 Sep 2016 at 16:47 Laszlo Ersek wrote: >=20 > > On 09/27/16 12:46, GN Keshava wrote: > > > Hi Laszlo, > > > > > > Thank you for the answer. It was helpful. > > > > > > Considering option #1, can you give some more details (a small exampl= e > > > or any reference link would be helpful), how I can use Shell APIs in = my > > > C file (which will compile to my .efi app)? > > > > Hmmm, I don't have hands-on experience with this, but you might want to > > try the ShellOpenFileByName() function, from > > "ShellPkg/Include/Library/ShellLib.h". > > > > You can find examples for UEFI applications that use the Shell library > > with: > > > > git grep -w ShellLib -- '*inf' > > > > or just grep the tree for ShellOpenFileByName(). > > > > See also "AppPkg/ReadMe.txt". > > > > > Considering option #2, How I can find device path programatically fro= m > > > my C file? > > > > The EFI_SHELL_PROTOCOL.GetDevicePathFromMap() member function > seems > > relevant -- it is specified in the UEFI Shell spec --, but I would > > definitely try ShellOpenFileByName() first. > > > > Thanks > > Laszlo > > > > > Thanks again for the help. :) > > > With regards, > > > Keshava > > > > > > On Tue, 27 Sep 2016 at 15:19 Laszlo Ersek > > > wrote: > > > > > > On 09/27/16 11:25, GN Keshava wrote: > > > > Hi Laszlo, > > > > > > > > Thanks for the reply. I meant I have complete file path. I beli= eve > > the > > > > "device path" is different. Is it possible to obtain DevicePath > > > using my > > > > full file path? > > > > > > The pathname you seem to have (as "complete") is specific to a gi= ven > > > simple FS, so system-wide it cannot be considered complete (there > > can be > > > multiple filesystems). > > > > > > In your original email I missed that you started with "FS1:". > > Andrew's > > > answer covers that case. > > > > > > In summary, you can do three things: > > > - have a pathname that starts with FSx: (which is a shell-specifi= c > > > mapping), and use Andrew's recommendation, > > > - have a complete UEFI device path, and then use what I > recommended, > > > - have no information for selecting the filesystem (from the many > > > possible), and use your current iteration. > > > > > > Options #1 and #2 actually correspond to each other, considering > > > "expressive power" / information content (as long as you are in t= he > > > shell); please see the MAP shell command. > > > > > > Thanks > > > Laszlo > > > > > > > On Tue, 27 Sep 2016 at 14:46 Laszlo Ersek > > > > > > >> wrote: > > > > > > > > On 09/27/16 11:03, GN Keshava wrote: > > > > > Hi all, > > > > > > > > > > > > > > > I'm trying to open a file from my UEFI application. The p= ath > > of > > > > file is > > > > > > > > > > fs1:/myfolder/myfile.txt > > > > > > > > > > The code : > > > > > > > > > > efiStatus =3D bs->LocateHandleBuffer(ByProtocol, > > > > > &sfspGuid, > > > > > NULL, > > > > > &handleCount, > > > > > &handles); > > > > > > > > > > for (index =3D 0; index < (int)handleCount; ++ index) > > > > > { > > > > > EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs =3D NULL; > > > > > > > > > > efiStatus =3D bs->HandleProtocol( > > > > > handles[index], > > > > > &sfspGuid, > > > > > (void**)&fs); > > > > > > > > > > EFI_FILE_PROTOCOL* root =3D NULL; > > > > > ... > > > > > efiStatus =3D fs->OpenVolume(fs, &root); > > > > > > > > > > EFI_FILE_PROTOCOL* token =3D NULL; > > > > > > > > > > efiStatus =3D root->Open( > > > > > root, > > > > > &token, > > > > > L"myfolder\\myfile.txt", > > > > > EFI_FILE_MODE_READ, > > > > > EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | > > EFI_FILE_SYSTEM); > > > > > } > > > > > > > > > > But using this method, I can only go through all the file > > system > > > > handles > > > > > and open each volume and try opening my file. > > > > > > > > > > But I want to give full path to my file and open it in it= 's > > > volume. > > > > > > > > > > How can I acheive this? > > > > > Thanks. > > > > > > > > If you have a complete device path, you can use > > > gBS->LocateDevicePath() > > > > with gEfiSimpleFileSystemProtocolGuid, to locate the handle > > > with the > > > > most specific device path (--> the longest device path pref= ix) > > > with the > > > > simple FS protocol installed on it. Then you can check if t= he > > > remaining > > > > device path (returned by the service) consist of nothing bu= t > > > one File > > > > Path Media Device Path node. If so, you can open the simple= FS > > > protocol > > > > on the handle found, then use that to open the file by > > pathname. > > > > > > > > Laszlo > > > > > > > > > > > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel