Deleted Added
full compact
kern_sysctl.c (217915) kern_sysctl.c (217916)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Karels at Berkeley Software Design, Inc.
7 *
8 * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD

--- 22 unchanged lines hidden (view full) ---

31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
36 */
37
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Karels at Berkeley Software Design, Inc.
7 *
8 * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD

--- 22 unchanged lines hidden (view full) ---

31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
36 */
37
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/sys/kern/kern_sysctl.c 217915 2011-01-26 22:48:09Z mdf $");
39__FBSDID("$FreeBSD: head/sys/kern/kern_sysctl.c 217916 2011-01-27 00:34:12Z mdf $");
40
41#include "opt_compat.h"
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/fail.h>
46#include <sys/systm.h>
47#include <sys/kernel.h>

--- 1538 unchanged lines hidden (view full) ---

1586 *retval = req.validlen;
1587 else
1588 *retval = req.oldidx;
1589 }
1590 return (error);
1591}
1592
1593/*
40
41#include "opt_compat.h"
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/fail.h>
46#include <sys/systm.h>
47#include <sys/kernel.h>

--- 1538 unchanged lines hidden (view full) ---

1586 *retval = req.validlen;
1587 else
1588 *retval = req.oldidx;
1589 }
1590 return (error);
1591}
1592
1593/*
1594 * Drain into a sysctl struct. The user buffer must be wired.
1594 * Drain into a sysctl struct. The user buffer should be wired if a page
1595 * fault would cause issue.
1595 */
1596static int
1597sbuf_sysctl_drain(void *arg, const char *data, int len)
1598{
1599 struct sysctl_req *req = arg;
1600 int error;
1601
1602 error = SYSCTL_OUT(req, data, len);
1603 KASSERT(error >= 0, ("Got unexpected negative value %d", error));
1604 return (error == 0 ? len : -error);
1605}
1606
1607struct sbuf *
1608sbuf_new_for_sysctl(struct sbuf *s, char *buf, int length,
1609 struct sysctl_req *req)
1610{
1611
1596 */
1597static int
1598sbuf_sysctl_drain(void *arg, const char *data, int len)
1599{
1600 struct sysctl_req *req = arg;
1601 int error;
1602
1603 error = SYSCTL_OUT(req, data, len);
1604 KASSERT(error >= 0, ("Got unexpected negative value %d", error));
1605 return (error == 0 ? len : -error);
1606}
1607
1608struct sbuf *
1609sbuf_new_for_sysctl(struct sbuf *s, char *buf, int length,
1610 struct sysctl_req *req)
1611{
1612
1612 /* Wire the user buffer, so we can write without blocking. */
1613 sysctl_wire_old_buffer(req, 0);
1614
1615 s = sbuf_new(s, buf, length, SBUF_FIXEDLEN);
1616 sbuf_set_drain(s, sbuf_sysctl_drain, req);
1617 return (s);
1618}
1613 s = sbuf_new(s, buf, length, SBUF_FIXEDLEN);
1614 sbuf_set_drain(s, sbuf_sysctl_drain, req);
1615 return (s);
1616}