zephyr/subsys/fs/fs_impl.c
Peter A. Bigot 312f05eaef subsys/fs: add implementation helper module
File system API functions that operate on paths are passed both the
absolute path including the mount point prefix, and the mount point
within which the path lies.

Unfortunately it's not entirely trivial to convert an arbitrary path
within the file system space to an absolute path within its mount point,
because the path may be to the mount point itself and not end with a
directory separator.  The effect is that a file system implementation
like nffs may be given an empty path when "/" is required.

Add an implementation module that does this transformation and use it to
transform paths within each filesystem wrapper.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-07-22 12:46:50 +02:00

23 lines
401 B
C

/*
* Copyright (c) 2019 Peter Bigot Consulting, LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <fs/fs.h>
#include "fs_impl.h"
const char *fs_impl_strip_prefix(const char *path,
const struct fs_mount_t *mp)
{
static const char *const root = "/";
if ((path == NULL) || (mp == NULL)) {
return path;
}
path += mp->mountp_len;
return *path ? path : root;
}