我可以使用EFI在本地文件系统上写入数据吗? [英] Can I write on my local filesystem using EFI

查看:283
本文介绍了我可以使用EFI在本地文件系统上写入数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事这个项目,一旦操作系统通过EFI应用程序启动,就将文件写入本地文件系统。我需要知道这是否可能。如果是的话,请引导我一点。
谢谢

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

推荐答案

好吧,我会给你一个好头......
$ b

Ok, I'll give you a good heads up...


  1. 首先列举系统中的所有FS协议。

  1. 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);


  • 然后,通过所有这些查找并打开每个找到的句柄的EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,然后你可以从一个句柄中抓取一个设备路径,找出它是什么设备,什么分区等。如果驱动器/分区不是你正在寻找的跳过它,并转到下一个句柄。或者如果你不想搞DP解析它,你可以简单地尝试在每个分区(句柄)上打开你的文件,直到操作成功。

  • 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);
    


  • 在EFI_FILE_PROTOCOL下,函数对文件进行操作:

    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;
    

    这篇关于我可以使用EFI在本地文件系统上写入数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆