1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 23 * Copyright 2020 Nexenta by DDN, Inc. All rights reserved. 24 * Copyright 2021 RackTop Systems, Inc. 25 */ 26 27 /* 28 * Structures and type definitions needed by the "testoplock" program 29 * (a small subset of what the SMB server uses) 30 */ 31 32 #ifndef _SMB_KTYPES_H 33 #define _SMB_KTYPES_H 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #include <sys/types.h> 40 #include <sys/debug.h> 41 #include <sys/systm.h> 42 #include <sys/cred.h> 43 #include <sys/list.h> 44 #include <sys/sdt.h> 45 46 typedef struct smb_session smb_session_t; 47 typedef struct smb_user smb_user_t; 48 typedef struct smb_tree smb_tree_t; 49 50 51 /* 52 * Destructor object used in the locked-list delete queue. 53 */ 54 #define SMB_DTOR_MAGIC 0x44544F52 /* DTOR */ 55 #define SMB_DTOR_VALID(d) \ 56 ASSERT(((d) != NULL) && ((d)->dt_magic == SMB_DTOR_MAGIC)) 57 58 typedef void (*smb_dtorproc_t)(void *); 59 60 typedef struct smb_dtor { 61 list_node_t dt_lnd; 62 uint32_t dt_magic; 63 void *dt_object; 64 smb_dtorproc_t dt_proc; 65 } smb_dtor_t; 66 67 typedef struct smb_llist { 68 krwlock_t ll_lock; 69 list_t ll_list; 70 uint32_t ll_count; 71 uint64_t ll_wrop; 72 kmutex_t ll_mutex; 73 list_t ll_deleteq; 74 uint32_t ll_deleteq_count; 75 boolean_t ll_flushing; 76 } smb_llist_t; 77 78 /* 79 * Per smb_node oplock state 80 */ 81 typedef struct smb_oplock { 82 kmutex_t ol_mutex; 83 boolean_t ol_fem; /* fem monitor installed? */ 84 struct smb_ofile *excl_open; 85 uint32_t ol_state; 86 int32_t cnt_II; 87 int32_t cnt_R; 88 int32_t cnt_RH; 89 int32_t cnt_RHBQ; 90 int32_t waiters; 91 kcondvar_t WaitingOpenCV; 92 } smb_oplock_t; 93 94 /* 95 * Per smb_ofile oplock state 96 */ 97 typedef struct smb_oplock_grant { 98 /* smb protocol-level state */ 99 uint32_t og_state; /* latest sent to client */ 100 uint32_t og_breaking; /* BREAK_TO... flags */ 101 uint16_t og_dialect; /* how to send breaks */ 102 /* File-system level state */ 103 uint8_t onlist_II; 104 uint8_t onlist_R; 105 uint8_t onlist_RH; 106 uint8_t onlist_RHBQ; 107 uint8_t BreakingToRead; 108 } smb_oplock_grant_t; 109 110 #define SMB_LEASE_KEY_SZ 16 111 112 #define SMB_NODE_MAGIC 0x4E4F4445 /* 'NODE' */ 113 #define SMB_NODE_VALID(p) ASSERT((p)->n_magic == SMB_NODE_MAGIC) 114 115 typedef enum { 116 SMB_NODE_STATE_AVAILABLE = 0, 117 SMB_NODE_STATE_DESTROYING 118 } smb_node_state_t; 119 120 /* 121 * waiting_event # of clients requesting FCN 122 * n_timestamps cached timestamps 123 * n_allocsz cached file allocation size 124 * n_dnode directory node 125 * n_unode unnamed stream node 126 * delete_on_close_cred credentials for delayed delete 127 */ 128 typedef struct smb_node { 129 list_node_t n_lnd; 130 uint32_t n_magic; 131 krwlock_t n_lock; 132 kmutex_t n_mutex; 133 smb_node_state_t n_state; 134 uint32_t n_refcnt; 135 uint32_t n_open_count; 136 volatile int flags; 137 138 smb_llist_t n_ofile_list; 139 smb_oplock_t n_oplock; 140 } smb_node_t; 141 142 #define NODE_FLAGS_WRITE_THROUGH 0x00100000 143 #define NODE_FLAGS_DELETE_COMMITTED 0x20000000 144 #define NODE_FLAGS_DELETE_ON_CLOSE 0x40000000 145 146 /* 147 * Some flags for ofile structure 148 * 149 * SMB_OFLAGS_SET_DELETE_ON_CLOSE 150 * Set this flag when the corresponding open operation whose 151 * DELETE_ON_CLOSE bit of the CreateOptions is set. If any 152 * open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE 153 * will be set for the file node upon close. 154 */ 155 156 /* SMB_OFLAGS_READONLY 0x0001 (obsolete) */ 157 #define SMB_OFLAGS_EXECONLY 0x0002 158 #define SMB_OFLAGS_SET_DELETE_ON_CLOSE 0x0004 159 #define SMB_OFLAGS_LLF_POS_VALID 0x0008 160 161 #define SMB_OFILE_MAGIC 0x4F464C45 /* 'OFLE' */ 162 #define SMB_OFILE_VALID(p) \ 163 ASSERT((p != NULL) && ((p)->f_magic == SMB_OFILE_MAGIC)) 164 165 /* 166 * This is the size of the per-handle "Lock Sequence" array. 167 * See LockSequenceIndex in [MS-SMB2] 2.2.26, and smb2_lock.c 168 */ 169 #define SMB_OFILE_LSEQ_MAX 64 170 171 /* {arg_open,ofile}->dh_vers values */ 172 typedef enum { 173 SMB2_NOT_DURABLE = 0, 174 SMB2_DURABLE_V1, 175 SMB2_DURABLE_V2, 176 SMB2_RESILIENT, 177 } smb_dh_vers_t; 178 179 /* 180 * See the long "Ofile State Machine" comment in smb_ofile.c 181 */ 182 typedef enum { 183 SMB_OFILE_STATE_ALLOC = 0, 184 SMB_OFILE_STATE_OPEN, 185 SMB_OFILE_STATE_SAVE_DH, 186 SMB_OFILE_STATE_SAVING, 187 SMB_OFILE_STATE_CLOSING, 188 SMB_OFILE_STATE_CLOSED, 189 SMB_OFILE_STATE_ORPHANED, 190 SMB_OFILE_STATE_RECONNECT, 191 SMB_OFILE_STATE_EXPIRED, 192 SMB_OFILE_STATE_SENTINEL 193 } smb_ofile_state_t; 194 195 typedef struct smb_ofile { 196 list_node_t f_tree_lnd; /* t_ofile_list */ 197 list_node_t f_node_lnd; /* n_ofile_list */ 198 list_node_t f_dh_lnd; /* sv_persistid_ht */ 199 uint32_t f_magic; 200 kmutex_t f_mutex; 201 smb_ofile_state_t f_state; 202 203 uint16_t f_fid; 204 uint16_t f_ftype; 205 uint32_t f_refcnt; 206 uint32_t f_granted_access; 207 uint32_t f_share_access; 208 209 smb_node_t *f_node; 210 211 smb_oplock_grant_t f_oplock; 212 boolean_t f_oplock_closing; 213 uint8_t TargetOplockKey[SMB_LEASE_KEY_SZ]; 214 uint8_t ParentOplockKey[SMB_LEASE_KEY_SZ]; 215 struct smb_lease *f_lease; 216 217 } smb_ofile_t; 218 219 typedef struct smb_request { 220 list_node_t sr_session_lnd; 221 uint32_t sr_magic; 222 kmutex_t sr_mutex; 223 } smb_request_t; 224 225 #ifdef __cplusplus 226 } 227 #endif 228 229 #endif /* _SMB_KTYPES_H */ 230