Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cifssmb.c |
| 3 | * |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * Contains the routines for constructing the SMB PDUs themselves |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* SMB/CIFS PDU handling routines here - except for leftovers in connect.c */ |
| 25 | /* These are mostly routines that operate on a pathname, or on a tree id */ |
| 26 | /* (mounted volume), but there are eight handle based routines which must be */ |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 27 | /* treated slightly differently for reconnection purposes since we never */ |
| 28 | /* want to reuse a stale file handle and only the caller knows the file info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <linux/fs.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/vfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/posix_acl_xattr.h> |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 35 | #include <linux/pagemap.h> |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 36 | #include <linux/swap.h> |
| 37 | #include <linux/task_io_accounting_ops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/uaccess.h> |
| 39 | #include "cifspdu.h" |
| 40 | #include "cifsglob.h" |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 41 | #include "cifsacl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "cifsproto.h" |
| 43 | #include "cifs_unicode.h" |
| 44 | #include "cifs_debug.h" |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 45 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #ifdef CONFIG_CIFS_POSIX |
| 48 | static struct { |
| 49 | int index; |
| 50 | char *name; |
| 51 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 52 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 53 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 54 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 55 | #endif /* weak password hashing for legacy clients */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 56 | {CIFS_PROT, "\2NT LM 0.12"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 57 | {POSIX_PROT, "\2POSIX 2"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | {BAD_PROT, "\2"} |
| 59 | }; |
| 60 | #else |
| 61 | static struct { |
| 62 | int index; |
| 63 | char *name; |
| 64 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 65 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 66 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 18f75ca | 2006-10-01 03:13:01 +0000 | [diff] [blame] | 67 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 68 | #endif /* weak password hashing for legacy clients */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 69 | {CIFS_PROT, "\2NT LM 0.12"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | {BAD_PROT, "\2"} |
| 71 | }; |
| 72 | #endif |
| 73 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 74 | /* define the number of elements in the cifs dialect array */ |
| 75 | #ifdef CONFIG_CIFS_POSIX |
| 76 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 77 | #define CIFS_NUM_PROT 4 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 78 | #else |
| 79 | #define CIFS_NUM_PROT 2 |
| 80 | #endif /* CIFS_WEAK_PW_HASH */ |
| 81 | #else /* not posix */ |
| 82 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 83 | #define CIFS_NUM_PROT 3 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 84 | #else |
| 85 | #define CIFS_NUM_PROT 1 |
| 86 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
| 87 | #endif /* CIFS_POSIX */ |
| 88 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 89 | /* Forward declarations */ |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* Mark as invalid, all open files on tree connections since they |
| 92 | were closed when session to server was lost */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 93 | static void mark_open_files_invalid(struct cifs_tcon *pTcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
| 95 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 96 | struct list_head *tmp; |
| 97 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | /* list all files open on tree connection and mark them invalid */ |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 100 | spin_lock(&cifs_file_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | list_for_each_safe(tmp, tmp1, &pTcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 102 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 103 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 104 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 106 | spin_unlock(&cifs_file_list_lock); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 107 | /* BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 108 | to this tcon */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 111 | /* reconnect the socket, tcon, and smb session if needed */ |
| 112 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 113 | cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 114 | { |
Jeff Layton | c4a5534 | 2011-07-28 12:40:36 -0400 | [diff] [blame] | 115 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 116 | struct cifs_ses *ses; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 117 | struct TCP_Server_Info *server; |
| 118 | struct nls_table *nls_codepage; |
| 119 | |
| 120 | /* |
| 121 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 122 | * tcp and smb session status done differently for those three - in the |
| 123 | * calling routine |
| 124 | */ |
| 125 | if (!tcon) |
| 126 | return 0; |
| 127 | |
| 128 | ses = tcon->ses; |
| 129 | server = ses->server; |
| 130 | |
| 131 | /* |
| 132 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 133 | * have tcon) are allowed as we start force umount |
| 134 | */ |
| 135 | if (tcon->tidStatus == CifsExiting) { |
| 136 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 137 | smb_command != SMB_COM_OPEN_ANDX && |
| 138 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 139 | cFYI(1, "can not send cmd %d while umounting", |
| 140 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 141 | return -ENODEV; |
| 142 | } |
| 143 | } |
| 144 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 145 | /* |
| 146 | * Give demultiplex thread up to 10 seconds to reconnect, should be |
| 147 | * greater than cifs socket timeout which is 7 seconds |
| 148 | */ |
| 149 | while (server->tcpStatus == CifsNeedReconnect) { |
| 150 | wait_event_interruptible_timeout(server->response_q, |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 151 | (server->tcpStatus != CifsNeedReconnect), 10 * HZ); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 152 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 153 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 154 | if (server->tcpStatus != CifsNeedReconnect) |
| 155 | break; |
| 156 | |
| 157 | /* |
| 158 | * on "soft" mounts we wait once. Hard mounts keep |
| 159 | * retrying until process is killed or server comes |
| 160 | * back on-line |
| 161 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 162 | if (!tcon->retry) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 163 | cFYI(1, "gave up waiting on reconnect in smb_init"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 164 | return -EHOSTDOWN; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 169 | return 0; |
| 170 | |
| 171 | nls_codepage = load_nls_default(); |
| 172 | |
| 173 | /* |
| 174 | * need to prevent multiple threads trying to simultaneously |
| 175 | * reconnect the same SMB session |
| 176 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 177 | mutex_lock(&ses->session_mutex); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 178 | rc = cifs_negotiate_protocol(0, ses); |
| 179 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 180 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 181 | |
| 182 | /* do we need to reconnect tcon? */ |
| 183 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 184 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 185 | goto out; |
| 186 | } |
| 187 | |
| 188 | mark_open_files_invalid(tcon); |
| 189 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 190 | mutex_unlock(&ses->session_mutex); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 191 | cFYI(1, "reconnect tcon rc = %d", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 192 | |
| 193 | if (rc) |
| 194 | goto out; |
| 195 | |
| 196 | /* |
| 197 | * FIXME: check if wsize needs updated due to negotiated smb buffer |
| 198 | * size shrinking |
| 199 | */ |
| 200 | atomic_inc(&tconInfoReconnectCount); |
| 201 | |
| 202 | /* tell server Unix caps we support */ |
| 203 | if (ses->capabilities & CAP_UNIX) |
| 204 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 205 | |
| 206 | /* |
| 207 | * Removed call to reopen open files here. It is safer (and faster) to |
| 208 | * reopen files one at a time as needed in read and write. |
| 209 | * |
| 210 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 211 | */ |
| 212 | |
| 213 | out: |
| 214 | /* |
| 215 | * Check if handle based operation so we know whether we can continue |
| 216 | * or not without returning to caller to reset file handle |
| 217 | */ |
| 218 | switch (smb_command) { |
| 219 | case SMB_COM_READ_ANDX: |
| 220 | case SMB_COM_WRITE_ANDX: |
| 221 | case SMB_COM_CLOSE: |
| 222 | case SMB_COM_FIND_CLOSE2: |
| 223 | case SMB_COM_LOCKING_ANDX: |
| 224 | rc = -EAGAIN; |
| 225 | } |
| 226 | |
| 227 | unload_nls(nls_codepage); |
| 228 | return rc; |
| 229 | } |
| 230 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 231 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 232 | SMB information in the SMB header. If the return code is zero, this |
| 233 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 235 | small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 236 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 238 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 240 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 241 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return rc; |
| 243 | |
| 244 | *request_buf = cifs_small_buf_get(); |
| 245 | if (*request_buf == NULL) { |
| 246 | /* BB should we add a retry in here if not a writepage? */ |
| 247 | return -ENOMEM; |
| 248 | } |
| 249 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 250 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 251 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 253 | if (tcon != NULL) |
| 254 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 255 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 256 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 259 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 260 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 261 | struct cifs_ses *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 262 | { |
| 263 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 264 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 265 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 266 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 267 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 268 | return rc; |
| 269 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 270 | buffer = (struct smb_hdr *)*request_buf; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 271 | buffer->Mid = GetNextMid(ses->server); |
| 272 | if (ses->capabilities & CAP_UNICODE) |
| 273 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 274 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 275 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 276 | |
| 277 | /* uid, tid can stay at zero as set in header assemble */ |
| 278 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 279 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 280 | this function is used after 1st of session setup requests */ |
| 281 | |
| 282 | return rc; |
| 283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 286 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 287 | __smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 288 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | *request_buf = cifs_buf_get(); |
| 291 | if (*request_buf == NULL) { |
| 292 | /* BB should we add a retry in here if not a writepage? */ |
| 293 | return -ENOMEM; |
| 294 | } |
| 295 | /* Although the original thought was we needed the response buf for */ |
| 296 | /* potential retries of smb operations it turns out we can determine */ |
| 297 | /* from the mid flags when the request buffer can be resent without */ |
| 298 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 299 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 300 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 303 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 305 | if (tcon != NULL) |
| 306 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 307 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 312 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 313 | smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 314 | void **request_buf, void **response_buf) |
| 315 | { |
| 316 | int rc; |
| 317 | |
| 318 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 319 | if (rc) |
| 320 | return rc; |
| 321 | |
| 322 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 323 | } |
| 324 | |
| 325 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 326 | smb_init_no_reconnect(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 327 | void **request_buf, void **response_buf) |
| 328 | { |
| 329 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 330 | return -EHOSTDOWN; |
| 331 | |
| 332 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 335 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 337 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 339 | /* check for plausible wct */ |
| 340 | if (pSMB->hdr.WordCount < 10) |
| 341 | goto vt2_err; |
| 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 344 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 345 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 346 | goto vt2_err; |
| 347 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 348 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 349 | if (total_size >= 512) |
| 350 | goto vt2_err; |
| 351 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 352 | /* check that bcc is at least as big as parms + data, and that it is |
| 353 | * less than negotiated smb buffer |
| 354 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 355 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 356 | if (total_size > get_bcc(&pSMB->hdr) || |
| 357 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 358 | goto vt2_err; |
| 359 | |
| 360 | return 0; |
| 361 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 362 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 364 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 366 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 367 | static inline void inc_rfc1001_len(void *pSMB, int count) |
| 368 | { |
| 369 | struct smb_hdr *hdr = (struct smb_hdr *)pSMB; |
| 370 | |
| 371 | be32_add_cpu(&hdr->smb_buf_length, count); |
| 372 | } |
| 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 375 | CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
| 377 | NEGOTIATE_REQ *pSMB; |
| 378 | NEGOTIATE_RSP *pSMBr; |
| 379 | int rc = 0; |
| 380 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 381 | int i; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 382 | struct TCP_Server_Info *server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | u16 count; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 384 | unsigned int secFlags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 386 | if (ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | server = ses->server; |
| 388 | else { |
| 389 | rc = -EIO; |
| 390 | return rc; |
| 391 | } |
| 392 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 393 | (void **) &pSMB, (void **) &pSMBr); |
| 394 | if (rc) |
| 395 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 396 | |
| 397 | /* if any of auth flags (ie not sign or seal) are overriden use them */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 398 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 399 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 400 | else /* if override flags set only sign/seal OR them with global auth */ |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 401 | secFlags = global_secflags | ses->overrideSecFlg; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 402 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 403 | cFYI(1, "secFlags 0x%x", secFlags); |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 404 | |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 405 | pSMB->hdr.Mid = GetNextMid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 406 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 407 | |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 408 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 409 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 410 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 411 | cFYI(1, "Kerberos only mechanism, enable extended security"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 412 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Jeff Layton | b4d6fcf | 2011-01-07 11:30:28 -0500 | [diff] [blame] | 413 | } else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 414 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 415 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 416 | cFYI(1, "NTLMSSP only mechanism, enable extended security"); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 417 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 418 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 419 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 420 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 421 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 422 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 423 | count += strlen(protocols[i].name) + 1; |
| 424 | /* null at end of source and target buffers anyway */ |
| 425 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 426 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | pSMB->ByteCount = cpu_to_le16(count); |
| 428 | |
| 429 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 430 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 431 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 432 | goto neg_err_exit; |
| 433 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 434 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
| 435 | cFYI(1, "Dialect: %d", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 436 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 437 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 438 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 439 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 440 | could not negotiate a common dialect */ |
| 441 | rc = -EOPNOTSUPP; |
| 442 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 443 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 444 | } else if ((pSMBr->hdr.WordCount == 13) |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 445 | && ((server->dialect == LANMAN_PROT) |
| 446 | || (server->dialect == LANMAN2_PROT))) { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 447 | __s16 tmp; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 448 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 449 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 450 | if ((secFlags & CIFSSEC_MAY_LANMAN) || |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 451 | (secFlags & CIFSSEC_MAY_PLNTXT)) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 452 | server->secType = LANMAN; |
| 453 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 454 | cERROR(1, "mount failed weak security disabled" |
| 455 | " in /proc/fs/cifs/SecurityFlags"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 456 | rc = -EOPNOTSUPP; |
| 457 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 458 | } |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 459 | server->sec_mode = (__u8)le16_to_cpu(rsp->SecurityMode); |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 460 | server->maxReq = min_t(unsigned int, |
| 461 | le16_to_cpu(rsp->MaxMpxCount), |
| 462 | cifs_max_pending); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 463 | cifs_set_credits(server, server->maxReq); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 464 | server->maxBuf = le16_to_cpu(rsp->MaxBufSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 465 | server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 466 | /* even though we do not use raw we might as well set this |
| 467 | accurately, in case we ever find a need for it */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 468 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 469 | server->max_rw = 0xFF00; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 470 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 471 | } else { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 472 | server->max_rw = 0;/* do not need to use raw anyway */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 473 | server->capabilities = CAP_MPX_MODE; |
| 474 | } |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 475 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
Steve French | 1a70d65 | 2006-10-02 05:59:18 +0000 | [diff] [blame] | 476 | if (tmp == -1) { |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 477 | /* OS/2 often does not set timezone therefore |
| 478 | * we must use server time to calc time zone. |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 479 | * Could deviate slightly from the right zone. |
| 480 | * Smallest defined timezone difference is 15 minutes |
| 481 | * (i.e. Nepal). Rounding up/down is done to match |
| 482 | * this requirement. |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 483 | */ |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 484 | int val, seconds, remain, result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 485 | struct timespec ts, utc; |
| 486 | utc = CURRENT_TIME; |
Jeff Layton | c4a2c08 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 487 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 488 | rsp->SrvTime.Time, 0); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 489 | cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d", |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 490 | (int)ts.tv_sec, (int)utc.tv_sec, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 491 | (int)(utc.tv_sec - ts.tv_sec)); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 492 | val = (int)(utc.tv_sec - ts.tv_sec); |
Andre Haupt | 8594c15 | 2007-08-30 20:18:41 +0000 | [diff] [blame] | 493 | seconds = abs(val); |
Steve French | 947a506 | 2006-10-02 05:55:25 +0000 | [diff] [blame] | 494 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 495 | remain = seconds % MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 496 | if (remain >= (MIN_TZ_ADJ / 2)) |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 497 | result += MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 498 | if (val < 0) |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 499 | result = -result; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 500 | server->timeAdj = result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 501 | } else { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 502 | server->timeAdj = (int)tmp; |
| 503 | server->timeAdj *= 60; /* also in seconds */ |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 504 | } |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 505 | cFYI(1, "server->timeAdj: %d seconds", server->timeAdj); |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 506 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 507 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 508 | /* BB get server time for time conversions and add |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 509 | code to use it and timezone since this is not UTC */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 510 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 511 | if (rsp->EncryptionKeyLength == |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 512 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 513 | memcpy(ses->server->cryptkey, rsp->EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 514 | CIFS_CRYPTO_KEY_SIZE); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 515 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 516 | rc = -EIO; /* need cryptkey unless plain text */ |
| 517 | goto neg_err_exit; |
| 518 | } |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 519 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 520 | cFYI(1, "LANMAN negotiated"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 521 | /* we will not end up setting signing flags - as no signing |
| 522 | was in LANMAN and server did not return the flags on */ |
| 523 | goto signing_check; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 524 | #else /* weak security disabled */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 525 | } else if (pSMBr->hdr.WordCount == 13) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 526 | cERROR(1, "mount failed, cifs module not built " |
| 527 | "with CIFS_WEAK_PW_HASH support"); |
Dan Carpenter | 8212cf7 | 2010-03-15 11:22:26 +0300 | [diff] [blame] | 528 | rc = -EOPNOTSUPP; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 529 | #endif /* WEAK_PW_HASH */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 530 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 531 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 532 | /* unknown wct */ |
| 533 | rc = -EOPNOTSUPP; |
| 534 | goto neg_err_exit; |
| 535 | } |
| 536 | /* else wct == 17 NTLM */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 537 | server->sec_mode = pSMBr->SecurityMode; |
| 538 | if ((server->sec_mode & SECMODE_USER) == 0) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 539 | cFYI(1, "share mode security"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 540 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 541 | if ((server->sec_mode & SECMODE_PW_ENCRYPT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 542 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 543 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 544 | #endif /* CIFS_WEAK_PW_HASH */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 545 | cERROR(1, "Server requests plain text password" |
| 546 | " but client support disabled"); |
Steve French | 9312f67 | 2006-06-04 22:21:07 +0000 | [diff] [blame] | 547 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 548 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 549 | server->secType = NTLMv2; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 550 | else if (secFlags & CIFSSEC_MAY_NTLM) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 551 | server->secType = NTLM; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 552 | else if (secFlags & CIFSSEC_MAY_NTLMV2) |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 553 | server->secType = NTLMv2; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 554 | else if (secFlags & CIFSSEC_MAY_KRB5) |
| 555 | server->secType = Kerberos; |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 556 | else if (secFlags & CIFSSEC_MAY_NTLMSSP) |
Steve French | f46c723 | 2009-06-25 03:04:20 +0000 | [diff] [blame] | 557 | server->secType = RawNTLMSSP; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 558 | else if (secFlags & CIFSSEC_MAY_LANMAN) |
| 559 | server->secType = LANMAN; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 560 | else { |
| 561 | rc = -EOPNOTSUPP; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 562 | cERROR(1, "Invalid security type"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 563 | goto neg_err_exit; |
| 564 | } |
| 565 | /* else ... any others ...? */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 566 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 567 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 568 | little endian */ |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 569 | server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), |
| 570 | cifs_max_pending); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 571 | cifs_set_credits(server, server->maxReq); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 572 | /* probably no need to store and check maxvcs */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 573 | server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 574 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 575 | cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 576 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 577 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 578 | server->timeAdj *= 60; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 579 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 580 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 581 | CIFS_CRYPTO_KEY_SIZE); |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 582 | } else if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC || |
| 583 | server->capabilities & CAP_EXTENDED_SECURITY) && |
| 584 | (pSMBr->EncryptionKeyLength == 0)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 585 | /* decode security blob */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 586 | count = get_bcc(&pSMBr->hdr); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 587 | if (count < 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | rc = -EIO; |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 589 | goto neg_err_exit; |
| 590 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 591 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 592 | if (server->srv_count > 1) { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 593 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 594 | if (memcmp(server->server_GUID, |
| 595 | pSMBr->u.extended_response. |
| 596 | GUID, 16) != 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 597 | cFYI(1, "server UID changed"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 598 | memcpy(server->server_GUID, |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 599 | pSMBr->u.extended_response.GUID, |
| 600 | 16); |
| 601 | } |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 602 | } else { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 603 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 604 | memcpy(server->server_GUID, |
| 605 | pSMBr->u.extended_response.GUID, 16); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 606 | } |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 607 | |
| 608 | if (count == 16) { |
| 609 | server->secType = RawNTLMSSP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 610 | } else { |
| 611 | rc = decode_negTokenInit(pSMBr->u.extended_response. |
Jeff Layton | 26efa0b | 2010-04-24 07:57:49 -0400 | [diff] [blame] | 612 | SecurityBlob, count - 16, |
| 613 | server); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 614 | if (rc == 1) |
Jeff Layton | e545937 | 2007-11-03 05:11:06 +0000 | [diff] [blame] | 615 | rc = 0; |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 616 | else |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 617 | rc = -EINVAL; |
Shirish Pargaonkar | 2b149f1 | 2010-09-18 22:02:18 -0500 | [diff] [blame] | 618 | if (server->secType == Kerberos) { |
| 619 | if (!server->sec_kerberos && |
| 620 | !server->sec_mskerberos) |
| 621 | rc = -EOPNOTSUPP; |
| 622 | } else if (server->secType == RawNTLMSSP) { |
| 623 | if (!server->sec_ntlmssp) |
| 624 | rc = -EOPNOTSUPP; |
| 625 | } else |
| 626 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 628 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 629 | rc = -EIO; /* no crypt key only if plain text pwd */ |
| 630 | goto neg_err_exit; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 631 | } else |
| 632 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
| 633 | |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 634 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 635 | signing_check: |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 636 | #endif |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 637 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
| 638 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
| 639 | so if this is zero it means that signing is disabled */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 640 | cFYI(1, "Signing disabled"); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 641 | if (server->sec_mode & SECMODE_SIGN_REQUIRED) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 642 | cERROR(1, "Server requires " |
Jeff Layton | 7111d21 | 2007-10-16 16:50:25 +0000 | [diff] [blame] | 643 | "packet signing to be enabled in " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 644 | "/proc/fs/cifs/SecurityFlags."); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 645 | rc = -EOPNOTSUPP; |
| 646 | } |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 647 | server->sec_mode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 648 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 649 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
| 650 | /* signing required */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 651 | cFYI(1, "Must sign - secFlags 0x%x", secFlags); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 652 | if ((server->sec_mode & |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 653 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 654 | cERROR(1, "signing required but server lacks support"); |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 655 | rc = -EOPNOTSUPP; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 656 | } else |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 657 | server->sec_mode |= SECMODE_SIGN_REQUIRED; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 658 | } else { |
| 659 | /* signing optional ie CIFSSEC_MAY_SIGN */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 660 | if ((server->sec_mode & SECMODE_SIGN_REQUIRED) == 0) |
| 661 | server->sec_mode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 662 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 664 | |
| 665 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 666 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 667 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 668 | cFYI(1, "negprot rc %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | return rc; |
| 670 | } |
| 671 | |
| 672 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 673 | CIFSSMBTDis(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | { |
| 675 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 678 | cFYI(1, "In tree disconnect"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 679 | |
| 680 | /* BB: do we need to check this? These should never be NULL. */ |
| 681 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 682 | return -EIO; |
| 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 685 | * No need to return error on this operation if tid invalidated and |
| 686 | * closed on server already e.g. due to tcp session crashing. Also, |
| 687 | * the tcon is no longer on the list, so no need to take lock before |
| 688 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 690 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 691 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 693 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 694 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 695 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 697 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 698 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 700 | cFYI(1, "Tree disconnect failed %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 702 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 703 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | if (rc == -EAGAIN) |
| 705 | rc = 0; |
| 706 | |
| 707 | return rc; |
| 708 | } |
| 709 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 710 | /* |
| 711 | * This is a no-op for now. We're not really interested in the reply, but |
| 712 | * rather in the fact that the server sent one and that server->lstrp |
| 713 | * gets updated. |
| 714 | * |
| 715 | * FIXME: maybe we should consider checking that the reply matches request? |
| 716 | */ |
| 717 | static void |
| 718 | cifs_echo_callback(struct mid_q_entry *mid) |
| 719 | { |
| 720 | struct TCP_Server_Info *server = mid->callback_data; |
| 721 | |
| 722 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 723 | cifs_add_credits(server, 1); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | int |
| 727 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 728 | { |
| 729 | ECHO_REQ *smb; |
| 730 | int rc = 0; |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 731 | struct kvec iov; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 732 | |
| 733 | cFYI(1, "In echo request"); |
| 734 | |
| 735 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 736 | if (rc) |
| 737 | return rc; |
| 738 | |
| 739 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 740 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8 | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 741 | smb->hdr.WordCount = 1; |
| 742 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 743 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 744 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 745 | inc_rfc1001_len(smb, 3); |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 746 | iov.iov_base = smb; |
| 747 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 748 | |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 749 | rc = cifs_call_async(server, &iov, 1, NULL, cifs_echo_callback, |
| 750 | server, true); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 751 | if (rc) |
| 752 | cFYI(1, "Echo request failed: %d", rc); |
| 753 | |
| 754 | cifs_small_buf_release(smb); |
| 755 | |
| 756 | return rc; |
| 757 | } |
| 758 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 760 | CIFSSMBLogoff(const int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | LOGOFF_ANDX_REQ *pSMB; |
| 763 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 765 | cFYI(1, "In SMBLogoff for session disconnect"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 766 | |
| 767 | /* |
| 768 | * BB: do we need to check validity of ses and server? They should |
| 769 | * always be valid since we have an active reference. If not, that |
| 770 | * should probably be a BUG() |
| 771 | */ |
| 772 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | return -EIO; |
| 774 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 775 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 776 | if (ses->need_reconnect) |
| 777 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 778 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 780 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 781 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | return rc; |
| 783 | } |
| 784 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 785 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 786 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 787 | if (ses->server->sec_mode & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 789 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | pSMB->hdr.Uid = ses->Suid; |
| 792 | |
| 793 | pSMB->AndXCommand = 0xFF; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 794 | rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 795 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 796 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
| 798 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 799 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | error */ |
| 801 | if (rc == -EAGAIN) |
| 802 | rc = 0; |
| 803 | return rc; |
| 804 | } |
| 805 | |
| 806 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 807 | CIFSPOSIXDelFile(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 808 | __u16 type, const struct nls_table *nls_codepage, int remap) |
| 809 | { |
| 810 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 811 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 812 | struct unlink_psx_rq *pRqD; |
| 813 | int name_len; |
| 814 | int rc = 0; |
| 815 | int bytes_returned = 0; |
| 816 | __u16 params, param_offset, offset, byte_count; |
| 817 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 818 | cFYI(1, "In POSIX delete"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 819 | PsxDelete: |
| 820 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 821 | (void **) &pSMBr); |
| 822 | if (rc) |
| 823 | return rc; |
| 824 | |
| 825 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 826 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 827 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 828 | PATH_MAX, nls_codepage, remap); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 829 | name_len++; /* trailing null */ |
| 830 | name_len *= 2; |
| 831 | } else { /* BB add path length overrun check */ |
| 832 | name_len = strnlen(fileName, PATH_MAX); |
| 833 | name_len++; /* trailing null */ |
| 834 | strncpy(pSMB->FileName, fileName, name_len); |
| 835 | } |
| 836 | |
| 837 | params = 6 + name_len; |
| 838 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 839 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 840 | pSMB->MaxSetupCount = 0; |
| 841 | pSMB->Reserved = 0; |
| 842 | pSMB->Flags = 0; |
| 843 | pSMB->Timeout = 0; |
| 844 | pSMB->Reserved2 = 0; |
| 845 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 846 | InformationLevel) - 4; |
| 847 | offset = param_offset + params; |
| 848 | |
| 849 | /* Setup pointer to Request Data (inode type) */ |
| 850 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 851 | pRqD->type = cpu_to_le16(type); |
| 852 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 853 | pSMB->DataOffset = cpu_to_le16(offset); |
| 854 | pSMB->SetupCount = 1; |
| 855 | pSMB->Reserved3 = 0; |
| 856 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 857 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 858 | |
| 859 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 860 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 861 | pSMB->ParameterCount = cpu_to_le16(params); |
| 862 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 863 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 864 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 865 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 866 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 867 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 868 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 869 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 870 | cFYI(1, "Posix delete returned %d", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 871 | cifs_buf_release(pSMB); |
| 872 | |
| 873 | cifs_stats_inc(&tcon->num_deletes); |
| 874 | |
| 875 | if (rc == -EAGAIN) |
| 876 | goto PsxDelete; |
| 877 | |
| 878 | return rc; |
| 879 | } |
| 880 | |
| 881 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 882 | CIFSSMBDelFile(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 883 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | { |
| 885 | DELETE_FILE_REQ *pSMB = NULL; |
| 886 | DELETE_FILE_RSP *pSMBr = NULL; |
| 887 | int rc = 0; |
| 888 | int bytes_returned; |
| 889 | int name_len; |
| 890 | |
| 891 | DelFileRetry: |
| 892 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 893 | (void **) &pSMBr); |
| 894 | if (rc) |
| 895 | return rc; |
| 896 | |
| 897 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 898 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 899 | cifsConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 900 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | name_len++; /* trailing null */ |
| 902 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 903 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | name_len = strnlen(fileName, PATH_MAX); |
| 905 | name_len++; /* trailing null */ |
| 906 | strncpy(pSMB->fileName, fileName, name_len); |
| 907 | } |
| 908 | pSMB->SearchAttributes = |
| 909 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 910 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 911 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 913 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 914 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 915 | cifs_stats_inc(&tcon->num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 916 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 917 | cFYI(1, "Error in RMFile = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
| 919 | cifs_buf_release(pSMB); |
| 920 | if (rc == -EAGAIN) |
| 921 | goto DelFileRetry; |
| 922 | |
| 923 | return rc; |
| 924 | } |
| 925 | |
| 926 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 927 | CIFSSMBRmDir(const int xid, struct cifs_tcon *tcon, const char *dirName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 928 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { |
| 930 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 931 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 932 | int rc = 0; |
| 933 | int bytes_returned; |
| 934 | int name_len; |
| 935 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 936 | cFYI(1, "In CIFSSMBRmDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | RmDirRetry: |
| 938 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 939 | (void **) &pSMBr); |
| 940 | if (rc) |
| 941 | return rc; |
| 942 | |
| 943 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 944 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, dirName, |
| 945 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | name_len++; /* trailing null */ |
| 947 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 948 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | name_len = strnlen(dirName, PATH_MAX); |
| 950 | name_len++; /* trailing null */ |
| 951 | strncpy(pSMB->DirName, dirName, name_len); |
| 952 | } |
| 953 | |
| 954 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 955 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 957 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 958 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 959 | cifs_stats_inc(&tcon->num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 960 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 961 | cFYI(1, "Error in RMDir = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | |
| 963 | cifs_buf_release(pSMB); |
| 964 | if (rc == -EAGAIN) |
| 965 | goto RmDirRetry; |
| 966 | return rc; |
| 967 | } |
| 968 | |
| 969 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 970 | CIFSSMBMkDir(const int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 971 | const char *name, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | { |
| 973 | int rc = 0; |
| 974 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 975 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 976 | int bytes_returned; |
| 977 | int name_len; |
| 978 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 979 | cFYI(1, "In CIFSSMBMkDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | MkDirRetry: |
| 981 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 982 | (void **) &pSMBr); |
| 983 | if (rc) |
| 984 | return rc; |
| 985 | |
| 986 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 987 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
| 988 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | name_len++; /* trailing null */ |
| 990 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 991 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | name_len = strnlen(name, PATH_MAX); |
| 993 | name_len++; /* trailing null */ |
| 994 | strncpy(pSMB->DirName, name, name_len); |
| 995 | } |
| 996 | |
| 997 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 998 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1000 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1001 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1002 | cifs_stats_inc(&tcon->num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1003 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1004 | cFYI(1, "Error in Mkdir = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | cifs_buf_release(pSMB); |
| 1007 | if (rc == -EAGAIN) |
| 1008 | goto MkDirRetry; |
| 1009 | return rc; |
| 1010 | } |
| 1011 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1012 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1013 | CIFSPOSIXCreate(const int xid, struct cifs_tcon *tcon, __u32 posix_flags, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1014 | __u64 mode, __u16 *netfid, FILE_UNIX_BASIC_INFO *pRetData, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1015 | __u32 *pOplock, const char *name, |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1016 | const struct nls_table *nls_codepage, int remap) |
| 1017 | { |
| 1018 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1019 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1020 | int name_len; |
| 1021 | int rc = 0; |
| 1022 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1023 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1024 | OPEN_PSX_REQ *pdata; |
| 1025 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1026 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1027 | cFYI(1, "In POSIX Create"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1028 | PsxCreat: |
| 1029 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1030 | (void **) &pSMBr); |
| 1031 | if (rc) |
| 1032 | return rc; |
| 1033 | |
| 1034 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1035 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1036 | cifsConvertToUTF16((__le16 *) pSMB->FileName, name, |
| 1037 | PATH_MAX, nls_codepage, remap); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1038 | name_len++; /* trailing null */ |
| 1039 | name_len *= 2; |
| 1040 | } else { /* BB improve the check for buffer overruns BB */ |
| 1041 | name_len = strnlen(name, PATH_MAX); |
| 1042 | name_len++; /* trailing null */ |
| 1043 | strncpy(pSMB->FileName, name, name_len); |
| 1044 | } |
| 1045 | |
| 1046 | params = 6 + name_len; |
| 1047 | count = sizeof(OPEN_PSX_REQ); |
| 1048 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1049 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1050 | pSMB->MaxSetupCount = 0; |
| 1051 | pSMB->Reserved = 0; |
| 1052 | pSMB->Flags = 0; |
| 1053 | pSMB->Timeout = 0; |
| 1054 | pSMB->Reserved2 = 0; |
| 1055 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1056 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1057 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1058 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1059 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1060 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1061 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1062 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1063 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1064 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1065 | pSMB->SetupCount = 1; |
| 1066 | pSMB->Reserved3 = 0; |
| 1067 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1068 | byte_count = 3 /* pad */ + params + count; |
| 1069 | |
| 1070 | pSMB->DataCount = cpu_to_le16(count); |
| 1071 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1072 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1073 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1074 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1075 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1076 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1077 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1078 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1079 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1080 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1081 | cFYI(1, "Posix create returned %d", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1082 | goto psx_create_err; |
| 1083 | } |
| 1084 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1085 | cFYI(1, "copying inode info"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1086 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1087 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1088 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1089 | rc = -EIO; /* bad smb */ |
| 1090 | goto psx_create_err; |
| 1091 | } |
| 1092 | |
| 1093 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1094 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1095 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1096 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1097 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1098 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1099 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1100 | /* Let caller know file was created so we can set the mode. */ |
| 1101 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1102 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1103 | *pOplock |= CIFS_CREATE_ACTION; |
| 1104 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1105 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1106 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1107 | cFYI(DBG2, "unknown type"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1108 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1109 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1110 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1111 | cERROR(1, "Open response data too small"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1112 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1113 | goto psx_create_err; |
| 1114 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1115 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1116 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1117 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1118 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1119 | |
| 1120 | psx_create_err: |
| 1121 | cifs_buf_release(pSMB); |
| 1122 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1123 | if (posix_flags & SMB_O_DIRECTORY) |
| 1124 | cifs_stats_inc(&tcon->num_posixmkdirs); |
| 1125 | else |
| 1126 | cifs_stats_inc(&tcon->num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1127 | |
| 1128 | if (rc == -EAGAIN) |
| 1129 | goto PsxCreat; |
| 1130 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1131 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1134 | static __u16 convert_disposition(int disposition) |
| 1135 | { |
| 1136 | __u16 ofun = 0; |
| 1137 | |
| 1138 | switch (disposition) { |
| 1139 | case FILE_SUPERSEDE: |
| 1140 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1141 | break; |
| 1142 | case FILE_OPEN: |
| 1143 | ofun = SMBOPEN_OAPPEND; |
| 1144 | break; |
| 1145 | case FILE_CREATE: |
| 1146 | ofun = SMBOPEN_OCREATE; |
| 1147 | break; |
| 1148 | case FILE_OPEN_IF: |
| 1149 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1150 | break; |
| 1151 | case FILE_OVERWRITE: |
| 1152 | ofun = SMBOPEN_OTRUNC; |
| 1153 | break; |
| 1154 | case FILE_OVERWRITE_IF: |
| 1155 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1156 | break; |
| 1157 | default: |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1158 | cFYI(1, "unknown disposition %d", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1159 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1160 | } |
| 1161 | return ofun; |
| 1162 | } |
| 1163 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1164 | static int |
| 1165 | access_flags_to_smbopen_mode(const int access_flags) |
| 1166 | { |
| 1167 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1168 | |
| 1169 | if (masked_flags == GENERIC_READ) |
| 1170 | return SMBOPEN_READ; |
| 1171 | else if (masked_flags == GENERIC_WRITE) |
| 1172 | return SMBOPEN_WRITE; |
| 1173 | |
| 1174 | /* just go for read/write */ |
| 1175 | return SMBOPEN_READWRITE; |
| 1176 | } |
| 1177 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1178 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1179 | SMBLegacyOpen(const int xid, struct cifs_tcon *tcon, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1180 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1181 | const int access_flags, const int create_options, __u16 *netfid, |
| 1182 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1183 | const struct nls_table *nls_codepage, int remap) |
| 1184 | { |
| 1185 | int rc = -EACCES; |
| 1186 | OPENX_REQ *pSMB = NULL; |
| 1187 | OPENX_RSP *pSMBr = NULL; |
| 1188 | int bytes_returned; |
| 1189 | int name_len; |
| 1190 | __u16 count; |
| 1191 | |
| 1192 | OldOpenRetry: |
| 1193 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1194 | (void **) &pSMBr); |
| 1195 | if (rc) |
| 1196 | return rc; |
| 1197 | |
| 1198 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1199 | |
| 1200 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1201 | count = 1; /* account for one byte pad to word boundary */ |
| 1202 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1203 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1204 | fileName, PATH_MAX, nls_codepage, remap); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1205 | name_len++; /* trailing null */ |
| 1206 | name_len *= 2; |
| 1207 | } else { /* BB improve check for buffer overruns BB */ |
| 1208 | count = 0; /* no pad */ |
| 1209 | name_len = strnlen(fileName, PATH_MAX); |
| 1210 | name_len++; /* trailing null */ |
| 1211 | strncpy(pSMB->fileName, fileName, name_len); |
| 1212 | } |
| 1213 | if (*pOplock & REQ_OPLOCK) |
| 1214 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1215 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1216 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1217 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1218 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1219 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1220 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1221 | /* set file as system file if special file such |
| 1222 | as fifo and server expecting SFU style and |
| 1223 | no Unix extensions */ |
| 1224 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1225 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1226 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1227 | else /* BB FIXME BB */ |
| 1228 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1229 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1230 | if (create_options & CREATE_OPTION_READONLY) |
| 1231 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1232 | |
| 1233 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1234 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1235 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1236 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1237 | |
| 1238 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1239 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1240 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1241 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1242 | |
| 1243 | pSMB->ByteCount = cpu_to_le16(count); |
| 1244 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1245 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1246 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1247 | cifs_stats_inc(&tcon->num_opens); |
| 1248 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1249 | cFYI(1, "Error in Open = %d", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1250 | } else { |
| 1251 | /* BB verify if wct == 15 */ |
| 1252 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1253 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1254 | |
| 1255 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1256 | /* Let caller know file was created so we can set the mode. */ |
| 1257 | /* Do we care about the CreateAction in any other cases? */ |
| 1258 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1259 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1260 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1261 | /* BB FIXME END */ |
| 1262 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1263 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1264 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1265 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1266 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1267 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1268 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1269 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1270 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1271 | pfile_info->AllocationSize = |
| 1272 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1273 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1274 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1275 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | cifs_buf_release(pSMB); |
| 1280 | if (rc == -EAGAIN) |
| 1281 | goto OldOpenRetry; |
| 1282 | return rc; |
| 1283 | } |
| 1284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1286 | CIFSSMBOpen(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1288 | const int access_flags, const int create_options, __u16 *netfid, |
| 1289 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1290 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | { |
| 1292 | int rc = -EACCES; |
| 1293 | OPEN_REQ *pSMB = NULL; |
| 1294 | OPEN_RSP *pSMBr = NULL; |
| 1295 | int bytes_returned; |
| 1296 | int name_len; |
| 1297 | __u16 count; |
| 1298 | |
| 1299 | openRetry: |
| 1300 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, |
| 1301 | (void **) &pSMBr); |
| 1302 | if (rc) |
| 1303 | return rc; |
| 1304 | |
| 1305 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1306 | |
| 1307 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1308 | count = 1; /* account for one byte pad to word boundary */ |
| 1309 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1310 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1311 | fileName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | name_len++; /* trailing null */ |
| 1313 | name_len *= 2; |
| 1314 | pSMB->NameLength = cpu_to_le16(name_len); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1315 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | count = 0; /* no pad */ |
| 1317 | name_len = strnlen(fileName, PATH_MAX); |
| 1318 | name_len++; /* trailing null */ |
| 1319 | pSMB->NameLength = cpu_to_le16(name_len); |
| 1320 | strncpy(pSMB->fileName, fileName, name_len); |
| 1321 | } |
| 1322 | if (*pOplock & REQ_OPLOCK) |
| 1323 | pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1324 | else if (*pOplock & REQ_BATCHOPLOCK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | pSMB->DesiredAccess = cpu_to_le32(access_flags); |
| 1327 | pSMB->AllocationSize = 0; |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1328 | /* set file as system file if special file such |
| 1329 | as fifo and server expecting SFU style and |
| 1330 | no Unix extensions */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1331 | if (create_options & CREATE_OPTION_SPECIAL) |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1332 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1333 | else |
| 1334 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | /* XP does not handle ATTR_POSIX_SEMANTICS */ |
| 1337 | /* but it helps speed up case sensitive checks for other |
| 1338 | servers such as Samba */ |
| 1339 | if (tcon->ses->capabilities & CAP_UNIX) |
| 1340 | pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
| 1341 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1342 | if (create_options & CREATE_OPTION_READONLY) |
| 1343 | pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
| 1344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1346 | pSMB->CreateDisposition = cpu_to_le32(openDisposition); |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1347 | pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1348 | /* BB Expirement with various impersonation levels and verify */ |
| 1349 | pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | pSMB->SecurityFlags = |
| 1351 | SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY; |
| 1352 | |
| 1353 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1354 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | |
| 1356 | pSMB->ByteCount = cpu_to_le16(count); |
| 1357 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1358 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1359 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1360 | cifs_stats_inc(&tcon->num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1362 | cFYI(1, "Error in Open = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | } else { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1364 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1366 | /* Let caller know file was created so we can set the mode. */ |
| 1367 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1368 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1369 | *pOplock |= CIFS_CREATE_ACTION; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1370 | if (pfile_info) { |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1371 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
| 1372 | 36 /* CreationTime to Attributes */); |
| 1373 | /* the file_info buf is endian converted by caller */ |
| 1374 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
| 1375 | pfile_info->EndOfFile = pSMBr->EndOfFile; |
| 1376 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
| 1377 | pfile_info->DeletePending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | cifs_buf_release(pSMB); |
| 1382 | if (rc == -EAGAIN) |
| 1383 | goto openRetry; |
| 1384 | return rc; |
| 1385 | } |
| 1386 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1387 | /* |
| 1388 | * Discard any remaining data in the current SMB. To do this, we borrow the |
| 1389 | * current bigbuf. |
| 1390 | */ |
| 1391 | static int |
| 1392 | cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1393 | { |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1394 | unsigned int rfclen = get_rfc1002_length(server->smallbuf); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1395 | int remaining = rfclen + 4 - server->total_read; |
| 1396 | struct cifs_readdata *rdata = mid->callback_data; |
| 1397 | |
| 1398 | while (remaining > 0) { |
| 1399 | int length; |
| 1400 | |
| 1401 | length = cifs_read_from_socket(server, server->bigbuf, |
| 1402 | min_t(unsigned int, remaining, |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1403 | CIFSMaxBufSize + max_header_size())); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1404 | if (length < 0) |
| 1405 | return length; |
| 1406 | server->total_read += length; |
| 1407 | remaining -= length; |
| 1408 | } |
| 1409 | |
| 1410 | dequeue_mid(mid, rdata->result); |
| 1411 | return 0; |
| 1412 | } |
| 1413 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1414 | static inline size_t |
| 1415 | read_rsp_size(void) |
| 1416 | { |
| 1417 | return sizeof(READ_RSP); |
| 1418 | } |
| 1419 | |
| 1420 | static inline unsigned int |
| 1421 | read_data_offset(char *buf) |
| 1422 | { |
| 1423 | READ_RSP *rsp = (READ_RSP *)buf; |
| 1424 | return le16_to_cpu(rsp->DataOffset); |
| 1425 | } |
| 1426 | |
| 1427 | static inline unsigned int |
| 1428 | read_data_length(char *buf) |
| 1429 | { |
| 1430 | READ_RSP *rsp = (READ_RSP *)buf; |
| 1431 | return (le16_to_cpu(rsp->DataLengthHigh) << 16) + |
| 1432 | le16_to_cpu(rsp->DataLength); |
| 1433 | } |
| 1434 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1435 | static int |
| 1436 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1437 | { |
| 1438 | int length, len; |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1439 | unsigned int data_offset, data_len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1440 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1441 | char *buf = server->smallbuf; |
| 1442 | unsigned int buflen = get_rfc1002_length(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1443 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1444 | cFYI(1, "%s: mid=%llu offset=%llu bytes=%u", __func__, |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1445 | mid->mid, rdata->offset, rdata->bytes); |
| 1446 | |
| 1447 | /* |
| 1448 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1449 | * can if there's not enough data. At this point, we've read down to |
| 1450 | * the Mid. |
| 1451 | */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1452 | len = min_t(unsigned int, buflen, read_rsp_size()) - header_size() + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1453 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1454 | rdata->iov[0].iov_base = buf + header_size() - 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1455 | rdata->iov[0].iov_len = len; |
| 1456 | |
| 1457 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); |
| 1458 | if (length < 0) |
| 1459 | return length; |
| 1460 | server->total_read += length; |
| 1461 | |
| 1462 | /* Was the SMB read successful? */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1463 | rdata->result = map_smb_to_linux_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1464 | if (rdata->result != 0) { |
| 1465 | cFYI(1, "%s: server returned error %d", __func__, |
| 1466 | rdata->result); |
| 1467 | return cifs_readv_discard(server, mid); |
| 1468 | } |
| 1469 | |
| 1470 | /* Is there enough to get to the rest of the READ_RSP header? */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1471 | if (server->total_read < read_rsp_size()) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1472 | cFYI(1, "%s: server returned short header. got=%u expected=%zu", |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1473 | __func__, server->total_read, read_rsp_size()); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1474 | rdata->result = -EIO; |
| 1475 | return cifs_readv_discard(server, mid); |
| 1476 | } |
| 1477 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1478 | data_offset = read_data_offset(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1479 | if (data_offset < server->total_read) { |
| 1480 | /* |
| 1481 | * win2k8 sometimes sends an offset of 0 when the read |
| 1482 | * is beyond the EOF. Treat it as if the data starts just after |
| 1483 | * the header. |
| 1484 | */ |
| 1485 | cFYI(1, "%s: data offset (%u) inside read response header", |
| 1486 | __func__, data_offset); |
| 1487 | data_offset = server->total_read; |
| 1488 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1489 | /* data_offset is beyond the end of smallbuf */ |
| 1490 | cFYI(1, "%s: data offset (%u) beyond end of smallbuf", |
| 1491 | __func__, data_offset); |
| 1492 | rdata->result = -EIO; |
| 1493 | return cifs_readv_discard(server, mid); |
| 1494 | } |
| 1495 | |
| 1496 | cFYI(1, "%s: total_read=%u data_offset=%u", __func__, |
| 1497 | server->total_read, data_offset); |
| 1498 | |
| 1499 | len = data_offset - server->total_read; |
| 1500 | if (len > 0) { |
| 1501 | /* read any junk before data into the rest of smallbuf */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1502 | rdata->iov[0].iov_base = buf + server->total_read; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1503 | rdata->iov[0].iov_len = len; |
| 1504 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); |
| 1505 | if (length < 0) |
| 1506 | return length; |
| 1507 | server->total_read += length; |
| 1508 | } |
| 1509 | |
| 1510 | /* set up first iov for signature check */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1511 | rdata->iov[0].iov_base = buf; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1512 | rdata->iov[0].iov_len = server->total_read; |
| 1513 | cFYI(1, "0: iov_base=%p iov_len=%zu", |
| 1514 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); |
| 1515 | |
| 1516 | /* how much data is in the response? */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1517 | data_len = read_data_length(buf); |
| 1518 | if (data_offset + data_len > buflen) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1519 | /* data_len is corrupt -- discard frame */ |
| 1520 | rdata->result = -EIO; |
| 1521 | return cifs_readv_discard(server, mid); |
| 1522 | } |
| 1523 | |
| 1524 | /* marshal up the page array */ |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1525 | len = rdata->marshal_iov(rdata, data_len); |
| 1526 | data_len -= len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1527 | |
| 1528 | /* issue the read if we have any iovecs left to fill */ |
| 1529 | if (rdata->nr_iov > 1) { |
| 1530 | length = cifs_readv_from_socket(server, &rdata->iov[1], |
| 1531 | rdata->nr_iov - 1, len); |
| 1532 | if (length < 0) |
| 1533 | return length; |
| 1534 | server->total_read += length; |
| 1535 | } else { |
| 1536 | length = 0; |
| 1537 | } |
| 1538 | |
| 1539 | rdata->bytes = length; |
| 1540 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1541 | cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read, |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1542 | buflen, data_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1543 | |
| 1544 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1545 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1546 | return cifs_readv_discard(server, mid); |
| 1547 | |
| 1548 | dequeue_mid(mid, false); |
| 1549 | return length; |
| 1550 | } |
| 1551 | |
| 1552 | static void |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1553 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1554 | { |
| 1555 | struct cifs_readdata *rdata = mid->callback_data; |
| 1556 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1557 | struct TCP_Server_Info *server = tcon->ses->server; |
| 1558 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1559 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, |
| 1560 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1561 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1562 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1563 | case MID_RESPONSE_RECEIVED: |
| 1564 | /* result already set, check signature */ |
| 1565 | if (server->sec_mode & |
| 1566 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
| 1567 | if (cifs_verify_signature(rdata->iov, rdata->nr_iov, |
| 1568 | server, mid->sequence_number + 1)) |
| 1569 | cERROR(1, "Unexpected SMB signature"); |
| 1570 | } |
| 1571 | /* FIXME: should this be counted toward the initiating task? */ |
| 1572 | task_io_account_read(rdata->bytes); |
| 1573 | cifs_stats_bytes_read(tcon, rdata->bytes); |
| 1574 | break; |
| 1575 | case MID_REQUEST_SUBMITTED: |
| 1576 | case MID_RETRY_NEEDED: |
| 1577 | rdata->result = -EAGAIN; |
| 1578 | break; |
| 1579 | default: |
| 1580 | rdata->result = -EIO; |
| 1581 | } |
| 1582 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1583 | queue_work(cifsiod_wq, &rdata->work); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1584 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 1585 | cifs_add_credits(server, 1); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1589 | int |
| 1590 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1591 | { |
| 1592 | int rc; |
| 1593 | READ_REQ *smb = NULL; |
| 1594 | int wct; |
| 1595 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1596 | |
| 1597 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, |
| 1598 | rdata->offset, rdata->bytes); |
| 1599 | |
| 1600 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1601 | wct = 12; |
| 1602 | else { |
| 1603 | wct = 10; /* old style read */ |
| 1604 | if ((rdata->offset >> 32) > 0) { |
| 1605 | /* can not handle this big offset for old */ |
| 1606 | return -EIO; |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1611 | if (rc) |
| 1612 | return rc; |
| 1613 | |
| 1614 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1615 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1616 | |
| 1617 | smb->AndXCommand = 0xFF; /* none */ |
| 1618 | smb->Fid = rdata->cfile->netfid; |
| 1619 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1620 | if (wct == 12) |
| 1621 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1622 | smb->Remaining = 0; |
| 1623 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1624 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1625 | if (wct == 12) |
| 1626 | smb->ByteCount = 0; |
| 1627 | else { |
| 1628 | /* old style read */ |
| 1629 | struct smb_com_readx_req *smbr = |
| 1630 | (struct smb_com_readx_req *)smb; |
| 1631 | smbr->ByteCount = 0; |
| 1632 | } |
| 1633 | |
| 1634 | /* 4 for RFC1001 length + 1 for BCC */ |
| 1635 | rdata->iov[0].iov_base = smb; |
| 1636 | rdata->iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
| 1637 | |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1638 | kref_get(&rdata->refcount); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1639 | rc = cifs_call_async(tcon->ses->server, rdata->iov, 1, |
| 1640 | cifs_readv_receive, cifs_readv_callback, |
| 1641 | rdata, false); |
| 1642 | |
| 1643 | if (rc == 0) |
| 1644 | cifs_stats_inc(&tcon->num_reads); |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1645 | else |
| 1646 | kref_put(&rdata->refcount, cifs_readdata_release); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1647 | |
| 1648 | cifs_small_buf_release(smb); |
| 1649 | return rc; |
| 1650 | } |
| 1651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | int |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1653 | CIFSSMBRead(const int xid, struct cifs_io_parms *io_parms, unsigned int *nbytes, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1654 | char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | { |
| 1656 | int rc = -EACCES; |
| 1657 | READ_REQ *pSMB = NULL; |
| 1658 | READ_RSP *pSMBr = NULL; |
| 1659 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1660 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1661 | int resp_buf_type = 0; |
| 1662 | struct kvec iov[1]; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1663 | __u32 pid = io_parms->pid; |
| 1664 | __u16 netfid = io_parms->netfid; |
| 1665 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1666 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1667 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1669 | cFYI(1, "Reading %d bytes on fid %d", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1670 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1671 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1672 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1673 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1674 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1675 | /* can not handle this big offset for old */ |
| 1676 | return -EIO; |
| 1677 | } |
| 1678 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | |
| 1680 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1681 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | if (rc) |
| 1683 | return rc; |
| 1684 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1685 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1686 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | /* tcon and ses pointer are checked in smb_init */ |
| 1689 | if (tcon->ses->server == NULL) |
| 1690 | return -ECONNABORTED; |
| 1691 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1692 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1694 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1695 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1696 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | pSMB->Remaining = 0; |
| 1699 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1700 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1701 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1702 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1703 | else { |
| 1704 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1705 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1706 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1707 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1708 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1709 | |
| 1710 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1711 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4; |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 1712 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1713 | &resp_buf_type, CIFS_LOG_ERROR); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1714 | cifs_stats_inc(&tcon->num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1715 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1717 | cERROR(1, "Send error in read = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | } else { |
| 1719 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1720 | data_length = data_length << 16; |
| 1721 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1722 | *nbytes = data_length; |
| 1723 | |
| 1724 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1725 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | || (data_length > count)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1727 | cFYI(1, "bad length %d for count %d", |
| 1728 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | rc = -EIO; |
| 1730 | *nbytes = 0; |
| 1731 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1732 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1733 | le16_to_cpu(pSMBr->DataOffset); |
| 1734 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1735 | cERROR(1, "Faulting on read rc = %d",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1736 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1737 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1738 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1739 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
| 1741 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1743 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1744 | if (*buf) { |
| 1745 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1746 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1747 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1748 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1749 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1750 | /* return buffer to caller to free */ |
| 1751 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1752 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1753 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1754 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1755 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1756 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1757 | |
| 1758 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | since file handle passed in no longer valid */ |
| 1760 | return rc; |
| 1761 | } |
| 1762 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1765 | CIFSSMBWrite(const int xid, struct cifs_io_parms *io_parms, |
| 1766 | unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1767 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | { |
| 1769 | int rc = -EACCES; |
| 1770 | WRITE_REQ *pSMB = NULL; |
| 1771 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1772 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | __u32 bytes_sent; |
| 1774 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1775 | __u32 pid = io_parms->pid; |
| 1776 | __u16 netfid = io_parms->netfid; |
| 1777 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1778 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1779 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1781 | *nbytes = 0; |
| 1782 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1783 | /* cFYI(1, "write at %lld %d bytes", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1784 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1785 | return -ECONNABORTED; |
| 1786 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1787 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1788 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1789 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1790 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1791 | if ((offset >> 32) > 0) { |
| 1792 | /* can not handle big offset for old srv */ |
| 1793 | return -EIO; |
| 1794 | } |
| 1795 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1796 | |
| 1797 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | (void **) &pSMBr); |
| 1799 | if (rc) |
| 1800 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1801 | |
| 1802 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1803 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | /* tcon and ses pointer are checked in smb_init */ |
| 1806 | if (tcon->ses->server == NULL) |
| 1807 | return -ECONNABORTED; |
| 1808 | |
| 1809 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1810 | pSMB->Fid = netfid; |
| 1811 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1812 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1813 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | pSMB->Reserved = 0xFFFFFFFF; |
| 1816 | pSMB->WriteMode = 0; |
| 1817 | pSMB->Remaining = 0; |
| 1818 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1819 | /* Can increase buffer size if buffer is big enough in some cases ie we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1821 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1822 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1823 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1825 | } else { |
| 1826 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1827 | & ~0xFF; |
| 1828 | } |
| 1829 | |
| 1830 | if (bytes_sent > count) |
| 1831 | bytes_sent = count; |
| 1832 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1833 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1834 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1835 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1836 | else if (ubuf) { |
| 1837 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | cifs_buf_release(pSMB); |
| 1839 | return -EFAULT; |
| 1840 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1841 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | /* No buffer */ |
| 1843 | cifs_buf_release(pSMB); |
| 1844 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1845 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1846 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1847 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1848 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1849 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1852 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1853 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1854 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1855 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1856 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1857 | else { /* old style write has byte count 4 bytes earlier |
| 1858 | so 4 bytes pad */ |
| 1859 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1860 | (struct smb_com_writex_req *)pSMB; |
| 1861 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1862 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | |
| 1864 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1865 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1866 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 1868 | cFYI(1, "Send error in write = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | } else { |
| 1870 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1871 | *nbytes = (*nbytes) << 16; |
| 1872 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1873 | |
| 1874 | /* |
| 1875 | * Mask off high 16 bits when bytes written as returned by the |
| 1876 | * server is greater than bytes requested by the client. Some |
| 1877 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1878 | */ |
| 1879 | if (*nbytes > count) |
| 1880 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | cifs_buf_release(pSMB); |
| 1884 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1885 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | since file handle passed in no longer valid */ |
| 1887 | |
| 1888 | return rc; |
| 1889 | } |
| 1890 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1891 | void |
| 1892 | cifs_writedata_release(struct kref *refcount) |
| 1893 | { |
| 1894 | struct cifs_writedata *wdata = container_of(refcount, |
| 1895 | struct cifs_writedata, refcount); |
| 1896 | |
| 1897 | if (wdata->cfile) |
| 1898 | cifsFileInfo_put(wdata->cfile); |
| 1899 | |
| 1900 | kfree(wdata); |
| 1901 | } |
| 1902 | |
| 1903 | /* |
| 1904 | * Write failed with a retryable error. Resend the write request. It's also |
| 1905 | * possible that the page was redirtied so re-clean the page. |
| 1906 | */ |
| 1907 | static void |
| 1908 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 1909 | { |
| 1910 | int i, rc; |
| 1911 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1912 | |
| 1913 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1914 | lock_page(wdata->pages[i]); |
| 1915 | clear_page_dirty_for_io(wdata->pages[i]); |
| 1916 | } |
| 1917 | |
| 1918 | do { |
| 1919 | rc = cifs_async_writev(wdata); |
| 1920 | } while (rc == -EAGAIN); |
| 1921 | |
| 1922 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1923 | if (rc != 0) |
| 1924 | SetPageError(wdata->pages[i]); |
| 1925 | unlock_page(wdata->pages[i]); |
| 1926 | } |
| 1927 | |
| 1928 | mapping_set_error(inode->i_mapping, rc); |
| 1929 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1930 | } |
| 1931 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 1932 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1933 | cifs_writev_complete(struct work_struct *work) |
| 1934 | { |
| 1935 | struct cifs_writedata *wdata = container_of(work, |
| 1936 | struct cifs_writedata, work); |
| 1937 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1938 | int i = 0; |
| 1939 | |
| 1940 | if (wdata->result == 0) { |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1941 | spin_lock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1942 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1943 | spin_unlock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1944 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 1945 | wdata->bytes); |
| 1946 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 1947 | return cifs_writev_requeue(wdata); |
| 1948 | |
| 1949 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1950 | struct page *page = wdata->pages[i]; |
| 1951 | if (wdata->result == -EAGAIN) |
| 1952 | __set_page_dirty_nobuffers(page); |
| 1953 | else if (wdata->result < 0) |
| 1954 | SetPageError(page); |
| 1955 | end_page_writeback(page); |
| 1956 | page_cache_release(page); |
| 1957 | } |
| 1958 | if (wdata->result != -EAGAIN) |
| 1959 | mapping_set_error(inode->i_mapping, wdata->result); |
| 1960 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1961 | } |
| 1962 | |
| 1963 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 1964 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1965 | { |
| 1966 | struct cifs_writedata *wdata; |
| 1967 | |
| 1968 | /* this would overflow */ |
| 1969 | if (nr_pages == 0) { |
| 1970 | cERROR(1, "%s: called with nr_pages == 0!", __func__); |
| 1971 | return NULL; |
| 1972 | } |
| 1973 | |
| 1974 | /* writedata + number of page pointers */ |
| 1975 | wdata = kzalloc(sizeof(*wdata) + |
| 1976 | sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); |
| 1977 | if (wdata != NULL) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1978 | kref_init(&wdata->refcount); |
Jeff Layton | da82f7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1979 | INIT_LIST_HEAD(&wdata->list); |
| 1980 | init_completion(&wdata->done); |
| 1981 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1982 | } |
| 1983 | return wdata; |
| 1984 | } |
| 1985 | |
| 1986 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1987 | * Check the mid_state and signature on received buffer (if any), and queue the |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1988 | * workqueue completion task. |
| 1989 | */ |
| 1990 | static void |
| 1991 | cifs_writev_callback(struct mid_q_entry *mid) |
| 1992 | { |
| 1993 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1994 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1995 | unsigned int written; |
| 1996 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
| 1997 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1998 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1999 | case MID_RESPONSE_RECEIVED: |
| 2000 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 2001 | if (wdata->result != 0) |
| 2002 | break; |
| 2003 | |
| 2004 | written = le16_to_cpu(smb->CountHigh); |
| 2005 | written <<= 16; |
| 2006 | written += le16_to_cpu(smb->Count); |
| 2007 | /* |
| 2008 | * Mask off high 16 bits when bytes written as returned |
| 2009 | * by the server is greater than bytes requested by the |
| 2010 | * client. OS/2 servers are known to set incorrect |
| 2011 | * CountHigh values. |
| 2012 | */ |
| 2013 | if (written > wdata->bytes) |
| 2014 | written &= 0xFFFF; |
| 2015 | |
| 2016 | if (written < wdata->bytes) |
| 2017 | wdata->result = -ENOSPC; |
| 2018 | else |
| 2019 | wdata->bytes = written; |
| 2020 | break; |
| 2021 | case MID_REQUEST_SUBMITTED: |
| 2022 | case MID_RETRY_NEEDED: |
| 2023 | wdata->result = -EAGAIN; |
| 2024 | break; |
| 2025 | default: |
| 2026 | wdata->result = -EIO; |
| 2027 | break; |
| 2028 | } |
| 2029 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2030 | queue_work(cifsiod_wq, &wdata->work); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2031 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 2032 | cifs_add_credits(tcon->ses->server, 1); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2036 | int |
| 2037 | cifs_async_writev(struct cifs_writedata *wdata) |
| 2038 | { |
| 2039 | int i, rc = -EACCES; |
| 2040 | WRITE_REQ *smb = NULL; |
| 2041 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2042 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2043 | struct kvec *iov = NULL; |
| 2044 | |
| 2045 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2046 | wct = 14; |
| 2047 | } else { |
| 2048 | wct = 12; |
| 2049 | if (wdata->offset >> 32 > 0) { |
| 2050 | /* can not handle big offset for old srv */ |
| 2051 | return -EIO; |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2056 | if (rc) |
| 2057 | goto async_writev_out; |
| 2058 | |
| 2059 | /* 1 iov per page + 1 for header */ |
| 2060 | iov = kzalloc((wdata->nr_pages + 1) * sizeof(*iov), GFP_NOFS); |
| 2061 | if (iov == NULL) { |
| 2062 | rc = -ENOMEM; |
| 2063 | goto async_writev_out; |
| 2064 | } |
| 2065 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2066 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2067 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2068 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2069 | smb->AndXCommand = 0xFF; /* none */ |
| 2070 | smb->Fid = wdata->cfile->netfid; |
| 2071 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2072 | if (wct == 14) |
| 2073 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2074 | smb->Reserved = 0xFFFFFFFF; |
| 2075 | smb->WriteMode = 0; |
| 2076 | smb->Remaining = 0; |
| 2077 | |
| 2078 | smb->DataOffset = |
| 2079 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2080 | |
| 2081 | /* 4 for RFC1001 length + 1 for BCC */ |
| 2082 | iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; |
| 2083 | iov[0].iov_base = smb; |
| 2084 | |
Jeff Layton | e949287 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2085 | /* |
| 2086 | * This function should marshal up the page array into the kvec |
| 2087 | * array, reserving [0] for the header. It should kmap the pages |
| 2088 | * and set the iov_len properly for each one. It may also set |
| 2089 | * wdata->bytes too. |
| 2090 | */ |
| 2091 | wdata->marshal_iov(iov, wdata); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2092 | |
| 2093 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); |
| 2094 | |
| 2095 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2096 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2097 | |
| 2098 | if (wct == 14) { |
| 2099 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2100 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2101 | } else { |
| 2102 | /* wct == 12 */ |
| 2103 | struct smb_com_writex_req *smbw = |
| 2104 | (struct smb_com_writex_req *)smb; |
| 2105 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2106 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
| 2107 | iov[0].iov_len += 4; /* pad bigger by four bytes */ |
| 2108 | } |
| 2109 | |
| 2110 | kref_get(&wdata->refcount); |
| 2111 | rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1, |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 2112 | NULL, cifs_writev_callback, wdata, false); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2113 | |
| 2114 | if (rc == 0) |
| 2115 | cifs_stats_inc(&tcon->num_writes); |
| 2116 | else |
| 2117 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2118 | |
| 2119 | /* send is done, unmap pages */ |
| 2120 | for (i = 0; i < wdata->nr_pages; i++) |
| 2121 | kunmap(wdata->pages[i]); |
| 2122 | |
| 2123 | async_writev_out: |
| 2124 | cifs_small_buf_release(smb); |
| 2125 | kfree(iov); |
| 2126 | return rc; |
| 2127 | } |
| 2128 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2129 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2130 | CIFSSMBWrite2(const int xid, struct cifs_io_parms *io_parms, |
| 2131 | unsigned int *nbytes, struct kvec *iov, int n_vec, |
| 2132 | const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | { |
| 2134 | int rc = -EACCES; |
| 2135 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2136 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2137 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2138 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2139 | __u32 pid = io_parms->pid; |
| 2140 | __u16 netfid = io_parms->netfid; |
| 2141 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2142 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2143 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2145 | *nbytes = 0; |
| 2146 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2147 | cFYI(1, "write2 at %lld %d bytes", (long long)offset, count); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2148 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2149 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2150 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2151 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2152 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2153 | if ((offset >> 32) > 0) { |
| 2154 | /* can not handle big offset for old srv */ |
| 2155 | return -EIO; |
| 2156 | } |
| 2157 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2158 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | if (rc) |
| 2160 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2161 | |
| 2162 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2163 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | /* tcon and ses pointer are checked in smb_init */ |
| 2166 | if (tcon->ses->server == NULL) |
| 2167 | return -ECONNABORTED; |
| 2168 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2169 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | pSMB->Fid = netfid; |
| 2171 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2172 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2173 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | pSMB->Reserved = 0xFFFFFFFF; |
| 2175 | pSMB->WriteMode = 0; |
| 2176 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2179 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2181 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2182 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2183 | /* header + 1 byte pad */ |
| 2184 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2185 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2186 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2187 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2188 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2189 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2190 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2191 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2192 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2193 | (struct smb_com_writex_req *)pSMB; |
| 2194 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2195 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2196 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2197 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2198 | iov[0].iov_len = smb_hdr_len + 4; |
| 2199 | else /* wct == 12 pad bigger by four bytes */ |
| 2200 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2201 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2202 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2203 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2204 | long_op); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2205 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2207 | cFYI(1, "Send error Write2 = %d", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2208 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2209 | /* presumably this can not happen, but best to be safe */ |
| 2210 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2211 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2212 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2213 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2214 | *nbytes = (*nbytes) << 16; |
| 2215 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2216 | |
| 2217 | /* |
| 2218 | * Mask off high 16 bits when bytes written as returned by the |
| 2219 | * server is greater than bytes requested by the client. OS/2 |
| 2220 | * servers are known to set incorrect CountHigh values. |
| 2221 | */ |
| 2222 | if (*nbytes > count) |
| 2223 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2224 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 2226 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2227 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2228 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2229 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2230 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2232 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | since file handle passed in no longer valid */ |
| 2234 | |
| 2235 | return rc; |
| 2236 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2237 | |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2238 | int cifs_lockv(const int xid, struct cifs_tcon *tcon, const __u16 netfid, |
| 2239 | const __u8 lock_type, const __u32 num_unlock, |
| 2240 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2241 | { |
| 2242 | int rc = 0; |
| 2243 | LOCK_REQ *pSMB = NULL; |
| 2244 | struct kvec iov[2]; |
| 2245 | int resp_buf_type; |
| 2246 | __u16 count; |
| 2247 | |
| 2248 | cFYI(1, "cifs_lockv num lock %d num unlock %d", num_lock, num_unlock); |
| 2249 | |
| 2250 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2251 | if (rc) |
| 2252 | return rc; |
| 2253 | |
| 2254 | pSMB->Timeout = 0; |
| 2255 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2256 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2257 | pSMB->LockType = lock_type; |
| 2258 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2259 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2260 | |
| 2261 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2262 | inc_rfc1001_len(pSMB, count); |
| 2263 | pSMB->ByteCount = cpu_to_le16(count); |
| 2264 | |
| 2265 | iov[0].iov_base = (char *)pSMB; |
| 2266 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2267 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2268 | iov[1].iov_base = (char *)buf; |
| 2269 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2270 | |
| 2271 | cifs_stats_inc(&tcon->num_locks); |
| 2272 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP); |
| 2273 | if (rc) |
| 2274 | cFYI(1, "Send error in cifs_lockv = %d", rc); |
| 2275 | |
| 2276 | return rc; |
| 2277 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2280 | CIFSSMBLock(const int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2281 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2283 | const __u32 numLock, const __u8 lockType, |
| 2284 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | { |
| 2286 | int rc = 0; |
| 2287 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2288 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | int bytes_returned; |
| 2290 | int timeout = 0; |
| 2291 | __u16 count; |
| 2292 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2293 | cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2294 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | if (rc) |
| 2297 | return rc; |
| 2298 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2299 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2300 | timeout = CIFS_ASYNC_OP; /* no response expected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2302 | } else if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2303 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2305 | } else { |
| 2306 | pSMB->Timeout = 0; |
| 2307 | } |
| 2308 | |
| 2309 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2310 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2311 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2312 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2314 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2315 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2316 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2317 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | /* BB where to store pid high? */ |
| 2319 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2320 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2321 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2322 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2323 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2324 | } else { |
| 2325 | /* oplock break */ |
| 2326 | count = 0; |
| 2327 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2328 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | pSMB->ByteCount = cpu_to_le16(count); |
| 2330 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2331 | if (waitFlag) { |
| 2332 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2333 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2334 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2335 | } else { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2336 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, timeout); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2337 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2338 | } |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2339 | cifs_stats_inc(&tcon->num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2340 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2341 | cFYI(1, "Send error in Lock = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2343 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | since file handle passed in no longer valid */ |
| 2345 | return rc; |
| 2346 | } |
| 2347 | |
| 2348 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2349 | CIFSSMBPosixLock(const int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2350 | const __u16 smb_file_id, const __u32 netpid, const int get_flag, |
| 2351 | const __u64 len, struct file_lock *pLockData, |
| 2352 | const __u16 lock_type, const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2353 | { |
| 2354 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2355 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2356 | struct cifs_posix_lock *parm_data; |
| 2357 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2358 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2359 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2360 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2361 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2362 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2363 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2364 | cFYI(1, "Posix Lock"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2365 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2366 | if (pLockData == NULL) |
Marcin Slusarz | ed5f037 | 2008-05-13 04:01:01 +0000 | [diff] [blame] | 2367 | return -EINVAL; |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2368 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2369 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2370 | |
| 2371 | if (rc) |
| 2372 | return rc; |
| 2373 | |
| 2374 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2375 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2376 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2377 | pSMB->MaxSetupCount = 0; |
| 2378 | pSMB->Reserved = 0; |
| 2379 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2380 | pSMB->Reserved2 = 0; |
| 2381 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2382 | offset = param_offset + params; |
| 2383 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2384 | count = sizeof(struct cifs_posix_lock); |
| 2385 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2386 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2387 | pSMB->SetupCount = 1; |
| 2388 | pSMB->Reserved3 = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2389 | if (get_flag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2390 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2391 | else |
| 2392 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2393 | byte_count = 3 /* pad */ + params + count; |
| 2394 | pSMB->DataCount = cpu_to_le16(count); |
| 2395 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2396 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2397 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2398 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2399 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2400 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2401 | |
| 2402 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2403 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2404 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2405 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2406 | pSMB->Timeout = cpu_to_le32(-1); |
| 2407 | } else |
| 2408 | pSMB->Timeout = 0; |
| 2409 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2410 | parm_data->pid = cpu_to_le32(netpid); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2411 | parm_data->start = cpu_to_le64(pLockData->fl_start); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2412 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2413 | |
| 2414 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2415 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2416 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2417 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2418 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2419 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2420 | if (waitFlag) { |
| 2421 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2422 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2423 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2424 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2425 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2426 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 2427 | &resp_buf_type, timeout); |
| 2428 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 2429 | not try to free it twice below on exit */ |
| 2430 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2431 | } |
| 2432 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2433 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2434 | cFYI(1, "Send error in Posix Lock = %d", rc); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2435 | } else if (get_flag) { |
| 2436 | /* lock structure can be returned on get */ |
| 2437 | __u16 data_offset; |
| 2438 | __u16 data_count; |
| 2439 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2440 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2441 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2442 | rc = -EIO; /* bad smb */ |
| 2443 | goto plk_err_exit; |
| 2444 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2445 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2446 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2447 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2448 | rc = -EIO; |
| 2449 | goto plk_err_exit; |
| 2450 | } |
| 2451 | parm_data = (struct cifs_posix_lock *) |
| 2452 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2453 | if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2454 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2455 | else { |
| 2456 | if (parm_data->lock_type == |
| 2457 | __constant_cpu_to_le16(CIFS_RDLCK)) |
| 2458 | pLockData->fl_type = F_RDLCK; |
| 2459 | else if (parm_data->lock_type == |
| 2460 | __constant_cpu_to_le16(CIFS_WRLCK)) |
| 2461 | pLockData->fl_type = F_WRLCK; |
| 2462 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2463 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2464 | pLockData->fl_end = pLockData->fl_start + |
| 2465 | le64_to_cpu(parm_data->length) - 1; |
| 2466 | pLockData->fl_pid = le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2467 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2468 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2469 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2470 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2471 | if (pSMB) |
| 2472 | cifs_small_buf_release(pSMB); |
| 2473 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2474 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 2475 | cifs_small_buf_release(iov[0].iov_base); |
| 2476 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 2477 | cifs_buf_release(iov[0].iov_base); |
| 2478 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2479 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2480 | since file handle passed in no longer valid */ |
| 2481 | |
| 2482 | return rc; |
| 2483 | } |
| 2484 | |
| 2485 | |
| 2486 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2487 | CIFSSMBClose(const int xid, struct cifs_tcon *tcon, int smb_file_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | { |
| 2489 | int rc = 0; |
| 2490 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2491 | cFYI(1, "In CIFSSMBClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | |
| 2493 | /* do not retry on dead session on close */ |
| 2494 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2495 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | return 0; |
| 2497 | if (rc) |
| 2498 | return rc; |
| 2499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2501 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2503 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2504 | cifs_stats_inc(&tcon->num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2506 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2508 | cERROR(1, "Send error in Close = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | } |
| 2510 | } |
| 2511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2513 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | rc = 0; |
| 2515 | |
| 2516 | return rc; |
| 2517 | } |
| 2518 | |
| 2519 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2520 | CIFSSMBFlush(const int xid, struct cifs_tcon *tcon, int smb_file_id) |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2521 | { |
| 2522 | int rc = 0; |
| 2523 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2524 | cFYI(1, "In CIFSSMBFlush"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2525 | |
| 2526 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2527 | if (rc) |
| 2528 | return rc; |
| 2529 | |
| 2530 | pSMB->FileID = (__u16) smb_file_id; |
| 2531 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2532 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2533 | cifs_stats_inc(&tcon->num_flushes); |
| 2534 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2535 | cERROR(1, "Send error in Flush = %d", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2536 | |
| 2537 | return rc; |
| 2538 | } |
| 2539 | |
| 2540 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2541 | CIFSSMBRename(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2543 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | { |
| 2545 | int rc = 0; |
| 2546 | RENAME_REQ *pSMB = NULL; |
| 2547 | RENAME_RSP *pSMBr = NULL; |
| 2548 | int bytes_returned; |
| 2549 | int name_len, name_len2; |
| 2550 | __u16 count; |
| 2551 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2552 | cFYI(1, "In CIFSSMBRename"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | renameRetry: |
| 2554 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2555 | (void **) &pSMBr); |
| 2556 | if (rc) |
| 2557 | return rc; |
| 2558 | |
| 2559 | pSMB->BufferFormat = 0x04; |
| 2560 | pSMB->SearchAttributes = |
| 2561 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2562 | ATTR_DIRECTORY); |
| 2563 | |
| 2564 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2565 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2566 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, |
| 2567 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | name_len++; /* trailing null */ |
| 2569 | name_len *= 2; |
| 2570 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2571 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2572 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2573 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2574 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2575 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2577 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2578 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | name_len = strnlen(fromName, PATH_MAX); |
| 2580 | name_len++; /* trailing null */ |
| 2581 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2582 | name_len2 = strnlen(toName, PATH_MAX); |
| 2583 | name_len2++; /* trailing null */ |
| 2584 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2585 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2586 | name_len2++; /* trailing null */ |
| 2587 | name_len2++; /* signature byte */ |
| 2588 | } |
| 2589 | |
| 2590 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2591 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | pSMB->ByteCount = cpu_to_le16(count); |
| 2593 | |
| 2594 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2595 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2596 | cifs_stats_inc(&tcon->num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2597 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2598 | cFYI(1, "Send error in rename = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | cifs_buf_release(pSMB); |
| 2601 | |
| 2602 | if (rc == -EAGAIN) |
| 2603 | goto renameRetry; |
| 2604 | |
| 2605 | return rc; |
| 2606 | } |
| 2607 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2608 | int CIFSSMBRenameOpenFile(const int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2609 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2610 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | { |
| 2612 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2613 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2614 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | char *data_offset; |
| 2616 | char dummy_string[30]; |
| 2617 | int rc = 0; |
| 2618 | int bytes_returned = 0; |
| 2619 | int len_of_str; |
| 2620 | __u16 params, param_offset, offset, count, byte_count; |
| 2621 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2622 | cFYI(1, "Rename to File by handle"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2624 | (void **) &pSMBr); |
| 2625 | if (rc) |
| 2626 | return rc; |
| 2627 | |
| 2628 | params = 6; |
| 2629 | pSMB->MaxSetupCount = 0; |
| 2630 | pSMB->Reserved = 0; |
| 2631 | pSMB->Flags = 0; |
| 2632 | pSMB->Timeout = 0; |
| 2633 | pSMB->Reserved2 = 0; |
| 2634 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2635 | offset = param_offset + params; |
| 2636 | |
| 2637 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2638 | rename_info = (struct set_file_rename *) data_offset; |
| 2639 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2640 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | pSMB->SetupCount = 1; |
| 2642 | pSMB->Reserved3 = 0; |
| 2643 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2644 | byte_count = 3 /* pad */ + params; |
| 2645 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2646 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2647 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2648 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2649 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2650 | rename_info->overwrite = cpu_to_le32(1); |
| 2651 | rename_info->root_fid = 0; |
| 2652 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2653 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2654 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2655 | len_of_str = |
| 2656 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2657 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2659 | len_of_str = |
| 2660 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2661 | target_name, PATH_MAX, nls_codepage, |
| 2662 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | } |
| 2664 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2665 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | byte_count += count; |
| 2667 | pSMB->DataCount = cpu_to_le16(count); |
| 2668 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2669 | pSMB->Fid = netfid; |
| 2670 | pSMB->InformationLevel = |
| 2671 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2672 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2673 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2675 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2676 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2677 | cifs_stats_inc(&pTcon->num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2678 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2679 | cFYI(1, "Send error in Rename (by file handle) = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | cifs_buf_release(pSMB); |
| 2682 | |
| 2683 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2684 | since file handle passed in no longer valid */ |
| 2685 | |
| 2686 | return rc; |
| 2687 | } |
| 2688 | |
| 2689 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2690 | CIFSSMBCopy(const int xid, struct cifs_tcon *tcon, const char *fromName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2691 | const __u16 target_tid, const char *toName, const int flags, |
| 2692 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | { |
| 2694 | int rc = 0; |
| 2695 | COPY_REQ *pSMB = NULL; |
| 2696 | COPY_RSP *pSMBr = NULL; |
| 2697 | int bytes_returned; |
| 2698 | int name_len, name_len2; |
| 2699 | __u16 count; |
| 2700 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2701 | cFYI(1, "In CIFSSMBCopy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | copyRetry: |
| 2703 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2704 | (void **) &pSMBr); |
| 2705 | if (rc) |
| 2706 | return rc; |
| 2707 | |
| 2708 | pSMB->BufferFormat = 0x04; |
| 2709 | pSMB->Tid2 = target_tid; |
| 2710 | |
| 2711 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2712 | |
| 2713 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2714 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2715 | fromName, PATH_MAX, nls_codepage, |
| 2716 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | name_len++; /* trailing null */ |
| 2718 | name_len *= 2; |
| 2719 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2720 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2721 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2722 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2723 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2724 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2726 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2727 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | name_len = strnlen(fromName, PATH_MAX); |
| 2729 | name_len++; /* trailing null */ |
| 2730 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2731 | name_len2 = strnlen(toName, PATH_MAX); |
| 2732 | name_len2++; /* trailing null */ |
| 2733 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2734 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2735 | name_len2++; /* trailing null */ |
| 2736 | name_len2++; /* signature byte */ |
| 2737 | } |
| 2738 | |
| 2739 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2740 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | pSMB->ByteCount = cpu_to_le16(count); |
| 2742 | |
| 2743 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2744 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2745 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2746 | cFYI(1, "Send error in copy = %d with %d files copied", |
| 2747 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2749 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | |
| 2751 | if (rc == -EAGAIN) |
| 2752 | goto copyRetry; |
| 2753 | |
| 2754 | return rc; |
| 2755 | } |
| 2756 | |
| 2757 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2758 | CIFSUnixCreateSymLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | const char *fromName, const char *toName, |
| 2760 | const struct nls_table *nls_codepage) |
| 2761 | { |
| 2762 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2763 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2764 | char *data_offset; |
| 2765 | int name_len; |
| 2766 | int name_len_target; |
| 2767 | int rc = 0; |
| 2768 | int bytes_returned = 0; |
| 2769 | __u16 params, param_offset, offset, byte_count; |
| 2770 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2771 | cFYI(1, "In Symlink Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | createSymLinkRetry: |
| 2773 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2774 | (void **) &pSMBr); |
| 2775 | if (rc) |
| 2776 | return rc; |
| 2777 | |
| 2778 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2779 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2780 | cifs_strtoUTF16((__le16 *) pSMB->FileName, fromName, |
| 2781 | /* find define for this maxpathcomponent */ |
| 2782 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | name_len++; /* trailing null */ |
| 2784 | name_len *= 2; |
| 2785 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2786 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | name_len = strnlen(fromName, PATH_MAX); |
| 2788 | name_len++; /* trailing null */ |
| 2789 | strncpy(pSMB->FileName, fromName, name_len); |
| 2790 | } |
| 2791 | params = 6 + name_len; |
| 2792 | pSMB->MaxSetupCount = 0; |
| 2793 | pSMB->Reserved = 0; |
| 2794 | pSMB->Flags = 0; |
| 2795 | pSMB->Timeout = 0; |
| 2796 | pSMB->Reserved2 = 0; |
| 2797 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2798 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | offset = param_offset + params; |
| 2800 | |
| 2801 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2802 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2803 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2804 | cifs_strtoUTF16((__le16 *) data_offset, toName, PATH_MAX |
| 2805 | /* find define for this maxpathcomponent */ |
| 2806 | , nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | name_len_target++; /* trailing null */ |
| 2808 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2809 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | name_len_target = strnlen(toName, PATH_MAX); |
| 2811 | name_len_target++; /* trailing null */ |
| 2812 | strncpy(data_offset, toName, name_len_target); |
| 2813 | } |
| 2814 | |
| 2815 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2816 | /* BB find exact max on data count below from sess */ |
| 2817 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2818 | pSMB->SetupCount = 1; |
| 2819 | pSMB->Reserved3 = 0; |
| 2820 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2821 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2822 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2823 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2824 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2825 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2826 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2827 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2828 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2829 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2830 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2832 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2833 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2834 | cifs_stats_inc(&tcon->num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2835 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2836 | cFYI(1, "Send error in SetPathInfo create symlink = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2838 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | |
| 2840 | if (rc == -EAGAIN) |
| 2841 | goto createSymLinkRetry; |
| 2842 | |
| 2843 | return rc; |
| 2844 | } |
| 2845 | |
| 2846 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2847 | CIFSUnixCreateHardLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2849 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | { |
| 2851 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2852 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2853 | char *data_offset; |
| 2854 | int name_len; |
| 2855 | int name_len_target; |
| 2856 | int rc = 0; |
| 2857 | int bytes_returned = 0; |
| 2858 | __u16 params, param_offset, offset, byte_count; |
| 2859 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2860 | cFYI(1, "In Create Hard link Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | createHardLinkRetry: |
| 2862 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2863 | (void **) &pSMBr); |
| 2864 | if (rc) |
| 2865 | return rc; |
| 2866 | |
| 2867 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2868 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 2869 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | name_len++; /* trailing null */ |
| 2871 | name_len *= 2; |
| 2872 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2873 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | name_len = strnlen(toName, PATH_MAX); |
| 2875 | name_len++; /* trailing null */ |
| 2876 | strncpy(pSMB->FileName, toName, name_len); |
| 2877 | } |
| 2878 | params = 6 + name_len; |
| 2879 | pSMB->MaxSetupCount = 0; |
| 2880 | pSMB->Reserved = 0; |
| 2881 | pSMB->Flags = 0; |
| 2882 | pSMB->Timeout = 0; |
| 2883 | pSMB->Reserved2 = 0; |
| 2884 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2885 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | offset = param_offset + params; |
| 2887 | |
| 2888 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2889 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2890 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2891 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 2892 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | name_len_target++; /* trailing null */ |
| 2894 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2895 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2897 | name_len_target++; /* trailing null */ |
| 2898 | strncpy(data_offset, fromName, name_len_target); |
| 2899 | } |
| 2900 | |
| 2901 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2902 | /* BB find exact max on data count below from sess*/ |
| 2903 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2904 | pSMB->SetupCount = 1; |
| 2905 | pSMB->Reserved3 = 0; |
| 2906 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2907 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2908 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2909 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2910 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2911 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2912 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2913 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2914 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2915 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2916 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2918 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2919 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2920 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2921 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2922 | cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | |
| 2924 | cifs_buf_release(pSMB); |
| 2925 | if (rc == -EAGAIN) |
| 2926 | goto createHardLinkRetry; |
| 2927 | |
| 2928 | return rc; |
| 2929 | } |
| 2930 | |
| 2931 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2932 | CIFSCreateHardLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2934 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | { |
| 2936 | int rc = 0; |
| 2937 | NT_RENAME_REQ *pSMB = NULL; |
| 2938 | RENAME_RSP *pSMBr = NULL; |
| 2939 | int bytes_returned; |
| 2940 | int name_len, name_len2; |
| 2941 | __u16 count; |
| 2942 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2943 | cFYI(1, "In CIFSCreateHardLink"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | winCreateHardLinkRetry: |
| 2945 | |
| 2946 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2947 | (void **) &pSMBr); |
| 2948 | if (rc) |
| 2949 | return rc; |
| 2950 | |
| 2951 | pSMB->SearchAttributes = |
| 2952 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2953 | ATTR_DIRECTORY); |
| 2954 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 2955 | pSMB->ClusterCount = 0; |
| 2956 | |
| 2957 | pSMB->BufferFormat = 0x04; |
| 2958 | |
| 2959 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2960 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2961 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, |
| 2962 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | name_len++; /* trailing null */ |
| 2964 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 2965 | |
| 2966 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 2967 | pSMB->OldFileName[name_len] = 0x04; |
| 2968 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2970 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2971 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2973 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2974 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | name_len = strnlen(fromName, PATH_MAX); |
| 2976 | name_len++; /* trailing null */ |
| 2977 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2978 | name_len2 = strnlen(toName, PATH_MAX); |
| 2979 | name_len2++; /* trailing null */ |
| 2980 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2981 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2982 | name_len2++; /* trailing null */ |
| 2983 | name_len2++; /* signature byte */ |
| 2984 | } |
| 2985 | |
| 2986 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2987 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | pSMB->ByteCount = cpu_to_le16(count); |
| 2989 | |
| 2990 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2991 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2992 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2993 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2994 | cFYI(1, "Send error in hard link (NT rename) = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2995 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | cifs_buf_release(pSMB); |
| 2997 | if (rc == -EAGAIN) |
| 2998 | goto winCreateHardLinkRetry; |
| 2999 | |
| 3000 | return rc; |
| 3001 | } |
| 3002 | |
| 3003 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3004 | CIFSSMBUnixQuerySymLink(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3005 | const unsigned char *searchName, char **symlinkinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | const struct nls_table *nls_codepage) |
| 3007 | { |
| 3008 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 3009 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3010 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3011 | int rc = 0; |
| 3012 | int bytes_returned; |
| 3013 | int name_len; |
| 3014 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3015 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3017 | cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | |
| 3019 | querySymLinkRetry: |
| 3020 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3021 | (void **) &pSMBr); |
| 3022 | if (rc) |
| 3023 | return rc; |
| 3024 | |
| 3025 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3026 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3027 | cifs_strtoUTF16((__le16 *) pSMB->FileName, searchName, |
| 3028 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | name_len++; /* trailing null */ |
| 3030 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3031 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | name_len = strnlen(searchName, PATH_MAX); |
| 3033 | name_len++; /* trailing null */ |
| 3034 | strncpy(pSMB->FileName, searchName, name_len); |
| 3035 | } |
| 3036 | |
| 3037 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3038 | pSMB->TotalDataCount = 0; |
| 3039 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3040 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | pSMB->MaxSetupCount = 0; |
| 3042 | pSMB->Reserved = 0; |
| 3043 | pSMB->Flags = 0; |
| 3044 | pSMB->Timeout = 0; |
| 3045 | pSMB->Reserved2 = 0; |
| 3046 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3047 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | pSMB->DataCount = 0; |
| 3049 | pSMB->DataOffset = 0; |
| 3050 | pSMB->SetupCount = 1; |
| 3051 | pSMB->Reserved3 = 0; |
| 3052 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3053 | byte_count = params + 1 /* pad */ ; |
| 3054 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3055 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3056 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3057 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3058 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3060 | |
| 3061 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3062 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3063 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3064 | cFYI(1, "Send error in QuerySymLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | } else { |
| 3066 | /* decode response */ |
| 3067 | |
| 3068 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3070 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3071 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3073 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3074 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3076 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3077 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3078 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3079 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3080 | is_unicode = true; |
| 3081 | else |
| 3082 | is_unicode = false; |
| 3083 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3084 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3085 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3086 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3087 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3088 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | } |
| 3090 | } |
| 3091 | cifs_buf_release(pSMB); |
| 3092 | if (rc == -EAGAIN) |
| 3093 | goto querySymLinkRetry; |
| 3094 | return rc; |
| 3095 | } |
| 3096 | |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3097 | #ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL |
| 3098 | /* |
| 3099 | * Recent Windows versions now create symlinks more frequently |
| 3100 | * and they use the "reparse point" mechanism below. We can of course |
| 3101 | * do symlinks nicely to Samba and other servers which support the |
| 3102 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3103 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3104 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3105 | * In the interim this code has been moved to its own config option so |
| 3106 | * it is not compiled in by default until callers fixed up and more tested. |
| 3107 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3109 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3111 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | const struct nls_table *nls_codepage) |
| 3113 | { |
| 3114 | int rc = 0; |
| 3115 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3116 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3117 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3119 | cFYI(1, "In Windows reparse style QueryLink for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3121 | (void **) &pSMBr); |
| 3122 | if (rc) |
| 3123 | return rc; |
| 3124 | |
| 3125 | pSMB->TotalParameterCount = 0 ; |
| 3126 | pSMB->TotalDataCount = 0; |
| 3127 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3128 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3129 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | pSMB->MaxSetupCount = 4; |
| 3131 | pSMB->Reserved = 0; |
| 3132 | pSMB->ParameterOffset = 0; |
| 3133 | pSMB->DataCount = 0; |
| 3134 | pSMB->DataOffset = 0; |
| 3135 | pSMB->SetupCount = 4; |
| 3136 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3137 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3138 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3139 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3140 | pSMB->IsRootFlag = 0; |
| 3141 | pSMB->Fid = fid; /* file handle always le */ |
| 3142 | pSMB->ByteCount = 0; |
| 3143 | |
| 3144 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3145 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3146 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3147 | cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | } else { /* decode response */ |
| 3149 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3150 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3151 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3152 | /* BB also check enough total bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | rc = -EIO; /* bad smb */ |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3154 | goto qreparse_out; |
| 3155 | } |
| 3156 | if (data_count && (data_count < 2048)) { |
| 3157 | char *end_of_smb = 2 /* sizeof byte count */ + |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3158 | get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3160 | struct reparse_data *reparse_buf = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3161 | (struct reparse_data *) |
| 3162 | ((char *)&pSMBr->hdr.Protocol |
| 3163 | + data_offset); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3164 | if ((char *)reparse_buf >= end_of_smb) { |
| 3165 | rc = -EIO; |
| 3166 | goto qreparse_out; |
| 3167 | } |
| 3168 | if ((reparse_buf->LinkNamesBuf + |
| 3169 | reparse_buf->TargetNameOffset + |
| 3170 | reparse_buf->TargetNameLen) > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3171 | cFYI(1, "reparse buf beyond SMB"); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3172 | rc = -EIO; |
| 3173 | goto qreparse_out; |
| 3174 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3175 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3176 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3177 | cifs_from_ucs2(symlinkinfo, (__le16 *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3178 | (reparse_buf->LinkNamesBuf + |
| 3179 | reparse_buf->TargetNameOffset), |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3180 | buflen, |
| 3181 | reparse_buf->TargetNameLen, |
| 3182 | nls_codepage, 0); |
| 3183 | } else { /* ASCII names */ |
| 3184 | strncpy(symlinkinfo, |
| 3185 | reparse_buf->LinkNamesBuf + |
| 3186 | reparse_buf->TargetNameOffset, |
| 3187 | min_t(const int, buflen, |
| 3188 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3190 | } else { |
| 3191 | rc = -EIO; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3192 | cFYI(1, "Invalid return data count on " |
| 3193 | "get reparse info ioctl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3195 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 3196 | does not go off the end of the buffer */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3197 | cFYI(1, "readlink result - %s", symlinkinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3201 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | |
| 3203 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 3204 | since file handle passed in no longer valid */ |
| 3205 | |
| 3206 | return rc; |
| 3207 | } |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3208 | #endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | |
| 3210 | #ifdef CONFIG_CIFS_POSIX |
| 3211 | |
| 3212 | /*Convert an Access Control Entry from wire format to local POSIX xattr format*/ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3213 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 3214 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | { |
| 3216 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3217 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3218 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3219 | ace->e_id = cpu_to_le32(le64_to_cpu(cifs_ace->cifs_uid)); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3220 | /* cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | |
| 3222 | return; |
| 3223 | } |
| 3224 | |
| 3225 | /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3226 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3227 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | { |
| 3229 | int size = 0; |
| 3230 | int i; |
| 3231 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3232 | struct cifs_posix_ace *pACE; |
| 3233 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 3234 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | |
| 3236 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3237 | return -EOPNOTSUPP; |
| 3238 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3239 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3241 | pACE = &cifs_acl->ace_array[0]; |
| 3242 | size = sizeof(struct cifs_posix_acl); |
| 3243 | size += sizeof(struct cifs_posix_ace) * count; |
| 3244 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3245 | if (size_of_data_area < size) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3246 | cFYI(1, "bad CIFS POSIX ACL size %d vs. %d", |
| 3247 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | return -EINVAL; |
| 3249 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3250 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3252 | size = sizeof(struct cifs_posix_acl); |
| 3253 | size += sizeof(struct cifs_posix_ace) * count; |
| 3254 | /* skip past access ACEs to get to default ACEs */ |
| 3255 | pACE = &cifs_acl->ace_array[count]; |
| 3256 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3257 | size += sizeof(struct cifs_posix_ace) * count; |
| 3258 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3259 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | return -EINVAL; |
| 3261 | } else { |
| 3262 | /* illegal type */ |
| 3263 | return -EINVAL; |
| 3264 | } |
| 3265 | |
| 3266 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3267 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3268 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3269 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | return -ERANGE; |
| 3271 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3272 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3273 | for (i = 0; i < count ; i++) { |
| 3274 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 3275 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | } |
| 3277 | } |
| 3278 | return size; |
| 3279 | } |
| 3280 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3281 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 3282 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | { |
| 3284 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 3285 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3286 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3287 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3289 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3291 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3292 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3293 | cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3294 | /*cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | return rc; |
| 3296 | } |
| 3297 | |
| 3298 | /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3299 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3300 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | { |
| 3302 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3303 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 3304 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | int count; |
| 3306 | int i; |
| 3307 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3308 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | return 0; |
| 3310 | |
| 3311 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3312 | cFYI(1, "setting acl with %d entries from buf of length %d and " |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 3313 | "version of %d", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3314 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3315 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3316 | cFYI(1, "unknown POSIX ACL version %d", |
| 3317 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | return 0; |
| 3319 | } |
| 3320 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3321 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3322 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3323 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3324 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3326 | cFYI(1, "unknown ACL type %d", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | return 0; |
| 3328 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3329 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 3331 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3332 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | /* ACE not converted */ |
| 3334 | break; |
| 3335 | } |
| 3336 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3337 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3339 | rc += sizeof(struct cifs_posix_acl); |
| 3340 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3341 | } |
| 3342 | return rc; |
| 3343 | } |
| 3344 | |
| 3345 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3346 | CIFSSMBGetPosixACL(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3347 | const unsigned char *searchName, |
| 3348 | char *acl_inf, const int buflen, const int acl_type, |
| 3349 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | { |
| 3351 | /* SMB_QUERY_POSIX_ACL */ |
| 3352 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3353 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3354 | int rc = 0; |
| 3355 | int bytes_returned; |
| 3356 | int name_len; |
| 3357 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3358 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3359 | cFYI(1, "In GetPosixACL (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | |
| 3361 | queryAclRetry: |
| 3362 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3363 | (void **) &pSMBr); |
| 3364 | if (rc) |
| 3365 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3368 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3369 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3370 | searchName, PATH_MAX, nls_codepage, |
| 3371 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | name_len++; /* trailing null */ |
| 3373 | name_len *= 2; |
| 3374 | pSMB->FileName[name_len] = 0; |
| 3375 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3376 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | name_len = strnlen(searchName, PATH_MAX); |
| 3378 | name_len++; /* trailing null */ |
| 3379 | strncpy(pSMB->FileName, searchName, name_len); |
| 3380 | } |
| 3381 | |
| 3382 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3383 | pSMB->TotalDataCount = 0; |
| 3384 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3385 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3387 | pSMB->MaxSetupCount = 0; |
| 3388 | pSMB->Reserved = 0; |
| 3389 | pSMB->Flags = 0; |
| 3390 | pSMB->Timeout = 0; |
| 3391 | pSMB->Reserved2 = 0; |
| 3392 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3393 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3394 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | pSMB->DataCount = 0; |
| 3396 | pSMB->DataOffset = 0; |
| 3397 | pSMB->SetupCount = 1; |
| 3398 | pSMB->Reserved3 = 0; |
| 3399 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3400 | byte_count = params + 1 /* pad */ ; |
| 3401 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3402 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3403 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3404 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3405 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3407 | |
| 3408 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3409 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3410 | cifs_stats_inc(&tcon->num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3412 | cFYI(1, "Send error in Query POSIX ACL = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | } else { |
| 3414 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3418 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | rc = -EIO; /* bad smb */ |
| 3420 | else { |
| 3421 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3422 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3423 | rc = cifs_copy_posix_acl(acl_inf, |
| 3424 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3425 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | } |
| 3427 | } |
| 3428 | cifs_buf_release(pSMB); |
| 3429 | if (rc == -EAGAIN) |
| 3430 | goto queryAclRetry; |
| 3431 | return rc; |
| 3432 | } |
| 3433 | |
| 3434 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3435 | CIFSSMBSetPosixACL(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3436 | const unsigned char *fileName, |
| 3437 | const char *local_acl, const int buflen, |
| 3438 | const int acl_type, |
| 3439 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | { |
| 3441 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3442 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3443 | char *parm_data; |
| 3444 | int name_len; |
| 3445 | int rc = 0; |
| 3446 | int bytes_returned = 0; |
| 3447 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3448 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3449 | cFYI(1, "In SetPosixACL (Unix) for path %s", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | setAclRetry: |
| 3451 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3452 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | if (rc) |
| 3454 | return rc; |
| 3455 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3456 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3457 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3458 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | name_len++; /* trailing null */ |
| 3460 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3461 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | name_len = strnlen(fileName, PATH_MAX); |
| 3463 | name_len++; /* trailing null */ |
| 3464 | strncpy(pSMB->FileName, fileName, name_len); |
| 3465 | } |
| 3466 | params = 6 + name_len; |
| 3467 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3468 | /* BB find max SMB size from sess */ |
| 3469 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | pSMB->MaxSetupCount = 0; |
| 3471 | pSMB->Reserved = 0; |
| 3472 | pSMB->Flags = 0; |
| 3473 | pSMB->Timeout = 0; |
| 3474 | pSMB->Reserved2 = 0; |
| 3475 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3476 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | offset = param_offset + params; |
| 3478 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3479 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3480 | |
| 3481 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3482 | data_count = ACL_to_cifs_posix(parm_data, local_acl, buflen, acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3484 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | rc = -EOPNOTSUPP; |
| 3486 | goto setACLerrorExit; |
| 3487 | } |
| 3488 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3489 | pSMB->SetupCount = 1; |
| 3490 | pSMB->Reserved3 = 0; |
| 3491 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3492 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3493 | byte_count = 3 /* pad */ + params + data_count; |
| 3494 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3495 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3496 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3497 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3498 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3499 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3501 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3502 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3503 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3504 | cFYI(1, "Set POSIX ACL returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | |
| 3506 | setACLerrorExit: |
| 3507 | cifs_buf_release(pSMB); |
| 3508 | if (rc == -EAGAIN) |
| 3509 | goto setAclRetry; |
| 3510 | return rc; |
| 3511 | } |
| 3512 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3513 | /* BB fix tabs in this function FIXME BB */ |
| 3514 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3515 | CIFSGetExtAttr(const int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3516 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3517 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3518 | int rc = 0; |
| 3519 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3520 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3521 | int bytes_returned; |
| 3522 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3523 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3524 | cFYI(1, "In GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3525 | if (tcon == NULL) |
| 3526 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3527 | |
| 3528 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3529 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3530 | (void **) &pSMBr); |
| 3531 | if (rc) |
| 3532 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3533 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3534 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3535 | pSMB->t2.TotalDataCount = 0; |
| 3536 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3537 | /* BB find exact max data count below from sess structure BB */ |
| 3538 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3539 | pSMB->t2.MaxSetupCount = 0; |
| 3540 | pSMB->t2.Reserved = 0; |
| 3541 | pSMB->t2.Flags = 0; |
| 3542 | pSMB->t2.Timeout = 0; |
| 3543 | pSMB->t2.Reserved2 = 0; |
| 3544 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3545 | Fid) - 4); |
| 3546 | pSMB->t2.DataCount = 0; |
| 3547 | pSMB->t2.DataOffset = 0; |
| 3548 | pSMB->t2.SetupCount = 1; |
| 3549 | pSMB->t2.Reserved3 = 0; |
| 3550 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3551 | byte_count = params + 1 /* pad */ ; |
| 3552 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3553 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3554 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3555 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3556 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3557 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3558 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3559 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3560 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3561 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3562 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3563 | cFYI(1, "error %d in GetExtAttr", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3564 | } else { |
| 3565 | /* decode response */ |
| 3566 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3567 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3568 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3569 | /* If rc should we check for EOPNOSUPP and |
| 3570 | disable the srvino flag? or in caller? */ |
| 3571 | rc = -EIO; /* bad smb */ |
| 3572 | else { |
| 3573 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3574 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3575 | struct file_chattr_info *pfinfo; |
| 3576 | /* BB Do we need a cast or hash here ? */ |
| 3577 | if (count != 16) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3578 | cFYI(1, "Illegal size ret in GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3579 | rc = -EIO; |
| 3580 | goto GetExtAttrOut; |
| 3581 | } |
| 3582 | pfinfo = (struct file_chattr_info *) |
| 3583 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3584 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3585 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3586 | } |
| 3587 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3588 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3589 | cifs_buf_release(pSMB); |
| 3590 | if (rc == -EAGAIN) |
| 3591 | goto GetExtAttrRetry; |
| 3592 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3593 | } |
| 3594 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3595 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3597 | #ifdef CONFIG_CIFS_ACL |
| 3598 | /* |
| 3599 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3600 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3601 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3602 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3603 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3604 | * by caller |
| 3605 | */ |
| 3606 | static int |
| 3607 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3608 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3609 | void **ret_buf) |
| 3610 | { |
| 3611 | int rc; |
| 3612 | __u32 temp_offset; |
| 3613 | struct smb_com_ntransact_req *pSMB; |
| 3614 | |
| 3615 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3616 | (void **)&pSMB); |
| 3617 | if (rc) |
| 3618 | return rc; |
| 3619 | *ret_buf = (void *)pSMB; |
| 3620 | pSMB->Reserved = 0; |
| 3621 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3622 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3623 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3624 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3625 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3626 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3627 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3628 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3629 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3630 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3631 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3632 | return 0; |
| 3633 | } |
| 3634 | |
| 3635 | static int |
| 3636 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3637 | __u32 *pparmlen, __u32 *pdatalen) |
| 3638 | { |
| 3639 | char *end_of_smb; |
| 3640 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3641 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3642 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3643 | |
| 3644 | *pdatalen = 0; |
| 3645 | *pparmlen = 0; |
| 3646 | |
| 3647 | if (buf == NULL) |
| 3648 | return -EINVAL; |
| 3649 | |
| 3650 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3651 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3652 | bcc = get_bcc(&pSMBr->hdr); |
| 3653 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3654 | (char *)&pSMBr->ByteCount; |
| 3655 | |
| 3656 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3657 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3658 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3659 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3660 | |
| 3661 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3662 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3663 | |
| 3664 | /* should we also check that parm and data areas do not overlap? */ |
| 3665 | if (*ppparm > end_of_smb) { |
| 3666 | cFYI(1, "parms start after end of smb"); |
| 3667 | return -EINVAL; |
| 3668 | } else if (parm_count + *ppparm > end_of_smb) { |
| 3669 | cFYI(1, "parm end after end of smb"); |
| 3670 | return -EINVAL; |
| 3671 | } else if (*ppdata > end_of_smb) { |
| 3672 | cFYI(1, "data starts after end of smb"); |
| 3673 | return -EINVAL; |
| 3674 | } else if (data_count + *ppdata > end_of_smb) { |
| 3675 | cFYI(1, "data %p + count %d (%p) past smb end %p start %p", |
| 3676 | *ppdata, data_count, (data_count + *ppdata), |
| 3677 | end_of_smb, pSMBr); |
| 3678 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3679 | } else if (parm_count + data_count > bcc) { |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3680 | cFYI(1, "parm count and data count larger than SMB"); |
| 3681 | return -EINVAL; |
| 3682 | } |
| 3683 | *pdatalen = data_count; |
| 3684 | *pparmlen = parm_count; |
| 3685 | return 0; |
| 3686 | } |
| 3687 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3688 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3689 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3690 | CIFSSMBGetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3691 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3692 | { |
| 3693 | int rc = 0; |
| 3694 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3695 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3696 | struct kvec iov[1]; |
| 3697 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3698 | cFYI(1, "GetCifsACL"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3699 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3700 | *pbuflen = 0; |
| 3701 | *acl_inf = NULL; |
| 3702 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3703 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3704 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3705 | if (rc) |
| 3706 | return rc; |
| 3707 | |
| 3708 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3709 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3710 | pSMB->MaxSetupCount = 0; |
| 3711 | pSMB->Fid = fid; /* file handle always le */ |
| 3712 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3713 | CIFS_ACL_DACL); |
| 3714 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3715 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3716 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3717 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3718 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3719 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 3720 | 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3721 | cifs_stats_inc(&tcon->num_acl_get); |
| 3722 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3723 | cFYI(1, "Send error in QuerySecDesc = %d", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3724 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3725 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3726 | __u32 parm_len; |
| 3727 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3728 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3729 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3730 | |
| 3731 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3732 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3733 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3734 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3735 | goto qsec_out; |
| 3736 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3737 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3738 | cFYI(1, "smb %p parm %p data %p", pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3739 | |
| 3740 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3741 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3742 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3743 | goto qsec_out; |
| 3744 | } |
| 3745 | |
| 3746 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3747 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3748 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3749 | if (acl_len != *pbuflen) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3750 | cERROR(1, "acl length %d does not match %d", |
| 3751 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3752 | if (*pbuflen > acl_len) |
| 3753 | *pbuflen = acl_len; |
| 3754 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3755 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3756 | /* check if buffer is big enough for the acl |
| 3757 | header followed by the smallest SID */ |
| 3758 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3759 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3760 | cERROR(1, "bad acl length %d", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3761 | rc = -EINVAL; |
| 3762 | *pbuflen = 0; |
| 3763 | } else { |
| 3764 | *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); |
| 3765 | if (*acl_inf == NULL) { |
| 3766 | *pbuflen = 0; |
| 3767 | rc = -ENOMEM; |
| 3768 | } |
| 3769 | memcpy(*acl_inf, pdata, *pbuflen); |
| 3770 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3771 | } |
| 3772 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3773 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3774 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3775 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3776 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3777 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3778 | return rc; |
| 3779 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3780 | |
| 3781 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3782 | CIFSSMBSetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3783 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3784 | { |
| 3785 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3786 | int rc = 0; |
| 3787 | int bytes_returned = 0; |
| 3788 | SET_SEC_DESC_REQ *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3789 | void *pSMBr; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3790 | |
| 3791 | setCifsAclRetry: |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3792 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3793 | if (rc) |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3794 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3795 | |
| 3796 | pSMB->MaxSetupCount = 0; |
| 3797 | pSMB->Reserved = 0; |
| 3798 | |
| 3799 | param_count = 8; |
| 3800 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3801 | data_count = acllen; |
| 3802 | data_offset = param_offset + param_count; |
| 3803 | byte_count = 3 /* pad */ + param_count; |
| 3804 | |
| 3805 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3806 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3807 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3808 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3809 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3810 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3811 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3812 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3813 | pSMB->SetupCount = 0; |
| 3814 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3815 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3816 | |
| 3817 | pSMB->Fid = fid; /* file handle always le */ |
| 3818 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3819 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3820 | |
| 3821 | if (pntsd && acllen) { |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3822 | memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + |
| 3823 | data_offset, pntsd, acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3824 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3825 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3826 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3827 | |
| 3828 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3829 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3830 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3831 | cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3832 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3833 | cFYI(1, "Set CIFS ACL returned %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3834 | cifs_buf_release(pSMB); |
| 3835 | |
| 3836 | if (rc == -EAGAIN) |
| 3837 | goto setCifsAclRetry; |
| 3838 | |
| 3839 | return (rc); |
| 3840 | } |
| 3841 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3842 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3843 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3844 | /* Legacy Query Path Information call for lookup to old servers such |
| 3845 | as Win9x/WinME */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3846 | int SMBQueryInformation(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3847 | const unsigned char *searchName, |
| 3848 | FILE_ALL_INFO *pFinfo, |
| 3849 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3850 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3851 | QUERY_INFORMATION_REQ *pSMB; |
| 3852 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3853 | int rc = 0; |
| 3854 | int bytes_returned; |
| 3855 | int name_len; |
| 3856 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3857 | cFYI(1, "In SMBQPath path %s", searchName); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3858 | QInfRetry: |
| 3859 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3860 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3861 | if (rc) |
| 3862 | return rc; |
| 3863 | |
| 3864 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3865 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3866 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3867 | searchName, PATH_MAX, nls_codepage, |
| 3868 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3869 | name_len++; /* trailing null */ |
| 3870 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3871 | } else { |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3872 | name_len = strnlen(searchName, PATH_MAX); |
| 3873 | name_len++; /* trailing null */ |
| 3874 | strncpy(pSMB->FileName, searchName, name_len); |
| 3875 | } |
| 3876 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3877 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3878 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3879 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3880 | |
| 3881 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3882 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3883 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3884 | cFYI(1, "Send error in QueryInfo = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3885 | } else if (pFinfo) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3886 | struct timespec ts; |
| 3887 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3888 | |
| 3889 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3890 | /* BB FIXME - add time zone adjustment BB */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3891 | memset(pFinfo, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3892 | ts.tv_nsec = 0; |
| 3893 | ts.tv_sec = time; |
| 3894 | /* decode time fields */ |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 3895 | pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3896 | pFinfo->LastWriteTime = pFinfo->ChangeTime; |
| 3897 | pFinfo->LastAccessTime = 0; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3898 | pFinfo->AllocationSize = |
| 3899 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
| 3900 | pFinfo->EndOfFile = pFinfo->AllocationSize; |
| 3901 | pFinfo->Attributes = |
| 3902 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3903 | } else |
| 3904 | rc = -EIO; /* bad buffer passed in */ |
| 3905 | |
| 3906 | cifs_buf_release(pSMB); |
| 3907 | |
| 3908 | if (rc == -EAGAIN) |
| 3909 | goto QInfRetry; |
| 3910 | |
| 3911 | return rc; |
| 3912 | } |
| 3913 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3914 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3915 | CIFSSMBQFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3916 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 3917 | { |
| 3918 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3919 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3920 | int rc = 0; |
| 3921 | int bytes_returned; |
| 3922 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3923 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3924 | QFileInfoRetry: |
| 3925 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3926 | (void **) &pSMBr); |
| 3927 | if (rc) |
| 3928 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3929 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3930 | params = 2 /* level */ + 2 /* fid */; |
| 3931 | pSMB->t2.TotalDataCount = 0; |
| 3932 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3933 | /* BB find exact max data count below from sess structure BB */ |
| 3934 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3935 | pSMB->t2.MaxSetupCount = 0; |
| 3936 | pSMB->t2.Reserved = 0; |
| 3937 | pSMB->t2.Flags = 0; |
| 3938 | pSMB->t2.Timeout = 0; |
| 3939 | pSMB->t2.Reserved2 = 0; |
| 3940 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3941 | Fid) - 4); |
| 3942 | pSMB->t2.DataCount = 0; |
| 3943 | pSMB->t2.DataOffset = 0; |
| 3944 | pSMB->t2.SetupCount = 1; |
| 3945 | pSMB->t2.Reserved3 = 0; |
| 3946 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3947 | byte_count = params + 1 /* pad */ ; |
| 3948 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3949 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3950 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 3951 | pSMB->Pad = 0; |
| 3952 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3953 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3954 | |
| 3955 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3956 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3957 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3958 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3959 | } else { /* decode response */ |
| 3960 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3961 | |
| 3962 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3963 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3964 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3965 | rc = -EIO; /* bad smb */ |
| 3966 | else if (pFindData) { |
| 3967 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3968 | memcpy((char *) pFindData, |
| 3969 | (char *) &pSMBr->hdr.Protocol + |
| 3970 | data_offset, sizeof(FILE_ALL_INFO)); |
| 3971 | } else |
| 3972 | rc = -ENOMEM; |
| 3973 | } |
| 3974 | cifs_buf_release(pSMB); |
| 3975 | if (rc == -EAGAIN) |
| 3976 | goto QFileInfoRetry; |
| 3977 | |
| 3978 | return rc; |
| 3979 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3982 | CIFSSMBQPathInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3984 | FILE_ALL_INFO *pFindData, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3985 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3986 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | { |
| 3988 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
| 3989 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3990 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3991 | int rc = 0; |
| 3992 | int bytes_returned; |
| 3993 | int name_len; |
| 3994 | __u16 params, byte_count; |
| 3995 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3996 | /* cFYI(1, "In QPathInfo path %s", searchName); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | QPathInfoRetry: |
| 3998 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3999 | (void **) &pSMBr); |
| 4000 | if (rc) |
| 4001 | return rc; |
| 4002 | |
| 4003 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4004 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4005 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4006 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | name_len++; /* trailing null */ |
| 4008 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4009 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | name_len = strnlen(searchName, PATH_MAX); |
| 4011 | name_len++; /* trailing null */ |
| 4012 | strncpy(pSMB->FileName, searchName, name_len); |
| 4013 | } |
| 4014 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4015 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | pSMB->TotalDataCount = 0; |
| 4017 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4018 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4019 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | pSMB->MaxSetupCount = 0; |
| 4021 | pSMB->Reserved = 0; |
| 4022 | pSMB->Flags = 0; |
| 4023 | pSMB->Timeout = 0; |
| 4024 | pSMB->Reserved2 = 0; |
| 4025 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4026 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | pSMB->DataCount = 0; |
| 4028 | pSMB->DataOffset = 0; |
| 4029 | pSMB->SetupCount = 1; |
| 4030 | pSMB->Reserved3 = 0; |
| 4031 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4032 | byte_count = params + 1 /* pad */ ; |
| 4033 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4034 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4035 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4036 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4037 | else |
| 4038 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4040 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4042 | |
| 4043 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4044 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4045 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4046 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | } else { /* decode response */ |
| 4048 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4049 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4050 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4051 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4052 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4054 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4055 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4056 | last field */ |
| 4057 | else if (pFindData) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4058 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4060 | |
| 4061 | /* On legacy responses we do not read the last field, |
| 4062 | EAsize, fortunately since it varies by subdialect and |
| 4063 | also note it differs on Set vs. Get, ie two bytes or 4 |
| 4064 | bytes depending but we don't care here */ |
| 4065 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4066 | size = sizeof(FILE_INFO_STANDARD); |
| 4067 | else |
| 4068 | size = sizeof(FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | memcpy((char *) pFindData, |
| 4070 | (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4071 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | } else |
| 4073 | rc = -ENOMEM; |
| 4074 | } |
| 4075 | cifs_buf_release(pSMB); |
| 4076 | if (rc == -EAGAIN) |
| 4077 | goto QPathInfoRetry; |
| 4078 | |
| 4079 | return rc; |
| 4080 | } |
| 4081 | |
| 4082 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4083 | CIFSSMBUnixQFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4084 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4085 | { |
| 4086 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4087 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4088 | int rc = 0; |
| 4089 | int bytes_returned; |
| 4090 | __u16 params, byte_count; |
| 4091 | |
| 4092 | UnixQFileInfoRetry: |
| 4093 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4094 | (void **) &pSMBr); |
| 4095 | if (rc) |
| 4096 | return rc; |
| 4097 | |
| 4098 | params = 2 /* level */ + 2 /* fid */; |
| 4099 | pSMB->t2.TotalDataCount = 0; |
| 4100 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4101 | /* BB find exact max data count below from sess structure BB */ |
| 4102 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4103 | pSMB->t2.MaxSetupCount = 0; |
| 4104 | pSMB->t2.Reserved = 0; |
| 4105 | pSMB->t2.Flags = 0; |
| 4106 | pSMB->t2.Timeout = 0; |
| 4107 | pSMB->t2.Reserved2 = 0; |
| 4108 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4109 | Fid) - 4); |
| 4110 | pSMB->t2.DataCount = 0; |
| 4111 | pSMB->t2.DataOffset = 0; |
| 4112 | pSMB->t2.SetupCount = 1; |
| 4113 | pSMB->t2.Reserved3 = 0; |
| 4114 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4115 | byte_count = params + 1 /* pad */ ; |
| 4116 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4117 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4118 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4119 | pSMB->Pad = 0; |
| 4120 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4121 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4122 | |
| 4123 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4124 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4125 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4126 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4127 | } else { /* decode response */ |
| 4128 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4129 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4130 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4131 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4132 | "Unix Extensions can be disabled on mount " |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4133 | "by specifying the nosfu mount option."); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4134 | rc = -EIO; /* bad smb */ |
| 4135 | } else { |
| 4136 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4137 | memcpy((char *) pFindData, |
| 4138 | (char *) &pSMBr->hdr.Protocol + |
| 4139 | data_offset, |
| 4140 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | cifs_buf_release(pSMB); |
| 4145 | if (rc == -EAGAIN) |
| 4146 | goto UnixQFileInfoRetry; |
| 4147 | |
| 4148 | return rc; |
| 4149 | } |
| 4150 | |
| 4151 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4152 | CIFSSMBUnixQPathInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4154 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4155 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | { |
| 4157 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4158 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4159 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4160 | int rc = 0; |
| 4161 | int bytes_returned = 0; |
| 4162 | int name_len; |
| 4163 | __u16 params, byte_count; |
| 4164 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4165 | cFYI(1, "In QPathInfo (Unix) the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | UnixQPathInfoRetry: |
| 4167 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4168 | (void **) &pSMBr); |
| 4169 | if (rc) |
| 4170 | return rc; |
| 4171 | |
| 4172 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4173 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4174 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4175 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | name_len++; /* trailing null */ |
| 4177 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4178 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | name_len = strnlen(searchName, PATH_MAX); |
| 4180 | name_len++; /* trailing null */ |
| 4181 | strncpy(pSMB->FileName, searchName, name_len); |
| 4182 | } |
| 4183 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4184 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | pSMB->TotalDataCount = 0; |
| 4186 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4187 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4188 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | pSMB->MaxSetupCount = 0; |
| 4190 | pSMB->Reserved = 0; |
| 4191 | pSMB->Flags = 0; |
| 4192 | pSMB->Timeout = 0; |
| 4193 | pSMB->Reserved2 = 0; |
| 4194 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4195 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | pSMB->DataCount = 0; |
| 4197 | pSMB->DataOffset = 0; |
| 4198 | pSMB->SetupCount = 1; |
| 4199 | pSMB->Reserved3 = 0; |
| 4200 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4201 | byte_count = params + 1 /* pad */ ; |
| 4202 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4203 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4204 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4205 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4206 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4208 | |
| 4209 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4210 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4211 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4212 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | } else { /* decode response */ |
| 4214 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4215 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4216 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4217 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Steve French | 1e71f25 | 2007-09-20 15:30:07 +0000 | [diff] [blame] | 4218 | "Unix Extensions can be disabled on mount " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4219 | "by specifying the nosfu mount option."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | rc = -EIO; /* bad smb */ |
| 4221 | } else { |
| 4222 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4223 | memcpy((char *) pFindData, |
| 4224 | (char *) &pSMBr->hdr.Protocol + |
| 4225 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4226 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | } |
| 4228 | } |
| 4229 | cifs_buf_release(pSMB); |
| 4230 | if (rc == -EAGAIN) |
| 4231 | goto UnixQPathInfoRetry; |
| 4232 | |
| 4233 | return rc; |
| 4234 | } |
| 4235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4237 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4238 | CIFSFindFirst(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4239 | const char *searchName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | const struct nls_table *nls_codepage, |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame^] | 4241 | __u16 *pnetfid, __u16 search_flags, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4242 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | { |
| 4244 | /* level 257 SMB_ */ |
| 4245 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4246 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4247 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | int rc = 0; |
| 4249 | int bytes_returned = 0; |
| 4250 | int name_len; |
| 4251 | __u16 params, byte_count; |
| 4252 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4253 | cFYI(1, "In FindFirst for %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | |
| 4255 | findFirstRetry: |
| 4256 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4257 | (void **) &pSMBr); |
| 4258 | if (rc) |
| 4259 | return rc; |
| 4260 | |
| 4261 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4262 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4263 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4264 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4265 | /* We can not add the asterik earlier in case |
| 4266 | it got remapped to 0xF03A as if it were part of the |
| 4267 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | name_len *= 2; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4269 | pSMB->FileName[name_len] = dirsep; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4270 | pSMB->FileName[name_len+1] = 0; |
| 4271 | pSMB->FileName[name_len+2] = '*'; |
| 4272 | pSMB->FileName[name_len+3] = 0; |
| 4273 | name_len += 4; /* now the trailing null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ |
| 4275 | pSMB->FileName[name_len+1] = 0; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4276 | name_len += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | } else { /* BB add check for overrun of SMB buf BB */ |
| 4278 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4280 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | free buffer exit; BB */ |
| 4282 | strncpy(pSMB->FileName, searchName, name_len); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4283 | pSMB->FileName[name_len] = dirsep; |
Steve French | 6857547 | 2005-04-30 11:10:57 -0700 | [diff] [blame] | 4284 | pSMB->FileName[name_len+1] = '*'; |
| 4285 | pSMB->FileName[name_len+2] = 0; |
| 4286 | name_len += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | } |
| 4288 | |
| 4289 | params = 12 + name_len /* includes null */ ; |
| 4290 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4291 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4292 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | pSMB->MaxSetupCount = 0; |
| 4294 | pSMB->Reserved = 0; |
| 4295 | pSMB->Flags = 0; |
| 4296 | pSMB->Timeout = 0; |
| 4297 | pSMB->Reserved2 = 0; |
| 4298 | byte_count = params + 1 /* pad */ ; |
| 4299 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4300 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4301 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4302 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4303 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | pSMB->DataCount = 0; |
| 4305 | pSMB->DataOffset = 0; |
| 4306 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4307 | pSMB->Reserved3 = 0; |
| 4308 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4309 | pSMB->SearchAttributes = |
| 4310 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4311 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4312 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame^] | 4313 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4315 | |
| 4316 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4317 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4318 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4320 | |
| 4321 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4322 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4323 | cifs_stats_inc(&tcon->num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4325 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4326 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4328 | cFYI(1, "Error in FindFirst = %d", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4329 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4330 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | |
| 4332 | /* BB eventually could optimize out free and realloc of buf */ |
| 4333 | /* for this case */ |
| 4334 | if (rc == -EAGAIN) |
| 4335 | goto findFirstRetry; |
| 4336 | } else { /* decode response */ |
| 4337 | /* BB remember to free buffer if error BB */ |
| 4338 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4339 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4340 | unsigned int lnoff; |
| 4341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4343 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4345 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | |
| 4347 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4348 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4349 | psrch_inf->srch_entries_start = |
| 4350 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4353 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4354 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4355 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4356 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4358 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4360 | psrch_inf->entries_in_buffer = |
| 4361 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4362 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4364 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4365 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4366 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4367 | psrch_inf->last_entry = NULL; |
| 4368 | return rc; |
| 4369 | } |
| 4370 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4371 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4372 | lnoff; |
| 4373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | *pnetfid = parms->SearchHandle; |
| 4375 | } else { |
| 4376 | cifs_buf_release(pSMB); |
| 4377 | } |
| 4378 | } |
| 4379 | |
| 4380 | return rc; |
| 4381 | } |
| 4382 | |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame^] | 4383 | int CIFSFindNext(const int xid, struct cifs_tcon *tcon, __u16 searchHandle, |
| 4384 | __u16 search_flags, struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | { |
| 4386 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4387 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4388 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | char *response_data; |
| 4390 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4391 | int bytes_returned; |
| 4392 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | __u16 params, byte_count; |
| 4394 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4395 | cFYI(1, "In FindNext"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4397 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | return -ENOENT; |
| 4399 | |
| 4400 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4401 | (void **) &pSMBr); |
| 4402 | if (rc) |
| 4403 | return rc; |
| 4404 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4405 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | byte_count = 0; |
| 4407 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4408 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4409 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | pSMB->MaxSetupCount = 0; |
| 4411 | pSMB->Reserved = 0; |
| 4412 | pSMB->Flags = 0; |
| 4413 | pSMB->Timeout = 0; |
| 4414 | pSMB->Reserved2 = 0; |
| 4415 | pSMB->ParameterOffset = cpu_to_le16( |
| 4416 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4417 | pSMB->DataCount = 0; |
| 4418 | pSMB->DataOffset = 0; |
| 4419 | pSMB->SetupCount = 1; |
| 4420 | pSMB->Reserved3 = 0; |
| 4421 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4422 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4423 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4424 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4426 | pSMB->ResumeKey = psrch_inf->resume_key; |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame^] | 4427 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | |
| 4429 | name_len = psrch_inf->resume_name_len; |
| 4430 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4431 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4433 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4434 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4435 | pSMB->ResumeFileName[name_len] = 0; |
| 4436 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | } else { |
| 4438 | rc = -EINVAL; |
| 4439 | goto FNext2_err_exit; |
| 4440 | } |
| 4441 | byte_count = params + 1 /* pad */ ; |
| 4442 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4443 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4444 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4448 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4449 | cifs_stats_inc(&tcon->num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | if (rc) { |
| 4451 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4452 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4453 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4454 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | } else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4456 | cFYI(1, "FindNext returned = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | } else { /* decode response */ |
| 4458 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4459 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4460 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4461 | unsigned int lnoff; |
| 4462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4464 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4465 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4467 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4469 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4470 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4471 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4472 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4473 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4474 | cifs_small_buf_release( |
| 4475 | psrch_inf->ntwrk_buf_start); |
| 4476 | else |
| 4477 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | psrch_inf->srch_entries_start = response_data; |
| 4479 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4480 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4481 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4482 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4484 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4485 | psrch_inf->entries_in_buffer = |
| 4486 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | psrch_inf->index_of_last_entry += |
| 4488 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4489 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4490 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4491 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4492 | psrch_inf->last_entry = NULL; |
| 4493 | return rc; |
| 4494 | } else |
| 4495 | psrch_inf->last_entry = |
| 4496 | psrch_inf->srch_entries_start + lnoff; |
| 4497 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4498 | /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d", |
| 4499 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | |
| 4501 | /* BB fixme add unlock here */ |
| 4502 | } |
| 4503 | |
| 4504 | } |
| 4505 | |
| 4506 | /* BB On error, should we leave previous search buf (and count and |
| 4507 | last entry fields) intact or free the previous one? */ |
| 4508 | |
| 4509 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4510 | since file handle passed in no longer valid */ |
| 4511 | FNext2_err_exit: |
| 4512 | if (rc != 0) |
| 4513 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | return rc; |
| 4515 | } |
| 4516 | |
| 4517 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4518 | CIFSFindClose(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4519 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | { |
| 4521 | int rc = 0; |
| 4522 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4523 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4524 | cFYI(1, "In CIFSSMBFindClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4526 | |
| 4527 | /* no sense returning error if session restarted |
| 4528 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4529 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | return 0; |
| 4531 | if (rc) |
| 4532 | return rc; |
| 4533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | pSMB->FileID = searchHandle; |
| 4535 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4536 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4537 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4538 | cERROR(1, "Send error in FindClose = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4539 | |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4540 | cifs_stats_inc(&tcon->num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | |
| 4542 | /* Since session is dead, search handle closed on server already */ |
| 4543 | if (rc == -EAGAIN) |
| 4544 | rc = 0; |
| 4545 | |
| 4546 | return rc; |
| 4547 | } |
| 4548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4550 | CIFSGetSrvInodeNumber(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4551 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4552 | __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4553 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | { |
| 4555 | int rc = 0; |
| 4556 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4557 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4558 | int name_len, bytes_returned; |
| 4559 | __u16 params, byte_count; |
| 4560 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4561 | cFYI(1, "In GetSrvInodeNum for %s", searchName); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4562 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4563 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | |
| 4565 | GetInodeNumberRetry: |
| 4566 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4567 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | if (rc) |
| 4569 | return rc; |
| 4570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4572 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4573 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 4574 | searchName, PATH_MAX, nls_codepage, |
| 4575 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | name_len++; /* trailing null */ |
| 4577 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4578 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | name_len = strnlen(searchName, PATH_MAX); |
| 4580 | name_len++; /* trailing null */ |
| 4581 | strncpy(pSMB->FileName, searchName, name_len); |
| 4582 | } |
| 4583 | |
| 4584 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4585 | pSMB->TotalDataCount = 0; |
| 4586 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4587 | /* BB find exact max data count below from sess structure BB */ |
| 4588 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4589 | pSMB->MaxSetupCount = 0; |
| 4590 | pSMB->Reserved = 0; |
| 4591 | pSMB->Flags = 0; |
| 4592 | pSMB->Timeout = 0; |
| 4593 | pSMB->Reserved2 = 0; |
| 4594 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4595 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | pSMB->DataCount = 0; |
| 4597 | pSMB->DataOffset = 0; |
| 4598 | pSMB->SetupCount = 1; |
| 4599 | pSMB->Reserved3 = 0; |
| 4600 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4601 | byte_count = params + 1 /* pad */ ; |
| 4602 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4603 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4604 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4605 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4606 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4608 | |
| 4609 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4610 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4611 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4612 | cFYI(1, "error %d in QueryInternalInfo", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | } else { |
| 4614 | /* decode response */ |
| 4615 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4616 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4617 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | /* If rc should we check for EOPNOSUPP and |
| 4619 | disable the srvino flag? or in caller? */ |
| 4620 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4621 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4623 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4624 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4626 | if (count < 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4627 | cFYI(1, "Illegal size ret in QryIntrnlInf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | rc = -EIO; |
| 4629 | goto GetInodeNumOut; |
| 4630 | } |
| 4631 | pfinfo = (struct file_internal_info *) |
| 4632 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4633 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | } |
| 4635 | } |
| 4636 | GetInodeNumOut: |
| 4637 | cifs_buf_release(pSMB); |
| 4638 | if (rc == -EAGAIN) |
| 4639 | goto GetInodeNumberRetry; |
| 4640 | return rc; |
| 4641 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4643 | /* parses DFS refferal V3 structure |
| 4644 | * caller is responsible for freeing target_nodes |
| 4645 | * returns: |
| 4646 | * on success - 0 |
| 4647 | * on failure - errno |
| 4648 | */ |
| 4649 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4650 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4651 | unsigned int *num_of_nodes, |
| 4652 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4653 | const struct nls_table *nls_codepage, int remap, |
| 4654 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4655 | { |
| 4656 | int i, rc = 0; |
| 4657 | char *data_end; |
| 4658 | bool is_unicode; |
| 4659 | struct dfs_referral_level_3 *ref; |
| 4660 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 4661 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 4662 | is_unicode = true; |
| 4663 | else |
| 4664 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4665 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 4666 | |
| 4667 | if (*num_of_nodes < 1) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4668 | cERROR(1, "num_referrals: must be at least > 0," |
| 4669 | "but we get num_referrals = %d\n", *num_of_nodes); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4670 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4671 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4675 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4676 | cERROR(1, "Referrals of V%d version are not supported," |
| 4677 | "should be V3", le16_to_cpu(ref->VersionNumber)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4678 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4679 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4680 | } |
| 4681 | |
| 4682 | /* get the upper boundary of the resp buffer */ |
| 4683 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 4684 | le16_to_cpu(pSMBr->t2.DataCount); |
| 4685 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4686 | cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n", |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4687 | *num_of_nodes, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4688 | le32_to_cpu(pSMBr->DFSFlags)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4689 | |
| 4690 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
| 4691 | *num_of_nodes, GFP_KERNEL); |
| 4692 | if (*target_nodes == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4693 | cERROR(1, "Failed to allocate buffer for target_nodes\n"); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4694 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4695 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4696 | } |
| 4697 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4698 | /* collect necessary data from referrals */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4699 | for (i = 0; i < *num_of_nodes; i++) { |
| 4700 | char *temp; |
| 4701 | int max_len; |
| 4702 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 4703 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4704 | node->flags = le32_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4705 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 4706 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 4707 | GFP_KERNEL); |
Steve French | 2920ee2 | 2009-08-31 15:27:26 +0000 | [diff] [blame] | 4708 | if (tmp == NULL) { |
| 4709 | rc = -ENOMEM; |
| 4710 | goto parse_DFS_referrals_exit; |
| 4711 | } |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4712 | cifsConvertToUTF16((__le16 *) tmp, searchName, |
| 4713 | PATH_MAX, nls_codepage, remap); |
| 4714 | node->path_consumed = cifs_utf16_bytes(tmp, |
Jeff Layton | 69f801f | 2009-04-30 06:46:32 -0400 | [diff] [blame] | 4715 | le16_to_cpu(pSMBr->PathConsumed), |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4716 | nls_codepage); |
| 4717 | kfree(tmp); |
| 4718 | } else |
| 4719 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4720 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4721 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4722 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4723 | |
| 4724 | /* copy DfsPath */ |
| 4725 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4726 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4727 | node->path_name = cifs_strndup_from_utf16(temp, max_len, |
| 4728 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4729 | if (!node->path_name) { |
| 4730 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4731 | goto parse_DFS_referrals_exit; |
Jeff Layton | 066ce68 | 2009-04-30 07:16:14 -0400 | [diff] [blame] | 4732 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4733 | |
| 4734 | /* copy link target UNC */ |
| 4735 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4736 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4737 | node->node_name = cifs_strndup_from_utf16(temp, max_len, |
| 4738 | is_unicode, nls_codepage); |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4739 | if (!node->node_name) { |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4740 | rc = -ENOMEM; |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4741 | goto parse_DFS_referrals_exit; |
| 4742 | } |
| 4743 | |
| 4744 | ref++; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4745 | } |
| 4746 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4747 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4748 | if (rc) { |
| 4749 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4750 | *target_nodes = NULL; |
| 4751 | *num_of_nodes = 0; |
| 4752 | } |
| 4753 | return rc; |
| 4754 | } |
| 4755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4757 | CIFSGetDFSRefer(const int xid, struct cifs_ses *ses, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | const unsigned char *searchName, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4759 | struct dfs_info3_param **target_nodes, |
| 4760 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4761 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | { |
| 4763 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4764 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4765 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | int rc = 0; |
| 4767 | int bytes_returned; |
| 4768 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4770 | *num_of_nodes = 0; |
| 4771 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4772 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4773 | cFYI(1, "In GetDFSRefer the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | if (ses == NULL) |
| 4775 | return -ENODEV; |
| 4776 | getDFSRetry: |
| 4777 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4778 | (void **) &pSMBr); |
| 4779 | if (rc) |
| 4780 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4781 | |
| 4782 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4783 | but should never be null here anyway */ |
| 4784 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4786 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4787 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4788 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4789 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | |
| 4792 | if (ses->capabilities & CAP_UNICODE) { |
| 4793 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4794 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4795 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
| 4796 | searchName, PATH_MAX, nls_codepage, |
| 4797 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | name_len++; /* trailing null */ |
| 4799 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4800 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | name_len = strnlen(searchName, PATH_MAX); |
| 4802 | name_len++; /* trailing null */ |
| 4803 | strncpy(pSMB->RequestFileName, searchName, name_len); |
| 4804 | } |
| 4805 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4806 | if (ses->server) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4807 | if (ses->server->sec_mode & |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4808 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 4809 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4810 | } |
| 4811 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4812 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4815 | pSMB->TotalDataCount = 0; |
| 4816 | pSMB->DataCount = 0; |
| 4817 | pSMB->DataOffset = 0; |
| 4818 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4819 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4820 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | pSMB->MaxSetupCount = 0; |
| 4822 | pSMB->Reserved = 0; |
| 4823 | pSMB->Flags = 0; |
| 4824 | pSMB->Timeout = 0; |
| 4825 | pSMB->Reserved2 = 0; |
| 4826 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4827 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | pSMB->SetupCount = 1; |
| 4829 | pSMB->Reserved3 = 0; |
| 4830 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4831 | byte_count = params + 3 /* pad */ ; |
| 4832 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4833 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4834 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4835 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4837 | |
| 4838 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4839 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4840 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4841 | cFYI(1, "Send error in GetDFSRefer = %d", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4842 | goto GetDFSRefExit; |
| 4843 | } |
| 4844 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4846 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4847 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4848 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4849 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4851 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4852 | cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4853 | get_bcc(&pSMBr->hdr), |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4854 | le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4855 | |
| 4856 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4857 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4858 | target_nodes, nls_codepage, remap, |
| 4859 | searchName); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4862 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | |
| 4864 | if (rc == -EAGAIN) |
| 4865 | goto getDFSRetry; |
| 4866 | |
| 4867 | return rc; |
| 4868 | } |
| 4869 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4870 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4871 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4872 | SMBOldQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4873 | { |
| 4874 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4875 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4876 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4877 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4878 | int rc = 0; |
| 4879 | int bytes_returned = 0; |
| 4880 | __u16 params, byte_count; |
| 4881 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4882 | cFYI(1, "OldQFSInfo"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4883 | oldQFSInfoRetry: |
| 4884 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4885 | (void **) &pSMBr); |
| 4886 | if (rc) |
| 4887 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4888 | |
| 4889 | params = 2; /* level */ |
| 4890 | pSMB->TotalDataCount = 0; |
| 4891 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4892 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4893 | pSMB->MaxSetupCount = 0; |
| 4894 | pSMB->Reserved = 0; |
| 4895 | pSMB->Flags = 0; |
| 4896 | pSMB->Timeout = 0; |
| 4897 | pSMB->Reserved2 = 0; |
| 4898 | byte_count = params + 1 /* pad */ ; |
| 4899 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4900 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4901 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4902 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4903 | pSMB->DataCount = 0; |
| 4904 | pSMB->DataOffset = 0; |
| 4905 | pSMB->SetupCount = 1; |
| 4906 | pSMB->Reserved3 = 0; |
| 4907 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4908 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4909 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4910 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4911 | |
| 4912 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4913 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4914 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4915 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4916 | } else { /* decode response */ |
| 4917 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4918 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4919 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4920 | rc = -EIO; /* bad smb */ |
| 4921 | else { |
| 4922 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4923 | cFYI(1, "qfsinf resp BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4924 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4925 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4926 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4927 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4928 | FSData->f_bsize = |
| 4929 | le16_to_cpu(response_data->BytesPerSector) * |
| 4930 | le32_to_cpu(response_data-> |
| 4931 | SectorsPerAllocationUnit); |
| 4932 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4933 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4934 | FSData->f_bfree = FSData->f_bavail = |
| 4935 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4936 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4937 | (unsigned long long)FSData->f_blocks, |
| 4938 | (unsigned long long)FSData->f_bfree, |
| 4939 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4940 | } |
| 4941 | } |
| 4942 | cifs_buf_release(pSMB); |
| 4943 | |
| 4944 | if (rc == -EAGAIN) |
| 4945 | goto oldQFSInfoRetry; |
| 4946 | |
| 4947 | return rc; |
| 4948 | } |
| 4949 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4951 | CIFSSMBQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | { |
| 4953 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4954 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4955 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4956 | FILE_SYSTEM_INFO *response_data; |
| 4957 | int rc = 0; |
| 4958 | int bytes_returned = 0; |
| 4959 | __u16 params, byte_count; |
| 4960 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4961 | cFYI(1, "In QFSInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | QFSInfoRetry: |
| 4963 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4964 | (void **) &pSMBr); |
| 4965 | if (rc) |
| 4966 | return rc; |
| 4967 | |
| 4968 | params = 2; /* level */ |
| 4969 | pSMB->TotalDataCount = 0; |
| 4970 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4971 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | pSMB->MaxSetupCount = 0; |
| 4973 | pSMB->Reserved = 0; |
| 4974 | pSMB->Flags = 0; |
| 4975 | pSMB->Timeout = 0; |
| 4976 | pSMB->Reserved2 = 0; |
| 4977 | byte_count = params + 1 /* pad */ ; |
| 4978 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4979 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4980 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4981 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | pSMB->DataCount = 0; |
| 4983 | pSMB->DataOffset = 0; |
| 4984 | pSMB->SetupCount = 1; |
| 4985 | pSMB->Reserved3 = 0; |
| 4986 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4987 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4988 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4990 | |
| 4991 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4992 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4993 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4994 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4996 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4997 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4998 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | rc = -EIO; /* bad smb */ |
| 5000 | else { |
| 5001 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | |
| 5003 | response_data = |
| 5004 | (FILE_SYSTEM_INFO |
| 5005 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5006 | data_offset); |
| 5007 | FSData->f_bsize = |
| 5008 | le32_to_cpu(response_data->BytesPerSector) * |
| 5009 | le32_to_cpu(response_data-> |
| 5010 | SectorsPerAllocationUnit); |
| 5011 | FSData->f_blocks = |
| 5012 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 5013 | FSData->f_bfree = FSData->f_bavail = |
| 5014 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5015 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 5016 | (unsigned long long)FSData->f_blocks, |
| 5017 | (unsigned long long)FSData->f_bfree, |
| 5018 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | } |
| 5020 | } |
| 5021 | cifs_buf_release(pSMB); |
| 5022 | |
| 5023 | if (rc == -EAGAIN) |
| 5024 | goto QFSInfoRetry; |
| 5025 | |
| 5026 | return rc; |
| 5027 | } |
| 5028 | |
| 5029 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5030 | CIFSSMBQFSAttributeInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | { |
| 5032 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5033 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5034 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5035 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5036 | int rc = 0; |
| 5037 | int bytes_returned = 0; |
| 5038 | __u16 params, byte_count; |
| 5039 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5040 | cFYI(1, "In QFSAttributeInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | QFSAttributeRetry: |
| 5042 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5043 | (void **) &pSMBr); |
| 5044 | if (rc) |
| 5045 | return rc; |
| 5046 | |
| 5047 | params = 2; /* level */ |
| 5048 | pSMB->TotalDataCount = 0; |
| 5049 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5050 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5051 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | pSMB->MaxSetupCount = 0; |
| 5053 | pSMB->Reserved = 0; |
| 5054 | pSMB->Flags = 0; |
| 5055 | pSMB->Timeout = 0; |
| 5056 | pSMB->Reserved2 = 0; |
| 5057 | byte_count = params + 1 /* pad */ ; |
| 5058 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5059 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5060 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5061 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | pSMB->DataCount = 0; |
| 5063 | pSMB->DataOffset = 0; |
| 5064 | pSMB->SetupCount = 1; |
| 5065 | pSMB->Reserved3 = 0; |
| 5066 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5067 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5068 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5070 | |
| 5071 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5072 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5073 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5074 | cERROR(1, "Send error in QFSAttributeInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5075 | } else { /* decode response */ |
| 5076 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5077 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5078 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5079 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5080 | rc = -EIO; /* bad smb */ |
| 5081 | } else { |
| 5082 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5083 | response_data = |
| 5084 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5085 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5086 | data_offset); |
| 5087 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5088 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5089 | } |
| 5090 | } |
| 5091 | cifs_buf_release(pSMB); |
| 5092 | |
| 5093 | if (rc == -EAGAIN) |
| 5094 | goto QFSAttributeRetry; |
| 5095 | |
| 5096 | return rc; |
| 5097 | } |
| 5098 | |
| 5099 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5100 | CIFSSMBQFSDeviceInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | { |
| 5102 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5103 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5104 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5105 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5106 | int rc = 0; |
| 5107 | int bytes_returned = 0; |
| 5108 | __u16 params, byte_count; |
| 5109 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5110 | cFYI(1, "In QFSDeviceInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | QFSDeviceRetry: |
| 5112 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5113 | (void **) &pSMBr); |
| 5114 | if (rc) |
| 5115 | return rc; |
| 5116 | |
| 5117 | params = 2; /* level */ |
| 5118 | pSMB->TotalDataCount = 0; |
| 5119 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5120 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5121 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 | pSMB->MaxSetupCount = 0; |
| 5123 | pSMB->Reserved = 0; |
| 5124 | pSMB->Flags = 0; |
| 5125 | pSMB->Timeout = 0; |
| 5126 | pSMB->Reserved2 = 0; |
| 5127 | byte_count = params + 1 /* pad */ ; |
| 5128 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5129 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5130 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5131 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | |
| 5133 | pSMB->DataCount = 0; |
| 5134 | pSMB->DataOffset = 0; |
| 5135 | pSMB->SetupCount = 1; |
| 5136 | pSMB->Reserved3 = 0; |
| 5137 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5138 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5139 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5140 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5141 | |
| 5142 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5143 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5144 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5145 | cFYI(1, "Send error in QFSDeviceInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5146 | } else { /* decode response */ |
| 5147 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5148 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5149 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5150 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5151 | rc = -EIO; /* bad smb */ |
| 5152 | else { |
| 5153 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5154 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5155 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5156 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | data_offset); |
| 5158 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5159 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 | } |
| 5161 | } |
| 5162 | cifs_buf_release(pSMB); |
| 5163 | |
| 5164 | if (rc == -EAGAIN) |
| 5165 | goto QFSDeviceRetry; |
| 5166 | |
| 5167 | return rc; |
| 5168 | } |
| 5169 | |
| 5170 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5171 | CIFSSMBQFSUnixInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | { |
| 5173 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5174 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5175 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5176 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5177 | int rc = 0; |
| 5178 | int bytes_returned = 0; |
| 5179 | __u16 params, byte_count; |
| 5180 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5181 | cFYI(1, "In QFSUnixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5183 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5184 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 | if (rc) |
| 5186 | return rc; |
| 5187 | |
| 5188 | params = 2; /* level */ |
| 5189 | pSMB->TotalDataCount = 0; |
| 5190 | pSMB->DataCount = 0; |
| 5191 | pSMB->DataOffset = 0; |
| 5192 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5193 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5194 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5195 | pSMB->MaxSetupCount = 0; |
| 5196 | pSMB->Reserved = 0; |
| 5197 | pSMB->Flags = 0; |
| 5198 | pSMB->Timeout = 0; |
| 5199 | pSMB->Reserved2 = 0; |
| 5200 | byte_count = params + 1 /* pad */ ; |
| 5201 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5202 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5203 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5204 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | pSMB->SetupCount = 1; |
| 5206 | pSMB->Reserved3 = 0; |
| 5207 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5208 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5209 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5211 | |
| 5212 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5213 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5214 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5215 | cERROR(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5216 | } else { /* decode response */ |
| 5217 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5218 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5219 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5220 | rc = -EIO; /* bad smb */ |
| 5221 | } else { |
| 5222 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5223 | response_data = |
| 5224 | (FILE_SYSTEM_UNIX_INFO |
| 5225 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5226 | data_offset); |
| 5227 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5228 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | } |
| 5230 | } |
| 5231 | cifs_buf_release(pSMB); |
| 5232 | |
| 5233 | if (rc == -EAGAIN) |
| 5234 | goto QFSUnixRetry; |
| 5235 | |
| 5236 | |
| 5237 | return rc; |
| 5238 | } |
| 5239 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5240 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5241 | CIFSSMBSetFSUnixInfo(const int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5242 | { |
| 5243 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5244 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5245 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5246 | int rc = 0; |
| 5247 | int bytes_returned = 0; |
| 5248 | __u16 params, param_offset, offset, byte_count; |
| 5249 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5250 | cFYI(1, "In SETFSUnixInfo"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5251 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5252 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5253 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5254 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5255 | if (rc) |
| 5256 | return rc; |
| 5257 | |
| 5258 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5259 | pSMB->MaxSetupCount = 0; |
| 5260 | pSMB->Reserved = 0; |
| 5261 | pSMB->Flags = 0; |
| 5262 | pSMB->Timeout = 0; |
| 5263 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5264 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5265 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5266 | offset = param_offset + params; |
| 5267 | |
| 5268 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5269 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5270 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5271 | pSMB->SetupCount = 1; |
| 5272 | pSMB->Reserved3 = 0; |
| 5273 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5274 | byte_count = 1 /* pad */ + params + 12; |
| 5275 | |
| 5276 | pSMB->DataCount = cpu_to_le16(12); |
| 5277 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5278 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5279 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5280 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5281 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5282 | |
| 5283 | /* Params. */ |
| 5284 | pSMB->FileNum = 0; |
| 5285 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5286 | |
| 5287 | /* Data. */ |
| 5288 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5289 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5290 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5291 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5292 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5293 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5294 | |
| 5295 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5296 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5297 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5298 | cERROR(1, "Send error in SETFSUnixInfo = %d", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5299 | } else { /* decode response */ |
| 5300 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5301 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5302 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5303 | } |
| 5304 | cifs_buf_release(pSMB); |
| 5305 | |
| 5306 | if (rc == -EAGAIN) |
| 5307 | goto SETFSUnixRetry; |
| 5308 | |
| 5309 | return rc; |
| 5310 | } |
| 5311 | |
| 5312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | |
| 5314 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5315 | CIFSSMBQFSPosixInfo(const int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5316 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5317 | { |
| 5318 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5319 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5320 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5321 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5322 | int rc = 0; |
| 5323 | int bytes_returned = 0; |
| 5324 | __u16 params, byte_count; |
| 5325 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5326 | cFYI(1, "In QFSPosixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | QFSPosixRetry: |
| 5328 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5329 | (void **) &pSMBr); |
| 5330 | if (rc) |
| 5331 | return rc; |
| 5332 | |
| 5333 | params = 2; /* level */ |
| 5334 | pSMB->TotalDataCount = 0; |
| 5335 | pSMB->DataCount = 0; |
| 5336 | pSMB->DataOffset = 0; |
| 5337 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5338 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5339 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5340 | pSMB->MaxSetupCount = 0; |
| 5341 | pSMB->Reserved = 0; |
| 5342 | pSMB->Flags = 0; |
| 5343 | pSMB->Timeout = 0; |
| 5344 | pSMB->Reserved2 = 0; |
| 5345 | byte_count = params + 1 /* pad */ ; |
| 5346 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5347 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5348 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5349 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5350 | pSMB->SetupCount = 1; |
| 5351 | pSMB->Reserved3 = 0; |
| 5352 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5353 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5354 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5355 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5356 | |
| 5357 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5358 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5359 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5360 | cFYI(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | } else { /* decode response */ |
| 5362 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5363 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5364 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5365 | rc = -EIO; /* bad smb */ |
| 5366 | } else { |
| 5367 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5368 | response_data = |
| 5369 | (FILE_SYSTEM_POSIX_INFO |
| 5370 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5371 | data_offset); |
| 5372 | FSData->f_bsize = |
| 5373 | le32_to_cpu(response_data->BlockSize); |
| 5374 | FSData->f_blocks = |
| 5375 | le64_to_cpu(response_data->TotalBlocks); |
| 5376 | FSData->f_bfree = |
| 5377 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5378 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5379 | FSData->f_bavail = FSData->f_bfree; |
| 5380 | } else { |
| 5381 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5382 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5384 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5385 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5386 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5387 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5388 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5389 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | } |
| 5391 | } |
| 5392 | cifs_buf_release(pSMB); |
| 5393 | |
| 5394 | if (rc == -EAGAIN) |
| 5395 | goto QFSPosixRetry; |
| 5396 | |
| 5397 | return rc; |
| 5398 | } |
| 5399 | |
| 5400 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5401 | /* We can not use write of zero bytes trick to |
| 5402 | set file size due to need for large file support. Also note that |
| 5403 | this SetPathInfo is preferred to SetFileInfo based method in next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | routine which is only needed to work around a sharing violation bug |
| 5405 | in Samba which this routine can run into */ |
| 5406 | |
| 5407 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5408 | CIFSSMBSetEOF(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5409 | __u64 size, bool SetAllocation, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5410 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 | { |
| 5412 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5413 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5414 | struct file_end_of_file_info *parm_data; |
| 5415 | int name_len; |
| 5416 | int rc = 0; |
| 5417 | int bytes_returned = 0; |
| 5418 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5419 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5420 | cFYI(1, "In SetEOF"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | SetEOFRetry: |
| 5422 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5423 | (void **) &pSMBr); |
| 5424 | if (rc) |
| 5425 | return rc; |
| 5426 | |
| 5427 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5428 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5429 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5430 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5431 | name_len++; /* trailing null */ |
| 5432 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5433 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5434 | name_len = strnlen(fileName, PATH_MAX); |
| 5435 | name_len++; /* trailing null */ |
| 5436 | strncpy(pSMB->FileName, fileName, name_len); |
| 5437 | } |
| 5438 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5439 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5440 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5441 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5442 | pSMB->MaxSetupCount = 0; |
| 5443 | pSMB->Reserved = 0; |
| 5444 | pSMB->Flags = 0; |
| 5445 | pSMB->Timeout = 0; |
| 5446 | pSMB->Reserved2 = 0; |
| 5447 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5448 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5449 | offset = param_offset + params; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5450 | if (SetAllocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5451 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5452 | pSMB->InformationLevel = |
| 5453 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5454 | else |
| 5455 | pSMB->InformationLevel = |
| 5456 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5457 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5459 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5460 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 | else |
| 5462 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5463 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | parm_data = |
| 5467 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5468 | offset); |
| 5469 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5470 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5471 | pSMB->SetupCount = 1; |
| 5472 | pSMB->Reserved3 = 0; |
| 5473 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5474 | byte_count = 3 /* pad */ + params + data_count; |
| 5475 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5476 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5477 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5478 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5479 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5480 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5481 | parm_data->FileSize = cpu_to_le64(size); |
| 5482 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5483 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5484 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5485 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5486 | cFYI(1, "SetPathInfo (file size) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | |
| 5488 | cifs_buf_release(pSMB); |
| 5489 | |
| 5490 | if (rc == -EAGAIN) |
| 5491 | goto SetEOFRetry; |
| 5492 | |
| 5493 | return rc; |
| 5494 | } |
| 5495 | |
| 5496 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5497 | CIFSSMBSetFileSize(const int xid, struct cifs_tcon *tcon, __u64 size, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5498 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5499 | { |
| 5500 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | struct file_end_of_file_info *parm_data; |
| 5502 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | __u16 params, param_offset, offset, byte_count, count; |
| 5504 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5505 | cFYI(1, "SetFileSize (via SetFileInfo) %lld", |
| 5506 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5507 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | if (rc) |
| 5510 | return rc; |
| 5511 | |
| 5512 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5513 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | params = 6; |
| 5516 | pSMB->MaxSetupCount = 0; |
| 5517 | pSMB->Reserved = 0; |
| 5518 | pSMB->Flags = 0; |
| 5519 | pSMB->Timeout = 0; |
| 5520 | pSMB->Reserved2 = 0; |
| 5521 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5522 | offset = param_offset + params; |
| 5523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | count = sizeof(struct file_end_of_file_info); |
| 5525 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5526 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5527 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5528 | pSMB->SetupCount = 1; |
| 5529 | pSMB->Reserved3 = 0; |
| 5530 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5531 | byte_count = 3 /* pad */ + params + count; |
| 5532 | pSMB->DataCount = cpu_to_le16(count); |
| 5533 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5534 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5535 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5536 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5537 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5538 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5539 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5541 | parm_data->FileSize = cpu_to_le64(size); |
| 5542 | pSMB->Fid = fid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5543 | if (SetAllocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5545 | pSMB->InformationLevel = |
| 5546 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5547 | else |
| 5548 | pSMB->InformationLevel = |
| 5549 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5550 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5551 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5552 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5553 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 | else |
| 5555 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5556 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5557 | } |
| 5558 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5559 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5560 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5561 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5562 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5563 | cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | } |
| 5565 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5566 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | since file handle passed in no longer valid */ |
| 5568 | |
| 5569 | return rc; |
| 5570 | } |
| 5571 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5572 | /* Some legacy servers such as NT4 require that the file times be set on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | an open handle, rather than by pathname - this is awkward due to |
| 5574 | potential access conflicts on the open, but it is unavoidable for these |
| 5575 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5576 | time and resort to the original setpathinfo level which takes the ancient |
| 5577 | DOS time format with 2 second granularity */ |
| 5578 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5579 | CIFSSMBSetFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5580 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5581 | { |
| 5582 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | char *data_offset; |
| 5584 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5585 | __u16 params, param_offset, offset, byte_count, count; |
| 5586 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5587 | cFYI(1, "Set Times (via SetFileInfo)"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5588 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | if (rc) |
| 5591 | return rc; |
| 5592 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5593 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5594 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5596 | params = 6; |
| 5597 | pSMB->MaxSetupCount = 0; |
| 5598 | pSMB->Reserved = 0; |
| 5599 | pSMB->Flags = 0; |
| 5600 | pSMB->Timeout = 0; |
| 5601 | pSMB->Reserved2 = 0; |
| 5602 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5603 | offset = param_offset + params; |
| 5604 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5605 | data_offset = (char *)pSMB + |
| 5606 | offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5607 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5608 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5609 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5610 | /* BB find max SMB PDU from sess */ |
| 5611 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | pSMB->SetupCount = 1; |
| 5613 | pSMB->Reserved3 = 0; |
| 5614 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5615 | byte_count = 3 /* pad */ + params + count; |
| 5616 | pSMB->DataCount = cpu_to_le16(count); |
| 5617 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5618 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5619 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5620 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5621 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5622 | pSMB->Fid = fid; |
| 5623 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5624 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5625 | else |
| 5626 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5627 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5628 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5629 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5630 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5631 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5632 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5633 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5635 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 | since file handle passed in no longer valid */ |
| 5637 | |
| 5638 | return rc; |
| 5639 | } |
| 5640 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5641 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5642 | CIFSSMBSetFileDisposition(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5643 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5644 | { |
| 5645 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5646 | char *data_offset; |
| 5647 | int rc = 0; |
| 5648 | __u16 params, param_offset, offset, byte_count, count; |
| 5649 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5650 | cFYI(1, "Set File Disposition (via SetFileInfo)"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5651 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5652 | |
| 5653 | if (rc) |
| 5654 | return rc; |
| 5655 | |
| 5656 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5657 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5658 | |
| 5659 | params = 6; |
| 5660 | pSMB->MaxSetupCount = 0; |
| 5661 | pSMB->Reserved = 0; |
| 5662 | pSMB->Flags = 0; |
| 5663 | pSMB->Timeout = 0; |
| 5664 | pSMB->Reserved2 = 0; |
| 5665 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5666 | offset = param_offset + params; |
| 5667 | |
| 5668 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5669 | |
| 5670 | count = 1; |
| 5671 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5672 | /* BB find max SMB PDU from sess */ |
| 5673 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5674 | pSMB->SetupCount = 1; |
| 5675 | pSMB->Reserved3 = 0; |
| 5676 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5677 | byte_count = 3 /* pad */ + params + count; |
| 5678 | pSMB->DataCount = cpu_to_le16(count); |
| 5679 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5680 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5681 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5682 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5683 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5684 | pSMB->Fid = fid; |
| 5685 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5686 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5687 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5688 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5689 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5690 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5691 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5692 | cFYI(1, "Send error in SetFileDisposition = %d", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5693 | |
| 5694 | return rc; |
| 5695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | |
| 5697 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5698 | CIFSSMBSetPathInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5699 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5700 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | { |
| 5702 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5703 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5704 | int name_len; |
| 5705 | int rc = 0; |
| 5706 | int bytes_returned = 0; |
| 5707 | char *data_offset; |
| 5708 | __u16 params, param_offset, offset, byte_count, count; |
| 5709 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5710 | cFYI(1, "In SetTimes"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5711 | |
| 5712 | SetTimesRetry: |
| 5713 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5714 | (void **) &pSMBr); |
| 5715 | if (rc) |
| 5716 | return rc; |
| 5717 | |
| 5718 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5719 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5720 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5721 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5722 | name_len++; /* trailing null */ |
| 5723 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5724 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5725 | name_len = strnlen(fileName, PATH_MAX); |
| 5726 | name_len++; /* trailing null */ |
| 5727 | strncpy(pSMB->FileName, fileName, name_len); |
| 5728 | } |
| 5729 | |
| 5730 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5731 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5733 | /* BB find max SMB PDU from sess structure BB */ |
| 5734 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | pSMB->MaxSetupCount = 0; |
| 5736 | pSMB->Reserved = 0; |
| 5737 | pSMB->Flags = 0; |
| 5738 | pSMB->Timeout = 0; |
| 5739 | pSMB->Reserved2 = 0; |
| 5740 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5741 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | offset = param_offset + params; |
| 5743 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5744 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5745 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5746 | pSMB->SetupCount = 1; |
| 5747 | pSMB->Reserved3 = 0; |
| 5748 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5749 | byte_count = 3 /* pad */ + params + count; |
| 5750 | |
| 5751 | pSMB->DataCount = cpu_to_le16(count); |
| 5752 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5753 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5754 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5755 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5756 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5757 | else |
| 5758 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5759 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5760 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5761 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5762 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5763 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5764 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5765 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5766 | cFYI(1, "SetPathInfo (times) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5767 | |
| 5768 | cifs_buf_release(pSMB); |
| 5769 | |
| 5770 | if (rc == -EAGAIN) |
| 5771 | goto SetTimesRetry; |
| 5772 | |
| 5773 | return rc; |
| 5774 | } |
| 5775 | |
| 5776 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5777 | /* Can be used to set attributes */ |
| 5778 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5779 | handling it anyway and NT4 was what we thought it would be needed for |
| 5780 | Do not delete it until we prove whether needed for Win9x though */ |
| 5781 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5782 | CIFSSMBSetAttrLegacy(int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5783 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5784 | { |
| 5785 | SETATTR_REQ *pSMB = NULL; |
| 5786 | SETATTR_RSP *pSMBr = NULL; |
| 5787 | int rc = 0; |
| 5788 | int bytes_returned; |
| 5789 | int name_len; |
| 5790 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5791 | cFYI(1, "In SetAttrLegacy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5792 | |
| 5793 | SetAttrLgcyRetry: |
| 5794 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5795 | (void **) &pSMBr); |
| 5796 | if (rc) |
| 5797 | return rc; |
| 5798 | |
| 5799 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5800 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5801 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 5802 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5803 | name_len++; /* trailing null */ |
| 5804 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5805 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | name_len = strnlen(fileName, PATH_MAX); |
| 5807 | name_len++; /* trailing null */ |
| 5808 | strncpy(pSMB->fileName, fileName, name_len); |
| 5809 | } |
| 5810 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5811 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5812 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5813 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5814 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5815 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5816 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5817 | cFYI(1, "Error in LegacySetAttr = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5818 | |
| 5819 | cifs_buf_release(pSMB); |
| 5820 | |
| 5821 | if (rc == -EAGAIN) |
| 5822 | goto SetAttrLgcyRetry; |
| 5823 | |
| 5824 | return rc; |
| 5825 | } |
| 5826 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5827 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5828 | static void |
| 5829 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5830 | const struct cifs_unix_set_info_args *args) |
| 5831 | { |
| 5832 | u64 mode = args->mode; |
| 5833 | |
| 5834 | /* |
| 5835 | * Samba server ignores set of file size to zero due to bugs in some |
| 5836 | * older clients, but we should be precise - we use SetFileSize to |
| 5837 | * set file size and do not want to truncate file size to zero |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5838 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5839 | * zero instead of -1 here |
| 5840 | */ |
| 5841 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5842 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5843 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5844 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5845 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
| 5846 | data_offset->Uid = cpu_to_le64(args->uid); |
| 5847 | data_offset->Gid = cpu_to_le64(args->gid); |
| 5848 | /* better to leave device as zero when it is */ |
| 5849 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5850 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5851 | data_offset->Permissions = cpu_to_le64(mode); |
| 5852 | |
| 5853 | if (S_ISREG(mode)) |
| 5854 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5855 | else if (S_ISDIR(mode)) |
| 5856 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 5857 | else if (S_ISLNK(mode)) |
| 5858 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 5859 | else if (S_ISCHR(mode)) |
| 5860 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 5861 | else if (S_ISBLK(mode)) |
| 5862 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 5863 | else if (S_ISFIFO(mode)) |
| 5864 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 5865 | else if (S_ISSOCK(mode)) |
| 5866 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5867 | } |
| 5868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5869 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5870 | CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5871 | const struct cifs_unix_set_info_args *args, |
| 5872 | u16 fid, u32 pid_of_opener) |
| 5873 | { |
| 5874 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5875 | char *data_offset; |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5876 | int rc = 0; |
| 5877 | u16 params, param_offset, offset, byte_count, count; |
| 5878 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5879 | cFYI(1, "Set Unix Info (via SetFileInfo)"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5880 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5881 | |
| 5882 | if (rc) |
| 5883 | return rc; |
| 5884 | |
| 5885 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5886 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5887 | |
| 5888 | params = 6; |
| 5889 | pSMB->MaxSetupCount = 0; |
| 5890 | pSMB->Reserved = 0; |
| 5891 | pSMB->Flags = 0; |
| 5892 | pSMB->Timeout = 0; |
| 5893 | pSMB->Reserved2 = 0; |
| 5894 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5895 | offset = param_offset + params; |
| 5896 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5897 | data_offset = (char *)pSMB + |
| 5898 | offsetof(struct smb_hdr, Protocol) + offset; |
| 5899 | |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5900 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 5901 | |
| 5902 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5903 | /* BB find max SMB PDU from sess */ |
| 5904 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5905 | pSMB->SetupCount = 1; |
| 5906 | pSMB->Reserved3 = 0; |
| 5907 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5908 | byte_count = 3 /* pad */ + params + count; |
| 5909 | pSMB->DataCount = cpu_to_le16(count); |
| 5910 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5911 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5912 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5913 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5914 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5915 | pSMB->Fid = fid; |
| 5916 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5917 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5918 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5919 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5920 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5921 | cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5922 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5923 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5924 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5925 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5926 | |
| 5927 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 5928 | since file handle passed in no longer valid */ |
| 5929 | |
| 5930 | return rc; |
| 5931 | } |
| 5932 | |
| 5933 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5934 | CIFSSMBUnixSetPathInfo(const int xid, struct cifs_tcon *tcon, char *fileName, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5935 | const struct cifs_unix_set_info_args *args, |
| 5936 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5937 | { |
| 5938 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5939 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5940 | int name_len; |
| 5941 | int rc = 0; |
| 5942 | int bytes_returned = 0; |
| 5943 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5944 | __u16 params, param_offset, offset, count, byte_count; |
| 5945 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5946 | cFYI(1, "In SetUID/GID/Mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5947 | setPermsRetry: |
| 5948 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5949 | (void **) &pSMBr); |
| 5950 | if (rc) |
| 5951 | return rc; |
| 5952 | |
| 5953 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5954 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5955 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5956 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5957 | name_len++; /* trailing null */ |
| 5958 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5959 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5960 | name_len = strnlen(fileName, PATH_MAX); |
| 5961 | name_len++; /* trailing null */ |
| 5962 | strncpy(pSMB->FileName, fileName, name_len); |
| 5963 | } |
| 5964 | |
| 5965 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5966 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5967 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5968 | /* BB find max SMB PDU from sess structure BB */ |
| 5969 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5970 | pSMB->MaxSetupCount = 0; |
| 5971 | pSMB->Reserved = 0; |
| 5972 | pSMB->Flags = 0; |
| 5973 | pSMB->Timeout = 0; |
| 5974 | pSMB->Reserved2 = 0; |
| 5975 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5976 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5977 | offset = param_offset + params; |
| 5978 | data_offset = |
| 5979 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 5980 | offset); |
| 5981 | memset(data_offset, 0, count); |
| 5982 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5983 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5984 | pSMB->SetupCount = 1; |
| 5985 | pSMB->Reserved3 = 0; |
| 5986 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5987 | byte_count = 3 /* pad */ + params + count; |
| 5988 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5989 | pSMB->DataCount = cpu_to_le16(count); |
| 5990 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5991 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5992 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5993 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5994 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5995 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5996 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5997 | |
| 5998 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5999 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6000 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6001 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6002 | cFYI(1, "SetPathInfo (perms) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6003 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6004 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6005 | if (rc == -EAGAIN) |
| 6006 | goto setPermsRetry; |
| 6007 | return rc; |
| 6008 | } |
| 6009 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6011 | /* |
| 6012 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 6013 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 6014 | * it looks for that attribute name and stuffs that value into the EAData |
| 6015 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 6016 | * buffer. In both cases, the return value is either the length of the |
| 6017 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 6018 | * the data isn't copied to it, but the length is returned. |
| 6019 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | ssize_t |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6021 | CIFSSMBQAllEAs(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6022 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6023 | char *EAData, size_t buf_size, |
| 6024 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6025 | { |
| 6026 | /* BB assumes one setup word */ |
| 6027 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6028 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 6029 | int rc = 0; |
| 6030 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6031 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6032 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6033 | struct fea *temp_fea; |
| 6034 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6035 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6036 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6037 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6038 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6039 | cFYI(1, "In Query All EAs path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6040 | QAllEAsRetry: |
| 6041 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6042 | (void **) &pSMBr); |
| 6043 | if (rc) |
| 6044 | return rc; |
| 6045 | |
| 6046 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6047 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6048 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6049 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6050 | list_len++; /* trailing null */ |
| 6051 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6052 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6053 | list_len = strnlen(searchName, PATH_MAX); |
| 6054 | list_len++; /* trailing null */ |
| 6055 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6056 | } |
| 6057 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6058 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6059 | pSMB->TotalDataCount = 0; |
| 6060 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6061 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6062 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6063 | pSMB->MaxSetupCount = 0; |
| 6064 | pSMB->Reserved = 0; |
| 6065 | pSMB->Flags = 0; |
| 6066 | pSMB->Timeout = 0; |
| 6067 | pSMB->Reserved2 = 0; |
| 6068 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6069 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6070 | pSMB->DataCount = 0; |
| 6071 | pSMB->DataOffset = 0; |
| 6072 | pSMB->SetupCount = 1; |
| 6073 | pSMB->Reserved3 = 0; |
| 6074 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6075 | byte_count = params + 1 /* pad */ ; |
| 6076 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6077 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6078 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6079 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6080 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6081 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6082 | |
| 6083 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6084 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6085 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6086 | cFYI(1, "Send error in QueryAllEAs = %d", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6087 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6088 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6089 | |
| 6090 | |
| 6091 | /* BB also check enough total bytes returned */ |
| 6092 | /* BB we need to improve the validity checking |
| 6093 | of these trans2 responses */ |
| 6094 | |
| 6095 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6096 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6097 | rc = -EIO; /* bad smb */ |
| 6098 | goto QAllEAsOut; |
| 6099 | } |
| 6100 | |
| 6101 | /* check that length of list is not more than bcc */ |
| 6102 | /* check that each entry does not go beyond length |
| 6103 | of list */ |
| 6104 | /* check that each element of each entry does not |
| 6105 | go beyond end of list */ |
| 6106 | /* validate_trans2_offsets() */ |
| 6107 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6108 | |
| 6109 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6110 | ea_response_data = (struct fealist *) |
| 6111 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6112 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6113 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6114 | cFYI(1, "ea length %d", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6115 | if (list_len <= 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6116 | cFYI(1, "empty EA list returned from server"); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6117 | goto QAllEAsOut; |
| 6118 | } |
| 6119 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6120 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6121 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6122 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6123 | cFYI(1, "EA list appears to go beyond SMB"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6124 | rc = -EIO; |
| 6125 | goto QAllEAsOut; |
| 6126 | } |
| 6127 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6128 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6129 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6130 | temp_fea = ea_response_data->list; |
| 6131 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6132 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6133 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6134 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6135 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6136 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6137 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6138 | /* make sure we can read name_len and value_len */ |
| 6139 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6140 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6141 | rc = -EIO; |
| 6142 | goto QAllEAsOut; |
| 6143 | } |
| 6144 | |
| 6145 | name_len = temp_fea->name_len; |
| 6146 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6147 | list_len -= name_len + 1 + value_len; |
| 6148 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6149 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6150 | rc = -EIO; |
| 6151 | goto QAllEAsOut; |
| 6152 | } |
| 6153 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6154 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6155 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6156 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6157 | temp_ptr += name_len + 1; |
| 6158 | rc = value_len; |
| 6159 | if (buf_size == 0) |
| 6160 | goto QAllEAsOut; |
| 6161 | if ((size_t)value_len > buf_size) { |
| 6162 | rc = -ERANGE; |
| 6163 | goto QAllEAsOut; |
| 6164 | } |
| 6165 | memcpy(EAData, temp_ptr, value_len); |
| 6166 | goto QAllEAsOut; |
| 6167 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6168 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6169 | /* account for prefix user. and trailing null */ |
| 6170 | rc += (5 + 1 + name_len); |
| 6171 | if (rc < (int) buf_size) { |
| 6172 | memcpy(EAData, "user.", 5); |
| 6173 | EAData += 5; |
| 6174 | memcpy(EAData, temp_ptr, name_len); |
| 6175 | EAData += name_len; |
| 6176 | /* null terminate name */ |
| 6177 | *EAData = 0; |
| 6178 | ++EAData; |
| 6179 | } else if (buf_size == 0) { |
| 6180 | /* skip copy - calc size only */ |
| 6181 | } else { |
| 6182 | /* stop before overrun buffer */ |
| 6183 | rc = -ERANGE; |
| 6184 | break; |
| 6185 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6186 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6187 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6188 | temp_fea = (struct fea *)temp_ptr; |
| 6189 | } |
| 6190 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6191 | /* didn't find the named attribute */ |
| 6192 | if (ea_name) |
| 6193 | rc = -ENODATA; |
| 6194 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6195 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6196 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6197 | if (rc == -EAGAIN) |
| 6198 | goto QAllEAsRetry; |
| 6199 | |
| 6200 | return (ssize_t)rc; |
| 6201 | } |
| 6202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6203 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6204 | CIFSSMBSetEA(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6205 | const char *ea_name, const void *ea_value, |
| 6206 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 6207 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6208 | { |
| 6209 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6210 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6211 | struct fealist *parm_data; |
| 6212 | int name_len; |
| 6213 | int rc = 0; |
| 6214 | int bytes_returned = 0; |
| 6215 | __u16 params, param_offset, byte_count, offset, count; |
| 6216 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6217 | cFYI(1, "In SetEA"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6218 | SetEARetry: |
| 6219 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6220 | (void **) &pSMBr); |
| 6221 | if (rc) |
| 6222 | return rc; |
| 6223 | |
| 6224 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6225 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6226 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6227 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | name_len++; /* trailing null */ |
| 6229 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6230 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6231 | name_len = strnlen(fileName, PATH_MAX); |
| 6232 | name_len++; /* trailing null */ |
| 6233 | strncpy(pSMB->FileName, fileName, name_len); |
| 6234 | } |
| 6235 | |
| 6236 | params = 6 + name_len; |
| 6237 | |
| 6238 | /* done calculating parms using name_len of file name, |
| 6239 | now use name_len to calculate length of ea name |
| 6240 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6241 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6242 | name_len = 0; |
| 6243 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6244 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6245 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6246 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6247 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6248 | /* BB find max SMB PDU from sess */ |
| 6249 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6250 | pSMB->MaxSetupCount = 0; |
| 6251 | pSMB->Reserved = 0; |
| 6252 | pSMB->Flags = 0; |
| 6253 | pSMB->Timeout = 0; |
| 6254 | pSMB->Reserved2 = 0; |
| 6255 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6256 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6257 | offset = param_offset + params; |
| 6258 | pSMB->InformationLevel = |
| 6259 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6260 | |
| 6261 | parm_data = |
| 6262 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 6263 | offset); |
| 6264 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6265 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6266 | pSMB->SetupCount = 1; |
| 6267 | pSMB->Reserved3 = 0; |
| 6268 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6269 | byte_count = 3 /* pad */ + params + count; |
| 6270 | pSMB->DataCount = cpu_to_le16(count); |
| 6271 | parm_data->list_len = cpu_to_le32(count); |
| 6272 | parm_data->list[0].EA_flags = 0; |
| 6273 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6274 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6275 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6276 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6277 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6278 | parm_data->list[0].name[name_len] = 0; |
| 6279 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6280 | /* caller ensures that ea_value_len is less than 64K but |
| 6281 | we need to ensure that it fits within the smb */ |
| 6282 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6283 | /*BB add length check to see if it would fit in |
| 6284 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6285 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6286 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6287 | memcpy(parm_data->list[0].name+name_len+1, |
| 6288 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | |
| 6290 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6291 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6292 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6293 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6294 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6295 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6296 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6297 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6298 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6299 | cFYI(1, "SetPathInfo (EA) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | |
| 6301 | cifs_buf_release(pSMB); |
| 6302 | |
| 6303 | if (rc == -EAGAIN) |
| 6304 | goto SetEARetry; |
| 6305 | |
| 6306 | return rc; |
| 6307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6308 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6309 | |
| 6310 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 6311 | /* |
| 6312 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 6313 | * to allow network clients (such as Windows) to display updated |
| 6314 | * lists of files in directory listings automatically when |
| 6315 | * files are added by one user when another user has the |
| 6316 | * same directory open on their desktop. The Linux cifs kernel |
| 6317 | * client hooked into the kernel side of this interface for |
| 6318 | * the same reason, but ironically when the VFS moved from |
| 6319 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 6320 | * network file system clients (the most obvious use case |
| 6321 | * for notify interfaces is when multiple users can update |
| 6322 | * the contents of the same directory - exactly what network |
| 6323 | * file systems can do) although the server (Samba) could |
| 6324 | * still use it. For the short term we leave the worker |
| 6325 | * function ifdeffed out (below) until inotify is fixed |
| 6326 | * in the VFS to make it easier to plug in network file |
| 6327 | * system clients. If inotify turns out to be permanently |
| 6328 | * incompatible for network fs clients, we could instead simply |
| 6329 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 6330 | */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6331 | int CIFSSMBNotify(const int xid, struct cifs_tcon *tcon, |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6332 | const int notify_subdirs, const __u16 netfid, |
| 6333 | __u32 filter, struct file *pfile, int multishot, |
| 6334 | const struct nls_table *nls_codepage) |
| 6335 | { |
| 6336 | int rc = 0; |
| 6337 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 6338 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 6339 | struct dir_notify_req *dnotify_req; |
| 6340 | int bytes_returned; |
| 6341 | |
| 6342 | cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid); |
| 6343 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 6344 | (void **) &pSMBr); |
| 6345 | if (rc) |
| 6346 | return rc; |
| 6347 | |
| 6348 | pSMB->TotalParameterCount = 0 ; |
| 6349 | pSMB->TotalDataCount = 0; |
| 6350 | pSMB->MaxParameterCount = cpu_to_le32(2); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6351 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6352 | pSMB->MaxSetupCount = 4; |
| 6353 | pSMB->Reserved = 0; |
| 6354 | pSMB->ParameterOffset = 0; |
| 6355 | pSMB->DataCount = 0; |
| 6356 | pSMB->DataOffset = 0; |
| 6357 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 6358 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 6359 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6360 | if (notify_subdirs) |
| 6361 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 6362 | pSMB->Reserved2 = 0; |
| 6363 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 6364 | pSMB->Fid = netfid; /* file handle always le */ |
| 6365 | pSMB->ByteCount = 0; |
| 6366 | |
| 6367 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6368 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 6369 | CIFS_ASYNC_OP); |
| 6370 | if (rc) { |
| 6371 | cFYI(1, "Error in Notify = %d", rc); |
| 6372 | } else { |
| 6373 | /* Add file to outstanding requests */ |
| 6374 | /* BB change to kmem cache alloc */ |
| 6375 | dnotify_req = kmalloc( |
| 6376 | sizeof(struct dir_notify_req), |
| 6377 | GFP_KERNEL); |
| 6378 | if (dnotify_req) { |
| 6379 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 6380 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 6381 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 6382 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 6383 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 6384 | dnotify_req->netfid = netfid; |
| 6385 | dnotify_req->pfile = pfile; |
| 6386 | dnotify_req->filter = filter; |
| 6387 | dnotify_req->multishot = multishot; |
| 6388 | spin_lock(&GlobalMid_Lock); |
| 6389 | list_add_tail(&dnotify_req->lhead, |
| 6390 | &GlobalDnotifyReqList); |
| 6391 | spin_unlock(&GlobalMid_Lock); |
| 6392 | } else |
| 6393 | rc = -ENOMEM; |
| 6394 | } |
| 6395 | cifs_buf_release(pSMB); |
| 6396 | return rc; |
| 6397 | } |
| 6398 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |