1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef LIB_ZXIO_OPS_H_ 6 #define LIB_ZXIO_OPS_H_ 7 8 #include <lib/zxio/types.h> 9 #include <lib/zxio/zxio.h> 10 #include <stdint.h> 11 #include <zircon/compiler.h> 12 #include <zircon/types.h> 13 14 __BEGIN_CDECLS 15 16 // See zxio.h 17 typedef struct zxio { 18 uint64_t reserved[4]; 19 } zxio_t; 20 21 // Storage for the |zxio_ops_t| implementation. 22 typedef struct zxio_private { 23 uint64_t reserved[6]; 24 } zxio_private_t; 25 26 // The storage backing a |zxio_t|. 27 typedef struct zxio_storage { 28 zxio_t io; 29 zxio_private_t reserved; 30 } zxio_storage_t; 31 32 // A table of operations for a zxio_t. 33 // 34 // Most of the functions that operate on a zxio_t call through this operations 35 // table to actually perform the operation. Use |zxio_alloc| to create a zxio_t 36 // with a custom operations table. 37 typedef struct zxio_ops zxio_ops_t; 38 39 // Initialize a |zxio_t| object with the given |ops| table. 40 void zxio_init(zxio_t* io, const zxio_ops_t* ops); 41 42 struct zxio_ops { 43 // After |release| returns, no further ops will be called relative to |ctx|. 44 zx_status_t (*release)(zxio_t* io, zx_handle_t* out_handle); 45 46 // After |close| returns, no further ops will be called relative to |ctx|. 47 zx_status_t (*close)(zxio_t* io); 48 49 void (*wait_begin)(zxio_t* io, zxio_signals_t zxio_signals, 50 zx_handle_t* out_handle, zx_signals_t* out_zx_signals); 51 void (*wait_end)(zxio_t* io, zx_signals_t zx_signals, 52 zxio_signals_t* out_zxio_signals); 53 zx_status_t (*clone_async)(zxio_t* io, uint32_t flags, zx_handle_t request); 54 zx_status_t (*sync)(zxio_t* io); 55 zx_status_t (*attr_get)(zxio_t* io, zxio_node_attr_t* out_attr); 56 zx_status_t (*attr_set)(zxio_t* io, uint32_t flags, 57 const zxio_node_attr_t* attr); 58 zx_status_t (*read)(zxio_t* io, void* buffer, size_t capacity, 59 size_t* out_actual); 60 zx_status_t (*read_at)(zxio_t* io, size_t offset, void* buffer, 61 size_t capacity, size_t* out_actual); 62 zx_status_t (*write)(zxio_t* io, const void* buffer, size_t capacity, 63 size_t* out_actual); 64 zx_status_t (*write_at)(zxio_t* io, size_t offset, const void* buffer, 65 size_t capacity, size_t* out_actual); 66 zx_status_t (*seek)(zxio_t* io, size_t offset, zxio_seek_origin_t start, 67 size_t* out_offset); 68 zx_status_t (*truncate)(zxio_t* io, size_t length); 69 zx_status_t (*flags_get)(zxio_t* io, uint32_t* out_flags); 70 zx_status_t (*flags_set)(zxio_t* io, uint32_t flags); 71 zx_status_t (*vmo_get)(zxio_t* io, uint32_t flags, zx_handle_t* out_vmo, 72 size_t* out_size); 73 zx_status_t (*open)(zxio_t* io, uint32_t flags, uint32_t mode, 74 const char* path, zxio_t** out_io); 75 zx_status_t (*open_async)(zxio_t* io, uint32_t flags, uint32_t mode, 76 const char* path, zx_handle_t request); 77 zx_status_t (*unlink)(zxio_t* io, const char* path); 78 zx_status_t (*token_get)(zxio_t* io, zx_handle_t* out_token); 79 zx_status_t (*rename)(zxio_t* io, const char* src_path, 80 zx_handle_t dst_token, const char* dst_path); 81 zx_status_t (*link)(zxio_t* io, const char* src_path, zx_handle_t dst_token, 82 const char* dst_path); 83 zx_status_t (*readdir)(zxio_t* io, void* buffer, size_t capacity, 84 size_t* out_actual); 85 zx_status_t (*rewind)(zxio_t* io); 86 }; 87 88 __END_CDECLS 89 90 #endif // LIB_ZXIO_OPS_H_ 91