将文件写入磁盘超过大小限制
Writing files to disk more than the size limitation
测试在 64-bit x86
Linux。
我有一些 x86 32-bit
汇编代码,它试图将大量日志数据写入磁盘。它是这样的:
logging_flush:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl , %esp
movl 8, 8(%esp) <--- 666
movl 89, 4(%esp) <--- O_WRONLY|O_APPEND|O_CREAT
movl $.LC1, (%esp)
call open
movl %eax, 28(%esp)
movl $buf, %eax
movl [=10=]x1000000, 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
,但它就是行不通..我在这里错过了什么吗?谁能帮我调整一下上面的汇编代码?
您需要使用 O_LARGEFILE
。见 man open:
O_LARGEFILE
(LFS) Allow files whose sizes cannot be represented in an off_t (but can be represented in an off64_t) to be opened.
因此,代码可能如下所示:
# O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE
movl [=10=]x1|0x40|0x400|0x8000, 4(%esp)
测试在 64-bit x86
Linux。
我有一些 x86 32-bit
汇编代码,它试图将大量日志数据写入磁盘。它是这样的:
logging_flush:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl , %esp
movl 8, 8(%esp) <--- 666
movl 89, 4(%esp) <--- O_WRONLY|O_APPEND|O_CREAT
movl $.LC1, (%esp)
call open
movl %eax, 28(%esp)
movl $buf, %eax
movl [=10=]x1000000, 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
,但它就是行不通..我在这里错过了什么吗?谁能帮我调整一下上面的汇编代码?
您需要使用 O_LARGEFILE
。见 man open:
O_LARGEFILE (LFS) Allow files whose sizes cannot be represented in an off_t (but can be represented in an off64_t) to be opened.
因此,代码可能如下所示:
# O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE
movl [=10=]x1|0x40|0x400|0x8000, 4(%esp)