Exemplo n.º 1
0
/*
 * Print information about disks
 */
static void
efifs_dev_print(int verbose)
{
	union {
		EFI_FILE_SYSTEM_INFO info;
		char buffer[1024];
	} fi;
	char line[80];
	EFI_FILE_IO_INTERFACE *fsif;
	EFI_FILE *volume;
	EFI_HANDLE h;
	EFI_STATUS status;
	UINTN sz;
	int i, unit;

	for (unit = 0, h = efi_find_handle(&efifs_dev, 0);
	    h != NULL; h = efi_find_handle(&efifs_dev, ++unit)) {
		sprintf(line, "    %s%d: ", efifs_dev.dv_name, unit);
		pager_output(line);

		status = BS->HandleProtocol(h, &sfs_guid, (VOID **)&fsif);
		if (EFI_ERROR(status))
			goto err;

		status = fsif->OpenVolume(fsif, &volume);
		if (EFI_ERROR(status))
			goto err;

		sz = sizeof(fi);
		status = volume->GetInfo(volume, &fs_guid, &sz, &fi);
		volume->Close(volume);
		if (EFI_ERROR(status))
			goto err;

		if (fi.info.ReadOnly)
			pager_output("[RO] ");
		else
			pager_output("     ");
		for (i = 0; fi.info.VolumeLabel[i] != 0; i++)
			fi.buffer[i] = fi.info.VolumeLabel[i];
		fi.buffer[i] = 0;
		if (fi.buffer[0] != 0)
			pager_output(fi.buffer);
		else
			pager_output("EFI filesystem");
		pager_output("\n");
		continue;

	err:
		sprintf(line, "[--] error %d: unable to obtain information\n",
		    efi_status_to_errno(status));
		pager_output(line);
	}
}
Exemplo n.º 2
0
static int
efifs_close(struct open_file *f)
{
	EFI_FILE *file = f->f_fsdata;

	if (file == NULL)
		return (EBADF);

	file->Close(file);
	f->f_fsdata = NULL;
	return (0);
}
Exemplo n.º 3
0
EFI_STATUS
EFIAPI
EBounceMain (IN EFI_HANDLE           ImageHandle,
             IN EFI_SYSTEM_TABLE     *SystemTable)
{
    EFI_STATUS              Status;
    EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
    EFI_CONSOLE_CONTROL_SCREEN_MODE currentMode;
    EFI_LOADED_IMAGE        *SelfLoadedImage;
    EFI_FILE                *RootDir;
    EFI_FILE                *BootFile;
    EFI_DEVICE_PATH         *DevicePath;
    CHAR16                  *DevicePathAsString;
    CHAR16                  DirName[256];
    CHAR16                  FileName[256];
    UINTN                   i, FileNameIndex;
    EFI_HANDLE              LoaderHandle;
    
    InitializeLib(ImageHandle, SystemTable);
    
    // switch to text mode
    if (BS->LocateProtocol(&gEfiConsoleControlProtocolGuid, NULL, &ConsoleControl) == EFI_SUCCESS) {
        ConsoleControl->GetMode(ConsoleControl, &currentMode, NULL, NULL);
        if (currentMode == EfiConsoleControlScreenGraphics)
            ConsoleControl->SetMode(ConsoleControl, EfiConsoleControlScreenText);
    }
    
    /// load elilo.efi or e.efi from the same directory
    
    // get loaded image protocol for ourselves
    if (BS->HandleProtocol(ImageHandle, &LoadedImageProtocol, (VOID*)&SelfLoadedImage) != EFI_SUCCESS) {
        Print(L"Can not retrieve a LoadedImageProtocol handle for ImageHandle\n");
        return EFI_NOT_FOUND;
    }
    
    // open volume
    RootDir = LibOpenRoot(SelfLoadedImage->DeviceHandle);
    if (RootDir == NULL) {
        Print(L"Can't open volume.\n");
        return EFI_NOT_FOUND;
    }
    
    // find the current directory
    DevicePathAsString = DevicePathToStr(SelfLoadedImage->FilePath);
    if (DevicePathAsString != NULL) {
        StrCpy(DirName, DevicePathAsString);
        FreePool(DevicePathAsString);
        for (i = StrLen(DirName) - 1; i > 0 && DirName[i] != '\\'; i--) ;
        DirName[i++] = '\\';
        DirName[i] = 0;
    } else {
        StrCpy(DirName, L"\\");
    }
    
    for (FileNameIndex = 0; FileNames[FileNameIndex]; FileNameIndex++) {
        // build full absolute path name
        StrCpy(FileName, DirName);
        StrCat(FileName, FileNames[FileNameIndex]);
        
        // check for presence of the file
        if (RootDir->Open(RootDir, &BootFile, FileName, EFI_FILE_MODE_READ, 0) != EFI_SUCCESS)
            continue;
        BootFile->Close(BootFile);
        
        // make a full device path for the image file
        DevicePath = FileDevicePath(SelfLoadedImage->DeviceHandle, FileName);
        
        // load the image into memory
        Status = BS->LoadImage(FALSE, ImageHandle, DevicePath, NULL, 0, &LoaderHandle);
        FreePool(DevicePath);
        if (EFI_ERROR(Status)) {
            Print(L"Can not load the file %s\n", FileName);
            return Status;
        }
        
        // start it!
        BS->StartImage(LoaderHandle, NULL, NULL);
        // just in case we get control back...
        break;
    }
    
    return EFI_SUCCESS;
}