From 6866feb73034b9af4678807573e75a847cc93f77 Mon Sep 17 00:00:00 2001 From: AlmAck Date: Sat, 29 Aug 2026 19:00:04 +0200 Subject: [PATCH] drivers/mtd/filemtd: open the backing file O_RDWR filemtd_initialize() opens its backing file with mode = O_RDONLY | O_WRONLY | O_CLOEXEC; Commit 6161c73639 introduced this when it replaced the non-standard O_RDOK | O_WROK pair, describing the change as a pure text substitution. That held while the access mode was a genuine bitmask: O_RDONLY was (1 << 0), O_WRONLY was (1 << 1), and O_RDWR was both bits, so the OR produced O_RDWR. O_ACCMODE was defined as an alias for O_RDWR. Commit 9e141acab3 then aligned the flags with Linux. The low two bits became an enumeration -- O_RDONLY 0, O_WRONLY 1, O_RDWR 2 -- and O_ACCMODE stopped being an alias for O_RDWR and became an independent mask of 3. OR-ing two members of that enumeration is no longer meaningful: O_RDONLY | O_WRONLY evaluates to 1, and masking it with O_ACCMODE yields O_WRONLY. The file is therefore opened write-only, and fs_read.c rejects every read on it with -EACCES. The failure does not name filemtd: on the simulator it surfaces as a LittleFS mount of a filemtd-backed partition returning -ENOSPC, after which nothing on that volume works. This appears to be an isolated miss rather than a pattern. Grepping the tree for the same construct -- two access-mode constants OR-ed together -- finds only this one call site. The one remaining place that bit-tests the mode, fs/xipfs/xipfs_vfs.c:606, happens to be correct under the new values (and would have been wrong under the old ones). The hostfs NUTTX_O_* mirror and host_oflags_convert() were updated in lockstep and switch on the masked value. Signed-off-by: AlmAck --- drivers/mtd/filemtd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/filemtd.c b/drivers/mtd/filemtd.c index 1ef36b84d6080..87c9e71022988 100644 --- a/drivers/mtd/filemtd.c +++ b/drivers/mtd/filemtd.c @@ -813,7 +813,7 @@ FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, off_t offset, /* Set the file open mode. */ - mode = O_RDONLY | O_WRONLY | O_CLOEXEC; + mode = O_RDWR | O_CLOEXEC; /* Try to open the file. NOTE that block devices will use a character * driver proxy.