Can not get large file size with LFS
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Can not get large file size with LFS




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Can not get large file size with LFS  
vian1381@china.com.cn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-16-07 06:19 PM

I can get the file (larger than 2GB) size with the following codes
bycompiling with "gcc XX.c -D_LARGE_FILE_SOURCE -
D_FILE_OFFSET_BITS=64".

struct stat buf;
if (stat("file_name",&buf) == 0)
printf("file size is %lld", buf.st_size);

But when I move these codes above to my application (a lots of source
codes), it doesn't work.

I user command "getconf LFS_CFLAGS" to retrieve the flags required for
LFS, and added -D_LARGE_FILE_SOURCE and -D_FILE_OFFSET_BITS=64 to the
makefile.
But I can't get the file size.

Do you have any idea why I can't get the file size?

Thanks in advance!






[ Post a follow-up to this message ]



    Re: Can not get large file size with LFS  
Fred Kleinschmidt


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-17-07 12:18 AM


<vian1381@china.com.cn> wrote in message
news:1179333133.314133.228650@q23g2000hsg.googlegroups.com...
>I can get the file (larger than 2GB) size with the following codes
> bycompiling with "gcc XX.c -D_LARGE_FILE_SOURCE -
> D_FILE_OFFSET_BITS=64".
>
> struct stat buf;
> if (stat("file_name",&buf) == 0)
>  printf("file size is %lld", buf.st_size);
>
> But when I move these codes above to my application (a lots of source
> codes), it doesn't work.

What do you mean by "it doesn't work"? It doesn't compile?
It compiles but the program crashes? It can't find the file?
It returns the wrong size?
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing








[ Post a follow-up to this message ]



    Re: Can not get large file size with LFS  
vian1381@china.com.cn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-17-07 06:19 AM

> What do you mean by "it doesn't work"? It doesn't compile?
> It compiles but the program crashes? It can't find the file?
> It returns the wrong size?
> --
> Fred L. Kleinschmidt
> Boeing Associate Technical Fellow
> Aero Stability and Controls Computing

Oh, I should give more detail. It returns a wrong size (negative).
BTW, fopen has no problem to open a more than 2GB file.

Thanks!






[ Post a follow-up to this message ]



    Re: Can not get large file size with LFS  
Anonymous


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-17-07 06:19 AM

vian1381@china.com.cn wrote:
> I can get the file (larger than 2GB) size with the following codes
> bycompiling with "gcc XX.c -D_LARGE_FILE_SOURCE -
> D_FILE_OFFSET_BITS=64".
>
> struct stat buf;
> if (stat("file_name",&buf) == 0)
>   printf("file size is %lld", buf.st_size);
>
> But when I move these codes above to my application (a lots of source
> codes), it doesn't work.
>
> I user command "getconf LFS_CFLAGS" to retrieve the flags required for
> LFS, and added -D_LARGE_FILE_SOURCE and -D_FILE_OFFSET_BITS=64 to the
> makefile.
> But I can't get the file size.
>
> Do you have any idea why I can't get the file size?
>
> Thanks in advance!
>
Can you set a break after the stat() call, then examine the value set in
buf?  I am not familiar with %lld in the printf statement.  If
buf.st_size gives you the correct size, then perhaps it's the printf
statement that you need to fix.





[ Post a follow-up to this message ]



    Re: Can not get large file size with LFS  
David Schwartz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-17-07 12:16 PM

On May 16, 6:50 pm, vian1...@china.com.cn wrote:

> Oh, I should give more detail. It returns a wrong size (negative).
> BTW, fopen has no problem to open a more than 2GB file.

*What* returns a wrong size? Post the code. (Perhaps you return the
size in an 'int' or something like that.)

DS






[ Post a follow-up to this message ]



    Re: Can not get large file size with LFS  
vian1381@china.com.cn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-17-07 06:18 PM

> Can you set a break after the stat() call, then examine the value set in
> buf?  I am not familiar with %lld in the printf statement.  If
> buf.st_size gives you the correct size, then perhaps it's the printf
> statement that you need to fix.- >

I set a break after stat(), it's correct when the file size is smaller
than 2GB. When the file size is larger than 2GB, the size is a
negative.
Why?






[ Post a follow-up to this message ]



    Re: Can not get large file size with LFS  
Mark


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-17-07 06:18 PM

vian1381@china.com.cn wrote:
> I can get the file (larger than 2GB) size with the following codes
> bycompiling with "gcc XX.c -D_LARGE_FILE_SOURCE -
> D_FILE_OFFSET_BITS=64".
>
> struct stat buf;
> if (stat("file_name",&buf) == 0)
>   printf("file size is %lld", buf.st_size);
>
> But when I move these codes above to my application (a lots of source
> codes), it doesn't work.
>
> I user command "getconf LFS_CFLAGS" to retrieve the flags required for
> LFS, and added -D_LARGE_FILE_SOURCE and -D_FILE_OFFSET_BITS=64 to the
> makefile.
> But I can't get the file size.
>
> Do you have any idea why I can't get the file size?
>
> Thanks in advance!
>

Maybe try:

struct stat64 buf;
if (stat64("file_name", &buf) == 0)
printf("file size is %lld", buf.st_size);

in this case, buf.st_size is of type off64_t instead
of the off_t you got from stat()

see
man lf64
and
man lfcompile64





[ Post a follow-up to this message ]



    Re: Can not get large file size with LFS  
David Schwartz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-17-07 06:18 PM

On May 17, 8:29 am, vian1...@china.com.cn wrote:

> I set a break after stat(), it's correct when the file size is smaller
> than 2GB. When the file size is larger than 2GB, the size is a
> negative.
> Why?

Can you paste the actual line of code, location of the breakpoint, and
debugger output showing the negative size?

DS






[ Post a follow-up to this message ]



    Re: Can not get large file size with LFS  
vian1381@china.com.cn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-18-07 12:20 PM

> Can you paste the actual line of code, location of the breakpoint, and
> debugger output showing the negative size?
>
The debugger output in my application source code is shown below:
(gdb) print buf
$1 = {st_dev = 30932999, st_pad1 = {0, 0, 0}, st_ino = {_d =
9.4608136456494459e-319, _l = {0, 191489}},
st_mode = 33188, st_nlink = 1, st_uid = 1406, st_gid = 227, st_rdev
= 0, st_pad2 = {0, 0}, st_size = {
_d = 1.8360945890051364e-314, _l = {0, -578670475}}, st_atim =
{tv_sec = 1179138644, tv_nsec = 671916000},
st_mtim = {tv_sec = 1179415806, tv_nsec = 504192000}, st_ctim =
{tv_sec = 1179415806, tv_nsec = 504192000},
st_blksize = 8192, st_blocks = {_d = 3.5878889099984655e-317, _l =
{0, 7261968}},
st_fstype = "ufs", '\0' <repeats 12 times>, st_pad4 = {0, 0, 0, 0,
0, 0, 0, 0}}
(gdb)


When I debug the below code (copy to a new file, and compile with gcc -
g XX.c -D_LARGE_FILE_SOURCE -
D_FILE_OFFSET_BITS=64"):

struct stat s;
if (stat("file_name",&s) == 0)
printf("file size is %lld", s.st_size);

The debugger output is:
(gdb) print s
$1 = {st_dev = 30932999, st_pad1 = {0, 0, 0}, st_ino = 191489, st_
mode
= 33188, st_nlink = 1, st_uid = 1406, st_gid = 227,
st_rdev = 0, st_pad2 = {0, 0}, st_size = 3716296821, st_atim =
{tv_sec = 1179138644, tv_nsec = 671916000}, st_mtim = {
tv_sec = 1179415806, tv_nsec = 504192000}, st_ctim = {tv_sec =
1179415806, tv_nsec = 504192000}, st_blksize = 8192,
st_blocks = 7261968, st_fstype = "ufs", '\0' <repeats 12 times>,
st_pad4 = {0, 0, 0, 0, 0, 0, 0, 0}}

The file size is correct.






[ Post a follow-up to this message ]



    Re: Can not get large file size with LFS  
Andrei Voropaev


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-18-07 12:20 PM

On 2007-05-18, vian1381@china.com.cn <vian1381@china.com.cn> wrote:
> The debugger output in my application source code is shown below:
> (gdb) print buf
[...]
>= 0, st_pad2 = {0, 0}, st_size = {
>     _d = 1.8360945890051364e-314, _l = {0, -578670475}}, st_atim =
[...]
>
> When I debug the below code (copy to a new file, and compile with gcc -
> g XX.c -D_LARGE_FILE_SOURCE -
> D_FILE_OFFSET_BITS=64"):
[...]
> The debugger output is:
>   st_rdev = 0, st_pad2 = {0, 0}, st_size = 3716296821, st_atim =
[...]

That's interesting. The off_t in your "main" program is presented as
some sort of a structure instead of plain 64-bit integer as it is in
your "test" program. Looks like the flags that you use for compilation
of the main program (or some defines inside of code) are messed up.

--
Minds, like parachutes, function best when open





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:43 PM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register