stat() / lstat() and incorrect field values




Hi all,

stat() and lstat() calls seem to be consistently giving me correct
st_dev and st_gid values, but incorrect values for st_ino, st_mode,
st_size, st_nlink, and st_uid (I've not analysed the other fileds yet).

I'm not doing anything special, just:

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

...
struct stat st;
stat(filename, &st);

/* printing values here gives unexpected results */

(I'm checking the result of the stat() call before querying values,
obviously :-)

For any file, st_mode seems to always end up being 0, st_ino is a random
integer value (consistent across runs against the same file), st_nlink
ends up being very close to what I st_ino *should* be (checking against
the 'stat' system binary).

It's almost as though memory gets copied somewhere behind the scenes and
something's getting misaligned; but if so, why might that be - and how
come it's not limited to a single kernel release? Makes me think it's user
error, but I'm not sure what I'm doing wrong :-)

cheers

Jules


.



Relevant Pages

  • Re: stat() / lstat() and incorrect field values
    ... stat() and lstatcalls seem to be consistently giving me correct ... int main(int argc, char *argv) ... Owner UID = 1000 ...
    (comp.os.linux.development.apps)
  • Re: listing a huge amount of file on one file system
    ... to lstat() every file every symlink!) in order to ... than a simple linear list, ... it finds the filename, which may be anywhere in the listing). ...
    (RedHat)
  • Re: efficiency of fstat calls?
    ... For lstat(), how many symbolic ... > point directly to a regular file (rather than to another symlink). ... > Do these issues affect the lookup time the stat call would need to find ... file size, mod time, etc. are kept in the inode structure of the ...
    (comp.unix.programmer)
  • Re: no lstat happens
    ... Did you change the lstat to stat like I suggested in my first post? ... (two ascii text files and one symlink). ...
    (perl.beginners)
  • Re: files
    ... fstatif you have a filehandle ... lstat() is special for getting at symbolic links - but normally you ... distros also include a stat in section 1. ...
    (uk.comp.os.linux)