|
From: Stefan S. <dev...@gm...> - 2012-07-09 12:54:34
|
Hi, On 07/09/2012 02:20 PM, Goswin von Brederlow wrote: > On Fri, Jul 06, 2012 at 08:18:04PM +0200, Stefan Schoenleitner wrote: >> Hi, >> >> according to the documentation [1,2] the CUSE/FUSE open callback >> function includes the flags that were given to the open() call. >> To my surprise these flags do not seem to be passed correctly. >> I used strace to trace a simple 'echo test > /dev/cusedev' and discovered that >> the flags provided to the open call are O_WRONLY|O_CREAT|O_TRUNC (0x0241). >> However, the flags in the CUSE open callback (fi->flags) are set to 0x8001 >> which leads to wrong results of course. >> Is this a bug in fuse-2.9.0, or is this intentional for some reason ? >> >> Cheers, >> Stefan >> >> [1] http://sourceforge.net/apps/mediawiki/fuse/index.php?title=Fuse_file_info >> [2] http://fuse.sourceforge.net/doxygen/structfuse__file__info.html > > /usr/include/fuse/fuse.h > > /** File open operation > * > * No creation (O_CREAT, O_EXCL) and by default also no > * truncation (O_TRUNC) flags will be passed to open(). If an > * application specifies O_TRUNC, fuse first calls truncate() > * and then open(). Only if 'atomic_o_trunc' has been > * specified and kernel version is 2.6.24 or later, O_TRUNC is > * passed on to open. thank you for the information. For CUSE, there is no truncate() or setattr() callback. How do I know whether these flags were specified in the open() call to the CUSE device ? For testing purposes, I forwarded any open/read/write calls to a regular file. In case truncate was called on the file, it seems to have had no effect. In case of a write operation to the CUSE device, the file is overwritten with the content, but not truncated. In my proxy, I guess I could just always use these flags whenever they make sense. So, if there is a call to open, I would always specify O_CREAT in the call to the real open(). And I would also add O_TRUNC, in case the file exists and O_APPEND is not set. Do you think this would work ? However, I wonder if truncation or file creation is relevant at all for character devices. After all, my goal is to pass on any communication with a character device to the (existing) character device on a remote host. Maybe this is also the reason why these flags are not passed on by FUSE/CUSE ? > > MfG > Goswin Cheers, Stefan |