Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ endif

ifneq (,$(filter net_if,$(USEMODULE)))
USEMODULE += transceiver
endif

ifneq (,$(filter scfs,$(USEMODULE)))
USEMODULE += fs
USEMODULE += shell_commands
endif

ifneq (,$(filter shell_commands,$(USEMODULE)))
USEMODULE += net_help
endif

Expand Down
6 changes: 6 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ endif
ifneq (,$(filter config,$(USEMODULE)))
DIRS += config
endif
ifneq (,$(filter fs,$(USEMODULE)))
DIRS += fs
endif
ifneq (,$(filter lib,$(USEMODULE)))
DIRS += lib
endif
Expand All @@ -22,6 +25,9 @@ endif
ifneq (,$(filter pthread,$(USEMODULE)))
DIRS += posix/pthread
endif
ifneq (,$(filter scfs,$(USEMODULE)))
DIRS += fs/scfs
endif
ifneq (,$(filter shell,$(USEMODULE)))
DIRS += shell
endif
Expand Down
3 changes: 3 additions & 0 deletions sys/fs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = fs

include $(RIOTBASE)/Makefile.base
79 changes: 79 additions & 0 deletions sys/fs/fs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2014 Martin Lenders
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/
#include <errno.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sys/fs/* is part of #1265 please comment there.

#include <string.h>

#include "fs.h"
#include "scfs.h"

static fs_table_t fs_table[FS_TABLE_SIZE];

const fs_op_table_t fs_op_table[1];

static fs_table_t *fs_search_entry(const char *path)
{
fs_table_t *tmp = NULL;
size_t tmp_len = 0;

for (int i = 0; i < FS_TABLE_SIZE; i++) {
if (fs_table[i].mp_len >= tmp_len &&
strncmp(fs_table[i].mount_point, path, fs_table[i].mp_len) == 0) {
tmp = &(fs_table[i]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sys/fs/* is part of #1265 please comment there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And fyi: no the fs_table is not expected to be sorted in any way).

tmp_len = fs_table[i].mp_len;
}
}

return tmp;
}

int fs_mount(const char *mount_point, int device, fs_type_t type)
{
if (strlen(mount_point) + 1 > FS_MOUNT_POINT_LEN) {
errno = ENAMETOOLONG;
return -ENAMETOOLONG;
}

for (int i = 0; fs_table[i].type != FS_NONE && i < FS_TABLE_SIZE; i++);

if (i == FS_TABLE_SIZE) {
errno = ENOMEM;
return -ENOMEM;
}

strncpy(fs_table[i].mount_point, mount_point, FS_MOUNT_POINT_LEN);
fs_table[i].mp_len = strlen(mount_point);

if (fs_table[i].mp_len < 0 || fs_table[i].mp_len > FS_MOUNT_POINT_LEN) {
fs_table[i].mp_len = FS_MOUNT_POINT_LEN;
}

fs_table[i].device = device;
fs_table[i].type = type;

int 1;
}

int fs_unmount(const char *mount_point, int device)
{
if (!mount_point && !device) {
errno = ENOENT;
return -ENOENT;
}

for (int i = 0; i < FS_TABLE_SIZE; i++) {
if ((device && fs_table[i].device == device) ||
(mount_point && !strncmp(fs_table[i].mount_point, mount_point,
strlen(fs_table[i].mount_point)))) {
fs_table[i].type = FS_NONE;
return 0;
}
}

errno = EINVAL;
return -EINVAL;
}
3 changes: 3 additions & 0 deletions sys/fs/scfs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE =scfs

include $(RIOTBASE)/Makefile.base
34 changes: 34 additions & 0 deletions sys/fs/scfs/scfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2014 Martin Lenders
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/

#include <errno.h>

#include "fs.h"
#include "scfs.h"
#include "shell_commands.h"

static int busy = 0;

int scfs_mount(const char *mount_point)
{
if (busy) {
errno = EBUSY;
return -EBUSY;
}

return fs_mount(mount_point, 0, FS_SCFS);
}

int scfs_unmount(const char *mount_point)
{
if (!busy) {
return 0;
}

return fs_unmount(mount_point, 0);
}
Loading