Skip to content

Commit

Permalink
Try to probe fs_type on mount
Browse files Browse the repository at this point in the history
CL: vfs-common: Try to probe fs_type on mount
  • Loading branch information
rojer committed Dec 9, 2019
1 parent 1d044ac commit 52a96fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ AllowShortFunctionsOnASingleLine: false
SpaceAfterCStyleCast: true
PointerBindsToType: false
DerivePointerBinding: false
IncludeBlocks: Preserve
1 change: 1 addition & 0 deletions include/mgos_vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ bool mgos_vfs_mkfs_dev_name(const char *dev_name, const char *fs_type,
* Nested mounts are not currently supported, so "/mnt/foo" is not ok.
* Device and filesystem types must've been previosly registered and options
* have device and filesystem-specific format and usually are JSON objects.
* If device type is NULL, device will be probed for known FS types.
*/
bool mgos_vfs_mount(const char *path, const char *dev_type,
const char *dev_opts, const char *fs_type,
Expand Down
33 changes: 30 additions & 3 deletions src/mgos_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "common/cs_dbg.h"
#include "common/queue.h"
#include "common/str_util.h"

#include "mgos_debug.h"
#include "mgos_hal.h"
Expand All @@ -34,6 +35,13 @@
#include <sys/mman.h>
#endif /* CS_MMAP */

#ifdef MGOS_HAVE_VFS_FS_LFS
#include "mgos_vfs_fs_lfs.h"
#endif
#ifdef MGOS_HAVE_VFS_FS_SPIFFS
#include "mgos_vfs_fs_spiffs.h"
#endif

#define MAKE_VFD(mount_id, fs_fd) (((mount_id) << 8) | ((fs_fd) &0xff))

struct mgos_vfs_fs_type_entry {
Expand Down Expand Up @@ -82,6 +90,7 @@ static inline void mgos_vfs_unlock(void) {
}

static const struct mgos_vfs_fs_type_entry *find_fs_type(const char *fs_type) {
if (fs_type == NULL) return NULL;
struct mgos_vfs_fs_type_entry *fte = NULL;
mgos_vfs_lock();
SLIST_FOREACH(fte, &s_fs_types, next) {
Expand Down Expand Up @@ -132,11 +141,29 @@ bool mgos_vfs_mkfs(const char *dev_type, const char *dev_opts,

bool mgos_vfs_mount_dev(const char *path, struct mgos_vfs_dev *dev,
const char *fs_type, const char *fs_opts) {
const struct mgos_vfs_fs_type_entry *fte = find_fs_type(fs_type);
if (fte == NULL) return false;
if (path == NULL || path[0] != DIRSEP || fs_type == NULL) {
if (path == NULL || path[0] != DIRSEP) {
return false;
}
if (fs_type == NULL) {
#ifdef MGOS_HAVE_VFS_FS_LFS
if (mgos_vfs_fs_lfs_probe(dev)) {
fs_type = MGOS_VFS_FS_TYPE_LFS;
if (fs_opts == NULL) fs_opts = CS_STRINGIFY_MACRO(MGOS_ROOT_FS_OPTS_LFS);
} else
#endif
#ifdef MGOS_HAVE_VFS_FS_SPIFFS
if (mgos_vfs_fs_spiffs_probe(dev)) {
fs_type = MGOS_VFS_FS_TYPE_SPIFFS;
if (fs_opts == NULL) fs_opts = CS_STRINGIFY_MACRO(MGOS_ROOT_FS_OPTS_SPIFFS);
} else
#endif
{
LOG(LL_ERROR, ("FS type for %s could not be detected", dev->name));
return false;
}
}
const struct mgos_vfs_fs_type_entry *fte = find_fs_type(fs_type);
if (fte == NULL) return false;
if (fs_opts == NULL) fs_opts = "";
struct mgos_vfs_fs *fs = (struct mgos_vfs_fs *) calloc(1, sizeof(*fs));
if (fs == NULL) return false;
Expand Down

0 comments on commit 52a96fe

Please sign in to comment.