-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fs: Filesystem module (WIP) #2474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
acd5a49
e2d114f
9fa346d
ec5daae
0f20eab
7e730c4
fdf19e5
6911334
83195cf
da358a5
ef5a906
e88825c
3a9a2fd
bdd8d70
d8becf3
8bb57f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include $(RIOTBASE)/Makefile.base |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Copyright (C) 2014 Martin Lenders | ||
| * Copyright (C) 2015 Lucas Jenß <lucas@x3ro.de> | ||
| * | ||
| * This file is subject to the terms and conditions of the GNU Lesser | ||
| * General Public License v2.1. See the file LICENSE in the top level | ||
| * directory for more details. | ||
| */ | ||
| #include <errno.h> | ||
| #include <string.h> | ||
|
|
||
| #include "fs.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]); | ||
| 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; | ||
| } | ||
|
|
||
| int i = 0; | ||
| for (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 > FS_MOUNT_POINT_LEN) { | ||
| fs_table[i].mp_len = FS_MOUNT_POINT_LEN; | ||
| } | ||
|
|
||
| fs_table[i].device = device; | ||
| fs_table[i].type = type; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| 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; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not exactly familiar with the semantics of these return codes, but from what I've read it seems that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it seems to follow the Linux behaviour of ENOENT for a bad mount point and EINVAL for not a mount point. Linux umount(2) manpage:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah thanks, that makes a lot of sense. I tried to match what I found here with the behavior of the function 😕 I'll check the Linux behavior more thoroughly from now on :) |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&&->||