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 | a454434 | 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 | a454434 | 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 | 99d86c8f | 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 | a454434 | 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 | a454434 | 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 | a454434 | 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 | a454434 | 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 | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1403 | CIFSMaxBufSize + MAX_HEADER_SIZE(server))); |
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 | |
| 1414 | static int |
| 1415 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1416 | { |
| 1417 | int length, len; |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1418 | unsigned int data_offset, data_len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1419 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1420 | char *buf = server->smallbuf; |
| 1421 | unsigned int buflen = get_rfc1002_length(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1422 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1423 | cFYI(1, "%s: mid=%llu offset=%llu bytes=%u", __func__, |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1424 | mid->mid, rdata->offset, rdata->bytes); |
| 1425 | |
| 1426 | /* |
| 1427 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1428 | * can if there's not enough data. At this point, we've read down to |
| 1429 | * the Mid. |
| 1430 | */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame^] | 1431 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1432 | HEADER_SIZE(server) + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1433 | |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1434 | rdata->iov[0].iov_base = buf + HEADER_SIZE(server) - 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1435 | rdata->iov[0].iov_len = len; |
| 1436 | |
| 1437 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); |
| 1438 | if (length < 0) |
| 1439 | return length; |
| 1440 | server->total_read += length; |
| 1441 | |
| 1442 | /* Was the SMB read successful? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame^] | 1443 | rdata->result = server->ops->map_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1444 | if (rdata->result != 0) { |
| 1445 | cFYI(1, "%s: server returned error %d", __func__, |
| 1446 | rdata->result); |
| 1447 | return cifs_readv_discard(server, mid); |
| 1448 | } |
| 1449 | |
| 1450 | /* Is there enough to get to the rest of the READ_RSP header? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame^] | 1451 | if (server->total_read < server->vals->read_rsp_size) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1452 | cFYI(1, "%s: server returned short header. got=%u expected=%zu", |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame^] | 1453 | __func__, server->total_read, |
| 1454 | server->vals->read_rsp_size); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1455 | rdata->result = -EIO; |
| 1456 | return cifs_readv_discard(server, mid); |
| 1457 | } |
| 1458 | |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame^] | 1459 | data_offset = server->ops->read_data_offset(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1460 | if (data_offset < server->total_read) { |
| 1461 | /* |
| 1462 | * win2k8 sometimes sends an offset of 0 when the read |
| 1463 | * is beyond the EOF. Treat it as if the data starts just after |
| 1464 | * the header. |
| 1465 | */ |
| 1466 | cFYI(1, "%s: data offset (%u) inside read response header", |
| 1467 | __func__, data_offset); |
| 1468 | data_offset = server->total_read; |
| 1469 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1470 | /* data_offset is beyond the end of smallbuf */ |
| 1471 | cFYI(1, "%s: data offset (%u) beyond end of smallbuf", |
| 1472 | __func__, data_offset); |
| 1473 | rdata->result = -EIO; |
| 1474 | return cifs_readv_discard(server, mid); |
| 1475 | } |
| 1476 | |
| 1477 | cFYI(1, "%s: total_read=%u data_offset=%u", __func__, |
| 1478 | server->total_read, data_offset); |
| 1479 | |
| 1480 | len = data_offset - server->total_read; |
| 1481 | if (len > 0) { |
| 1482 | /* read any junk before data into the rest of smallbuf */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1483 | rdata->iov[0].iov_base = buf + server->total_read; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1484 | rdata->iov[0].iov_len = len; |
| 1485 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); |
| 1486 | if (length < 0) |
| 1487 | return length; |
| 1488 | server->total_read += length; |
| 1489 | } |
| 1490 | |
| 1491 | /* set up first iov for signature check */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1492 | rdata->iov[0].iov_base = buf; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1493 | rdata->iov[0].iov_len = server->total_read; |
| 1494 | cFYI(1, "0: iov_base=%p iov_len=%zu", |
| 1495 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); |
| 1496 | |
| 1497 | /* how much data is in the response? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame^] | 1498 | data_len = server->ops->read_data_length(buf); |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1499 | if (data_offset + data_len > buflen) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1500 | /* data_len is corrupt -- discard frame */ |
| 1501 | rdata->result = -EIO; |
| 1502 | return cifs_readv_discard(server, mid); |
| 1503 | } |
| 1504 | |
| 1505 | /* marshal up the page array */ |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1506 | len = rdata->marshal_iov(rdata, data_len); |
| 1507 | data_len -= len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1508 | |
| 1509 | /* issue the read if we have any iovecs left to fill */ |
| 1510 | if (rdata->nr_iov > 1) { |
| 1511 | length = cifs_readv_from_socket(server, &rdata->iov[1], |
| 1512 | rdata->nr_iov - 1, len); |
| 1513 | if (length < 0) |
| 1514 | return length; |
| 1515 | server->total_read += length; |
| 1516 | } else { |
| 1517 | length = 0; |
| 1518 | } |
| 1519 | |
| 1520 | rdata->bytes = length; |
| 1521 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1522 | cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read, |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1523 | buflen, data_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1524 | |
| 1525 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1526 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1527 | return cifs_readv_discard(server, mid); |
| 1528 | |
| 1529 | dequeue_mid(mid, false); |
| 1530 | return length; |
| 1531 | } |
| 1532 | |
| 1533 | static void |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1534 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1535 | { |
| 1536 | struct cifs_readdata *rdata = mid->callback_data; |
| 1537 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1538 | struct TCP_Server_Info *server = tcon->ses->server; |
| 1539 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1540 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, |
| 1541 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1542 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1543 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1544 | case MID_RESPONSE_RECEIVED: |
| 1545 | /* result already set, check signature */ |
| 1546 | if (server->sec_mode & |
| 1547 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
| 1548 | if (cifs_verify_signature(rdata->iov, rdata->nr_iov, |
| 1549 | server, mid->sequence_number + 1)) |
| 1550 | cERROR(1, "Unexpected SMB signature"); |
| 1551 | } |
| 1552 | /* FIXME: should this be counted toward the initiating task? */ |
| 1553 | task_io_account_read(rdata->bytes); |
| 1554 | cifs_stats_bytes_read(tcon, rdata->bytes); |
| 1555 | break; |
| 1556 | case MID_REQUEST_SUBMITTED: |
| 1557 | case MID_RETRY_NEEDED: |
| 1558 | rdata->result = -EAGAIN; |
| 1559 | break; |
| 1560 | default: |
| 1561 | rdata->result = -EIO; |
| 1562 | } |
| 1563 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1564 | queue_work(cifsiod_wq, &rdata->work); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1565 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 1566 | cifs_add_credits(server, 1); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1570 | int |
| 1571 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1572 | { |
| 1573 | int rc; |
| 1574 | READ_REQ *smb = NULL; |
| 1575 | int wct; |
| 1576 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1577 | |
| 1578 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, |
| 1579 | rdata->offset, rdata->bytes); |
| 1580 | |
| 1581 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1582 | wct = 12; |
| 1583 | else { |
| 1584 | wct = 10; /* old style read */ |
| 1585 | if ((rdata->offset >> 32) > 0) { |
| 1586 | /* can not handle this big offset for old */ |
| 1587 | return -EIO; |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1592 | if (rc) |
| 1593 | return rc; |
| 1594 | |
| 1595 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1596 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1597 | |
| 1598 | smb->AndXCommand = 0xFF; /* none */ |
| 1599 | smb->Fid = rdata->cfile->netfid; |
| 1600 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1601 | if (wct == 12) |
| 1602 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1603 | smb->Remaining = 0; |
| 1604 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1605 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1606 | if (wct == 12) |
| 1607 | smb->ByteCount = 0; |
| 1608 | else { |
| 1609 | /* old style read */ |
| 1610 | struct smb_com_readx_req *smbr = |
| 1611 | (struct smb_com_readx_req *)smb; |
| 1612 | smbr->ByteCount = 0; |
| 1613 | } |
| 1614 | |
| 1615 | /* 4 for RFC1001 length + 1 for BCC */ |
| 1616 | rdata->iov[0].iov_base = smb; |
| 1617 | rdata->iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
| 1618 | |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1619 | kref_get(&rdata->refcount); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1620 | rc = cifs_call_async(tcon->ses->server, rdata->iov, 1, |
| 1621 | cifs_readv_receive, cifs_readv_callback, |
| 1622 | rdata, false); |
| 1623 | |
| 1624 | if (rc == 0) |
| 1625 | cifs_stats_inc(&tcon->num_reads); |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1626 | else |
| 1627 | kref_put(&rdata->refcount, cifs_readdata_release); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1628 | |
| 1629 | cifs_small_buf_release(smb); |
| 1630 | return rc; |
| 1631 | } |
| 1632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | int |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1634 | 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] | 1635 | char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | { |
| 1637 | int rc = -EACCES; |
| 1638 | READ_REQ *pSMB = NULL; |
| 1639 | READ_RSP *pSMBr = NULL; |
| 1640 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1641 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1642 | int resp_buf_type = 0; |
| 1643 | struct kvec iov[1]; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1644 | __u32 pid = io_parms->pid; |
| 1645 | __u16 netfid = io_parms->netfid; |
| 1646 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1647 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1648 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1650 | cFYI(1, "Reading %d bytes on fid %d", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1651 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1652 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1653 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1654 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1655 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1656 | /* can not handle this big offset for old */ |
| 1657 | return -EIO; |
| 1658 | } |
| 1659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
| 1661 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1662 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | if (rc) |
| 1664 | return rc; |
| 1665 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1666 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1667 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | /* tcon and ses pointer are checked in smb_init */ |
| 1670 | if (tcon->ses->server == NULL) |
| 1671 | return -ECONNABORTED; |
| 1672 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1673 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1675 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1676 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1677 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | pSMB->Remaining = 0; |
| 1680 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1681 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1682 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1683 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1684 | else { |
| 1685 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1686 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1687 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1688 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1689 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1690 | |
| 1691 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1692 | 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] | 1693 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1694 | &resp_buf_type, CIFS_LOG_ERROR); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1695 | cifs_stats_inc(&tcon->num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1696 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1698 | cERROR(1, "Send error in read = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | } else { |
| 1700 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1701 | data_length = data_length << 16; |
| 1702 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1703 | *nbytes = data_length; |
| 1704 | |
| 1705 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1706 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | || (data_length > count)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1708 | cFYI(1, "bad length %d for count %d", |
| 1709 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | rc = -EIO; |
| 1711 | *nbytes = 0; |
| 1712 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1713 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1714 | le16_to_cpu(pSMBr->DataOffset); |
| 1715 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1716 | cERROR(1, "Faulting on read rc = %d",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1717 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1718 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1719 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1720 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | } |
| 1722 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1724 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1725 | if (*buf) { |
| 1726 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1727 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1728 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1729 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1730 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1731 | /* return buffer to caller to free */ |
| 1732 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1733 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1734 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1735 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1736 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1737 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1738 | |
| 1739 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | since file handle passed in no longer valid */ |
| 1741 | return rc; |
| 1742 | } |
| 1743 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1746 | CIFSSMBWrite(const int xid, struct cifs_io_parms *io_parms, |
| 1747 | unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1748 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | { |
| 1750 | int rc = -EACCES; |
| 1751 | WRITE_REQ *pSMB = NULL; |
| 1752 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1753 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | __u32 bytes_sent; |
| 1755 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1756 | __u32 pid = io_parms->pid; |
| 1757 | __u16 netfid = io_parms->netfid; |
| 1758 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1759 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1760 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1762 | *nbytes = 0; |
| 1763 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1764 | /* cFYI(1, "write at %lld %d bytes", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1765 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1766 | return -ECONNABORTED; |
| 1767 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1768 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1769 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1770 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1771 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1772 | if ((offset >> 32) > 0) { |
| 1773 | /* can not handle big offset for old srv */ |
| 1774 | return -EIO; |
| 1775 | } |
| 1776 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1777 | |
| 1778 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | (void **) &pSMBr); |
| 1780 | if (rc) |
| 1781 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1782 | |
| 1783 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1784 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | /* tcon and ses pointer are checked in smb_init */ |
| 1787 | if (tcon->ses->server == NULL) |
| 1788 | return -ECONNABORTED; |
| 1789 | |
| 1790 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1791 | pSMB->Fid = netfid; |
| 1792 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1793 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1794 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | pSMB->Reserved = 0xFFFFFFFF; |
| 1797 | pSMB->WriteMode = 0; |
| 1798 | pSMB->Remaining = 0; |
| 1799 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1800 | /* 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] | 1801 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1802 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1803 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1804 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1806 | } else { |
| 1807 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1808 | & ~0xFF; |
| 1809 | } |
| 1810 | |
| 1811 | if (bytes_sent > count) |
| 1812 | bytes_sent = count; |
| 1813 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1814 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1815 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1816 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1817 | else if (ubuf) { |
| 1818 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | cifs_buf_release(pSMB); |
| 1820 | return -EFAULT; |
| 1821 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1822 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | /* No buffer */ |
| 1824 | cifs_buf_release(pSMB); |
| 1825 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1826 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1827 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1828 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1829 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1830 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1833 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1834 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1835 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1836 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1837 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1838 | else { /* old style write has byte count 4 bytes earlier |
| 1839 | so 4 bytes pad */ |
| 1840 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1841 | (struct smb_com_writex_req *)pSMB; |
| 1842 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1843 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
| 1845 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1846 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1847 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 1849 | cFYI(1, "Send error in write = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | } else { |
| 1851 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1852 | *nbytes = (*nbytes) << 16; |
| 1853 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1854 | |
| 1855 | /* |
| 1856 | * Mask off high 16 bits when bytes written as returned by the |
| 1857 | * server is greater than bytes requested by the client. Some |
| 1858 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1859 | */ |
| 1860 | if (*nbytes > count) |
| 1861 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | cifs_buf_release(pSMB); |
| 1865 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1866 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | since file handle passed in no longer valid */ |
| 1868 | |
| 1869 | return rc; |
| 1870 | } |
| 1871 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1872 | void |
| 1873 | cifs_writedata_release(struct kref *refcount) |
| 1874 | { |
| 1875 | struct cifs_writedata *wdata = container_of(refcount, |
| 1876 | struct cifs_writedata, refcount); |
| 1877 | |
| 1878 | if (wdata->cfile) |
| 1879 | cifsFileInfo_put(wdata->cfile); |
| 1880 | |
| 1881 | kfree(wdata); |
| 1882 | } |
| 1883 | |
| 1884 | /* |
| 1885 | * Write failed with a retryable error. Resend the write request. It's also |
| 1886 | * possible that the page was redirtied so re-clean the page. |
| 1887 | */ |
| 1888 | static void |
| 1889 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 1890 | { |
| 1891 | int i, rc; |
| 1892 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1893 | |
| 1894 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1895 | lock_page(wdata->pages[i]); |
| 1896 | clear_page_dirty_for_io(wdata->pages[i]); |
| 1897 | } |
| 1898 | |
| 1899 | do { |
| 1900 | rc = cifs_async_writev(wdata); |
| 1901 | } while (rc == -EAGAIN); |
| 1902 | |
| 1903 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1904 | if (rc != 0) |
| 1905 | SetPageError(wdata->pages[i]); |
| 1906 | unlock_page(wdata->pages[i]); |
| 1907 | } |
| 1908 | |
| 1909 | mapping_set_error(inode->i_mapping, rc); |
| 1910 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1911 | } |
| 1912 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 1913 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1914 | cifs_writev_complete(struct work_struct *work) |
| 1915 | { |
| 1916 | struct cifs_writedata *wdata = container_of(work, |
| 1917 | struct cifs_writedata, work); |
| 1918 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1919 | int i = 0; |
| 1920 | |
| 1921 | if (wdata->result == 0) { |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1922 | spin_lock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1923 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1924 | spin_unlock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1925 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 1926 | wdata->bytes); |
| 1927 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 1928 | return cifs_writev_requeue(wdata); |
| 1929 | |
| 1930 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1931 | struct page *page = wdata->pages[i]; |
| 1932 | if (wdata->result == -EAGAIN) |
| 1933 | __set_page_dirty_nobuffers(page); |
| 1934 | else if (wdata->result < 0) |
| 1935 | SetPageError(page); |
| 1936 | end_page_writeback(page); |
| 1937 | page_cache_release(page); |
| 1938 | } |
| 1939 | if (wdata->result != -EAGAIN) |
| 1940 | mapping_set_error(inode->i_mapping, wdata->result); |
| 1941 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1942 | } |
| 1943 | |
| 1944 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 1945 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1946 | { |
| 1947 | struct cifs_writedata *wdata; |
| 1948 | |
| 1949 | /* this would overflow */ |
| 1950 | if (nr_pages == 0) { |
| 1951 | cERROR(1, "%s: called with nr_pages == 0!", __func__); |
| 1952 | return NULL; |
| 1953 | } |
| 1954 | |
| 1955 | /* writedata + number of page pointers */ |
| 1956 | wdata = kzalloc(sizeof(*wdata) + |
| 1957 | sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); |
| 1958 | if (wdata != NULL) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1959 | kref_init(&wdata->refcount); |
Jeff Layton | da82f7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1960 | INIT_LIST_HEAD(&wdata->list); |
| 1961 | init_completion(&wdata->done); |
| 1962 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1963 | } |
| 1964 | return wdata; |
| 1965 | } |
| 1966 | |
| 1967 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1968 | * 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] | 1969 | * workqueue completion task. |
| 1970 | */ |
| 1971 | static void |
| 1972 | cifs_writev_callback(struct mid_q_entry *mid) |
| 1973 | { |
| 1974 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1975 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1976 | unsigned int written; |
| 1977 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
| 1978 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1979 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1980 | case MID_RESPONSE_RECEIVED: |
| 1981 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 1982 | if (wdata->result != 0) |
| 1983 | break; |
| 1984 | |
| 1985 | written = le16_to_cpu(smb->CountHigh); |
| 1986 | written <<= 16; |
| 1987 | written += le16_to_cpu(smb->Count); |
| 1988 | /* |
| 1989 | * Mask off high 16 bits when bytes written as returned |
| 1990 | * by the server is greater than bytes requested by the |
| 1991 | * client. OS/2 servers are known to set incorrect |
| 1992 | * CountHigh values. |
| 1993 | */ |
| 1994 | if (written > wdata->bytes) |
| 1995 | written &= 0xFFFF; |
| 1996 | |
| 1997 | if (written < wdata->bytes) |
| 1998 | wdata->result = -ENOSPC; |
| 1999 | else |
| 2000 | wdata->bytes = written; |
| 2001 | break; |
| 2002 | case MID_REQUEST_SUBMITTED: |
| 2003 | case MID_RETRY_NEEDED: |
| 2004 | wdata->result = -EAGAIN; |
| 2005 | break; |
| 2006 | default: |
| 2007 | wdata->result = -EIO; |
| 2008 | break; |
| 2009 | } |
| 2010 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2011 | queue_work(cifsiod_wq, &wdata->work); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2012 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 2013 | cifs_add_credits(tcon->ses->server, 1); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2017 | int |
| 2018 | cifs_async_writev(struct cifs_writedata *wdata) |
| 2019 | { |
| 2020 | int i, rc = -EACCES; |
| 2021 | WRITE_REQ *smb = NULL; |
| 2022 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2023 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2024 | struct kvec *iov = NULL; |
| 2025 | |
| 2026 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2027 | wct = 14; |
| 2028 | } else { |
| 2029 | wct = 12; |
| 2030 | if (wdata->offset >> 32 > 0) { |
| 2031 | /* can not handle big offset for old srv */ |
| 2032 | return -EIO; |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2037 | if (rc) |
| 2038 | goto async_writev_out; |
| 2039 | |
| 2040 | /* 1 iov per page + 1 for header */ |
| 2041 | iov = kzalloc((wdata->nr_pages + 1) * sizeof(*iov), GFP_NOFS); |
| 2042 | if (iov == NULL) { |
| 2043 | rc = -ENOMEM; |
| 2044 | goto async_writev_out; |
| 2045 | } |
| 2046 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2047 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2048 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2049 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2050 | smb->AndXCommand = 0xFF; /* none */ |
| 2051 | smb->Fid = wdata->cfile->netfid; |
| 2052 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2053 | if (wct == 14) |
| 2054 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2055 | smb->Reserved = 0xFFFFFFFF; |
| 2056 | smb->WriteMode = 0; |
| 2057 | smb->Remaining = 0; |
| 2058 | |
| 2059 | smb->DataOffset = |
| 2060 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2061 | |
| 2062 | /* 4 for RFC1001 length + 1 for BCC */ |
| 2063 | iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; |
| 2064 | iov[0].iov_base = smb; |
| 2065 | |
Jeff Layton | e949287 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2066 | /* |
| 2067 | * This function should marshal up the page array into the kvec |
| 2068 | * array, reserving [0] for the header. It should kmap the pages |
| 2069 | * and set the iov_len properly for each one. It may also set |
| 2070 | * wdata->bytes too. |
| 2071 | */ |
| 2072 | wdata->marshal_iov(iov, wdata); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2073 | |
| 2074 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); |
| 2075 | |
| 2076 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2077 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2078 | |
| 2079 | if (wct == 14) { |
| 2080 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2081 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2082 | } else { |
| 2083 | /* wct == 12 */ |
| 2084 | struct smb_com_writex_req *smbw = |
| 2085 | (struct smb_com_writex_req *)smb; |
| 2086 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2087 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
| 2088 | iov[0].iov_len += 4; /* pad bigger by four bytes */ |
| 2089 | } |
| 2090 | |
| 2091 | kref_get(&wdata->refcount); |
| 2092 | rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1, |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 2093 | NULL, cifs_writev_callback, wdata, false); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2094 | |
| 2095 | if (rc == 0) |
| 2096 | cifs_stats_inc(&tcon->num_writes); |
| 2097 | else |
| 2098 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2099 | |
| 2100 | /* send is done, unmap pages */ |
| 2101 | for (i = 0; i < wdata->nr_pages; i++) |
| 2102 | kunmap(wdata->pages[i]); |
| 2103 | |
| 2104 | async_writev_out: |
| 2105 | cifs_small_buf_release(smb); |
| 2106 | kfree(iov); |
| 2107 | return rc; |
| 2108 | } |
| 2109 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2110 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2111 | CIFSSMBWrite2(const int xid, struct cifs_io_parms *io_parms, |
| 2112 | unsigned int *nbytes, struct kvec *iov, int n_vec, |
| 2113 | const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | { |
| 2115 | int rc = -EACCES; |
| 2116 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2117 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2118 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2119 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2120 | __u32 pid = io_parms->pid; |
| 2121 | __u16 netfid = io_parms->netfid; |
| 2122 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2123 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2124 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2126 | *nbytes = 0; |
| 2127 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2128 | cFYI(1, "write2 at %lld %d bytes", (long long)offset, count); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2129 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2130 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2131 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2132 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2133 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2134 | if ((offset >> 32) > 0) { |
| 2135 | /* can not handle big offset for old srv */ |
| 2136 | return -EIO; |
| 2137 | } |
| 2138 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2139 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | if (rc) |
| 2141 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2142 | |
| 2143 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2144 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | /* tcon and ses pointer are checked in smb_init */ |
| 2147 | if (tcon->ses->server == NULL) |
| 2148 | return -ECONNABORTED; |
| 2149 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2150 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | pSMB->Fid = netfid; |
| 2152 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2153 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2154 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | pSMB->Reserved = 0xFFFFFFFF; |
| 2156 | pSMB->WriteMode = 0; |
| 2157 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2160 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2162 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2163 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2164 | /* header + 1 byte pad */ |
| 2165 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2166 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2167 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2168 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2169 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2170 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2171 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2172 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2173 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2174 | (struct smb_com_writex_req *)pSMB; |
| 2175 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2176 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2177 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2178 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2179 | iov[0].iov_len = smb_hdr_len + 4; |
| 2180 | else /* wct == 12 pad bigger by four bytes */ |
| 2181 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2182 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2183 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2184 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2185 | long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2186 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2188 | cFYI(1, "Send error Write2 = %d", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2189 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2190 | /* presumably this can not happen, but best to be safe */ |
| 2191 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2192 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2193 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2194 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2195 | *nbytes = (*nbytes) << 16; |
| 2196 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2197 | |
| 2198 | /* |
| 2199 | * Mask off high 16 bits when bytes written as returned by the |
| 2200 | * server is greater than bytes requested by the client. OS/2 |
| 2201 | * servers are known to set incorrect CountHigh values. |
| 2202 | */ |
| 2203 | if (*nbytes > count) |
| 2204 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2205 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 2207 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2208 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2209 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2210 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2211 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2213 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | since file handle passed in no longer valid */ |
| 2215 | |
| 2216 | return rc; |
| 2217 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2218 | |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2219 | int cifs_lockv(const int xid, struct cifs_tcon *tcon, const __u16 netfid, |
| 2220 | const __u8 lock_type, const __u32 num_unlock, |
| 2221 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2222 | { |
| 2223 | int rc = 0; |
| 2224 | LOCK_REQ *pSMB = NULL; |
| 2225 | struct kvec iov[2]; |
| 2226 | int resp_buf_type; |
| 2227 | __u16 count; |
| 2228 | |
| 2229 | cFYI(1, "cifs_lockv num lock %d num unlock %d", num_lock, num_unlock); |
| 2230 | |
| 2231 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2232 | if (rc) |
| 2233 | return rc; |
| 2234 | |
| 2235 | pSMB->Timeout = 0; |
| 2236 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2237 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2238 | pSMB->LockType = lock_type; |
| 2239 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2240 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2241 | |
| 2242 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2243 | inc_rfc1001_len(pSMB, count); |
| 2244 | pSMB->ByteCount = cpu_to_le16(count); |
| 2245 | |
| 2246 | iov[0].iov_base = (char *)pSMB; |
| 2247 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2248 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2249 | iov[1].iov_base = (char *)buf; |
| 2250 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2251 | |
| 2252 | cifs_stats_inc(&tcon->num_locks); |
| 2253 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP); |
| 2254 | if (rc) |
| 2255 | cFYI(1, "Send error in cifs_lockv = %d", rc); |
| 2256 | |
| 2257 | return rc; |
| 2258 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2261 | CIFSSMBLock(const int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2262 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2264 | const __u32 numLock, const __u8 lockType, |
| 2265 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | { |
| 2267 | int rc = 0; |
| 2268 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2269 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | int bytes_returned; |
| 2271 | int timeout = 0; |
| 2272 | __u16 count; |
| 2273 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2274 | cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2275 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | if (rc) |
| 2278 | return rc; |
| 2279 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2280 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2281 | timeout = CIFS_ASYNC_OP; /* no response expected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2283 | } else if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2284 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2286 | } else { |
| 2287 | pSMB->Timeout = 0; |
| 2288 | } |
| 2289 | |
| 2290 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2291 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2292 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2293 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2295 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2296 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2297 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2298 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | /* BB where to store pid high? */ |
| 2300 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2301 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2302 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2303 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2304 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2305 | } else { |
| 2306 | /* oplock break */ |
| 2307 | count = 0; |
| 2308 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2309 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | pSMB->ByteCount = cpu_to_le16(count); |
| 2311 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2312 | if (waitFlag) { |
| 2313 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2314 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2315 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2316 | } else { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2317 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, timeout); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2318 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2319 | } |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2320 | cifs_stats_inc(&tcon->num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2321 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2322 | cFYI(1, "Send error in Lock = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2324 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | since file handle passed in no longer valid */ |
| 2326 | return rc; |
| 2327 | } |
| 2328 | |
| 2329 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2330 | CIFSSMBPosixLock(const int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2331 | const __u16 smb_file_id, const __u32 netpid, const int get_flag, |
| 2332 | const __u64 len, struct file_lock *pLockData, |
| 2333 | const __u16 lock_type, const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2334 | { |
| 2335 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2336 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2337 | struct cifs_posix_lock *parm_data; |
| 2338 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2339 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2340 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2341 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2342 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2343 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2344 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2345 | cFYI(1, "Posix Lock"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2346 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2347 | if (pLockData == NULL) |
Marcin Slusarz | ed5f037 | 2008-05-13 04:01:01 +0000 | [diff] [blame] | 2348 | return -EINVAL; |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2349 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2350 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2351 | |
| 2352 | if (rc) |
| 2353 | return rc; |
| 2354 | |
| 2355 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2356 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2357 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2358 | pSMB->MaxSetupCount = 0; |
| 2359 | pSMB->Reserved = 0; |
| 2360 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2361 | pSMB->Reserved2 = 0; |
| 2362 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2363 | offset = param_offset + params; |
| 2364 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2365 | count = sizeof(struct cifs_posix_lock); |
| 2366 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2367 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2368 | pSMB->SetupCount = 1; |
| 2369 | pSMB->Reserved3 = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2370 | if (get_flag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2371 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2372 | else |
| 2373 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2374 | byte_count = 3 /* pad */ + params + count; |
| 2375 | pSMB->DataCount = cpu_to_le16(count); |
| 2376 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2377 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2378 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2379 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2380 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2381 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2382 | |
| 2383 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2384 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2385 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2386 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2387 | pSMB->Timeout = cpu_to_le32(-1); |
| 2388 | } else |
| 2389 | pSMB->Timeout = 0; |
| 2390 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2391 | parm_data->pid = cpu_to_le32(netpid); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2392 | parm_data->start = cpu_to_le64(pLockData->fl_start); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2393 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2394 | |
| 2395 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2396 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2397 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2398 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2399 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2400 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2401 | if (waitFlag) { |
| 2402 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2403 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2404 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2405 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2406 | 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] | 2407 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 2408 | &resp_buf_type, timeout); |
| 2409 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 2410 | not try to free it twice below on exit */ |
| 2411 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2414 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2415 | cFYI(1, "Send error in Posix Lock = %d", rc); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2416 | } else if (get_flag) { |
| 2417 | /* lock structure can be returned on get */ |
| 2418 | __u16 data_offset; |
| 2419 | __u16 data_count; |
| 2420 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2421 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2422 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2423 | rc = -EIO; /* bad smb */ |
| 2424 | goto plk_err_exit; |
| 2425 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2426 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2427 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2428 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2429 | rc = -EIO; |
| 2430 | goto plk_err_exit; |
| 2431 | } |
| 2432 | parm_data = (struct cifs_posix_lock *) |
| 2433 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2434 | if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2435 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2436 | else { |
| 2437 | if (parm_data->lock_type == |
| 2438 | __constant_cpu_to_le16(CIFS_RDLCK)) |
| 2439 | pLockData->fl_type = F_RDLCK; |
| 2440 | else if (parm_data->lock_type == |
| 2441 | __constant_cpu_to_le16(CIFS_WRLCK)) |
| 2442 | pLockData->fl_type = F_WRLCK; |
| 2443 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2444 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2445 | pLockData->fl_end = pLockData->fl_start + |
| 2446 | le64_to_cpu(parm_data->length) - 1; |
| 2447 | pLockData->fl_pid = le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2448 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2449 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2450 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2451 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2452 | if (pSMB) |
| 2453 | cifs_small_buf_release(pSMB); |
| 2454 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2455 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 2456 | cifs_small_buf_release(iov[0].iov_base); |
| 2457 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 2458 | cifs_buf_release(iov[0].iov_base); |
| 2459 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2460 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2461 | since file handle passed in no longer valid */ |
| 2462 | |
| 2463 | return rc; |
| 2464 | } |
| 2465 | |
| 2466 | |
| 2467 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2468 | CIFSSMBClose(const int xid, struct cifs_tcon *tcon, int smb_file_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | { |
| 2470 | int rc = 0; |
| 2471 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2472 | cFYI(1, "In CIFSSMBClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | |
| 2474 | /* do not retry on dead session on close */ |
| 2475 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2476 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | return 0; |
| 2478 | if (rc) |
| 2479 | return rc; |
| 2480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2482 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2484 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2485 | cifs_stats_inc(&tcon->num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2487 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2489 | cERROR(1, "Send error in Close = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | } |
| 2491 | } |
| 2492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2494 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | rc = 0; |
| 2496 | |
| 2497 | return rc; |
| 2498 | } |
| 2499 | |
| 2500 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2501 | CIFSSMBFlush(const int xid, struct cifs_tcon *tcon, int smb_file_id) |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2502 | { |
| 2503 | int rc = 0; |
| 2504 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2505 | cFYI(1, "In CIFSSMBFlush"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2506 | |
| 2507 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2508 | if (rc) |
| 2509 | return rc; |
| 2510 | |
| 2511 | pSMB->FileID = (__u16) smb_file_id; |
| 2512 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2513 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2514 | cifs_stats_inc(&tcon->num_flushes); |
| 2515 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2516 | cERROR(1, "Send error in Flush = %d", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2517 | |
| 2518 | return rc; |
| 2519 | } |
| 2520 | |
| 2521 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2522 | CIFSSMBRename(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2524 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | { |
| 2526 | int rc = 0; |
| 2527 | RENAME_REQ *pSMB = NULL; |
| 2528 | RENAME_RSP *pSMBr = NULL; |
| 2529 | int bytes_returned; |
| 2530 | int name_len, name_len2; |
| 2531 | __u16 count; |
| 2532 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2533 | cFYI(1, "In CIFSSMBRename"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | renameRetry: |
| 2535 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2536 | (void **) &pSMBr); |
| 2537 | if (rc) |
| 2538 | return rc; |
| 2539 | |
| 2540 | pSMB->BufferFormat = 0x04; |
| 2541 | pSMB->SearchAttributes = |
| 2542 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2543 | ATTR_DIRECTORY); |
| 2544 | |
| 2545 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2546 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2547 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, |
| 2548 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | name_len++; /* trailing null */ |
| 2550 | name_len *= 2; |
| 2551 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2552 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2553 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2554 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2555 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2556 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2558 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2559 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | name_len = strnlen(fromName, PATH_MAX); |
| 2561 | name_len++; /* trailing null */ |
| 2562 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2563 | name_len2 = strnlen(toName, PATH_MAX); |
| 2564 | name_len2++; /* trailing null */ |
| 2565 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2566 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2567 | name_len2++; /* trailing null */ |
| 2568 | name_len2++; /* signature byte */ |
| 2569 | } |
| 2570 | |
| 2571 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2572 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | pSMB->ByteCount = cpu_to_le16(count); |
| 2574 | |
| 2575 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2576 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2577 | cifs_stats_inc(&tcon->num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2578 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2579 | cFYI(1, "Send error in rename = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | cifs_buf_release(pSMB); |
| 2582 | |
| 2583 | if (rc == -EAGAIN) |
| 2584 | goto renameRetry; |
| 2585 | |
| 2586 | return rc; |
| 2587 | } |
| 2588 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2589 | int CIFSSMBRenameOpenFile(const int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2590 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2591 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | { |
| 2593 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2594 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2595 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | char *data_offset; |
| 2597 | char dummy_string[30]; |
| 2598 | int rc = 0; |
| 2599 | int bytes_returned = 0; |
| 2600 | int len_of_str; |
| 2601 | __u16 params, param_offset, offset, count, byte_count; |
| 2602 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2603 | cFYI(1, "Rename to File by handle"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2605 | (void **) &pSMBr); |
| 2606 | if (rc) |
| 2607 | return rc; |
| 2608 | |
| 2609 | params = 6; |
| 2610 | pSMB->MaxSetupCount = 0; |
| 2611 | pSMB->Reserved = 0; |
| 2612 | pSMB->Flags = 0; |
| 2613 | pSMB->Timeout = 0; |
| 2614 | pSMB->Reserved2 = 0; |
| 2615 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2616 | offset = param_offset + params; |
| 2617 | |
| 2618 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2619 | rename_info = (struct set_file_rename *) data_offset; |
| 2620 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2621 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | pSMB->SetupCount = 1; |
| 2623 | pSMB->Reserved3 = 0; |
| 2624 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2625 | byte_count = 3 /* pad */ + params; |
| 2626 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2627 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2628 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2629 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2630 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2631 | rename_info->overwrite = cpu_to_le32(1); |
| 2632 | rename_info->root_fid = 0; |
| 2633 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2634 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2635 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2636 | len_of_str = |
| 2637 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2638 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2640 | len_of_str = |
| 2641 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2642 | target_name, PATH_MAX, nls_codepage, |
| 2643 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | } |
| 2645 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2646 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | byte_count += count; |
| 2648 | pSMB->DataCount = cpu_to_le16(count); |
| 2649 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2650 | pSMB->Fid = netfid; |
| 2651 | pSMB->InformationLevel = |
| 2652 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2653 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2654 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2656 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2657 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2658 | cifs_stats_inc(&pTcon->num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2659 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2660 | cFYI(1, "Send error in Rename (by file handle) = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | cifs_buf_release(pSMB); |
| 2663 | |
| 2664 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2665 | since file handle passed in no longer valid */ |
| 2666 | |
| 2667 | return rc; |
| 2668 | } |
| 2669 | |
| 2670 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2671 | CIFSSMBCopy(const int xid, struct cifs_tcon *tcon, const char *fromName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2672 | const __u16 target_tid, const char *toName, const int flags, |
| 2673 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | { |
| 2675 | int rc = 0; |
| 2676 | COPY_REQ *pSMB = NULL; |
| 2677 | COPY_RSP *pSMBr = NULL; |
| 2678 | int bytes_returned; |
| 2679 | int name_len, name_len2; |
| 2680 | __u16 count; |
| 2681 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2682 | cFYI(1, "In CIFSSMBCopy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | copyRetry: |
| 2684 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2685 | (void **) &pSMBr); |
| 2686 | if (rc) |
| 2687 | return rc; |
| 2688 | |
| 2689 | pSMB->BufferFormat = 0x04; |
| 2690 | pSMB->Tid2 = target_tid; |
| 2691 | |
| 2692 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2693 | |
| 2694 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2695 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2696 | fromName, PATH_MAX, nls_codepage, |
| 2697 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | name_len++; /* trailing null */ |
| 2699 | name_len *= 2; |
| 2700 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2701 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2702 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2703 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2704 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2705 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2707 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2708 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | name_len = strnlen(fromName, PATH_MAX); |
| 2710 | name_len++; /* trailing null */ |
| 2711 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2712 | name_len2 = strnlen(toName, PATH_MAX); |
| 2713 | name_len2++; /* trailing null */ |
| 2714 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2715 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2716 | name_len2++; /* trailing null */ |
| 2717 | name_len2++; /* signature byte */ |
| 2718 | } |
| 2719 | |
| 2720 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2721 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | pSMB->ByteCount = cpu_to_le16(count); |
| 2723 | |
| 2724 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2725 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2726 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2727 | cFYI(1, "Send error in copy = %d with %d files copied", |
| 2728 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2730 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | |
| 2732 | if (rc == -EAGAIN) |
| 2733 | goto copyRetry; |
| 2734 | |
| 2735 | return rc; |
| 2736 | } |
| 2737 | |
| 2738 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2739 | CIFSUnixCreateSymLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | const char *fromName, const char *toName, |
| 2741 | const struct nls_table *nls_codepage) |
| 2742 | { |
| 2743 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2744 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2745 | char *data_offset; |
| 2746 | int name_len; |
| 2747 | int name_len_target; |
| 2748 | int rc = 0; |
| 2749 | int bytes_returned = 0; |
| 2750 | __u16 params, param_offset, offset, byte_count; |
| 2751 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2752 | cFYI(1, "In Symlink Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | createSymLinkRetry: |
| 2754 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2755 | (void **) &pSMBr); |
| 2756 | if (rc) |
| 2757 | return rc; |
| 2758 | |
| 2759 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2760 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2761 | cifs_strtoUTF16((__le16 *) pSMB->FileName, fromName, |
| 2762 | /* find define for this maxpathcomponent */ |
| 2763 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | name_len++; /* trailing null */ |
| 2765 | name_len *= 2; |
| 2766 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2767 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | name_len = strnlen(fromName, PATH_MAX); |
| 2769 | name_len++; /* trailing null */ |
| 2770 | strncpy(pSMB->FileName, fromName, name_len); |
| 2771 | } |
| 2772 | params = 6 + name_len; |
| 2773 | pSMB->MaxSetupCount = 0; |
| 2774 | pSMB->Reserved = 0; |
| 2775 | pSMB->Flags = 0; |
| 2776 | pSMB->Timeout = 0; |
| 2777 | pSMB->Reserved2 = 0; |
| 2778 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2779 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | offset = param_offset + params; |
| 2781 | |
| 2782 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2783 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2784 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2785 | cifs_strtoUTF16((__le16 *) data_offset, toName, PATH_MAX |
| 2786 | /* find define for this maxpathcomponent */ |
| 2787 | , nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | name_len_target++; /* trailing null */ |
| 2789 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2790 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | name_len_target = strnlen(toName, PATH_MAX); |
| 2792 | name_len_target++; /* trailing null */ |
| 2793 | strncpy(data_offset, toName, name_len_target); |
| 2794 | } |
| 2795 | |
| 2796 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2797 | /* BB find exact max on data count below from sess */ |
| 2798 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2799 | pSMB->SetupCount = 1; |
| 2800 | pSMB->Reserved3 = 0; |
| 2801 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2802 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2803 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2804 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2805 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2806 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2807 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2808 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2809 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2810 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2811 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2813 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2814 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2815 | cifs_stats_inc(&tcon->num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2816 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2817 | cFYI(1, "Send error in SetPathInfo create symlink = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2819 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | |
| 2821 | if (rc == -EAGAIN) |
| 2822 | goto createSymLinkRetry; |
| 2823 | |
| 2824 | return rc; |
| 2825 | } |
| 2826 | |
| 2827 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2828 | CIFSUnixCreateHardLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2830 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | { |
| 2832 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2833 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2834 | char *data_offset; |
| 2835 | int name_len; |
| 2836 | int name_len_target; |
| 2837 | int rc = 0; |
| 2838 | int bytes_returned = 0; |
| 2839 | __u16 params, param_offset, offset, byte_count; |
| 2840 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2841 | cFYI(1, "In Create Hard link Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | createHardLinkRetry: |
| 2843 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2844 | (void **) &pSMBr); |
| 2845 | if (rc) |
| 2846 | return rc; |
| 2847 | |
| 2848 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2849 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 2850 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | name_len++; /* trailing null */ |
| 2852 | name_len *= 2; |
| 2853 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2854 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | name_len = strnlen(toName, PATH_MAX); |
| 2856 | name_len++; /* trailing null */ |
| 2857 | strncpy(pSMB->FileName, toName, name_len); |
| 2858 | } |
| 2859 | params = 6 + name_len; |
| 2860 | pSMB->MaxSetupCount = 0; |
| 2861 | pSMB->Reserved = 0; |
| 2862 | pSMB->Flags = 0; |
| 2863 | pSMB->Timeout = 0; |
| 2864 | pSMB->Reserved2 = 0; |
| 2865 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2866 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | offset = param_offset + params; |
| 2868 | |
| 2869 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2870 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2871 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2872 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 2873 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | name_len_target++; /* trailing null */ |
| 2875 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2876 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2878 | name_len_target++; /* trailing null */ |
| 2879 | strncpy(data_offset, fromName, name_len_target); |
| 2880 | } |
| 2881 | |
| 2882 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2883 | /* BB find exact max on data count below from sess*/ |
| 2884 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2885 | pSMB->SetupCount = 1; |
| 2886 | pSMB->Reserved3 = 0; |
| 2887 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2888 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2889 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2890 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2891 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2892 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2893 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2894 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2895 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2896 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2897 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2899 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2900 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2901 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2902 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2903 | cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | |
| 2905 | cifs_buf_release(pSMB); |
| 2906 | if (rc == -EAGAIN) |
| 2907 | goto createHardLinkRetry; |
| 2908 | |
| 2909 | return rc; |
| 2910 | } |
| 2911 | |
| 2912 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2913 | CIFSCreateHardLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2915 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | { |
| 2917 | int rc = 0; |
| 2918 | NT_RENAME_REQ *pSMB = NULL; |
| 2919 | RENAME_RSP *pSMBr = NULL; |
| 2920 | int bytes_returned; |
| 2921 | int name_len, name_len2; |
| 2922 | __u16 count; |
| 2923 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2924 | cFYI(1, "In CIFSCreateHardLink"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | winCreateHardLinkRetry: |
| 2926 | |
| 2927 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2928 | (void **) &pSMBr); |
| 2929 | if (rc) |
| 2930 | return rc; |
| 2931 | |
| 2932 | pSMB->SearchAttributes = |
| 2933 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2934 | ATTR_DIRECTORY); |
| 2935 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 2936 | pSMB->ClusterCount = 0; |
| 2937 | |
| 2938 | pSMB->BufferFormat = 0x04; |
| 2939 | |
| 2940 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2941 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2942 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, |
| 2943 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | name_len++; /* trailing null */ |
| 2945 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 2946 | |
| 2947 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 2948 | pSMB->OldFileName[name_len] = 0x04; |
| 2949 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2951 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2952 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2954 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2955 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | name_len = strnlen(fromName, PATH_MAX); |
| 2957 | name_len++; /* trailing null */ |
| 2958 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2959 | name_len2 = strnlen(toName, PATH_MAX); |
| 2960 | name_len2++; /* trailing null */ |
| 2961 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2962 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2963 | name_len2++; /* trailing null */ |
| 2964 | name_len2++; /* signature byte */ |
| 2965 | } |
| 2966 | |
| 2967 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2968 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | pSMB->ByteCount = cpu_to_le16(count); |
| 2970 | |
| 2971 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2972 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2973 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2974 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2975 | cFYI(1, "Send error in hard link (NT rename) = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | cifs_buf_release(pSMB); |
| 2978 | if (rc == -EAGAIN) |
| 2979 | goto winCreateHardLinkRetry; |
| 2980 | |
| 2981 | return rc; |
| 2982 | } |
| 2983 | |
| 2984 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2985 | CIFSSMBUnixQuerySymLink(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2986 | const unsigned char *searchName, char **symlinkinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | const struct nls_table *nls_codepage) |
| 2988 | { |
| 2989 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 2990 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2991 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2992 | int rc = 0; |
| 2993 | int bytes_returned; |
| 2994 | int name_len; |
| 2995 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2996 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2998 | cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | |
| 3000 | querySymLinkRetry: |
| 3001 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3002 | (void **) &pSMBr); |
| 3003 | if (rc) |
| 3004 | return rc; |
| 3005 | |
| 3006 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3007 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3008 | cifs_strtoUTF16((__le16 *) pSMB->FileName, searchName, |
| 3009 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | name_len++; /* trailing null */ |
| 3011 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3012 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | name_len = strnlen(searchName, PATH_MAX); |
| 3014 | name_len++; /* trailing null */ |
| 3015 | strncpy(pSMB->FileName, searchName, name_len); |
| 3016 | } |
| 3017 | |
| 3018 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3019 | pSMB->TotalDataCount = 0; |
| 3020 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3021 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | pSMB->MaxSetupCount = 0; |
| 3023 | pSMB->Reserved = 0; |
| 3024 | pSMB->Flags = 0; |
| 3025 | pSMB->Timeout = 0; |
| 3026 | pSMB->Reserved2 = 0; |
| 3027 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3028 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | pSMB->DataCount = 0; |
| 3030 | pSMB->DataOffset = 0; |
| 3031 | pSMB->SetupCount = 1; |
| 3032 | pSMB->Reserved3 = 0; |
| 3033 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3034 | byte_count = params + 1 /* pad */ ; |
| 3035 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3036 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3037 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3038 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3039 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3041 | |
| 3042 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3043 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3044 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3045 | cFYI(1, "Send error in QuerySymLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | } else { |
| 3047 | /* decode response */ |
| 3048 | |
| 3049 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3051 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3052 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3054 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3055 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3057 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3058 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3059 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3060 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3061 | is_unicode = true; |
| 3062 | else |
| 3063 | is_unicode = false; |
| 3064 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3065 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3066 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3067 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3068 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3069 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | } |
| 3071 | } |
| 3072 | cifs_buf_release(pSMB); |
| 3073 | if (rc == -EAGAIN) |
| 3074 | goto querySymLinkRetry; |
| 3075 | return rc; |
| 3076 | } |
| 3077 | |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3078 | #ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL |
| 3079 | /* |
| 3080 | * Recent Windows versions now create symlinks more frequently |
| 3081 | * and they use the "reparse point" mechanism below. We can of course |
| 3082 | * do symlinks nicely to Samba and other servers which support the |
| 3083 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3084 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3085 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3086 | * In the interim this code has been moved to its own config option so |
| 3087 | * it is not compiled in by default until callers fixed up and more tested. |
| 3088 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3090 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3092 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | const struct nls_table *nls_codepage) |
| 3094 | { |
| 3095 | int rc = 0; |
| 3096 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3097 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3098 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3100 | cFYI(1, "In Windows reparse style QueryLink for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3102 | (void **) &pSMBr); |
| 3103 | if (rc) |
| 3104 | return rc; |
| 3105 | |
| 3106 | pSMB->TotalParameterCount = 0 ; |
| 3107 | pSMB->TotalDataCount = 0; |
| 3108 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3109 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3110 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | pSMB->MaxSetupCount = 4; |
| 3112 | pSMB->Reserved = 0; |
| 3113 | pSMB->ParameterOffset = 0; |
| 3114 | pSMB->DataCount = 0; |
| 3115 | pSMB->DataOffset = 0; |
| 3116 | pSMB->SetupCount = 4; |
| 3117 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3118 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3119 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3120 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3121 | pSMB->IsRootFlag = 0; |
| 3122 | pSMB->Fid = fid; /* file handle always le */ |
| 3123 | pSMB->ByteCount = 0; |
| 3124 | |
| 3125 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3126 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3127 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3128 | cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | } else { /* decode response */ |
| 3130 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3131 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3132 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3133 | /* BB also check enough total bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | rc = -EIO; /* bad smb */ |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3135 | goto qreparse_out; |
| 3136 | } |
| 3137 | if (data_count && (data_count < 2048)) { |
| 3138 | char *end_of_smb = 2 /* sizeof byte count */ + |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3139 | get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3141 | struct reparse_data *reparse_buf = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3142 | (struct reparse_data *) |
| 3143 | ((char *)&pSMBr->hdr.Protocol |
| 3144 | + data_offset); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3145 | if ((char *)reparse_buf >= end_of_smb) { |
| 3146 | rc = -EIO; |
| 3147 | goto qreparse_out; |
| 3148 | } |
| 3149 | if ((reparse_buf->LinkNamesBuf + |
| 3150 | reparse_buf->TargetNameOffset + |
| 3151 | reparse_buf->TargetNameLen) > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3152 | cFYI(1, "reparse buf beyond SMB"); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3153 | rc = -EIO; |
| 3154 | goto qreparse_out; |
| 3155 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3156 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3157 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3158 | cifs_from_ucs2(symlinkinfo, (__le16 *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3159 | (reparse_buf->LinkNamesBuf + |
| 3160 | reparse_buf->TargetNameOffset), |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3161 | buflen, |
| 3162 | reparse_buf->TargetNameLen, |
| 3163 | nls_codepage, 0); |
| 3164 | } else { /* ASCII names */ |
| 3165 | strncpy(symlinkinfo, |
| 3166 | reparse_buf->LinkNamesBuf + |
| 3167 | reparse_buf->TargetNameOffset, |
| 3168 | min_t(const int, buflen, |
| 3169 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3171 | } else { |
| 3172 | rc = -EIO; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3173 | cFYI(1, "Invalid return data count on " |
| 3174 | "get reparse info ioctl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3176 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 3177 | does not go off the end of the buffer */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3178 | cFYI(1, "readlink result - %s", symlinkinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3182 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | |
| 3184 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 3185 | since file handle passed in no longer valid */ |
| 3186 | |
| 3187 | return rc; |
| 3188 | } |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3189 | #endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | |
| 3191 | #ifdef CONFIG_CIFS_POSIX |
| 3192 | |
| 3193 | /*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] | 3194 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 3195 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | { |
| 3197 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3198 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3199 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3200 | 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] | 3201 | /* 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] | 3202 | |
| 3203 | return; |
| 3204 | } |
| 3205 | |
| 3206 | /* 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] | 3207 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3208 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | { |
| 3210 | int size = 0; |
| 3211 | int i; |
| 3212 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3213 | struct cifs_posix_ace *pACE; |
| 3214 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 3215 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | |
| 3217 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3218 | return -EOPNOTSUPP; |
| 3219 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3220 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3222 | pACE = &cifs_acl->ace_array[0]; |
| 3223 | size = sizeof(struct cifs_posix_acl); |
| 3224 | size += sizeof(struct cifs_posix_ace) * count; |
| 3225 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3226 | if (size_of_data_area < size) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3227 | cFYI(1, "bad CIFS POSIX ACL size %d vs. %d", |
| 3228 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | return -EINVAL; |
| 3230 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3231 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3233 | size = sizeof(struct cifs_posix_acl); |
| 3234 | size += sizeof(struct cifs_posix_ace) * count; |
| 3235 | /* skip past access ACEs to get to default ACEs */ |
| 3236 | pACE = &cifs_acl->ace_array[count]; |
| 3237 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3238 | size += sizeof(struct cifs_posix_ace) * count; |
| 3239 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3240 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | return -EINVAL; |
| 3242 | } else { |
| 3243 | /* illegal type */ |
| 3244 | return -EINVAL; |
| 3245 | } |
| 3246 | |
| 3247 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3248 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3249 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3250 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | return -ERANGE; |
| 3252 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3253 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3254 | for (i = 0; i < count ; i++) { |
| 3255 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 3256 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | } |
| 3258 | } |
| 3259 | return size; |
| 3260 | } |
| 3261 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3262 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 3263 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | { |
| 3265 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 3266 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3267 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3268 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3270 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3272 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3273 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3274 | 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] | 3275 | /*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] | 3276 | return rc; |
| 3277 | } |
| 3278 | |
| 3279 | /* 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] | 3280 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3281 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | { |
| 3283 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3284 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 3285 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | int count; |
| 3287 | int i; |
| 3288 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3289 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | return 0; |
| 3291 | |
| 3292 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3293 | 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] | 3294 | "version of %d", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3295 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3296 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3297 | cFYI(1, "unknown POSIX ACL version %d", |
| 3298 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | return 0; |
| 3300 | } |
| 3301 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3302 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3303 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3304 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3305 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3307 | cFYI(1, "unknown ACL type %d", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | return 0; |
| 3309 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3310 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 3312 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3313 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | /* ACE not converted */ |
| 3315 | break; |
| 3316 | } |
| 3317 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3318 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3320 | rc += sizeof(struct cifs_posix_acl); |
| 3321 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3322 | } |
| 3323 | return rc; |
| 3324 | } |
| 3325 | |
| 3326 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3327 | CIFSSMBGetPosixACL(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3328 | const unsigned char *searchName, |
| 3329 | char *acl_inf, const int buflen, const int acl_type, |
| 3330 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | { |
| 3332 | /* SMB_QUERY_POSIX_ACL */ |
| 3333 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3334 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3335 | int rc = 0; |
| 3336 | int bytes_returned; |
| 3337 | int name_len; |
| 3338 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3339 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3340 | cFYI(1, "In GetPosixACL (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | |
| 3342 | queryAclRetry: |
| 3343 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3344 | (void **) &pSMBr); |
| 3345 | if (rc) |
| 3346 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3349 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3350 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3351 | searchName, PATH_MAX, nls_codepage, |
| 3352 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | name_len++; /* trailing null */ |
| 3354 | name_len *= 2; |
| 3355 | pSMB->FileName[name_len] = 0; |
| 3356 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3357 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | name_len = strnlen(searchName, PATH_MAX); |
| 3359 | name_len++; /* trailing null */ |
| 3360 | strncpy(pSMB->FileName, searchName, name_len); |
| 3361 | } |
| 3362 | |
| 3363 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3364 | pSMB->TotalDataCount = 0; |
| 3365 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3366 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3368 | pSMB->MaxSetupCount = 0; |
| 3369 | pSMB->Reserved = 0; |
| 3370 | pSMB->Flags = 0; |
| 3371 | pSMB->Timeout = 0; |
| 3372 | pSMB->Reserved2 = 0; |
| 3373 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3374 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3375 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | pSMB->DataCount = 0; |
| 3377 | pSMB->DataOffset = 0; |
| 3378 | pSMB->SetupCount = 1; |
| 3379 | pSMB->Reserved3 = 0; |
| 3380 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3381 | byte_count = params + 1 /* pad */ ; |
| 3382 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3383 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3384 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3385 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3386 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3388 | |
| 3389 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3390 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3391 | cifs_stats_inc(&tcon->num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3393 | cFYI(1, "Send error in Query POSIX ACL = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | } else { |
| 3395 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3399 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | rc = -EIO; /* bad smb */ |
| 3401 | else { |
| 3402 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3403 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3404 | rc = cifs_copy_posix_acl(acl_inf, |
| 3405 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3406 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | cifs_buf_release(pSMB); |
| 3410 | if (rc == -EAGAIN) |
| 3411 | goto queryAclRetry; |
| 3412 | return rc; |
| 3413 | } |
| 3414 | |
| 3415 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3416 | CIFSSMBSetPosixACL(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3417 | const unsigned char *fileName, |
| 3418 | const char *local_acl, const int buflen, |
| 3419 | const int acl_type, |
| 3420 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | { |
| 3422 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3423 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3424 | char *parm_data; |
| 3425 | int name_len; |
| 3426 | int rc = 0; |
| 3427 | int bytes_returned = 0; |
| 3428 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3429 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3430 | cFYI(1, "In SetPosixACL (Unix) for path %s", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | setAclRetry: |
| 3432 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3433 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | if (rc) |
| 3435 | return rc; |
| 3436 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3437 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3438 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3439 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | name_len++; /* trailing null */ |
| 3441 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3442 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | name_len = strnlen(fileName, PATH_MAX); |
| 3444 | name_len++; /* trailing null */ |
| 3445 | strncpy(pSMB->FileName, fileName, name_len); |
| 3446 | } |
| 3447 | params = 6 + name_len; |
| 3448 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3449 | /* BB find max SMB size from sess */ |
| 3450 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | pSMB->MaxSetupCount = 0; |
| 3452 | pSMB->Reserved = 0; |
| 3453 | pSMB->Flags = 0; |
| 3454 | pSMB->Timeout = 0; |
| 3455 | pSMB->Reserved2 = 0; |
| 3456 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3457 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | offset = param_offset + params; |
| 3459 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3460 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3461 | |
| 3462 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3463 | 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] | 3464 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3465 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | rc = -EOPNOTSUPP; |
| 3467 | goto setACLerrorExit; |
| 3468 | } |
| 3469 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3470 | pSMB->SetupCount = 1; |
| 3471 | pSMB->Reserved3 = 0; |
| 3472 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3473 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3474 | byte_count = 3 /* pad */ + params + data_count; |
| 3475 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3476 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3477 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3478 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3479 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3480 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3482 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3483 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3484 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3485 | cFYI(1, "Set POSIX ACL returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | |
| 3487 | setACLerrorExit: |
| 3488 | cifs_buf_release(pSMB); |
| 3489 | if (rc == -EAGAIN) |
| 3490 | goto setAclRetry; |
| 3491 | return rc; |
| 3492 | } |
| 3493 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3494 | /* BB fix tabs in this function FIXME BB */ |
| 3495 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3496 | CIFSGetExtAttr(const int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3497 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3498 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3499 | int rc = 0; |
| 3500 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3501 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3502 | int bytes_returned; |
| 3503 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3504 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3505 | cFYI(1, "In GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3506 | if (tcon == NULL) |
| 3507 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3508 | |
| 3509 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3510 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3511 | (void **) &pSMBr); |
| 3512 | if (rc) |
| 3513 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3514 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3515 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3516 | pSMB->t2.TotalDataCount = 0; |
| 3517 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3518 | /* BB find exact max data count below from sess structure BB */ |
| 3519 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3520 | pSMB->t2.MaxSetupCount = 0; |
| 3521 | pSMB->t2.Reserved = 0; |
| 3522 | pSMB->t2.Flags = 0; |
| 3523 | pSMB->t2.Timeout = 0; |
| 3524 | pSMB->t2.Reserved2 = 0; |
| 3525 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3526 | Fid) - 4); |
| 3527 | pSMB->t2.DataCount = 0; |
| 3528 | pSMB->t2.DataOffset = 0; |
| 3529 | pSMB->t2.SetupCount = 1; |
| 3530 | pSMB->t2.Reserved3 = 0; |
| 3531 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3532 | byte_count = params + 1 /* pad */ ; |
| 3533 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3534 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3535 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3536 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3537 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3538 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3539 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3540 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3541 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3542 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3543 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3544 | cFYI(1, "error %d in GetExtAttr", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3545 | } else { |
| 3546 | /* decode response */ |
| 3547 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3548 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3549 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3550 | /* If rc should we check for EOPNOSUPP and |
| 3551 | disable the srvino flag? or in caller? */ |
| 3552 | rc = -EIO; /* bad smb */ |
| 3553 | else { |
| 3554 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3555 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3556 | struct file_chattr_info *pfinfo; |
| 3557 | /* BB Do we need a cast or hash here ? */ |
| 3558 | if (count != 16) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3559 | cFYI(1, "Illegal size ret in GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3560 | rc = -EIO; |
| 3561 | goto GetExtAttrOut; |
| 3562 | } |
| 3563 | pfinfo = (struct file_chattr_info *) |
| 3564 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3565 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3566 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3567 | } |
| 3568 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3569 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3570 | cifs_buf_release(pSMB); |
| 3571 | if (rc == -EAGAIN) |
| 3572 | goto GetExtAttrRetry; |
| 3573 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3576 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3578 | #ifdef CONFIG_CIFS_ACL |
| 3579 | /* |
| 3580 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3581 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3582 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3583 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3584 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3585 | * by caller |
| 3586 | */ |
| 3587 | static int |
| 3588 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3589 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3590 | void **ret_buf) |
| 3591 | { |
| 3592 | int rc; |
| 3593 | __u32 temp_offset; |
| 3594 | struct smb_com_ntransact_req *pSMB; |
| 3595 | |
| 3596 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3597 | (void **)&pSMB); |
| 3598 | if (rc) |
| 3599 | return rc; |
| 3600 | *ret_buf = (void *)pSMB; |
| 3601 | pSMB->Reserved = 0; |
| 3602 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3603 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3604 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3605 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3606 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3607 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3608 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3609 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3610 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3611 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3612 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3613 | return 0; |
| 3614 | } |
| 3615 | |
| 3616 | static int |
| 3617 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3618 | __u32 *pparmlen, __u32 *pdatalen) |
| 3619 | { |
| 3620 | char *end_of_smb; |
| 3621 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3622 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3623 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3624 | |
| 3625 | *pdatalen = 0; |
| 3626 | *pparmlen = 0; |
| 3627 | |
| 3628 | if (buf == NULL) |
| 3629 | return -EINVAL; |
| 3630 | |
| 3631 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3632 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3633 | bcc = get_bcc(&pSMBr->hdr); |
| 3634 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3635 | (char *)&pSMBr->ByteCount; |
| 3636 | |
| 3637 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3638 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3639 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3640 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3641 | |
| 3642 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3643 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3644 | |
| 3645 | /* should we also check that parm and data areas do not overlap? */ |
| 3646 | if (*ppparm > end_of_smb) { |
| 3647 | cFYI(1, "parms start after end of smb"); |
| 3648 | return -EINVAL; |
| 3649 | } else if (parm_count + *ppparm > end_of_smb) { |
| 3650 | cFYI(1, "parm end after end of smb"); |
| 3651 | return -EINVAL; |
| 3652 | } else if (*ppdata > end_of_smb) { |
| 3653 | cFYI(1, "data starts after end of smb"); |
| 3654 | return -EINVAL; |
| 3655 | } else if (data_count + *ppdata > end_of_smb) { |
| 3656 | cFYI(1, "data %p + count %d (%p) past smb end %p start %p", |
| 3657 | *ppdata, data_count, (data_count + *ppdata), |
| 3658 | end_of_smb, pSMBr); |
| 3659 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3660 | } else if (parm_count + data_count > bcc) { |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3661 | cFYI(1, "parm count and data count larger than SMB"); |
| 3662 | return -EINVAL; |
| 3663 | } |
| 3664 | *pdatalen = data_count; |
| 3665 | *pparmlen = parm_count; |
| 3666 | return 0; |
| 3667 | } |
| 3668 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3669 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3670 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3671 | CIFSSMBGetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3672 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3673 | { |
| 3674 | int rc = 0; |
| 3675 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3676 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3677 | struct kvec iov[1]; |
| 3678 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3679 | cFYI(1, "GetCifsACL"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3680 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3681 | *pbuflen = 0; |
| 3682 | *acl_inf = NULL; |
| 3683 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3684 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3685 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3686 | if (rc) |
| 3687 | return rc; |
| 3688 | |
| 3689 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3690 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3691 | pSMB->MaxSetupCount = 0; |
| 3692 | pSMB->Fid = fid; /* file handle always le */ |
| 3693 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3694 | CIFS_ACL_DACL); |
| 3695 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3696 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3697 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3698 | 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] | 3699 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3700 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 3701 | 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3702 | cifs_stats_inc(&tcon->num_acl_get); |
| 3703 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3704 | cFYI(1, "Send error in QuerySecDesc = %d", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3705 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3706 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3707 | __u32 parm_len; |
| 3708 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3709 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3710 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3711 | |
| 3712 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3713 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3714 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3715 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3716 | goto qsec_out; |
| 3717 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3718 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3719 | cFYI(1, "smb %p parm %p data %p", pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3720 | |
| 3721 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3722 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3723 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3724 | goto qsec_out; |
| 3725 | } |
| 3726 | |
| 3727 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3728 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3729 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3730 | if (acl_len != *pbuflen) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3731 | cERROR(1, "acl length %d does not match %d", |
| 3732 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3733 | if (*pbuflen > acl_len) |
| 3734 | *pbuflen = acl_len; |
| 3735 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3736 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3737 | /* check if buffer is big enough for the acl |
| 3738 | header followed by the smallest SID */ |
| 3739 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3740 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3741 | cERROR(1, "bad acl length %d", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3742 | rc = -EINVAL; |
| 3743 | *pbuflen = 0; |
| 3744 | } else { |
| 3745 | *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); |
| 3746 | if (*acl_inf == NULL) { |
| 3747 | *pbuflen = 0; |
| 3748 | rc = -ENOMEM; |
| 3749 | } |
| 3750 | memcpy(*acl_inf, pdata, *pbuflen); |
| 3751 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3752 | } |
| 3753 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3754 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3755 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3756 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3757 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3758 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3759 | return rc; |
| 3760 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3761 | |
| 3762 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3763 | CIFSSMBSetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3764 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3765 | { |
| 3766 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3767 | int rc = 0; |
| 3768 | int bytes_returned = 0; |
| 3769 | SET_SEC_DESC_REQ *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3770 | void *pSMBr; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3771 | |
| 3772 | setCifsAclRetry: |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3773 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3774 | if (rc) |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3775 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3776 | |
| 3777 | pSMB->MaxSetupCount = 0; |
| 3778 | pSMB->Reserved = 0; |
| 3779 | |
| 3780 | param_count = 8; |
| 3781 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3782 | data_count = acllen; |
| 3783 | data_offset = param_offset + param_count; |
| 3784 | byte_count = 3 /* pad */ + param_count; |
| 3785 | |
| 3786 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3787 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3788 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3789 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3790 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3791 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3792 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3793 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3794 | pSMB->SetupCount = 0; |
| 3795 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3796 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3797 | |
| 3798 | pSMB->Fid = fid; /* file handle always le */ |
| 3799 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3800 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3801 | |
| 3802 | if (pntsd && acllen) { |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3803 | memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + |
| 3804 | data_offset, pntsd, acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3805 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3806 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3807 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3808 | |
| 3809 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3810 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3811 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3812 | cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3813 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3814 | cFYI(1, "Set CIFS ACL returned %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3815 | cifs_buf_release(pSMB); |
| 3816 | |
| 3817 | if (rc == -EAGAIN) |
| 3818 | goto setCifsAclRetry; |
| 3819 | |
| 3820 | return (rc); |
| 3821 | } |
| 3822 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3823 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3824 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3825 | /* Legacy Query Path Information call for lookup to old servers such |
| 3826 | as Win9x/WinME */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3827 | int SMBQueryInformation(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3828 | const unsigned char *searchName, |
| 3829 | FILE_ALL_INFO *pFinfo, |
| 3830 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3831 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3832 | QUERY_INFORMATION_REQ *pSMB; |
| 3833 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3834 | int rc = 0; |
| 3835 | int bytes_returned; |
| 3836 | int name_len; |
| 3837 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3838 | cFYI(1, "In SMBQPath path %s", searchName); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3839 | QInfRetry: |
| 3840 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3841 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3842 | if (rc) |
| 3843 | return rc; |
| 3844 | |
| 3845 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3846 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3847 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3848 | searchName, PATH_MAX, nls_codepage, |
| 3849 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3850 | name_len++; /* trailing null */ |
| 3851 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3852 | } else { |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3853 | name_len = strnlen(searchName, PATH_MAX); |
| 3854 | name_len++; /* trailing null */ |
| 3855 | strncpy(pSMB->FileName, searchName, name_len); |
| 3856 | } |
| 3857 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3858 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3859 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3860 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3861 | |
| 3862 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3863 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3864 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3865 | cFYI(1, "Send error in QueryInfo = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3866 | } else if (pFinfo) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3867 | struct timespec ts; |
| 3868 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3869 | |
| 3870 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3871 | /* BB FIXME - add time zone adjustment BB */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3872 | memset(pFinfo, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3873 | ts.tv_nsec = 0; |
| 3874 | ts.tv_sec = time; |
| 3875 | /* decode time fields */ |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 3876 | pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3877 | pFinfo->LastWriteTime = pFinfo->ChangeTime; |
| 3878 | pFinfo->LastAccessTime = 0; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3879 | pFinfo->AllocationSize = |
| 3880 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
| 3881 | pFinfo->EndOfFile = pFinfo->AllocationSize; |
| 3882 | pFinfo->Attributes = |
| 3883 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3884 | } else |
| 3885 | rc = -EIO; /* bad buffer passed in */ |
| 3886 | |
| 3887 | cifs_buf_release(pSMB); |
| 3888 | |
| 3889 | if (rc == -EAGAIN) |
| 3890 | goto QInfRetry; |
| 3891 | |
| 3892 | return rc; |
| 3893 | } |
| 3894 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3895 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3896 | CIFSSMBQFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3897 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 3898 | { |
| 3899 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3900 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3901 | int rc = 0; |
| 3902 | int bytes_returned; |
| 3903 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3904 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3905 | QFileInfoRetry: |
| 3906 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3907 | (void **) &pSMBr); |
| 3908 | if (rc) |
| 3909 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3910 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3911 | params = 2 /* level */ + 2 /* fid */; |
| 3912 | pSMB->t2.TotalDataCount = 0; |
| 3913 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3914 | /* BB find exact max data count below from sess structure BB */ |
| 3915 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3916 | pSMB->t2.MaxSetupCount = 0; |
| 3917 | pSMB->t2.Reserved = 0; |
| 3918 | pSMB->t2.Flags = 0; |
| 3919 | pSMB->t2.Timeout = 0; |
| 3920 | pSMB->t2.Reserved2 = 0; |
| 3921 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3922 | Fid) - 4); |
| 3923 | pSMB->t2.DataCount = 0; |
| 3924 | pSMB->t2.DataOffset = 0; |
| 3925 | pSMB->t2.SetupCount = 1; |
| 3926 | pSMB->t2.Reserved3 = 0; |
| 3927 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3928 | byte_count = params + 1 /* pad */ ; |
| 3929 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3930 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3931 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 3932 | pSMB->Pad = 0; |
| 3933 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3934 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3935 | |
| 3936 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3937 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3938 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3939 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3940 | } else { /* decode response */ |
| 3941 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3942 | |
| 3943 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3944 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3945 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3946 | rc = -EIO; /* bad smb */ |
| 3947 | else if (pFindData) { |
| 3948 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3949 | memcpy((char *) pFindData, |
| 3950 | (char *) &pSMBr->hdr.Protocol + |
| 3951 | data_offset, sizeof(FILE_ALL_INFO)); |
| 3952 | } else |
| 3953 | rc = -ENOMEM; |
| 3954 | } |
| 3955 | cifs_buf_release(pSMB); |
| 3956 | if (rc == -EAGAIN) |
| 3957 | goto QFileInfoRetry; |
| 3958 | |
| 3959 | return rc; |
| 3960 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3963 | CIFSSMBQPathInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3965 | FILE_ALL_INFO *pFindData, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3966 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3967 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | { |
| 3969 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
| 3970 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3971 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3972 | int rc = 0; |
| 3973 | int bytes_returned; |
| 3974 | int name_len; |
| 3975 | __u16 params, byte_count; |
| 3976 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3977 | /* cFYI(1, "In QPathInfo path %s", searchName); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | QPathInfoRetry: |
| 3979 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3980 | (void **) &pSMBr); |
| 3981 | if (rc) |
| 3982 | return rc; |
| 3983 | |
| 3984 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3985 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3986 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 3987 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | name_len++; /* trailing null */ |
| 3989 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3990 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | name_len = strnlen(searchName, PATH_MAX); |
| 3992 | name_len++; /* trailing null */ |
| 3993 | strncpy(pSMB->FileName, searchName, name_len); |
| 3994 | } |
| 3995 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3996 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | pSMB->TotalDataCount = 0; |
| 3998 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3999 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4000 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | pSMB->MaxSetupCount = 0; |
| 4002 | pSMB->Reserved = 0; |
| 4003 | pSMB->Flags = 0; |
| 4004 | pSMB->Timeout = 0; |
| 4005 | pSMB->Reserved2 = 0; |
| 4006 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4007 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | pSMB->DataCount = 0; |
| 4009 | pSMB->DataOffset = 0; |
| 4010 | pSMB->SetupCount = 1; |
| 4011 | pSMB->Reserved3 = 0; |
| 4012 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4013 | byte_count = params + 1 /* pad */ ; |
| 4014 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4015 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4016 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4017 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4018 | else |
| 4019 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4021 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4023 | |
| 4024 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4025 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4026 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4027 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | } else { /* decode response */ |
| 4029 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4030 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4031 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4032 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4033 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4035 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4036 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4037 | last field */ |
| 4038 | else if (pFindData) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4039 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4041 | |
| 4042 | /* On legacy responses we do not read the last field, |
| 4043 | EAsize, fortunately since it varies by subdialect and |
| 4044 | also note it differs on Set vs. Get, ie two bytes or 4 |
| 4045 | bytes depending but we don't care here */ |
| 4046 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4047 | size = sizeof(FILE_INFO_STANDARD); |
| 4048 | else |
| 4049 | size = sizeof(FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | memcpy((char *) pFindData, |
| 4051 | (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4052 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | } else |
| 4054 | rc = -ENOMEM; |
| 4055 | } |
| 4056 | cifs_buf_release(pSMB); |
| 4057 | if (rc == -EAGAIN) |
| 4058 | goto QPathInfoRetry; |
| 4059 | |
| 4060 | return rc; |
| 4061 | } |
| 4062 | |
| 4063 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4064 | CIFSSMBUnixQFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4065 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4066 | { |
| 4067 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4068 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4069 | int rc = 0; |
| 4070 | int bytes_returned; |
| 4071 | __u16 params, byte_count; |
| 4072 | |
| 4073 | UnixQFileInfoRetry: |
| 4074 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4075 | (void **) &pSMBr); |
| 4076 | if (rc) |
| 4077 | return rc; |
| 4078 | |
| 4079 | params = 2 /* level */ + 2 /* fid */; |
| 4080 | pSMB->t2.TotalDataCount = 0; |
| 4081 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4082 | /* BB find exact max data count below from sess structure BB */ |
| 4083 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4084 | pSMB->t2.MaxSetupCount = 0; |
| 4085 | pSMB->t2.Reserved = 0; |
| 4086 | pSMB->t2.Flags = 0; |
| 4087 | pSMB->t2.Timeout = 0; |
| 4088 | pSMB->t2.Reserved2 = 0; |
| 4089 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4090 | Fid) - 4); |
| 4091 | pSMB->t2.DataCount = 0; |
| 4092 | pSMB->t2.DataOffset = 0; |
| 4093 | pSMB->t2.SetupCount = 1; |
| 4094 | pSMB->t2.Reserved3 = 0; |
| 4095 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4096 | byte_count = params + 1 /* pad */ ; |
| 4097 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4098 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4099 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4100 | pSMB->Pad = 0; |
| 4101 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4102 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4103 | |
| 4104 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4105 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4106 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4107 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4108 | } else { /* decode response */ |
| 4109 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4110 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4111 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4112 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4113 | "Unix Extensions can be disabled on mount " |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4114 | "by specifying the nosfu mount option."); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4115 | rc = -EIO; /* bad smb */ |
| 4116 | } else { |
| 4117 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4118 | memcpy((char *) pFindData, |
| 4119 | (char *) &pSMBr->hdr.Protocol + |
| 4120 | data_offset, |
| 4121 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4122 | } |
| 4123 | } |
| 4124 | |
| 4125 | cifs_buf_release(pSMB); |
| 4126 | if (rc == -EAGAIN) |
| 4127 | goto UnixQFileInfoRetry; |
| 4128 | |
| 4129 | return rc; |
| 4130 | } |
| 4131 | |
| 4132 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4133 | CIFSSMBUnixQPathInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4135 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4136 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | { |
| 4138 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4139 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4140 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4141 | int rc = 0; |
| 4142 | int bytes_returned = 0; |
| 4143 | int name_len; |
| 4144 | __u16 params, byte_count; |
| 4145 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4146 | cFYI(1, "In QPathInfo (Unix) the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | UnixQPathInfoRetry: |
| 4148 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4149 | (void **) &pSMBr); |
| 4150 | if (rc) |
| 4151 | return rc; |
| 4152 | |
| 4153 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4154 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4155 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4156 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | name_len++; /* trailing null */ |
| 4158 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4159 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | name_len = strnlen(searchName, PATH_MAX); |
| 4161 | name_len++; /* trailing null */ |
| 4162 | strncpy(pSMB->FileName, searchName, name_len); |
| 4163 | } |
| 4164 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4165 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | pSMB->TotalDataCount = 0; |
| 4167 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4168 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4169 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | pSMB->MaxSetupCount = 0; |
| 4171 | pSMB->Reserved = 0; |
| 4172 | pSMB->Flags = 0; |
| 4173 | pSMB->Timeout = 0; |
| 4174 | pSMB->Reserved2 = 0; |
| 4175 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4176 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | pSMB->DataCount = 0; |
| 4178 | pSMB->DataOffset = 0; |
| 4179 | pSMB->SetupCount = 1; |
| 4180 | pSMB->Reserved3 = 0; |
| 4181 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4182 | byte_count = params + 1 /* pad */ ; |
| 4183 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4184 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4185 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4186 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4187 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4189 | |
| 4190 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4191 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4192 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4193 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | } else { /* decode response */ |
| 4195 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4196 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4197 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4198 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Steve French | 1e71f25 | 2007-09-20 15:30:07 +0000 | [diff] [blame] | 4199 | "Unix Extensions can be disabled on mount " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4200 | "by specifying the nosfu mount option."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | rc = -EIO; /* bad smb */ |
| 4202 | } else { |
| 4203 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4204 | memcpy((char *) pFindData, |
| 4205 | (char *) &pSMBr->hdr.Protocol + |
| 4206 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4207 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | } |
| 4209 | } |
| 4210 | cifs_buf_release(pSMB); |
| 4211 | if (rc == -EAGAIN) |
| 4212 | goto UnixQPathInfoRetry; |
| 4213 | |
| 4214 | return rc; |
| 4215 | } |
| 4216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4218 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4219 | CIFSFindFirst(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4220 | const char *searchName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | const struct nls_table *nls_codepage, |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4222 | __u16 *pnetfid, __u16 search_flags, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4223 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | { |
| 4225 | /* level 257 SMB_ */ |
| 4226 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4227 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4228 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | int rc = 0; |
| 4230 | int bytes_returned = 0; |
| 4231 | int name_len; |
| 4232 | __u16 params, byte_count; |
| 4233 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4234 | cFYI(1, "In FindFirst for %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | |
| 4236 | findFirstRetry: |
| 4237 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4238 | (void **) &pSMBr); |
| 4239 | if (rc) |
| 4240 | return rc; |
| 4241 | |
| 4242 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4243 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4244 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4245 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4246 | /* We can not add the asterik earlier in case |
| 4247 | it got remapped to 0xF03A as if it were part of the |
| 4248 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | name_len *= 2; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4250 | pSMB->FileName[name_len] = dirsep; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4251 | pSMB->FileName[name_len+1] = 0; |
| 4252 | pSMB->FileName[name_len+2] = '*'; |
| 4253 | pSMB->FileName[name_len+3] = 0; |
| 4254 | name_len += 4; /* now the trailing null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ |
| 4256 | pSMB->FileName[name_len+1] = 0; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4257 | name_len += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | } else { /* BB add check for overrun of SMB buf BB */ |
| 4259 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4261 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | free buffer exit; BB */ |
| 4263 | strncpy(pSMB->FileName, searchName, name_len); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4264 | pSMB->FileName[name_len] = dirsep; |
Steve French | 6857547 | 2005-04-30 11:10:57 -0700 | [diff] [blame] | 4265 | pSMB->FileName[name_len+1] = '*'; |
| 4266 | pSMB->FileName[name_len+2] = 0; |
| 4267 | name_len += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | params = 12 + name_len /* includes null */ ; |
| 4271 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4272 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4273 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | pSMB->MaxSetupCount = 0; |
| 4275 | pSMB->Reserved = 0; |
| 4276 | pSMB->Flags = 0; |
| 4277 | pSMB->Timeout = 0; |
| 4278 | pSMB->Reserved2 = 0; |
| 4279 | byte_count = params + 1 /* pad */ ; |
| 4280 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4281 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4282 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4283 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4284 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | pSMB->DataCount = 0; |
| 4286 | pSMB->DataOffset = 0; |
| 4287 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4288 | pSMB->Reserved3 = 0; |
| 4289 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4290 | pSMB->SearchAttributes = |
| 4291 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4292 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4293 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4294 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4296 | |
| 4297 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4298 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4299 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4301 | |
| 4302 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4303 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4304 | cifs_stats_inc(&tcon->num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4306 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4307 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4309 | cFYI(1, "Error in FindFirst = %d", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4310 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4311 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | |
| 4313 | /* BB eventually could optimize out free and realloc of buf */ |
| 4314 | /* for this case */ |
| 4315 | if (rc == -EAGAIN) |
| 4316 | goto findFirstRetry; |
| 4317 | } else { /* decode response */ |
| 4318 | /* BB remember to free buffer if error BB */ |
| 4319 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4320 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4321 | unsigned int lnoff; |
| 4322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4324 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4326 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | |
| 4328 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4329 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4330 | psrch_inf->srch_entries_start = |
| 4331 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4334 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4335 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4336 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4337 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4339 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4341 | psrch_inf->entries_in_buffer = |
| 4342 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4343 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4345 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4346 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4347 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4348 | psrch_inf->last_entry = NULL; |
| 4349 | return rc; |
| 4350 | } |
| 4351 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4352 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4353 | lnoff; |
| 4354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | *pnetfid = parms->SearchHandle; |
| 4356 | } else { |
| 4357 | cifs_buf_release(pSMB); |
| 4358 | } |
| 4359 | } |
| 4360 | |
| 4361 | return rc; |
| 4362 | } |
| 4363 | |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4364 | int CIFSFindNext(const int xid, struct cifs_tcon *tcon, __u16 searchHandle, |
| 4365 | __u16 search_flags, struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | { |
| 4367 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4368 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4369 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | char *response_data; |
| 4371 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4372 | int bytes_returned; |
| 4373 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | __u16 params, byte_count; |
| 4375 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4376 | cFYI(1, "In FindNext"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4378 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | return -ENOENT; |
| 4380 | |
| 4381 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4382 | (void **) &pSMBr); |
| 4383 | if (rc) |
| 4384 | return rc; |
| 4385 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4386 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | byte_count = 0; |
| 4388 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4389 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4390 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | pSMB->MaxSetupCount = 0; |
| 4392 | pSMB->Reserved = 0; |
| 4393 | pSMB->Flags = 0; |
| 4394 | pSMB->Timeout = 0; |
| 4395 | pSMB->Reserved2 = 0; |
| 4396 | pSMB->ParameterOffset = cpu_to_le16( |
| 4397 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4398 | pSMB->DataCount = 0; |
| 4399 | pSMB->DataOffset = 0; |
| 4400 | pSMB->SetupCount = 1; |
| 4401 | pSMB->Reserved3 = 0; |
| 4402 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4403 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4404 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4405 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4407 | pSMB->ResumeKey = psrch_inf->resume_key; |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4408 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | |
| 4410 | name_len = psrch_inf->resume_name_len; |
| 4411 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4412 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4414 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4415 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4416 | pSMB->ResumeFileName[name_len] = 0; |
| 4417 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | } else { |
| 4419 | rc = -EINVAL; |
| 4420 | goto FNext2_err_exit; |
| 4421 | } |
| 4422 | byte_count = params + 1 /* pad */ ; |
| 4423 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4424 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4425 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4429 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4430 | cifs_stats_inc(&tcon->num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | if (rc) { |
| 4432 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4433 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4434 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4435 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | } else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4437 | cFYI(1, "FindNext returned = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | } else { /* decode response */ |
| 4439 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4440 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4441 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4442 | unsigned int lnoff; |
| 4443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4445 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4446 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4448 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4450 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4451 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4452 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4453 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4454 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4455 | cifs_small_buf_release( |
| 4456 | psrch_inf->ntwrk_buf_start); |
| 4457 | else |
| 4458 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | psrch_inf->srch_entries_start = response_data; |
| 4460 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4461 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4462 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4463 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4465 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4466 | psrch_inf->entries_in_buffer = |
| 4467 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | psrch_inf->index_of_last_entry += |
| 4469 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4470 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4471 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4472 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4473 | psrch_inf->last_entry = NULL; |
| 4474 | return rc; |
| 4475 | } else |
| 4476 | psrch_inf->last_entry = |
| 4477 | psrch_inf->srch_entries_start + lnoff; |
| 4478 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4479 | /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d", |
| 4480 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | |
| 4482 | /* BB fixme add unlock here */ |
| 4483 | } |
| 4484 | |
| 4485 | } |
| 4486 | |
| 4487 | /* BB On error, should we leave previous search buf (and count and |
| 4488 | last entry fields) intact or free the previous one? */ |
| 4489 | |
| 4490 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4491 | since file handle passed in no longer valid */ |
| 4492 | FNext2_err_exit: |
| 4493 | if (rc != 0) |
| 4494 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | return rc; |
| 4496 | } |
| 4497 | |
| 4498 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4499 | CIFSFindClose(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4500 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | { |
| 4502 | int rc = 0; |
| 4503 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4505 | cFYI(1, "In CIFSSMBFindClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4507 | |
| 4508 | /* no sense returning error if session restarted |
| 4509 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4510 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | return 0; |
| 4512 | if (rc) |
| 4513 | return rc; |
| 4514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | pSMB->FileID = searchHandle; |
| 4516 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4517 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4518 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4519 | cERROR(1, "Send error in FindClose = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4520 | |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4521 | cifs_stats_inc(&tcon->num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | |
| 4523 | /* Since session is dead, search handle closed on server already */ |
| 4524 | if (rc == -EAGAIN) |
| 4525 | rc = 0; |
| 4526 | |
| 4527 | return rc; |
| 4528 | } |
| 4529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4531 | CIFSGetSrvInodeNumber(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4532 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4533 | __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4534 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | { |
| 4536 | int rc = 0; |
| 4537 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4538 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4539 | int name_len, bytes_returned; |
| 4540 | __u16 params, byte_count; |
| 4541 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4542 | cFYI(1, "In GetSrvInodeNum for %s", searchName); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4543 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4544 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | |
| 4546 | GetInodeNumberRetry: |
| 4547 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4548 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | if (rc) |
| 4550 | return rc; |
| 4551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4553 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4554 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 4555 | searchName, PATH_MAX, nls_codepage, |
| 4556 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | name_len++; /* trailing null */ |
| 4558 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4559 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | name_len = strnlen(searchName, PATH_MAX); |
| 4561 | name_len++; /* trailing null */ |
| 4562 | strncpy(pSMB->FileName, searchName, name_len); |
| 4563 | } |
| 4564 | |
| 4565 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4566 | pSMB->TotalDataCount = 0; |
| 4567 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4568 | /* BB find exact max data count below from sess structure BB */ |
| 4569 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4570 | pSMB->MaxSetupCount = 0; |
| 4571 | pSMB->Reserved = 0; |
| 4572 | pSMB->Flags = 0; |
| 4573 | pSMB->Timeout = 0; |
| 4574 | pSMB->Reserved2 = 0; |
| 4575 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4576 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | pSMB->DataCount = 0; |
| 4578 | pSMB->DataOffset = 0; |
| 4579 | pSMB->SetupCount = 1; |
| 4580 | pSMB->Reserved3 = 0; |
| 4581 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4582 | byte_count = params + 1 /* pad */ ; |
| 4583 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4584 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4585 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4586 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4587 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4589 | |
| 4590 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4591 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4592 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4593 | cFYI(1, "error %d in QueryInternalInfo", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | } else { |
| 4595 | /* decode response */ |
| 4596 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4598 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4599 | /* If rc should we check for EOPNOSUPP and |
| 4600 | disable the srvino flag? or in caller? */ |
| 4601 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4602 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4604 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4605 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4607 | if (count < 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4608 | cFYI(1, "Illegal size ret in QryIntrnlInf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | rc = -EIO; |
| 4610 | goto GetInodeNumOut; |
| 4611 | } |
| 4612 | pfinfo = (struct file_internal_info *) |
| 4613 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4614 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | } |
| 4616 | } |
| 4617 | GetInodeNumOut: |
| 4618 | cifs_buf_release(pSMB); |
| 4619 | if (rc == -EAGAIN) |
| 4620 | goto GetInodeNumberRetry; |
| 4621 | return rc; |
| 4622 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4624 | /* parses DFS refferal V3 structure |
| 4625 | * caller is responsible for freeing target_nodes |
| 4626 | * returns: |
| 4627 | * on success - 0 |
| 4628 | * on failure - errno |
| 4629 | */ |
| 4630 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4631 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4632 | unsigned int *num_of_nodes, |
| 4633 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4634 | const struct nls_table *nls_codepage, int remap, |
| 4635 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4636 | { |
| 4637 | int i, rc = 0; |
| 4638 | char *data_end; |
| 4639 | bool is_unicode; |
| 4640 | struct dfs_referral_level_3 *ref; |
| 4641 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 4642 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 4643 | is_unicode = true; |
| 4644 | else |
| 4645 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4646 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 4647 | |
| 4648 | if (*num_of_nodes < 1) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4649 | cERROR(1, "num_referrals: must be at least > 0," |
| 4650 | "but we get num_referrals = %d\n", *num_of_nodes); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4651 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4652 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4656 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4657 | cERROR(1, "Referrals of V%d version are not supported," |
| 4658 | "should be V3", le16_to_cpu(ref->VersionNumber)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4659 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4660 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | /* get the upper boundary of the resp buffer */ |
| 4664 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 4665 | le16_to_cpu(pSMBr->t2.DataCount); |
| 4666 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4667 | cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n", |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4668 | *num_of_nodes, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4669 | le32_to_cpu(pSMBr->DFSFlags)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4670 | |
| 4671 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
| 4672 | *num_of_nodes, GFP_KERNEL); |
| 4673 | if (*target_nodes == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4674 | cERROR(1, "Failed to allocate buffer for target_nodes\n"); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4675 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4676 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4677 | } |
| 4678 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4679 | /* collect necessary data from referrals */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4680 | for (i = 0; i < *num_of_nodes; i++) { |
| 4681 | char *temp; |
| 4682 | int max_len; |
| 4683 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 4684 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4685 | node->flags = le32_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4686 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 4687 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 4688 | GFP_KERNEL); |
Steve French | 2920ee2 | 2009-08-31 15:27:26 +0000 | [diff] [blame] | 4689 | if (tmp == NULL) { |
| 4690 | rc = -ENOMEM; |
| 4691 | goto parse_DFS_referrals_exit; |
| 4692 | } |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4693 | cifsConvertToUTF16((__le16 *) tmp, searchName, |
| 4694 | PATH_MAX, nls_codepage, remap); |
| 4695 | node->path_consumed = cifs_utf16_bytes(tmp, |
Jeff Layton | 69f801f | 2009-04-30 06:46:32 -0400 | [diff] [blame] | 4696 | le16_to_cpu(pSMBr->PathConsumed), |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4697 | nls_codepage); |
| 4698 | kfree(tmp); |
| 4699 | } else |
| 4700 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4701 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4702 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4703 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4704 | |
| 4705 | /* copy DfsPath */ |
| 4706 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4707 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4708 | node->path_name = cifs_strndup_from_utf16(temp, max_len, |
| 4709 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4710 | if (!node->path_name) { |
| 4711 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4712 | goto parse_DFS_referrals_exit; |
Jeff Layton | 066ce68 | 2009-04-30 07:16:14 -0400 | [diff] [blame] | 4713 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4714 | |
| 4715 | /* copy link target UNC */ |
| 4716 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4717 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4718 | node->node_name = cifs_strndup_from_utf16(temp, max_len, |
| 4719 | is_unicode, nls_codepage); |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4720 | if (!node->node_name) { |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4721 | rc = -ENOMEM; |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4722 | goto parse_DFS_referrals_exit; |
| 4723 | } |
| 4724 | |
| 4725 | ref++; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4726 | } |
| 4727 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4728 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4729 | if (rc) { |
| 4730 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4731 | *target_nodes = NULL; |
| 4732 | *num_of_nodes = 0; |
| 4733 | } |
| 4734 | return rc; |
| 4735 | } |
| 4736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4738 | CIFSGetDFSRefer(const int xid, struct cifs_ses *ses, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | const unsigned char *searchName, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4740 | struct dfs_info3_param **target_nodes, |
| 4741 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4742 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | { |
| 4744 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4745 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4746 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | int rc = 0; |
| 4748 | int bytes_returned; |
| 4749 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4751 | *num_of_nodes = 0; |
| 4752 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4754 | cFYI(1, "In GetDFSRefer the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | if (ses == NULL) |
| 4756 | return -ENODEV; |
| 4757 | getDFSRetry: |
| 4758 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4759 | (void **) &pSMBr); |
| 4760 | if (rc) |
| 4761 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4762 | |
| 4763 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4764 | but should never be null here anyway */ |
| 4765 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4767 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4768 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4770 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4772 | |
| 4773 | if (ses->capabilities & CAP_UNICODE) { |
| 4774 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4775 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4776 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
| 4777 | searchName, PATH_MAX, nls_codepage, |
| 4778 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | name_len++; /* trailing null */ |
| 4780 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4781 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | name_len = strnlen(searchName, PATH_MAX); |
| 4783 | name_len++; /* trailing null */ |
| 4784 | strncpy(pSMB->RequestFileName, searchName, name_len); |
| 4785 | } |
| 4786 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4787 | if (ses->server) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4788 | if (ses->server->sec_mode & |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4789 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 4790 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4791 | } |
| 4792 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4793 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4795 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4796 | pSMB->TotalDataCount = 0; |
| 4797 | pSMB->DataCount = 0; |
| 4798 | pSMB->DataOffset = 0; |
| 4799 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4800 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4801 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | pSMB->MaxSetupCount = 0; |
| 4803 | pSMB->Reserved = 0; |
| 4804 | pSMB->Flags = 0; |
| 4805 | pSMB->Timeout = 0; |
| 4806 | pSMB->Reserved2 = 0; |
| 4807 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4808 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | pSMB->SetupCount = 1; |
| 4810 | pSMB->Reserved3 = 0; |
| 4811 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4812 | byte_count = params + 3 /* pad */ ; |
| 4813 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4814 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4815 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4816 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4818 | |
| 4819 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4820 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4821 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4822 | cFYI(1, "Send error in GetDFSRefer = %d", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4823 | goto GetDFSRefExit; |
| 4824 | } |
| 4825 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4827 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4828 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4829 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4830 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4832 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4833 | cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4834 | get_bcc(&pSMBr->hdr), |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4835 | le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4836 | |
| 4837 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4838 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4839 | target_nodes, nls_codepage, remap, |
| 4840 | searchName); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4843 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | |
| 4845 | if (rc == -EAGAIN) |
| 4846 | goto getDFSRetry; |
| 4847 | |
| 4848 | return rc; |
| 4849 | } |
| 4850 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4851 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4852 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4853 | SMBOldQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4854 | { |
| 4855 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4856 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4857 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4858 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4859 | int rc = 0; |
| 4860 | int bytes_returned = 0; |
| 4861 | __u16 params, byte_count; |
| 4862 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4863 | cFYI(1, "OldQFSInfo"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4864 | oldQFSInfoRetry: |
| 4865 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4866 | (void **) &pSMBr); |
| 4867 | if (rc) |
| 4868 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4869 | |
| 4870 | params = 2; /* level */ |
| 4871 | pSMB->TotalDataCount = 0; |
| 4872 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4873 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4874 | pSMB->MaxSetupCount = 0; |
| 4875 | pSMB->Reserved = 0; |
| 4876 | pSMB->Flags = 0; |
| 4877 | pSMB->Timeout = 0; |
| 4878 | pSMB->Reserved2 = 0; |
| 4879 | byte_count = params + 1 /* pad */ ; |
| 4880 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4881 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4882 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4883 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4884 | pSMB->DataCount = 0; |
| 4885 | pSMB->DataOffset = 0; |
| 4886 | pSMB->SetupCount = 1; |
| 4887 | pSMB->Reserved3 = 0; |
| 4888 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4889 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4890 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4891 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4892 | |
| 4893 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4894 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4895 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4896 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4897 | } else { /* decode response */ |
| 4898 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4899 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4900 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4901 | rc = -EIO; /* bad smb */ |
| 4902 | else { |
| 4903 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4904 | cFYI(1, "qfsinf resp BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4905 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4906 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4907 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4908 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4909 | FSData->f_bsize = |
| 4910 | le16_to_cpu(response_data->BytesPerSector) * |
| 4911 | le32_to_cpu(response_data-> |
| 4912 | SectorsPerAllocationUnit); |
| 4913 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4914 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4915 | FSData->f_bfree = FSData->f_bavail = |
| 4916 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4917 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4918 | (unsigned long long)FSData->f_blocks, |
| 4919 | (unsigned long long)FSData->f_bfree, |
| 4920 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4921 | } |
| 4922 | } |
| 4923 | cifs_buf_release(pSMB); |
| 4924 | |
| 4925 | if (rc == -EAGAIN) |
| 4926 | goto oldQFSInfoRetry; |
| 4927 | |
| 4928 | return rc; |
| 4929 | } |
| 4930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4931 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4932 | CIFSSMBQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4933 | { |
| 4934 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4935 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4936 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4937 | FILE_SYSTEM_INFO *response_data; |
| 4938 | int rc = 0; |
| 4939 | int bytes_returned = 0; |
| 4940 | __u16 params, byte_count; |
| 4941 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4942 | cFYI(1, "In QFSInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | QFSInfoRetry: |
| 4944 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4945 | (void **) &pSMBr); |
| 4946 | if (rc) |
| 4947 | return rc; |
| 4948 | |
| 4949 | params = 2; /* level */ |
| 4950 | pSMB->TotalDataCount = 0; |
| 4951 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4952 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | pSMB->MaxSetupCount = 0; |
| 4954 | pSMB->Reserved = 0; |
| 4955 | pSMB->Flags = 0; |
| 4956 | pSMB->Timeout = 0; |
| 4957 | pSMB->Reserved2 = 0; |
| 4958 | byte_count = params + 1 /* pad */ ; |
| 4959 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4960 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4961 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4962 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | pSMB->DataCount = 0; |
| 4964 | pSMB->DataOffset = 0; |
| 4965 | pSMB->SetupCount = 1; |
| 4966 | pSMB->Reserved3 = 0; |
| 4967 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4968 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4969 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4970 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4971 | |
| 4972 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4973 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4974 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4975 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4976 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4977 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4979 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | rc = -EIO; /* bad smb */ |
| 4981 | else { |
| 4982 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | |
| 4984 | response_data = |
| 4985 | (FILE_SYSTEM_INFO |
| 4986 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4987 | data_offset); |
| 4988 | FSData->f_bsize = |
| 4989 | le32_to_cpu(response_data->BytesPerSector) * |
| 4990 | le32_to_cpu(response_data-> |
| 4991 | SectorsPerAllocationUnit); |
| 4992 | FSData->f_blocks = |
| 4993 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 4994 | FSData->f_bfree = FSData->f_bavail = |
| 4995 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4996 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4997 | (unsigned long long)FSData->f_blocks, |
| 4998 | (unsigned long long)FSData->f_bfree, |
| 4999 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | } |
| 5001 | } |
| 5002 | cifs_buf_release(pSMB); |
| 5003 | |
| 5004 | if (rc == -EAGAIN) |
| 5005 | goto QFSInfoRetry; |
| 5006 | |
| 5007 | return rc; |
| 5008 | } |
| 5009 | |
| 5010 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5011 | CIFSSMBQFSAttributeInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | { |
| 5013 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5014 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5015 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5016 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5017 | int rc = 0; |
| 5018 | int bytes_returned = 0; |
| 5019 | __u16 params, byte_count; |
| 5020 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5021 | cFYI(1, "In QFSAttributeInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | QFSAttributeRetry: |
| 5023 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5024 | (void **) &pSMBr); |
| 5025 | if (rc) |
| 5026 | return rc; |
| 5027 | |
| 5028 | params = 2; /* level */ |
| 5029 | pSMB->TotalDataCount = 0; |
| 5030 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5031 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5032 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5033 | pSMB->MaxSetupCount = 0; |
| 5034 | pSMB->Reserved = 0; |
| 5035 | pSMB->Flags = 0; |
| 5036 | pSMB->Timeout = 0; |
| 5037 | pSMB->Reserved2 = 0; |
| 5038 | byte_count = params + 1 /* pad */ ; |
| 5039 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5040 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5041 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5042 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | pSMB->DataCount = 0; |
| 5044 | pSMB->DataOffset = 0; |
| 5045 | pSMB->SetupCount = 1; |
| 5046 | pSMB->Reserved3 = 0; |
| 5047 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5048 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5049 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5050 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5051 | |
| 5052 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5053 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5054 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5055 | cERROR(1, "Send error in QFSAttributeInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | } else { /* decode response */ |
| 5057 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5058 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5059 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5060 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | rc = -EIO; /* bad smb */ |
| 5062 | } else { |
| 5063 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5064 | response_data = |
| 5065 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5066 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5067 | data_offset); |
| 5068 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5069 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | } |
| 5071 | } |
| 5072 | cifs_buf_release(pSMB); |
| 5073 | |
| 5074 | if (rc == -EAGAIN) |
| 5075 | goto QFSAttributeRetry; |
| 5076 | |
| 5077 | return rc; |
| 5078 | } |
| 5079 | |
| 5080 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5081 | CIFSSMBQFSDeviceInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | { |
| 5083 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5084 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5085 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5086 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5087 | int rc = 0; |
| 5088 | int bytes_returned = 0; |
| 5089 | __u16 params, byte_count; |
| 5090 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5091 | cFYI(1, "In QFSDeviceInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | QFSDeviceRetry: |
| 5093 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5094 | (void **) &pSMBr); |
| 5095 | if (rc) |
| 5096 | return rc; |
| 5097 | |
| 5098 | params = 2; /* level */ |
| 5099 | pSMB->TotalDataCount = 0; |
| 5100 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5101 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5102 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5103 | pSMB->MaxSetupCount = 0; |
| 5104 | pSMB->Reserved = 0; |
| 5105 | pSMB->Flags = 0; |
| 5106 | pSMB->Timeout = 0; |
| 5107 | pSMB->Reserved2 = 0; |
| 5108 | byte_count = params + 1 /* pad */ ; |
| 5109 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5110 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5111 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5112 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5113 | |
| 5114 | pSMB->DataCount = 0; |
| 5115 | pSMB->DataOffset = 0; |
| 5116 | pSMB->SetupCount = 1; |
| 5117 | pSMB->Reserved3 = 0; |
| 5118 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5119 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5120 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5121 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5122 | |
| 5123 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5124 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5125 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5126 | cFYI(1, "Send error in QFSDeviceInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | } else { /* decode response */ |
| 5128 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5129 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5130 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5131 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | rc = -EIO; /* bad smb */ |
| 5133 | else { |
| 5134 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5135 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5136 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5137 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | data_offset); |
| 5139 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5140 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5141 | } |
| 5142 | } |
| 5143 | cifs_buf_release(pSMB); |
| 5144 | |
| 5145 | if (rc == -EAGAIN) |
| 5146 | goto QFSDeviceRetry; |
| 5147 | |
| 5148 | return rc; |
| 5149 | } |
| 5150 | |
| 5151 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5152 | CIFSSMBQFSUnixInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5153 | { |
| 5154 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5155 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5156 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5157 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5158 | int rc = 0; |
| 5159 | int bytes_returned = 0; |
| 5160 | __u16 params, byte_count; |
| 5161 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5162 | cFYI(1, "In QFSUnixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5163 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5164 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5165 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5166 | if (rc) |
| 5167 | return rc; |
| 5168 | |
| 5169 | params = 2; /* level */ |
| 5170 | pSMB->TotalDataCount = 0; |
| 5171 | pSMB->DataCount = 0; |
| 5172 | pSMB->DataOffset = 0; |
| 5173 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5174 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5175 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5176 | pSMB->MaxSetupCount = 0; |
| 5177 | pSMB->Reserved = 0; |
| 5178 | pSMB->Flags = 0; |
| 5179 | pSMB->Timeout = 0; |
| 5180 | pSMB->Reserved2 = 0; |
| 5181 | byte_count = params + 1 /* pad */ ; |
| 5182 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5183 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5184 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5185 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 | pSMB->SetupCount = 1; |
| 5187 | pSMB->Reserved3 = 0; |
| 5188 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5189 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5190 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5191 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5192 | |
| 5193 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5194 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5195 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5196 | cERROR(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5197 | } else { /* decode response */ |
| 5198 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5199 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5200 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5201 | rc = -EIO; /* bad smb */ |
| 5202 | } else { |
| 5203 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5204 | response_data = |
| 5205 | (FILE_SYSTEM_UNIX_INFO |
| 5206 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5207 | data_offset); |
| 5208 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5209 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | } |
| 5211 | } |
| 5212 | cifs_buf_release(pSMB); |
| 5213 | |
| 5214 | if (rc == -EAGAIN) |
| 5215 | goto QFSUnixRetry; |
| 5216 | |
| 5217 | |
| 5218 | return rc; |
| 5219 | } |
| 5220 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5221 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5222 | CIFSSMBSetFSUnixInfo(const int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5223 | { |
| 5224 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5225 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5226 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5227 | int rc = 0; |
| 5228 | int bytes_returned = 0; |
| 5229 | __u16 params, param_offset, offset, byte_count; |
| 5230 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5231 | cFYI(1, "In SETFSUnixInfo"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5232 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5233 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5234 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5235 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5236 | if (rc) |
| 5237 | return rc; |
| 5238 | |
| 5239 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5240 | pSMB->MaxSetupCount = 0; |
| 5241 | pSMB->Reserved = 0; |
| 5242 | pSMB->Flags = 0; |
| 5243 | pSMB->Timeout = 0; |
| 5244 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5245 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5246 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5247 | offset = param_offset + params; |
| 5248 | |
| 5249 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5250 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5251 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5252 | pSMB->SetupCount = 1; |
| 5253 | pSMB->Reserved3 = 0; |
| 5254 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5255 | byte_count = 1 /* pad */ + params + 12; |
| 5256 | |
| 5257 | pSMB->DataCount = cpu_to_le16(12); |
| 5258 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5259 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5260 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5261 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5262 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5263 | |
| 5264 | /* Params. */ |
| 5265 | pSMB->FileNum = 0; |
| 5266 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5267 | |
| 5268 | /* Data. */ |
| 5269 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5270 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5271 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5272 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5273 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5274 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5275 | |
| 5276 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5277 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5278 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5279 | cERROR(1, "Send error in SETFSUnixInfo = %d", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5280 | } else { /* decode response */ |
| 5281 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5282 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5283 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5284 | } |
| 5285 | cifs_buf_release(pSMB); |
| 5286 | |
| 5287 | if (rc == -EAGAIN) |
| 5288 | goto SETFSUnixRetry; |
| 5289 | |
| 5290 | return rc; |
| 5291 | } |
| 5292 | |
| 5293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | |
| 5295 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5296 | CIFSSMBQFSPosixInfo(const int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5297 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | { |
| 5299 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5300 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5301 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5302 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5303 | int rc = 0; |
| 5304 | int bytes_returned = 0; |
| 5305 | __u16 params, byte_count; |
| 5306 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5307 | cFYI(1, "In QFSPosixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5308 | QFSPosixRetry: |
| 5309 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5310 | (void **) &pSMBr); |
| 5311 | if (rc) |
| 5312 | return rc; |
| 5313 | |
| 5314 | params = 2; /* level */ |
| 5315 | pSMB->TotalDataCount = 0; |
| 5316 | pSMB->DataCount = 0; |
| 5317 | pSMB->DataOffset = 0; |
| 5318 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5319 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5320 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | pSMB->MaxSetupCount = 0; |
| 5322 | pSMB->Reserved = 0; |
| 5323 | pSMB->Flags = 0; |
| 5324 | pSMB->Timeout = 0; |
| 5325 | pSMB->Reserved2 = 0; |
| 5326 | byte_count = params + 1 /* pad */ ; |
| 5327 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5328 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5329 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5330 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5331 | pSMB->SetupCount = 1; |
| 5332 | pSMB->Reserved3 = 0; |
| 5333 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5334 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5335 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5336 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5337 | |
| 5338 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5339 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5340 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5341 | cFYI(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | } else { /* decode response */ |
| 5343 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5344 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5345 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5346 | rc = -EIO; /* bad smb */ |
| 5347 | } else { |
| 5348 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5349 | response_data = |
| 5350 | (FILE_SYSTEM_POSIX_INFO |
| 5351 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5352 | data_offset); |
| 5353 | FSData->f_bsize = |
| 5354 | le32_to_cpu(response_data->BlockSize); |
| 5355 | FSData->f_blocks = |
| 5356 | le64_to_cpu(response_data->TotalBlocks); |
| 5357 | FSData->f_bfree = |
| 5358 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5359 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | FSData->f_bavail = FSData->f_bfree; |
| 5361 | } else { |
| 5362 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5363 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5364 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5365 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5366 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5367 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5368 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5370 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5371 | } |
| 5372 | } |
| 5373 | cifs_buf_release(pSMB); |
| 5374 | |
| 5375 | if (rc == -EAGAIN) |
| 5376 | goto QFSPosixRetry; |
| 5377 | |
| 5378 | return rc; |
| 5379 | } |
| 5380 | |
| 5381 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5382 | /* We can not use write of zero bytes trick to |
| 5383 | set file size due to need for large file support. Also note that |
| 5384 | this SetPathInfo is preferred to SetFileInfo based method in next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5385 | routine which is only needed to work around a sharing violation bug |
| 5386 | in Samba which this routine can run into */ |
| 5387 | |
| 5388 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5389 | CIFSSMBSetEOF(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5390 | __u64 size, bool SetAllocation, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5391 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5392 | { |
| 5393 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5394 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5395 | struct file_end_of_file_info *parm_data; |
| 5396 | int name_len; |
| 5397 | int rc = 0; |
| 5398 | int bytes_returned = 0; |
| 5399 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5400 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5401 | cFYI(1, "In SetEOF"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5402 | SetEOFRetry: |
| 5403 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5404 | (void **) &pSMBr); |
| 5405 | if (rc) |
| 5406 | return rc; |
| 5407 | |
| 5408 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5409 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5410 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5411 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | name_len++; /* trailing null */ |
| 5413 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5414 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5415 | name_len = strnlen(fileName, PATH_MAX); |
| 5416 | name_len++; /* trailing null */ |
| 5417 | strncpy(pSMB->FileName, fileName, name_len); |
| 5418 | } |
| 5419 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5420 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5422 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | pSMB->MaxSetupCount = 0; |
| 5424 | pSMB->Reserved = 0; |
| 5425 | pSMB->Flags = 0; |
| 5426 | pSMB->Timeout = 0; |
| 5427 | pSMB->Reserved2 = 0; |
| 5428 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5429 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5430 | offset = param_offset + params; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5431 | if (SetAllocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5432 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5433 | pSMB->InformationLevel = |
| 5434 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5435 | else |
| 5436 | pSMB->InformationLevel = |
| 5437 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5438 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5439 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5440 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5441 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5442 | else |
| 5443 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5444 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5445 | } |
| 5446 | |
| 5447 | parm_data = |
| 5448 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5449 | offset); |
| 5450 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5451 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5452 | pSMB->SetupCount = 1; |
| 5453 | pSMB->Reserved3 = 0; |
| 5454 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5455 | byte_count = 3 /* pad */ + params + data_count; |
| 5456 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5457 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5458 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5459 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5460 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5461 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5462 | parm_data->FileSize = cpu_to_le64(size); |
| 5463 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5464 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5465 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5466 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5467 | cFYI(1, "SetPathInfo (file size) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5468 | |
| 5469 | cifs_buf_release(pSMB); |
| 5470 | |
| 5471 | if (rc == -EAGAIN) |
| 5472 | goto SetEOFRetry; |
| 5473 | |
| 5474 | return rc; |
| 5475 | } |
| 5476 | |
| 5477 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5478 | CIFSSMBSetFileSize(const int xid, struct cifs_tcon *tcon, __u64 size, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5479 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | { |
| 5481 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5482 | struct file_end_of_file_info *parm_data; |
| 5483 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5484 | __u16 params, param_offset, offset, byte_count, count; |
| 5485 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5486 | cFYI(1, "SetFileSize (via SetFileInfo) %lld", |
| 5487 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5488 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | if (rc) |
| 5491 | return rc; |
| 5492 | |
| 5493 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5494 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | params = 6; |
| 5497 | pSMB->MaxSetupCount = 0; |
| 5498 | pSMB->Reserved = 0; |
| 5499 | pSMB->Flags = 0; |
| 5500 | pSMB->Timeout = 0; |
| 5501 | pSMB->Reserved2 = 0; |
| 5502 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5503 | offset = param_offset + params; |
| 5504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | count = sizeof(struct file_end_of_file_info); |
| 5506 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5507 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5508 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | pSMB->SetupCount = 1; |
| 5510 | pSMB->Reserved3 = 0; |
| 5511 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5512 | byte_count = 3 /* pad */ + params + count; |
| 5513 | pSMB->DataCount = cpu_to_le16(count); |
| 5514 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5515 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5516 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5517 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5518 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5519 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5520 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5522 | parm_data->FileSize = cpu_to_le64(size); |
| 5523 | pSMB->Fid = fid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5524 | if (SetAllocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5526 | pSMB->InformationLevel = |
| 5527 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5528 | else |
| 5529 | pSMB->InformationLevel = |
| 5530 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5531 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5533 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5534 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5535 | else |
| 5536 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5537 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | } |
| 5539 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5540 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5541 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5542 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5544 | cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5545 | } |
| 5546 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5547 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5548 | since file handle passed in no longer valid */ |
| 5549 | |
| 5550 | return rc; |
| 5551 | } |
| 5552 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5553 | /* 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] | 5554 | an open handle, rather than by pathname - this is awkward due to |
| 5555 | potential access conflicts on the open, but it is unavoidable for these |
| 5556 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5557 | time and resort to the original setpathinfo level which takes the ancient |
| 5558 | DOS time format with 2 second granularity */ |
| 5559 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5560 | CIFSSMBSetFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5561 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5562 | { |
| 5563 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | char *data_offset; |
| 5565 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | __u16 params, param_offset, offset, byte_count, count; |
| 5567 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5568 | cFYI(1, "Set Times (via SetFileInfo)"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5569 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | if (rc) |
| 5572 | return rc; |
| 5573 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5574 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5575 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5577 | params = 6; |
| 5578 | pSMB->MaxSetupCount = 0; |
| 5579 | pSMB->Reserved = 0; |
| 5580 | pSMB->Flags = 0; |
| 5581 | pSMB->Timeout = 0; |
| 5582 | pSMB->Reserved2 = 0; |
| 5583 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5584 | offset = param_offset + params; |
| 5585 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5586 | data_offset = (char *)pSMB + |
| 5587 | offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5588 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5589 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5591 | /* BB find max SMB PDU from sess */ |
| 5592 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5593 | pSMB->SetupCount = 1; |
| 5594 | pSMB->Reserved3 = 0; |
| 5595 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5596 | byte_count = 3 /* pad */ + params + count; |
| 5597 | pSMB->DataCount = cpu_to_le16(count); |
| 5598 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5599 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5600 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5601 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5602 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5603 | pSMB->Fid = fid; |
| 5604 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5605 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5606 | else |
| 5607 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5608 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5609 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5611 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5612 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5613 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5614 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5615 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5616 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | since file handle passed in no longer valid */ |
| 5618 | |
| 5619 | return rc; |
| 5620 | } |
| 5621 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5622 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5623 | CIFSSMBSetFileDisposition(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5624 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5625 | { |
| 5626 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5627 | char *data_offset; |
| 5628 | int rc = 0; |
| 5629 | __u16 params, param_offset, offset, byte_count, count; |
| 5630 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5631 | cFYI(1, "Set File Disposition (via SetFileInfo)"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5632 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5633 | |
| 5634 | if (rc) |
| 5635 | return rc; |
| 5636 | |
| 5637 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5638 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5639 | |
| 5640 | params = 6; |
| 5641 | pSMB->MaxSetupCount = 0; |
| 5642 | pSMB->Reserved = 0; |
| 5643 | pSMB->Flags = 0; |
| 5644 | pSMB->Timeout = 0; |
| 5645 | pSMB->Reserved2 = 0; |
| 5646 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5647 | offset = param_offset + params; |
| 5648 | |
| 5649 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5650 | |
| 5651 | count = 1; |
| 5652 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5653 | /* BB find max SMB PDU from sess */ |
| 5654 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5655 | pSMB->SetupCount = 1; |
| 5656 | pSMB->Reserved3 = 0; |
| 5657 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5658 | byte_count = 3 /* pad */ + params + count; |
| 5659 | pSMB->DataCount = cpu_to_le16(count); |
| 5660 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5661 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5662 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5663 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5664 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5665 | pSMB->Fid = fid; |
| 5666 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5667 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5668 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5669 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5670 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5671 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5672 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5673 | cFYI(1, "Send error in SetFileDisposition = %d", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5674 | |
| 5675 | return rc; |
| 5676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | |
| 5678 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5679 | CIFSSMBSetPathInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5680 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5681 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | { |
| 5683 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5684 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5685 | int name_len; |
| 5686 | int rc = 0; |
| 5687 | int bytes_returned = 0; |
| 5688 | char *data_offset; |
| 5689 | __u16 params, param_offset, offset, byte_count, count; |
| 5690 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5691 | cFYI(1, "In SetTimes"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | |
| 5693 | SetTimesRetry: |
| 5694 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5695 | (void **) &pSMBr); |
| 5696 | if (rc) |
| 5697 | return rc; |
| 5698 | |
| 5699 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5700 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5701 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5702 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | name_len++; /* trailing null */ |
| 5704 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5705 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5706 | name_len = strnlen(fileName, PATH_MAX); |
| 5707 | name_len++; /* trailing null */ |
| 5708 | strncpy(pSMB->FileName, fileName, name_len); |
| 5709 | } |
| 5710 | |
| 5711 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5712 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5714 | /* BB find max SMB PDU from sess structure BB */ |
| 5715 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | pSMB->MaxSetupCount = 0; |
| 5717 | pSMB->Reserved = 0; |
| 5718 | pSMB->Flags = 0; |
| 5719 | pSMB->Timeout = 0; |
| 5720 | pSMB->Reserved2 = 0; |
| 5721 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5722 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5723 | offset = param_offset + params; |
| 5724 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5725 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5726 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5727 | pSMB->SetupCount = 1; |
| 5728 | pSMB->Reserved3 = 0; |
| 5729 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5730 | byte_count = 3 /* pad */ + params + count; |
| 5731 | |
| 5732 | pSMB->DataCount = cpu_to_le16(count); |
| 5733 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5734 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5735 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5736 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5737 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5738 | else |
| 5739 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5740 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5741 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5742 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5743 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5744 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5745 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5746 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5747 | cFYI(1, "SetPathInfo (times) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5748 | |
| 5749 | cifs_buf_release(pSMB); |
| 5750 | |
| 5751 | if (rc == -EAGAIN) |
| 5752 | goto SetTimesRetry; |
| 5753 | |
| 5754 | return rc; |
| 5755 | } |
| 5756 | |
| 5757 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5758 | /* Can be used to set attributes */ |
| 5759 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5760 | handling it anyway and NT4 was what we thought it would be needed for |
| 5761 | Do not delete it until we prove whether needed for Win9x though */ |
| 5762 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5763 | CIFSSMBSetAttrLegacy(int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5765 | { |
| 5766 | SETATTR_REQ *pSMB = NULL; |
| 5767 | SETATTR_RSP *pSMBr = NULL; |
| 5768 | int rc = 0; |
| 5769 | int bytes_returned; |
| 5770 | int name_len; |
| 5771 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5772 | cFYI(1, "In SetAttrLegacy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5773 | |
| 5774 | SetAttrLgcyRetry: |
| 5775 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5776 | (void **) &pSMBr); |
| 5777 | if (rc) |
| 5778 | return rc; |
| 5779 | |
| 5780 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5781 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5782 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 5783 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | name_len++; /* trailing null */ |
| 5785 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5786 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5787 | name_len = strnlen(fileName, PATH_MAX); |
| 5788 | name_len++; /* trailing null */ |
| 5789 | strncpy(pSMB->fileName, fileName, name_len); |
| 5790 | } |
| 5791 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5792 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5793 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5795 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5796 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5797 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5798 | cFYI(1, "Error in LegacySetAttr = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5799 | |
| 5800 | cifs_buf_release(pSMB); |
| 5801 | |
| 5802 | if (rc == -EAGAIN) |
| 5803 | goto SetAttrLgcyRetry; |
| 5804 | |
| 5805 | return rc; |
| 5806 | } |
| 5807 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5808 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5809 | static void |
| 5810 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5811 | const struct cifs_unix_set_info_args *args) |
| 5812 | { |
| 5813 | u64 mode = args->mode; |
| 5814 | |
| 5815 | /* |
| 5816 | * Samba server ignores set of file size to zero due to bugs in some |
| 5817 | * older clients, but we should be precise - we use SetFileSize to |
| 5818 | * 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] | 5819 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5820 | * zero instead of -1 here |
| 5821 | */ |
| 5822 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5823 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5824 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5825 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5826 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
| 5827 | data_offset->Uid = cpu_to_le64(args->uid); |
| 5828 | data_offset->Gid = cpu_to_le64(args->gid); |
| 5829 | /* better to leave device as zero when it is */ |
| 5830 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5831 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5832 | data_offset->Permissions = cpu_to_le64(mode); |
| 5833 | |
| 5834 | if (S_ISREG(mode)) |
| 5835 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5836 | else if (S_ISDIR(mode)) |
| 5837 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 5838 | else if (S_ISLNK(mode)) |
| 5839 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 5840 | else if (S_ISCHR(mode)) |
| 5841 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 5842 | else if (S_ISBLK(mode)) |
| 5843 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 5844 | else if (S_ISFIFO(mode)) |
| 5845 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 5846 | else if (S_ISSOCK(mode)) |
| 5847 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5848 | } |
| 5849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5850 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5851 | CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5852 | const struct cifs_unix_set_info_args *args, |
| 5853 | u16 fid, u32 pid_of_opener) |
| 5854 | { |
| 5855 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5856 | char *data_offset; |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5857 | int rc = 0; |
| 5858 | u16 params, param_offset, offset, byte_count, count; |
| 5859 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5860 | cFYI(1, "Set Unix Info (via SetFileInfo)"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5861 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5862 | |
| 5863 | if (rc) |
| 5864 | return rc; |
| 5865 | |
| 5866 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5867 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5868 | |
| 5869 | params = 6; |
| 5870 | pSMB->MaxSetupCount = 0; |
| 5871 | pSMB->Reserved = 0; |
| 5872 | pSMB->Flags = 0; |
| 5873 | pSMB->Timeout = 0; |
| 5874 | pSMB->Reserved2 = 0; |
| 5875 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5876 | offset = param_offset + params; |
| 5877 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5878 | data_offset = (char *)pSMB + |
| 5879 | offsetof(struct smb_hdr, Protocol) + offset; |
| 5880 | |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5881 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 5882 | |
| 5883 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5884 | /* BB find max SMB PDU from sess */ |
| 5885 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5886 | pSMB->SetupCount = 1; |
| 5887 | pSMB->Reserved3 = 0; |
| 5888 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5889 | byte_count = 3 /* pad */ + params + count; |
| 5890 | pSMB->DataCount = cpu_to_le16(count); |
| 5891 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5892 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5893 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5894 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5895 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5896 | pSMB->Fid = fid; |
| 5897 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5898 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5899 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5900 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5901 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5902 | cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5903 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5904 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5905 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5906 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5907 | |
| 5908 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 5909 | since file handle passed in no longer valid */ |
| 5910 | |
| 5911 | return rc; |
| 5912 | } |
| 5913 | |
| 5914 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5915 | CIFSSMBUnixSetPathInfo(const int xid, struct cifs_tcon *tcon, char *fileName, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5916 | const struct cifs_unix_set_info_args *args, |
| 5917 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5918 | { |
| 5919 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5920 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5921 | int name_len; |
| 5922 | int rc = 0; |
| 5923 | int bytes_returned = 0; |
| 5924 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5925 | __u16 params, param_offset, offset, count, byte_count; |
| 5926 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5927 | cFYI(1, "In SetUID/GID/Mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5928 | setPermsRetry: |
| 5929 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5930 | (void **) &pSMBr); |
| 5931 | if (rc) |
| 5932 | return rc; |
| 5933 | |
| 5934 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5935 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5936 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5937 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5938 | name_len++; /* trailing null */ |
| 5939 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5940 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5941 | name_len = strnlen(fileName, PATH_MAX); |
| 5942 | name_len++; /* trailing null */ |
| 5943 | strncpy(pSMB->FileName, fileName, name_len); |
| 5944 | } |
| 5945 | |
| 5946 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5947 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5948 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5949 | /* BB find max SMB PDU from sess structure BB */ |
| 5950 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5951 | pSMB->MaxSetupCount = 0; |
| 5952 | pSMB->Reserved = 0; |
| 5953 | pSMB->Flags = 0; |
| 5954 | pSMB->Timeout = 0; |
| 5955 | pSMB->Reserved2 = 0; |
| 5956 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5957 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5958 | offset = param_offset + params; |
| 5959 | data_offset = |
| 5960 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 5961 | offset); |
| 5962 | memset(data_offset, 0, count); |
| 5963 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5964 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5965 | pSMB->SetupCount = 1; |
| 5966 | pSMB->Reserved3 = 0; |
| 5967 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5968 | byte_count = 3 /* pad */ + params + count; |
| 5969 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5970 | pSMB->DataCount = cpu_to_le16(count); |
| 5971 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5972 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5973 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5974 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5975 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5976 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5977 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5978 | |
| 5979 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5980 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5981 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5982 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5983 | cFYI(1, "SetPathInfo (perms) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5984 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5985 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5986 | if (rc == -EAGAIN) |
| 5987 | goto setPermsRetry; |
| 5988 | return rc; |
| 5989 | } |
| 5990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5991 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5992 | /* |
| 5993 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 5994 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 5995 | * it looks for that attribute name and stuffs that value into the EAData |
| 5996 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 5997 | * buffer. In both cases, the return value is either the length of the |
| 5998 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 5999 | * the data isn't copied to it, but the length is returned. |
| 6000 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6001 | ssize_t |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6002 | CIFSSMBQAllEAs(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6003 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6004 | char *EAData, size_t buf_size, |
| 6005 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6006 | { |
| 6007 | /* BB assumes one setup word */ |
| 6008 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6009 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 6010 | int rc = 0; |
| 6011 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6012 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6013 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6014 | struct fea *temp_fea; |
| 6015 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6016 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6017 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6018 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6019 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6020 | cFYI(1, "In Query All EAs path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6021 | QAllEAsRetry: |
| 6022 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6023 | (void **) &pSMBr); |
| 6024 | if (rc) |
| 6025 | return rc; |
| 6026 | |
| 6027 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6028 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6029 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6030 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6031 | list_len++; /* trailing null */ |
| 6032 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6033 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6034 | list_len = strnlen(searchName, PATH_MAX); |
| 6035 | list_len++; /* trailing null */ |
| 6036 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6037 | } |
| 6038 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6039 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6040 | pSMB->TotalDataCount = 0; |
| 6041 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6042 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6043 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6044 | pSMB->MaxSetupCount = 0; |
| 6045 | pSMB->Reserved = 0; |
| 6046 | pSMB->Flags = 0; |
| 6047 | pSMB->Timeout = 0; |
| 6048 | pSMB->Reserved2 = 0; |
| 6049 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6050 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6051 | pSMB->DataCount = 0; |
| 6052 | pSMB->DataOffset = 0; |
| 6053 | pSMB->SetupCount = 1; |
| 6054 | pSMB->Reserved3 = 0; |
| 6055 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6056 | byte_count = params + 1 /* pad */ ; |
| 6057 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6058 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6059 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6060 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6061 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6062 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6063 | |
| 6064 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6065 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6066 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6067 | cFYI(1, "Send error in QueryAllEAs = %d", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6068 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6069 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6070 | |
| 6071 | |
| 6072 | /* BB also check enough total bytes returned */ |
| 6073 | /* BB we need to improve the validity checking |
| 6074 | of these trans2 responses */ |
| 6075 | |
| 6076 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6077 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6078 | rc = -EIO; /* bad smb */ |
| 6079 | goto QAllEAsOut; |
| 6080 | } |
| 6081 | |
| 6082 | /* check that length of list is not more than bcc */ |
| 6083 | /* check that each entry does not go beyond length |
| 6084 | of list */ |
| 6085 | /* check that each element of each entry does not |
| 6086 | go beyond end of list */ |
| 6087 | /* validate_trans2_offsets() */ |
| 6088 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6089 | |
| 6090 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6091 | ea_response_data = (struct fealist *) |
| 6092 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6093 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6094 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6095 | cFYI(1, "ea length %d", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6096 | if (list_len <= 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6097 | cFYI(1, "empty EA list returned from server"); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6098 | goto QAllEAsOut; |
| 6099 | } |
| 6100 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6101 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6102 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6103 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6104 | cFYI(1, "EA list appears to go beyond SMB"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6105 | rc = -EIO; |
| 6106 | goto QAllEAsOut; |
| 6107 | } |
| 6108 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6109 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6110 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6111 | temp_fea = ea_response_data->list; |
| 6112 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6113 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6114 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6115 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6116 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6117 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6118 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6119 | /* make sure we can read name_len and value_len */ |
| 6120 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6121 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6122 | rc = -EIO; |
| 6123 | goto QAllEAsOut; |
| 6124 | } |
| 6125 | |
| 6126 | name_len = temp_fea->name_len; |
| 6127 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6128 | list_len -= name_len + 1 + value_len; |
| 6129 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6130 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6131 | rc = -EIO; |
| 6132 | goto QAllEAsOut; |
| 6133 | } |
| 6134 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6135 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6136 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6137 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6138 | temp_ptr += name_len + 1; |
| 6139 | rc = value_len; |
| 6140 | if (buf_size == 0) |
| 6141 | goto QAllEAsOut; |
| 6142 | if ((size_t)value_len > buf_size) { |
| 6143 | rc = -ERANGE; |
| 6144 | goto QAllEAsOut; |
| 6145 | } |
| 6146 | memcpy(EAData, temp_ptr, value_len); |
| 6147 | goto QAllEAsOut; |
| 6148 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6149 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6150 | /* account for prefix user. and trailing null */ |
| 6151 | rc += (5 + 1 + name_len); |
| 6152 | if (rc < (int) buf_size) { |
| 6153 | memcpy(EAData, "user.", 5); |
| 6154 | EAData += 5; |
| 6155 | memcpy(EAData, temp_ptr, name_len); |
| 6156 | EAData += name_len; |
| 6157 | /* null terminate name */ |
| 6158 | *EAData = 0; |
| 6159 | ++EAData; |
| 6160 | } else if (buf_size == 0) { |
| 6161 | /* skip copy - calc size only */ |
| 6162 | } else { |
| 6163 | /* stop before overrun buffer */ |
| 6164 | rc = -ERANGE; |
| 6165 | break; |
| 6166 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6167 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6168 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6169 | temp_fea = (struct fea *)temp_ptr; |
| 6170 | } |
| 6171 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6172 | /* didn't find the named attribute */ |
| 6173 | if (ea_name) |
| 6174 | rc = -ENODATA; |
| 6175 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6176 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6177 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6178 | if (rc == -EAGAIN) |
| 6179 | goto QAllEAsRetry; |
| 6180 | |
| 6181 | return (ssize_t)rc; |
| 6182 | } |
| 6183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6185 | CIFSSMBSetEA(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6186 | const char *ea_name, const void *ea_value, |
| 6187 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 6188 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6189 | { |
| 6190 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6191 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6192 | struct fealist *parm_data; |
| 6193 | int name_len; |
| 6194 | int rc = 0; |
| 6195 | int bytes_returned = 0; |
| 6196 | __u16 params, param_offset, byte_count, offset, count; |
| 6197 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6198 | cFYI(1, "In SetEA"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6199 | SetEARetry: |
| 6200 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6201 | (void **) &pSMBr); |
| 6202 | if (rc) |
| 6203 | return rc; |
| 6204 | |
| 6205 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6206 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6207 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6208 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6209 | name_len++; /* trailing null */ |
| 6210 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6211 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6212 | name_len = strnlen(fileName, PATH_MAX); |
| 6213 | name_len++; /* trailing null */ |
| 6214 | strncpy(pSMB->FileName, fileName, name_len); |
| 6215 | } |
| 6216 | |
| 6217 | params = 6 + name_len; |
| 6218 | |
| 6219 | /* done calculating parms using name_len of file name, |
| 6220 | now use name_len to calculate length of ea name |
| 6221 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6222 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6223 | name_len = 0; |
| 6224 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6225 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6227 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6229 | /* BB find max SMB PDU from sess */ |
| 6230 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6231 | pSMB->MaxSetupCount = 0; |
| 6232 | pSMB->Reserved = 0; |
| 6233 | pSMB->Flags = 0; |
| 6234 | pSMB->Timeout = 0; |
| 6235 | pSMB->Reserved2 = 0; |
| 6236 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6237 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6238 | offset = param_offset + params; |
| 6239 | pSMB->InformationLevel = |
| 6240 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6241 | |
| 6242 | parm_data = |
| 6243 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 6244 | offset); |
| 6245 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6246 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6247 | pSMB->SetupCount = 1; |
| 6248 | pSMB->Reserved3 = 0; |
| 6249 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6250 | byte_count = 3 /* pad */ + params + count; |
| 6251 | pSMB->DataCount = cpu_to_le16(count); |
| 6252 | parm_data->list_len = cpu_to_le32(count); |
| 6253 | parm_data->list[0].EA_flags = 0; |
| 6254 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6255 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6256 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6257 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6258 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6259 | parm_data->list[0].name[name_len] = 0; |
| 6260 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6261 | /* caller ensures that ea_value_len is less than 64K but |
| 6262 | we need to ensure that it fits within the smb */ |
| 6263 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6264 | /*BB add length check to see if it would fit in |
| 6265 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6266 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6267 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6268 | memcpy(parm_data->list[0].name+name_len+1, |
| 6269 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6270 | |
| 6271 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6272 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6273 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6274 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6275 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6276 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6277 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6278 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6279 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6280 | cFYI(1, "SetPathInfo (EA) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6281 | |
| 6282 | cifs_buf_release(pSMB); |
| 6283 | |
| 6284 | if (rc == -EAGAIN) |
| 6285 | goto SetEARetry; |
| 6286 | |
| 6287 | return rc; |
| 6288 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6290 | |
| 6291 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 6292 | /* |
| 6293 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 6294 | * to allow network clients (such as Windows) to display updated |
| 6295 | * lists of files in directory listings automatically when |
| 6296 | * files are added by one user when another user has the |
| 6297 | * same directory open on their desktop. The Linux cifs kernel |
| 6298 | * client hooked into the kernel side of this interface for |
| 6299 | * the same reason, but ironically when the VFS moved from |
| 6300 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 6301 | * network file system clients (the most obvious use case |
| 6302 | * for notify interfaces is when multiple users can update |
| 6303 | * the contents of the same directory - exactly what network |
| 6304 | * file systems can do) although the server (Samba) could |
| 6305 | * still use it. For the short term we leave the worker |
| 6306 | * function ifdeffed out (below) until inotify is fixed |
| 6307 | * in the VFS to make it easier to plug in network file |
| 6308 | * system clients. If inotify turns out to be permanently |
| 6309 | * incompatible for network fs clients, we could instead simply |
| 6310 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 6311 | */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6312 | int CIFSSMBNotify(const int xid, struct cifs_tcon *tcon, |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6313 | const int notify_subdirs, const __u16 netfid, |
| 6314 | __u32 filter, struct file *pfile, int multishot, |
| 6315 | const struct nls_table *nls_codepage) |
| 6316 | { |
| 6317 | int rc = 0; |
| 6318 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 6319 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 6320 | struct dir_notify_req *dnotify_req; |
| 6321 | int bytes_returned; |
| 6322 | |
| 6323 | cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid); |
| 6324 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 6325 | (void **) &pSMBr); |
| 6326 | if (rc) |
| 6327 | return rc; |
| 6328 | |
| 6329 | pSMB->TotalParameterCount = 0 ; |
| 6330 | pSMB->TotalDataCount = 0; |
| 6331 | pSMB->MaxParameterCount = cpu_to_le32(2); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6332 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6333 | pSMB->MaxSetupCount = 4; |
| 6334 | pSMB->Reserved = 0; |
| 6335 | pSMB->ParameterOffset = 0; |
| 6336 | pSMB->DataCount = 0; |
| 6337 | pSMB->DataOffset = 0; |
| 6338 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 6339 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 6340 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6341 | if (notify_subdirs) |
| 6342 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 6343 | pSMB->Reserved2 = 0; |
| 6344 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 6345 | pSMB->Fid = netfid; /* file handle always le */ |
| 6346 | pSMB->ByteCount = 0; |
| 6347 | |
| 6348 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6349 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 6350 | CIFS_ASYNC_OP); |
| 6351 | if (rc) { |
| 6352 | cFYI(1, "Error in Notify = %d", rc); |
| 6353 | } else { |
| 6354 | /* Add file to outstanding requests */ |
| 6355 | /* BB change to kmem cache alloc */ |
| 6356 | dnotify_req = kmalloc( |
| 6357 | sizeof(struct dir_notify_req), |
| 6358 | GFP_KERNEL); |
| 6359 | if (dnotify_req) { |
| 6360 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 6361 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 6362 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 6363 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 6364 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 6365 | dnotify_req->netfid = netfid; |
| 6366 | dnotify_req->pfile = pfile; |
| 6367 | dnotify_req->filter = filter; |
| 6368 | dnotify_req->multishot = multishot; |
| 6369 | spin_lock(&GlobalMid_Lock); |
| 6370 | list_add_tail(&dnotify_req->lhead, |
| 6371 | &GlobalDnotifyReqList); |
| 6372 | spin_unlock(&GlobalMid_Lock); |
| 6373 | } else |
| 6374 | rc = -ENOMEM; |
| 6375 | } |
| 6376 | cifs_buf_release(pSMB); |
| 6377 | return rc; |
| 6378 | } |
| 6379 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |