Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

O_RDWR vs. O_WRONLY #2861

Closed
christophgil opened this issue Feb 7, 2024 · 9 comments
Closed

O_RDWR vs. O_WRONLY #2861

christophgil opened this issue Feb 7, 2024 · 9 comments

Comments

@christophgil
Copy link

I am using msconvert through docker.
When the outfile is opened for writing the system function open() is invoked with flag O_RDWR.

Why not O_WRONLY?
The file is to be written right?

I am developing a fuse file system.
Interestingly, I have seen the flag O_RDWR in other MS-software where a file is read and not written and therefore
I used to treat O_RDWR as O_RDONLY. I think this software was also running in Wine.

Since O_RDWR is used with the intention to write here , my simple rule does not work any more.

Is this flag comming from Wine or from msconvert.ext?
How do you create the file pointer / file descriptor of the outfile?

Best
Christoph

@chambm
Copy link
Member

chambm commented Feb 7, 2024

If you're talking about a text format like mzML or mzXML, then it's opened with a boost::nowide::ofstream call in MSDataFile.cpp:openFile(). This boils down to:
_wfopen(filename, mode)
where mode is wb.

According to https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-170 the w mode should use _O_WRONLY. Checking the system call in Process Monitor, I see:

Operation:	CreateFile
Result:	SUCCESS
Path:	C:\dev\pwiz\xxxx.mzML
Desired Access:	Generic Write, Read Attributes
Disposition:	OverwriteIf
Options:	Synchronous IO Non-Alert, Non-Directory File
Attributes:	N
ShareMode:	Read, Write
AllocationSize:	0
OpenResult:	Overwritten

I'm not sure whether ShareMode or "Desired Access" having "Read" in it means it actually opened with _O_RDWR though. Stepping in deeper with the debug CRT doesn't make anything stick out at me about it being opened with read access.

So I'm guessing the mismatch is coming from Wine. But msvcrt_get_flags in https://gitlab.winehq.org/wine/wine/-/blob/master/dlls/msvcrt/file.c looks like it should also be using _O_WRONLY.

It strikes me as much stranger to see a file opened as O_RDWR when it's never written to. That would imply people opening read-only files with mode 'w+', 'a+', or 'r+'.

@christophgil
Copy link
Author

christophgil commented Feb 7, 2024 via email

@chambm
Copy link
Member

chambm commented Feb 7, 2024

By default the file extension gets overridden if it isn't one of the supported output formats' extensions (e.g. mzML, mzXML, mgf, mz5, etc.). You can override that override with --ext .tmp.

I am not at all surprised that the output to stdout does not work on Wine/Docker. The whole thing is basically indistinguishable from magic. ;)

@christophgil
Copy link
Author

christophgil commented Feb 7, 2024 via email

@christophgil
Copy link
Author

christophgil commented Feb 9, 2024 via email

@chambm chambm closed this as completed Feb 15, 2024
@christophgil
Copy link
Author

christophgil commented Apr 12, 2024 via email

@christophgil
Copy link
Author

christophgil commented Apr 12, 2024 via email

@chambm
Copy link
Member

chambm commented Apr 12, 2024

IIRC --outfile only changes the filename (useful for WIFF if you know it only has one sample because normally the sample name is automatically appended to the filename). To change the output path, use -o.

@chambm
Copy link
Member

chambm commented Apr 12, 2024

Oh maybe I should read all the posts before replying. :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants