1.1 --- a/libfsclient/include/fsclient/client.h Tue Aug 10 23:41:57 2021 +0200
1.2 +++ b/libfsclient/include/fsclient/client.h Wed Aug 11 00:51:09 2021 +0200
1.3 @@ -39,6 +39,9 @@
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(const char *name);
1.8 +file_t *client_opendir_using(const char *name, l4_cap_idx_t server);
1.9 +
1.10 long client_pipe(file_t **reader, file_t **writer);
1.11 long client_pipe_using(file_t **reader, file_t **writer, l4_cap_idx_t server);
1.12
2.1 --- a/libfsclient/lib/src/client.cc Tue Aug 10 23:41:57 2021 +0200
2.2 +++ b/libfsclient/lib/src/client.cc Wed Aug 11 00:51:09 2021 +0200
2.3 @@ -25,6 +25,8 @@
2.4 #include <stdlib.h>
2.5 #include <string.h>
2.6
2.7 +#include <systypes/fcntl.h>
2.8 +
2.9 #include "client.h"
2.10
2.11
2.12 @@ -236,6 +238,38 @@
2.13
2.14
2.15
2.16 +/* Open a directory. */
2.17 +
2.18 +file_t *client_opendir(const char *name)
2.19 +{
2.20 + l4_cap_idx_t server = l4re_env_get_cap("server");
2.21 +
2.22 + return client_opendir_using(name, server);
2.23 +}
2.24 +
2.25 +/* Open a directory using a named capability. */
2.26 +
2.27 +file_t *client_opendir_using(const char *name, l4_cap_idx_t server)
2.28 +{
2.29 + file_t *file = client_open_using(name, O_DIRECTORY, server);
2.30 +
2.31 + if (file == NULL)
2.32 + return NULL;
2.33 +
2.34 + /* Set blocking read mode to be able to conveniently read directory entries
2.35 + from the stream. */
2.36 +
2.37 + if (client_set_blocking(file, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED))
2.38 + {
2.39 + client_close(file);
2.40 + return NULL;
2.41 + }
2.42 +
2.43 + return file;
2.44 +}
2.45 +
2.46 +
2.47 +
2.48 /* Open a pipe object. */
2.49
2.50 long client_pipe(file_t **reader, file_t **writer)
3.1 --- a/tests/dstest_file_readdir.cc Tue Aug 10 23:41:57 2021 +0200
3.2 +++ b/tests/dstest_file_readdir.cc Wed Aug 11 00:51:09 2021 +0200
3.3 @@ -31,7 +31,7 @@
3.4
3.5
3.6
3.7 -static file_t *open_file(char *filename, bool have_uid, sys_uid_t uid)
3.8 +static file_t *open_directory(char *filename, bool have_uid, sys_uid_t uid)
3.9 {
3.10 /* With a user, open a user-specific file opener. */
3.11
3.12 @@ -47,25 +47,16 @@
3.13
3.14 /* Invoke the open method to receive the file reference. */
3.15
3.16 - return client_open_using(filename, O_DIRECTORY, opener);
3.17 + return client_opendir_using(filename, opener);
3.18 }
3.19 else
3.20 {
3.21 - return client_open(filename, O_DIRECTORY);
3.22 + return client_opendir(filename);
3.23 }
3.24 }
3.25
3.26
3.27
3.28 -static long open_directory(file_t *file)
3.29 -{
3.30 - /* Register the reader for notification. */
3.31 -
3.32 - return client_set_blocking(file, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED);
3.33 -}
3.34 -
3.35 -
3.36 -
3.37 int main(int argc, char *argv[])
3.38 {
3.39 if (argc < 2)
3.40 @@ -77,7 +68,7 @@
3.41 char *filename = argv[1];
3.42 bool have_uid = (argc > 2) && strlen(argv[2]);
3.43 sys_uid_t uid = have_uid ? atoi(argv[2]) : 0;
3.44 - file_t *file = open_file(filename, have_uid, uid);
3.45 + file_t *file = open_directory(filename, have_uid, uid);
3.46
3.47 if (file == NULL)
3.48 {
3.49 @@ -85,14 +76,6 @@
3.50 return 1;
3.51 }
3.52
3.53 - long err = open_directory(file);
3.54 -
3.55 - if (err)
3.56 - {
3.57 - printf("Could not subscribe to notifications: %s\n", l4sys_errtostr(err));
3.58 - return 1;
3.59 - }
3.60 -
3.61 struct dirent *dirent;
3.62
3.63 while ((dirent = client_readdir(file)) != NULL)
3.64 @@ -105,7 +88,7 @@
3.65
3.66 /* Open again, reading a single entry only. */
3.67
3.68 - file = open_file(filename, have_uid, uid);
3.69 + file = open_directory(filename, have_uid, uid);
3.70
3.71 if (file == NULL)
3.72 {
3.73 @@ -113,14 +96,6 @@
3.74 return 1;
3.75 }
3.76
3.77 - err = open_directory(file);
3.78 -
3.79 - if (err)
3.80 - {
3.81 - printf("Could not subscribe to notifications: %s\n", l4sys_errtostr(err));
3.82 - return 1;
3.83 - }
3.84 -
3.85 dirent = client_readdir(file);
3.86
3.87 if (dirent != NULL)