Bug 57162 - stat() function in glibc-devel-2.2.4-19 return fail when file larger than 2GB
Summary: stat() function in glibc-devel-2.2.4-19 return fail when file larger than 2GB
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
(Show other bugs)
Version: 7.1
Hardware: i386 Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Aaron Brown
Depends On:
TreeView+ depends on / blocked
Reported: 2001-12-06 07:03 UTC by Xuan Li
Modified: 2016-11-24 15:02 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-12-06 07:03:23 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Xuan Li 2001-12-06 07:03:16 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)

Description of problem:
stat(const char* filename, struct stat* buf); return fail when the 
filename specified file larger than 2GB.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1.create a large file: mybigfile.txt   (must larger than 2GB)
2.use ls -l to see the file size, result is:
 -rw-r--r-- 1 root root 2257265203 Nov 30 14:39 mybigfile.txt
3.create teststat.c
   #include <sys/types.h>
   #include <sys/stat.h>

   int main(int argc, char* argv[])
      int ret;
      struct stat buf;
      if(argc < 2) return -1;
      ret = stat(argv[1], &buf);
      if(ret == 0) printf("file size: %ld\n", buf.st_size);
      else printf("stat error\n");
      return 0;
4.compile mystat.c with 'cc -o mystat mystat.c'
5.run 'mystat mybigfile.txt'

Actual Results:  the mystat program output:
   stat error

Expected Results:  the mystat program output:
   file size: 2257265203      (a number larger than 2GB)

Additional info:

After upgrade stat command to stat-2.5-3, the stat command can output the 
file information larger than 2GB successfully, but what I want to use is 
not the command line, but the stat(const char* filename, struct stat* buf) 
function in program.  It kept failing when file is larger than 2GB even 
after I upgrade glibc to 2.2.4-19.

Comment 1 Jakub Jelinek 2001-12-06 09:19:15 UTC
Please read info libc and search for LFS or _FILE_OFFSET_BITS.
You either need to use stat64 (and use appropriate -D, e.g. -D_LARGEFILE64_SOURCE,
or -D_GNU_SOURCE), or use -D_FILE_OFFSET_BITS=64 and have this remapped
transparently (after checking the source that all file offsets are
stored in off_t type variables).

Note You need to log in before you can comment on or make changes to this bug.