I'm developing a program which need to access a special USB device. This USB device acts as a regular file in filesystem, so I have to open this file with O_DIRECT flag. As follow:
open(pathname, O_CREAT | O_RDWR | O_DIRECT | O_SYNC, S_IRWXU)
The program works well on PC environment. But when I port it to embedded board with openwrt, the "open" function returns EINVAL 22 /* Invalid argument */.
- O_DIRECT support is selected in kernel configuration.
- The filesystem of openwrt is squashfs and jffs2.
- The filesystem of USB device is fat, and mounted on /media/aegis directory.
- The ARCH of board is mips.
It seems that error is returned from following function in kernel:
int open_check_o_direct(struct file *f)
{
/* NB: we're sure to have correct a_ops only after f_op->open */
if (f->f_flags & O_DIRECT) {
if (!f->f_mapping->a_ops ||
((!f->f_mapping->a_ops->direct_IO) &&
(!f->f_mapping->a_ops->get_xip_mem))) {
return -EINVAL;
}
}
return 0;
}
Is it known that O_DIRECT isn't supported on jffs2 and supported on fat. When operating on file in /media/aegis I guess the a_ops of fat is used, but program doesn't run in my expectation.