Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent stat() implementation wrt inode numbers #11146

Closed
p5pRT opened this issue Feb 21, 2011 · 6 comments
Closed

Inconsistent stat() implementation wrt inode numbers #11146

p5pRT opened this issue Feb 21, 2011 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 21, 2011

Migrated from rt.perl.org#84590 (status was 'resolved')

Searchable as RT84590$

@p5pRT
Copy link
Author

p5pRT commented Feb 21, 2011

From @ribasushi

Created by ribasushi@cpan.org

This is from an XFS filesystem on a 32bit workstation​:

rabbit@​Thesaurus​:~$ perl -E 'my $fn = "xxx"; my $sys = `stat -c%i "$fn"`; chomp $sys; my $perl = (stat($fn))[1]; die "$fn\tP​:$perl\tS​:$sys\n" unless $sys == $perl'
xxx P​:-2086220941 S​:2208746355

It appears that perl treats ino_t as signed whereas it is overwhelmingly
defined as unsigned​:

rabbit@​Thesaurus​:~$ perl -E 'say unpack("L", pack( "l", -2086220941) )'
2208746355

http​://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html

#p5p backlog​:

<Nicholas> the inode has a value so large that it's being treated by perl as a negative number?
<ribasushi> Nicholas​: it looks like signed/unsigned problem
<ribasushi> Nicholas​: note this is my workstation, not some crazy server
<ribasushi> I just... like to keep things around :)
<ribasushi> also this is a 32bit machine
<Nicholas> I don't *know* if it's a "bug" because I can't find anything via google that says whether ino_t in POSIX is defined to be unsigned
<Zefram> de facto, inode numbers are always interpreted as unsigned
<ilmari> * fsblkcnt_t, fsfilcnt_t, and ino_t shall be defined as unsigned integer types.
<ilmari> sys_types.h(7posix)
<ilmari> de jure as well
<ilmari> Nicholas​: http​://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html
<Nicholas> ilmari​: aha. you win
<ilmari> Nicholas​: linked from stat(3posix) via sys/stat.h(7posix)
<ilmari> http​://www.opengroup.org/onlinepubs/000095399/functions/stat.html

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl 5.13.10:

Configured by rabbit at Mon Feb 21 14:02:25 CET 2011.

Summary of my perl5 (revision 5 version 13 subversion 10) configuration:
   
  Platform:
    osname=linux, osvers=2.6.32-5-686, archname=i686-linux-thread-multi-64int
    uname='linux thesaurus 2.6.32-5-686 #1 smp wed jan 12 04:01:41 utc 2011 i686 gnulinux '
    config_args='-de -Dprefix=/home/rabbit/perl5/perlbrew/perls/5.13.10 -Dusethreads -Duse64bitint -Dusedevel'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.4.5', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/lib64
    libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.11.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.11.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'

Locally applied patches:
    


@INC for perl 5.13.10:
    /home/rabbit/devel/utils/perl
    /home/rabbit/perl5/perlbrew/perls/5.13.10/lib/site_perl/5.13.10/i686-linux-thread-multi-64int
    /home/rabbit/perl5/perlbrew/perls/5.13.10/lib/site_perl/5.13.10
    /home/rabbit/perl5/perlbrew/perls/5.13.10/lib/5.13.10/i686-linux-thread-multi-64int
    /home/rabbit/perl5/perlbrew/perls/5.13.10/lib/5.13.10
    .


Environment for perl 5.13.10:
    HOME=/home/rabbit
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_ADDRESS=en_US.UTF-8
    LC_COLLATE=en_US.UTF-8
    LC_CTYPE=en_US.UTF-8
    LC_IDENTIFICATION=en_US.UTF-8
    LC_MESSAGES=en_US.UTF-8
    LC_MONETARY=en_US.UTF-8
    LC_NAME=en_US.UTF-8
    LC_NUMERIC=en_US.UTF-8
    LC_TELEPHONE=en_US.UTF-8
    LC_TIME=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/rabbit/devel/utils:/home/rabbit/perl5/perlbrew/bin:/home/rabbit/perl5/perlbrew/perls/current/bin:/home/rabbit/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
    PERL5LIB=/home/rabbit/devel/utils/perl:
    PERL_AUTOINSTALL_PREFER_CPAN=1
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Feb 22, 2011

From @iabyn

On Mon, Feb 21, 2011 at 09​:19​:06AM -0800, Peter Rabbitson wrote​:

This is from an XFS filesystem on a 32bit workstation​:

rabbit@​Thesaurus​:~$ perl -E 'my $fn = "xxx"; my $sys = `stat -c%i "$fn"`; chomp $sys; my $perl = (stat($fn))[1]; die "$fn\tP​:$perl\tS​:$sys\n" unless $sys == $perl'
xxx P​:-2086220941 S​:2208746355

It appears that perl treats ino_t as signed whereas it is overwhelmingly
defined as unsigned​:

So, would this be as simple as changing mPUSHi(PL_statcache.st_ino)
to mPUSHu() in pp_stat?

--
Lear​: Dost thou call me fool, boy?
Fool​: All thy other titles thou hast given away; that thou wast born with.

@p5pRT
Copy link
Author

p5pRT commented Feb 22, 2011

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 8, 2011

From @dgl

On 22 Feb 2011, at 13​:00, Dave Mitchell wrote​:
[...]

It appears that perl treats ino_t as signed whereas it is overwhelmingly
defined as unsigned​:

So, would this be as simple as changing mPUSHi(PL_statcache.st_ino)
to mPUSHu() in pp_stat?

To fix this particular issue, yes, however on Linux (and probably similar on other systems) the size of ino_t depends on what _FILE_OFFSET_BITS is set to (i.e. if perl is configured with large file support), so it probably should take that into account too.

David

PS, on 32-bit x86 Linux​:
$ echo -e '#include <stdio.h>\n#include <sys/types.h>\nmain(){printf("%lu\\n", sizeof(ino_t));}' > i.c && make i CFLAGS=-D_FILE_OFFSET_BITS=64 && ./i
8
$ echo -e '#include <stdio.h>\n#include <sys/types.h>\nmain(){printf("%lu\\n", sizeof(ino_t));}' > i.c && make i && ./i
4

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2011

From @tonycoz

On Mon, Feb 21, 2011 at 09​:19​:06AM -0800, Peter Rabbitson wrote​:

This is from an XFS filesystem on a 32bit workstation​:

rabbit@​Thesaurus​:~$ perl -E 'my $fn = "xxx"; my $sys = `stat -c%i "$fn"`; chomp $sys; my $perl = (stat($fn))[1]; die "$fn\tP​:$perl\tS​:$sys\n" unless $sys == $perl'
xxx P​:-2086220941 S​:2208746355

It appears that perl treats ino_t as signed whereas it is overwhelmingly
defined as unsigned​:

rabbit@​Thesaurus​:~$ perl -E 'say unpack("L", pack( "l", -2086220941) )'
2208746355

http​://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html

Fixed in 668fdbe and
8d8cba8.

Tony

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2011

@tonycoz - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant