LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   some question about the __user_walk function declared in linux-2.4.20/fs/namei.c (https://www.linuxquestions.org/questions/linux-kernel-70/some-question-about-the-__user_walk-function-declared-in-linux-2-4-20-fs-namei-c-726704/)

ao.yuan.young 05-18-2009 02:35 AM

some question about the __user_walk function declared in linux-2.4.20/fs/namei.c
 
Can any one tell me that which function in kernel-2.6.27 replaces the function __user_walk defined kernel-2.4.20?

titan22 05-18-2009 10:59 AM

__user_walk() is split into user_path_at() (for no LOOKUP_PARENT) and user_path_parent() (for LOOKUP_PARENT)

ao.yuan.young 05-18-2009 09:20 PM

Thank you for your answer very much.

The codes I have in kernel-2.4.20 are:
...
error = 0;
error = __user_walk(filename, LOOKUP_FOLLOW, &nd);
if (error) return error;
...

so, if I want to implement the code block above in kernel-2.6.27, I should code like this:
...
error = 0;
error = user_path_at('dfd', 'name', LOOKUP_FOLLOW, 'path');
if (error) return error;
...

Sorry, I haven't been sure the value of argument "int dfd", "const char __user *name", and "struct path *path", so I use placeholder here.

Am I right? Will you introduce the use of user_path_at and user_path_parent here?

ao.yuan.young 05-19-2009 07:04 AM

Thanks, and more question
 
Quote:

Originally Posted by titan22 (Post 3544802)
__user_walk() is split into user_path_at() (for no LOOKUP_PARENT) and user_path_parent() (for LOOKUP_PARENT)

Thank you for your answer very much.

The codes I have in kernel-2.4.20 are:
...
error = 0;
error = __user_walk(filename, LOOKUP_FOLLOW, &nd);
if (error) return error;
...

so, if I want to implement the code block above in kernel-2.6.27, I should code like this:
...
error = 0;
error = user_path_at('dfd', 'name', LOOKUP_FOLLOW, 'path');
if (error) return error;
...

Sorry, I haven't been sure the value of argument "int dfd", "const char __user *name", and "struct path *path", so I use placeholder here.

Am I right? Will you introduce the use of user_path_at and user_path_parent here, for I have been looking for a long time by google, but I can't find any article which introduce the usage of the two funciton?

ao.yuan.young 05-19-2009 08:26 AM

maybe I shoud use path_lookup to replace __user_walk
 
The code of function __user_walk() in kernel-2.4.20 is follows:

int __user_walk(const char *name, unsigned flags, struct nameidata *nd)
{
char *tmp;
int err;

tmp = getname(name);
err = PTR_ERR(tmp);
if (!IS_ERR(tmp)) {
err = 0;
err = path_lookup(tmp, flags, nd);
putname(tmp);
}
return err;
}

As we can see, in the function, its main point is calling function path_lookup(), the only difference with calling path_lookup() directly is that, it calls function getname() to copy the argument name from user space into kernel space, and free the space allocated after calling, so I think perhaps I should should use the function path_lookup() to replace the function __user_walk(), just like this:
...
error = 0;
error = path_lookup(filename, LOOKUP_FOLLOW, &nd);
if (error) return error;
...

How do you think?

titan22 05-19-2009 08:52 PM

__user_walk() and user_path_xxx() take user space filename
path_lookup() and do_path_lookup() take kernel space filename

user_walk() cannot be replaced by path_lookup() which does not know how to handle user space address. You probably want to read through the new/old APIs and printk or debug to verify.

error = __user_walk(filename, LOOKUP_FOLLOW, &nd);
==>
error = user_path_at(AT_FDCWD, filename, LOOKUP_FOLLOW, &nd);


All times are GMT -5. The time now is 03:47 PM.