Getting the list of IOCTLS in the kernel.

Sometime back I was helping one of my friends in looking for all the IOCTLs supported by the kernel. Well we did not find the info we were looking for and thus thought to write a perl script to get all the IOCTLS supported by the kernel. Here it is, simple script to scan through the code and give you a list:

#!/usr/bin/perl —

@files = `grep -r \” _IO\” /usr/src/redhat/SOURCES/linux-2.6.20/* |grep define ioctls_grep`;
open (DAT, \”ioctls_grep\”) ||die \”could not open ioctls_grep\”;
@files = DAT;
close(DAT);
my %ioctls_numbers;
print \”Grep completed..\\n\”;
open (DAT, \”ioctls_numbers_found\”);

foreach (@files)
{
($file, $line) = split(/:/);
print \”$file\\n\\t\”;
$_ = $line;
($junk, $name, $test) = split;
$temp = $test;
if ($temp =~ m/^_IORW/) { print \” Read/Write :: $name $test\\n\”;}
elsif ($temp =~ m/^_IOR/) { print \” Read :: $name $test\\n\”;}
elsif ($temp =~ m/^_IOW/){ print \” Write :: $name $test\\n\”;}
elsif ($temp =~ m/^_IO/) {print \” IOCTLS :: $name $test\\n\”;}
else {
print \”$name $test\\n\”;
if ($test =~ m/^0x/ ){
$ioctls_numbers{$name} = $test;
print DAT \”$name \\t\\t\\t– $test in file $file\\n\”
}
}

}
close(DAT);

for $keys (keys %ioctls_numbers)
{
print \”$keys — $ioctls_numbers{$keys}\\n\”;
}

2 thoughts on “Getting the list of IOCTLS in the kernel.”

  1. Nice script. But for the linux kernel it is not more than a good try. This script finds all new IOCTLs, but no legacy IOCTLs, such as in net/ipv4/.

    Ergo, this script does not find all IOCTLs.

    Ciao
    Stephan