Re: lseek: Value too large for defined data type



I am unable to seek. again same error it is giving.

First i will write 21GB then run the below program

The program

#define _GNU_SOURCE
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
main()
{

int file = 0;
char *buff = NULL;
int bytewr,count=0,loopcount,choice;
long long seekOffset = 0;

buff = (char *)malloc(1024 * 1024);
if(buff == NULL)
{
printf("Memory Allocation failed\n");
return -1;
}
else
{
printf("Memory allocation success\n");
}

file = open("/HDR1/test1.txt", O_LARGEFILE|O_RDWR);
if(file == -1)
{
printf("Error opening file\n");
return -1;
}
else
{
printf("File opening success\n");
}
/*1MB seek*/
seekOffset = lseek(file,(1024*1024),SEEK_CUR);
if(seekOffset == -1)
{
printf("Seek Fail\n");
return -1;
}
else
{
printf("Seek Success=%d\n",seekOffset);
}

memset(buff,0x44,(1024*1024));
loopcount = 10240; /*do it for this many times*/
{
count = 0;
do {
bytewr = write(file, buff,(1024*1024));
if(bytewr == (1024*1024))
{
printf("Count: %d Write Success\n",count); }
else
{
printf("Write fail\n");
return -1;
}
if((count%100) == 0)
{
/*Seek afterevery
100MB*/
seekOffset = lseek(file,(1024),SEEK_CUR);
if(seekOffset == -1)
{
printf("Seek Fail\n");
return -1;
}
else
{
printf("Seek Success=%Ld\n",seekOffset);
}
}

}while(count++ < loopcount);
close(file);
free(buff);
}

while compiling i have to give

gcc -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE append.c -o append

after 2100 loop, it is failing.

is there any problem with application.

Regards
Gururaja

spacecriter (Bill C) wrote:
guru wrote:
Hi All,

I have written 21GB file and updating the file by seeking 1K and
writing 100MB of data consecutively 10240 times. when after writing
2GB(2100 times) of file it was giving

lseek: Value too large for defined data type error.

What is got is the value passed to 'Offset' argument is too large to
handle.

The last return value of seek is '2099270656'

Is there any way to overcome this.


As others have said, add -D_FILE_OFFSET_BITS=64 to the compiler command line

I have found that it is a good idea to also add -D_LARGEFILE64_SOURCE to the
command line as well.

--
Bill C.

.



Relevant Pages

  • Re: lseek: Value too large for defined data type
    ... printf("File opening success\n"); ... spacecriter (Bill C) wrote: ... writing 100MB of data consecutively 10240 times. ... Value too large for defined data type error. ...
    (comp.os.linux.development.system)
  • Re: fopen() question.
    ... note that opening a file for update does not create ... so if you want to open only an existing file for writing you ... opening it again with "r+" if you really do want update mode). ... platform-dependant anyway, you may as well write platform-dependant ...
    (comp.lang.c)
  • Re: local happenings here in Georgia.....courtesy of the republican state leg
    ... Bryan S. Slick wrote: ... street and beaten by an angry mob for writing.. ... his electric bill, gas bill, phone bill, and other necessary utilities ...
    (rec.sport.football.college)
  • Re: module: zipfile.writestr - line endings issue
    ... Maybe the issue lies with this way ) of writing the ... The problem is with how you are opening the file. ... dfile = file ... Python documentation seem to recommend using open. ...
    (comp.lang.python)
  • Re: Jewel Digs Bruce (if anyone cares)
    ... had been out for 2 weeks) and opening in solo mode, ... I saw Jewel on a bill with Neil Young & Crazy Horse and that band I ...
    (rec.music.artists.springsteen)