117dfbc1cSKonstantin Belousov /*-
251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni *
417dfbc1cSKonstantin Belousov * Copyright (c) 2009 Konstantin Belousov
517dfbc1cSKonstantin Belousov * All rights reserved.
617dfbc1cSKonstantin Belousov *
717dfbc1cSKonstantin Belousov * Redistribution and use in source and binary forms, with or without
817dfbc1cSKonstantin Belousov * modification, are permitted provided that the following conditions
917dfbc1cSKonstantin Belousov * are met:
1017dfbc1cSKonstantin Belousov * 1. Redistributions of source code must retain the above copyright
1117dfbc1cSKonstantin Belousov * notice, this list of conditions and the following disclaimer.
1217dfbc1cSKonstantin Belousov * 2. Redistributions in binary form must reproduce the above copyright
1317dfbc1cSKonstantin Belousov * notice, this list of conditions and the following disclaimer in the
1417dfbc1cSKonstantin Belousov * documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors
1617dfbc1cSKonstantin Belousov * may be used to endorse or promote products derived from this software
1717dfbc1cSKonstantin Belousov * without specific prior written permission.
1817dfbc1cSKonstantin Belousov *
1917dfbc1cSKonstantin Belousov * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2017dfbc1cSKonstantin Belousov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2117dfbc1cSKonstantin Belousov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2217dfbc1cSKonstantin Belousov * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2317dfbc1cSKonstantin Belousov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2417dfbc1cSKonstantin Belousov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2517dfbc1cSKonstantin Belousov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2617dfbc1cSKonstantin Belousov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2717dfbc1cSKonstantin Belousov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2817dfbc1cSKonstantin Belousov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2917dfbc1cSKonstantin Belousov * SUCH DAMAGE.
3017dfbc1cSKonstantin Belousov */
3117dfbc1cSKonstantin Belousov
3217dfbc1cSKonstantin Belousov #include <sys/param.h>
3317dfbc1cSKonstantin Belousov #include <sys/proc.h>
3417dfbc1cSKonstantin Belousov #include <sys/sbuf.h>
3517dfbc1cSKonstantin Belousov #include <sys/uio.h>
3617dfbc1cSKonstantin Belousov
3717dfbc1cSKonstantin Belousov #include <fs/pseudofs/pseudofs.h>
3817dfbc1cSKonstantin Belousov #include <fs/procfs/procfs.h>
3917dfbc1cSKonstantin Belousov
4017dfbc1cSKonstantin Belousov int
procfs_doosrel(PFS_FILL_ARGS)4117dfbc1cSKonstantin Belousov procfs_doosrel(PFS_FILL_ARGS)
4217dfbc1cSKonstantin Belousov {
4317dfbc1cSKonstantin Belousov const char *pp;
4417dfbc1cSKonstantin Belousov int ov, osrel, i;
4517dfbc1cSKonstantin Belousov
4617dfbc1cSKonstantin Belousov if (uio == NULL)
4717dfbc1cSKonstantin Belousov return (EOPNOTSUPP);
48*473c90acSJohn Baldwin switch (uio->uio_rw) {
49*473c90acSJohn Baldwin case UIO_READ:
5017dfbc1cSKonstantin Belousov sbuf_printf(sb, "%d\n", p->p_osrel);
51*473c90acSJohn Baldwin break;
52*473c90acSJohn Baldwin case UIO_WRITE:
5317dfbc1cSKonstantin Belousov sbuf_trim(sb);
5417dfbc1cSKonstantin Belousov sbuf_finish(sb);
5517dfbc1cSKonstantin Belousov pp = sbuf_data(sb);
5617dfbc1cSKonstantin Belousov osrel = 0;
5717dfbc1cSKonstantin Belousov i = sbuf_len(sb);
5817dfbc1cSKonstantin Belousov while (i--) {
5917dfbc1cSKonstantin Belousov if (*pp < '0' || *pp > '9')
6017dfbc1cSKonstantin Belousov return (EINVAL);
6117dfbc1cSKonstantin Belousov ov = osrel * 10 + *pp++ - '0';
6217dfbc1cSKonstantin Belousov if (ov < osrel)
6317dfbc1cSKonstantin Belousov return (EINVAL);
6417dfbc1cSKonstantin Belousov osrel = ov;
6517dfbc1cSKonstantin Belousov }
6617dfbc1cSKonstantin Belousov p->p_osrel = osrel;
67*473c90acSJohn Baldwin break;
6817dfbc1cSKonstantin Belousov }
6917dfbc1cSKonstantin Belousov return (0);
7017dfbc1cSKonstantin Belousov }
71