45 lines
953 B
C
45 lines
953 B
C
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/sched.h>
|
|
#include <linux/nsproxy.h>
|
|
#include <linux/mount.h>
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("create /proc/mymounts file that lists mounts");
|
|
|
|
struct proc_dir_entry *proc_file;
|
|
|
|
int list_mounts(struct seq_file *m, void *v);
|
|
|
|
static int list_mounts_open(struct inode *inode, struct file *file)
|
|
{
|
|
return single_open(file, list_mounts, NULL);
|
|
}
|
|
|
|
static const struct proc_ops proc_fops = {
|
|
.proc_open = list_mounts_open,
|
|
.proc_read = seq_read,
|
|
.proc_lseek = seq_lseek,
|
|
.proc_release = single_release,
|
|
};
|
|
|
|
static int __init mounts_init(void)
|
|
{
|
|
proc_file = proc_create("mymounts", 0444, 0, &proc_fops);
|
|
if(IS_ERR(proc_file)) return PTR_ERR(proc_file);
|
|
return 0;
|
|
}
|
|
|
|
static void __exit mounts_exit(void)
|
|
{
|
|
proc_remove(proc_file);
|
|
}
|
|
|
|
module_init(mounts_init);
|
|
module_exit(mounts_exit);
|
|
|