1.1 --- a/dstest_client.cc Mon Feb 01 01:04:30 2021 +0100
1.2 +++ b/dstest_client.cc Wed Feb 03 00:15:16 2021 +0100
1.3 @@ -36,8 +36,26 @@
1.4
1.5
1.6
1.7 -int main(void)
1.8 +int main(int argc, char *argv[])
1.9 {
1.10 + if (argc < 4)
1.11 + {
1.12 + printf("Need filename, step and sample size.\n");
1.13 + return 1;
1.14 + }
1.15 +
1.16 + /* Obtain filename and access parameters. */
1.17 +
1.18 + char *filename = argv[1];
1.19 + unsigned long step = atoi(argv[2]);
1.20 + unsigned long sample = atoi(argv[3]);
1.21 +
1.22 + /* Allocate a buffer for sampling from the file. */
1.23 +
1.24 + char buf[sample + 1];
1.25 +
1.26 + /* Obtain access to the filesystem. */
1.27 +
1.28 l4_cap_idx_t server = l4re_env_get_cap("server");
1.29 l4_cap_idx_t context_ref;
1.30 client_Opener opener(server);
1.31 @@ -80,7 +98,7 @@
1.32
1.33 /* Write the filename. */
1.34
1.35 - strcpy(memory, "123");
1.36 + strcpy(memory, filename);
1.37
1.38 /* Invoke the open method to receive the file reference. */
1.39
1.40 @@ -110,6 +128,9 @@
1.41 return 1;
1.42 }
1.43
1.44 + printf("Mapped region from %ld to %ld with content %ld.\n",
1.45 + start_pos, end_pos, data_end);
1.46 +
1.47 size = end_pos - start_pos;
1.48
1.49 printf("Attach region of size %ld...\n", size);
1.50 @@ -124,12 +145,17 @@
1.51
1.52 printf("Mapped memory at %p\n", memory);
1.53
1.54 - for (unsigned long offset = 0; offset < size; offset += 1024)
1.55 + if (data_end < size)
1.56 + size = data_end;
1.57 +
1.58 + for (unsigned long offset = 0; offset < size; offset += step)
1.59 {
1.60 - char buf[11];
1.61 - printf("10 bytes from %p...\n", (memory + offset));
1.62 - strncpy(buf, (memory + offset), 10);
1.63 - buf[10] = '\0';
1.64 + unsigned long remaining = size - offset;
1.65 + unsigned long sample_remaining = remaining < sample ? remaining : sample;
1.66 +
1.67 + printf("%ld bytes from %p...\n", sample_remaining, (memory + offset));
1.68 + strncpy(buf, (memory + offset), sample_remaining);
1.69 + buf[sample_remaining] = '\0';
1.70 printf("%s\n", buf);
1.71 }
1.72