1.1 --- a/libfsclient/include/fsclient/client.h Mon Sep 20 01:16:59 2021 +0200
1.2 +++ b/libfsclient/include/fsclient/client.h Sat Sep 25 23:47:51 2021 +0200
1.3 @@ -39,7 +39,10 @@
1.4 file_t *client_open(const char *name, flags_t flags);
1.5 file_t *client_open_using(const char *name, flags_t flags, l4_cap_idx_t server);
1.6
1.7 -file_t *client_opendir(file_t *file);
1.8 +file_t *client_opendir(const char *name);
1.9 +file_t *client_opendir_using(const char *name, l4_cap_idx_t server);
1.10 +
1.11 +file_t *client_opendir_at(file_t *file);
1.12
1.13 long client_pipe(file_t **reader, file_t **writer, flags_t flags);
1.14 long client_pipe_using(file_t **reader, file_t **writer, flags_t flags, l4_cap_idx_t server);
2.1 --- a/libfsclient/lib/src/client.cc Mon Sep 20 01:16:59 2021 +0200
2.2 +++ b/libfsclient/lib/src/client.cc Sat Sep 25 23:47:51 2021 +0200
2.3 @@ -247,9 +247,41 @@
2.4
2.5
2.6
2.7 +/* Open a directory listing stream via the given named directory. */
2.8 +
2.9 +file_t *client_opendir(const char *name)
2.10 +{
2.11 + l4_cap_idx_t server = l4re_env_get_cap("server");
2.12 +
2.13 + return client_opendir_using(name, server);
2.14 +}
2.15 +
2.16 +/* Open a directory listing stream via the given named directory and a named
2.17 + capability. */
2.18 +
2.19 +file_t *client_opendir_using(const char *name, l4_cap_idx_t server)
2.20 +{
2.21 + file_t *file = client_open_using(name, O_DIRECTORY, server);
2.22 +
2.23 + if (file == NULL)
2.24 + return NULL;
2.25 +
2.26 + file_t *reader = client_opendir_at(file);
2.27 +
2.28 + if (reader == NULL)
2.29 + return NULL;
2.30 +
2.31 + /* Release the directory and return the reader. */
2.32 +
2.33 + client_close(file);
2.34 + return reader;
2.35 +}
2.36 +
2.37 +
2.38 +
2.39 /* Open a directory listing stream via the given directory. */
2.40
2.41 -file_t *client_opendir(file_t *file)
2.42 +file_t *client_opendir_at(file_t *file)
2.43 {
2.44 if (file == NULL)
2.45 return NULL;
3.1 --- a/tests/dstest_file_readdir.cc Mon Sep 20 01:16:59 2021 +0200
3.2 +++ b/tests/dstest_file_readdir.cc Sat Sep 25 23:47:51 2021 +0200
3.3 @@ -47,11 +47,11 @@
3.4
3.5 /* Invoke the open method to receive the file reference. */
3.6
3.7 - return client_open_using(filename, O_DIRECTORY, opener);
3.8 + return client_opendir_using(filename, opener);
3.9 }
3.10 else
3.11 {
3.12 - return client_open(filename, O_DIRECTORY);
3.13 + return client_opendir(filename);
3.14 }
3.15 }
3.16
3.17 @@ -71,15 +71,7 @@
3.18
3.19 printf("Opening %s...\n", filename);
3.20
3.21 - file_t *file = open_directory(filename, have_uid, uid);
3.22 -
3.23 - if (file == NULL)
3.24 - {
3.25 - printf("Could not obtain directory.\n");
3.26 - return 1;
3.27 - }
3.28 -
3.29 - file_t *reader = client_opendir(file);
3.30 + file_t *reader = open_directory(filename, have_uid, uid);
3.31
3.32 if (reader == NULL)
3.33 {
3.34 @@ -101,15 +93,7 @@
3.35
3.36 /* Open again, reading a single entry only. */
3.37
3.38 - file = open_directory(filename, have_uid, uid);
3.39 -
3.40 - if (file == NULL)
3.41 - {
3.42 - printf("Could not obtain directory.\n");
3.43 - return 1;
3.44 - }
3.45 -
3.46 - reader = client_opendir(file);
3.47 + reader = open_directory(filename, have_uid, uid);
3.48
3.49 if (reader == NULL)
3.50 {