Skip to content

Commit

Permalink
Merge pull request #6 from d-grossman/master
Browse files Browse the repository at this point in the history
Added an example of using the proc filesystem (add more linux kernel programs #2)
  • Loading branch information
doomers authored Oct 17, 2017
2 parents 18088a0 + 745b2d8 commit 792cecb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
7 changes: 7 additions & 0 deletions procfs_hw/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
obj-m += procfs_hw.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
63 changes: 63 additions & 0 deletions procfs_hw/procfs_hw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>

#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>

#define procfs_msg "Hello World\n"
#define procfs_name "procfs_hw"
#define procfs_parent NULL
#define procfs_perms 0644

static struct proc_dir_entry *procfs_hw_file;

static int
procfs_hw_show (struct seq_file *m, void *v)
{
seq_printf (m, "%s\n", procfs_msg);

return 0;
}

static int
procfs_hw_open (struct inode *inode, struct file *file)
{
return single_open (file, procfs_hw_show, NULL);
}

static const struct file_operations procfs_hw_fops = {
.owner = THIS_MODULE,
.open = procfs_hw_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static int __init
procfs_hw_init (void)
{
procfs_hw_file =
proc_create (procfs_name, procfs_perms, procfs_parent, &procfs_hw_fops);

if (!procfs_hw_file)
{
return -ENOMEM;
}

return 0;
}

static void __exit
procfs_hw_exit (void)
{
remove_proc_entry ("procfs_hw", procfs_parent);
}

module_init (procfs_hw_init);
module_exit (procfs_hw_exit);

MODULE_LICENSE ("GPL");
MODULE_AUTHOR ("d-grossman");
MODULE_DESCRIPTION ("procfs hello world");

0 comments on commit 792cecb

Please sign in to comment.