I am working on this project to write files to local filesystem as soon as the OS starts through an EFI application. I need to know if it is possible. And if yes then kindly guide me a little. Thanks
Ok, I'll give you a good heads up...
First you enumerate all FS protocols in the system.
EFI_BOOT_SERVICES* bs = ...;
EFI_GUID sfspGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
EFI_HANDLE* handles = NULL;
UINTN handleCount = 0;
efiStatus = bs->LocateHandleBuffer(ByProtocol,
&sfspGuid,
NULL,
&handleCount,
&handles);
Then you go through all of them and open the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL for each handle you found, then you can grab a device path from a handle and figure out what device it is, what partition ect. and if the drive/partition is not what you are looking for skip it and go to the next handle. Or if you don't want to mess with DP parsing it you can simply try to open your file on each partition (handle) until the operation is successful.
for (index = 0; index < (int)handleCount; ++ index)
{
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs = NULL;
efiStatus = bs->HandleProtocol(
handles[index],
&sfspGuid,
(void**)&fs);
You found the handle for a partition you need. Then you open the volume.
EFI_FILE_PROTOCOL* root = NULL;
...
efiStatus = fs->OpenVolume(fs, &root);
There is some functions to enumerate files and folders ect... But if you know the correct file path you can open it right away.
EFI_FILE_PROTOCOL* token = NULL;
efiStatus = root->Open(
root,
&token,
L"myfolder\\token.bin",
EFI_FILE_MODE_READ,
EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
Under the EFI_FILE_PROTOCOL you have a whole bunch of functions to operate on files:
EFI_FILE_OPEN Open;
EFI_FILE_CLOSE Close;
EFI_FILE_DELETE Delete;
EFI_FILE_READ Read;
EFI_FILE_WRITE Write;
EFI_FILE_GET_POSITION GetPosition;
EFI_FILE_SET_POSITION SetPosition;
EFI_FILE_GET_INFO GetInfo;
EFI_FILE_SET_INFO SetInfo;
EFI_FILE_FLUSH Flush;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With