jingfei195887 opened a new pull request, #21720:
URL: https://github.com/apache/nuttx/pull/21720
## Summary
Two fixes in the userfs kernel driver.
- **fs/userfs: fix the response codes of truncate and chstat.**
`userfs_chstat()` expects `USERFS_RESP_STAT`, but the daemon side in
`lib_userfs.c` replies with `USERFS_RESP_CHSTAT`, so every chmod, chown
or utimens through userfs fails with EIO. `userfs_truncate()` and the
daemon both use `USERFS_RESP_FSTAT` for a truncate and only agree by
sharing the wrong code; add `USERFS_RESP_TRUNCATE` and use it on both
sides.
- **fs/userfs: keep f_pos in step with the daemon.** `userfs_read()`,
`userfs_write()` and `userfs_seek()` never update `filep->f_pos`.
`file_seek()` returns `f_pos`, so `lseek(fd, 0, SEEK_CUR)` keeps
reporting the position of the open, and `pread()`/`pwrite()` restore
that stale offset afterwards, so the next `write()` lands at the wrong
place.
## Impact
`USERFS_RESP_TRUNCATE` is inserted after `USERFS_RESP_FSTAT`, so the
values of the later response codes change. The kernel driver and
`lib_userfs.c` are built together, but an out-of-tree daemon that hard
codes these values must be rebuilt.
## Testing
Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master
e14f23226b (rebased onto 5fbae0c401; no
new commit touches userfs), `sim:nsh` with `CONFIG_NET_LOOPBACK`,
`CONFIG_NET_UDP`, `CONFIG_FS_USERFS` and `CONFIG_EXAMPLES_USERFS`. The
`userfs` example mounts `/mnt/ufstest`; a small test program then works
on `/mnt/ufstest/File1` ("This is file 1"):
| step | master | this PR |
|---|---|---|
| `chmod(0644)` | -1, EIO | 0 |
| `read(4)`, then `lseek(SEEK_CUR)` | 0 | 4 |
| `read(4)`, then `lseek(SEEK_CUR)` | 0 | 8 |
| `pread(2, offset 0)`, then `lseek(SEEK_CUR)` | 0 | 8 |
| `write("XY")`, then `lseek(SEEK_CUR)` | 0 | 10 |
| `pread(4, offset 6)` | "s fi" (the write went to offset 0) | "s XY" |
The example daemon returns ENOSYS for truncate, so the truncate response
code is covered by review only.
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- Make and CMake builds pass; `ostest` exits with status 0.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]