ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
fs_path.h File Reference

Shared filesystem path helpers for the file-transfer servers (SFTP / SCP, and the pattern the static file server + WebDAV also use): join a mount root with a request subpath and reject .. traversal - the single choke point that keeps a request from escaping its mount. More...

#include "protocore_config.h"
#include "shared_primitives/strbuf.h"
#include <stddef.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Functions

bool fs_path_join (const char *root, const char *sub, char *out, size_t cap)
 Join a filesystem root and a sub path into out, normalizing the separator.
 
int fs_path_resolve (const char *root, const char *sub, char *out, size_t cap)
 Resolve a mount root + a request sub path to an on-disk path in out: reject any .. traversal, join onto the root, and drop a trailing '/'.
 

Detailed Description

Shared filesystem path helpers for the file-transfer servers (SFTP / SCP, and the pattern the static file server + WebDAV also use): join a mount root with a request subpath and reject .. traversal - the single choke point that keeps a request from escaping its mount.

Pure string logic (no fs::FS, no heap, no stdlib) so it is host-testable and identical on device + host. The guard is a substring reject (not realpath/symlink resolution) - the on-flash filesystems (FAT / LittleFS) have no symlinks, so a ..-free joined path cannot escape the root.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file fs_path.h.

Function Documentation

◆ fs_path_join()

bool fs_path_join ( const char *  root,
const char *  sub,
char *  out,
size_t  cap 
)
inline

Join a filesystem root and a sub path into out, normalizing the separator.

Returns
false on overflow.

Definition at line 29 of file fs_path.h.

References pc_sb_finish(), and pc_sb_put().

Referenced by fs_path_resolve().

◆ fs_path_resolve()

int fs_path_resolve ( const char *  root,
const char *  sub,
char *  out,
size_t  cap 
)
inline

Resolve a mount root + a request sub path to an on-disk path in out: reject any .. traversal, join onto the root, and drop a trailing '/'.

Returns
0 on success, -1 on a traversal attempt (.. present), -2 if the joined path would overflow out.

Definition at line 58 of file fs_path.h.

References fs_path_join().