Skip to content

fs: Filesystem module (WIP)#1265

Closed
miri64 wants to merge 4 commits intoRIOT-OS:masterfrom
miri64:filesystem
Closed

fs: Filesystem module (WIP)#1265
miri64 wants to merge 4 commits intoRIOT-OS:masterfrom
miri64:filesystem

Conversation

@miri64
Copy link
Member

@miri64 miri64 commented Jun 3, 2014

This PR creates a common interface for all filesystems to use.

STILL WIP

@miri64 miri64 added WIP labels Jun 3, 2014
@miri64 miri64 added this to the POSIX compliance milestone Jun 3, 2014
@Kijewski
Copy link
Contributor

Kijewski commented Jun 3, 2014

Strong "no" to the use of errno.

sys/fs/fs.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Superfluous. The variable is auto initialized with zeroes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

@OlegHahm
Copy link
Member

OlegHahm commented Jun 3, 2014

What's wrong with errno?

sys/include/fs.h Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

I see no advantage in having this as a static inline instead of a regular function.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought that all of them will be just wrappers of two function calls, this might save memory.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I don't think that this will safe memory, on the contrary. The static inline function is quite big, as it employs to function calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but it goes into the ROM, rather than the RAM, and on most devices ROM >> RAM.

Copy link
Member Author

Choose a reason for hiding this comment

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

(On the contrary: a non-inline function would build up RAM space through its parameters)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the static inline function will neither safe RAM nor ROM. :)

@kaspar030
Copy link
Contributor

errno is not thread safe / reentrant.

@OlegHahm
Copy link
Member

OlegHahm commented Jun 3, 2014

Does it have to here?

@Kijewski
Copy link
Contributor

Kijewski commented Jun 3, 2014

There is virtually no advantage in setting errno since it is not reentrant. All reads to the variable are spurious.
The functions should just use a wide enough int type (e.g. ssize_t) to return negated error codes.

sys/include/fs.h Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did you find this list? Fuse?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes ;-)

@Kijewski
Copy link
Contributor

Kijewski commented Jun 3, 2014

At many lines the semicola are missing.

@Kijewski
Copy link
Contributor

Kijewski commented Jun 3, 2014

I like the idea, and think that we will need FS support (and SD card support for MSB-A2) and a proper VFS.
But I think we should not target to implement all these functions. We don't want to become a less well-tested Linux.

@OlegHahm
Copy link
Member

OlegHahm commented Jun 3, 2014

There is SD card support for the MSB-A2.

@miri64
Copy link
Member Author

miri64 commented Jun 20, 2014

@Kijewski regarding errno: better this way?

@miri64
Copy link
Member Author

miri64 commented Jun 20, 2014

Squashed and rebased to master

@Kijewski
Copy link
Contributor

@authmillenon, yes, I like using the return code. 👍

sys/fs/fs.c Outdated

Choose a reason for hiding this comment

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

It's not necessary to use strncmp. strcmp (without n) will do the work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Confirmed.
Also, please use strcmp with != 0, because it's not quite a boolean value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well the idea is to only compare up to the length of the mount point's path. As far as I understand it strcmp() would yield < 0 if I compare for example fs_table[i].mount_point == "/mnt" with path == "/mnt/where/ever/files/go". But about != 0 you are right

Copy link
Member Author

Choose a reason for hiding this comment

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

(But it should be == 0 to be equivalent to !strncmp ;-))

Choose a reason for hiding this comment

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

I miss understood the function. In that case of course strncmp() :-).

sys/fs/fs.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now you are looking for the last match. This could be easified by reverse iterating the list and exiting eagerly.
But don't you have to find the longest prefix?
And maybe the mount point could memoize it's strlen?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I search for the longest prefix. You are right, I have to save the length, too :/

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe an all-on-one solution?

size_t is_prefix_len(const char *restrict prefix, const char *restrict str)
{
    size_t len = 0;
    while (1) {
        if (!*prefix) {
            return len;
        }
        else if (*prefix != *str) {
            return 0;
        }
        else {
            ++prefix;
            ++str;
            ++len;
        }
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

see 3cce976 ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

I like 👍

@LudwigKnuepfer LudwigKnuepfer changed the title fs: Filesystem module fs: Filesystem module (WIP) Jul 15, 2014
@miri64
Copy link
Member Author

miri64 commented Jan 26, 2015

@kaspar030 FatFS is a full library for FAT for embedded systems. We don't need to do anything, exept providing an interface ;-)

@miri64
Copy link
Member Author

miri64 commented Jan 26, 2015

@gebart I guess pkg is the always the best option for external libs, since maintenance in case of updates is easier this way (the avoidance of license hassle is just an extra ;-)).

OT: embunit is currently the only non-package module which was included from an external source. Mainly because it IS license-compatible, since it is pretty integral to our testing infrastructure, since we applied a lot of changes by now and to avoid redownloads on Travis.

@jnohlgard
Copy link
Member

@authmillenon FatFS as a pkg sounds like a good solution.

btw, do any of the RIOT boards have an implementation for SDHC so far?

@miri64
Copy link
Member Author

miri64 commented Jan 27, 2015

The msba2 has at least a microSD slot, but I don't now if it is SDHC or just SD and if a driver implementation for this exists. Maybe @OlegHahm can shed some light on this.

@miri64
Copy link
Member Author

miri64 commented Jan 27, 2015

@gebart if you like you can adopt this PR, btw. I don't know if I come to continue this in the near future. The interface is inspired mainly by fuse's btw (exept that I did not use filenames but fds as identifiers apparently I did use filenames) ;-)

@jnohlgard
Copy link
Member

@authmillenon I meant SD host controller interface, sorry about the unclear acronym.

@jnohlgard
Copy link
Member

I do not have any time to work on this at the moment either, maybe I will adopt this later when things clear up, but for now this one may be up for grabs.

@miri64
Copy link
Member Author

miri64 commented Jan 27, 2015

👍

@waehlisch
Copy link
Member

@x3ro started also to think/work about a file system for RIOT. Maybe he can join the discussion.

@x3ro
Copy link
Contributor

x3ro commented Jan 27, 2015

Thanks for the ping @waehlisch :) My plan is to be working on bringing SDHC and filesystem support to RIOT over the next couple of months as part of my masters thesis. @authmillenon Would it be an option for me to adopt this PR?

The msba2 has at least a microSD slot, but I don't now if it is SDHC or just SD and if a driver implementation for this exists. @authmillenon

As far as I know there is no such driver. I played with the msba2 at the last Hack&Ack to see if I can talk to the SD card but have so far been unsuccessful.

@miri64
Copy link
Member Author

miri64 commented Jan 27, 2015

@authmillenon Would it be an option for me to adopt this PR?

@x3ro, of course. GitHub has no feature however to just let me give it to you. You have to check out my corresponding branch and open your own PR with it. Then we can close this one.

@OlegHahm
Copy link
Member

@gebart:

Contiki has CFS, but that is BSD licensed, so we can't use that code.

Why should this be a problem? AFAIK it shouldn't be a problem to include BSD/MIT/... code into a (L)GPL project - but of course not via versa.

@authmillenon:

OT: embunit is currently the only non-package module which was included from an external source.

ccn-lite is also a non-package stemming from an external source - and currently it seems to me that this was a bad idea (although it looked wise back when the decision was originally made). Hence, I would also vote for "packaging" wherever possible.

@gebart @authmillenon @x3ro:

As far as I know there is no such driver. I played with the msba2 at the last Hack&Ack to see if I can talk to the SD card but have so far been unsuccessful.

I used to work with micro SDHC cards on the MSB-A2 and RIOT (though it was still named µkleos back then) about three years ago, which worked more or less fine (see also #127). However, I haven't tested for a looong time.

@jnohlgard
Copy link
Member

@OlegHahm

Why should this be a problem? AFAIK it shouldn't be a problem to include BSD/MIT/... code into a (L)GPL project - but of course not via versa.

I am sorry, I did not think this through before I wrote it. You are right, AFAIK we are allowed to use BSD sources within an LGPL project such as this. I also found this document regarding different open source licenses and their interoperability:

http://wiki.osdev.org/Licensing

@authmillenon , @OlegHahm What would be a reasonable way to integrate Contiki's CFS into RIOT?
CFS does not have a separate repo, but is closely integrated into the Contiki repo.

Can we add it as a pkg with some script to fetch a git revision and strip everything except the CFS pieces?

@OlegHahm
Copy link
Member

I think that could be one way to do this, but probably not the most elegant way. Maybe we should reach out to the Contiki people and see if we can maintain CFS as an external library together on the long run.

@miri64
Copy link
Member Author

miri64 commented Jan 30, 2015

Some thought on file descriptors I had I'd like to share: Maybe any value of kernel_pid_t with > MAXTHREADS is the best solution, since in POSIX even pthreads have fds and this way we can just have them be the actual PID, while anything else is uniquely identified. This way we have a unique numbering scheme and have the POSIX wrapper for pthreads and file operations as easy as possible. Sockets would also grab from the same pool then (and we have the option to run every socket in it's own light-weight thread (if we'll have something like that) in the future, maybe).

@jnohlgard
Copy link
Member

@authmillenon watch out for the FDs of stdout, stdin, stderr though. They are defined as 0, 1, and 2 in most implementations.

@miri64
Copy link
Member Author

miri64 commented Jan 31, 2015

Damn you're right. It's even specified this way: http://pubs.opengroup.org/onlinepubs/9699919799/functions/stdin.html

@x3ro
Copy link
Contributor

x3ro commented Feb 19, 2015

Sorry for my idleness so far 🐌 If nobody objects I would open a new pull request from my fork, adding a summary of the discussion so far to that PR. This thread could then be closed and the discussion would continue in the new PR. Does that make sense?

@jnohlgard
Copy link
Member

@x3ro That makes sense.
Just add the text #1265 somewhere in the description of your PR and a back-reference will be added inside this thread to your new PR, to make it easier to follow.

@OlegHahm
Copy link
Member

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Can anyone explain what this does/should do? 😕

Copy link
Member

Choose a reason for hiding this comment

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

I think they meant to do return 0; or return 1; or something

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess this was meant to be this, too.

@x3ro x3ro mentioned this pull request Feb 19, 2015
6 tasks
@OlegHahm
Copy link
Member

Should we close this as a memo now?

@miri64 miri64 added the State: archived State: The PR has been archived for possible future re-adaptation label Feb 20, 2015
@miri64
Copy link
Member Author

miri64 commented Feb 20, 2015

Yes

@miri64 miri64 closed this Feb 20, 2015
@miri64 miri64 deleted the filesystem branch February 20, 2015 08:21
@jnohlgard jnohlgard mentioned this pull request Jul 8, 2016
55 tasks
@jnohlgard jnohlgard added the Area: fs Area: File systems label Feb 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: fs Area: File systems Area: POSIX Area: POSIX API wrapper State: archived State: The PR has been archived for possible future re-adaptation State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants