Repository navigation
Conversation
|
194c2b4 to
0324aea
Compare
| { | ||
| case SEEK_CUR: | ||
| newpos = filep->f_pos + offset; | ||
| base = filep->f_pos; |
There was a problem hiding this comment.
I changed this to avoid signed overflow in f_pos + offset. SEEK_CUR now uses the same bounds check as SEEK_END before adding the offset.
| } | ||
|
|
||
| ret = bchlib_read(bch, buffer, filep->f_pos, len); | ||
| ret = bch_limit_transfer(bch, filep->f_pos, &len); |
There was a problem hiding this comment.
bchlib_read already done the check, why need check here again?
There was a problem hiding this comment.
bchlib_read() checks the device boundary. bch_limit_transfer() checks whether advancing f_pos after the transfer will still fit in off_t. For example, on a device of NX_OFF_MAX + 1 bytes, a two byte read from NX_OFF_MAX - 1 fits on the device and would advance f_pos past its limit. The driver caps that read at one byte. The write path applies the same check before doing I/O.
Use off_t for register_driver_with_size() and the inode size so large-file builds can retain capacities larger than size_t. Keep memory-backed pseudofile operations within their allocation limits. Signed-off-by: ocadovski <ognjen.cadovski@robbit.rs>
Register the character device with the byte capacity of the backing block device. Use blkcnt_t for sector counts and indices, and check seek and transfer positions against the off_t limit. Report zero for capacities outside the range of off_t. Preserve the character-device type and permissions. Document how to query the underlying MTD geometry. Refs: apache#16074 Signed-off-by: ocadovski <ognjen.cadovski@robbit.rs>
0324aea to
b551aa5
Compare
Summary
Refs #16074. Pathname
stat()succeeds on a BCH character device butcurrently reports
st_size = 0because the node registers without a size.Use the block geometry BCH already holds to register its exposed byte
length when it fits in
off_t.Impact
The BCH node remains a character device with the same permissions.
Unrepresentable lengths continue to report zero. This change does not
make pathname
stat()identify the backing MTD device. Documentationdescribes the distinction and points to
MTDIOC_GEOMETRY.Testing
Kubuntu host, NuttX simulator, RAM-backed MTD partition with FTL and BCH:
Passed with and without large-file support. The 64 KiB capacity matched
fstat()andSEEK_END, and the control devices were unchanged.ELF32 i386 simulator: ten synthetic geometry cases passed with 32-bit
size_tand both 32-bit and 64-bitoff_t, including the boundariesat 2 GiB and 4 GiB. An unrepresentable size reported zero without
preventing registration.
tools/checkpatch.shpassed.ESP32-DevKitC-32UE hardware (ESP32-D0WD-V3 revision 3.1)
Built both images on Kubuntu using the same Xtensa toolchain and
esp32-devkitc:nshWROOM32 configuration with BCH, FTL and RAM-backedMTD enabled. Both images booted to NSH after esptool verified their
writes. Ran
bchstatagainst a 64 KiB RAM-backed MTD partition on theboard, not real flash media:
SEEK_ENDandMTDIOC_GEOMETRYreturned 65536 in both builds.