diff --git a/libs/libc/misc/Kconfig b/libs/libc/misc/Kconfig index 4a7635e5333..fc7de51b7d8 100644 --- a/libs/libc/misc/Kconfig +++ b/libs/libc/misc/Kconfig @@ -62,6 +62,12 @@ config LIBC_ENVPATH Use the contents of the common environment variable to locate executable or library files. Default: n +config LIBC_FTOK_VFS_PATH + string "Relative path to ftok storage" + default "/var/ftok" + ---help--- + The relative path to where ftok will exist in the root namespace. + config LIBC_MEM_FD_VFS_PATH string "Relative path to memfd storage" default "memfd" diff --git a/libs/libc/misc/lib_ftok.c b/libs/libc/misc/lib_ftok.c index 6d38ed62b18..faaddc2c34f 100644 --- a/libs/libc/misc/lib_ftok.c +++ b/libs/libc/misc/lib_ftok.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include /**************************************************************************** * Public Functions @@ -56,11 +58,19 @@ key_t ftok(FAR const char *pathname, int proj_id) { + char fullpath[PATH_MAX] = CONFIG_LIBC_FTOK_VFS_PATH "/"; struct stat st; - if (stat(pathname, &st) < 0) + strlcat(fullpath, pathname, sizeof(fullpath)); + if (stat(fullpath, &st) < 0 && get_errno() == ENOENT) { - return (key_t)-1; + /* Directory not exist, let's create one for caller */ + + mkdir(fullpath, S_IRWXU); + if (stat(fullpath, &st) < 0) + { + return (key_t)-1; + } } return ((key_t)proj_id << 24 |