Hi,
If I understand correctly we can add one single "dummy_read" implementation
for all drivers that do not supply the read method. This will ensure that
O_RDOK is always supported if file permissions allow it. By doing so we can
relax check in inode_checkflags() to:
int inode_checkflags(FAR struct inode *inode, int oflags)
{
if ((oflags == 0) ||
(oflags & O_WROK) != 0 && !inode->u.i_ops->write)
{
return -EACCES;
}
else
{
return OK;
}
}
Also the "0" oflags will not be allowed.
If yes, then I'm happy to submit the change. Otherwise please correct me if
I'm wrong.
Best regards,
Petro
сб, 2 квіт. 2022 р. о 08:06 Jukka Laitinen <[email protected]> пише:
> As Greg said, this is a traditional way. I'd maybe allow dummy
> reads/writes if permissions allow, but keep that logic in vfs by checking
> if the pointer is initialized. Then you don't need to provide the dummy
> implementation in every driver.
>
> Petro Karashchenko kirjoitti lauantai 2. huhtikuuta 2022:
> > Hello Gregory,
> >
> > Do you recommend not to allow registration of a driver that does not have
> > read method and make a requirement for the driver to provide at least
> dummy
> > read?
> >
> > Best regards,
> > Petro
> >
> > On Fri, Apr 1, 2022, 9:48 PM Gregory Nutt <[email protected]> wrote:
> >
> > >
> > > > One option, conforming standard, would be that you just always give
> > > O_RDWR (same flags as what linux devices have), but then when calling
> > > read/write you check if the pointer is non-null. If the driver doesn't
> > > define read or write, those operations are allowed on the device, but
> act
> > > as no-op.
> > >
> > > If you can't think of anything useful to do with read() or write(),
> > > thenthis has been historically handled is by including a dummy read
> > > method in the driver that just returns zero (EOF). For example, the
> > > loop driver:
> > >
> > >
> > >
> /****************************************************************************
> > > * Name: loop_read
> > >
> > >
> ****************************************************************************/
> > >
> > > static ssize_t loop_read(FAR struct file *filep, FAR char *buffer,
> > > size_t len)
> > > {
> > > return 0; /* Return EOF */
> > > }
> > > *
> > > *
> > >
> >