paul@196 | 1 | /* |
paul@196 | 2 | * A resource offering support for accessing directories. |
paul@196 | 3 | * |
paul@196 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@196 | 5 | * |
paul@196 | 6 | * This program is free software; you can redistribute it and/or |
paul@196 | 7 | * modify it under the terms of the GNU General Public License as |
paul@196 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@196 | 9 | * the License, or (at your option) any later version. |
paul@196 | 10 | * |
paul@196 | 11 | * This program is distributed in the hope that it will be useful, |
paul@196 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@196 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@196 | 14 | * GNU General Public License for more details. |
paul@196 | 15 | * |
paul@196 | 16 | * You should have received a copy of the GNU General Public License |
paul@196 | 17 | * along with this program; if not, write to the Free Software |
paul@196 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@196 | 19 | * Boston, MA 02110-1301, USA |
paul@196 | 20 | */ |
paul@196 | 21 | |
paul@196 | 22 | #include <ipc/cap_alloc.h> |
paul@196 | 23 | |
paul@196 | 24 | #include "directory_resource.h" |
paul@196 | 25 | #include "directory_object_server.h" |
paul@196 | 26 | |
paul@196 | 27 | |
paul@196 | 28 | |
paul@196 | 29 | int DirectoryResource::expected_items() |
paul@196 | 30 | { |
paul@196 | 31 | return DirectoryObject_expected_items; |
paul@196 | 32 | } |
paul@196 | 33 | |
paul@196 | 34 | ipc_server_handler_type DirectoryResource::handler() |
paul@196 | 35 | { |
paul@196 | 36 | return (ipc_server_handler_type) handle_DirectoryObject; |
paul@196 | 37 | } |
paul@196 | 38 | |
paul@196 | 39 | |
paul@196 | 40 | |
paul@196 | 41 | /* Open a directory to read the directory entries via a file-like object. */ |
paul@196 | 42 | |
paul@196 | 43 | long DirectoryResource::opendir(flags_t flags, offset_t *size, |
paul@196 | 44 | l4_cap_idx_t *file, object_flags_t *object_flags) |
paul@196 | 45 | { |
paul@196 | 46 | /* Invoke the specialised directory opening method. */ |
paul@196 | 47 | |
paul@196 | 48 | long err = _opendir(flags, size, file, object_flags); |
paul@196 | 49 | |
paul@196 | 50 | /* Handle propagated capabilities. By indicating the special status, the |
paul@196 | 51 | operation is first completed and then the capability is discarded. */ |
paul@196 | 52 | |
paul@196 | 53 | if (err == IPC_MESSAGE_SENT) |
paul@196 | 54 | { |
paul@196 | 55 | complete_DirectoryObject_open(*size, *file, *object_flags); |
paul@196 | 56 | ipc_cap_free_um(*file); |
paul@196 | 57 | return IPC_MESSAGE_SENT; |
paul@196 | 58 | } |
paul@196 | 59 | |
paul@196 | 60 | return err; |
paul@196 | 61 | } |
paul@196 | 62 | |
paul@196 | 63 | // vim: tabstop=4 expandtab shiftwidth=4 |