+ down(&hello_mtx);
+ 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;
+ down(&hello_mtx);
+ 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)
+{
+ int r;
+ down(&hello_mtx);
+ if (sz + *pos > MAXLEN)
+ sz = MAXLEN - *pos;
+ r = copy_from_user(hello->buffer + *pos, buf, sz);
+ if (r) {
+ up(&hello_mtx);
+ return -EFAULT;
+ }
+ *pos += sz;
+ if (hello->len < *pos)
+ hello->len = *pos;
+ up(&hello_mtx);
+ return sz;
+}
+
+static int hello_release(struct inode *ino, struct file *fp)
+{