1 /* 2 * A dataspace server exposing files each as a block of writable memory. 3 * 4 * Copyright (C) 2020, 2021, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/sys/debugger.h> 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/block_file_opener.h> 34 #include <resource/resource_server.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 l4_debugger_set_object_name(l4re_env()->main_thread, "block_server"); 50 long err; 51 52 /* Introduce concurrency control. */ 53 54 err = ipc_thread_init(); 55 56 if (err) 57 { 58 printf("Initialisation error: %s\n", l4sys_errtostr(err)); 59 return 1; 60 } 61 62 unsigned int memory_pages = MEMORY_PAGES; 63 64 if (argc > 1) 65 memory_pages = atoi(argv[1]); 66 67 /* Some memory plus infrastructure. */ 68 69 MemoryIncremental mem(memory_pages); 70 PageQueueShared queue; 71 Pages pages(&mem, &queue); 72 ResourceRegistry registry(&pages); 73 BlockFileOpener opener(®istry); 74 75 /* Register a server associating it with the given object. */ 76 77 const char *server_name = (argc > 2) ? argv[2] : ENV_FILESYSTEM_SERVER_NAME; 78 79 ResourceServer server(&opener); 80 err = server.bind(server_name); 81 82 if (err) 83 { 84 printf("Could not bind server: %s\n", l4sys_errtostr(err)); 85 return 1; 86 } 87 88 printf("Starting server using %d pages...\n", memory_pages); 89 server.start(); 90 return 0; 91 } 92 93 // vim: tabstop=2 expandtab shiftwidth=2