Source code for the Trusted Boot Module.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
tbm-mcu/source/fs/mufs/path.c

68 lines
1.2 KiB

#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <flash.h>
#include <macros.h>
#include <fs/mufs.h>
#include "dir.h"
#include "path.h"
#include "tree.h"
int mufs_mkpath(struct mufs *fs, const char *path, unsigned type)
{
struct mufs_dirent dirent;
struct mufs_tree *tree;
size_t len;
char *s;
char *name;
if (!path || *path == '\0')
return -1;
if (!(s = mufs_abspath(path)))
return -1;
/* TODO: already exists. */
if (resolve_path(fs, s)) {
free(s);
return 0;
}
if (!(name = strrchr(s, '/'))) {
name = s;
s = "/";
} else {
*name++ = '\0';
}
if (*name == '\0')
return -1;
if (!(tree = resolve_path(fs, s)))
return -1;
len = min(strlen(name), sizeof(dirent.path) - 1);
memcpy(dirent.path, name, len);
dirent.path[len] = '\0';
dirent.type = type;
dirent.tree.fs = fs;
dirent.tree.file_size = 0;
dirent.tree.root = 0;
dirent.tree.depth = 0;
if (!is_aligned(tree->file_size, fs->dev->log2_block_size) &&
write_dirent(tree, tree->file_size, &dirent) > 0)
return 0;
if (write_dirent(tree, align_up(tree->file_size,
fs->dev->log2_block_size), &dirent) > 0)
return 0;
return -1;
}