0

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.

feyeye
  • 1
  • possible duplicate of [O\_DIRECT support on a jffs2 Linux filesystem](http://stackoverflow.com/questions/6030002/o-direct-support-on-a-jffs2-linux-filesystem) – SSC Nov 28 '14 at 03:49
  • How is the USB `direct_IO`? XIP is for memory mapped NOR type devices. You need the USB driver to transfer the pages across the USB bus to memory. The CPU can not directly access the USB **BUS**. – artless noise Dec 01 '14 at 23:06

0 Answers0