I wrote a piece of code trying to print all the mount point in the system.But
the is a issue with this code, when install this module to kernel it premot
a "Segmentation fault“. [?]
>From my understanding the vfsmount->mnt_list should be a loop.
Anyone could help me on this issue?

I post my code here, hope someone could help me:
#include <linux/init.h>
#include <linux/module.h>
#include <asm/thread_info.h>
#include <linux/dcache.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/mount.h>
#include <linux/string.h>
#include <asm/current.h>

MODULE_LICENSE("Dual BSD/GPL");

int print_mntp_list(void);

static int __init hello_init(void) {
        printk(KERN_ALERT "Trying to print the mount point name list\n");
        print_mntp_list();
        return 0;
}

int print_mntp_list(void) {
        struct vfsmount *vfs_mount_p, *iterator;
        struct list_head * mnt_glist;

        iterator = vfs_mount_p = current -> fs -> root.mnt;

        do {
                printk(KERN_ALERT "Mount point name: %s\n",
iterator->mnt_mountpoint->d_na\
me.name);
                iterator = container_of( iterator -> mnt_list.next, struct
vfsmount, mnt_l\
ist );
        } while (strcmp(iterator->mnt_mountpoint->d_name.name,
vfs_mount_p->mnt_mountpoint\
->d_name.name) != 0 );

        return 0;
}

static void __exit hello_exit(void) {
        printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);



Any help will be more than appreciate,
Thanks,
Wang Yan

<<323.gif>>

Reply via email to