Yes, /proc/[pid] handling is diferent and your solution is perfect just for the other proc directories.<div><br></div><div>Informations under [pid] directories are about tasks (processes), and most of this information is represented by task_struct structure (defined in include/linux/sched.h).</div>
<div><br></div><div>I think one easy way to solve this problem is:</div><div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>In include/linux/sched.h file</div><div>1 - add a new element in task_struct structure.<br>
<div>struct task_struct {</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>int my_value;</div></div><div> .......</div></div><div><br></div><div>In fs/proc/base.c file</div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>
<meta http-equiv="content-type" content="text/html; charset=utf-8">1 - Create a new entry in static pid_entry tgid_base_stuff[] array.</div><div>e.g. <span class="Apple-tab-span" style="white-space:pre">        </span>ONE("MY_FILE", S_IRUSR, proc_pid_my_file),</div>
<div><br></div><div>2 - Create a callback function that will be invoked when the new proc entry is accessed (*task_struct is passed to this function).</div><div><div>static int proc_pid_my_file(struct seq_file *m, struct pid_namespace *ns,</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>struct pid *pid, struct task_struct *task)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>seq_printf(m, "%s %d\n", "here we go....", task->my_value);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>return 0;</div><div>}</div></div><div><br></div><div><br></div><div>Use the task_struct as usual:</div><div><div><span class="Apple-tab-span" style="white-space:pre">        </span>struct task_struct *task;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>task = pid_task(find_vpid(1), PIDTYPE_PID);</div></div><div><br></div><div><br></div><div>I don't know if it is the best solution, but it seems it worked.</div>
<div>If anyone know a more easy or correct solution please let me know.</div><div><br></div><div>Thanks again,</div><div>Mauro Romano Trajber</div><div><br><div class="gmail_quote">On Wed, Jan 12, 2011 at 7:41 AM, Rajat Sharma <span dir="ltr"><<a href="mailto:fs.rajat@gmail.com">fs.rajat@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">yes you are right, it gives NULL for <pid> directories under proc but<br>
I tried changing pid to something else, say /proc/sys and it works.<br>
Looks like handling of pid directories is entirely different. I didn't<br>
get time to explore on that, will have to dig more into this.<br>
<br>
Rajat<br>
<br>
On Wed, Jan 12, 2011 at 12:50 AM, Mauro Romano Trajber<br>
<div><div></div><div class="h5"><<a href="mailto:trajber@gmail.com">trajber@gmail.com</a>> wrote:<br>
> Following your recommendations parent->pde always returns NULL. You know why<br>
> ?<br>
> // code...<br>
> err = kern_path("/proc/1/", LOOKUP_FOLLOW, &path);<br>
> if (err) {<br>
> return err;<br>
> }<br>
> struct proc_inode *parent = PROC_I(path.dentry->d_inode);<br>
> struct proc_dir_entry *parent_dir = parent->pde;<br>
> if (parent_dir == NULL) {<br>
> printk("parent_dir is NULL\n");<br>
> } else {<br>
> create_proc_entry("SOMEFile", 0644, parent_dir);<br>
> }<br>
><br>
> Mauro!<br>
> On Tue, Jan 11, 2011 at 4:39 AM, Rajat Sharma <<a href="mailto:fs.rajat@gmail.com">fs.rajat@gmail.com</a>> wrote:<br>
>><br>
>> Try this:<br>
>> 1. do a path_lookup for parent proc dir e.g. /proc/1234 and get its inode.<br>
>> 2. get proc_inode structure for parent from vfs inode like this:<br>
>> sruct proc_inode *parent = PROC_I(inode).<br>
>> PROC_I is defined in proc_fs.h<br>
>> 3. get parent proc_dir_entry object:<br>
>> struct proc_dir_entry *parent_dir = parent->pde;<br>
>> 4. now you can call:<br>
>> create_proc_entry("SOME file", 0644, parent_dir);<br>
>> 5. or you can create a directory if you want:<br>
>> proc_mkdir("your dir", parent_dir);<br>
>><br>
>> hope this helps.<br>
>><br>
>> Rajat<br>
>><br>
>> On Tue, Jan 11, 2011 at 12:19 AM, Mauro Romano Trajber<br>
>> <<a href="mailto:trajber@gmail.com">trajber@gmail.com</a>> wrote:<br>
>> > I think I found:<br>
>> > static const struct pid_entry tgid_base_stuff[] at fs/proc/base.c has<br>
>> > all<br>
>> > /proc/[pid] entries.<br>
>> > But unfortunately it does not use create_proc_entry function, and I'm<br>
>> > trying<br>
>> > to create a new syscall that creates a new proc_entry for the caller<br>
>> > process.<br>
>> > Adding a new element in tgid_base_stuff[] makes the things more<br>
>> > complicated<br>
>> > than simply call a create_proc_entry function.<br>
>> > Is there another way to do it ?<br>
>> > Mauro Romano Trajber<br>
>> ><br>
>> > On Mon, Jan 10, 2011 at 3:18 PM, Mauro Romano Trajber<br>
>> > <<a href="mailto:trajber@gmail.com">trajber@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> How can I create a new proc entry under /proc/[pid] ?<br>
>> >> I using create_proc_entry("SOME_FILE", 0644, NULL /* here goes the pid<br>
>> >> proc entry */);<br>
>> >> Is there any way to get PID directory as a parent proc entry ? How ?<br>
>> >> Thanks,<br>
>> >> Mauro<br>
>> ><br>
>> > _______________________________________________<br>
>> > Kernelnewbies mailing list<br>
>> > <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
>> > <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br></div>