procfs_osrel.c revision 303975
115060Sdfuchs/*- 215060Sdfuchs * Copyright (c) 2009 Konstantin Belousov 315060Sdfuchs * All rights reserved. 415060Sdfuchs * 515060Sdfuchs * Redistribution and use in source and binary forms, with or without 615060Sdfuchs * modification, are permitted provided that the following conditions 715060Sdfuchs * are met: 815060Sdfuchs * 1. Redistributions of source code must retain the above copyright 915060Sdfuchs * notice, this list of conditions and the following disclaimer. 1015060Sdfuchs * 2. Redistributions in binary form must reproduce the above copyright 1115060Sdfuchs * notice, this list of conditions and the following disclaimer in the 1215060Sdfuchs * documentation and/or other materials provided with the distribution. 1315060Sdfuchs * 4. Neither the name of the University nor the names of its contributors 1415060Sdfuchs * may be used to endorse or promote products derived from this software 1515060Sdfuchs * without specific prior written permission. 1615060Sdfuchs * 1715060Sdfuchs * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1815060Sdfuchs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1915060Sdfuchs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2015060Sdfuchs * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2115060Sdfuchs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2215060Sdfuchs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2315060Sdfuchs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2415060Sdfuchs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2515060Sdfuchs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2615060Sdfuchs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2715060Sdfuchs * SUCH DAMAGE. 2815060Sdfuchs */ 2915060Sdfuchs 3015060Sdfuchs#include <sys/cdefs.h> 3115060Sdfuchs__FBSDID("$FreeBSD: releng/11.0/sys/fs/procfs/procfs_osrel.c 197428 2009-09-23 12:08:08Z kib $"); 3215060Sdfuchs 3315060Sdfuchs#include <sys/param.h> 3415060Sdfuchs#include <sys/proc.h> 3515060Sdfuchs#include <sys/sbuf.h> 3615060Sdfuchs#include <sys/uio.h> 3715060Sdfuchs 3815060Sdfuchs#include <fs/pseudofs/pseudofs.h> 3915060Sdfuchs#include <fs/procfs/procfs.h> 4015060Sdfuchs 4115060Sdfuchsint 4215060Sdfuchsprocfs_doosrel(PFS_FILL_ARGS) 4315060Sdfuchs{ 4415060Sdfuchs const char *pp; 4515060Sdfuchs int ov, osrel, i; 4615060Sdfuchs 4715060Sdfuchs if (uio == NULL) 4815060Sdfuchs return (EOPNOTSUPP); 4915060Sdfuchs if (uio->uio_rw == UIO_READ) { 5015060Sdfuchs sbuf_printf(sb, "%d\n", p->p_osrel); 5115060Sdfuchs } else { 5215060Sdfuchs sbuf_trim(sb); 5315060Sdfuchs sbuf_finish(sb); 5415060Sdfuchs pp = sbuf_data(sb); 5515060Sdfuchs osrel = 0; 5615060Sdfuchs i = sbuf_len(sb); 5715060Sdfuchs while (i--) { 5815060Sdfuchs if (*pp < '0' || *pp > '9') 5915060Sdfuchs return (EINVAL); 6015060Sdfuchs ov = osrel * 10 + *pp++ - '0'; 6115060Sdfuchs if (ov < osrel) 6215060Sdfuchs return (EINVAL); 6315060Sdfuchs osrel = ov; 6415060Sdfuchs } 6515060Sdfuchs p->p_osrel = osrel; 6615060Sdfuchs } 6715060Sdfuchs return (0); 6815060Sdfuchs} 6915060Sdfuchs