paul@0 | 1 | /* |
paul@84 | 2 | * A dataspace server exposing "host" file contents. |
paul@0 | 3 | * |
paul@507 | 4 | * Copyright (C) 2020, 2021, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 5 | * |
paul@0 | 6 | * This program is free software; you can redistribute it and/or |
paul@0 | 7 | * modify it under the terms of the GNU General Public License as |
paul@0 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@0 | 9 | * the License, or (at your option) any later version. |
paul@0 | 10 | * |
paul@0 | 11 | * This program is distributed in the hope that it will be useful, |
paul@0 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@0 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@0 | 14 | * GNU General Public License for more details. |
paul@0 | 15 | * |
paul@0 | 16 | * You should have received a copy of the GNU General Public License |
paul@0 | 17 | * along with this program; if not, write to the Free Software |
paul@0 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@0 | 19 | * Boston, MA 02110-1301, USA |
paul@0 | 20 | */ |
paul@0 | 21 | |
paul@0 | 22 | #include <l4/sys/err.h> |
paul@0 | 23 | |
paul@84 | 24 | #include <ipc/thread.h> |
paul@84 | 25 | |
paul@0 | 26 | #include <stdio.h> |
paul@0 | 27 | #include <stdlib.h> |
paul@0 | 28 | |
paul@94 | 29 | #include <mem/memory_incremental.h> |
paul@94 | 30 | #include <fsserver/page_queue_shared.h> |
paul@94 | 31 | #include <fsserver/pages.h> |
paul@94 | 32 | #include <fsserver/resource_server.h> |
paul@94 | 33 | #include <fsserver/host_file_opener.h> |
paul@507 | 34 | #include <systypes/env.h> |
paul@0 | 35 | |
paul@0 | 36 | |
paul@0 | 37 | |
paul@84 | 38 | /* Default number of pages for files. */ |
paul@84 | 39 | |
paul@84 | 40 | const unsigned int MEMORY_PAGES = 20; |
paul@84 | 41 | |
paul@84 | 42 | |
paul@84 | 43 | |
paul@84 | 44 | /* Server program. */ |
paul@84 | 45 | |
paul@84 | 46 | int main(int argc, char *argv[]) |
paul@84 | 47 | { |
paul@84 | 48 | long err; |
paul@84 | 49 | |
paul@84 | 50 | /* Introduce concurrency control. */ |
paul@7 | 51 | |
paul@84 | 52 | err = ipc_thread_init(); |
paul@84 | 53 | |
paul@84 | 54 | if (err) |
paul@84 | 55 | { |
paul@84 | 56 | printf("Initialisation error: %s\n", l4sys_errtostr(err)); |
paul@84 | 57 | return 1; |
paul@84 | 58 | } |
paul@84 | 59 | |
paul@84 | 60 | unsigned int memory_pages = MEMORY_PAGES; |
paul@84 | 61 | |
paul@84 | 62 | if (argc > 1) |
paul@84 | 63 | memory_pages = atoi(argv[1]); |
paul@84 | 64 | |
paul@9 | 65 | /* Some memory plus infrastructure. */ |
paul@0 | 66 | |
paul@84 | 67 | MemoryIncremental mem(memory_pages); |
paul@72 | 68 | PageQueueShared queue; |
paul@72 | 69 | Pages pages(&mem, &queue); |
paul@224 | 70 | ResourceRegistry registry(&pages); |
paul@209 | 71 | HostFileOpener opener(®istry); |
paul@0 | 72 | |
paul@0 | 73 | /* Register a server associating it with the given object. */ |
paul@0 | 74 | |
paul@507 | 75 | const char *server_name = (argc > 2) ? argv[2] : ENV_FILESYSTEM_SERVER_NAME; |
paul@97 | 76 | |
paul@10 | 77 | ResourceServer server(&opener); |
paul@97 | 78 | err = server.bind(server_name); |
paul@0 | 79 | |
paul@0 | 80 | if (err) |
paul@0 | 81 | { |
paul@0 | 82 | printf("Could not bind server: %s\n", l4sys_errtostr(err)); |
paul@0 | 83 | return 1; |
paul@0 | 84 | } |
paul@0 | 85 | |
paul@84 | 86 | printf("Starting server using %d pages...\n", memory_pages); |
paul@10 | 87 | server.start(); |
paul@0 | 88 | return 0; |
paul@0 | 89 | } |