lkml.org 
[lkml]   [1997]   [Nov]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: Filesize limitation
From
Date
Andre Uratsuka Manoel <andre@insite.com.br> writes:

> Hello gentlemen,
>
> I was contact by people asking about filesize limits in Linux as
> they tried to create a 2GB file, but couldn't. I figured the problem
> might be the filesize limitation. At least that is what I'd expect to
> happen with a file that size. Am I right on that? If it is so, is there
> a 64-bit filesystem for Linux?

There is a very simple workaround for this. Linux allows partitions much
bigger than 2GB. So just use multiple files:

/* Only supports one big file, extending it for more is trivial */
/* Untested and no error checking. */
/* IO is limited to 2^31 bytes (that's OK because i386 linux only
* has a address room of 2^30 bytes per process) */
typedef long long big_offset_t;
int bigfdtab[NROPEN];
big_offset_t big_offset;
char *big_name;
int big_mode;

#define BIGFD(offset) (bigfdtab[(offset) >> 31])
#define BIGOFFSET(offset) ((offset) & 0x7fffffff)
static int bopen(int fd)
{
char name[strlen(big_name) + 10];
sprintf(name, "%s%d", fd);
bigfdtab[fd] = open(name, big_flags, big_mode);
}
/* Use return value only for error checking */
int big_open(char *name, int flags, int mode)
{
big_name = strdup(name);
big_flags = flags;
big_offset = 0;
big_mode = mode;
return bopen(0);
}
void big_close()
{
int n;
for (n = 2; n < NROPEN; n++)
if (bigfdtab[n])
close(bigfdtab[n]);
free(big_name); big_name = NULL;
}
int big_read(char *buf, long size)
{
int fd = BIGFD(big_offset);
long r;
if (!bigfdtab[fd]) {
bopen(fd);
}
fd = bigfdtab[fd];
if (BIGFD(bigoffset+size) != fd) {
/* Crosses file borders */
lseek(fd, BIGOFFSET(big_offset), SEEK_SET);
r = read(fd, buf, (big_offset+size) & 0x7fffffff);
big_offset += r;
size -= r;
fd = BIGFD(big_offset);
}
/* Could be optimized. */
lseek(fd, BIGOFFSET(big_offset), SEEK_SET);
r = read(fd, buf, size);
big_offset += r;
return r;
}
That's very simple of course and has a few problems (you can still overflow
the fd table by using big holes, it does unnecessary seeks etc.) but you get
the basic idea. I have never tried to compile it, so don't blame me if it
doesn't :)

-Andi

\
 
 \ /
  Last update: 2005-03-22 13:40    [from the cache]
©2003-2011 Jasper Spaans. Advertise on this site