# HG changeset patch # User Paul Boddie # Date 1677620125 -3600 # Node ID d9b9ac497264fedcbb67e50adccf3cb97f74c64c # Parent 7f5b80fdea592ca42cb6bd456089e6bfbc8d8d73 Moved get_path to the SimplePager class as get_string for broader potential use. diff -r 7f5b80fdea59 -r d9b9ac497264 libfsserver/include/fsserver/opener_context_resource.h --- a/libfsserver/include/fsserver/opener_context_resource.h Mon Feb 27 14:46:13 2023 +0100 +++ b/libfsserver/include/fsserver/opener_context_resource.h Tue Feb 28 22:35:25 2023 +0100 @@ -1,7 +1,7 @@ /* * A context resource offering support for opening files. * - * Copyright (C) 2021, 2022 Paul Boddie + * Copyright (C) 2021, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -49,10 +49,6 @@ void *interface() { return static_cast(this); } - /* Data access methods. */ - - char *get_path(offset_t offset=0); - /* Opener context interface methods. */ long mkdir(sys_mode_t mode); diff -r 7f5b80fdea59 -r d9b9ac497264 libfsserver/include/fsserver/simple_pager.h --- a/libfsserver/include/fsserver/simple_pager.h Mon Feb 27 14:46:13 2023 +0100 +++ b/libfsserver/include/fsserver/simple_pager.h Tue Feb 28 22:35:25 2023 +0100 @@ -1,7 +1,7 @@ /* * A simple pager exposing a single memory region. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -41,6 +41,10 @@ void close(); + /* Data access methods. */ + + char *get_string(offset_t offset=0); + /* Paging methods. */ long map(offset_t offset, map_address_t hot_spot, map_flags_t flags, l4_snd_fpage_t *region); diff -r 7f5b80fdea59 -r d9b9ac497264 libfsserver/lib/files/opener_context_resource.cc --- a/libfsserver/lib/files/opener_context_resource.cc Mon Feb 27 14:46:13 2023 +0100 +++ b/libfsserver/lib/files/opener_context_resource.cc Tue Feb 28 22:35:25 2023 +0100 @@ -1,7 +1,7 @@ /* * A context resource offering support for opening files. * - * Copyright (C) 2021, 2022 Paul Boddie + * Copyright (C) 2021, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -43,28 +43,11 @@ -/* Data access methods. */ - -char *OpenerContextResource::get_path(offset_t offset) -{ - char *buffer = _region->read(offset); - offset_t size = _region->size(); - - /* Confine the path to the limit of the buffer. */ - - if ((buffer != NULL) && (strnlen(buffer, size) < size)) - return buffer; - else - return NULL; -} - - - /* Opener context interface methods. */ long OpenerContextResource::mkdir(sys_mode_t mode) { - char *path = get_path(); + char *path = get_string(); if (path == NULL) return -L4_EINVAL; @@ -75,7 +58,7 @@ long OpenerContextResource::open(flags_t flags, offset_t *size, l4_cap_idx_t *file, object_flags_t *object_flags) { - char *path = get_path(); + char *path = get_string(); if (path == NULL) return -L4_EINVAL; @@ -85,7 +68,7 @@ long OpenerContextResource::remove() { - char *path = get_path(); + char *path = get_string(); if (path == NULL) return -L4_EINVAL; @@ -97,12 +80,12 @@ { char *source, *target; - source = get_path(); + source = get_string(); if (source == NULL) return -L4_EINVAL; - target = get_path(strlen(source) + 1); + target = get_string(strlen(source) + 1); if (target == NULL) return -L4_EINVAL; @@ -112,7 +95,7 @@ long OpenerContextResource::stat() { - char *path = get_path(); + char *path = get_string(); if (path == NULL) return -L4_EINVAL; diff -r 7f5b80fdea59 -r d9b9ac497264 libfsserver/lib/generic/simple_pager.cc --- a/libfsserver/lib/generic/simple_pager.cc Mon Feb 27 14:46:13 2023 +0100 +++ b/libfsserver/lib/generic/simple_pager.cc Tue Feb 28 22:35:25 2023 +0100 @@ -1,7 +1,7 @@ /* * A simple pager exposing a single memory region. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -23,6 +23,8 @@ #include +#include + #include "dataspace_server.h" #include "ipc.h" #include "simple_pager.h" @@ -48,6 +50,25 @@ } } + + +/* Data access methods. */ + +char *SimplePager::get_string(offset_t offset) +{ + char *buffer = _region->read(offset); + offset_t size = _region->size(); + + /* Confine the path to the limit of the buffer. */ + + if ((buffer != NULL) && (strnlen(buffer, size) < size)) + return buffer; + else + return NULL; +} + + + /* Map a flexpage corresponding to the dataspace 'offset' involving a 'hot_spot' (flexpage offset). */