1 /* SPDX-License-Identifier: MIT */ 2 /****************************************************************************** 3 * fsif.h 4 * 5 * Interface to FS level split device drivers. 6 * 7 * Copyright (c) 2007, Grzegorz Milos, <gm281@cam.ac.uk>. 8 */ 9 10 #ifndef __XEN_PUBLIC_IO_FSIF_H__ 11 #define __XEN_PUBLIC_IO_FSIF_H__ 12 13 #include "ring.h" 14 #include "../grant_table.h" 15 16 #define REQ_FILE_OPEN 1 17 #define REQ_FILE_CLOSE 2 18 #define REQ_FILE_READ 3 19 #define REQ_FILE_WRITE 4 20 #define REQ_STAT 5 21 #define REQ_FILE_TRUNCATE 6 22 #define REQ_REMOVE 7 23 #define REQ_RENAME 8 24 #define REQ_CREATE 9 25 #define REQ_DIR_LIST 10 26 #define REQ_CHMOD 11 27 #define REQ_FS_SPACE 12 28 #define REQ_FILE_SYNC 13 29 30 struct fsif_open_request { 31 grant_ref_t gref; 32 }; 33 34 struct fsif_close_request { 35 uint32_t fd; 36 }; 37 38 struct fsif_read_request { 39 uint32_t fd; 40 int32_t pad; 41 uint64_t len; 42 uint64_t offset; 43 grant_ref_t grefs[XENPV_FLEX_ARRAY_DIM]; 44 }; 45 46 struct fsif_write_request { 47 uint32_t fd; 48 int32_t pad; 49 uint64_t len; 50 uint64_t offset; 51 grant_ref_t grefs[XENPV_FLEX_ARRAY_DIM]; 52 }; 53 54 struct fsif_stat_request { 55 uint32_t fd; 56 }; 57 58 /* This structure is a copy of some fields from stat structure, returned 59 * via the ring. */ 60 struct fsif_stat_response { 61 int32_t stat_mode; 62 uint32_t stat_uid; 63 uint32_t stat_gid; 64 int32_t stat_ret; 65 int64_t stat_size; 66 int64_t stat_atime; 67 int64_t stat_mtime; 68 int64_t stat_ctime; 69 }; 70 71 struct fsif_truncate_request { 72 uint32_t fd; 73 int32_t pad; 74 int64_t length; 75 }; 76 77 struct fsif_remove_request { 78 grant_ref_t gref; 79 }; 80 81 struct fsif_rename_request { 82 uint16_t old_name_offset; 83 uint16_t new_name_offset; 84 grant_ref_t gref; 85 }; 86 87 struct fsif_create_request { 88 int8_t directory; 89 int8_t pad; 90 int16_t pad2; 91 int32_t mode; 92 grant_ref_t gref; 93 }; 94 95 struct fsif_list_request { 96 uint32_t offset; 97 grant_ref_t gref; 98 }; 99 100 #define NR_FILES_SHIFT 0 101 #define NR_FILES_SIZE 16 /* 16 bits for the number of files mask */ 102 #define NR_FILES_MASK (((1ULL << NR_FILES_SIZE) - 1) << NR_FILES_SHIFT) 103 #define ERROR_SIZE 32 /* 32 bits for the error mask */ 104 #define ERROR_SHIFT (NR_FILES_SIZE + NR_FILES_SHIFT) 105 #define ERROR_MASK (((1ULL << ERROR_SIZE) - 1) << ERROR_SHIFT) 106 #define HAS_MORE_SHIFT (ERROR_SHIFT + ERROR_SIZE) 107 #define HAS_MORE_FLAG (1ULL << HAS_MORE_SHIFT) 108 109 struct fsif_chmod_request { 110 uint32_t fd; 111 int32_t mode; 112 }; 113 114 struct fsif_space_request { 115 grant_ref_t gref; 116 }; 117 118 struct fsif_sync_request { 119 uint32_t fd; 120 }; 121 122 123 /* FS operation request */ 124 struct fsif_request { 125 uint8_t type; /* Type of the request */ 126 uint8_t pad; 127 uint16_t id; /* Request ID, copied to the response */ 128 uint32_t pad2; 129 union { 130 struct fsif_open_request fopen; 131 struct fsif_close_request fclose; 132 struct fsif_read_request fread; 133 struct fsif_write_request fwrite; 134 struct fsif_stat_request fstat; 135 struct fsif_truncate_request ftruncate; 136 struct fsif_remove_request fremove; 137 struct fsif_rename_request frename; 138 struct fsif_create_request fcreate; 139 struct fsif_list_request flist; 140 struct fsif_chmod_request fchmod; 141 struct fsif_space_request fspace; 142 struct fsif_sync_request fsync; 143 } u; 144 }; 145 typedef struct fsif_request fsif_request_t; 146 147 /* FS operation response */ 148 struct fsif_response { 149 uint16_t id; 150 uint16_t pad1; 151 uint32_t pad2; 152 union { 153 uint64_t ret_val; 154 struct fsif_stat_response fstat; 155 } u; 156 }; 157 158 typedef struct fsif_response fsif_response_t; 159 160 #define FSIF_RING_ENTRY_SIZE 64 161 162 #define FSIF_NR_READ_GNTS ((FSIF_RING_ENTRY_SIZE - sizeof(struct fsif_read_request)) / \ 163 sizeof(grant_ref_t) + 1) 164 #define FSIF_NR_WRITE_GNTS ((FSIF_RING_ENTRY_SIZE - sizeof(struct fsif_write_request)) / \ 165 sizeof(grant_ref_t) + 1) 166 167 DEFINE_RING_TYPES(fsif, struct fsif_request, struct fsif_response); 168 169 #define STATE_INITIALISED "init" 170 #define STATE_READY "ready" 171 #define STATE_CLOSING "closing" 172 #define STATE_CLOSED "closed" 173 174 175 #endif 176