1.1 --- a/conf/dstest_host_readdir.cfg Fri Aug 06 19:26:54 2021 +0200
1.2 +++ b/conf/dstest_host_readdir.cfg Fri Aug 06 19:30:20 2021 +0200
1.3 @@ -31,4 +31,4 @@
1.4 },
1.5 log = { "client", "g" },
1.6 },
1.7 - "rom/dstest_host_readdir", "rom");
1.8 + "rom/dstest_file_readdir", "rom");
2.1 --- a/conf/dstest_host_readdir.list Fri Aug 06 19:26:54 2021 +0200
2.2 +++ b/conf/dstest_host_readdir.list Fri Aug 06 19:30:20 2021 +0200
2.3 @@ -3,7 +3,7 @@
2.4 module dstest_host_readdir.cfg
2.5 module l4re
2.6 module ned
2.7 -module dstest_host_readdir
2.8 +module dstest_file_readdir
2.9 module dstest_host_server
2.10 module dstest_pipe_server
2.11 module lib4re-c.so
3.1 --- a/tests/Makefile Fri Aug 06 19:26:54 2021 +0200
3.2 +++ b/tests/Makefile Fri Aug 06 19:30:20 2021 +0200
3.3 @@ -5,8 +5,8 @@
3.4 dstest_block_client dstest_block_client_simple \
3.5 dstest_ext2fs_client \
3.6 dstest_file_client \
3.7 + dstest_file_readdir \
3.8 dstest_host_client \
3.9 - dstest_host_readdir \
3.10 dstest_pipe_client \
3.11 dstest_test_client
3.12
3.13 @@ -20,9 +20,9 @@
3.14
3.15 SRC_CC_dstest_file_client = dstest_file_client.cc
3.16
3.17 -SRC_CC_dstest_host_client = dstest_host_client.cc
3.18 +SRC_CC_dstest_file_readdir = dstest_file_readdir.cc
3.19
3.20 -SRC_CC_dstest_host_readdir = dstest_host_readdir.cc
3.21 +SRC_CC_dstest_host_client = dstest_host_client.cc
3.22
3.23 SRC_CC_dstest_pipe_client = dstest_pipe_client.cc
3.24
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/dstest_file_readdir.cc Fri Aug 06 19:30:20 2021 +0200
4.3 @@ -0,0 +1,138 @@
4.4 +/*
4.5 + * Test directory reading operations.
4.6 + *
4.7 + * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
4.8 + *
4.9 + * This program is free software; you can redistribute it and/or
4.10 + * modify it under the terms of the GNU General Public License as
4.11 + * published by the Free Software Foundation; either version 2 of
4.12 + * the License, or (at your option) any later version.
4.13 + *
4.14 + * This program is distributed in the hope that it will be useful,
4.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 + * GNU General Public License for more details.
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License
4.20 + * along with this program; if not, write to the Free Software
4.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
4.22 + * Boston, MA 02110-1301, USA
4.23 + */
4.24 +
4.25 +#include <l4/re/env.h>
4.26 +#include <l4/sys/err.h>
4.27 +
4.28 +#include <dirent.h>
4.29 +#include <stdio.h>
4.30 +#include <string.h>
4.31 +#include <stdlib.h>
4.32 +
4.33 +#include <fsclient/client.h>
4.34 +#include <systypes/fcntl.h>
4.35 +
4.36 +
4.37 +
4.38 +#define DIRENT_CORE_SIZE (sizeof(struct dirent) - sizeof(((struct dirent *) 0)->d_name))
4.39 +
4.40 +int main(int argc, char *argv[])
4.41 +{
4.42 + if (argc < 2)
4.43 + {
4.44 + printf("Need a directory name and an optional user identifier (if used with a filesystem).\n");
4.45 + return 1;
4.46 + }
4.47 +
4.48 + char *filename = argv[1];
4.49 + bool have_uid = (argc > 2) && strlen(argv[2]);
4.50 + sys_uid_t uid = have_uid ? atoi(argv[2]) : 0;
4.51 + file_t *file;
4.52 +
4.53 + /* With a user, open a user-specific file opener. */
4.54 +
4.55 + if (have_uid)
4.56 + {
4.57 + l4_cap_idx_t opener = client_open_for_user((user_t) {uid, uid, 0022});
4.58 +
4.59 + if (l4_is_invalid_cap(opener))
4.60 + {
4.61 + printf("Could not obtain opener for file.\n");
4.62 + return 1;
4.63 + }
4.64 +
4.65 + /* Invoke the open method to receive the file reference. */
4.66 +
4.67 + file = client_open_using(filename, O_DIRECTORY, opener);
4.68 + }
4.69 + else
4.70 + {
4.71 + file = client_open(filename, O_DIRECTORY);
4.72 + }
4.73 +
4.74 + if (file == NULL)
4.75 + {
4.76 + printf("Could not obtain directory.\n");
4.77 + return 1;
4.78 + }
4.79 +
4.80 + // NOTE: To be replaced by a proper mechanism identifying the nature of each
4.81 + // NOTE: obtained object.
4.82 +
4.83 + file->can_mmap = 0;
4.84 + file->has_size = 0;
4.85 +
4.86 + /* Register the reader for notification. */
4.87 +
4.88 + long err = client_set_blocking(file, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED);
4.89 +
4.90 + if (err)
4.91 + {
4.92 + printf("Could not subscribe to notifications: %s\n", l4sys_errtostr(err));
4.93 + return 1;
4.94 + }
4.95 +
4.96 + char buffer[DIRENT_CORE_SIZE];
4.97 + offset_t nread = client_read(file, buffer, DIRENT_CORE_SIZE);
4.98 + offset_t total = 0;
4.99 +
4.100 + while (1)
4.101 + {
4.102 + if (!nread && (file->notifications & NOTIFY_PEER_CLOSED))
4.103 + break;
4.104 +
4.105 + total += nread;
4.106 +
4.107 + if (total == DIRENT_CORE_SIZE)
4.108 + {
4.109 + struct dirent *dirent = (struct dirent *) buffer;
4.110 + int remaining = dirent->d_reclen - DIRENT_CORE_SIZE;
4.111 + char entry[DIRENT_CORE_SIZE + remaining], *current;
4.112 +
4.113 + memcpy(entry, buffer, DIRENT_CORE_SIZE);
4.114 + current = entry + DIRENT_CORE_SIZE;
4.115 +
4.116 + do
4.117 + {
4.118 + nread = client_read(file, current, remaining);
4.119 + remaining -= nread;
4.120 + current += nread;
4.121 + }
4.122 + while (nread && remaining);
4.123 +
4.124 + if (remaining)
4.125 + break;
4.126 +
4.127 + dirent = (struct dirent *) entry;
4.128 + printf("> %s\n", dirent->d_name);
4.129 +
4.130 + total = 0;
4.131 + }
4.132 +
4.133 + nread = client_read(file, buffer, DIRENT_CORE_SIZE);
4.134 + }
4.135 +
4.136 + printf("Directory shown.\n");
4.137 +
4.138 + return 0;
4.139 +}
4.140 +
4.141 +// vim: tabstop=2 expandtab shiftwidth=2
5.1 --- a/tests/dstest_host_readdir.cc Fri Aug 06 19:26:54 2021 +0200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,138 +0,0 @@
5.4 -/*
5.5 - * Test directory reading operations.
5.6 - *
5.7 - * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
5.8 - *
5.9 - * This program is free software; you can redistribute it and/or
5.10 - * modify it under the terms of the GNU General Public License as
5.11 - * published by the Free Software Foundation; either version 2 of
5.12 - * the License, or (at your option) any later version.
5.13 - *
5.14 - * This program is distributed in the hope that it will be useful,
5.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.17 - * GNU General Public License for more details.
5.18 - *
5.19 - * You should have received a copy of the GNU General Public License
5.20 - * along with this program; if not, write to the Free Software
5.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
5.22 - * Boston, MA 02110-1301, USA
5.23 - */
5.24 -
5.25 -#include <l4/re/env.h>
5.26 -#include <l4/sys/err.h>
5.27 -
5.28 -#include <dirent.h>
5.29 -#include <stdio.h>
5.30 -#include <string.h>
5.31 -#include <stdlib.h>
5.32 -
5.33 -#include <fsclient/client.h>
5.34 -#include <systypes/fcntl.h>
5.35 -
5.36 -
5.37 -
5.38 -#define DIRENT_CORE_SIZE (sizeof(struct dirent) - sizeof(((struct dirent *) 0)->d_name))
5.39 -
5.40 -int main(int argc, char *argv[])
5.41 -{
5.42 - if (argc < 2)
5.43 - {
5.44 - printf("Need a directory name and an optional user identifier (if used with a filesystem).\n");
5.45 - return 1;
5.46 - }
5.47 -
5.48 - char *filename = argv[1];
5.49 - bool have_uid = (argc > 2) && strlen(argv[2]);
5.50 - sys_uid_t uid = have_uid ? atoi(argv[2]) : 0;
5.51 - file_t *file;
5.52 -
5.53 - /* With a user, open a user-specific file opener. */
5.54 -
5.55 - if (have_uid)
5.56 - {
5.57 - l4_cap_idx_t opener = client_open_for_user((user_t) {uid, uid, 0022});
5.58 -
5.59 - if (l4_is_invalid_cap(opener))
5.60 - {
5.61 - printf("Could not obtain opener for file.\n");
5.62 - return 1;
5.63 - }
5.64 -
5.65 - /* Invoke the open method to receive the file reference. */
5.66 -
5.67 - file = client_open_using(filename, O_DIRECTORY, opener);
5.68 - }
5.69 - else
5.70 - {
5.71 - file = client_open(filename, O_DIRECTORY);
5.72 - }
5.73 -
5.74 - if (file == NULL)
5.75 - {
5.76 - printf("Could not obtain directory.\n");
5.77 - return 1;
5.78 - }
5.79 -
5.80 - // NOTE: To be replaced by a proper mechanism identifying the nature of each
5.81 - // NOTE: obtained object.
5.82 -
5.83 - file->can_mmap = 0;
5.84 - file->has_size = 0;
5.85 -
5.86 - /* Register the reader for notification. */
5.87 -
5.88 - long err = client_set_blocking(file, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED);
5.89 -
5.90 - if (err)
5.91 - {
5.92 - printf("Could not subscribe to notifications: %s\n", l4sys_errtostr(err));
5.93 - return 1;
5.94 - }
5.95 -
5.96 - char buffer[DIRENT_CORE_SIZE];
5.97 - offset_t nread = client_read(file, buffer, DIRENT_CORE_SIZE);
5.98 - offset_t total = 0;
5.99 -
5.100 - while (1)
5.101 - {
5.102 - total += nread;
5.103 -
5.104 - if (total == DIRENT_CORE_SIZE)
5.105 - {
5.106 - struct dirent *dirent = (struct dirent *) buffer;
5.107 - int remaining = dirent->d_reclen - DIRENT_CORE_SIZE;
5.108 - char entry[DIRENT_CORE_SIZE + remaining], *current;
5.109 -
5.110 - memcpy(entry, buffer, DIRENT_CORE_SIZE);
5.111 - current = entry + DIRENT_CORE_SIZE;
5.112 -
5.113 - do
5.114 - {
5.115 - nread = client_read(file, current, remaining);
5.116 - remaining -= nread;
5.117 - current += nread;
5.118 - }
5.119 - while (nread && remaining);
5.120 -
5.121 - if (remaining)
5.122 - break;
5.123 -
5.124 - dirent = (struct dirent *) entry;
5.125 - printf("> %s\n", dirent->d_name);
5.126 -
5.127 - total = 0;
5.128 - }
5.129 -
5.130 - if (file->notifications & NOTIFY_PEER_CLOSED)
5.131 - break;
5.132 -
5.133 - nread = client_read(file, buffer, DIRENT_CORE_SIZE);
5.134 - }
5.135 -
5.136 - printf("Directory shown.\n");
5.137 -
5.138 - return 0;
5.139 -}
5.140 -
5.141 -// vim: tabstop=2 expandtab shiftwidth=2