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