[Mono-list] FileStream weirdness

Dan Lewis dihlewis@yahoo.co.uk
Mon, 11 Mar 2002 16:28:51 +0000 (GMT)


--0-79791208-1015864131=:57944
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Content-Disposition: inline

Hi all,

I added buffering to the System.IO.FileStream class, and I'm trying write some
decent tests for it at the moment. The program below creates a 64k random data
file, then uses FileStream to read it. It throws a load of random seeks and
contiguous/discontiguous reads at the stream.

When you run it using the Microsoft VM, it will first create a data file called
test.dat. Here's portion of an od dump from that file:

  od -Ax -tx1 test.dat

  009110 2d e0 24 a5 71 01 99 c4 1d f1 66 8a dd d8 f1 1d
  009120 e9 46 67 20 79 98 72 e8 ec 11 63 e1 4d 91 b3 d2

In particular note that starting at 0x9115, we have 01 99 c4 ...

If you run the program, it will seek to that address and dump 100 bytes:

  fstest.exe

  Seeking to 0x9115
  Position is now 9115
  Read 100 bytes:
  01 99 c4 1d f1 66 8a ...

So far so good. Now try running with the --confuse option, which does some
random seeks and reads beforehand:

  fstest.exe --confuse

  Seeking to 0x9115
  Position is now 9115
  Read 100 bytes:
  0e a5 22 da 56 4d 86 ...

Not the answer I was expecting. I really need a second pair of eyes to look at
this program -- is it me or is this an MS library bug?

Thanks,
  Dan.


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
--0-79791208-1015864131=:57944
Content-Type: application/octet-stream; name="fstest.cs"
Content-Transfer-Encoding: base64
Content-Description: fstest.cs
Content-Disposition: attachment; filename="fstest.cs"

dXNpbmcgU3lzdGVtOw0KdXNpbmcgU3lzdGVtLklPOw0KDQpwdWJsaWMgY2xh
c3MgRmlsZVN0cmVhbVRlc3Qgew0KCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWlu
IChzdHJpbmcgW10gYXJncykgew0KCQlkYXRhID0gbmV3IGJ5dGUgWzY1NTM2
XTsNCgkJYnVmID0gbmV3IGJ5dGUgW2RhdGEuTGVuZ3RoXT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