122028508SToomas Soome /* $NetBSD: ioctl.c,v 1.4 1994/10/30 21:48:24 cgd Exp $ */
222028508SToomas Soome
322028508SToomas Soome /*
422028508SToomas Soome * Copyright (c) 1993
522028508SToomas Soome * The Regents of the University of California. All rights reserved.
6*001c1290SToomas Soome * Copyright 2024 MNX Cloud, Inc.
722028508SToomas Soome *
822028508SToomas Soome * This code is derived from software contributed to Berkeley by
922028508SToomas Soome * The Mach Operating System project at Carnegie-Mellon University.
1022028508SToomas Soome *
1122028508SToomas Soome * Redistribution and use in source and binary forms, with or without
1222028508SToomas Soome * modification, are permitted provided that the following conditions
1322028508SToomas Soome * are met:
1422028508SToomas Soome * 1. Redistributions of source code must retain the above copyright
1522028508SToomas Soome * notice, this list of conditions and the following disclaimer.
1622028508SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
1722028508SToomas Soome * notice, this list of conditions and the following disclaimer in the
1822028508SToomas Soome * documentation and/or other materials provided with the distribution.
1922028508SToomas Soome * 3. Neither the name of the University nor the names of its contributors
2022028508SToomas Soome * may be used to endorse or promote products derived from this software
2122028508SToomas Soome * without specific prior written permission.
2222028508SToomas Soome *
2322028508SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2422028508SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2522028508SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2622028508SToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2722028508SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2822028508SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2922028508SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3022028508SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3122028508SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3222028508SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3322028508SToomas Soome * SUCH DAMAGE.
3422028508SToomas Soome *
3522028508SToomas Soome * @(#)ioctl.c 8.1 (Berkeley) 6/11/93
3622028508SToomas Soome *
3722028508SToomas Soome *
3822028508SToomas Soome * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University
3922028508SToomas Soome * All Rights Reserved.
4022028508SToomas Soome *
4122028508SToomas Soome * Author: Alessandro Forin
4222028508SToomas Soome *
4322028508SToomas Soome * Permission to use, copy, modify and distribute this software and its
4422028508SToomas Soome * documentation is hereby granted, provided that both the copyright
4522028508SToomas Soome * notice and this permission notice appear in all copies of the
4622028508SToomas Soome * software, derivative works or modified versions, and any portions
4722028508SToomas Soome * thereof, and that both notices appear in supporting documentation.
4822028508SToomas Soome *
4922028508SToomas Soome * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
5022028508SToomas Soome * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
5122028508SToomas Soome * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
5222028508SToomas Soome *
5322028508SToomas Soome * Carnegie Mellon requests users of this software to return to
5422028508SToomas Soome *
5522028508SToomas Soome * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
5622028508SToomas Soome * School of Computer Science
5722028508SToomas Soome * Carnegie Mellon University
5822028508SToomas Soome * Pittsburgh PA 15213-3890
5922028508SToomas Soome *
6022028508SToomas Soome * any improvements or extensions that they make and grant Carnegie the
6122028508SToomas Soome * rights to redistribute these changes.
6222028508SToomas Soome */
6322028508SToomas Soome
6422028508SToomas Soome #include <sys/cdefs.h>
6522028508SToomas Soome
6622028508SToomas Soome #include "stand.h"
6722028508SToomas Soome
6822028508SToomas Soome int
ioctl(int fd,ulong_t cmd,char * arg)6922028508SToomas Soome ioctl(int fd, ulong_t cmd, char *arg)
7022028508SToomas Soome {
7122028508SToomas Soome struct open_file *f;
7222028508SToomas Soome
7322028508SToomas Soome f = fd2open_file(fd);
7422028508SToomas Soome if (f == NULL || f->f_flags == 0) {
7522028508SToomas Soome errno = EBADF;
7622028508SToomas Soome return (-1);
7722028508SToomas Soome }
78*001c1290SToomas Soome if (f->f_dev == NULL)
79*001c1290SToomas Soome errno = EIO;
80*001c1290SToomas Soome else
8122028508SToomas Soome errno = (f->f_dev->dv_ioctl)(f, cmd, arg);
82*001c1290SToomas Soome
83*001c1290SToomas Soome if (errno != 0)
8422028508SToomas Soome return (-1);
8522028508SToomas Soome return (0);
8622028508SToomas Soome }
87