+static char hello_message[] = "hello, world\n";
+static char goodbye_message[] = "goodbye, world\n";
+
+struct message {
+ char *text;
+ size_t len;
+};
+
+static int helloc_open(struct inode *ino, struct file *filp)
+{
+ struct message *msg;
+ printk(KERN_INFO "Opened file with minor %d\n", iminor(ino));
+ msg = kmalloc(sizeof(struct message), GFP_KERNEL);
+ if (!msg)
+ return -ENOMEM;
+ if (iminor(ino) == 0) {
+ msg->text = hello_message;
+ msg->len = sizeof(hello_message);
+ } else {
+ msg->text = goodbye_message;
+ msg->len = sizeof(goodbye_message);
+ }
+ filp->private_data = msg;
+ return 0;
+}
+
+static int helloc_release(struct inode *ino, struct file *filp)
+{
+ kfree(filp->private_data);
+ return 0;
+}