1.1 --- a/libfsserver/include/fsserver/host_file_opener.h Tue Jul 13 00:26:11 2021 +0200
1.2 +++ b/libfsserver/include/fsserver/host_file_opener.h Tue Jul 13 23:18:37 2021 +0200
1.3 @@ -22,16 +22,29 @@
1.4 #pragma once
1.5
1.6 #include <map>
1.7 +#include <mutex>
1.8 +#include <string>
1.9
1.10 #include <fsserver/opener_resource.h>
1.11
1.12
1.13
1.14 +/* Collection data types. */
1.15 +
1.16 +typedef std::map<std::string, fileid_t> HostFileIdentifiers;
1.17 +
1.18 +
1.19 +
1.20 /* Support for providing access to files. */
1.21
1.22 class HostFileOpener : public OpenerResource
1.23 {
1.24 protected:
1.25 + std::mutex _lock;
1.26 +
1.27 + /* File identifier register. */
1.28 +
1.29 + HostFileIdentifiers _fileids;
1.30
1.31 /* Configurable methods. */
1.32
2.1 --- a/libfsserver/lib/files/host_file_opener.cc Tue Jul 13 00:26:11 2021 +0200
2.2 +++ b/libfsserver/lib/files/host_file_opener.cc Tue Jul 13 23:18:37 2021 +0200
2.3 @@ -19,8 +19,6 @@
2.4 * Boston, MA 02110-1301, USA
2.5 */
2.6
2.7 -#include <sys/stat.h>
2.8 -
2.9 #include "host_file_accessor.h"
2.10 #include "host_file_opener.h"
2.11
2.12 @@ -28,14 +26,25 @@
2.13
2.14 fileid_t HostFileOpener::get_fileid(const char *path)
2.15 {
2.16 - struct stat statbuf;
2.17 + std::lock_guard<std::mutex> guard(_lock);
2.18 +
2.19 + /* The inode number would be a good choice, but the L4Re read-only file
2.20 + implementation just provides the value of a counter!
2.21 +
2.22 + See: pkg/l4re-core/l4re_vfs/include/impl/ro_file_impl.h */
2.23 +
2.24 + std::string s(path);
2.25
2.26 - /* Obtain the inode number.
2.27 - NOTE: This does not handle errors! */
2.28 + HostFileIdentifiers::iterator it = _fileids.find(s);
2.29 +
2.30 + if (it != _fileids.end())
2.31 + return it->second;
2.32
2.33 - stat(path, &statbuf);
2.34 + fileid_t fileid = _fileids.size();
2.35
2.36 - return statbuf.st_ino;
2.37 + _fileids[s] = fileid;
2.38 +
2.39 + return fileid;
2.40 }
2.41
2.42 /* Return a new accessor for 'fileid'. */