[Haskell-beginners] given these types (HFuse), can I share state?

Antoine Latter aslatter at gmail.com
Wed Mar 28 16:58:38 CEST 2012


On Wed, Mar 28, 2012 at 9:32 AM, Jon Dowland
<jon+haskell-beginners at dowland.me> wrote:
> Hi,
>
> Firstly, this is my first post to this list, I consider myself a Haskell
> beginner but this question might be a bit esoteric so please let me know if I'm
> better directing this elsewhere.
>
> I'm writing a small fuse-based filesystem[1] using hfuse[2].  I get to write
> functions to a defined type.  One of these is 'open', for when the user opens a
> file; another is 'read', for when a user invokes the read syscall. Here are the
> type signatures:
>
>  fuseOpen :: FilePath -> OpenMode -> OpenFileFlags -> IO (Either Errno fh)
>
>  fuseRead :: FilePath -> fh -> ByteCount -> FileOffset -> IO (Either Errno ByteString)
>
> In the case of my filesystem, for a typical work pattern of open, read, read, read…;
> there's an amount of setup that is required up front (possibly combining two or more
> files via patches; uncompressing files, etc.) which can be quite expensive.
>
> With my current implementation, I am having to do this work in the read function[3],
> because I can't figure out a way of doing it in the open function and sharing the
> state with subsequent reads.  I think this is likely to be a performance issue and
> I'd prefer to have it done once, in the open function.
>

I've never used hfuse, but can't you put the state you need in the
'fh' type you pass back from 'fuseOpen'? In your case it is the 'HT'
type.

I'm imagining something like:

> data HT = HT (IORef HandleState)

Antoine



More information about the Beginners mailing list