[openbeos] Re: Tracker icons - ReadDir for Attributes

Axel Dörfler wrote on Sat, 23 Jul 2005 14:06:00 +0200 CEST:
> It is that slow. Sure the attributes in the small_data section are in 
> the cache at the time the inode has been read in - but you need an 
> extra kernel call for each lookup, which is costly as well.

Reminds me of my desire to do a replacement for ReadDir which lets you
specify the names of attributes you want to get listed too, not just
file name and file type.  This is also good for getting a list of files
back from a query, not just a directory.

In case you don't know, ReadDir for multiple entries returns a packed
list of variable length records (only as much space as needed for the
file name is used) that look like this:

struct dirent
{
  __uint32_t d_fileno;   /* file number of entry */
  __uint16_t d_reclen;   /* length of this record */
  __uint8_t  d_type;     /* file type, see below */
  __uint8_t  d_namlen;   /* length of string in d_name */
  char       d_name[0];  /* file name, variable length field */
};

You just give ReadDir a buffer and it fills in as many records as it
can fit into it.  Calling ReadDir again gets you the next batch.  Using
the length you can advance from one record to the next in the buffer.

If you had ReadDirPlus working, it would copy the attributes you want
into the record, avoiding the need to open files and examine attributes
individually (though internally it has to open the inode of each file
and maybe read in large external attribute areas).  When traversing a
query, attributes that are part of the index being traversed can
sometimes be added without even that inode read, like the filename is
for Unix style directories (which if you think about it, a directory
is an index for file names).  In any case, it would be ideal for bulk
reading of icons when drawing a directory window with thousands of files.

- Alex

Other related posts: