On Fri, May 30, 2014 at 10:42 PM, M Farkas-Dyck <strake...@gmail.com> wrote:

> Ls seems to stat the directory and allocate a large enough dent
> buffer. I couldn't find what ls calls to do so, but I assume that it's
> a common function and other programs use it too.


opendir() and readdir() are the functions you're looking for.  They're the
ones that open a directory and call getdents() to read the entries from it.
 They're both standardized and used *everywhere* for reading directories,
so if you want this file system to work at all, it must work for those
functions.  Note that getdents() is used by some ports, so it must work
correctly too; you can't just hack around problems by changing readdir().

ls invokes those via fts_open() and related functions.  It's used by
basically all BSD programs that might need to traverse a directory tree.



> Problem is that
> directories in 9p customarily have length 0, so ls says every such
> directory empty.

Getdents itself works.
>

It returns dirent structures, as defined in <sys/dirent.h>, with non-zero
d_fileno, with d_off values that are seek offsets to the succeeding entry
in the directory, with d_reclen of the padded and 8-byte aligned size of
the directory entry, with d_type of either DT_UNKNOWN or the appropriate
DT_* value, with d_name of the desired NUL-terminated name, and with
d_namlen the length of the name?



> 3 options immediately come to mind:
> 1. Modify said function to not care how long stat says the directory
> is, choose an arbitrary dent buffer size, and iterate if need be

2. Read full directory on every stat call, blah

3. Lie that every directory length is (off_t)(-1) and hope that
> programs know to not try to allocate so much...
>

opendir/readdir don't look at the st_size member, so I don't think any of
those will help.  You haven't found the real problem yet.


Philip Guenther

Reply via email to