2002-02-20 23:34:17

by Kallol Biswas

[permalink] [raw]
Subject: lseek SEEK_END fails on a Toshiba 6007MB disk.

#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>



main(int argc, char *argv[])
{
int fd;
int offset;
int loffset;

fd = open("/dev/hda", O_RDONLY);

if (fd < 0) {
perror("open");
return;
}

offset = lseek(fd, 0, SEEK_END);

if (offset < 0) {
perror("lseek");
}

}


# ./seek
lseek: Value too large for defined data type

The system runs 2.4.17 kernel.

A fix may be found reading the source code, but if someone already knows

the solution, please reply to me.

Kallol


2002-02-20 23:47:37

by Alan

[permalink] [raw]
Subject: Re: lseek SEEK_END fails on a Toshiba 6007MB disk.

> # ./seek
> lseek: Value too large for defined data type
>
> The system runs 2.4.17 kernel.

This is correct behaviour

2002-02-21 00:23:36

by Andreas Dilger

[permalink] [raw]
Subject: Re: lseek SEEK_END fails on a Toshiba 6007MB disk.

On Feb 20, 2002 15:40 -0800, Kallol Biswas wrote:
> offset = lseek(fd, 0, SEEK_END);
>
> lseek: Value too large for defined data type

You need to use a 64-bit lseek (e.g. llseek or lseek64). This can
be done with '#define _LARGEFILE_SOURCE' and/or '#define _LARGEFILE64_SOURCE'
and/or '#define _FILE_OFFSET_BITS=64'.

Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/