# HG changeset patch # User Paul Boddie # Date 1634079033 -7200 # Node ID 5bb0970d9eb6ef3a1916eb42ec3d9998d9f6bd07 # Parent 8ed52ed7ac888fce1abe53881cd4005b5db87b5b Introduced a helper method to get parent filesystem objects. diff -r 8ed52ed7ac88 -r 5bb0970d9eb6 libfsserver/include/fsserver/opener_resource.h --- a/libfsserver/include/fsserver/opener_resource.h Mon Oct 11 23:56:21 2021 +0200 +++ b/libfsserver/include/fsserver/opener_resource.h Wed Oct 13 00:50:33 2021 +0200 @@ -52,6 +52,10 @@ offset_t *size, l4_cap_idx_t *cap, object_flags_t *object_flags); + /* Retrieval methods. */ + + virtual long get_parent(const char *path, fileid_t *fileid); + /* Notification methods. */ virtual long notify_parent(const char *path); diff -r 8ed52ed7ac88 -r 5bb0970d9eb6 libfsserver/lib/files/opener_resource.cc --- a/libfsserver/lib/files/opener_resource.cc Mon Oct 11 23:56:21 2021 +0200 +++ b/libfsserver/lib/files/opener_resource.cc Wed Oct 13 00:50:33 2021 +0200 @@ -48,14 +48,11 @@ -/* Obtain any active parent directory for a path, notifying its subscribers of - the file opening event. */ +/* Obtain the identifier for any active parent directory for a path. */ -long OpenerResource::notify_parent(const char *path) +long OpenerResource::get_parent(const char *path, fileid_t *fileid) { char *sep = strrchr(path, (int) '/'); - DirectoryProvider *provider; - fileid_t fileid; long err; /* For top-level paths, use the empty string to get the root directory. @@ -63,16 +60,30 @@ identifier. */ if (sep == NULL) - err = get_fileid("", 0, &fileid); + err = get_fileid("", 0, fileid); else { char *parent = strndup(path, sep - path + 1); parent[sep - path] = '\0'; - err = get_fileid(parent, 0, &fileid); + err = get_fileid(parent, 0, fileid); free(parent); } + return err; +} + +/* Obtain any active parent directory for a path, notifying its subscribers of + the file opening event. */ + +long OpenerResource::notify_parent(const char *path) +{ + DirectoryProvider *provider; + fileid_t fileid; + long err; + + err = get_parent(path, &fileid); + if (err) return err; @@ -98,7 +109,8 @@ long OpenerResource::open(const char *path, flags_t flags, offset_t *size, l4_cap_idx_t *cap, object_flags_t *object_flags) { - /* Obtain an identifier for the file, even for new files. */ + /* Obtain an identifier for the file, even for new files (subject to use of + the appropriate flag). */ fileid_t fileid; long err = get_fileid(path, flags, &fileid);