1.1 --- a/libfsclient/lib/src/client.cc Mon May 06 01:14:09 2024 +0200
1.2 +++ b/libfsclient/lib/src/client.cc Thu May 09 16:46:44 2024 +0200
1.3 @@ -257,6 +257,9 @@
1.4 if (file == NULL)
1.5 return;
1.6
1.7 + if (file->metadata != NULL)
1.8 + client_close(file->metadata);
1.9 +
1.10 file_flush(file);
1.11 file_close(file);
1.12 free(file);
1.13 @@ -348,33 +351,30 @@
1.14 }
1.15
1.16 /* Open a directory listing stream via the given named directory and a named
1.17 - capability. */
1.18 + capability, returning the directory object with a metadata file object
1.19 + reference to the directory listing stream. */
1.20
1.21 file_t *client_opendir_using(const char *name, l4_cap_idx_t server)
1.22 {
1.23 file_t *file = client_open_using(name, O_DIRECTORY, server);
1.24
1.25 - if (file == NULL)
1.26 - return NULL;
1.27 -
1.28 /* Return the directory structure itself for error handling. */
1.29
1.30 if (!client_opened(file))
1.31 return file;
1.32
1.33 - file_t *reader = client_opendir_at(file);
1.34 + file->metadata = client_opendir_reader(file);
1.35
1.36 - /* Release the directory and return the reader even if an error occurs. */
1.37 + /* Return the directory even if an error occurs. */
1.38
1.39 - client_close(file);
1.40 - return reader;
1.41 + return file;
1.42 }
1.43
1.44
1.45
1.46 /* Open a directory listing stream via the given directory. */
1.47
1.48 -file_t *client_opendir_at(file_t *file)
1.49 +file_t *client_opendir_reader(file_t *file)
1.50 {
1.51 file_t *reader = (file_t *) malloc(sizeof(file_t));
1.52
1.53 @@ -640,8 +640,11 @@
1.54
1.55 struct dirent *client_readdir(file_t *file)
1.56 {
1.57 + if ((file == NULL) || (file->metadata == NULL))
1.58 + return NULL;
1.59 +
1.60 char buffer[DIRENT_CORE_SIZE];
1.61 - offset_t nread = client_read(file, buffer, DIRENT_CORE_SIZE);
1.62 + offset_t nread = client_read(file->metadata, buffer, DIRENT_CORE_SIZE);
1.63
1.64 /* Stop if no new structure can be successfully read. */
1.65
1.66 @@ -666,7 +669,7 @@
1.67
1.68 char *current = entry + DIRENT_CORE_SIZE;
1.69
1.70 - nread = client_read(file, current, remaining);
1.71 + nread = client_read(file->metadata, current, remaining);
1.72
1.73 /* Stop if no complete structure can be successfully read. */
1.74
1.75 @@ -679,6 +682,18 @@
1.76 return (struct dirent *) entry;
1.77 }
1.78
1.79 +/* Rewind directory reading. */
1.80 +
1.81 +void client_rewinddir(file_t *file)
1.82 +{
1.83 + if ((file == NULL) || (file->metadata == NULL))
1.84 + return;
1.85 +
1.86 + client_close(file->metadata);
1.87 +
1.88 + file->metadata = client_opendir_reader(file);
1.89 +}
1.90 +
1.91
1.92
1.93 /* Read from the filesystem object into the buffer provided. */