[haiku-development] Re: publish_vnode / get_vnode

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 07 Jun 2009 13:47:26 +0200

On 2009-06-07 at 14:22:24 [+0200], Brecht Machiels <brecht@xxxxxxxxxxx> wrote:
> 
> I'm having some trouble understanding how Haiku's file system module
> works. Bear with me, I have never written a FS before.
> 
> I'm currently in the following situation. I can mount my filesystem (I
> publish the root node). When directory contents of this root node are
> being listed (using ls for example), I return the device id, name and
> vnode id for each entry in the read_dir hook (one entry per call). Now,
> after reading the first entry, close_dir is called for some reason. I
> think this has something to do with the vfs module trying to access the
> entry's node. Indeed, publishing the this node by means of publish_vnode
> results in read_dir being called as many times as there are entries in
> the directory.
> 
> However, from my understanding of the documentation, I do not believe
> publish_vnode should be called in this case (just reading a directory).
> This seems to be confirmed here:
> //www.freelists.org/post/haiku-development/Filesystem-API-documentation,4
> I would think that the vfs layer should call my get_vnode() in this
> case. Is this correct? My debug output however does not indicate that
> this hook is being called.

The get_vnode() hook is actually not triggered by POSIX API that often (or at 
all?). It is called mostly only when your file system requests it -- i.e. you 
call the VFS's get_vnode() function -- or when via the Be API node_refs or 
entry_refs are resolved.

The more likely hook to be called during directory iteration is lookup(), which 
resolves the entry in directory to a node. On success it does indeed have to 
return a new vnode reference, i.e. call the get_vnode() function.

> Ingo told me to enable debug for the userlandfs module. I added the
> following to my UserBuildConfig:
> SetConfigVar DEBUG : HAIKU_TOP src add-ons kernel file_systems
> userlandfs : 1 : global ;
> I only seem to get critical warnings in he syslog however. What did I miss?

What kind of critical warnings?

> I have tried to find some answers in the available documentation:
> * the Haiku Book
> * Practical File System Design by D. Giampaolo
> * the POSIX specifications on opengroup.org
> 
> Could the Haiku Book documentation be brought up to date to reflect the
> recent changes in the fs API?

Though not as complete as it could be, it is up to date. The generated Haiku 
Book on factory.haiku-os.org seems to be an old version, though. Just build a 
fresh one from the sources. The FS documentation lives in 
docs/user/drivers/fs_{modules,interface}.dox.

> I also dug in the sources for bfs and some others, but these are still a
> bit too complicated for me to find my way in.

For a less complex and completely virtual FS you can have a look at the rootfs 
sources in src/system/kernel/fs/rootfs.cpp.

CU, Ingo

Other related posts: