Re: VFS readdir

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

 



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

readdir function which is implemented as a part of the file_operation
structure which
is supposed to return the next directory entry in a dirent and filldir is
used to extract the
fields in the directory entry.

readdir function is called when we are trying to get the dentry at that
point if the following directory is not dead we call
readdir function
res = file->f_op->readdir(file, buf, filler);
from this point it will call internally its  readdir function which is
defined by a particular filesystem like yours
myfs_readdir( ) which has been initialized by you in your base file.
this function will return 1 on success .in devfs file system, declare one
variable and assign it to 0
when filldir is called and if it successfully works it returns 0 and after
that we increment the offset
value and then increment this new variable which comes out to be 1 on
success.

>>>>>>>>>>> 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;
>>Also, what is the offset argument to filldir used for?

as far as filldir function is concerned the offset argument passed here is
the offset value of the file descriptor.
Don't increment the offset value while calling the filldir after returning
from the function and checking whether the filldir returns successfully
increment the offset value. make this change and see.....
because if you increment it while passing it will affect further in the
definition as it is used there also.
moreover put these filldir statements in a switch case.

i hope this will help you out.

regards
lk
----- Original Message ----- 
From: "Jason J. Herne" <hernejj@xxxxxxxxxxxx>
To: <kernelnewbies@xxxxxxxxxxxx>
Sent: Sunday, May 08, 2005 4:16 PM
Subject: VFS readdir


> 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/



--
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