将文件写入磁盘超过大小限制

时间:2015-07-19 02:55:14

标签: assembly x86 x86-64 file-writing

测试在64-bit x86 Linux上进行。

我有一些x86 32-bit汇编代码,它试图将大量日志数据写入磁盘。它是这样的:

logging_flush:
pushl   %ebp
movl    %esp, %ebp
andl    $-16, %esp
subl    $32, %esp
movl    $438, 8(%esp)       <--- 666
movl    $1089, 4(%esp)      <--- O_WRONLY|O_APPEND|O_CREAT
movl    $.LC1, (%esp)
call    open
movl    %eax, 28(%esp)
movl    $buf, %eax
movl    $0x1000000, 8(%esp)
movl    %eax, 4(%esp)
movl    28(%esp), %eax
movl    %eax, (%esp)
call    write
movl    28(%esp), %eax
movl    %eax, (%esp)
call    close
leave
ret

section .rodata
.LC1:
.string "trace.bin"

但是,由于大小限制,转储日志文件的大小不会大于2G

我试图以这种方式编译我的代码:

gcc final.s -D_FILE_OFFSET_BITS=64 -m32 -lm

但是没有字节可以写入日志文件..

我也尝试使用fopen64,但它无法正常工作..我在这里错过了什么吗?任何人都可以帮我调整上面的汇编代码吗?

1 个答案:

答案 0 :(得分:3)

您需要使用O_LARGEFILE。见man open

  

O_LARGEFILE       (LFS)允许打开大小无法在off_t中表示(但可以在off64_t中表示)的文件。

所以,代码看起来像这样:

# O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE
movl    $0x1|0x40|0x400|0x8000, 4(%esp)