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/err.h> 24 25 #include <ipc/thread.h> 26 27 #include <stdio.h> 28 #include <stdlib.h> 29 30 #include <mem/memory_incremental.h> 31 #include <fsserver/page_queue_shared.h> 32 #include <fsserver/pages.h> 33 #include <fsserver/resource_server.h> 34 #include <fsserver/client_file_opener.h> 35 #include <systypes/env.h> 36 37 38 39 /* Default number of pages for files. */ 40 41 const unsigned int MEMORY_PAGES = 20; 42 43 44 45 /* Server program. */ 46 47 int main(int argc, char *argv[]) 48 { 49 long err; 50 51 /* Introduce concurrency control. */ 52 53 err = ipc_thread_init(); 54 55 if (err) 56 { 57 printf("Initialisation error: %s\n", l4sys_errtostr(err)); 58 return 1; 59 } 60 61 unsigned int memory_pages = MEMORY_PAGES; 62 63 if (argc > 1) 64 memory_pages = atoi(argv[1]); 65 66 /* Some memory plus infrastructure. */ 67 68 MemoryIncremental mem(memory_pages); 69 PageQueueShared queue; 70 Pages pages(&mem, &queue); 71 ResourceRegistry registry(&pages); 72 ClientFileOpener opener(®istry); 73 74 /* Register a server associating it with the given object. */ 75 76 const char *server_name = (argc > 2) ? argv[2] : ENV_FILESYSTEM_SERVER_NAME; 77 78 ResourceServer server(&opener); 79 err = server.bind(server_name); 80 81 if (err) 82 { 83 printf("Could not bind server: %s\n", l4sys_errtostr(err)); 84 return 1; 85 } 86 87 printf("Starting server using %d pages...\n", memory_pages); 88 server.start(); 89 return 0; 90 }