1.1 --- a/libfsserver/include/fsserver/file_object_registry.h Sat Oct 16 22:09:18 2021 +0200
1.2 +++ b/libfsserver/include/fsserver/file_object_registry.h Sat Oct 16 22:11:11 2021 +0200
1.3 @@ -49,6 +49,16 @@
1.4 flags_t flags, fileid_t fileid,
1.5 FileProvider **file_provider);
1.6
1.7 + /* Resource initialisation methods. */
1.8 +
1.9 + long get_directory(FileOpening *opening, const char *path, flags_t flags,
1.10 + fileid_t fileid, offset_t *size, object_flags_t *object_flags,
1.11 + Resource **resource);
1.12 +
1.13 + long get_file(FileOpening *opening, const char *path, flags_t flags,
1.14 + fileid_t fileid, offset_t *size, object_flags_t *object_flags,
1.15 + Resource **resource);
1.16 +
1.17 public:
1.18 explicit FileObjectRegistry(Pages *pages);
1.19
1.20 @@ -59,11 +69,9 @@
1.21
1.22 /* Resource initialisation methods. */
1.23
1.24 - long get_directory(FileOpening *opening, const char *path, flags_t flags,
1.25 - fileid_t fileid, Resource **resource);
1.26 -
1.27 - long get_pager(FileOpening *opening, const char *path, flags_t flags,
1.28 - fileid_t fileid, Pager **pager);
1.29 + long get_resource(FileOpening *opening, const char *path, flags_t flags,
1.30 + offset_t *size, object_flags_t *object_flags,
1.31 + Resource **resource);
1.32 };
1.33
1.34 // vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/libfsserver/include/fsserver/file_opening.h Sat Oct 16 22:09:18 2021 +0200
2.2 +++ b/libfsserver/include/fsserver/file_opening.h Sat Oct 16 22:11:11 2021 +0200
2.3 @@ -31,6 +31,10 @@
2.4 class FileOpening
2.5 {
2.6 public:
2.7 + virtual bool accessing_directory(const char *path, flags_t flags, fileid_t fileid) = 0;
2.8 +
2.9 + virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid) = 0;
2.10 +
2.11 virtual long get_fileid(const char *path, flags_t flags, fileid_t *fileid) = 0;
2.12
2.13 virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid,
3.1 --- a/libfsserver/include/fsserver/opener_resource.h Sat Oct 16 22:09:18 2021 +0200
3.2 +++ b/libfsserver/include/fsserver/opener_resource.h Sat Oct 16 22:11:11 2021 +0200
3.3 @@ -36,22 +36,6 @@
3.4 protected:
3.5 FileObjectRegistry *_registry;
3.6
3.7 - /* Convenience methods determining different object types. */
3.8 -
3.9 - virtual bool accessing_directory(const char *path, flags_t flags, fileid_t fileid) = 0;
3.10 -
3.11 - virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid) = 0;
3.12 -
3.13 - /* Convenience methods obtaining different resource types. */
3.14 -
3.15 - virtual long get_directory(const char *path, flags_t flags, fileid_t fileid,
3.16 - offset_t *size, l4_cap_idx_t *cap,
3.17 - object_flags_t *object_flags);
3.18 -
3.19 - virtual long get_file(const char *path, flags_t flags, fileid_t fileid,
3.20 - offset_t *size, l4_cap_idx_t *cap,
3.21 - object_flags_t *object_flags);
3.22 -
3.23 /* Retrieval methods. */
3.24
3.25 virtual long get_parent(const char *path, fileid_t *fileid);
4.1 --- a/libfsserver/lib/files/file_object_registry.cc Sat Oct 16 22:09:18 2021 +0200
4.2 +++ b/libfsserver/lib/files/file_object_registry.cc Sat Oct 16 22:11:11 2021 +0200
4.3 @@ -140,10 +140,9 @@
4.4
4.5 long FileObjectRegistry::get_directory(FileOpening *opening, const char *path,
4.6 flags_t flags, fileid_t fileid,
4.7 + offset_t *size, object_flags_t *object_flags,
4.8 Resource **resource)
4.9 {
4.10 - std::lock_guard<std::mutex> guard(_lock);
4.11 -
4.12 /* Obtain any existing provider registered for the object, or make a new
4.13 provider. */
4.14
4.15 @@ -153,6 +152,11 @@
4.16 if (err)
4.17 return err;
4.18
4.19 + /* Provide non-file values for certain outputs. */
4.20 +
4.21 + *size = 0;
4.22 + *object_flags = 0;
4.23 +
4.24 /* Initialise the resource with the provider and a reference to this object
4.25 for detaching from the provider. */
4.26
4.27 @@ -161,14 +165,13 @@
4.28 return L4_EOK;
4.29 }
4.30
4.31 -/* Return a pager initialised with a provider, page mapper and accessor. */
4.32 +/* Return a file pager initialised with a provider, page mapper and accessor. */
4.33
4.34 -long FileObjectRegistry::get_pager(FileOpening *opening, const char *path,
4.35 - flags_t flags, fileid_t fileid,
4.36 - Pager **pager)
4.37 +long FileObjectRegistry::get_file(FileOpening *opening, const char *path,
4.38 + flags_t flags, fileid_t fileid,
4.39 + offset_t *size, object_flags_t *object_flags,
4.40 + Resource **resource)
4.41 {
4.42 - std::lock_guard<std::mutex> guard(_lock);
4.43 -
4.44 /* Obtain any existing provider registered for the file, or make a new
4.45 provider. */
4.46
4.47 @@ -181,9 +184,47 @@
4.48 /* Initialise the pager with the provider and a reference to this object for
4.49 detaching from the provider. */
4.50
4.51 + FilePager *pager = new FilePager(fileid, provider, get_flags(flags), this);
4.52 +
4.53 + /* Obtain the size details from the pager, also providing appropriate
4.54 + flags. */
4.55 +
4.56 + *size = pager->get_data_size();
4.57 + *object_flags = OBJECT_SUPPORTS_MMAP | OBJECT_HAS_SIZE;
4.58 +
4.59 provider->attach();
4.60 - *pager = new FilePager(fileid, provider, get_flags(flags), this);
4.61 + *resource = pager;
4.62 return L4_EOK;
4.63 }
4.64
4.65 +
4.66 +
4.67 +/* Return a resource for a filesystem object. */
4.68 +
4.69 +long FileObjectRegistry::get_resource(FileOpening *opening, const char *path,
4.70 + flags_t flags, offset_t *size,
4.71 + object_flags_t *object_flags,
4.72 + Resource **resource)
4.73 +{
4.74 + std::lock_guard<std::mutex> guard(_lock);
4.75 +
4.76 + /* Obtain an identifier for the file, even for new files (subject to use of
4.77 + the appropriate flag). */
4.78 +
4.79 + fileid_t fileid;
4.80 + long err = opening->get_fileid(path, flags, &fileid);
4.81 +
4.82 + if (err)
4.83 + return err;
4.84 +
4.85 + /* Test for file and directory access. */
4.86 +
4.87 + if (opening->accessing_directory(path, flags, fileid))
4.88 + return get_directory(opening, path, flags, fileid, size, object_flags, resource);
4.89 + else if (opening->accessing_file(path, flags, fileid))
4.90 + return get_file(opening, path, flags, fileid, size, object_flags, resource);
4.91 + else
4.92 + return -L4_EIO;
4.93 +}
4.94 +
4.95 // vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/libfsserver/lib/files/opener_resource.cc Sat Oct 16 22:09:18 2021 +0200
5.2 +++ b/libfsserver/lib/files/opener_resource.cc Sat Oct 16 22:11:11 2021 +0200
5.3 @@ -109,11 +109,8 @@
5.4 long OpenerResource::open(const char *path, flags_t flags, offset_t *size,
5.5 l4_cap_idx_t *cap, object_flags_t *object_flags)
5.6 {
5.7 - /* Obtain an identifier for the file, even for new files (subject to use of
5.8 - the appropriate flag). */
5.9 -
5.10 - fileid_t fileid;
5.11 - long err = get_fileid(path, flags, &fileid);
5.12 + Resource *resource;
5.13 + long err = _registry->get_resource(this, path, flags, size, object_flags, &resource);
5.14
5.15 if (err)
5.16 return err;
5.17 @@ -122,58 +119,9 @@
5.18
5.19 notify_parent(path);
5.20
5.21 - /* Test for file and directory access. */
5.22 -
5.23 - if (accessing_directory(path, flags, fileid))
5.24 - return get_directory(path, flags, fileid, size, cap, object_flags);
5.25 - else if (accessing_file(path, flags, fileid))
5.26 - return get_file(path, flags, fileid, size, cap, object_flags);
5.27 - else
5.28 - return -L4_EIO;
5.29 -}
5.30 -
5.31 -
5.32 -
5.33 -/* Return a directory object reference for the given file identifier. */
5.34 -
5.35 -long OpenerResource::get_directory(const char *path, flags_t flags,
5.36 - fileid_t fileid, offset_t *size,
5.37 - l4_cap_idx_t *cap,
5.38 - object_flags_t *object_flags)
5.39 -{
5.40 - Resource *directory;
5.41 - long err = _registry->get_directory(this, path, flags, fileid, &directory);
5.42 -
5.43 - if (err)
5.44 - return err;
5.45 + /* Start a server for the resource. */
5.46
5.47 - /* Provide non-file values for certain outputs. */
5.48 -
5.49 - *size = 0;
5.50 - *object_flags = 0;
5.51 -
5.52 - return ResourceServer(directory).start_thread(cap);
5.53 -}
5.54 -
5.55 -/* Return a file pager. */
5.56 -
5.57 -long OpenerResource::get_file(const char *path, flags_t flags, fileid_t fileid,
5.58 - offset_t *size, l4_cap_idx_t *cap,
5.59 - object_flags_t *object_flags)
5.60 -{
5.61 - Pager *pager;
5.62 - long err = _registry->get_pager(this, path, flags, fileid, &pager);
5.63 -
5.64 - if (err)
5.65 - return err;
5.66 -
5.67 - /* Obtain the size details from the pager, also providing appropriate
5.68 - flags. */
5.69 -
5.70 - *size = pager->get_data_size();
5.71 - *object_flags = OBJECT_SUPPORTS_MMAP | OBJECT_HAS_SIZE;
5.72 -
5.73 - return ResourceServer(pager).start_thread(cap);
5.74 + return ResourceServer(resource).start_thread(cap);
5.75 }
5.76
5.77