1.1 --- a/libfsserver/lib/files/host_file_opener.cc Wed Feb 09 22:30:29 2022 +0100
1.2 +++ b/libfsserver/lib/files/host_file_opener.cc Thu Feb 10 17:55:05 2022 +0100
1.3 @@ -36,9 +36,15 @@
1.4 {
1.5 }
1.6
1.7 -bool HostFileOpener::accessing_directory(const char *path, flags_t flags, fileid_t fileid)
1.8 +bool HostFileOpener::accessing_directory(flags_t flags, fileid_t fileid)
1.9 {
1.10 - (void) flags; (void) fileid;
1.11 + (void) flags;
1.12 +
1.13 + const char *path = _get_path(fileid);
1.14 +
1.15 + if (path == NULL)
1.16 + return false;
1.17 +
1.18 struct stat st;
1.19
1.20 if (stat(path, &st))
1.21 @@ -47,11 +53,16 @@
1.22 return (st.st_mode & S_IFDIR) ? true : false;
1.23 }
1.24
1.25 -bool HostFileOpener::accessing_file(const char *path, flags_t flags, fileid_t fileid)
1.26 +bool HostFileOpener::accessing_file(flags_t flags, fileid_t fileid)
1.27 {
1.28 - (void) flags; (void) fileid;
1.29 + (void) flags;
1.30 struct stat st;
1.31
1.32 + const char *path = _get_path(fileid);
1.33 +
1.34 + if (path == NULL)
1.35 + return false;
1.36 +
1.37 if (stat(path, &st))
1.38 return false;
1.39
1.40 @@ -99,19 +110,37 @@
1.41 fileid_t fileid = _fileids.size();
1.42
1.43 _fileids[s] = fileid;
1.44 + _paths[fileid] = s;
1.45
1.46 return fileid;
1.47 }
1.48
1.49 +const char *HostFileOpener::_get_path(fileid_t fileid)
1.50 +{
1.51 + std::lock_guard<std::mutex> guard(_lock);
1.52 +
1.53 + HostFilePaths::iterator it = _paths.find(fileid);
1.54 +
1.55 + if (it != _paths.end())
1.56 + return it->second.c_str();
1.57 + else
1.58 + return NULL;
1.59 +}
1.60 +
1.61 /* Return a new accessor for 'fileid'. */
1.62
1.63 -long HostFileOpener::make_accessor(const char *path, flags_t flags,
1.64 - fileid_t fileid, Accessor **accessor)
1.65 +long HostFileOpener::make_accessor(flags_t flags, fileid_t fileid,
1.66 + Accessor **accessor)
1.67 {
1.68 // NOTE: Not testing for create or write flags.
1.69
1.70 (void) flags;
1.71
1.72 + const char *path = _get_path(fileid);
1.73 +
1.74 + if (path == NULL)
1.75 + return -L4_ENOENT;
1.76 +
1.77 FILE *fp = fopen(path, "r");
1.78
1.79 if (fp == NULL)
1.80 @@ -123,11 +152,15 @@
1.81
1.82 /* Return a directory accessor for 'fileid'. */
1.83
1.84 -long HostFileOpener::make_directory_accessor(const char *path, flags_t flags,
1.85 - fileid_t fileid,
1.86 +long HostFileOpener::make_directory_accessor(flags_t flags, fileid_t fileid,
1.87 DirectoryAccessor **accessor)
1.88 {
1.89 - (void) flags; (void) fileid;
1.90 + (void) flags;
1.91 +
1.92 + const char *path = _get_path(fileid);
1.93 +
1.94 + if (path == NULL)
1.95 + return -L4_ENOENT;
1.96
1.97 *accessor = new HostDirectoryAccessor(path);
1.98 return L4_EOK;
1.99 @@ -135,19 +168,16 @@
1.100
1.101 /* Remove a filesystem object. */
1.102
1.103 -long HostFileOpener::remove_object(const char *path, fileid_t fileid)
1.104 +long HostFileOpener::remove_object(fileid_t fileid)
1.105 {
1.106 - (void) path; (void) fileid;
1.107 + (void) fileid;
1.108 return L4_EOK;
1.109 }
1.110
1.111 /* Rename a filesystem object, placing source inside the parent of target. */
1.112
1.113 -long HostFileOpener::rename_object(const char *source, fileid_t source_fileid,
1.114 - const char *target)
1.115 +long HostFileOpener::rename_object(const char *source, const char *target)
1.116 {
1.117 - (void) source_fileid;
1.118 -
1.119 /* NOTE: Should propagate a more meaningful error. */
1.120
1.121 if (rename(source, target))
1.122 @@ -158,11 +188,16 @@
1.123
1.124 /* Unlink a filesystem object. */
1.125
1.126 -long HostFileOpener::unlink_object(const char *path, fileid_t fileid)
1.127 +long HostFileOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid)
1.128 {
1.129 - /* Ignore the fileid and always use the path. */
1.130 + /* Ignore the parent and always use the path. */
1.131 +
1.132 + (void) parent_fileid;
1.133
1.134 - (void) fileid;
1.135 + const char *path = _get_path(fileid);
1.136 +
1.137 + if (path == NULL)
1.138 + return -L4_ENOENT;
1.139
1.140 // NOTE: Return code may need converting.
1.141
1.142 @@ -180,6 +215,11 @@
1.143 if (it != _fileids.end())
1.144 _fileids.erase(it);
1.145
1.146 + HostFilePaths::iterator pit = _paths.find(fileid);
1.147 +
1.148 + if (pit != _paths.end())
1.149 + _paths.erase(pit);
1.150 +
1.151 return L4_EOK;
1.152 }
1.153