11541Srgrimes/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1990, 1993, 1994 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)ioccom.h 8.2 (Berkeley) 3/28/94 3050477Speter * $FreeBSD$ 311541Srgrimes */ 321541Srgrimes 331541Srgrimes#ifndef _SYS_IOCCOM_H_ 341541Srgrimes#define _SYS_IOCCOM_H_ 351541Srgrimes 361541Srgrimes/* 371541Srgrimes * Ioctl's have the command encoded in the lower word, and the size of 381541Srgrimes * any in or out parameters in the upper word. The high 3 bits of the 391541Srgrimes * upper word are used to encode the in/out status of the parameter. 401541Srgrimes */ 41206051Spjd#define IOCPARM_SHIFT 13 /* number of bits for ioctl size */ 42206051Spjd#define IOCPARM_MASK ((1 << IOCPARM_SHIFT) - 1) /* parameter length mask */ 431541Srgrimes#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK) 441541Srgrimes#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16)) 451541Srgrimes#define IOCGROUP(x) (((x) >> 8) & 0xff) 461541Srgrimes 47206051Spjd#define IOCPARM_MAX (1 << IOCPARM_SHIFT) /* max size of ioctl */ 481541Srgrimes#define IOC_VOID 0x20000000 /* no parameters */ 491541Srgrimes#define IOC_OUT 0x40000000 /* copy out parameters */ 501541Srgrimes#define IOC_IN 0x80000000 /* copy in parameters */ 511541Srgrimes#define IOC_INOUT (IOC_IN|IOC_OUT) 52162711Sru#define IOC_DIRMASK (IOC_VOID|IOC_OUT|IOC_IN) 531541Srgrimes 54182391Sobrien#define _IOC(inout,group,num,len) ((unsigned long) \ 55182391Sobrien ((inout) | (((len) & IOCPARM_MASK) << 16) | ((group) << 8) | (num))) 561541Srgrimes#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0) 57162711Sru#define _IOWINT(g,n) _IOC(IOC_VOID, (g), (n), sizeof(int)) 581541Srgrimes#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t)) 591541Srgrimes#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t)) 601541Srgrimes/* this should be _IORW, but stdio got there first */ 611541Srgrimes#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) 621541Srgrimes 63162711Sru#ifdef _KERNEL 6418440Sbde 65162711Sru#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ 66162711Sru defined(COMPAT_FREEBSD4) || defined(COMPAT_43) 67162711Sru#define IOCPARM_IVAL(x) ((int)(intptr_t)(void *)*(caddr_t *)(void *)(x)) 68162711Sru#endif 69162711Sru 70162711Sru#else 71162711Sru 7218440Sbde#include <sys/cdefs.h> 7318440Sbde 7418440Sbde__BEGIN_DECLS 7594345Simpint ioctl(int, unsigned long, ...); 7618440Sbde__END_DECLS 7718440Sbde 7855205Speter#endif 7918440Sbde 801541Srgrimes#endif /* !_SYS_IOCCOM_H_ */ 81