1.1 --- a/libfsserver/lib/files/file_object_registry.cc Sat Oct 16 22:09:18 2021 +0200
1.2 +++ b/libfsserver/lib/files/file_object_registry.cc Sat Oct 16 22:11:11 2021 +0200
1.3 @@ -140,10 +140,9 @@
1.4
1.5 long FileObjectRegistry::get_directory(FileOpening *opening, const char *path,
1.6 flags_t flags, fileid_t fileid,
1.7 + offset_t *size, object_flags_t *object_flags,
1.8 Resource **resource)
1.9 {
1.10 - std::lock_guard<std::mutex> guard(_lock);
1.11 -
1.12 /* Obtain any existing provider registered for the object, or make a new
1.13 provider. */
1.14
1.15 @@ -153,6 +152,11 @@
1.16 if (err)
1.17 return err;
1.18
1.19 + /* Provide non-file values for certain outputs. */
1.20 +
1.21 + *size = 0;
1.22 + *object_flags = 0;
1.23 +
1.24 /* Initialise the resource with the provider and a reference to this object
1.25 for detaching from the provider. */
1.26
1.27 @@ -161,14 +165,13 @@
1.28 return L4_EOK;
1.29 }
1.30
1.31 -/* Return a pager initialised with a provider, page mapper and accessor. */
1.32 +/* Return a file pager initialised with a provider, page mapper and accessor. */
1.33
1.34 -long FileObjectRegistry::get_pager(FileOpening *opening, const char *path,
1.35 - flags_t flags, fileid_t fileid,
1.36 - Pager **pager)
1.37 +long FileObjectRegistry::get_file(FileOpening *opening, const char *path,
1.38 + flags_t flags, fileid_t fileid,
1.39 + offset_t *size, object_flags_t *object_flags,
1.40 + Resource **resource)
1.41 {
1.42 - std::lock_guard<std::mutex> guard(_lock);
1.43 -
1.44 /* Obtain any existing provider registered for the file, or make a new
1.45 provider. */
1.46
1.47 @@ -181,9 +184,47 @@
1.48 /* Initialise the pager with the provider and a reference to this object for
1.49 detaching from the provider. */
1.50
1.51 + FilePager *pager = new FilePager(fileid, provider, get_flags(flags), this);
1.52 +
1.53 + /* Obtain the size details from the pager, also providing appropriate
1.54 + flags. */
1.55 +
1.56 + *size = pager->get_data_size();
1.57 + *object_flags = OBJECT_SUPPORTS_MMAP | OBJECT_HAS_SIZE;
1.58 +
1.59 provider->attach();
1.60 - *pager = new FilePager(fileid, provider, get_flags(flags), this);
1.61 + *resource = pager;
1.62 return L4_EOK;
1.63 }
1.64
1.65 +
1.66 +
1.67 +/* Return a resource for a filesystem object. */
1.68 +
1.69 +long FileObjectRegistry::get_resource(FileOpening *opening, const char *path,
1.70 + flags_t flags, offset_t *size,
1.71 + object_flags_t *object_flags,
1.72 + Resource **resource)
1.73 +{
1.74 + std::lock_guard<std::mutex> guard(_lock);
1.75 +
1.76 + /* Obtain an identifier for the file, even for new files (subject to use of
1.77 + the appropriate flag). */
1.78 +
1.79 + fileid_t fileid;
1.80 + long err = opening->get_fileid(path, flags, &fileid);
1.81 +
1.82 + if (err)
1.83 + return err;
1.84 +
1.85 + /* Test for file and directory access. */
1.86 +
1.87 + if (opening->accessing_directory(path, flags, fileid))
1.88 + return get_directory(opening, path, flags, fileid, size, object_flags, resource);
1.89 + else if (opening->accessing_file(path, flags, fileid))
1.90 + return get_file(opening, path, flags, fileid, size, object_flags, resource);
1.91 + else
1.92 + return -L4_EIO;
1.93 +}
1.94 +
1.95 // vim: tabstop=4 expandtab shiftwidth=4