This answer shows us how the current working directory in kernel code. I tried to implement this in my module but without success, I really need someone to share with me a full program with the answer above. Because I really don't know how to use the answer above and how implement it.
I tried the following:
which struct do I need to use in the get_fs_pwd function, and what is the pwd argument? The answer didn't provide an example of how to really get the cwd.
#include <linux/init.h> #include <linux/module.h> #include <linux/fs_struct.h> MODULE_LICENSE("GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello, World\n"); get_fs_pwd(); // which struct do I need to use, and what is the pwd argument? return 0; } static void hello_exit(void) { printk(KERN_ALERT "Goodbye, cruel world.\n"); } module_init(hello_init); module_exit(hello_exit); static inline void get_fs_pwd(struct fs_struct *fs, struct path *pwd) { spin_lock(&fs->lock); *pwd = fs->pwd; path_get(pwd); spin_unlock(&fs->lock); }
pwdcommand.insmoded?