L4Re/departure

libfsserver/lib/files/opener_resource.cc

202:85396ddb3260
2021-09-20 Paul Boddie Introduced directory resource, provider and accessor objects. The opendir operation has been moved from the opener to the directory resource, and the opener resource and file paging coordinator now support the creation of directory-related objects.
     1 /*     2  * A resource offering support for creating contexts and opening files.     3  *     4  * Copyright (C) 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 "opener_server.h"    23 #include "opener_resource.h"    24 #include "resource_server.h"    25     26 /* Support for providing access to files. */    27     28 OpenerResource::OpenerResource(FilePaging *paging)    29 : _paging(paging)    30 {    31 }    32     33 OpenerResource::~OpenerResource()    34 {    35 }    36     37 int OpenerResource::expected_items()    38 {    39     return Opener_expected_items;    40 }    41     42 ipc_server_handler_type OpenerResource::handler()    43 {    44     return (ipc_server_handler_type) handle_Opener;    45 }    46     47     48     49 /* Return a pager object for the given path and flags. */    50     51 long OpenerResource::open(const char *path, flags_t flags, offset_t *size,    52                           l4_cap_idx_t *cap, object_flags_t *object_flags)    53 {    54     /* Obtain an identifier for the file, even for new files. */    55     56     fileid_t fileid;    57     long err = get_fileid(path, flags, &fileid);    58     59     if (err)    60         return err;    61     62     /* Test for file and directory access. */    63     64     if (accessing_directory(path, flags, fileid))    65         return get_directory(path, flags, fileid, size, cap, object_flags);    66     else if (accessing_file(path, flags, fileid))    67         return get_file(path, flags, fileid, size, cap, object_flags);    68     else    69         return -L4_EIO;    70 }    71     72     73     74 /* Return a directory object reference for the given file identifier. */    75     76 long OpenerResource::get_directory(const char *path, flags_t flags,    77                                    fileid_t fileid, offset_t *size,    78                                    l4_cap_idx_t *cap,    79                                    object_flags_t *object_flags)    80 {    81     Resource *directory;    82     long err = _paging->get_directory(this, path, flags, fileid, &directory);    83     84     if (err)    85         return err;    86     87     /* Provide non-file values for certain outputs. */    88     89     *size = 0;    90     *object_flags = 0;    91     92     return ResourceServer(directory).start_thread(cap);    93 }    94     95 /* Return a file pager. */    96     97 long OpenerResource::get_file(const char *path, flags_t flags, fileid_t fileid,    98                               offset_t *size, l4_cap_idx_t *cap,    99                               object_flags_t *object_flags)   100 {   101     Pager *pager;   102     long err = _paging->get_pager(this, path, flags, fileid, &pager);   103    104     if (err)   105         return err;   106    107     /* Obtain the size details from the pager, also providing appropriate   108        flags. */   109    110     *size = pager->get_data_size();   111     *object_flags = OBJECT_SUPPORTS_MMAP | OBJECT_HAS_SIZE;   112    113     return ResourceServer(pager).start_thread(cap);   114 }   115    116    117    118 /* Opener interface methods. */   119    120 long OpenerResource::context(l4_cap_idx_t *context)   121 {   122     OpenerContextResource *resource = new OpenerContextResource(this);   123    124     /* Complete the initialisation and start a server in a new thread.   125        If the thread does not start, the resource will be finalised. */   126    127     return ResourceServer(resource).start_thread(context);   128 }   129    130 // vim: tabstop=4 expandtab shiftwidth=4