fs/inode: add POSIX path-resolution infrastructure - #19950
Conversation
|
|
@Kaben123 please fix: |
066e6d8 to
661c2d0
Compare
0d54467 to
18127da
Compare
|
@xiaoxiang781216 Could you help re-run CI on this PR when convenient? The only failing job — This is a CI infrastructure hiccup cloning the Note the previously failing |
|
Hi @Kaben123 please rebase |
18127da to
0ccee60
Compare
2f0c845 to
2530ca7
Compare
2530ca7 to
78b772d
Compare
|
ci was fixed, please rebase your change to the last master. @Kaben123 |
When resolving a symbolic link target, call the public inode_search() instead of the internal _inode_search() so that the link target path is first formatted (leading '/' handling and relative-path conversion) before the lookup. This ensures link targets are resolved through the same normalization path as ordinary lookups. Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
An empty pathname does not name any inode. Return -ENOENT early in inode_search() when the path is an empty string, instead of continuing into the search logic with a zero-length path. Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
While walking the path components, a non-final component must refer to a directory. When descending into a child, verify the parent inode is a pseudo directory; if it is not, stop the search and return -ENOTDIR as required by POSIX for a path prefix that is not a directory. Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
Replace the fs_heap_asprintf()/fs_heap_free() based allocation of the path buffer in the inode search with the lib_get_tempbuffer()/ lib_put_tempbuffer() pool. Fixed PATH_MAX sized temporary buffers avoid per-call heap allocation and keep the buffer allocator consistent with the rest of the path-resolution code. Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
Add support for resolving relative path components (in particular the ".." parent references) during the inode search. A helper _compute_path_depth() computes the remaining path depth so that a mount point is only treated as the terminal node when the depth is positive, and "../" components walk back up to the parent inode. Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
example: stat(".", buf) and stat("..", buf)
Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
Add a helper _inode_checkpath() that validates the path before the search: it returns -ENOENT for an empty path and -ENAMETOOLONG when any single path component exceeds NAME_MAX or the whole path exceeds PATH_MAX. inode_search() now runs this check first so that oversized paths and file names are rejected with the correct POSIX error code. Signed-off-by: guohao15 <guohao15@xiaomi.com>
The _inode_checkpath function uses `namelen < NAME_MAX` to validate path segment lengths. When a filename is exactly NAME_MAX characters long and is followed by more path segments (e.g. /dir/), the loop exits with namelen == NAME_MAX before processing the '/' separator, causing a spurious ENAMETOOLONG error. Per POSIX, NAME_MAX is the maximum number of bytes in a filename not including the terminating null, so a filename of exactly NAME_MAX characters is valid. Change the condition to `namelen <= NAME_MAX` so the loop can process the trailing '/' separator and correctly reset namelen for the next path segment. Signed-off-by: wangxingxing <wangxingxing@xiaomi.com>
…ssert
The esp32s3-devkit:usbmsc config uses CONFIG_ESPRESSIF_SIMPLE_BOOT, so
the image is packaged with "esptool elf2image --ram-only-header". With
esptool v5.2.0, that path asserts that each flash segment satisfies
(f.tell() + 8 + BOOTLOADER_FLASH_OFFSET) % IROM_ALIGN
== segment.addr % IROM_ALIGN
When .flash.text lands right on a 64 KB (IROM_ALIGN) boundary the
assertion cannot be satisfied and elf2image fails with AssertionError,
even though NuttX itself links cleanly.
usbmsc is a plain C test and does not need the C++ runtime. Disabling
CONFIG_HAVE_CXX / CONFIG_HAVE_CXXINITIALIZE moves .flash.text off the
IROM_ALIGN boundary so the SIMPLE_BOOT image can be generated, without
changing the boot mode or the test's intent.
Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
78b772d to
c036807
Compare
Summary
This PR adds POSIX path-resolution infrastructure to
inode_search(). It isindependent of the hardlink infrastructure PR (both are based on master and
can be reviewed in parallel), and provides the path-canonicalization
primitives that later bug-fix PRs depend on.
Changes (one upstream commit each), all touching only
fs/inode/fs_inodesearch.candfs/inode/inode.h:moves the inode search-path buffer allocation onto the temp-buffer pool
(updates the
RELEASE_SEARCHmacro anddesc->buffer). This keeps theallocator consistent across the whole path-resolution logic.
Impact
(
ENOENT/ENOTDIR/ENAMETOOLONG) and correctly handles relative pathsand
./..segments.lib_get_tempbuffer/lib_put_tempbufferconsistently (commit 4), so the allocation and release paths match.
Testing
sim:nsh— zero errors/warnings.tools/checkpatch.shpasses on all changed lines.This is part of a filesystem enhancement stack. It is independent of the
hardlink infrastructure PR and can be merged in either order. A later bug-fix
PR depends on both this PR and the hardlink/backends PRs.