1 /* 2 * A dataspace server exposing file contents from an Ext2-based filesystem. 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 <e2access/fs.h> 31 #include <fsserver/page_queue_shared.h> 32 #include <fsserver/pages.h> 33 #include <fsserver/ext2_filesystem.h> 34 #include <mem/memory_incremental.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, "ext2_server"); 51 52 /* Require filesystem object details. */ 53 54 if (argc < 3) 55 { 56 printf("Need a filesystem capability name and filename.\n"); 57 return 1; 58 } 59 60 const char *fs_cap = argv[1]; 61 const char *fs_filename = argv[2]; 62 long err; 63 64 /* Introduce concurrency control. */ 65 66 err = ipc_thread_init(); 67 68 if (err) 69 { 70 printf("Initialisation error: %s\n", l4sys_errtostr(err)); 71 return 1; 72 } 73 74 unsigned int memory_pages = MEMORY_PAGES; 75 76 if (argc > 3) 77 memory_pages = atoi(argv[3]); 78 79 const char *server_name = (argc > 4) ? argv[4] : ENV_FILESYSTEM_SERVER_NAME; 80 81 /* Set the capability used to access the filesystem. */ 82 83 e2access_init(fs_cap); 84 85 /* Attempt to open the filesystem. */ 86 87 ext2_filsys fs; 88 errcode_t retval = e2access_open(fs_filename, EXT2_FLAG_RW, &fs); // EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS 89 90 if (retval) 91 { 92 printf("Could not obtain filesystem: %ld.\n", retval); 93 return 1; 94 } 95 96 /* Some memory plus infrastructure. */ 97 98 MemoryIncremental mem(memory_pages); 99 PageQueueShared queue; 100 Pages pages(&mem, &queue); 101 Ext2Filesystem filesystem(&pages, fs); 102 103 /* Register a server associating it with the given object. */ 104 105 ResourceServer server(&filesystem); 106 err = server.bind(server_name); 107 108 if (err) 109 { 110 printf("Could not bind server: %s\n", l4sys_errtostr(err)); 111 return 1; 112 } 113 114 printf("Starting server using %d pages...\n", memory_pages); 115 server.start(); 116 return 0; 117 }