paul@102 | 1 | /* |
paul@106 | 2 | * An opener for a file provided by an Ext2-compatible filesystem. |
paul@102 | 3 | * |
paul@102 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@102 | 5 | * |
paul@102 | 6 | * This program is free software; you can redistribute it and/or |
paul@102 | 7 | * modify it under the terms of the GNU General Public License as |
paul@102 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@102 | 9 | * the License, or (at your option) any later version. |
paul@102 | 10 | * |
paul@102 | 11 | * This program is distributed in the hope that it will be useful, |
paul@102 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@102 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@102 | 14 | * GNU General Public License for more details. |
paul@102 | 15 | * |
paul@102 | 16 | * You should have received a copy of the GNU General Public License |
paul@102 | 17 | * along with this program; if not, write to the Free Software |
paul@102 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@102 | 19 | * Boston, MA 02110-1301, USA |
paul@102 | 20 | */ |
paul@102 | 21 | |
paul@106 | 22 | #include <e2access/image.h> |
paul@106 | 23 | |
paul@106 | 24 | #include "ext2_file_accessor.h" |
paul@106 | 25 | #include "ext2_file_opener.h" |
paul@102 | 26 | |
paul@102 | 27 | /* Return a file identifier for the given 'path'. */ |
paul@102 | 28 | |
paul@143 | 29 | fileid_t Ext2FileOpener::get_fileid(const char *path, flags_t flags) |
paul@102 | 30 | { |
paul@106 | 31 | /* Obtain the inode number. */ |
paul@106 | 32 | |
paul@106 | 33 | ext2_ino_t ino; |
paul@106 | 34 | errcode_t retval = image_find_path(_fs, &path, &ino); |
paul@102 | 35 | |
paul@143 | 36 | // NOTE: Support file creation. |
paul@143 | 37 | |
paul@106 | 38 | if (retval) |
paul@106 | 39 | return FILEID_INVALID; |
paul@106 | 40 | |
paul@106 | 41 | return (fileid_t) ino; |
paul@102 | 42 | } |
paul@102 | 43 | |
paul@102 | 44 | /* Return a new accessor for 'fileid'. */ |
paul@102 | 45 | |
paul@143 | 46 | long Ext2FileOpener::make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor) |
paul@102 | 47 | { |
paul@143 | 48 | (void) path; (void) flags; |
paul@102 | 49 | |
paul@106 | 50 | ext2_file_t file; |
paul@106 | 51 | errcode_t retval = ext2fs_file_open(_fs, (ext2_ino_t) fileid, EXT2_FILE_WRITE, &file); |
paul@106 | 52 | |
paul@143 | 53 | // NOTE: Map error conditions. |
paul@143 | 54 | |
paul@106 | 55 | if (retval) |
paul@143 | 56 | return -L4_EIO; |
paul@106 | 57 | |
paul@143 | 58 | *accessor = new Ext2FileAccessor(file, fileid); |
paul@143 | 59 | return L4_EOK; |
paul@102 | 60 | } |
paul@102 | 61 | |
paul@102 | 62 | // vim: tabstop=4 expandtab shiftwidth=4 |