MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / egSaveFile

Function egSaveFile

rEFIt_UEFI/libeg/image.cpp:136–217  ·  view source on GitHub ↗

if (NULL, ...) then save to EFI partition

Source from the content-addressed store, hash-verified

134}
135//if (NULL, ...) then save to EFI partition
136EFI_STATUS egSaveFile(IN EFI_FILE_HANDLE BaseDir OPTIONAL, IN CONST CHAR16 *FileName,
137 IN CONST VOID *FileData, IN UINTN FileDataLength)
138{
139 EFI_STATUS Status;
140 EFI_FILE_HANDLE FileHandle;
141 UINTN BufferSize;
142 BOOLEAN CreateNew = TRUE;
143 CONST CHAR16 *p = FileName + StrLen(FileName);
144 CHAR16 DirName[256];
145 UINTN dirNameLen;
146
147 if (BaseDir == NULL) {
148 Status = egFindESP(&BaseDir);
149 if (EFI_ERROR(Status)) {
150 DBG("no ESP %s\n", efiStrError(Status));
151 return Status;
152 }
153 }
154
155 // syscl - make directory if not exist
156 while (*p != L'\\' && p >= FileName) {
157 // find the first '\\' traverse from the end to head of FileName
158 p -= 1;
159 }
160 dirNameLen = p - FileName;
161 StrnCpyS(DirName, 256, FileName, dirNameLen);
162 DirName[dirNameLen] = L'\0';
163 Status = BaseDir->Open(BaseDir, &FileHandle, DirName,
164 EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, EFI_FILE_DIRECTORY);
165
166 if (EFI_ERROR(Status)) {
167 // make dir
168// DBG("no dir %s\n", efiStrError(Status));
169 Status = BaseDir->Open(BaseDir, &FileHandle, DirName,
170 EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, EFI_FILE_DIRECTORY);
171// DBG("cant make dir %s\n", efiStrError(Status));
172 }
173 // end of folder checking
174
175 // Delete existing file if it exists
176 Status = BaseDir->Open(BaseDir, &FileHandle, FileName,
177 EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
178 if (!EFI_ERROR(Status)) {
179 Status = FileHandle->Delete(FileHandle);
180 if (Status == EFI_WARN_DELETE_FAILURE) {
181 //This is READ_ONLY file system
182 CreateNew = FALSE; // will write into existing file (Slice - ???)
183// DBG("RO FS %s\n", efiStrError(Status));
184 }
185 }
186
187 if (CreateNew) {
188 // Write new file
189 Status = BaseDir->Open(BaseDir, &FileHandle, FileName,
190 EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
191 if (EFI_ERROR(Status)) {
192// DBG("no write %s\n", efiStrError(Status));
193 return Status;

Callers 8

SaveBooterLogFunction · 0.85
SaveBufferToDiskFunction · 0.85
SaveOemDsdtFunction · 0.85
PatchACPIFunction · 0.85
SaveHdaDumpTxtFunction · 0.85
SaveHdaDumpBinFunction · 0.85
RunGenericMenuMethod · 0.85
egScreenShotFunction · 0.85

Calls 9

egFindESPFunction · 0.85
StrnCpySFunction · 0.85
EfiLibFileInfoFunction · 0.70
StrLenFunction · 0.50
efiStrErrorFunction · 0.50
FreePoolFunction · 0.50
OpenMethod · 0.45
WriteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected