blob: d9d615fbed3f5547ad62fadb0c811f339769cede [file] [log] [blame]
Jeff Layton23db65f2012-05-15 12:20:51 -04001/*
2 * SMB1 (CIFS) version specific operations
3 *
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "cifsglob.h"
Jeff Layton121b0462012-05-15 12:21:10 -040021#include "cifsproto.h"
22#include "cifs_debug.h"
Pavel Shilovsky106dc532012-02-28 14:23:34 +030023#include "cifspdu.h"
Jeff Layton121b0462012-05-15 12:21:10 -040024
25/*
26 * An NT cancel request header looks just like the original request except:
27 *
28 * The Command is SMB_COM_NT_CANCEL
29 * The WordCount is zeroed out
30 * The ByteCount is zeroed out
31 *
32 * This function mangles an existing request buffer into a
33 * SMB_COM_NT_CANCEL request and then sends it.
34 */
35static int
36send_nt_cancel(struct TCP_Server_Info *server, void *buf,
37 struct mid_q_entry *mid)
38{
39 int rc = 0;
40 struct smb_hdr *in_buf = (struct smb_hdr *)buf;
41
42 /* -4 for RFC1001 length and +2 for BCC field */
43 in_buf->smb_buf_length = cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2);
44 in_buf->Command = SMB_COM_NT_CANCEL;
45 in_buf->WordCount = 0;
46 put_bcc(0, in_buf);
47
48 mutex_lock(&server->srv_mutex);
49 rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
50 if (rc) {
51 mutex_unlock(&server->srv_mutex);
52 return rc;
53 }
54 rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
55 mutex_unlock(&server->srv_mutex);
56
57 cFYI(1, "issued NT_CANCEL for mid %u, rc = %d",
58 in_buf->Mid, rc);
59
60 return rc;
61}
Jeff Layton23db65f2012-05-15 12:20:51 -040062
Pavel Shilovsky55157df2012-02-28 14:04:17 +030063static bool
64cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
65{
66 return ob1->netfid == ob2->netfid;
67}
68
Pavel Shilovskyeb378712012-05-17 13:02:51 +040069static unsigned int
70cifs_read_data_offset(char *buf)
71{
72 READ_RSP *rsp = (READ_RSP *)buf;
73 return le16_to_cpu(rsp->DataOffset);
74}
75
76static unsigned int
77cifs_read_data_length(char *buf)
78{
79 READ_RSP *rsp = (READ_RSP *)buf;
80 return (le16_to_cpu(rsp->DataLengthHigh) << 16) +
81 le16_to_cpu(rsp->DataLength);
82}
83
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040084static struct mid_q_entry *
85cifs_find_mid(struct TCP_Server_Info *server, char *buffer)
86{
87 struct smb_hdr *buf = (struct smb_hdr *)buffer;
88 struct mid_q_entry *mid;
89
90 spin_lock(&GlobalMid_Lock);
91 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
92 if (mid->mid == buf->Mid &&
93 mid->mid_state == MID_REQUEST_SUBMITTED &&
94 le16_to_cpu(mid->command) == buf->Command) {
95 spin_unlock(&GlobalMid_Lock);
96 return mid;
97 }
98 }
99 spin_unlock(&GlobalMid_Lock);
100 return NULL;
101}
102
Pavel Shilovsky45275782012-05-17 17:53:29 +0400103static void
104cifs_add_credits(struct TCP_Server_Info *server, const unsigned int add)
105{
106 spin_lock(&server->req_lock);
107 server->credits += add;
108 server->in_flight--;
109 spin_unlock(&server->req_lock);
110 wake_up(&server->request_q);
111}
112
113static void
114cifs_set_credits(struct TCP_Server_Info *server, const int val)
115{
116 spin_lock(&server->req_lock);
117 server->credits = val;
118 server->oplocks = val > 1 ? enable_oplocks : false;
119 spin_unlock(&server->req_lock);
120}
121
122static int *
123cifs_get_credits_field(struct TCP_Server_Info *server)
124{
125 return &server->credits;
126}
127
Jeff Layton23db65f2012-05-15 12:20:51 -0400128struct smb_version_operations smb1_operations = {
Jeff Layton121b0462012-05-15 12:21:10 -0400129 .send_cancel = send_nt_cancel,
Pavel Shilovsky55157df2012-02-28 14:04:17 +0300130 .compare_fids = cifs_compare_fids,
Pavel Shilovsky082d0642012-05-17 12:18:21 +0400131 .setup_request = cifs_setup_request,
132 .check_receive = cifs_check_receive,
Pavel Shilovsky45275782012-05-17 17:53:29 +0400133 .add_credits = cifs_add_credits,
134 .set_credits = cifs_set_credits,
135 .get_credits_field = cifs_get_credits_field,
Pavel Shilovskyeb378712012-05-17 13:02:51 +0400136 .read_data_offset = cifs_read_data_offset,
137 .read_data_length = cifs_read_data_length,
138 .map_error = map_smb_to_linux_error,
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +0400139 .find_mid = cifs_find_mid,
140 .check_message = checkSMB,
141 .dump_detail = cifs_dump_detail,
142 .is_oplock_break = is_valid_oplock_break,
Jeff Layton23db65f2012-05-15 12:20:51 -0400143};
144
145struct smb_version_values smb1_values = {
146 .version_string = SMB1_VERSION_STRING,
Pavel Shilovsky106dc532012-02-28 14:23:34 +0300147 .large_lock_type = LOCKING_ANDX_LARGE_FILES,
148 .exclusive_lock_type = 0,
149 .shared_lock_type = LOCKING_ANDX_SHARED_LOCK,
150 .unlock_lock_type = 0,
Pavel Shilovsky1887f602012-05-17 12:45:31 +0400151 .header_size = sizeof(struct smb_hdr),
152 .max_header_size = MAX_CIFS_HDR_SIZE,
Pavel Shilovskyeb378712012-05-17 13:02:51 +0400153 .read_rsp_size = sizeof(READ_RSP),
Jeff Layton23db65f2012-05-15 12:20:51 -0400154};