Fix readonly_rootfs blocking writes to device files#2135
Fix readonly_rootfs blocking writes to device files#2135niklasfemerstrand wants to merge 1 commit intonanovms:masterfrom
Conversation
open() with O_WRONLY or O_RDWR on device files like /dev/null returns EROFS when readonly_rootfs is enabled. Device writes go to the driver, not the filesystem, so special files should be exempt from the read-only check. nanovms#2134
There was a problem hiding this comment.
This is a sensible fix, but I would like to take this opportunity to do some cleanup.
The get() call is somewhat expensive, as is does a table lookup, and we already have a couple of similarly expensive lookups in the same function in the form of is_dir() calls; then we have a file_type_from_tuple() call which can potentially re-do the same lookups again. It would be better to move the file_type_from_tuple() call at the top of the function, so we have the type variable which we can compare against known values in the rest of the function: so the is_dir() calls become type == FDESC_TYPE_DIRECTORY, and your fix would become if (type == FDESC_TYPE_REGULAR && filesystem_is_readonly(fs)) (regular files are the only file types where a write modifies the filesystem, so this is more accurate than testing against special files).
Thanks!
Fixes #2134
open()withO_WRONLYorO_RDWRon device files like/dev/nullreturnsEROFSwhenreadonly_rootfsis enabled. Device writes go to the driver, not the filesystem, so special files should be exempt from the read-only check.