Fixed some bugs for dirent files.
Add tests.