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.