[Haskell-beginners] please critique my first stab at systems programming

Sean Perry shaleh at speakeasy.net
Thu Apr 14 17:29:25 CEST 2011


On Apr 14, 2011, at 6:17 AM, Felipe Almeida Lessa wrote:

> On Thu, Apr 14, 2011 at 9:50 AM, Daniel Fischer
> <daniel.is.fischer at googlemail.com> wrote:
>> Well, I would have expected that, but
> [snip]
>> searches the entire block and checks whether the second component is empty
>> to see whether there's any match at all. So I thought that'd be the desired
>> behaviour.
> 
> Oops, you're right =).  I wonder what was OP's intended behaviour.
> 

Well, I started with B.findSubstring, but the compiler told me that was deprecated and break was the preferred replacement. Looking at the docs, findSubstring was shown to be the equivalent of the case statement which you see in my code.

I do not care how many times the pattern appears in a sector just whether or not it exists at all.

> 
> On Thu, Apr 14, 2011 at 7:14 AM, Sean Perry <shaleh at speakeasy.net> wrote:
>> The idea is to walk the disk looking for a signature, say NTFS or EXT.
>> Since we do not know where the block containing this identifier is, we
>> read the blocks in one at a time.
> 
> You may use an iteratee as well, which gives clean, efficient code
> that doesn't depend on IO (among other things).  Using the
> "enumerator" package [1], (and assuming that you just want to check
> the beginning of each block), you could write:
> 

Now that I am a little more awake, let me state my requirements more clearly to ensure this works as I expect.

I am hunting through the raw sectors of the disk looking for a sector with a specific pattern. "PART" is just a standin for the real thing. Since disks are obviously bigger than a meg or two I need to worry about space usage. Time performance is important but not as important as not reading all 256G of a disk into memory (-:

I need to output the sector number when found. This is why I started with the very simple sector by sector search instead of larger chunk based one. In my experience the OS tends to read in 4k multiples even when you just ask for 512 so there is a buffer somewhere helping with performance.

I like your approach Felipe. Thanks. Definitely not something that would have been obvious from reading the library docs. I knew there was a better way hiding somewhere though. Had I been coding in Python or some other language I typically use I would have let Handle be the point of abstraction. Anything that looked like a File would work for me.

The definition of 'go' looks nice and elegant. What does 'the $!i here in 'go $! i+1' do?




More information about the Beginners mailing list