+#define MAXLEN 4000
+static dev_t devnum;
+static struct cdev *dev;
+static const char default_greeting[] = "Hello, World!\n";
+
+struct hello_buffer {
+ size_t len;
+ char buffer[0];
+};
+static struct hello_buffer *hello;
+static DECLARE_MUTEX(hello_mtx);
+
+static int hello_open(struct inode *ino, struct file *fp)
+{
+ if (down_interruptible(&hello_mtx))
+ return -ERESTARTSYS;
+ if (fp->f_flags & O_TRUNC) {
+ memset(hello->buffer, 0, MAXLEN);
+ hello->len = 0;
+ }
+ if (fp->f_flags & O_APPEND)
+ fp->f_pos = hello->len;
+ up(&hello_mtx);
+ return 0;
+}
+
+static ssize_t hello_read(struct file *fp, char __user *buf, size_t sz,
+ loff_t *pos)
+{
+ int r;
+ if (down_interruptible(&hello_mtx))
+ return -ERESTARTSYS;
+ if (sz + *pos > hello->len)
+ sz = hello->len - *pos;
+ r = copy_to_user(buf, hello->buffer + *pos, sz);
+ up(&hello_mtx);
+ if (r)
+ return -EFAULT;
+ *pos += sz;
+ return sz;
+}
+
+static ssize_t hello_write(struct file *fp, const char __user *buf, size_t sz,
+ loff_t *pos)