1 #include "opener_context_resource.h" 2 #include "opener_context_object_server.h" 3 #include "opener_resource.h" 4 #include "resource_server.h" 5 6 #include <string.h> 7 8 9 10 /* Support for providing access to files. */ 11 12 OpenerContextResource::OpenerContextResource(OpenerResource *opener, Memory *memory) 13 : SimplePager(memory), _opener(opener) 14 { 15 } 16 17 int OpenerContextResource::expected_items() 18 { 19 return OpenerContextObject_expected_items; 20 } 21 22 ipc_server_handler_type OpenerContextResource::handler() 23 { 24 return (ipc_server_handler_type) handle_OpenerContextObject; 25 } 26 27 28 29 /* Data access methods. */ 30 31 char *OpenerContextResource::get_path() 32 { 33 char *buffer = _region->read(); 34 offset_t size = _region->size(); 35 36 /* Confine the path to the limit of the buffer. */ 37 38 if ((buffer != NULL) && (strnlen(buffer, size) < size)) 39 return buffer; 40 else 41 return NULL; 42 } 43 44 45 46 /* Opener context interface methods. */ 47 48 long OpenerContextResource::open(flags_t flags, offset_t *size, l4_cap_idx_t *file) 49 { 50 char *path = get_path(); 51 52 if (path == NULL) 53 return -L4_EINVAL; 54 55 Pager *pager = _opener->open(path, flags); 56 57 /* Complete the initialisation and start a server in a new thread. 58 If the thread does not start, the resource should be finalised. */ 59 60 ResourceServer server(pager); 61 long err = server.start_thread(); 62 63 if (!err) 64 { 65 /* Return the file size. */ 66 /* Return the server capability to the caller. */ 67 68 *size = pager->get_data_size(); 69 *file = server.config()->server; 70 } 71 72 return err; 73 } 74 75 // vim: tabstop=4 expandtab shiftwidth=4