Re: 64 Bits from Larry McVoy

Christian Hardmeier (chrigi@darkstar.chrigi.net)
Thu, 7 Nov 1996 19:58:14 +0100 (MET)


On Wed, 6 Nov 1996, Jim Nance wrote:

> First I want to thank all the people who pointed out that I don't know how
> to use open(). I have patched the program call it correctly, and have
> included the errors I am seeing. Also, I am running on an Alpha, not an
> intel machine. I would expect compleatly different behavior on an intel
> since the longs are only 32 bits. Here is the program:
>
[code & output snipped]

I tried the program on two Intel boxes. Both of them reacted similarly:

Script started on Wed Nov 6 12:22:52 1996
bash$ gcc bigfile_.c
bigfile_.c: In function `main':
bigfile_.c:17: warning: integer overflow in expression
bigfile_.c:17: warning: integer overflow in expression
bigfile_.c:17: warning: integer overflow in expression
bash$ a.out
lseek:: Invalid argument
bash$ ls -l big*
-rw-r--r-- 1 ch user 1 Nov 6 12:23 bigfile
-rw-r--r-- 1 ch user 311 Nov 6 12:23 bigfile.script
-rw-rw-rw- 1 ch user 555 Nov 6 12:17 bigfile_.c
bash$ exit
exit

Script done on Wed Nov 6 12:23:54 1996

Then, I tried it on an Alpha running NetBSD (unfortunately I have no
access to a Linux Alpha). It worked perfectly.

Then, I tried the one with _llseek:

Script started on Thu Nov 7 19:55:36 1996
darkstar:~$ gcc bigfile.c
darkstar:~$ a.out
pos: 0x80000000; offset: 0x80000000
write:: File too large
darkstar:~$ ls -l bigfile
-rw-r--r-- 1 chrigi users 2147483648 Nov 7 19:55 bigfile
darkstar:~$ exit
Script done on Thu Nov 7 19:56:26 1996

The code follows below.

Christian

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

#define GB ((long long)(1024*1024*1024))
#define NG (2048L)

_syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, loff_t *, res,
uint, wh);

int main()
{
loff_t offset, pos;

int fd = open("bigfile", O_CREAT|O_TRUNC|O_WRONLY, 0666);

if(fd<0) {perror("open:"); exit(1);}

for(offset=0; offset<((long long)NG*(long long)GB); offset += GB) {
int num;
if(_llseek(fd, offset>>32, (unsigned long)offset,
&pos, SEEK_SET) == -1)
{
printf("pos: 0x%LX; offset: 0x%LX\n", pos, offset);
perror("lseek:"); exit(1);}
num=write(fd,"x",1);
if(num!=1) {
printf("pos: 0x%LX; offset: 0x%LX\n", pos, offset);
perror("write:"); exit(1);}
}

printf("Done!\n");
return 0;
}