rizxt wrote:
iansjack wrote:
Have you looked at the simple file system protocol?
Yes, however I can't get readable or commented example code on it...
the specification isn't a tutorial, so it barely contains copy-and-paste ready snippets, but from my own experience, it's really quite easy to get what to do with it, at least simple file system protocol (SFSP).
here is the snippets from some files of my loader.
0) you need to get the device handle of the device, where your volume resides for opening the needed protocol - be it SFSP for FW-supported FAT volumes or Block I/O protocol for the rest cases. note, in this example, we use the same volume, where the loader comes from, so we locate DeviceHandle through the LoadedImageProtocol instance installed on the image handle of our loader. For the volume, where the OS resides (Boot Volume), locating the handle and overall path is different, both - because you would use Device Path to it and - because it's your burden to parse the format of the volume, that differs from FW supported, of your OS Boot Volume. In most cases, it's non-FAT and firmware can only provide you with the block level access to this device. read below. this example extracts the logo to show on the screen, from the same volume where the loader comes, from the "res" subdirectory of your own "home", inside the "efi" folder. it's how it should have been done - having your own subdirectory inside the "efi" directory, for your (loader! not OS) stuff - loader(s), resources, configuration. it's generally done on a system partition, but as well will work on an ordinary FAT volume.
Code:
/* Opening Loaded Image Protocol instance on our image handle */
Status = pbs->OpenProtocol(
ImageHandle,
&gEfiLoadedImageGuid,
&gpLoadedImageProtocol,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if(Status != EFI_SUCCESS){
return ErrorExit(Status, L"ERROR: OpenProtocol() unsuccess on LOADED_IMAGE_PROTOCOL, status: ");
}
1) now, when you have a device handle, you open an SFSP instance on it. On non-FAT volumes, you use block I/O protocol to get sectors content into memory and your own FS reading code for parsing it and extracting your files. how to obtain the device handle for this case? during installation of the OS, you know, where it goes. so, you get the Device Path for your Boot Volume and put it for example in the FilePathList[1] of the Load Option descriptor for this Load Option. then, having the device path for your Boot Volume, you can open block I/O protocol on it, first getting the handle through the LocateDevicePath() call and then OpenProtocol() on that handle.
Code:
/* Opening Simple FS Protocol on DeviceHandle from the above to obtain file access on the Home Volume - for logo extracting e.g. */
Status = pbs->OpenProtocol(
gpLoadedImageProtocol->DeviceHandle,
&gEfiSimpleFileSystemGuid,
&gpSfspHomeDrive,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if(Status != EFI_SUCCESS){
return ErrorExit(Status, L"ERROR: OpenProtocol() unsuccess on SIMPLE_FILE_SYSTEM_PROTOCOL for OSL home volume, status: ");
}
2) Now, you open the Volume for further file operations:
Code:
/* Opening the Home Volume on the Home Drive - Root Directory */
Status = gpSfspHomeDrive->OpenVolume(gpSfspHomeDrive, &gpEfiDirHvRoot);
if(Status != EFI_SUCCESS){
return ErrorExit(Status, L"ERROR:OPENMEDIA:HOMEVOLUME:STATUS: ");
}
3) Now, when you want to get some file, and this example extracts a logo, you do this, using
gpEfiDirHvRoot pointer:
Code:
/* Opening the Logo .bmp file */
AAA: Status = gpEfiDirHvRoot->Open(
gpEfiDirHvRoot,
&pEfiFileLogo,
L"efi\\rizxt\\res\\LOGO.BMP",
EFI_FILE_MODE_READ,
0
);
if(Status == EFI_SUCCESS){
goto BBB;
}else if(Status == EFI_MEDIA_CHANGED){ /* trying to reopen HV */
Status = gpSfspHomeDrive->OpenVolume(gpSfspHomeDrive, &gpEfiDirHvRoot);
if(Status != EFI_SUCCESS){
return NULL;
}else{
goto AAA;
}
}else{
return NULL;
}
BBB:
Notice, the retry, because since you last opened the volume, it may have "changed", you may need to reopen it, thus the retry.
All this was done by just reading through the specifuication, so don't deem it "unhelpful", it's pretty helpful.