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 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 89 | /* |
| 90 | * Mark as invalid, all open files on tree connections since they |
| 91 | * were closed when session to server was lost. |
| 92 | */ |
| 93 | void |
| 94 | cifs_mark_open_files_invalid(struct cifs_tcon *tcon) |
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 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 100 | /* list all files open on tree connection and mark them invalid */ |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 101 | spin_lock(&tcon->open_file_lock); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 102 | list_for_each_safe(tmp, tmp1, &tcon->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 | } |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 107 | spin_unlock(&tcon->open_file_lock); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 108 | /* |
| 109 | * BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 110 | * to this tcon. |
| 111 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 114 | /* reconnect the socket, tcon, and smb session if needed */ |
| 115 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 116 | cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 117 | { |
Jeff Layton | c4a5534 | 2011-07-28 12:40:36 -0400 | [diff] [blame] | 118 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 119 | struct cifs_ses *ses; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 120 | struct TCP_Server_Info *server; |
| 121 | struct nls_table *nls_codepage; |
| 122 | |
| 123 | /* |
| 124 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 125 | * tcp and smb session status done differently for those three - in the |
| 126 | * calling routine |
| 127 | */ |
| 128 | if (!tcon) |
| 129 | return 0; |
| 130 | |
| 131 | ses = tcon->ses; |
| 132 | server = ses->server; |
| 133 | |
| 134 | /* |
| 135 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 136 | * have tcon) are allowed as we start force umount |
| 137 | */ |
| 138 | if (tcon->tidStatus == CifsExiting) { |
| 139 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 140 | smb_command != SMB_COM_OPEN_ANDX && |
| 141 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 142 | cifs_dbg(FYI, "can not send cmd %d while umounting\n", |
| 143 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 144 | return -ENODEV; |
| 145 | } |
| 146 | } |
| 147 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 148 | /* |
| 149 | * Give demultiplex thread up to 10 seconds to reconnect, should be |
| 150 | * greater than cifs socket timeout which is 7 seconds |
| 151 | */ |
| 152 | while (server->tcpStatus == CifsNeedReconnect) { |
| 153 | wait_event_interruptible_timeout(server->response_q, |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 154 | (server->tcpStatus != CifsNeedReconnect), 10 * HZ); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 155 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 156 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 157 | if (server->tcpStatus != CifsNeedReconnect) |
| 158 | break; |
| 159 | |
| 160 | /* |
| 161 | * on "soft" mounts we wait once. Hard mounts keep |
| 162 | * retrying until process is killed or server comes |
| 163 | * back on-line |
| 164 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 165 | if (!tcon->retry) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 166 | cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 167 | return -EHOSTDOWN; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 172 | return 0; |
| 173 | |
| 174 | nls_codepage = load_nls_default(); |
| 175 | |
| 176 | /* |
| 177 | * need to prevent multiple threads trying to simultaneously |
| 178 | * reconnect the same SMB session |
| 179 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 180 | mutex_lock(&ses->session_mutex); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 181 | rc = cifs_negotiate_protocol(0, ses); |
| 182 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 183 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 184 | |
| 185 | /* do we need to reconnect tcon? */ |
| 186 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 187 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 188 | goto out; |
| 189 | } |
| 190 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 191 | cifs_mark_open_files_invalid(tcon); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 192 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 193 | mutex_unlock(&ses->session_mutex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 194 | cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 195 | |
| 196 | if (rc) |
| 197 | goto out; |
| 198 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 199 | atomic_inc(&tconInfoReconnectCount); |
| 200 | |
| 201 | /* tell server Unix caps we support */ |
| 202 | if (ses->capabilities & CAP_UNIX) |
| 203 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 204 | |
| 205 | /* |
| 206 | * Removed call to reopen open files here. It is safer (and faster) to |
| 207 | * reopen files one at a time as needed in read and write. |
| 208 | * |
| 209 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 210 | */ |
| 211 | |
| 212 | out: |
| 213 | /* |
| 214 | * Check if handle based operation so we know whether we can continue |
| 215 | * or not without returning to caller to reset file handle |
| 216 | */ |
| 217 | switch (smb_command) { |
| 218 | case SMB_COM_READ_ANDX: |
| 219 | case SMB_COM_WRITE_ANDX: |
| 220 | case SMB_COM_CLOSE: |
| 221 | case SMB_COM_FIND_CLOSE2: |
| 222 | case SMB_COM_LOCKING_ANDX: |
| 223 | rc = -EAGAIN; |
| 224 | } |
| 225 | |
| 226 | unload_nls(nls_codepage); |
| 227 | return rc; |
| 228 | } |
| 229 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 230 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 231 | SMB information in the SMB header. If the return code is zero, this |
| 232 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 234 | small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 235 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 237 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 239 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 240 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | return rc; |
| 242 | |
| 243 | *request_buf = cifs_small_buf_get(); |
| 244 | if (*request_buf == NULL) { |
| 245 | /* BB should we add a retry in here if not a writepage? */ |
| 246 | return -ENOMEM; |
| 247 | } |
| 248 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 249 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 250 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 252 | if (tcon != NULL) |
| 253 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 254 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 255 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 258 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 259 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 260 | struct cifs_ses *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 261 | { |
| 262 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 263 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 264 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 265 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 266 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 267 | return rc; |
| 268 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 269 | buffer = (struct smb_hdr *)*request_buf; |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 270 | buffer->Mid = get_next_mid(ses->server); |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 271 | if (ses->capabilities & CAP_UNICODE) |
| 272 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 273 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 274 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 275 | |
| 276 | /* uid, tid can stay at zero as set in header assemble */ |
| 277 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 278 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 279 | this function is used after 1st of session setup requests */ |
| 280 | |
| 281 | return rc; |
| 282 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 285 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 286 | __smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 287 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | *request_buf = cifs_buf_get(); |
| 290 | if (*request_buf == NULL) { |
| 291 | /* BB should we add a retry in here if not a writepage? */ |
| 292 | return -ENOMEM; |
| 293 | } |
| 294 | /* Although the original thought was we needed the response buf for */ |
| 295 | /* potential retries of smb operations it turns out we can determine */ |
| 296 | /* from the mid flags when the request buffer can be resent without */ |
| 297 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 298 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 299 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 302 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 304 | if (tcon != NULL) |
| 305 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 306 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 311 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 312 | smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 313 | void **request_buf, void **response_buf) |
| 314 | { |
| 315 | int rc; |
| 316 | |
| 317 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 318 | if (rc) |
| 319 | return rc; |
| 320 | |
| 321 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 322 | } |
| 323 | |
| 324 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 325 | 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] | 326 | void **request_buf, void **response_buf) |
| 327 | { |
| 328 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 329 | return -EHOSTDOWN; |
| 330 | |
| 331 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 334 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 336 | unsigned int total_size; |
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 | /* check for plausible wct */ |
| 339 | if (pSMB->hdr.WordCount < 10) |
| 340 | goto vt2_err; |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 343 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 344 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 345 | goto vt2_err; |
| 346 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 347 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 348 | if (total_size >= 512) |
| 349 | goto vt2_err; |
| 350 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 351 | /* check that bcc is at least as big as parms + data, and that it is |
| 352 | * less than negotiated smb buffer |
| 353 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 354 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 355 | if (total_size > get_bcc(&pSMB->hdr) || |
| 356 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 357 | goto vt2_err; |
| 358 | |
| 359 | return 0; |
| 360 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 361 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 363 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 365 | |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 366 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 367 | decode_ext_sec_blob(struct cifs_ses *ses, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 368 | { |
| 369 | int rc = 0; |
| 370 | u16 count; |
| 371 | char *guid = pSMBr->u.extended_response.GUID; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 372 | struct TCP_Server_Info *server = ses->server; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 373 | |
| 374 | count = get_bcc(&pSMBr->hdr); |
| 375 | if (count < SMB1_CLIENT_GUID_SIZE) |
| 376 | return -EIO; |
| 377 | |
| 378 | spin_lock(&cifs_tcp_ses_lock); |
| 379 | if (server->srv_count > 1) { |
| 380 | spin_unlock(&cifs_tcp_ses_lock); |
| 381 | if (memcmp(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE) != 0) { |
| 382 | cifs_dbg(FYI, "server UID changed\n"); |
| 383 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 384 | } |
| 385 | } else { |
| 386 | spin_unlock(&cifs_tcp_ses_lock); |
| 387 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 388 | } |
| 389 | |
| 390 | if (count == SMB1_CLIENT_GUID_SIZE) { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 391 | server->sec_ntlmssp = true; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 392 | } else { |
| 393 | count -= SMB1_CLIENT_GUID_SIZE; |
| 394 | rc = decode_negTokenInit( |
| 395 | pSMBr->u.extended_response.SecurityBlob, count, server); |
| 396 | if (rc != 1) |
| 397 | return -EINVAL; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 403 | int |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 404 | cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required) |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 405 | { |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 406 | bool srv_sign_required = server->sec_mode & server->vals->signing_required; |
| 407 | bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled; |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 408 | bool mnt_sign_enabled = global_secflags & CIFSSEC_MAY_SIGN; |
| 409 | |
| 410 | /* |
| 411 | * Is signing required by mnt options? If not then check |
| 412 | * global_secflags to see if it is there. |
| 413 | */ |
| 414 | if (!mnt_sign_required) |
| 415 | mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) == |
| 416 | CIFSSEC_MUST_SIGN); |
| 417 | |
| 418 | /* |
| 419 | * If signing is required then it's automatically enabled too, |
| 420 | * otherwise, check to see if the secflags allow it. |
| 421 | */ |
| 422 | mnt_sign_enabled = mnt_sign_required ? mnt_sign_required : |
| 423 | (global_secflags & CIFSSEC_MAY_SIGN); |
| 424 | |
| 425 | /* If server requires signing, does client allow it? */ |
| 426 | if (srv_sign_required) { |
| 427 | if (!mnt_sign_enabled) { |
| 428 | cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!"); |
| 429 | return -ENOTSUPP; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 430 | } |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 431 | server->sign = true; |
| 432 | } |
| 433 | |
| 434 | /* If client requires signing, does server allow it? */ |
| 435 | if (mnt_sign_required) { |
| 436 | if (!srv_sign_enabled) { |
| 437 | cifs_dbg(VFS, "Server does not support signing!"); |
| 438 | return -ENOTSUPP; |
| 439 | } |
| 440 | server->sign = true; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | return 0; |
| 444 | } |
| 445 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 446 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 447 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 448 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 449 | { |
| 450 | __s16 tmp; |
| 451 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
| 452 | |
| 453 | if (server->dialect != LANMAN_PROT && server->dialect != LANMAN2_PROT) |
| 454 | return -EOPNOTSUPP; |
| 455 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 456 | server->sec_mode = le16_to_cpu(rsp->SecurityMode); |
| 457 | server->maxReq = min_t(unsigned int, |
| 458 | le16_to_cpu(rsp->MaxMpxCount), |
| 459 | cifs_max_pending); |
| 460 | set_credits(server, server->maxReq); |
| 461 | server->maxBuf = le16_to_cpu(rsp->MaxBufSize); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 462 | /* even though we do not use raw we might as well set this |
| 463 | accurately, in case we ever find a need for it */ |
| 464 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
| 465 | server->max_rw = 0xFF00; |
| 466 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 467 | } else { |
| 468 | server->max_rw = 0;/* do not need to use raw anyway */ |
| 469 | server->capabilities = CAP_MPX_MODE; |
| 470 | } |
| 471 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
| 472 | if (tmp == -1) { |
| 473 | /* OS/2 often does not set timezone therefore |
| 474 | * we must use server time to calc time zone. |
| 475 | * Could deviate slightly from the right zone. |
| 476 | * Smallest defined timezone difference is 15 minutes |
| 477 | * (i.e. Nepal). Rounding up/down is done to match |
| 478 | * this requirement. |
| 479 | */ |
| 480 | int val, seconds, remain, result; |
| 481 | struct timespec ts, utc; |
| 482 | utc = CURRENT_TIME; |
| 483 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 484 | rsp->SrvTime.Time, 0); |
| 485 | cifs_dbg(FYI, "SrvTime %d sec since 1970 (utc: %d) diff: %d\n", |
| 486 | (int)ts.tv_sec, (int)utc.tv_sec, |
| 487 | (int)(utc.tv_sec - ts.tv_sec)); |
| 488 | val = (int)(utc.tv_sec - ts.tv_sec); |
| 489 | seconds = abs(val); |
| 490 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
| 491 | remain = seconds % MIN_TZ_ADJ; |
| 492 | if (remain >= (MIN_TZ_ADJ / 2)) |
| 493 | result += MIN_TZ_ADJ; |
| 494 | if (val < 0) |
| 495 | result = -result; |
| 496 | server->timeAdj = result; |
| 497 | } else { |
| 498 | server->timeAdj = (int)tmp; |
| 499 | server->timeAdj *= 60; /* also in seconds */ |
| 500 | } |
| 501 | cifs_dbg(FYI, "server->timeAdj: %d seconds\n", server->timeAdj); |
| 502 | |
| 503 | |
| 504 | /* BB get server time for time conversions and add |
| 505 | code to use it and timezone since this is not UTC */ |
| 506 | |
| 507 | if (rsp->EncryptionKeyLength == |
| 508 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
| 509 | memcpy(server->cryptkey, rsp->EncryptionKey, |
| 510 | CIFS_CRYPTO_KEY_SIZE); |
| 511 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
| 512 | return -EIO; /* need cryptkey unless plain text */ |
| 513 | } |
| 514 | |
| 515 | cifs_dbg(FYI, "LANMAN negotiated\n"); |
| 516 | return 0; |
| 517 | } |
| 518 | #else |
| 519 | static inline int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 520 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 521 | { |
| 522 | cifs_dbg(VFS, "mount failed, cifs module not built with CIFS_WEAK_PW_HASH support\n"); |
| 523 | return -EOPNOTSUPP; |
| 524 | } |
| 525 | #endif |
| 526 | |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 527 | static bool |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 528 | should_set_ext_sec_flag(enum securityEnum sectype) |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 529 | { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 530 | switch (sectype) { |
| 531 | case RawNTLMSSP: |
| 532 | case Kerberos: |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 533 | return true; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 534 | case Unspecified: |
| 535 | if (global_secflags & |
| 536 | (CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)) |
| 537 | return true; |
| 538 | /* Fallthrough */ |
| 539 | default: |
| 540 | return false; |
| 541 | } |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 542 | } |
| 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | int |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 545 | CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | { |
| 547 | NEGOTIATE_REQ *pSMB; |
| 548 | NEGOTIATE_RSP *pSMBr; |
| 549 | int rc = 0; |
| 550 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 551 | int i; |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 552 | struct TCP_Server_Info *server = ses->server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | u16 count; |
| 554 | |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 555 | if (!server) { |
| 556 | WARN(1, "%s: server is NULL!\n", __func__); |
| 557 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 561 | (void **) &pSMB, (void **) &pSMBr); |
| 562 | if (rc) |
| 563 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 564 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 565 | pSMB->hdr.Mid = get_next_mid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 566 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 567 | |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 568 | if (should_set_ext_sec_flag(ses->sectype)) { |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 569 | cifs_dbg(FYI, "Requesting extended security."); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 570 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 571 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 572 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 573 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 574 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 575 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 576 | count += strlen(protocols[i].name) + 1; |
| 577 | /* null at end of source and target buffers anyway */ |
| 578 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 579 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | pSMB->ByteCount = cpu_to_le16(count); |
| 581 | |
| 582 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 583 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 584 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 585 | goto neg_err_exit; |
| 586 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 587 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 588 | cifs_dbg(FYI, "Dialect: %d\n", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 589 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 590 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 591 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 592 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 593 | could not negotiate a common dialect */ |
| 594 | rc = -EOPNOTSUPP; |
| 595 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 596 | } else if (pSMBr->hdr.WordCount == 13) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 597 | server->negflavor = CIFS_NEGFLAVOR_LANMAN; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 598 | rc = decode_lanman_negprot_rsp(server, pSMBr); |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 599 | goto signing_check; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 600 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 601 | /* unknown wct */ |
| 602 | rc = -EOPNOTSUPP; |
| 603 | goto neg_err_exit; |
| 604 | } |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 605 | /* else wct == 17, NTLM or better */ |
| 606 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 607 | server->sec_mode = pSMBr->SecurityMode; |
| 608 | if ((server->sec_mode & SECMODE_USER) == 0) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 609 | cifs_dbg(FYI, "share mode security\n"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 610 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 611 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 612 | little endian */ |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 613 | server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), |
| 614 | cifs_max_pending); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 615 | set_credits(server, server->maxReq); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 616 | /* probably no need to store and check maxvcs */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 617 | server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 618 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 619 | cifs_dbg(NOISY, "Max buf = %d\n", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 620 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 621 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 622 | server->timeAdj *= 60; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 623 | |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 624 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
| 625 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 626 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 627 | CIFS_CRYPTO_KEY_SIZE); |
Noel Power | f291095 | 2015-05-27 09:22:10 +0100 | [diff] [blame] | 628 | } else if (pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC || |
| 629 | server->capabilities & CAP_EXTENDED_SECURITY) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 630 | server->negflavor = CIFS_NEGFLAVOR_EXTENDED; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 631 | rc = decode_ext_sec_blob(ses, pSMBr); |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 632 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 633 | rc = -EIO; /* no crypt key only if plain text pwd */ |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 634 | } else { |
| 635 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 636 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 637 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 638 | |
| 639 | signing_check: |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 640 | if (!rc) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 641 | rc = cifs_enable_signing(server, ses->sign); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 642 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 643 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 644 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 645 | cifs_dbg(FYI, "negprot rc %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | return rc; |
| 647 | } |
| 648 | |
| 649 | int |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 650 | CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
| 652 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 655 | cifs_dbg(FYI, "In tree disconnect\n"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 656 | |
| 657 | /* BB: do we need to check this? These should never be NULL. */ |
| 658 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 659 | return -EIO; |
| 660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 662 | * No need to return error on this operation if tid invalidated and |
| 663 | * closed on server already e.g. due to tcp session crashing. Also, |
| 664 | * the tcon is no longer on the list, so no need to take lock before |
| 665 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 667 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 668 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 670 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 671 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 672 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 674 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 675 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 677 | cifs_dbg(FYI, "Tree disconnect failed %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 679 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 680 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | if (rc == -EAGAIN) |
| 682 | rc = 0; |
| 683 | |
| 684 | return rc; |
| 685 | } |
| 686 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 687 | /* |
| 688 | * This is a no-op for now. We're not really interested in the reply, but |
| 689 | * rather in the fact that the server sent one and that server->lstrp |
| 690 | * gets updated. |
| 691 | * |
| 692 | * FIXME: maybe we should consider checking that the reply matches request? |
| 693 | */ |
| 694 | static void |
| 695 | cifs_echo_callback(struct mid_q_entry *mid) |
| 696 | { |
| 697 | struct TCP_Server_Info *server = mid->callback_data; |
| 698 | |
Christopher Oo | 5fb4e28 | 2015-06-25 16:10:48 -0700 | [diff] [blame] | 699 | mutex_lock(&server->srv_mutex); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 700 | DeleteMidQEntry(mid); |
Christopher Oo | 5fb4e28 | 2015-06-25 16:10:48 -0700 | [diff] [blame] | 701 | mutex_unlock(&server->srv_mutex); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 702 | add_credits(server, 1, CIFS_ECHO_OP); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | int |
| 706 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 707 | { |
| 708 | ECHO_REQ *smb; |
| 709 | int rc = 0; |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 710 | struct kvec iov; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 711 | struct smb_rqst rqst = { .rq_iov = &iov, |
| 712 | .rq_nvec = 1 }; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 713 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 714 | cifs_dbg(FYI, "In echo request\n"); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 715 | |
| 716 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 717 | if (rc) |
| 718 | return rc; |
| 719 | |
Steve French | 2ac2ad9 | 2017-05-02 13:35:20 -0500 | [diff] [blame] | 720 | if (server->capabilities & CAP_UNICODE) |
| 721 | smb->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 722 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 723 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 724 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8 | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 725 | smb->hdr.WordCount = 1; |
| 726 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 727 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 728 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 729 | inc_rfc1001_len(smb, 3); |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 730 | iov.iov_base = smb; |
| 731 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 732 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 733 | rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 734 | server, CIFS_ASYNC_OP | CIFS_ECHO_OP); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 735 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 736 | cifs_dbg(FYI, "Echo request failed: %d\n", rc); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 737 | |
| 738 | cifs_small_buf_release(smb); |
| 739 | |
| 740 | return rc; |
| 741 | } |
| 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | int |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 744 | CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | LOGOFF_ANDX_REQ *pSMB; |
| 747 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 749 | cifs_dbg(FYI, "In SMBLogoff for session disconnect\n"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 750 | |
| 751 | /* |
| 752 | * BB: do we need to check validity of ses and server? They should |
| 753 | * always be valid since we have an active reference. If not, that |
| 754 | * should probably be a BUG() |
| 755 | */ |
| 756 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | return -EIO; |
| 758 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 759 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 760 | if (ses->need_reconnect) |
| 761 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 762 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 764 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 765 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | return rc; |
| 767 | } |
| 768 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 769 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 770 | |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 771 | if (ses->server->sign) |
| 772 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | pSMB->hdr.Uid = ses->Suid; |
| 775 | |
| 776 | pSMB->AndXCommand = 0xFF; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 777 | rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 778 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 779 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
| 781 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 782 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | error */ |
| 784 | if (rc == -EAGAIN) |
| 785 | rc = 0; |
| 786 | return rc; |
| 787 | } |
| 788 | |
| 789 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 790 | CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, |
| 791 | const char *fileName, __u16 type, |
| 792 | const struct nls_table *nls_codepage, int remap) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 793 | { |
| 794 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 795 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 796 | struct unlink_psx_rq *pRqD; |
| 797 | int name_len; |
| 798 | int rc = 0; |
| 799 | int bytes_returned = 0; |
| 800 | __u16 params, param_offset, offset, byte_count; |
| 801 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 802 | cifs_dbg(FYI, "In POSIX delete\n"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 803 | PsxDelete: |
| 804 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 805 | (void **) &pSMBr); |
| 806 | if (rc) |
| 807 | return rc; |
| 808 | |
| 809 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 810 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 811 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 812 | PATH_MAX, nls_codepage, remap); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 813 | name_len++; /* trailing null */ |
| 814 | name_len *= 2; |
| 815 | } else { /* BB add path length overrun check */ |
| 816 | name_len = strnlen(fileName, PATH_MAX); |
| 817 | name_len++; /* trailing null */ |
| 818 | strncpy(pSMB->FileName, fileName, name_len); |
| 819 | } |
| 820 | |
| 821 | params = 6 + name_len; |
| 822 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 823 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 824 | pSMB->MaxSetupCount = 0; |
| 825 | pSMB->Reserved = 0; |
| 826 | pSMB->Flags = 0; |
| 827 | pSMB->Timeout = 0; |
| 828 | pSMB->Reserved2 = 0; |
| 829 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 830 | InformationLevel) - 4; |
| 831 | offset = param_offset + params; |
| 832 | |
| 833 | /* Setup pointer to Request Data (inode type) */ |
| 834 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 835 | pRqD->type = cpu_to_le16(type); |
| 836 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 837 | pSMB->DataOffset = cpu_to_le16(offset); |
| 838 | pSMB->SetupCount = 1; |
| 839 | pSMB->Reserved3 = 0; |
| 840 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 841 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 842 | |
| 843 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 844 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 845 | pSMB->ParameterCount = cpu_to_le16(params); |
| 846 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 847 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 848 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 849 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 850 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 851 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 852 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 853 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 854 | cifs_dbg(FYI, "Posix delete returned %d\n", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 855 | cifs_buf_release(pSMB); |
| 856 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 857 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 858 | |
| 859 | if (rc == -EAGAIN) |
| 860 | goto PsxDelete; |
| 861 | |
| 862 | return rc; |
| 863 | } |
| 864 | |
| 865 | int |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 866 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 867 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | { |
| 869 | DELETE_FILE_REQ *pSMB = NULL; |
| 870 | DELETE_FILE_RSP *pSMBr = NULL; |
| 871 | int rc = 0; |
| 872 | int bytes_returned; |
| 873 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 874 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
| 876 | DelFileRetry: |
| 877 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 878 | (void **) &pSMBr); |
| 879 | if (rc) |
| 880 | return rc; |
| 881 | |
| 882 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 883 | name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name, |
| 884 | PATH_MAX, cifs_sb->local_nls, |
| 885 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | name_len++; /* trailing null */ |
| 887 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 888 | } else { /* BB improve check for buffer overruns BB */ |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 889 | name_len = strnlen(name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | name_len++; /* trailing null */ |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 891 | strncpy(pSMB->fileName, name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | } |
| 893 | pSMB->SearchAttributes = |
| 894 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 895 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 896 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 898 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 899 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 900 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 901 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 902 | cifs_dbg(FYI, "Error in RMFile = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | cifs_buf_release(pSMB); |
| 905 | if (rc == -EAGAIN) |
| 906 | goto DelFileRetry; |
| 907 | |
| 908 | return rc; |
| 909 | } |
| 910 | |
| 911 | int |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 912 | CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 913 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | { |
| 915 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 916 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 917 | int rc = 0; |
| 918 | int bytes_returned; |
| 919 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 920 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 922 | cifs_dbg(FYI, "In CIFSSMBRmDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | RmDirRetry: |
| 924 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 925 | (void **) &pSMBr); |
| 926 | if (rc) |
| 927 | return rc; |
| 928 | |
| 929 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 930 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
| 931 | PATH_MAX, cifs_sb->local_nls, |
| 932 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | name_len++; /* trailing null */ |
| 934 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 935 | } else { /* BB improve check for buffer overruns BB */ |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 936 | name_len = strnlen(name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | name_len++; /* trailing null */ |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 938 | strncpy(pSMB->DirName, name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 942 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 944 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 945 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 946 | cifs_stats_inc(&tcon->stats.cifs_stats.num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 947 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 948 | cifs_dbg(FYI, "Error in RMDir = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | |
| 950 | cifs_buf_release(pSMB); |
| 951 | if (rc == -EAGAIN) |
| 952 | goto RmDirRetry; |
| 953 | return rc; |
| 954 | } |
| 955 | |
| 956 | int |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 957 | CIFSSMBMkDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 958 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | { |
| 960 | int rc = 0; |
| 961 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 962 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 963 | int bytes_returned; |
| 964 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 965 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 967 | cifs_dbg(FYI, "In CIFSSMBMkDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | MkDirRetry: |
| 969 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 970 | (void **) &pSMBr); |
| 971 | if (rc) |
| 972 | return rc; |
| 973 | |
| 974 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 975 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 976 | PATH_MAX, cifs_sb->local_nls, |
| 977 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | name_len++; /* trailing null */ |
| 979 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 980 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | name_len = strnlen(name, PATH_MAX); |
| 982 | name_len++; /* trailing null */ |
| 983 | strncpy(pSMB->DirName, name, name_len); |
| 984 | } |
| 985 | |
| 986 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 987 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 989 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 990 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 991 | cifs_stats_inc(&tcon->stats.cifs_stats.num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 992 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 993 | cifs_dbg(FYI, "Error in Mkdir = %d\n", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | cifs_buf_release(pSMB); |
| 996 | if (rc == -EAGAIN) |
| 997 | goto MkDirRetry; |
| 998 | return rc; |
| 999 | } |
| 1000 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1001 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1002 | CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, |
| 1003 | __u32 posix_flags, __u64 mode, __u16 *netfid, |
| 1004 | FILE_UNIX_BASIC_INFO *pRetData, __u32 *pOplock, |
| 1005 | const char *name, const struct nls_table *nls_codepage, |
| 1006 | int remap) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1007 | { |
| 1008 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1009 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1010 | int name_len; |
| 1011 | int rc = 0; |
| 1012 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1013 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1014 | OPEN_PSX_REQ *pdata; |
| 1015 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1016 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1017 | cifs_dbg(FYI, "In POSIX Create\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1018 | PsxCreat: |
| 1019 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1020 | (void **) &pSMBr); |
| 1021 | if (rc) |
| 1022 | return rc; |
| 1023 | |
| 1024 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1025 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1026 | cifsConvertToUTF16((__le16 *) pSMB->FileName, name, |
| 1027 | PATH_MAX, nls_codepage, remap); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1028 | name_len++; /* trailing null */ |
| 1029 | name_len *= 2; |
| 1030 | } else { /* BB improve the check for buffer overruns BB */ |
| 1031 | name_len = strnlen(name, PATH_MAX); |
| 1032 | name_len++; /* trailing null */ |
| 1033 | strncpy(pSMB->FileName, name, name_len); |
| 1034 | } |
| 1035 | |
| 1036 | params = 6 + name_len; |
| 1037 | count = sizeof(OPEN_PSX_REQ); |
| 1038 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1039 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1040 | pSMB->MaxSetupCount = 0; |
| 1041 | pSMB->Reserved = 0; |
| 1042 | pSMB->Flags = 0; |
| 1043 | pSMB->Timeout = 0; |
| 1044 | pSMB->Reserved2 = 0; |
| 1045 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1046 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1047 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1048 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1049 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1050 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1051 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1052 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1053 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1054 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1055 | pSMB->SetupCount = 1; |
| 1056 | pSMB->Reserved3 = 0; |
| 1057 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1058 | byte_count = 3 /* pad */ + params + count; |
| 1059 | |
| 1060 | pSMB->DataCount = cpu_to_le16(count); |
| 1061 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1062 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1063 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1064 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1065 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1066 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1067 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1068 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1069 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1070 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1071 | cifs_dbg(FYI, "Posix create returned %d\n", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1072 | goto psx_create_err; |
| 1073 | } |
| 1074 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1075 | cifs_dbg(FYI, "copying inode info\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1076 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1077 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1078 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1079 | rc = -EIO; /* bad smb */ |
| 1080 | goto psx_create_err; |
| 1081 | } |
| 1082 | |
| 1083 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1084 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1085 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1086 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1087 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1088 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1089 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1090 | /* Let caller know file was created so we can set the mode. */ |
| 1091 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1092 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1093 | *pOplock |= CIFS_CREATE_ACTION; |
| 1094 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1095 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1096 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1097 | cifs_dbg(NOISY, "unknown type\n"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1098 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1099 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1100 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1101 | cifs_dbg(VFS, "Open response data too small\n"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1102 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1103 | goto psx_create_err; |
| 1104 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1105 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1106 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1107 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1108 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1109 | |
| 1110 | psx_create_err: |
| 1111 | cifs_buf_release(pSMB); |
| 1112 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1113 | if (posix_flags & SMB_O_DIRECTORY) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1114 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixmkdirs); |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1115 | else |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1116 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1117 | |
| 1118 | if (rc == -EAGAIN) |
| 1119 | goto PsxCreat; |
| 1120 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1121 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1124 | static __u16 convert_disposition(int disposition) |
| 1125 | { |
| 1126 | __u16 ofun = 0; |
| 1127 | |
| 1128 | switch (disposition) { |
| 1129 | case FILE_SUPERSEDE: |
| 1130 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1131 | break; |
| 1132 | case FILE_OPEN: |
| 1133 | ofun = SMBOPEN_OAPPEND; |
| 1134 | break; |
| 1135 | case FILE_CREATE: |
| 1136 | ofun = SMBOPEN_OCREATE; |
| 1137 | break; |
| 1138 | case FILE_OPEN_IF: |
| 1139 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1140 | break; |
| 1141 | case FILE_OVERWRITE: |
| 1142 | ofun = SMBOPEN_OTRUNC; |
| 1143 | break; |
| 1144 | case FILE_OVERWRITE_IF: |
| 1145 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1146 | break; |
| 1147 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1148 | cifs_dbg(FYI, "unknown disposition %d\n", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1149 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1150 | } |
| 1151 | return ofun; |
| 1152 | } |
| 1153 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1154 | static int |
| 1155 | access_flags_to_smbopen_mode(const int access_flags) |
| 1156 | { |
| 1157 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1158 | |
| 1159 | if (masked_flags == GENERIC_READ) |
| 1160 | return SMBOPEN_READ; |
| 1161 | else if (masked_flags == GENERIC_WRITE) |
| 1162 | return SMBOPEN_WRITE; |
| 1163 | |
| 1164 | /* just go for read/write */ |
| 1165 | return SMBOPEN_READWRITE; |
| 1166 | } |
| 1167 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1168 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1169 | SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1170 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1171 | const int access_flags, const int create_options, __u16 *netfid, |
| 1172 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1173 | const struct nls_table *nls_codepage, int remap) |
| 1174 | { |
| 1175 | int rc = -EACCES; |
| 1176 | OPENX_REQ *pSMB = NULL; |
| 1177 | OPENX_RSP *pSMBr = NULL; |
| 1178 | int bytes_returned; |
| 1179 | int name_len; |
| 1180 | __u16 count; |
| 1181 | |
| 1182 | OldOpenRetry: |
| 1183 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1184 | (void **) &pSMBr); |
| 1185 | if (rc) |
| 1186 | return rc; |
| 1187 | |
| 1188 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1189 | |
| 1190 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1191 | count = 1; /* account for one byte pad to word boundary */ |
| 1192 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1193 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1194 | fileName, PATH_MAX, nls_codepage, remap); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1195 | name_len++; /* trailing null */ |
| 1196 | name_len *= 2; |
| 1197 | } else { /* BB improve check for buffer overruns BB */ |
| 1198 | count = 0; /* no pad */ |
| 1199 | name_len = strnlen(fileName, PATH_MAX); |
| 1200 | name_len++; /* trailing null */ |
| 1201 | strncpy(pSMB->fileName, fileName, name_len); |
| 1202 | } |
| 1203 | if (*pOplock & REQ_OPLOCK) |
| 1204 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1205 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1206 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1207 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1208 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1209 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1210 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1211 | /* set file as system file if special file such |
| 1212 | as fifo and server expecting SFU style and |
| 1213 | no Unix extensions */ |
| 1214 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1215 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1216 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1217 | else /* BB FIXME BB */ |
| 1218 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1219 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1220 | if (create_options & CREATE_OPTION_READONLY) |
| 1221 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1222 | |
| 1223 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1224 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1225 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1226 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1227 | |
| 1228 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1229 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1230 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1231 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1232 | |
| 1233 | pSMB->ByteCount = cpu_to_le16(count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1234 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1235 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1236 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1237 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1238 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1239 | } else { |
| 1240 | /* BB verify if wct == 15 */ |
| 1241 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1242 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1243 | |
| 1244 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1245 | /* Let caller know file was created so we can set the mode. */ |
| 1246 | /* Do we care about the CreateAction in any other cases? */ |
| 1247 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1248 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1249 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1250 | /* BB FIXME END */ |
| 1251 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1252 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1253 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1254 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1255 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1256 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1257 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1258 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1259 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1260 | pfile_info->AllocationSize = |
| 1261 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1262 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1263 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1264 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | cifs_buf_release(pSMB); |
| 1269 | if (rc == -EAGAIN) |
| 1270 | goto OldOpenRetry; |
| 1271 | return rc; |
| 1272 | } |
| 1273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | int |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1275 | CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock, |
| 1276 | FILE_ALL_INFO *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | { |
| 1278 | int rc = -EACCES; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1279 | OPEN_REQ *req = NULL; |
| 1280 | OPEN_RSP *rsp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | int bytes_returned; |
| 1282 | int name_len; |
| 1283 | __u16 count; |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1284 | struct cifs_sb_info *cifs_sb = oparms->cifs_sb; |
| 1285 | struct cifs_tcon *tcon = oparms->tcon; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1286 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1287 | const struct nls_table *nls = cifs_sb->local_nls; |
| 1288 | int create_options = oparms->create_options; |
| 1289 | int desired_access = oparms->desired_access; |
| 1290 | int disposition = oparms->disposition; |
| 1291 | const char *path = oparms->path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
| 1293 | openRetry: |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1294 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **)&req, |
| 1295 | (void **)&rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | if (rc) |
| 1297 | return rc; |
| 1298 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1299 | /* no commands go after this */ |
| 1300 | req->AndXCommand = 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1302 | if (req->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1303 | /* account for one byte pad to word boundary */ |
| 1304 | count = 1; |
| 1305 | name_len = cifsConvertToUTF16((__le16 *)(req->fileName + 1), |
| 1306 | path, PATH_MAX, nls, remap); |
| 1307 | /* trailing null */ |
| 1308 | name_len++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | name_len *= 2; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1310 | req->NameLength = cpu_to_le16(name_len); |
| 1311 | } else { |
| 1312 | /* BB improve check for buffer overruns BB */ |
| 1313 | /* no pad */ |
| 1314 | count = 0; |
| 1315 | name_len = strnlen(path, PATH_MAX); |
| 1316 | /* trailing null */ |
| 1317 | name_len++; |
| 1318 | req->NameLength = cpu_to_le16(name_len); |
| 1319 | strncpy(req->fileName, path, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | } |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1321 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1322 | if (*oplock & REQ_OPLOCK) |
| 1323 | req->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
| 1324 | else if (*oplock & REQ_BATCHOPLOCK) |
| 1325 | req->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
| 1326 | |
| 1327 | req->DesiredAccess = cpu_to_le32(desired_access); |
| 1328 | req->AllocationSize = 0; |
| 1329 | |
| 1330 | /* |
| 1331 | * Set file as system file if special file such as fifo and server |
| 1332 | * expecting SFU style and no Unix extensions. |
| 1333 | */ |
| 1334 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1335 | req->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1336 | else |
| 1337 | req->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
| 1338 | |
| 1339 | /* |
| 1340 | * XP does not handle ATTR_POSIX_SEMANTICS but it helps speed up case |
| 1341 | * sensitive checks for other servers such as Samba. |
| 1342 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | if (tcon->ses->capabilities & CAP_UNIX) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1344 | req->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1346 | if (create_options & CREATE_OPTION_READONLY) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1347 | req->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1348 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1349 | req->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1350 | req->CreateDisposition = cpu_to_le32(disposition); |
| 1351 | req->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
| 1352 | |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1353 | /* BB Expirement with various impersonation levels and verify */ |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1354 | req->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
| 1355 | req->SecurityFlags = SECURITY_CONTEXT_TRACKING|SECURITY_EFFECTIVE_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
| 1357 | count += name_len; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1358 | inc_rfc1001_len(req, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1360 | req->ByteCount = cpu_to_le16(count); |
| 1361 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *)req, |
| 1362 | (struct smb_hdr *)rsp, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1363 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1365 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1366 | cifs_buf_release(req); |
| 1367 | if (rc == -EAGAIN) |
| 1368 | goto openRetry; |
| 1369 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1371 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1372 | /* 1 byte no need to le_to_cpu */ |
| 1373 | *oplock = rsp->OplockLevel; |
| 1374 | /* cifs fid stays in le */ |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1375 | oparms->fid->netfid = rsp->Fid; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1376 | |
| 1377 | /* Let caller know file was created so we can set the mode. */ |
| 1378 | /* Do we care about the CreateAction in any other cases? */ |
| 1379 | if (cpu_to_le32(FILE_CREATE) == rsp->CreateAction) |
| 1380 | *oplock |= CIFS_CREATE_ACTION; |
| 1381 | |
| 1382 | if (buf) { |
| 1383 | /* copy from CreationTime to Attributes */ |
| 1384 | memcpy((char *)buf, (char *)&rsp->CreationTime, 36); |
| 1385 | /* the file_info buf is endian converted by caller */ |
| 1386 | buf->AllocationSize = rsp->AllocationSize; |
| 1387 | buf->EndOfFile = rsp->EndOfFile; |
| 1388 | buf->NumberOfLinks = cpu_to_le32(1); |
| 1389 | buf->DeletePending = 0; |
| 1390 | } |
| 1391 | |
| 1392 | cifs_buf_release(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | return rc; |
| 1394 | } |
| 1395 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1396 | /* |
| 1397 | * Discard any remaining data in the current SMB. To do this, we borrow the |
| 1398 | * current bigbuf. |
| 1399 | */ |
| 1400 | static int |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1401 | discard_remaining_data(struct TCP_Server_Info *server) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1402 | { |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1403 | unsigned int rfclen = get_rfc1002_length(server->smallbuf); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1404 | int remaining = rfclen + 4 - server->total_read; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1405 | |
| 1406 | while (remaining > 0) { |
| 1407 | int length; |
| 1408 | |
| 1409 | length = cifs_read_from_socket(server, server->bigbuf, |
| 1410 | min_t(unsigned int, remaining, |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1411 | CIFSMaxBufSize + MAX_HEADER_SIZE(server))); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1412 | if (length < 0) |
| 1413 | return length; |
| 1414 | server->total_read += length; |
| 1415 | remaining -= length; |
| 1416 | } |
| 1417 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1418 | return 0; |
| 1419 | } |
| 1420 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1421 | static int |
| 1422 | cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1423 | { |
| 1424 | int length; |
| 1425 | struct cifs_readdata *rdata = mid->callback_data; |
| 1426 | |
| 1427 | length = discard_remaining_data(server); |
| 1428 | dequeue_mid(mid, rdata->result); |
Sachin Prabhu | d8fd99d | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 1429 | mid->resp_buf = server->smallbuf; |
| 1430 | server->smallbuf = NULL; |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1431 | return length; |
| 1432 | } |
| 1433 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1434 | int |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1435 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1436 | { |
| 1437 | int length, len; |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1438 | unsigned int data_offset, data_len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1439 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1440 | char *buf = server->smallbuf; |
| 1441 | unsigned int buflen = get_rfc1002_length(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1442 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1443 | cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n", |
| 1444 | __func__, mid->mid, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1445 | |
| 1446 | /* |
| 1447 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1448 | * can if there's not enough data. At this point, we've read down to |
| 1449 | * the Mid. |
| 1450 | */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1451 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1452 | HEADER_SIZE(server) + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1453 | |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1454 | length = cifs_read_from_socket(server, |
| 1455 | buf + HEADER_SIZE(server) - 1, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1456 | if (length < 0) |
| 1457 | return length; |
| 1458 | server->total_read += length; |
| 1459 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1460 | if (server->ops->is_status_pending && |
| 1461 | server->ops->is_status_pending(buf, server, 0)) { |
| 1462 | discard_remaining_data(server); |
| 1463 | return -1; |
| 1464 | } |
| 1465 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1466 | /* Was the SMB read successful? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1467 | rdata->result = server->ops->map_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1468 | if (rdata->result != 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1469 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 1470 | __func__, rdata->result); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1471 | return cifs_readv_discard(server, mid); |
| 1472 | } |
| 1473 | |
| 1474 | /* Is there enough to get to the rest of the READ_RSP header? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1475 | if (server->total_read < server->vals->read_rsp_size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1476 | cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n", |
| 1477 | __func__, server->total_read, |
| 1478 | server->vals->read_rsp_size); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1479 | rdata->result = -EIO; |
| 1480 | return cifs_readv_discard(server, mid); |
| 1481 | } |
| 1482 | |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1483 | data_offset = server->ops->read_data_offset(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1484 | if (data_offset < server->total_read) { |
| 1485 | /* |
| 1486 | * win2k8 sometimes sends an offset of 0 when the read |
| 1487 | * is beyond the EOF. Treat it as if the data starts just after |
| 1488 | * the header. |
| 1489 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1490 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 1491 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1492 | data_offset = server->total_read; |
| 1493 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1494 | /* data_offset is beyond the end of smallbuf */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1495 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 1496 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1497 | rdata->result = -EIO; |
| 1498 | return cifs_readv_discard(server, mid); |
| 1499 | } |
| 1500 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1501 | cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n", |
| 1502 | __func__, server->total_read, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1503 | |
| 1504 | len = data_offset - server->total_read; |
| 1505 | if (len > 0) { |
| 1506 | /* read any junk before data into the rest of smallbuf */ |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1507 | length = cifs_read_from_socket(server, |
| 1508 | buf + server->total_read, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1509 | if (length < 0) |
| 1510 | return length; |
| 1511 | server->total_read += length; |
| 1512 | } |
| 1513 | |
| 1514 | /* set up first iov for signature check */ |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1515 | rdata->iov.iov_base = buf; |
| 1516 | rdata->iov.iov_len = server->total_read; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1517 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 1518 | rdata->iov.iov_base, rdata->iov.iov_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1519 | |
| 1520 | /* how much data is in the response? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1521 | data_len = server->ops->read_data_length(buf); |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1522 | if (data_offset + data_len > buflen) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1523 | /* data_len is corrupt -- discard frame */ |
| 1524 | rdata->result = -EIO; |
| 1525 | return cifs_readv_discard(server, mid); |
| 1526 | } |
| 1527 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1528 | length = rdata->read_into_pages(server, rdata, data_len); |
| 1529 | if (length < 0) |
| 1530 | return length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1531 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1532 | server->total_read += length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1533 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1534 | cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n", |
| 1535 | server->total_read, buflen, data_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1536 | |
| 1537 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1538 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1539 | return cifs_readv_discard(server, mid); |
| 1540 | |
| 1541 | dequeue_mid(mid, false); |
Sachin Prabhu | d8fd99d | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 1542 | mid->resp_buf = server->smallbuf; |
| 1543 | server->smallbuf = NULL; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1544 | return length; |
| 1545 | } |
| 1546 | |
| 1547 | static void |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1548 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1549 | { |
| 1550 | struct cifs_readdata *rdata = mid->callback_data; |
| 1551 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1552 | struct TCP_Server_Info *server = tcon->ses->server; |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1553 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, |
| 1554 | .rq_nvec = 1, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1555 | .rq_pages = rdata->pages, |
| 1556 | .rq_npages = rdata->nr_pages, |
| 1557 | .rq_pagesz = rdata->pagesz, |
| 1558 | .rq_tailsz = rdata->tailsz }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1559 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1560 | cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", |
| 1561 | __func__, mid->mid, mid->mid_state, rdata->result, |
| 1562 | rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1563 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1564 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1565 | case MID_RESPONSE_RECEIVED: |
| 1566 | /* result already set, check signature */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 1567 | if (server->sign) { |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1568 | int rc = 0; |
| 1569 | |
Jeff Layton | bf5ea0e | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1570 | rc = cifs_verify_signature(&rqst, server, |
Jeff Layton | 0124cc4 | 2013-04-03 11:55:03 -0400 | [diff] [blame] | 1571 | mid->sequence_number); |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1572 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1573 | cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
| 1574 | rc); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1575 | } |
| 1576 | /* FIXME: should this be counted toward the initiating task? */ |
Pavel Shilovsky | 34a54d6 | 2014-07-10 10:03:29 +0400 | [diff] [blame] | 1577 | task_io_account_read(rdata->got_bytes); |
| 1578 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1579 | break; |
| 1580 | case MID_REQUEST_SUBMITTED: |
| 1581 | case MID_RETRY_NEEDED: |
| 1582 | rdata->result = -EAGAIN; |
Pavel Shilovsky | d913ed1 | 2014-07-10 11:31:48 +0400 | [diff] [blame] | 1583 | if (server->sign && rdata->got_bytes) |
| 1584 | /* reset bytes number since we can not check a sign */ |
| 1585 | rdata->got_bytes = 0; |
| 1586 | /* FIXME: should this be counted toward the initiating task? */ |
| 1587 | task_io_account_read(rdata->got_bytes); |
| 1588 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1589 | break; |
| 1590 | default: |
| 1591 | rdata->result = -EIO; |
| 1592 | } |
| 1593 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1594 | queue_work(cifsiod_wq, &rdata->work); |
Christopher Oo | 5fb4e28 | 2015-06-25 16:10:48 -0700 | [diff] [blame] | 1595 | mutex_lock(&server->srv_mutex); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1596 | DeleteMidQEntry(mid); |
Christopher Oo | 5fb4e28 | 2015-06-25 16:10:48 -0700 | [diff] [blame] | 1597 | mutex_unlock(&server->srv_mutex); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1598 | add_credits(server, 1, 0); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1602 | int |
| 1603 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1604 | { |
| 1605 | int rc; |
| 1606 | READ_REQ *smb = NULL; |
| 1607 | int wct; |
| 1608 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1609 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 1610 | .rq_nvec = 1 }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1611 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1612 | cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n", |
| 1613 | __func__, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1614 | |
| 1615 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1616 | wct = 12; |
| 1617 | else { |
| 1618 | wct = 10; /* old style read */ |
| 1619 | if ((rdata->offset >> 32) > 0) { |
| 1620 | /* can not handle this big offset for old */ |
| 1621 | return -EIO; |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1626 | if (rc) |
| 1627 | return rc; |
| 1628 | |
| 1629 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1630 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1631 | |
| 1632 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1633 | smb->Fid = rdata->cfile->fid.netfid; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1634 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1635 | if (wct == 12) |
| 1636 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1637 | smb->Remaining = 0; |
| 1638 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1639 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1640 | if (wct == 12) |
| 1641 | smb->ByteCount = 0; |
| 1642 | else { |
| 1643 | /* old style read */ |
| 1644 | struct smb_com_readx_req *smbr = |
| 1645 | (struct smb_com_readx_req *)smb; |
| 1646 | smbr->ByteCount = 0; |
| 1647 | } |
| 1648 | |
| 1649 | /* 4 for RFC1001 length + 1 for BCC */ |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1650 | rdata->iov.iov_base = smb; |
| 1651 | rdata->iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1652 | |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1653 | kref_get(&rdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 1654 | rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, |
| 1655 | cifs_readv_callback, rdata, 0); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1656 | |
| 1657 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1658 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1659 | else |
| 1660 | kref_put(&rdata->refcount, cifs_readdata_release); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1661 | |
| 1662 | cifs_small_buf_release(smb); |
| 1663 | return rc; |
| 1664 | } |
| 1665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1667 | CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms, |
| 1668 | unsigned int *nbytes, char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | { |
| 1670 | int rc = -EACCES; |
| 1671 | READ_REQ *pSMB = NULL; |
| 1672 | READ_RSP *pSMBr = NULL; |
| 1673 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1674 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1675 | int resp_buf_type = 0; |
| 1676 | struct kvec iov[1]; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1677 | __u32 pid = io_parms->pid; |
| 1678 | __u16 netfid = io_parms->netfid; |
| 1679 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1680 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1681 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1683 | cifs_dbg(FYI, "Reading %d bytes on fid %d\n", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1684 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1685 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1686 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1687 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1688 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1689 | /* can not handle this big offset for old */ |
| 1690 | return -EIO; |
| 1691 | } |
| 1692 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | |
| 1694 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1695 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | if (rc) |
| 1697 | return rc; |
| 1698 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1699 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1700 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | /* tcon and ses pointer are checked in smb_init */ |
| 1703 | if (tcon->ses->server == NULL) |
| 1704 | return -ECONNABORTED; |
| 1705 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1706 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1708 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1709 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1710 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | pSMB->Remaining = 0; |
| 1713 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1714 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1715 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1716 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1717 | else { |
| 1718 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1719 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1720 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1721 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1722 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1723 | |
| 1724 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1725 | 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] | 1726 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1727 | &resp_buf_type, CIFS_LOG_ERROR); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1728 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1729 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1731 | cifs_dbg(VFS, "Send error in read = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | } else { |
| 1733 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1734 | data_length = data_length << 16; |
| 1735 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1736 | *nbytes = data_length; |
| 1737 | |
| 1738 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1739 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | || (data_length > count)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1741 | cifs_dbg(FYI, "bad length %d for count %d\n", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1742 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | rc = -EIO; |
| 1744 | *nbytes = 0; |
| 1745 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1746 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1747 | le16_to_cpu(pSMBr->DataOffset); |
| 1748 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1749 | cifs_dbg(VFS, "Faulting on read rc = %d\n",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1750 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1751 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1752 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1753 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | } |
| 1755 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1757 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1758 | if (*buf) { |
Sachin Prabhu | 6d81ed1 | 2014-06-16 15:35:24 +0100 | [diff] [blame] | 1759 | free_rsp_buf(resp_buf_type, iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1760 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1761 | /* return buffer to caller to free */ |
| 1762 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1763 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1764 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1765 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1766 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1767 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1768 | |
| 1769 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | since file handle passed in no longer valid */ |
| 1771 | return rc; |
| 1772 | } |
| 1773 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1776 | CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1777 | unsigned int *nbytes, const char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | { |
| 1779 | int rc = -EACCES; |
| 1780 | WRITE_REQ *pSMB = NULL; |
| 1781 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1782 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | __u32 bytes_sent; |
| 1784 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1785 | __u32 pid = io_parms->pid; |
| 1786 | __u16 netfid = io_parms->netfid; |
| 1787 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1788 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1789 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1791 | *nbytes = 0; |
| 1792 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1793 | /* cifs_dbg(FYI, "write at %lld %d bytes\n", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1794 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1795 | return -ECONNABORTED; |
| 1796 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1797 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1798 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1799 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1800 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1801 | if ((offset >> 32) > 0) { |
| 1802 | /* can not handle big offset for old srv */ |
| 1803 | return -EIO; |
| 1804 | } |
| 1805 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1806 | |
| 1807 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | (void **) &pSMBr); |
| 1809 | if (rc) |
| 1810 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1811 | |
| 1812 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1813 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | /* tcon and ses pointer are checked in smb_init */ |
| 1816 | if (tcon->ses->server == NULL) |
| 1817 | return -ECONNABORTED; |
| 1818 | |
| 1819 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1820 | pSMB->Fid = netfid; |
| 1821 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1822 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1823 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | pSMB->Reserved = 0xFFFFFFFF; |
| 1826 | pSMB->WriteMode = 0; |
| 1827 | pSMB->Remaining = 0; |
| 1828 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1829 | /* 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] | 1830 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1831 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1832 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1833 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1835 | } else { |
| 1836 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1837 | & ~0xFF; |
| 1838 | } |
| 1839 | |
| 1840 | if (bytes_sent > count) |
| 1841 | bytes_sent = count; |
| 1842 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1843 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1844 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1845 | memcpy(pSMB->Data, buf, bytes_sent); |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1846 | else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | /* No buffer */ |
| 1848 | cifs_buf_release(pSMB); |
| 1849 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1850 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1851 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1852 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1853 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1854 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1857 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1858 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1859 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1860 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1861 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1862 | else { /* old style write has byte count 4 bytes earlier |
| 1863 | so 4 bytes pad */ |
| 1864 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1865 | (struct smb_com_writex_req *)pSMB; |
| 1866 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | |
| 1869 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1870 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1871 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1873 | cifs_dbg(FYI, "Send error in write = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } else { |
| 1875 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1876 | *nbytes = (*nbytes) << 16; |
| 1877 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1878 | |
| 1879 | /* |
| 1880 | * Mask off high 16 bits when bytes written as returned by the |
| 1881 | * server is greater than bytes requested by the client. Some |
| 1882 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1883 | */ |
| 1884 | if (*nbytes > count) |
| 1885 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | cifs_buf_release(pSMB); |
| 1889 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1890 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | since file handle passed in no longer valid */ |
| 1892 | |
| 1893 | return rc; |
| 1894 | } |
| 1895 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1896 | void |
| 1897 | cifs_writedata_release(struct kref *refcount) |
| 1898 | { |
| 1899 | struct cifs_writedata *wdata = container_of(refcount, |
| 1900 | struct cifs_writedata, refcount); |
| 1901 | |
| 1902 | if (wdata->cfile) |
| 1903 | cifsFileInfo_put(wdata->cfile); |
| 1904 | |
| 1905 | kfree(wdata); |
| 1906 | } |
| 1907 | |
| 1908 | /* |
| 1909 | * Write failed with a retryable error. Resend the write request. It's also |
| 1910 | * possible that the page was redirtied so re-clean the page. |
| 1911 | */ |
| 1912 | static void |
| 1913 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 1914 | { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1915 | int i, rc = 0; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1916 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Pavel Shilovsky | c9de5c8 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1917 | struct TCP_Server_Info *server; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1918 | unsigned int rest_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1919 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1920 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
| 1921 | i = 0; |
| 1922 | rest_len = wdata->bytes; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1923 | do { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1924 | struct cifs_writedata *wdata2; |
| 1925 | unsigned int j, nr_pages, wsize, tailsz, cur_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1926 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1927 | wsize = server->ops->wp_retry_size(inode); |
| 1928 | if (wsize < rest_len) { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1929 | nr_pages = wsize / PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1930 | if (!nr_pages) { |
| 1931 | rc = -ENOTSUPP; |
| 1932 | break; |
| 1933 | } |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1934 | cur_len = nr_pages * PAGE_SIZE; |
| 1935 | tailsz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1936 | } else { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1937 | nr_pages = DIV_ROUND_UP(rest_len, PAGE_SIZE); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1938 | cur_len = rest_len; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1939 | tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE; |
Ouyang Maochun | c51bb0e | 2013-02-18 09:54:52 -0600 | [diff] [blame] | 1940 | } |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1941 | |
| 1942 | wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete); |
| 1943 | if (!wdata2) { |
| 1944 | rc = -ENOMEM; |
| 1945 | break; |
| 1946 | } |
| 1947 | |
| 1948 | for (j = 0; j < nr_pages; j++) { |
| 1949 | wdata2->pages[j] = wdata->pages[i + j]; |
| 1950 | lock_page(wdata2->pages[j]); |
| 1951 | clear_page_dirty_for_io(wdata2->pages[j]); |
| 1952 | } |
| 1953 | |
| 1954 | wdata2->sync_mode = wdata->sync_mode; |
| 1955 | wdata2->nr_pages = nr_pages; |
| 1956 | wdata2->offset = page_offset(wdata2->pages[0]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1957 | wdata2->pagesz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1958 | wdata2->tailsz = tailsz; |
| 1959 | wdata2->bytes = cur_len; |
| 1960 | |
| 1961 | wdata2->cfile = find_writable_file(CIFS_I(inode), false); |
| 1962 | if (!wdata2->cfile) { |
| 1963 | cifs_dbg(VFS, "No writable handles for inode\n"); |
| 1964 | rc = -EBADF; |
| 1965 | break; |
| 1966 | } |
| 1967 | wdata2->pid = wdata2->cfile->pid; |
| 1968 | rc = server->ops->async_writev(wdata2, cifs_writedata_release); |
| 1969 | |
| 1970 | for (j = 0; j < nr_pages; j++) { |
| 1971 | unlock_page(wdata2->pages[j]); |
| 1972 | if (rc != 0 && rc != -EAGAIN) { |
| 1973 | SetPageError(wdata2->pages[j]); |
| 1974 | end_page_writeback(wdata2->pages[j]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1975 | put_page(wdata2->pages[j]); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | if (rc) { |
| 1980 | kref_put(&wdata2->refcount, cifs_writedata_release); |
| 1981 | if (rc == -EAGAIN) |
| 1982 | continue; |
| 1983 | break; |
| 1984 | } |
| 1985 | |
| 1986 | rest_len -= cur_len; |
| 1987 | i += nr_pages; |
| 1988 | } while (i < wdata->nr_pages); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1989 | |
| 1990 | mapping_set_error(inode->i_mapping, rc); |
| 1991 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1992 | } |
| 1993 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 1994 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1995 | cifs_writev_complete(struct work_struct *work) |
| 1996 | { |
| 1997 | struct cifs_writedata *wdata = container_of(work, |
| 1998 | struct cifs_writedata, work); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1999 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2000 | int i = 0; |
| 2001 | |
| 2002 | if (wdata->result == 0) { |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2003 | spin_lock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2004 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2005 | spin_unlock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2006 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 2007 | wdata->bytes); |
| 2008 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 2009 | return cifs_writev_requeue(wdata); |
| 2010 | |
| 2011 | for (i = 0; i < wdata->nr_pages; i++) { |
| 2012 | struct page *page = wdata->pages[i]; |
| 2013 | if (wdata->result == -EAGAIN) |
| 2014 | __set_page_dirty_nobuffers(page); |
| 2015 | else if (wdata->result < 0) |
| 2016 | SetPageError(page); |
| 2017 | end_page_writeback(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2018 | put_page(page); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2019 | } |
| 2020 | if (wdata->result != -EAGAIN) |
| 2021 | mapping_set_error(inode->i_mapping, wdata->result); |
| 2022 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2023 | } |
| 2024 | |
| 2025 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2026 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2027 | { |
| 2028 | struct cifs_writedata *wdata; |
| 2029 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2030 | /* writedata + number of page pointers */ |
| 2031 | wdata = kzalloc(sizeof(*wdata) + |
Jeff Layton | 26c8f0d | 2014-02-07 11:04:04 -0500 | [diff] [blame] | 2032 | sizeof(struct page *) * nr_pages, GFP_NOFS); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2033 | if (wdata != NULL) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2034 | kref_init(&wdata->refcount); |
Jeff Layton | da82f7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2035 | INIT_LIST_HEAD(&wdata->list); |
| 2036 | init_completion(&wdata->done); |
| 2037 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2038 | } |
| 2039 | return wdata; |
| 2040 | } |
| 2041 | |
| 2042 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2043 | * 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] | 2044 | * workqueue completion task. |
| 2045 | */ |
| 2046 | static void |
| 2047 | cifs_writev_callback(struct mid_q_entry *mid) |
| 2048 | { |
| 2049 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2050 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Christopher Oo | 5fb4e28 | 2015-06-25 16:10:48 -0700 | [diff] [blame] | 2051 | struct TCP_Server_Info *server = tcon->ses->server; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2052 | unsigned int written; |
| 2053 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
| 2054 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2055 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2056 | case MID_RESPONSE_RECEIVED: |
| 2057 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 2058 | if (wdata->result != 0) |
| 2059 | break; |
| 2060 | |
| 2061 | written = le16_to_cpu(smb->CountHigh); |
| 2062 | written <<= 16; |
| 2063 | written += le16_to_cpu(smb->Count); |
| 2064 | /* |
| 2065 | * Mask off high 16 bits when bytes written as returned |
| 2066 | * by the server is greater than bytes requested by the |
| 2067 | * client. OS/2 servers are known to set incorrect |
| 2068 | * CountHigh values. |
| 2069 | */ |
| 2070 | if (written > wdata->bytes) |
| 2071 | written &= 0xFFFF; |
| 2072 | |
| 2073 | if (written < wdata->bytes) |
| 2074 | wdata->result = -ENOSPC; |
| 2075 | else |
| 2076 | wdata->bytes = written; |
| 2077 | break; |
| 2078 | case MID_REQUEST_SUBMITTED: |
| 2079 | case MID_RETRY_NEEDED: |
| 2080 | wdata->result = -EAGAIN; |
| 2081 | break; |
| 2082 | default: |
| 2083 | wdata->result = -EIO; |
| 2084 | break; |
| 2085 | } |
| 2086 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2087 | queue_work(cifsiod_wq, &wdata->work); |
Christopher Oo | 5fb4e28 | 2015-06-25 16:10:48 -0700 | [diff] [blame] | 2088 | mutex_lock(&server->srv_mutex); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2089 | DeleteMidQEntry(mid); |
Christopher Oo | 5fb4e28 | 2015-06-25 16:10:48 -0700 | [diff] [blame] | 2090 | mutex_unlock(&server->srv_mutex); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2091 | add_credits(tcon->ses->server, 1, 0); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2095 | int |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2096 | cifs_async_writev(struct cifs_writedata *wdata, |
| 2097 | void (*release)(struct kref *kref)) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2098 | { |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2099 | int rc = -EACCES; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2100 | WRITE_REQ *smb = NULL; |
| 2101 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2102 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2103 | struct kvec iov; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2104 | struct smb_rqst rqst = { }; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2105 | |
| 2106 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2107 | wct = 14; |
| 2108 | } else { |
| 2109 | wct = 12; |
| 2110 | if (wdata->offset >> 32 > 0) { |
| 2111 | /* can not handle big offset for old srv */ |
| 2112 | return -EIO; |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2117 | if (rc) |
| 2118 | goto async_writev_out; |
| 2119 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2120 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2121 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2122 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2123 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2124 | smb->Fid = wdata->cfile->fid.netfid; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2125 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2126 | if (wct == 14) |
| 2127 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2128 | smb->Reserved = 0xFFFFFFFF; |
| 2129 | smb->WriteMode = 0; |
| 2130 | smb->Remaining = 0; |
| 2131 | |
| 2132 | smb->DataOffset = |
| 2133 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2134 | |
| 2135 | /* 4 for RFC1001 length + 1 for BCC */ |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2136 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; |
| 2137 | iov.iov_base = smb; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2138 | |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2139 | rqst.rq_iov = &iov; |
| 2140 | rqst.rq_nvec = 1; |
| 2141 | rqst.rq_pages = wdata->pages; |
| 2142 | rqst.rq_npages = wdata->nr_pages; |
| 2143 | rqst.rq_pagesz = wdata->pagesz; |
| 2144 | rqst.rq_tailsz = wdata->tailsz; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2145 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2146 | cifs_dbg(FYI, "async write at %llu %u bytes\n", |
| 2147 | wdata->offset, wdata->bytes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2148 | |
| 2149 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2150 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2151 | |
| 2152 | if (wct == 14) { |
| 2153 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2154 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2155 | } else { |
| 2156 | /* wct == 12 */ |
| 2157 | struct smb_com_writex_req *smbw = |
| 2158 | (struct smb_com_writex_req *)smb; |
| 2159 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2160 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2161 | iov.iov_len += 4; /* pad bigger by four bytes */ |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | kref_get(&wdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2165 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, |
| 2166 | cifs_writev_callback, wdata, 0); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2167 | |
| 2168 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2169 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2170 | else |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2171 | kref_put(&wdata->refcount, release); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2172 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2173 | async_writev_out: |
| 2174 | cifs_small_buf_release(smb); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2175 | return rc; |
| 2176 | } |
| 2177 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2178 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2179 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2180 | unsigned int *nbytes, struct kvec *iov, int n_vec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | { |
| 2182 | int rc = -EACCES; |
| 2183 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2184 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2185 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2186 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2187 | __u32 pid = io_parms->pid; |
| 2188 | __u16 netfid = io_parms->netfid; |
| 2189 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2190 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2191 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2193 | *nbytes = 0; |
| 2194 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2195 | cifs_dbg(FYI, "write2 at %lld %d bytes\n", (long long)offset, count); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2196 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2197 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2198 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2199 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2200 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2201 | if ((offset >> 32) > 0) { |
| 2202 | /* can not handle big offset for old srv */ |
| 2203 | return -EIO; |
| 2204 | } |
| 2205 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2206 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | if (rc) |
| 2208 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2209 | |
| 2210 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2211 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | /* tcon and ses pointer are checked in smb_init */ |
| 2214 | if (tcon->ses->server == NULL) |
| 2215 | return -ECONNABORTED; |
| 2216 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2217 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | pSMB->Fid = netfid; |
| 2219 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2220 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2221 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | pSMB->Reserved = 0xFFFFFFFF; |
| 2223 | pSMB->WriteMode = 0; |
| 2224 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2227 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2229 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2230 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2231 | /* header + 1 byte pad */ |
| 2232 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2233 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2234 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2235 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2236 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2237 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2238 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2239 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2240 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2241 | (struct smb_com_writex_req *)pSMB; |
| 2242 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2243 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2244 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2245 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2246 | iov[0].iov_len = smb_hdr_len + 4; |
| 2247 | else /* wct == 12 pad bigger by four bytes */ |
| 2248 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2249 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2250 | |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2251 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2252 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2254 | cifs_dbg(FYI, "Send error Write2 = %d\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2255 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2256 | /* presumably this can not happen, but best to be safe */ |
| 2257 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2258 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2259 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2260 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2261 | *nbytes = (*nbytes) << 16; |
| 2262 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2263 | |
| 2264 | /* |
| 2265 | * Mask off high 16 bits when bytes written as returned by the |
| 2266 | * server is greater than bytes requested by the client. OS/2 |
| 2267 | * servers are known to set incorrect CountHigh values. |
| 2268 | */ |
| 2269 | if (*nbytes > count) |
| 2270 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 2273 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Sachin Prabhu | 6d81ed1 | 2014-06-16 15:35:24 +0100 | [diff] [blame] | 2274 | free_rsp_buf(resp_buf_type, iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2276 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | since file handle passed in no longer valid */ |
| 2278 | |
| 2279 | return rc; |
| 2280 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2281 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2282 | int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon, |
| 2283 | const __u16 netfid, const __u8 lock_type, const __u32 num_unlock, |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2284 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2285 | { |
| 2286 | int rc = 0; |
| 2287 | LOCK_REQ *pSMB = NULL; |
| 2288 | struct kvec iov[2]; |
| 2289 | int resp_buf_type; |
| 2290 | __u16 count; |
| 2291 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2292 | cifs_dbg(FYI, "cifs_lockv num lock %d num unlock %d\n", |
| 2293 | num_lock, num_unlock); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2294 | |
| 2295 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2296 | if (rc) |
| 2297 | return rc; |
| 2298 | |
| 2299 | pSMB->Timeout = 0; |
| 2300 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2301 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2302 | pSMB->LockType = lock_type; |
| 2303 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2304 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2305 | |
| 2306 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2307 | inc_rfc1001_len(pSMB, count); |
| 2308 | pSMB->ByteCount = cpu_to_le16(count); |
| 2309 | |
| 2310 | iov[0].iov_base = (char *)pSMB; |
| 2311 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2312 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2313 | iov[1].iov_base = (char *)buf; |
| 2314 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2315 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2316 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2317 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP); |
| 2318 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2319 | cifs_dbg(FYI, "Send error in cifs_lockv = %d\n", rc); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2320 | |
| 2321 | return rc; |
| 2322 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2325 | CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2326 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2328 | const __u32 numLock, const __u8 lockType, |
| 2329 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | { |
| 2331 | int rc = 0; |
| 2332 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2333 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | int bytes_returned; |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2335 | int flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | __u16 count; |
| 2337 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2338 | cifs_dbg(FYI, "CIFSSMBLock timeout %d numLock %d\n", |
| 2339 | (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2340 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | if (rc) |
| 2343 | return rc; |
| 2344 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2345 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2346 | /* no response expected */ |
| 2347 | flags = CIFS_ASYNC_OP | CIFS_OBREAK_OP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2349 | } else if (waitFlag) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2350 | flags = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2352 | } else { |
| 2353 | pSMB->Timeout = 0; |
| 2354 | } |
| 2355 | |
| 2356 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2357 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2358 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2359 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2361 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2362 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2363 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2364 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | /* BB where to store pid high? */ |
| 2366 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2367 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2368 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2369 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2370 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2371 | } else { |
| 2372 | /* oplock break */ |
| 2373 | count = 0; |
| 2374 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2375 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | pSMB->ByteCount = cpu_to_le16(count); |
| 2377 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2378 | if (waitFlag) { |
| 2379 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2380 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2381 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2382 | } else { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2383 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, flags); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2384 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2385 | } |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2386 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2387 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2388 | cifs_dbg(FYI, "Send error in Lock = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2390 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | since file handle passed in no longer valid */ |
| 2392 | return rc; |
| 2393 | } |
| 2394 | |
| 2395 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2396 | CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2397 | const __u16 smb_file_id, const __u32 netpid, |
| 2398 | const loff_t start_offset, const __u64 len, |
| 2399 | struct file_lock *pLockData, const __u16 lock_type, |
| 2400 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2401 | { |
| 2402 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2403 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2404 | struct cifs_posix_lock *parm_data; |
| 2405 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2406 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2407 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2408 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2409 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2410 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2411 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2412 | cifs_dbg(FYI, "Posix Lock\n"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2413 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2414 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2415 | |
| 2416 | if (rc) |
| 2417 | return rc; |
| 2418 | |
| 2419 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2420 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2421 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2422 | pSMB->MaxSetupCount = 0; |
| 2423 | pSMB->Reserved = 0; |
| 2424 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2425 | pSMB->Reserved2 = 0; |
| 2426 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2427 | offset = param_offset + params; |
| 2428 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2429 | count = sizeof(struct cifs_posix_lock); |
| 2430 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2431 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2432 | pSMB->SetupCount = 1; |
| 2433 | pSMB->Reserved3 = 0; |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2434 | if (pLockData) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2435 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2436 | else |
| 2437 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2438 | byte_count = 3 /* pad */ + params + count; |
| 2439 | pSMB->DataCount = cpu_to_le16(count); |
| 2440 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2441 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2442 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2443 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2444 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2445 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2446 | |
| 2447 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2448 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2449 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2450 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2451 | pSMB->Timeout = cpu_to_le32(-1); |
| 2452 | } else |
| 2453 | pSMB->Timeout = 0; |
| 2454 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2455 | parm_data->pid = cpu_to_le32(netpid); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2456 | parm_data->start = cpu_to_le64(start_offset); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2457 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2458 | |
| 2459 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2460 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2461 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2462 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2463 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2464 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2465 | if (waitFlag) { |
| 2466 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2467 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2468 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2469 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2470 | 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] | 2471 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 2472 | &resp_buf_type, timeout); |
| 2473 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 2474 | not try to free it twice below on exit */ |
| 2475 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2476 | } |
| 2477 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2478 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2479 | cifs_dbg(FYI, "Send error in Posix Lock = %d\n", rc); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2480 | } else if (pLockData) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2481 | /* lock structure can be returned on get */ |
| 2482 | __u16 data_offset; |
| 2483 | __u16 data_count; |
| 2484 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2485 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2486 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2487 | rc = -EIO; /* bad smb */ |
| 2488 | goto plk_err_exit; |
| 2489 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2490 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2491 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2492 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2493 | rc = -EIO; |
| 2494 | goto plk_err_exit; |
| 2495 | } |
| 2496 | parm_data = (struct cifs_posix_lock *) |
| 2497 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2498 | if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2499 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2500 | else { |
| 2501 | if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2502 | cpu_to_le16(CIFS_RDLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2503 | pLockData->fl_type = F_RDLCK; |
| 2504 | else if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2505 | cpu_to_le16(CIFS_WRLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2506 | pLockData->fl_type = F_WRLCK; |
| 2507 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2508 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2509 | pLockData->fl_end = pLockData->fl_start + |
| 2510 | le64_to_cpu(parm_data->length) - 1; |
| 2511 | pLockData->fl_pid = le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2512 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2513 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2514 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2515 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2516 | if (pSMB) |
| 2517 | cifs_small_buf_release(pSMB); |
| 2518 | |
Sachin Prabhu | 6d81ed1 | 2014-06-16 15:35:24 +0100 | [diff] [blame] | 2519 | free_rsp_buf(resp_buf_type, iov[0].iov_base); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2520 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2521 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2522 | since file handle passed in no longer valid */ |
| 2523 | |
| 2524 | return rc; |
| 2525 | } |
| 2526 | |
| 2527 | |
| 2528 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2529 | CIFSSMBClose(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | { |
| 2531 | int rc = 0; |
| 2532 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2533 | cifs_dbg(FYI, "In CIFSSMBClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | |
| 2535 | /* do not retry on dead session on close */ |
| 2536 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2537 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | return 0; |
| 2539 | if (rc) |
| 2540 | return rc; |
| 2541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2543 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2545 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2546 | cifs_stats_inc(&tcon->stats.cifs_stats.num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2548 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2550 | cifs_dbg(VFS, "Send error in Close = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | } |
| 2552 | } |
| 2553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2555 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | rc = 0; |
| 2557 | |
| 2558 | return rc; |
| 2559 | } |
| 2560 | |
| 2561 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2562 | CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id) |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2563 | { |
| 2564 | int rc = 0; |
| 2565 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2566 | cifs_dbg(FYI, "In CIFSSMBFlush\n"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2567 | |
| 2568 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2569 | if (rc) |
| 2570 | return rc; |
| 2571 | |
| 2572 | pSMB->FileID = (__u16) smb_file_id; |
| 2573 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2574 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2575 | cifs_stats_inc(&tcon->stats.cifs_stats.num_flushes); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2576 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2577 | cifs_dbg(VFS, "Send error in Flush = %d\n", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2578 | |
| 2579 | return rc; |
| 2580 | } |
| 2581 | |
| 2582 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2583 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2584 | const char *from_name, const char *to_name, |
| 2585 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | { |
| 2587 | int rc = 0; |
| 2588 | RENAME_REQ *pSMB = NULL; |
| 2589 | RENAME_RSP *pSMBr = NULL; |
| 2590 | int bytes_returned; |
| 2591 | int name_len, name_len2; |
| 2592 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 2593 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2595 | cifs_dbg(FYI, "In CIFSSMBRename\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | renameRetry: |
| 2597 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2598 | (void **) &pSMBr); |
| 2599 | if (rc) |
| 2600 | return rc; |
| 2601 | |
| 2602 | pSMB->BufferFormat = 0x04; |
| 2603 | pSMB->SearchAttributes = |
| 2604 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2605 | ATTR_DIRECTORY); |
| 2606 | |
| 2607 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2608 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2609 | from_name, PATH_MAX, |
| 2610 | cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | name_len++; /* trailing null */ |
| 2612 | name_len *= 2; |
| 2613 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2614 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2615 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2616 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2617 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2618 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 2619 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2621 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2622 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2623 | name_len = strnlen(from_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | name_len++; /* trailing null */ |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2625 | strncpy(pSMB->OldFileName, from_name, name_len); |
| 2626 | name_len2 = strnlen(to_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | name_len2++; /* trailing null */ |
| 2628 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2629 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | name_len2++; /* trailing null */ |
| 2631 | name_len2++; /* signature byte */ |
| 2632 | } |
| 2633 | |
| 2634 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2635 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | pSMB->ByteCount = cpu_to_le16(count); |
| 2637 | |
| 2638 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2639 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2640 | cifs_stats_inc(&tcon->stats.cifs_stats.num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2641 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2642 | cifs_dbg(FYI, "Send error in rename = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | cifs_buf_release(pSMB); |
| 2645 | |
| 2646 | if (rc == -EAGAIN) |
| 2647 | goto renameRetry; |
| 2648 | |
| 2649 | return rc; |
| 2650 | } |
| 2651 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2652 | int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2653 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2654 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | { |
| 2656 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2657 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2658 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | char *data_offset; |
| 2660 | char dummy_string[30]; |
| 2661 | int rc = 0; |
| 2662 | int bytes_returned = 0; |
| 2663 | int len_of_str; |
| 2664 | __u16 params, param_offset, offset, count, byte_count; |
| 2665 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2666 | cifs_dbg(FYI, "Rename to File by handle\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2668 | (void **) &pSMBr); |
| 2669 | if (rc) |
| 2670 | return rc; |
| 2671 | |
| 2672 | params = 6; |
| 2673 | pSMB->MaxSetupCount = 0; |
| 2674 | pSMB->Reserved = 0; |
| 2675 | pSMB->Flags = 0; |
| 2676 | pSMB->Timeout = 0; |
| 2677 | pSMB->Reserved2 = 0; |
| 2678 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2679 | offset = param_offset + params; |
| 2680 | |
| 2681 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2682 | rename_info = (struct set_file_rename *) data_offset; |
| 2683 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2684 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | pSMB->SetupCount = 1; |
| 2686 | pSMB->Reserved3 = 0; |
| 2687 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2688 | byte_count = 3 /* pad */ + params; |
| 2689 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2690 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2691 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2692 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2693 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2694 | rename_info->overwrite = cpu_to_le32(1); |
| 2695 | rename_info->root_fid = 0; |
| 2696 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2697 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2698 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2699 | len_of_str = |
| 2700 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2701 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2703 | len_of_str = |
| 2704 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2705 | target_name, PATH_MAX, nls_codepage, |
| 2706 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | } |
| 2708 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2709 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | byte_count += count; |
| 2711 | pSMB->DataCount = cpu_to_le16(count); |
| 2712 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2713 | pSMB->Fid = netfid; |
| 2714 | pSMB->InformationLevel = |
| 2715 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2716 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2717 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2719 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2720 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2721 | cifs_stats_inc(&pTcon->stats.cifs_stats.num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2722 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2723 | cifs_dbg(FYI, "Send error in Rename (by file handle) = %d\n", |
| 2724 | rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | cifs_buf_release(pSMB); |
| 2727 | |
| 2728 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2729 | since file handle passed in no longer valid */ |
| 2730 | |
| 2731 | return rc; |
| 2732 | } |
| 2733 | |
| 2734 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2735 | CIFSSMBCopy(const unsigned int xid, struct cifs_tcon *tcon, |
| 2736 | const char *fromName, const __u16 target_tid, const char *toName, |
| 2737 | const int flags, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | { |
| 2739 | int rc = 0; |
| 2740 | COPY_REQ *pSMB = NULL; |
| 2741 | COPY_RSP *pSMBr = NULL; |
| 2742 | int bytes_returned; |
| 2743 | int name_len, name_len2; |
| 2744 | __u16 count; |
| 2745 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2746 | cifs_dbg(FYI, "In CIFSSMBCopy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | copyRetry: |
| 2748 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2749 | (void **) &pSMBr); |
| 2750 | if (rc) |
| 2751 | return rc; |
| 2752 | |
| 2753 | pSMB->BufferFormat = 0x04; |
| 2754 | pSMB->Tid2 = target_tid; |
| 2755 | |
| 2756 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2757 | |
| 2758 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2759 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2760 | fromName, PATH_MAX, nls_codepage, |
| 2761 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | name_len++; /* trailing null */ |
| 2763 | name_len *= 2; |
| 2764 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2765 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2766 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2767 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2768 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2769 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2771 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2772 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | name_len = strnlen(fromName, PATH_MAX); |
| 2774 | name_len++; /* trailing null */ |
| 2775 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2776 | name_len2 = strnlen(toName, PATH_MAX); |
| 2777 | name_len2++; /* trailing null */ |
| 2778 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2779 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2780 | name_len2++; /* trailing null */ |
| 2781 | name_len2++; /* signature byte */ |
| 2782 | } |
| 2783 | |
| 2784 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2785 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | pSMB->ByteCount = cpu_to_le16(count); |
| 2787 | |
| 2788 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2789 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2790 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2791 | cifs_dbg(FYI, "Send error in copy = %d with %d files copied\n", |
| 2792 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2794 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | |
| 2796 | if (rc == -EAGAIN) |
| 2797 | goto copyRetry; |
| 2798 | |
| 2799 | return rc; |
| 2800 | } |
| 2801 | |
| 2802 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2803 | CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | const char *fromName, const char *toName, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2805 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | { |
| 2807 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2808 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2809 | char *data_offset; |
| 2810 | int name_len; |
| 2811 | int name_len_target; |
| 2812 | int rc = 0; |
| 2813 | int bytes_returned = 0; |
| 2814 | __u16 params, param_offset, offset, byte_count; |
| 2815 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2816 | cifs_dbg(FYI, "In Symlink Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | createSymLinkRetry: |
| 2818 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2819 | (void **) &pSMBr); |
| 2820 | if (rc) |
| 2821 | return rc; |
| 2822 | |
| 2823 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2824 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2825 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fromName, |
| 2826 | /* find define for this maxpathcomponent */ |
| 2827 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | name_len++; /* trailing null */ |
| 2829 | name_len *= 2; |
| 2830 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2831 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | name_len = strnlen(fromName, PATH_MAX); |
| 2833 | name_len++; /* trailing null */ |
| 2834 | strncpy(pSMB->FileName, fromName, name_len); |
| 2835 | } |
| 2836 | params = 6 + name_len; |
| 2837 | pSMB->MaxSetupCount = 0; |
| 2838 | pSMB->Reserved = 0; |
| 2839 | pSMB->Flags = 0; |
| 2840 | pSMB->Timeout = 0; |
| 2841 | pSMB->Reserved2 = 0; |
| 2842 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2843 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | offset = param_offset + params; |
| 2845 | |
| 2846 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2847 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2848 | name_len_target = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2849 | cifsConvertToUTF16((__le16 *) data_offset, toName, |
| 2850 | /* find define for this maxpathcomponent */ |
| 2851 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | name_len_target++; /* trailing null */ |
| 2853 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2854 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | name_len_target = strnlen(toName, PATH_MAX); |
| 2856 | name_len_target++; /* trailing null */ |
| 2857 | strncpy(data_offset, toName, name_len_target); |
| 2858 | } |
| 2859 | |
| 2860 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2861 | /* BB find exact max on data count below from sess */ |
| 2862 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2863 | pSMB->SetupCount = 1; |
| 2864 | pSMB->Reserved3 = 0; |
| 2865 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2866 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2867 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2868 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2869 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2870 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2871 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2872 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2873 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2874 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2875 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2877 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2878 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2879 | cifs_stats_inc(&tcon->stats.cifs_stats.num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2880 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2881 | cifs_dbg(FYI, "Send error in SetPathInfo create symlink = %d\n", |
| 2882 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2884 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | |
| 2886 | if (rc == -EAGAIN) |
| 2887 | goto createSymLinkRetry; |
| 2888 | |
| 2889 | return rc; |
| 2890 | } |
| 2891 | |
| 2892 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2893 | CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2895 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | { |
| 2897 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2898 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2899 | char *data_offset; |
| 2900 | int name_len; |
| 2901 | int name_len_target; |
| 2902 | int rc = 0; |
| 2903 | int bytes_returned = 0; |
| 2904 | __u16 params, param_offset, offset, byte_count; |
| 2905 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2906 | cifs_dbg(FYI, "In Create Hard link Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | createHardLinkRetry: |
| 2908 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2909 | (void **) &pSMBr); |
| 2910 | if (rc) |
| 2911 | return rc; |
| 2912 | |
| 2913 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2914 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 2915 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | name_len++; /* trailing null */ |
| 2917 | name_len *= 2; |
| 2918 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2919 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | name_len = strnlen(toName, PATH_MAX); |
| 2921 | name_len++; /* trailing null */ |
| 2922 | strncpy(pSMB->FileName, toName, name_len); |
| 2923 | } |
| 2924 | params = 6 + name_len; |
| 2925 | pSMB->MaxSetupCount = 0; |
| 2926 | pSMB->Reserved = 0; |
| 2927 | pSMB->Flags = 0; |
| 2928 | pSMB->Timeout = 0; |
| 2929 | pSMB->Reserved2 = 0; |
| 2930 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2931 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | offset = param_offset + params; |
| 2933 | |
| 2934 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2935 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2936 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2937 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 2938 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | name_len_target++; /* trailing null */ |
| 2940 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2941 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2943 | name_len_target++; /* trailing null */ |
| 2944 | strncpy(data_offset, fromName, name_len_target); |
| 2945 | } |
| 2946 | |
| 2947 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2948 | /* BB find exact max on data count below from sess*/ |
| 2949 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2950 | pSMB->SetupCount = 1; |
| 2951 | pSMB->Reserved3 = 0; |
| 2952 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2953 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2954 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2955 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2956 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2957 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2958 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2959 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2960 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2961 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2962 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2964 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2965 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2966 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2967 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2968 | cifs_dbg(FYI, "Send error in SetPathInfo (hard link) = %d\n", |
| 2969 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | |
| 2971 | cifs_buf_release(pSMB); |
| 2972 | if (rc == -EAGAIN) |
| 2973 | goto createHardLinkRetry; |
| 2974 | |
| 2975 | return rc; |
| 2976 | } |
| 2977 | |
| 2978 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2979 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2980 | const char *from_name, const char *to_name, |
| 2981 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | { |
| 2983 | int rc = 0; |
| 2984 | NT_RENAME_REQ *pSMB = NULL; |
| 2985 | RENAME_RSP *pSMBr = NULL; |
| 2986 | int bytes_returned; |
| 2987 | int name_len, name_len2; |
| 2988 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 2989 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2991 | cifs_dbg(FYI, "In CIFSCreateHardLink\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | winCreateHardLinkRetry: |
| 2993 | |
| 2994 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2995 | (void **) &pSMBr); |
| 2996 | if (rc) |
| 2997 | return rc; |
| 2998 | |
| 2999 | pSMB->SearchAttributes = |
| 3000 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3001 | ATTR_DIRECTORY); |
| 3002 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 3003 | pSMB->ClusterCount = 0; |
| 3004 | |
| 3005 | pSMB->BufferFormat = 0x04; |
| 3006 | |
| 3007 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3008 | name_len = |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3009 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, from_name, |
| 3010 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | name_len++; /* trailing null */ |
| 3012 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 3013 | |
| 3014 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 3015 | pSMB->OldFileName[name_len] = 0x04; |
| 3016 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3018 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3019 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 3020 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 3022 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3023 | } else { /* BB improve the check for buffer overruns BB */ |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3024 | name_len = strnlen(from_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | name_len++; /* trailing null */ |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3026 | strncpy(pSMB->OldFileName, from_name, name_len); |
| 3027 | name_len2 = strnlen(to_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | name_len2++; /* trailing null */ |
| 3029 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3030 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | name_len2++; /* trailing null */ |
| 3032 | name_len2++; /* signature byte */ |
| 3033 | } |
| 3034 | |
| 3035 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3036 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | pSMB->ByteCount = cpu_to_le16(count); |
| 3038 | |
| 3039 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3040 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3041 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3042 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3043 | cifs_dbg(FYI, "Send error in hard link (NT rename) = %d\n", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | cifs_buf_release(pSMB); |
| 3046 | if (rc == -EAGAIN) |
| 3047 | goto winCreateHardLinkRetry; |
| 3048 | |
| 3049 | return rc; |
| 3050 | } |
| 3051 | |
| 3052 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3053 | CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3054 | const unsigned char *searchName, char **symlinkinfo, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3055 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | { |
| 3057 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 3058 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3059 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3060 | int rc = 0; |
| 3061 | int bytes_returned; |
| 3062 | int name_len; |
| 3063 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3064 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3066 | cifs_dbg(FYI, "In QPathSymLinkInfo (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | |
| 3068 | querySymLinkRetry: |
| 3069 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3070 | (void **) &pSMBr); |
| 3071 | if (rc) |
| 3072 | return rc; |
| 3073 | |
| 3074 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3075 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3076 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3077 | searchName, PATH_MAX, nls_codepage, |
| 3078 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | name_len++; /* trailing null */ |
| 3080 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3081 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | name_len = strnlen(searchName, PATH_MAX); |
| 3083 | name_len++; /* trailing null */ |
| 3084 | strncpy(pSMB->FileName, searchName, name_len); |
| 3085 | } |
| 3086 | |
| 3087 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3088 | pSMB->TotalDataCount = 0; |
| 3089 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3090 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | pSMB->MaxSetupCount = 0; |
| 3092 | pSMB->Reserved = 0; |
| 3093 | pSMB->Flags = 0; |
| 3094 | pSMB->Timeout = 0; |
| 3095 | pSMB->Reserved2 = 0; |
| 3096 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3097 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | pSMB->DataCount = 0; |
| 3099 | pSMB->DataOffset = 0; |
| 3100 | pSMB->SetupCount = 1; |
| 3101 | pSMB->Reserved3 = 0; |
| 3102 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3103 | byte_count = params + 1 /* pad */ ; |
| 3104 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3105 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3106 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3107 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3108 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3110 | |
| 3111 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3112 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3113 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3114 | cifs_dbg(FYI, "Send error in QuerySymLinkInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } else { |
| 3116 | /* decode response */ |
| 3117 | |
| 3118 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3120 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3121 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3123 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3124 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3126 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3127 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3128 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3129 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3130 | is_unicode = true; |
| 3131 | else |
| 3132 | is_unicode = false; |
| 3133 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3134 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3135 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3136 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3137 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3138 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | } |
| 3140 | } |
| 3141 | cifs_buf_release(pSMB); |
| 3142 | if (rc == -EAGAIN) |
| 3143 | goto querySymLinkRetry; |
| 3144 | return rc; |
| 3145 | } |
| 3146 | |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3147 | /* |
| 3148 | * Recent Windows versions now create symlinks more frequently |
| 3149 | * and they use the "reparse point" mechanism below. We can of course |
| 3150 | * do symlinks nicely to Samba and other servers which support the |
| 3151 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3152 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3153 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3154 | * In the interim this code has been moved to its own config option so |
| 3155 | * it is not compiled in by default until callers fixed up and more tested. |
| 3156 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | int |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3158 | CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
| 3159 | __u16 fid, char **symlinkinfo, |
| 3160 | const struct nls_table *nls_codepage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | { |
| 3162 | int rc = 0; |
| 3163 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3164 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3165 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3166 | bool is_unicode; |
| 3167 | unsigned int sub_len; |
| 3168 | char *sub_start; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3169 | struct reparse_symlink_data *reparse_buf; |
| 3170 | struct reparse_posix_data *posix_buf; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3171 | __u32 data_offset, data_count; |
| 3172 | char *end_of_smb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3174 | cifs_dbg(FYI, "In Windows reparse style QueryLink for fid %u\n", fid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3176 | (void **) &pSMBr); |
| 3177 | if (rc) |
| 3178 | return rc; |
| 3179 | |
| 3180 | pSMB->TotalParameterCount = 0 ; |
| 3181 | pSMB->TotalDataCount = 0; |
| 3182 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3183 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3184 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | pSMB->MaxSetupCount = 4; |
| 3186 | pSMB->Reserved = 0; |
| 3187 | pSMB->ParameterOffset = 0; |
| 3188 | pSMB->DataCount = 0; |
| 3189 | pSMB->DataOffset = 0; |
| 3190 | pSMB->SetupCount = 4; |
| 3191 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3192 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3193 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3194 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3195 | pSMB->IsRootFlag = 0; |
| 3196 | pSMB->Fid = fid; /* file handle always le */ |
| 3197 | pSMB->ByteCount = 0; |
| 3198 | |
| 3199 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3200 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3201 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3202 | cifs_dbg(FYI, "Send error in QueryReparseLinkInfo = %d\n", rc); |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3203 | goto qreparse_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3205 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3206 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3207 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3208 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3209 | /* BB also check enough total bytes returned */ |
| 3210 | rc = -EIO; /* bad smb */ |
| 3211 | goto qreparse_out; |
| 3212 | } |
| 3213 | if (!data_count || (data_count > 2048)) { |
| 3214 | rc = -EIO; |
| 3215 | cifs_dbg(FYI, "Invalid return data count on get reparse info ioctl\n"); |
| 3216 | goto qreparse_out; |
| 3217 | } |
| 3218 | end_of_smb = 2 + get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3219 | reparse_buf = (struct reparse_symlink_data *) |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3220 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
| 3221 | if ((char *)reparse_buf >= end_of_smb) { |
| 3222 | rc = -EIO; |
| 3223 | goto qreparse_out; |
| 3224 | } |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3225 | if (reparse_buf->ReparseTag == cpu_to_le32(IO_REPARSE_TAG_NFS)) { |
| 3226 | cifs_dbg(FYI, "NFS style reparse tag\n"); |
| 3227 | posix_buf = (struct reparse_posix_data *)reparse_buf; |
| 3228 | |
| 3229 | if (posix_buf->InodeType != cpu_to_le64(NFS_SPECFILE_LNK)) { |
| 3230 | cifs_dbg(FYI, "unsupported file type 0x%llx\n", |
| 3231 | le64_to_cpu(posix_buf->InodeType)); |
| 3232 | rc = -EOPNOTSUPP; |
| 3233 | goto qreparse_out; |
| 3234 | } |
| 3235 | is_unicode = true; |
| 3236 | sub_len = le16_to_cpu(reparse_buf->ReparseDataLength); |
| 3237 | if (posix_buf->PathBuffer + sub_len > end_of_smb) { |
| 3238 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3239 | rc = -EIO; |
| 3240 | goto qreparse_out; |
| 3241 | } |
| 3242 | *symlinkinfo = cifs_strndup_from_utf16(posix_buf->PathBuffer, |
| 3243 | sub_len, is_unicode, nls_codepage); |
| 3244 | goto qreparse_out; |
| 3245 | } else if (reparse_buf->ReparseTag != |
| 3246 | cpu_to_le32(IO_REPARSE_TAG_SYMLINK)) { |
| 3247 | rc = -EOPNOTSUPP; |
| 3248 | goto qreparse_out; |
| 3249 | } |
| 3250 | |
| 3251 | /* Reparse tag is NTFS symlink */ |
| 3252 | sub_start = le16_to_cpu(reparse_buf->SubstituteNameOffset) + |
| 3253 | reparse_buf->PathBuffer; |
| 3254 | sub_len = le16_to_cpu(reparse_buf->SubstituteNameLength); |
| 3255 | if (sub_start + sub_len > end_of_smb) { |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3256 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3257 | rc = -EIO; |
| 3258 | goto qreparse_out; |
| 3259 | } |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3260 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3261 | is_unicode = true; |
| 3262 | else |
| 3263 | is_unicode = false; |
| 3264 | |
| 3265 | /* BB FIXME investigate remapping reserved chars here */ |
| 3266 | *symlinkinfo = cifs_strndup_from_utf16(sub_start, sub_len, is_unicode, |
| 3267 | nls_codepage); |
| 3268 | if (!*symlinkinfo) |
| 3269 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3271 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3273 | /* |
| 3274 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3275 | * since file handle passed in no longer valid. |
| 3276 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | return rc; |
| 3278 | } |
| 3279 | |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3280 | int |
| 3281 | CIFSSMB_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 3282 | __u16 fid) |
| 3283 | { |
| 3284 | int rc = 0; |
| 3285 | int bytes_returned; |
| 3286 | struct smb_com_transaction_compr_ioctl_req *pSMB; |
| 3287 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
| 3288 | |
| 3289 | cifs_dbg(FYI, "Set compression for %u\n", fid); |
| 3290 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3291 | (void **) &pSMBr); |
| 3292 | if (rc) |
| 3293 | return rc; |
| 3294 | |
| 3295 | pSMB->compression_state = cpu_to_le16(COMPRESSION_FORMAT_DEFAULT); |
| 3296 | |
| 3297 | pSMB->TotalParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3298 | pSMB->TotalDataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3299 | pSMB->MaxParameterCount = 0; |
| 3300 | pSMB->MaxDataCount = 0; |
| 3301 | pSMB->MaxSetupCount = 4; |
| 3302 | pSMB->Reserved = 0; |
| 3303 | pSMB->ParameterOffset = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3304 | pSMB->DataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3305 | pSMB->DataOffset = |
| 3306 | cpu_to_le32(offsetof(struct smb_com_transaction_compr_ioctl_req, |
| 3307 | compression_state) - 4); /* 84 */ |
| 3308 | pSMB->SetupCount = 4; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3309 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3310 | pSMB->ParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3311 | pSMB->FunctionCode = cpu_to_le32(FSCTL_SET_COMPRESSION); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3312 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3313 | pSMB->IsRootFlag = 0; |
| 3314 | pSMB->Fid = fid; /* file handle always le */ |
| 3315 | /* 3 byte pad, followed by 2 byte compress state */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3316 | pSMB->ByteCount = cpu_to_le16(5); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3317 | inc_rfc1001_len(pSMB, 5); |
| 3318 | |
| 3319 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3320 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3321 | if (rc) |
| 3322 | cifs_dbg(FYI, "Send error in SetCompression = %d\n", rc); |
| 3323 | |
| 3324 | cifs_buf_release(pSMB); |
| 3325 | |
| 3326 | /* |
| 3327 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3328 | * since file handle passed in no longer valid. |
| 3329 | */ |
| 3330 | return rc; |
| 3331 | } |
| 3332 | |
| 3333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | #ifdef CONFIG_CIFS_POSIX |
| 3335 | |
| 3336 | /*Convert an Access Control Entry from wire format to local POSIX xattr format*/ |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3337 | static void cifs_convert_ace(struct posix_acl_xattr_entry *ace, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3338 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | { |
| 3340 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3341 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3342 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3343 | ace->e_id = cpu_to_le32(le64_to_cpu(cifs_ace->cifs_uid)); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3344 | /* |
| 3345 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3346 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3347 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | |
| 3349 | return; |
| 3350 | } |
| 3351 | |
| 3352 | /* 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] | 3353 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3354 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | { |
| 3356 | int size = 0; |
| 3357 | int i; |
| 3358 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3359 | struct cifs_posix_ace *pACE; |
| 3360 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3361 | struct posix_acl_xattr_header *local_acl = (void *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | |
| 3363 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3364 | return -EOPNOTSUPP; |
| 3365 | |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3366 | if (acl_type == ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3368 | pACE = &cifs_acl->ace_array[0]; |
| 3369 | size = sizeof(struct cifs_posix_acl); |
| 3370 | size += sizeof(struct cifs_posix_ace) * count; |
| 3371 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3372 | if (size_of_data_area < size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3373 | cifs_dbg(FYI, "bad CIFS POSIX ACL size %d vs. %d\n", |
| 3374 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | return -EINVAL; |
| 3376 | } |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3377 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3379 | size = sizeof(struct cifs_posix_acl); |
| 3380 | size += sizeof(struct cifs_posix_ace) * count; |
| 3381 | /* skip past access ACEs to get to default ACEs */ |
| 3382 | pACE = &cifs_acl->ace_array[count]; |
| 3383 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3384 | size += sizeof(struct cifs_posix_ace) * count; |
| 3385 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3386 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | return -EINVAL; |
| 3388 | } else { |
| 3389 | /* illegal type */ |
| 3390 | return -EINVAL; |
| 3391 | } |
| 3392 | |
| 3393 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3394 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3395 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3396 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | return -ERANGE; |
| 3398 | } else /* buffer big enough */ { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3399 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
| 3400 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3401 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3402 | for (i = 0; i < count ; i++) { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3403 | cifs_convert_ace(&ace[i], pACE); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3404 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | } |
| 3406 | } |
| 3407 | return size; |
| 3408 | } |
| 3409 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3410 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3411 | const struct posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | { |
| 3413 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 3414 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3415 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3416 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3418 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3420 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3421 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3422 | cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3423 | /* |
| 3424 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3425 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3426 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | return rc; |
| 3428 | } |
| 3429 | |
| 3430 | /* 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] | 3431 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3432 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | { |
| 3434 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3435 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3436 | struct posix_acl_xattr_header *local_acl = (void *)pACL; |
Eryu Guan | ae9ebe7 | 2016-10-24 20:46:40 +0800 | [diff] [blame] | 3437 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | int count; |
| 3439 | int i; |
| 3440 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3441 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | return 0; |
| 3443 | |
| 3444 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3445 | cifs_dbg(FYI, "setting acl with %d entries from buf of length %d and version of %d\n", |
| 3446 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3447 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3448 | cifs_dbg(FYI, "unknown POSIX ACL version %d\n", |
| 3449 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | return 0; |
| 3451 | } |
| 3452 | cifs_acl->version = cpu_to_le16(1); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3453 | if (acl_type == ACL_TYPE_ACCESS) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3454 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3455 | cifs_acl->default_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3456 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3457 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3458 | cifs_acl->access_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3459 | } else { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3460 | cifs_dbg(FYI, "unknown ACL type %d\n", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | return 0; |
| 3462 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3463 | for (i = 0; i < count; i++) { |
Eryu Guan | ae9ebe7 | 2016-10-24 20:46:40 +0800 | [diff] [blame] | 3464 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], &ace[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3465 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | /* ACE not converted */ |
| 3467 | break; |
| 3468 | } |
| 3469 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3470 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3472 | rc += sizeof(struct cifs_posix_acl); |
| 3473 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3474 | } |
| 3475 | return rc; |
| 3476 | } |
| 3477 | |
| 3478 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3479 | CIFSSMBGetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3480 | const unsigned char *searchName, |
| 3481 | char *acl_inf, const int buflen, const int acl_type, |
| 3482 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | { |
| 3484 | /* SMB_QUERY_POSIX_ACL */ |
| 3485 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3486 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3487 | int rc = 0; |
| 3488 | int bytes_returned; |
| 3489 | int name_len; |
| 3490 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3491 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3492 | cifs_dbg(FYI, "In GetPosixACL (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | |
| 3494 | queryAclRetry: |
| 3495 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3496 | (void **) &pSMBr); |
| 3497 | if (rc) |
| 3498 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3501 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3502 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3503 | searchName, PATH_MAX, nls_codepage, |
| 3504 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | name_len++; /* trailing null */ |
| 3506 | name_len *= 2; |
| 3507 | pSMB->FileName[name_len] = 0; |
| 3508 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3509 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | name_len = strnlen(searchName, PATH_MAX); |
| 3511 | name_len++; /* trailing null */ |
| 3512 | strncpy(pSMB->FileName, searchName, name_len); |
| 3513 | } |
| 3514 | |
| 3515 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3516 | pSMB->TotalDataCount = 0; |
| 3517 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3518 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3520 | pSMB->MaxSetupCount = 0; |
| 3521 | pSMB->Reserved = 0; |
| 3522 | pSMB->Flags = 0; |
| 3523 | pSMB->Timeout = 0; |
| 3524 | pSMB->Reserved2 = 0; |
| 3525 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3526 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3527 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | pSMB->DataCount = 0; |
| 3529 | pSMB->DataOffset = 0; |
| 3530 | pSMB->SetupCount = 1; |
| 3531 | pSMB->Reserved3 = 0; |
| 3532 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3533 | byte_count = params + 1 /* pad */ ; |
| 3534 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3535 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3536 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3537 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3538 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3540 | |
| 3541 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3542 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3543 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3545 | cifs_dbg(FYI, "Send error in Query POSIX ACL = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | } else { |
| 3547 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3551 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | rc = -EIO; /* bad smb */ |
| 3553 | else { |
| 3554 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3555 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3556 | rc = cifs_copy_posix_acl(acl_inf, |
| 3557 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3558 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | } |
| 3560 | } |
| 3561 | cifs_buf_release(pSMB); |
| 3562 | if (rc == -EAGAIN) |
| 3563 | goto queryAclRetry; |
| 3564 | return rc; |
| 3565 | } |
| 3566 | |
| 3567 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3568 | CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3569 | const unsigned char *fileName, |
| 3570 | const char *local_acl, const int buflen, |
| 3571 | const int acl_type, |
| 3572 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | { |
| 3574 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3575 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3576 | char *parm_data; |
| 3577 | int name_len; |
| 3578 | int rc = 0; |
| 3579 | int bytes_returned = 0; |
| 3580 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3581 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3582 | cifs_dbg(FYI, "In SetPosixACL (Unix) for path %s\n", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | setAclRetry: |
| 3584 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3585 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | if (rc) |
| 3587 | return rc; |
| 3588 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3589 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3590 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3591 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | name_len++; /* trailing null */ |
| 3593 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3594 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | name_len = strnlen(fileName, PATH_MAX); |
| 3596 | name_len++; /* trailing null */ |
| 3597 | strncpy(pSMB->FileName, fileName, name_len); |
| 3598 | } |
| 3599 | params = 6 + name_len; |
| 3600 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3601 | /* BB find max SMB size from sess */ |
| 3602 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | pSMB->MaxSetupCount = 0; |
| 3604 | pSMB->Reserved = 0; |
| 3605 | pSMB->Flags = 0; |
| 3606 | pSMB->Timeout = 0; |
| 3607 | pSMB->Reserved2 = 0; |
| 3608 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3609 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | offset = param_offset + params; |
| 3611 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3612 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3613 | |
| 3614 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3615 | 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] | 3616 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3617 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | rc = -EOPNOTSUPP; |
| 3619 | goto setACLerrorExit; |
| 3620 | } |
| 3621 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3622 | pSMB->SetupCount = 1; |
| 3623 | pSMB->Reserved3 = 0; |
| 3624 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3625 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3626 | byte_count = 3 /* pad */ + params + data_count; |
| 3627 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3628 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3629 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3630 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3631 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3632 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3634 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3635 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3636 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3637 | cifs_dbg(FYI, "Set POSIX ACL returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | |
| 3639 | setACLerrorExit: |
| 3640 | cifs_buf_release(pSMB); |
| 3641 | if (rc == -EAGAIN) |
| 3642 | goto setAclRetry; |
| 3643 | return rc; |
| 3644 | } |
| 3645 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3646 | /* BB fix tabs in this function FIXME BB */ |
| 3647 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3648 | CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3649 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3650 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3651 | int rc = 0; |
| 3652 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3653 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3654 | int bytes_returned; |
| 3655 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3656 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3657 | cifs_dbg(FYI, "In GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3658 | if (tcon == NULL) |
| 3659 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3660 | |
| 3661 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3662 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3663 | (void **) &pSMBr); |
| 3664 | if (rc) |
| 3665 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3666 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3667 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3668 | pSMB->t2.TotalDataCount = 0; |
| 3669 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3670 | /* BB find exact max data count below from sess structure BB */ |
| 3671 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3672 | pSMB->t2.MaxSetupCount = 0; |
| 3673 | pSMB->t2.Reserved = 0; |
| 3674 | pSMB->t2.Flags = 0; |
| 3675 | pSMB->t2.Timeout = 0; |
| 3676 | pSMB->t2.Reserved2 = 0; |
| 3677 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3678 | Fid) - 4); |
| 3679 | pSMB->t2.DataCount = 0; |
| 3680 | pSMB->t2.DataOffset = 0; |
| 3681 | pSMB->t2.SetupCount = 1; |
| 3682 | pSMB->t2.Reserved3 = 0; |
| 3683 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3684 | byte_count = params + 1 /* pad */ ; |
| 3685 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3686 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3687 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3688 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3689 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3690 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3691 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3692 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3693 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3694 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3695 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3696 | cifs_dbg(FYI, "error %d in GetExtAttr\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3697 | } else { |
| 3698 | /* decode response */ |
| 3699 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3700 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3701 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3702 | /* If rc should we check for EOPNOSUPP and |
| 3703 | disable the srvino flag? or in caller? */ |
| 3704 | rc = -EIO; /* bad smb */ |
| 3705 | else { |
| 3706 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3707 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3708 | struct file_chattr_info *pfinfo; |
| 3709 | /* BB Do we need a cast or hash here ? */ |
| 3710 | if (count != 16) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3711 | cifs_dbg(FYI, "Illegal size ret in GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3712 | rc = -EIO; |
| 3713 | goto GetExtAttrOut; |
| 3714 | } |
| 3715 | pfinfo = (struct file_chattr_info *) |
| 3716 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3717 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3718 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3719 | } |
| 3720 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3721 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3722 | cifs_buf_release(pSMB); |
| 3723 | if (rc == -EAGAIN) |
| 3724 | goto GetExtAttrRetry; |
| 3725 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3726 | } |
| 3727 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3728 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3730 | #ifdef CONFIG_CIFS_ACL |
| 3731 | /* |
| 3732 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3733 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3734 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3735 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3736 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3737 | * by caller |
| 3738 | */ |
| 3739 | static int |
| 3740 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3741 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3742 | void **ret_buf) |
| 3743 | { |
| 3744 | int rc; |
| 3745 | __u32 temp_offset; |
| 3746 | struct smb_com_ntransact_req *pSMB; |
| 3747 | |
| 3748 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3749 | (void **)&pSMB); |
| 3750 | if (rc) |
| 3751 | return rc; |
| 3752 | *ret_buf = (void *)pSMB; |
| 3753 | pSMB->Reserved = 0; |
| 3754 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3755 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3756 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3757 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3758 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3759 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3760 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3761 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3762 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3763 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3764 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3765 | return 0; |
| 3766 | } |
| 3767 | |
| 3768 | static int |
| 3769 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3770 | __u32 *pparmlen, __u32 *pdatalen) |
| 3771 | { |
| 3772 | char *end_of_smb; |
| 3773 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3774 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3775 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3776 | |
| 3777 | *pdatalen = 0; |
| 3778 | *pparmlen = 0; |
| 3779 | |
| 3780 | if (buf == NULL) |
| 3781 | return -EINVAL; |
| 3782 | |
| 3783 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3784 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3785 | bcc = get_bcc(&pSMBr->hdr); |
| 3786 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3787 | (char *)&pSMBr->ByteCount; |
| 3788 | |
| 3789 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3790 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3791 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3792 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3793 | |
| 3794 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3795 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3796 | |
| 3797 | /* should we also check that parm and data areas do not overlap? */ |
| 3798 | if (*ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3799 | cifs_dbg(FYI, "parms start after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3800 | return -EINVAL; |
| 3801 | } else if (parm_count + *ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3802 | cifs_dbg(FYI, "parm end after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3803 | return -EINVAL; |
| 3804 | } else if (*ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3805 | cifs_dbg(FYI, "data starts after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3806 | return -EINVAL; |
| 3807 | } else if (data_count + *ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3808 | cifs_dbg(FYI, "data %p + count %d (%p) past smb end %p start %p\n", |
| 3809 | *ppdata, data_count, (data_count + *ppdata), |
| 3810 | end_of_smb, pSMBr); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3811 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3812 | } else if (parm_count + data_count > bcc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3813 | cifs_dbg(FYI, "parm count and data count larger than SMB\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3814 | return -EINVAL; |
| 3815 | } |
| 3816 | *pdatalen = data_count; |
| 3817 | *pparmlen = parm_count; |
| 3818 | return 0; |
| 3819 | } |
| 3820 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3821 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3822 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3823 | CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3824 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3825 | { |
| 3826 | int rc = 0; |
| 3827 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3828 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3829 | struct kvec iov[1]; |
| 3830 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3831 | cifs_dbg(FYI, "GetCifsACL\n"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3832 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3833 | *pbuflen = 0; |
| 3834 | *acl_inf = NULL; |
| 3835 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3836 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3837 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3838 | if (rc) |
| 3839 | return rc; |
| 3840 | |
| 3841 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3842 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3843 | pSMB->MaxSetupCount = 0; |
| 3844 | pSMB->Fid = fid; /* file handle always le */ |
| 3845 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3846 | CIFS_ACL_DACL); |
| 3847 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3848 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3849 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3850 | 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] | 3851 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3852 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 3853 | 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3854 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3855 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3856 | cifs_dbg(FYI, "Send error in QuerySecDesc = %d\n", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3857 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3858 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3859 | __u32 parm_len; |
| 3860 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3861 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3862 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3863 | |
| 3864 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3865 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3866 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3867 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3868 | goto qsec_out; |
| 3869 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3870 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3871 | cifs_dbg(FYI, "smb %p parm %p data %p\n", |
| 3872 | pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3873 | |
| 3874 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3875 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3876 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3877 | goto qsec_out; |
| 3878 | } |
| 3879 | |
| 3880 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3881 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3882 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3883 | if (acl_len != *pbuflen) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3884 | cifs_dbg(VFS, "acl length %d does not match %d\n", |
| 3885 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3886 | if (*pbuflen > acl_len) |
| 3887 | *pbuflen = acl_len; |
| 3888 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3889 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3890 | /* check if buffer is big enough for the acl |
| 3891 | header followed by the smallest SID */ |
| 3892 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3893 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3894 | cifs_dbg(VFS, "bad acl length %d\n", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3895 | rc = -EINVAL; |
| 3896 | *pbuflen = 0; |
| 3897 | } else { |
Silviu-Mihai Popescu | f7f7c18 | 2013-03-11 18:22:32 +0200 | [diff] [blame] | 3898 | *acl_inf = kmemdup(pdata, *pbuflen, GFP_KERNEL); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3899 | if (*acl_inf == NULL) { |
| 3900 | *pbuflen = 0; |
| 3901 | rc = -ENOMEM; |
| 3902 | } |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3903 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3904 | } |
| 3905 | qsec_out: |
Sachin Prabhu | 6d81ed1 | 2014-06-16 15:35:24 +0100 | [diff] [blame] | 3906 | free_rsp_buf(buf_type, iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3907 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3908 | return rc; |
| 3909 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3910 | |
| 3911 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3912 | CIFSSMBSetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3913 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3914 | { |
| 3915 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3916 | int rc = 0; |
| 3917 | int bytes_returned = 0; |
| 3918 | SET_SEC_DESC_REQ *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3919 | void *pSMBr; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3920 | |
| 3921 | setCifsAclRetry: |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3922 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3923 | if (rc) |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3924 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3925 | |
| 3926 | pSMB->MaxSetupCount = 0; |
| 3927 | pSMB->Reserved = 0; |
| 3928 | |
| 3929 | param_count = 8; |
| 3930 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3931 | data_count = acllen; |
| 3932 | data_offset = param_offset + param_count; |
| 3933 | byte_count = 3 /* pad */ + param_count; |
| 3934 | |
| 3935 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3936 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3937 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3938 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3939 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3940 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3941 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3942 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3943 | pSMB->SetupCount = 0; |
| 3944 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3945 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3946 | |
| 3947 | pSMB->Fid = fid; /* file handle always le */ |
| 3948 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3949 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3950 | |
| 3951 | if (pntsd && acllen) { |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3952 | memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + |
| 3953 | data_offset, pntsd, acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3954 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3955 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3956 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3957 | |
| 3958 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3959 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3960 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3961 | cifs_dbg(FYI, "SetCIFSACL bytes_returned: %d, rc: %d\n", |
| 3962 | bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3963 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3964 | cifs_dbg(FYI, "Set CIFS ACL returned %d\n", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3965 | cifs_buf_release(pSMB); |
| 3966 | |
| 3967 | if (rc == -EAGAIN) |
| 3968 | goto setCifsAclRetry; |
| 3969 | |
| 3970 | return (rc); |
| 3971 | } |
| 3972 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3973 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3974 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3975 | /* Legacy Query Path Information call for lookup to old servers such |
| 3976 | as Win9x/WinME */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3977 | int |
| 3978 | SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, |
| 3979 | const char *search_name, FILE_ALL_INFO *data, |
| 3980 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3981 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3982 | QUERY_INFORMATION_REQ *pSMB; |
| 3983 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3984 | int rc = 0; |
| 3985 | int bytes_returned; |
| 3986 | int name_len; |
| 3987 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3988 | cifs_dbg(FYI, "In SMBQPath path %s\n", search_name); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3989 | QInfRetry: |
| 3990 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3991 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3992 | if (rc) |
| 3993 | return rc; |
| 3994 | |
| 3995 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3996 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3997 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3998 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3999 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4000 | name_len++; /* trailing null */ |
| 4001 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4002 | } else { |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4003 | name_len = strnlen(search_name, PATH_MAX); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4004 | name_len++; /* trailing null */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4005 | strncpy(pSMB->FileName, search_name, name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4006 | } |
| 4007 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4008 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4009 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4010 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 4011 | |
| 4012 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4013 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4014 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4015 | cifs_dbg(FYI, "Send error in QueryInfo = %d\n", rc); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4016 | } else if (data) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4017 | struct timespec ts; |
| 4018 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4019 | |
| 4020 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4021 | /* BB FIXME - add time zone adjustment BB */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4022 | memset(data, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4023 | ts.tv_nsec = 0; |
| 4024 | ts.tv_sec = time; |
| 4025 | /* decode time fields */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4026 | data->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
| 4027 | data->LastWriteTime = data->ChangeTime; |
| 4028 | data->LastAccessTime = 0; |
| 4029 | data->AllocationSize = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4030 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4031 | data->EndOfFile = data->AllocationSize; |
| 4032 | data->Attributes = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4033 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4034 | } else |
| 4035 | rc = -EIO; /* bad buffer passed in */ |
| 4036 | |
| 4037 | cifs_buf_release(pSMB); |
| 4038 | |
| 4039 | if (rc == -EAGAIN) |
| 4040 | goto QInfRetry; |
| 4041 | |
| 4042 | return rc; |
| 4043 | } |
| 4044 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4045 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4046 | CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4047 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 4048 | { |
| 4049 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4050 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4051 | int rc = 0; |
| 4052 | int bytes_returned; |
| 4053 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4054 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4055 | QFileInfoRetry: |
| 4056 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4057 | (void **) &pSMBr); |
| 4058 | if (rc) |
| 4059 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4060 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4061 | params = 2 /* level */ + 2 /* fid */; |
| 4062 | pSMB->t2.TotalDataCount = 0; |
| 4063 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4064 | /* BB find exact max data count below from sess structure BB */ |
| 4065 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4066 | pSMB->t2.MaxSetupCount = 0; |
| 4067 | pSMB->t2.Reserved = 0; |
| 4068 | pSMB->t2.Flags = 0; |
| 4069 | pSMB->t2.Timeout = 0; |
| 4070 | pSMB->t2.Reserved2 = 0; |
| 4071 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4072 | Fid) - 4); |
| 4073 | pSMB->t2.DataCount = 0; |
| 4074 | pSMB->t2.DataOffset = 0; |
| 4075 | pSMB->t2.SetupCount = 1; |
| 4076 | pSMB->t2.Reserved3 = 0; |
| 4077 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4078 | byte_count = params + 1 /* pad */ ; |
| 4079 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4080 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4081 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 4082 | pSMB->Pad = 0; |
| 4083 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4084 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4085 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4086 | |
| 4087 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4088 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4089 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4090 | cifs_dbg(FYI, "Send error in QFileInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4091 | } else { /* decode response */ |
| 4092 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4093 | |
| 4094 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4095 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4096 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4097 | rc = -EIO; /* bad smb */ |
| 4098 | else if (pFindData) { |
| 4099 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4100 | memcpy((char *) pFindData, |
| 4101 | (char *) &pSMBr->hdr.Protocol + |
| 4102 | data_offset, sizeof(FILE_ALL_INFO)); |
| 4103 | } else |
| 4104 | rc = -ENOMEM; |
| 4105 | } |
| 4106 | cifs_buf_release(pSMB); |
| 4107 | if (rc == -EAGAIN) |
| 4108 | goto QFileInfoRetry; |
| 4109 | |
| 4110 | return rc; |
| 4111 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4114 | CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4115 | const char *search_name, FILE_ALL_INFO *data, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4116 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4117 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | { |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4119 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4121 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4122 | int rc = 0; |
| 4123 | int bytes_returned; |
| 4124 | int name_len; |
| 4125 | __u16 params, byte_count; |
| 4126 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4127 | /* cifs_dbg(FYI, "In QPathInfo path %s\n", search_name); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | QPathInfoRetry: |
| 4129 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4130 | (void **) &pSMBr); |
| 4131 | if (rc) |
| 4132 | return rc; |
| 4133 | |
| 4134 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4135 | name_len = |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4136 | cifsConvertToUTF16((__le16 *) pSMB->FileName, search_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4137 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | name_len++; /* trailing null */ |
| 4139 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4140 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4141 | name_len = strnlen(search_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | name_len++; /* trailing null */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4143 | strncpy(pSMB->FileName, search_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | } |
| 4145 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4146 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | pSMB->TotalDataCount = 0; |
| 4148 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4149 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4150 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | pSMB->MaxSetupCount = 0; |
| 4152 | pSMB->Reserved = 0; |
| 4153 | pSMB->Flags = 0; |
| 4154 | pSMB->Timeout = 0; |
| 4155 | pSMB->Reserved2 = 0; |
| 4156 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4157 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | pSMB->DataCount = 0; |
| 4159 | pSMB->DataOffset = 0; |
| 4160 | pSMB->SetupCount = 1; |
| 4161 | pSMB->Reserved3 = 0; |
| 4162 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4163 | byte_count = params + 1 /* pad */ ; |
| 4164 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4165 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4166 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4167 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4168 | else |
| 4169 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4171 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4173 | |
| 4174 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4175 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4176 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4177 | cifs_dbg(FYI, "Send error in QPathInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | } else { /* decode response */ |
| 4179 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4180 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4181 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4182 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4183 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4185 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4186 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4187 | last field */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4188 | else if (data) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4189 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4191 | |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4192 | /* |
| 4193 | * On legacy responses we do not read the last field, |
| 4194 | * EAsize, fortunately since it varies by subdialect and |
| 4195 | * also note it differs on Set vs Get, ie two bytes or 4 |
| 4196 | * bytes depending but we don't care here. |
| 4197 | */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4198 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4199 | size = sizeof(FILE_INFO_STANDARD); |
| 4200 | else |
| 4201 | size = sizeof(FILE_ALL_INFO); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4202 | memcpy((char *) data, (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4203 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | } else |
| 4205 | rc = -ENOMEM; |
| 4206 | } |
| 4207 | cifs_buf_release(pSMB); |
| 4208 | if (rc == -EAGAIN) |
| 4209 | goto QPathInfoRetry; |
| 4210 | |
| 4211 | return rc; |
| 4212 | } |
| 4213 | |
| 4214 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4215 | CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4216 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4217 | { |
| 4218 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4219 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4220 | int rc = 0; |
| 4221 | int bytes_returned; |
| 4222 | __u16 params, byte_count; |
| 4223 | |
| 4224 | UnixQFileInfoRetry: |
| 4225 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4226 | (void **) &pSMBr); |
| 4227 | if (rc) |
| 4228 | return rc; |
| 4229 | |
| 4230 | params = 2 /* level */ + 2 /* fid */; |
| 4231 | pSMB->t2.TotalDataCount = 0; |
| 4232 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4233 | /* BB find exact max data count below from sess structure BB */ |
| 4234 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4235 | pSMB->t2.MaxSetupCount = 0; |
| 4236 | pSMB->t2.Reserved = 0; |
| 4237 | pSMB->t2.Flags = 0; |
| 4238 | pSMB->t2.Timeout = 0; |
| 4239 | pSMB->t2.Reserved2 = 0; |
| 4240 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4241 | Fid) - 4); |
| 4242 | pSMB->t2.DataCount = 0; |
| 4243 | pSMB->t2.DataOffset = 0; |
| 4244 | pSMB->t2.SetupCount = 1; |
| 4245 | pSMB->t2.Reserved3 = 0; |
| 4246 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4247 | byte_count = params + 1 /* pad */ ; |
| 4248 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4249 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4250 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4251 | pSMB->Pad = 0; |
| 4252 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4253 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4254 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4255 | |
| 4256 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4257 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4258 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4259 | cifs_dbg(FYI, "Send error in UnixQFileInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4260 | } else { /* decode response */ |
| 4261 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4262 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4263 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4264 | cifs_dbg(VFS, "Malformed FILE_UNIX_BASIC_INFO response. Unix Extensions can be disabled on mount by specifying the nosfu mount option.\n"); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4265 | rc = -EIO; /* bad smb */ |
| 4266 | } else { |
| 4267 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4268 | memcpy((char *) pFindData, |
| 4269 | (char *) &pSMBr->hdr.Protocol + |
| 4270 | data_offset, |
| 4271 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4272 | } |
| 4273 | } |
| 4274 | |
| 4275 | cifs_buf_release(pSMB); |
| 4276 | if (rc == -EAGAIN) |
| 4277 | goto UnixQFileInfoRetry; |
| 4278 | |
| 4279 | return rc; |
| 4280 | } |
| 4281 | |
| 4282 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4283 | CIFSSMBUnixQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4285 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4286 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | { |
| 4288 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4289 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4290 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4291 | int rc = 0; |
| 4292 | int bytes_returned = 0; |
| 4293 | int name_len; |
| 4294 | __u16 params, byte_count; |
| 4295 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4296 | cifs_dbg(FYI, "In QPathInfo (Unix) the path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | UnixQPathInfoRetry: |
| 4298 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4299 | (void **) &pSMBr); |
| 4300 | if (rc) |
| 4301 | return rc; |
| 4302 | |
| 4303 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4304 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4305 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4306 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | name_len++; /* trailing null */ |
| 4308 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4309 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | name_len = strnlen(searchName, PATH_MAX); |
| 4311 | name_len++; /* trailing null */ |
| 4312 | strncpy(pSMB->FileName, searchName, name_len); |
| 4313 | } |
| 4314 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4315 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | pSMB->TotalDataCount = 0; |
| 4317 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4318 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4319 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | pSMB->MaxSetupCount = 0; |
| 4321 | pSMB->Reserved = 0; |
| 4322 | pSMB->Flags = 0; |
| 4323 | pSMB->Timeout = 0; |
| 4324 | pSMB->Reserved2 = 0; |
| 4325 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4326 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | pSMB->DataCount = 0; |
| 4328 | pSMB->DataOffset = 0; |
| 4329 | pSMB->SetupCount = 1; |
| 4330 | pSMB->Reserved3 = 0; |
| 4331 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4332 | byte_count = params + 1 /* pad */ ; |
| 4333 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4334 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4335 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4336 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4337 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4339 | |
| 4340 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4341 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4342 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4343 | cifs_dbg(FYI, "Send error in UnixQPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | } else { /* decode response */ |
| 4345 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4346 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4347 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4348 | cifs_dbg(VFS, "Malformed FILE_UNIX_BASIC_INFO response. Unix Extensions can be disabled on mount by specifying the nosfu mount option.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | rc = -EIO; /* bad smb */ |
| 4350 | } else { |
| 4351 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4352 | memcpy((char *) pFindData, |
| 4353 | (char *) &pSMBr->hdr.Protocol + |
| 4354 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4355 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | } |
| 4357 | } |
| 4358 | cifs_buf_release(pSMB); |
| 4359 | if (rc == -EAGAIN) |
| 4360 | goto UnixQPathInfoRetry; |
| 4361 | |
| 4362 | return rc; |
| 4363 | } |
| 4364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4366 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4367 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4368 | const char *searchName, struct cifs_sb_info *cifs_sb, |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4369 | __u16 *pnetfid, __u16 search_flags, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4370 | struct cifs_search_info *psrch_inf, bool msearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | { |
| 4372 | /* level 257 SMB_ */ |
| 4373 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4374 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4375 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | int rc = 0; |
| 4377 | int bytes_returned = 0; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4378 | int name_len, remap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | __u16 params, byte_count; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4380 | struct nls_table *nls_codepage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4382 | cifs_dbg(FYI, "In FindFirst for %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | |
| 4384 | findFirstRetry: |
| 4385 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4386 | (void **) &pSMBr); |
| 4387 | if (rc) |
| 4388 | return rc; |
| 4389 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4390 | nls_codepage = cifs_sb->local_nls; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 4391 | remap = cifs_remap(cifs_sb); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4394 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4395 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4396 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4397 | /* We can not add the asterik earlier in case |
| 4398 | it got remapped to 0xF03A as if it were part of the |
| 4399 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | name_len *= 2; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4401 | if (msearch) { |
| 4402 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
| 4403 | pSMB->FileName[name_len+1] = 0; |
| 4404 | pSMB->FileName[name_len+2] = '*'; |
| 4405 | pSMB->FileName[name_len+3] = 0; |
| 4406 | name_len += 4; /* now the trailing null */ |
| 4407 | /* null terminate just in case */ |
| 4408 | pSMB->FileName[name_len] = 0; |
| 4409 | pSMB->FileName[name_len+1] = 0; |
| 4410 | name_len += 2; |
| 4411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | } else { /* BB add check for overrun of SMB buf BB */ |
| 4413 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4415 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4416 | free buffer exit; BB */ |
| 4417 | strncpy(pSMB->FileName, searchName, name_len); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4418 | if (msearch) { |
| 4419 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
| 4420 | pSMB->FileName[name_len+1] = '*'; |
| 4421 | pSMB->FileName[name_len+2] = 0; |
| 4422 | name_len += 3; |
| 4423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | } |
| 4425 | |
| 4426 | params = 12 + name_len /* includes null */ ; |
| 4427 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4428 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4429 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | pSMB->MaxSetupCount = 0; |
| 4431 | pSMB->Reserved = 0; |
| 4432 | pSMB->Flags = 0; |
| 4433 | pSMB->Timeout = 0; |
| 4434 | pSMB->Reserved2 = 0; |
| 4435 | byte_count = params + 1 /* pad */ ; |
| 4436 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4437 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4438 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4439 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4440 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | pSMB->DataCount = 0; |
| 4442 | pSMB->DataOffset = 0; |
| 4443 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4444 | pSMB->Reserved3 = 0; |
| 4445 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4446 | pSMB->SearchAttributes = |
| 4447 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4448 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4449 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4450 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4452 | |
| 4453 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4454 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4455 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4457 | |
| 4458 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4459 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4460 | cifs_stats_inc(&tcon->stats.cifs_stats.num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4462 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4463 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4465 | cifs_dbg(FYI, "Error in FindFirst = %d\n", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4466 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4467 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | |
| 4469 | /* BB eventually could optimize out free and realloc of buf */ |
| 4470 | /* for this case */ |
| 4471 | if (rc == -EAGAIN) |
| 4472 | goto findFirstRetry; |
| 4473 | } else { /* decode response */ |
| 4474 | /* BB remember to free buffer if error BB */ |
| 4475 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4476 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4477 | unsigned int lnoff; |
| 4478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4480 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4482 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | |
| 4484 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4485 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4486 | psrch_inf->srch_entries_start = |
| 4487 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4490 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4491 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4492 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4493 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4495 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4497 | psrch_inf->entries_in_buffer = |
| 4498 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4499 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4501 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4502 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4503 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4504 | psrch_inf->last_entry = NULL; |
| 4505 | return rc; |
| 4506 | } |
| 4507 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4508 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4509 | lnoff; |
| 4510 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4511 | if (pnetfid) |
| 4512 | *pnetfid = parms->SearchHandle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4513 | } else { |
| 4514 | cifs_buf_release(pSMB); |
| 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | return rc; |
| 4519 | } |
| 4520 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4521 | int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, |
| 4522 | __u16 searchHandle, __u16 search_flags, |
| 4523 | struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | { |
| 4525 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4526 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4527 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | char *response_data; |
| 4529 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4530 | int bytes_returned; |
| 4531 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | __u16 params, byte_count; |
| 4533 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4534 | cifs_dbg(FYI, "In FindNext\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4536 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | return -ENOENT; |
| 4538 | |
| 4539 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4540 | (void **) &pSMBr); |
| 4541 | if (rc) |
| 4542 | return rc; |
| 4543 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4544 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | byte_count = 0; |
| 4546 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4547 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4548 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | pSMB->MaxSetupCount = 0; |
| 4550 | pSMB->Reserved = 0; |
| 4551 | pSMB->Flags = 0; |
| 4552 | pSMB->Timeout = 0; |
| 4553 | pSMB->Reserved2 = 0; |
| 4554 | pSMB->ParameterOffset = cpu_to_le16( |
| 4555 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4556 | pSMB->DataCount = 0; |
| 4557 | pSMB->DataOffset = 0; |
| 4558 | pSMB->SetupCount = 1; |
| 4559 | pSMB->Reserved3 = 0; |
| 4560 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4561 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4562 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4563 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4565 | pSMB->ResumeKey = psrch_inf->resume_key; |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4566 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | |
| 4568 | name_len = psrch_inf->resume_name_len; |
| 4569 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4570 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4572 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4573 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4574 | pSMB->ResumeFileName[name_len] = 0; |
| 4575 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | } else { |
| 4577 | rc = -EINVAL; |
| 4578 | goto FNext2_err_exit; |
| 4579 | } |
| 4580 | byte_count = params + 1 /* pad */ ; |
| 4581 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4582 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4583 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4587 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4588 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | if (rc) { |
| 4590 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4591 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4592 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4593 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | } else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4595 | cifs_dbg(FYI, "FindNext returned = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | } else { /* decode response */ |
| 4597 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4598 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4599 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4600 | unsigned int lnoff; |
| 4601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4603 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4604 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4606 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4608 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4609 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4610 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4611 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4612 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4613 | cifs_small_buf_release( |
| 4614 | psrch_inf->ntwrk_buf_start); |
| 4615 | else |
| 4616 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | psrch_inf->srch_entries_start = response_data; |
| 4618 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4619 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4620 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4621 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4623 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4624 | psrch_inf->entries_in_buffer = |
| 4625 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | psrch_inf->index_of_last_entry += |
| 4627 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4628 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4629 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4630 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4631 | psrch_inf->last_entry = NULL; |
| 4632 | return rc; |
| 4633 | } else |
| 4634 | psrch_inf->last_entry = |
| 4635 | psrch_inf->srch_entries_start + lnoff; |
| 4636 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4637 | /* cifs_dbg(FYI, "fnxt2 entries in buf %d index_of_last %d\n", |
| 4638 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | |
| 4640 | /* BB fixme add unlock here */ |
| 4641 | } |
| 4642 | |
| 4643 | } |
| 4644 | |
| 4645 | /* BB On error, should we leave previous search buf (and count and |
| 4646 | last entry fields) intact or free the previous one? */ |
| 4647 | |
| 4648 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4649 | since file handle passed in no longer valid */ |
| 4650 | FNext2_err_exit: |
| 4651 | if (rc != 0) |
| 4652 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | return rc; |
| 4654 | } |
| 4655 | |
| 4656 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4657 | CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4658 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | { |
| 4660 | int rc = 0; |
| 4661 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4663 | cifs_dbg(FYI, "In CIFSSMBFindClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4664 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4665 | |
| 4666 | /* no sense returning error if session restarted |
| 4667 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4668 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | return 0; |
| 4670 | if (rc) |
| 4671 | return rc; |
| 4672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | pSMB->FileID = searchHandle; |
| 4674 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4675 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4676 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4677 | cifs_dbg(VFS, "Send error in FindClose = %d\n", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4678 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4679 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | |
| 4681 | /* Since session is dead, search handle closed on server already */ |
| 4682 | if (rc == -EAGAIN) |
| 4683 | rc = 0; |
| 4684 | |
| 4685 | return rc; |
| 4686 | } |
| 4687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4689 | CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4690 | const char *search_name, __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4691 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4692 | { |
| 4693 | int rc = 0; |
| 4694 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4695 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4696 | int name_len, bytes_returned; |
| 4697 | __u16 params, byte_count; |
| 4698 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4699 | cifs_dbg(FYI, "In GetSrvInodeNum for %s\n", search_name); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4700 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4701 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4702 | |
| 4703 | GetInodeNumberRetry: |
| 4704 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4705 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4706 | if (rc) |
| 4707 | return rc; |
| 4708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4709 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4710 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4711 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4712 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4713 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | name_len++; /* trailing null */ |
| 4715 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4716 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4717 | name_len = strnlen(search_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4718 | name_len++; /* trailing null */ |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4719 | strncpy(pSMB->FileName, search_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4723 | pSMB->TotalDataCount = 0; |
| 4724 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4725 | /* BB find exact max data count below from sess structure BB */ |
| 4726 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4727 | pSMB->MaxSetupCount = 0; |
| 4728 | pSMB->Reserved = 0; |
| 4729 | pSMB->Flags = 0; |
| 4730 | pSMB->Timeout = 0; |
| 4731 | pSMB->Reserved2 = 0; |
| 4732 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4733 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | pSMB->DataCount = 0; |
| 4735 | pSMB->DataOffset = 0; |
| 4736 | pSMB->SetupCount = 1; |
| 4737 | pSMB->Reserved3 = 0; |
| 4738 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4739 | byte_count = params + 1 /* pad */ ; |
| 4740 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4741 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4742 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4743 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4744 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4746 | |
| 4747 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4748 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4749 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4750 | cifs_dbg(FYI, "error %d in QueryInternalInfo\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | } else { |
| 4752 | /* decode response */ |
| 4753 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4755 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | /* If rc should we check for EOPNOSUPP and |
| 4757 | disable the srvino flag? or in caller? */ |
| 4758 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4759 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4761 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4762 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4764 | if (count < 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4765 | cifs_dbg(FYI, "Illegal size ret in QryIntrnlInf\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | rc = -EIO; |
| 4767 | goto GetInodeNumOut; |
| 4768 | } |
| 4769 | pfinfo = (struct file_internal_info *) |
| 4770 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4771 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4772 | } |
| 4773 | } |
| 4774 | GetInodeNumOut: |
| 4775 | cifs_buf_release(pSMB); |
| 4776 | if (rc == -EAGAIN) |
| 4777 | goto GetInodeNumberRetry; |
| 4778 | return rc; |
| 4779 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4780 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4781 | /* parses DFS refferal V3 structure |
| 4782 | * caller is responsible for freeing target_nodes |
| 4783 | * returns: |
| 4784 | * on success - 0 |
| 4785 | * on failure - errno |
| 4786 | */ |
| 4787 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4788 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4789 | unsigned int *num_of_nodes, |
| 4790 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4791 | const struct nls_table *nls_codepage, int remap, |
| 4792 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4793 | { |
| 4794 | int i, rc = 0; |
| 4795 | char *data_end; |
| 4796 | bool is_unicode; |
| 4797 | struct dfs_referral_level_3 *ref; |
| 4798 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 4799 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 4800 | is_unicode = true; |
| 4801 | else |
| 4802 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4803 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 4804 | |
| 4805 | if (*num_of_nodes < 1) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4806 | cifs_dbg(VFS, "num_referrals: must be at least > 0, but we get num_referrals = %d\n", |
| 4807 | *num_of_nodes); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4808 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4809 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4810 | } |
| 4811 | |
| 4812 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4813 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4814 | cifs_dbg(VFS, "Referrals of V%d version are not supported, should be V3\n", |
| 4815 | le16_to_cpu(ref->VersionNumber)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4816 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4817 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | /* get the upper boundary of the resp buffer */ |
| 4821 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 4822 | le16_to_cpu(pSMBr->t2.DataCount); |
| 4823 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4824 | cifs_dbg(FYI, "num_referrals: %d dfs flags: 0x%x ...\n", |
| 4825 | *num_of_nodes, le32_to_cpu(pSMBr->DFSFlags)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4826 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4827 | *target_nodes = kcalloc(*num_of_nodes, sizeof(struct dfs_info3_param), |
| 4828 | GFP_KERNEL); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4829 | if (*target_nodes == NULL) { |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4830 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4831 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4832 | } |
| 4833 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4834 | /* collect necessary data from referrals */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4835 | for (i = 0; i < *num_of_nodes; i++) { |
| 4836 | char *temp; |
| 4837 | int max_len; |
| 4838 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 4839 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4840 | node->flags = le32_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4841 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 4842 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 4843 | GFP_KERNEL); |
Steve French | 2920ee2 | 2009-08-31 15:27:26 +0000 | [diff] [blame] | 4844 | if (tmp == NULL) { |
| 4845 | rc = -ENOMEM; |
| 4846 | goto parse_DFS_referrals_exit; |
| 4847 | } |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4848 | cifsConvertToUTF16((__le16 *) tmp, searchName, |
| 4849 | PATH_MAX, nls_codepage, remap); |
| 4850 | node->path_consumed = cifs_utf16_bytes(tmp, |
Jeff Layton | 69f801f | 2009-04-30 06:46:32 -0400 | [diff] [blame] | 4851 | le16_to_cpu(pSMBr->PathConsumed), |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4852 | nls_codepage); |
| 4853 | kfree(tmp); |
| 4854 | } else |
| 4855 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4856 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4857 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4858 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4859 | |
| 4860 | /* copy DfsPath */ |
| 4861 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4862 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4863 | node->path_name = cifs_strndup_from_utf16(temp, max_len, |
| 4864 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4865 | if (!node->path_name) { |
| 4866 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4867 | goto parse_DFS_referrals_exit; |
Jeff Layton | 066ce68 | 2009-04-30 07:16:14 -0400 | [diff] [blame] | 4868 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4869 | |
| 4870 | /* copy link target UNC */ |
| 4871 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4872 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4873 | node->node_name = cifs_strndup_from_utf16(temp, max_len, |
| 4874 | is_unicode, nls_codepage); |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4875 | if (!node->node_name) { |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4876 | rc = -ENOMEM; |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4877 | goto parse_DFS_referrals_exit; |
| 4878 | } |
| 4879 | |
| 4880 | ref++; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4881 | } |
| 4882 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4883 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4884 | if (rc) { |
| 4885 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4886 | *target_nodes = NULL; |
| 4887 | *num_of_nodes = 0; |
| 4888 | } |
| 4889 | return rc; |
| 4890 | } |
| 4891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4893 | CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4894 | const char *search_name, struct dfs_info3_param **target_nodes, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4895 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4896 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | { |
| 4898 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4899 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4900 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | int rc = 0; |
| 4902 | int bytes_returned; |
| 4903 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4904 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4905 | *num_of_nodes = 0; |
| 4906 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4908 | cifs_dbg(FYI, "In GetDFSRefer the path %s\n", search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | if (ses == NULL) |
| 4910 | return -ENODEV; |
| 4911 | getDFSRetry: |
| 4912 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4913 | (void **) &pSMBr); |
| 4914 | if (rc) |
| 4915 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4916 | |
| 4917 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4918 | but should never be null here anyway */ |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 4919 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4921 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4922 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4924 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | |
| 4927 | if (ses->capabilities & CAP_UNICODE) { |
| 4928 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4929 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4930 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4931 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4932 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4933 | name_len++; /* trailing null */ |
| 4934 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4935 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4936 | name_len = strnlen(search_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | name_len++; /* trailing null */ |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4938 | strncpy(pSMB->RequestFileName, search_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | } |
| 4940 | |
Dan Carpenter | 65c3b20 | 2015-04-30 17:30:24 +0300 | [diff] [blame] | 4941 | if (ses->server->sign) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 4942 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4943 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4944 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4947 | pSMB->TotalDataCount = 0; |
| 4948 | pSMB->DataCount = 0; |
| 4949 | pSMB->DataOffset = 0; |
| 4950 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4951 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4952 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | pSMB->MaxSetupCount = 0; |
| 4954 | pSMB->Reserved = 0; |
| 4955 | pSMB->Flags = 0; |
| 4956 | pSMB->Timeout = 0; |
| 4957 | pSMB->Reserved2 = 0; |
| 4958 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4959 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | pSMB->SetupCount = 1; |
| 4961 | pSMB->Reserved3 = 0; |
| 4962 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4963 | byte_count = params + 3 /* pad */ ; |
| 4964 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4965 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4966 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4967 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4969 | |
| 4970 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4971 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4972 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4973 | cifs_dbg(FYI, "Send error in GetDFSRefer = %d\n", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4974 | goto GetDFSRefExit; |
| 4975 | } |
| 4976 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4978 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4979 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4980 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4981 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4983 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4984 | cifs_dbg(FYI, "Decoding GetDFSRefer response BCC: %d Offset %d\n", |
| 4985 | get_bcc(&pSMBr->hdr), le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4986 | |
| 4987 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4988 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4989 | target_nodes, nls_codepage, remap, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4990 | search_name); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4993 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 | |
| 4995 | if (rc == -EAGAIN) |
| 4996 | goto getDFSRetry; |
| 4997 | |
| 4998 | return rc; |
| 4999 | } |
| 5000 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5001 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 5002 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5003 | SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 5004 | struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5005 | { |
| 5006 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5007 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5008 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5009 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 5010 | int rc = 0; |
| 5011 | int bytes_returned = 0; |
| 5012 | __u16 params, byte_count; |
| 5013 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5014 | cifs_dbg(FYI, "OldQFSInfo\n"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5015 | oldQFSInfoRetry: |
| 5016 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5017 | (void **) &pSMBr); |
| 5018 | if (rc) |
| 5019 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5020 | |
| 5021 | params = 2; /* level */ |
| 5022 | pSMB->TotalDataCount = 0; |
| 5023 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5024 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5025 | pSMB->MaxSetupCount = 0; |
| 5026 | pSMB->Reserved = 0; |
| 5027 | pSMB->Flags = 0; |
| 5028 | pSMB->Timeout = 0; |
| 5029 | pSMB->Reserved2 = 0; |
| 5030 | byte_count = params + 1 /* pad */ ; |
| 5031 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5032 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5033 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 5034 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 5035 | pSMB->DataCount = 0; |
| 5036 | pSMB->DataOffset = 0; |
| 5037 | pSMB->SetupCount = 1; |
| 5038 | pSMB->Reserved3 = 0; |
| 5039 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5040 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5041 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5042 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5043 | |
| 5044 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5045 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5046 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5047 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5048 | } else { /* decode response */ |
| 5049 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5050 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5051 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5052 | rc = -EIO; /* bad smb */ |
| 5053 | else { |
| 5054 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5055 | cifs_dbg(FYI, "qfsinf resp BCC: %d Offset %d\n", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5056 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5057 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5058 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5059 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 5060 | FSData->f_bsize = |
| 5061 | le16_to_cpu(response_data->BytesPerSector) * |
| 5062 | le32_to_cpu(response_data-> |
| 5063 | SectorsPerAllocationUnit); |
| 5064 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5065 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5066 | FSData->f_bfree = FSData->f_bavail = |
| 5067 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5068 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5069 | (unsigned long long)FSData->f_blocks, |
| 5070 | (unsigned long long)FSData->f_bfree, |
| 5071 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5072 | } |
| 5073 | } |
| 5074 | cifs_buf_release(pSMB); |
| 5075 | |
| 5076 | if (rc == -EAGAIN) |
| 5077 | goto oldQFSInfoRetry; |
| 5078 | |
| 5079 | return rc; |
| 5080 | } |
| 5081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5083 | CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 5084 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | { |
| 5086 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5087 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5088 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5089 | FILE_SYSTEM_INFO *response_data; |
| 5090 | int rc = 0; |
| 5091 | int bytes_returned = 0; |
| 5092 | __u16 params, byte_count; |
| 5093 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5094 | cifs_dbg(FYI, "In QFSInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | QFSInfoRetry: |
| 5096 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5097 | (void **) &pSMBr); |
| 5098 | if (rc) |
| 5099 | return rc; |
| 5100 | |
| 5101 | params = 2; /* level */ |
| 5102 | pSMB->TotalDataCount = 0; |
| 5103 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5104 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5105 | pSMB->MaxSetupCount = 0; |
| 5106 | pSMB->Reserved = 0; |
| 5107 | pSMB->Flags = 0; |
| 5108 | pSMB->Timeout = 0; |
| 5109 | pSMB->Reserved2 = 0; |
| 5110 | byte_count = params + 1 /* pad */ ; |
| 5111 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5112 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5113 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5114 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5115 | pSMB->DataCount = 0; |
| 5116 | pSMB->DataOffset = 0; |
| 5117 | pSMB->SetupCount = 1; |
| 5118 | pSMB->Reserved3 = 0; |
| 5119 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5120 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5121 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5123 | |
| 5124 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5125 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5126 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5127 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5129 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5131 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | rc = -EIO; /* bad smb */ |
| 5133 | else { |
| 5134 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5135 | |
| 5136 | response_data = |
| 5137 | (FILE_SYSTEM_INFO |
| 5138 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5139 | data_offset); |
| 5140 | FSData->f_bsize = |
| 5141 | le32_to_cpu(response_data->BytesPerSector) * |
| 5142 | le32_to_cpu(response_data-> |
| 5143 | SectorsPerAllocationUnit); |
| 5144 | FSData->f_blocks = |
| 5145 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 5146 | FSData->f_bfree = FSData->f_bavail = |
| 5147 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5148 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5149 | (unsigned long long)FSData->f_blocks, |
| 5150 | (unsigned long long)FSData->f_bfree, |
| 5151 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | } |
| 5153 | } |
| 5154 | cifs_buf_release(pSMB); |
| 5155 | |
| 5156 | if (rc == -EAGAIN) |
| 5157 | goto QFSInfoRetry; |
| 5158 | |
| 5159 | return rc; |
| 5160 | } |
| 5161 | |
| 5162 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5163 | CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | { |
| 5165 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5166 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5167 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5168 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5169 | int rc = 0; |
| 5170 | int bytes_returned = 0; |
| 5171 | __u16 params, byte_count; |
| 5172 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5173 | cifs_dbg(FYI, "In QFSAttributeInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | QFSAttributeRetry: |
| 5175 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5176 | (void **) &pSMBr); |
| 5177 | if (rc) |
| 5178 | return rc; |
| 5179 | |
| 5180 | params = 2; /* level */ |
| 5181 | pSMB->TotalDataCount = 0; |
| 5182 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5183 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5184 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 | pSMB->MaxSetupCount = 0; |
| 5186 | pSMB->Reserved = 0; |
| 5187 | pSMB->Flags = 0; |
| 5188 | pSMB->Timeout = 0; |
| 5189 | pSMB->Reserved2 = 0; |
| 5190 | byte_count = params + 1 /* pad */ ; |
| 5191 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5192 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5193 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5194 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5195 | pSMB->DataCount = 0; |
| 5196 | pSMB->DataOffset = 0; |
| 5197 | pSMB->SetupCount = 1; |
| 5198 | pSMB->Reserved3 = 0; |
| 5199 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5200 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5201 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5202 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5203 | |
| 5204 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5205 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5206 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5207 | cifs_dbg(VFS, "Send error in QFSAttributeInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | } else { /* decode response */ |
| 5209 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5210 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5211 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5212 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | rc = -EIO; /* bad smb */ |
| 5214 | } else { |
| 5215 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5216 | response_data = |
| 5217 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5218 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5219 | data_offset); |
| 5220 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5221 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5222 | } |
| 5223 | } |
| 5224 | cifs_buf_release(pSMB); |
| 5225 | |
| 5226 | if (rc == -EAGAIN) |
| 5227 | goto QFSAttributeRetry; |
| 5228 | |
| 5229 | return rc; |
| 5230 | } |
| 5231 | |
| 5232 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5233 | CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | { |
| 5235 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5236 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5237 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5238 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5239 | int rc = 0; |
| 5240 | int bytes_returned = 0; |
| 5241 | __u16 params, byte_count; |
| 5242 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5243 | cifs_dbg(FYI, "In QFSDeviceInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5244 | QFSDeviceRetry: |
| 5245 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5246 | (void **) &pSMBr); |
| 5247 | if (rc) |
| 5248 | return rc; |
| 5249 | |
| 5250 | params = 2; /* level */ |
| 5251 | pSMB->TotalDataCount = 0; |
| 5252 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5253 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5254 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5255 | pSMB->MaxSetupCount = 0; |
| 5256 | pSMB->Reserved = 0; |
| 5257 | pSMB->Flags = 0; |
| 5258 | pSMB->Timeout = 0; |
| 5259 | pSMB->Reserved2 = 0; |
| 5260 | byte_count = params + 1 /* pad */ ; |
| 5261 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5262 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5263 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5264 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5265 | |
| 5266 | pSMB->DataCount = 0; |
| 5267 | pSMB->DataOffset = 0; |
| 5268 | pSMB->SetupCount = 1; |
| 5269 | pSMB->Reserved3 = 0; |
| 5270 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5271 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5272 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5273 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5274 | |
| 5275 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5276 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5277 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5278 | cifs_dbg(FYI, "Send error in QFSDeviceInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5279 | } else { /* decode response */ |
| 5280 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5281 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5282 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5283 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5284 | rc = -EIO; /* bad smb */ |
| 5285 | else { |
| 5286 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5287 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5288 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5289 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5290 | data_offset); |
| 5291 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5292 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | } |
| 5294 | } |
| 5295 | cifs_buf_release(pSMB); |
| 5296 | |
| 5297 | if (rc == -EAGAIN) |
| 5298 | goto QFSDeviceRetry; |
| 5299 | |
| 5300 | return rc; |
| 5301 | } |
| 5302 | |
| 5303 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5304 | CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | { |
| 5306 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5307 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5308 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5309 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5310 | int rc = 0; |
| 5311 | int bytes_returned = 0; |
| 5312 | __u16 params, byte_count; |
| 5313 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5314 | cifs_dbg(FYI, "In QFSUnixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5315 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5316 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5317 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | if (rc) |
| 5319 | return rc; |
| 5320 | |
| 5321 | params = 2; /* level */ |
| 5322 | pSMB->TotalDataCount = 0; |
| 5323 | pSMB->DataCount = 0; |
| 5324 | pSMB->DataOffset = 0; |
| 5325 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5326 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5327 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5328 | pSMB->MaxSetupCount = 0; |
| 5329 | pSMB->Reserved = 0; |
| 5330 | pSMB->Flags = 0; |
| 5331 | pSMB->Timeout = 0; |
| 5332 | pSMB->Reserved2 = 0; |
| 5333 | byte_count = params + 1 /* pad */ ; |
| 5334 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5335 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5336 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5337 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5338 | pSMB->SetupCount = 1; |
| 5339 | pSMB->Reserved3 = 0; |
| 5340 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5341 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5342 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5343 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5344 | |
| 5345 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5346 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5347 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5348 | cifs_dbg(VFS, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | } else { /* decode response */ |
| 5350 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5351 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5352 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5353 | rc = -EIO; /* bad smb */ |
| 5354 | } else { |
| 5355 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5356 | response_data = |
| 5357 | (FILE_SYSTEM_UNIX_INFO |
| 5358 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5359 | data_offset); |
| 5360 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5361 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | } |
| 5363 | } |
| 5364 | cifs_buf_release(pSMB); |
| 5365 | |
| 5366 | if (rc == -EAGAIN) |
| 5367 | goto QFSUnixRetry; |
| 5368 | |
| 5369 | |
| 5370 | return rc; |
| 5371 | } |
| 5372 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5373 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5374 | CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5375 | { |
| 5376 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5377 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5378 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5379 | int rc = 0; |
| 5380 | int bytes_returned = 0; |
| 5381 | __u16 params, param_offset, offset, byte_count; |
| 5382 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5383 | cifs_dbg(FYI, "In SETFSUnixInfo\n"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5384 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5385 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5386 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5387 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5388 | if (rc) |
| 5389 | return rc; |
| 5390 | |
| 5391 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5392 | pSMB->MaxSetupCount = 0; |
| 5393 | pSMB->Reserved = 0; |
| 5394 | pSMB->Flags = 0; |
| 5395 | pSMB->Timeout = 0; |
| 5396 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5397 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5398 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5399 | offset = param_offset + params; |
| 5400 | |
| 5401 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5402 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5403 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5404 | pSMB->SetupCount = 1; |
| 5405 | pSMB->Reserved3 = 0; |
| 5406 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5407 | byte_count = 1 /* pad */ + params + 12; |
| 5408 | |
| 5409 | pSMB->DataCount = cpu_to_le16(12); |
| 5410 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5411 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5412 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5413 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5414 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5415 | |
| 5416 | /* Params. */ |
| 5417 | pSMB->FileNum = 0; |
| 5418 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5419 | |
| 5420 | /* Data. */ |
| 5421 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5422 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5423 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5424 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5425 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5426 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5427 | |
| 5428 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5429 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5430 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5431 | cifs_dbg(VFS, "Send error in SETFSUnixInfo = %d\n", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5432 | } else { /* decode response */ |
| 5433 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5434 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5435 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5436 | } |
| 5437 | cifs_buf_release(pSMB); |
| 5438 | |
| 5439 | if (rc == -EAGAIN) |
| 5440 | goto SETFSUnixRetry; |
| 5441 | |
| 5442 | return rc; |
| 5443 | } |
| 5444 | |
| 5445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5446 | |
| 5447 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5448 | CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5449 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5450 | { |
| 5451 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5452 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5453 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5454 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5455 | int rc = 0; |
| 5456 | int bytes_returned = 0; |
| 5457 | __u16 params, byte_count; |
| 5458 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5459 | cifs_dbg(FYI, "In QFSPosixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5460 | QFSPosixRetry: |
| 5461 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5462 | (void **) &pSMBr); |
| 5463 | if (rc) |
| 5464 | return rc; |
| 5465 | |
| 5466 | params = 2; /* level */ |
| 5467 | pSMB->TotalDataCount = 0; |
| 5468 | pSMB->DataCount = 0; |
| 5469 | pSMB->DataOffset = 0; |
| 5470 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5471 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5472 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5473 | pSMB->MaxSetupCount = 0; |
| 5474 | pSMB->Reserved = 0; |
| 5475 | pSMB->Flags = 0; |
| 5476 | pSMB->Timeout = 0; |
| 5477 | pSMB->Reserved2 = 0; |
| 5478 | byte_count = params + 1 /* pad */ ; |
| 5479 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5480 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5481 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5482 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 | pSMB->SetupCount = 1; |
| 5484 | pSMB->Reserved3 = 0; |
| 5485 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5486 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5487 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5488 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5489 | |
| 5490 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5491 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5492 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5493 | cifs_dbg(FYI, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | } else { /* decode response */ |
| 5495 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5496 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5497 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5498 | rc = -EIO; /* bad smb */ |
| 5499 | } else { |
| 5500 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5501 | response_data = |
| 5502 | (FILE_SYSTEM_POSIX_INFO |
| 5503 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5504 | data_offset); |
| 5505 | FSData->f_bsize = |
| 5506 | le32_to_cpu(response_data->BlockSize); |
| 5507 | FSData->f_blocks = |
| 5508 | le64_to_cpu(response_data->TotalBlocks); |
| 5509 | FSData->f_bfree = |
| 5510 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5511 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | FSData->f_bavail = FSData->f_bfree; |
| 5513 | } else { |
| 5514 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5515 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5517 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5519 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5520 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5522 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5523 | } |
| 5524 | } |
| 5525 | cifs_buf_release(pSMB); |
| 5526 | |
| 5527 | if (rc == -EAGAIN) |
| 5528 | goto QFSPosixRetry; |
| 5529 | |
| 5530 | return rc; |
| 5531 | } |
| 5532 | |
| 5533 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5534 | /* |
| 5535 | * We can not use write of zero bytes trick to set file size due to need for |
| 5536 | * large file support. Also note that this SetPathInfo is preferred to |
| 5537 | * SetFileInfo based method in next routine which is only needed to work around |
| 5538 | * a sharing violation bugin Samba which this routine can run into. |
| 5539 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5541 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5542 | const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, |
| 5543 | bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | { |
| 5545 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5546 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5547 | struct file_end_of_file_info *parm_data; |
| 5548 | int name_len; |
| 5549 | int rc = 0; |
| 5550 | int bytes_returned = 0; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 5551 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5554 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5555 | cifs_dbg(FYI, "In SetEOF\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5556 | SetEOFRetry: |
| 5557 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5558 | (void **) &pSMBr); |
| 5559 | if (rc) |
| 5560 | return rc; |
| 5561 | |
| 5562 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5563 | name_len = |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5564 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
| 5565 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | name_len++; /* trailing null */ |
| 5567 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5568 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5569 | name_len = strnlen(file_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5570 | name_len++; /* trailing null */ |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5571 | strncpy(pSMB->FileName, file_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5572 | } |
| 5573 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5574 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5576 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5577 | pSMB->MaxSetupCount = 0; |
| 5578 | pSMB->Reserved = 0; |
| 5579 | pSMB->Flags = 0; |
| 5580 | pSMB->Timeout = 0; |
| 5581 | pSMB->Reserved2 = 0; |
| 5582 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5583 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | offset = param_offset + params; |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5585 | if (set_allocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5586 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5587 | pSMB->InformationLevel = |
| 5588 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5589 | else |
| 5590 | pSMB->InformationLevel = |
| 5591 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5592 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5593 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5594 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5595 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5596 | else |
| 5597 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5598 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | parm_data = |
| 5602 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5603 | offset); |
| 5604 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5605 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5606 | pSMB->SetupCount = 1; |
| 5607 | pSMB->Reserved3 = 0; |
| 5608 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5609 | byte_count = 3 /* pad */ + params + data_count; |
| 5610 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5611 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5612 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5613 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5614 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5615 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | parm_data->FileSize = cpu_to_le64(size); |
| 5617 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5618 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5619 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5620 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5621 | cifs_dbg(FYI, "SetPathInfo (file size) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5622 | |
| 5623 | cifs_buf_release(pSMB); |
| 5624 | |
| 5625 | if (rc == -EAGAIN) |
| 5626 | goto SetEOFRetry; |
| 5627 | |
| 5628 | return rc; |
| 5629 | } |
| 5630 | |
| 5631 | int |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5632 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
| 5633 | struct cifsFileInfo *cfile, __u64 size, bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | { |
| 5635 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 | struct file_end_of_file_info *parm_data; |
| 5637 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5638 | __u16 params, param_offset, offset, byte_count, count; |
| 5639 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5640 | cifs_dbg(FYI, "SetFileSize (via SetFileInfo) %lld\n", |
| 5641 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5642 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | if (rc) |
| 5645 | return rc; |
| 5646 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5647 | pSMB->hdr.Pid = cpu_to_le16((__u16)cfile->pid); |
| 5648 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(cfile->pid >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5650 | params = 6; |
| 5651 | pSMB->MaxSetupCount = 0; |
| 5652 | pSMB->Reserved = 0; |
| 5653 | pSMB->Flags = 0; |
| 5654 | pSMB->Timeout = 0; |
| 5655 | pSMB->Reserved2 = 0; |
| 5656 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5657 | offset = param_offset + params; |
| 5658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | count = sizeof(struct file_end_of_file_info); |
| 5660 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5661 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5662 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5663 | pSMB->SetupCount = 1; |
| 5664 | pSMB->Reserved3 = 0; |
| 5665 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5666 | byte_count = 3 /* pad */ + params + count; |
| 5667 | pSMB->DataCount = cpu_to_le16(count); |
| 5668 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5669 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5670 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5671 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5672 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5673 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5674 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5676 | parm_data->FileSize = cpu_to_le64(size); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5677 | pSMB->Fid = cfile->fid.netfid; |
| 5678 | if (set_allocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5679 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5680 | pSMB->InformationLevel = |
| 5681 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5682 | else |
| 5683 | pSMB->InformationLevel = |
| 5684 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5685 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5686 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5687 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5688 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5689 | else |
| 5690 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5691 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | } |
| 5693 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5694 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5695 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5696 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5697 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5698 | cifs_dbg(FYI, "Send error in SetFileInfo (SetFileSize) = %d\n", |
| 5699 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | } |
| 5701 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5702 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | since file handle passed in no longer valid */ |
| 5704 | |
| 5705 | return rc; |
| 5706 | } |
| 5707 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5708 | /* 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] | 5709 | an open handle, rather than by pathname - this is awkward due to |
| 5710 | potential access conflicts on the open, but it is unavoidable for these |
| 5711 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5712 | time and resort to the original setpathinfo level which takes the ancient |
| 5713 | DOS time format with 2 second granularity */ |
| 5714 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5715 | CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5716 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | { |
| 5718 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | char *data_offset; |
| 5720 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | __u16 params, param_offset, offset, byte_count, count; |
| 5722 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5723 | cifs_dbg(FYI, "Set Times (via SetFileInfo)\n"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5724 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5726 | if (rc) |
| 5727 | return rc; |
| 5728 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5729 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5730 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | params = 6; |
| 5733 | pSMB->MaxSetupCount = 0; |
| 5734 | pSMB->Reserved = 0; |
| 5735 | pSMB->Flags = 0; |
| 5736 | pSMB->Timeout = 0; |
| 5737 | pSMB->Reserved2 = 0; |
| 5738 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5739 | offset = param_offset + params; |
| 5740 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5741 | data_offset = (char *)pSMB + |
| 5742 | offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5743 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5744 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5746 | /* BB find max SMB PDU from sess */ |
| 5747 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5748 | pSMB->SetupCount = 1; |
| 5749 | pSMB->Reserved3 = 0; |
| 5750 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5751 | byte_count = 3 /* pad */ + params + count; |
| 5752 | pSMB->DataCount = cpu_to_le16(count); |
| 5753 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5754 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5755 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5756 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5757 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5758 | pSMB->Fid = fid; |
| 5759 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5760 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5761 | else |
| 5762 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5763 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5764 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5765 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5766 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5767 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5768 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5769 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 5770 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5772 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5773 | since file handle passed in no longer valid */ |
| 5774 | |
| 5775 | return rc; |
| 5776 | } |
| 5777 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5778 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5779 | CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5780 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5781 | { |
| 5782 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5783 | char *data_offset; |
| 5784 | int rc = 0; |
| 5785 | __u16 params, param_offset, offset, byte_count, count; |
| 5786 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5787 | cifs_dbg(FYI, "Set File Disposition (via SetFileInfo)\n"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5788 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5789 | |
| 5790 | if (rc) |
| 5791 | return rc; |
| 5792 | |
| 5793 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5794 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5795 | |
| 5796 | params = 6; |
| 5797 | pSMB->MaxSetupCount = 0; |
| 5798 | pSMB->Reserved = 0; |
| 5799 | pSMB->Flags = 0; |
| 5800 | pSMB->Timeout = 0; |
| 5801 | pSMB->Reserved2 = 0; |
| 5802 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5803 | offset = param_offset + params; |
| 5804 | |
| 5805 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5806 | |
| 5807 | count = 1; |
| 5808 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5809 | /* BB find max SMB PDU from sess */ |
| 5810 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5811 | pSMB->SetupCount = 1; |
| 5812 | pSMB->Reserved3 = 0; |
| 5813 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5814 | byte_count = 3 /* pad */ + params + count; |
| 5815 | pSMB->DataCount = cpu_to_le16(count); |
| 5816 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5817 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5818 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5819 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5820 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5821 | pSMB->Fid = fid; |
| 5822 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5823 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5824 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5825 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5826 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5827 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5828 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5829 | cifs_dbg(FYI, "Send error in SetFileDisposition = %d\n", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5830 | |
| 5831 | return rc; |
| 5832 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | |
| 5834 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5835 | CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5836 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5837 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5838 | { |
| 5839 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5840 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5841 | int name_len; |
| 5842 | int rc = 0; |
| 5843 | int bytes_returned = 0; |
| 5844 | char *data_offset; |
| 5845 | __u16 params, param_offset, offset, byte_count, count; |
| 5846 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5847 | cifs_dbg(FYI, "In SetTimes\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5848 | |
| 5849 | SetTimesRetry: |
| 5850 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5851 | (void **) &pSMBr); |
| 5852 | if (rc) |
| 5853 | return rc; |
| 5854 | |
| 5855 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5856 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5857 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5858 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | name_len++; /* trailing null */ |
| 5860 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5861 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5862 | name_len = strnlen(fileName, PATH_MAX); |
| 5863 | name_len++; /* trailing null */ |
| 5864 | strncpy(pSMB->FileName, fileName, name_len); |
| 5865 | } |
| 5866 | |
| 5867 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5868 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5869 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5870 | /* BB find max SMB PDU from sess structure BB */ |
| 5871 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5872 | pSMB->MaxSetupCount = 0; |
| 5873 | pSMB->Reserved = 0; |
| 5874 | pSMB->Flags = 0; |
| 5875 | pSMB->Timeout = 0; |
| 5876 | pSMB->Reserved2 = 0; |
| 5877 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5878 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5879 | offset = param_offset + params; |
| 5880 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5881 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5882 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5883 | pSMB->SetupCount = 1; |
| 5884 | pSMB->Reserved3 = 0; |
| 5885 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5886 | byte_count = 3 /* pad */ + params + count; |
| 5887 | |
| 5888 | pSMB->DataCount = cpu_to_le16(count); |
| 5889 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5890 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5891 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5892 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5893 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5894 | else |
| 5895 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5896 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5897 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5898 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5899 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5900 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5901 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5902 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5903 | cifs_dbg(FYI, "SetPathInfo (times) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5904 | |
| 5905 | cifs_buf_release(pSMB); |
| 5906 | |
| 5907 | if (rc == -EAGAIN) |
| 5908 | goto SetTimesRetry; |
| 5909 | |
| 5910 | return rc; |
| 5911 | } |
| 5912 | |
| 5913 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5914 | /* Can be used to set attributes */ |
| 5915 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5916 | handling it anyway and NT4 was what we thought it would be needed for |
| 5917 | Do not delete it until we prove whether needed for Win9x though */ |
| 5918 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5919 | CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5920 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5921 | { |
| 5922 | SETATTR_REQ *pSMB = NULL; |
| 5923 | SETATTR_RSP *pSMBr = NULL; |
| 5924 | int rc = 0; |
| 5925 | int bytes_returned; |
| 5926 | int name_len; |
| 5927 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5928 | cifs_dbg(FYI, "In SetAttrLegacy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5929 | |
| 5930 | SetAttrLgcyRetry: |
| 5931 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5932 | (void **) &pSMBr); |
| 5933 | if (rc) |
| 5934 | return rc; |
| 5935 | |
| 5936 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5937 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5938 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 5939 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5940 | name_len++; /* trailing null */ |
| 5941 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5942 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5943 | name_len = strnlen(fileName, PATH_MAX); |
| 5944 | name_len++; /* trailing null */ |
| 5945 | strncpy(pSMB->fileName, fileName, name_len); |
| 5946 | } |
| 5947 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5948 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5949 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5950 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5951 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5952 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5953 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5954 | cifs_dbg(FYI, "Error in LegacySetAttr = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5955 | |
| 5956 | cifs_buf_release(pSMB); |
| 5957 | |
| 5958 | if (rc == -EAGAIN) |
| 5959 | goto SetAttrLgcyRetry; |
| 5960 | |
| 5961 | return rc; |
| 5962 | } |
| 5963 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5964 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5965 | static void |
| 5966 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5967 | const struct cifs_unix_set_info_args *args) |
| 5968 | { |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5969 | u64 uid = NO_CHANGE_64, gid = NO_CHANGE_64; |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5970 | u64 mode = args->mode; |
| 5971 | |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5972 | if (uid_valid(args->uid)) |
| 5973 | uid = from_kuid(&init_user_ns, args->uid); |
| 5974 | if (gid_valid(args->gid)) |
| 5975 | gid = from_kgid(&init_user_ns, args->gid); |
| 5976 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5977 | /* |
| 5978 | * Samba server ignores set of file size to zero due to bugs in some |
| 5979 | * older clients, but we should be precise - we use SetFileSize to |
| 5980 | * 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] | 5981 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5982 | * zero instead of -1 here |
| 5983 | */ |
| 5984 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5985 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5986 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5987 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5988 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5989 | data_offset->Uid = cpu_to_le64(uid); |
| 5990 | data_offset->Gid = cpu_to_le64(gid); |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5991 | /* better to leave device as zero when it is */ |
| 5992 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5993 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5994 | data_offset->Permissions = cpu_to_le64(mode); |
| 5995 | |
| 5996 | if (S_ISREG(mode)) |
| 5997 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5998 | else if (S_ISDIR(mode)) |
| 5999 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 6000 | else if (S_ISLNK(mode)) |
| 6001 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 6002 | else if (S_ISCHR(mode)) |
| 6003 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 6004 | else if (S_ISBLK(mode)) |
| 6005 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 6006 | else if (S_ISFIFO(mode)) |
| 6007 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 6008 | else if (S_ISSOCK(mode)) |
| 6009 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 6010 | } |
| 6011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6012 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6013 | CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6014 | const struct cifs_unix_set_info_args *args, |
| 6015 | u16 fid, u32 pid_of_opener) |
| 6016 | { |
| 6017 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6018 | char *data_offset; |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6019 | int rc = 0; |
| 6020 | u16 params, param_offset, offset, byte_count, count; |
| 6021 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6022 | cifs_dbg(FYI, "Set Unix Info (via SetFileInfo)\n"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6023 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 6024 | |
| 6025 | if (rc) |
| 6026 | return rc; |
| 6027 | |
| 6028 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 6029 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 6030 | |
| 6031 | params = 6; |
| 6032 | pSMB->MaxSetupCount = 0; |
| 6033 | pSMB->Reserved = 0; |
| 6034 | pSMB->Flags = 0; |
| 6035 | pSMB->Timeout = 0; |
| 6036 | pSMB->Reserved2 = 0; |
| 6037 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 6038 | offset = param_offset + params; |
| 6039 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6040 | data_offset = (char *)pSMB + |
| 6041 | offsetof(struct smb_hdr, Protocol) + offset; |
| 6042 | |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6043 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 6044 | |
| 6045 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 6046 | /* BB find max SMB PDU from sess */ |
| 6047 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 6048 | pSMB->SetupCount = 1; |
| 6049 | pSMB->Reserved3 = 0; |
| 6050 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 6051 | byte_count = 3 /* pad */ + params + count; |
| 6052 | pSMB->DataCount = cpu_to_le16(count); |
| 6053 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6054 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6055 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6056 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6057 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6058 | pSMB->Fid = fid; |
| 6059 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6060 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6061 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6062 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6063 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6064 | cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6065 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 6066 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6067 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6068 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 6069 | rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6070 | |
| 6071 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 6072 | since file handle passed in no longer valid */ |
| 6073 | |
| 6074 | return rc; |
| 6075 | } |
| 6076 | |
| 6077 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6078 | CIFSSMBUnixSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6079 | const char *file_name, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6080 | const struct cifs_unix_set_info_args *args, |
| 6081 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6082 | { |
| 6083 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 6084 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 6085 | int name_len; |
| 6086 | int rc = 0; |
| 6087 | int bytes_returned = 0; |
| 6088 | FILE_UNIX_BASIC_INFO *data_offset; |
| 6089 | __u16 params, param_offset, offset, count, byte_count; |
| 6090 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6091 | cifs_dbg(FYI, "In SetUID/GID/Mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6092 | setPermsRetry: |
| 6093 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6094 | (void **) &pSMBr); |
| 6095 | if (rc) |
| 6096 | return rc; |
| 6097 | |
| 6098 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6099 | name_len = |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6100 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6101 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6102 | name_len++; /* trailing null */ |
| 6103 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 6104 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6105 | name_len = strnlen(file_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6106 | name_len++; /* trailing null */ |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6107 | strncpy(pSMB->FileName, file_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | } |
| 6109 | |
| 6110 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 6111 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6112 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6113 | /* BB find max SMB PDU from sess structure BB */ |
| 6114 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6115 | pSMB->MaxSetupCount = 0; |
| 6116 | pSMB->Reserved = 0; |
| 6117 | pSMB->Flags = 0; |
| 6118 | pSMB->Timeout = 0; |
| 6119 | pSMB->Reserved2 = 0; |
| 6120 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6121 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6122 | offset = param_offset + params; |
| 6123 | data_offset = |
| 6124 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 6125 | offset); |
| 6126 | memset(data_offset, 0, count); |
| 6127 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6128 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6129 | pSMB->SetupCount = 1; |
| 6130 | pSMB->Reserved3 = 0; |
| 6131 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6132 | byte_count = 3 /* pad */ + params + count; |
| 6133 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6134 | pSMB->DataCount = cpu_to_le16(count); |
| 6135 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6136 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6137 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6138 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6139 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6140 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6141 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6142 | |
| 6143 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6144 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6145 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6146 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6147 | cifs_dbg(FYI, "SetPathInfo (perms) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6148 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6149 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6150 | if (rc == -EAGAIN) |
| 6151 | goto setPermsRetry; |
| 6152 | return rc; |
| 6153 | } |
| 6154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6155 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6156 | /* |
| 6157 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 6158 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 6159 | * it looks for that attribute name and stuffs that value into the EAData |
| 6160 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 6161 | * buffer. In both cases, the return value is either the length of the |
| 6162 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 6163 | * the data isn't copied to it, but the length is returned. |
| 6164 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6165 | ssize_t |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6166 | CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6167 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6168 | char *EAData, size_t buf_size, |
| 6169 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6170 | { |
| 6171 | /* BB assumes one setup word */ |
| 6172 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6173 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 6174 | int rc = 0; |
| 6175 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6176 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6177 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6178 | struct fea *temp_fea; |
| 6179 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6180 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6181 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6182 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6183 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6184 | cifs_dbg(FYI, "In Query All EAs path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6185 | QAllEAsRetry: |
| 6186 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6187 | (void **) &pSMBr); |
| 6188 | if (rc) |
| 6189 | return rc; |
| 6190 | |
| 6191 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6192 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6193 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6194 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6195 | list_len++; /* trailing null */ |
| 6196 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6197 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6198 | list_len = strnlen(searchName, PATH_MAX); |
| 6199 | list_len++; /* trailing null */ |
| 6200 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6201 | } |
| 6202 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6203 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6204 | pSMB->TotalDataCount = 0; |
| 6205 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6206 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6207 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6208 | pSMB->MaxSetupCount = 0; |
| 6209 | pSMB->Reserved = 0; |
| 6210 | pSMB->Flags = 0; |
| 6211 | pSMB->Timeout = 0; |
| 6212 | pSMB->Reserved2 = 0; |
| 6213 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6214 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6215 | pSMB->DataCount = 0; |
| 6216 | pSMB->DataOffset = 0; |
| 6217 | pSMB->SetupCount = 1; |
| 6218 | pSMB->Reserved3 = 0; |
| 6219 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6220 | byte_count = params + 1 /* pad */ ; |
| 6221 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6222 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6223 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6224 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6225 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6227 | |
| 6228 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6229 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6230 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6231 | cifs_dbg(FYI, "Send error in QueryAllEAs = %d\n", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6232 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6233 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6234 | |
| 6235 | |
| 6236 | /* BB also check enough total bytes returned */ |
| 6237 | /* BB we need to improve the validity checking |
| 6238 | of these trans2 responses */ |
| 6239 | |
| 6240 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6241 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6242 | rc = -EIO; /* bad smb */ |
| 6243 | goto QAllEAsOut; |
| 6244 | } |
| 6245 | |
| 6246 | /* check that length of list is not more than bcc */ |
| 6247 | /* check that each entry does not go beyond length |
| 6248 | of list */ |
| 6249 | /* check that each element of each entry does not |
| 6250 | go beyond end of list */ |
| 6251 | /* validate_trans2_offsets() */ |
| 6252 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6253 | |
| 6254 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6255 | ea_response_data = (struct fealist *) |
| 6256 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6257 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6258 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6259 | cifs_dbg(FYI, "ea length %d\n", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6260 | if (list_len <= 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6261 | cifs_dbg(FYI, "empty EA list returned from server\n"); |
Steve French | 60977fc | 2014-03-25 19:46:36 -0500 | [diff] [blame] | 6262 | /* didn't find the named attribute */ |
| 6263 | if (ea_name) |
| 6264 | rc = -ENODATA; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6265 | goto QAllEAsOut; |
| 6266 | } |
| 6267 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6268 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6269 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6270 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6271 | cifs_dbg(FYI, "EA list appears to go beyond SMB\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6272 | rc = -EIO; |
| 6273 | goto QAllEAsOut; |
| 6274 | } |
| 6275 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6276 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6277 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6278 | temp_fea = ea_response_data->list; |
| 6279 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6280 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6281 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6282 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6283 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6284 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6285 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6286 | /* make sure we can read name_len and value_len */ |
| 6287 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6288 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6289 | rc = -EIO; |
| 6290 | goto QAllEAsOut; |
| 6291 | } |
| 6292 | |
| 6293 | name_len = temp_fea->name_len; |
| 6294 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6295 | list_len -= name_len + 1 + value_len; |
| 6296 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6297 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6298 | rc = -EIO; |
| 6299 | goto QAllEAsOut; |
| 6300 | } |
| 6301 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6302 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6303 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6304 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6305 | temp_ptr += name_len + 1; |
| 6306 | rc = value_len; |
| 6307 | if (buf_size == 0) |
| 6308 | goto QAllEAsOut; |
| 6309 | if ((size_t)value_len > buf_size) { |
| 6310 | rc = -ERANGE; |
| 6311 | goto QAllEAsOut; |
| 6312 | } |
| 6313 | memcpy(EAData, temp_ptr, value_len); |
| 6314 | goto QAllEAsOut; |
| 6315 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6316 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6317 | /* account for prefix user. and trailing null */ |
| 6318 | rc += (5 + 1 + name_len); |
| 6319 | if (rc < (int) buf_size) { |
| 6320 | memcpy(EAData, "user.", 5); |
| 6321 | EAData += 5; |
| 6322 | memcpy(EAData, temp_ptr, name_len); |
| 6323 | EAData += name_len; |
| 6324 | /* null terminate name */ |
| 6325 | *EAData = 0; |
| 6326 | ++EAData; |
| 6327 | } else if (buf_size == 0) { |
| 6328 | /* skip copy - calc size only */ |
| 6329 | } else { |
| 6330 | /* stop before overrun buffer */ |
| 6331 | rc = -ERANGE; |
| 6332 | break; |
| 6333 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6334 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6335 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6336 | temp_fea = (struct fea *)temp_ptr; |
| 6337 | } |
| 6338 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6339 | /* didn't find the named attribute */ |
| 6340 | if (ea_name) |
| 6341 | rc = -ENODATA; |
| 6342 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6343 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6344 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | if (rc == -EAGAIN) |
| 6346 | goto QAllEAsRetry; |
| 6347 | |
| 6348 | return (ssize_t)rc; |
| 6349 | } |
| 6350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6351 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6352 | CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, |
| 6353 | const char *fileName, const char *ea_name, const void *ea_value, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6354 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 6355 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6356 | { |
| 6357 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6358 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6359 | struct fealist *parm_data; |
| 6360 | int name_len; |
| 6361 | int rc = 0; |
| 6362 | int bytes_returned = 0; |
| 6363 | __u16 params, param_offset, byte_count, offset, count; |
| 6364 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6365 | cifs_dbg(FYI, "In SetEA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6366 | SetEARetry: |
| 6367 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6368 | (void **) &pSMBr); |
| 6369 | if (rc) |
| 6370 | return rc; |
| 6371 | |
| 6372 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6373 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6374 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6375 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6376 | name_len++; /* trailing null */ |
| 6377 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6378 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6379 | name_len = strnlen(fileName, PATH_MAX); |
| 6380 | name_len++; /* trailing null */ |
| 6381 | strncpy(pSMB->FileName, fileName, name_len); |
| 6382 | } |
| 6383 | |
| 6384 | params = 6 + name_len; |
| 6385 | |
| 6386 | /* done calculating parms using name_len of file name, |
| 6387 | now use name_len to calculate length of ea name |
| 6388 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6389 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6390 | name_len = 0; |
| 6391 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6392 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6393 | |
Steve French | dae5dbdb | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6394 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6395 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6396 | /* BB find max SMB PDU from sess */ |
| 6397 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6398 | pSMB->MaxSetupCount = 0; |
| 6399 | pSMB->Reserved = 0; |
| 6400 | pSMB->Flags = 0; |
| 6401 | pSMB->Timeout = 0; |
| 6402 | pSMB->Reserved2 = 0; |
| 6403 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6404 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6405 | offset = param_offset + params; |
| 6406 | pSMB->InformationLevel = |
| 6407 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6408 | |
| 6409 | parm_data = |
| 6410 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 6411 | offset); |
| 6412 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6413 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6414 | pSMB->SetupCount = 1; |
| 6415 | pSMB->Reserved3 = 0; |
| 6416 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6417 | byte_count = 3 /* pad */ + params + count; |
| 6418 | pSMB->DataCount = cpu_to_le16(count); |
| 6419 | parm_data->list_len = cpu_to_le32(count); |
| 6420 | parm_data->list[0].EA_flags = 0; |
| 6421 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6422 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6423 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6424 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6425 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6426 | parm_data->list[0].name[name_len] = 0; |
| 6427 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6428 | /* caller ensures that ea_value_len is less than 64K but |
| 6429 | we need to ensure that it fits within the smb */ |
| 6430 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6431 | /*BB add length check to see if it would fit in |
| 6432 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6433 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6434 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6435 | memcpy(parm_data->list[0].name+name_len+1, |
| 6436 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6437 | |
| 6438 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6439 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6440 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6441 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6442 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6443 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6444 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6445 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6446 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6447 | cifs_dbg(FYI, "SetPathInfo (EA) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6448 | |
| 6449 | cifs_buf_release(pSMB); |
| 6450 | |
| 6451 | if (rc == -EAGAIN) |
| 6452 | goto SetEARetry; |
| 6453 | |
| 6454 | return rc; |
| 6455 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6456 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6457 | |
| 6458 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 6459 | /* |
| 6460 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 6461 | * to allow network clients (such as Windows) to display updated |
| 6462 | * lists of files in directory listings automatically when |
| 6463 | * files are added by one user when another user has the |
| 6464 | * same directory open on their desktop. The Linux cifs kernel |
| 6465 | * client hooked into the kernel side of this interface for |
| 6466 | * the same reason, but ironically when the VFS moved from |
| 6467 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 6468 | * network file system clients (the most obvious use case |
| 6469 | * for notify interfaces is when multiple users can update |
| 6470 | * the contents of the same directory - exactly what network |
| 6471 | * file systems can do) although the server (Samba) could |
| 6472 | * still use it. For the short term we leave the worker |
| 6473 | * function ifdeffed out (below) until inotify is fixed |
| 6474 | * in the VFS to make it easier to plug in network file |
| 6475 | * system clients. If inotify turns out to be permanently |
| 6476 | * incompatible for network fs clients, we could instead simply |
| 6477 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 6478 | */ |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6479 | int CIFSSMBNotify(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6480 | const int notify_subdirs, const __u16 netfid, |
| 6481 | __u32 filter, struct file *pfile, int multishot, |
| 6482 | const struct nls_table *nls_codepage) |
| 6483 | { |
| 6484 | int rc = 0; |
| 6485 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 6486 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 6487 | struct dir_notify_req *dnotify_req; |
| 6488 | int bytes_returned; |
| 6489 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6490 | cifs_dbg(FYI, "In CIFSSMBNotify for file handle %d\n", (int)netfid); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6491 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 6492 | (void **) &pSMBr); |
| 6493 | if (rc) |
| 6494 | return rc; |
| 6495 | |
| 6496 | pSMB->TotalParameterCount = 0 ; |
| 6497 | pSMB->TotalDataCount = 0; |
| 6498 | pSMB->MaxParameterCount = cpu_to_le32(2); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6499 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6500 | pSMB->MaxSetupCount = 4; |
| 6501 | pSMB->Reserved = 0; |
| 6502 | pSMB->ParameterOffset = 0; |
| 6503 | pSMB->DataCount = 0; |
| 6504 | pSMB->DataOffset = 0; |
| 6505 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 6506 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 6507 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6508 | if (notify_subdirs) |
| 6509 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 6510 | pSMB->Reserved2 = 0; |
| 6511 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 6512 | pSMB->Fid = netfid; /* file handle always le */ |
| 6513 | pSMB->ByteCount = 0; |
| 6514 | |
| 6515 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6516 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 6517 | CIFS_ASYNC_OP); |
| 6518 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6519 | cifs_dbg(FYI, "Error in Notify = %d\n", rc); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6520 | } else { |
| 6521 | /* Add file to outstanding requests */ |
| 6522 | /* BB change to kmem cache alloc */ |
| 6523 | dnotify_req = kmalloc( |
| 6524 | sizeof(struct dir_notify_req), |
| 6525 | GFP_KERNEL); |
| 6526 | if (dnotify_req) { |
| 6527 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 6528 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 6529 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 6530 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 6531 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 6532 | dnotify_req->netfid = netfid; |
| 6533 | dnotify_req->pfile = pfile; |
| 6534 | dnotify_req->filter = filter; |
| 6535 | dnotify_req->multishot = multishot; |
| 6536 | spin_lock(&GlobalMid_Lock); |
| 6537 | list_add_tail(&dnotify_req->lhead, |
| 6538 | &GlobalDnotifyReqList); |
| 6539 | spin_unlock(&GlobalMid_Lock); |
| 6540 | } else |
| 6541 | rc = -ENOMEM; |
| 6542 | } |
| 6543 | cifs_buf_release(pSMB); |
| 6544 | return rc; |
| 6545 | } |
| 6546 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |