Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
OpenCorePKG_MOD
提交
4314cec0
O
OpenCorePKG_MOD
项目概览
btwise
/
OpenCorePKG_MOD
通知
26
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
OpenCorePKG_MOD
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4314cec0
编写于
3月 28, 2019
作者:
V
vit9696
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
OcFileLib: Implement file writing functionality based on CrScreenshotDxe from LongSoft
上级
504612ff
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
179 addition
and
0 deletion
+179
-0
Include/Library/OcFileLib.h
Include/Library/OcFileLib.h
+31
-0
Library/OcFileLib/FileProtocol.c
Library/OcFileLib/FileProtocol.c
+148
-0
未找到文件。
Include/Library/OcFileLib.h
浏览文件 @
4314cec0
...
...
@@ -86,6 +86,25 @@ ReadFileData (
OUT
UINT8
*
Buffer
);
/**
Write exact amount of bytes to a newly created file in EFI_FILE_PROTOCOL.
Please note, that several filesystems (or drivers) may limit file name length.
@param[in] WritableFs A pointer to the file protocol, any will be tried if NULL.
@param[in] FileName File name (possibly with path) to write.
@param[in] Buffer A pointer with the data to be written.
@param[in] Size Amount of data to be written.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
WriteFileData
(
IN
EFI_FILE_PROTOCOL
*
WritableFs
OPTIONAL
,
IN
CONST
CHAR16
*
FileName
,
IN
CONST
VOID
*
Buffer
,
IN
UINT32
Size
);
/**
Determine file size if it is less than 4 GB.
...
...
@@ -114,4 +133,16 @@ ReadFileModifcationTime (
OUT
EFI_TIME
*
Time
);
/**
Determine writeable filesystem.
@param[in,out] WritableFs First found writeable file system.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
FindWritableFileSystem
(
IN
OUT
EFI_FILE_PROTOCOL
**
WritableFs
);
#endif // OC_FILE_LIB_H
Library/OcFileLib/FileProtocol.c
浏览文件 @
4314cec0
...
...
@@ -18,8 +18,10 @@
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcFileLib.h>
#include <Library/UefiBootServicesTableLib.h>
EFI_STATUS
ReadFileData
(
...
...
@@ -115,3 +117,149 @@ ReadFileModifcationTime (
return
EFI_SUCCESS
;
}
EFI_STATUS
FindWritableFileSystem
(
IN
OUT
EFI_FILE_PROTOCOL
**
WritableFs
)
{
EFI_HANDLE
*
HandleBuffer
;
UINTN
HandleCount
;
UINTN
Index
;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*
SimpleFs
;
EFI_FILE_PROTOCOL
*
Fs
;
EFI_FILE_PROTOCOL
*
File
;
//
// Locate all the simple file system devices in the system.
//
EFI_STATUS
Status
=
gBS
->
LocateHandleBuffer
(
ByProtocol
,
&
gEfiSimpleFileSystemProtocolGuid
,
NULL
,
&
HandleCount
,
&
HandleBuffer
);
if
(
EFI_ERROR
(
Status
))
{
return
Status
;
}
for
(
Index
=
0
;
Index
<
HandleCount
;
++
Index
)
{
Status
=
gBS
->
HandleProtocol
(
HandleBuffer
[
Index
],
&
gEfiSimpleFileSystemProtocolGuid
,
(
VOID
**
)
&
SimpleFs
);
if
(
EFI_ERROR
(
Status
))
{
DEBUG
((
DEBUG_VERBOSE
,
"FindWritableFileSystem: gBS->HandleProtocol[%u] returned %r
\n
"
,
(
UINT32
)
Index
,
Status
));
continue
;
}
Status
=
SimpleFs
->
OpenVolume
(
SimpleFs
,
&
Fs
);
if
(
EFI_ERROR
(
Status
))
{
DEBUG
((
DEBUG_VERBOSE
,
"FindWritableFileSystem: SimpleFs->OpenVolume[%u] returned %r
\n
"
,
(
UINT32
)
Index
,
Status
));
continue
;
}
//
// We cannot test if the file system is writeable without attempting to create some file.
//
Status
=
Fs
->
Open
(
Fs
,
&
File
,
L"octest.fil"
,
EFI_FILE_MODE_CREATE
|
EFI_FILE_MODE_READ
|
EFI_FILE_MODE_WRITE
,
0
);
if
(
EFI_ERROR
(
Status
))
{
DEBUG
((
DEBUG_VERBOSE
,
"FindWritableFileSystem: Fs->Open[%u] returned %r
\n
"
,
(
UINT32
)
Index
,
Status
));
continue
;
}
//
// Delete the temporary file and report the found file system.
//
Fs
->
Delete
(
File
);
*
WritableFs
=
Fs
;
break
;
}
gBS
->
FreePool
(
HandleBuffer
);
return
Status
;
}
EFI_STATUS
WriteFileData
(
IN
EFI_FILE_PROTOCOL
*
WritableFs
OPTIONAL
,
IN
CONST
CHAR16
*
FileName
,
IN
CONST
VOID
*
Buffer
,
IN
UINT32
Size
)
{
EFI_STATUS
Status
;
EFI_FILE_PROTOCOL
*
Fs
;
EFI_FILE_PROTOCOL
*
File
;
UINTN
WrittenSize
;
if
(
WritableFs
==
NULL
)
{
Status
=
FindWritableFileSystem
(
&
Fs
);
if
(
EFI_ERROR
(
Status
))
{
DEBUG
((
DEBUG_VERBOSE
,
"WriteFileData: Can't find writable FS
\n
"
));
return
Status
;
}
}
else
{
Fs
=
WritableFs
;
}
Status
=
Fs
->
Open
(
Fs
,
&
File
,
(
CHAR16
*
)
FileName
,
EFI_FILE_MODE_CREATE
|
EFI_FILE_MODE_READ
|
EFI_FILE_MODE_WRITE
,
0
);
if
(
!
EFI_ERROR
(
Status
))
{
WrittenSize
=
Size
;
Status
=
File
->
Write
(
File
,
&
WrittenSize
,
(
VOID
*
)
Buffer
);
Fs
->
Close
(
File
);
if
(
EFI_ERROR
(
Status
))
{
DEBUG
((
DEBUG_VERBOSE
,
"WriteFileData: File->Write returned %r
\n
"
,
Status
));
}
else
if
(
WrittenSize
!=
Size
)
{
DEBUG
((
DEBUG_VERBOSE
,
"WriteFileData: File->Write truncated %u to %u
\n
"
,
Status
,
Size
,
(
UINT32
)
WrittenSize
));
Status
=
EFI_BAD_BUFFER_SIZE
;
}
}
else
{
DEBUG
((
DEBUG_VERBOSE
,
"WriteFileData: Fs->Open of %s returned %r
\n
"
,
FileName
,
Status
));
}
if
(
WritableFs
==
NULL
)
{
Fs
->
Close
(
Fs
);
}
return
Status
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录