VFS readdir

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Can anyone explain to me exactly how the VFS readdir function is
supposed to operate?  I'm talking about the readdir that an FS is
supposed to implement as part of its file_operations struct for
directories.

   int myfs_readdir(struct file* f, void* dirent, filldir_t filldir)

I understand that f is the directory I need to work with.  And I know I
need to find the children of f and use the function pointer filldir to
add the children to dirent.  

But what I do not understand is how readdir is called, how it is
supposed to operate, and what it is supposed to return.

I wrote myfs_readdir() (basing it off of the bfs readdir in
fs/bfs/dir.c) and I basically just make three hard coded calls to
filldir() for "." ".." and "test".  And I returned 0.

filldir(dirent, "test", 4, pos++, 4, DT_REG);
filldir(dirent, "..", 2, pos++, inoA, DT_DIR);
filldir(dirent, ".", 1, f->f_pos++, inoB, DT_DIR);
return 0;


And when I tested it by mounting my FS and issuing cmd 'ls /mnt/myfs' it
got stuck in an infinte loop of calling readdir() over and over and over
again!  I know this because I was printing a simple "myfs: readdir
called" message in the kernel log, and when I hit ctrl+C to kill ls, I
ran dmesg and the kernel log was filled with many copies of this
message.  I looked at someone else's sample code
(http://www.geocities.com/ravikiran_uvs/articles/rkfs-old.html) and it
returns 1 instead of 0 in some places.  This code seems to work! ???
The BFS readir NEVER returns 1?? I don't get it? :) 


Any help anyone could provide would be most appreciated.  There is no
real documentation on this stuff, at all.

Also, what is the offset argument to filldir used for?

-- 
Jason J. Herne <hernejj@xxxxxxxxxxxx>


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux