Question

Shouldn't be hard, right? Right?

I am currently trawling the OpenAFS codebase to find the header definition of pioctl. I've thrown everything I've got at it: checked ctags, grepped the source code for pioctl, etc. The closest I've got to a lead is the fact that there's a file pioctl_nt.h that contains the definition, except it's not actually what I want because none of the userspace code directly includes it, and it's Windows specific.

Now, I'm not expecting you to go and download the OpenAFS codebase and find the header file for me. I am curious, though: what are your techniques for finding the header file you need when everything else fails? What are the worst case scenarios that could cause a grep for pioctl in the codebase to not actually come up with anything that looks like a function definition?

I should also note that I have access to two independent userspace programs that have done it properly, so in theory I could do an O(n) search for the function. But none of the header files pop out to me, and n is large...

Edit: The immediate issue has been resolved: pioctl() is defined implicitly, as shown by this:

AFS.xs:2796: error: implicit declaration of function ‘pioctl’
Was it helpful?

Solution

If grep -r and ctags are failing, then it's probably being defined as the result of some nasty macro(s). You can try making the simplest possible file that calls pioctl() and compiles successfully, and then preprocessing it to see what happens:

gcc -E test.c -o test.i
grep pioctl -C10 test.i

OTHER TIPS

There are compiler options to show the preprocessor output. Try those? In a horrible pinch where my head was completely empty of any possible definition the -E option (in most c compilers) does nothing but spew out the the preprocessed code.

Per requested information: Normally I just capture a compile of the file in question as it is output on the screen do a quick copy and paste and put the -E right after the compiler invocation. The result will spew preprocessor output to the screen so redirect it to a file. Look through that file as all of the macros and silly things are already taken care of.

Worst case scenarios:

  • K&R style prototypes
  • Macros are hiding the definition
  • Implicit Declaration (per your answer)

Have you considered using cscope (available from SourceForge)?

I use it on some fairly significant code sets (25,000+ files, ranging up to about 20,000 lines in a file) with good success. It takes a while to derive the file list (5-10 minutes) and longer (20-30 minutes) to build the cross-reference on an ancient Sun E450, but I find the results useful.


On an almost equally ancient Mac (dual 1GHz PPC 32-bit processors), cscope run on the OpenAFS (1.5.59) source code comes up with quite a lot of places where the function is declared, sometimes inline in code, sometimes in headers. It took a few minutes to scan the 4949 files, generating a 58 MB cscope.out file.

  • openafs-1.5.59/src/sys/sys_prototypes.h
  • openafs-1.5.59/src/aklog/aklog_main.c (along with comment "Why doesn't AFS provide these prototypes?")
  • openafs-1.5.59/src/sys/pioctl_nt.h
  • openafs-1.5.59/src/auth/ktc.c includes a define for PIOCTL
  • openafs-1.5.59/src/sys/pioctl_nt.c provides an implementation of it
  • openafs-1.5.59/src/sys/rmtsysc.c provides an implementation of it (and sometimes afs_pioctl() instead)

The rest of the 184 instances found seem to be uses of the function, or documentation references, or release notes, change logs, and the like.

The current working theory that we've decided on, after poking at the preprocessor and not finding anything either, is that OpenAFS is letting the compiler infer the prototype of the function, since it returns an integer and takes pointer, integer, pointer, integer as its parameters. I'll be dealing with this by merely defining it myself.

Edit: Excellent! I've found the smoking gun:

AFS.xs:2796: error: implicit declaration of function ‘pioctl’

While the original general question has been answered, if anyone arrives at this page wondering where to find a header file that defines pioctl:

In current releases of OpenAFS (1.6.7), a protoype for pioctl is defined in sys_prototypes.h. But that the time that this question was originally asked, that file did not exist, and there was no prototype for pioctl visible from outside the OpenAFS code tree.

However, most users of pioctl probably want, or are at least okay with using, lpioctl ("local" pioctl), which always issues a syscall on the local machine. There is a prototype for this in afssyscalls.h (and these days, also sys_prototypes.h).

The easiest option these days, though, is just to use libkopenafs. For that, include kopenafs.h, use the function k_pioctl, and link against -lkopenafs. That tends to be a much more convenient interface than trying to link with OpenAFS libsys and other stuff.

Doesn't it usually say in the man page synopsis?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top