On 08/28/14 08:39, Gabor Puha wrote: > All, > > I am developing an efi loader and having problem to write an allocated > mem or text to a file on efi partition. I can create and del but I am > not able to write a file. I have checked all doc but example with > declaration was not found. Please, help with an example(or correct my > one)...regards > Gab.. > > here my code:
Please post plaintext, not HTML; the code is near unreadable. But: > > > static CHAR16 *PATH = L"\\TEST\\test.txt > > EFI_STATUS SavePass(EFI_DEVICE_PATH **LoaderDevicePath2) > { > EFI_FILE_IO_INTERFACE *Device_unit; > > EFI_FILE_HANDLE efi_hand_root,pass_file; > > EFI_HANDLE* efi_hand_array; > > UINTN handler,i; > > EFI_STATUS ferr,err; > > > UINTN Size,wsize; > VOID *OsKernelBuffer = NULL; > *LoaderDevicePath2 = (EFI_DEVICE_PATH *)NULL; > > Size=0x00000012; > > BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); > > > wsize=sizeof(OsKernelBuffer); Not sure if this causes your problem, but "wsize" here is set to the size of a *pointer*, not to the size of the pointed-to buffer. Then, > > > err = > efi_hand_root->Open(efi_hand_root,&pass_file,PATH,EFI_FILE_MODE_WRITE | > EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ,0); //THIS IS OK. ITS CREATE > IS SUCCESS > > if(err == EFI_SUCCESS) > > { > > > > Print(L"[*] File Opened..\r\n"); > > > ferr=efi_hand_root->Write(efi_hand_root,wsize,OsKernelBuffer); > //IT returns with 8000000000002 means EFI_INVALID_PARAMETER You try to write out the number of bytes inside the pointer, from the buffer pointed-to by the pointer. That's not ideal. Worse, you're trying to write through "efi_hand_root", which is a handle to the root directory of the volume. (Well, I assume that anyway, because your code doesn't show how "efi_hand_root" is populated at all. But you said that the file was at least created, so I must assume "efi_hand_root" was valid.) Anyway, as I said, assuming "efi_hand_root" is valid: you just opened the new file under handle "pass_file". But here you don't use "pass_file" to write to the file, you're trying to write to it through the root directory's handle. Laszlo > > > Print(L"\nPress [ENTER] to continue...\n"); > Input(NULL,Keypass,10); > > Print(L"Write ERROR: %lX \r\n",ferr); > if(ferr == EFI_SUCCESS) > { > efi_hand_root->Flush(pass_file); > efi_hand_root->Close(pass_file); > > > Print(L"[*] Write Success...\r\n"); > } > > efi_hand_root->Close(pass_file); > > *LoaderDevicePath2 = FileDevicePath(efi_hand_array[i],PATH); > > > break; > > } > > > > break; > > } > > > } > > > > FreePool(OsKernelBuffer); > > return err; > } > > > > > ------------------------------------------------------------------------------ > Slashdot TV. > Video for Nerds. Stuff that matters. > http://tv.slashdot.org/ > > > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/edk2-devel > ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/ _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel