-
Notifications
You must be signed in to change notification settings - Fork 7
/
uefi_driver.h
150 lines (133 loc) · 5.79 KB
/
uefi_driver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* uefi_driver.h - ntfs-3g UEFI filesystem driver */
/*
* Copyright © 2021 Pete Batard <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef __MAKEWITH_GNUEFI
#include <efi.h>
#include <efilib.h>
#include <efidebug.h>
#else /* __MAKEWITH_GNUEFI */
#include <Base.h>
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DevicePathLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/DriverBinding.h>
#include <Protocol/DevicePathFromText.h>
#include <Protocol/DevicePathToText.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/BlockIo.h>
#include <Protocol/BlockIo2.h>
#include <Protocol/DiskIo.h>
#include <Protocol/DiskIo2.h>
#include <Protocol/ComponentName.h>
#include <Protocol/ComponentName2.h>
#include <Guid/FileSystemInfo.h>
#include <Guid/FileInfo.h>
#include <Guid/FileSystemVolumeLabelInfo.h>
#include <Guid/ShellVariableGuid.h>
#endif /* __MAKEWITH_GNUEFI */
/* Define the following to force NTFS volumes to be opened read-only */
/* #undef FORCE_READONLY */
#define NTFS_MUTEX_GUID { 0xf4ed18ca, 0xcdfb, 0x40ca, { 0x97, 0xec, 0x32, 0x2a, 0x8b, 0x01, 0x4e, 0x5f } }
/* Version information to be displayed by the driver. */
#ifndef DRIVER_VERSION
#define DRIVER_VERSION DEV
#endif
#ifndef COMMIT_INFO
#define COMMIT_INFO unknown
#endif
/* A file instance */
typedef struct _EFI_NTFS_FILE {
/*
* Considering that there are only two variations of a file
* handle (one for rw desired access mode and the other for
* ro) it doesn't really make sense to allocate a different
* EFI_NTFS_FILE structure for each. Instead since the handle
* we return must start with an EFI_FILE we can just have two
* EFI_FILE members, with one followed by an 0xFF..FF address
* (i.e. an invalid one) which we then use to detect if the
* desired access mode should be RO or RW. Note that, per
* UEFI specs, the only valid combinations that a file may be
* opened with are: Read, Read/Write, or Create/Read/Write.
* so we only need to consider read-only vs read/write.
*/
EFI_FILE EfiFileRW;
UINTN DetectRO;
EFI_FILE EfiFileRO;
UINTN MarkerRO;
BOOLEAN IsDir;
BOOLEAN IsRoot;
INT64 DirPos;
INT64 Offset;
CHAR16 *Path;
CHAR16 *BaseName;
INTN RefCount;
struct _EFI_FS *FileSystem;
VOID *NtfsInode;
} EFI_NTFS_FILE;
/* A file system instance */
typedef struct _EFI_FS {
LIST_ENTRY *ForwardLink;
LIST_ENTRY *BackLink;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL FileIoInterface;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
EFI_BLOCK_IO2_PROTOCOL *BlockIo2;
EFI_DISK_IO_PROTOCOL *DiskIo;
EFI_DISK_IO2_PROTOCOL *DiskIo2;
EFI_DISK_IO2_TOKEN DiskIo2Token;
CHAR16 *DevicePathString;
VOID *NtfsVolume;
CHAR16 *NtfsVolumeLabel;
UINT64 NtfsVolumeSerial;
INT64 Offset;
INTN MountCount;
INTN TotalRefCount;
LIST_ENTRY LookupListHead;
} EFI_FS;
/* The top of our file system instances list */
extern LIST_ENTRY FsListHead;
extern EFI_STATUS FSInstall(EFI_FS* This, EFI_HANDLE ControllerHandle);
extern VOID FSUninstall(EFI_FS* This, EFI_HANDLE ControllerHandle);
extern EFI_STATUS EFIAPI FileOpenVolume(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* This,
EFI_FILE_HANDLE* Root);
/*
* All the public file system operations that are defined in uefi_file.c
*/
EFI_STATUS EFIAPI FileOpen(EFI_FILE_HANDLE This, EFI_FILE_HANDLE* New,
CHAR16* Name, UINT64 Mode, UINT64 Attributes);
EFI_STATUS EFIAPI FileOpenEx(EFI_FILE_HANDLE This, EFI_FILE_HANDLE* New,
CHAR16* Name, UINT64 Mode, UINT64 Attributes, EFI_FILE_IO_TOKEN* Token);
EFI_STATUS EFIAPI FileClose(EFI_FILE_HANDLE This);
EFI_STATUS EFIAPI FileDelete(EFI_FILE_HANDLE This);
EFI_STATUS EFIAPI FileRead(EFI_FILE_HANDLE This, UINTN* Len, VOID* Data);
EFI_STATUS EFIAPI FileReadEx(IN EFI_FILE_PROTOCOL* This, IN OUT EFI_FILE_IO_TOKEN* Token);
EFI_STATUS EFIAPI FileWrite(EFI_FILE_HANDLE This, UINTN* Len, VOID* Data);
EFI_STATUS EFIAPI FileWriteEx(IN EFI_FILE_PROTOCOL* This, EFI_FILE_IO_TOKEN* Token);
EFI_STATUS EFIAPI FileSetPosition(EFI_FILE_HANDLE This, UINT64 Position);
EFI_STATUS EFIAPI FileGetPosition(EFI_FILE_HANDLE This, UINT64* Position);
EFI_STATUS EFIAPI FileGetInfo(EFI_FILE_HANDLE This, EFI_GUID* Type, UINTN* Len, VOID* Data);
EFI_STATUS EFIAPI FileSetInfo(EFI_FILE_HANDLE This, EFI_GUID* Type, UINTN Len, VOID* Data);
EFI_STATUS EFIAPI FileFlush(EFI_FILE_HANDLE This);
EFI_STATUS EFIAPI FileFlushEx(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN* Token);