nda*_*day 5 c++ linux ubuntu file-io disk
我正在尝试使用O_DIRECT标志打开一个文件.在Ubuntu上,程序以errno 22失败.我刚刚在同一台机器上安装了Fedora,双启动,这个完全相同的代码顺利运行.
我正在运行Ubuntu 13.10,内核3.12.6和g ++版本4.8.1和文件系统ext4.我刚刚安装的Fedora是版本20,内核为3.12.6.
#include <unistd.h>
#include <fcntl.h>
#include <iostream>
#include <errno.h>
using namespace std;
int main(void)
{
int filedesc = open("testfile.txt", O_RDWR | O_CREAT | O_APPEND | O_DIRECT);
if (filedesc < 0) {
std::cout << "fail with errno: " << errno << std::endl;
return -1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)