complete upgrade nffs to 1.0.0
This commit is contained in:
1 parent
868395efce
commit
efd8c48538
23 files changed
+616
-48
No files matched your search
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef __DISK_H__
|
||||
#define __DISK_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
#include <os/queue.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DISK_EOK 0 /* Success */
|
||||
#define DISK_EHW 1 /* Error accessing storage medium */
|
||||
#define DISK_ENOMEM 2 /* Insufficient memory */
|
||||
#define DISK_ENOENT 3 /* No such file or directory */
|
||||
#define DISK_EOS 4 /* OS error */
|
||||
#define DISK_EUNINIT 5 /* File system not initialized */
|
||||
|
||||
struct disk_ops {
|
||||
int (*read)(uint8_t, uint32_t, void *, uint32_t);
|
||||
int (*write)(uint8_t, uint32_t, const void *, uint32_t);
|
||||
int (*ioctl)(uint8_t, uint32_t, void *);
|
||||
|
||||
SLIST_ENTRY(disk_ops) sc_next;
|
||||
};
|
||||
|
||||
int disk_register(const char *disk_name, const char *fs_name, struct disk_ops *dops);
|
||||
struct disk_ops *disk_ops_for(const char *disk_name);
|
||||
char *disk_fs_for(const char *disk_name);
|
||||
char *disk_name_from_path(const char *path);
|
||||
char *disk_filepath_from_path(const char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
pkg.name: fs/disk
|
||||
pkg.description: Disk management layer to glue filesystems to disk devices.
|
||||
pkg.author: "Apache Mynewt <dev@mynewt.incubator.apache.org>"
|
||||
pkg.homepage: "http://mynewt.apache.org/"
|
||||
pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- kernel/os
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <syscfg/syscfg.h>
|
||||
#include <disk/disk.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct disk_info {
|
||||
const char *disk_name;
|
||||
const char *fs_name;
|
||||
struct disk_ops *dops;
|
||||
|
||||
SLIST_ENTRY(disk_info) sc_next;
|
||||
};
|
||||
|
||||
static SLIST_HEAD(, disk_info) disks = SLIST_HEAD_INITIALIZER();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
int disk_register(const char *disk_name, const char *fs_name, struct disk_ops *dops)
|
||||
{
|
||||
struct disk_info *info = NULL;
|
||||
struct disk_info *sc;
|
||||
|
||||
SLIST_FOREACH(sc, &disks, sc_next) {
|
||||
if (strcmp(sc->disk_name, disk_name) == 0) {
|
||||
return DISK_ENOENT;
|
||||
}
|
||||
}
|
||||
|
||||
info = malloc(sizeof(struct disk_info));
|
||||
if (!info) {
|
||||
return DISK_ENOMEM;
|
||||
}
|
||||
|
||||
info->disk_name = disk_name;
|
||||
info->fs_name = fs_name;
|
||||
info->dops = dops;
|
||||
|
||||
SLIST_INSERT_HEAD(&disks, info, sc_next);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct disk_ops *
|
||||
disk_ops_for(const char *disk_name)
|
||||
{
|
||||
struct disk_info *sc;
|
||||
|
||||
if (disk_name) {
|
||||
SLIST_FOREACH(sc, &disks, sc_next) {
|
||||
if (strcmp(sc->disk_name, disk_name) == 0) {
|
||||
return sc->dops;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
disk_fs_for(const char *disk_name)
|
||||
{
|
||||
struct disk_info *sc;
|
||||
|
||||
if (disk_name) {
|
||||
SLIST_FOREACH(sc, &disks, sc_next) {
|
||||
if (strcmp(sc->disk_name, disk_name) == 0) {
|
||||
return ((char *) sc->fs_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
disk_name_from_path(const char *path)
|
||||
{
|
||||
char *colon;
|
||||
uint8_t len;
|
||||
char *disk;
|
||||
|
||||
colon = (char *) path;
|
||||
while (*colon && *colon != ':') {
|
||||
colon++;
|
||||
}
|
||||
|
||||
if (*colon != ':') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = colon - path;
|
||||
disk = malloc(len + 1);
|
||||
if (!disk) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(disk, path, len);
|
||||
disk[len] = '\0';
|
||||
|
||||
return disk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the path with the disk prefix removed (if found)
|
||||
*
|
||||
* Paths should be given in the form disk<number>:/path. This routine
|
||||
* will parse and return only the path, removing the disk information.
|
||||
*/
|
||||
char *
|
||||
disk_filepath_from_path(const char *path)
|
||||
{
|
||||
char *colon;
|
||||
char *filepath;
|
||||
size_t len;
|
||||
|
||||
colon = (char *) path;
|
||||
while (*colon && *colon != ':') {
|
||||
colon++;
|
||||
}
|
||||
|
||||
if (*colon != ':') {
|
||||
filepath = strdup(path);
|
||||
} else {
|
||||
colon++;
|
||||
len = strlen(colon);
|
||||
filepath = malloc(len);
|
||||
memcpy(filepath, colon, len);
|
||||
filepath[len] = '\0';
|
||||
}
|
||||
|
||||
return filepath;
|
||||
}
|
||||
@@ -79,6 +79,11 @@ int fs_dirent_is_dir(const struct fs_dirent *);
|
||||
#define FS_EACCESS 12 /* Operation prohibited by file open mode */
|
||||
#define FS_EUNINIT 13 /* File system not initialized */
|
||||
|
||||
#define FS_NMGR_ID_FILE 0
|
||||
|
||||
#define FS_NMGR_MAX_MSG 400
|
||||
#define FS_NMGR_MAX_NAME 64
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <os/queue.h>
|
||||
|
||||
/*
|
||||
* Common interface filesystem(s) provide.
|
||||
*/
|
||||
@@ -52,12 +54,41 @@ struct fs_ops {
|
||||
int (*f_dirent_is_dir)(const struct fs_dirent *dirent);
|
||||
|
||||
const char *f_name;
|
||||
|
||||
SLIST_ENTRY(fs_ops) sc_next;
|
||||
};
|
||||
|
||||
/*
|
||||
* Currently allow only one type of FS, starts at root.
|
||||
struct fops_container {
|
||||
struct fs_ops *fops;
|
||||
};
|
||||
|
||||
/**
|
||||
* Registers a new filesystem interface
|
||||
*
|
||||
* @param fops filesystem operations table
|
||||
*
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
int fs_register(const struct fs_ops *);
|
||||
int fs_register(struct fs_ops *fops);
|
||||
|
||||
/**
|
||||
* Will look for the number of registered filesystems and will return
|
||||
* the fops if there is only one.
|
||||
*
|
||||
* @return fops if there's only one registered filesystem, NULL otherwise.
|
||||
*/
|
||||
struct fs_ops *fs_ops_try_unique(void);
|
||||
|
||||
/**
|
||||
* Retrieve a filesystem's operations table
|
||||
*
|
||||
* @param name Name of the filesystem to retrieve fs_ops for
|
||||
*
|
||||
* @return valid pointer on success, NULL on failure
|
||||
*/
|
||||
struct fs_ops *fs_ops_for(const char *name);
|
||||
|
||||
struct fs_ops *fs_ops_from_container(struct fops_container *container);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -26,5 +26,8 @@ pkg.keywords:
|
||||
- filesystem
|
||||
- ffs
|
||||
|
||||
pkg.deps:
|
||||
- fs/disk
|
||||
|
||||
pkg.deps.FS_CLI:
|
||||
- sys/shell
|
||||
@@ -20,33 +20,52 @@
|
||||
#include <fs/fs_if.h>
|
||||
#include "fs_priv.h"
|
||||
|
||||
struct fs_ops *fops_from_filename(const char *);
|
||||
|
||||
static struct fs_ops *
|
||||
fops_from_dir(const struct fs_dir *dir)
|
||||
{
|
||||
return fs_ops_from_container((struct fops_container *) dir);
|
||||
}
|
||||
|
||||
static inline struct fs_ops *
|
||||
fops_from_dirent(const struct fs_dirent *dirent)
|
||||
{
|
||||
return fs_ops_from_container((struct fops_container *) dirent);
|
||||
}
|
||||
|
||||
int
|
||||
fs_opendir(const char *path, struct fs_dir **out_dir)
|
||||
{
|
||||
return fs_root_ops->f_opendir(path, out_dir);
|
||||
struct fs_ops *fops = fops_from_filename(path);
|
||||
return fops->f_opendir(path, out_dir);
|
||||
}
|
||||
|
||||
int
|
||||
fs_readdir(struct fs_dir *dir, struct fs_dirent **out_dirent)
|
||||
{
|
||||
return fs_root_ops->f_readdir(dir, out_dirent);
|
||||
struct fs_ops *fops = fops_from_dir(dir);
|
||||
return fops->f_readdir(dir, out_dirent);
|
||||
}
|
||||
|
||||
int
|
||||
fs_closedir(struct fs_dir *dir)
|
||||
{
|
||||
return fs_root_ops->f_closedir(dir);
|
||||
struct fs_ops *fops = fops_from_dir(dir);
|
||||
return fops->f_closedir(dir);
|
||||
}
|
||||
|
||||
int
|
||||
fs_dirent_name(const struct fs_dirent *dirent, size_t max_len,
|
||||
char *out_name, uint8_t *out_name_len)
|
||||
{
|
||||
return fs_root_ops->f_dirent_name(dirent, max_len, out_name, out_name_len);
|
||||
struct fs_ops *fops = fops_from_dirent(dirent);
|
||||
return fops->f_dirent_name(dirent, max_len, out_name, out_name_len);
|
||||
}
|
||||
|
||||
int
|
||||
fs_dirent_is_dir(const struct fs_dirent *dirent)
|
||||
{
|
||||
return fs_root_ops->f_dirent_is_dir(dirent);
|
||||
struct fs_ops *fops = fops_from_dirent(dirent);
|
||||
return fops->f_dirent_is_dir(dirent);
|
||||
}
|
||||
@@ -19,52 +19,216 @@
|
||||
#include <fs/fs.h>
|
||||
#include <fs/fs_if.h>
|
||||
|
||||
#include <disk/disk.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "fs_priv.h"
|
||||
|
||||
static int
|
||||
fake_open(const char *filename, uint8_t access_flags,
|
||||
struct fs_file **out_file)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_close(struct fs_file *file)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_read(struct fs_file *file, uint32_t len, void *out_data,
|
||||
uint32_t *out_len)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_write(struct fs_file *file, const void *data, int len)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_seek(struct fs_file *file, uint32_t offset)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
fake_getpos(const struct fs_file *file)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_filelen(const struct fs_file *file, uint32_t *out_len)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_unlink(const char *filename)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_rename(const char *from, const char *to)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_mkdir(const char *path)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_opendir(const char *path, struct fs_dir **out_dir)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_readdir(struct fs_dir *dir, struct fs_dirent **out_dirent)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_closedir(struct fs_dir *dir)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int fake_dirent_name(const struct fs_dirent *dirent, size_t max_len,
|
||||
char *out_name, uint8_t *out_name_len)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_dirent_is_dir(const struct fs_dirent *dirent)
|
||||
{
|
||||
return FS_EUNINIT;
|
||||
}
|
||||
|
||||
struct fs_ops not_initialized_ops = {
|
||||
.f_open = &fake_open,
|
||||
.f_close = &fake_close,
|
||||
.f_read = &fake_read,
|
||||
.f_write = &fake_write,
|
||||
.f_seek = &fake_seek,
|
||||
.f_getpos = &fake_getpos,
|
||||
.f_filelen = &fake_filelen,
|
||||
.f_unlink = &fake_unlink,
|
||||
.f_rename = &fake_rename,
|
||||
.f_mkdir = &fake_mkdir,
|
||||
.f_opendir = &fake_opendir,
|
||||
.f_readdir = &fake_readdir,
|
||||
.f_closedir = &fake_closedir,
|
||||
.f_dirent_name = &fake_dirent_name,
|
||||
.f_dirent_is_dir = &fake_dirent_is_dir,
|
||||
.f_name = "fakefs",
|
||||
};
|
||||
|
||||
struct fs_ops *
|
||||
safe_fs_ops_for(const char *fs_name)
|
||||
{
|
||||
struct fs_ops *fops;
|
||||
|
||||
fops = fs_ops_for(fs_name);
|
||||
if (fops == NULL) {
|
||||
fops = ¬_initialized_ops;
|
||||
}
|
||||
|
||||
return fops;
|
||||
}
|
||||
|
||||
struct fs_ops *
|
||||
fops_from_filename(const char *filename)
|
||||
{
|
||||
char *disk;
|
||||
char *fs_name = NULL;
|
||||
struct fs_ops *unique;
|
||||
|
||||
disk = disk_name_from_path(filename);
|
||||
if (disk) {
|
||||
fs_name = disk_fs_for(disk);
|
||||
} else {
|
||||
/**
|
||||
* special case: if only one fs was ever registered,
|
||||
* return that fs' ops.
|
||||
*/
|
||||
if ((unique = fs_ops_try_unique()) != NULL) {
|
||||
return unique;
|
||||
}
|
||||
}
|
||||
return safe_fs_ops_for(fs_name);
|
||||
}
|
||||
|
||||
static inline struct fs_ops *
|
||||
fops_from_file(const struct fs_file *file)
|
||||
{
|
||||
return fs_ops_from_container((struct fops_container *) file);
|
||||
}
|
||||
|
||||
int
|
||||
fs_open(const char *filename, uint8_t access_flags, struct fs_file **out_file)
|
||||
{
|
||||
return fs_root_ops->f_open(filename, access_flags, out_file);
|
||||
struct fs_ops *fops = fops_from_filename(filename);
|
||||
return fops->f_open(filename, access_flags, out_file);
|
||||
}
|
||||
|
||||
int
|
||||
fs_close(struct fs_file *file)
|
||||
{
|
||||
return fs_root_ops->f_close(file);
|
||||
struct fs_ops *fops = fops_from_file(file);
|
||||
return fops->f_close(file);
|
||||
}
|
||||
|
||||
int
|
||||
fs_read(struct fs_file *file, uint32_t len, void *out_data, uint32_t *out_len)
|
||||
{
|
||||
return fs_root_ops->f_read(file, len, out_data, out_len);
|
||||
struct fs_ops *fops = fops_from_file(file);
|
||||
return fops->f_read(file, len, out_data, out_len);
|
||||
}
|
||||
|
||||
int
|
||||
fs_write(struct fs_file *file, const void *data, int len)
|
||||
{
|
||||
return fs_root_ops->f_write(file, data, len);
|
||||
struct fs_ops *fops = fops_from_file(file);
|
||||
return fops->f_write(file, data, len);
|
||||
}
|
||||
|
||||
int
|
||||
fs_seek(struct fs_file *file, uint32_t offset)
|
||||
{
|
||||
return fs_root_ops->f_seek(file, offset);
|
||||
struct fs_ops *fops = fops_from_file(file);
|
||||
return fops->f_seek(file, offset);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
fs_getpos(const struct fs_file *file)
|
||||
{
|
||||
return fs_root_ops->f_getpos(file);
|
||||
struct fs_ops *fops = fops_from_file(file);
|
||||
return fops->f_getpos(file);
|
||||
}
|
||||
|
||||
int
|
||||
fs_filelen(const struct fs_file *file, uint32_t *out_len)
|
||||
{
|
||||
return fs_root_ops->f_filelen(file, out_len);
|
||||
struct fs_ops *fops = fops_from_file(file);
|
||||
return fops->f_filelen(file, out_len);
|
||||
}
|
||||
|
||||
int
|
||||
fs_unlink(const char *filename)
|
||||
{
|
||||
return fs_root_ops->f_unlink(filename);
|
||||
struct fs_ops *fops = fops_from_filename(filename);
|
||||
return fops->f_unlink(filename);
|
||||
}
|
||||
@@ -21,14 +21,18 @@
|
||||
|
||||
#include "fs_priv.h"
|
||||
|
||||
struct fs_ops *fops_from_filename(const char *);
|
||||
|
||||
int
|
||||
fs_rename(const char *from, const char *to)
|
||||
{
|
||||
return fs_root_ops->f_rename(from, to);
|
||||
struct fs_ops *fops = fops_from_filename(from);
|
||||
return fops->f_rename(from, to);
|
||||
}
|
||||
|
||||
int
|
||||
fs_mkdir(const char *path)
|
||||
{
|
||||
return fs_root_ops->f_mkdir(path);
|
||||
struct fs_ops *fops = fops_from_filename(path);
|
||||
return fops->f_mkdir(path);
|
||||
}
|
||||
@@ -21,20 +21,83 @@
|
||||
#include "fs/fs.h"
|
||||
#include "fs/fs_if.h"
|
||||
#include "fs_priv.h"
|
||||
#include <string.h>
|
||||
|
||||
const struct fs_ops *fs_root_ops = NULL;
|
||||
|
||||
int
|
||||
fs_register(const struct fs_ops *fops)
|
||||
{
|
||||
if (fs_root_ops) {
|
||||
return FS_EEXIST;
|
||||
}
|
||||
fs_root_ops = fops;
|
||||
static SLIST_HEAD(, fs_ops) root_fops = SLIST_HEAD_INITIALIZER();
|
||||
|
||||
#if MYNEWT_VAL(FS_CLI)
|
||||
fs_cli_init();
|
||||
static uint8_t g_cli_initialized;
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(FS_NMGR)
|
||||
static uint8_t g_nmgr_initialized;
|
||||
#endif
|
||||
|
||||
int
|
||||
fs_register(struct fs_ops *fops)
|
||||
{
|
||||
struct fs_ops *sc;
|
||||
|
||||
SLIST_FOREACH(sc, &root_fops, sc_next) {
|
||||
if (strcmp(sc->f_name, fops->f_name) == 0) {
|
||||
return FS_EEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
SLIST_INSERT_HEAD(&root_fops, fops, sc_next);
|
||||
|
||||
#if MYNEWT_VAL(FS_CLI)
|
||||
if (!g_cli_initialized) {
|
||||
fs_cli_init();
|
||||
g_cli_initialized = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(FS_NMGR)
|
||||
if (!g_nmgr_initialized) {
|
||||
fs_nmgr_init();
|
||||
g_nmgr_initialized = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return FS_EOK;
|
||||
}
|
||||
|
||||
struct fs_ops *
|
||||
fs_ops_try_unique(void)
|
||||
{
|
||||
struct fs_ops *fops = SLIST_FIRST(&root_fops);
|
||||
|
||||
if (fops && !SLIST_NEXT(fops, sc_next)) {
|
||||
return fops;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fs_ops *
|
||||
fs_ops_for(const char *fs_name)
|
||||
{
|
||||
struct fs_ops *fops = NULL;
|
||||
struct fs_ops *sc;
|
||||
|
||||
SLIST_FOREACH(sc, &root_fops, sc_next) {
|
||||
if (strcmp(sc->f_name, fs_name) == 0) {
|
||||
fops = sc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return fops;
|
||||
}
|
||||
|
||||
extern struct fs_ops not_initialized_ops;
|
||||
|
||||
struct fs_ops *
|
||||
fs_ops_from_container(struct fops_container *container)
|
||||
{
|
||||
if (!container) {
|
||||
return ¬_initialized_ops;
|
||||
}
|
||||
return container->fops;
|
||||
}
|
||||
@@ -26,12 +26,17 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
struct fs_ops;
|
||||
extern const struct fs_ops *fs_root_ops;
|
||||
struct fs_ops *fs_ops_for(const char *fs_name);
|
||||
struct fs_ops *safe_fs_ops_for(const char *fs_name);
|
||||
|
||||
#if MYNEWT_VAL(FS_CLI)
|
||||
void fs_cli_init(void);
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(FS_NMGR)
|
||||
int fs_nmgr_init(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,7 @@ fsutil_read_file(const char *path, uint32_t offset, uint32_t len, void *dst,
|
||||
|
||||
rc = fs_open(path, FS_ACCESS_READ, &file);
|
||||
if (rc != 0) {
|
||||
goto done;
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = fs_read(file, len, dst, out_len);
|
||||
@@ -51,7 +51,7 @@ fsutil_write_file(const char *path, const void *data, uint32_t len)
|
||||
|
||||
rc = fs_open(path, FS_ACCESS_WRITE, &file);
|
||||
if (rc != 0) {
|
||||
goto done;
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = fs_write(file, data, len);
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
|
||||
syscfg.defs:
|
||||
FS_CLI:
|
||||
description: 'TBD'
|
||||
description: 'CLI commands to interact with files.'
|
||||
value: 0
|
||||
restrictions:
|
||||
- SHELL_TASK
|
||||
|
||||
FS_NMGR:
|
||||
description: 'Enables file system newtmgr commands.'
|
||||
value: 0
|
||||
@@ -33,8 +33,9 @@ pkg.deps:
|
||||
- kernel/os
|
||||
- test/testutil
|
||||
- sys/flash_map
|
||||
- sys/log
|
||||
- sys/stats
|
||||
pkg.req_apis:
|
||||
- log
|
||||
- stats
|
||||
|
||||
pkg.init_function: nffs_pkg_init
|
||||
pkg.init_stage: 2
|
||||
pkg.init:
|
||||
nffs_pkg_init: 200
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "nffs_priv.h"
|
||||
#include "nffs/nffs.h"
|
||||
#include "fs/fs_if.h"
|
||||
#include "disk/disk.h"
|
||||
|
||||
struct nffs_area *nffs_areas;
|
||||
uint8_t nffs_num_areas;
|
||||
@@ -81,7 +82,7 @@ static int nffs_dirent_name(const struct fs_dirent *fs_dirent, size_t max_len,
|
||||
char *out_name, uint8_t *out_name_len);
|
||||
static int nffs_dirent_is_dir(const struct fs_dirent *fs_dirent);
|
||||
|
||||
static const struct fs_ops nffs_ops = {
|
||||
struct fs_ops nffs_ops = {
|
||||
.f_open = nffs_open,
|
||||
.f_close = nffs_close,
|
||||
.f_read = nffs_read,
|
||||
@@ -196,6 +197,7 @@ nffs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
|
||||
{
|
||||
int rc;
|
||||
struct nffs_file *out_file;
|
||||
char *filepath = NULL;
|
||||
|
||||
nffs_lock();
|
||||
|
||||
@@ -204,12 +206,17 @@ nffs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
|
||||
goto done;
|
||||
}
|
||||
|
||||
rc = nffs_file_open(&out_file, path, access_flags);
|
||||
filepath = disk_filepath_from_path(path);
|
||||
|
||||
rc = nffs_file_open(&out_file, filepath, access_flags);
|
||||
if (rc != 0) {
|
||||
goto done;
|
||||
}
|
||||
*out_fs_file = (struct fs_file *)out_file;
|
||||
done:
|
||||
if (filepath) {
|
||||
free(filepath);
|
||||
}
|
||||
nffs_unlock();
|
||||
if (rc != 0) {
|
||||
*out_fs_file = NULL;
|
||||
@@ -495,6 +502,7 @@ nffs_opendir(const char *path, struct fs_dir **out_fs_dir)
|
||||
{
|
||||
int rc;
|
||||
struct nffs_dir **out_dir = (struct nffs_dir **)out_fs_dir;
|
||||
char *filepath = NULL;
|
||||
|
||||
nffs_lock();
|
||||
|
||||
@@ -503,10 +511,18 @@ nffs_opendir(const char *path, struct fs_dir **out_fs_dir)
|
||||
goto done;
|
||||
}
|
||||
|
||||
rc = nffs_dir_open(path, out_dir);
|
||||
filepath = disk_filepath_from_path(path);
|
||||
|
||||
rc = nffs_dir_open(filepath, out_dir);
|
||||
|
||||
done:
|
||||
if (filepath) {
|
||||
free(filepath);
|
||||
}
|
||||
nffs_unlock();
|
||||
if (rc != 0) {
|
||||
*out_dir = NULL;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -738,8 +754,6 @@ nffs_init(void)
|
||||
return rc;
|
||||
}
|
||||
|
||||
NFFS_LOG(DEBUG, "nffs_init");
|
||||
|
||||
fs_register(&nffs_ops);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#include <string.h>
|
||||
#include "nffs_priv.h"
|
||||
#include "nffs/nffs.h"
|
||||
#include "fs/fs_if.h"
|
||||
|
||||
extern struct fs_ops nffs_ops;
|
||||
|
||||
static struct nffs_dir *
|
||||
nffs_dir_alloc(void)
|
||||
@@ -74,6 +77,7 @@ nffs_dir_open(const char *path, struct nffs_dir **out_dir)
|
||||
dir->nd_parent_inode_entry = parent_inode_entry;
|
||||
nffs_inode_inc_refcnt(dir->nd_parent_inode_entry);
|
||||
memset(&dir->nd_dirent, 0, sizeof dir->nd_dirent);
|
||||
dir->fops = &nffs_ops;
|
||||
|
||||
*out_dir = dir;
|
||||
|
||||
@@ -104,6 +108,7 @@ nffs_dir_read(struct nffs_dir *dir, struct nffs_dirent **out_dirent)
|
||||
}
|
||||
|
||||
nffs_inode_inc_refcnt(child);
|
||||
dir->nd_dirent.fops = &nffs_ops;
|
||||
*out_dirent = &dir->nd_dirent;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#include <string.h>
|
||||
#include "nffs_priv.h"
|
||||
#include "nffs/nffs.h"
|
||||
#include "fs/fs_if.h"
|
||||
|
||||
extern struct fs_ops nffs_ops;
|
||||
|
||||
static struct nffs_file *
|
||||
nffs_file_alloc(void)
|
||||
@@ -242,6 +245,7 @@ nffs_file_open(struct nffs_file **out_file, const char *path,
|
||||
}
|
||||
nffs_inode_inc_refcnt(file->nf_inode_entry);
|
||||
file->nf_access_flags = access_flags;
|
||||
file->fops = &nffs_ops;
|
||||
|
||||
*out_file = file;
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
//#include "log/log.h"
|
||||
|
||||
#include "os/queue.h"
|
||||
#include "os/os_mempool.h"
|
||||
#include "nffs/nffs.h"
|
||||
@@ -30,8 +29,6 @@
|
||||
#include "crc/crc16.h"
|
||||
//#include "stats/stats.h"
|
||||
|
||||
#include "common_func.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -174,6 +171,7 @@ struct nffs_block {
|
||||
};
|
||||
|
||||
struct nffs_file {
|
||||
struct fs_ops *fops;
|
||||
struct nffs_inode_entry *nf_inode_entry;
|
||||
uint32_t nf_offset;
|
||||
uint8_t nf_access_flags;
|
||||
@@ -241,10 +239,12 @@ struct nffs_cache_inode {
|
||||
};
|
||||
|
||||
struct nffs_dirent {
|
||||
struct fs_ops *fops;
|
||||
struct nffs_inode_entry *nde_inode_entry;
|
||||
};
|
||||
|
||||
struct nffs_dir {
|
||||
struct fs_ops *fops;
|
||||
struct nffs_inode_entry *nd_parent_inode_entry;
|
||||
struct nffs_dirent nd_dirent;
|
||||
};
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
|
||||
syscfg.defs:
|
||||
NFFS_FLASH_AREA:
|
||||
description: 'TBD'
|
||||
description: 'Flash area to use for NFFS.'
|
||||
type: flash_owner
|
||||
value:
|
||||
restrictions:
|
||||
- $notnull
|
||||
|
||||
NFFS_DETECT_FAIL:
|
||||
description: 'TBD'
|
||||
description: 'Controls behaviour when encountering corrupt NFFS area.'
|
||||
value: 'NFFS_DETECT_FAIL_FORMAT'
|
||||
@@ -85,8 +85,10 @@ typedef enum os_error os_error_t;
|
||||
|
||||
#if 0
|
||||
#define OS_IDLE_PRIO (0xff)
|
||||
#define OS_MAIN_TASK_PRIO MYNEWT_VAL(OS_MAIN_TASK_PRIO)
|
||||
#define OS_MAIN_STACK_SIZE MYNEWT_VAL(OS_MAIN_STACK_SIZE)
|
||||
|
||||
void os_init(void);
|
||||
void os_init(int (*fn)(int argc, char **argv));
|
||||
void os_start(void);
|
||||
|
||||
/* XXX: Not sure if this should go here; I want to differentiate API that
|
||||
@@ -100,6 +102,7 @@ void os_init_idle_task(void);
|
||||
//#include "os/os_dev.h"
|
||||
//#include "os/os_eventq.h"
|
||||
//#include "os/os_heap.h"
|
||||
//#include "os/os_fault.h"
|
||||
//#include "os/os_mbuf.h"
|
||||
#include "os/os_mempool.h"
|
||||
#include "os/os_mutex.h"
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
* @defgroup OSMempool Memory Pools
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
#define OS_CHECK_DUP_FREE 1
|
||||
*/
|
||||
|
||||
#define OS_MEMPOOL_TRUE_BLOCK_SIZE(bsize) OS_ALIGN(bsize, OS_ALIGNMENT)
|
||||
|
||||
@@ -202,6 +205,11 @@ os_memblock_put(struct os_mempool *mp, void *block_addr)
|
||||
return OS_INVALID_PARM;
|
||||
}
|
||||
|
||||
#ifdef OS_CHECK_DUP_FREE
|
||||
SLIST_FOREACH(block, mp, mb_next) {
|
||||
assert(block != (struct os_memblock *)block_addr);
|
||||
}
|
||||
#endif
|
||||
block = (struct os_memblock *)block_addr;
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#define MYNEWT_VAL(x) MYNEWT_VAL_ ## x
|
||||
|
||||
#define MYNEWT_VAL_FS_CLI (0)
|
||||
#define MYNEWT_VAL_FS_NMGR (0)
|
||||
#define MYNEWT_VAL_NFFS_DETECT_FAIL (NFFS_DETECT_FAIL_FORMAT)
|
||||
|
||||
#endif /* SYSCFG_H_ */
|
||||
+1
-1
@@ -61,7 +61,7 @@ nffs.path={runtime.platform.path}/libraries/nffs/src
|
||||
|
||||
compiler.nrf.flags=-DARDUINO_NRF52_ADAFRUIT -DNRF5 -DNRF52 -DS132 "-I{nrf.sdk.path}/components/toolchain/" "-I{nrf.sdk.path}/components/toolchain/CMSIS/Include" "-I{nrf.sdk.path}/components/toolchain/gcc/" "-I{nrf.sdk.path}/components/device/" "-I{nrf.sdk.path}/components/drivers_nrf/delay/" "-I{nrf.sdk.path}/components/softdevice/s132/headers/" "-I{rtos.path}/source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52"
|
||||
|
||||
nffs.includes="-I{nffs.path}/fs/nffs/include" "-I{nffs.path}/fs/fs/include" "-I{nffs.path}/util/crc/include" "-I{nffs.path}/kernel/os/include" "-I{nffs.path}/kernel/os/include/os/arch/cortex_m4" "-I{nffs.path}/hw/hal/include" "-I{nffs.path}/sys/flash_map/include" "-I{nffs.path}/sys/defs/include"
|
||||
nffs.includes="-I{nffs.path}/fs/nffs/include" "-I{nffs.path}/fs/fs/include" "-I{nffs.path}/fs/disk/include" "-I{nffs.path}/util/crc/include" "-I{nffs.path}/kernel/os/include" "-I{nffs.path}/kernel/os/include/os/arch/cortex_m4" "-I{nffs.path}/hw/hal/include" "-I{nffs.path}/sys/flash_map/include" "-I{nffs.path}/sys/defs/include"
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
|
||||
Reference in new issue
Block a user