Esempio n. 1
0
static int
cmm_pages_handler(ctl_table *ctl, int write, struct file *filp,
		  void *buffer, size_t *lenp)
{
	char buf[16], *p;
	long pages;
	int len;

	if (!*lenp || (filp->f_pos && !write)) {
		*lenp = 0;
		return 0;
	}

	if (write) {
		len = *lenp;
		if (copy_from_user(buf, buffer,
				   len > sizeof(buf) ? sizeof(buf) : len))
			return -EFAULT;
		buf[sizeof(buf) - 1] = '\0';
		cmm_skip_blanks(buf, &p);
		pages = cmm_strtoul(p, &p);
		if (ctl == &cmm_table[0])
			cmm_set_pages(pages);
		else
			cmm_add_timed_pages(pages);
	} else {
		if (ctl == &cmm_table[0])
			pages = cmm_get_pages();
		else
			pages = cmm_get_timed_pages();
		len = sprintf(buf, "%ld\n", pages);
		if (len > *lenp)
			len = *lenp;
		if (copy_to_user(buffer, buf, len))
			return -EFAULT;
	}
	*lenp = len;
	filp->f_pos += len;
	return 0;
}
Esempio n. 2
0
static int
cmm_pages_handler(ctl_table *ctl, int write,
		  void __user *buffer, size_t *lenp, loff_t *ppos)
{
	char buf[16], *p;
	long nr;
	int len;

	if (!*lenp || (*ppos && !write)) {
		*lenp = 0;
		return 0;
	}

	if (write) {
		len = *lenp;
		if (copy_from_user(buf, buffer,
				   len > sizeof(buf) ? sizeof(buf) : len))
			return -EFAULT;
		buf[sizeof(buf) - 1] = '\0';
		cmm_skip_blanks(buf, &p);
		nr = simple_strtoul(p, &p, 0);
		if (ctl == &cmm_table[0])
			cmm_set_pages(nr);
		else
			cmm_add_timed_pages(nr);
	} else {
		if (ctl == &cmm_table[0])
			nr = cmm_get_pages();
		else
			nr = cmm_get_timed_pages();
		len = sprintf(buf, "%ld\n", nr);
		if (len > *lenp)
			len = *lenp;
		if (copy_to_user(buffer, buf, len))
			return -EFAULT;
	}
	*lenp = len;
	*ppos += len;
	return 0;
}