/* The write routine is generic, it fills in a preallocated rbuffer to supply the data.  */
static ssize_t proc_write(struct file *file, const char __user *buffer, size_t len, loff_t *offset)
/* The write routine is generic, it fills in a preallocated rbuffer to supply the data.  */
static ssize_t proc_write(struct file *file, const char __user *buffer, size_t len, loff_t *offset)
{
	loff_t pos = *offset;
	struct proc_data *priv = (struct proc_data*)file->private_data;
	if (!priv->wbuffer)
		return -EINVAL;
	if (pos < 0)
		return -EINVAL;
	if (pos >= priv->maxwritelen)
		return 0;
	if (len > priv->maxwritelen - pos)
		len = priv->maxwritelen - pos;
	if (copy_from_user(priv->wbuffer + pos, buffer, len))
		return -EFAULT;
	if ( pos + len > priv->writelen )
		priv->writelen = len + file->f_pos;
	*offset = pos + len;
	return len;
}