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