1.1 --- a/libfsserver/lib/files/host_file_opener.cc Sat Sep 18 18:51:43 2021 +0200
1.2 +++ b/libfsserver/lib/files/host_file_opener.cc Mon Sep 20 01:16:59 2021 +0200
1.3 @@ -19,40 +19,14 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 -#include <thread>
1.8 -
1.9 -#include <dirent.h>
1.10 #include <sys/stat.h>
1.11
1.12 #include <fsclient/client.h>
1.13 -#include <systypes/fcntl.h>
1.14
1.15 +#include "host_directory_accessor.h"
1.16 #include "host_file_accessor.h"
1.17 #include "host_file_opener.h"
1.18 -
1.19 -
1.20 -
1.21 -/* Thread payload. */
1.22 -
1.23 -static void read_directory(const char *path, file_t *writer)
1.24 -{
1.25 - DIR *dir = opendir(path);
1.26 - struct dirent *dirent;
1.27 -
1.28 - /* Write directory entries to the pipe, closing the pipe when finished. */
1.29 -
1.30 - while ((dirent = readdir(dir)) != NULL)
1.31 - {
1.32 - offset_t nwritten = client_write(writer, (const void *) dirent, dirent->d_reclen);
1.33 -
1.34 - /* Stop writing if the pipe is closed. */
1.35 -
1.36 - if (nwritten < dirent->d_reclen)
1.37 - break;
1.38 - }
1.39 -
1.40 - client_close(writer);
1.41 -}
1.42 +#include "resource_server.h"
1.43
1.44
1.45
1.46 @@ -82,41 +56,6 @@
1.47 return (st.st_mode & S_IFREG) ? true : false;
1.48 }
1.49
1.50 -long HostFileOpener::get_directory(const char *path, flags_t flags,
1.51 - fileid_t fileid, offset_t *size,
1.52 - l4_cap_idx_t *cap, object_flags_t *object_flags)
1.53 -{
1.54 - /* The path is used to obtain the directory. */
1.55 -
1.56 - (void) flags; (void) fileid;
1.57 -
1.58 - file_t *reader, *writer;
1.59 -
1.60 - // Mapping of the reader's memory region should be avoided because no use
1.61 - // of the reader will be made here.
1.62 -
1.63 - long err = client_pipe(&reader, &writer, 0);
1.64 -
1.65 - if (err)
1.66 - return err;
1.67 -
1.68 - *size = reader->size;
1.69 - *cap = reader->ref;
1.70 - *object_flags = 0; /* does not support mmap, has no fixed size */
1.71 -
1.72 - /* Discard the reader structure but preserve the capability. */
1.73 -
1.74 - reader->ref = L4_INVALID_CAP;
1.75 - file_close(reader);
1.76 -
1.77 - /* Spawn a independent thread for reading the directory details and writing
1.78 - them to the pipe. */
1.79 -
1.80 - std::thread(read_directory, path, writer).detach();
1.81 -
1.82 - return L4_EOK;
1.83 -}
1.84 -
1.85 /* Return a file identifier for the given 'path'. */
1.86
1.87 long HostFileOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid)
1.88 @@ -164,7 +103,8 @@
1.89
1.90 /* Return a new accessor for 'fileid'. */
1.91
1.92 -long HostFileOpener::make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor)
1.93 +long HostFileOpener::make_accessor(const char *path, flags_t flags,
1.94 + fileid_t fileid, Accessor **accessor)
1.95 {
1.96 // NOTE: Not testing for create or write flags.
1.97
1.98 @@ -179,4 +119,16 @@
1.99 return L4_EOK;
1.100 }
1.101
1.102 +/* Return a directory accessor for 'fileid'. */
1.103 +
1.104 +long HostFileOpener::make_directory_accessor(const char *path, flags_t flags,
1.105 + fileid_t fileid,
1.106 + DirectoryAccessor **accessor)
1.107 +{
1.108 + (void) flags; (void) fileid;
1.109 +
1.110 + *accessor = new HostDirectoryAccessor(path);
1.111 + return L4_EOK;
1.112 +}
1.113 +
1.114 // vim: tabstop=4 expandtab shiftwidth=4