paul@106 | 1 | /* |
paul@106 | 2 | * A dataspace server exposing file contents from an Ext2-based filesystem. |
paul@106 | 3 | * |
paul@106 | 4 | * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk> |
paul@106 | 5 | * |
paul@106 | 6 | * This program is free software; you can redistribute it and/or |
paul@106 | 7 | * modify it under the terms of the GNU General Public License as |
paul@106 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@106 | 9 | * the License, or (at your option) any later version. |
paul@106 | 10 | * |
paul@106 | 11 | * This program is distributed in the hope that it will be useful, |
paul@106 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@106 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@106 | 14 | * GNU General Public License for more details. |
paul@106 | 15 | * |
paul@106 | 16 | * You should have received a copy of the GNU General Public License |
paul@106 | 17 | * along with this program; if not, write to the Free Software |
paul@106 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@106 | 19 | * Boston, MA 02110-1301, USA |
paul@106 | 20 | */ |
paul@106 | 21 | |
paul@106 | 22 | #include <l4/sys/err.h> |
paul@106 | 23 | |
paul@106 | 24 | #include <ipc/thread.h> |
paul@106 | 25 | |
paul@106 | 26 | #include <stdio.h> |
paul@106 | 27 | #include <stdlib.h> |
paul@106 | 28 | |
paul@106 | 29 | #include <e2access/fs.h> |
paul@106 | 30 | #include <fsserver/page_queue_shared.h> |
paul@106 | 31 | #include <fsserver/pages.h> |
paul@106 | 32 | #include <fsserver/resource_server.h> |
paul@144 | 33 | #include <fsserver/ext2_filesystem.h> |
paul@106 | 34 | #include <mem/memory_incremental.h> |
paul@106 | 35 | |
paul@106 | 36 | |
paul@106 | 37 | |
paul@106 | 38 | /* Default number of pages for files. */ |
paul@106 | 39 | |
paul@106 | 40 | const unsigned int MEMORY_PAGES = 20; |
paul@106 | 41 | |
paul@106 | 42 | |
paul@106 | 43 | |
paul@106 | 44 | /* Server program. */ |
paul@106 | 45 | |
paul@106 | 46 | int main(int argc, char *argv[]) |
paul@106 | 47 | { |
paul@106 | 48 | /* Require filesystem object details. */ |
paul@106 | 49 | |
paul@106 | 50 | if (argc < 3) |
paul@106 | 51 | { |
paul@106 | 52 | printf("Need a filesystem capability name and filename.\n"); |
paul@106 | 53 | return 1; |
paul@106 | 54 | } |
paul@106 | 55 | |
paul@106 | 56 | const char *fs_cap = argv[1]; |
paul@106 | 57 | const char *fs_filename = argv[2]; |
paul@106 | 58 | long err; |
paul@106 | 59 | |
paul@106 | 60 | /* Introduce concurrency control. */ |
paul@106 | 61 | |
paul@106 | 62 | err = ipc_thread_init(); |
paul@106 | 63 | |
paul@106 | 64 | if (err) |
paul@106 | 65 | { |
paul@106 | 66 | printf("Initialisation error: %s\n", l4sys_errtostr(err)); |
paul@106 | 67 | return 1; |
paul@106 | 68 | } |
paul@106 | 69 | |
paul@106 | 70 | unsigned int memory_pages = MEMORY_PAGES; |
paul@106 | 71 | |
paul@106 | 72 | if (argc > 3) |
paul@106 | 73 | memory_pages = atoi(argv[3]); |
paul@106 | 74 | |
paul@106 | 75 | const char *server_name = (argc > 4) ? argv[4] : "server"; |
paul@106 | 76 | |
paul@106 | 77 | /* Set the capability used to access the filesystem. */ |
paul@106 | 78 | |
paul@106 | 79 | e2access_init(fs_cap); |
paul@106 | 80 | |
paul@106 | 81 | /* Attempt to open the filesystem. */ |
paul@106 | 82 | |
paul@106 | 83 | ext2_filsys fs; |
paul@106 | 84 | errcode_t retval = e2access_open(fs_filename, EXT2_FLAG_RW, &fs); // EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS |
paul@106 | 85 | |
paul@106 | 86 | if (retval) |
paul@106 | 87 | { |
paul@106 | 88 | printf("Could not obtain filesystem: %ld.\n", retval); |
paul@106 | 89 | return 1; |
paul@106 | 90 | } |
paul@106 | 91 | |
paul@106 | 92 | /* Some memory plus infrastructure. */ |
paul@106 | 93 | |
paul@106 | 94 | MemoryIncremental mem(memory_pages); |
paul@106 | 95 | PageQueueShared queue; |
paul@106 | 96 | Pages pages(&mem, &queue); |
paul@200 | 97 | Ext2Filesystem filesystem(&pages, fs); |
paul@106 | 98 | |
paul@106 | 99 | /* Register a server associating it with the given object. */ |
paul@106 | 100 | |
paul@144 | 101 | ResourceServer server(&filesystem); |
paul@106 | 102 | err = server.bind(server_name); |
paul@106 | 103 | |
paul@106 | 104 | if (err) |
paul@106 | 105 | { |
paul@106 | 106 | printf("Could not bind server: %s\n", l4sys_errtostr(err)); |
paul@106 | 107 | return 1; |
paul@106 | 108 | } |
paul@106 | 109 | |
paul@106 | 110 | printf("Starting server using %d pages...\n", memory_pages); |
paul@106 | 111 | server.start(); |
paul@106 | 112 | return 0; |
paul@106 | 113 | } |