1.1 --- a/libfsserver/lib/files/host_file_opener.cc Fri Jul 16 00:40:22 2021 +0200
1.2 +++ b/libfsserver/lib/files/host_file_opener.cc Sun Jul 18 00:47:14 2021 +0200
1.3 @@ -24,7 +24,23 @@
1.4
1.5 /* Return a file identifier for the given 'path'. */
1.6
1.7 -fileid_t HostFileOpener::get_fileid(const char *path)
1.8 +fileid_t HostFileOpener::get_fileid(const char *path, flags_t flags)
1.9 +{
1.10 + (void) flags;
1.11 +
1.12 + /* Test for a valid file or an attempt to create a file. */
1.13 +
1.14 + FILE *fp = fopen(path, "r");
1.15 +
1.16 + if (fp == NULL)
1.17 + return FILEID_INVALID;
1.18 +
1.19 + fclose(fp);
1.20 +
1.21 + return _get_fileid(path, true);
1.22 +}
1.23 +
1.24 +fileid_t HostFileOpener::_get_fileid(const char *path, bool create)
1.25 {
1.26 std::lock_guard<std::mutex> guard(_lock);
1.27
1.28 @@ -40,6 +56,9 @@
1.29 if (it != _fileids.end())
1.30 return it->second;
1.31
1.32 + if (!create)
1.33 + return FILEID_INVALID;
1.34 +
1.35 fileid_t fileid = _fileids.size();
1.36
1.37 _fileids[s] = fileid;
1.38 @@ -49,14 +68,19 @@
1.39
1.40 /* Return a new accessor for 'fileid'. */
1.41
1.42 -Accessor *HostFileOpener::make_accessor(const char *path, fileid_t fileid)
1.43 +long HostFileOpener::make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor)
1.44 {
1.45 + // NOTE: Not testing for create or write flags.
1.46 +
1.47 + (void) flags;
1.48 +
1.49 FILE *fp = fopen(path, "r");
1.50
1.51 if (fp == NULL)
1.52 - return NULL;
1.53 + return -L4_ENOENT;
1.54
1.55 - return new HostFileAccessor(fp, fileid);
1.56 + *accessor = new HostFileAccessor(fp, fileid);
1.57 + return L4_EOK;
1.58 }
1.59
1.60 // vim: tabstop=4 expandtab shiftwidth=4