Thomas Gleixner | b6a3d1b | 2019-06-03 07:44:47 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 2 | /* |
| 3 | * SMB1 (CIFS) version specific operations |
| 4 | * |
| 5 | * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com> |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 6 | */ |
| 7 | |
Pavel Shilovsky | 24985c5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 8 | #include <linux/pagemap.h> |
Pavel Shilovsky | 76ec5e3 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 9 | #include <linux/vfs.h> |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 10 | #include "cifsglob.h" |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 11 | #include "cifsproto.h" |
| 12 | #include "cifs_debug.h" |
Pavel Shilovsky | 106dc53 | 2012-02-28 14:23:34 +0300 | [diff] [blame] | 13 | #include "cifspdu.h" |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 14 | #include "cifs_unicode.h" |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 15 | |
| 16 | /* |
| 17 | * An NT cancel request header looks just like the original request except: |
| 18 | * |
| 19 | * The Command is SMB_COM_NT_CANCEL |
| 20 | * The WordCount is zeroed out |
| 21 | * The ByteCount is zeroed out |
| 22 | * |
| 23 | * This function mangles an existing request buffer into a |
| 24 | * SMB_COM_NT_CANCEL request and then sends it. |
| 25 | */ |
| 26 | static int |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 27 | send_nt_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst, |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 28 | struct mid_q_entry *mid) |
| 29 | { |
| 30 | int rc = 0; |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 31 | struct smb_hdr *in_buf = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 32 | |
| 33 | /* -4 for RFC1001 length and +2 for BCC field */ |
| 34 | in_buf->smb_buf_length = cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2); |
| 35 | in_buf->Command = SMB_COM_NT_CANCEL; |
| 36 | in_buf->WordCount = 0; |
| 37 | put_bcc(0, in_buf); |
| 38 | |
| 39 | mutex_lock(&server->srv_mutex); |
| 40 | rc = cifs_sign_smb(in_buf, server, &mid->sequence_number); |
| 41 | if (rc) { |
| 42 | mutex_unlock(&server->srv_mutex); |
| 43 | return rc; |
| 44 | } |
Jeff Layton | 31efee6 | 2012-12-27 08:05:03 -0500 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * The response to this call was already factored into the sequence |
| 48 | * number when the call went out, so we must adjust it back downward |
| 49 | * after signing here. |
| 50 | */ |
| 51 | --server->sequence_number; |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 52 | rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length)); |
Jeff Layton | ad313cb | 2013-04-03 10:27:36 -0400 | [diff] [blame] | 53 | if (rc < 0) |
| 54 | server->sequence_number--; |
| 55 | |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 56 | mutex_unlock(&server->srv_mutex); |
| 57 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 58 | cifs_dbg(FYI, "issued NT_CANCEL for mid %u, rc = %d\n", |
Tim Gardner | 3d378d3 | 2013-11-02 12:50:34 -0500 | [diff] [blame] | 59 | get_mid(in_buf), rc); |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 60 | |
| 61 | return rc; |
| 62 | } |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 63 | |
Pavel Shilovsky | 55157df | 2012-02-28 14:04:17 +0300 | [diff] [blame] | 64 | static bool |
| 65 | cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
| 66 | { |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 67 | return ob1->fid.netfid == ob2->fid.netfid; |
Pavel Shilovsky | 55157df | 2012-02-28 14:04:17 +0300 | [diff] [blame] | 68 | } |
| 69 | |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 70 | static unsigned int |
| 71 | cifs_read_data_offset(char *buf) |
| 72 | { |
| 73 | READ_RSP *rsp = (READ_RSP *)buf; |
| 74 | return le16_to_cpu(rsp->DataOffset); |
| 75 | } |
| 76 | |
| 77 | static unsigned int |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 78 | cifs_read_data_length(char *buf, bool in_remaining) |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 79 | { |
| 80 | READ_RSP *rsp = (READ_RSP *)buf; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 81 | /* It's a bug reading remaining data for SMB1 packets */ |
| 82 | WARN_ON(in_remaining); |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 83 | return (le16_to_cpu(rsp->DataLengthHigh) << 16) + |
| 84 | le16_to_cpu(rsp->DataLength); |
| 85 | } |
| 86 | |
Pavel Shilovsky | 8aa26f3 | 2012-05-17 13:25:35 +0400 | [diff] [blame] | 87 | static struct mid_q_entry * |
| 88 | cifs_find_mid(struct TCP_Server_Info *server, char *buffer) |
| 89 | { |
| 90 | struct smb_hdr *buf = (struct smb_hdr *)buffer; |
| 91 | struct mid_q_entry *mid; |
| 92 | |
| 93 | spin_lock(&GlobalMid_Lock); |
| 94 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { |
Tim Gardner | 3d378d3 | 2013-11-02 12:50:34 -0500 | [diff] [blame] | 95 | if (compare_mid(mid->mid, buf) && |
Pavel Shilovsky | 8aa26f3 | 2012-05-17 13:25:35 +0400 | [diff] [blame] | 96 | mid->mid_state == MID_REQUEST_SUBMITTED && |
| 97 | le16_to_cpu(mid->command) == buf->Command) { |
Lars Persson | 696e420 | 2018-06-25 14:05:25 +0200 | [diff] [blame] | 98 | kref_get(&mid->refcount); |
Pavel Shilovsky | 8aa26f3 | 2012-05-17 13:25:35 +0400 | [diff] [blame] | 99 | spin_unlock(&GlobalMid_Lock); |
| 100 | return mid; |
| 101 | } |
| 102 | } |
| 103 | spin_unlock(&GlobalMid_Lock); |
| 104 | return NULL; |
| 105 | } |
| 106 | |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 107 | static void |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 108 | cifs_add_credits(struct TCP_Server_Info *server, |
| 109 | const struct cifs_credits *credits, const int optype) |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 110 | { |
| 111 | spin_lock(&server->req_lock); |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 112 | server->credits += credits->value; |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 113 | server->in_flight--; |
| 114 | spin_unlock(&server->req_lock); |
| 115 | wake_up(&server->request_q); |
| 116 | } |
| 117 | |
| 118 | static void |
| 119 | cifs_set_credits(struct TCP_Server_Info *server, const int val) |
| 120 | { |
| 121 | spin_lock(&server->req_lock); |
| 122 | server->credits = val; |
| 123 | server->oplocks = val > 1 ? enable_oplocks : false; |
| 124 | spin_unlock(&server->req_lock); |
| 125 | } |
| 126 | |
| 127 | static int * |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 128 | cifs_get_credits_field(struct TCP_Server_Info *server, const int optype) |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 129 | { |
| 130 | return &server->credits; |
| 131 | } |
| 132 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 133 | static unsigned int |
| 134 | cifs_get_credits(struct mid_q_entry *mid) |
| 135 | { |
| 136 | return 1; |
| 137 | } |
| 138 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 139 | /* |
| 140 | * Find a free multiplex id (SMB mid). Otherwise there could be |
| 141 | * mid collisions which might cause problems, demultiplexing the |
| 142 | * wrong response to this request. Multiplex ids could collide if |
| 143 | * one of a series requests takes much longer than the others, or |
| 144 | * if a very large number of long lived requests (byte range |
| 145 | * locks or FindNotify requests) are pending. No more than |
| 146 | * 64K-1 requests can be outstanding at one time. If no |
| 147 | * mids are available, return zero. A future optimization |
| 148 | * could make the combination of mids and uid the key we use |
| 149 | * to demultiplex on (rather than mid alone). |
| 150 | * In addition to the above check, the cifs demultiplex |
| 151 | * code already used the command code as a secondary |
| 152 | * check of the frame and if signing is negotiated the |
| 153 | * response would be discarded if the mid were the same |
| 154 | * but the signature was wrong. Since the mid is not put in the |
| 155 | * pending queue until later (when it is about to be dispatched) |
| 156 | * we do have to limit the number of outstanding requests |
| 157 | * to somewhat less than 64K-1 although it is hard to imagine |
| 158 | * so many threads being in the vfs at one time. |
| 159 | */ |
| 160 | static __u64 |
| 161 | cifs_get_next_mid(struct TCP_Server_Info *server) |
| 162 | { |
| 163 | __u64 mid = 0; |
| 164 | __u16 last_mid, cur_mid; |
| 165 | bool collision; |
| 166 | |
| 167 | spin_lock(&GlobalMid_Lock); |
| 168 | |
| 169 | /* mid is 16 bit only for CIFS/SMB */ |
| 170 | cur_mid = (__u16)((server->CurrentMid) & 0xffff); |
| 171 | /* we do not want to loop forever */ |
| 172 | last_mid = cur_mid; |
| 173 | cur_mid++; |
| 174 | |
| 175 | /* |
| 176 | * This nested loop looks more expensive than it is. |
| 177 | * In practice the list of pending requests is short, |
| 178 | * fewer than 50, and the mids are likely to be unique |
| 179 | * on the first pass through the loop unless some request |
| 180 | * takes longer than the 64 thousand requests before it |
| 181 | * (and it would also have to have been a request that |
| 182 | * did not time out). |
| 183 | */ |
| 184 | while (cur_mid != last_mid) { |
| 185 | struct mid_q_entry *mid_entry; |
| 186 | unsigned int num_mids; |
| 187 | |
| 188 | collision = false; |
| 189 | if (cur_mid == 0) |
| 190 | cur_mid++; |
| 191 | |
| 192 | num_mids = 0; |
| 193 | list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) { |
| 194 | ++num_mids; |
| 195 | if (mid_entry->mid == cur_mid && |
| 196 | mid_entry->mid_state == MID_REQUEST_SUBMITTED) { |
| 197 | /* This mid is in use, try a different one */ |
| 198 | collision = true; |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * if we have more than 32k mids in the list, then something |
| 205 | * is very wrong. Possibly a local user is trying to DoS the |
| 206 | * box by issuing long-running calls and SIGKILL'ing them. If |
| 207 | * we get to 2^16 mids then we're in big trouble as this |
| 208 | * function could loop forever. |
| 209 | * |
| 210 | * Go ahead and assign out the mid in this situation, but force |
| 211 | * an eventual reconnect to clean out the pending_mid_q. |
| 212 | */ |
| 213 | if (num_mids > 32768) |
| 214 | server->tcpStatus = CifsNeedReconnect; |
| 215 | |
| 216 | if (!collision) { |
| 217 | mid = (__u64)cur_mid; |
| 218 | server->CurrentMid = mid; |
| 219 | break; |
| 220 | } |
| 221 | cur_mid++; |
| 222 | } |
| 223 | spin_unlock(&GlobalMid_Lock); |
| 224 | return mid; |
| 225 | } |
| 226 | |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 227 | /* |
| 228 | return codes: |
| 229 | 0 not a transact2, or all data present |
| 230 | >0 transact2 with that much data missing |
| 231 | -EINVAL invalid transact2 |
| 232 | */ |
| 233 | static int |
| 234 | check2ndT2(char *buf) |
| 235 | { |
| 236 | struct smb_hdr *pSMB = (struct smb_hdr *)buf; |
| 237 | struct smb_t2_rsp *pSMBt; |
| 238 | int remaining; |
| 239 | __u16 total_data_size, data_in_this_rsp; |
| 240 | |
| 241 | if (pSMB->Command != SMB_COM_TRANSACTION2) |
| 242 | return 0; |
| 243 | |
| 244 | /* check for plausible wct, bcc and t2 data and parm sizes */ |
| 245 | /* check for parm and data offset going beyond end of smb */ |
| 246 | if (pSMB->WordCount != 10) { /* coalesce_t2 depends on this */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 247 | cifs_dbg(FYI, "invalid transact2 word count\n"); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 248 | return -EINVAL; |
| 249 | } |
| 250 | |
| 251 | pSMBt = (struct smb_t2_rsp *)pSMB; |
| 252 | |
| 253 | total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount); |
| 254 | data_in_this_rsp = get_unaligned_le16(&pSMBt->t2_rsp.DataCount); |
| 255 | |
| 256 | if (total_data_size == data_in_this_rsp) |
| 257 | return 0; |
| 258 | else if (total_data_size < data_in_this_rsp) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 259 | cifs_dbg(FYI, "total data %d smaller than data in frame %d\n", |
| 260 | total_data_size, data_in_this_rsp); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 261 | return -EINVAL; |
| 262 | } |
| 263 | |
| 264 | remaining = total_data_size - data_in_this_rsp; |
| 265 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 266 | cifs_dbg(FYI, "missing %d bytes from transact2, check next response\n", |
| 267 | remaining); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 268 | if (total_data_size > CIFSMaxBufSize) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 269 | cifs_dbg(VFS, "TotalDataSize %d is over maximum buffer %d\n", |
| 270 | total_data_size, CIFSMaxBufSize); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 271 | return -EINVAL; |
| 272 | } |
| 273 | return remaining; |
| 274 | } |
| 275 | |
| 276 | static int |
| 277 | coalesce_t2(char *second_buf, struct smb_hdr *target_hdr) |
| 278 | { |
| 279 | struct smb_t2_rsp *pSMBs = (struct smb_t2_rsp *)second_buf; |
| 280 | struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)target_hdr; |
| 281 | char *data_area_of_tgt; |
| 282 | char *data_area_of_src; |
| 283 | int remaining; |
| 284 | unsigned int byte_count, total_in_tgt; |
| 285 | __u16 tgt_total_cnt, src_total_cnt, total_in_src; |
| 286 | |
| 287 | src_total_cnt = get_unaligned_le16(&pSMBs->t2_rsp.TotalDataCount); |
| 288 | tgt_total_cnt = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount); |
| 289 | |
| 290 | if (tgt_total_cnt != src_total_cnt) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 291 | cifs_dbg(FYI, "total data count of primary and secondary t2 differ source=%hu target=%hu\n", |
| 292 | src_total_cnt, tgt_total_cnt); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 293 | |
| 294 | total_in_tgt = get_unaligned_le16(&pSMBt->t2_rsp.DataCount); |
| 295 | |
| 296 | remaining = tgt_total_cnt - total_in_tgt; |
| 297 | |
| 298 | if (remaining < 0) { |
Louis Taylor | 259594b | 2019-02-27 22:25:15 +0000 | [diff] [blame] | 299 | cifs_dbg(FYI, "Server sent too much data. tgt_total_cnt=%hu total_in_tgt=%u\n", |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 300 | tgt_total_cnt, total_in_tgt); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 301 | return -EPROTO; |
| 302 | } |
| 303 | |
| 304 | if (remaining == 0) { |
| 305 | /* nothing to do, ignore */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 306 | cifs_dbg(FYI, "no more data remains\n"); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | total_in_src = get_unaligned_le16(&pSMBs->t2_rsp.DataCount); |
| 311 | if (remaining < total_in_src) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 312 | cifs_dbg(FYI, "transact2 2nd response contains too much data\n"); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 313 | |
| 314 | /* find end of first SMB data area */ |
| 315 | data_area_of_tgt = (char *)&pSMBt->hdr.Protocol + |
| 316 | get_unaligned_le16(&pSMBt->t2_rsp.DataOffset); |
| 317 | |
| 318 | /* validate target area */ |
| 319 | data_area_of_src = (char *)&pSMBs->hdr.Protocol + |
| 320 | get_unaligned_le16(&pSMBs->t2_rsp.DataOffset); |
| 321 | |
| 322 | data_area_of_tgt += total_in_tgt; |
| 323 | |
| 324 | total_in_tgt += total_in_src; |
| 325 | /* is the result too big for the field? */ |
| 326 | if (total_in_tgt > USHRT_MAX) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 327 | cifs_dbg(FYI, "coalesced DataCount too large (%u)\n", |
| 328 | total_in_tgt); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 329 | return -EPROTO; |
| 330 | } |
| 331 | put_unaligned_le16(total_in_tgt, &pSMBt->t2_rsp.DataCount); |
| 332 | |
| 333 | /* fix up the BCC */ |
| 334 | byte_count = get_bcc(target_hdr); |
| 335 | byte_count += total_in_src; |
| 336 | /* is the result too big for the field? */ |
| 337 | if (byte_count > USHRT_MAX) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 338 | cifs_dbg(FYI, "coalesced BCC too large (%u)\n", byte_count); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 339 | return -EPROTO; |
| 340 | } |
| 341 | put_bcc(byte_count, target_hdr); |
| 342 | |
| 343 | byte_count = be32_to_cpu(target_hdr->smb_buf_length); |
| 344 | byte_count += total_in_src; |
| 345 | /* don't allow buffer to overflow */ |
| 346 | if (byte_count > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 347 | cifs_dbg(FYI, "coalesced BCC exceeds buffer size (%u)\n", |
| 348 | byte_count); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 349 | return -ENOBUFS; |
| 350 | } |
| 351 | target_hdr->smb_buf_length = cpu_to_be32(byte_count); |
| 352 | |
| 353 | /* copy second buffer into end of first buffer */ |
| 354 | memcpy(data_area_of_tgt, data_area_of_src, total_in_src); |
| 355 | |
| 356 | if (remaining != total_in_src) { |
| 357 | /* more responses to go */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 358 | cifs_dbg(FYI, "waiting for more secondary responses\n"); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 359 | return 1; |
| 360 | } |
| 361 | |
| 362 | /* we are done */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 363 | cifs_dbg(FYI, "found the last secondary response\n"); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 367 | static void |
| 368 | cifs_downgrade_oplock(struct TCP_Server_Info *server, |
| 369 | struct cifsInodeInfo *cinode, bool set_level2) |
| 370 | { |
| 371 | if (set_level2) |
| 372 | cifs_set_oplock_level(cinode, OPLOCK_READ); |
| 373 | else |
| 374 | cifs_set_oplock_level(cinode, 0); |
| 375 | } |
| 376 | |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 377 | static bool |
| 378 | cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server, |
| 379 | char *buf, int malformed) |
| 380 | { |
| 381 | if (malformed) |
| 382 | return false; |
| 383 | if (check2ndT2(buf) <= 0) |
| 384 | return false; |
| 385 | mid->multiRsp = true; |
| 386 | if (mid->resp_buf) { |
| 387 | /* merge response - fix up 1st*/ |
| 388 | malformed = coalesce_t2(buf, mid->resp_buf); |
| 389 | if (malformed > 0) |
| 390 | return true; |
| 391 | /* All parts received or packet is malformed. */ |
| 392 | mid->multiEnd = true; |
| 393 | dequeue_mid(mid, malformed); |
| 394 | return true; |
| 395 | } |
| 396 | if (!server->large_buf) { |
| 397 | /*FIXME: switch to already allocated largebuf?*/ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 398 | cifs_dbg(VFS, "1st trans2 resp needs bigbuf\n"); |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 399 | } else { |
| 400 | /* Have first buffer */ |
| 401 | mid->resp_buf = buf; |
| 402 | mid->large_buf = true; |
| 403 | server->bigbuf = NULL; |
| 404 | } |
| 405 | return true; |
| 406 | } |
| 407 | |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 408 | static bool |
| 409 | cifs_need_neg(struct TCP_Server_Info *server) |
| 410 | { |
| 411 | return server->maxBuf == 0; |
| 412 | } |
| 413 | |
| 414 | static int |
| 415 | cifs_negotiate(const unsigned int xid, struct cifs_ses *ses) |
| 416 | { |
| 417 | int rc; |
| 418 | rc = CIFSSMBNegotiate(xid, ses); |
| 419 | if (rc == -EAGAIN) { |
| 420 | /* retry only once on 1st time connection */ |
| 421 | set_credits(ses->server, 1); |
| 422 | rc = CIFSSMBNegotiate(xid, ses); |
| 423 | if (rc == -EAGAIN) |
| 424 | rc = -EHOSTDOWN; |
| 425 | } |
| 426 | return rc; |
| 427 | } |
| 428 | |
Pavel Shilovsky | 24985c5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 429 | static unsigned int |
| 430 | cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 431 | { |
| 432 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); |
| 433 | struct TCP_Server_Info *server = tcon->ses->server; |
| 434 | unsigned int wsize; |
| 435 | |
| 436 | /* start with specified wsize, or default */ |
| 437 | if (volume_info->wsize) |
| 438 | wsize = volume_info->wsize; |
| 439 | else if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) |
| 440 | wsize = CIFS_DEFAULT_IOSIZE; |
| 441 | else |
| 442 | wsize = CIFS_DEFAULT_NON_POSIX_WSIZE; |
| 443 | |
| 444 | /* can server support 24-bit write sizes? (via UNIX extensions) */ |
| 445 | if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) |
| 446 | wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE); |
| 447 | |
| 448 | /* |
| 449 | * no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set? |
| 450 | * Limit it to max buffer offered by the server, minus the size of the |
| 451 | * WRITEX header, not including the 4 byte RFC1001 length. |
| 452 | */ |
| 453 | if (!(server->capabilities & CAP_LARGE_WRITE_X) || |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 454 | (!(server->capabilities & CAP_UNIX) && server->sign)) |
Pavel Shilovsky | 24985c5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 455 | wsize = min_t(unsigned int, wsize, |
| 456 | server->maxBuf - sizeof(WRITE_REQ) + 4); |
| 457 | |
Pavel Shilovsky | 24985c5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 458 | /* hard limit of CIFS_MAX_WSIZE */ |
| 459 | wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE); |
| 460 | |
| 461 | return wsize; |
| 462 | } |
| 463 | |
| 464 | static unsigned int |
| 465 | cifs_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 466 | { |
| 467 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); |
| 468 | struct TCP_Server_Info *server = tcon->ses->server; |
| 469 | unsigned int rsize, defsize; |
| 470 | |
| 471 | /* |
| 472 | * Set default value... |
| 473 | * |
| 474 | * HACK alert! Ancient servers have very small buffers. Even though |
| 475 | * MS-CIFS indicates that servers are only limited by the client's |
| 476 | * bufsize for reads, testing against win98se shows that it throws |
| 477 | * INVALID_PARAMETER errors if you try to request too large a read. |
| 478 | * OS/2 just sends back short reads. |
| 479 | * |
| 480 | * If the server doesn't advertise CAP_LARGE_READ_X, then assume that |
| 481 | * it can't handle a read request larger than its MaxBufferSize either. |
| 482 | */ |
| 483 | if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP)) |
| 484 | defsize = CIFS_DEFAULT_IOSIZE; |
| 485 | else if (server->capabilities & CAP_LARGE_READ_X) |
| 486 | defsize = CIFS_DEFAULT_NON_POSIX_RSIZE; |
| 487 | else |
| 488 | defsize = server->maxBuf - sizeof(READ_RSP); |
| 489 | |
| 490 | rsize = volume_info->rsize ? volume_info->rsize : defsize; |
| 491 | |
| 492 | /* |
| 493 | * no CAP_LARGE_READ_X? Then MS-CIFS states that we must limit this to |
| 494 | * the client's MaxBufferSize. |
| 495 | */ |
| 496 | if (!(server->capabilities & CAP_LARGE_READ_X)) |
| 497 | rsize = min_t(unsigned int, CIFSMaxBufSize, rsize); |
| 498 | |
Pavel Shilovsky | 24985c5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 499 | /* hard limit of CIFS_MAX_RSIZE */ |
| 500 | rsize = min_t(unsigned int, rsize, CIFS_MAX_RSIZE); |
| 501 | |
| 502 | return rsize; |
| 503 | } |
| 504 | |
Pavel Shilovsky | af4281d | 2012-05-27 20:48:35 +0400 | [diff] [blame] | 505 | static void |
| 506 | cifs_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 507 | { |
| 508 | CIFSSMBQFSDeviceInfo(xid, tcon); |
| 509 | CIFSSMBQFSAttributeInfo(xid, tcon); |
| 510 | } |
| 511 | |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 512 | static int |
| 513 | cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
| 514 | struct cifs_sb_info *cifs_sb, const char *full_path) |
| 515 | { |
| 516 | int rc; |
| 517 | FILE_ALL_INFO *file_info; |
| 518 | |
| 519 | file_info = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
| 520 | if (file_info == NULL) |
| 521 | return -ENOMEM; |
| 522 | |
| 523 | rc = CIFSSMBQPathInfo(xid, tcon, full_path, file_info, |
| 524 | 0 /* not legacy */, cifs_sb->local_nls, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 525 | cifs_remap(cifs_sb)); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 526 | |
| 527 | if (rc == -EOPNOTSUPP || rc == -EINVAL) |
| 528 | rc = SMBQueryInformation(xid, tcon, full_path, file_info, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 529 | cifs_sb->local_nls, cifs_remap(cifs_sb)); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 530 | kfree(file_info); |
| 531 | return rc; |
| 532 | } |
| 533 | |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 534 | static int |
| 535 | cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 536 | struct cifs_sb_info *cifs_sb, const char *full_path, |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 537 | FILE_ALL_INFO *data, bool *adjustTZ, bool *symlink) |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 538 | { |
| 539 | int rc; |
| 540 | |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 541 | *symlink = false; |
| 542 | |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 543 | /* could do find first instead but this returns more info */ |
| 544 | rc = CIFSSMBQPathInfo(xid, tcon, full_path, data, 0 /* not legacy */, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 545 | cifs_sb->local_nls, cifs_remap(cifs_sb)); |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 546 | /* |
| 547 | * BB optimize code so we do not make the above call when server claims |
| 548 | * no NT SMB support and the above call failed at least once - set flag |
| 549 | * in tcon or mount. |
| 550 | */ |
| 551 | if ((rc == -EOPNOTSUPP) || (rc == -EINVAL)) { |
| 552 | rc = SMBQueryInformation(xid, tcon, full_path, data, |
| 553 | cifs_sb->local_nls, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 554 | cifs_remap(cifs_sb)); |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 555 | *adjustTZ = true; |
| 556 | } |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 557 | |
| 558 | if (!rc && (le32_to_cpu(data->Attributes) & ATTR_REPARSE)) { |
| 559 | int tmprc; |
| 560 | int oplock = 0; |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 561 | struct cifs_fid fid; |
| 562 | struct cifs_open_parms oparms; |
| 563 | |
| 564 | oparms.tcon = tcon; |
| 565 | oparms.cifs_sb = cifs_sb; |
| 566 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 567 | oparms.create_options = 0; |
| 568 | oparms.disposition = FILE_OPEN; |
| 569 | oparms.path = full_path; |
| 570 | oparms.fid = &fid; |
| 571 | oparms.reconnect = false; |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 572 | |
| 573 | /* Need to check if this is a symbolic link or not */ |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 574 | tmprc = CIFS_open(xid, &oparms, &oplock, NULL); |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 575 | if (tmprc == -EOPNOTSUPP) |
| 576 | *symlink = true; |
Steve French | 19e8157 | 2014-09-25 01:26:55 -0500 | [diff] [blame] | 577 | else if (tmprc == 0) |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 578 | CIFSSMBClose(xid, tcon, fid.netfid); |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 579 | } |
| 580 | |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 581 | return rc; |
| 582 | } |
| 583 | |
| 584 | static int |
| 585 | cifs_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, |
| 586 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 587 | u64 *uniqueid, FILE_ALL_INFO *data) |
| 588 | { |
| 589 | /* |
| 590 | * We can not use the IndexNumber field by default from Windows or |
| 591 | * Samba (in ALL_INFO buf) but we can request it explicitly. The SNIA |
| 592 | * CIFS spec claims that this value is unique within the scope of a |
| 593 | * share, and the windows docs hint that it's actually unique |
| 594 | * per-machine. |
| 595 | * |
| 596 | * There may be higher info levels that work but are there Windows |
| 597 | * server or network appliances for which IndexNumber field is not |
| 598 | * guaranteed unique? |
| 599 | */ |
| 600 | return CIFSGetSrvInodeNumber(xid, tcon, full_path, uniqueid, |
| 601 | cifs_sb->local_nls, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 602 | cifs_remap(cifs_sb)); |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 603 | } |
| 604 | |
Pavel Shilovsky | 4ad6504 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 605 | static int |
| 606 | cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 607 | struct cifs_fid *fid, FILE_ALL_INFO *data) |
| 608 | { |
| 609 | return CIFSSMBQFileInfo(xid, tcon, fid->netfid, data); |
| 610 | } |
| 611 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 612 | static void |
| 613 | cifs_clear_stats(struct cifs_tcon *tcon) |
| 614 | { |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 615 | atomic_set(&tcon->stats.cifs_stats.num_writes, 0); |
| 616 | atomic_set(&tcon->stats.cifs_stats.num_reads, 0); |
| 617 | atomic_set(&tcon->stats.cifs_stats.num_flushes, 0); |
| 618 | atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0); |
| 619 | atomic_set(&tcon->stats.cifs_stats.num_opens, 0); |
| 620 | atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0); |
| 621 | atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0); |
| 622 | atomic_set(&tcon->stats.cifs_stats.num_closes, 0); |
| 623 | atomic_set(&tcon->stats.cifs_stats.num_deletes, 0); |
| 624 | atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0); |
| 625 | atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0); |
| 626 | atomic_set(&tcon->stats.cifs_stats.num_renames, 0); |
| 627 | atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0); |
| 628 | atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0); |
| 629 | atomic_set(&tcon->stats.cifs_stats.num_fnext, 0); |
| 630 | atomic_set(&tcon->stats.cifs_stats.num_fclose, 0); |
| 631 | atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0); |
| 632 | atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0); |
| 633 | atomic_set(&tcon->stats.cifs_stats.num_locks, 0); |
| 634 | atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0); |
| 635 | atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static void |
| 639 | cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon) |
| 640 | { |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 641 | seq_printf(m, " Oplocks breaks: %d", |
| 642 | atomic_read(&tcon->stats.cifs_stats.num_oplock_brks)); |
| 643 | seq_printf(m, "\nReads: %d Bytes: %llu", |
| 644 | atomic_read(&tcon->stats.cifs_stats.num_reads), |
| 645 | (long long)(tcon->bytes_read)); |
| 646 | seq_printf(m, "\nWrites: %d Bytes: %llu", |
| 647 | atomic_read(&tcon->stats.cifs_stats.num_writes), |
| 648 | (long long)(tcon->bytes_written)); |
| 649 | seq_printf(m, "\nFlushes: %d", |
| 650 | atomic_read(&tcon->stats.cifs_stats.num_flushes)); |
| 651 | seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d", |
| 652 | atomic_read(&tcon->stats.cifs_stats.num_locks), |
| 653 | atomic_read(&tcon->stats.cifs_stats.num_hardlinks), |
| 654 | atomic_read(&tcon->stats.cifs_stats.num_symlinks)); |
| 655 | seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d", |
| 656 | atomic_read(&tcon->stats.cifs_stats.num_opens), |
| 657 | atomic_read(&tcon->stats.cifs_stats.num_closes), |
| 658 | atomic_read(&tcon->stats.cifs_stats.num_deletes)); |
| 659 | seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d", |
| 660 | atomic_read(&tcon->stats.cifs_stats.num_posixopens), |
| 661 | atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs)); |
| 662 | seq_printf(m, "\nMkdirs: %d Rmdirs: %d", |
| 663 | atomic_read(&tcon->stats.cifs_stats.num_mkdirs), |
| 664 | atomic_read(&tcon->stats.cifs_stats.num_rmdirs)); |
| 665 | seq_printf(m, "\nRenames: %d T2 Renames %d", |
| 666 | atomic_read(&tcon->stats.cifs_stats.num_renames), |
| 667 | atomic_read(&tcon->stats.cifs_stats.num_t2renames)); |
| 668 | seq_printf(m, "\nFindFirst: %d FNext %d FClose %d", |
| 669 | atomic_read(&tcon->stats.cifs_stats.num_ffirst), |
| 670 | atomic_read(&tcon->stats.cifs_stats.num_fnext), |
| 671 | atomic_read(&tcon->stats.cifs_stats.num_fclose)); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 672 | } |
| 673 | |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 674 | static void |
| 675 | cifs_mkdir_setinfo(struct inode *inode, const char *full_path, |
| 676 | struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon, |
| 677 | const unsigned int xid) |
| 678 | { |
| 679 | FILE_BASIC_INFO info; |
| 680 | struct cifsInodeInfo *cifsInode; |
| 681 | u32 dosattrs; |
| 682 | int rc; |
| 683 | |
| 684 | memset(&info, 0, sizeof(info)); |
| 685 | cifsInode = CIFS_I(inode); |
| 686 | dosattrs = cifsInode->cifsAttrs|ATTR_READONLY; |
| 687 | info.Attributes = cpu_to_le32(dosattrs); |
| 688 | rc = CIFSSMBSetPathInfo(xid, tcon, full_path, &info, cifs_sb->local_nls, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 689 | cifs_remap(cifs_sb)); |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 690 | if (rc == 0) |
| 691 | cifsInode->cifsAttrs = dosattrs; |
| 692 | } |
| 693 | |
Pavel Shilovsky | fb1214e | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 694 | static int |
Pavel Shilovsky | 226730b | 2013-07-05 12:00:30 +0400 | [diff] [blame] | 695 | cifs_open_file(const unsigned int xid, struct cifs_open_parms *oparms, |
| 696 | __u32 *oplock, FILE_ALL_INFO *buf) |
Pavel Shilovsky | fb1214e | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 697 | { |
Pavel Shilovsky | 226730b | 2013-07-05 12:00:30 +0400 | [diff] [blame] | 698 | if (!(oparms->tcon->ses->capabilities & CAP_NT_SMBS)) |
| 699 | return SMBLegacyOpen(xid, oparms->tcon, oparms->path, |
| 700 | oparms->disposition, |
| 701 | oparms->desired_access, |
| 702 | oparms->create_options, |
| 703 | &oparms->fid->netfid, oplock, buf, |
| 704 | oparms->cifs_sb->local_nls, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 705 | cifs_remap(oparms->cifs_sb)); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 706 | return CIFS_open(xid, oparms, oplock, buf); |
Pavel Shilovsky | fb1214e | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | static void |
| 710 | cifs_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) |
| 711 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 712 | struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); |
Pavel Shilovsky | fb1214e | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 713 | cfile->fid.netfid = fid->netfid; |
| 714 | cifs_set_oplock_level(cinode, oplock); |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 715 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
Pavel Shilovsky | fb1214e | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 718 | static void |
Pavel Shilovsky | 0ff78a2 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 719 | cifs_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 720 | struct cifs_fid *fid) |
| 721 | { |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 722 | CIFSSMBClose(xid, tcon, fid->netfid); |
Pavel Shilovsky | 0ff78a2 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Pavel Shilovsky | 1d8c4c0 | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 725 | static int |
| 726 | cifs_flush_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 727 | struct cifs_fid *fid) |
| 728 | { |
| 729 | return CIFSSMBFlush(xid, tcon, fid->netfid); |
| 730 | } |
| 731 | |
Pavel Shilovsky | f9c6e23 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 732 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 733 | cifs_sync_read(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | f9c6e23 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 734 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 735 | char **buf, int *buf_type) |
| 736 | { |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 737 | parms->netfid = pfid->netfid; |
Pavel Shilovsky | f9c6e23 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 738 | return CIFSSMBRead(xid, parms, bytes_read, buf, buf_type); |
| 739 | } |
| 740 | |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 741 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 742 | cifs_sync_write(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 743 | struct cifs_io_parms *parms, unsigned int *written, |
| 744 | struct kvec *iov, unsigned long nr_segs) |
| 745 | { |
| 746 | |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 747 | parms->netfid = pfid->netfid; |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 748 | return CIFSSMBWrite2(xid, parms, written, iov, nr_segs); |
| 749 | } |
| 750 | |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 751 | static int |
| 752 | smb_set_file_info(struct inode *inode, const char *full_path, |
| 753 | FILE_BASIC_INFO *buf, const unsigned int xid) |
| 754 | { |
| 755 | int oplock = 0; |
| 756 | int rc; |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 757 | __u32 netpid; |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 758 | struct cifs_fid fid; |
| 759 | struct cifs_open_parms oparms; |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 760 | struct cifsFileInfo *open_file; |
| 761 | struct cifsInodeInfo *cinode = CIFS_I(inode); |
| 762 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 763 | struct tcon_link *tlink = NULL; |
| 764 | struct cifs_tcon *tcon; |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 765 | |
| 766 | /* if the file is already open for write, just use that fileid */ |
| 767 | open_file = find_writable_file(cinode, true); |
| 768 | if (open_file) { |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 769 | fid.netfid = open_file->fid.netfid; |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 770 | netpid = open_file->pid; |
| 771 | tcon = tlink_tcon(open_file->tlink); |
| 772 | goto set_via_filehandle; |
| 773 | } |
| 774 | |
| 775 | tlink = cifs_sb_tlink(cifs_sb); |
| 776 | if (IS_ERR(tlink)) { |
| 777 | rc = PTR_ERR(tlink); |
| 778 | tlink = NULL; |
| 779 | goto out; |
| 780 | } |
| 781 | tcon = tlink_tcon(tlink); |
| 782 | |
Jeff Layton | 281e2e7 | 2013-05-26 07:00:56 -0400 | [diff] [blame] | 783 | rc = CIFSSMBSetPathInfo(xid, tcon, full_path, buf, cifs_sb->local_nls, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 784 | cifs_remap(cifs_sb)); |
Jeff Layton | 281e2e7 | 2013-05-26 07:00:56 -0400 | [diff] [blame] | 785 | if (rc == 0) { |
| 786 | cinode->cifsAttrs = le32_to_cpu(buf->Attributes); |
| 787 | goto out; |
| 788 | } else if (rc != -EOPNOTSUPP && rc != -EINVAL) { |
| 789 | goto out; |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 792 | oparms.tcon = tcon; |
| 793 | oparms.cifs_sb = cifs_sb; |
| 794 | oparms.desired_access = SYNCHRONIZE | FILE_WRITE_ATTRIBUTES; |
| 795 | oparms.create_options = CREATE_NOT_DIR; |
| 796 | oparms.disposition = FILE_OPEN; |
| 797 | oparms.path = full_path; |
| 798 | oparms.fid = &fid; |
| 799 | oparms.reconnect = false; |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 800 | |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 801 | cifs_dbg(FYI, "calling SetFileInfo since SetPathInfo for times not supported by this server\n"); |
| 802 | rc = CIFS_open(xid, &oparms, &oplock, NULL); |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 803 | if (rc != 0) { |
| 804 | if (rc == -EIO) |
| 805 | rc = -EINVAL; |
| 806 | goto out; |
| 807 | } |
| 808 | |
| 809 | netpid = current->tgid; |
| 810 | |
| 811 | set_via_filehandle: |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 812 | rc = CIFSSMBSetFileInfo(xid, tcon, buf, fid.netfid, netpid); |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 813 | if (!rc) |
| 814 | cinode->cifsAttrs = le32_to_cpu(buf->Attributes); |
| 815 | |
| 816 | if (open_file == NULL) |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 817 | CIFSSMBClose(xid, tcon, fid.netfid); |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 818 | else |
| 819 | cifsFileInfo_put(open_file); |
| 820 | out: |
| 821 | if (tlink != NULL) |
| 822 | cifs_put_tlink(tlink); |
| 823 | return rc; |
| 824 | } |
| 825 | |
Pavel Shilovsky | 92fc65a | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 826 | static int |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 827 | cifs_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 828 | struct cifsFileInfo *cfile) |
| 829 | { |
| 830 | return CIFSSMB_set_compression(xid, tcon, cfile->fid.netfid); |
| 831 | } |
| 832 | |
| 833 | static int |
Pavel Shilovsky | 92fc65a | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 834 | cifs_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, |
| 835 | const char *path, struct cifs_sb_info *cifs_sb, |
| 836 | struct cifs_fid *fid, __u16 search_flags, |
| 837 | struct cifs_search_info *srch_inf) |
| 838 | { |
Pavel Shilovsky | dcd87838 | 2017-06-06 16:58:58 -0700 | [diff] [blame] | 839 | int rc; |
| 840 | |
| 841 | rc = CIFSFindFirst(xid, tcon, path, cifs_sb, |
| 842 | &fid->netfid, search_flags, srch_inf, true); |
| 843 | if (rc) |
| 844 | cifs_dbg(FYI, "find first failed=%d\n", rc); |
| 845 | return rc; |
Pavel Shilovsky | 92fc65a | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | static int |
| 849 | cifs_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, |
| 850 | struct cifs_fid *fid, __u16 search_flags, |
| 851 | struct cifs_search_info *srch_inf) |
| 852 | { |
| 853 | return CIFSFindNext(xid, tcon, fid->netfid, search_flags, srch_inf); |
| 854 | } |
| 855 | |
| 856 | static int |
| 857 | cifs_close_dir(const unsigned int xid, struct cifs_tcon *tcon, |
| 858 | struct cifs_fid *fid) |
| 859 | { |
| 860 | return CIFSFindClose(xid, tcon, fid->netfid); |
| 861 | } |
| 862 | |
Pavel Shilovsky | 95a3f2f | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 863 | static int |
| 864 | cifs_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 865 | struct cifsInodeInfo *cinode) |
| 866 | { |
| 867 | return CIFSSMBLock(0, tcon, fid->netfid, current->tgid, 0, 0, 0, 0, |
| 868 | LOCKING_ANDX_OPLOCK_RELEASE, false, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 869 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 95a3f2f | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Pavel Shilovsky | 76ec5e3 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 872 | static int |
| 873 | cifs_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 874 | struct kstatfs *buf) |
| 875 | { |
| 876 | int rc = -EOPNOTSUPP; |
| 877 | |
| 878 | buf->f_type = CIFS_MAGIC_NUMBER; |
| 879 | |
| 880 | /* |
| 881 | * We could add a second check for a QFS Unix capability bit |
| 882 | */ |
| 883 | if ((tcon->ses->capabilities & CAP_UNIX) && |
| 884 | (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability))) |
| 885 | rc = CIFSSMBQFSPosixInfo(xid, tcon, buf); |
| 886 | |
| 887 | /* |
| 888 | * Only need to call the old QFSInfo if failed on newer one, |
| 889 | * e.g. by OS/2. |
| 890 | **/ |
| 891 | if (rc && (tcon->ses->capabilities & CAP_NT_SMBS)) |
| 892 | rc = CIFSSMBQFSInfo(xid, tcon, buf); |
| 893 | |
| 894 | /* |
| 895 | * Some old Windows servers also do not support level 103, retry with |
| 896 | * older level one if old server failed the previous call or we |
| 897 | * bypassed it because we detected that this was an older LANMAN sess |
| 898 | */ |
| 899 | if (rc) |
| 900 | rc = SMBOldQFSInfo(xid, tcon, buf); |
| 901 | return rc; |
| 902 | } |
| 903 | |
Pavel Shilovsky | d39a4f7 | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 904 | static int |
| 905 | cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, |
| 906 | __u64 length, __u32 type, int lock, int unlock, bool wait) |
| 907 | { |
| 908 | return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->fid.netfid, |
| 909 | current->tgid, length, offset, unlock, lock, |
| 910 | (__u8)type, wait, 0); |
| 911 | } |
| 912 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 913 | static int |
Sachin Prabhu | 924e3fa | 2013-12-02 16:37:43 +0000 | [diff] [blame] | 914 | cifs_unix_dfs_readlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 915 | const unsigned char *searchName, char **symlinkinfo, |
| 916 | const struct nls_table *nls_codepage) |
| 917 | { |
| 918 | #ifdef CONFIG_CIFS_DFS_UPCALL |
| 919 | int rc; |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame] | 920 | struct dfs_info3_param referral = {0}; |
Sachin Prabhu | 924e3fa | 2013-12-02 16:37:43 +0000 | [diff] [blame] | 921 | |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame] | 922 | rc = get_dfs_path(xid, tcon->ses, searchName, nls_codepage, &referral, |
| 923 | 0); |
Sachin Prabhu | 924e3fa | 2013-12-02 16:37:43 +0000 | [diff] [blame] | 924 | |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame] | 925 | if (!rc) { |
| 926 | *symlinkinfo = kstrndup(referral.node_name, |
| 927 | strlen(referral.node_name), |
Sachin Prabhu | 924e3fa | 2013-12-02 16:37:43 +0000 | [diff] [blame] | 928 | GFP_KERNEL); |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame] | 929 | free_dfs_info_param(&referral); |
Sachin Prabhu | 924e3fa | 2013-12-02 16:37:43 +0000 | [diff] [blame] | 930 | if (!*symlinkinfo) |
| 931 | rc = -ENOMEM; |
Sachin Prabhu | 924e3fa | 2013-12-02 16:37:43 +0000 | [diff] [blame] | 932 | } |
| 933 | return rc; |
| 934 | #else /* No DFS support */ |
| 935 | return -EREMOTE; |
| 936 | #endif |
| 937 | } |
| 938 | |
| 939 | static int |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 940 | cifs_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 941 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 942 | char **target_path, bool is_reparse_point) |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 943 | { |
| 944 | int rc; |
| 945 | int oplock = 0; |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 946 | struct cifs_fid fid; |
| 947 | struct cifs_open_parms oparms; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 948 | |
| 949 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 950 | |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 951 | if (is_reparse_point) { |
| 952 | cifs_dbg(VFS, "reparse points not handled for SMB1 symlinks\n"); |
| 953 | return -EOPNOTSUPP; |
| 954 | } |
| 955 | |
Sachin Prabhu | 0ecdb4f | 2013-11-27 13:27:12 +0000 | [diff] [blame] | 956 | /* Check for unix extensions */ |
| 957 | if (cap_unix(tcon->ses)) { |
| 958 | rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, target_path, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 959 | cifs_sb->local_nls, |
| 960 | cifs_remap(cifs_sb)); |
Sachin Prabhu | 924e3fa | 2013-12-02 16:37:43 +0000 | [diff] [blame] | 961 | if (rc == -EREMOTE) |
| 962 | rc = cifs_unix_dfs_readlink(xid, tcon, full_path, |
| 963 | target_path, |
| 964 | cifs_sb->local_nls); |
| 965 | |
Sachin Prabhu | 0ecdb4f | 2013-11-27 13:27:12 +0000 | [diff] [blame] | 966 | goto out; |
| 967 | } |
| 968 | |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 969 | oparms.tcon = tcon; |
| 970 | oparms.cifs_sb = cifs_sb; |
| 971 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 972 | oparms.create_options = OPEN_REPARSE_POINT; |
| 973 | oparms.disposition = FILE_OPEN; |
| 974 | oparms.path = full_path; |
| 975 | oparms.fid = &fid; |
| 976 | oparms.reconnect = false; |
| 977 | |
| 978 | rc = CIFS_open(xid, &oparms, &oplock, NULL); |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 979 | if (rc) |
Sachin Prabhu | 0ecdb4f | 2013-11-27 13:27:12 +0000 | [diff] [blame] | 980 | goto out; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 981 | |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 982 | rc = CIFSSMBQuerySymLink(xid, tcon, fid.netfid, target_path, |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 983 | cifs_sb->local_nls); |
Sachin Prabhu | 0ecdb4f | 2013-11-27 13:27:12 +0000 | [diff] [blame] | 984 | if (rc) |
| 985 | goto out_close; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 986 | |
| 987 | convert_delimiter(*target_path, '/'); |
Sachin Prabhu | 0ecdb4f | 2013-11-27 13:27:12 +0000 | [diff] [blame] | 988 | out_close: |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 989 | CIFSSMBClose(xid, tcon, fid.netfid); |
Sachin Prabhu | 0ecdb4f | 2013-11-27 13:27:12 +0000 | [diff] [blame] | 990 | out: |
| 991 | if (!rc) |
| 992 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 993 | return rc; |
| 994 | } |
| 995 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 996 | static bool |
| 997 | cifs_is_read_op(__u32 oplock) |
| 998 | { |
| 999 | return oplock == OPLOCK_READ; |
| 1000 | } |
| 1001 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1002 | static unsigned int |
| 1003 | cifs_wp_retry_size(struct inode *inode) |
| 1004 | { |
| 1005 | return CIFS_SB(inode->i_sb)->wsize; |
| 1006 | } |
| 1007 | |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 1008 | static bool |
| 1009 | cifs_dir_needs_close(struct cifsFileInfo *cfile) |
| 1010 | { |
| 1011 | return !cfile->srch_inf.endOfSearch && !cfile->invalidHandle; |
| 1012 | } |
| 1013 | |
Sachin Prabhu | 62a6cfd | 2017-04-16 20:37:24 +0100 | [diff] [blame] | 1014 | static bool |
| 1015 | cifs_can_echo(struct TCP_Server_Info *server) |
| 1016 | { |
| 1017 | if (server->tcpStatus == CifsGood) |
| 1018 | return true; |
| 1019 | |
| 1020 | return false; |
| 1021 | } |
| 1022 | |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 1023 | static int |
| 1024 | cifs_make_node(unsigned int xid, struct inode *inode, |
| 1025 | struct dentry *dentry, struct cifs_tcon *tcon, |
| 1026 | char *full_path, umode_t mode, dev_t dev) |
| 1027 | { |
| 1028 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 1029 | struct inode *newinode = NULL; |
| 1030 | int rc = -EPERM; |
| 1031 | int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL; |
| 1032 | FILE_ALL_INFO *buf = NULL; |
| 1033 | struct cifs_io_parms io_parms; |
| 1034 | __u32 oplock = 0; |
| 1035 | struct cifs_fid fid; |
| 1036 | struct cifs_open_parms oparms; |
| 1037 | unsigned int bytes_written; |
| 1038 | struct win_dev *pdev; |
| 1039 | struct kvec iov[2]; |
| 1040 | |
| 1041 | if (tcon->unix_ext) { |
| 1042 | /* |
| 1043 | * SMB1 Unix Extensions: requires server support but |
| 1044 | * works with all special files |
| 1045 | */ |
| 1046 | struct cifs_unix_set_info_args args = { |
| 1047 | .mode = mode & ~current_umask(), |
| 1048 | .ctime = NO_CHANGE_64, |
| 1049 | .atime = NO_CHANGE_64, |
| 1050 | .mtime = NO_CHANGE_64, |
| 1051 | .device = dev, |
| 1052 | }; |
| 1053 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { |
| 1054 | args.uid = current_fsuid(); |
| 1055 | args.gid = current_fsgid(); |
| 1056 | } else { |
| 1057 | args.uid = INVALID_UID; /* no change */ |
| 1058 | args.gid = INVALID_GID; /* no change */ |
| 1059 | } |
| 1060 | rc = CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args, |
| 1061 | cifs_sb->local_nls, |
| 1062 | cifs_remap(cifs_sb)); |
| 1063 | if (rc) |
| 1064 | goto out; |
| 1065 | |
| 1066 | rc = cifs_get_inode_info_unix(&newinode, full_path, |
| 1067 | inode->i_sb, xid); |
| 1068 | |
| 1069 | if (rc == 0) |
| 1070 | d_instantiate(dentry, newinode); |
| 1071 | goto out; |
| 1072 | } |
| 1073 | |
| 1074 | /* |
| 1075 | * SMB1 SFU emulation: should work with all servers, but only |
| 1076 | * support block and char device (no socket & fifo) |
| 1077 | */ |
| 1078 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)) |
| 1079 | goto out; |
| 1080 | |
| 1081 | if (!S_ISCHR(mode) && !S_ISBLK(mode)) |
| 1082 | goto out; |
| 1083 | |
| 1084 | cifs_dbg(FYI, "sfu compat create special file\n"); |
| 1085 | |
| 1086 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
| 1087 | if (buf == NULL) { |
| 1088 | rc = -ENOMEM; |
| 1089 | goto out; |
| 1090 | } |
| 1091 | |
| 1092 | if (backup_cred(cifs_sb)) |
| 1093 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
| 1094 | |
| 1095 | oparms.tcon = tcon; |
| 1096 | oparms.cifs_sb = cifs_sb; |
| 1097 | oparms.desired_access = GENERIC_WRITE; |
| 1098 | oparms.create_options = create_options; |
| 1099 | oparms.disposition = FILE_CREATE; |
| 1100 | oparms.path = full_path; |
| 1101 | oparms.fid = &fid; |
| 1102 | oparms.reconnect = false; |
| 1103 | |
| 1104 | if (tcon->ses->server->oplocks) |
| 1105 | oplock = REQ_OPLOCK; |
| 1106 | else |
| 1107 | oplock = 0; |
| 1108 | rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf); |
| 1109 | if (rc) |
| 1110 | goto out; |
| 1111 | |
| 1112 | /* |
| 1113 | * BB Do not bother to decode buf since no local inode yet to put |
| 1114 | * timestamps in, but we can reuse it safely. |
| 1115 | */ |
| 1116 | |
| 1117 | pdev = (struct win_dev *)buf; |
| 1118 | io_parms.pid = current->tgid; |
| 1119 | io_parms.tcon = tcon; |
| 1120 | io_parms.offset = 0; |
| 1121 | io_parms.length = sizeof(struct win_dev); |
| 1122 | iov[1].iov_base = buf; |
| 1123 | iov[1].iov_len = sizeof(struct win_dev); |
| 1124 | if (S_ISCHR(mode)) { |
| 1125 | memcpy(pdev->type, "IntxCHR", 8); |
| 1126 | pdev->major = cpu_to_le64(MAJOR(dev)); |
| 1127 | pdev->minor = cpu_to_le64(MINOR(dev)); |
| 1128 | rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, |
| 1129 | &bytes_written, iov, 1); |
| 1130 | } else if (S_ISBLK(mode)) { |
| 1131 | memcpy(pdev->type, "IntxBLK", 8); |
| 1132 | pdev->major = cpu_to_le64(MAJOR(dev)); |
| 1133 | pdev->minor = cpu_to_le64(MINOR(dev)); |
| 1134 | rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, |
| 1135 | &bytes_written, iov, 1); |
| 1136 | } |
| 1137 | tcon->ses->server->ops->close(xid, tcon, &fid); |
| 1138 | d_drop(dentry); |
| 1139 | |
| 1140 | /* FIXME: add code here to set EAs */ |
| 1141 | out: |
| 1142 | kfree(buf); |
| 1143 | return rc; |
| 1144 | } |
| 1145 | |
| 1146 | |
| 1147 | |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1148 | struct smb_version_operations smb1_operations = { |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 1149 | .send_cancel = send_nt_cancel, |
Pavel Shilovsky | 55157df | 2012-02-28 14:04:17 +0300 | [diff] [blame] | 1150 | .compare_fids = cifs_compare_fids, |
Pavel Shilovsky | 082d064 | 2012-05-17 12:18:21 +0400 | [diff] [blame] | 1151 | .setup_request = cifs_setup_request, |
Pavel Shilovsky | 4574084 | 2012-06-01 14:26:18 +0400 | [diff] [blame] | 1152 | .setup_async_request = cifs_setup_async_request, |
Pavel Shilovsky | 082d064 | 2012-05-17 12:18:21 +0400 | [diff] [blame] | 1153 | .check_receive = cifs_check_receive, |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 1154 | .add_credits = cifs_add_credits, |
| 1155 | .set_credits = cifs_set_credits, |
| 1156 | .get_credits_field = cifs_get_credits_field, |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1157 | .get_credits = cifs_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 1158 | .wait_mtu_credits = cifs_wait_mtu_credits, |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 1159 | .get_next_mid = cifs_get_next_mid, |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1160 | .read_data_offset = cifs_read_data_offset, |
| 1161 | .read_data_length = cifs_read_data_length, |
| 1162 | .map_error = map_smb_to_linux_error, |
Pavel Shilovsky | 8aa26f3 | 2012-05-17 13:25:35 +0400 | [diff] [blame] | 1163 | .find_mid = cifs_find_mid, |
| 1164 | .check_message = checkSMB, |
| 1165 | .dump_detail = cifs_dump_detail, |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1166 | .clear_stats = cifs_clear_stats, |
| 1167 | .print_stats = cifs_print_stats, |
Pavel Shilovsky | 8aa26f3 | 2012-05-17 13:25:35 +0400 | [diff] [blame] | 1168 | .is_oplock_break = is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1169 | .downgrade_oplock = cifs_downgrade_oplock, |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 1170 | .check_trans2 = cifs_check_trans2, |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 1171 | .need_neg = cifs_need_neg, |
| 1172 | .negotiate = cifs_negotiate, |
Pavel Shilovsky | 24985c5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1173 | .negotiate_wsize = cifs_negotiate_wsize, |
| 1174 | .negotiate_rsize = cifs_negotiate_rsize, |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 1175 | .sess_setup = CIFS_SessSetup, |
| 1176 | .logoff = CIFSSMBLogoff, |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 1177 | .tree_connect = CIFSTCon, |
| 1178 | .tree_disconnect = CIFSSMBTDis, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 1179 | .get_dfs_refer = CIFSGetDFSRefer, |
Pavel Shilovsky | af4281d | 2012-05-27 20:48:35 +0400 | [diff] [blame] | 1180 | .qfs_tcon = cifs_qfs_tcon, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 1181 | .is_path_accessible = cifs_is_path_accessible, |
Sachin Prabhu | 62a6cfd | 2017-04-16 20:37:24 +0100 | [diff] [blame] | 1182 | .can_echo = cifs_can_echo, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 1183 | .query_path_info = cifs_query_path_info, |
Pavel Shilovsky | 4ad6504 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1184 | .query_file_info = cifs_query_file_info, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 1185 | .get_srv_inum = cifs_get_srv_inum, |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 1186 | .set_path_size = CIFSSMBSetEOF, |
| 1187 | .set_file_size = CIFSSMBSetFileSize, |
Pavel Shilovsky | 6bdf6db | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1188 | .set_file_info = smb_set_file_info, |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 1189 | .set_compression = cifs_set_compression, |
Pavel Shilovsky | f6d7617 | 2012-05-25 14:47:16 +0400 | [diff] [blame] | 1190 | .echo = CIFSSMBEcho, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 1191 | .mkdir = CIFSSMBMkDir, |
| 1192 | .mkdir_setinfo = cifs_mkdir_setinfo, |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 1193 | .rmdir = CIFSSMBRmDir, |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 1194 | .unlink = CIFSSMBDelFile, |
| 1195 | .rename_pending_delete = cifs_rename_pending_delete, |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1196 | .rename = CIFSSMBRename, |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 1197 | .create_hardlink = CIFSCreateHardLink, |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 1198 | .query_symlink = cifs_query_symlink, |
Pavel Shilovsky | fb1214e | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1199 | .open = cifs_open_file, |
| 1200 | .set_fid = cifs_set_fid, |
Pavel Shilovsky | 0ff78a2 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1201 | .close = cifs_close_file, |
Pavel Shilovsky | 1d8c4c0 | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 1202 | .flush = cifs_flush_file, |
Pavel Shilovsky | fc9c596 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1203 | .async_readv = cifs_async_readv, |
Pavel Shilovsky | c9de5c8 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1204 | .async_writev = cifs_async_writev, |
Pavel Shilovsky | f9c6e23 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1205 | .sync_read = cifs_sync_read, |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1206 | .sync_write = cifs_sync_write, |
Pavel Shilovsky | 92fc65a | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1207 | .query_dir_first = cifs_query_dir_first, |
| 1208 | .query_dir_next = cifs_query_dir_next, |
| 1209 | .close_dir = cifs_close_dir, |
| 1210 | .calc_smb_size = smbCalcSize, |
Pavel Shilovsky | 95a3f2f | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1211 | .oplock_response = cifs_oplock_response, |
Pavel Shilovsky | 76ec5e3 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1212 | .queryfs = cifs_queryfs, |
Pavel Shilovsky | d39a4f7 | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1213 | .mand_lock = cifs_mand_lock, |
| 1214 | .mand_unlock_range = cifs_unlock_range, |
| 1215 | .push_mand_locks = cifs_push_mandatory_locks, |
Sachin Prabhu | b5be1a1 | 2013-11-25 17:09:49 +0000 | [diff] [blame] | 1216 | .query_mf_symlink = cifs_query_mf_symlink, |
Sachin Prabhu | cbb0aba | 2013-11-25 17:09:52 +0000 | [diff] [blame] | 1217 | .create_mf_symlink = cifs_create_mf_symlink, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1218 | .is_read_op = cifs_is_read_op, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1219 | .wp_retry_size = cifs_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 1220 | .dir_needs_close = cifs_dir_needs_close, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 1221 | .select_sectype = cifs_select_sectype, |
Steve French | d979f3b | 2014-02-01 23:27:18 -0600 | [diff] [blame] | 1222 | #ifdef CONFIG_CIFS_XATTR |
| 1223 | .query_all_EAs = CIFSSMBQAllEAs, |
| 1224 | .set_EA = CIFSSMBSetEA, |
| 1225 | #endif /* CIFS_XATTR */ |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 1226 | #ifdef CONFIG_CIFS_ACL |
| 1227 | .get_acl = get_cifs_acl, |
Steve French | 42eacf9 | 2014-02-10 14:08:16 -0600 | [diff] [blame] | 1228 | .get_acl_by_fid = get_cifs_acl_by_fid, |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 1229 | .set_acl = set_cifs_acl, |
| 1230 | #endif /* CIFS_ACL */ |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 1231 | .make_node = cifs_make_node, |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1232 | }; |
| 1233 | |
| 1234 | struct smb_version_values smb1_values = { |
| 1235 | .version_string = SMB1_VERSION_STRING, |
Pavel Shilovsky | 106dc53 | 2012-02-28 14:23:34 +0300 | [diff] [blame] | 1236 | .large_lock_type = LOCKING_ANDX_LARGE_FILES, |
| 1237 | .exclusive_lock_type = 0, |
| 1238 | .shared_lock_type = LOCKING_ANDX_SHARED_LOCK, |
| 1239 | .unlock_lock_type = 0, |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 1240 | .header_preamble_size = 4, |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1241 | .header_size = sizeof(struct smb_hdr), |
| 1242 | .max_header_size = MAX_CIFS_HDR_SIZE, |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1243 | .read_rsp_size = sizeof(READ_RSP), |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1244 | .lock_cmd = cpu_to_le16(SMB_COM_LOCKING_ANDX), |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 1245 | .cap_unix = CAP_UNIX, |
| 1246 | .cap_nt_find = CAP_NT_SMBS | CAP_NT_FIND, |
| 1247 | .cap_large_files = CAP_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1248 | .signing_enabled = SECMODE_SIGN_ENABLED, |
| 1249 | .signing_required = SECMODE_SIGN_REQUIRED, |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1250 | }; |