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 */ |
| 90 | static void cifs_readv_complete(struct work_struct *work); |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* Mark as invalid, all open files on tree connections since they |
| 93 | were closed when session to server was lost */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 94 | static void mark_open_files_invalid(struct cifs_tcon *pTcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 97 | struct list_head *tmp; |
| 98 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | /* list all files open on tree connection and mark them invalid */ |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 101 | spin_lock(&cifs_file_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | list_for_each_safe(tmp, tmp1, &pTcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 103 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 104 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 105 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 107 | spin_unlock(&cifs_file_list_lock); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 108 | /* BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 109 | to this tcon */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 112 | /* reconnect the socket, tcon, and smb session if needed */ |
| 113 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 114 | cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 115 | { |
Jeff Layton | c4a5534 | 2011-07-28 12:40:36 -0400 | [diff] [blame] | 116 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 117 | struct cifs_ses *ses; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 118 | struct TCP_Server_Info *server; |
| 119 | struct nls_table *nls_codepage; |
| 120 | |
| 121 | /* |
| 122 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 123 | * tcp and smb session status done differently for those three - in the |
| 124 | * calling routine |
| 125 | */ |
| 126 | if (!tcon) |
| 127 | return 0; |
| 128 | |
| 129 | ses = tcon->ses; |
| 130 | server = ses->server; |
| 131 | |
| 132 | /* |
| 133 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 134 | * have tcon) are allowed as we start force umount |
| 135 | */ |
| 136 | if (tcon->tidStatus == CifsExiting) { |
| 137 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 138 | smb_command != SMB_COM_OPEN_ANDX && |
| 139 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 140 | cFYI(1, "can not send cmd %d while umounting", |
| 141 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 142 | return -ENODEV; |
| 143 | } |
| 144 | } |
| 145 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 146 | /* |
| 147 | * Give demultiplex thread up to 10 seconds to reconnect, should be |
| 148 | * greater than cifs socket timeout which is 7 seconds |
| 149 | */ |
| 150 | while (server->tcpStatus == CifsNeedReconnect) { |
| 151 | wait_event_interruptible_timeout(server->response_q, |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 152 | (server->tcpStatus != CifsNeedReconnect), 10 * HZ); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 153 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 154 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 155 | if (server->tcpStatus != CifsNeedReconnect) |
| 156 | break; |
| 157 | |
| 158 | /* |
| 159 | * on "soft" mounts we wait once. Hard mounts keep |
| 160 | * retrying until process is killed or server comes |
| 161 | * back on-line |
| 162 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 163 | if (!tcon->retry) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 164 | cFYI(1, "gave up waiting on reconnect in smb_init"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 165 | return -EHOSTDOWN; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 170 | return 0; |
| 171 | |
| 172 | nls_codepage = load_nls_default(); |
| 173 | |
| 174 | /* |
| 175 | * need to prevent multiple threads trying to simultaneously |
| 176 | * reconnect the same SMB session |
| 177 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 178 | mutex_lock(&ses->session_mutex); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 179 | rc = cifs_negotiate_protocol(0, ses); |
| 180 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 181 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 182 | |
| 183 | /* do we need to reconnect tcon? */ |
| 184 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 185 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 186 | goto out; |
| 187 | } |
| 188 | |
| 189 | mark_open_files_invalid(tcon); |
| 190 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 191 | mutex_unlock(&ses->session_mutex); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 192 | cFYI(1, "reconnect tcon rc = %d", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 193 | |
| 194 | if (rc) |
| 195 | goto out; |
| 196 | |
| 197 | /* |
| 198 | * FIXME: check if wsize needs updated due to negotiated smb buffer |
| 199 | * size shrinking |
| 200 | */ |
| 201 | atomic_inc(&tconInfoReconnectCount); |
| 202 | |
| 203 | /* tell server Unix caps we support */ |
| 204 | if (ses->capabilities & CAP_UNIX) |
| 205 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 206 | |
| 207 | /* |
| 208 | * Removed call to reopen open files here. It is safer (and faster) to |
| 209 | * reopen files one at a time as needed in read and write. |
| 210 | * |
| 211 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 212 | */ |
| 213 | |
| 214 | out: |
| 215 | /* |
| 216 | * Check if handle based operation so we know whether we can continue |
| 217 | * or not without returning to caller to reset file handle |
| 218 | */ |
| 219 | switch (smb_command) { |
| 220 | case SMB_COM_READ_ANDX: |
| 221 | case SMB_COM_WRITE_ANDX: |
| 222 | case SMB_COM_CLOSE: |
| 223 | case SMB_COM_FIND_CLOSE2: |
| 224 | case SMB_COM_LOCKING_ANDX: |
| 225 | rc = -EAGAIN; |
| 226 | } |
| 227 | |
| 228 | unload_nls(nls_codepage); |
| 229 | return rc; |
| 230 | } |
| 231 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 232 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 233 | SMB information in the SMB header. If the return code is zero, this |
| 234 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 236 | small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 237 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 239 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 241 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 242 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | return rc; |
| 244 | |
| 245 | *request_buf = cifs_small_buf_get(); |
| 246 | if (*request_buf == NULL) { |
| 247 | /* BB should we add a retry in here if not a writepage? */ |
| 248 | return -ENOMEM; |
| 249 | } |
| 250 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 251 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 252 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 254 | if (tcon != NULL) |
| 255 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 256 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 257 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 260 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 261 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 262 | struct cifs_ses *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 263 | { |
| 264 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 265 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 266 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 267 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 268 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 269 | return rc; |
| 270 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 271 | buffer = (struct smb_hdr *)*request_buf; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 272 | buffer->Mid = GetNextMid(ses->server); |
| 273 | if (ses->capabilities & CAP_UNICODE) |
| 274 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 275 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 276 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 277 | |
| 278 | /* uid, tid can stay at zero as set in header assemble */ |
| 279 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 280 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 281 | this function is used after 1st of session setup requests */ |
| 282 | |
| 283 | return rc; |
| 284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 287 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 288 | __smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 289 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | *request_buf = cifs_buf_get(); |
| 292 | if (*request_buf == NULL) { |
| 293 | /* BB should we add a retry in here if not a writepage? */ |
| 294 | return -ENOMEM; |
| 295 | } |
| 296 | /* Although the original thought was we needed the response buf for */ |
| 297 | /* potential retries of smb operations it turns out we can determine */ |
| 298 | /* from the mid flags when the request buffer can be resent without */ |
| 299 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 300 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 301 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 304 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 306 | if (tcon != NULL) |
| 307 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 308 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 313 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 314 | smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 315 | void **request_buf, void **response_buf) |
| 316 | { |
| 317 | int rc; |
| 318 | |
| 319 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 320 | if (rc) |
| 321 | return rc; |
| 322 | |
| 323 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 324 | } |
| 325 | |
| 326 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 327 | 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] | 328 | void **request_buf, void **response_buf) |
| 329 | { |
| 330 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 331 | return -EHOSTDOWN; |
| 332 | |
| 333 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 336 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 338 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 340 | /* check for plausible wct */ |
| 341 | if (pSMB->hdr.WordCount < 10) |
| 342 | goto vt2_err; |
| 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 345 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 346 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 347 | goto vt2_err; |
| 348 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 349 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 350 | if (total_size >= 512) |
| 351 | goto vt2_err; |
| 352 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 353 | /* check that bcc is at least as big as parms + data, and that it is |
| 354 | * less than negotiated smb buffer |
| 355 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 356 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 357 | if (total_size > get_bcc(&pSMB->hdr) || |
| 358 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 359 | goto vt2_err; |
| 360 | |
| 361 | return 0; |
| 362 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 363 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 365 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 367 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 368 | static inline void inc_rfc1001_len(void *pSMB, int count) |
| 369 | { |
| 370 | struct smb_hdr *hdr = (struct smb_hdr *)pSMB; |
| 371 | |
| 372 | be32_add_cpu(&hdr->smb_buf_length, count); |
| 373 | } |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 376 | CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
| 378 | NEGOTIATE_REQ *pSMB; |
| 379 | NEGOTIATE_RSP *pSMBr; |
| 380 | int rc = 0; |
| 381 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 382 | int i; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 383 | struct TCP_Server_Info *server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | u16 count; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 385 | unsigned int secFlags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 387 | if (ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | server = ses->server; |
| 389 | else { |
| 390 | rc = -EIO; |
| 391 | return rc; |
| 392 | } |
| 393 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 394 | (void **) &pSMB, (void **) &pSMBr); |
| 395 | if (rc) |
| 396 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 397 | |
| 398 | /* 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] | 399 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 400 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 401 | 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] | 402 | secFlags = global_secflags | ses->overrideSecFlg; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 403 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 404 | cFYI(1, "secFlags 0x%x", secFlags); |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 405 | |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 406 | pSMB->hdr.Mid = GetNextMid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 407 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 408 | |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 409 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 410 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 411 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 412 | cFYI(1, "Kerberos only mechanism, enable extended security"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 413 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Jeff Layton | b4d6fcf | 2011-01-07 11:30:28 -0500 | [diff] [blame] | 414 | } else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 415 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 416 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 417 | cFYI(1, "NTLMSSP only mechanism, enable extended security"); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 418 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 419 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 420 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 421 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 422 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 423 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 424 | count += strlen(protocols[i].name) + 1; |
| 425 | /* null at end of source and target buffers anyway */ |
| 426 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 427 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | pSMB->ByteCount = cpu_to_le16(count); |
| 429 | |
| 430 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 431 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 432 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 433 | goto neg_err_exit; |
| 434 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 435 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
| 436 | cFYI(1, "Dialect: %d", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 437 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 438 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 439 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 440 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 441 | could not negotiate a common dialect */ |
| 442 | rc = -EOPNOTSUPP; |
| 443 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 444 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 445 | } else if ((pSMBr->hdr.WordCount == 13) |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 446 | && ((server->dialect == LANMAN_PROT) |
| 447 | || (server->dialect == LANMAN2_PROT))) { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 448 | __s16 tmp; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 449 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 450 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 451 | if ((secFlags & CIFSSEC_MAY_LANMAN) || |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 452 | (secFlags & CIFSSEC_MAY_PLNTXT)) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 453 | server->secType = LANMAN; |
| 454 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 455 | cERROR(1, "mount failed weak security disabled" |
| 456 | " in /proc/fs/cifs/SecurityFlags"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 457 | rc = -EOPNOTSUPP; |
| 458 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 459 | } |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 460 | server->sec_mode = (__u8)le16_to_cpu(rsp->SecurityMode); |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 461 | server->maxReq = min_t(unsigned int, |
| 462 | le16_to_cpu(rsp->MaxMpxCount), |
| 463 | cifs_max_pending); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 464 | cifs_set_credits(server, server->maxReq); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 465 | server->maxBuf = le16_to_cpu(rsp->MaxBufSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 466 | server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 467 | /* even though we do not use raw we might as well set this |
| 468 | accurately, in case we ever find a need for it */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 469 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 470 | server->max_rw = 0xFF00; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 471 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 472 | } else { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 473 | server->max_rw = 0;/* do not need to use raw anyway */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 474 | server->capabilities = CAP_MPX_MODE; |
| 475 | } |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 476 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
Steve French | 1a70d65 | 2006-10-02 05:59:18 +0000 | [diff] [blame] | 477 | if (tmp == -1) { |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 478 | /* OS/2 often does not set timezone therefore |
| 479 | * we must use server time to calc time zone. |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 480 | * Could deviate slightly from the right zone. |
| 481 | * Smallest defined timezone difference is 15 minutes |
| 482 | * (i.e. Nepal). Rounding up/down is done to match |
| 483 | * this requirement. |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 484 | */ |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 485 | int val, seconds, remain, result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 486 | struct timespec ts, utc; |
| 487 | utc = CURRENT_TIME; |
Jeff Layton | c4a2c08 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 488 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 489 | rsp->SrvTime.Time, 0); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 490 | cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d", |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 491 | (int)ts.tv_sec, (int)utc.tv_sec, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 492 | (int)(utc.tv_sec - ts.tv_sec)); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 493 | val = (int)(utc.tv_sec - ts.tv_sec); |
Andre Haupt | 8594c15 | 2007-08-30 20:18:41 +0000 | [diff] [blame] | 494 | seconds = abs(val); |
Steve French | 947a506 | 2006-10-02 05:55:25 +0000 | [diff] [blame] | 495 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 496 | remain = seconds % MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 497 | if (remain >= (MIN_TZ_ADJ / 2)) |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 498 | result += MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 499 | if (val < 0) |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 500 | result = -result; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 501 | server->timeAdj = result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 502 | } else { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 503 | server->timeAdj = (int)tmp; |
| 504 | server->timeAdj *= 60; /* also in seconds */ |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 505 | } |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 506 | cFYI(1, "server->timeAdj: %d seconds", server->timeAdj); |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 507 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 508 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 509 | /* BB get server time for time conversions and add |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 510 | code to use it and timezone since this is not UTC */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 511 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 512 | if (rsp->EncryptionKeyLength == |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 513 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 514 | memcpy(ses->server->cryptkey, rsp->EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 515 | CIFS_CRYPTO_KEY_SIZE); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 516 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 517 | rc = -EIO; /* need cryptkey unless plain text */ |
| 518 | goto neg_err_exit; |
| 519 | } |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 520 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 521 | cFYI(1, "LANMAN negotiated"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 522 | /* we will not end up setting signing flags - as no signing |
| 523 | was in LANMAN and server did not return the flags on */ |
| 524 | goto signing_check; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 525 | #else /* weak security disabled */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 526 | } else if (pSMBr->hdr.WordCount == 13) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 527 | cERROR(1, "mount failed, cifs module not built " |
| 528 | "with CIFS_WEAK_PW_HASH support"); |
Dan Carpenter | 8212cf7 | 2010-03-15 11:22:26 +0300 | [diff] [blame] | 529 | rc = -EOPNOTSUPP; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 530 | #endif /* WEAK_PW_HASH */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 531 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 532 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 533 | /* unknown wct */ |
| 534 | rc = -EOPNOTSUPP; |
| 535 | goto neg_err_exit; |
| 536 | } |
| 537 | /* else wct == 17 NTLM */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 538 | server->sec_mode = pSMBr->SecurityMode; |
| 539 | if ((server->sec_mode & SECMODE_USER) == 0) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 540 | cFYI(1, "share mode security"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 541 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 542 | if ((server->sec_mode & SECMODE_PW_ENCRYPT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 543 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 544 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 545 | #endif /* CIFS_WEAK_PW_HASH */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 546 | cERROR(1, "Server requests plain text password" |
| 547 | " but client support disabled"); |
Steve French | 9312f67 | 2006-06-04 22:21:07 +0000 | [diff] [blame] | 548 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 549 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 550 | server->secType = NTLMv2; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 551 | else if (secFlags & CIFSSEC_MAY_NTLM) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 552 | server->secType = NTLM; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 553 | else if (secFlags & CIFSSEC_MAY_NTLMV2) |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 554 | server->secType = NTLMv2; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 555 | else if (secFlags & CIFSSEC_MAY_KRB5) |
| 556 | server->secType = Kerberos; |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 557 | else if (secFlags & CIFSSEC_MAY_NTLMSSP) |
Steve French | f46c723 | 2009-06-25 03:04:20 +0000 | [diff] [blame] | 558 | server->secType = RawNTLMSSP; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 559 | else if (secFlags & CIFSSEC_MAY_LANMAN) |
| 560 | server->secType = LANMAN; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 561 | else { |
| 562 | rc = -EOPNOTSUPP; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 563 | cERROR(1, "Invalid security type"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 564 | goto neg_err_exit; |
| 565 | } |
| 566 | /* else ... any others ...? */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 567 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 568 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 569 | little endian */ |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 570 | server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), |
| 571 | cifs_max_pending); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 572 | cifs_set_credits(server, server->maxReq); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 573 | /* probably no need to store and check maxvcs */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 574 | server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 575 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 576 | cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 577 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 578 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 579 | server->timeAdj *= 60; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 580 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 581 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 582 | CIFS_CRYPTO_KEY_SIZE); |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 583 | } else if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC || |
| 584 | server->capabilities & CAP_EXTENDED_SECURITY) && |
| 585 | (pSMBr->EncryptionKeyLength == 0)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 586 | /* decode security blob */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 587 | count = get_bcc(&pSMBr->hdr); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 588 | if (count < 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | rc = -EIO; |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 590 | goto neg_err_exit; |
| 591 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 592 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 593 | if (server->srv_count > 1) { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 594 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 595 | if (memcmp(server->server_GUID, |
| 596 | pSMBr->u.extended_response. |
| 597 | GUID, 16) != 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 598 | cFYI(1, "server UID changed"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 599 | memcpy(server->server_GUID, |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 600 | pSMBr->u.extended_response.GUID, |
| 601 | 16); |
| 602 | } |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 603 | } else { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 604 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 605 | memcpy(server->server_GUID, |
| 606 | pSMBr->u.extended_response.GUID, 16); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 607 | } |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 608 | |
| 609 | if (count == 16) { |
| 610 | server->secType = RawNTLMSSP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 611 | } else { |
| 612 | rc = decode_negTokenInit(pSMBr->u.extended_response. |
Jeff Layton | 26efa0b | 2010-04-24 07:57:49 -0400 | [diff] [blame] | 613 | SecurityBlob, count - 16, |
| 614 | server); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 615 | if (rc == 1) |
Jeff Layton | e545937 | 2007-11-03 05:11:06 +0000 | [diff] [blame] | 616 | rc = 0; |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 617 | else |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 618 | rc = -EINVAL; |
Shirish Pargaonkar | 2b149f1 | 2010-09-18 22:02:18 -0500 | [diff] [blame] | 619 | if (server->secType == Kerberos) { |
| 620 | if (!server->sec_kerberos && |
| 621 | !server->sec_mskerberos) |
| 622 | rc = -EOPNOTSUPP; |
| 623 | } else if (server->secType == RawNTLMSSP) { |
| 624 | if (!server->sec_ntlmssp) |
| 625 | rc = -EOPNOTSUPP; |
| 626 | } else |
| 627 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 629 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 630 | rc = -EIO; /* no crypt key only if plain text pwd */ |
| 631 | goto neg_err_exit; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 632 | } else |
| 633 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
| 634 | |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 635 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 636 | signing_check: |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 637 | #endif |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 638 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
| 639 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
| 640 | so if this is zero it means that signing is disabled */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 641 | cFYI(1, "Signing disabled"); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 642 | if (server->sec_mode & SECMODE_SIGN_REQUIRED) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 643 | cERROR(1, "Server requires " |
Jeff Layton | 7111d21 | 2007-10-16 16:50:25 +0000 | [diff] [blame] | 644 | "packet signing to be enabled in " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 645 | "/proc/fs/cifs/SecurityFlags."); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 646 | rc = -EOPNOTSUPP; |
| 647 | } |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 648 | server->sec_mode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 649 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 650 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
| 651 | /* signing required */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 652 | cFYI(1, "Must sign - secFlags 0x%x", secFlags); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 653 | if ((server->sec_mode & |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 654 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 655 | cERROR(1, "signing required but server lacks support"); |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 656 | rc = -EOPNOTSUPP; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 657 | } else |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 658 | server->sec_mode |= SECMODE_SIGN_REQUIRED; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 659 | } else { |
| 660 | /* signing optional ie CIFSSEC_MAY_SIGN */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 661 | if ((server->sec_mode & SECMODE_SIGN_REQUIRED) == 0) |
| 662 | server->sec_mode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 663 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 665 | |
| 666 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 667 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 668 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 669 | cFYI(1, "negprot rc %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | return rc; |
| 671 | } |
| 672 | |
| 673 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 674 | CIFSSMBTDis(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
| 676 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 679 | cFYI(1, "In tree disconnect"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 680 | |
| 681 | /* BB: do we need to check this? These should never be NULL. */ |
| 682 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 683 | return -EIO; |
| 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 686 | * No need to return error on this operation if tid invalidated and |
| 687 | * closed on server already e.g. due to tcp session crashing. Also, |
| 688 | * the tcon is no longer on the list, so no need to take lock before |
| 689 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 691 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 692 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 694 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 695 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 696 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 698 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 699 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 701 | cFYI(1, "Tree disconnect failed %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 703 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 704 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | if (rc == -EAGAIN) |
| 706 | rc = 0; |
| 707 | |
| 708 | return rc; |
| 709 | } |
| 710 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 711 | /* |
| 712 | * This is a no-op for now. We're not really interested in the reply, but |
| 713 | * rather in the fact that the server sent one and that server->lstrp |
| 714 | * gets updated. |
| 715 | * |
| 716 | * FIXME: maybe we should consider checking that the reply matches request? |
| 717 | */ |
| 718 | static void |
| 719 | cifs_echo_callback(struct mid_q_entry *mid) |
| 720 | { |
| 721 | struct TCP_Server_Info *server = mid->callback_data; |
| 722 | |
| 723 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 724 | cifs_add_credits(server, 1); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | int |
| 728 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 729 | { |
| 730 | ECHO_REQ *smb; |
| 731 | int rc = 0; |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 732 | struct kvec iov; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 733 | |
| 734 | cFYI(1, "In echo request"); |
| 735 | |
| 736 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 737 | if (rc) |
| 738 | return rc; |
| 739 | |
| 740 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 741 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8 | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 742 | smb->hdr.WordCount = 1; |
| 743 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 744 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 745 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 746 | inc_rfc1001_len(smb, 3); |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 747 | iov.iov_base = smb; |
| 748 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 749 | |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 750 | rc = cifs_call_async(server, &iov, 1, NULL, cifs_echo_callback, |
| 751 | server, true); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 752 | if (rc) |
| 753 | cFYI(1, "Echo request failed: %d", rc); |
| 754 | |
| 755 | cifs_small_buf_release(smb); |
| 756 | |
| 757 | return rc; |
| 758 | } |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 761 | CIFSSMBLogoff(const int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | LOGOFF_ANDX_REQ *pSMB; |
| 764 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 766 | cFYI(1, "In SMBLogoff for session disconnect"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 767 | |
| 768 | /* |
| 769 | * BB: do we need to check validity of ses and server? They should |
| 770 | * always be valid since we have an active reference. If not, that |
| 771 | * should probably be a BUG() |
| 772 | */ |
| 773 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | return -EIO; |
| 775 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 776 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 777 | if (ses->need_reconnect) |
| 778 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 779 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 781 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 782 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | return rc; |
| 784 | } |
| 785 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 786 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 787 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 788 | if (ses->server->sec_mode & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 790 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
| 792 | pSMB->hdr.Uid = ses->Suid; |
| 793 | |
| 794 | pSMB->AndXCommand = 0xFF; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 795 | rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 796 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 797 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 800 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | error */ |
| 802 | if (rc == -EAGAIN) |
| 803 | rc = 0; |
| 804 | return rc; |
| 805 | } |
| 806 | |
| 807 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 808 | CIFSPOSIXDelFile(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 809 | __u16 type, const struct nls_table *nls_codepage, int remap) |
| 810 | { |
| 811 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 812 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 813 | struct unlink_psx_rq *pRqD; |
| 814 | int name_len; |
| 815 | int rc = 0; |
| 816 | int bytes_returned = 0; |
| 817 | __u16 params, param_offset, offset, byte_count; |
| 818 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 819 | cFYI(1, "In POSIX delete"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 820 | PsxDelete: |
| 821 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 822 | (void **) &pSMBr); |
| 823 | if (rc) |
| 824 | return rc; |
| 825 | |
| 826 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 827 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 828 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 829 | PATH_MAX, nls_codepage, remap); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 830 | name_len++; /* trailing null */ |
| 831 | name_len *= 2; |
| 832 | } else { /* BB add path length overrun check */ |
| 833 | name_len = strnlen(fileName, PATH_MAX); |
| 834 | name_len++; /* trailing null */ |
| 835 | strncpy(pSMB->FileName, fileName, name_len); |
| 836 | } |
| 837 | |
| 838 | params = 6 + name_len; |
| 839 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 840 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 841 | pSMB->MaxSetupCount = 0; |
| 842 | pSMB->Reserved = 0; |
| 843 | pSMB->Flags = 0; |
| 844 | pSMB->Timeout = 0; |
| 845 | pSMB->Reserved2 = 0; |
| 846 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 847 | InformationLevel) - 4; |
| 848 | offset = param_offset + params; |
| 849 | |
| 850 | /* Setup pointer to Request Data (inode type) */ |
| 851 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 852 | pRqD->type = cpu_to_le16(type); |
| 853 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 854 | pSMB->DataOffset = cpu_to_le16(offset); |
| 855 | pSMB->SetupCount = 1; |
| 856 | pSMB->Reserved3 = 0; |
| 857 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 858 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 859 | |
| 860 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 861 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 862 | pSMB->ParameterCount = cpu_to_le16(params); |
| 863 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 864 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 865 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 866 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 867 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 868 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 869 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 870 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 871 | cFYI(1, "Posix delete returned %d", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 872 | cifs_buf_release(pSMB); |
| 873 | |
| 874 | cifs_stats_inc(&tcon->num_deletes); |
| 875 | |
| 876 | if (rc == -EAGAIN) |
| 877 | goto PsxDelete; |
| 878 | |
| 879 | return rc; |
| 880 | } |
| 881 | |
| 882 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 883 | CIFSSMBDelFile(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 884 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | { |
| 886 | DELETE_FILE_REQ *pSMB = NULL; |
| 887 | DELETE_FILE_RSP *pSMBr = NULL; |
| 888 | int rc = 0; |
| 889 | int bytes_returned; |
| 890 | int name_len; |
| 891 | |
| 892 | DelFileRetry: |
| 893 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 894 | (void **) &pSMBr); |
| 895 | if (rc) |
| 896 | return rc; |
| 897 | |
| 898 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 899 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 900 | cifsConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 901 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | name_len++; /* trailing null */ |
| 903 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 904 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | name_len = strnlen(fileName, PATH_MAX); |
| 906 | name_len++; /* trailing null */ |
| 907 | strncpy(pSMB->fileName, fileName, name_len); |
| 908 | } |
| 909 | pSMB->SearchAttributes = |
| 910 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 911 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 912 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 914 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 915 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 916 | cifs_stats_inc(&tcon->num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 917 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 918 | cFYI(1, "Error in RMFile = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
| 920 | cifs_buf_release(pSMB); |
| 921 | if (rc == -EAGAIN) |
| 922 | goto DelFileRetry; |
| 923 | |
| 924 | return rc; |
| 925 | } |
| 926 | |
| 927 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 928 | CIFSSMBRmDir(const int xid, struct cifs_tcon *tcon, const char *dirName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 929 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | { |
| 931 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 932 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 933 | int rc = 0; |
| 934 | int bytes_returned; |
| 935 | int name_len; |
| 936 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 937 | cFYI(1, "In CIFSSMBRmDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | RmDirRetry: |
| 939 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 940 | (void **) &pSMBr); |
| 941 | if (rc) |
| 942 | return rc; |
| 943 | |
| 944 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 945 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, dirName, |
| 946 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | name_len++; /* trailing null */ |
| 948 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 949 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | name_len = strnlen(dirName, PATH_MAX); |
| 951 | name_len++; /* trailing null */ |
| 952 | strncpy(pSMB->DirName, dirName, name_len); |
| 953 | } |
| 954 | |
| 955 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 956 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 958 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 959 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 960 | cifs_stats_inc(&tcon->num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 961 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 962 | cFYI(1, "Error in RMDir = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
| 964 | cifs_buf_release(pSMB); |
| 965 | if (rc == -EAGAIN) |
| 966 | goto RmDirRetry; |
| 967 | return rc; |
| 968 | } |
| 969 | |
| 970 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 971 | CIFSSMBMkDir(const int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 972 | const char *name, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
| 974 | int rc = 0; |
| 975 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 976 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 977 | int bytes_returned; |
| 978 | int name_len; |
| 979 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 980 | cFYI(1, "In CIFSSMBMkDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | MkDirRetry: |
| 982 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 983 | (void **) &pSMBr); |
| 984 | if (rc) |
| 985 | return rc; |
| 986 | |
| 987 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 988 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
| 989 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | name_len++; /* trailing null */ |
| 991 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 992 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | name_len = strnlen(name, PATH_MAX); |
| 994 | name_len++; /* trailing null */ |
| 995 | strncpy(pSMB->DirName, name, name_len); |
| 996 | } |
| 997 | |
| 998 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 999 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1001 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1002 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1003 | cifs_stats_inc(&tcon->num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1004 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1005 | cFYI(1, "Error in Mkdir = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | cifs_buf_release(pSMB); |
| 1008 | if (rc == -EAGAIN) |
| 1009 | goto MkDirRetry; |
| 1010 | return rc; |
| 1011 | } |
| 1012 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1013 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1014 | CIFSPOSIXCreate(const int xid, struct cifs_tcon *tcon, __u32 posix_flags, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1015 | __u64 mode, __u16 *netfid, FILE_UNIX_BASIC_INFO *pRetData, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1016 | __u32 *pOplock, const char *name, |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1017 | const struct nls_table *nls_codepage, int remap) |
| 1018 | { |
| 1019 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1020 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1021 | int name_len; |
| 1022 | int rc = 0; |
| 1023 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1024 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1025 | OPEN_PSX_REQ *pdata; |
| 1026 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1027 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1028 | cFYI(1, "In POSIX Create"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1029 | PsxCreat: |
| 1030 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1031 | (void **) &pSMBr); |
| 1032 | if (rc) |
| 1033 | return rc; |
| 1034 | |
| 1035 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1036 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1037 | cifsConvertToUTF16((__le16 *) pSMB->FileName, name, |
| 1038 | PATH_MAX, nls_codepage, remap); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1039 | name_len++; /* trailing null */ |
| 1040 | name_len *= 2; |
| 1041 | } else { /* BB improve the check for buffer overruns BB */ |
| 1042 | name_len = strnlen(name, PATH_MAX); |
| 1043 | name_len++; /* trailing null */ |
| 1044 | strncpy(pSMB->FileName, name, name_len); |
| 1045 | } |
| 1046 | |
| 1047 | params = 6 + name_len; |
| 1048 | count = sizeof(OPEN_PSX_REQ); |
| 1049 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1050 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1051 | pSMB->MaxSetupCount = 0; |
| 1052 | pSMB->Reserved = 0; |
| 1053 | pSMB->Flags = 0; |
| 1054 | pSMB->Timeout = 0; |
| 1055 | pSMB->Reserved2 = 0; |
| 1056 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1057 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1058 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1059 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1060 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1061 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1062 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1063 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1064 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1065 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1066 | pSMB->SetupCount = 1; |
| 1067 | pSMB->Reserved3 = 0; |
| 1068 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1069 | byte_count = 3 /* pad */ + params + count; |
| 1070 | |
| 1071 | pSMB->DataCount = cpu_to_le16(count); |
| 1072 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1073 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1074 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1075 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1076 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1077 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1078 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1079 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1080 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1081 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1082 | cFYI(1, "Posix create returned %d", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1083 | goto psx_create_err; |
| 1084 | } |
| 1085 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1086 | cFYI(1, "copying inode info"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1087 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1088 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1089 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1090 | rc = -EIO; /* bad smb */ |
| 1091 | goto psx_create_err; |
| 1092 | } |
| 1093 | |
| 1094 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1095 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1096 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1097 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1098 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1099 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1100 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1101 | /* Let caller know file was created so we can set the mode. */ |
| 1102 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1103 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1104 | *pOplock |= CIFS_CREATE_ACTION; |
| 1105 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1106 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1107 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1108 | cFYI(DBG2, "unknown type"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1109 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1110 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1111 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1112 | cERROR(1, "Open response data too small"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1113 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1114 | goto psx_create_err; |
| 1115 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1116 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1117 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1118 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1119 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1120 | |
| 1121 | psx_create_err: |
| 1122 | cifs_buf_release(pSMB); |
| 1123 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1124 | if (posix_flags & SMB_O_DIRECTORY) |
| 1125 | cifs_stats_inc(&tcon->num_posixmkdirs); |
| 1126 | else |
| 1127 | cifs_stats_inc(&tcon->num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1128 | |
| 1129 | if (rc == -EAGAIN) |
| 1130 | goto PsxCreat; |
| 1131 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1132 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1135 | static __u16 convert_disposition(int disposition) |
| 1136 | { |
| 1137 | __u16 ofun = 0; |
| 1138 | |
| 1139 | switch (disposition) { |
| 1140 | case FILE_SUPERSEDE: |
| 1141 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1142 | break; |
| 1143 | case FILE_OPEN: |
| 1144 | ofun = SMBOPEN_OAPPEND; |
| 1145 | break; |
| 1146 | case FILE_CREATE: |
| 1147 | ofun = SMBOPEN_OCREATE; |
| 1148 | break; |
| 1149 | case FILE_OPEN_IF: |
| 1150 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1151 | break; |
| 1152 | case FILE_OVERWRITE: |
| 1153 | ofun = SMBOPEN_OTRUNC; |
| 1154 | break; |
| 1155 | case FILE_OVERWRITE_IF: |
| 1156 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1157 | break; |
| 1158 | default: |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1159 | cFYI(1, "unknown disposition %d", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1160 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1161 | } |
| 1162 | return ofun; |
| 1163 | } |
| 1164 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1165 | static int |
| 1166 | access_flags_to_smbopen_mode(const int access_flags) |
| 1167 | { |
| 1168 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1169 | |
| 1170 | if (masked_flags == GENERIC_READ) |
| 1171 | return SMBOPEN_READ; |
| 1172 | else if (masked_flags == GENERIC_WRITE) |
| 1173 | return SMBOPEN_WRITE; |
| 1174 | |
| 1175 | /* just go for read/write */ |
| 1176 | return SMBOPEN_READWRITE; |
| 1177 | } |
| 1178 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1179 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1180 | SMBLegacyOpen(const int xid, struct cifs_tcon *tcon, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1181 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1182 | const int access_flags, const int create_options, __u16 *netfid, |
| 1183 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1184 | const struct nls_table *nls_codepage, int remap) |
| 1185 | { |
| 1186 | int rc = -EACCES; |
| 1187 | OPENX_REQ *pSMB = NULL; |
| 1188 | OPENX_RSP *pSMBr = NULL; |
| 1189 | int bytes_returned; |
| 1190 | int name_len; |
| 1191 | __u16 count; |
| 1192 | |
| 1193 | OldOpenRetry: |
| 1194 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1195 | (void **) &pSMBr); |
| 1196 | if (rc) |
| 1197 | return rc; |
| 1198 | |
| 1199 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1200 | |
| 1201 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1202 | count = 1; /* account for one byte pad to word boundary */ |
| 1203 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1204 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1205 | fileName, PATH_MAX, nls_codepage, remap); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1206 | name_len++; /* trailing null */ |
| 1207 | name_len *= 2; |
| 1208 | } else { /* BB improve check for buffer overruns BB */ |
| 1209 | count = 0; /* no pad */ |
| 1210 | name_len = strnlen(fileName, PATH_MAX); |
| 1211 | name_len++; /* trailing null */ |
| 1212 | strncpy(pSMB->fileName, fileName, name_len); |
| 1213 | } |
| 1214 | if (*pOplock & REQ_OPLOCK) |
| 1215 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1216 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1217 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1218 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1219 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1220 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1221 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1222 | /* set file as system file if special file such |
| 1223 | as fifo and server expecting SFU style and |
| 1224 | no Unix extensions */ |
| 1225 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1226 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1227 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1228 | else /* BB FIXME BB */ |
| 1229 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1230 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1231 | if (create_options & CREATE_OPTION_READONLY) |
| 1232 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1233 | |
| 1234 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1235 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1236 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1237 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1238 | |
| 1239 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1240 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1241 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1242 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1243 | |
| 1244 | pSMB->ByteCount = cpu_to_le16(count); |
| 1245 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1246 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1247 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1248 | cifs_stats_inc(&tcon->num_opens); |
| 1249 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1250 | cFYI(1, "Error in Open = %d", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1251 | } else { |
| 1252 | /* BB verify if wct == 15 */ |
| 1253 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1254 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1255 | |
| 1256 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1257 | /* Let caller know file was created so we can set the mode. */ |
| 1258 | /* Do we care about the CreateAction in any other cases? */ |
| 1259 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1260 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1261 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1262 | /* BB FIXME END */ |
| 1263 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1264 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1265 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1266 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1267 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1268 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1269 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1270 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1271 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1272 | pfile_info->AllocationSize = |
| 1273 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1274 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1275 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1276 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | cifs_buf_release(pSMB); |
| 1281 | if (rc == -EAGAIN) |
| 1282 | goto OldOpenRetry; |
| 1283 | return rc; |
| 1284 | } |
| 1285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1287 | CIFSSMBOpen(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1289 | const int access_flags, const int create_options, __u16 *netfid, |
| 1290 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1291 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | { |
| 1293 | int rc = -EACCES; |
| 1294 | OPEN_REQ *pSMB = NULL; |
| 1295 | OPEN_RSP *pSMBr = NULL; |
| 1296 | int bytes_returned; |
| 1297 | int name_len; |
| 1298 | __u16 count; |
| 1299 | |
| 1300 | openRetry: |
| 1301 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, |
| 1302 | (void **) &pSMBr); |
| 1303 | if (rc) |
| 1304 | return rc; |
| 1305 | |
| 1306 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1307 | |
| 1308 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1309 | count = 1; /* account for one byte pad to word boundary */ |
| 1310 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1311 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1312 | fileName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | name_len++; /* trailing null */ |
| 1314 | name_len *= 2; |
| 1315 | pSMB->NameLength = cpu_to_le16(name_len); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1316 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | count = 0; /* no pad */ |
| 1318 | name_len = strnlen(fileName, PATH_MAX); |
| 1319 | name_len++; /* trailing null */ |
| 1320 | pSMB->NameLength = cpu_to_le16(name_len); |
| 1321 | strncpy(pSMB->fileName, fileName, name_len); |
| 1322 | } |
| 1323 | if (*pOplock & REQ_OPLOCK) |
| 1324 | pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1325 | else if (*pOplock & REQ_BATCHOPLOCK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | pSMB->DesiredAccess = cpu_to_le32(access_flags); |
| 1328 | pSMB->AllocationSize = 0; |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1329 | /* set file as system file if special file such |
| 1330 | as fifo and server expecting SFU style and |
| 1331 | no Unix extensions */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1332 | if (create_options & CREATE_OPTION_SPECIAL) |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1333 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1334 | else |
| 1335 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | /* XP does not handle ATTR_POSIX_SEMANTICS */ |
| 1338 | /* but it helps speed up case sensitive checks for other |
| 1339 | servers such as Samba */ |
| 1340 | if (tcon->ses->capabilities & CAP_UNIX) |
| 1341 | pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
| 1342 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1343 | if (create_options & CREATE_OPTION_READONLY) |
| 1344 | pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
| 1345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1347 | pSMB->CreateDisposition = cpu_to_le32(openDisposition); |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1348 | pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1349 | /* BB Expirement with various impersonation levels and verify */ |
| 1350 | pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | pSMB->SecurityFlags = |
| 1352 | SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY; |
| 1353 | |
| 1354 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1355 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
| 1357 | pSMB->ByteCount = cpu_to_le16(count); |
| 1358 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1359 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1360 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1361 | cifs_stats_inc(&tcon->num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1363 | cFYI(1, "Error in Open = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | } else { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1365 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1367 | /* Let caller know file was created so we can set the mode. */ |
| 1368 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1369 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1370 | *pOplock |= CIFS_CREATE_ACTION; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1371 | if (pfile_info) { |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1372 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
| 1373 | 36 /* CreationTime to Attributes */); |
| 1374 | /* the file_info buf is endian converted by caller */ |
| 1375 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
| 1376 | pfile_info->EndOfFile = pSMBr->EndOfFile; |
| 1377 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
| 1378 | pfile_info->DeletePending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | cifs_buf_release(pSMB); |
| 1383 | if (rc == -EAGAIN) |
| 1384 | goto openRetry; |
| 1385 | return rc; |
| 1386 | } |
| 1387 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1388 | struct cifs_readdata * |
| 1389 | cifs_readdata_alloc(unsigned int nr_pages) |
| 1390 | { |
| 1391 | struct cifs_readdata *rdata; |
| 1392 | |
| 1393 | /* readdata + 1 kvec for each page */ |
| 1394 | rdata = kzalloc(sizeof(*rdata) + |
| 1395 | sizeof(struct kvec) * nr_pages, GFP_KERNEL); |
| 1396 | if (rdata != NULL) { |
| 1397 | INIT_WORK(&rdata->work, cifs_readv_complete); |
| 1398 | INIT_LIST_HEAD(&rdata->pages); |
| 1399 | } |
| 1400 | return rdata; |
| 1401 | } |
| 1402 | |
| 1403 | void |
| 1404 | cifs_readdata_free(struct cifs_readdata *rdata) |
| 1405 | { |
| 1406 | cifsFileInfo_put(rdata->cfile); |
| 1407 | kfree(rdata); |
| 1408 | } |
| 1409 | |
| 1410 | /* |
| 1411 | * Discard any remaining data in the current SMB. To do this, we borrow the |
| 1412 | * current bigbuf. |
| 1413 | */ |
| 1414 | static int |
| 1415 | cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1416 | { |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1417 | unsigned int rfclen = get_rfc1002_length(server->smallbuf); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1418 | int remaining = rfclen + 4 - server->total_read; |
| 1419 | struct cifs_readdata *rdata = mid->callback_data; |
| 1420 | |
| 1421 | while (remaining > 0) { |
| 1422 | int length; |
| 1423 | |
| 1424 | length = cifs_read_from_socket(server, server->bigbuf, |
| 1425 | min_t(unsigned int, remaining, |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1426 | CIFSMaxBufSize + max_header_size())); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1427 | if (length < 0) |
| 1428 | return length; |
| 1429 | server->total_read += length; |
| 1430 | remaining -= length; |
| 1431 | } |
| 1432 | |
| 1433 | dequeue_mid(mid, rdata->result); |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1437 | static inline size_t |
| 1438 | read_rsp_size(void) |
| 1439 | { |
| 1440 | return sizeof(READ_RSP); |
| 1441 | } |
| 1442 | |
| 1443 | static inline unsigned int |
| 1444 | read_data_offset(char *buf) |
| 1445 | { |
| 1446 | READ_RSP *rsp = (READ_RSP *)buf; |
| 1447 | return le16_to_cpu(rsp->DataOffset); |
| 1448 | } |
| 1449 | |
| 1450 | static inline unsigned int |
| 1451 | read_data_length(char *buf) |
| 1452 | { |
| 1453 | READ_RSP *rsp = (READ_RSP *)buf; |
| 1454 | return (le16_to_cpu(rsp->DataLengthHigh) << 16) + |
| 1455 | le16_to_cpu(rsp->DataLength); |
| 1456 | } |
| 1457 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1458 | static int |
| 1459 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1460 | { |
| 1461 | int length, len; |
| 1462 | unsigned int data_offset, remaining, data_len; |
| 1463 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1464 | char *buf = server->smallbuf; |
| 1465 | unsigned int buflen = get_rfc1002_length(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1466 | u64 eof; |
| 1467 | pgoff_t eof_index; |
| 1468 | struct page *page, *tpage; |
| 1469 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1470 | cFYI(1, "%s: mid=%llu offset=%llu bytes=%u", __func__, |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1471 | mid->mid, rdata->offset, rdata->bytes); |
| 1472 | |
| 1473 | /* |
| 1474 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1475 | * can if there's not enough data. At this point, we've read down to |
| 1476 | * the Mid. |
| 1477 | */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1478 | len = min_t(unsigned int, buflen, read_rsp_size()) - header_size() + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1479 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1480 | rdata->iov[0].iov_base = buf + header_size() - 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1481 | rdata->iov[0].iov_len = len; |
| 1482 | |
| 1483 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); |
| 1484 | if (length < 0) |
| 1485 | return length; |
| 1486 | server->total_read += length; |
| 1487 | |
| 1488 | /* Was the SMB read successful? */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1489 | rdata->result = map_smb_to_linux_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1490 | if (rdata->result != 0) { |
| 1491 | cFYI(1, "%s: server returned error %d", __func__, |
| 1492 | rdata->result); |
| 1493 | return cifs_readv_discard(server, mid); |
| 1494 | } |
| 1495 | |
| 1496 | /* Is there enough to get to the rest of the READ_RSP header? */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1497 | if (server->total_read < read_rsp_size()) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1498 | cFYI(1, "%s: server returned short header. got=%u expected=%zu", |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1499 | __func__, server->total_read, read_rsp_size()); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1500 | rdata->result = -EIO; |
| 1501 | return cifs_readv_discard(server, mid); |
| 1502 | } |
| 1503 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1504 | data_offset = read_data_offset(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1505 | if (data_offset < server->total_read) { |
| 1506 | /* |
| 1507 | * win2k8 sometimes sends an offset of 0 when the read |
| 1508 | * is beyond the EOF. Treat it as if the data starts just after |
| 1509 | * the header. |
| 1510 | */ |
| 1511 | cFYI(1, "%s: data offset (%u) inside read response header", |
| 1512 | __func__, data_offset); |
| 1513 | data_offset = server->total_read; |
| 1514 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1515 | /* data_offset is beyond the end of smallbuf */ |
| 1516 | cFYI(1, "%s: data offset (%u) beyond end of smallbuf", |
| 1517 | __func__, data_offset); |
| 1518 | rdata->result = -EIO; |
| 1519 | return cifs_readv_discard(server, mid); |
| 1520 | } |
| 1521 | |
| 1522 | cFYI(1, "%s: total_read=%u data_offset=%u", __func__, |
| 1523 | server->total_read, data_offset); |
| 1524 | |
| 1525 | len = data_offset - server->total_read; |
| 1526 | if (len > 0) { |
| 1527 | /* read any junk before data into the rest of smallbuf */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1528 | rdata->iov[0].iov_base = buf + server->total_read; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1529 | rdata->iov[0].iov_len = len; |
| 1530 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); |
| 1531 | if (length < 0) |
| 1532 | return length; |
| 1533 | server->total_read += length; |
| 1534 | } |
| 1535 | |
| 1536 | /* set up first iov for signature check */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1537 | rdata->iov[0].iov_base = buf; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1538 | rdata->iov[0].iov_len = server->total_read; |
| 1539 | cFYI(1, "0: iov_base=%p iov_len=%zu", |
| 1540 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); |
| 1541 | |
| 1542 | /* how much data is in the response? */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1543 | data_len = read_data_length(buf); |
| 1544 | if (data_offset + data_len > buflen) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1545 | /* data_len is corrupt -- discard frame */ |
| 1546 | rdata->result = -EIO; |
| 1547 | return cifs_readv_discard(server, mid); |
| 1548 | } |
| 1549 | |
| 1550 | /* marshal up the page array */ |
| 1551 | len = 0; |
| 1552 | remaining = data_len; |
| 1553 | rdata->nr_iov = 1; |
| 1554 | |
| 1555 | /* determine the eof that the server (probably) has */ |
| 1556 | eof = CIFS_I(rdata->mapping->host)->server_eof; |
| 1557 | eof_index = eof ? (eof - 1) >> PAGE_CACHE_SHIFT : 0; |
| 1558 | cFYI(1, "eof=%llu eof_index=%lu", eof, eof_index); |
| 1559 | |
| 1560 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { |
| 1561 | if (remaining >= PAGE_CACHE_SIZE) { |
| 1562 | /* enough data to fill the page */ |
| 1563 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); |
| 1564 | rdata->iov[rdata->nr_iov].iov_len = PAGE_CACHE_SIZE; |
| 1565 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", |
| 1566 | rdata->nr_iov, page->index, |
| 1567 | rdata->iov[rdata->nr_iov].iov_base, |
| 1568 | rdata->iov[rdata->nr_iov].iov_len); |
| 1569 | ++rdata->nr_iov; |
| 1570 | len += PAGE_CACHE_SIZE; |
| 1571 | remaining -= PAGE_CACHE_SIZE; |
| 1572 | } else if (remaining > 0) { |
| 1573 | /* enough for partial page, fill and zero the rest */ |
| 1574 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); |
| 1575 | rdata->iov[rdata->nr_iov].iov_len = remaining; |
| 1576 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", |
| 1577 | rdata->nr_iov, page->index, |
| 1578 | rdata->iov[rdata->nr_iov].iov_base, |
| 1579 | rdata->iov[rdata->nr_iov].iov_len); |
| 1580 | memset(rdata->iov[rdata->nr_iov].iov_base + remaining, |
| 1581 | '\0', PAGE_CACHE_SIZE - remaining); |
| 1582 | ++rdata->nr_iov; |
| 1583 | len += remaining; |
| 1584 | remaining = 0; |
| 1585 | } else if (page->index > eof_index) { |
| 1586 | /* |
| 1587 | * The VFS will not try to do readahead past the |
| 1588 | * i_size, but it's possible that we have outstanding |
| 1589 | * writes with gaps in the middle and the i_size hasn't |
| 1590 | * caught up yet. Populate those with zeroed out pages |
| 1591 | * to prevent the VFS from repeatedly attempting to |
| 1592 | * fill them until the writes are flushed. |
| 1593 | */ |
| 1594 | zero_user(page, 0, PAGE_CACHE_SIZE); |
| 1595 | list_del(&page->lru); |
| 1596 | lru_cache_add_file(page); |
| 1597 | flush_dcache_page(page); |
| 1598 | SetPageUptodate(page); |
| 1599 | unlock_page(page); |
| 1600 | page_cache_release(page); |
| 1601 | } else { |
| 1602 | /* no need to hold page hostage */ |
| 1603 | list_del(&page->lru); |
| 1604 | lru_cache_add_file(page); |
| 1605 | unlock_page(page); |
| 1606 | page_cache_release(page); |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | /* issue the read if we have any iovecs left to fill */ |
| 1611 | if (rdata->nr_iov > 1) { |
| 1612 | length = cifs_readv_from_socket(server, &rdata->iov[1], |
| 1613 | rdata->nr_iov - 1, len); |
| 1614 | if (length < 0) |
| 1615 | return length; |
| 1616 | server->total_read += length; |
| 1617 | } else { |
| 1618 | length = 0; |
| 1619 | } |
| 1620 | |
| 1621 | rdata->bytes = length; |
| 1622 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1623 | cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read, |
| 1624 | buflen, remaining); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1625 | |
| 1626 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1627 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1628 | return cifs_readv_discard(server, mid); |
| 1629 | |
| 1630 | dequeue_mid(mid, false); |
| 1631 | return length; |
| 1632 | } |
| 1633 | |
| 1634 | static void |
| 1635 | cifs_readv_complete(struct work_struct *work) |
| 1636 | { |
| 1637 | struct cifs_readdata *rdata = container_of(work, |
| 1638 | struct cifs_readdata, work); |
| 1639 | struct page *page, *tpage; |
| 1640 | |
| 1641 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { |
| 1642 | list_del(&page->lru); |
| 1643 | lru_cache_add_file(page); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1644 | |
| 1645 | if (rdata->result == 0) { |
Pavel Shilovsky | a2d6b6c | 2011-10-21 10:14:04 +0400 | [diff] [blame] | 1646 | kunmap(page); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1647 | flush_dcache_page(page); |
| 1648 | SetPageUptodate(page); |
| 1649 | } |
| 1650 | |
| 1651 | unlock_page(page); |
| 1652 | |
| 1653 | if (rdata->result == 0) |
| 1654 | cifs_readpage_to_fscache(rdata->mapping->host, page); |
| 1655 | |
| 1656 | page_cache_release(page); |
| 1657 | } |
| 1658 | cifs_readdata_free(rdata); |
| 1659 | } |
| 1660 | |
| 1661 | static void |
| 1662 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1663 | { |
| 1664 | struct cifs_readdata *rdata = mid->callback_data; |
| 1665 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1666 | struct TCP_Server_Info *server = tcon->ses->server; |
| 1667 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1668 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, |
| 1669 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1670 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1671 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1672 | case MID_RESPONSE_RECEIVED: |
| 1673 | /* result already set, check signature */ |
| 1674 | if (server->sec_mode & |
| 1675 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
| 1676 | if (cifs_verify_signature(rdata->iov, rdata->nr_iov, |
| 1677 | server, mid->sequence_number + 1)) |
| 1678 | cERROR(1, "Unexpected SMB signature"); |
| 1679 | } |
| 1680 | /* FIXME: should this be counted toward the initiating task? */ |
| 1681 | task_io_account_read(rdata->bytes); |
| 1682 | cifs_stats_bytes_read(tcon, rdata->bytes); |
| 1683 | break; |
| 1684 | case MID_REQUEST_SUBMITTED: |
| 1685 | case MID_RETRY_NEEDED: |
| 1686 | rdata->result = -EAGAIN; |
| 1687 | break; |
| 1688 | default: |
| 1689 | rdata->result = -EIO; |
| 1690 | } |
| 1691 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1692 | queue_work(cifsiod_wq, &rdata->work); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1693 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 1694 | cifs_add_credits(server, 1); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1698 | int |
| 1699 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1700 | { |
| 1701 | int rc; |
| 1702 | READ_REQ *smb = NULL; |
| 1703 | int wct; |
| 1704 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1705 | |
| 1706 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, |
| 1707 | rdata->offset, rdata->bytes); |
| 1708 | |
| 1709 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1710 | wct = 12; |
| 1711 | else { |
| 1712 | wct = 10; /* old style read */ |
| 1713 | if ((rdata->offset >> 32) > 0) { |
| 1714 | /* can not handle this big offset for old */ |
| 1715 | return -EIO; |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1720 | if (rc) |
| 1721 | return rc; |
| 1722 | |
| 1723 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1724 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1725 | |
| 1726 | smb->AndXCommand = 0xFF; /* none */ |
| 1727 | smb->Fid = rdata->cfile->netfid; |
| 1728 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1729 | if (wct == 12) |
| 1730 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1731 | smb->Remaining = 0; |
| 1732 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1733 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1734 | if (wct == 12) |
| 1735 | smb->ByteCount = 0; |
| 1736 | else { |
| 1737 | /* old style read */ |
| 1738 | struct smb_com_readx_req *smbr = |
| 1739 | (struct smb_com_readx_req *)smb; |
| 1740 | smbr->ByteCount = 0; |
| 1741 | } |
| 1742 | |
| 1743 | /* 4 for RFC1001 length + 1 for BCC */ |
| 1744 | rdata->iov[0].iov_base = smb; |
| 1745 | rdata->iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
| 1746 | |
| 1747 | rc = cifs_call_async(tcon->ses->server, rdata->iov, 1, |
| 1748 | cifs_readv_receive, cifs_readv_callback, |
| 1749 | rdata, false); |
| 1750 | |
| 1751 | if (rc == 0) |
| 1752 | cifs_stats_inc(&tcon->num_reads); |
| 1753 | |
| 1754 | cifs_small_buf_release(smb); |
| 1755 | return rc; |
| 1756 | } |
| 1757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | int |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1759 | 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] | 1760 | char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | { |
| 1762 | int rc = -EACCES; |
| 1763 | READ_REQ *pSMB = NULL; |
| 1764 | READ_RSP *pSMBr = NULL; |
| 1765 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1766 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1767 | int resp_buf_type = 0; |
| 1768 | struct kvec iov[1]; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1769 | __u32 pid = io_parms->pid; |
| 1770 | __u16 netfid = io_parms->netfid; |
| 1771 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1772 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1773 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1775 | cFYI(1, "Reading %d bytes on fid %d", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1776 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1777 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1778 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1779 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1780 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1781 | /* can not handle this big offset for old */ |
| 1782 | return -EIO; |
| 1783 | } |
| 1784 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | |
| 1786 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1787 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | if (rc) |
| 1789 | return rc; |
| 1790 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1791 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1792 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | /* tcon and ses pointer are checked in smb_init */ |
| 1795 | if (tcon->ses->server == NULL) |
| 1796 | return -ECONNABORTED; |
| 1797 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1798 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1800 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1801 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1802 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | pSMB->Remaining = 0; |
| 1805 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1806 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1807 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1808 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1809 | else { |
| 1810 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1811 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1812 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1813 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1814 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1815 | |
| 1816 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1817 | 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] | 1818 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1819 | &resp_buf_type, CIFS_LOG_ERROR); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1820 | cifs_stats_inc(&tcon->num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1821 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1823 | cERROR(1, "Send error in read = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | } else { |
| 1825 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1826 | data_length = data_length << 16; |
| 1827 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1828 | *nbytes = data_length; |
| 1829 | |
| 1830 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1831 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | || (data_length > count)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1833 | cFYI(1, "bad length %d for count %d", |
| 1834 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | rc = -EIO; |
| 1836 | *nbytes = 0; |
| 1837 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1838 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1839 | le16_to_cpu(pSMBr->DataOffset); |
| 1840 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1841 | cERROR(1, "Faulting on read rc = %d",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1842 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1843 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1844 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1845 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | } |
| 1847 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1849 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1850 | if (*buf) { |
| 1851 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1852 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1853 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1854 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1855 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1856 | /* return buffer to caller to free */ |
| 1857 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1858 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1859 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1860 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1861 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1862 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1863 | |
| 1864 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | since file handle passed in no longer valid */ |
| 1866 | return rc; |
| 1867 | } |
| 1868 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1871 | CIFSSMBWrite(const int xid, struct cifs_io_parms *io_parms, |
| 1872 | unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1873 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | { |
| 1875 | int rc = -EACCES; |
| 1876 | WRITE_REQ *pSMB = NULL; |
| 1877 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1878 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | __u32 bytes_sent; |
| 1880 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1881 | __u32 pid = io_parms->pid; |
| 1882 | __u16 netfid = io_parms->netfid; |
| 1883 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1884 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1885 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1887 | *nbytes = 0; |
| 1888 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1889 | /* cFYI(1, "write at %lld %d bytes", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1890 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1891 | return -ECONNABORTED; |
| 1892 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1893 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1894 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1895 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1896 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1897 | if ((offset >> 32) > 0) { |
| 1898 | /* can not handle big offset for old srv */ |
| 1899 | return -EIO; |
| 1900 | } |
| 1901 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1902 | |
| 1903 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | (void **) &pSMBr); |
| 1905 | if (rc) |
| 1906 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1907 | |
| 1908 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1909 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | /* tcon and ses pointer are checked in smb_init */ |
| 1912 | if (tcon->ses->server == NULL) |
| 1913 | return -ECONNABORTED; |
| 1914 | |
| 1915 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1916 | pSMB->Fid = netfid; |
| 1917 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1918 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1919 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | pSMB->Reserved = 0xFFFFFFFF; |
| 1922 | pSMB->WriteMode = 0; |
| 1923 | pSMB->Remaining = 0; |
| 1924 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1925 | /* 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] | 1926 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1927 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1928 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1929 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1931 | } else { |
| 1932 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1933 | & ~0xFF; |
| 1934 | } |
| 1935 | |
| 1936 | if (bytes_sent > count) |
| 1937 | bytes_sent = count; |
| 1938 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1939 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1940 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1941 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1942 | else if (ubuf) { |
| 1943 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | cifs_buf_release(pSMB); |
| 1945 | return -EFAULT; |
| 1946 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1947 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | /* No buffer */ |
| 1949 | cifs_buf_release(pSMB); |
| 1950 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1951 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1952 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1953 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1954 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1955 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1956 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1958 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1959 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1960 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1961 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1962 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1963 | else { /* old style write has byte count 4 bytes earlier |
| 1964 | so 4 bytes pad */ |
| 1965 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1966 | (struct smb_com_writex_req *)pSMB; |
| 1967 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | |
| 1970 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1971 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1972 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 1974 | cFYI(1, "Send error in write = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | } else { |
| 1976 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1977 | *nbytes = (*nbytes) << 16; |
| 1978 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1979 | |
| 1980 | /* |
| 1981 | * Mask off high 16 bits when bytes written as returned by the |
| 1982 | * server is greater than bytes requested by the client. Some |
| 1983 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1984 | */ |
| 1985 | if (*nbytes > count) |
| 1986 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | cifs_buf_release(pSMB); |
| 1990 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1991 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | since file handle passed in no longer valid */ |
| 1993 | |
| 1994 | return rc; |
| 1995 | } |
| 1996 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1997 | void |
| 1998 | cifs_writedata_release(struct kref *refcount) |
| 1999 | { |
| 2000 | struct cifs_writedata *wdata = container_of(refcount, |
| 2001 | struct cifs_writedata, refcount); |
| 2002 | |
| 2003 | if (wdata->cfile) |
| 2004 | cifsFileInfo_put(wdata->cfile); |
| 2005 | |
| 2006 | kfree(wdata); |
| 2007 | } |
| 2008 | |
| 2009 | /* |
| 2010 | * Write failed with a retryable error. Resend the write request. It's also |
| 2011 | * possible that the page was redirtied so re-clean the page. |
| 2012 | */ |
| 2013 | static void |
| 2014 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 2015 | { |
| 2016 | int i, rc; |
| 2017 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 2018 | |
| 2019 | for (i = 0; i < wdata->nr_pages; i++) { |
| 2020 | lock_page(wdata->pages[i]); |
| 2021 | clear_page_dirty_for_io(wdata->pages[i]); |
| 2022 | } |
| 2023 | |
| 2024 | do { |
| 2025 | rc = cifs_async_writev(wdata); |
| 2026 | } while (rc == -EAGAIN); |
| 2027 | |
| 2028 | for (i = 0; i < wdata->nr_pages; i++) { |
| 2029 | if (rc != 0) |
| 2030 | SetPageError(wdata->pages[i]); |
| 2031 | unlock_page(wdata->pages[i]); |
| 2032 | } |
| 2033 | |
| 2034 | mapping_set_error(inode->i_mapping, rc); |
| 2035 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2036 | } |
| 2037 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2038 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2039 | cifs_writev_complete(struct work_struct *work) |
| 2040 | { |
| 2041 | struct cifs_writedata *wdata = container_of(work, |
| 2042 | struct cifs_writedata, work); |
| 2043 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 2044 | int i = 0; |
| 2045 | |
| 2046 | if (wdata->result == 0) { |
| 2047 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
| 2048 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 2049 | wdata->bytes); |
| 2050 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 2051 | return cifs_writev_requeue(wdata); |
| 2052 | |
| 2053 | for (i = 0; i < wdata->nr_pages; i++) { |
| 2054 | struct page *page = wdata->pages[i]; |
| 2055 | if (wdata->result == -EAGAIN) |
| 2056 | __set_page_dirty_nobuffers(page); |
| 2057 | else if (wdata->result < 0) |
| 2058 | SetPageError(page); |
| 2059 | end_page_writeback(page); |
| 2060 | page_cache_release(page); |
| 2061 | } |
| 2062 | if (wdata->result != -EAGAIN) |
| 2063 | mapping_set_error(inode->i_mapping, wdata->result); |
| 2064 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2065 | } |
| 2066 | |
| 2067 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2068 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2069 | { |
| 2070 | struct cifs_writedata *wdata; |
| 2071 | |
| 2072 | /* this would overflow */ |
| 2073 | if (nr_pages == 0) { |
| 2074 | cERROR(1, "%s: called with nr_pages == 0!", __func__); |
| 2075 | return NULL; |
| 2076 | } |
| 2077 | |
| 2078 | /* writedata + number of page pointers */ |
| 2079 | wdata = kzalloc(sizeof(*wdata) + |
| 2080 | sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); |
| 2081 | if (wdata != NULL) { |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2082 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2083 | kref_init(&wdata->refcount); |
| 2084 | } |
| 2085 | return wdata; |
| 2086 | } |
| 2087 | |
| 2088 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2089 | * 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] | 2090 | * workqueue completion task. |
| 2091 | */ |
| 2092 | static void |
| 2093 | cifs_writev_callback(struct mid_q_entry *mid) |
| 2094 | { |
| 2095 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2096 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2097 | unsigned int written; |
| 2098 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
| 2099 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2100 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2101 | case MID_RESPONSE_RECEIVED: |
| 2102 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 2103 | if (wdata->result != 0) |
| 2104 | break; |
| 2105 | |
| 2106 | written = le16_to_cpu(smb->CountHigh); |
| 2107 | written <<= 16; |
| 2108 | written += le16_to_cpu(smb->Count); |
| 2109 | /* |
| 2110 | * Mask off high 16 bits when bytes written as returned |
| 2111 | * by the server is greater than bytes requested by the |
| 2112 | * client. OS/2 servers are known to set incorrect |
| 2113 | * CountHigh values. |
| 2114 | */ |
| 2115 | if (written > wdata->bytes) |
| 2116 | written &= 0xFFFF; |
| 2117 | |
| 2118 | if (written < wdata->bytes) |
| 2119 | wdata->result = -ENOSPC; |
| 2120 | else |
| 2121 | wdata->bytes = written; |
| 2122 | break; |
| 2123 | case MID_REQUEST_SUBMITTED: |
| 2124 | case MID_RETRY_NEEDED: |
| 2125 | wdata->result = -EAGAIN; |
| 2126 | break; |
| 2127 | default: |
| 2128 | wdata->result = -EIO; |
| 2129 | break; |
| 2130 | } |
| 2131 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2132 | queue_work(cifsiod_wq, &wdata->work); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2133 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 2134 | cifs_add_credits(tcon->ses->server, 1); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2138 | int |
| 2139 | cifs_async_writev(struct cifs_writedata *wdata) |
| 2140 | { |
| 2141 | int i, rc = -EACCES; |
| 2142 | WRITE_REQ *smb = NULL; |
| 2143 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2144 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2145 | struct kvec *iov = NULL; |
| 2146 | |
| 2147 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2148 | wct = 14; |
| 2149 | } else { |
| 2150 | wct = 12; |
| 2151 | if (wdata->offset >> 32 > 0) { |
| 2152 | /* can not handle big offset for old srv */ |
| 2153 | return -EIO; |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2158 | if (rc) |
| 2159 | goto async_writev_out; |
| 2160 | |
| 2161 | /* 1 iov per page + 1 for header */ |
| 2162 | iov = kzalloc((wdata->nr_pages + 1) * sizeof(*iov), GFP_NOFS); |
| 2163 | if (iov == NULL) { |
| 2164 | rc = -ENOMEM; |
| 2165 | goto async_writev_out; |
| 2166 | } |
| 2167 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2168 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2169 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2170 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2171 | smb->AndXCommand = 0xFF; /* none */ |
| 2172 | smb->Fid = wdata->cfile->netfid; |
| 2173 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2174 | if (wct == 14) |
| 2175 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2176 | smb->Reserved = 0xFFFFFFFF; |
| 2177 | smb->WriteMode = 0; |
| 2178 | smb->Remaining = 0; |
| 2179 | |
| 2180 | smb->DataOffset = |
| 2181 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2182 | |
| 2183 | /* 4 for RFC1001 length + 1 for BCC */ |
| 2184 | iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; |
| 2185 | iov[0].iov_base = smb; |
| 2186 | |
Jeff Layton | e949287 | 2012-03-23 14:40:56 -0400 | [diff] [blame^] | 2187 | /* |
| 2188 | * This function should marshal up the page array into the kvec |
| 2189 | * array, reserving [0] for the header. It should kmap the pages |
| 2190 | * and set the iov_len properly for each one. It may also set |
| 2191 | * wdata->bytes too. |
| 2192 | */ |
| 2193 | wdata->marshal_iov(iov, wdata); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2194 | |
| 2195 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); |
| 2196 | |
| 2197 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2198 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2199 | |
| 2200 | if (wct == 14) { |
| 2201 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2202 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2203 | } else { |
| 2204 | /* wct == 12 */ |
| 2205 | struct smb_com_writex_req *smbw = |
| 2206 | (struct smb_com_writex_req *)smb; |
| 2207 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2208 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
| 2209 | iov[0].iov_len += 4; /* pad bigger by four bytes */ |
| 2210 | } |
| 2211 | |
| 2212 | kref_get(&wdata->refcount); |
| 2213 | rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1, |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 2214 | NULL, cifs_writev_callback, wdata, false); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2215 | |
| 2216 | if (rc == 0) |
| 2217 | cifs_stats_inc(&tcon->num_writes); |
| 2218 | else |
| 2219 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2220 | |
| 2221 | /* send is done, unmap pages */ |
| 2222 | for (i = 0; i < wdata->nr_pages; i++) |
| 2223 | kunmap(wdata->pages[i]); |
| 2224 | |
| 2225 | async_writev_out: |
| 2226 | cifs_small_buf_release(smb); |
| 2227 | kfree(iov); |
| 2228 | return rc; |
| 2229 | } |
| 2230 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2231 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2232 | CIFSSMBWrite2(const int xid, struct cifs_io_parms *io_parms, |
| 2233 | unsigned int *nbytes, struct kvec *iov, int n_vec, |
| 2234 | const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | { |
| 2236 | int rc = -EACCES; |
| 2237 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2238 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2239 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2240 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2241 | __u32 pid = io_parms->pid; |
| 2242 | __u16 netfid = io_parms->netfid; |
| 2243 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2244 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2245 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2247 | *nbytes = 0; |
| 2248 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2249 | cFYI(1, "write2 at %lld %d bytes", (long long)offset, count); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2250 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2251 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2252 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2253 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2254 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2255 | if ((offset >> 32) > 0) { |
| 2256 | /* can not handle big offset for old srv */ |
| 2257 | return -EIO; |
| 2258 | } |
| 2259 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2260 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | if (rc) |
| 2262 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2263 | |
| 2264 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2265 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | /* tcon and ses pointer are checked in smb_init */ |
| 2268 | if (tcon->ses->server == NULL) |
| 2269 | return -ECONNABORTED; |
| 2270 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2271 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | pSMB->Fid = netfid; |
| 2273 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2274 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2275 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | pSMB->Reserved = 0xFFFFFFFF; |
| 2277 | pSMB->WriteMode = 0; |
| 2278 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2281 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2283 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2284 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2285 | /* header + 1 byte pad */ |
| 2286 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2287 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2288 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2289 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2290 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2291 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2292 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2293 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2294 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2295 | (struct smb_com_writex_req *)pSMB; |
| 2296 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2297 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2298 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2299 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2300 | iov[0].iov_len = smb_hdr_len + 4; |
| 2301 | else /* wct == 12 pad bigger by four bytes */ |
| 2302 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2303 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2304 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2305 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2306 | long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2307 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2309 | cFYI(1, "Send error Write2 = %d", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2310 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2311 | /* presumably this can not happen, but best to be safe */ |
| 2312 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2313 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2314 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2315 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2316 | *nbytes = (*nbytes) << 16; |
| 2317 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2318 | |
| 2319 | /* |
| 2320 | * Mask off high 16 bits when bytes written as returned by the |
| 2321 | * server is greater than bytes requested by the client. OS/2 |
| 2322 | * servers are known to set incorrect CountHigh values. |
| 2323 | */ |
| 2324 | if (*nbytes > count) |
| 2325 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2326 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 2328 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2329 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2330 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2331 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2332 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2334 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | since file handle passed in no longer valid */ |
| 2336 | |
| 2337 | return rc; |
| 2338 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2339 | |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2340 | int cifs_lockv(const int xid, struct cifs_tcon *tcon, const __u16 netfid, |
| 2341 | const __u8 lock_type, const __u32 num_unlock, |
| 2342 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2343 | { |
| 2344 | int rc = 0; |
| 2345 | LOCK_REQ *pSMB = NULL; |
| 2346 | struct kvec iov[2]; |
| 2347 | int resp_buf_type; |
| 2348 | __u16 count; |
| 2349 | |
| 2350 | cFYI(1, "cifs_lockv num lock %d num unlock %d", num_lock, num_unlock); |
| 2351 | |
| 2352 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2353 | if (rc) |
| 2354 | return rc; |
| 2355 | |
| 2356 | pSMB->Timeout = 0; |
| 2357 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2358 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2359 | pSMB->LockType = lock_type; |
| 2360 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2361 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2362 | |
| 2363 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2364 | inc_rfc1001_len(pSMB, count); |
| 2365 | pSMB->ByteCount = cpu_to_le16(count); |
| 2366 | |
| 2367 | iov[0].iov_base = (char *)pSMB; |
| 2368 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2369 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2370 | iov[1].iov_base = (char *)buf; |
| 2371 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2372 | |
| 2373 | cifs_stats_inc(&tcon->num_locks); |
| 2374 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP); |
| 2375 | if (rc) |
| 2376 | cFYI(1, "Send error in cifs_lockv = %d", rc); |
| 2377 | |
| 2378 | return rc; |
| 2379 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2382 | CIFSSMBLock(const int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2383 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2385 | const __u32 numLock, const __u8 lockType, |
| 2386 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | { |
| 2388 | int rc = 0; |
| 2389 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2390 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | int bytes_returned; |
| 2392 | int timeout = 0; |
| 2393 | __u16 count; |
| 2394 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2395 | cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2396 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | if (rc) |
| 2399 | return rc; |
| 2400 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2401 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2402 | timeout = CIFS_ASYNC_OP; /* no response expected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2404 | } else if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2405 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2407 | } else { |
| 2408 | pSMB->Timeout = 0; |
| 2409 | } |
| 2410 | |
| 2411 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2412 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2413 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2414 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2416 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2417 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2418 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2419 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | /* BB where to store pid high? */ |
| 2421 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2422 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2423 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2424 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2425 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2426 | } else { |
| 2427 | /* oplock break */ |
| 2428 | count = 0; |
| 2429 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2430 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | pSMB->ByteCount = cpu_to_le16(count); |
| 2432 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2433 | if (waitFlag) { |
| 2434 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2435 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2436 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2437 | } else { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2438 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, timeout); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2439 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2440 | } |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2441 | cifs_stats_inc(&tcon->num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2442 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2443 | cFYI(1, "Send error in Lock = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2445 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | since file handle passed in no longer valid */ |
| 2447 | return rc; |
| 2448 | } |
| 2449 | |
| 2450 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2451 | CIFSSMBPosixLock(const int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2452 | const __u16 smb_file_id, const __u32 netpid, const int get_flag, |
| 2453 | const __u64 len, struct file_lock *pLockData, |
| 2454 | const __u16 lock_type, const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2455 | { |
| 2456 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2457 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2458 | struct cifs_posix_lock *parm_data; |
| 2459 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2460 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2461 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2462 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2463 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2464 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2465 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2466 | cFYI(1, "Posix Lock"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2467 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2468 | if (pLockData == NULL) |
Marcin Slusarz | ed5f037 | 2008-05-13 04:01:01 +0000 | [diff] [blame] | 2469 | return -EINVAL; |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2470 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2471 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2472 | |
| 2473 | if (rc) |
| 2474 | return rc; |
| 2475 | |
| 2476 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2477 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2478 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2479 | pSMB->MaxSetupCount = 0; |
| 2480 | pSMB->Reserved = 0; |
| 2481 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2482 | pSMB->Reserved2 = 0; |
| 2483 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2484 | offset = param_offset + params; |
| 2485 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2486 | count = sizeof(struct cifs_posix_lock); |
| 2487 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2488 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2489 | pSMB->SetupCount = 1; |
| 2490 | pSMB->Reserved3 = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2491 | if (get_flag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2492 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2493 | else |
| 2494 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2495 | byte_count = 3 /* pad */ + params + count; |
| 2496 | pSMB->DataCount = cpu_to_le16(count); |
| 2497 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2498 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2499 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2500 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2501 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2502 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2503 | |
| 2504 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2505 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2506 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2507 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2508 | pSMB->Timeout = cpu_to_le32(-1); |
| 2509 | } else |
| 2510 | pSMB->Timeout = 0; |
| 2511 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2512 | parm_data->pid = cpu_to_le32(netpid); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2513 | parm_data->start = cpu_to_le64(pLockData->fl_start); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2514 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2515 | |
| 2516 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2517 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2518 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2519 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2520 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2521 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2522 | if (waitFlag) { |
| 2523 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2524 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2525 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2526 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2527 | 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] | 2528 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 2529 | &resp_buf_type, timeout); |
| 2530 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 2531 | not try to free it twice below on exit */ |
| 2532 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2533 | } |
| 2534 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2535 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2536 | cFYI(1, "Send error in Posix Lock = %d", rc); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2537 | } else if (get_flag) { |
| 2538 | /* lock structure can be returned on get */ |
| 2539 | __u16 data_offset; |
| 2540 | __u16 data_count; |
| 2541 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2542 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2543 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2544 | rc = -EIO; /* bad smb */ |
| 2545 | goto plk_err_exit; |
| 2546 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2547 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2548 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2549 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2550 | rc = -EIO; |
| 2551 | goto plk_err_exit; |
| 2552 | } |
| 2553 | parm_data = (struct cifs_posix_lock *) |
| 2554 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2555 | if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2556 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2557 | else { |
| 2558 | if (parm_data->lock_type == |
| 2559 | __constant_cpu_to_le16(CIFS_RDLCK)) |
| 2560 | pLockData->fl_type = F_RDLCK; |
| 2561 | else if (parm_data->lock_type == |
| 2562 | __constant_cpu_to_le16(CIFS_WRLCK)) |
| 2563 | pLockData->fl_type = F_WRLCK; |
| 2564 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2565 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2566 | pLockData->fl_end = pLockData->fl_start + |
| 2567 | le64_to_cpu(parm_data->length) - 1; |
| 2568 | pLockData->fl_pid = le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2569 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2570 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2571 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2572 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2573 | if (pSMB) |
| 2574 | cifs_small_buf_release(pSMB); |
| 2575 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2576 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 2577 | cifs_small_buf_release(iov[0].iov_base); |
| 2578 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 2579 | cifs_buf_release(iov[0].iov_base); |
| 2580 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2581 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2582 | since file handle passed in no longer valid */ |
| 2583 | |
| 2584 | return rc; |
| 2585 | } |
| 2586 | |
| 2587 | |
| 2588 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2589 | CIFSSMBClose(const int xid, struct cifs_tcon *tcon, int smb_file_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | { |
| 2591 | int rc = 0; |
| 2592 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2593 | cFYI(1, "In CIFSSMBClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | |
| 2595 | /* do not retry on dead session on close */ |
| 2596 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2597 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | return 0; |
| 2599 | if (rc) |
| 2600 | return rc; |
| 2601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2603 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2605 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2606 | cifs_stats_inc(&tcon->num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2608 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2610 | cERROR(1, "Send error in Close = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | } |
| 2612 | } |
| 2613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2615 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | rc = 0; |
| 2617 | |
| 2618 | return rc; |
| 2619 | } |
| 2620 | |
| 2621 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2622 | CIFSSMBFlush(const int xid, struct cifs_tcon *tcon, int smb_file_id) |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2623 | { |
| 2624 | int rc = 0; |
| 2625 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2626 | cFYI(1, "In CIFSSMBFlush"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2627 | |
| 2628 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2629 | if (rc) |
| 2630 | return rc; |
| 2631 | |
| 2632 | pSMB->FileID = (__u16) smb_file_id; |
| 2633 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2634 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2635 | cifs_stats_inc(&tcon->num_flushes); |
| 2636 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2637 | cERROR(1, "Send error in Flush = %d", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2638 | |
| 2639 | return rc; |
| 2640 | } |
| 2641 | |
| 2642 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2643 | CIFSSMBRename(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2645 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | { |
| 2647 | int rc = 0; |
| 2648 | RENAME_REQ *pSMB = NULL; |
| 2649 | RENAME_RSP *pSMBr = NULL; |
| 2650 | int bytes_returned; |
| 2651 | int name_len, name_len2; |
| 2652 | __u16 count; |
| 2653 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2654 | cFYI(1, "In CIFSSMBRename"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | renameRetry: |
| 2656 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2657 | (void **) &pSMBr); |
| 2658 | if (rc) |
| 2659 | return rc; |
| 2660 | |
| 2661 | pSMB->BufferFormat = 0x04; |
| 2662 | pSMB->SearchAttributes = |
| 2663 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2664 | ATTR_DIRECTORY); |
| 2665 | |
| 2666 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2667 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2668 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, |
| 2669 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | name_len++; /* trailing null */ |
| 2671 | name_len *= 2; |
| 2672 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2673 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2674 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2675 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2676 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2677 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2679 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2680 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | name_len = strnlen(fromName, PATH_MAX); |
| 2682 | name_len++; /* trailing null */ |
| 2683 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2684 | name_len2 = strnlen(toName, PATH_MAX); |
| 2685 | name_len2++; /* trailing null */ |
| 2686 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2687 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2688 | name_len2++; /* trailing null */ |
| 2689 | name_len2++; /* signature byte */ |
| 2690 | } |
| 2691 | |
| 2692 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2693 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | pSMB->ByteCount = cpu_to_le16(count); |
| 2695 | |
| 2696 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2697 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2698 | cifs_stats_inc(&tcon->num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2699 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2700 | cFYI(1, "Send error in rename = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | cifs_buf_release(pSMB); |
| 2703 | |
| 2704 | if (rc == -EAGAIN) |
| 2705 | goto renameRetry; |
| 2706 | |
| 2707 | return rc; |
| 2708 | } |
| 2709 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2710 | int CIFSSMBRenameOpenFile(const int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2711 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2712 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | { |
| 2714 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2715 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2716 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | char *data_offset; |
| 2718 | char dummy_string[30]; |
| 2719 | int rc = 0; |
| 2720 | int bytes_returned = 0; |
| 2721 | int len_of_str; |
| 2722 | __u16 params, param_offset, offset, count, byte_count; |
| 2723 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2724 | cFYI(1, "Rename to File by handle"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2726 | (void **) &pSMBr); |
| 2727 | if (rc) |
| 2728 | return rc; |
| 2729 | |
| 2730 | params = 6; |
| 2731 | pSMB->MaxSetupCount = 0; |
| 2732 | pSMB->Reserved = 0; |
| 2733 | pSMB->Flags = 0; |
| 2734 | pSMB->Timeout = 0; |
| 2735 | pSMB->Reserved2 = 0; |
| 2736 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2737 | offset = param_offset + params; |
| 2738 | |
| 2739 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2740 | rename_info = (struct set_file_rename *) data_offset; |
| 2741 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2742 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | pSMB->SetupCount = 1; |
| 2744 | pSMB->Reserved3 = 0; |
| 2745 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2746 | byte_count = 3 /* pad */ + params; |
| 2747 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2748 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2749 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2750 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2751 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2752 | rename_info->overwrite = cpu_to_le32(1); |
| 2753 | rename_info->root_fid = 0; |
| 2754 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2755 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2756 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2757 | len_of_str = |
| 2758 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2759 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2761 | len_of_str = |
| 2762 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2763 | target_name, PATH_MAX, nls_codepage, |
| 2764 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | } |
| 2766 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2767 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | byte_count += count; |
| 2769 | pSMB->DataCount = cpu_to_le16(count); |
| 2770 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2771 | pSMB->Fid = netfid; |
| 2772 | pSMB->InformationLevel = |
| 2773 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2774 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2775 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2777 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2778 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2779 | cifs_stats_inc(&pTcon->num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2780 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2781 | cFYI(1, "Send error in Rename (by file handle) = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | cifs_buf_release(pSMB); |
| 2784 | |
| 2785 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2786 | since file handle passed in no longer valid */ |
| 2787 | |
| 2788 | return rc; |
| 2789 | } |
| 2790 | |
| 2791 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2792 | CIFSSMBCopy(const int xid, struct cifs_tcon *tcon, const char *fromName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2793 | const __u16 target_tid, const char *toName, const int flags, |
| 2794 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | { |
| 2796 | int rc = 0; |
| 2797 | COPY_REQ *pSMB = NULL; |
| 2798 | COPY_RSP *pSMBr = NULL; |
| 2799 | int bytes_returned; |
| 2800 | int name_len, name_len2; |
| 2801 | __u16 count; |
| 2802 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2803 | cFYI(1, "In CIFSSMBCopy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | copyRetry: |
| 2805 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2806 | (void **) &pSMBr); |
| 2807 | if (rc) |
| 2808 | return rc; |
| 2809 | |
| 2810 | pSMB->BufferFormat = 0x04; |
| 2811 | pSMB->Tid2 = target_tid; |
| 2812 | |
| 2813 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2814 | |
| 2815 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2816 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2817 | fromName, PATH_MAX, nls_codepage, |
| 2818 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | name_len++; /* trailing null */ |
| 2820 | name_len *= 2; |
| 2821 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2822 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2823 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2824 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2825 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2826 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2828 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2829 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | name_len = strnlen(fromName, PATH_MAX); |
| 2831 | name_len++; /* trailing null */ |
| 2832 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2833 | name_len2 = strnlen(toName, PATH_MAX); |
| 2834 | name_len2++; /* trailing null */ |
| 2835 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2836 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2837 | name_len2++; /* trailing null */ |
| 2838 | name_len2++; /* signature byte */ |
| 2839 | } |
| 2840 | |
| 2841 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2842 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | pSMB->ByteCount = cpu_to_le16(count); |
| 2844 | |
| 2845 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2846 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2847 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2848 | cFYI(1, "Send error in copy = %d with %d files copied", |
| 2849 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2851 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | |
| 2853 | if (rc == -EAGAIN) |
| 2854 | goto copyRetry; |
| 2855 | |
| 2856 | return rc; |
| 2857 | } |
| 2858 | |
| 2859 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2860 | CIFSUnixCreateSymLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | const char *fromName, const char *toName, |
| 2862 | const struct nls_table *nls_codepage) |
| 2863 | { |
| 2864 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2865 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2866 | char *data_offset; |
| 2867 | int name_len; |
| 2868 | int name_len_target; |
| 2869 | int rc = 0; |
| 2870 | int bytes_returned = 0; |
| 2871 | __u16 params, param_offset, offset, byte_count; |
| 2872 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2873 | cFYI(1, "In Symlink Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | createSymLinkRetry: |
| 2875 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2876 | (void **) &pSMBr); |
| 2877 | if (rc) |
| 2878 | return rc; |
| 2879 | |
| 2880 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2881 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2882 | cifs_strtoUTF16((__le16 *) pSMB->FileName, fromName, |
| 2883 | /* find define for this maxpathcomponent */ |
| 2884 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | name_len++; /* trailing null */ |
| 2886 | name_len *= 2; |
| 2887 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2888 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | name_len = strnlen(fromName, PATH_MAX); |
| 2890 | name_len++; /* trailing null */ |
| 2891 | strncpy(pSMB->FileName, fromName, name_len); |
| 2892 | } |
| 2893 | params = 6 + name_len; |
| 2894 | pSMB->MaxSetupCount = 0; |
| 2895 | pSMB->Reserved = 0; |
| 2896 | pSMB->Flags = 0; |
| 2897 | pSMB->Timeout = 0; |
| 2898 | pSMB->Reserved2 = 0; |
| 2899 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2900 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | offset = param_offset + params; |
| 2902 | |
| 2903 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2904 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2905 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2906 | cifs_strtoUTF16((__le16 *) data_offset, toName, PATH_MAX |
| 2907 | /* find define for this maxpathcomponent */ |
| 2908 | , nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | name_len_target++; /* trailing null */ |
| 2910 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2911 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | name_len_target = strnlen(toName, PATH_MAX); |
| 2913 | name_len_target++; /* trailing null */ |
| 2914 | strncpy(data_offset, toName, name_len_target); |
| 2915 | } |
| 2916 | |
| 2917 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2918 | /* BB find exact max on data count below from sess */ |
| 2919 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2920 | pSMB->SetupCount = 1; |
| 2921 | pSMB->Reserved3 = 0; |
| 2922 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2923 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2924 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2925 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2926 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2927 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2928 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2929 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2930 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2931 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2932 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2934 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2935 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2936 | cifs_stats_inc(&tcon->num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2937 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2938 | cFYI(1, "Send error in SetPathInfo create symlink = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2940 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | |
| 2942 | if (rc == -EAGAIN) |
| 2943 | goto createSymLinkRetry; |
| 2944 | |
| 2945 | return rc; |
| 2946 | } |
| 2947 | |
| 2948 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2949 | CIFSUnixCreateHardLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2951 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | { |
| 2953 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2954 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2955 | char *data_offset; |
| 2956 | int name_len; |
| 2957 | int name_len_target; |
| 2958 | int rc = 0; |
| 2959 | int bytes_returned = 0; |
| 2960 | __u16 params, param_offset, offset, byte_count; |
| 2961 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2962 | cFYI(1, "In Create Hard link Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | createHardLinkRetry: |
| 2964 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2965 | (void **) &pSMBr); |
| 2966 | if (rc) |
| 2967 | return rc; |
| 2968 | |
| 2969 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2970 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 2971 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | name_len++; /* trailing null */ |
| 2973 | name_len *= 2; |
| 2974 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2975 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | name_len = strnlen(toName, PATH_MAX); |
| 2977 | name_len++; /* trailing null */ |
| 2978 | strncpy(pSMB->FileName, toName, name_len); |
| 2979 | } |
| 2980 | params = 6 + name_len; |
| 2981 | pSMB->MaxSetupCount = 0; |
| 2982 | pSMB->Reserved = 0; |
| 2983 | pSMB->Flags = 0; |
| 2984 | pSMB->Timeout = 0; |
| 2985 | pSMB->Reserved2 = 0; |
| 2986 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2987 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | offset = param_offset + params; |
| 2989 | |
| 2990 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2991 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2992 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2993 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 2994 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | name_len_target++; /* trailing null */ |
| 2996 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2997 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2999 | name_len_target++; /* trailing null */ |
| 3000 | strncpy(data_offset, fromName, name_len_target); |
| 3001 | } |
| 3002 | |
| 3003 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3004 | /* BB find exact max on data count below from sess*/ |
| 3005 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 3006 | pSMB->SetupCount = 1; |
| 3007 | pSMB->Reserved3 = 0; |
| 3008 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3009 | byte_count = 3 /* pad */ + params + name_len_target; |
| 3010 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3011 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3012 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 3013 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3014 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3015 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3016 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 3017 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3018 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3020 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3021 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3022 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3023 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3024 | cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | |
| 3026 | cifs_buf_release(pSMB); |
| 3027 | if (rc == -EAGAIN) |
| 3028 | goto createHardLinkRetry; |
| 3029 | |
| 3030 | return rc; |
| 3031 | } |
| 3032 | |
| 3033 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3034 | CIFSCreateHardLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3036 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | { |
| 3038 | int rc = 0; |
| 3039 | NT_RENAME_REQ *pSMB = NULL; |
| 3040 | RENAME_RSP *pSMBr = NULL; |
| 3041 | int bytes_returned; |
| 3042 | int name_len, name_len2; |
| 3043 | __u16 count; |
| 3044 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3045 | cFYI(1, "In CIFSCreateHardLink"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | winCreateHardLinkRetry: |
| 3047 | |
| 3048 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 3049 | (void **) &pSMBr); |
| 3050 | if (rc) |
| 3051 | return rc; |
| 3052 | |
| 3053 | pSMB->SearchAttributes = |
| 3054 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3055 | ATTR_DIRECTORY); |
| 3056 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 3057 | pSMB->ClusterCount = 0; |
| 3058 | |
| 3059 | pSMB->BufferFormat = 0x04; |
| 3060 | |
| 3061 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3062 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3063 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, |
| 3064 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | name_len++; /* trailing null */ |
| 3066 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 3067 | |
| 3068 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 3069 | pSMB->OldFileName[name_len] = 0x04; |
| 3070 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3072 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 3073 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 3075 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3076 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | name_len = strnlen(fromName, PATH_MAX); |
| 3078 | name_len++; /* trailing null */ |
| 3079 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 3080 | name_len2 = strnlen(toName, PATH_MAX); |
| 3081 | name_len2++; /* trailing null */ |
| 3082 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 3083 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 3084 | name_len2++; /* trailing null */ |
| 3085 | name_len2++; /* signature byte */ |
| 3086 | } |
| 3087 | |
| 3088 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3089 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | pSMB->ByteCount = cpu_to_le16(count); |
| 3091 | |
| 3092 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3093 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3094 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3095 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3096 | cFYI(1, "Send error in hard link (NT rename) = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | cifs_buf_release(pSMB); |
| 3099 | if (rc == -EAGAIN) |
| 3100 | goto winCreateHardLinkRetry; |
| 3101 | |
| 3102 | return rc; |
| 3103 | } |
| 3104 | |
| 3105 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3106 | CIFSSMBUnixQuerySymLink(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3107 | const unsigned char *searchName, char **symlinkinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | const struct nls_table *nls_codepage) |
| 3109 | { |
| 3110 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 3111 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3112 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3113 | int rc = 0; |
| 3114 | int bytes_returned; |
| 3115 | int name_len; |
| 3116 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3117 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3119 | cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | |
| 3121 | querySymLinkRetry: |
| 3122 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3123 | (void **) &pSMBr); |
| 3124 | if (rc) |
| 3125 | return rc; |
| 3126 | |
| 3127 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3128 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3129 | cifs_strtoUTF16((__le16 *) pSMB->FileName, searchName, |
| 3130 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | name_len++; /* trailing null */ |
| 3132 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3133 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | name_len = strnlen(searchName, PATH_MAX); |
| 3135 | name_len++; /* trailing null */ |
| 3136 | strncpy(pSMB->FileName, searchName, name_len); |
| 3137 | } |
| 3138 | |
| 3139 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3140 | pSMB->TotalDataCount = 0; |
| 3141 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3142 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | pSMB->MaxSetupCount = 0; |
| 3144 | pSMB->Reserved = 0; |
| 3145 | pSMB->Flags = 0; |
| 3146 | pSMB->Timeout = 0; |
| 3147 | pSMB->Reserved2 = 0; |
| 3148 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3149 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | pSMB->DataCount = 0; |
| 3151 | pSMB->DataOffset = 0; |
| 3152 | pSMB->SetupCount = 1; |
| 3153 | pSMB->Reserved3 = 0; |
| 3154 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3155 | byte_count = params + 1 /* pad */ ; |
| 3156 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3157 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3158 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3159 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3160 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3162 | |
| 3163 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3164 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3165 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3166 | cFYI(1, "Send error in QuerySymLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | } else { |
| 3168 | /* decode response */ |
| 3169 | |
| 3170 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3172 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3173 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3175 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3176 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3178 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3179 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3180 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3181 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3182 | is_unicode = true; |
| 3183 | else |
| 3184 | is_unicode = false; |
| 3185 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3186 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3187 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3188 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3189 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3190 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | } |
| 3192 | } |
| 3193 | cifs_buf_release(pSMB); |
| 3194 | if (rc == -EAGAIN) |
| 3195 | goto querySymLinkRetry; |
| 3196 | return rc; |
| 3197 | } |
| 3198 | |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3199 | #ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL |
| 3200 | /* |
| 3201 | * Recent Windows versions now create symlinks more frequently |
| 3202 | * and they use the "reparse point" mechanism below. We can of course |
| 3203 | * do symlinks nicely to Samba and other servers which support the |
| 3204 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3205 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3206 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3207 | * In the interim this code has been moved to its own config option so |
| 3208 | * it is not compiled in by default until callers fixed up and more tested. |
| 3209 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3211 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3213 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | const struct nls_table *nls_codepage) |
| 3215 | { |
| 3216 | int rc = 0; |
| 3217 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3218 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3219 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3221 | cFYI(1, "In Windows reparse style QueryLink for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3223 | (void **) &pSMBr); |
| 3224 | if (rc) |
| 3225 | return rc; |
| 3226 | |
| 3227 | pSMB->TotalParameterCount = 0 ; |
| 3228 | pSMB->TotalDataCount = 0; |
| 3229 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3230 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3231 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | pSMB->MaxSetupCount = 4; |
| 3233 | pSMB->Reserved = 0; |
| 3234 | pSMB->ParameterOffset = 0; |
| 3235 | pSMB->DataCount = 0; |
| 3236 | pSMB->DataOffset = 0; |
| 3237 | pSMB->SetupCount = 4; |
| 3238 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3239 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3240 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3241 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3242 | pSMB->IsRootFlag = 0; |
| 3243 | pSMB->Fid = fid; /* file handle always le */ |
| 3244 | pSMB->ByteCount = 0; |
| 3245 | |
| 3246 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3247 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3248 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3249 | cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | } else { /* decode response */ |
| 3251 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3252 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3253 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3254 | /* BB also check enough total bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | rc = -EIO; /* bad smb */ |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3256 | goto qreparse_out; |
| 3257 | } |
| 3258 | if (data_count && (data_count < 2048)) { |
| 3259 | char *end_of_smb = 2 /* sizeof byte count */ + |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3260 | get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3262 | struct reparse_data *reparse_buf = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3263 | (struct reparse_data *) |
| 3264 | ((char *)&pSMBr->hdr.Protocol |
| 3265 | + data_offset); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3266 | if ((char *)reparse_buf >= end_of_smb) { |
| 3267 | rc = -EIO; |
| 3268 | goto qreparse_out; |
| 3269 | } |
| 3270 | if ((reparse_buf->LinkNamesBuf + |
| 3271 | reparse_buf->TargetNameOffset + |
| 3272 | reparse_buf->TargetNameLen) > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3273 | cFYI(1, "reparse buf beyond SMB"); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3274 | rc = -EIO; |
| 3275 | goto qreparse_out; |
| 3276 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3277 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3278 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3279 | cifs_from_ucs2(symlinkinfo, (__le16 *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3280 | (reparse_buf->LinkNamesBuf + |
| 3281 | reparse_buf->TargetNameOffset), |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3282 | buflen, |
| 3283 | reparse_buf->TargetNameLen, |
| 3284 | nls_codepage, 0); |
| 3285 | } else { /* ASCII names */ |
| 3286 | strncpy(symlinkinfo, |
| 3287 | reparse_buf->LinkNamesBuf + |
| 3288 | reparse_buf->TargetNameOffset, |
| 3289 | min_t(const int, buflen, |
| 3290 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3292 | } else { |
| 3293 | rc = -EIO; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3294 | cFYI(1, "Invalid return data count on " |
| 3295 | "get reparse info ioctl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3297 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 3298 | does not go off the end of the buffer */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3299 | cFYI(1, "readlink result - %s", symlinkinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3303 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | |
| 3305 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 3306 | since file handle passed in no longer valid */ |
| 3307 | |
| 3308 | return rc; |
| 3309 | } |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3310 | #endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | |
| 3312 | #ifdef CONFIG_CIFS_POSIX |
| 3313 | |
| 3314 | /*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] | 3315 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 3316 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | { |
| 3318 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3319 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3320 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3321 | 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] | 3322 | /* 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] | 3323 | |
| 3324 | return; |
| 3325 | } |
| 3326 | |
| 3327 | /* 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] | 3328 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3329 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | { |
| 3331 | int size = 0; |
| 3332 | int i; |
| 3333 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3334 | struct cifs_posix_ace *pACE; |
| 3335 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 3336 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | |
| 3338 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3339 | return -EOPNOTSUPP; |
| 3340 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3341 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3343 | pACE = &cifs_acl->ace_array[0]; |
| 3344 | size = sizeof(struct cifs_posix_acl); |
| 3345 | size += sizeof(struct cifs_posix_ace) * count; |
| 3346 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3347 | if (size_of_data_area < size) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3348 | cFYI(1, "bad CIFS POSIX ACL size %d vs. %d", |
| 3349 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | return -EINVAL; |
| 3351 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3352 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3354 | size = sizeof(struct cifs_posix_acl); |
| 3355 | size += sizeof(struct cifs_posix_ace) * count; |
| 3356 | /* skip past access ACEs to get to default ACEs */ |
| 3357 | pACE = &cifs_acl->ace_array[count]; |
| 3358 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3359 | size += sizeof(struct cifs_posix_ace) * count; |
| 3360 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3361 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | return -EINVAL; |
| 3363 | } else { |
| 3364 | /* illegal type */ |
| 3365 | return -EINVAL; |
| 3366 | } |
| 3367 | |
| 3368 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3369 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3370 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3371 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | return -ERANGE; |
| 3373 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3374 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3375 | for (i = 0; i < count ; i++) { |
| 3376 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 3377 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | } |
| 3379 | } |
| 3380 | return size; |
| 3381 | } |
| 3382 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3383 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 3384 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | { |
| 3386 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 3387 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3388 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3389 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3391 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3393 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3394 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3395 | 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] | 3396 | /*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] | 3397 | return rc; |
| 3398 | } |
| 3399 | |
| 3400 | /* 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] | 3401 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3402 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | { |
| 3404 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3405 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 3406 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | int count; |
| 3408 | int i; |
| 3409 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3410 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | return 0; |
| 3412 | |
| 3413 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3414 | 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] | 3415 | "version of %d", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3416 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3417 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3418 | cFYI(1, "unknown POSIX ACL version %d", |
| 3419 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | return 0; |
| 3421 | } |
| 3422 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3423 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3424 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3425 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3426 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3428 | cFYI(1, "unknown ACL type %d", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | return 0; |
| 3430 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3431 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 3433 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3434 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | /* ACE not converted */ |
| 3436 | break; |
| 3437 | } |
| 3438 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3439 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3441 | rc += sizeof(struct cifs_posix_acl); |
| 3442 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3443 | } |
| 3444 | return rc; |
| 3445 | } |
| 3446 | |
| 3447 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3448 | CIFSSMBGetPosixACL(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3449 | const unsigned char *searchName, |
| 3450 | char *acl_inf, const int buflen, const int acl_type, |
| 3451 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | { |
| 3453 | /* SMB_QUERY_POSIX_ACL */ |
| 3454 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3455 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3456 | int rc = 0; |
| 3457 | int bytes_returned; |
| 3458 | int name_len; |
| 3459 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3460 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3461 | cFYI(1, "In GetPosixACL (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | |
| 3463 | queryAclRetry: |
| 3464 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3465 | (void **) &pSMBr); |
| 3466 | if (rc) |
| 3467 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3470 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3471 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3472 | searchName, PATH_MAX, nls_codepage, |
| 3473 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | name_len++; /* trailing null */ |
| 3475 | name_len *= 2; |
| 3476 | pSMB->FileName[name_len] = 0; |
| 3477 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3478 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | name_len = strnlen(searchName, PATH_MAX); |
| 3480 | name_len++; /* trailing null */ |
| 3481 | strncpy(pSMB->FileName, searchName, name_len); |
| 3482 | } |
| 3483 | |
| 3484 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3485 | pSMB->TotalDataCount = 0; |
| 3486 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3487 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3489 | pSMB->MaxSetupCount = 0; |
| 3490 | pSMB->Reserved = 0; |
| 3491 | pSMB->Flags = 0; |
| 3492 | pSMB->Timeout = 0; |
| 3493 | pSMB->Reserved2 = 0; |
| 3494 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3495 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3496 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | pSMB->DataCount = 0; |
| 3498 | pSMB->DataOffset = 0; |
| 3499 | pSMB->SetupCount = 1; |
| 3500 | pSMB->Reserved3 = 0; |
| 3501 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3502 | byte_count = params + 1 /* pad */ ; |
| 3503 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3504 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3505 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3506 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3507 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3509 | |
| 3510 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3511 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3512 | cifs_stats_inc(&tcon->num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3514 | cFYI(1, "Send error in Query POSIX ACL = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | } else { |
| 3516 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3520 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | rc = -EIO; /* bad smb */ |
| 3522 | else { |
| 3523 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3524 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3525 | rc = cifs_copy_posix_acl(acl_inf, |
| 3526 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3527 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | } |
| 3529 | } |
| 3530 | cifs_buf_release(pSMB); |
| 3531 | if (rc == -EAGAIN) |
| 3532 | goto queryAclRetry; |
| 3533 | return rc; |
| 3534 | } |
| 3535 | |
| 3536 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3537 | CIFSSMBSetPosixACL(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3538 | const unsigned char *fileName, |
| 3539 | const char *local_acl, const int buflen, |
| 3540 | const int acl_type, |
| 3541 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | { |
| 3543 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3544 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3545 | char *parm_data; |
| 3546 | int name_len; |
| 3547 | int rc = 0; |
| 3548 | int bytes_returned = 0; |
| 3549 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3550 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3551 | cFYI(1, "In SetPosixACL (Unix) for path %s", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | setAclRetry: |
| 3553 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3554 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | if (rc) |
| 3556 | return rc; |
| 3557 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3558 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3559 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3560 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | name_len++; /* trailing null */ |
| 3562 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3563 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | name_len = strnlen(fileName, PATH_MAX); |
| 3565 | name_len++; /* trailing null */ |
| 3566 | strncpy(pSMB->FileName, fileName, name_len); |
| 3567 | } |
| 3568 | params = 6 + name_len; |
| 3569 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3570 | /* BB find max SMB size from sess */ |
| 3571 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | pSMB->MaxSetupCount = 0; |
| 3573 | pSMB->Reserved = 0; |
| 3574 | pSMB->Flags = 0; |
| 3575 | pSMB->Timeout = 0; |
| 3576 | pSMB->Reserved2 = 0; |
| 3577 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3578 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | offset = param_offset + params; |
| 3580 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3581 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3582 | |
| 3583 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3584 | 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] | 3585 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3586 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | rc = -EOPNOTSUPP; |
| 3588 | goto setACLerrorExit; |
| 3589 | } |
| 3590 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3591 | pSMB->SetupCount = 1; |
| 3592 | pSMB->Reserved3 = 0; |
| 3593 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3594 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3595 | byte_count = 3 /* pad */ + params + data_count; |
| 3596 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3597 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3598 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3599 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3600 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3601 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3603 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3604 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3605 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3606 | cFYI(1, "Set POSIX ACL returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | |
| 3608 | setACLerrorExit: |
| 3609 | cifs_buf_release(pSMB); |
| 3610 | if (rc == -EAGAIN) |
| 3611 | goto setAclRetry; |
| 3612 | return rc; |
| 3613 | } |
| 3614 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3615 | /* BB fix tabs in this function FIXME BB */ |
| 3616 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3617 | CIFSGetExtAttr(const int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3618 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3619 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3620 | int rc = 0; |
| 3621 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3622 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3623 | int bytes_returned; |
| 3624 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3625 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3626 | cFYI(1, "In GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3627 | if (tcon == NULL) |
| 3628 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3629 | |
| 3630 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3631 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3632 | (void **) &pSMBr); |
| 3633 | if (rc) |
| 3634 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3635 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3636 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3637 | pSMB->t2.TotalDataCount = 0; |
| 3638 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3639 | /* BB find exact max data count below from sess structure BB */ |
| 3640 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3641 | pSMB->t2.MaxSetupCount = 0; |
| 3642 | pSMB->t2.Reserved = 0; |
| 3643 | pSMB->t2.Flags = 0; |
| 3644 | pSMB->t2.Timeout = 0; |
| 3645 | pSMB->t2.Reserved2 = 0; |
| 3646 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3647 | Fid) - 4); |
| 3648 | pSMB->t2.DataCount = 0; |
| 3649 | pSMB->t2.DataOffset = 0; |
| 3650 | pSMB->t2.SetupCount = 1; |
| 3651 | pSMB->t2.Reserved3 = 0; |
| 3652 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3653 | byte_count = params + 1 /* pad */ ; |
| 3654 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3655 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3656 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3657 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3658 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3659 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3660 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3661 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3662 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3663 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3664 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3665 | cFYI(1, "error %d in GetExtAttr", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3666 | } else { |
| 3667 | /* decode response */ |
| 3668 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3669 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3670 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3671 | /* If rc should we check for EOPNOSUPP and |
| 3672 | disable the srvino flag? or in caller? */ |
| 3673 | rc = -EIO; /* bad smb */ |
| 3674 | else { |
| 3675 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3676 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3677 | struct file_chattr_info *pfinfo; |
| 3678 | /* BB Do we need a cast or hash here ? */ |
| 3679 | if (count != 16) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3680 | cFYI(1, "Illegal size ret in GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3681 | rc = -EIO; |
| 3682 | goto GetExtAttrOut; |
| 3683 | } |
| 3684 | pfinfo = (struct file_chattr_info *) |
| 3685 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3686 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3687 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3688 | } |
| 3689 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3690 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3691 | cifs_buf_release(pSMB); |
| 3692 | if (rc == -EAGAIN) |
| 3693 | goto GetExtAttrRetry; |
| 3694 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3695 | } |
| 3696 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3697 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3699 | #ifdef CONFIG_CIFS_ACL |
| 3700 | /* |
| 3701 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3702 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3703 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3704 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3705 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3706 | * by caller |
| 3707 | */ |
| 3708 | static int |
| 3709 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3710 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3711 | void **ret_buf) |
| 3712 | { |
| 3713 | int rc; |
| 3714 | __u32 temp_offset; |
| 3715 | struct smb_com_ntransact_req *pSMB; |
| 3716 | |
| 3717 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3718 | (void **)&pSMB); |
| 3719 | if (rc) |
| 3720 | return rc; |
| 3721 | *ret_buf = (void *)pSMB; |
| 3722 | pSMB->Reserved = 0; |
| 3723 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3724 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3725 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3726 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3727 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3728 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3729 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3730 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3731 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3732 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3733 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3734 | return 0; |
| 3735 | } |
| 3736 | |
| 3737 | static int |
| 3738 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3739 | __u32 *pparmlen, __u32 *pdatalen) |
| 3740 | { |
| 3741 | char *end_of_smb; |
| 3742 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3743 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3744 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3745 | |
| 3746 | *pdatalen = 0; |
| 3747 | *pparmlen = 0; |
| 3748 | |
| 3749 | if (buf == NULL) |
| 3750 | return -EINVAL; |
| 3751 | |
| 3752 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3753 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3754 | bcc = get_bcc(&pSMBr->hdr); |
| 3755 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3756 | (char *)&pSMBr->ByteCount; |
| 3757 | |
| 3758 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3759 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3760 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3761 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3762 | |
| 3763 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3764 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3765 | |
| 3766 | /* should we also check that parm and data areas do not overlap? */ |
| 3767 | if (*ppparm > end_of_smb) { |
| 3768 | cFYI(1, "parms start after end of smb"); |
| 3769 | return -EINVAL; |
| 3770 | } else if (parm_count + *ppparm > end_of_smb) { |
| 3771 | cFYI(1, "parm end after end of smb"); |
| 3772 | return -EINVAL; |
| 3773 | } else if (*ppdata > end_of_smb) { |
| 3774 | cFYI(1, "data starts after end of smb"); |
| 3775 | return -EINVAL; |
| 3776 | } else if (data_count + *ppdata > end_of_smb) { |
| 3777 | cFYI(1, "data %p + count %d (%p) past smb end %p start %p", |
| 3778 | *ppdata, data_count, (data_count + *ppdata), |
| 3779 | end_of_smb, pSMBr); |
| 3780 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3781 | } else if (parm_count + data_count > bcc) { |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3782 | cFYI(1, "parm count and data count larger than SMB"); |
| 3783 | return -EINVAL; |
| 3784 | } |
| 3785 | *pdatalen = data_count; |
| 3786 | *pparmlen = parm_count; |
| 3787 | return 0; |
| 3788 | } |
| 3789 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3790 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3791 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3792 | CIFSSMBGetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3793 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3794 | { |
| 3795 | int rc = 0; |
| 3796 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3797 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3798 | struct kvec iov[1]; |
| 3799 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3800 | cFYI(1, "GetCifsACL"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3801 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3802 | *pbuflen = 0; |
| 3803 | *acl_inf = NULL; |
| 3804 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3805 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3806 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3807 | if (rc) |
| 3808 | return rc; |
| 3809 | |
| 3810 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3811 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3812 | pSMB->MaxSetupCount = 0; |
| 3813 | pSMB->Fid = fid; /* file handle always le */ |
| 3814 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3815 | CIFS_ACL_DACL); |
| 3816 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3817 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3818 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3819 | 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] | 3820 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3821 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 3822 | 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3823 | cifs_stats_inc(&tcon->num_acl_get); |
| 3824 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3825 | cFYI(1, "Send error in QuerySecDesc = %d", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3826 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3827 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3828 | __u32 parm_len; |
| 3829 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3830 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3831 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3832 | |
| 3833 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3834 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3835 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3836 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3837 | goto qsec_out; |
| 3838 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3839 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3840 | cFYI(1, "smb %p parm %p data %p", pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3841 | |
| 3842 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3843 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3844 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3845 | goto qsec_out; |
| 3846 | } |
| 3847 | |
| 3848 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3849 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3850 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3851 | if (acl_len != *pbuflen) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3852 | cERROR(1, "acl length %d does not match %d", |
| 3853 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3854 | if (*pbuflen > acl_len) |
| 3855 | *pbuflen = acl_len; |
| 3856 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3857 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3858 | /* check if buffer is big enough for the acl |
| 3859 | header followed by the smallest SID */ |
| 3860 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3861 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3862 | cERROR(1, "bad acl length %d", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3863 | rc = -EINVAL; |
| 3864 | *pbuflen = 0; |
| 3865 | } else { |
| 3866 | *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); |
| 3867 | if (*acl_inf == NULL) { |
| 3868 | *pbuflen = 0; |
| 3869 | rc = -ENOMEM; |
| 3870 | } |
| 3871 | memcpy(*acl_inf, pdata, *pbuflen); |
| 3872 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3873 | } |
| 3874 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3875 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3876 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3877 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3878 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3879 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3880 | return rc; |
| 3881 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3882 | |
| 3883 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3884 | CIFSSMBSetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3885 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3886 | { |
| 3887 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3888 | int rc = 0; |
| 3889 | int bytes_returned = 0; |
| 3890 | SET_SEC_DESC_REQ *pSMB = NULL; |
| 3891 | NTRANSACT_RSP *pSMBr = NULL; |
| 3892 | |
| 3893 | setCifsAclRetry: |
| 3894 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, |
| 3895 | (void **) &pSMBr); |
| 3896 | if (rc) |
| 3897 | return (rc); |
| 3898 | |
| 3899 | pSMB->MaxSetupCount = 0; |
| 3900 | pSMB->Reserved = 0; |
| 3901 | |
| 3902 | param_count = 8; |
| 3903 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3904 | data_count = acllen; |
| 3905 | data_offset = param_offset + param_count; |
| 3906 | byte_count = 3 /* pad */ + param_count; |
| 3907 | |
| 3908 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3909 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3910 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3911 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3912 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3913 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3914 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3915 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3916 | pSMB->SetupCount = 0; |
| 3917 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3918 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3919 | |
| 3920 | pSMB->Fid = fid; /* file handle always le */ |
| 3921 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3922 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3923 | |
| 3924 | if (pntsd && acllen) { |
| 3925 | memcpy((char *) &pSMBr->hdr.Protocol + data_offset, |
| 3926 | (char *) pntsd, |
| 3927 | acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3928 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3929 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3930 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3931 | |
| 3932 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3933 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3934 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3935 | cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3936 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3937 | cFYI(1, "Set CIFS ACL returned %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3938 | cifs_buf_release(pSMB); |
| 3939 | |
| 3940 | if (rc == -EAGAIN) |
| 3941 | goto setCifsAclRetry; |
| 3942 | |
| 3943 | return (rc); |
| 3944 | } |
| 3945 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3946 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3947 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3948 | /* Legacy Query Path Information call for lookup to old servers such |
| 3949 | as Win9x/WinME */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3950 | int SMBQueryInformation(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3951 | const unsigned char *searchName, |
| 3952 | FILE_ALL_INFO *pFinfo, |
| 3953 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3954 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3955 | QUERY_INFORMATION_REQ *pSMB; |
| 3956 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3957 | int rc = 0; |
| 3958 | int bytes_returned; |
| 3959 | int name_len; |
| 3960 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3961 | cFYI(1, "In SMBQPath path %s", searchName); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3962 | QInfRetry: |
| 3963 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3964 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3965 | if (rc) |
| 3966 | return rc; |
| 3967 | |
| 3968 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3969 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3970 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3971 | searchName, PATH_MAX, nls_codepage, |
| 3972 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3973 | name_len++; /* trailing null */ |
| 3974 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3975 | } else { |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3976 | name_len = strnlen(searchName, PATH_MAX); |
| 3977 | name_len++; /* trailing null */ |
| 3978 | strncpy(pSMB->FileName, searchName, name_len); |
| 3979 | } |
| 3980 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3981 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3982 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3983 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3984 | |
| 3985 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3986 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3987 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3988 | cFYI(1, "Send error in QueryInfo = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3989 | } else if (pFinfo) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3990 | struct timespec ts; |
| 3991 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3992 | |
| 3993 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3994 | /* BB FIXME - add time zone adjustment BB */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3995 | memset(pFinfo, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3996 | ts.tv_nsec = 0; |
| 3997 | ts.tv_sec = time; |
| 3998 | /* decode time fields */ |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 3999 | pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4000 | pFinfo->LastWriteTime = pFinfo->ChangeTime; |
| 4001 | pFinfo->LastAccessTime = 0; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4002 | pFinfo->AllocationSize = |
| 4003 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
| 4004 | pFinfo->EndOfFile = pFinfo->AllocationSize; |
| 4005 | pFinfo->Attributes = |
| 4006 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4007 | } else |
| 4008 | rc = -EIO; /* bad buffer passed in */ |
| 4009 | |
| 4010 | cifs_buf_release(pSMB); |
| 4011 | |
| 4012 | if (rc == -EAGAIN) |
| 4013 | goto QInfRetry; |
| 4014 | |
| 4015 | return rc; |
| 4016 | } |
| 4017 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4018 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4019 | CIFSSMBQFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4020 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 4021 | { |
| 4022 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4023 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4024 | int rc = 0; |
| 4025 | int bytes_returned; |
| 4026 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4027 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4028 | QFileInfoRetry: |
| 4029 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4030 | (void **) &pSMBr); |
| 4031 | if (rc) |
| 4032 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4033 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4034 | params = 2 /* level */ + 2 /* fid */; |
| 4035 | pSMB->t2.TotalDataCount = 0; |
| 4036 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4037 | /* BB find exact max data count below from sess structure BB */ |
| 4038 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4039 | pSMB->t2.MaxSetupCount = 0; |
| 4040 | pSMB->t2.Reserved = 0; |
| 4041 | pSMB->t2.Flags = 0; |
| 4042 | pSMB->t2.Timeout = 0; |
| 4043 | pSMB->t2.Reserved2 = 0; |
| 4044 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4045 | Fid) - 4); |
| 4046 | pSMB->t2.DataCount = 0; |
| 4047 | pSMB->t2.DataOffset = 0; |
| 4048 | pSMB->t2.SetupCount = 1; |
| 4049 | pSMB->t2.Reserved3 = 0; |
| 4050 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4051 | byte_count = params + 1 /* pad */ ; |
| 4052 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4053 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4054 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 4055 | pSMB->Pad = 0; |
| 4056 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4057 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4058 | |
| 4059 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4060 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4061 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4062 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4063 | } else { /* decode response */ |
| 4064 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4065 | |
| 4066 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4067 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4068 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4069 | rc = -EIO; /* bad smb */ |
| 4070 | else if (pFindData) { |
| 4071 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4072 | memcpy((char *) pFindData, |
| 4073 | (char *) &pSMBr->hdr.Protocol + |
| 4074 | data_offset, sizeof(FILE_ALL_INFO)); |
| 4075 | } else |
| 4076 | rc = -ENOMEM; |
| 4077 | } |
| 4078 | cifs_buf_release(pSMB); |
| 4079 | if (rc == -EAGAIN) |
| 4080 | goto QFileInfoRetry; |
| 4081 | |
| 4082 | return rc; |
| 4083 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4086 | CIFSSMBQPathInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4088 | FILE_ALL_INFO *pFindData, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4089 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4090 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | { |
| 4092 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
| 4093 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4094 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4095 | int rc = 0; |
| 4096 | int bytes_returned; |
| 4097 | int name_len; |
| 4098 | __u16 params, byte_count; |
| 4099 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4100 | /* cFYI(1, "In QPathInfo path %s", searchName); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | QPathInfoRetry: |
| 4102 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4103 | (void **) &pSMBr); |
| 4104 | if (rc) |
| 4105 | return rc; |
| 4106 | |
| 4107 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4108 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4109 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4110 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | name_len++; /* trailing null */ |
| 4112 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4113 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | name_len = strnlen(searchName, PATH_MAX); |
| 4115 | name_len++; /* trailing null */ |
| 4116 | strncpy(pSMB->FileName, searchName, name_len); |
| 4117 | } |
| 4118 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4119 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | pSMB->TotalDataCount = 0; |
| 4121 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4122 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4123 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | pSMB->MaxSetupCount = 0; |
| 4125 | pSMB->Reserved = 0; |
| 4126 | pSMB->Flags = 0; |
| 4127 | pSMB->Timeout = 0; |
| 4128 | pSMB->Reserved2 = 0; |
| 4129 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4130 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | pSMB->DataCount = 0; |
| 4132 | pSMB->DataOffset = 0; |
| 4133 | pSMB->SetupCount = 1; |
| 4134 | pSMB->Reserved3 = 0; |
| 4135 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4136 | byte_count = params + 1 /* pad */ ; |
| 4137 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4138 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4139 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4140 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4141 | else |
| 4142 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4144 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4146 | |
| 4147 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4148 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4149 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4150 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | } else { /* decode response */ |
| 4152 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4153 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4154 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4155 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4156 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4158 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4159 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4160 | last field */ |
| 4161 | else if (pFindData) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4162 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4164 | |
| 4165 | /* On legacy responses we do not read the last field, |
| 4166 | EAsize, fortunately since it varies by subdialect and |
| 4167 | also note it differs on Set vs. Get, ie two bytes or 4 |
| 4168 | bytes depending but we don't care here */ |
| 4169 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4170 | size = sizeof(FILE_INFO_STANDARD); |
| 4171 | else |
| 4172 | size = sizeof(FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | memcpy((char *) pFindData, |
| 4174 | (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4175 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | } else |
| 4177 | rc = -ENOMEM; |
| 4178 | } |
| 4179 | cifs_buf_release(pSMB); |
| 4180 | if (rc == -EAGAIN) |
| 4181 | goto QPathInfoRetry; |
| 4182 | |
| 4183 | return rc; |
| 4184 | } |
| 4185 | |
| 4186 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4187 | CIFSSMBUnixQFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4188 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4189 | { |
| 4190 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4191 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4192 | int rc = 0; |
| 4193 | int bytes_returned; |
| 4194 | __u16 params, byte_count; |
| 4195 | |
| 4196 | UnixQFileInfoRetry: |
| 4197 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4198 | (void **) &pSMBr); |
| 4199 | if (rc) |
| 4200 | return rc; |
| 4201 | |
| 4202 | params = 2 /* level */ + 2 /* fid */; |
| 4203 | pSMB->t2.TotalDataCount = 0; |
| 4204 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4205 | /* BB find exact max data count below from sess structure BB */ |
| 4206 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4207 | pSMB->t2.MaxSetupCount = 0; |
| 4208 | pSMB->t2.Reserved = 0; |
| 4209 | pSMB->t2.Flags = 0; |
| 4210 | pSMB->t2.Timeout = 0; |
| 4211 | pSMB->t2.Reserved2 = 0; |
| 4212 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4213 | Fid) - 4); |
| 4214 | pSMB->t2.DataCount = 0; |
| 4215 | pSMB->t2.DataOffset = 0; |
| 4216 | pSMB->t2.SetupCount = 1; |
| 4217 | pSMB->t2.Reserved3 = 0; |
| 4218 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4219 | byte_count = params + 1 /* pad */ ; |
| 4220 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4221 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4222 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4223 | pSMB->Pad = 0; |
| 4224 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4225 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4226 | |
| 4227 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4228 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4229 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4230 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4231 | } else { /* decode response */ |
| 4232 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4233 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4234 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4235 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4236 | "Unix Extensions can be disabled on mount " |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4237 | "by specifying the nosfu mount option."); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4238 | rc = -EIO; /* bad smb */ |
| 4239 | } else { |
| 4240 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4241 | memcpy((char *) pFindData, |
| 4242 | (char *) &pSMBr->hdr.Protocol + |
| 4243 | data_offset, |
| 4244 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4245 | } |
| 4246 | } |
| 4247 | |
| 4248 | cifs_buf_release(pSMB); |
| 4249 | if (rc == -EAGAIN) |
| 4250 | goto UnixQFileInfoRetry; |
| 4251 | |
| 4252 | return rc; |
| 4253 | } |
| 4254 | |
| 4255 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4256 | CIFSSMBUnixQPathInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4258 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4259 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | { |
| 4261 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4262 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4263 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4264 | int rc = 0; |
| 4265 | int bytes_returned = 0; |
| 4266 | int name_len; |
| 4267 | __u16 params, byte_count; |
| 4268 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4269 | cFYI(1, "In QPathInfo (Unix) the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | UnixQPathInfoRetry: |
| 4271 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4272 | (void **) &pSMBr); |
| 4273 | if (rc) |
| 4274 | return rc; |
| 4275 | |
| 4276 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4277 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4278 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4279 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | name_len++; /* trailing null */ |
| 4281 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4282 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | name_len = strnlen(searchName, PATH_MAX); |
| 4284 | name_len++; /* trailing null */ |
| 4285 | strncpy(pSMB->FileName, searchName, name_len); |
| 4286 | } |
| 4287 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4288 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | pSMB->TotalDataCount = 0; |
| 4290 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4291 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4292 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | pSMB->MaxSetupCount = 0; |
| 4294 | pSMB->Reserved = 0; |
| 4295 | pSMB->Flags = 0; |
| 4296 | pSMB->Timeout = 0; |
| 4297 | pSMB->Reserved2 = 0; |
| 4298 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4299 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | pSMB->DataCount = 0; |
| 4301 | pSMB->DataOffset = 0; |
| 4302 | pSMB->SetupCount = 1; |
| 4303 | pSMB->Reserved3 = 0; |
| 4304 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4305 | byte_count = params + 1 /* pad */ ; |
| 4306 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4307 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4308 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4309 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4310 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4312 | |
| 4313 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4314 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4315 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4316 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | } else { /* decode response */ |
| 4318 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4319 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4320 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4321 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Steve French | 1e71f25 | 2007-09-20 15:30:07 +0000 | [diff] [blame] | 4322 | "Unix Extensions can be disabled on mount " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4323 | "by specifying the nosfu mount option."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | rc = -EIO; /* bad smb */ |
| 4325 | } else { |
| 4326 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4327 | memcpy((char *) pFindData, |
| 4328 | (char *) &pSMBr->hdr.Protocol + |
| 4329 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4330 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | } |
| 4332 | } |
| 4333 | cifs_buf_release(pSMB); |
| 4334 | if (rc == -EAGAIN) |
| 4335 | goto UnixQPathInfoRetry; |
| 4336 | |
| 4337 | return rc; |
| 4338 | } |
| 4339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4341 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4342 | CIFSFindFirst(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4343 | const char *searchName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | const struct nls_table *nls_codepage, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4345 | __u16 *pnetfid, |
| 4346 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | { |
| 4348 | /* level 257 SMB_ */ |
| 4349 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4350 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4351 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | int rc = 0; |
| 4353 | int bytes_returned = 0; |
| 4354 | int name_len; |
| 4355 | __u16 params, byte_count; |
| 4356 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4357 | cFYI(1, "In FindFirst for %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | |
| 4359 | findFirstRetry: |
| 4360 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4361 | (void **) &pSMBr); |
| 4362 | if (rc) |
| 4363 | return rc; |
| 4364 | |
| 4365 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4366 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4367 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4368 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4369 | /* We can not add the asterik earlier in case |
| 4370 | it got remapped to 0xF03A as if it were part of the |
| 4371 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4372 | name_len *= 2; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4373 | pSMB->FileName[name_len] = dirsep; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4374 | pSMB->FileName[name_len+1] = 0; |
| 4375 | pSMB->FileName[name_len+2] = '*'; |
| 4376 | pSMB->FileName[name_len+3] = 0; |
| 4377 | name_len += 4; /* now the trailing null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ |
| 4379 | pSMB->FileName[name_len+1] = 0; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4380 | name_len += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | } else { /* BB add check for overrun of SMB buf BB */ |
| 4382 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4384 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | free buffer exit; BB */ |
| 4386 | strncpy(pSMB->FileName, searchName, name_len); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4387 | pSMB->FileName[name_len] = dirsep; |
Steve French | 6857547 | 2005-04-30 11:10:57 -0700 | [diff] [blame] | 4388 | pSMB->FileName[name_len+1] = '*'; |
| 4389 | pSMB->FileName[name_len+2] = 0; |
| 4390 | name_len += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | } |
| 4392 | |
| 4393 | params = 12 + name_len /* includes null */ ; |
| 4394 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4395 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4396 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | pSMB->MaxSetupCount = 0; |
| 4398 | pSMB->Reserved = 0; |
| 4399 | pSMB->Flags = 0; |
| 4400 | pSMB->Timeout = 0; |
| 4401 | pSMB->Reserved2 = 0; |
| 4402 | byte_count = params + 1 /* pad */ ; |
| 4403 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4404 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4405 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4406 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4407 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | pSMB->DataCount = 0; |
| 4409 | pSMB->DataOffset = 0; |
| 4410 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4411 | pSMB->Reserved3 = 0; |
| 4412 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4413 | pSMB->SearchAttributes = |
| 4414 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4415 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4416 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
| 4417 | pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | CIFS_SEARCH_RETURN_RESUME); |
| 4419 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4420 | |
| 4421 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4422 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4423 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4425 | |
| 4426 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4427 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4428 | cifs_stats_inc(&tcon->num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4430 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4431 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4433 | cFYI(1, "Error in FindFirst = %d", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4434 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4435 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | |
| 4437 | /* BB eventually could optimize out free and realloc of buf */ |
| 4438 | /* for this case */ |
| 4439 | if (rc == -EAGAIN) |
| 4440 | goto findFirstRetry; |
| 4441 | } else { /* decode response */ |
| 4442 | /* BB remember to free buffer if error BB */ |
| 4443 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4444 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4445 | unsigned int lnoff; |
| 4446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4448 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4450 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | |
| 4452 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4453 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4454 | psrch_inf->srch_entries_start = |
| 4455 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4458 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4459 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4460 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4461 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4463 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4465 | psrch_inf->entries_in_buffer = |
| 4466 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4467 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4469 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4470 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4471 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4472 | psrch_inf->last_entry = NULL; |
| 4473 | return rc; |
| 4474 | } |
| 4475 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4476 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4477 | lnoff; |
| 4478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | *pnetfid = parms->SearchHandle; |
| 4480 | } else { |
| 4481 | cifs_buf_release(pSMB); |
| 4482 | } |
| 4483 | } |
| 4484 | |
| 4485 | return rc; |
| 4486 | } |
| 4487 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4488 | int CIFSFindNext(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4489 | __u16 searchHandle, struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | { |
| 4491 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4492 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4493 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | char *response_data; |
| 4495 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4496 | int bytes_returned; |
| 4497 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | __u16 params, byte_count; |
| 4499 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4500 | cFYI(1, "In FindNext"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4502 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | return -ENOENT; |
| 4504 | |
| 4505 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4506 | (void **) &pSMBr); |
| 4507 | if (rc) |
| 4508 | return rc; |
| 4509 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4510 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | byte_count = 0; |
| 4512 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4513 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4514 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | pSMB->MaxSetupCount = 0; |
| 4516 | pSMB->Reserved = 0; |
| 4517 | pSMB->Flags = 0; |
| 4518 | pSMB->Timeout = 0; |
| 4519 | pSMB->Reserved2 = 0; |
| 4520 | pSMB->ParameterOffset = cpu_to_le16( |
| 4521 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4522 | pSMB->DataCount = 0; |
| 4523 | pSMB->DataOffset = 0; |
| 4524 | pSMB->SetupCount = 1; |
| 4525 | pSMB->Reserved3 = 0; |
| 4526 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4527 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4528 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4529 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4531 | pSMB->ResumeKey = psrch_inf->resume_key; |
| 4532 | pSMB->SearchFlags = |
| 4533 | cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME); |
| 4534 | |
| 4535 | name_len = psrch_inf->resume_name_len; |
| 4536 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4537 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4539 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4540 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4541 | pSMB->ResumeFileName[name_len] = 0; |
| 4542 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | } else { |
| 4544 | rc = -EINVAL; |
| 4545 | goto FNext2_err_exit; |
| 4546 | } |
| 4547 | byte_count = params + 1 /* pad */ ; |
| 4548 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4549 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4550 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4554 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4555 | cifs_stats_inc(&tcon->num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | if (rc) { |
| 4557 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4558 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4559 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4560 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | } else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4562 | cFYI(1, "FindNext returned = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | } else { /* decode response */ |
| 4564 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4565 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4566 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4567 | unsigned int lnoff; |
| 4568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4570 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4571 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4573 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4575 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4576 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4577 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4578 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4579 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4580 | cifs_small_buf_release( |
| 4581 | psrch_inf->ntwrk_buf_start); |
| 4582 | else |
| 4583 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | psrch_inf->srch_entries_start = response_data; |
| 4585 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4586 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4587 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4588 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4590 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4591 | psrch_inf->entries_in_buffer = |
| 4592 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | psrch_inf->index_of_last_entry += |
| 4594 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4595 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4596 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4597 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4598 | psrch_inf->last_entry = NULL; |
| 4599 | return rc; |
| 4600 | } else |
| 4601 | psrch_inf->last_entry = |
| 4602 | psrch_inf->srch_entries_start + lnoff; |
| 4603 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4604 | /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d", |
| 4605 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | |
| 4607 | /* BB fixme add unlock here */ |
| 4608 | } |
| 4609 | |
| 4610 | } |
| 4611 | |
| 4612 | /* BB On error, should we leave previous search buf (and count and |
| 4613 | last entry fields) intact or free the previous one? */ |
| 4614 | |
| 4615 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4616 | since file handle passed in no longer valid */ |
| 4617 | FNext2_err_exit: |
| 4618 | if (rc != 0) |
| 4619 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4620 | return rc; |
| 4621 | } |
| 4622 | |
| 4623 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4624 | CIFSFindClose(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4625 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | { |
| 4627 | int rc = 0; |
| 4628 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4630 | cFYI(1, "In CIFSSMBFindClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4632 | |
| 4633 | /* no sense returning error if session restarted |
| 4634 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4635 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | return 0; |
| 4637 | if (rc) |
| 4638 | return rc; |
| 4639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | pSMB->FileID = searchHandle; |
| 4641 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4642 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4643 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4644 | cERROR(1, "Send error in FindClose = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4645 | |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4646 | cifs_stats_inc(&tcon->num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | |
| 4648 | /* Since session is dead, search handle closed on server already */ |
| 4649 | if (rc == -EAGAIN) |
| 4650 | rc = 0; |
| 4651 | |
| 4652 | return rc; |
| 4653 | } |
| 4654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4656 | CIFSGetSrvInodeNumber(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4657 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4658 | __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4659 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | { |
| 4661 | int rc = 0; |
| 4662 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4663 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4664 | int name_len, bytes_returned; |
| 4665 | __u16 params, byte_count; |
| 4666 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4667 | cFYI(1, "In GetSrvInodeNum for %s", searchName); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4668 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4669 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | |
| 4671 | GetInodeNumberRetry: |
| 4672 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4673 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | if (rc) |
| 4675 | return rc; |
| 4676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4678 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4679 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 4680 | searchName, PATH_MAX, nls_codepage, |
| 4681 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | name_len++; /* trailing null */ |
| 4683 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4684 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | name_len = strnlen(searchName, PATH_MAX); |
| 4686 | name_len++; /* trailing null */ |
| 4687 | strncpy(pSMB->FileName, searchName, name_len); |
| 4688 | } |
| 4689 | |
| 4690 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4691 | pSMB->TotalDataCount = 0; |
| 4692 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4693 | /* BB find exact max data count below from sess structure BB */ |
| 4694 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4695 | pSMB->MaxSetupCount = 0; |
| 4696 | pSMB->Reserved = 0; |
| 4697 | pSMB->Flags = 0; |
| 4698 | pSMB->Timeout = 0; |
| 4699 | pSMB->Reserved2 = 0; |
| 4700 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4701 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4702 | pSMB->DataCount = 0; |
| 4703 | pSMB->DataOffset = 0; |
| 4704 | pSMB->SetupCount = 1; |
| 4705 | pSMB->Reserved3 = 0; |
| 4706 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4707 | byte_count = params + 1 /* pad */ ; |
| 4708 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4709 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4710 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4711 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4712 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4714 | |
| 4715 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4716 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4717 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4718 | cFYI(1, "error %d in QueryInternalInfo", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | } else { |
| 4720 | /* decode response */ |
| 4721 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4723 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | /* If rc should we check for EOPNOSUPP and |
| 4725 | disable the srvino flag? or in caller? */ |
| 4726 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4727 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4728 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4729 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4730 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4732 | if (count < 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4733 | cFYI(1, "Illegal size ret in QryIntrnlInf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | rc = -EIO; |
| 4735 | goto GetInodeNumOut; |
| 4736 | } |
| 4737 | pfinfo = (struct file_internal_info *) |
| 4738 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4739 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | } |
| 4741 | } |
| 4742 | GetInodeNumOut: |
| 4743 | cifs_buf_release(pSMB); |
| 4744 | if (rc == -EAGAIN) |
| 4745 | goto GetInodeNumberRetry; |
| 4746 | return rc; |
| 4747 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4749 | /* parses DFS refferal V3 structure |
| 4750 | * caller is responsible for freeing target_nodes |
| 4751 | * returns: |
| 4752 | * on success - 0 |
| 4753 | * on failure - errno |
| 4754 | */ |
| 4755 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4756 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4757 | unsigned int *num_of_nodes, |
| 4758 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4759 | const struct nls_table *nls_codepage, int remap, |
| 4760 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4761 | { |
| 4762 | int i, rc = 0; |
| 4763 | char *data_end; |
| 4764 | bool is_unicode; |
| 4765 | struct dfs_referral_level_3 *ref; |
| 4766 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 4767 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 4768 | is_unicode = true; |
| 4769 | else |
| 4770 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4771 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 4772 | |
| 4773 | if (*num_of_nodes < 1) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4774 | cERROR(1, "num_referrals: must be at least > 0," |
| 4775 | "but we get num_referrals = %d\n", *num_of_nodes); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4776 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4777 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4781 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4782 | cERROR(1, "Referrals of V%d version are not supported," |
| 4783 | "should be V3", le16_to_cpu(ref->VersionNumber)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4784 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4785 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | /* get the upper boundary of the resp buffer */ |
| 4789 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 4790 | le16_to_cpu(pSMBr->t2.DataCount); |
| 4791 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4792 | cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n", |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4793 | *num_of_nodes, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4794 | le32_to_cpu(pSMBr->DFSFlags)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4795 | |
| 4796 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
| 4797 | *num_of_nodes, GFP_KERNEL); |
| 4798 | if (*target_nodes == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4799 | cERROR(1, "Failed to allocate buffer for target_nodes\n"); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4800 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4801 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4802 | } |
| 4803 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4804 | /* collect necessary data from referrals */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4805 | for (i = 0; i < *num_of_nodes; i++) { |
| 4806 | char *temp; |
| 4807 | int max_len; |
| 4808 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 4809 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4810 | node->flags = le32_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4811 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 4812 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 4813 | GFP_KERNEL); |
Steve French | 2920ee2 | 2009-08-31 15:27:26 +0000 | [diff] [blame] | 4814 | if (tmp == NULL) { |
| 4815 | rc = -ENOMEM; |
| 4816 | goto parse_DFS_referrals_exit; |
| 4817 | } |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4818 | cifsConvertToUTF16((__le16 *) tmp, searchName, |
| 4819 | PATH_MAX, nls_codepage, remap); |
| 4820 | node->path_consumed = cifs_utf16_bytes(tmp, |
Jeff Layton | 69f801f | 2009-04-30 06:46:32 -0400 | [diff] [blame] | 4821 | le16_to_cpu(pSMBr->PathConsumed), |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4822 | nls_codepage); |
| 4823 | kfree(tmp); |
| 4824 | } else |
| 4825 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4826 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4827 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4828 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4829 | |
| 4830 | /* copy DfsPath */ |
| 4831 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4832 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4833 | node->path_name = cifs_strndup_from_utf16(temp, max_len, |
| 4834 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4835 | if (!node->path_name) { |
| 4836 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4837 | goto parse_DFS_referrals_exit; |
Jeff Layton | 066ce68 | 2009-04-30 07:16:14 -0400 | [diff] [blame] | 4838 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4839 | |
| 4840 | /* copy link target UNC */ |
| 4841 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4842 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4843 | node->node_name = cifs_strndup_from_utf16(temp, max_len, |
| 4844 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4845 | if (!node->node_name) |
| 4846 | rc = -ENOMEM; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4847 | } |
| 4848 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4849 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4850 | if (rc) { |
| 4851 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4852 | *target_nodes = NULL; |
| 4853 | *num_of_nodes = 0; |
| 4854 | } |
| 4855 | return rc; |
| 4856 | } |
| 4857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4859 | CIFSGetDFSRefer(const int xid, struct cifs_ses *ses, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | const unsigned char *searchName, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4861 | struct dfs_info3_param **target_nodes, |
| 4862 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4863 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | { |
| 4865 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4866 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4867 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | int rc = 0; |
| 4869 | int bytes_returned; |
| 4870 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4872 | *num_of_nodes = 0; |
| 4873 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4875 | cFYI(1, "In GetDFSRefer the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | if (ses == NULL) |
| 4877 | return -ENODEV; |
| 4878 | getDFSRetry: |
| 4879 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4880 | (void **) &pSMBr); |
| 4881 | if (rc) |
| 4882 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4883 | |
| 4884 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4885 | but should never be null here anyway */ |
| 4886 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4888 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4889 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4891 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | |
| 4894 | if (ses->capabilities & CAP_UNICODE) { |
| 4895 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4896 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4897 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
| 4898 | searchName, PATH_MAX, nls_codepage, |
| 4899 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4900 | name_len++; /* trailing null */ |
| 4901 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4902 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4903 | name_len = strnlen(searchName, PATH_MAX); |
| 4904 | name_len++; /* trailing null */ |
| 4905 | strncpy(pSMB->RequestFileName, searchName, name_len); |
| 4906 | } |
| 4907 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4908 | if (ses->server) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4909 | if (ses->server->sec_mode & |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4910 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 4911 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4912 | } |
| 4913 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4914 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4917 | pSMB->TotalDataCount = 0; |
| 4918 | pSMB->DataCount = 0; |
| 4919 | pSMB->DataOffset = 0; |
| 4920 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4921 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4922 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | pSMB->MaxSetupCount = 0; |
| 4924 | pSMB->Reserved = 0; |
| 4925 | pSMB->Flags = 0; |
| 4926 | pSMB->Timeout = 0; |
| 4927 | pSMB->Reserved2 = 0; |
| 4928 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4929 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | pSMB->SetupCount = 1; |
| 4931 | pSMB->Reserved3 = 0; |
| 4932 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4933 | byte_count = params + 3 /* pad */ ; |
| 4934 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4935 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4936 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4937 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4939 | |
| 4940 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4941 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4942 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4943 | cFYI(1, "Send error in GetDFSRefer = %d", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4944 | goto GetDFSRefExit; |
| 4945 | } |
| 4946 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4947 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4948 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4949 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4950 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4951 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4953 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4954 | cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4955 | get_bcc(&pSMBr->hdr), |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4956 | le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4957 | |
| 4958 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4959 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4960 | target_nodes, nls_codepage, remap, |
| 4961 | searchName); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4964 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 | |
| 4966 | if (rc == -EAGAIN) |
| 4967 | goto getDFSRetry; |
| 4968 | |
| 4969 | return rc; |
| 4970 | } |
| 4971 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4972 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4973 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4974 | SMBOldQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4975 | { |
| 4976 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4977 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4978 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4979 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4980 | int rc = 0; |
| 4981 | int bytes_returned = 0; |
| 4982 | __u16 params, byte_count; |
| 4983 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4984 | cFYI(1, "OldQFSInfo"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4985 | oldQFSInfoRetry: |
| 4986 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4987 | (void **) &pSMBr); |
| 4988 | if (rc) |
| 4989 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4990 | |
| 4991 | params = 2; /* level */ |
| 4992 | pSMB->TotalDataCount = 0; |
| 4993 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4994 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4995 | pSMB->MaxSetupCount = 0; |
| 4996 | pSMB->Reserved = 0; |
| 4997 | pSMB->Flags = 0; |
| 4998 | pSMB->Timeout = 0; |
| 4999 | pSMB->Reserved2 = 0; |
| 5000 | byte_count = params + 1 /* pad */ ; |
| 5001 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5002 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5003 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 5004 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 5005 | pSMB->DataCount = 0; |
| 5006 | pSMB->DataOffset = 0; |
| 5007 | pSMB->SetupCount = 1; |
| 5008 | pSMB->Reserved3 = 0; |
| 5009 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5010 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5011 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5012 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5013 | |
| 5014 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5015 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5016 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5017 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5018 | } else { /* decode response */ |
| 5019 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5020 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5021 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5022 | rc = -EIO; /* bad smb */ |
| 5023 | else { |
| 5024 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5025 | cFYI(1, "qfsinf resp BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5026 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5027 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5028 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5029 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 5030 | FSData->f_bsize = |
| 5031 | le16_to_cpu(response_data->BytesPerSector) * |
| 5032 | le32_to_cpu(response_data-> |
| 5033 | SectorsPerAllocationUnit); |
| 5034 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5035 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5036 | FSData->f_bfree = FSData->f_bavail = |
| 5037 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5038 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 5039 | (unsigned long long)FSData->f_blocks, |
| 5040 | (unsigned long long)FSData->f_bfree, |
| 5041 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5042 | } |
| 5043 | } |
| 5044 | cifs_buf_release(pSMB); |
| 5045 | |
| 5046 | if (rc == -EAGAIN) |
| 5047 | goto oldQFSInfoRetry; |
| 5048 | |
| 5049 | return rc; |
| 5050 | } |
| 5051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5053 | CIFSSMBQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5054 | { |
| 5055 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5056 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5057 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5058 | FILE_SYSTEM_INFO *response_data; |
| 5059 | int rc = 0; |
| 5060 | int bytes_returned = 0; |
| 5061 | __u16 params, byte_count; |
| 5062 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5063 | cFYI(1, "In QFSInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | QFSInfoRetry: |
| 5065 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5066 | (void **) &pSMBr); |
| 5067 | if (rc) |
| 5068 | return rc; |
| 5069 | |
| 5070 | params = 2; /* level */ |
| 5071 | pSMB->TotalDataCount = 0; |
| 5072 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5073 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | pSMB->MaxSetupCount = 0; |
| 5075 | pSMB->Reserved = 0; |
| 5076 | pSMB->Flags = 0; |
| 5077 | pSMB->Timeout = 0; |
| 5078 | pSMB->Reserved2 = 0; |
| 5079 | byte_count = params + 1 /* pad */ ; |
| 5080 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5081 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5082 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5083 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5084 | pSMB->DataCount = 0; |
| 5085 | pSMB->DataOffset = 0; |
| 5086 | pSMB->SetupCount = 1; |
| 5087 | pSMB->Reserved3 = 0; |
| 5088 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5089 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5090 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5091 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5092 | |
| 5093 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5094 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5095 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5096 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5098 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5100 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | rc = -EIO; /* bad smb */ |
| 5102 | else { |
| 5103 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5104 | |
| 5105 | response_data = |
| 5106 | (FILE_SYSTEM_INFO |
| 5107 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5108 | data_offset); |
| 5109 | FSData->f_bsize = |
| 5110 | le32_to_cpu(response_data->BytesPerSector) * |
| 5111 | le32_to_cpu(response_data-> |
| 5112 | SectorsPerAllocationUnit); |
| 5113 | FSData->f_blocks = |
| 5114 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 5115 | FSData->f_bfree = FSData->f_bavail = |
| 5116 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5117 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 5118 | (unsigned long long)FSData->f_blocks, |
| 5119 | (unsigned long long)FSData->f_bfree, |
| 5120 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5121 | } |
| 5122 | } |
| 5123 | cifs_buf_release(pSMB); |
| 5124 | |
| 5125 | if (rc == -EAGAIN) |
| 5126 | goto QFSInfoRetry; |
| 5127 | |
| 5128 | return rc; |
| 5129 | } |
| 5130 | |
| 5131 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5132 | CIFSSMBQFSAttributeInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | { |
| 5134 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5135 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5136 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5137 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5138 | int rc = 0; |
| 5139 | int bytes_returned = 0; |
| 5140 | __u16 params, byte_count; |
| 5141 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5142 | cFYI(1, "In QFSAttributeInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | QFSAttributeRetry: |
| 5144 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5145 | (void **) &pSMBr); |
| 5146 | if (rc) |
| 5147 | return rc; |
| 5148 | |
| 5149 | params = 2; /* level */ |
| 5150 | pSMB->TotalDataCount = 0; |
| 5151 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5152 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5153 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | pSMB->MaxSetupCount = 0; |
| 5155 | pSMB->Reserved = 0; |
| 5156 | pSMB->Flags = 0; |
| 5157 | pSMB->Timeout = 0; |
| 5158 | pSMB->Reserved2 = 0; |
| 5159 | byte_count = params + 1 /* pad */ ; |
| 5160 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5161 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5162 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5163 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | pSMB->DataCount = 0; |
| 5165 | pSMB->DataOffset = 0; |
| 5166 | pSMB->SetupCount = 1; |
| 5167 | pSMB->Reserved3 = 0; |
| 5168 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5169 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5170 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5171 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5172 | |
| 5173 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5174 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5175 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5176 | cERROR(1, "Send error in QFSAttributeInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | } else { /* decode response */ |
| 5178 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5179 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5180 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5181 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | rc = -EIO; /* bad smb */ |
| 5183 | } else { |
| 5184 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5185 | response_data = |
| 5186 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5187 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5188 | data_offset); |
| 5189 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5190 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5191 | } |
| 5192 | } |
| 5193 | cifs_buf_release(pSMB); |
| 5194 | |
| 5195 | if (rc == -EAGAIN) |
| 5196 | goto QFSAttributeRetry; |
| 5197 | |
| 5198 | return rc; |
| 5199 | } |
| 5200 | |
| 5201 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5202 | CIFSSMBQFSDeviceInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | { |
| 5204 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5205 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5206 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5207 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5208 | int rc = 0; |
| 5209 | int bytes_returned = 0; |
| 5210 | __u16 params, byte_count; |
| 5211 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5212 | cFYI(1, "In QFSDeviceInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | QFSDeviceRetry: |
| 5214 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5215 | (void **) &pSMBr); |
| 5216 | if (rc) |
| 5217 | return rc; |
| 5218 | |
| 5219 | params = 2; /* level */ |
| 5220 | pSMB->TotalDataCount = 0; |
| 5221 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5222 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5223 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | pSMB->MaxSetupCount = 0; |
| 5225 | pSMB->Reserved = 0; |
| 5226 | pSMB->Flags = 0; |
| 5227 | pSMB->Timeout = 0; |
| 5228 | pSMB->Reserved2 = 0; |
| 5229 | byte_count = params + 1 /* pad */ ; |
| 5230 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5231 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5232 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5233 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | |
| 5235 | pSMB->DataCount = 0; |
| 5236 | pSMB->DataOffset = 0; |
| 5237 | pSMB->SetupCount = 1; |
| 5238 | pSMB->Reserved3 = 0; |
| 5239 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5240 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5241 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5243 | |
| 5244 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5245 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5246 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5247 | cFYI(1, "Send error in QFSDeviceInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | } else { /* decode response */ |
| 5249 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5250 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5251 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5252 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5253 | rc = -EIO; /* bad smb */ |
| 5254 | else { |
| 5255 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5256 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5257 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5258 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5259 | data_offset); |
| 5260 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5261 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | } |
| 5263 | } |
| 5264 | cifs_buf_release(pSMB); |
| 5265 | |
| 5266 | if (rc == -EAGAIN) |
| 5267 | goto QFSDeviceRetry; |
| 5268 | |
| 5269 | return rc; |
| 5270 | } |
| 5271 | |
| 5272 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5273 | CIFSSMBQFSUnixInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5274 | { |
| 5275 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5276 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5277 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5278 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5279 | int rc = 0; |
| 5280 | int bytes_returned = 0; |
| 5281 | __u16 params, byte_count; |
| 5282 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5283 | cFYI(1, "In QFSUnixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5284 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5285 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5286 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 | if (rc) |
| 5288 | return rc; |
| 5289 | |
| 5290 | params = 2; /* level */ |
| 5291 | pSMB->TotalDataCount = 0; |
| 5292 | pSMB->DataCount = 0; |
| 5293 | pSMB->DataOffset = 0; |
| 5294 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5295 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5296 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5297 | pSMB->MaxSetupCount = 0; |
| 5298 | pSMB->Reserved = 0; |
| 5299 | pSMB->Flags = 0; |
| 5300 | pSMB->Timeout = 0; |
| 5301 | pSMB->Reserved2 = 0; |
| 5302 | byte_count = params + 1 /* pad */ ; |
| 5303 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5304 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5305 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5306 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5307 | pSMB->SetupCount = 1; |
| 5308 | pSMB->Reserved3 = 0; |
| 5309 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5310 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5311 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5312 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5313 | |
| 5314 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5315 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5316 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5317 | cERROR(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | } else { /* decode response */ |
| 5319 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5320 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5321 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | rc = -EIO; /* bad smb */ |
| 5323 | } else { |
| 5324 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5325 | response_data = |
| 5326 | (FILE_SYSTEM_UNIX_INFO |
| 5327 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5328 | data_offset); |
| 5329 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5330 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5331 | } |
| 5332 | } |
| 5333 | cifs_buf_release(pSMB); |
| 5334 | |
| 5335 | if (rc == -EAGAIN) |
| 5336 | goto QFSUnixRetry; |
| 5337 | |
| 5338 | |
| 5339 | return rc; |
| 5340 | } |
| 5341 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5342 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5343 | CIFSSMBSetFSUnixInfo(const int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5344 | { |
| 5345 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5346 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5347 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5348 | int rc = 0; |
| 5349 | int bytes_returned = 0; |
| 5350 | __u16 params, param_offset, offset, byte_count; |
| 5351 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5352 | cFYI(1, "In SETFSUnixInfo"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5353 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5354 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5355 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5356 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5357 | if (rc) |
| 5358 | return rc; |
| 5359 | |
| 5360 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5361 | pSMB->MaxSetupCount = 0; |
| 5362 | pSMB->Reserved = 0; |
| 5363 | pSMB->Flags = 0; |
| 5364 | pSMB->Timeout = 0; |
| 5365 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5366 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5367 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5368 | offset = param_offset + params; |
| 5369 | |
| 5370 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5371 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5372 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5373 | pSMB->SetupCount = 1; |
| 5374 | pSMB->Reserved3 = 0; |
| 5375 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5376 | byte_count = 1 /* pad */ + params + 12; |
| 5377 | |
| 5378 | pSMB->DataCount = cpu_to_le16(12); |
| 5379 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5380 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5381 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5382 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5383 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5384 | |
| 5385 | /* Params. */ |
| 5386 | pSMB->FileNum = 0; |
| 5387 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5388 | |
| 5389 | /* Data. */ |
| 5390 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5391 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5392 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5393 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5394 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5395 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5396 | |
| 5397 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5398 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5399 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5400 | cERROR(1, "Send error in SETFSUnixInfo = %d", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5401 | } else { /* decode response */ |
| 5402 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5403 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5404 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5405 | } |
| 5406 | cifs_buf_release(pSMB); |
| 5407 | |
| 5408 | if (rc == -EAGAIN) |
| 5409 | goto SETFSUnixRetry; |
| 5410 | |
| 5411 | return rc; |
| 5412 | } |
| 5413 | |
| 5414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5415 | |
| 5416 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5417 | CIFSSMBQFSPosixInfo(const int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5418 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5419 | { |
| 5420 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5421 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5422 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5423 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5424 | int rc = 0; |
| 5425 | int bytes_returned = 0; |
| 5426 | __u16 params, byte_count; |
| 5427 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5428 | cFYI(1, "In QFSPosixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5429 | QFSPosixRetry: |
| 5430 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5431 | (void **) &pSMBr); |
| 5432 | if (rc) |
| 5433 | return rc; |
| 5434 | |
| 5435 | params = 2; /* level */ |
| 5436 | pSMB->TotalDataCount = 0; |
| 5437 | pSMB->DataCount = 0; |
| 5438 | pSMB->DataOffset = 0; |
| 5439 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5440 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5441 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5442 | pSMB->MaxSetupCount = 0; |
| 5443 | pSMB->Reserved = 0; |
| 5444 | pSMB->Flags = 0; |
| 5445 | pSMB->Timeout = 0; |
| 5446 | pSMB->Reserved2 = 0; |
| 5447 | byte_count = params + 1 /* pad */ ; |
| 5448 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5449 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5450 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5451 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | pSMB->SetupCount = 1; |
| 5453 | pSMB->Reserved3 = 0; |
| 5454 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5455 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5456 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5457 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5458 | |
| 5459 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5460 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5461 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5462 | cFYI(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5463 | } else { /* decode response */ |
| 5464 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5465 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5466 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 | rc = -EIO; /* bad smb */ |
| 5468 | } else { |
| 5469 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5470 | response_data = |
| 5471 | (FILE_SYSTEM_POSIX_INFO |
| 5472 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5473 | data_offset); |
| 5474 | FSData->f_bsize = |
| 5475 | le32_to_cpu(response_data->BlockSize); |
| 5476 | FSData->f_blocks = |
| 5477 | le64_to_cpu(response_data->TotalBlocks); |
| 5478 | FSData->f_bfree = |
| 5479 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5480 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5481 | FSData->f_bavail = FSData->f_bfree; |
| 5482 | } else { |
| 5483 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5484 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5485 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5486 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5488 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5489 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5491 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | } |
| 5493 | } |
| 5494 | cifs_buf_release(pSMB); |
| 5495 | |
| 5496 | if (rc == -EAGAIN) |
| 5497 | goto QFSPosixRetry; |
| 5498 | |
| 5499 | return rc; |
| 5500 | } |
| 5501 | |
| 5502 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5503 | /* We can not use write of zero bytes trick to |
| 5504 | set file size due to need for large file support. Also note that |
| 5505 | this SetPathInfo is preferred to SetFileInfo based method in next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | routine which is only needed to work around a sharing violation bug |
| 5507 | in Samba which this routine can run into */ |
| 5508 | |
| 5509 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5510 | CIFSSMBSetEOF(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5511 | __u64 size, bool SetAllocation, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5512 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5513 | { |
| 5514 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5515 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5516 | struct file_end_of_file_info *parm_data; |
| 5517 | int name_len; |
| 5518 | int rc = 0; |
| 5519 | int bytes_returned = 0; |
| 5520 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5521 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5522 | cFYI(1, "In SetEOF"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5523 | SetEOFRetry: |
| 5524 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5525 | (void **) &pSMBr); |
| 5526 | if (rc) |
| 5527 | return rc; |
| 5528 | |
| 5529 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5530 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5531 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5532 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | name_len++; /* trailing null */ |
| 5534 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5535 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 | name_len = strnlen(fileName, PATH_MAX); |
| 5537 | name_len++; /* trailing null */ |
| 5538 | strncpy(pSMB->FileName, fileName, name_len); |
| 5539 | } |
| 5540 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5541 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5543 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | pSMB->MaxSetupCount = 0; |
| 5545 | pSMB->Reserved = 0; |
| 5546 | pSMB->Flags = 0; |
| 5547 | pSMB->Timeout = 0; |
| 5548 | pSMB->Reserved2 = 0; |
| 5549 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5550 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5551 | offset = param_offset + params; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5552 | if (SetAllocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5553 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5554 | pSMB->InformationLevel = |
| 5555 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5556 | else |
| 5557 | pSMB->InformationLevel = |
| 5558 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5559 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5560 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5561 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5562 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5563 | else |
| 5564 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5565 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | } |
| 5567 | |
| 5568 | parm_data = |
| 5569 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5570 | offset); |
| 5571 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5572 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5573 | pSMB->SetupCount = 1; |
| 5574 | pSMB->Reserved3 = 0; |
| 5575 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5576 | byte_count = 3 /* pad */ + params + data_count; |
| 5577 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5578 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5579 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5580 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5581 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5582 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | parm_data->FileSize = cpu_to_le64(size); |
| 5584 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5585 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5586 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5587 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5588 | cFYI(1, "SetPathInfo (file size) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5589 | |
| 5590 | cifs_buf_release(pSMB); |
| 5591 | |
| 5592 | if (rc == -EAGAIN) |
| 5593 | goto SetEOFRetry; |
| 5594 | |
| 5595 | return rc; |
| 5596 | } |
| 5597 | |
| 5598 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5599 | CIFSSMBSetFileSize(const int xid, struct cifs_tcon *tcon, __u64 size, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5600 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | { |
| 5602 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5603 | struct file_end_of_file_info *parm_data; |
| 5604 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | __u16 params, param_offset, offset, byte_count, count; |
| 5606 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5607 | cFYI(1, "SetFileSize (via SetFileInfo) %lld", |
| 5608 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5609 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5611 | if (rc) |
| 5612 | return rc; |
| 5613 | |
| 5614 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5615 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | params = 6; |
| 5618 | pSMB->MaxSetupCount = 0; |
| 5619 | pSMB->Reserved = 0; |
| 5620 | pSMB->Flags = 0; |
| 5621 | pSMB->Timeout = 0; |
| 5622 | pSMB->Reserved2 = 0; |
| 5623 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5624 | offset = param_offset + params; |
| 5625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5626 | count = sizeof(struct file_end_of_file_info); |
| 5627 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5628 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5629 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5630 | pSMB->SetupCount = 1; |
| 5631 | pSMB->Reserved3 = 0; |
| 5632 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5633 | byte_count = 3 /* pad */ + params + count; |
| 5634 | pSMB->DataCount = cpu_to_le16(count); |
| 5635 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5636 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5637 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5638 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5639 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5640 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5641 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5643 | parm_data->FileSize = cpu_to_le64(size); |
| 5644 | pSMB->Fid = fid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5645 | if (SetAllocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5646 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5647 | pSMB->InformationLevel = |
| 5648 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5649 | else |
| 5650 | pSMB->InformationLevel = |
| 5651 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5652 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5653 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5654 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5655 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | else |
| 5657 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5658 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | } |
| 5660 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5661 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5662 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5663 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5664 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5665 | cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5666 | } |
| 5667 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5668 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5669 | since file handle passed in no longer valid */ |
| 5670 | |
| 5671 | return rc; |
| 5672 | } |
| 5673 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5674 | /* 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] | 5675 | an open handle, rather than by pathname - this is awkward due to |
| 5676 | potential access conflicts on the open, but it is unavoidable for these |
| 5677 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5678 | time and resort to the original setpathinfo level which takes the ancient |
| 5679 | DOS time format with 2 second granularity */ |
| 5680 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5681 | CIFSSMBSetFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5682 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | { |
| 5684 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | char *data_offset; |
| 5686 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | __u16 params, param_offset, offset, byte_count, count; |
| 5688 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5689 | cFYI(1, "Set Times (via SetFileInfo)"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5690 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5691 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | if (rc) |
| 5693 | return rc; |
| 5694 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5695 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5696 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | params = 6; |
| 5699 | pSMB->MaxSetupCount = 0; |
| 5700 | pSMB->Reserved = 0; |
| 5701 | pSMB->Flags = 0; |
| 5702 | pSMB->Timeout = 0; |
| 5703 | pSMB->Reserved2 = 0; |
| 5704 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5705 | offset = param_offset + params; |
| 5706 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5707 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5709 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5710 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5711 | /* BB find max SMB PDU from sess */ |
| 5712 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | pSMB->SetupCount = 1; |
| 5714 | pSMB->Reserved3 = 0; |
| 5715 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5716 | byte_count = 3 /* pad */ + params + count; |
| 5717 | pSMB->DataCount = cpu_to_le16(count); |
| 5718 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5719 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5720 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5721 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5722 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5723 | pSMB->Fid = fid; |
| 5724 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5725 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5726 | else |
| 5727 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5728 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5729 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5730 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5731 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5732 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5733 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5734 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5736 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5737 | since file handle passed in no longer valid */ |
| 5738 | |
| 5739 | return rc; |
| 5740 | } |
| 5741 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5742 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5743 | CIFSSMBSetFileDisposition(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5744 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5745 | { |
| 5746 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5747 | char *data_offset; |
| 5748 | int rc = 0; |
| 5749 | __u16 params, param_offset, offset, byte_count, count; |
| 5750 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5751 | cFYI(1, "Set File Disposition (via SetFileInfo)"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5752 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5753 | |
| 5754 | if (rc) |
| 5755 | return rc; |
| 5756 | |
| 5757 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5758 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5759 | |
| 5760 | params = 6; |
| 5761 | pSMB->MaxSetupCount = 0; |
| 5762 | pSMB->Reserved = 0; |
| 5763 | pSMB->Flags = 0; |
| 5764 | pSMB->Timeout = 0; |
| 5765 | pSMB->Reserved2 = 0; |
| 5766 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5767 | offset = param_offset + params; |
| 5768 | |
| 5769 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5770 | |
| 5771 | count = 1; |
| 5772 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5773 | /* BB find max SMB PDU from sess */ |
| 5774 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5775 | pSMB->SetupCount = 1; |
| 5776 | pSMB->Reserved3 = 0; |
| 5777 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5778 | byte_count = 3 /* pad */ + params + count; |
| 5779 | pSMB->DataCount = cpu_to_le16(count); |
| 5780 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5781 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5782 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5783 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5784 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5785 | pSMB->Fid = fid; |
| 5786 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5787 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5788 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5789 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5790 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5791 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5792 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5793 | cFYI(1, "Send error in SetFileDisposition = %d", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5794 | |
| 5795 | return rc; |
| 5796 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5797 | |
| 5798 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5799 | CIFSSMBSetPathInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5800 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5801 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5802 | { |
| 5803 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5804 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5805 | int name_len; |
| 5806 | int rc = 0; |
| 5807 | int bytes_returned = 0; |
| 5808 | char *data_offset; |
| 5809 | __u16 params, param_offset, offset, byte_count, count; |
| 5810 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5811 | cFYI(1, "In SetTimes"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5812 | |
| 5813 | SetTimesRetry: |
| 5814 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5815 | (void **) &pSMBr); |
| 5816 | if (rc) |
| 5817 | return rc; |
| 5818 | |
| 5819 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5820 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5821 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5822 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5823 | name_len++; /* trailing null */ |
| 5824 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5825 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | name_len = strnlen(fileName, PATH_MAX); |
| 5827 | name_len++; /* trailing null */ |
| 5828 | strncpy(pSMB->FileName, fileName, name_len); |
| 5829 | } |
| 5830 | |
| 5831 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5832 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5834 | /* BB find max SMB PDU from sess structure BB */ |
| 5835 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | pSMB->MaxSetupCount = 0; |
| 5837 | pSMB->Reserved = 0; |
| 5838 | pSMB->Flags = 0; |
| 5839 | pSMB->Timeout = 0; |
| 5840 | pSMB->Reserved2 = 0; |
| 5841 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5842 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5843 | offset = param_offset + params; |
| 5844 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5845 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5846 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5847 | pSMB->SetupCount = 1; |
| 5848 | pSMB->Reserved3 = 0; |
| 5849 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5850 | byte_count = 3 /* pad */ + params + count; |
| 5851 | |
| 5852 | pSMB->DataCount = cpu_to_le16(count); |
| 5853 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5854 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5855 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5856 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5857 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5858 | else |
| 5859 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5860 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5861 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5862 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5863 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5864 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5865 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5866 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5867 | cFYI(1, "SetPathInfo (times) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5868 | |
| 5869 | cifs_buf_release(pSMB); |
| 5870 | |
| 5871 | if (rc == -EAGAIN) |
| 5872 | goto SetTimesRetry; |
| 5873 | |
| 5874 | return rc; |
| 5875 | } |
| 5876 | |
| 5877 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5878 | /* Can be used to set attributes */ |
| 5879 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5880 | handling it anyway and NT4 was what we thought it would be needed for |
| 5881 | Do not delete it until we prove whether needed for Win9x though */ |
| 5882 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5883 | CIFSSMBSetAttrLegacy(int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5884 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5885 | { |
| 5886 | SETATTR_REQ *pSMB = NULL; |
| 5887 | SETATTR_RSP *pSMBr = NULL; |
| 5888 | int rc = 0; |
| 5889 | int bytes_returned; |
| 5890 | int name_len; |
| 5891 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5892 | cFYI(1, "In SetAttrLegacy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5893 | |
| 5894 | SetAttrLgcyRetry: |
| 5895 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5896 | (void **) &pSMBr); |
| 5897 | if (rc) |
| 5898 | return rc; |
| 5899 | |
| 5900 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5901 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5902 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 5903 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5904 | name_len++; /* trailing null */ |
| 5905 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5906 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5907 | name_len = strnlen(fileName, PATH_MAX); |
| 5908 | name_len++; /* trailing null */ |
| 5909 | strncpy(pSMB->fileName, fileName, name_len); |
| 5910 | } |
| 5911 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5912 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5913 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5914 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5915 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5916 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5917 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5918 | cFYI(1, "Error in LegacySetAttr = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5919 | |
| 5920 | cifs_buf_release(pSMB); |
| 5921 | |
| 5922 | if (rc == -EAGAIN) |
| 5923 | goto SetAttrLgcyRetry; |
| 5924 | |
| 5925 | return rc; |
| 5926 | } |
| 5927 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5928 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5929 | static void |
| 5930 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5931 | const struct cifs_unix_set_info_args *args) |
| 5932 | { |
| 5933 | u64 mode = args->mode; |
| 5934 | |
| 5935 | /* |
| 5936 | * Samba server ignores set of file size to zero due to bugs in some |
| 5937 | * older clients, but we should be precise - we use SetFileSize to |
| 5938 | * 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] | 5939 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5940 | * zero instead of -1 here |
| 5941 | */ |
| 5942 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5943 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5944 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5945 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5946 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
| 5947 | data_offset->Uid = cpu_to_le64(args->uid); |
| 5948 | data_offset->Gid = cpu_to_le64(args->gid); |
| 5949 | /* better to leave device as zero when it is */ |
| 5950 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5951 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5952 | data_offset->Permissions = cpu_to_le64(mode); |
| 5953 | |
| 5954 | if (S_ISREG(mode)) |
| 5955 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5956 | else if (S_ISDIR(mode)) |
| 5957 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 5958 | else if (S_ISLNK(mode)) |
| 5959 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 5960 | else if (S_ISCHR(mode)) |
| 5961 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 5962 | else if (S_ISBLK(mode)) |
| 5963 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 5964 | else if (S_ISFIFO(mode)) |
| 5965 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 5966 | else if (S_ISSOCK(mode)) |
| 5967 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5968 | } |
| 5969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5970 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5971 | CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5972 | const struct cifs_unix_set_info_args *args, |
| 5973 | u16 fid, u32 pid_of_opener) |
| 5974 | { |
| 5975 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5976 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5977 | int rc = 0; |
| 5978 | u16 params, param_offset, offset, byte_count, count; |
| 5979 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5980 | cFYI(1, "Set Unix Info (via SetFileInfo)"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5981 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5982 | |
| 5983 | if (rc) |
| 5984 | return rc; |
| 5985 | |
| 5986 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5987 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5988 | |
| 5989 | params = 6; |
| 5990 | pSMB->MaxSetupCount = 0; |
| 5991 | pSMB->Reserved = 0; |
| 5992 | pSMB->Flags = 0; |
| 5993 | pSMB->Timeout = 0; |
| 5994 | pSMB->Reserved2 = 0; |
| 5995 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5996 | offset = param_offset + params; |
| 5997 | |
| 5998 | data_offset = (FILE_UNIX_BASIC_INFO *) |
| 5999 | ((char *)(&pSMB->hdr.Protocol) + offset); |
| 6000 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 6001 | |
| 6002 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 6003 | /* BB find max SMB PDU from sess */ |
| 6004 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 6005 | pSMB->SetupCount = 1; |
| 6006 | pSMB->Reserved3 = 0; |
| 6007 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 6008 | byte_count = 3 /* pad */ + params + count; |
| 6009 | pSMB->DataCount = cpu_to_le16(count); |
| 6010 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6011 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6012 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6013 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6014 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6015 | pSMB->Fid = fid; |
| 6016 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6017 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6018 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6019 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6020 | |
| 6021 | cifs_fill_unix_set_info(data_offset, args); |
| 6022 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 6023 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6024 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6025 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6026 | |
| 6027 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 6028 | since file handle passed in no longer valid */ |
| 6029 | |
| 6030 | return rc; |
| 6031 | } |
| 6032 | |
| 6033 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6034 | CIFSSMBUnixSetPathInfo(const int xid, struct cifs_tcon *tcon, char *fileName, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6035 | const struct cifs_unix_set_info_args *args, |
| 6036 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6037 | { |
| 6038 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 6039 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 6040 | int name_len; |
| 6041 | int rc = 0; |
| 6042 | int bytes_returned = 0; |
| 6043 | FILE_UNIX_BASIC_INFO *data_offset; |
| 6044 | __u16 params, param_offset, offset, count, byte_count; |
| 6045 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6046 | cFYI(1, "In SetUID/GID/Mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6047 | setPermsRetry: |
| 6048 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6049 | (void **) &pSMBr); |
| 6050 | if (rc) |
| 6051 | return rc; |
| 6052 | |
| 6053 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6054 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6055 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6056 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6057 | name_len++; /* trailing null */ |
| 6058 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 6059 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6060 | name_len = strnlen(fileName, PATH_MAX); |
| 6061 | name_len++; /* trailing null */ |
| 6062 | strncpy(pSMB->FileName, fileName, name_len); |
| 6063 | } |
| 6064 | |
| 6065 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 6066 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6067 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6068 | /* BB find max SMB PDU from sess structure BB */ |
| 6069 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6070 | pSMB->MaxSetupCount = 0; |
| 6071 | pSMB->Reserved = 0; |
| 6072 | pSMB->Flags = 0; |
| 6073 | pSMB->Timeout = 0; |
| 6074 | pSMB->Reserved2 = 0; |
| 6075 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6076 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6077 | offset = param_offset + params; |
| 6078 | data_offset = |
| 6079 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 6080 | offset); |
| 6081 | memset(data_offset, 0, count); |
| 6082 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6083 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6084 | pSMB->SetupCount = 1; |
| 6085 | pSMB->Reserved3 = 0; |
| 6086 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6087 | byte_count = 3 /* pad */ + params + count; |
| 6088 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6089 | pSMB->DataCount = cpu_to_le16(count); |
| 6090 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6091 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6092 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6093 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6094 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6095 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6096 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6097 | |
| 6098 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6099 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6100 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6101 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6102 | cFYI(1, "SetPathInfo (perms) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6103 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6104 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6105 | if (rc == -EAGAIN) |
| 6106 | goto setPermsRetry; |
| 6107 | return rc; |
| 6108 | } |
| 6109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6110 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6111 | /* |
| 6112 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 6113 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 6114 | * it looks for that attribute name and stuffs that value into the EAData |
| 6115 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 6116 | * buffer. In both cases, the return value is either the length of the |
| 6117 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 6118 | * the data isn't copied to it, but the length is returned. |
| 6119 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6120 | ssize_t |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6121 | CIFSSMBQAllEAs(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6122 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6123 | char *EAData, size_t buf_size, |
| 6124 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | { |
| 6126 | /* BB assumes one setup word */ |
| 6127 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6128 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 6129 | int rc = 0; |
| 6130 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6131 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6132 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6133 | struct fea *temp_fea; |
| 6134 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6135 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6136 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6137 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6138 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6139 | cFYI(1, "In Query All EAs path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6140 | QAllEAsRetry: |
| 6141 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6142 | (void **) &pSMBr); |
| 6143 | if (rc) |
| 6144 | return rc; |
| 6145 | |
| 6146 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6147 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6148 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6149 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6150 | list_len++; /* trailing null */ |
| 6151 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6153 | list_len = strnlen(searchName, PATH_MAX); |
| 6154 | list_len++; /* trailing null */ |
| 6155 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6156 | } |
| 6157 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6158 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6159 | pSMB->TotalDataCount = 0; |
| 6160 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6161 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6162 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6163 | pSMB->MaxSetupCount = 0; |
| 6164 | pSMB->Reserved = 0; |
| 6165 | pSMB->Flags = 0; |
| 6166 | pSMB->Timeout = 0; |
| 6167 | pSMB->Reserved2 = 0; |
| 6168 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6169 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6170 | pSMB->DataCount = 0; |
| 6171 | pSMB->DataOffset = 0; |
| 6172 | pSMB->SetupCount = 1; |
| 6173 | pSMB->Reserved3 = 0; |
| 6174 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6175 | byte_count = params + 1 /* pad */ ; |
| 6176 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6177 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6178 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6179 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6180 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6181 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6182 | |
| 6183 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6184 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6185 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6186 | cFYI(1, "Send error in QueryAllEAs = %d", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6187 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6189 | |
| 6190 | |
| 6191 | /* BB also check enough total bytes returned */ |
| 6192 | /* BB we need to improve the validity checking |
| 6193 | of these trans2 responses */ |
| 6194 | |
| 6195 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6196 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6197 | rc = -EIO; /* bad smb */ |
| 6198 | goto QAllEAsOut; |
| 6199 | } |
| 6200 | |
| 6201 | /* check that length of list is not more than bcc */ |
| 6202 | /* check that each entry does not go beyond length |
| 6203 | of list */ |
| 6204 | /* check that each element of each entry does not |
| 6205 | go beyond end of list */ |
| 6206 | /* validate_trans2_offsets() */ |
| 6207 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6208 | |
| 6209 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6210 | ea_response_data = (struct fealist *) |
| 6211 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6212 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6213 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6214 | cFYI(1, "ea length %d", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6215 | if (list_len <= 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6216 | cFYI(1, "empty EA list returned from server"); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6217 | goto QAllEAsOut; |
| 6218 | } |
| 6219 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6220 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6221 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6222 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6223 | cFYI(1, "EA list appears to go beyond SMB"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6224 | rc = -EIO; |
| 6225 | goto QAllEAsOut; |
| 6226 | } |
| 6227 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6228 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6229 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6230 | temp_fea = ea_response_data->list; |
| 6231 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6232 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6233 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6234 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6235 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6236 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6237 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6238 | /* make sure we can read name_len and value_len */ |
| 6239 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6240 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6241 | rc = -EIO; |
| 6242 | goto QAllEAsOut; |
| 6243 | } |
| 6244 | |
| 6245 | name_len = temp_fea->name_len; |
| 6246 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6247 | list_len -= name_len + 1 + value_len; |
| 6248 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6249 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6250 | rc = -EIO; |
| 6251 | goto QAllEAsOut; |
| 6252 | } |
| 6253 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6254 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6255 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6256 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6257 | temp_ptr += name_len + 1; |
| 6258 | rc = value_len; |
| 6259 | if (buf_size == 0) |
| 6260 | goto QAllEAsOut; |
| 6261 | if ((size_t)value_len > buf_size) { |
| 6262 | rc = -ERANGE; |
| 6263 | goto QAllEAsOut; |
| 6264 | } |
| 6265 | memcpy(EAData, temp_ptr, value_len); |
| 6266 | goto QAllEAsOut; |
| 6267 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6268 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6269 | /* account for prefix user. and trailing null */ |
| 6270 | rc += (5 + 1 + name_len); |
| 6271 | if (rc < (int) buf_size) { |
| 6272 | memcpy(EAData, "user.", 5); |
| 6273 | EAData += 5; |
| 6274 | memcpy(EAData, temp_ptr, name_len); |
| 6275 | EAData += name_len; |
| 6276 | /* null terminate name */ |
| 6277 | *EAData = 0; |
| 6278 | ++EAData; |
| 6279 | } else if (buf_size == 0) { |
| 6280 | /* skip copy - calc size only */ |
| 6281 | } else { |
| 6282 | /* stop before overrun buffer */ |
| 6283 | rc = -ERANGE; |
| 6284 | break; |
| 6285 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6286 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6287 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6288 | temp_fea = (struct fea *)temp_ptr; |
| 6289 | } |
| 6290 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6291 | /* didn't find the named attribute */ |
| 6292 | if (ea_name) |
| 6293 | rc = -ENODATA; |
| 6294 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6295 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6296 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6297 | if (rc == -EAGAIN) |
| 6298 | goto QAllEAsRetry; |
| 6299 | |
| 6300 | return (ssize_t)rc; |
| 6301 | } |
| 6302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6303 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6304 | CIFSSMBSetEA(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6305 | const char *ea_name, const void *ea_value, |
| 6306 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 6307 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6308 | { |
| 6309 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6310 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6311 | struct fealist *parm_data; |
| 6312 | int name_len; |
| 6313 | int rc = 0; |
| 6314 | int bytes_returned = 0; |
| 6315 | __u16 params, param_offset, byte_count, offset, count; |
| 6316 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6317 | cFYI(1, "In SetEA"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6318 | SetEARetry: |
| 6319 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6320 | (void **) &pSMBr); |
| 6321 | if (rc) |
| 6322 | return rc; |
| 6323 | |
| 6324 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6325 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6326 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6327 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6328 | name_len++; /* trailing null */ |
| 6329 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6330 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6331 | name_len = strnlen(fileName, PATH_MAX); |
| 6332 | name_len++; /* trailing null */ |
| 6333 | strncpy(pSMB->FileName, fileName, name_len); |
| 6334 | } |
| 6335 | |
| 6336 | params = 6 + name_len; |
| 6337 | |
| 6338 | /* done calculating parms using name_len of file name, |
| 6339 | now use name_len to calculate length of ea name |
| 6340 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6341 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6342 | name_len = 0; |
| 6343 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6344 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | |
Steve French | dae5dbdb | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6346 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6347 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6348 | /* BB find max SMB PDU from sess */ |
| 6349 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6350 | pSMB->MaxSetupCount = 0; |
| 6351 | pSMB->Reserved = 0; |
| 6352 | pSMB->Flags = 0; |
| 6353 | pSMB->Timeout = 0; |
| 6354 | pSMB->Reserved2 = 0; |
| 6355 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6356 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6357 | offset = param_offset + params; |
| 6358 | pSMB->InformationLevel = |
| 6359 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6360 | |
| 6361 | parm_data = |
| 6362 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 6363 | offset); |
| 6364 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6365 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6366 | pSMB->SetupCount = 1; |
| 6367 | pSMB->Reserved3 = 0; |
| 6368 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6369 | byte_count = 3 /* pad */ + params + count; |
| 6370 | pSMB->DataCount = cpu_to_le16(count); |
| 6371 | parm_data->list_len = cpu_to_le32(count); |
| 6372 | parm_data->list[0].EA_flags = 0; |
| 6373 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6374 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6375 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6376 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6377 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6378 | parm_data->list[0].name[name_len] = 0; |
| 6379 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6380 | /* caller ensures that ea_value_len is less than 64K but |
| 6381 | we need to ensure that it fits within the smb */ |
| 6382 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6383 | /*BB add length check to see if it would fit in |
| 6384 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6385 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6386 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6387 | memcpy(parm_data->list[0].name+name_len+1, |
| 6388 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6389 | |
| 6390 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6391 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6392 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6393 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6394 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6395 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6396 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6397 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6398 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6399 | cFYI(1, "SetPathInfo (EA) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6400 | |
| 6401 | cifs_buf_release(pSMB); |
| 6402 | |
| 6403 | if (rc == -EAGAIN) |
| 6404 | goto SetEARetry; |
| 6405 | |
| 6406 | return rc; |
| 6407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6408 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6409 | |
| 6410 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 6411 | /* |
| 6412 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 6413 | * to allow network clients (such as Windows) to display updated |
| 6414 | * lists of files in directory listings automatically when |
| 6415 | * files are added by one user when another user has the |
| 6416 | * same directory open on their desktop. The Linux cifs kernel |
| 6417 | * client hooked into the kernel side of this interface for |
| 6418 | * the same reason, but ironically when the VFS moved from |
| 6419 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 6420 | * network file system clients (the most obvious use case |
| 6421 | * for notify interfaces is when multiple users can update |
| 6422 | * the contents of the same directory - exactly what network |
| 6423 | * file systems can do) although the server (Samba) could |
| 6424 | * still use it. For the short term we leave the worker |
| 6425 | * function ifdeffed out (below) until inotify is fixed |
| 6426 | * in the VFS to make it easier to plug in network file |
| 6427 | * system clients. If inotify turns out to be permanently |
| 6428 | * incompatible for network fs clients, we could instead simply |
| 6429 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 6430 | */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6431 | int CIFSSMBNotify(const int xid, struct cifs_tcon *tcon, |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6432 | const int notify_subdirs, const __u16 netfid, |
| 6433 | __u32 filter, struct file *pfile, int multishot, |
| 6434 | const struct nls_table *nls_codepage) |
| 6435 | { |
| 6436 | int rc = 0; |
| 6437 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 6438 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 6439 | struct dir_notify_req *dnotify_req; |
| 6440 | int bytes_returned; |
| 6441 | |
| 6442 | cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid); |
| 6443 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 6444 | (void **) &pSMBr); |
| 6445 | if (rc) |
| 6446 | return rc; |
| 6447 | |
| 6448 | pSMB->TotalParameterCount = 0 ; |
| 6449 | pSMB->TotalDataCount = 0; |
| 6450 | pSMB->MaxParameterCount = cpu_to_le32(2); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6451 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6452 | pSMB->MaxSetupCount = 4; |
| 6453 | pSMB->Reserved = 0; |
| 6454 | pSMB->ParameterOffset = 0; |
| 6455 | pSMB->DataCount = 0; |
| 6456 | pSMB->DataOffset = 0; |
| 6457 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 6458 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 6459 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6460 | if (notify_subdirs) |
| 6461 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 6462 | pSMB->Reserved2 = 0; |
| 6463 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 6464 | pSMB->Fid = netfid; /* file handle always le */ |
| 6465 | pSMB->ByteCount = 0; |
| 6466 | |
| 6467 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6468 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 6469 | CIFS_ASYNC_OP); |
| 6470 | if (rc) { |
| 6471 | cFYI(1, "Error in Notify = %d", rc); |
| 6472 | } else { |
| 6473 | /* Add file to outstanding requests */ |
| 6474 | /* BB change to kmem cache alloc */ |
| 6475 | dnotify_req = kmalloc( |
| 6476 | sizeof(struct dir_notify_req), |
| 6477 | GFP_KERNEL); |
| 6478 | if (dnotify_req) { |
| 6479 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 6480 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 6481 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 6482 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 6483 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 6484 | dnotify_req->netfid = netfid; |
| 6485 | dnotify_req->pfile = pfile; |
| 6486 | dnotify_req->filter = filter; |
| 6487 | dnotify_req->multishot = multishot; |
| 6488 | spin_lock(&GlobalMid_Lock); |
| 6489 | list_add_tail(&dnotify_req->lhead, |
| 6490 | &GlobalDnotifyReqList); |
| 6491 | spin_unlock(&GlobalMid_Lock); |
| 6492 | } else |
| 6493 | rc = -ENOMEM; |
| 6494 | } |
| 6495 | cifs_buf_release(pSMB); |
| 6496 | return rc; |
| 6497 | } |
| 6498 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |