1.1 --- a/libfsserver/lib/generic/resource_registry.cc Tue Jan 04 23:27:53 2022 +0100
1.2 +++ b/libfsserver/lib/generic/resource_registry.cc Tue Jan 04 23:43:56 2022 +0100
1.3 @@ -169,4 +169,44 @@
1.4 return provider->make_resource(size, object_flags, resource);
1.5 }
1.6
1.7 +/* Request the removal of a filesystem object through any active provider. */
1.8 +
1.9 +long ResourceRegistry::remove_provider(FileOpening *opening, const char *path)
1.10 +{
1.11 + std::lock_guard<std::mutex> guard(_lock);
1.12 +
1.13 + /* Obtain an identifier for any recognised object. */
1.14 +
1.15 + fileid_t fileid;
1.16 + long err = opening->get_fileid(path, 0, &fileid);
1.17 +
1.18 + if (err)
1.19 + return err;
1.20 +
1.21 + /* Obtain a provider for the object. */
1.22 +
1.23 + Provider *provider;
1.24 + err = find_provider(fileid, &provider);
1.25 +
1.26 + if (err && (err != -L4_ENOENT))
1.27 + return err;
1.28 +
1.29 + /* Unlink the object regardless of whether it can be removed. */
1.30 +
1.31 + err = opening->unlink_object(path, fileid);
1.32 +
1.33 + if (err)
1.34 + return err;
1.35 +
1.36 + /* Without a provider being active, remove the object directly. */
1.37 +
1.38 + if (err)
1.39 + return opening->remove_object(path, fileid);
1.40 +
1.41 + /* With a provider active, request the object's removal upon closure. */
1.42 +
1.43 + provider->remove_pending(true);
1.44 + return L4_EOK;
1.45 +}
1.46 +
1.47 // vim: tabstop=4 expandtab shiftwidth=4