+static ssize_t helloc_write(struct file *filp, const char __user *buf,
+ size_t len, loff_t *pos)
+{
+ int r;
+ struct message *msg = filp->private_data;
+ /* do not read pass through the size of the message */
+ if (*pos >= msg->len)
+ /* return end of file */
+ return 0;
+ /* if len is bigger than the rest of the message, clamp it */
+ if (len > msg->len - *pos)
+ len = msg->len - *pos;
+ /* copy message to user space and return error if it fails */
+ r = copy_from_user(msg->text + *pos, buf, len);
+ if (r)
+ return -EFAULT;
+ /* update the file position */
+ *pos += len;
+ return len;
+}
+