Can't create file bigger than 2GB with my application

Hi,

I've created a simple application that is supposed to fill up a file with messages up
to the size I pass as parameter.

The problem is that once the file reaches the 2GB size, it stops growing.

The flow of the application, for what is worth, is as follows:
while ( bytes written < bytes wanted )
create message;
fwrite message;
free message;

At first I thought it was something related to some default limit of the file system (perhaps some obscure ubuntu configuration), so I tried with dd but I managed to create a 7GB file.

I then realized that I was passing the size as a parameter in bytes `expr 1024 * 1024 * 1024 * 4` which was converted with atoi and assigned to an int variable, so I thought that was problem. I decided to manually set the size internally using an unit64_t variable set to 4GB, but the result is the same.

I also tried to attach to the process with gdb once the size of 2147483647 bytes was reached but the flow was just normal (althought I don't check the return value of fwrite).

Can somebody shine some light on this one?

Thanks,
S.

you can use

ulimit -a

and check if your filesize is limited.
Regards

Yes, I did that already and it shows not limit.
Thanks.

salvatore@salvatore-desktop:~$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 20
file size               (blocks, -f) unlimited
pending signals                 (-i) 16382
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

you can use mkfile .Check the man pages for details.

I'm sorry, but what do I need mkfile for ?

My problem here is not only to be able to write with my application to a file until it reaches a certain size, but also to understand why it does not work as it is coded right now.

Thanks anyway for your answer.

Try compiling your code with the macro -D_FILE_OFFSET_BITS=64.

Look at _FILE_OFFSET_BITS under info libc 'Feature Test Macros'.

Yeah! That worked. Thank you very much.
Now I want to understand what the problem was.
Unfortunately info libc says "No menu item `libc' in node `(dir)Top'".
and I don't know how to get it in Ubuntu.

Care to explain with few words or point me somewhere else beside info?
Otherwise I'll just google! :wink:

S.

It is part of the Large File Support in Linux. See Large File Support in Linux