1.1 --- a/libfsserver/lib/files/opener_resource.cc Fri Oct 01 01:16:14 2021 +0200
1.2 +++ b/libfsserver/lib/files/opener_resource.cc Sat Oct 02 23:57:02 2021 +0200
1.3 @@ -19,6 +19,8 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 +#include <string.h>
1.8 +
1.9 #include "opener_server.h"
1.10 #include "opener_resource.h"
1.11 #include "resource_server.h"
1.12 @@ -46,6 +48,51 @@
1.13
1.14
1.15
1.16 +/* Obtain any active parent directory for a path, notifying its subscribers of
1.17 + the file opening event. */
1.18 +
1.19 +long OpenerResource::notify_parent(const char *path)
1.20 +{
1.21 + char *sep = strrchr(path, (int) '/');
1.22 + DirectoryProvider *provider;
1.23 + fileid_t fileid;
1.24 + long err;
1.25 +
1.26 + /* For top-level paths, use the empty string to get the root directory.
1.27 + Otherwise, obtain the parent directory path to obtain the file
1.28 + identifier. */
1.29 +
1.30 + if (sep == NULL)
1.31 + err = get_fileid("", 0, &fileid);
1.32 + else
1.33 + {
1.34 + char *parent = strndup(path, sep - path + 1);
1.35 +
1.36 + parent[sep - path] = '\0';
1.37 + err = get_fileid(parent, 0, &fileid);
1.38 + free(parent);
1.39 + }
1.40 +
1.41 + if (err)
1.42 + return err;
1.43 +
1.44 + /* Obtain the provider of the parent directory. */
1.45 +
1.46 + err = _registry->find_directory_provider(fileid, &provider);
1.47 +
1.48 + if (err)
1.49 + return err;
1.50 +
1.51 + /* With any active provider, send a notification.
1.52 + NOTE: This should also communicate which file was involved, probably
1.53 + NOTE: using the file identifier of the opened file. */
1.54 +
1.55 + provider->notify_all(NOTIFY_FILE_OPENED);
1.56 + return L4_EOK;
1.57 +}
1.58 +
1.59 +
1.60 +
1.61 /* Return an object for the given path and flags. */
1.62
1.63 long OpenerResource::open(const char *path, flags_t flags, offset_t *size,
1.64 @@ -59,6 +106,10 @@
1.65 if (err)
1.66 return err;
1.67
1.68 + /* Notify listeners subscribed to the parent of the opened object. */
1.69 +
1.70 + notify_parent(path);
1.71 +
1.72 /* Test for file and directory access. */
1.73
1.74 if (accessing_directory(path, flags, fileid))