如何将 mmap 输入内存写入 O

编程入门 行业动态 更新时间:2024-10-25 18:36:34
本文介绍了如何将 mmap 输入内存写入 O_DIRECT 输出文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么不遵循伪代码工作(O_DIRECT 结果为 EFAULT)

why doesn't following pseudo-code work (O_DIRECT results in EFAULT)

in_fd = open("/dev/mem"); in_mmap = mmap(in_fd); out_fd = open("/tmp/file", O_DIRECT); write(out_fd, in_mmap, PAGE_SIZE);

虽然跟随(没有 O_DIRECT)

while following does (no O_DIRECT)

in_fd = open("/dev/mem"); in_mmap = mmap(in_fd); out_fd = open("/tmp/file"); write(out_fd, in_mmap, PAGE_SIZE);

我猜是虚拟内核页面到虚拟用户页面的问题,在写入调用中无法转换?

I guess it's something with virtual kernel pages to virtual user pages, which cannot be translated in the write call?

最好的问候,

弗里德里希

推荐答案

将 mmap() 与 O_DIRECT 一起使用很棘手.有一些限制.文件的输出应该是块对齐的.例如,如果您将 mmap() 中的偏移量设置为 0,您的代码将起作用.您必须检查文件系统的块大小才能正确设置该值.

Using mmap() with O_DIRECT is tricky. There are some restrictions. The output to the file should be block aligned. For example, if you set offset in mmap() to 0 your code will work. You have to check the block size of your filesystem to set that value properly.

更多推荐

如何将 mmap 输入内存写入 O

本文发布于:2023-08-01 04:31:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1265239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   内存   mmap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!