# HG changeset patch # User Paul Boddie # Date 1628271020 -7200 # Node ID eca2519bb8ee755c92fe48441e897c2bb7554188 # Parent 211abeb2a17edaf97406a5f426334a5e23071291 Renamed the directory reading test, adjusting slightly. diff -r 211abeb2a17e -r eca2519bb8ee conf/dstest_host_readdir.cfg --- a/conf/dstest_host_readdir.cfg Fri Aug 06 19:26:54 2021 +0200 +++ b/conf/dstest_host_readdir.cfg Fri Aug 06 19:30:20 2021 +0200 @@ -31,4 +31,4 @@ }, log = { "client", "g" }, }, - "rom/dstest_host_readdir", "rom"); + "rom/dstest_file_readdir", "rom"); diff -r 211abeb2a17e -r eca2519bb8ee conf/dstest_host_readdir.list --- a/conf/dstest_host_readdir.list Fri Aug 06 19:26:54 2021 +0200 +++ b/conf/dstest_host_readdir.list Fri Aug 06 19:30:20 2021 +0200 @@ -3,7 +3,7 @@ module dstest_host_readdir.cfg module l4re module ned -module dstest_host_readdir +module dstest_file_readdir module dstest_host_server module dstest_pipe_server module lib4re-c.so diff -r 211abeb2a17e -r eca2519bb8ee tests/Makefile --- a/tests/Makefile Fri Aug 06 19:26:54 2021 +0200 +++ b/tests/Makefile Fri Aug 06 19:30:20 2021 +0200 @@ -5,8 +5,8 @@ dstest_block_client dstest_block_client_simple \ dstest_ext2fs_client \ dstest_file_client \ + dstest_file_readdir \ dstest_host_client \ - dstest_host_readdir \ dstest_pipe_client \ dstest_test_client @@ -20,9 +20,9 @@ SRC_CC_dstest_file_client = dstest_file_client.cc -SRC_CC_dstest_host_client = dstest_host_client.cc +SRC_CC_dstest_file_readdir = dstest_file_readdir.cc -SRC_CC_dstest_host_readdir = dstest_host_readdir.cc +SRC_CC_dstest_host_client = dstest_host_client.cc SRC_CC_dstest_pipe_client = dstest_pipe_client.cc diff -r 211abeb2a17e -r eca2519bb8ee tests/dstest_file_readdir.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/dstest_file_readdir.cc Fri Aug 06 19:30:20 2021 +0200 @@ -0,0 +1,138 @@ +/* + * Test directory reading operations. + * + * Copyright (C) 2020, 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include +#include + +#include +#include +#include +#include + +#include +#include + + + +#define DIRENT_CORE_SIZE (sizeof(struct dirent) - sizeof(((struct dirent *) 0)->d_name)) + +int main(int argc, char *argv[]) +{ + if (argc < 2) + { + printf("Need a directory name and an optional user identifier (if used with a filesystem).\n"); + return 1; + } + + char *filename = argv[1]; + bool have_uid = (argc > 2) && strlen(argv[2]); + sys_uid_t uid = have_uid ? atoi(argv[2]) : 0; + file_t *file; + + /* With a user, open a user-specific file opener. */ + + if (have_uid) + { + l4_cap_idx_t opener = client_open_for_user((user_t) {uid, uid, 0022}); + + if (l4_is_invalid_cap(opener)) + { + printf("Could not obtain opener for file.\n"); + return 1; + } + + /* Invoke the open method to receive the file reference. */ + + file = client_open_using(filename, O_DIRECTORY, opener); + } + else + { + file = client_open(filename, O_DIRECTORY); + } + + if (file == NULL) + { + printf("Could not obtain directory.\n"); + return 1; + } + + // NOTE: To be replaced by a proper mechanism identifying the nature of each + // NOTE: obtained object. + + file->can_mmap = 0; + file->has_size = 0; + + /* Register the reader for notification. */ + + long err = client_set_blocking(file, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED); + + if (err) + { + printf("Could not subscribe to notifications: %s\n", l4sys_errtostr(err)); + return 1; + } + + char buffer[DIRENT_CORE_SIZE]; + offset_t nread = client_read(file, buffer, DIRENT_CORE_SIZE); + offset_t total = 0; + + while (1) + { + if (!nread && (file->notifications & NOTIFY_PEER_CLOSED)) + break; + + total += nread; + + if (total == DIRENT_CORE_SIZE) + { + struct dirent *dirent = (struct dirent *) buffer; + int remaining = dirent->d_reclen - DIRENT_CORE_SIZE; + char entry[DIRENT_CORE_SIZE + remaining], *current; + + memcpy(entry, buffer, DIRENT_CORE_SIZE); + current = entry + DIRENT_CORE_SIZE; + + do + { + nread = client_read(file, current, remaining); + remaining -= nread; + current += nread; + } + while (nread && remaining); + + if (remaining) + break; + + dirent = (struct dirent *) entry; + printf("> %s\n", dirent->d_name); + + total = 0; + } + + nread = client_read(file, buffer, DIRENT_CORE_SIZE); + } + + printf("Directory shown.\n"); + + return 0; +} + +// vim: tabstop=2 expandtab shiftwidth=2 diff -r 211abeb2a17e -r eca2519bb8ee tests/dstest_host_readdir.cc --- a/tests/dstest_host_readdir.cc Fri Aug 06 19:26:54 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -/* - * Test directory reading operations. - * - * Copyright (C) 2020, 2021 Paul Boddie - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#include -#include - -#include -#include -#include -#include - -#include -#include - - - -#define DIRENT_CORE_SIZE (sizeof(struct dirent) - sizeof(((struct dirent *) 0)->d_name)) - -int main(int argc, char *argv[]) -{ - if (argc < 2) - { - printf("Need a directory name and an optional user identifier (if used with a filesystem).\n"); - return 1; - } - - char *filename = argv[1]; - bool have_uid = (argc > 2) && strlen(argv[2]); - sys_uid_t uid = have_uid ? atoi(argv[2]) : 0; - file_t *file; - - /* With a user, open a user-specific file opener. */ - - if (have_uid) - { - l4_cap_idx_t opener = client_open_for_user((user_t) {uid, uid, 0022}); - - if (l4_is_invalid_cap(opener)) - { - printf("Could not obtain opener for file.\n"); - return 1; - } - - /* Invoke the open method to receive the file reference. */ - - file = client_open_using(filename, O_DIRECTORY, opener); - } - else - { - file = client_open(filename, O_DIRECTORY); - } - - if (file == NULL) - { - printf("Could not obtain directory.\n"); - return 1; - } - - // NOTE: To be replaced by a proper mechanism identifying the nature of each - // NOTE: obtained object. - - file->can_mmap = 0; - file->has_size = 0; - - /* Register the reader for notification. */ - - long err = client_set_blocking(file, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED); - - if (err) - { - printf("Could not subscribe to notifications: %s\n", l4sys_errtostr(err)); - return 1; - } - - char buffer[DIRENT_CORE_SIZE]; - offset_t nread = client_read(file, buffer, DIRENT_CORE_SIZE); - offset_t total = 0; - - while (1) - { - total += nread; - - if (total == DIRENT_CORE_SIZE) - { - struct dirent *dirent = (struct dirent *) buffer; - int remaining = dirent->d_reclen - DIRENT_CORE_SIZE; - char entry[DIRENT_CORE_SIZE + remaining], *current; - - memcpy(entry, buffer, DIRENT_CORE_SIZE); - current = entry + DIRENT_CORE_SIZE; - - do - { - nread = client_read(file, current, remaining); - remaining -= nread; - current += nread; - } - while (nread && remaining); - - if (remaining) - break; - - dirent = (struct dirent *) entry; - printf("> %s\n", dirent->d_name); - - total = 0; - } - - if (file->notifications & NOTIFY_PEER_CLOSED) - break; - - nread = client_read(file, buffer, DIRENT_CORE_SIZE); - } - - printf("Directory shown.\n"); - - return 0; -} - -// vim: tabstop=2 expandtab shiftwidth=2