1.1 --- a/client/file.cc Sat Apr 03 00:02:41 2021 +0200
1.2 +++ b/client/file.cc Sun Apr 04 01:19:22 2021 +0200
1.3 @@ -53,6 +53,9 @@
1.4
1.5 long file_context(file_t *file, l4_cap_idx_t server)
1.6 {
1.7 + if (l4_is_invalid_cap(server))
1.8 + return -L4_EINVAL;
1.9 +
1.10 client_Opener opener(server);
1.11 unsigned long size, flags;
1.12 long err;
1.13 @@ -77,11 +80,11 @@
1.14
1.15 /* Open a file using the given structure and context. */
1.16
1.17 -long file_context_open(file_t *file, file_t *context)
1.18 +long file_context_open(file_t *file, flags_t flags, file_t *context)
1.19 {
1.20 client_OpenerContext openercontext(context->ref);
1.21 file_init(file);
1.22 - return openercontext.open(L4_FPAGE_RW, &file->size, &file->ref);
1.23 + return openercontext.open(flags, &file->size, &file->ref);
1.24 }
1.25
1.26 /* Initialise the given file structure. */
1.27 @@ -99,7 +102,7 @@
1.28 filesystem server. This is a convenience function invoking file_context and
1.29 file_context_open. */
1.30
1.31 -long file_open(file_t *file, const char *filename, l4_cap_idx_t server)
1.32 +long file_open(file_t *file, const char *filename, flags_t flags, l4_cap_idx_t server)
1.33 {
1.34 file_t context;
1.35 long err;
1.36 @@ -111,7 +114,7 @@
1.37 if (!file_string_set(&context, filename, 0, NULL))
1.38 return -L4_ENOMEM;
1.39
1.40 - err = file_context_open(file, &context);
1.41 + err = file_context_open(file, flags, &context);
1.42 file_close(&context);
1.43 return err;
1.44 }
1.45 @@ -237,6 +240,9 @@
1.46
1.47 long pipe_open(offset_t size, file_t *reader, file_t *writer, l4_cap_idx_t server)
1.48 {
1.49 + if (l4_is_invalid_cap(server))
1.50 + return -L4_EINVAL;
1.51 +
1.52 client_PipeOpener opener(server);
1.53
1.54 file_init(reader);
2.1 --- a/client/file.h Sat Apr 03 00:02:41 2021 +0200
2.2 +++ b/client/file.h Sun Apr 04 01:19:22 2021 +0200
2.3 @@ -55,12 +55,12 @@
2.4 /* File operations. */
2.5
2.6 void file_close(file_t *file);
2.7 -long file_open(file_t *file, const char *filename, l4_cap_idx_t server);
2.8 +long file_open(file_t *file, const char *filename, flags_t flags, l4_cap_idx_t server);
2.9
2.10 /* File lifecycle operations. */
2.11
2.12 long file_context(file_t *file, l4_cap_idx_t server);
2.13 -long file_context_open(file_t *file, file_t *context);
2.14 +long file_context_open(file_t *file, flags_t flags, file_t *context);
2.15 void file_init(file_t *file);
2.16
2.17 /* File and region operations. */
3.1 --- a/files/file_paging.cc Sat Apr 03 00:02:41 2021 +0200
3.2 +++ b/files/file_paging.cc Sun Apr 04 01:19:22 2021 +0200
3.3 @@ -1,6 +1,8 @@
3.4 #include "file_pager.h"
3.5 #include "file_paging.h"
3.6
3.7 +#include <systypes/fcntl.h>
3.8 +
3.9
3.10
3.11 FilePaging::FilePaging(Pages *pages)
3.12 @@ -8,6 +10,8 @@
3.13 {
3.14 }
3.15
3.16 +
3.17 +
3.18 /* Return any registered page mapper for the given 'fileid' or NULL if no such
3.19 mapper is registered. */
3.20
3.21 @@ -34,6 +38,17 @@
3.22 _mappers[fileid] = mapper;
3.23 }
3.24
3.25 +
3.26 +
3.27 +/* Convert opening flags to paging flags. */
3.28 +
3.29 +flags_t FilePaging::get_flags(flags_t flags)
3.30 +{
3.31 + return flags & (O_WRONLY | O_RDWR) ? L4_FPAGE_RW : L4_FPAGE_RO;
3.32 +}
3.33 +
3.34 +
3.35 +
3.36 /* Obtain a page mapper for the 'fileid' or register a new one in the
3.37 paging object. */
3.38
4.1 --- a/files/file_paging.h Sat Apr 03 00:02:41 2021 +0200
4.2 +++ b/files/file_paging.h Sun Apr 04 01:19:22 2021 +0200
4.3 @@ -36,6 +36,8 @@
4.4
4.5 virtual fileid_t get_fileid(const char *path) = 0;
4.6
4.7 + virtual flags_t get_flags(flags_t flags);
4.8 +
4.9 virtual Accessor *make_accessor(fileid_t fileid) = 0;
4.10
4.11 /* Mapper registry access. */
5.1 --- a/files/opener_resource.cc Sat Apr 03 00:02:41 2021 +0200
5.2 +++ b/files/opener_resource.cc Sun Apr 04 01:19:22 2021 +0200
5.3 @@ -30,7 +30,7 @@
5.4 if (fileid == FILEID_INVALID)
5.5 return NULL;
5.6
5.7 - return get_pager(fileid, flags);
5.8 + return get_pager(fileid, get_flags(flags));
5.9 }
5.10
5.11
6.1 --- a/tests/dstest_block_client.cc Sat Apr 03 00:02:41 2021 +0200
6.2 +++ b/tests/dstest_block_client.cc Sun Apr 04 01:19:22 2021 +0200
6.3 @@ -22,6 +22,8 @@
6.4 #include <l4/re/env.h>
6.5 #include <l4/sys/err.h>
6.6
6.7 +#include <systypes/fcntl.h>
6.8 +
6.9 #include <stdio.h>
6.10 #include <string.h>
6.11 #include <stdlib.h>
6.12 @@ -70,7 +72,7 @@
6.13 /* Invoke the open method to receive the file reference. */
6.14
6.15 file_t file;
6.16 - long err = file_open(&file, filename, server);
6.17 + long err = file_open(&file, filename, O_RDWR, server);
6.18
6.19 if (err)
6.20 {
7.1 --- a/tests/dstest_host_client.cc Sat Apr 03 00:02:41 2021 +0200
7.2 +++ b/tests/dstest_host_client.cc Sun Apr 04 01:19:22 2021 +0200
7.3 @@ -22,6 +22,8 @@
7.4 #include <l4/re/env.h>
7.5 #include <l4/sys/err.h>
7.6
7.7 +#include <systypes/fcntl.h>
7.8 +
7.9 #include <stdio.h>
7.10 #include <string.h>
7.11 #include <stdlib.h>
7.12 @@ -56,7 +58,7 @@
7.13 /* Invoke the open method to receive the file reference. */
7.14
7.15 file_t file;
7.16 - long err = file_open(&file, filename, server);
7.17 + long err = file_open(&file, filename, O_RDWR, server);
7.18
7.19 if (err)
7.20 {
8.1 --- a/tests/dstest_test_client.cc Sat Apr 03 00:02:41 2021 +0200
8.2 +++ b/tests/dstest_test_client.cc Sun Apr 04 01:19:22 2021 +0200
8.3 @@ -22,6 +22,8 @@
8.4 #include <l4/re/env.h>
8.5 #include <l4/sys/err.h>
8.6
8.7 +#include <systypes/fcntl.h>
8.8 +
8.9 #include <stdio.h>
8.10 #include <string.h>
8.11 #include <stdlib.h>
8.12 @@ -65,7 +67,7 @@
8.13
8.14 file_t file;
8.15
8.16 - long err = file_context_open(&file, context);
8.17 + long err = file_context_open(&file, O_RDONLY, context);
8.18
8.19 if (err)
8.20 {