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. Problem is that directories in 9p customarily have length 0, so ls says every such directory empty. Getdents itself works.
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... Are any others? Which is the least evil?