Hello.
What purpose of value 3 in File-sink-file-mode?
Here code which open file for writing from gstfilesink.c +156:
int fd;
int flags = O_CREAT | O_WRONLY;
/* NOTE: below code is for handing spurious EACCES return on write
* See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/143
*/
if (strcmp (mode, "wb") == 0)
flags |= O_TRUNC;
else if (strcmp (mode, "ab") == 0)
flags |= O_APPEND;
else if (strcmp (mode, "rb+") == 0) // <- our case
flags |= O_RDWR;
else
g_assert_not_reached ();
if (o_sync)
flags |= O_SYNC;
fd = open (filename, flags, 0666);
if (fd < 0)
return NULL;
retval = fdopen (fd, mode);
return retval;
Open flags init value will be O_CREAT | O_WRONLY (at this point we don’t care about O_CREATE or other higher bits), so open mode will be 0x01
Then if property of File-sink-file-mode is overwrite (3), then is add O_RDWR flag and open mode becomes 0x03! Maybe that’s not how it was intended.
man 2 open on linux says:
Unlike the other values that can be specified in flags, the access mode values O_RDONLY, O_WRONLY, and O_RDWR do not specify individual bits. Rather, they define the low order two bits of flags, and are defined respectively as 0, 1, and 2.In other words, the combination O_RDONLY | O_WRONLY is a logical error, and certainly does not have the same meaning as O_RDWR.
Linux reserves the special, nonstandard access mode 3 (binary 11) in flags to mean: check for read and write permission on the file and return a file descriptor that can't be used for reading or writing. This nonstandard access mode is used by some Linux drivers to return a file descriptor that is to be used only for device-specific ioctl(2) operations.
This is really used for some rare writing operations with linux drivers?
If not, please tell me true purpose of this mode. It’s interesting.