On 07/29/14 20:18, lowell_den...@dell.com wrote:
> Every copy of EFI Shell V2.0 that I have found seems to have a file
> processing bug.
> 
>  
> 
> It looks like appending to a file does not work as expected.  The
> following shell snippet does not work:
> 
>  
> 
>                 del test.dat
> 
>                 echo 1234 >> test.dat                    # This works
> 
>                 echo 5678 >> test.dat                    # This give
> “Error. Unable to redirect file”
> 
>  
> 
> If I modify that shell snippet as follows it works:
> 
>  
> 
>                 del test.dat
> 
>                 echo 1234 > test.dat
> 
>                 echo 5678 >> test.dat
> 
>  
> 
> Additionally appending as ASCII also works:
> 
>  
> 
>                 del test.dat
> 
>                 echo 1234 >>a  test.dat
> 
>                 echo 5678 >>a  test.dat
> 
>  
> 
> This error carries over to programming interfaces.  If I try to open an
> existing file for append in Python I get an error”
> 
>  
> 
> f = open(‘ExistingFile’, ‘a’)
> 
> # ERROR
> 
>  
> 
> However, if I open the file in mode ‘r+’ there is no error:
> 
>  
> 
> f = open(‘ExistingFile’, ‘r+’)
> 
> f.seek(0,2)
> 
>  
> 
> What is going on here?

This is intended behavior. (I'm not saying it is correct, but it is intended.)

Refer to UpdateStdInStdOutStdErr() in 
"ShellPkg/Application/Shell/ShellParametersProtocol.c". Specifically, this 
check:

      //
      // Check that filetypes (Unicode/Ascii) do not change during an append
      //

...

      ||(StdOutFileName != NULL && OutUnicode && OutAppend && 
(!EFI_ERROR(ShellFileExists(StdOutFileName)) && 
EFI_ERROR(IsUnicodeFile(StdOutFileName))))

...

      Status = EFI_INVALID_PARAMETER;

With >> you are requesting stdout redirection (StdOutFileName != NULL), unicode 
(OutUnicode), append mode (OutAppend). The file you're redirecting to already 
exists (!EFI_ERROR(ShellFileExists(StdOutFileName)), and it does *not* have a 
BOM (byte order mark) at the beginning, because previously you created the file 
with contents "1234", which does not contain a BOM.

Therefore the IsUnicodeFile() function 
[ShellPkg/Application/Shell/ShellParametersProtocol.c], which checks for the 
BOM ("gUnicodeFileTag", EFI_UNICODE_BYTE_ORDER_MARK) fails, and you get 
EFI_INVALID_PARAMETER.

Hence the bug is not in the "append check" for the second >> redirection. The 
bug is in the first >> redirection, because it doesn't place the BOM at the 
beginning of the new file. (According to your testing, the first > redirection 
*does* create the BOM.) I'm posting a patchset soon, please test it.

Thanks,
Laszlo


------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to