1.1 --- a/Makefile Mon Mar 01 00:22:56 2021 +0100
1.2 +++ b/Makefile Thu Mar 04 23:50:40 2021 +0100
1.3 @@ -40,7 +40,7 @@
1.4
1.5 COMMON_SRC_CC = memory_utils.cc
1.6
1.7 -PLAIN_SRC_CC_dstest_host_client = dstest_host_client.cc
1.8 +PLAIN_SRC_CC_dstest_host_client = dstest_host_client.cc file.cc
1.9
1.10 PLAIN_SRC_CC_dstest_test_client = dstest_test_client.cc file.cc
1.11
2.1 --- a/dstest_host_client.cc Mon Mar 01 00:22:56 2021 +0100
2.2 +++ b/dstest_host_client.cc Thu Mar 04 23:50:40 2021 +0100
2.3 @@ -26,12 +26,9 @@
2.4 #include <string.h>
2.5 #include <stdlib.h>
2.6
2.7 -#include <ipc/mem_ipc.h>
2.8 +#include <ipc/thread.h>
2.9
2.10 -#include "dataspace_client.h"
2.11 -#include "opener_client.h"
2.12 -#include "opener_context_client.h"
2.13 -#include "mapped_file_client.h"
2.14 +#include "file.h"
2.15 #include "memory_utils.h"
2.16
2.17
2.18 @@ -57,10 +54,9 @@
2.19 /* Obtain access to the filesystem. */
2.20
2.21 l4_cap_idx_t server = l4re_env_get_cap("server");
2.22 - l4_cap_idx_t context_ref;
2.23 - client_Opener opener(server);
2.24 + file_t context;
2.25
2.26 - long err = opener.context(&context_ref);
2.27 + long err = file_context(&context, server);
2.28
2.29 if (err)
2.30 {
2.31 @@ -68,43 +64,15 @@
2.32 return 1;
2.33 }
2.34
2.35 - client_OpenerContext context(context_ref);
2.36 - client_Dataspace context_ds(context_ref);
2.37 - unsigned long size, flags;
2.38 -
2.39 - err = context_ds.info(&size, &flags);
2.40 -
2.41 - if (err)
2.42 - {
2.43 - printf("Could not obtain context info: %s\n", l4sys_errtostr(err));
2.44 - return 1;
2.45 - }
2.46 -
2.47 - /* Map context memory to write the filename. */
2.48 -
2.49 - char *memory;
2.50 -
2.51 - printf("Attach region of size %ld...\n", size);
2.52 -
2.53 - err = ipc_attach_dataspace(context_ref, size, (void **) &memory);
2.54 -
2.55 - if (err)
2.56 - {
2.57 - printf("Could not map memory: %s\n", l4sys_errtostr(err));
2.58 - return 1;
2.59 - }
2.60 -
2.61 - printf("Mapped memory at %p\n", memory);
2.62 -
2.63 /* Write the filename. */
2.64
2.65 - strcpy(memory, filename);
2.66 + strcpy(context.memory, filename);
2.67
2.68 /* Invoke the open method to receive the file reference. */
2.69
2.70 - l4_cap_idx_t file;
2.71 + file_t file;
2.72
2.73 - err = context.open(L4_FPAGE_RW, &size, &file);
2.74 + err = file_open(&file, context.ref);
2.75
2.76 if (err)
2.77 {
2.78 @@ -112,15 +80,9 @@
2.79 return 1;
2.80 }
2.81
2.82 - client_MappedFile obj(file);
2.83 -
2.84 - /* Some memory to be mapped. */
2.85 + /* A region of the file is mapped. */
2.86
2.87 - size_t start_pos, end_pos, data_end;
2.88 -
2.89 - printf("Map region from %ld to %ld...\n", 0L, page(10));
2.90 -
2.91 - err = obj.mmap(0, page(10), &start_pos, &end_pos, &data_end);
2.92 + err = file_mmap(&file, 0, page(10));
2.93
2.94 if (err)
2.95 {
2.96 @@ -128,36 +90,18 @@
2.97 return 1;
2.98 }
2.99
2.100 - printf("Mapped region from %ld to %ld with content %ld.\n",
2.101 - start_pos, end_pos, data_end);
2.102 -
2.103 - size = end_pos - start_pos;
2.104 -
2.105 - printf("Attach region of size %ld...\n", size);
2.106 -
2.107 - err = ipc_attach_dataspace(file, size, (void **) &memory);
2.108 -
2.109 - if (err)
2.110 + for (unsigned long offset = 0; offset < file_span(&file); offset += step)
2.111 {
2.112 - printf("Could not map memory: %s\n", l4sys_errtostr(err));
2.113 - return 1;
2.114 - }
2.115 -
2.116 - printf("Mapped memory at %p\n", memory);
2.117 -
2.118 - if (data_end < size)
2.119 - size = data_end;
2.120 -
2.121 - for (unsigned long offset = 0; offset < size; offset += step)
2.122 - {
2.123 - unsigned long remaining = size - offset;
2.124 + unsigned long remaining = file_span(&file) - offset;
2.125 unsigned long sample_remaining = remaining < sample ? remaining : sample;
2.126
2.127 - printf("%ld bytes from %p...\n", sample_remaining, (memory + offset));
2.128 - strncpy(buf, (memory + offset), sample_remaining);
2.129 + printf("%ld bytes from %p...\n", sample_remaining, (file.memory + offset));
2.130 + strncpy(buf, (file.memory + offset), sample_remaining);
2.131 buf[sample_remaining] = '\0';
2.132 printf("%s\n", buf);
2.133 }
2.134
2.135 return 0;
2.136 }
2.137 +
2.138 +// vim: tabstop=2 expandtab shiftwidth=2
3.1 --- a/dstest_test_client.cc Mon Mar 01 00:22:56 2021 +0100
3.2 +++ b/dstest_test_client.cc Thu Mar 04 23:50:40 2021 +0100
3.3 @@ -71,7 +71,7 @@
3.4 return err;
3.5 }
3.6
3.7 - /* Some memory to be mapped. */
3.8 + /* A region of the file is mapped. */
3.9
3.10 err = file_mmap(&file, page(start_page), page(MAP_PAGES));
3.11