[Libguestfs] [PATCH nbdkit 2/2] file: Allow a file descriptor to be passed to the plugin
Laszlo Ersek
lersek at redhat.com
Thu Aug 18 08:25:28 UTC 2022
On 08/17/22 23:56, Richard W.M. Jones wrote:
> On Wed, Aug 17, 2022 at 10:37:00PM +0100, Richard W.M. Jones wrote:
>> Is that actually possible? “fcntl (fd, F_GETFL) & O_WRONLY”
>> should do it?
>
> So the answer is no as it's a kind of tri-state.
>
> I think this should work (untested)?
>
> r = fcntl (fd, F_GETFL);
> if (r == -1) ...
> r &= O_ACCMODE;
> if (r == O_RDONLY)
> h->can_write = false;
>
> There's also the case where r == O_WRONLY which the plugin (and NBD)
> cannot deal with. Not sure what to do about that - error?
(after a bit of reading POSIX):
I think a switch statement should handle these; O_RDONLY and O_RDWR
intuitively, everything else (O_EXEC, O_SEARCH, O_WRONLY) should be
rejected.
Laszlo
More information about the Libguestfs
mailing list