You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/01/19 17:36:12 UTC
[01/19] incubator-mynewt-core git commit: Add disk interface for nffs
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop f35d5d193 -> 56ae794c2
Add disk interface for nffs
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/06b5f0ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/06b5f0ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/06b5f0ae
Branch: refs/heads/develop
Commit: 06b5f0aef4f3bbc2154c0d95b590560b388a9896
Parents: e2fcc8f
Author: Fabio Utzig <ut...@utzig.org>
Authored: Tue Jan 10 22:42:23 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/nffs/src/nffs.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/06b5f0ae/fs/nffs/src/nffs.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs.c b/fs/nffs/src/nffs.c
index 4475420..83c75d1 100644
--- a/fs/nffs/src/nffs.c
+++ b/fs/nffs/src/nffs.c
@@ -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;
@@ -192,6 +193,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();
@@ -200,12 +202,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;
@@ -491,6 +498,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();
@@ -499,9 +507,14 @@ 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();
return rc;
}
[12/19] incubator-mynewt-core git commit: Fix compilation
Posted by cc...@apache.org.
Fix compilation
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/6e9213fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6e9213fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6e9213fe
Branch: refs/heads/develop
Commit: 6e9213fe1136d369cbbbf141f46895e38441910a
Parents: 1a02962
Author: Fabio Utzig <ut...@utzig.org>
Authored: Mon Dec 19 07:46:07 2016 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/disk/include/disk/disk.h | 52 ++++
fs/disk/pkg.yml | 27 +++
fs/disk/src/disk.c | 62 +++++
fs/fatfs/src/mynewt_glue.c | 2 +-
fs/fatfs/src/mynewt_glue_2.c | 410 --------------------------------
fs/fs/include/fs/fs_if.h | 4 +-
fs/fs/src/fs_file.c | 118 +++++++--
fs/fs/src/fs_mount.c | 13 +-
fs/nffs/src/nffs.c | 2 +-
hw/drivers/mmc/include/mmc/mmc.h | 12 +-
hw/drivers/mmc/src/mmc.c | 16 +-
hw/hal/include/hal/hal_flash.h | 2 +-
hw/hal/src/hal_flash.c | 10 +-
sys/diskio/include/diskio/diskio.h | 51 ----
sys/diskio/pkg.yml | 27 ---
sys/diskio/src/diskio.c | 57 -----
16 files changed, 281 insertions(+), 584 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/fs/disk/include/disk/disk.h
----------------------------------------------------------------------
diff --git a/fs/disk/include/disk/disk.h b/fs/disk/include/disk/disk.h
new file mode 100644
index 0000000..e87fc7b
--- /dev/null
+++ b/fs/disk/include/disk/disk.h
@@ -0,0 +1,52 @@
+/*
+ * 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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/fs/disk/pkg.yml
----------------------------------------------------------------------
diff --git a/fs/disk/pkg.yml b/fs/disk/pkg.yml
new file mode 100644
index 0000000..61813a7
--- /dev/null
+++ b/fs/disk/pkg.yml
@@ -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 <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - kernel/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/fs/disk/src/disk.c
----------------------------------------------------------------------
diff --git a/fs/disk/src/disk.c b/fs/disk/src/disk.c
new file mode 100644
index 0000000..803e1a5
--- /dev/null
+++ b/fs/disk/src/disk.c
@@ -0,0 +1,62 @@
+/*
+ * 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 <fs/fs.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;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/fs/fatfs/src/mynewt_glue.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index f2382f8..f64bbb2 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -38,7 +38,7 @@ static int fatfs_dirent_is_dir(const struct fs_dirent *fs_dirent);
*/
static FILINFO filinfo;
-static const struct fs_ops fatfs_ops = {
+static struct fs_ops fatfs_ops = {
.f_open = fatfs_open,
.f_close = fatfs_close,
.f_read = fatfs_read,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/fs/fatfs/src/mynewt_glue_2.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue_2.c b/fs/fatfs/src/mynewt_glue_2.c
deleted file mode 100644
index 8be7265..0000000
--- a/fs/fatfs/src/mynewt_glue_2.c
+++ /dev/null
@@ -1,410 +0,0 @@
-#include <assert.h>
-#include <sysinit/sysinit.h>
-#include <hal/hal_flash.h>
-#include <flash_map/flash_map.h>
-#include <mmc/mmc.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <fatfs/ff.h>
-#include <fatfs/diskio.h>
-
-#include <fs/fs.h>
-#include <fs/fs_if.h>
-
-static int fatfs_open(const char *path, uint8_t access_flags,
- struct fs_file **out_file);
-static int fatfs_close(struct fs_file *fs_file);
-static int fatfs_read(struct fs_file *fs_file, uint32_t len, void *out_data,
- uint32_t *out_len);
-static int fatfs_write(struct fs_file *fs_file, const void *data, int len);
-static int fatfs_seek(struct fs_file *fs_file, uint32_t offset);
-static uint32_t fatfs_getpos(const struct fs_file *fs_file);
-static int fatfs_file_len(const struct fs_file *fs_file, uint32_t *out_len);
-static int fatfs_unlink(const char *path);
-static int fatfs_rename(const char *from, const char *to);
-static int fatfs_mkdir(const char *path);
-static int fatfs_opendir(const char *path, struct fs_dir **out_fs_dir);
-static int fatfs_readdir(struct fs_dir *dir, struct fs_dirent **out_dirent);
-static int fatfs_closedir(struct fs_dir *dir);
-static int fatfs_dirent_name(const struct fs_dirent *fs_dirent, size_t max_len,
- char *out_name, uint8_t *out_name_len);
-static int fatfs_dirent_is_dir(const struct fs_dirent *fs_dirent);
-
-/* NOTE: to ease memory management of dirent structs, this single static
- * variable holds the latest entry found by readdir. This limits FAT to
- * working on a single thread, single opendir -> closedir cycle.
- */
-static FILINFO filinfo;
-
-static const struct fs_ops fatfs_ops = {
- .f_open = fatfs_open,
- .f_close = fatfs_close,
- .f_read = fatfs_read,
- .f_write = fatfs_write,
-
- .f_seek = fatfs_seek,
- .f_getpos = fatfs_getpos,
- .f_filelen = fatfs_file_len,
-
- .f_unlink = fatfs_unlink,
- .f_rename = fatfs_rename,
- .f_mkdir = fatfs_mkdir,
-
- .f_opendir = fatfs_opendir,
- .f_readdir = fatfs_readdir,
- .f_closedir = fatfs_closedir,
-
- .f_dirent_name = fatfs_dirent_name,
- .f_dirent_is_dir = fatfs_dirent_is_dir,
-
- .f_name = "fatfs"
-};
-
-int fatfs_to_vfs_error(FRESULT res)
-{
- int rc = FS_EOS;
-
- switch (res) {
- case FR_OK:
- rc = FS_EOK;
- break;
- case FR_DISK_ERR: /* (1) A hard error occurred in the low level disk I/O layer */
- rc = FS_EHW;
- break;
- case FR_INT_ERR: /* (2) Assertion failed */
- rc = FS_EOS;
- break;
- case FR_NOT_READY: /* (3) The physical drive cannot work */
- rc = FS_ECORRUPT;
- break;
- case FR_NO_FILE: /* (4) Could not find the file */
- /* passthrough */
- case FR_NO_PATH: /* (5) Could not find the path */
- rc = FS_ENOENT;
- break;
- case FR_INVALID_NAME: /* (6) The path name format is invalid */
- rc = FS_EINVAL;
- break;
- case FR_DENIED: /* (7) Access denied due to prohibited access or directory full */
- rc = FS_EACCESS;
- break;
- case FR_EXIST: /* (8) Access denied due to prohibited access */
- rc = FS_EEXIST;
- break;
- case FR_INVALID_OBJECT: /* (9) The file/directory object is invalid */
- rc = FS_EINVAL;
- break;
- case FR_WRITE_PROTECTED: /* (10) The physical drive is write protected */
- /* TODO: assign correct error */
- break;
- case FR_INVALID_DRIVE: /* (11) The logical drive number is invalid */
- rc = FS_EHW;
- break;
- case FR_NOT_ENABLED: /* (12) The volume has no work area */
- rc = FS_EUNEXP;
- break;
- case FR_NO_FILESYSTEM: /* (13) There is no valid FAT volume */
- rc = FS_EUNINIT;
- break;
- case FR_MKFS_ABORTED: /* (14) The f_mkfs() aborted due to any problem */
- /* TODO: assign correct error */
- break;
- case FR_TIMEOUT: /* (15) Could not get a grant to access the volume within defined period */
- /* TODO: assign correct error */
- break;
- case FR_LOCKED: /* (16) The operation is rejected according to the file sharing policy */
- /* TODO: assign correct error */
- break;
- case FR_NOT_ENOUGH_CORE: /* (17) LFN working buffer could not be allocated */
- rc = FS_ENOMEM;
- break;
- case FR_TOO_MANY_OPEN_FILES: /* (18) Number of open files > _FS_LOCK */
- /* TODO: assign correct error */
- break;
- case FR_INVALID_PARAMETER: /* (19) Given parameter is invalid */
- rc = FS_EINVAL;
- break;
- }
-
- return rc;
-}
-
-static int
-fatfs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
-{
- FRESULT res;
- FIL *out_file;
- BYTE mode;
-
- out_file = malloc(sizeof(FIL));
- if (!out_file) {
- return FS_ENOMEM;
- }
-
- mode = FA_OPEN_EXISTING;
- if (access_flags & FS_ACCESS_READ) {
- mode |= FA_READ;
- }
- if (access_flags & FS_ACCESS_WRITE) {
- mode |= FA_WRITE;
- }
- if (access_flags & FS_ACCESS_APPEND) {
- mode |= FA_OPEN_APPEND;
- }
- if (access_flags & FS_ACCESS_TRUNCATE) {
- mode &= ~FA_OPEN_EXISTING;
- mode |= FA_CREATE_ALWAYS;
- }
-
- res = f_open(out_file, path, mode);
- if (res != FR_OK) {
- free(out_file);
- return fatfs_to_vfs_error(res);
- }
- *out_fs_file = (struct fs_file *)out_file;
- return FS_EOK;
-}
-
-static int
-fatfs_close(struct fs_file *fs_file)
-{
- FRESULT res;
- FIL *file = (FIL *)fs_file;
-
- if (file == NULL) {
- return FS_EOK;
- }
-
- res = f_close(file);
- free(file);
- return fatfs_to_vfs_error(res);
-}
-
-static int
-fatfs_seek(struct fs_file *fs_file, uint32_t offset)
-{
- FRESULT res;
- FIL *file = (FIL *)fs_file;
-
- res = f_lseek(file, offset);
- return fatfs_to_vfs_error(res);
-}
-
-static uint32_t
-fatfs_getpos(const struct fs_file *fs_file)
-{
- uint32_t offset;
- FIL *file = (FIL *)fs_file;
-
- offset = (uint32_t) f_tell(file);
- return offset;
-}
-
-static int
-fatfs_file_len(const struct fs_file *fs_file, uint32_t *out_len)
-{
- uint32_t offset;
- FIL *file = (FIL *)fs_file;
-
- offset = (uint32_t) f_size(file);
- return offset;
-}
-
-static int
-fatfs_read(struct fs_file *fs_file, uint32_t len, void *out_data,
- uint32_t *out_len)
-{
- FRESULT res;
- FIL *file = (FIL *)fs_file;
-
- res = f_read(file, out_data, len, (UINT *)out_len);
- return fatfs_to_vfs_error(res);
-}
-
-static int
-fatfs_write(struct fs_file *fs_file, const void *data, int len)
-{
- FRESULT res;
- UINT out_len;
- FIL *file = (FIL *)fs_file;
-
- res = f_write(file, data, len, &out_len);
- if (len != out_len) {
- return FS_EFULL;
- }
- return fatfs_to_vfs_error(res);
-}
-
-static int
-fatfs_unlink(const char *path)
-{
- FRESULT res;
-
- res = f_unlink(path);
- return fatfs_to_vfs_error(res);
-}
-
-static int
-fatfs_rename(const char *from, const char *to)
-{
- FRESULT res;
-
- res = f_rename(from, to);
- return fatfs_to_vfs_error(res);
-}
-
-static int
-fatfs_mkdir(const char *path)
-{
- FRESULT res;
-
- res = f_mkdir(path);
- return fatfs_to_vfs_error(res);
-}
-
-static int
-fatfs_opendir(const char *path, struct fs_dir **out_fs_dir)
-{
- FRESULT res;
- FATFS_DIR *out_dir;
-
- out_dir = malloc(sizeof(FATFS_DIR));
- if (!out_dir) {
- return FS_ENOMEM;
- }
-
- res = f_opendir(out_dir, path);
- if (res != FR_OK) {
- return fatfs_to_vfs_error(res);
- }
- *out_fs_dir = (struct fs_dir *)out_dir;
- return FS_EOK;
-}
-
-static int
-fatfs_readdir(struct fs_dir *fs_dir, struct fs_dirent **out_fs_dirent)
-{
- FRESULT res;
- FATFS_DIR *dir = (FATFS_DIR *)fs_dir;
-
- res = f_readdir(dir, &filinfo);
- if (res != FR_OK) {
- return fatfs_to_vfs_error(res);
- }
-
- *out_fs_dirent = (struct fs_dirent *)&filinfo;
- if (!filinfo.fname[0]) {
- return FS_ENOENT;
- }
- return FS_EOK;
-}
-
-static int
-fatfs_closedir(struct fs_dir *fs_dir)
-{
- FRESULT res;
- FATFS_DIR *dir = (FATFS_DIR *)fs_dir;
-
- res = f_closedir(dir);
- free(dir);
- return fatfs_to_vfs_error(res);
-}
-
-static int
-fatfs_dirent_name(const struct fs_dirent *fs_dirent, size_t max_len,
- char *out_name, uint8_t *out_name_len)
-{
- const FILINFO *dirent = (const FILINFO *)fs_dirent;
- size_t out_len;
-
- assert(dirent != NULL);
- out_len = max_len < sizeof(dirent->fname) ? max_len : sizeof(dirent->fname);
- memcpy(out_name, dirent->fname, out_len);
- *out_name_len = out_len;
- return FS_EOK;
-}
-
-static int
-fatfs_dirent_is_dir(const struct fs_dirent *fs_dirent)
-{
- const FILINFO *dirent = (const FILINFO *)fs_dirent;
-
- assert(dirent != NULL);
- return dirent->fattrib & AM_DIR;
-}
-
-DSTATUS
-disk_initialize(BYTE pdrv)
-{
- /* Don't need to do anything while using hal_flash */
- return RES_OK;
-}
-
-DSTATUS
-disk_status(BYTE pdrv)
-{
- /* Always OK on native emulated flash */
- return RES_OK;
-}
-
-DRESULT
-disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count)
-{
- int rc;
- uint32_t address;
- uint32_t num_bytes;
-
- /* NOTE: safe to assume sector size as 512 for now, see ffconf.h */
- address = (uint32_t) sector * 512;
- num_bytes = (uint32_t) count * 512;
- //rc = hal_flash_read(pdrv, address, (void *) buff, num_bytes);
- rc = mmc_read(pdrv, address, (void *) buff, num_bytes);
- if (rc < 0) {
- return STA_NOINIT;
- }
-
- return RES_OK;
-}
-
-DRESULT
-disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)
-{
- int rc;
- uint32_t address;
- uint32_t num_bytes;
-
- /* NOTE: safe to assume sector size as 512 for now, see ffconf.h */
- address = (uint32_t) sector * 512;
- num_bytes = (uint32_t) count * 512;
- //rc = hal_flash_write(pdrv, address, (const void *) buff, num_bytes);
- rc = mmc_write(pdrv, address, (const void *) buff, num_bytes);
- if (rc < 0) {
- return STA_NOINIT;
- }
-
- return RES_OK;
-}
-
-DRESULT
-disk_ioctl(BYTE pdrv, BYTE cmd, void* buff)
-{
- return RES_OK;
-}
-
-/* FIXME: _FS_NORTC=1 because there is not hal_rtc interface */
-DWORD
-get_fattime(void)
-{
- return 0;
-}
-
-void
-fatfs_pkg_init(void)
-{
- /* Ensure this function only gets called by sysinit. */
- SYSINIT_ASSERT_ACTIVE();
-
- fs_register(&fatfs_ops);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/fs/fs/include/fs/fs_if.h
----------------------------------------------------------------------
diff --git a/fs/fs/include/fs/fs_if.h b/fs/fs/include/fs/fs_if.h
index 842f070..015d832 100644
--- a/fs/fs/include/fs/fs_if.h
+++ b/fs/fs/include/fs/fs_if.h
@@ -24,6 +24,8 @@
extern "C" {
#endif
+#include <os/queue.h>
+
/*
* Common interface filesystem(s) provide.
*/
@@ -63,7 +65,7 @@ struct fs_ops {
*
* @return 0 on success, non-zero on failure
*/
-int fs_register(const struct fs_ops *fops);
+int fs_register(struct fs_ops *fops);
/**
* Retrieve a filesystem's operations table
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/fs/fs/src/fs_file.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_file.c b/fs/fs/src/fs_file.c
index fdcecda..a18d0ba 100644
--- a/fs/fs/src/fs_file.c
+++ b/fs/fs/src/fs_file.c
@@ -22,27 +22,113 @@
#include "fs_priv.h"
static int
-not_initialized(const void *v, ...)
+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;
}
static struct fs_ops not_initialized_ops = {
- .f_open = not_initialized,
- .f_close = not_initialized,
- .f_read = not_initialized,
- .f_write = not_initialized,
- .f_seek = not_initialized,
- .f_getpos = not_initialized,
- .f_filelen = not_initialized,
- .f_unlink = not_initialized,
- .f_rename = not_initialized,
- .f_mkdir = not_initialized,
- .f_opendir = not_initialized,
- .f_readdir = not_initialized,
- .f_closedir = not_initialized,
- .f_dirent_name = not_initialized,
- .f_dirent_is_dir = not_initialized,
+ .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",
};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/fs/fs/src/fs_mount.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_mount.c b/fs/fs/src/fs_mount.c
index 174fac8..5f020cf 100644
--- a/fs/fs/src/fs_mount.c
+++ b/fs/fs/src/fs_mount.c
@@ -21,13 +21,19 @@
#include "fs/fs.h"
#include "fs/fs_if.h"
#include "fs_priv.h"
+#include <string.h>
static SLIST_HEAD(, fs_ops) root_fops = SLIST_HEAD_INITIALIZER();
-static bool g_cli_initialized = false;
+
+#if MYNEWT_VAL(FS_CLI)
+static int g_cli_initialized = 0;
+#endif
int
-fs_register(const struct fs_ops *fops)
+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;
@@ -39,7 +45,7 @@ fs_register(const struct fs_ops *fops)
#if MYNEWT_VAL(FS_CLI)
if (!g_cli_initialized) {
fs_cli_init();
- g_cli_initialized = true;
+ g_cli_initialized = 1;
}
#endif
@@ -50,6 +56,7 @@ 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) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/fs/nffs/src/nffs.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs.c b/fs/nffs/src/nffs.c
index 8f25cb5..eacec07 100644
--- a/fs/nffs/src/nffs.c
+++ b/fs/nffs/src/nffs.c
@@ -81,7 +81,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 = {
+static struct fs_ops nffs_ops = {
.f_open = nffs_open,
.f_close = nffs_close,
.f_read = nffs_read,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/hw/drivers/mmc/include/mmc/mmc.h
----------------------------------------------------------------------
diff --git a/hw/drivers/mmc/include/mmc/mmc.h b/hw/drivers/mmc/include/mmc/mmc.h
index a13b682..4b14e27 100644
--- a/hw/drivers/mmc/include/mmc/mmc.h
+++ b/hw/drivers/mmc/include/mmc/mmc.h
@@ -21,7 +21,7 @@
#define __MMC_H__
#include <os/os_dev.h>
-#include <diskio/diskio.h>
+#include <disk/disk.h>
#ifdef __cplusplus
extern "C" {
@@ -69,7 +69,7 @@ mmc_init(int spi_num, void *spi_cfg, int ss_pin);
* @return 0 on success, non-zero on failure
*/
int
-mmc_read(uint8_t mmc_id, uint32_t addr, void *buf, size_t len);
+mmc_read(uint8_t mmc_id, uint32_t addr, void *buf, uint32_t len);
/**
* Write data to the MMC
@@ -82,7 +82,13 @@ mmc_read(uint8_t mmc_id, uint32_t addr, void *buf, size_t len);
* @return 0 on success, non-zero on failure
*/
int
-mmc_write(uint8_t mmc_id, uint32_t addr, const void *buf, size_t len);
+mmc_write(uint8_t mmc_id, uint32_t addr, const void *buf, uint32_t len);
+
+/**
+ * TODO
+ */
+int
+mmc_ioctl(uint8_t mmc_id, uint32_t cmd, void *arg);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/hw/drivers/mmc/src/mmc.c
----------------------------------------------------------------------
diff --git a/hw/drivers/mmc/src/mmc.c b/hw/drivers/mmc/src/mmc.c
index 0b2aa98..cae8c29 100644
--- a/hw/drivers/mmc/src/mmc.c
+++ b/hw/drivers/mmc/src/mmc.c
@@ -19,9 +19,8 @@
#include <hal/hal_spi.h>
#include <hal/hal_gpio.h>
-
+#include <disk/disk.h>
#include <mmc/mmc.h>
-
#include <stdio.h>
#define MIN(n, m) (((n) < (m)) ? (n) : (m))
@@ -361,7 +360,7 @@ wait_busy(struct mmc_cfg *mmc)
* @return 0 on success, non-zero on failure
*/
int
-mmc_read(uint8_t mmc_id, uint32_t addr, void *buf, size_t len)
+mmc_read(uint8_t mmc_id, uint32_t addr, void *buf, uint32_t len)
{
uint8_t cmd;
uint8_t res;
@@ -449,7 +448,7 @@ out:
* @return 0 on success, non-zero on failure
*/
int
-mmc_write(uint8_t mmc_id, uint32_t addr, const void *buf, size_t len)
+mmc_write(uint8_t mmc_id, uint32_t addr, const void *buf, uint32_t len)
{
uint8_t cmd;
uint8_t res;
@@ -587,7 +586,8 @@ out:
/*
*
*/
-int mmc_ioctl(int cmd, void *arg)
+int
+mmc_ioctl(uint8_t mmc_id, uint32_t cmd, void *arg)
{
return 0;
}
@@ -596,7 +596,7 @@ int mmc_ioctl(int cmd, void *arg)
*
*/
struct disk_ops mmc_ops = {
- .read = mmc_read,
- .write = mmc_write,
- .ioctl = mmc_ioctl,
+ .read = &mmc_read,
+ .write = &mmc_write,
+ .ioctl = &mmc_ioctl,
};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/hw/hal/include/hal/hal_flash.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_flash.h b/hw/hal/include/hal/hal_flash.h
index 1fdc91e..bd4f6f3 100644
--- a/hw/hal/include/hal/hal_flash.h
+++ b/hw/hal/include/hal/hal_flash.h
@@ -25,7 +25,7 @@ extern "C" {
#endif
#include <inttypes.h>
-#include <diskio/diskio.h>
+#include <disk/disk.h>
extern struct disk_ops hal_flash_ops;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/hw/hal/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index a95b57b..ada6e23 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -24,7 +24,7 @@
#include "hal/hal_flash.h"
#include "hal/hal_flash_int.h"
-#include <diskio/diskio.h>
+#include <disk/disk.h>
int
hal_flash_init(void)
@@ -176,8 +176,8 @@ hal_flash_ioctl(uint8_t id, uint32_t cmd, void *args)
return 0;
}
-static struct disk_ops hal_flash_ops = {
- .read = hal_flash_read,
- .write = hal_flash_write,
- .ioctl = hal_flash_ioctl,
+struct disk_ops hal_flash_ops = {
+ .read = &hal_flash_read,
+ .write = &hal_flash_write,
+ .ioctl = &hal_flash_ioctl,
};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/sys/diskio/include/diskio/diskio.h
----------------------------------------------------------------------
diff --git a/sys/diskio/include/diskio/diskio.h b/sys/diskio/include/diskio/diskio.h
deleted file mode 100644
index a0a68f6..0000000
--- a/sys/diskio/include/diskio/diskio.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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 __DISKIO_H__
-#define __DISKIO_H__
-
-#include <stddef.h>
-#include <inttypes.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define DISKIO_EOK 0 /* Success */
-#define DISKIO_EHW 1 /* Error accessing storage medium */
-#define DISKIO_ENOMEM 2 /* Insufficient memory */
-#define DISKIO_ENOENT 3 /* No such file or directory */
-#define DISKIO_EOS 4 /* OS error */
-#define DISKIO_EUNINIT 5 /* File system not initialized */
-
-struct disk_ops {
- int (*read)(int, uint32_t, void *, uint32_t);
- int (*write)(int, uint32_t, const void *, uint32_t);
- int (*ioctl)(int, uint32_t, const void *);
-
- SLIST_ENTRY(disk_ops) sc_next;
-};
-
-int diskio_register(const char *disk_name, const char *fs_name, struct disk_ops *dops);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/sys/diskio/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/diskio/pkg.yml b/sys/diskio/pkg.yml
deleted file mode 100644
index 8981937..0000000
--- a/sys/diskio/pkg.yml
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# 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: sys/diskio
-pkg.description: Disk IO layer to glue filesystems to disk devices.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-
-pkg.deps:
- - kernel/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e9213fe/sys/diskio/src/diskio.c
----------------------------------------------------------------------
diff --git a/sys/diskio/src/diskio.c b/sys/diskio/src/diskio.c
deleted file mode 100644
index e74eae3..0000000
--- a/sys/diskio/src/diskio.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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 "fs/fs.h"
-#include <diskio/diskio.h>
-
-static struct disk_info {
- char *disk_name;
- char *fs_name;
- struct disk_ops *dops;
-};
-
-static SLIST_HEAD(, disk_info) disks = SLIST_HEAD_INITIALIZER();
-
-/**
- *
- */
-int diskio_register(const char *disk_name, const char *fs_name, struct disk_ops *dops)
-{
- struct disk_info *info = NULL;
-
- SLIST_FOREACH(sc, &disks, sc_next) {
- if (strcmp(sc->disk_name, disk_name) == 0) {
- return DISKIO_EEXIST;
- }
- }
-
- info = malloc(sizeof(struct disk_info));
- if (!info) {
- return DISKIO_ENOMEM;
- }
-
- info.disk_name = disk_name;
- info.fs_name = fs_name;
- info.dops = dops;
-
- SLIST_INSERT_HEAD(&disks, info, sc_next);
-
- return 0;
-}
[10/19] incubator-mynewt-core git commit: Revert stm32f4-discovery
LED pin
Posted by cc...@apache.org.
Revert stm32f4-discovery LED pin
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/fab9ee36
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fab9ee36
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fab9ee36
Branch: refs/heads/develop
Commit: fab9ee36c86ab988dfc8084485cf371ca5c5ecd9
Parents: 9f73112
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 5 21:17:12 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
hw/bsp/stm32f4discovery/include/bsp/bsp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fab9ee36/hw/bsp/stm32f4discovery/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/include/bsp/bsp.h b/hw/bsp/stm32f4discovery/include/bsp/bsp.h
index ca8a92c..dd038e9 100644
--- a/hw/bsp/stm32f4discovery/include/bsp/bsp.h
+++ b/hw/bsp/stm32f4discovery/include/bsp/bsp.h
@@ -41,7 +41,7 @@ extern uint8_t _ccram_start;
#define CCRAM_SIZE (64 * 1024)
/* LED pins */
-#define LED_BLINK_PIN MCU_GPIO_PORTD(13)
+#define LED_BLINK_PIN MCU_GPIO_PORTD(12)
/* UART */
#define UART_CNT 1
[09/19] incubator-mynewt-core git commit: Add fops container for
nicer casting
Posted by cc...@apache.org.
Add fops container for nicer casting
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7a0dfc8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7a0dfc8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7a0dfc8e
Branch: refs/heads/develop
Commit: 7a0dfc8ecc103e1eb55d5945c6b55fbfff56b6f0
Parents: fab9ee3
Author: Fabio Utzig <ut...@utzig.org>
Authored: Tue Jan 10 22:30:25 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/fs/include/fs/fs_if.h | 6 ++++++
fs/fs/src/fs_mount.c | 6 ++++++
2 files changed, 12 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7a0dfc8e/fs/fs/include/fs/fs_if.h
----------------------------------------------------------------------
diff --git a/fs/fs/include/fs/fs_if.h b/fs/fs/include/fs/fs_if.h
index ade4f97..5ce3d4e 100644
--- a/fs/fs/include/fs/fs_if.h
+++ b/fs/fs/include/fs/fs_if.h
@@ -58,6 +58,10 @@ struct fs_ops {
SLIST_ENTRY(fs_ops) sc_next;
};
+struct fops_container {
+ struct fs_ops *fops;
+};
+
/**
* Registers a new filesystem interface
*
@@ -84,6 +88,8 @@ struct fs_ops *fs_ops_try_unique(void);
*/
struct fs_ops *fs_ops_for(const char *name);
+struct fs_ops *fs_ops_from_container(struct fops_container *container);
+
#ifdef __cplusplus
}
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7a0dfc8e/fs/fs/src/fs_mount.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_mount.c b/fs/fs/src/fs_mount.c
index 3fceb70..d79854e 100644
--- a/fs/fs/src/fs_mount.c
+++ b/fs/fs/src/fs_mount.c
@@ -79,3 +79,9 @@ fs_ops_for(const char *fs_name)
return fops;
}
+
+struct fs_ops *
+fs_ops_from_container(struct fops_container *container)
+{
+ return container->fops;
+}
[14/19] incubator-mynewt-core git commit: Remove FAT dependency on MMC
Posted by cc...@apache.org.
Remove FAT dependency on MMC
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/59cdc465
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/59cdc465
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/59cdc465
Branch: refs/heads/develop
Commit: 59cdc465195bb9422c3b3f5d93091c5aa97a7ed3
Parents: 06b5f0a
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 12 12:20:17 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 12:20:17 2017 -0200
----------------------------------------------------------------------
fs/disk/src/disk.c | 12 ++++--------
fs/fatfs/src/mynewt_glue.c | 21 +++++++++++++++------
2 files changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/59cdc465/fs/disk/src/disk.c
----------------------------------------------------------------------
diff --git a/fs/disk/src/disk.c b/fs/disk/src/disk.c
index 550dade..4c915d4 100644
--- a/fs/disk/src/disk.c
+++ b/fs/disk/src/disk.c
@@ -64,37 +64,33 @@ int disk_register(const char *disk_name, const char *fs_name, struct disk_ops *d
struct disk_ops *
disk_ops_for(const char *disk_name)
{
- struct disk_ops *dops = NULL;
struct disk_info *sc;
if (disk_name) {
SLIST_FOREACH(sc, &disks, sc_next) {
if (strcmp(sc->disk_name, disk_name) == 0) {
- dops = sc->dops;
- break;
+ return sc->dops;
}
}
}
- return dops;
+ return NULL;
}
char *
disk_fs_for(const char *disk_name)
{
- char *fs_name = NULL;
struct disk_info *sc;
if (disk_name) {
SLIST_FOREACH(sc, &disks, sc_next) {
if (strcmp(sc->disk_name, disk_name) == 0) {
- fs_name = (char *) sc->fs_name;
- break;
+ return ((char *) sc->fs_name);
}
}
}
- return fs_name;
+ return NULL;
}
char *
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/59cdc465/fs/fatfs/src/mynewt_glue.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index 189ca8a..c840185 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -1,7 +1,7 @@
#include <assert.h>
#include <sysinit/sysinit.h>
#include <hal/hal_flash.h>
-#include <mmc/mmc.h>
+#include <disk/disk.h>
#include <flash_map/flash_map.h>
#include <stdio.h>
#include <stdlib.h>
@@ -151,6 +151,7 @@ int fatfs_to_vfs_error(FRESULT res)
struct mounted_disk {
char *disk_name;
int disk_number;
+ struct disk_ops *dops;
SLIST_ENTRY(mounted_disk) sc_next;
};
@@ -185,6 +186,7 @@ drivenumber_from_disk(char *disk_name)
new_disk = malloc(sizeof(struct mounted_disk));
new_disk->disk_name = strdup(disk_name);
new_disk->disk_number = disk_number;
+ new_disk->dops = disk_ops_for(disk_name);
SLIST_INSERT_HEAD(&mounted_disks, new_disk, sc_next);
return disk_number;
@@ -472,10 +474,17 @@ disk_status(BYTE pdrv)
return RES_OK;
}
-/* FIXME */
-static struct disk_ops *disk_ops_from_handle(BYTE pdrv)
+static struct disk_ops *dops_from_handle(BYTE pdrv)
{
- return &mmc_ops;
+ struct mounted_disk *sc;
+
+ SLIST_FOREACH(sc, &mounted_disks, sc_next) {
+ if (sc->disk_number == pdrv) {
+ return sc->dops;
+ }
+ }
+
+ return NULL;
}
DRESULT
@@ -490,7 +499,7 @@ disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count)
address = (uint32_t) sector * 512;
num_bytes = (uint32_t) count * 512;
- dops = disk_ops_from_handle(pdrv);
+ dops = dops_from_handle(pdrv);
if (dops == NULL) {
return STA_NOINIT;
}
@@ -515,7 +524,7 @@ disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)
address = (uint32_t) sector * 512;
num_bytes = (uint32_t) count * 512;
- dops = disk_ops_from_handle(pdrv);
+ dops = dops_from_handle(pdrv);
if (dops == NULL) {
return STA_NOINIT;
}
[03/19] incubator-mynewt-core git commit: Accept paths without disk
when single fs registered
Posted by cc...@apache.org.
Accept paths without disk when single fs registered
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2e972af5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2e972af5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2e972af5
Branch: refs/heads/develop
Commit: 2e972af5420bd304dc1c7863e9d510575896ddb1
Parents: e5d09d2
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 5 20:34:45 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/fs/src/fs_file.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2e972af5/fs/fs/src/fs_file.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_file.c b/fs/fs/src/fs_file.c
index 35c7fe7..c706534 100644
--- a/fs/fs/src/fs_file.c
+++ b/fs/fs/src/fs_file.c
@@ -22,7 +22,6 @@
#include <disk/disk.h>
#include <string.h>
#include <stdlib.h>
-#include <stdio.h>
#include "fs_priv.h"
@@ -181,10 +180,19 @@ fops_from_filename(const char *filename)
{
char *disk;
char *fs_name = NULL;
+ struct fs_ops *unique;
disk = disk_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);
}
[02/19] incubator-mynewt-core git commit: Add nffs compat with
multiple fs
Posted by cc...@apache.org.
Add nffs compat with multiple fs
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/9f731125
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9f731125
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9f731125
Branch: refs/heads/develop
Commit: 9f7311256c9a4814e44d18e1b3f2edce4af489df
Parents: 45e0416
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 5 20:36:12 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/nffs/src/nffs.c | 2 +-
fs/nffs/src/nffs_dir.c | 5 +++++
fs/nffs/src/nffs_file.c | 4 ++++
fs/nffs/src/nffs_priv.h | 3 +++
4 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f731125/fs/nffs/src/nffs.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs.c b/fs/nffs/src/nffs.c
index eacec07..4475420 100644
--- a/fs/nffs/src/nffs.c
+++ b/fs/nffs/src/nffs.c
@@ -81,7 +81,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 struct fs_ops nffs_ops = {
+struct fs_ops nffs_ops = {
.f_open = nffs_open,
.f_close = nffs_close,
.f_read = nffs_read,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f731125/fs/nffs/src/nffs_dir.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_dir.c b/fs/nffs/src/nffs_dir.c
index 7d5ce00..8cdefa9 100644
--- a/fs/nffs/src/nffs_dir.c
+++ b/fs/nffs/src/nffs_dir.c
@@ -21,6 +21,9 @@
#include <string.h>
#include "nffs_priv.h"
#include "nffs/nffs.h"
+#include "fs/fs_if.h"
+
+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;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f731125/fs/nffs/src/nffs_file.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_file.c b/fs/nffs/src/nffs_file.c
index e065926..c542a66 100644
--- a/fs/nffs/src/nffs_file.c
+++ b/fs/nffs/src/nffs_file.c
@@ -21,6 +21,9 @@
#include <string.h>
#include "nffs_priv.h"
#include "nffs/nffs.h"
+#include "fs/fs_if.h"
+
+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;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f731125/fs/nffs/src/nffs_priv.h
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_priv.h b/fs/nffs/src/nffs_priv.h
index c871962..50cbc85 100644
--- a/fs/nffs/src/nffs_priv.h
+++ b/fs/nffs/src/nffs_priv.h
@@ -171,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;
@@ -238,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;
};
[18/19] incubator-mynewt-core git commit: Update for compatibility
with multiple FS
Posted by cc...@apache.org.
Update for compatibility with multiple FS
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4326070f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4326070f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4326070f
Branch: refs/heads/develop
Commit: 4326070fe4b5f9f92c6dca263b9cfb53236537c8
Parents: fb01e49
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 19 07:23:19 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 19 07:23:19 2017 -0200
----------------------------------------------------------------------
fs/fs/src/fs_mkdir.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4326070f/fs/fs/src/fs_mkdir.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_mkdir.c b/fs/fs/src/fs_mkdir.c
index 546736f..aca27f5 100644
--- a/fs/fs/src/fs_mkdir.c
+++ b/fs/fs/src/fs_mkdir.c
@@ -21,16 +21,18 @@
#include "fs_priv.h"
+struct fs_ops *fops_from_filename(const char *);
+
int
fs_rename(const char *from, const char *to)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ struct fs_ops *fops = fops_from_filename(from);
return fops->f_rename(from, to);
}
int
fs_mkdir(const char *path)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ struct fs_ops *fops = fops_from_filename(path);
return fops->f_mkdir(path);
}
[13/19] incubator-mynewt-core git commit: Add fops return func for
single fs registered
Posted by cc...@apache.org.
Add fops return func for single fs registered
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2f8213bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2f8213bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2f8213bd
Branch: refs/heads/develop
Commit: 2f8213bd7599c062a71ba1882ee26bbf265a8fe8
Parents: ca1b491
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 5 20:32:53 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/fs/include/fs/fs_if.h | 8 ++++++++
fs/fs/src/fs_mount.c | 12 ++++++++++++
2 files changed, 20 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2f8213bd/fs/fs/include/fs/fs_if.h
----------------------------------------------------------------------
diff --git a/fs/fs/include/fs/fs_if.h b/fs/fs/include/fs/fs_if.h
index 015d832..ade4f97 100644
--- a/fs/fs/include/fs/fs_if.h
+++ b/fs/fs/include/fs/fs_if.h
@@ -68,6 +68,14 @@ 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
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2f8213bd/fs/fs/src/fs_mount.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_mount.c b/fs/fs/src/fs_mount.c
index 5f020cf..3fceb70 100644
--- a/fs/fs/src/fs_mount.c
+++ b/fs/fs/src/fs_mount.c
@@ -53,6 +53,18 @@ fs_register(struct fs_ops *fops)
}
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;
[11/19] incubator-mynewt-core git commit: Use fops container
Posted by cc...@apache.org.
Use fops container
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4333192f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4333192f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4333192f
Branch: refs/heads/develop
Commit: 4333192f9048019439a4dfe7dbe332a807834149
Parents: 7a0dfc8
Author: Fabio Utzig <ut...@utzig.org>
Authored: Tue Jan 10 22:33:24 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/fs/src/fs_dirent.c | 5 ++---
fs/fs/src/fs_file.c | 5 ++---
2 files changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4333192f/fs/fs/src/fs_dirent.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_dirent.c b/fs/fs/src/fs_dirent.c
index ec26745..0216f3b 100644
--- a/fs/fs/src/fs_dirent.c
+++ b/fs/fs/src/fs_dirent.c
@@ -29,11 +29,10 @@ fops_from_dir(const struct fs_dir *dir)
return (struct fs_ops *) *((uint32_t *)dir);
}
-static struct fs_ops *
+static inline struct fs_ops *
fops_from_dirent(const struct fs_dirent *dirent)
{
- /* NOTE: fs_ops must always be the first field for any fs_file */
- return (struct fs_ops *) *((uint32_t *)dirent);
+ return fs_ops_from_container((struct fops_container *) dirent);
}
int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4333192f/fs/fs/src/fs_file.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_file.c b/fs/fs/src/fs_file.c
index c706534..5ad28cd 100644
--- a/fs/fs/src/fs_file.c
+++ b/fs/fs/src/fs_file.c
@@ -197,11 +197,10 @@ fops_from_filename(const char *filename)
return safe_fs_ops_for(fs_name);
}
-static struct fs_ops *
+static inline struct fs_ops *
fops_from_file(const struct fs_file *file)
{
- /* NOTE: fs_ops must always be the first field for any fs_file */
- return (struct fs_ops *) *((uint32_t *)file);
+ return fs_ops_from_container((struct fops_container *) file);
}
int
[15/19] incubator-mynewt-core git commit: hal_flash doesn't depend on
disk yet
Posted by cc...@apache.org.
hal_flash doesn't depend on disk yet
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b9bf994d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b9bf994d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b9bf994d
Branch: refs/heads/develop
Commit: b9bf994d388a44552b8066b5e5b47c5c9958df63
Parents: 59cdc46
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 12 12:20:56 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 12:20:56 2017 -0200
----------------------------------------------------------------------
hw/hal/src/hal_flash.c | 2 --
1 file changed, 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b9bf994d/hw/hal/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index 27d260a..41f0c0d 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -24,8 +24,6 @@
#include "hal/hal_flash.h"
#include "hal/hal_flash_int.h"
-#include <disk/disk.h>
-
int
hal_flash_init(void)
{
[07/19] incubator-mynewt-core git commit: Revert hal_flash
compatibility with disk/disk
Posted by cc...@apache.org.
Revert hal_flash compatibility with disk/disk
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/45e04163
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/45e04163
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/45e04163
Branch: refs/heads/develop
Commit: 45e04163e92c63ff22c59aa140420f8fba41edf1
Parents: 2e972af
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 5 20:35:15 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
hw/hal/include/hal/hal_flash.h | 3 ---
hw/hal/src/hal_flash.c | 6 ------
2 files changed, 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/45e04163/hw/hal/include/hal/hal_flash.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_flash.h b/hw/hal/include/hal/hal_flash.h
index bd4f6f3..11f5f1d 100644
--- a/hw/hal/include/hal/hal_flash.h
+++ b/hw/hal/include/hal/hal_flash.h
@@ -25,9 +25,6 @@ extern "C" {
#endif
#include <inttypes.h>
-#include <disk/disk.h>
-
-extern struct disk_ops hal_flash_ops;
int hal_flash_ioctl(uint8_t flash_id, uint32_t cmd, void *args);
int hal_flash_read(uint8_t flash_id, uint32_t address, void *dst,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/45e04163/hw/hal/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index ada6e23..27d260a 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -175,9 +175,3 @@ hal_flash_ioctl(uint8_t id, uint32_t cmd, void *args)
{
return 0;
}
-
-struct disk_ops hal_flash_ops = {
- .read = &hal_flash_read,
- .write = &hal_flash_write,
- .ioctl = &hal_flash_ioctl,
-};
[17/19] incubator-mynewt-core git commit: Remove unused include
Posted by cc...@apache.org.
Remove unused include
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/fb01e49d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fb01e49d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fb01e49d
Branch: refs/heads/develop
Commit: fb01e49df47bdb7cf45de399c107d56e0a1528b0
Parents: 2779830
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 19 07:22:56 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 19 07:22:56 2017 -0200
----------------------------------------------------------------------
fs/disk/src/disk.c | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fb01e49d/fs/disk/src/disk.c
----------------------------------------------------------------------
diff --git a/fs/disk/src/disk.c b/fs/disk/src/disk.c
index 4c915d4..cea5aee 100644
--- a/fs/disk/src/disk.c
+++ b/fs/disk/src/disk.c
@@ -18,7 +18,6 @@
*/
#include <syscfg/syscfg.h>
-#include <fs/fs.h>
#include <disk/disk.h>
#include <stdlib.h>
#include <string.h>
[19/19] incubator-mynewt-core git commit: This closes #158.
Posted by cc...@apache.org.
This closes #158.
Merge remote-tracking branch 'utzig/multi-disk' into develop
* utzig/multi-disk:
Update for compatibility with multiple FS
Remove unused include
Fix pointer int size handling
hal_flash doesn't depend on disk yet
Remove FAT dependency on MMC
Add disk interface for nffs
Move disk path routines to disk module
Use fops container
Add fops container for nicer casting
Revert stm32f4-discovery LED pin
Add nffs compat with multiple fs
Revert hal_flash compatibility with disk/disk
Accept paths without disk when single fs registered
Add disk/disk as fs dep
Add fops return func for single fs registered
FAT support for working with multi-disk interface
Fix compilation
Save multi-disk support WIP
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/56ae794c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/56ae794c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/56ae794c
Branch: refs/heads/develop
Commit: 56ae794c2088cf8308ad44a973a61b94b08a495f
Parents: f35d5d1 4326070
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jan 19 09:35:19 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Jan 19 09:35:19 2017 -0800
----------------------------------------------------------------------
fs/disk/include/disk/disk.h | 56 +++++++++
fs/disk/pkg.yml | 27 ++++
fs/disk/src/disk.c | 151 ++++++++++++++++++++++
fs/fatfs/src/mynewt_glue.c | 227 ++++++++++++++++++++++++++++------
fs/fs/include/fs/fs_if.h | 37 +++++-
fs/fs/pkg.yml | 3 +
fs/fs/src/fs_dirent.c | 30 ++++-
fs/fs/src/fs_file.c | 180 +++++++++++++++++++++++++--
fs/fs/src/fs_mkdir.c | 8 +-
fs/fs/src/fs_mount.c | 59 ++++++++-
fs/fs/src/fs_priv.h | 3 +-
fs/nffs/src/nffs.c | 19 ++-
fs/nffs/src/nffs_dir.c | 5 +
fs/nffs/src/nffs_file.c | 4 +
fs/nffs/src/nffs_priv.h | 3 +
hw/drivers/mmc/include/mmc/mmc.h | 13 +-
hw/drivers/mmc/src/mmc.c | 25 +++-
hw/hal/include/hal/hal_flash.h | 2 +-
hw/hal/src/hal_flash.c | 6 +
19 files changed, 787 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
[08/19] incubator-mynewt-core git commit: Move disk path routines to
disk module
Posted by cc...@apache.org.
Move disk path routines to disk module
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e2fcc8fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e2fcc8fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e2fcc8fa
Branch: refs/heads/develop
Commit: e2fcc8fa8d536c943b39ed2955f66e5dc8c875ae
Parents: 4333192
Author: Fabio Utzig <ut...@utzig.org>
Authored: Tue Jan 10 22:35:31 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/disk/include/disk/disk.h | 2 ++
fs/disk/src/disk.c | 58 ++++++++++++++++++++++++++++++++++++++++
fs/fatfs/src/mynewt_glue.c | 39 +++------------------------
fs/fs/include/fs/fs.h | 3 ---
fs/fs/src/fs_file.c | 28 +------------------
5 files changed, 65 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e2fcc8fa/fs/disk/include/disk/disk.h
----------------------------------------------------------------------
diff --git a/fs/disk/include/disk/disk.h b/fs/disk/include/disk/disk.h
index 49b9dde..a8695e8 100644
--- a/fs/disk/include/disk/disk.h
+++ b/fs/disk/include/disk/disk.h
@@ -46,6 +46,8 @@ struct disk_ops {
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
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e2fcc8fa/fs/disk/src/disk.c
----------------------------------------------------------------------
diff --git a/fs/disk/src/disk.c b/fs/disk/src/disk.c
index 846c44d..550dade 100644
--- a/fs/disk/src/disk.c
+++ b/fs/disk/src/disk.c
@@ -96,3 +96,61 @@ disk_fs_for(const char *disk_name)
return fs_name;
}
+
+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;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e2fcc8fa/fs/fatfs/src/mynewt_glue.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index c622ffb..189ca8a 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -190,37 +190,6 @@ drivenumber_from_disk(char *disk_name)
return disk_number;
}
-/**
- * @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 *
-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;
-}
-
static int
fatfs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
{
@@ -261,9 +230,9 @@ fatfs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
mode |= FA_CREATE_ALWAYS;
}
- disk = disk_from_path(path);
+ disk = disk_name_from_path(path);
number = drivenumber_from_disk(disk);
- filepath = filepath_from_path(path);
+ filepath = disk_filepath_from_path(path);
sprintf(drivepath, "%d:%s", number, filepath);
free(filepath);
@@ -409,9 +378,9 @@ fatfs_opendir(const char *path, struct fs_dir **out_fs_dir)
goto out;
}
- disk = disk_from_path(path);
+ disk = disk_name_from_path(path);
number = drivenumber_from_disk(disk);
- filepath = filepath_from_path(path);
+ filepath = disk_filepath_from_path(path);
sprintf(drivepath, "%d:%s", number, filepath);
free(filepath);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e2fcc8fa/fs/fs/include/fs/fs.h
----------------------------------------------------------------------
diff --git a/fs/fs/include/fs/fs.h b/fs/fs/include/fs/fs.h
index f823b32..b44f624 100644
--- a/fs/fs/include/fs/fs.h
+++ b/fs/fs/include/fs/fs.h
@@ -53,9 +53,6 @@ int fs_dirent_name(const struct fs_dirent *, size_t max_len,
char *out_name, uint8_t *out_name_len);
int fs_dirent_is_dir(const struct fs_dirent *);
-/* Helper functions */
-char *disk_from_path(const char *path);
-
/*
* File access flags.
*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e2fcc8fa/fs/fs/src/fs_file.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_file.c b/fs/fs/src/fs_file.c
index 5ad28cd..305a3c4 100644
--- a/fs/fs/src/fs_file.c
+++ b/fs/fs/src/fs_file.c
@@ -149,32 +149,6 @@ safe_fs_ops_for(const char *fs_name)
return fops;
}
-char *disk_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;
-}
-
struct fs_ops *
fops_from_filename(const char *filename)
{
@@ -182,7 +156,7 @@ fops_from_filename(const char *filename)
char *fs_name = NULL;
struct fs_ops *unique;
- disk = disk_from_path(filename);
+ disk = disk_name_from_path(filename);
if (disk) {
fs_name = disk_fs_for(disk);
} else {
[05/19] incubator-mynewt-core git commit: Save multi-disk support WIP
Posted by cc...@apache.org.
Save multi-disk support WIP
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1a029621
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1a029621
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1a029621
Branch: refs/heads/develop
Commit: 1a029621576f068a361d322d9dfb789a7f34d54d
Parents: 0845466
Author: Fabio Utzig <ut...@utzig.org>
Authored: Wed Dec 14 16:39:52 2016 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/fatfs/src/mynewt_glue.c | 24 +-
fs/fatfs/src/mynewt_glue_2.c | 410 +++++++++++++++++++++++++
fs/fs/include/fs/fs_if.h | 21 +-
fs/fs/src/fs_dirent.c | 15 +-
fs/fs/src/fs_file.c | 62 +++-
fs/fs/src/fs_mkdir.c | 6 +-
fs/fs/src/fs_mount.c | 32 +-
fs/fs/src/fs_priv.h | 3 +-
hw/bsp/stm32f4discovery/include/bsp/bsp.h | 2 +-
hw/drivers/mmc/include/mmc/mmc.h | 3 +
hw/drivers/mmc/src/mmc.c | 17 +
hw/hal/include/hal/hal_flash.h | 5 +-
hw/hal/src/hal_flash.c | 14 +
sys/diskio/include/diskio/diskio.h | 51 +++
sys/diskio/pkg.yml | 27 ++
sys/diskio/src/diskio.c | 57 ++++
16 files changed, 721 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/fs/fatfs/src/mynewt_glue.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index 0f45cfb..f2382f8 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -1,6 +1,7 @@
#include <assert.h>
#include <sysinit/sysinit.h>
#include <hal/hal_flash.h>
+#include <mmc/mmc.h>
#include <flash_map/flash_map.h>
#include <stdio.h>
#include <stdlib.h>
@@ -348,17 +349,29 @@ disk_status(BYTE pdrv)
return RES_OK;
}
+static struct disk_ops *disk_ops_from_handle(BYTE pdrv)
+{
+ return &mmc_ops;
+}
+
DRESULT
disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count)
{
int rc;
uint32_t address;
uint32_t num_bytes;
+ struct disk_ops *dops;
/* NOTE: safe to assume sector size as 512 for now, see ffconf.h */
address = (uint32_t) sector * 512;
num_bytes = (uint32_t) count * 512;
- rc = hal_flash_read(pdrv, address, (void *) buff, num_bytes);
+
+ dops = disk_ops_from_handle(pdrv);
+ if (dops == NULL) {
+ return STA_NOINIT;
+ }
+
+ rc = dops->read(pdrv, address, (void *) buff, num_bytes);
if (rc < 0) {
return STA_NOINIT;
}
@@ -372,11 +385,18 @@ disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)
int rc;
uint32_t address;
uint32_t num_bytes;
+ struct disk_ops *dops;
/* NOTE: safe to assume sector size as 512 for now, see ffconf.h */
address = (uint32_t) sector * 512;
num_bytes = (uint32_t) count * 512;
- rc = hal_flash_write(pdrv, address, (const void *) buff, num_bytes);
+
+ dops = disk_ops_from_handle(pdrv);
+ if (dops == NULL) {
+ return STA_NOINIT;
+ }
+
+ rc = dops->write(pdrv, address, (const void *) buff, num_bytes);
if (rc < 0) {
return STA_NOINIT;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/fs/fatfs/src/mynewt_glue_2.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue_2.c b/fs/fatfs/src/mynewt_glue_2.c
new file mode 100644
index 0000000..8be7265
--- /dev/null
+++ b/fs/fatfs/src/mynewt_glue_2.c
@@ -0,0 +1,410 @@
+#include <assert.h>
+#include <sysinit/sysinit.h>
+#include <hal/hal_flash.h>
+#include <flash_map/flash_map.h>
+#include <mmc/mmc.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <fatfs/ff.h>
+#include <fatfs/diskio.h>
+
+#include <fs/fs.h>
+#include <fs/fs_if.h>
+
+static int fatfs_open(const char *path, uint8_t access_flags,
+ struct fs_file **out_file);
+static int fatfs_close(struct fs_file *fs_file);
+static int fatfs_read(struct fs_file *fs_file, uint32_t len, void *out_data,
+ uint32_t *out_len);
+static int fatfs_write(struct fs_file *fs_file, const void *data, int len);
+static int fatfs_seek(struct fs_file *fs_file, uint32_t offset);
+static uint32_t fatfs_getpos(const struct fs_file *fs_file);
+static int fatfs_file_len(const struct fs_file *fs_file, uint32_t *out_len);
+static int fatfs_unlink(const char *path);
+static int fatfs_rename(const char *from, const char *to);
+static int fatfs_mkdir(const char *path);
+static int fatfs_opendir(const char *path, struct fs_dir **out_fs_dir);
+static int fatfs_readdir(struct fs_dir *dir, struct fs_dirent **out_dirent);
+static int fatfs_closedir(struct fs_dir *dir);
+static int fatfs_dirent_name(const struct fs_dirent *fs_dirent, size_t max_len,
+ char *out_name, uint8_t *out_name_len);
+static int fatfs_dirent_is_dir(const struct fs_dirent *fs_dirent);
+
+/* NOTE: to ease memory management of dirent structs, this single static
+ * variable holds the latest entry found by readdir. This limits FAT to
+ * working on a single thread, single opendir -> closedir cycle.
+ */
+static FILINFO filinfo;
+
+static const struct fs_ops fatfs_ops = {
+ .f_open = fatfs_open,
+ .f_close = fatfs_close,
+ .f_read = fatfs_read,
+ .f_write = fatfs_write,
+
+ .f_seek = fatfs_seek,
+ .f_getpos = fatfs_getpos,
+ .f_filelen = fatfs_file_len,
+
+ .f_unlink = fatfs_unlink,
+ .f_rename = fatfs_rename,
+ .f_mkdir = fatfs_mkdir,
+
+ .f_opendir = fatfs_opendir,
+ .f_readdir = fatfs_readdir,
+ .f_closedir = fatfs_closedir,
+
+ .f_dirent_name = fatfs_dirent_name,
+ .f_dirent_is_dir = fatfs_dirent_is_dir,
+
+ .f_name = "fatfs"
+};
+
+int fatfs_to_vfs_error(FRESULT res)
+{
+ int rc = FS_EOS;
+
+ switch (res) {
+ case FR_OK:
+ rc = FS_EOK;
+ break;
+ case FR_DISK_ERR: /* (1) A hard error occurred in the low level disk I/O layer */
+ rc = FS_EHW;
+ break;
+ case FR_INT_ERR: /* (2) Assertion failed */
+ rc = FS_EOS;
+ break;
+ case FR_NOT_READY: /* (3) The physical drive cannot work */
+ rc = FS_ECORRUPT;
+ break;
+ case FR_NO_FILE: /* (4) Could not find the file */
+ /* passthrough */
+ case FR_NO_PATH: /* (5) Could not find the path */
+ rc = FS_ENOENT;
+ break;
+ case FR_INVALID_NAME: /* (6) The path name format is invalid */
+ rc = FS_EINVAL;
+ break;
+ case FR_DENIED: /* (7) Access denied due to prohibited access or directory full */
+ rc = FS_EACCESS;
+ break;
+ case FR_EXIST: /* (8) Access denied due to prohibited access */
+ rc = FS_EEXIST;
+ break;
+ case FR_INVALID_OBJECT: /* (9) The file/directory object is invalid */
+ rc = FS_EINVAL;
+ break;
+ case FR_WRITE_PROTECTED: /* (10) The physical drive is write protected */
+ /* TODO: assign correct error */
+ break;
+ case FR_INVALID_DRIVE: /* (11) The logical drive number is invalid */
+ rc = FS_EHW;
+ break;
+ case FR_NOT_ENABLED: /* (12) The volume has no work area */
+ rc = FS_EUNEXP;
+ break;
+ case FR_NO_FILESYSTEM: /* (13) There is no valid FAT volume */
+ rc = FS_EUNINIT;
+ break;
+ case FR_MKFS_ABORTED: /* (14) The f_mkfs() aborted due to any problem */
+ /* TODO: assign correct error */
+ break;
+ case FR_TIMEOUT: /* (15) Could not get a grant to access the volume within defined period */
+ /* TODO: assign correct error */
+ break;
+ case FR_LOCKED: /* (16) The operation is rejected according to the file sharing policy */
+ /* TODO: assign correct error */
+ break;
+ case FR_NOT_ENOUGH_CORE: /* (17) LFN working buffer could not be allocated */
+ rc = FS_ENOMEM;
+ break;
+ case FR_TOO_MANY_OPEN_FILES: /* (18) Number of open files > _FS_LOCK */
+ /* TODO: assign correct error */
+ break;
+ case FR_INVALID_PARAMETER: /* (19) Given parameter is invalid */
+ rc = FS_EINVAL;
+ break;
+ }
+
+ return rc;
+}
+
+static int
+fatfs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
+{
+ FRESULT res;
+ FIL *out_file;
+ BYTE mode;
+
+ out_file = malloc(sizeof(FIL));
+ if (!out_file) {
+ return FS_ENOMEM;
+ }
+
+ mode = FA_OPEN_EXISTING;
+ if (access_flags & FS_ACCESS_READ) {
+ mode |= FA_READ;
+ }
+ if (access_flags & FS_ACCESS_WRITE) {
+ mode |= FA_WRITE;
+ }
+ if (access_flags & FS_ACCESS_APPEND) {
+ mode |= FA_OPEN_APPEND;
+ }
+ if (access_flags & FS_ACCESS_TRUNCATE) {
+ mode &= ~FA_OPEN_EXISTING;
+ mode |= FA_CREATE_ALWAYS;
+ }
+
+ res = f_open(out_file, path, mode);
+ if (res != FR_OK) {
+ free(out_file);
+ return fatfs_to_vfs_error(res);
+ }
+ *out_fs_file = (struct fs_file *)out_file;
+ return FS_EOK;
+}
+
+static int
+fatfs_close(struct fs_file *fs_file)
+{
+ FRESULT res;
+ FIL *file = (FIL *)fs_file;
+
+ if (file == NULL) {
+ return FS_EOK;
+ }
+
+ res = f_close(file);
+ free(file);
+ return fatfs_to_vfs_error(res);
+}
+
+static int
+fatfs_seek(struct fs_file *fs_file, uint32_t offset)
+{
+ FRESULT res;
+ FIL *file = (FIL *)fs_file;
+
+ res = f_lseek(file, offset);
+ return fatfs_to_vfs_error(res);
+}
+
+static uint32_t
+fatfs_getpos(const struct fs_file *fs_file)
+{
+ uint32_t offset;
+ FIL *file = (FIL *)fs_file;
+
+ offset = (uint32_t) f_tell(file);
+ return offset;
+}
+
+static int
+fatfs_file_len(const struct fs_file *fs_file, uint32_t *out_len)
+{
+ uint32_t offset;
+ FIL *file = (FIL *)fs_file;
+
+ offset = (uint32_t) f_size(file);
+ return offset;
+}
+
+static int
+fatfs_read(struct fs_file *fs_file, uint32_t len, void *out_data,
+ uint32_t *out_len)
+{
+ FRESULT res;
+ FIL *file = (FIL *)fs_file;
+
+ res = f_read(file, out_data, len, (UINT *)out_len);
+ return fatfs_to_vfs_error(res);
+}
+
+static int
+fatfs_write(struct fs_file *fs_file, const void *data, int len)
+{
+ FRESULT res;
+ UINT out_len;
+ FIL *file = (FIL *)fs_file;
+
+ res = f_write(file, data, len, &out_len);
+ if (len != out_len) {
+ return FS_EFULL;
+ }
+ return fatfs_to_vfs_error(res);
+}
+
+static int
+fatfs_unlink(const char *path)
+{
+ FRESULT res;
+
+ res = f_unlink(path);
+ return fatfs_to_vfs_error(res);
+}
+
+static int
+fatfs_rename(const char *from, const char *to)
+{
+ FRESULT res;
+
+ res = f_rename(from, to);
+ return fatfs_to_vfs_error(res);
+}
+
+static int
+fatfs_mkdir(const char *path)
+{
+ FRESULT res;
+
+ res = f_mkdir(path);
+ return fatfs_to_vfs_error(res);
+}
+
+static int
+fatfs_opendir(const char *path, struct fs_dir **out_fs_dir)
+{
+ FRESULT res;
+ FATFS_DIR *out_dir;
+
+ out_dir = malloc(sizeof(FATFS_DIR));
+ if (!out_dir) {
+ return FS_ENOMEM;
+ }
+
+ res = f_opendir(out_dir, path);
+ if (res != FR_OK) {
+ return fatfs_to_vfs_error(res);
+ }
+ *out_fs_dir = (struct fs_dir *)out_dir;
+ return FS_EOK;
+}
+
+static int
+fatfs_readdir(struct fs_dir *fs_dir, struct fs_dirent **out_fs_dirent)
+{
+ FRESULT res;
+ FATFS_DIR *dir = (FATFS_DIR *)fs_dir;
+
+ res = f_readdir(dir, &filinfo);
+ if (res != FR_OK) {
+ return fatfs_to_vfs_error(res);
+ }
+
+ *out_fs_dirent = (struct fs_dirent *)&filinfo;
+ if (!filinfo.fname[0]) {
+ return FS_ENOENT;
+ }
+ return FS_EOK;
+}
+
+static int
+fatfs_closedir(struct fs_dir *fs_dir)
+{
+ FRESULT res;
+ FATFS_DIR *dir = (FATFS_DIR *)fs_dir;
+
+ res = f_closedir(dir);
+ free(dir);
+ return fatfs_to_vfs_error(res);
+}
+
+static int
+fatfs_dirent_name(const struct fs_dirent *fs_dirent, size_t max_len,
+ char *out_name, uint8_t *out_name_len)
+{
+ const FILINFO *dirent = (const FILINFO *)fs_dirent;
+ size_t out_len;
+
+ assert(dirent != NULL);
+ out_len = max_len < sizeof(dirent->fname) ? max_len : sizeof(dirent->fname);
+ memcpy(out_name, dirent->fname, out_len);
+ *out_name_len = out_len;
+ return FS_EOK;
+}
+
+static int
+fatfs_dirent_is_dir(const struct fs_dirent *fs_dirent)
+{
+ const FILINFO *dirent = (const FILINFO *)fs_dirent;
+
+ assert(dirent != NULL);
+ return dirent->fattrib & AM_DIR;
+}
+
+DSTATUS
+disk_initialize(BYTE pdrv)
+{
+ /* Don't need to do anything while using hal_flash */
+ return RES_OK;
+}
+
+DSTATUS
+disk_status(BYTE pdrv)
+{
+ /* Always OK on native emulated flash */
+ return RES_OK;
+}
+
+DRESULT
+disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count)
+{
+ int rc;
+ uint32_t address;
+ uint32_t num_bytes;
+
+ /* NOTE: safe to assume sector size as 512 for now, see ffconf.h */
+ address = (uint32_t) sector * 512;
+ num_bytes = (uint32_t) count * 512;
+ //rc = hal_flash_read(pdrv, address, (void *) buff, num_bytes);
+ rc = mmc_read(pdrv, address, (void *) buff, num_bytes);
+ if (rc < 0) {
+ return STA_NOINIT;
+ }
+
+ return RES_OK;
+}
+
+DRESULT
+disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)
+{
+ int rc;
+ uint32_t address;
+ uint32_t num_bytes;
+
+ /* NOTE: safe to assume sector size as 512 for now, see ffconf.h */
+ address = (uint32_t) sector * 512;
+ num_bytes = (uint32_t) count * 512;
+ //rc = hal_flash_write(pdrv, address, (const void *) buff, num_bytes);
+ rc = mmc_write(pdrv, address, (const void *) buff, num_bytes);
+ if (rc < 0) {
+ return STA_NOINIT;
+ }
+
+ return RES_OK;
+}
+
+DRESULT
+disk_ioctl(BYTE pdrv, BYTE cmd, void* buff)
+{
+ return RES_OK;
+}
+
+/* FIXME: _FS_NORTC=1 because there is not hal_rtc interface */
+DWORD
+get_fattime(void)
+{
+ return 0;
+}
+
+void
+fatfs_pkg_init(void)
+{
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
+ fs_register(&fatfs_ops);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/fs/fs/include/fs/fs_if.h
----------------------------------------------------------------------
diff --git a/fs/fs/include/fs/fs_if.h b/fs/fs/include/fs/fs_if.h
index 5d71f1b..842f070 100644
--- a/fs/fs/include/fs/fs_if.h
+++ b/fs/fs/include/fs/fs_if.h
@@ -52,12 +52,27 @@ 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.
+/**
+ * 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 *fops);
+
+/**
+ * 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
*/
-int fs_register(const struct fs_ops *);
+struct fs_ops *fs_ops_for(const char *name);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/fs/fs/src/fs_dirent.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_dirent.c b/fs/fs/src/fs_dirent.c
index bc526f2..b5fd6c5 100644
--- a/fs/fs/src/fs_dirent.c
+++ b/fs/fs/src/fs_dirent.c
@@ -23,30 +23,35 @@
int
fs_opendir(const char *path, struct fs_dir **out_dir)
{
- return fs_root_ops->f_opendir(path, out_dir);
+ struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ return fops->f_dirent_is_dir(dirent);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/fs/fs/src/fs_file.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_file.c b/fs/fs/src/fs_file.c
index fcc2e2c..fdcecda 100644
--- a/fs/fs/src/fs_file.c
+++ b/fs/fs/src/fs_file.c
@@ -21,50 +21,96 @@
#include "fs_priv.h"
+static int
+not_initialized(const void *v, ...)
+{
+ return FS_EUNINIT;
+}
+
+static struct fs_ops not_initialized_ops = {
+ .f_open = not_initialized,
+ .f_close = not_initialized,
+ .f_read = not_initialized,
+ .f_write = not_initialized,
+ .f_seek = not_initialized,
+ .f_getpos = not_initialized,
+ .f_filelen = not_initialized,
+ .f_unlink = not_initialized,
+ .f_rename = not_initialized,
+ .f_mkdir = not_initialized,
+ .f_opendir = not_initialized,
+ .f_readdir = not_initialized,
+ .f_closedir = not_initialized,
+ .f_dirent_name = not_initialized,
+ .f_dirent_is_dir = not_initialized,
+ .f_name = "fakefs",
+};
+
+struct fs_ops *
+safe_fs_ops_for(const char *fs_name)
+{
+ struct fs_ops *fops;
+
+ fops = fs_ops_for("fatfs");
+ if (fops == NULL) {
+ fops = ¬_initialized_ops;
+ }
+
+ return fops;
+}
+
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 = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ 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 = safe_fs_ops_for("fatfs");
+ return fops->f_filelen(file, out_len);
}
int
fs_unlink(const char *filename)
{
- return fs_root_ops->f_unlink(filename);
+ struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ return fops->f_unlink(filename);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/fs/fs/src/fs_mkdir.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_mkdir.c b/fs/fs/src/fs_mkdir.c
index 2072229..546736f 100644
--- a/fs/fs/src/fs_mkdir.c
+++ b/fs/fs/src/fs_mkdir.c
@@ -24,11 +24,13 @@
int
fs_rename(const char *from, const char *to)
{
- return fs_root_ops->f_rename(from, to);
+ struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ return fops->f_rename(from, to);
}
int
fs_mkdir(const char *path)
{
- return fs_root_ops->f_mkdir(path);
+ struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ return fops->f_mkdir(path);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/fs/fs/src/fs_mount.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_mount.c b/fs/fs/src/fs_mount.c
index 9645d1a..174fac8 100644
--- a/fs/fs/src/fs_mount.c
+++ b/fs/fs/src/fs_mount.c
@@ -22,19 +22,41 @@
#include "fs/fs_if.h"
#include "fs_priv.h"
-const struct fs_ops *fs_root_ops = NULL;
+static SLIST_HEAD(, fs_ops) root_fops = SLIST_HEAD_INITIALIZER();
+static bool g_cli_initialized = false;
int
fs_register(const struct fs_ops *fops)
{
- if (fs_root_ops) {
- return FS_EEXIST;
+ SLIST_FOREACH(sc, &root_fops, sc_next) {
+ if (strcmp(sc->f_name, fops->f_name) == 0) {
+ return FS_EEXIST;
+ }
}
- fs_root_ops = fops;
+
+ SLIST_INSERT_HEAD(&root_fops, fops, sc_next);
#if MYNEWT_VAL(FS_CLI)
- fs_cli_init();
+ if (!g_cli_initialized) {
+ fs_cli_init();
+ g_cli_initialized = true;
+ }
#endif
return FS_EOK;
}
+
+struct fs_ops *
+fs_ops_for(const char *fs_name)
+{
+ struct fs_ops *fops = NULL;
+
+ SLIST_FOREACH(sc, &root_fops, sc_next) {
+ if (strcmp(sc->f_name, fs_name) == 0) {
+ fops = sc;
+ break;
+ }
+ }
+
+ return fops;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/fs/fs/src/fs_priv.h
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_priv.h b/fs/fs/src/fs_priv.h
index 5733733..d9cbd2d 100644
--- a/fs/fs/src/fs_priv.h
+++ b/fs/fs/src/fs_priv.h
@@ -26,7 +26,8 @@ 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);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/hw/bsp/stm32f4discovery/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/include/bsp/bsp.h b/hw/bsp/stm32f4discovery/include/bsp/bsp.h
index dd038e9..ca8a92c 100644
--- a/hw/bsp/stm32f4discovery/include/bsp/bsp.h
+++ b/hw/bsp/stm32f4discovery/include/bsp/bsp.h
@@ -41,7 +41,7 @@ extern uint8_t _ccram_start;
#define CCRAM_SIZE (64 * 1024)
/* LED pins */
-#define LED_BLINK_PIN MCU_GPIO_PORTD(12)
+#define LED_BLINK_PIN MCU_GPIO_PORTD(13)
/* UART */
#define UART_CNT 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/hw/drivers/mmc/include/mmc/mmc.h
----------------------------------------------------------------------
diff --git a/hw/drivers/mmc/include/mmc/mmc.h b/hw/drivers/mmc/include/mmc/mmc.h
index d65363d..a13b682 100644
--- a/hw/drivers/mmc/include/mmc/mmc.h
+++ b/hw/drivers/mmc/include/mmc/mmc.h
@@ -21,6 +21,7 @@
#define __MMC_H__
#include <os/os_dev.h>
+#include <diskio/diskio.h>
#ifdef __cplusplus
extern "C" {
@@ -43,6 +44,8 @@ extern "C" {
#define MMC_ERASE_ERROR (-11)
#define MMC_ADDR_ERROR (-12)
+extern struct disk_ops mmc_ops;
+
/**
* Initialize the MMC driver
*
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/hw/drivers/mmc/src/mmc.c
----------------------------------------------------------------------
diff --git a/hw/drivers/mmc/src/mmc.c b/hw/drivers/mmc/src/mmc.c
index ca89434..0b2aa98 100644
--- a/hw/drivers/mmc/src/mmc.c
+++ b/hw/drivers/mmc/src/mmc.c
@@ -583,3 +583,20 @@ out:
hal_gpio_write(mmc->ss_pin, 1);
return (rc);
}
+
+/*
+ *
+ */
+int mmc_ioctl(int cmd, void *arg)
+{
+ return 0;
+}
+
+/*
+ *
+ */
+struct disk_ops mmc_ops = {
+ .read = mmc_read,
+ .write = mmc_write,
+ .ioctl = mmc_ioctl,
+};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/hw/hal/include/hal/hal_flash.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_flash.h b/hw/hal/include/hal/hal_flash.h
index 2895479..1fdc91e 100644
--- a/hw/hal/include/hal/hal_flash.h
+++ b/hw/hal/include/hal/hal_flash.h
@@ -25,7 +25,11 @@ extern "C" {
#endif
#include <inttypes.h>
+#include <diskio/diskio.h>
+extern struct disk_ops hal_flash_ops;
+
+int hal_flash_ioctl(uint8_t flash_id, uint32_t cmd, void *args);
int hal_flash_read(uint8_t flash_id, uint32_t address, void *dst,
uint32_t num_bytes);
int hal_flash_write(uint8_t flash_id, uint32_t address, const void *src,
@@ -35,7 +39,6 @@ int hal_flash_erase(uint8_t flash_id, uint32_t address, uint32_t num_bytes);
uint8_t hal_flash_align(uint8_t flash_id);
int hal_flash_init(void);
-
#ifdef __cplusplus
}
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/hw/hal/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index ba51f8a..a95b57b 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -24,6 +24,8 @@
#include "hal/hal_flash.h"
#include "hal/hal_flash_int.h"
+#include <diskio/diskio.h>
+
int
hal_flash_init(void)
{
@@ -167,3 +169,15 @@ hal_flash_erase(uint8_t id, uint32_t address, uint32_t num_bytes)
}
return 0;
}
+
+int
+hal_flash_ioctl(uint8_t id, uint32_t cmd, void *args)
+{
+ return 0;
+}
+
+static struct disk_ops hal_flash_ops = {
+ .read = hal_flash_read,
+ .write = hal_flash_write,
+ .ioctl = hal_flash_ioctl,
+};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/sys/diskio/include/diskio/diskio.h
----------------------------------------------------------------------
diff --git a/sys/diskio/include/diskio/diskio.h b/sys/diskio/include/diskio/diskio.h
new file mode 100644
index 0000000..a0a68f6
--- /dev/null
+++ b/sys/diskio/include/diskio/diskio.h
@@ -0,0 +1,51 @@
+/*
+ * 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 __DISKIO_H__
+#define __DISKIO_H__
+
+#include <stddef.h>
+#include <inttypes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DISKIO_EOK 0 /* Success */
+#define DISKIO_EHW 1 /* Error accessing storage medium */
+#define DISKIO_ENOMEM 2 /* Insufficient memory */
+#define DISKIO_ENOENT 3 /* No such file or directory */
+#define DISKIO_EOS 4 /* OS error */
+#define DISKIO_EUNINIT 5 /* File system not initialized */
+
+struct disk_ops {
+ int (*read)(int, uint32_t, void *, uint32_t);
+ int (*write)(int, uint32_t, const void *, uint32_t);
+ int (*ioctl)(int, uint32_t, const void *);
+
+ SLIST_ENTRY(disk_ops) sc_next;
+};
+
+int diskio_register(const char *disk_name, const char *fs_name, struct disk_ops *dops);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/sys/diskio/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/diskio/pkg.yml b/sys/diskio/pkg.yml
new file mode 100644
index 0000000..8981937
--- /dev/null
+++ b/sys/diskio/pkg.yml
@@ -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: sys/diskio
+pkg.description: Disk IO layer to glue filesystems to disk devices.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - kernel/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a029621/sys/diskio/src/diskio.c
----------------------------------------------------------------------
diff --git a/sys/diskio/src/diskio.c b/sys/diskio/src/diskio.c
new file mode 100644
index 0000000..e74eae3
--- /dev/null
+++ b/sys/diskio/src/diskio.c
@@ -0,0 +1,57 @@
+/*
+ * 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 "fs/fs.h"
+#include <diskio/diskio.h>
+
+static struct disk_info {
+ char *disk_name;
+ char *fs_name;
+ struct disk_ops *dops;
+};
+
+static SLIST_HEAD(, disk_info) disks = SLIST_HEAD_INITIALIZER();
+
+/**
+ *
+ */
+int diskio_register(const char *disk_name, const char *fs_name, struct disk_ops *dops)
+{
+ struct disk_info *info = NULL;
+
+ SLIST_FOREACH(sc, &disks, sc_next) {
+ if (strcmp(sc->disk_name, disk_name) == 0) {
+ return DISKIO_EEXIST;
+ }
+ }
+
+ info = malloc(sizeof(struct disk_info));
+ if (!info) {
+ return DISKIO_ENOMEM;
+ }
+
+ info.disk_name = disk_name;
+ info.fs_name = fs_name;
+ info.dops = dops;
+
+ SLIST_INSERT_HEAD(&disks, info, sc_next);
+
+ return 0;
+}
[16/19] incubator-mynewt-core git commit: Fix pointer int size
handling
Posted by cc...@apache.org.
Fix pointer int size handling
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/27798309
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/27798309
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/27798309
Branch: refs/heads/develop
Commit: 2779830924429bd3bad2e218d79d6aef8aaa67a0
Parents: b9bf994
Author: Fabio Utzig <ut...@utzig.org>
Authored: Wed Jan 18 20:12:38 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Wed Jan 18 20:12:38 2017 -0200
----------------------------------------------------------------------
fs/fatfs/src/mynewt_glue.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27798309/fs/fatfs/src/mynewt_glue.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index c840185..c065fc1 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -308,8 +308,10 @@ fatfs_read(struct fs_file *fs_file, uint32_t len, void *out_data,
{
FRESULT res;
FIL *file = ((struct fatfs_file *) fs_file)->file;
+ UINT uint_len;
- res = f_read(file, out_data, len, (UINT *)out_len);
+ res = f_read(file, out_data, len, &uint_len);
+ *out_len = uint_len;
return fatfs_to_vfs_error(res);
}
[04/19] incubator-mynewt-core git commit: Add disk/disk as fs dep
Posted by cc...@apache.org.
Add disk/disk as fs dep
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e5d09d2e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e5d09d2e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e5d09d2e
Branch: refs/heads/develop
Commit: e5d09d2e2eb049a10ae0b6280fe41192efb9d494
Parents: 2f8213b
Author: Fabio Utzig <ut...@utzig.org>
Authored: Thu Jan 5 20:33:21 2017 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/fs/pkg.yml | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5d09d2e/fs/fs/pkg.yml
----------------------------------------------------------------------
diff --git a/fs/fs/pkg.yml b/fs/fs/pkg.yml
index 7225192..431dc24 100644
--- a/fs/fs/pkg.yml
+++ b/fs/fs/pkg.yml
@@ -26,5 +26,8 @@ pkg.keywords:
- filesystem
- ffs
+pkg.deps:
+ - fs/disk
+
pkg.deps.FS_CLI:
- sys/shell
[06/19] incubator-mynewt-core git commit: FAT support for working
with multi-disk interface
Posted by cc...@apache.org.
FAT support for working with multi-disk interface
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ca1b4915
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ca1b4915
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ca1b4915
Branch: refs/heads/develop
Commit: ca1b4915cea82b54570d4b7bc2ad68bdf1240aae
Parents: 6e9213f
Author: Fabio Utzig <ut...@utzig.org>
Authored: Mon Dec 19 21:15:22 2016 -0200
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Thu Jan 12 10:51:46 2017 -0200
----------------------------------------------------------------------
fs/disk/include/disk/disk.h | 2 +
fs/disk/src/disk.c | 36 +++++++
fs/fatfs/src/mynewt_glue.c | 219 +++++++++++++++++++++++++++++++++------
fs/fs/include/fs/fs.h | 3 +
fs/fs/src/fs_dirent.c | 26 ++++-
fs/fs/src/fs_file.c | 69 ++++++++++--
6 files changed, 309 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca1b4915/fs/disk/include/disk/disk.h
----------------------------------------------------------------------
diff --git a/fs/disk/include/disk/disk.h b/fs/disk/include/disk/disk.h
index e87fc7b..49b9dde 100644
--- a/fs/disk/include/disk/disk.h
+++ b/fs/disk/include/disk/disk.h
@@ -44,6 +44,8 @@ struct disk_ops {
};
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);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca1b4915/fs/disk/src/disk.c
----------------------------------------------------------------------
diff --git a/fs/disk/src/disk.c b/fs/disk/src/disk.c
index 803e1a5..846c44d 100644
--- a/fs/disk/src/disk.c
+++ b/fs/disk/src/disk.c
@@ -60,3 +60,39 @@ int disk_register(const char *disk_name, const char *fs_name, struct disk_ops *d
return 0;
}
+
+struct disk_ops *
+disk_ops_for(const char *disk_name)
+{
+ struct disk_ops *dops = NULL;
+ struct disk_info *sc;
+
+ if (disk_name) {
+ SLIST_FOREACH(sc, &disks, sc_next) {
+ if (strcmp(sc->disk_name, disk_name) == 0) {
+ dops = sc->dops;
+ break;
+ }
+ }
+ }
+
+ return dops;
+}
+
+char *
+disk_fs_for(const char *disk_name)
+{
+ char *fs_name = NULL;
+ struct disk_info *sc;
+
+ if (disk_name) {
+ SLIST_FOREACH(sc, &disks, sc_next) {
+ if (strcmp(sc->disk_name, disk_name) == 0) {
+ fs_name = (char *) sc->fs_name;
+ break;
+ }
+ }
+ }
+
+ return fs_name;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca1b4915/fs/fatfs/src/mynewt_glue.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index f64bbb2..c622ffb 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -32,11 +32,28 @@ static int fatfs_dirent_name(const struct fs_dirent *fs_dirent, size_t max_len,
char *out_name, uint8_t *out_name_len);
static int fatfs_dirent_is_dir(const struct fs_dirent *fs_dirent);
+#define DRIVE_LEN 4
+
+struct fatfs_file {
+ struct fs_ops *fops;
+ FIL *file;
+};
+
+struct fatfs_dir {
+ struct fs_ops *fops;
+ FATFS_DIR *dir;
+};
+
+struct fatfs_dirent {
+ struct fs_ops *fops;
+ FILINFO filinfo;
+};
+
/* NOTE: to ease memory management of dirent structs, this single static
* variable holds the latest entry found by readdir. This limits FAT to
* working on a single thread, single opendir -> closedir cycle.
*/
-static FILINFO filinfo;
+static struct fatfs_dirent dirent;
static struct fs_ops fatfs_ops = {
.f_open = fatfs_open,
@@ -131,16 +148,102 @@ int fatfs_to_vfs_error(FRESULT res)
return rc;
}
+struct mounted_disk {
+ char *disk_name;
+ int disk_number;
+
+ SLIST_ENTRY(mounted_disk) sc_next;
+};
+
+static SLIST_HEAD(, mounted_disk) mounted_disks = SLIST_HEAD_INITIALIZER();
+
+static int
+drivenumber_from_disk(char *disk_name)
+{
+ struct mounted_disk *sc;
+ struct mounted_disk *new_disk;
+ int disk_number;
+ FATFS *fs;
+ char path[DRIVE_LEN];
+
+ disk_number = 0;
+ if (disk_name) {
+ SLIST_FOREACH(sc, &mounted_disks, sc_next) {
+ if (strcmp(sc->disk_name, disk_name) == 0) {
+ return sc->disk_number;
+ }
+ disk_number++;
+ }
+ }
+
+ /* XXX: check for errors? */
+ fs = malloc(sizeof(FATFS));
+ sprintf(path, "%d:", disk_number);
+ f_mount(fs, path, 1);
+
+ /* FIXME */
+ new_disk = malloc(sizeof(struct mounted_disk));
+ new_disk->disk_name = strdup(disk_name);
+ new_disk->disk_number = disk_number;
+ SLIST_INSERT_HEAD(&mounted_disks, new_disk, sc_next);
+
+ return disk_number;
+}
+
+/**
+ * @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 *
+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;
+}
+
static int
fatfs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
{
FRESULT res;
- FIL *out_file;
+ FIL *out_file = NULL;
BYTE mode;
+ struct fatfs_file *file = NULL;
+ char *disk;
+ int number;
+ char *filepath;
+ char drivepath[255 + DRIVE_LEN]; /* FIXME */
+ int rc;
+
+ file = malloc(sizeof(struct fatfs_file));
+ if (!file) {
+ rc = FS_ENOMEM;
+ goto out;
+ }
out_file = malloc(sizeof(FIL));
if (!out_file) {
- return FS_ENOMEM;
+ rc = FS_ENOMEM;
+ goto out;
}
mode = FA_OPEN_EXISTING;
@@ -158,20 +261,36 @@ fatfs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
mode |= FA_CREATE_ALWAYS;
}
- res = f_open(out_file, path, mode);
+ disk = disk_from_path(path);
+ number = drivenumber_from_disk(disk);
+ filepath = filepath_from_path(path);
+ sprintf(drivepath, "%d:%s", number, filepath);
+ free(filepath);
+
+ res = f_open(out_file, drivepath, mode);
if (res != FR_OK) {
- free(out_file);
- return fatfs_to_vfs_error(res);
+ rc = fatfs_to_vfs_error(res);
+ goto out;
}
- *out_fs_file = (struct fs_file *)out_file;
- return FS_EOK;
+
+ file->file = out_file;
+ file->fops = &fatfs_ops;
+ *out_fs_file = (struct fs_file *) file;
+ rc = FS_EOK;
+
+out:
+ if (rc != FS_EOK) {
+ if (file) free(file);
+ if (out_file) free(out_file);
+ }
+ return rc;
}
static int
fatfs_close(struct fs_file *fs_file)
{
FRESULT res;
- FIL *file = (FIL *)fs_file;
+ FIL *file = ((struct fatfs_file *) fs_file)->file;
if (file == NULL) {
return FS_EOK;
@@ -186,7 +305,7 @@ static int
fatfs_seek(struct fs_file *fs_file, uint32_t offset)
{
FRESULT res;
- FIL *file = (FIL *)fs_file;
+ FIL *file = ((struct fatfs_file *) fs_file)->file;
res = f_lseek(file, offset);
return fatfs_to_vfs_error(res);
@@ -196,7 +315,7 @@ static uint32_t
fatfs_getpos(const struct fs_file *fs_file)
{
uint32_t offset;
- FIL *file = (FIL *)fs_file;
+ FIL *file = ((struct fatfs_file *) fs_file)->file;
offset = (uint32_t) f_tell(file);
return offset;
@@ -206,7 +325,7 @@ static int
fatfs_file_len(const struct fs_file *fs_file, uint32_t *out_len)
{
uint32_t offset;
- FIL *file = (FIL *)fs_file;
+ FIL *file = ((struct fatfs_file *) fs_file)->file;
offset = (uint32_t) f_size(file);
return offset;
@@ -217,7 +336,7 @@ fatfs_read(struct fs_file *fs_file, uint32_t len, void *out_data,
uint32_t *out_len)
{
FRESULT res;
- FIL *file = (FIL *)fs_file;
+ FIL *file = ((struct fatfs_file *) fs_file)->file;
res = f_read(file, out_data, len, (UINT *)out_len);
return fatfs_to_vfs_error(res);
@@ -228,7 +347,7 @@ fatfs_write(struct fs_file *fs_file, const void *data, int len)
{
FRESULT res;
UINT out_len;
- FIL *file = (FIL *)fs_file;
+ FIL *file = ((struct fatfs_file *) fs_file)->file;
res = f_write(file, data, len, &out_len);
if (len != out_len) {
@@ -242,6 +361,7 @@ fatfs_unlink(const char *path)
{
FRESULT res;
+ //FIXME: handle disk
res = f_unlink(path);
return fatfs_to_vfs_error(res);
}
@@ -251,6 +371,7 @@ fatfs_rename(const char *from, const char *to)
{
FRESULT res;
+ //FIXME: handle disk
res = f_rename(from, to);
return fatfs_to_vfs_error(res);
}
@@ -268,18 +389,48 @@ static int
fatfs_opendir(const char *path, struct fs_dir **out_fs_dir)
{
FRESULT res;
- FATFS_DIR *out_dir;
+ FATFS_DIR *out_dir = NULL;
+ struct fatfs_dir *dir = NULL;
+ char *disk;
+ int number;
+ char *filepath;
+ char drivepath[255 + DRIVE_LEN]; /* FIXME */
+ int rc;
+
+ dir = malloc(sizeof(struct fatfs_dir));
+ if (!dir) {
+ rc = FS_ENOMEM;
+ goto out;
+ }
out_dir = malloc(sizeof(FATFS_DIR));
if (!out_dir) {
- return FS_ENOMEM;
+ rc = FS_ENOMEM;
+ goto out;
}
- res = f_opendir(out_dir, path);
+ disk = disk_from_path(path);
+ number = drivenumber_from_disk(disk);
+ filepath = filepath_from_path(path);
+ sprintf(drivepath, "%d:%s", number, filepath);
+ free(filepath);
+
+ res = f_opendir(out_dir, drivepath);
if (res != FR_OK) {
- return fatfs_to_vfs_error(res);
+ rc = fatfs_to_vfs_error(res);
+ goto out;
+ }
+
+ dir->dir = out_dir;
+ dir->fops = &fatfs_ops;
+ *out_fs_dir = (struct fs_dir *)dir;
+ rc = FS_EOK;
+
+out:
+ if (rc != FS_EOK) {
+ if (dir) free(dir);
+ if (out_dir) free(out_dir);
}
- *out_fs_dir = (struct fs_dir *)out_dir;
return FS_EOK;
}
@@ -287,15 +438,16 @@ static int
fatfs_readdir(struct fs_dir *fs_dir, struct fs_dirent **out_fs_dirent)
{
FRESULT res;
- FATFS_DIR *dir = (FATFS_DIR *)fs_dir;
+ FATFS_DIR *dir = ((struct fatfs_dir *) fs_dir)->dir;
- res = f_readdir(dir, &filinfo);
+ dirent.fops = &fatfs_ops;
+ res = f_readdir(dir, &dirent.filinfo);
if (res != FR_OK) {
return fatfs_to_vfs_error(res);
}
- *out_fs_dirent = (struct fs_dirent *)&filinfo;
- if (!filinfo.fname[0]) {
+ *out_fs_dirent = (struct fs_dirent *) &dirent;
+ if (!dirent.filinfo.fname[0]) {
return FS_ENOENT;
}
return FS_EOK;
@@ -305,7 +457,7 @@ static int
fatfs_closedir(struct fs_dir *fs_dir)
{
FRESULT res;
- FATFS_DIR *dir = (FATFS_DIR *)fs_dir;
+ FATFS_DIR *dir = ((struct fatfs_dir *) fs_dir)->dir;
res = f_closedir(dir);
free(dir);
@@ -316,12 +468,14 @@ static int
fatfs_dirent_name(const struct fs_dirent *fs_dirent, size_t max_len,
char *out_name, uint8_t *out_name_len)
{
- const FILINFO *dirent = (const FILINFO *)fs_dirent;
+
+ FILINFO *filinfo;
size_t out_len;
- assert(dirent != NULL);
- out_len = max_len < sizeof(dirent->fname) ? max_len : sizeof(dirent->fname);
- memcpy(out_name, dirent->fname, out_len);
+ assert(fs_dirent != NULL);
+ filinfo = &(((struct fatfs_dirent *)fs_dirent)->filinfo);
+ out_len = max_len < sizeof(filinfo->fname) ? max_len : sizeof(filinfo->fname);
+ memcpy(out_name, filinfo->fname, out_len);
*out_name_len = out_len;
return FS_EOK;
}
@@ -329,10 +483,10 @@ fatfs_dirent_name(const struct fs_dirent *fs_dirent, size_t max_len,
static int
fatfs_dirent_is_dir(const struct fs_dirent *fs_dirent)
{
- const FILINFO *dirent = (const FILINFO *)fs_dirent;
-
- assert(dirent != NULL);
- return dirent->fattrib & AM_DIR;
+ FILINFO *filinfo;
+ assert(fs_dirent != NULL);
+ filinfo = &(((struct fatfs_dirent *)fs_dirent)->filinfo);
+ return filinfo->fattrib & AM_DIR;
}
DSTATUS
@@ -349,6 +503,7 @@ disk_status(BYTE pdrv)
return RES_OK;
}
+/* FIXME */
static struct disk_ops *disk_ops_from_handle(BYTE pdrv)
{
return &mmc_ops;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca1b4915/fs/fs/include/fs/fs.h
----------------------------------------------------------------------
diff --git a/fs/fs/include/fs/fs.h b/fs/fs/include/fs/fs.h
index b44f624..f823b32 100644
--- a/fs/fs/include/fs/fs.h
+++ b/fs/fs/include/fs/fs.h
@@ -53,6 +53,9 @@ int fs_dirent_name(const struct fs_dirent *, size_t max_len,
char *out_name, uint8_t *out_name_len);
int fs_dirent_is_dir(const struct fs_dirent *);
+/* Helper functions */
+char *disk_from_path(const char *path);
+
/*
* File access flags.
*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca1b4915/fs/fs/src/fs_dirent.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_dirent.c b/fs/fs/src/fs_dirent.c
index b5fd6c5..ec26745 100644
--- a/fs/fs/src/fs_dirent.c
+++ b/fs/fs/src/fs_dirent.c
@@ -20,24 +20,40 @@
#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)
+{
+ /* NOTE: fs_ops must always be the first field for any fs_file */
+ return (struct fs_ops *) *((uint32_t *)dir);
+}
+
+static struct fs_ops *
+fops_from_dirent(const struct fs_dirent *dirent)
+{
+ /* NOTE: fs_ops must always be the first field for any fs_file */
+ return (struct fs_ops *) *((uint32_t *)dirent);
+}
+
int
fs_opendir(const char *path, struct fs_dir **out_dir)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ 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)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ struct fs_ops *fops = fops_from_dir(dir);
return fops->f_readdir(dir, out_dirent);
}
int
fs_closedir(struct fs_dir *dir)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ struct fs_ops *fops = fops_from_dir(dir);
return fops->f_closedir(dir);
}
@@ -45,13 +61,13 @@ int
fs_dirent_name(const struct fs_dirent *dirent, size_t max_len,
char *out_name, uint8_t *out_name_len)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ 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)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ struct fs_ops *fops = fops_from_dirent(dirent);
return fops->f_dirent_is_dir(dirent);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca1b4915/fs/fs/src/fs_file.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_file.c b/fs/fs/src/fs_file.c
index a18d0ba..35c7fe7 100644
--- a/fs/fs/src/fs_file.c
+++ b/fs/fs/src/fs_file.c
@@ -19,6 +19,11 @@
#include <fs/fs.h>
#include <fs/fs_if.h>
+#include <disk/disk.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
#include "fs_priv.h"
static int
@@ -137,7 +142,7 @@ safe_fs_ops_for(const char *fs_name)
{
struct fs_ops *fops;
- fops = fs_ops_for("fatfs");
+ fops = fs_ops_for(fs_name);
if (fops == NULL) {
fops = ¬_initialized_ops;
}
@@ -145,58 +150,104 @@ safe_fs_ops_for(const char *fs_name)
return fops;
}
+char *disk_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;
+}
+
+struct fs_ops *
+fops_from_filename(const char *filename)
+{
+ char *disk;
+ char *fs_name = NULL;
+
+ disk = disk_from_path(filename);
+ if (disk) {
+ fs_name = disk_fs_for(disk);
+ }
+ return safe_fs_ops_for(fs_name);
+}
+
+static struct fs_ops *
+fops_from_file(const struct fs_file *file)
+{
+ /* NOTE: fs_ops must always be the first field for any fs_file */
+ return (struct fs_ops *) *((uint32_t *)file);
+}
+
int
fs_open(const char *filename, uint8_t access_flags, struct fs_file **out_file)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ struct fs_ops *fops = fops_from_filename(filename);
return fops->f_open(filename, access_flags, out_file);
}
int
fs_close(struct fs_file *file)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ 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)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ 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)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ 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)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ struct fs_ops *fops = fops_from_file(file);
return fops->f_seek(file, offset);
}
uint32_t
fs_getpos(const struct fs_file *file)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ 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)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ struct fs_ops *fops = fops_from_file(file);
return fops->f_filelen(file, out_len);
}
int
fs_unlink(const char *filename)
{
- struct fs_ops *fops = safe_fs_ops_for("fatfs");
+ struct fs_ops *fops = fops_from_filename(filename);
return fops->f_unlink(filename);
}