[Mono-devel-list] System.IO.FileStream behaves strangely on large files.

alfius alfius at freemail.gr
Thu Jul 1 07:41:41 EDT 2004


Hello,
I have observed some strange behaviour while using a FileStream to
access large files (>4GB).

For example I have a large file 'bigfile':
-rw-r--r--    1 alf      users    4898967552 Jul  1 00:44 bigfile

When I run the following program:

---Code start------------------------------------

using System.IO;
using System;

class btest {

    public static void Main() 
    {
	FileStream fs=new FileStream("bigfile", FileMode.Open,
FileAccess.Read);
	
	Console.WriteLine("Offset 1: {0:x}", fs.Seek(0x1000000,
SeekOrigin.Begin));
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	Console.WriteLine("Offset 2: {0:x}", fs.Seek(0x100,
SeekOrigin.Begin));	
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	Console.WriteLine("Offset 3: {0:x}", fs.Seek(0x7fffffff,
SeekOrigin.Begin));
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	Console.WriteLine("Offset 4: {0:x}", fs.Seek(0x80000000,
SeekOrigin.Begin));
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	Console.WriteLine("Offset 5: {0:x}", fs.Seek(0xf0000000,
SeekOrigin.Begin));	
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	Console.WriteLine("Offset 6: {0:x}", fs.Seek(0xfffffffe,
SeekOrigin.Begin));	
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	Console.WriteLine("Offset 7: {0:x}", fs.Seek(0x100000000,
SeekOrigin.Begin));	
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	Console.WriteLine("Offset 8: {0:x}", fs.Seek(0x1234555,
SeekOrigin.Begin));	
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	Console.WriteLine("Offset 9: {0:x}", fs.Seek(0x100000000,
SeekOrigin.Begin));	
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	
	string[] files=Directory.GetFiles(".","*.cs");
	
	Console.WriteLine("Offset 10: {0:x}", fs.Seek(0x1234555,
SeekOrigin.Begin));	
	Console.WriteLine("Value {0:x}", fs.ReadByte());
	Console.WriteLine("Offset 11: {0:x}", fs.Seek(0x100000000,
SeekOrigin.Begin));	
	Console.WriteLine("Value {0:x}", fs.ReadByte());

	Console.WriteLine("Offset 12: {0:x}", fs.Seek(0xf0000000,
SeekOrigin.Begin));	
	Console.WriteLine("Value {0:x}", fs.ReadByte());    
    }

}

---Code End------------------------------------------------

---Results Start-------------------------------------------
$ mcs btest.cs
Compilation succeeded
$ mono --debug btest.exe
Offset 1: 1000000
Value 11
Offset 2: 100
Value b4
Offset 3: 7fffffff
Value e0
Offset 4: 80000000
Value 10
Offset 5: ffffffff
Value ae
Offset 6: ffffffff
Value fd
Offset 7: 100000000
Value c0
Offset 8: 1234555
Value c4
Offset 9: 100000000
Value f5
Offset 10: 1234555
Value c4
Offset 11: 100000000
Value f5

Unhandled Exception: System.IO.IOException: Win32 IO returned
ERROR_NO_MORE_FILES. Path: bigfile
in [0x00111] (at /cvs/mcs/class/corlib/System.IO/FileStream.cs:707)
System.IO.FileStream:Seek (long,System.IO.SeekOrigin)
in <0x005f1> btest:Main ()
---Results End-------------------------------------------

First of all when trying to access offsets between 0x80000000-0xffffffff
I some time get that the offset is 0xffffffff. Also when trying to
access an offset above 0x80000000 twice (eg offset 7,11) the results I
get from ReadByte() are not always the same.

Directory.GetFiles() seems to have a strange effect. After calling it,
all access that would be "invalid" before calling it (return 0xffffffff)
throw an apparently irrelevant exception.

I am missing something or are these bugs?

Thanks,
Alexandros

PS I am using Beta 2, haven't been able to get 1.0




____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.



More information about the Mono-devel-list mailing list