Traversing/Counting contents of /proc/[pid]/fd directories
I have a rather straightforward challenge and I need a little help. Let me preface that I am not a very experienced kernel module developer, but I have read through some of the basic tutorials and examples. I also have a fair amount of C/C++ experience, so I am not a complete novice in those regards.
The challenge is to count the contents of each /proc/[pid]/fd directory from a kernel module. Basically, counting the number of open file descriptors for each process. Now, I can get each pid using the following segment:
From that, I can construct the absolute pathname /proc/[pid]/fd for each process, and use the path_loookup() method to begin further analysis of the directory. After that, I am struggling on how to traverse/count the contents of the /fd directories. I can get the struct dentry object for the directory using struct dentry *lookup_create(), but I don't have a good enough understanding of using the struct dentry or struct inode types to proceed after that.
struct task_struct *task;
Any suggestions on how to properly proceed or recommendations on how I can accomplish this task. I know there are easy ways to do this from user space; however, that option is not available. The challenge is to do it from kernel space.
I am developing this for kernel distro 2.6.31-14-generic on Ubuntu 9.10 Karmic Koala.
Thank you for any help.