# HG changeset patch # User Paul Boddie # Date 1632606471 -7200 # Node ID ff48359ce6d7bd0513dbc49d3eb705f0c61feb7b # Parent 85396ddb32608faf4e5011923d46c377ac30fbd2 Made client_opendir obtain a directory listing reader object, renaming the previous version of the function to client_opendir_at, in anticipation of a suite of *_at functions. Added a client_opendir_using function. diff -r 85396ddb3260 -r ff48359ce6d7 libfsclient/include/fsclient/client.h --- a/libfsclient/include/fsclient/client.h Mon Sep 20 01:16:59 2021 +0200 +++ b/libfsclient/include/fsclient/client.h Sat Sep 25 23:47:51 2021 +0200 @@ -39,7 +39,10 @@ file_t *client_open(const char *name, flags_t flags); file_t *client_open_using(const char *name, flags_t flags, l4_cap_idx_t server); -file_t *client_opendir(file_t *file); +file_t *client_opendir(const char *name); +file_t *client_opendir_using(const char *name, l4_cap_idx_t server); + +file_t *client_opendir_at(file_t *file); long client_pipe(file_t **reader, file_t **writer, flags_t flags); long client_pipe_using(file_t **reader, file_t **writer, flags_t flags, l4_cap_idx_t server); diff -r 85396ddb3260 -r ff48359ce6d7 libfsclient/lib/src/client.cc --- a/libfsclient/lib/src/client.cc Mon Sep 20 01:16:59 2021 +0200 +++ b/libfsclient/lib/src/client.cc Sat Sep 25 23:47:51 2021 +0200 @@ -247,9 +247,41 @@ +/* Open a directory listing stream via the given named directory. */ + +file_t *client_opendir(const char *name) +{ + l4_cap_idx_t server = l4re_env_get_cap("server"); + + return client_opendir_using(name, server); +} + +/* Open a directory listing stream via the given named directory and a named + capability. */ + +file_t *client_opendir_using(const char *name, l4_cap_idx_t server) +{ + file_t *file = client_open_using(name, O_DIRECTORY, server); + + if (file == NULL) + return NULL; + + file_t *reader = client_opendir_at(file); + + if (reader == NULL) + return NULL; + + /* Release the directory and return the reader. */ + + client_close(file); + return reader; +} + + + /* Open a directory listing stream via the given directory. */ -file_t *client_opendir(file_t *file) +file_t *client_opendir_at(file_t *file) { if (file == NULL) return NULL; diff -r 85396ddb3260 -r ff48359ce6d7 tests/dstest_file_readdir.cc --- a/tests/dstest_file_readdir.cc Mon Sep 20 01:16:59 2021 +0200 +++ b/tests/dstest_file_readdir.cc Sat Sep 25 23:47:51 2021 +0200 @@ -47,11 +47,11 @@ /* Invoke the open method to receive the file reference. */ - return client_open_using(filename, O_DIRECTORY, opener); + return client_opendir_using(filename, opener); } else { - return client_open(filename, O_DIRECTORY); + return client_opendir(filename); } } @@ -71,15 +71,7 @@ printf("Opening %s...\n", filename); - file_t *file = open_directory(filename, have_uid, uid); - - if (file == NULL) - { - printf("Could not obtain directory.\n"); - return 1; - } - - file_t *reader = client_opendir(file); + file_t *reader = open_directory(filename, have_uid, uid); if (reader == NULL) { @@ -101,15 +93,7 @@ /* Open again, reading a single entry only. */ - file = open_directory(filename, have_uid, uid); - - if (file == NULL) - { - printf("Could not obtain directory.\n"); - return 1; - } - - reader = client_opendir(file); + reader = open_directory(filename, have_uid, uid); if (reader == NULL) {