Bug #68209 [NEW]: php does not work with files that have 64bit inodes on a 32bit filesystem

From: Date: Fri, 10 Oct 2014 18:53:15 +0000
Subject: Bug #68209 [NEW]: php does not work with files that have 64bit inodes on a 32bit filesystem
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188010@lists.php.net to get a copy of this message
From:             arekm at maven dot pl
Operating system: 
PHP version:      5.6.1
Package:          *General Issues
Bug Type:         Bug
Bug description:php does not work with files that have 64bit inodes on a 32bit filesystem

Description:
------------
It's perfectly valid to have files with 64bit inodes on a system with
32bit Linux kernel. Unfortunately php is not capable of handling these
files. Example:

[arekm@farm 100]$ ls -li 100.txt 
425201762433 -rw-r--r-- 1 root root 0 10-08 23:09 100.txt
[arekm@farm 100]$ php --version
PHP 5.6.0 (cli) (built: Aug 28 2014 20:53:25) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
[arekm@farm 100]$ php -r "var_dump(stat('100.txt'));"
PHP Warning:  stat(): stat failed for 100.txt in Command line code on
line 1
bool(false)
[arekm@farm 100]$ file /usr/bin/php
/usr/bin/php: symbolic link to `php56'
[arekm@farm 100]$ file /usr/bin/php56
/usr/bin/php56: ELF 32-bit LSB executable, Intel 80386, version 1
(SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16,
BuildID[sha1]=9b3d30e4bb089221042dfbe36ca43c8b69a8021f, stripped


The whole problem comes from PHP not being compiled with
// this makes LFS (large file support) functions to be used
// (so glibc stat64() will be called instead of stat())
#define _LARGEFILE_SOURCE
// this makes resulting binary ready for 64bit off_t type (off64_t) this
stat()
// won't die with EOVERFLOW errno (see stat(2) for more details)
#define _FILE_OFFSET_BITS=64

The solution is simple. Add
AC_SYS_LARGEFILE
macro to configure.ac. configure will then figure out what defines are
needed to get LFS support.

Two reasons to get LFS enabled with php:
- files over 2GB will be correctly handled on 32bit kernels
- small files that have 64bit inodes will be correctly handled on 32bit
kernels

ps. there are some bugs that will be uncovered in PHP with LFS enabled
(some nesting detection error). That bug would need to be fixed too.


Test script:
---------------
php -r "var_dump(stat('test_file.txt'));"

is enough but test_file.txt needs to have 64bit inode number. To get
test file with 64bit inode number do:

# create sparse 10T image

[arekm@farm test]$ truncate -s 10T testimage 

# create fs on it (it will take about 2GB on filesystem), note agcount
got set to 10

[arekm@farm test]$ mkfs.xfs testimage       
meta-data=testimage              isize=256    agcount=10,
agsize=268435455 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=2684354550,
imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=521728, version=2
         =                       sectsz=512   sunit=0 blks,
lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[arekm@farm test]$ mkdir mntpoint
[arekm@farm test]$ sudo bash

# mount with inode64 option. This option is default in recent kernels.

[root@farm test]# mount testimage mntpoint -o inode64
[root@farm test]# for i in seq 1 100; do mkdir mntpoint/$i && touch
mntpoint/$i/$i.txt; done
[root@farm test]# ls -l mntpoint/100/100.txt 
-rw-r--r-- 1 root root 0 Oct 10 20:42 mntpoint/100/100.txt

# make sure one of txt files created has 64bit inode

[root@farm test]# ls -li mntpoint/100/100.txt 
38654705811 -rw-r--r-- 1 root root 0 Oct 10 20:42 mntpoint/100/100.txt

# so test php now on it

[root@farm test]# php -r 'stat("mntpoint/100/100.txt");';
PHP Warning:  stat(): stat failed for mntpoint/100/100.txt in Command
line code on line 1
[root@farm test]# 



Expected result:
----------------
Working stat().

Actual result:
--------------
PHP Warning:  stat(): stat failed for mntpoint/100/100.txt in Command
line code on line 1
failure.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=68209&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68209&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68209&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68209&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68209&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68209&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68209&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68209&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68209&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68209&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68209&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68209&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68209&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68209&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68209&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68209&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68209&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68209&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68209&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68209&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68209&r=mysqlcfg



Thread (7 messages)

« previous php.bugs (#188010) next »