1 /* 2 * Access an ext2-based filesystem. 3 * 4 * Copyright (C) 2018, 2019 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/types.h> 23 24 #include <stdio.h> 25 #include <stdlib.h> 26 27 #include <ext2fs/ext2fs.h> 28 #include <fsserver/file_resource_server.h> 29 30 #include "fs_filesystem.h" 31 32 33 34 /* Access to block servers for libext2fs. */ 35 36 extern io_manager blockserver_io_manager; 37 38 39 40 int main(int argc, char *argv[]) 41 { 42 char *devname; 43 errcode_t retval; 44 int num_pages; 45 46 if (argc < 3) 47 { 48 printf("Need a block device capability or a file accessible via the fs capability.\n" 49 "Also need a number of pages to reserve for data.\n"); 50 return 1; 51 } 52 53 devname = argv[1]; 54 num_pages = atoi(argv[2]); 55 56 /* Obtain access to a filesystem situated on a block device. */ 57 58 ext2_filsys fs = NULL; 59 int ext2flags = EXT2_FLAG_RW; // | EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS; 60 61 if ((retval = ext2fs_open(devname, ext2flags, 0, 0, blockserver_io_manager, &fs))) 62 { 63 printf("Could not obtain filesystem: %ld.\n", retval); 64 return 1; 65 } 66 67 if ((retval = ext2fs_read_bitmaps(fs))) 68 { 69 printf("Could not obtain filesystem: %ld.\n", retval); 70 return 1; 71 } 72 73 /* Allocate pages for filesystem data. */ 74 75 Paging *paging = new Paging(new Pages(L4_PAGESIZE * num_pages)); 76 77 /* Initialise and register a new server object. */ 78 79 Fs_filesystem filesystem(paging, fs, devname); 80 FilesystemServer server(&filesystem); 81 82 if (server.bind("export")) 83 { 84 printf("Could not bind thread.\n"); 85 return 1; 86 } 87 88 /* Enter the IPC server loop. */ 89 90 server.start(); 91 return 0; 92 }