ioctlent.sh revision d26566955711969411c6f48d3990b47ffd400b41
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#! /bin/sh 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Copyright (c) 2001 Wichert Akkerman <wichert@cistron.nl> 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# All rights reserved. 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Redistribution and use in source and binary forms, with or without 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# modification, are permitted provided that the following conditions 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# are met: 9a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch# 1. Redistributions of source code must retain the above copyright 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# notice, this list of conditions and the following disclaimer. 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 2. Redistributions in binary form must reproduce the above copyright 12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch# notice, this list of conditions and the following disclaimer in the 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# documentation and/or other materials provided with the distribution. 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 3. The name of the author may not be used to endorse or promote products 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# derived from this software without specific prior written permission. 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# $Id$ 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Validate arg count. 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)case $# in 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)1) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dir="$1" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) asm=asm 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ;; 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)2) 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) dir="$1" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) asm="$2" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ;; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo "usage: $0 include-directory [asm-subdirectory]" >&2 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) exit 1 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ;; 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)esac 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)lookup_ioctls() 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){ 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) type="$1" 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) shift 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) # Build the list of all ioctls 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) regexp='^[[:space:]]*#[[:space:]]*define[[:space:]]\+[A-Z][A-Z0-9_]*[[:space:]]\+0x'"$type"'..\>' 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) (cd "$dir" ; grep "$regexp" "$@" /dev/null 2>/dev/null ) | 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) sed -ne 's/^\(.*\):[[:space:]]*#[[:space:]]*define[[:space:]]*\([A-Z0-9_]*\)[[:space:]]*\(0x'"$type"'..\).*/ { "\1", "\2", \3 },/p' \ 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) >> ioctls.h 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles): > ioctls.h 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)lookup_ioctls 46 linux/fb.h 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)lookup_ioctls 4B linux/kd.h 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)lookup_ioctls 53 linux/cdrom.h 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)lookup_ioctls 54 $asm/ioctls.h 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)lookup_ioctls 56 linux/vt.h 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)lookup_ioctls '7[12]' linux/videotext.h 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)lookup_ioctls 89 $asm/sockios.h linux/sockios.h 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)lookup_ioctls 8B linux/wireless.h 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)files="linux/* $asm/* scsi/* sound/*" 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Build the list of all ioctls 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)regexp='^[[:space:]]*#[[:space:]]*define[[:space:]]\+[A-Z][A-Z0-9_]*[[:space:]]\+_S\?\(IO\|IOW\|IOR\|IOWR\)\>' 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)(cd $dir ; grep $regexp $files 2>/dev/null ) | \ 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sed -ne "s,$asm/,asm/,"' 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)s/^\(.*\):[[:space:]]*#[[:space:]]*define[[:space:]]*\([A-Z0-9_]*\)[[:space:]]*_S\?I.*(\([^[,]*\)[[:space:]]*,[[:space:]]*\([^,)]*\).*/ { "\1", "\2", _IOC(_IOC_NONE,\3,\4,0) },/p' \ 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) >> ioctls.h 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Some use a special base to offset their ioctls on. Extract that as well. 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles): > ioctldefs.h 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bases=$(sed -ne 's/.*_IOC_NONE.*,[[:space:]]*\([A-Z][A-Z0-9_]\+\)[[:space:]+,].*/\1/p' ioctls.h | uniq | sort) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)for base in $bases ; do 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo "Looking for $base" 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) regexp="^[[:space:]]*#[[:space:]]*define[[:space:]]\+$base" 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (cd $dir ; grep -h $regexp 2>/dev/null $files ) | \ 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) grep -v '\<_IO' >> ioctldefs.h 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)done 88