c - fread() on 6gb file fails -


OK, I'm reading at fread () which gives a kind of size and about big files I have seen many posts and some other issues are happening - but I still have some problems. This function is from a file indicator and a long long int LLD main, where I use another function to get the actual files I am 6448619520 bytes. I

  four * getBuffer (FILE * fptr, perpendicular Time to size) {char * bfr; Size_t result; Printf ("Size of file in allocation buffer:% lld \ n", size); // size here 6448619520 bfr = (four *) molk (size (four) * size); If (bfr == NULL) {printf ("error, malloc failed ... .. \ n"); Exhaust (EXIT_FAILURE); } // position fptr offset locale that is here 0 fasec (ftrs, 0, SEEKTST); // read the entire input file in the BFF result = Fred (BFF, size (four), size, FPTR); Printf ("result =% lld \ n", (long-term) results); If (Result! = Size) {printf ("Failed to read file \ n"); Exit (5); } Return (BFR); }  

I have tested it on about 1-2 GB size files and it works fine, however, when I test it on 6GB file, then nothing in buffer It is not read. Ignore other results, (focus on the bold for the result), this problem is with reading in the BFR. Here are some results given here.

The first of a file that is 735844352 bytes (700 + MB)

root @ redbox: / data / project / c / stub / # ./testrun -x 45004E00 -i /data/Helix2008R1.iso

image file /data/helix2008R1.iso.html hex string = 45004E00
> total file size: 735844352
receive File size in buffer: 735844352
results = 735844352


Start parsing the command line hex value: 45004E00 Total number of hex string in bytes: 4

Results of hex string:
hex Tring was found at 45004E00 byte location: 37441
Hex String 45004E00 Byte Locations was found: 524768
....

Run # 2 against 6gb file: Root @ Redbox: / data / projects / c / stubs / # ./testrun -x BF1B0650 -i / data / images /sixgbimage.img

image file /data/images/sixgbimage.img
hex String = BF1B0650
Total file size: 6448619520
File size in the allotted buffer: 644861 9520
Result = 0
Failed to read file

I still can not believe that Why this fails with big files and not small, this is a> 4 GB issue I am using the following:

  / * Use a large file * / #define _LARGEFILE_SOURCE 1 #define _LARGEFILE64_SOURCE 1 #define _FILE_OFFSET_BITS 64  

BTW, I am using an Ubuntu 9.10 box (2.6.x kernel). TIA

If you just want to read through the file, then do not modify it, I suggest Instead of mmap (2) using fread (3) . It should be very efficient, although I have not tried to do this on large files. You need to change your very simplified / do not know if you want to do this, but I'm not sure for whom you want points. :)

#define _GNU_SOURCE #include & lt; String.h & gt; # Include & lt; Fcntl.h & gt; # Include & lt; Sys / mman.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Sys / types.h & gt; # Include & lt; Sys / stat.h & gt; # Include & lt; Unistd.h & gt; Int main (int argc, char * argv []) {char * base, * found; Off lane; Structure State SB; Int rate; Int FD; Unsigned int needle = 0x45004E00; Rate = Stat (argv [1], & SB); If (RT) {mirror ("state"); Return 1; } Lane = sb.st_size; FD = Open (RGR [1], O_RDON); If (FD & lt; 0) {mirror ("open"); Return 1; } Base = mmap (NULL, len, PROT_READ, MAP_PRIVATE, FD, 0); If (base!) {Mirror ("mmap"); Return 1; } Found = memmem (base, lane, and needle, size (unsigned int)); If (found) printf ("% x on% p found \ n", needle, found); Else printf ("not found"); Return 0; }

Some tests:

  $ ./mmap ./mmap found 0x7f8c4c13a6c0 $ ./mmap / etc / passwd not found 45004E00  

Comments