stat call in kernel always returns 'bad address'

<[email protected]> Fri, 5 Apr 2002 09:45:02 -0800
Newsgroups gmane.linux.redhat.axp.kernel
Message-ID <[email protected]>
Hello all,

I compiled some code into the 7.2 kernel which has a 'stat' 
function call for checking on a particular file in /tmp. 
Unfortunately, this stat call always returns with an errno 
of 14 (EFAULT: bad address). When I compile and run the same 
code outside the kernel everything works just fine. Can 
anyone give me a pointer?

A couple extra notes:

stat requires libc which I believe is not compatible with 
the libraries the kernel uses (errno conflicts I found) so I 
had to remove errno from the kernel lib for the kernel to 
link cleanly.

I confirmed in the code (with print statements-see below) 
that the stat struct was intact as well as the pointer to 
it. The print statements work fine in the kernel. And, as I 
said, the user version of the code works fine.

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

struct stat statbuf1;
struct stat *statbufptr = &statbuf1;

int foo ()
{
  statbufptr->st_blocks = 44;
  printk("foo.c :: Just confirming we can access statbufptr 
st_blocks: %d\n", statbufptr->st_blocks);

  if ( stat("/tmp/myfile", statbufptr) != 0 )
...

Thanks,
Rick

Please let me know if I should be posting this somewhere 
else.