-
Notifications
You must be signed in to change notification settings - Fork 2.1k
VFS Module does not reserve file descriptors 0, 1, and 2 #8309
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
Comments
This would affect other platforms too though right? |
Yes, but after further investigation I believe that the problem may be restricted to So there are two options that I have identified.
Personally, I am in favor of the second option, since otherwise there would be multiple copies of the code to maintain. Plus, I think there needs to be a |
I've written a fix for this. See Pull Request #8310. |
See an alternative solution in #8552, which does not require adding any new functions or dependencies between vfs and other modules. |
@gebart, thanks for your comments on this issue and in my Pull Request #8310. I agree that your solution in #8552 is cleaner, in the sense that VFS doesn't depend on other modules. However, it doesn't resolve that problem that printf() does not work in rtt_stdio (see Method #1 in the original description). The reason is that rtt_stdio doesn't bind the file descriptors 0, 1, and 2 if VFS is used, yet printf() writes to file descriptor 1 (stdout) when VFS is used. Basically, if you look at the comment I made above, my solution uses Option 2, and yours uses Option 1. But to make Option 1 work, we also need to duplicate the binding logic used by uart_stdio, in rtt_stdio. I've opened Pull Request #8654 that does just that. In essence, your solution in #8552 fixes the first half of the problem, that VFS could bind file descriptors 0, 1, and 2 to other files, causing printf() to be redirected to those files. But we also need #8654 to fix the second half of the problem, which is that rtt_stdio needs to allocate those file descriptors so that printf() works. |
Description
The VFS module does not reserve file descriptors 0, 1, and 2 for stdin, stdout, and stderr. As a result, the following bugs exist:
printf
do not work. The output is written to file descriptor 1 anduart_stdio_write
never gets called.More generally, there seems to be no
vfs_init
procedure, so it seems that all the_vfs_open_files
array is unintialized. In my opinion, the correct solution is to add avfs_init
procedure that initializes the_vfs_open_files
array and reserves file descriptors 0, 1, and 2.Steps to reproduce the issue
Method 1: Call printf().
Method 2: Open a socket with the posix_sockets module.
Expected results
Expected Results for Method 1: The output is written to the screen.
Expected Results for Method 2: The resulting file descriptor is greater than 2.
Actual results
Actual Results for Method 1: Nothing is written to the screen.
Actual Results for Method 2: The resulting file descriptor is 0.
Versions
I am building the code from a Linux computer running Ubuntu 16.04.
The platform I am targeting is HAMILTON (@immesys).
Output from
print_toolchain_versions.sh
:The text was updated successfully, but these errors were encountered: