Article 4YK2P Path lookup in linux kernel 4.15

Path lookup in linux kernel 4.15

by
donky1989
from LinuxQuestions.org on (#4YK2P)
Hi, this is my first thread, so I'll take this opportunity to say hello.
I'm trying to write a simple kernel module, just for didactic purpose. In particular, what is giving me headaches is the path lookup. I'd like to have a sysfs entry and in the store operation I want to receive a buffer and I want to save it only if it's a valid path. So I tried to use the vfs_path_lookup Exported Symbols from here namei.c. But even inserting a valid path, it prints me the ENOENT error.

This is my code:

Into the header:

Code:extern int vfs_path_lookup(struct dentry *, struct vfsmount *, const char *, unsigned int, struct path *path);Code:ssize_t path_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count){

int err = vfs_path_lookup(current->fs->root.dentry, current->fs->root.mnt, buf, LOOKUP_DIRECTORY, base_path);
printk(KERN_DEBUG "%s\n", __FUNCTION__);
printk(KERN_DEBUG "Received: %s err is %d\n", buf, err);

strncpy(base_addr, buf, MAX_FILENAME_SIZE);
printk(KERN_DEBUG "Base Addr: %s\n", base_addr);
return strlen(base_addr);
}What I tried to write into the file is the string "/home/osboxes/Documents" that is an existing directory. I suspect that I didn't get the real usage of the function, maybe something with flags. Thank you in advance for your help.latest?d=yIl2AUoC8zA latest?i=7pxh14TuqwQ:fR-V-irZnKI:F7zBnMy latest?i=7pxh14TuqwQ:fR-V-irZnKI:V_sGLiP latest?d=qj6IDK7rITs latest?i=7pxh14TuqwQ:fR-V-irZnKI:gIN9vFw7pxh14TuqwQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments