1 /* 2 * A dataspace server exposing file contents from an Ext2-based filesystem. 3 * 4 * Copyright (C) 2020, 2021 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 36 37 38 /* Default number of pages for files. */ 39 40 const unsigned int MEMORY_PAGES = 20; 41 42 43 44 /* Server program. */ 45 46 int main(int argc, char *argv[]) 47 { 48 /* Require filesystem object details. */ 49 50 if (argc < 3) 51 { 52 printf("Need a filesystem capability name and filename.\n"); 53 return 1; 54 } 55 56 const char *fs_cap = argv[1]; 57 const char *fs_filename = argv[2]; 58 long err; 59 60 /* Introduce concurrency control. */ 61 62 err = ipc_thread_init(); 63 64 if (err) 65 { 66 printf("Initialisation error: %s\n", l4sys_errtostr(err)); 67 return 1; 68 } 69 70 unsigned int memory_pages = MEMORY_PAGES; 71 72 if (argc > 3) 73 memory_pages = atoi(argv[3]); 74 75 const char *server_name = (argc > 4) ? argv[4] : "server"; 76 77 /* Set the capability used to access the filesystem. */ 78 79 e2access_init(fs_cap); 80 81 /* Attempt to open the filesystem. */ 82 83 ext2_filsys fs; 84 errcode_t retval = e2access_open(fs_filename, EXT2_FLAG_RW, &fs); // EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS 85 86 if (retval) 87 { 88 printf("Could not obtain filesystem: %ld.\n", retval); 89 return 1; 90 } 91 92 /* Some memory plus infrastructure. */ 93 94 MemoryIncremental mem(memory_pages); 95 PageQueueShared queue; 96 Pages pages(&mem, &queue); 97 Ext2Filesystem filesystem(&pages, fs); 98 99 /* Register a server associating it with the given object. */ 100 101 ResourceServer server(&filesystem); 102 err = server.bind(server_name); 103 104 if (err) 105 { 106 printf("Could not bind server: %s\n", l4sys_errtostr(err)); 107 return 1; 108 } 109 110 printf("Starting server using %d pages...\n", memory_pages); 111 server.start(); 112 return 0; 113 }