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 | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 38 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" |
Long Li | db223a5 | 2017-11-22 17:38:45 -0700 | [diff] [blame] | 46 | #include "smbdirect.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | #ifdef CONFIG_CIFS_POSIX |
| 49 | static struct { |
| 50 | int index; |
| 51 | char *name; |
| 52 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 53 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 54 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 55 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 56 | #endif /* weak password hashing for legacy clients */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 57 | {CIFS_PROT, "\2NT LM 0.12"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 58 | {POSIX_PROT, "\2POSIX 2"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | {BAD_PROT, "\2"} |
| 60 | }; |
| 61 | #else |
| 62 | static struct { |
| 63 | int index; |
| 64 | char *name; |
| 65 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 66 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 67 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 18f75ca | 2006-10-01 03:13:01 +0000 | [diff] [blame] | 68 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 69 | #endif /* weak password hashing for legacy clients */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 70 | {CIFS_PROT, "\2NT LM 0.12"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | {BAD_PROT, "\2"} |
| 72 | }; |
| 73 | #endif |
| 74 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 75 | /* define the number of elements in the cifs dialect array */ |
| 76 | #ifdef CONFIG_CIFS_POSIX |
| 77 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 78 | #define CIFS_NUM_PROT 4 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 79 | #else |
| 80 | #define CIFS_NUM_PROT 2 |
| 81 | #endif /* CIFS_WEAK_PW_HASH */ |
| 82 | #else /* not posix */ |
| 83 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 84 | #define CIFS_NUM_PROT 3 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 85 | #else |
| 86 | #define CIFS_NUM_PROT 1 |
| 87 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
| 88 | #endif /* CIFS_POSIX */ |
| 89 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 90 | /* |
| 91 | * Mark as invalid, all open files on tree connections since they |
| 92 | * were closed when session to server was lost. |
| 93 | */ |
| 94 | void |
| 95 | cifs_mark_open_files_invalid(struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 98 | struct list_head *tmp; |
| 99 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 101 | /* list all files open on tree connection and mark them invalid */ |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 102 | spin_lock(&tcon->open_file_lock); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 103 | list_for_each_safe(tmp, tmp1, &tcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 104 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 105 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 106 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 108 | spin_unlock(&tcon->open_file_lock); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 109 | /* |
| 110 | * BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 111 | * to this tcon. |
| 112 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 115 | /* reconnect the socket, tcon, and smb session if needed */ |
| 116 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 117 | cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 118 | { |
Jeff Layton | c4a5534 | 2011-07-28 12:40:36 -0400 | [diff] [blame] | 119 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 120 | struct cifs_ses *ses; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 121 | struct TCP_Server_Info *server; |
| 122 | struct nls_table *nls_codepage; |
| 123 | |
| 124 | /* |
| 125 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 126 | * tcp and smb session status done differently for those three - in the |
| 127 | * calling routine |
| 128 | */ |
| 129 | if (!tcon) |
| 130 | return 0; |
| 131 | |
| 132 | ses = tcon->ses; |
| 133 | server = ses->server; |
| 134 | |
| 135 | /* |
| 136 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 137 | * have tcon) are allowed as we start force umount |
| 138 | */ |
| 139 | if (tcon->tidStatus == CifsExiting) { |
| 140 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 141 | smb_command != SMB_COM_OPEN_ANDX && |
| 142 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 143 | cifs_dbg(FYI, "can not send cmd %d while umounting\n", |
| 144 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 145 | return -ENODEV; |
| 146 | } |
| 147 | } |
| 148 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 149 | /* |
| 150 | * Give demultiplex thread up to 10 seconds to reconnect, should be |
| 151 | * greater than cifs socket timeout which is 7 seconds |
| 152 | */ |
| 153 | while (server->tcpStatus == CifsNeedReconnect) { |
| 154 | wait_event_interruptible_timeout(server->response_q, |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 155 | (server->tcpStatus != CifsNeedReconnect), 10 * HZ); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 156 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 157 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 158 | if (server->tcpStatus != CifsNeedReconnect) |
| 159 | break; |
| 160 | |
| 161 | /* |
| 162 | * on "soft" mounts we wait once. Hard mounts keep |
| 163 | * retrying until process is killed or server comes |
| 164 | * back on-line |
| 165 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 166 | if (!tcon->retry) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 167 | cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 168 | return -EHOSTDOWN; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 173 | return 0; |
| 174 | |
| 175 | nls_codepage = load_nls_default(); |
| 176 | |
| 177 | /* |
| 178 | * need to prevent multiple threads trying to simultaneously |
| 179 | * reconnect the same SMB session |
| 180 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 181 | mutex_lock(&ses->session_mutex); |
Samuel Cabrero | 76e7527 | 2017-07-11 12:44:39 +0200 | [diff] [blame] | 182 | |
| 183 | /* |
| 184 | * Recheck after acquire mutex. If another thread is negotiating |
| 185 | * and the server never sends an answer the socket will be closed |
| 186 | * and tcpStatus set to reconnect. |
| 187 | */ |
| 188 | if (server->tcpStatus == CifsNeedReconnect) { |
| 189 | rc = -EHOSTDOWN; |
| 190 | mutex_unlock(&ses->session_mutex); |
| 191 | goto out; |
| 192 | } |
| 193 | |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 194 | rc = cifs_negotiate_protocol(0, ses); |
| 195 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 196 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 197 | |
| 198 | /* do we need to reconnect tcon? */ |
| 199 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 200 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 201 | goto out; |
| 202 | } |
| 203 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 204 | cifs_mark_open_files_invalid(tcon); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 205 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 206 | mutex_unlock(&ses->session_mutex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 207 | cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 208 | |
Steve French | c318e6c | 2018-04-04 14:08:52 -0500 | [diff] [blame^] | 209 | if (rc) { |
| 210 | printk_once(KERN_WARNING "reconnect tcon failed rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 211 | goto out; |
Steve French | c318e6c | 2018-04-04 14:08:52 -0500 | [diff] [blame^] | 212 | } |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 213 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 214 | atomic_inc(&tconInfoReconnectCount); |
| 215 | |
| 216 | /* tell server Unix caps we support */ |
| 217 | if (ses->capabilities & CAP_UNIX) |
| 218 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 219 | |
| 220 | /* |
| 221 | * Removed call to reopen open files here. It is safer (and faster) to |
| 222 | * reopen files one at a time as needed in read and write. |
| 223 | * |
| 224 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 225 | */ |
| 226 | |
| 227 | out: |
| 228 | /* |
| 229 | * Check if handle based operation so we know whether we can continue |
| 230 | * or not without returning to caller to reset file handle |
| 231 | */ |
| 232 | switch (smb_command) { |
| 233 | case SMB_COM_READ_ANDX: |
| 234 | case SMB_COM_WRITE_ANDX: |
| 235 | case SMB_COM_CLOSE: |
| 236 | case SMB_COM_FIND_CLOSE2: |
| 237 | case SMB_COM_LOCKING_ANDX: |
| 238 | rc = -EAGAIN; |
| 239 | } |
| 240 | |
| 241 | unload_nls(nls_codepage); |
| 242 | return rc; |
| 243 | } |
| 244 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 245 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 246 | SMB information in the SMB header. If the return code is zero, this |
| 247 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 249 | small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 250 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 252 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 254 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 255 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | return rc; |
| 257 | |
| 258 | *request_buf = cifs_small_buf_get(); |
| 259 | if (*request_buf == NULL) { |
| 260 | /* BB should we add a retry in here if not a writepage? */ |
| 261 | return -ENOMEM; |
| 262 | } |
| 263 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 264 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 265 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 267 | if (tcon != NULL) |
| 268 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 269 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 270 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 273 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 274 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 275 | struct cifs_ses *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 276 | { |
| 277 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 278 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 279 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 280 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 281 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 282 | return rc; |
| 283 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 284 | buffer = (struct smb_hdr *)*request_buf; |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 285 | buffer->Mid = get_next_mid(ses->server); |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 286 | if (ses->capabilities & CAP_UNICODE) |
| 287 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 288 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 289 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 290 | |
| 291 | /* uid, tid can stay at zero as set in header assemble */ |
| 292 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 293 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 294 | this function is used after 1st of session setup requests */ |
| 295 | |
| 296 | return rc; |
| 297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 300 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 301 | __smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 302 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | *request_buf = cifs_buf_get(); |
| 305 | if (*request_buf == NULL) { |
| 306 | /* BB should we add a retry in here if not a writepage? */ |
| 307 | return -ENOMEM; |
| 308 | } |
| 309 | /* Although the original thought was we needed the response buf for */ |
| 310 | /* potential retries of smb operations it turns out we can determine */ |
| 311 | /* from the mid flags when the request buffer can be resent without */ |
| 312 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 313 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 314 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 317 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 319 | if (tcon != NULL) |
| 320 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 321 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 326 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 327 | smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 328 | void **request_buf, void **response_buf) |
| 329 | { |
| 330 | int rc; |
| 331 | |
| 332 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 333 | if (rc) |
| 334 | return rc; |
| 335 | |
| 336 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 337 | } |
| 338 | |
| 339 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 340 | 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] | 341 | void **request_buf, void **response_buf) |
| 342 | { |
| 343 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 344 | return -EHOSTDOWN; |
| 345 | |
| 346 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 349 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 351 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 353 | /* check for plausible wct */ |
| 354 | if (pSMB->hdr.WordCount < 10) |
| 355 | goto vt2_err; |
| 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 358 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 359 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 360 | goto vt2_err; |
| 361 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 362 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 363 | if (total_size >= 512) |
| 364 | goto vt2_err; |
| 365 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 366 | /* check that bcc is at least as big as parms + data, and that it is |
| 367 | * less than negotiated smb buffer |
| 368 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 369 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 370 | if (total_size > get_bcc(&pSMB->hdr) || |
| 371 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 372 | goto vt2_err; |
| 373 | |
| 374 | return 0; |
| 375 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 376 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 378 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 380 | |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 381 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 382 | decode_ext_sec_blob(struct cifs_ses *ses, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 383 | { |
| 384 | int rc = 0; |
| 385 | u16 count; |
| 386 | char *guid = pSMBr->u.extended_response.GUID; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 387 | struct TCP_Server_Info *server = ses->server; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 388 | |
| 389 | count = get_bcc(&pSMBr->hdr); |
| 390 | if (count < SMB1_CLIENT_GUID_SIZE) |
| 391 | return -EIO; |
| 392 | |
| 393 | spin_lock(&cifs_tcp_ses_lock); |
| 394 | if (server->srv_count > 1) { |
| 395 | spin_unlock(&cifs_tcp_ses_lock); |
| 396 | if (memcmp(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE) != 0) { |
| 397 | cifs_dbg(FYI, "server UID changed\n"); |
| 398 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 399 | } |
| 400 | } else { |
| 401 | spin_unlock(&cifs_tcp_ses_lock); |
| 402 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 403 | } |
| 404 | |
| 405 | if (count == SMB1_CLIENT_GUID_SIZE) { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 406 | server->sec_ntlmssp = true; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 407 | } else { |
| 408 | count -= SMB1_CLIENT_GUID_SIZE; |
| 409 | rc = decode_negTokenInit( |
| 410 | pSMBr->u.extended_response.SecurityBlob, count, server); |
| 411 | if (rc != 1) |
| 412 | return -EINVAL; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 418 | int |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 419 | cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required) |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 420 | { |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 421 | bool srv_sign_required = server->sec_mode & server->vals->signing_required; |
| 422 | bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled; |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 423 | bool mnt_sign_enabled = global_secflags & CIFSSEC_MAY_SIGN; |
| 424 | |
| 425 | /* |
| 426 | * Is signing required by mnt options? If not then check |
| 427 | * global_secflags to see if it is there. |
| 428 | */ |
| 429 | if (!mnt_sign_required) |
| 430 | mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) == |
| 431 | CIFSSEC_MUST_SIGN); |
| 432 | |
| 433 | /* |
| 434 | * If signing is required then it's automatically enabled too, |
| 435 | * otherwise, check to see if the secflags allow it. |
| 436 | */ |
| 437 | mnt_sign_enabled = mnt_sign_required ? mnt_sign_required : |
| 438 | (global_secflags & CIFSSEC_MAY_SIGN); |
| 439 | |
| 440 | /* If server requires signing, does client allow it? */ |
| 441 | if (srv_sign_required) { |
| 442 | if (!mnt_sign_enabled) { |
| 443 | cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!"); |
| 444 | return -ENOTSUPP; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 445 | } |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 446 | server->sign = true; |
| 447 | } |
| 448 | |
| 449 | /* If client requires signing, does server allow it? */ |
| 450 | if (mnt_sign_required) { |
| 451 | if (!srv_sign_enabled) { |
| 452 | cifs_dbg(VFS, "Server does not support signing!"); |
| 453 | return -ENOTSUPP; |
| 454 | } |
| 455 | server->sign = true; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 461 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 462 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 463 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 464 | { |
| 465 | __s16 tmp; |
| 466 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
| 467 | |
| 468 | if (server->dialect != LANMAN_PROT && server->dialect != LANMAN2_PROT) |
| 469 | return -EOPNOTSUPP; |
| 470 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 471 | server->sec_mode = le16_to_cpu(rsp->SecurityMode); |
| 472 | server->maxReq = min_t(unsigned int, |
| 473 | le16_to_cpu(rsp->MaxMpxCount), |
| 474 | cifs_max_pending); |
| 475 | set_credits(server, server->maxReq); |
| 476 | server->maxBuf = le16_to_cpu(rsp->MaxBufSize); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 477 | /* even though we do not use raw we might as well set this |
| 478 | accurately, in case we ever find a need for it */ |
| 479 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
| 480 | server->max_rw = 0xFF00; |
| 481 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 482 | } else { |
| 483 | server->max_rw = 0;/* do not need to use raw anyway */ |
| 484 | server->capabilities = CAP_MPX_MODE; |
| 485 | } |
| 486 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
| 487 | if (tmp == -1) { |
| 488 | /* OS/2 often does not set timezone therefore |
| 489 | * we must use server time to calc time zone. |
| 490 | * Could deviate slightly from the right zone. |
| 491 | * Smallest defined timezone difference is 15 minutes |
| 492 | * (i.e. Nepal). Rounding up/down is done to match |
| 493 | * this requirement. |
| 494 | */ |
| 495 | int val, seconds, remain, result; |
Deepa Dinamani | e37fea5 | 2017-05-08 15:59:16 -0700 | [diff] [blame] | 496 | struct timespec ts; |
| 497 | unsigned long utc = ktime_get_real_seconds(); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 498 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 499 | rsp->SrvTime.Time, 0); |
| 500 | cifs_dbg(FYI, "SrvTime %d sec since 1970 (utc: %d) diff: %d\n", |
Deepa Dinamani | e37fea5 | 2017-05-08 15:59:16 -0700 | [diff] [blame] | 501 | (int)ts.tv_sec, (int)utc, |
| 502 | (int)(utc - ts.tv_sec)); |
| 503 | val = (int)(utc - ts.tv_sec); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 504 | seconds = abs(val); |
| 505 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
| 506 | remain = seconds % MIN_TZ_ADJ; |
| 507 | if (remain >= (MIN_TZ_ADJ / 2)) |
| 508 | result += MIN_TZ_ADJ; |
| 509 | if (val < 0) |
| 510 | result = -result; |
| 511 | server->timeAdj = result; |
| 512 | } else { |
| 513 | server->timeAdj = (int)tmp; |
| 514 | server->timeAdj *= 60; /* also in seconds */ |
| 515 | } |
| 516 | cifs_dbg(FYI, "server->timeAdj: %d seconds\n", server->timeAdj); |
| 517 | |
| 518 | |
| 519 | /* BB get server time for time conversions and add |
| 520 | code to use it and timezone since this is not UTC */ |
| 521 | |
| 522 | if (rsp->EncryptionKeyLength == |
| 523 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
| 524 | memcpy(server->cryptkey, rsp->EncryptionKey, |
| 525 | CIFS_CRYPTO_KEY_SIZE); |
| 526 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
| 527 | return -EIO; /* need cryptkey unless plain text */ |
| 528 | } |
| 529 | |
| 530 | cifs_dbg(FYI, "LANMAN negotiated\n"); |
| 531 | return 0; |
| 532 | } |
| 533 | #else |
| 534 | static inline int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 535 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 536 | { |
| 537 | cifs_dbg(VFS, "mount failed, cifs module not built with CIFS_WEAK_PW_HASH support\n"); |
| 538 | return -EOPNOTSUPP; |
| 539 | } |
| 540 | #endif |
| 541 | |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 542 | static bool |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 543 | should_set_ext_sec_flag(enum securityEnum sectype) |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 544 | { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 545 | switch (sectype) { |
| 546 | case RawNTLMSSP: |
| 547 | case Kerberos: |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 548 | return true; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 549 | case Unspecified: |
| 550 | if (global_secflags & |
| 551 | (CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)) |
| 552 | return true; |
| 553 | /* Fallthrough */ |
| 554 | default: |
| 555 | return false; |
| 556 | } |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 557 | } |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | int |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 560 | CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
| 562 | NEGOTIATE_REQ *pSMB; |
| 563 | NEGOTIATE_RSP *pSMBr; |
| 564 | int rc = 0; |
| 565 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 566 | int i; |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 567 | struct TCP_Server_Info *server = ses->server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | u16 count; |
| 569 | |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 570 | if (!server) { |
| 571 | WARN(1, "%s: server is NULL!\n", __func__); |
| 572 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 576 | (void **) &pSMB, (void **) &pSMBr); |
| 577 | if (rc) |
| 578 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 579 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 580 | pSMB->hdr.Mid = get_next_mid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 581 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 582 | |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 583 | if (should_set_ext_sec_flag(ses->sectype)) { |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 584 | cifs_dbg(FYI, "Requesting extended security."); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 585 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 586 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 587 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 588 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 589 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 590 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 591 | count += strlen(protocols[i].name) + 1; |
| 592 | /* null at end of source and target buffers anyway */ |
| 593 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 594 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | pSMB->ByteCount = cpu_to_le16(count); |
| 596 | |
| 597 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 598 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 599 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 600 | goto neg_err_exit; |
| 601 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 602 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 603 | cifs_dbg(FYI, "Dialect: %d\n", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 604 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 605 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 606 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 607 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 608 | could not negotiate a common dialect */ |
| 609 | rc = -EOPNOTSUPP; |
| 610 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 611 | } else if (pSMBr->hdr.WordCount == 13) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 612 | server->negflavor = CIFS_NEGFLAVOR_LANMAN; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 613 | rc = decode_lanman_negprot_rsp(server, pSMBr); |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 614 | goto signing_check; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 615 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 616 | /* unknown wct */ |
| 617 | rc = -EOPNOTSUPP; |
| 618 | goto neg_err_exit; |
| 619 | } |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 620 | /* else wct == 17, NTLM or better */ |
| 621 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 622 | server->sec_mode = pSMBr->SecurityMode; |
| 623 | if ((server->sec_mode & SECMODE_USER) == 0) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 624 | cifs_dbg(FYI, "share mode security\n"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 625 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 626 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 627 | little endian */ |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 628 | server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), |
| 629 | cifs_max_pending); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 630 | set_credits(server, server->maxReq); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 631 | /* probably no need to store and check maxvcs */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 632 | server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 633 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 634 | cifs_dbg(NOISY, "Max buf = %d\n", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 635 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 636 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 637 | server->timeAdj *= 60; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 638 | |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 639 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
| 640 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 641 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 642 | CIFS_CRYPTO_KEY_SIZE); |
Noel Power | f291095 | 2015-05-27 09:22:10 +0100 | [diff] [blame] | 643 | } else if (pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC || |
| 644 | server->capabilities & CAP_EXTENDED_SECURITY) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 645 | server->negflavor = CIFS_NEGFLAVOR_EXTENDED; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 646 | rc = decode_ext_sec_blob(ses, pSMBr); |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 647 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 648 | rc = -EIO; /* no crypt key only if plain text pwd */ |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 649 | } else { |
| 650 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 651 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 652 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 653 | |
| 654 | signing_check: |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 655 | if (!rc) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 656 | rc = cifs_enable_signing(server, ses->sign); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 657 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 658 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 659 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 660 | cifs_dbg(FYI, "negprot rc %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | return rc; |
| 662 | } |
| 663 | |
| 664 | int |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 665 | CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | { |
| 667 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 670 | cifs_dbg(FYI, "In tree disconnect\n"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 671 | |
| 672 | /* BB: do we need to check this? These should never be NULL. */ |
| 673 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 674 | return -EIO; |
| 675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 677 | * No need to return error on this operation if tid invalidated and |
| 678 | * closed on server already e.g. due to tcp session crashing. Also, |
| 679 | * the tcon is no longer on the list, so no need to take lock before |
| 680 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 682 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 683 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 685 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 686 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 687 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 689 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 690 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 691 | cifs_small_buf_release(smb_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 693 | cifs_dbg(FYI, "Tree disconnect failed %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 695 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 696 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (rc == -EAGAIN) |
| 698 | rc = 0; |
| 699 | |
| 700 | return rc; |
| 701 | } |
| 702 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 703 | /* |
| 704 | * This is a no-op for now. We're not really interested in the reply, but |
| 705 | * rather in the fact that the server sent one and that server->lstrp |
| 706 | * gets updated. |
| 707 | * |
| 708 | * FIXME: maybe we should consider checking that the reply matches request? |
| 709 | */ |
| 710 | static void |
| 711 | cifs_echo_callback(struct mid_q_entry *mid) |
| 712 | { |
| 713 | struct TCP_Server_Info *server = mid->callback_data; |
| 714 | |
| 715 | DeleteMidQEntry(mid); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 716 | add_credits(server, 1, CIFS_ECHO_OP); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | int |
| 720 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 721 | { |
| 722 | ECHO_REQ *smb; |
| 723 | int rc = 0; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 724 | struct kvec iov[2]; |
| 725 | struct smb_rqst rqst = { .rq_iov = iov, |
| 726 | .rq_nvec = 2 }; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 727 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 728 | cifs_dbg(FYI, "In echo request\n"); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 729 | |
| 730 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 731 | if (rc) |
| 732 | return rc; |
| 733 | |
Steve French | 26c9cb6 | 2017-05-02 13:35:20 -0500 | [diff] [blame] | 734 | if (server->capabilities & CAP_UNICODE) |
| 735 | smb->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 736 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 737 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 738 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8f | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 739 | smb->hdr.WordCount = 1; |
| 740 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 741 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 742 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 743 | inc_rfc1001_len(smb, 3); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 744 | |
| 745 | iov[0].iov_len = 4; |
| 746 | iov[0].iov_base = smb; |
| 747 | iov[1].iov_len = get_rfc1002_length(smb); |
| 748 | iov[1].iov_base = (char *)smb + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 749 | |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 750 | rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, NULL, |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 751 | server, CIFS_ASYNC_OP | CIFS_ECHO_OP); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 752 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 753 | cifs_dbg(FYI, "Echo request failed: %d\n", rc); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 754 | |
| 755 | cifs_small_buf_release(smb); |
| 756 | |
| 757 | return rc; |
| 758 | } |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | int |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 761 | CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | LOGOFF_ANDX_REQ *pSMB; |
| 764 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 766 | cifs_dbg(FYI, "In SMBLogoff for session disconnect\n"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 767 | |
| 768 | /* |
| 769 | * BB: do we need to check validity of ses and server? They should |
| 770 | * always be valid since we have an active reference. If not, that |
| 771 | * should probably be a BUG() |
| 772 | */ |
| 773 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | return -EIO; |
| 775 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 776 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 777 | if (ses->need_reconnect) |
| 778 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 779 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 781 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 782 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | return rc; |
| 784 | } |
| 785 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 786 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 787 | |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 788 | if (ses->server->sign) |
| 789 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | pSMB->hdr.Uid = ses->Suid; |
| 792 | |
| 793 | pSMB->AndXCommand = 0xFF; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 794 | rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 795 | cifs_small_buf_release(pSMB); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 796 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 797 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 800 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | error */ |
| 802 | if (rc == -EAGAIN) |
| 803 | rc = 0; |
| 804 | return rc; |
| 805 | } |
| 806 | |
| 807 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 808 | CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, |
| 809 | const char *fileName, __u16 type, |
| 810 | const struct nls_table *nls_codepage, int remap) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 811 | { |
| 812 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 813 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 814 | struct unlink_psx_rq *pRqD; |
| 815 | int name_len; |
| 816 | int rc = 0; |
| 817 | int bytes_returned = 0; |
| 818 | __u16 params, param_offset, offset, byte_count; |
| 819 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 820 | cifs_dbg(FYI, "In POSIX delete\n"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 821 | PsxDelete: |
| 822 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 823 | (void **) &pSMBr); |
| 824 | if (rc) |
| 825 | return rc; |
| 826 | |
| 827 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 828 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 829 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 830 | PATH_MAX, nls_codepage, remap); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 831 | name_len++; /* trailing null */ |
| 832 | name_len *= 2; |
| 833 | } else { /* BB add path length overrun check */ |
| 834 | name_len = strnlen(fileName, PATH_MAX); |
| 835 | name_len++; /* trailing null */ |
| 836 | strncpy(pSMB->FileName, fileName, name_len); |
| 837 | } |
| 838 | |
| 839 | params = 6 + name_len; |
| 840 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 841 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 842 | pSMB->MaxSetupCount = 0; |
| 843 | pSMB->Reserved = 0; |
| 844 | pSMB->Flags = 0; |
| 845 | pSMB->Timeout = 0; |
| 846 | pSMB->Reserved2 = 0; |
| 847 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 848 | InformationLevel) - 4; |
| 849 | offset = param_offset + params; |
| 850 | |
| 851 | /* Setup pointer to Request Data (inode type) */ |
| 852 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 853 | pRqD->type = cpu_to_le16(type); |
| 854 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 855 | pSMB->DataOffset = cpu_to_le16(offset); |
| 856 | pSMB->SetupCount = 1; |
| 857 | pSMB->Reserved3 = 0; |
| 858 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 859 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 860 | |
| 861 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 862 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 863 | pSMB->ParameterCount = cpu_to_le16(params); |
| 864 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 865 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 866 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 867 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 868 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 869 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 870 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 871 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 872 | cifs_dbg(FYI, "Posix delete returned %d\n", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 873 | cifs_buf_release(pSMB); |
| 874 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 875 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 876 | |
| 877 | if (rc == -EAGAIN) |
| 878 | goto PsxDelete; |
| 879 | |
| 880 | return rc; |
| 881 | } |
| 882 | |
| 883 | int |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 884 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 885 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | { |
| 887 | DELETE_FILE_REQ *pSMB = NULL; |
| 888 | DELETE_FILE_RSP *pSMBr = NULL; |
| 889 | int rc = 0; |
| 890 | int bytes_returned; |
| 891 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 892 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
| 894 | DelFileRetry: |
| 895 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 896 | (void **) &pSMBr); |
| 897 | if (rc) |
| 898 | return rc; |
| 899 | |
| 900 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 901 | name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name, |
| 902 | PATH_MAX, cifs_sb->local_nls, |
| 903 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | name_len++; /* trailing null */ |
| 905 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 906 | } else { /* BB improve check for buffer overruns BB */ |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 907 | name_len = strnlen(name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | name_len++; /* trailing null */ |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 909 | strncpy(pSMB->fileName, name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | } |
| 911 | pSMB->SearchAttributes = |
| 912 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 913 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 914 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 916 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 917 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 918 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 919 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 920 | cifs_dbg(FYI, "Error in RMFile = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
| 922 | cifs_buf_release(pSMB); |
| 923 | if (rc == -EAGAIN) |
| 924 | goto DelFileRetry; |
| 925 | |
| 926 | return rc; |
| 927 | } |
| 928 | |
| 929 | int |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 930 | CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 931 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | { |
| 933 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 934 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 935 | int rc = 0; |
| 936 | int bytes_returned; |
| 937 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 938 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 940 | cifs_dbg(FYI, "In CIFSSMBRmDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | RmDirRetry: |
| 942 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 943 | (void **) &pSMBr); |
| 944 | if (rc) |
| 945 | return rc; |
| 946 | |
| 947 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 948 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
| 949 | PATH_MAX, cifs_sb->local_nls, |
| 950 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | name_len++; /* trailing null */ |
| 952 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 953 | } else { /* BB improve check for buffer overruns BB */ |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 954 | name_len = strnlen(name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | name_len++; /* trailing null */ |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 956 | strncpy(pSMB->DirName, name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 960 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 962 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 963 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 964 | cifs_stats_inc(&tcon->stats.cifs_stats.num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 965 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 966 | cifs_dbg(FYI, "Error in RMDir = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | |
| 968 | cifs_buf_release(pSMB); |
| 969 | if (rc == -EAGAIN) |
| 970 | goto RmDirRetry; |
| 971 | return rc; |
| 972 | } |
| 973 | |
| 974 | int |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 975 | CIFSSMBMkDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 976 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | { |
| 978 | int rc = 0; |
| 979 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 980 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 981 | int bytes_returned; |
| 982 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 983 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 985 | cifs_dbg(FYI, "In CIFSSMBMkDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | MkDirRetry: |
| 987 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 988 | (void **) &pSMBr); |
| 989 | if (rc) |
| 990 | return rc; |
| 991 | |
| 992 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 993 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 994 | PATH_MAX, cifs_sb->local_nls, |
| 995 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | name_len++; /* trailing null */ |
| 997 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 998 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | name_len = strnlen(name, PATH_MAX); |
| 1000 | name_len++; /* trailing null */ |
| 1001 | strncpy(pSMB->DirName, name, name_len); |
| 1002 | } |
| 1003 | |
| 1004 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1005 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1007 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1008 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1009 | cifs_stats_inc(&tcon->stats.cifs_stats.num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1010 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1011 | cifs_dbg(FYI, "Error in Mkdir = %d\n", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | cifs_buf_release(pSMB); |
| 1014 | if (rc == -EAGAIN) |
| 1015 | goto MkDirRetry; |
| 1016 | return rc; |
| 1017 | } |
| 1018 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1019 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1020 | CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, |
| 1021 | __u32 posix_flags, __u64 mode, __u16 *netfid, |
| 1022 | FILE_UNIX_BASIC_INFO *pRetData, __u32 *pOplock, |
| 1023 | const char *name, const struct nls_table *nls_codepage, |
| 1024 | int remap) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1025 | { |
| 1026 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1027 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1028 | int name_len; |
| 1029 | int rc = 0; |
| 1030 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1031 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1032 | OPEN_PSX_REQ *pdata; |
| 1033 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1034 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1035 | cifs_dbg(FYI, "In POSIX Create\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1036 | PsxCreat: |
| 1037 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1038 | (void **) &pSMBr); |
| 1039 | if (rc) |
| 1040 | return rc; |
| 1041 | |
| 1042 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1043 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1044 | cifsConvertToUTF16((__le16 *) pSMB->FileName, name, |
| 1045 | PATH_MAX, nls_codepage, remap); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1046 | name_len++; /* trailing null */ |
| 1047 | name_len *= 2; |
| 1048 | } else { /* BB improve the check for buffer overruns BB */ |
| 1049 | name_len = strnlen(name, PATH_MAX); |
| 1050 | name_len++; /* trailing null */ |
| 1051 | strncpy(pSMB->FileName, name, name_len); |
| 1052 | } |
| 1053 | |
| 1054 | params = 6 + name_len; |
| 1055 | count = sizeof(OPEN_PSX_REQ); |
| 1056 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1057 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1058 | pSMB->MaxSetupCount = 0; |
| 1059 | pSMB->Reserved = 0; |
| 1060 | pSMB->Flags = 0; |
| 1061 | pSMB->Timeout = 0; |
| 1062 | pSMB->Reserved2 = 0; |
| 1063 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1064 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1065 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1066 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1067 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1068 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1069 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1070 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1071 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1072 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1073 | pSMB->SetupCount = 1; |
| 1074 | pSMB->Reserved3 = 0; |
| 1075 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1076 | byte_count = 3 /* pad */ + params + count; |
| 1077 | |
| 1078 | pSMB->DataCount = cpu_to_le16(count); |
| 1079 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1080 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1081 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1082 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1083 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1084 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1085 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1086 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1087 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1088 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1089 | cifs_dbg(FYI, "Posix create returned %d\n", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1090 | goto psx_create_err; |
| 1091 | } |
| 1092 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1093 | cifs_dbg(FYI, "copying inode info\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1094 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1095 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1096 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1097 | rc = -EIO; /* bad smb */ |
| 1098 | goto psx_create_err; |
| 1099 | } |
| 1100 | |
| 1101 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1102 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1103 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1104 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1105 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1106 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1107 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1108 | /* Let caller know file was created so we can set the mode. */ |
| 1109 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1110 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1111 | *pOplock |= CIFS_CREATE_ACTION; |
| 1112 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1113 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1114 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1115 | cifs_dbg(NOISY, "unknown type\n"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1116 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1117 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1118 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1119 | cifs_dbg(VFS, "Open response data too small\n"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1120 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1121 | goto psx_create_err; |
| 1122 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1123 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1124 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1125 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1126 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1127 | |
| 1128 | psx_create_err: |
| 1129 | cifs_buf_release(pSMB); |
| 1130 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1131 | if (posix_flags & SMB_O_DIRECTORY) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1132 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixmkdirs); |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1133 | else |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1134 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1135 | |
| 1136 | if (rc == -EAGAIN) |
| 1137 | goto PsxCreat; |
| 1138 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1139 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1142 | static __u16 convert_disposition(int disposition) |
| 1143 | { |
| 1144 | __u16 ofun = 0; |
| 1145 | |
| 1146 | switch (disposition) { |
| 1147 | case FILE_SUPERSEDE: |
| 1148 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1149 | break; |
| 1150 | case FILE_OPEN: |
| 1151 | ofun = SMBOPEN_OAPPEND; |
| 1152 | break; |
| 1153 | case FILE_CREATE: |
| 1154 | ofun = SMBOPEN_OCREATE; |
| 1155 | break; |
| 1156 | case FILE_OPEN_IF: |
| 1157 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1158 | break; |
| 1159 | case FILE_OVERWRITE: |
| 1160 | ofun = SMBOPEN_OTRUNC; |
| 1161 | break; |
| 1162 | case FILE_OVERWRITE_IF: |
| 1163 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1164 | break; |
| 1165 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1166 | cifs_dbg(FYI, "unknown disposition %d\n", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1167 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1168 | } |
| 1169 | return ofun; |
| 1170 | } |
| 1171 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1172 | static int |
| 1173 | access_flags_to_smbopen_mode(const int access_flags) |
| 1174 | { |
| 1175 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1176 | |
| 1177 | if (masked_flags == GENERIC_READ) |
| 1178 | return SMBOPEN_READ; |
| 1179 | else if (masked_flags == GENERIC_WRITE) |
| 1180 | return SMBOPEN_WRITE; |
| 1181 | |
| 1182 | /* just go for read/write */ |
| 1183 | return SMBOPEN_READWRITE; |
| 1184 | } |
| 1185 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1186 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1187 | SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1188 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1189 | const int access_flags, const int create_options, __u16 *netfid, |
| 1190 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1191 | const struct nls_table *nls_codepage, int remap) |
| 1192 | { |
| 1193 | int rc = -EACCES; |
| 1194 | OPENX_REQ *pSMB = NULL; |
| 1195 | OPENX_RSP *pSMBr = NULL; |
| 1196 | int bytes_returned; |
| 1197 | int name_len; |
| 1198 | __u16 count; |
| 1199 | |
| 1200 | OldOpenRetry: |
| 1201 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1202 | (void **) &pSMBr); |
| 1203 | if (rc) |
| 1204 | return rc; |
| 1205 | |
| 1206 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1207 | |
| 1208 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1209 | count = 1; /* account for one byte pad to word boundary */ |
| 1210 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1211 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1212 | fileName, PATH_MAX, nls_codepage, remap); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1213 | name_len++; /* trailing null */ |
| 1214 | name_len *= 2; |
| 1215 | } else { /* BB improve check for buffer overruns BB */ |
| 1216 | count = 0; /* no pad */ |
| 1217 | name_len = strnlen(fileName, PATH_MAX); |
| 1218 | name_len++; /* trailing null */ |
| 1219 | strncpy(pSMB->fileName, fileName, name_len); |
| 1220 | } |
| 1221 | if (*pOplock & REQ_OPLOCK) |
| 1222 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1223 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1224 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1225 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1226 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1227 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1228 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1229 | /* set file as system file if special file such |
| 1230 | as fifo and server expecting SFU style and |
| 1231 | no Unix extensions */ |
| 1232 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1233 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1234 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1235 | else /* BB FIXME BB */ |
| 1236 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1237 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1238 | if (create_options & CREATE_OPTION_READONLY) |
| 1239 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1240 | |
| 1241 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1242 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1243 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1244 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1245 | |
| 1246 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1247 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1248 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1249 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1250 | |
| 1251 | pSMB->ByteCount = cpu_to_le16(count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1252 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1253 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1254 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1255 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1256 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1257 | } else { |
| 1258 | /* BB verify if wct == 15 */ |
| 1259 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1260 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1261 | |
| 1262 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1263 | /* Let caller know file was created so we can set the mode. */ |
| 1264 | /* Do we care about the CreateAction in any other cases? */ |
| 1265 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1266 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1267 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1268 | /* BB FIXME END */ |
| 1269 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1270 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1271 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1272 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1273 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1274 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1275 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1276 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1277 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1278 | pfile_info->AllocationSize = |
| 1279 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1280 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1281 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1282 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | cifs_buf_release(pSMB); |
| 1287 | if (rc == -EAGAIN) |
| 1288 | goto OldOpenRetry; |
| 1289 | return rc; |
| 1290 | } |
| 1291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | int |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1293 | CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock, |
| 1294 | FILE_ALL_INFO *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | { |
| 1296 | int rc = -EACCES; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1297 | OPEN_REQ *req = NULL; |
| 1298 | OPEN_RSP *rsp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | int bytes_returned; |
| 1300 | int name_len; |
| 1301 | __u16 count; |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1302 | struct cifs_sb_info *cifs_sb = oparms->cifs_sb; |
| 1303 | struct cifs_tcon *tcon = oparms->tcon; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1304 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1305 | const struct nls_table *nls = cifs_sb->local_nls; |
| 1306 | int create_options = oparms->create_options; |
| 1307 | int desired_access = oparms->desired_access; |
| 1308 | int disposition = oparms->disposition; |
| 1309 | const char *path = oparms->path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
| 1311 | openRetry: |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1312 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **)&req, |
| 1313 | (void **)&rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | if (rc) |
| 1315 | return rc; |
| 1316 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1317 | /* no commands go after this */ |
| 1318 | req->AndXCommand = 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1320 | if (req->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1321 | /* account for one byte pad to word boundary */ |
| 1322 | count = 1; |
| 1323 | name_len = cifsConvertToUTF16((__le16 *)(req->fileName + 1), |
| 1324 | path, PATH_MAX, nls, remap); |
| 1325 | /* trailing null */ |
| 1326 | name_len++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | name_len *= 2; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1328 | req->NameLength = cpu_to_le16(name_len); |
| 1329 | } else { |
| 1330 | /* BB improve check for buffer overruns BB */ |
| 1331 | /* no pad */ |
| 1332 | count = 0; |
| 1333 | name_len = strnlen(path, PATH_MAX); |
| 1334 | /* trailing null */ |
| 1335 | name_len++; |
| 1336 | req->NameLength = cpu_to_le16(name_len); |
| 1337 | strncpy(req->fileName, path, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | } |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1339 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1340 | if (*oplock & REQ_OPLOCK) |
| 1341 | req->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
| 1342 | else if (*oplock & REQ_BATCHOPLOCK) |
| 1343 | req->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
| 1344 | |
| 1345 | req->DesiredAccess = cpu_to_le32(desired_access); |
| 1346 | req->AllocationSize = 0; |
| 1347 | |
| 1348 | /* |
| 1349 | * Set file as system file if special file such as fifo and server |
| 1350 | * expecting SFU style and no Unix extensions. |
| 1351 | */ |
| 1352 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1353 | req->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1354 | else |
| 1355 | req->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
| 1356 | |
| 1357 | /* |
| 1358 | * XP does not handle ATTR_POSIX_SEMANTICS but it helps speed up case |
| 1359 | * sensitive checks for other servers such as Samba. |
| 1360 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | if (tcon->ses->capabilities & CAP_UNIX) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1362 | req->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1364 | if (create_options & CREATE_OPTION_READONLY) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1365 | req->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1366 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1367 | req->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1368 | req->CreateDisposition = cpu_to_le32(disposition); |
| 1369 | req->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
| 1370 | |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1371 | /* BB Expirement with various impersonation levels and verify */ |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1372 | req->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
| 1373 | req->SecurityFlags = SECURITY_CONTEXT_TRACKING|SECURITY_EFFECTIVE_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | |
| 1375 | count += name_len; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1376 | inc_rfc1001_len(req, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1378 | req->ByteCount = cpu_to_le16(count); |
| 1379 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *)req, |
| 1380 | (struct smb_hdr *)rsp, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1381 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1383 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1384 | cifs_buf_release(req); |
| 1385 | if (rc == -EAGAIN) |
| 1386 | goto openRetry; |
| 1387 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1389 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1390 | /* 1 byte no need to le_to_cpu */ |
| 1391 | *oplock = rsp->OplockLevel; |
| 1392 | /* cifs fid stays in le */ |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1393 | oparms->fid->netfid = rsp->Fid; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1394 | |
| 1395 | /* Let caller know file was created so we can set the mode. */ |
| 1396 | /* Do we care about the CreateAction in any other cases? */ |
| 1397 | if (cpu_to_le32(FILE_CREATE) == rsp->CreateAction) |
| 1398 | *oplock |= CIFS_CREATE_ACTION; |
| 1399 | |
| 1400 | if (buf) { |
| 1401 | /* copy from CreationTime to Attributes */ |
| 1402 | memcpy((char *)buf, (char *)&rsp->CreationTime, 36); |
| 1403 | /* the file_info buf is endian converted by caller */ |
| 1404 | buf->AllocationSize = rsp->AllocationSize; |
| 1405 | buf->EndOfFile = rsp->EndOfFile; |
| 1406 | buf->NumberOfLinks = cpu_to_le32(1); |
| 1407 | buf->DeletePending = 0; |
| 1408 | } |
| 1409 | |
| 1410 | cifs_buf_release(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | return rc; |
| 1412 | } |
| 1413 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1414 | /* |
| 1415 | * Discard any remaining data in the current SMB. To do this, we borrow the |
| 1416 | * current bigbuf. |
| 1417 | */ |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 1418 | int |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1419 | cifs_discard_remaining_data(struct TCP_Server_Info *server) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1420 | { |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1421 | unsigned int rfclen = get_rfc1002_length(server->smallbuf); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1422 | int remaining = rfclen + 4 - server->total_read; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1423 | |
| 1424 | while (remaining > 0) { |
| 1425 | int length; |
| 1426 | |
| 1427 | length = cifs_read_from_socket(server, server->bigbuf, |
| 1428 | min_t(unsigned int, remaining, |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1429 | CIFSMaxBufSize + MAX_HEADER_SIZE(server))); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1430 | if (length < 0) |
| 1431 | return length; |
| 1432 | server->total_read += length; |
| 1433 | remaining -= length; |
| 1434 | } |
| 1435 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1436 | return 0; |
| 1437 | } |
| 1438 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1439 | static int |
| 1440 | cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1441 | { |
| 1442 | int length; |
| 1443 | struct cifs_readdata *rdata = mid->callback_data; |
| 1444 | |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1445 | length = cifs_discard_remaining_data(server); |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1446 | dequeue_mid(mid, rdata->result); |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1447 | mid->resp_buf = server->smallbuf; |
| 1448 | server->smallbuf = NULL; |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1449 | return length; |
| 1450 | } |
| 1451 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1452 | int |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1453 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1454 | { |
| 1455 | int length, len; |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1456 | unsigned int data_offset, data_len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1457 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1458 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 1459 | unsigned int buflen = get_rfc1002_length(buf) + |
| 1460 | server->vals->header_preamble_size; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1461 | bool use_rdma_mr = false; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1462 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1463 | cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n", |
| 1464 | __func__, mid->mid, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1465 | |
| 1466 | /* |
| 1467 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1468 | * can if there's not enough data. At this point, we've read down to |
| 1469 | * the Mid. |
| 1470 | */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1471 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1472 | HEADER_SIZE(server) + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1473 | |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1474 | length = cifs_read_from_socket(server, |
| 1475 | buf + HEADER_SIZE(server) - 1, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1476 | if (length < 0) |
| 1477 | return length; |
| 1478 | server->total_read += length; |
| 1479 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1480 | if (server->ops->is_session_expired && |
| 1481 | server->ops->is_session_expired(buf)) { |
| 1482 | cifs_reconnect(server); |
| 1483 | wake_up(&server->response_q); |
| 1484 | return -1; |
| 1485 | } |
| 1486 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1487 | if (server->ops->is_status_pending && |
| 1488 | server->ops->is_status_pending(buf, server, 0)) { |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1489 | cifs_discard_remaining_data(server); |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1490 | return -1; |
| 1491 | } |
| 1492 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1493 | /* Was the SMB read successful? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1494 | rdata->result = server->ops->map_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1495 | if (rdata->result != 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1496 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 1497 | __func__, rdata->result); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1498 | return cifs_readv_discard(server, mid); |
| 1499 | } |
| 1500 | |
| 1501 | /* 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] | 1502 | if (server->total_read < server->vals->read_rsp_size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1503 | cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n", |
| 1504 | __func__, server->total_read, |
| 1505 | server->vals->read_rsp_size); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1506 | rdata->result = -EIO; |
| 1507 | return cifs_readv_discard(server, mid); |
| 1508 | } |
| 1509 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 1510 | data_offset = server->ops->read_data_offset(buf) + |
| 1511 | server->vals->header_preamble_size; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1512 | if (data_offset < server->total_read) { |
| 1513 | /* |
| 1514 | * win2k8 sometimes sends an offset of 0 when the read |
| 1515 | * is beyond the EOF. Treat it as if the data starts just after |
| 1516 | * the header. |
| 1517 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1518 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 1519 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1520 | data_offset = server->total_read; |
| 1521 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1522 | /* data_offset is beyond the end of smallbuf */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1523 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 1524 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1525 | rdata->result = -EIO; |
| 1526 | return cifs_readv_discard(server, mid); |
| 1527 | } |
| 1528 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1529 | cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n", |
| 1530 | __func__, server->total_read, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1531 | |
| 1532 | len = data_offset - server->total_read; |
| 1533 | if (len > 0) { |
| 1534 | /* read any junk before data into the rest of smallbuf */ |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1535 | length = cifs_read_from_socket(server, |
| 1536 | buf + server->total_read, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1537 | if (length < 0) |
| 1538 | return length; |
| 1539 | server->total_read += length; |
| 1540 | } |
| 1541 | |
| 1542 | /* set up first iov for signature check */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1543 | rdata->iov[0].iov_base = buf; |
| 1544 | rdata->iov[0].iov_len = 4; |
| 1545 | rdata->iov[1].iov_base = buf + 4; |
| 1546 | rdata->iov[1].iov_len = server->total_read - 4; |
| 1547 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%u\n", |
| 1548 | rdata->iov[0].iov_base, server->total_read); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1549 | |
| 1550 | /* how much data is in the response? */ |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1551 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 1552 | use_rdma_mr = rdata->mr; |
| 1553 | #endif |
| 1554 | data_len = server->ops->read_data_length(buf, use_rdma_mr); |
| 1555 | if (!use_rdma_mr && (data_offset + data_len > buflen)) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1556 | /* data_len is corrupt -- discard frame */ |
| 1557 | rdata->result = -EIO; |
| 1558 | return cifs_readv_discard(server, mid); |
| 1559 | } |
| 1560 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1561 | length = rdata->read_into_pages(server, rdata, data_len); |
| 1562 | if (length < 0) |
| 1563 | return length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1564 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1565 | server->total_read += length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1566 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1567 | cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n", |
| 1568 | server->total_read, buflen, data_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1569 | |
| 1570 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1571 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1572 | return cifs_readv_discard(server, mid); |
| 1573 | |
| 1574 | dequeue_mid(mid, false); |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1575 | mid->resp_buf = server->smallbuf; |
| 1576 | server->smallbuf = NULL; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1577 | return length; |
| 1578 | } |
| 1579 | |
| 1580 | static void |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1581 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1582 | { |
| 1583 | struct cifs_readdata *rdata = mid->callback_data; |
| 1584 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1585 | struct TCP_Server_Info *server = tcon->ses->server; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1586 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 1587 | .rq_nvec = 2, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1588 | .rq_pages = rdata->pages, |
| 1589 | .rq_npages = rdata->nr_pages, |
| 1590 | .rq_pagesz = rdata->pagesz, |
| 1591 | .rq_tailsz = rdata->tailsz }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1592 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1593 | cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", |
| 1594 | __func__, mid->mid, mid->mid_state, rdata->result, |
| 1595 | rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1596 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1597 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1598 | case MID_RESPONSE_RECEIVED: |
| 1599 | /* result already set, check signature */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 1600 | if (server->sign) { |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1601 | int rc = 0; |
| 1602 | |
Jeff Layton | bf5ea0e | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1603 | rc = cifs_verify_signature(&rqst, server, |
Jeff Layton | 0124cc4 | 2013-04-03 11:55:03 -0400 | [diff] [blame] | 1604 | mid->sequence_number); |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1605 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1606 | cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
| 1607 | rc); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1608 | } |
| 1609 | /* FIXME: should this be counted toward the initiating task? */ |
Pavel Shilovsky | 34a54d6 | 2014-07-10 10:03:29 +0400 | [diff] [blame] | 1610 | task_io_account_read(rdata->got_bytes); |
| 1611 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1612 | break; |
| 1613 | case MID_REQUEST_SUBMITTED: |
| 1614 | case MID_RETRY_NEEDED: |
| 1615 | rdata->result = -EAGAIN; |
Pavel Shilovsky | d913ed1 | 2014-07-10 11:31:48 +0400 | [diff] [blame] | 1616 | if (server->sign && rdata->got_bytes) |
| 1617 | /* reset bytes number since we can not check a sign */ |
| 1618 | rdata->got_bytes = 0; |
| 1619 | /* FIXME: should this be counted toward the initiating task? */ |
| 1620 | task_io_account_read(rdata->got_bytes); |
| 1621 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1622 | break; |
| 1623 | default: |
| 1624 | rdata->result = -EIO; |
| 1625 | } |
| 1626 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1627 | queue_work(cifsiod_wq, &rdata->work); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1628 | DeleteMidQEntry(mid); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1629 | add_credits(server, 1, 0); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1633 | int |
| 1634 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1635 | { |
| 1636 | int rc; |
| 1637 | READ_REQ *smb = NULL; |
| 1638 | int wct; |
| 1639 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1640 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 1641 | .rq_nvec = 2 }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1642 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1643 | cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n", |
| 1644 | __func__, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1645 | |
| 1646 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1647 | wct = 12; |
| 1648 | else { |
| 1649 | wct = 10; /* old style read */ |
| 1650 | if ((rdata->offset >> 32) > 0) { |
| 1651 | /* can not handle this big offset for old */ |
| 1652 | return -EIO; |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1657 | if (rc) |
| 1658 | return rc; |
| 1659 | |
| 1660 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1661 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1662 | |
| 1663 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1664 | smb->Fid = rdata->cfile->fid.netfid; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1665 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1666 | if (wct == 12) |
| 1667 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1668 | smb->Remaining = 0; |
| 1669 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1670 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1671 | if (wct == 12) |
| 1672 | smb->ByteCount = 0; |
| 1673 | else { |
| 1674 | /* old style read */ |
| 1675 | struct smb_com_readx_req *smbr = |
| 1676 | (struct smb_com_readx_req *)smb; |
| 1677 | smbr->ByteCount = 0; |
| 1678 | } |
| 1679 | |
| 1680 | /* 4 for RFC1001 length + 1 for BCC */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1681 | rdata->iov[0].iov_base = smb; |
| 1682 | rdata->iov[0].iov_len = 4; |
| 1683 | rdata->iov[1].iov_base = (char *)smb + 4; |
| 1684 | rdata->iov[1].iov_len = get_rfc1002_length(smb); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1685 | |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1686 | kref_get(&rdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 1687 | rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 1688 | cifs_readv_callback, NULL, rdata, 0); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1689 | |
| 1690 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1691 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1692 | else |
| 1693 | kref_put(&rdata->refcount, cifs_readdata_release); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1694 | |
| 1695 | cifs_small_buf_release(smb); |
| 1696 | return rc; |
| 1697 | } |
| 1698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1700 | CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms, |
| 1701 | unsigned int *nbytes, char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | { |
| 1703 | int rc = -EACCES; |
| 1704 | READ_REQ *pSMB = NULL; |
| 1705 | READ_RSP *pSMBr = NULL; |
| 1706 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1707 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1708 | int resp_buf_type = 0; |
| 1709 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1710 | struct kvec rsp_iov; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1711 | __u32 pid = io_parms->pid; |
| 1712 | __u16 netfid = io_parms->netfid; |
| 1713 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1714 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1715 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1717 | cifs_dbg(FYI, "Reading %d bytes on fid %d\n", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1718 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1719 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1720 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1721 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1722 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1723 | /* can not handle this big offset for old */ |
| 1724 | return -EIO; |
| 1725 | } |
| 1726 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | |
| 1728 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1729 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | if (rc) |
| 1731 | return rc; |
| 1732 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1733 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1734 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | /* tcon and ses pointer are checked in smb_init */ |
| 1737 | if (tcon->ses->server == NULL) |
| 1738 | return -ECONNABORTED; |
| 1739 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1740 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1742 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1743 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1744 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | pSMB->Remaining = 0; |
| 1747 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1748 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1749 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1750 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1751 | else { |
| 1752 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1753 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1754 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1755 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1756 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1757 | |
| 1758 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1759 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1760 | rc = SendReceive2(xid, tcon->ses, iov, 1, &resp_buf_type, |
| 1761 | CIFS_LOG_ERROR, &rsp_iov); |
| 1762 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1763 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1764 | pSMBr = (READ_RSP *)rsp_iov.iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1766 | cifs_dbg(VFS, "Send error in read = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | } else { |
| 1768 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1769 | data_length = data_length << 16; |
| 1770 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1771 | *nbytes = data_length; |
| 1772 | |
| 1773 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1774 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | || (data_length > count)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1776 | cifs_dbg(FYI, "bad length %d for count %d\n", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1777 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | rc = -EIO; |
| 1779 | *nbytes = 0; |
| 1780 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1781 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1782 | le16_to_cpu(pSMBr->DataOffset); |
| 1783 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1784 | cifs_dbg(VFS, "Faulting on read rc = %d\n",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1785 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1786 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1787 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1788 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | } |
| 1790 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1792 | if (*buf) { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1793 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1794 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1795 | /* return buffer to caller to free */ |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1796 | *buf = rsp_iov.iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1797 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1798 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1799 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1800 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1801 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1802 | |
| 1803 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | since file handle passed in no longer valid */ |
| 1805 | return rc; |
| 1806 | } |
| 1807 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1810 | CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1811 | unsigned int *nbytes, const char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | { |
| 1813 | int rc = -EACCES; |
| 1814 | WRITE_REQ *pSMB = NULL; |
| 1815 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1816 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | __u32 bytes_sent; |
| 1818 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1819 | __u32 pid = io_parms->pid; |
| 1820 | __u16 netfid = io_parms->netfid; |
| 1821 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1822 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1823 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1825 | *nbytes = 0; |
| 1826 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1827 | /* cifs_dbg(FYI, "write at %lld %d bytes\n", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1828 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1829 | return -ECONNABORTED; |
| 1830 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1831 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1832 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1833 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1834 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1835 | if ((offset >> 32) > 0) { |
| 1836 | /* can not handle big offset for old srv */ |
| 1837 | return -EIO; |
| 1838 | } |
| 1839 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1840 | |
| 1841 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | (void **) &pSMBr); |
| 1843 | if (rc) |
| 1844 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1845 | |
| 1846 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1847 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | /* tcon and ses pointer are checked in smb_init */ |
| 1850 | if (tcon->ses->server == NULL) |
| 1851 | return -ECONNABORTED; |
| 1852 | |
| 1853 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1854 | pSMB->Fid = netfid; |
| 1855 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1856 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1857 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | pSMB->Reserved = 0xFFFFFFFF; |
| 1860 | pSMB->WriteMode = 0; |
| 1861 | pSMB->Remaining = 0; |
| 1862 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1863 | /* 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] | 1864 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1865 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1866 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1867 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1869 | } else { |
| 1870 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1871 | & ~0xFF; |
| 1872 | } |
| 1873 | |
| 1874 | if (bytes_sent > count) |
| 1875 | bytes_sent = count; |
| 1876 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1877 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1878 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1879 | memcpy(pSMB->Data, buf, bytes_sent); |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1880 | else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | /* No buffer */ |
| 1882 | cifs_buf_release(pSMB); |
| 1883 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1884 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1885 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1886 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1887 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1888 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1891 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1892 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1893 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1894 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1895 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1896 | else { /* old style write has byte count 4 bytes earlier |
| 1897 | so 4 bytes pad */ |
| 1898 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1899 | (struct smb_com_writex_req *)pSMB; |
| 1900 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1901 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | |
| 1903 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1904 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1905 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1907 | cifs_dbg(FYI, "Send error in write = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | } else { |
| 1909 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1910 | *nbytes = (*nbytes) << 16; |
| 1911 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1912 | |
| 1913 | /* |
| 1914 | * Mask off high 16 bits when bytes written as returned by the |
| 1915 | * server is greater than bytes requested by the client. Some |
| 1916 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1917 | */ |
| 1918 | if (*nbytes > count) |
| 1919 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | cifs_buf_release(pSMB); |
| 1923 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1924 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | since file handle passed in no longer valid */ |
| 1926 | |
| 1927 | return rc; |
| 1928 | } |
| 1929 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1930 | void |
| 1931 | cifs_writedata_release(struct kref *refcount) |
| 1932 | { |
| 1933 | struct cifs_writedata *wdata = container_of(refcount, |
| 1934 | struct cifs_writedata, refcount); |
Long Li | db223a5 | 2017-11-22 17:38:45 -0700 | [diff] [blame] | 1935 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 1936 | if (wdata->mr) { |
| 1937 | smbd_deregister_mr(wdata->mr); |
| 1938 | wdata->mr = NULL; |
| 1939 | } |
| 1940 | #endif |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1941 | |
| 1942 | if (wdata->cfile) |
| 1943 | cifsFileInfo_put(wdata->cfile); |
| 1944 | |
| 1945 | kfree(wdata); |
| 1946 | } |
| 1947 | |
| 1948 | /* |
| 1949 | * Write failed with a retryable error. Resend the write request. It's also |
| 1950 | * possible that the page was redirtied so re-clean the page. |
| 1951 | */ |
| 1952 | static void |
| 1953 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 1954 | { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1955 | int i, rc = 0; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1956 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Pavel Shilovsky | c9de5c8 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1957 | struct TCP_Server_Info *server; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1958 | unsigned int rest_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1959 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1960 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
| 1961 | i = 0; |
| 1962 | rest_len = wdata->bytes; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1963 | do { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1964 | struct cifs_writedata *wdata2; |
| 1965 | unsigned int j, nr_pages, wsize, tailsz, cur_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1966 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1967 | wsize = server->ops->wp_retry_size(inode); |
| 1968 | if (wsize < rest_len) { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1969 | nr_pages = wsize / PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1970 | if (!nr_pages) { |
| 1971 | rc = -ENOTSUPP; |
| 1972 | break; |
| 1973 | } |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1974 | cur_len = nr_pages * PAGE_SIZE; |
| 1975 | tailsz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1976 | } else { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1977 | nr_pages = DIV_ROUND_UP(rest_len, PAGE_SIZE); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1978 | cur_len = rest_len; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1979 | tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE; |
Ouyang Maochun | c51bb0e | 2013-02-18 09:54:52 -0600 | [diff] [blame] | 1980 | } |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1981 | |
| 1982 | wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete); |
| 1983 | if (!wdata2) { |
| 1984 | rc = -ENOMEM; |
| 1985 | break; |
| 1986 | } |
| 1987 | |
| 1988 | for (j = 0; j < nr_pages; j++) { |
| 1989 | wdata2->pages[j] = wdata->pages[i + j]; |
| 1990 | lock_page(wdata2->pages[j]); |
| 1991 | clear_page_dirty_for_io(wdata2->pages[j]); |
| 1992 | } |
| 1993 | |
| 1994 | wdata2->sync_mode = wdata->sync_mode; |
| 1995 | wdata2->nr_pages = nr_pages; |
| 1996 | wdata2->offset = page_offset(wdata2->pages[0]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1997 | wdata2->pagesz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1998 | wdata2->tailsz = tailsz; |
| 1999 | wdata2->bytes = cur_len; |
| 2000 | |
| 2001 | wdata2->cfile = find_writable_file(CIFS_I(inode), false); |
| 2002 | if (!wdata2->cfile) { |
| 2003 | cifs_dbg(VFS, "No writable handles for inode\n"); |
| 2004 | rc = -EBADF; |
| 2005 | break; |
| 2006 | } |
| 2007 | wdata2->pid = wdata2->cfile->pid; |
| 2008 | rc = server->ops->async_writev(wdata2, cifs_writedata_release); |
| 2009 | |
| 2010 | for (j = 0; j < nr_pages; j++) { |
| 2011 | unlock_page(wdata2->pages[j]); |
| 2012 | if (rc != 0 && rc != -EAGAIN) { |
| 2013 | SetPageError(wdata2->pages[j]); |
| 2014 | end_page_writeback(wdata2->pages[j]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2015 | put_page(wdata2->pages[j]); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | if (rc) { |
| 2020 | kref_put(&wdata2->refcount, cifs_writedata_release); |
| 2021 | if (rc == -EAGAIN) |
| 2022 | continue; |
| 2023 | break; |
| 2024 | } |
| 2025 | |
| 2026 | rest_len -= cur_len; |
| 2027 | i += nr_pages; |
| 2028 | } while (i < wdata->nr_pages); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2029 | |
| 2030 | mapping_set_error(inode->i_mapping, rc); |
| 2031 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2032 | } |
| 2033 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2034 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2035 | cifs_writev_complete(struct work_struct *work) |
| 2036 | { |
| 2037 | struct cifs_writedata *wdata = container_of(work, |
| 2038 | struct cifs_writedata, work); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2039 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2040 | int i = 0; |
| 2041 | |
| 2042 | if (wdata->result == 0) { |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2043 | spin_lock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2044 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2045 | spin_unlock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2046 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 2047 | wdata->bytes); |
| 2048 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 2049 | return cifs_writev_requeue(wdata); |
| 2050 | |
| 2051 | for (i = 0; i < wdata->nr_pages; i++) { |
| 2052 | struct page *page = wdata->pages[i]; |
| 2053 | if (wdata->result == -EAGAIN) |
| 2054 | __set_page_dirty_nobuffers(page); |
| 2055 | else if (wdata->result < 0) |
| 2056 | SetPageError(page); |
| 2057 | end_page_writeback(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2058 | put_page(page); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2059 | } |
| 2060 | if (wdata->result != -EAGAIN) |
| 2061 | mapping_set_error(inode->i_mapping, wdata->result); |
| 2062 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2063 | } |
| 2064 | |
| 2065 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2066 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2067 | { |
| 2068 | struct cifs_writedata *wdata; |
| 2069 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2070 | /* writedata + number of page pointers */ |
| 2071 | wdata = kzalloc(sizeof(*wdata) + |
Jeff Layton | 26c8f0d | 2014-02-07 11:04:04 -0500 | [diff] [blame] | 2072 | sizeof(struct page *) * nr_pages, GFP_NOFS); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2073 | if (wdata != NULL) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2074 | kref_init(&wdata->refcount); |
Jeff Layton | da82f7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2075 | INIT_LIST_HEAD(&wdata->list); |
| 2076 | init_completion(&wdata->done); |
| 2077 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2078 | } |
| 2079 | return wdata; |
| 2080 | } |
| 2081 | |
| 2082 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2083 | * 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] | 2084 | * workqueue completion task. |
| 2085 | */ |
| 2086 | static void |
| 2087 | cifs_writev_callback(struct mid_q_entry *mid) |
| 2088 | { |
| 2089 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2090 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2091 | unsigned int written; |
| 2092 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
| 2093 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2094 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2095 | case MID_RESPONSE_RECEIVED: |
| 2096 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 2097 | if (wdata->result != 0) |
| 2098 | break; |
| 2099 | |
| 2100 | written = le16_to_cpu(smb->CountHigh); |
| 2101 | written <<= 16; |
| 2102 | written += le16_to_cpu(smb->Count); |
| 2103 | /* |
| 2104 | * Mask off high 16 bits when bytes written as returned |
| 2105 | * by the server is greater than bytes requested by the |
| 2106 | * client. OS/2 servers are known to set incorrect |
| 2107 | * CountHigh values. |
| 2108 | */ |
| 2109 | if (written > wdata->bytes) |
| 2110 | written &= 0xFFFF; |
| 2111 | |
| 2112 | if (written < wdata->bytes) |
| 2113 | wdata->result = -ENOSPC; |
| 2114 | else |
| 2115 | wdata->bytes = written; |
| 2116 | break; |
| 2117 | case MID_REQUEST_SUBMITTED: |
| 2118 | case MID_RETRY_NEEDED: |
| 2119 | wdata->result = -EAGAIN; |
| 2120 | break; |
| 2121 | default: |
| 2122 | wdata->result = -EIO; |
| 2123 | break; |
| 2124 | } |
| 2125 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2126 | queue_work(cifsiod_wq, &wdata->work); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2127 | DeleteMidQEntry(mid); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2128 | add_credits(tcon->ses->server, 1, 0); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2132 | int |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2133 | cifs_async_writev(struct cifs_writedata *wdata, |
| 2134 | void (*release)(struct kref *kref)) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2135 | { |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2136 | int rc = -EACCES; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2137 | WRITE_REQ *smb = NULL; |
| 2138 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2139 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2140 | struct kvec iov[2]; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2141 | struct smb_rqst rqst = { }; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2142 | |
| 2143 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2144 | wct = 14; |
| 2145 | } else { |
| 2146 | wct = 12; |
| 2147 | if (wdata->offset >> 32 > 0) { |
| 2148 | /* can not handle big offset for old srv */ |
| 2149 | return -EIO; |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2154 | if (rc) |
| 2155 | goto async_writev_out; |
| 2156 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2157 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2158 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2159 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2160 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2161 | smb->Fid = wdata->cfile->fid.netfid; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2162 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2163 | if (wct == 14) |
| 2164 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2165 | smb->Reserved = 0xFFFFFFFF; |
| 2166 | smb->WriteMode = 0; |
| 2167 | smb->Remaining = 0; |
| 2168 | |
| 2169 | smb->DataOffset = |
| 2170 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2171 | |
| 2172 | /* 4 for RFC1001 length + 1 for BCC */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2173 | iov[0].iov_len = 4; |
| 2174 | iov[0].iov_base = smb; |
| 2175 | iov[1].iov_len = get_rfc1002_length(smb) + 1; |
| 2176 | iov[1].iov_base = (char *)smb + 4; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2177 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2178 | rqst.rq_iov = iov; |
| 2179 | rqst.rq_nvec = 2; |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2180 | rqst.rq_pages = wdata->pages; |
| 2181 | rqst.rq_npages = wdata->nr_pages; |
| 2182 | rqst.rq_pagesz = wdata->pagesz; |
| 2183 | rqst.rq_tailsz = wdata->tailsz; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2184 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2185 | cifs_dbg(FYI, "async write at %llu %u bytes\n", |
| 2186 | wdata->offset, wdata->bytes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2187 | |
| 2188 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2189 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2190 | |
| 2191 | if (wct == 14) { |
| 2192 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2193 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2194 | } else { |
| 2195 | /* wct == 12 */ |
| 2196 | struct smb_com_writex_req *smbw = |
| 2197 | (struct smb_com_writex_req *)smb; |
| 2198 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2199 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2200 | iov[1].iov_len += 4; /* pad bigger by four bytes */ |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | kref_get(&wdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2204 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 2205 | cifs_writev_callback, NULL, wdata, 0); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2206 | |
| 2207 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2208 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2209 | else |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2210 | kref_put(&wdata->refcount, release); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2211 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2212 | async_writev_out: |
| 2213 | cifs_small_buf_release(smb); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2214 | return rc; |
| 2215 | } |
| 2216 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2217 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2218 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2219 | unsigned int *nbytes, struct kvec *iov, int n_vec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | { |
| 2221 | int rc = -EACCES; |
| 2222 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2223 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2224 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2225 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2226 | __u32 pid = io_parms->pid; |
| 2227 | __u16 netfid = io_parms->netfid; |
| 2228 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2229 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2230 | unsigned int count = io_parms->length; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2231 | struct kvec rsp_iov; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2233 | *nbytes = 0; |
| 2234 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2235 | 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] | 2236 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2237 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2238 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2239 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2240 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2241 | if ((offset >> 32) > 0) { |
| 2242 | /* can not handle big offset for old srv */ |
| 2243 | return -EIO; |
| 2244 | } |
| 2245 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2246 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | if (rc) |
| 2248 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2249 | |
| 2250 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2251 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | /* tcon and ses pointer are checked in smb_init */ |
| 2254 | if (tcon->ses->server == NULL) |
| 2255 | return -ECONNABORTED; |
| 2256 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2257 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | pSMB->Fid = netfid; |
| 2259 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2260 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2261 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | pSMB->Reserved = 0xFFFFFFFF; |
| 2263 | pSMB->WriteMode = 0; |
| 2264 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2267 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2269 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2270 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2271 | /* header + 1 byte pad */ |
| 2272 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2273 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2274 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2275 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2276 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2277 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2278 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2279 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2280 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2281 | (struct smb_com_writex_req *)pSMB; |
| 2282 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2283 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2284 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2285 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2286 | iov[0].iov_len = smb_hdr_len + 4; |
| 2287 | else /* wct == 12 pad bigger by four bytes */ |
| 2288 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2289 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2290 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0, |
| 2291 | &rsp_iov); |
| 2292 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2293 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2295 | cifs_dbg(FYI, "Send error Write2 = %d\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2296 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2297 | /* presumably this can not happen, but best to be safe */ |
| 2298 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2299 | } else { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2300 | WRITE_RSP *pSMBr = (WRITE_RSP *)rsp_iov.iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2301 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2302 | *nbytes = (*nbytes) << 16; |
| 2303 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2304 | |
| 2305 | /* |
| 2306 | * Mask off high 16 bits when bytes written as returned by the |
| 2307 | * server is greater than bytes requested by the client. OS/2 |
| 2308 | * servers are known to set incorrect CountHigh values. |
| 2309 | */ |
| 2310 | if (*nbytes > count) |
| 2311 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2314 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2316 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | since file handle passed in no longer valid */ |
| 2318 | |
| 2319 | return rc; |
| 2320 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2321 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2322 | int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon, |
| 2323 | const __u16 netfid, const __u8 lock_type, const __u32 num_unlock, |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2324 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2325 | { |
| 2326 | int rc = 0; |
| 2327 | LOCK_REQ *pSMB = NULL; |
| 2328 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2329 | struct kvec rsp_iov; |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2330 | int resp_buf_type; |
| 2331 | __u16 count; |
| 2332 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2333 | cifs_dbg(FYI, "cifs_lockv num lock %d num unlock %d\n", |
| 2334 | num_lock, num_unlock); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2335 | |
| 2336 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2337 | if (rc) |
| 2338 | return rc; |
| 2339 | |
| 2340 | pSMB->Timeout = 0; |
| 2341 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2342 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2343 | pSMB->LockType = lock_type; |
| 2344 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2345 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2346 | |
| 2347 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2348 | inc_rfc1001_len(pSMB, count); |
| 2349 | pSMB->ByteCount = cpu_to_le16(count); |
| 2350 | |
| 2351 | iov[0].iov_base = (char *)pSMB; |
| 2352 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2353 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2354 | iov[1].iov_base = (char *)buf; |
| 2355 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2356 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2357 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2358 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP, |
| 2359 | &rsp_iov); |
| 2360 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2361 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2362 | cifs_dbg(FYI, "Send error in cifs_lockv = %d\n", rc); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2363 | |
| 2364 | return rc; |
| 2365 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2368 | CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2369 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2371 | const __u32 numLock, const __u8 lockType, |
| 2372 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | { |
| 2374 | int rc = 0; |
| 2375 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2376 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | int bytes_returned; |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2378 | int flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | __u16 count; |
| 2380 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2381 | cifs_dbg(FYI, "CIFSSMBLock timeout %d numLock %d\n", |
| 2382 | (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2383 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | if (rc) |
| 2386 | return rc; |
| 2387 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2388 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2389 | /* no response expected */ |
| 2390 | flags = CIFS_ASYNC_OP | CIFS_OBREAK_OP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2392 | } else if (waitFlag) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2393 | flags = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2395 | } else { |
| 2396 | pSMB->Timeout = 0; |
| 2397 | } |
| 2398 | |
| 2399 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2400 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2401 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2402 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2404 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2405 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2406 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2407 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | /* BB where to store pid high? */ |
| 2409 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2410 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2411 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2412 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2413 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2414 | } else { |
| 2415 | /* oplock break */ |
| 2416 | count = 0; |
| 2417 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2418 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | pSMB->ByteCount = cpu_to_le16(count); |
| 2420 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2421 | if (waitFlag) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2422 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2423 | (struct smb_hdr *) pSMB, &bytes_returned); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2424 | else |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2425 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, flags); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2426 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2427 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2428 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2429 | cifs_dbg(FYI, "Send error in Lock = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2431 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | since file handle passed in no longer valid */ |
| 2433 | return rc; |
| 2434 | } |
| 2435 | |
| 2436 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2437 | CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2438 | const __u16 smb_file_id, const __u32 netpid, |
| 2439 | const loff_t start_offset, const __u64 len, |
| 2440 | struct file_lock *pLockData, const __u16 lock_type, |
| 2441 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2442 | { |
| 2443 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2444 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2445 | struct cifs_posix_lock *parm_data; |
| 2446 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2447 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2448 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2449 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2450 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2451 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2452 | struct kvec rsp_iov; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2453 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2454 | cifs_dbg(FYI, "Posix Lock\n"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2455 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2456 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2457 | |
| 2458 | if (rc) |
| 2459 | return rc; |
| 2460 | |
| 2461 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2462 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2463 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2464 | pSMB->MaxSetupCount = 0; |
| 2465 | pSMB->Reserved = 0; |
| 2466 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2467 | pSMB->Reserved2 = 0; |
| 2468 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2469 | offset = param_offset + params; |
| 2470 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2471 | count = sizeof(struct cifs_posix_lock); |
| 2472 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2473 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2474 | pSMB->SetupCount = 1; |
| 2475 | pSMB->Reserved3 = 0; |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2476 | if (pLockData) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2477 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2478 | else |
| 2479 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2480 | byte_count = 3 /* pad */ + params + count; |
| 2481 | pSMB->DataCount = cpu_to_le16(count); |
| 2482 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2483 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2484 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2485 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2486 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2487 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2488 | |
| 2489 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2490 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2491 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2492 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2493 | pSMB->Timeout = cpu_to_le32(-1); |
| 2494 | } else |
| 2495 | pSMB->Timeout = 0; |
| 2496 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2497 | parm_data->pid = cpu_to_le32(netpid); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2498 | parm_data->start = cpu_to_le64(start_offset); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2499 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2500 | |
| 2501 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2502 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2503 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2504 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2505 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2506 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2507 | if (waitFlag) { |
| 2508 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2509 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2510 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2511 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2512 | 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] | 2513 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2514 | &resp_buf_type, timeout, &rsp_iov); |
| 2515 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)rsp_iov.iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2516 | } |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2517 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2518 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2519 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2520 | cifs_dbg(FYI, "Send error in Posix Lock = %d\n", rc); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2521 | } else if (pLockData) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2522 | /* lock structure can be returned on get */ |
| 2523 | __u16 data_offset; |
| 2524 | __u16 data_count; |
| 2525 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2526 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2527 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2528 | rc = -EIO; /* bad smb */ |
| 2529 | goto plk_err_exit; |
| 2530 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2531 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2532 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2533 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2534 | rc = -EIO; |
| 2535 | goto plk_err_exit; |
| 2536 | } |
| 2537 | parm_data = (struct cifs_posix_lock *) |
| 2538 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2539 | if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2540 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2541 | else { |
| 2542 | if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2543 | cpu_to_le16(CIFS_RDLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2544 | pLockData->fl_type = F_RDLCK; |
| 2545 | else if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2546 | cpu_to_le16(CIFS_WRLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2547 | pLockData->fl_type = F_WRLCK; |
| 2548 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2549 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2550 | pLockData->fl_end = pLockData->fl_start + |
| 2551 | le64_to_cpu(parm_data->length) - 1; |
Benjamin Coddington | 9d5b86a | 2017-07-16 10:28:22 -0400 | [diff] [blame] | 2552 | pLockData->fl_pid = -le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2553 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2554 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2555 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2556 | plk_err_exit: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2557 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2558 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2559 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2560 | since file handle passed in no longer valid */ |
| 2561 | |
| 2562 | return rc; |
| 2563 | } |
| 2564 | |
| 2565 | |
| 2566 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2567 | 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] | 2568 | { |
| 2569 | int rc = 0; |
| 2570 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2571 | cifs_dbg(FYI, "In CIFSSMBClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | |
| 2573 | /* do not retry on dead session on close */ |
| 2574 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2575 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | return 0; |
| 2577 | if (rc) |
| 2578 | return rc; |
| 2579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2581 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2583 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2584 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2585 | cifs_stats_inc(&tcon->stats.cifs_stats.num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2587 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2589 | cifs_dbg(VFS, "Send error in Close = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | } |
| 2591 | } |
| 2592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2594 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | rc = 0; |
| 2596 | |
| 2597 | return rc; |
| 2598 | } |
| 2599 | |
| 2600 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2601 | 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] | 2602 | { |
| 2603 | int rc = 0; |
| 2604 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2605 | cifs_dbg(FYI, "In CIFSSMBFlush\n"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2606 | |
| 2607 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2608 | if (rc) |
| 2609 | return rc; |
| 2610 | |
| 2611 | pSMB->FileID = (__u16) smb_file_id; |
| 2612 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2613 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2614 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2615 | cifs_stats_inc(&tcon->stats.cifs_stats.num_flushes); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2616 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2617 | cifs_dbg(VFS, "Send error in Flush = %d\n", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2618 | |
| 2619 | return rc; |
| 2620 | } |
| 2621 | |
| 2622 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2623 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2624 | const char *from_name, const char *to_name, |
| 2625 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | { |
| 2627 | int rc = 0; |
| 2628 | RENAME_REQ *pSMB = NULL; |
| 2629 | RENAME_RSP *pSMBr = NULL; |
| 2630 | int bytes_returned; |
| 2631 | int name_len, name_len2; |
| 2632 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 2633 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2635 | cifs_dbg(FYI, "In CIFSSMBRename\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | renameRetry: |
| 2637 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2638 | (void **) &pSMBr); |
| 2639 | if (rc) |
| 2640 | return rc; |
| 2641 | |
| 2642 | pSMB->BufferFormat = 0x04; |
| 2643 | pSMB->SearchAttributes = |
| 2644 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2645 | ATTR_DIRECTORY); |
| 2646 | |
| 2647 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2648 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2649 | from_name, PATH_MAX, |
| 2650 | cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | name_len++; /* trailing null */ |
| 2652 | name_len *= 2; |
| 2653 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2654 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2655 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2656 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2657 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2658 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 2659 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2661 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2662 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2663 | name_len = strnlen(from_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | name_len++; /* trailing null */ |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2665 | strncpy(pSMB->OldFileName, from_name, name_len); |
| 2666 | name_len2 = strnlen(to_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | name_len2++; /* trailing null */ |
| 2668 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2669 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | name_len2++; /* trailing null */ |
| 2671 | name_len2++; /* signature byte */ |
| 2672 | } |
| 2673 | |
| 2674 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2675 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | pSMB->ByteCount = cpu_to_le16(count); |
| 2677 | |
| 2678 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2679 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2680 | cifs_stats_inc(&tcon->stats.cifs_stats.num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2681 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2682 | cifs_dbg(FYI, "Send error in rename = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | cifs_buf_release(pSMB); |
| 2685 | |
| 2686 | if (rc == -EAGAIN) |
| 2687 | goto renameRetry; |
| 2688 | |
| 2689 | return rc; |
| 2690 | } |
| 2691 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2692 | int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2693 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2694 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | { |
| 2696 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2697 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2698 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | char *data_offset; |
| 2700 | char dummy_string[30]; |
| 2701 | int rc = 0; |
| 2702 | int bytes_returned = 0; |
| 2703 | int len_of_str; |
| 2704 | __u16 params, param_offset, offset, count, byte_count; |
| 2705 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2706 | cifs_dbg(FYI, "Rename to File by handle\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2708 | (void **) &pSMBr); |
| 2709 | if (rc) |
| 2710 | return rc; |
| 2711 | |
| 2712 | params = 6; |
| 2713 | pSMB->MaxSetupCount = 0; |
| 2714 | pSMB->Reserved = 0; |
| 2715 | pSMB->Flags = 0; |
| 2716 | pSMB->Timeout = 0; |
| 2717 | pSMB->Reserved2 = 0; |
| 2718 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2719 | offset = param_offset + params; |
| 2720 | |
| 2721 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2722 | rename_info = (struct set_file_rename *) data_offset; |
| 2723 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2724 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | pSMB->SetupCount = 1; |
| 2726 | pSMB->Reserved3 = 0; |
| 2727 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2728 | byte_count = 3 /* pad */ + params; |
| 2729 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2730 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2731 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2732 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2733 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2734 | rename_info->overwrite = cpu_to_le32(1); |
| 2735 | rename_info->root_fid = 0; |
| 2736 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2737 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2738 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2739 | len_of_str = |
| 2740 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2741 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2743 | len_of_str = |
| 2744 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2745 | target_name, PATH_MAX, nls_codepage, |
| 2746 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | } |
| 2748 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2749 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | byte_count += count; |
| 2751 | pSMB->DataCount = cpu_to_le16(count); |
| 2752 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2753 | pSMB->Fid = netfid; |
| 2754 | pSMB->InformationLevel = |
| 2755 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2756 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2757 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2759 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2760 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2761 | cifs_stats_inc(&pTcon->stats.cifs_stats.num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2762 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2763 | cifs_dbg(FYI, "Send error in Rename (by file handle) = %d\n", |
| 2764 | rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | cifs_buf_release(pSMB); |
| 2767 | |
| 2768 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2769 | since file handle passed in no longer valid */ |
| 2770 | |
| 2771 | return rc; |
| 2772 | } |
| 2773 | |
| 2774 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2775 | CIFSSMBCopy(const unsigned int xid, struct cifs_tcon *tcon, |
| 2776 | const char *fromName, const __u16 target_tid, const char *toName, |
| 2777 | const int flags, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | { |
| 2779 | int rc = 0; |
| 2780 | COPY_REQ *pSMB = NULL; |
| 2781 | COPY_RSP *pSMBr = NULL; |
| 2782 | int bytes_returned; |
| 2783 | int name_len, name_len2; |
| 2784 | __u16 count; |
| 2785 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2786 | cifs_dbg(FYI, "In CIFSSMBCopy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | copyRetry: |
| 2788 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2789 | (void **) &pSMBr); |
| 2790 | if (rc) |
| 2791 | return rc; |
| 2792 | |
| 2793 | pSMB->BufferFormat = 0x04; |
| 2794 | pSMB->Tid2 = target_tid; |
| 2795 | |
| 2796 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2797 | |
| 2798 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2799 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2800 | fromName, PATH_MAX, nls_codepage, |
| 2801 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | name_len++; /* trailing null */ |
| 2803 | name_len *= 2; |
| 2804 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2805 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2806 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2807 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2808 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2809 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2811 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2812 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | name_len = strnlen(fromName, PATH_MAX); |
| 2814 | name_len++; /* trailing null */ |
| 2815 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2816 | name_len2 = strnlen(toName, PATH_MAX); |
| 2817 | name_len2++; /* trailing null */ |
| 2818 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2819 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2820 | name_len2++; /* trailing null */ |
| 2821 | name_len2++; /* signature byte */ |
| 2822 | } |
| 2823 | |
| 2824 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2825 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | pSMB->ByteCount = cpu_to_le16(count); |
| 2827 | |
| 2828 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2829 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2830 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2831 | cifs_dbg(FYI, "Send error in copy = %d with %d files copied\n", |
| 2832 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2834 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | |
| 2836 | if (rc == -EAGAIN) |
| 2837 | goto copyRetry; |
| 2838 | |
| 2839 | return rc; |
| 2840 | } |
| 2841 | |
| 2842 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2843 | CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | const char *fromName, const char *toName, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2845 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | { |
| 2847 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2848 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2849 | char *data_offset; |
| 2850 | int name_len; |
| 2851 | int name_len_target; |
| 2852 | int rc = 0; |
| 2853 | int bytes_returned = 0; |
| 2854 | __u16 params, param_offset, offset, byte_count; |
| 2855 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2856 | cifs_dbg(FYI, "In Symlink Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | createSymLinkRetry: |
| 2858 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2859 | (void **) &pSMBr); |
| 2860 | if (rc) |
| 2861 | return rc; |
| 2862 | |
| 2863 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2864 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2865 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fromName, |
| 2866 | /* find define for this maxpathcomponent */ |
| 2867 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | name_len++; /* trailing null */ |
| 2869 | name_len *= 2; |
| 2870 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2871 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | name_len = strnlen(fromName, PATH_MAX); |
| 2873 | name_len++; /* trailing null */ |
| 2874 | strncpy(pSMB->FileName, fromName, name_len); |
| 2875 | } |
| 2876 | params = 6 + name_len; |
| 2877 | pSMB->MaxSetupCount = 0; |
| 2878 | pSMB->Reserved = 0; |
| 2879 | pSMB->Flags = 0; |
| 2880 | pSMB->Timeout = 0; |
| 2881 | pSMB->Reserved2 = 0; |
| 2882 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2883 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | offset = param_offset + params; |
| 2885 | |
| 2886 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2887 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2888 | name_len_target = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2889 | cifsConvertToUTF16((__le16 *) data_offset, toName, |
| 2890 | /* find define for this maxpathcomponent */ |
| 2891 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | name_len_target++; /* trailing null */ |
| 2893 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2894 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | name_len_target = strnlen(toName, PATH_MAX); |
| 2896 | name_len_target++; /* trailing null */ |
| 2897 | strncpy(data_offset, toName, name_len_target); |
| 2898 | } |
| 2899 | |
| 2900 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2901 | /* BB find exact max on data count below from sess */ |
| 2902 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2903 | pSMB->SetupCount = 1; |
| 2904 | pSMB->Reserved3 = 0; |
| 2905 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2906 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2907 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2908 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2909 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2910 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2911 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2912 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2913 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2914 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2915 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2917 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2918 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2919 | cifs_stats_inc(&tcon->stats.cifs_stats.num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2920 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2921 | cifs_dbg(FYI, "Send error in SetPathInfo create symlink = %d\n", |
| 2922 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2924 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | |
| 2926 | if (rc == -EAGAIN) |
| 2927 | goto createSymLinkRetry; |
| 2928 | |
| 2929 | return rc; |
| 2930 | } |
| 2931 | |
| 2932 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2933 | CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2935 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | { |
| 2937 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2938 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2939 | char *data_offset; |
| 2940 | int name_len; |
| 2941 | int name_len_target; |
| 2942 | int rc = 0; |
| 2943 | int bytes_returned = 0; |
| 2944 | __u16 params, param_offset, offset, byte_count; |
| 2945 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2946 | cifs_dbg(FYI, "In Create Hard link Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | createHardLinkRetry: |
| 2948 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2949 | (void **) &pSMBr); |
| 2950 | if (rc) |
| 2951 | return rc; |
| 2952 | |
| 2953 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2954 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 2955 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | name_len++; /* trailing null */ |
| 2957 | name_len *= 2; |
| 2958 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2959 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | name_len = strnlen(toName, PATH_MAX); |
| 2961 | name_len++; /* trailing null */ |
| 2962 | strncpy(pSMB->FileName, toName, name_len); |
| 2963 | } |
| 2964 | params = 6 + name_len; |
| 2965 | pSMB->MaxSetupCount = 0; |
| 2966 | pSMB->Reserved = 0; |
| 2967 | pSMB->Flags = 0; |
| 2968 | pSMB->Timeout = 0; |
| 2969 | pSMB->Reserved2 = 0; |
| 2970 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2971 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | offset = param_offset + params; |
| 2973 | |
| 2974 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2975 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2976 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2977 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 2978 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | name_len_target++; /* trailing null */ |
| 2980 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2981 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2983 | name_len_target++; /* trailing null */ |
| 2984 | strncpy(data_offset, fromName, name_len_target); |
| 2985 | } |
| 2986 | |
| 2987 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2988 | /* BB find exact max on data count below from sess*/ |
| 2989 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2990 | pSMB->SetupCount = 1; |
| 2991 | pSMB->Reserved3 = 0; |
| 2992 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2993 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2994 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2995 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2996 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2997 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2998 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2999 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3000 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 3001 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3002 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3004 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3005 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3006 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3007 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3008 | cifs_dbg(FYI, "Send error in SetPathInfo (hard link) = %d\n", |
| 3009 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | |
| 3011 | cifs_buf_release(pSMB); |
| 3012 | if (rc == -EAGAIN) |
| 3013 | goto createHardLinkRetry; |
| 3014 | |
| 3015 | return rc; |
| 3016 | } |
| 3017 | |
| 3018 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3019 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3020 | const char *from_name, const char *to_name, |
| 3021 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | { |
| 3023 | int rc = 0; |
| 3024 | NT_RENAME_REQ *pSMB = NULL; |
| 3025 | RENAME_RSP *pSMBr = NULL; |
| 3026 | int bytes_returned; |
| 3027 | int name_len, name_len2; |
| 3028 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 3029 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3031 | cifs_dbg(FYI, "In CIFSCreateHardLink\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | winCreateHardLinkRetry: |
| 3033 | |
| 3034 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 3035 | (void **) &pSMBr); |
| 3036 | if (rc) |
| 3037 | return rc; |
| 3038 | |
| 3039 | pSMB->SearchAttributes = |
| 3040 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3041 | ATTR_DIRECTORY); |
| 3042 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 3043 | pSMB->ClusterCount = 0; |
| 3044 | |
| 3045 | pSMB->BufferFormat = 0x04; |
| 3046 | |
| 3047 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3048 | name_len = |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3049 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, from_name, |
| 3050 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | name_len++; /* trailing null */ |
| 3052 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 3053 | |
| 3054 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 3055 | pSMB->OldFileName[name_len] = 0x04; |
| 3056 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3058 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3059 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 3060 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 3062 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3063 | } else { /* BB improve the check for buffer overruns BB */ |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3064 | name_len = strnlen(from_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | name_len++; /* trailing null */ |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3066 | strncpy(pSMB->OldFileName, from_name, name_len); |
| 3067 | name_len2 = strnlen(to_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | name_len2++; /* trailing null */ |
| 3069 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3070 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | name_len2++; /* trailing null */ |
| 3072 | name_len2++; /* signature byte */ |
| 3073 | } |
| 3074 | |
| 3075 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3076 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | pSMB->ByteCount = cpu_to_le16(count); |
| 3078 | |
| 3079 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3080 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3081 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3082 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3083 | 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] | 3084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | cifs_buf_release(pSMB); |
| 3086 | if (rc == -EAGAIN) |
| 3087 | goto winCreateHardLinkRetry; |
| 3088 | |
| 3089 | return rc; |
| 3090 | } |
| 3091 | |
| 3092 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3093 | CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3094 | const unsigned char *searchName, char **symlinkinfo, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3095 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | { |
| 3097 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 3098 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3099 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3100 | int rc = 0; |
| 3101 | int bytes_returned; |
| 3102 | int name_len; |
| 3103 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3104 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3106 | cifs_dbg(FYI, "In QPathSymLinkInfo (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | |
| 3108 | querySymLinkRetry: |
| 3109 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3110 | (void **) &pSMBr); |
| 3111 | if (rc) |
| 3112 | return rc; |
| 3113 | |
| 3114 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3115 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3116 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3117 | searchName, PATH_MAX, nls_codepage, |
| 3118 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | name_len++; /* trailing null */ |
| 3120 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3121 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | name_len = strnlen(searchName, PATH_MAX); |
| 3123 | name_len++; /* trailing null */ |
| 3124 | strncpy(pSMB->FileName, searchName, name_len); |
| 3125 | } |
| 3126 | |
| 3127 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3128 | pSMB->TotalDataCount = 0; |
| 3129 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3130 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | pSMB->MaxSetupCount = 0; |
| 3132 | pSMB->Reserved = 0; |
| 3133 | pSMB->Flags = 0; |
| 3134 | pSMB->Timeout = 0; |
| 3135 | pSMB->Reserved2 = 0; |
| 3136 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3137 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | pSMB->DataCount = 0; |
| 3139 | pSMB->DataOffset = 0; |
| 3140 | pSMB->SetupCount = 1; |
| 3141 | pSMB->Reserved3 = 0; |
| 3142 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3143 | byte_count = params + 1 /* pad */ ; |
| 3144 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3145 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3146 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3147 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3148 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3150 | |
| 3151 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3152 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3153 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3154 | cifs_dbg(FYI, "Send error in QuerySymLinkInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | } else { |
| 3156 | /* decode response */ |
| 3157 | |
| 3158 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3160 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3161 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3163 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3164 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3166 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3167 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3168 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3169 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3170 | is_unicode = true; |
| 3171 | else |
| 3172 | is_unicode = false; |
| 3173 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3174 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3175 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3176 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3177 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3178 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | } |
| 3180 | } |
| 3181 | cifs_buf_release(pSMB); |
| 3182 | if (rc == -EAGAIN) |
| 3183 | goto querySymLinkRetry; |
| 3184 | return rc; |
| 3185 | } |
| 3186 | |
Steve French | c52a9554 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3187 | /* |
| 3188 | * Recent Windows versions now create symlinks more frequently |
| 3189 | * and they use the "reparse point" mechanism below. We can of course |
| 3190 | * do symlinks nicely to Samba and other servers which support the |
| 3191 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3192 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3193 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3194 | * In the interim this code has been moved to its own config option so |
| 3195 | * it is not compiled in by default until callers fixed up and more tested. |
| 3196 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | int |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3198 | CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
| 3199 | __u16 fid, char **symlinkinfo, |
| 3200 | const struct nls_table *nls_codepage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | { |
| 3202 | int rc = 0; |
| 3203 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3204 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3205 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3206 | bool is_unicode; |
| 3207 | unsigned int sub_len; |
| 3208 | char *sub_start; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3209 | struct reparse_symlink_data *reparse_buf; |
| 3210 | struct reparse_posix_data *posix_buf; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3211 | __u32 data_offset, data_count; |
| 3212 | char *end_of_smb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3214 | 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] | 3215 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3216 | (void **) &pSMBr); |
| 3217 | if (rc) |
| 3218 | return rc; |
| 3219 | |
| 3220 | pSMB->TotalParameterCount = 0 ; |
| 3221 | pSMB->TotalDataCount = 0; |
| 3222 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3223 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3224 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | pSMB->MaxSetupCount = 4; |
| 3226 | pSMB->Reserved = 0; |
| 3227 | pSMB->ParameterOffset = 0; |
| 3228 | pSMB->DataCount = 0; |
| 3229 | pSMB->DataOffset = 0; |
| 3230 | pSMB->SetupCount = 4; |
| 3231 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3232 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3233 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3234 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3235 | pSMB->IsRootFlag = 0; |
| 3236 | pSMB->Fid = fid; /* file handle always le */ |
| 3237 | pSMB->ByteCount = 0; |
| 3238 | |
| 3239 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3240 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3241 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3242 | cifs_dbg(FYI, "Send error in QueryReparseLinkInfo = %d\n", rc); |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3243 | goto qreparse_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3245 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3246 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3247 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3248 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3249 | /* BB also check enough total bytes returned */ |
| 3250 | rc = -EIO; /* bad smb */ |
| 3251 | goto qreparse_out; |
| 3252 | } |
| 3253 | if (!data_count || (data_count > 2048)) { |
| 3254 | rc = -EIO; |
| 3255 | cifs_dbg(FYI, "Invalid return data count on get reparse info ioctl\n"); |
| 3256 | goto qreparse_out; |
| 3257 | } |
| 3258 | end_of_smb = 2 + get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3259 | reparse_buf = (struct reparse_symlink_data *) |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3260 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
| 3261 | if ((char *)reparse_buf >= end_of_smb) { |
| 3262 | rc = -EIO; |
| 3263 | goto qreparse_out; |
| 3264 | } |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3265 | if (reparse_buf->ReparseTag == cpu_to_le32(IO_REPARSE_TAG_NFS)) { |
| 3266 | cifs_dbg(FYI, "NFS style reparse tag\n"); |
| 3267 | posix_buf = (struct reparse_posix_data *)reparse_buf; |
| 3268 | |
| 3269 | if (posix_buf->InodeType != cpu_to_le64(NFS_SPECFILE_LNK)) { |
| 3270 | cifs_dbg(FYI, "unsupported file type 0x%llx\n", |
| 3271 | le64_to_cpu(posix_buf->InodeType)); |
| 3272 | rc = -EOPNOTSUPP; |
| 3273 | goto qreparse_out; |
| 3274 | } |
| 3275 | is_unicode = true; |
| 3276 | sub_len = le16_to_cpu(reparse_buf->ReparseDataLength); |
| 3277 | if (posix_buf->PathBuffer + sub_len > end_of_smb) { |
| 3278 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3279 | rc = -EIO; |
| 3280 | goto qreparse_out; |
| 3281 | } |
| 3282 | *symlinkinfo = cifs_strndup_from_utf16(posix_buf->PathBuffer, |
| 3283 | sub_len, is_unicode, nls_codepage); |
| 3284 | goto qreparse_out; |
| 3285 | } else if (reparse_buf->ReparseTag != |
| 3286 | cpu_to_le32(IO_REPARSE_TAG_SYMLINK)) { |
| 3287 | rc = -EOPNOTSUPP; |
| 3288 | goto qreparse_out; |
| 3289 | } |
| 3290 | |
| 3291 | /* Reparse tag is NTFS symlink */ |
| 3292 | sub_start = le16_to_cpu(reparse_buf->SubstituteNameOffset) + |
| 3293 | reparse_buf->PathBuffer; |
| 3294 | sub_len = le16_to_cpu(reparse_buf->SubstituteNameLength); |
| 3295 | if (sub_start + sub_len > end_of_smb) { |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3296 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3297 | rc = -EIO; |
| 3298 | goto qreparse_out; |
| 3299 | } |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3300 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3301 | is_unicode = true; |
| 3302 | else |
| 3303 | is_unicode = false; |
| 3304 | |
| 3305 | /* BB FIXME investigate remapping reserved chars here */ |
| 3306 | *symlinkinfo = cifs_strndup_from_utf16(sub_start, sub_len, is_unicode, |
| 3307 | nls_codepage); |
| 3308 | if (!*symlinkinfo) |
| 3309 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3311 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3313 | /* |
| 3314 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3315 | * since file handle passed in no longer valid. |
| 3316 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | return rc; |
| 3318 | } |
| 3319 | |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3320 | int |
| 3321 | CIFSSMB_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 3322 | __u16 fid) |
| 3323 | { |
| 3324 | int rc = 0; |
| 3325 | int bytes_returned; |
| 3326 | struct smb_com_transaction_compr_ioctl_req *pSMB; |
| 3327 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
| 3328 | |
| 3329 | cifs_dbg(FYI, "Set compression for %u\n", fid); |
| 3330 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3331 | (void **) &pSMBr); |
| 3332 | if (rc) |
| 3333 | return rc; |
| 3334 | |
| 3335 | pSMB->compression_state = cpu_to_le16(COMPRESSION_FORMAT_DEFAULT); |
| 3336 | |
| 3337 | pSMB->TotalParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3338 | pSMB->TotalDataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3339 | pSMB->MaxParameterCount = 0; |
| 3340 | pSMB->MaxDataCount = 0; |
| 3341 | pSMB->MaxSetupCount = 4; |
| 3342 | pSMB->Reserved = 0; |
| 3343 | pSMB->ParameterOffset = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3344 | pSMB->DataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3345 | pSMB->DataOffset = |
| 3346 | cpu_to_le32(offsetof(struct smb_com_transaction_compr_ioctl_req, |
| 3347 | compression_state) - 4); /* 84 */ |
| 3348 | pSMB->SetupCount = 4; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3349 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3350 | pSMB->ParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3351 | pSMB->FunctionCode = cpu_to_le32(FSCTL_SET_COMPRESSION); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3352 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3353 | pSMB->IsRootFlag = 0; |
| 3354 | pSMB->Fid = fid; /* file handle always le */ |
| 3355 | /* 3 byte pad, followed by 2 byte compress state */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3356 | pSMB->ByteCount = cpu_to_le16(5); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3357 | inc_rfc1001_len(pSMB, 5); |
| 3358 | |
| 3359 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3360 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3361 | if (rc) |
| 3362 | cifs_dbg(FYI, "Send error in SetCompression = %d\n", rc); |
| 3363 | |
| 3364 | cifs_buf_release(pSMB); |
| 3365 | |
| 3366 | /* |
| 3367 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3368 | * since file handle passed in no longer valid. |
| 3369 | */ |
| 3370 | return rc; |
| 3371 | } |
| 3372 | |
| 3373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | #ifdef CONFIG_CIFS_POSIX |
| 3375 | |
| 3376 | /*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] | 3377 | static void cifs_convert_ace(struct posix_acl_xattr_entry *ace, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3378 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | { |
| 3380 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3381 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3382 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3383 | 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] | 3384 | /* |
| 3385 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3386 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3387 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | |
| 3389 | return; |
| 3390 | } |
| 3391 | |
| 3392 | /* 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] | 3393 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3394 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | { |
| 3396 | int size = 0; |
| 3397 | int i; |
| 3398 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3399 | struct cifs_posix_ace *pACE; |
| 3400 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3401 | struct posix_acl_xattr_header *local_acl = (void *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | |
| 3403 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3404 | return -EOPNOTSUPP; |
| 3405 | |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3406 | if (acl_type == ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3408 | pACE = &cifs_acl->ace_array[0]; |
| 3409 | size = sizeof(struct cifs_posix_acl); |
| 3410 | size += sizeof(struct cifs_posix_ace) * count; |
| 3411 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3412 | if (size_of_data_area < size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3413 | cifs_dbg(FYI, "bad CIFS POSIX ACL size %d vs. %d\n", |
| 3414 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | return -EINVAL; |
| 3416 | } |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3417 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3419 | size = sizeof(struct cifs_posix_acl); |
| 3420 | size += sizeof(struct cifs_posix_ace) * count; |
| 3421 | /* skip past access ACEs to get to default ACEs */ |
| 3422 | pACE = &cifs_acl->ace_array[count]; |
| 3423 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3424 | size += sizeof(struct cifs_posix_ace) * count; |
| 3425 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3426 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | return -EINVAL; |
| 3428 | } else { |
| 3429 | /* illegal type */ |
| 3430 | return -EINVAL; |
| 3431 | } |
| 3432 | |
| 3433 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3434 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3435 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3436 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | return -ERANGE; |
| 3438 | } else /* buffer big enough */ { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3439 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
| 3440 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3441 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3442 | for (i = 0; i < count ; i++) { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3443 | cifs_convert_ace(&ace[i], pACE); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3444 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | } |
| 3446 | } |
| 3447 | return size; |
| 3448 | } |
| 3449 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3450 | 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] | 3451 | const struct posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | { |
| 3453 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 3454 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3455 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3456 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3458 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3460 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3461 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3462 | 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] | 3463 | /* |
| 3464 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3465 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3466 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | return rc; |
| 3468 | } |
| 3469 | |
| 3470 | /* 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] | 3471 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3472 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | { |
| 3474 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3475 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3476 | struct posix_acl_xattr_header *local_acl = (void *)pACL; |
Eryu Guan | ae9ebe7 | 2016-10-24 20:46:40 +0800 | [diff] [blame] | 3477 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | int count; |
| 3479 | int i; |
| 3480 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3481 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | return 0; |
| 3483 | |
| 3484 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3485 | cifs_dbg(FYI, "setting acl with %d entries from buf of length %d and version of %d\n", |
| 3486 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3487 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3488 | cifs_dbg(FYI, "unknown POSIX ACL version %d\n", |
| 3489 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | return 0; |
| 3491 | } |
| 3492 | cifs_acl->version = cpu_to_le16(1); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3493 | if (acl_type == ACL_TYPE_ACCESS) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3494 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3495 | cifs_acl->default_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3496 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3497 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3498 | cifs_acl->access_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3499 | } else { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3500 | cifs_dbg(FYI, "unknown ACL type %d\n", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | return 0; |
| 3502 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3503 | for (i = 0; i < count; i++) { |
Eryu Guan | ae9ebe7 | 2016-10-24 20:46:40 +0800 | [diff] [blame] | 3504 | 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] | 3505 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | /* ACE not converted */ |
| 3507 | break; |
| 3508 | } |
| 3509 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3510 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3512 | rc += sizeof(struct cifs_posix_acl); |
| 3513 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3514 | } |
| 3515 | return rc; |
| 3516 | } |
| 3517 | |
| 3518 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3519 | CIFSSMBGetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3520 | const unsigned char *searchName, |
| 3521 | char *acl_inf, const int buflen, const int acl_type, |
| 3522 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | { |
| 3524 | /* SMB_QUERY_POSIX_ACL */ |
| 3525 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3526 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3527 | int rc = 0; |
| 3528 | int bytes_returned; |
| 3529 | int name_len; |
| 3530 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3531 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3532 | cifs_dbg(FYI, "In GetPosixACL (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | |
| 3534 | queryAclRetry: |
| 3535 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3536 | (void **) &pSMBr); |
| 3537 | if (rc) |
| 3538 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3541 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3542 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3543 | searchName, PATH_MAX, nls_codepage, |
| 3544 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | name_len++; /* trailing null */ |
| 3546 | name_len *= 2; |
| 3547 | pSMB->FileName[name_len] = 0; |
| 3548 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3549 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | name_len = strnlen(searchName, PATH_MAX); |
| 3551 | name_len++; /* trailing null */ |
| 3552 | strncpy(pSMB->FileName, searchName, name_len); |
| 3553 | } |
| 3554 | |
| 3555 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3556 | pSMB->TotalDataCount = 0; |
| 3557 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3558 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3560 | pSMB->MaxSetupCount = 0; |
| 3561 | pSMB->Reserved = 0; |
| 3562 | pSMB->Flags = 0; |
| 3563 | pSMB->Timeout = 0; |
| 3564 | pSMB->Reserved2 = 0; |
| 3565 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3566 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3567 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | pSMB->DataCount = 0; |
| 3569 | pSMB->DataOffset = 0; |
| 3570 | pSMB->SetupCount = 1; |
| 3571 | pSMB->Reserved3 = 0; |
| 3572 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3573 | byte_count = params + 1 /* pad */ ; |
| 3574 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3575 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3576 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3577 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3578 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3580 | |
| 3581 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3582 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3583 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3585 | cifs_dbg(FYI, "Send error in Query POSIX ACL = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | } else { |
| 3587 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3591 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | rc = -EIO; /* bad smb */ |
| 3593 | else { |
| 3594 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3595 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3596 | rc = cifs_copy_posix_acl(acl_inf, |
| 3597 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3598 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | } |
| 3600 | } |
| 3601 | cifs_buf_release(pSMB); |
| 3602 | if (rc == -EAGAIN) |
| 3603 | goto queryAclRetry; |
| 3604 | return rc; |
| 3605 | } |
| 3606 | |
| 3607 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3608 | CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3609 | const unsigned char *fileName, |
| 3610 | const char *local_acl, const int buflen, |
| 3611 | const int acl_type, |
| 3612 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | { |
| 3614 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3615 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3616 | char *parm_data; |
| 3617 | int name_len; |
| 3618 | int rc = 0; |
| 3619 | int bytes_returned = 0; |
| 3620 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3621 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3622 | cifs_dbg(FYI, "In SetPosixACL (Unix) for path %s\n", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | setAclRetry: |
| 3624 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3625 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | if (rc) |
| 3627 | return rc; |
| 3628 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3629 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3630 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3631 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | name_len++; /* trailing null */ |
| 3633 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3634 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | name_len = strnlen(fileName, PATH_MAX); |
| 3636 | name_len++; /* trailing null */ |
| 3637 | strncpy(pSMB->FileName, fileName, name_len); |
| 3638 | } |
| 3639 | params = 6 + name_len; |
| 3640 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3641 | /* BB find max SMB size from sess */ |
| 3642 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | pSMB->MaxSetupCount = 0; |
| 3644 | pSMB->Reserved = 0; |
| 3645 | pSMB->Flags = 0; |
| 3646 | pSMB->Timeout = 0; |
| 3647 | pSMB->Reserved2 = 0; |
| 3648 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3649 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | offset = param_offset + params; |
| 3651 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3652 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3653 | |
| 3654 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3655 | 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] | 3656 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3657 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | rc = -EOPNOTSUPP; |
| 3659 | goto setACLerrorExit; |
| 3660 | } |
| 3661 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3662 | pSMB->SetupCount = 1; |
| 3663 | pSMB->Reserved3 = 0; |
| 3664 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3665 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3666 | byte_count = 3 /* pad */ + params + data_count; |
| 3667 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3668 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3669 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3670 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3671 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3672 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3674 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3675 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3676 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3677 | cifs_dbg(FYI, "Set POSIX ACL returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | |
| 3679 | setACLerrorExit: |
| 3680 | cifs_buf_release(pSMB); |
| 3681 | if (rc == -EAGAIN) |
| 3682 | goto setAclRetry; |
| 3683 | return rc; |
| 3684 | } |
| 3685 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3686 | /* BB fix tabs in this function FIXME BB */ |
| 3687 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3688 | CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3689 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3690 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3691 | int rc = 0; |
| 3692 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3693 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3694 | int bytes_returned; |
| 3695 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3696 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3697 | cifs_dbg(FYI, "In GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3698 | if (tcon == NULL) |
| 3699 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3700 | |
| 3701 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3702 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3703 | (void **) &pSMBr); |
| 3704 | if (rc) |
| 3705 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3706 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3707 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3708 | pSMB->t2.TotalDataCount = 0; |
| 3709 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3710 | /* BB find exact max data count below from sess structure BB */ |
| 3711 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3712 | pSMB->t2.MaxSetupCount = 0; |
| 3713 | pSMB->t2.Reserved = 0; |
| 3714 | pSMB->t2.Flags = 0; |
| 3715 | pSMB->t2.Timeout = 0; |
| 3716 | pSMB->t2.Reserved2 = 0; |
| 3717 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3718 | Fid) - 4); |
| 3719 | pSMB->t2.DataCount = 0; |
| 3720 | pSMB->t2.DataOffset = 0; |
| 3721 | pSMB->t2.SetupCount = 1; |
| 3722 | pSMB->t2.Reserved3 = 0; |
| 3723 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3724 | byte_count = params + 1 /* pad */ ; |
| 3725 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3726 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3727 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3728 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3729 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3730 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3731 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3732 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3733 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3734 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3735 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3736 | cifs_dbg(FYI, "error %d in GetExtAttr\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3737 | } else { |
| 3738 | /* decode response */ |
| 3739 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3740 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3741 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3742 | /* If rc should we check for EOPNOSUPP and |
| 3743 | disable the srvino flag? or in caller? */ |
| 3744 | rc = -EIO; /* bad smb */ |
| 3745 | else { |
| 3746 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3747 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3748 | struct file_chattr_info *pfinfo; |
| 3749 | /* BB Do we need a cast or hash here ? */ |
| 3750 | if (count != 16) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3751 | cifs_dbg(FYI, "Illegal size ret in GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3752 | rc = -EIO; |
| 3753 | goto GetExtAttrOut; |
| 3754 | } |
| 3755 | pfinfo = (struct file_chattr_info *) |
| 3756 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3757 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3758 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3759 | } |
| 3760 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3761 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3762 | cifs_buf_release(pSMB); |
| 3763 | if (rc == -EAGAIN) |
| 3764 | goto GetExtAttrRetry; |
| 3765 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3768 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3770 | #ifdef CONFIG_CIFS_ACL |
| 3771 | /* |
| 3772 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3773 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3774 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3775 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3776 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3777 | * by caller |
| 3778 | */ |
| 3779 | static int |
| 3780 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3781 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3782 | void **ret_buf) |
| 3783 | { |
| 3784 | int rc; |
| 3785 | __u32 temp_offset; |
| 3786 | struct smb_com_ntransact_req *pSMB; |
| 3787 | |
| 3788 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3789 | (void **)&pSMB); |
| 3790 | if (rc) |
| 3791 | return rc; |
| 3792 | *ret_buf = (void *)pSMB; |
| 3793 | pSMB->Reserved = 0; |
| 3794 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3795 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3796 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3797 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3798 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3799 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3800 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3801 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3802 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3803 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3804 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3805 | return 0; |
| 3806 | } |
| 3807 | |
| 3808 | static int |
| 3809 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3810 | __u32 *pparmlen, __u32 *pdatalen) |
| 3811 | { |
| 3812 | char *end_of_smb; |
| 3813 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3814 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3815 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3816 | |
| 3817 | *pdatalen = 0; |
| 3818 | *pparmlen = 0; |
| 3819 | |
| 3820 | if (buf == NULL) |
| 3821 | return -EINVAL; |
| 3822 | |
| 3823 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3824 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3825 | bcc = get_bcc(&pSMBr->hdr); |
| 3826 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3827 | (char *)&pSMBr->ByteCount; |
| 3828 | |
| 3829 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3830 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3831 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3832 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3833 | |
| 3834 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3835 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3836 | |
| 3837 | /* should we also check that parm and data areas do not overlap? */ |
| 3838 | if (*ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3839 | cifs_dbg(FYI, "parms start after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3840 | return -EINVAL; |
| 3841 | } else if (parm_count + *ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3842 | cifs_dbg(FYI, "parm end after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3843 | return -EINVAL; |
| 3844 | } else if (*ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3845 | cifs_dbg(FYI, "data starts after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3846 | return -EINVAL; |
| 3847 | } else if (data_count + *ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3848 | cifs_dbg(FYI, "data %p + count %d (%p) past smb end %p start %p\n", |
| 3849 | *ppdata, data_count, (data_count + *ppdata), |
| 3850 | end_of_smb, pSMBr); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3851 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3852 | } else if (parm_count + data_count > bcc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3853 | cifs_dbg(FYI, "parm count and data count larger than SMB\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3854 | return -EINVAL; |
| 3855 | } |
| 3856 | *pdatalen = data_count; |
| 3857 | *pparmlen = parm_count; |
| 3858 | return 0; |
| 3859 | } |
| 3860 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3861 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3862 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3863 | CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3864 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3865 | { |
| 3866 | int rc = 0; |
| 3867 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3868 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3869 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3870 | struct kvec rsp_iov; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3871 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3872 | cifs_dbg(FYI, "GetCifsACL\n"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3873 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3874 | *pbuflen = 0; |
| 3875 | *acl_inf = NULL; |
| 3876 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3877 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3878 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3879 | if (rc) |
| 3880 | return rc; |
| 3881 | |
| 3882 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3883 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3884 | pSMB->MaxSetupCount = 0; |
| 3885 | pSMB->Fid = fid; /* file handle always le */ |
| 3886 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3887 | CIFS_ACL_DACL); |
| 3888 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3889 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3890 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3891 | 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] | 3892 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3893 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3894 | 0, &rsp_iov); |
| 3895 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3896 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3897 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3898 | cifs_dbg(FYI, "Send error in QuerySecDesc = %d\n", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3899 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3900 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3901 | __u32 parm_len; |
| 3902 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3903 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3904 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3905 | |
| 3906 | /* validate_nttransact */ |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3907 | rc = validate_ntransact(rsp_iov.iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3908 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3909 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3910 | goto qsec_out; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3911 | pSMBr = (struct smb_com_ntransact_rsp *)rsp_iov.iov_base; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3912 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3913 | cifs_dbg(FYI, "smb %p parm %p data %p\n", |
| 3914 | pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3915 | |
| 3916 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3917 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3918 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3919 | goto qsec_out; |
| 3920 | } |
| 3921 | |
| 3922 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3923 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3924 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3925 | if (acl_len != *pbuflen) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3926 | cifs_dbg(VFS, "acl length %d does not match %d\n", |
| 3927 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3928 | if (*pbuflen > acl_len) |
| 3929 | *pbuflen = acl_len; |
| 3930 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3931 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3932 | /* check if buffer is big enough for the acl |
| 3933 | header followed by the smallest SID */ |
| 3934 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3935 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3936 | cifs_dbg(VFS, "bad acl length %d\n", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3937 | rc = -EINVAL; |
| 3938 | *pbuflen = 0; |
| 3939 | } else { |
Silviu-Mihai Popescu | f7f7c18 | 2013-03-11 18:22:32 +0200 | [diff] [blame] | 3940 | *acl_inf = kmemdup(pdata, *pbuflen, GFP_KERNEL); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3941 | if (*acl_inf == NULL) { |
| 3942 | *pbuflen = 0; |
| 3943 | rc = -ENOMEM; |
| 3944 | } |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3945 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3946 | } |
| 3947 | qsec_out: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3948 | free_rsp_buf(buf_type, rsp_iov.iov_base); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3949 | return rc; |
| 3950 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3951 | |
| 3952 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3953 | CIFSSMBSetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3954 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3955 | { |
| 3956 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3957 | int rc = 0; |
| 3958 | int bytes_returned = 0; |
| 3959 | SET_SEC_DESC_REQ *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3960 | void *pSMBr; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3961 | |
| 3962 | setCifsAclRetry: |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3963 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3964 | if (rc) |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3965 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3966 | |
| 3967 | pSMB->MaxSetupCount = 0; |
| 3968 | pSMB->Reserved = 0; |
| 3969 | |
| 3970 | param_count = 8; |
| 3971 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3972 | data_count = acllen; |
| 3973 | data_offset = param_offset + param_count; |
| 3974 | byte_count = 3 /* pad */ + param_count; |
| 3975 | |
| 3976 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3977 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3978 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3979 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3980 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3981 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3982 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3983 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3984 | pSMB->SetupCount = 0; |
| 3985 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3986 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3987 | |
| 3988 | pSMB->Fid = fid; /* file handle always le */ |
| 3989 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3990 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3991 | |
| 3992 | if (pntsd && acllen) { |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3993 | memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + |
| 3994 | data_offset, pntsd, acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3995 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3996 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3997 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3998 | |
| 3999 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4000 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4001 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4002 | cifs_dbg(FYI, "SetCIFSACL bytes_returned: %d, rc: %d\n", |
| 4003 | bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4004 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4005 | cifs_dbg(FYI, "Set CIFS ACL returned %d\n", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4006 | cifs_buf_release(pSMB); |
| 4007 | |
| 4008 | if (rc == -EAGAIN) |
| 4009 | goto setCifsAclRetry; |
| 4010 | |
| 4011 | return (rc); |
| 4012 | } |
| 4013 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 4014 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4015 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4016 | /* Legacy Query Path Information call for lookup to old servers such |
| 4017 | as Win9x/WinME */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4018 | int |
| 4019 | SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, |
| 4020 | const char *search_name, FILE_ALL_INFO *data, |
| 4021 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4022 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4023 | QUERY_INFORMATION_REQ *pSMB; |
| 4024 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4025 | int rc = 0; |
| 4026 | int bytes_returned; |
| 4027 | int name_len; |
| 4028 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4029 | cifs_dbg(FYI, "In SMBQPath path %s\n", search_name); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4030 | QInfRetry: |
| 4031 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4032 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4033 | if (rc) |
| 4034 | return rc; |
| 4035 | |
| 4036 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4037 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4038 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4039 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4040 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4041 | name_len++; /* trailing null */ |
| 4042 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4043 | } else { |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4044 | name_len = strnlen(search_name, PATH_MAX); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4045 | name_len++; /* trailing null */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4046 | strncpy(pSMB->FileName, search_name, name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4047 | } |
| 4048 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4049 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4050 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4051 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 4052 | |
| 4053 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4054 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4055 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4056 | cifs_dbg(FYI, "Send error in QueryInfo = %d\n", rc); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4057 | } else if (data) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4058 | struct timespec ts; |
| 4059 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4060 | |
| 4061 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4062 | /* BB FIXME - add time zone adjustment BB */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4063 | memset(data, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4064 | ts.tv_nsec = 0; |
| 4065 | ts.tv_sec = time; |
| 4066 | /* decode time fields */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4067 | data->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
| 4068 | data->LastWriteTime = data->ChangeTime; |
| 4069 | data->LastAccessTime = 0; |
| 4070 | data->AllocationSize = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4071 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4072 | data->EndOfFile = data->AllocationSize; |
| 4073 | data->Attributes = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4074 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4075 | } else |
| 4076 | rc = -EIO; /* bad buffer passed in */ |
| 4077 | |
| 4078 | cifs_buf_release(pSMB); |
| 4079 | |
| 4080 | if (rc == -EAGAIN) |
| 4081 | goto QInfRetry; |
| 4082 | |
| 4083 | return rc; |
| 4084 | } |
| 4085 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4086 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4087 | CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4088 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 4089 | { |
| 4090 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4091 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4092 | int rc = 0; |
| 4093 | int bytes_returned; |
| 4094 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4095 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4096 | QFileInfoRetry: |
| 4097 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4098 | (void **) &pSMBr); |
| 4099 | if (rc) |
| 4100 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4101 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4102 | params = 2 /* level */ + 2 /* fid */; |
| 4103 | pSMB->t2.TotalDataCount = 0; |
| 4104 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4105 | /* BB find exact max data count below from sess structure BB */ |
| 4106 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4107 | pSMB->t2.MaxSetupCount = 0; |
| 4108 | pSMB->t2.Reserved = 0; |
| 4109 | pSMB->t2.Flags = 0; |
| 4110 | pSMB->t2.Timeout = 0; |
| 4111 | pSMB->t2.Reserved2 = 0; |
| 4112 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4113 | Fid) - 4); |
| 4114 | pSMB->t2.DataCount = 0; |
| 4115 | pSMB->t2.DataOffset = 0; |
| 4116 | pSMB->t2.SetupCount = 1; |
| 4117 | pSMB->t2.Reserved3 = 0; |
| 4118 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4119 | byte_count = params + 1 /* pad */ ; |
| 4120 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4121 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4122 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 4123 | pSMB->Pad = 0; |
| 4124 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4125 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4126 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4127 | |
| 4128 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4129 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4130 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4131 | cifs_dbg(FYI, "Send error in QFileInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4132 | } else { /* decode response */ |
| 4133 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4134 | |
| 4135 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4136 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4137 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4138 | rc = -EIO; /* bad smb */ |
| 4139 | else if (pFindData) { |
| 4140 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4141 | memcpy((char *) pFindData, |
| 4142 | (char *) &pSMBr->hdr.Protocol + |
| 4143 | data_offset, sizeof(FILE_ALL_INFO)); |
| 4144 | } else |
| 4145 | rc = -ENOMEM; |
| 4146 | } |
| 4147 | cifs_buf_release(pSMB); |
| 4148 | if (rc == -EAGAIN) |
| 4149 | goto QFileInfoRetry; |
| 4150 | |
| 4151 | return rc; |
| 4152 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4155 | CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4156 | const char *search_name, FILE_ALL_INFO *data, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4157 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4158 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | { |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4160 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4162 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4163 | int rc = 0; |
| 4164 | int bytes_returned; |
| 4165 | int name_len; |
| 4166 | __u16 params, byte_count; |
| 4167 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4168 | /* cifs_dbg(FYI, "In QPathInfo path %s\n", search_name); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | QPathInfoRetry: |
| 4170 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4171 | (void **) &pSMBr); |
| 4172 | if (rc) |
| 4173 | return rc; |
| 4174 | |
| 4175 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4176 | name_len = |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4177 | cifsConvertToUTF16((__le16 *) pSMB->FileName, search_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4178 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | name_len++; /* trailing null */ |
| 4180 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4181 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4182 | name_len = strnlen(search_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | name_len++; /* trailing null */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4184 | strncpy(pSMB->FileName, search_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | } |
| 4186 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4187 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | pSMB->TotalDataCount = 0; |
| 4189 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4190 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4191 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | pSMB->MaxSetupCount = 0; |
| 4193 | pSMB->Reserved = 0; |
| 4194 | pSMB->Flags = 0; |
| 4195 | pSMB->Timeout = 0; |
| 4196 | pSMB->Reserved2 = 0; |
| 4197 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4198 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4199 | pSMB->DataCount = 0; |
| 4200 | pSMB->DataOffset = 0; |
| 4201 | pSMB->SetupCount = 1; |
| 4202 | pSMB->Reserved3 = 0; |
| 4203 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4204 | byte_count = params + 1 /* pad */ ; |
| 4205 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4206 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4207 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4208 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4209 | else |
| 4210 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4212 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4214 | |
| 4215 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4216 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4217 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4218 | cifs_dbg(FYI, "Send error in QPathInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | } else { /* decode response */ |
| 4220 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4221 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4222 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4223 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4224 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4226 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4227 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4228 | last field */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4229 | else if (data) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4230 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4232 | |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4233 | /* |
| 4234 | * On legacy responses we do not read the last field, |
| 4235 | * EAsize, fortunately since it varies by subdialect and |
| 4236 | * also note it differs on Set vs Get, ie two bytes or 4 |
| 4237 | * bytes depending but we don't care here. |
| 4238 | */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4239 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4240 | size = sizeof(FILE_INFO_STANDARD); |
| 4241 | else |
| 4242 | size = sizeof(FILE_ALL_INFO); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4243 | memcpy((char *) data, (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4244 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | } else |
| 4246 | rc = -ENOMEM; |
| 4247 | } |
| 4248 | cifs_buf_release(pSMB); |
| 4249 | if (rc == -EAGAIN) |
| 4250 | goto QPathInfoRetry; |
| 4251 | |
| 4252 | return rc; |
| 4253 | } |
| 4254 | |
| 4255 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4256 | CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4257 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4258 | { |
| 4259 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4260 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4261 | int rc = 0; |
| 4262 | int bytes_returned; |
| 4263 | __u16 params, byte_count; |
| 4264 | |
| 4265 | UnixQFileInfoRetry: |
| 4266 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4267 | (void **) &pSMBr); |
| 4268 | if (rc) |
| 4269 | return rc; |
| 4270 | |
| 4271 | params = 2 /* level */ + 2 /* fid */; |
| 4272 | pSMB->t2.TotalDataCount = 0; |
| 4273 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4274 | /* BB find exact max data count below from sess structure BB */ |
| 4275 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4276 | pSMB->t2.MaxSetupCount = 0; |
| 4277 | pSMB->t2.Reserved = 0; |
| 4278 | pSMB->t2.Flags = 0; |
| 4279 | pSMB->t2.Timeout = 0; |
| 4280 | pSMB->t2.Reserved2 = 0; |
| 4281 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4282 | Fid) - 4); |
| 4283 | pSMB->t2.DataCount = 0; |
| 4284 | pSMB->t2.DataOffset = 0; |
| 4285 | pSMB->t2.SetupCount = 1; |
| 4286 | pSMB->t2.Reserved3 = 0; |
| 4287 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4288 | byte_count = params + 1 /* pad */ ; |
| 4289 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4290 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4291 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4292 | pSMB->Pad = 0; |
| 4293 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4294 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4295 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4296 | |
| 4297 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4298 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4299 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4300 | cifs_dbg(FYI, "Send error in UnixQFileInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4301 | } else { /* decode response */ |
| 4302 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4303 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4304 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4305 | 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] | 4306 | rc = -EIO; /* bad smb */ |
| 4307 | } else { |
| 4308 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4309 | memcpy((char *) pFindData, |
| 4310 | (char *) &pSMBr->hdr.Protocol + |
| 4311 | data_offset, |
| 4312 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4313 | } |
| 4314 | } |
| 4315 | |
| 4316 | cifs_buf_release(pSMB); |
| 4317 | if (rc == -EAGAIN) |
| 4318 | goto UnixQFileInfoRetry; |
| 4319 | |
| 4320 | return rc; |
| 4321 | } |
| 4322 | |
| 4323 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4324 | CIFSSMBUnixQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4326 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4327 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | { |
| 4329 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4330 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4331 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4332 | int rc = 0; |
| 4333 | int bytes_returned = 0; |
| 4334 | int name_len; |
| 4335 | __u16 params, byte_count; |
| 4336 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4337 | cifs_dbg(FYI, "In QPathInfo (Unix) the path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | UnixQPathInfoRetry: |
| 4339 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4340 | (void **) &pSMBr); |
| 4341 | if (rc) |
| 4342 | return rc; |
| 4343 | |
| 4344 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4345 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4346 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4347 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | name_len++; /* trailing null */ |
| 4349 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4350 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | name_len = strnlen(searchName, PATH_MAX); |
| 4352 | name_len++; /* trailing null */ |
| 4353 | strncpy(pSMB->FileName, searchName, name_len); |
| 4354 | } |
| 4355 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4356 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | pSMB->TotalDataCount = 0; |
| 4358 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4359 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4360 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | pSMB->MaxSetupCount = 0; |
| 4362 | pSMB->Reserved = 0; |
| 4363 | pSMB->Flags = 0; |
| 4364 | pSMB->Timeout = 0; |
| 4365 | pSMB->Reserved2 = 0; |
| 4366 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4367 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | pSMB->DataCount = 0; |
| 4369 | pSMB->DataOffset = 0; |
| 4370 | pSMB->SetupCount = 1; |
| 4371 | pSMB->Reserved3 = 0; |
| 4372 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4373 | byte_count = params + 1 /* pad */ ; |
| 4374 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4375 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4376 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4377 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4378 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4380 | |
| 4381 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4382 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4383 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4384 | cifs_dbg(FYI, "Send error in UnixQPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | } else { /* decode response */ |
| 4386 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4387 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4388 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4389 | 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] | 4390 | rc = -EIO; /* bad smb */ |
| 4391 | } else { |
| 4392 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4393 | memcpy((char *) pFindData, |
| 4394 | (char *) &pSMBr->hdr.Protocol + |
| 4395 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4396 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | } |
| 4398 | } |
| 4399 | cifs_buf_release(pSMB); |
| 4400 | if (rc == -EAGAIN) |
| 4401 | goto UnixQPathInfoRetry; |
| 4402 | |
| 4403 | return rc; |
| 4404 | } |
| 4405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4407 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4408 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4409 | const char *searchName, struct cifs_sb_info *cifs_sb, |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4410 | __u16 *pnetfid, __u16 search_flags, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4411 | struct cifs_search_info *psrch_inf, bool msearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | { |
| 4413 | /* level 257 SMB_ */ |
| 4414 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4415 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4416 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | int rc = 0; |
| 4418 | int bytes_returned = 0; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4419 | int name_len, remap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | __u16 params, byte_count; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4421 | struct nls_table *nls_codepage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4423 | cifs_dbg(FYI, "In FindFirst for %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | |
| 4425 | findFirstRetry: |
| 4426 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4427 | (void **) &pSMBr); |
| 4428 | if (rc) |
| 4429 | return rc; |
| 4430 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4431 | nls_codepage = cifs_sb->local_nls; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 4432 | remap = cifs_remap(cifs_sb); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4435 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4436 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4437 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4438 | /* We can not add the asterik earlier in case |
| 4439 | it got remapped to 0xF03A as if it were part of the |
| 4440 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | name_len *= 2; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4442 | if (msearch) { |
| 4443 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
| 4444 | pSMB->FileName[name_len+1] = 0; |
| 4445 | pSMB->FileName[name_len+2] = '*'; |
| 4446 | pSMB->FileName[name_len+3] = 0; |
| 4447 | name_len += 4; /* now the trailing null */ |
| 4448 | /* null terminate just in case */ |
| 4449 | pSMB->FileName[name_len] = 0; |
| 4450 | pSMB->FileName[name_len+1] = 0; |
| 4451 | name_len += 2; |
| 4452 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | } else { /* BB add check for overrun of SMB buf BB */ |
| 4454 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4456 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | free buffer exit; BB */ |
| 4458 | strncpy(pSMB->FileName, searchName, name_len); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4459 | if (msearch) { |
| 4460 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
| 4461 | pSMB->FileName[name_len+1] = '*'; |
| 4462 | pSMB->FileName[name_len+2] = 0; |
| 4463 | name_len += 3; |
| 4464 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | params = 12 + name_len /* includes null */ ; |
| 4468 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4469 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4470 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | pSMB->MaxSetupCount = 0; |
| 4472 | pSMB->Reserved = 0; |
| 4473 | pSMB->Flags = 0; |
| 4474 | pSMB->Timeout = 0; |
| 4475 | pSMB->Reserved2 = 0; |
| 4476 | byte_count = params + 1 /* pad */ ; |
| 4477 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4478 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4479 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4480 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4481 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | pSMB->DataCount = 0; |
| 4483 | pSMB->DataOffset = 0; |
| 4484 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4485 | pSMB->Reserved3 = 0; |
| 4486 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4487 | pSMB->SearchAttributes = |
| 4488 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4489 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4490 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4491 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4493 | |
| 4494 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4495 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4496 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4498 | |
| 4499 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4500 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4501 | cifs_stats_inc(&tcon->stats.cifs_stats.num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4503 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4504 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4506 | cifs_dbg(FYI, "Error in FindFirst = %d\n", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4507 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4508 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | |
| 4510 | /* BB eventually could optimize out free and realloc of buf */ |
| 4511 | /* for this case */ |
| 4512 | if (rc == -EAGAIN) |
| 4513 | goto findFirstRetry; |
| 4514 | } else { /* decode response */ |
| 4515 | /* BB remember to free buffer if error BB */ |
| 4516 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4517 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4518 | unsigned int lnoff; |
| 4519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4521 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4523 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | |
| 4525 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4526 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4527 | psrch_inf->srch_entries_start = |
| 4528 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4531 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4532 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4533 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4534 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4536 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4538 | psrch_inf->entries_in_buffer = |
| 4539 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4540 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4542 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4543 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4544 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4545 | psrch_inf->last_entry = NULL; |
| 4546 | return rc; |
| 4547 | } |
| 4548 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4549 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4550 | lnoff; |
| 4551 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4552 | if (pnetfid) |
| 4553 | *pnetfid = parms->SearchHandle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | } else { |
| 4555 | cifs_buf_release(pSMB); |
| 4556 | } |
| 4557 | } |
| 4558 | |
| 4559 | return rc; |
| 4560 | } |
| 4561 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4562 | int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, |
| 4563 | __u16 searchHandle, __u16 search_flags, |
| 4564 | struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | { |
| 4566 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4567 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4568 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | char *response_data; |
| 4570 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4571 | int bytes_returned; |
| 4572 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | __u16 params, byte_count; |
| 4574 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4575 | cifs_dbg(FYI, "In FindNext\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4577 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | return -ENOENT; |
| 4579 | |
| 4580 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4581 | (void **) &pSMBr); |
| 4582 | if (rc) |
| 4583 | return rc; |
| 4584 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4585 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | byte_count = 0; |
| 4587 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4588 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4589 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | pSMB->MaxSetupCount = 0; |
| 4591 | pSMB->Reserved = 0; |
| 4592 | pSMB->Flags = 0; |
| 4593 | pSMB->Timeout = 0; |
| 4594 | pSMB->Reserved2 = 0; |
| 4595 | pSMB->ParameterOffset = cpu_to_le16( |
| 4596 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4597 | pSMB->DataCount = 0; |
| 4598 | pSMB->DataOffset = 0; |
| 4599 | pSMB->SetupCount = 1; |
| 4600 | pSMB->Reserved3 = 0; |
| 4601 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4602 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4603 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4604 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4606 | pSMB->ResumeKey = psrch_inf->resume_key; |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4607 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | |
| 4609 | name_len = psrch_inf->resume_name_len; |
| 4610 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4611 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4613 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4614 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4615 | pSMB->ResumeFileName[name_len] = 0; |
| 4616 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | } else { |
| 4618 | rc = -EINVAL; |
| 4619 | goto FNext2_err_exit; |
| 4620 | } |
| 4621 | byte_count = params + 1 /* pad */ ; |
| 4622 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4623 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4624 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4628 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4629 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4630 | if (rc) { |
| 4631 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4632 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4633 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4634 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | } else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4636 | cifs_dbg(FYI, "FindNext returned = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | } else { /* decode response */ |
| 4638 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4639 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4640 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4641 | unsigned int lnoff; |
| 4642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4644 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4645 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4647 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4649 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4650 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4651 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4652 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4653 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4654 | cifs_small_buf_release( |
| 4655 | psrch_inf->ntwrk_buf_start); |
| 4656 | else |
| 4657 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | psrch_inf->srch_entries_start = response_data; |
| 4659 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4660 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4661 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4662 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4664 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4665 | psrch_inf->entries_in_buffer = |
| 4666 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4667 | psrch_inf->index_of_last_entry += |
| 4668 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4669 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4670 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4671 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4672 | psrch_inf->last_entry = NULL; |
| 4673 | return rc; |
| 4674 | } else |
| 4675 | psrch_inf->last_entry = |
| 4676 | psrch_inf->srch_entries_start + lnoff; |
| 4677 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4678 | /* cifs_dbg(FYI, "fnxt2 entries in buf %d index_of_last %d\n", |
| 4679 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | |
| 4681 | /* BB fixme add unlock here */ |
| 4682 | } |
| 4683 | |
| 4684 | } |
| 4685 | |
| 4686 | /* BB On error, should we leave previous search buf (and count and |
| 4687 | last entry fields) intact or free the previous one? */ |
| 4688 | |
| 4689 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4690 | since file handle passed in no longer valid */ |
| 4691 | FNext2_err_exit: |
| 4692 | if (rc != 0) |
| 4693 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4694 | return rc; |
| 4695 | } |
| 4696 | |
| 4697 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4698 | CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4699 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | { |
| 4701 | int rc = 0; |
| 4702 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4704 | cifs_dbg(FYI, "In CIFSSMBFindClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4706 | |
| 4707 | /* no sense returning error if session restarted |
| 4708 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4709 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | return 0; |
| 4711 | if (rc) |
| 4712 | return rc; |
| 4713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | pSMB->FileID = searchHandle; |
| 4715 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4716 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4717 | cifs_small_buf_release(pSMB); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4718 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4719 | cifs_dbg(VFS, "Send error in FindClose = %d\n", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4720 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4721 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | |
| 4723 | /* Since session is dead, search handle closed on server already */ |
| 4724 | if (rc == -EAGAIN) |
| 4725 | rc = 0; |
| 4726 | |
| 4727 | return rc; |
| 4728 | } |
| 4729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4731 | CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4732 | const char *search_name, __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4733 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | { |
| 4735 | int rc = 0; |
| 4736 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4737 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4738 | int name_len, bytes_returned; |
| 4739 | __u16 params, byte_count; |
| 4740 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4741 | cifs_dbg(FYI, "In GetSrvInodeNum for %s\n", search_name); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4742 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4743 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | |
| 4745 | GetInodeNumberRetry: |
| 4746 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4747 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | if (rc) |
| 4749 | return rc; |
| 4750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4752 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4753 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4754 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4755 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | name_len++; /* trailing null */ |
| 4757 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4758 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4759 | name_len = strnlen(search_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | name_len++; /* trailing null */ |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4761 | strncpy(pSMB->FileName, search_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4765 | pSMB->TotalDataCount = 0; |
| 4766 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4767 | /* BB find exact max data count below from sess structure BB */ |
| 4768 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4769 | pSMB->MaxSetupCount = 0; |
| 4770 | pSMB->Reserved = 0; |
| 4771 | pSMB->Flags = 0; |
| 4772 | pSMB->Timeout = 0; |
| 4773 | pSMB->Reserved2 = 0; |
| 4774 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4775 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | pSMB->DataCount = 0; |
| 4777 | pSMB->DataOffset = 0; |
| 4778 | pSMB->SetupCount = 1; |
| 4779 | pSMB->Reserved3 = 0; |
| 4780 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4781 | byte_count = params + 1 /* pad */ ; |
| 4782 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4783 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4784 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4785 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4786 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4788 | |
| 4789 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4790 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4791 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4792 | cifs_dbg(FYI, "error %d in QueryInternalInfo\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | } else { |
| 4794 | /* decode response */ |
| 4795 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4797 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | /* If rc should we check for EOPNOSUPP and |
| 4799 | disable the srvino flag? or in caller? */ |
| 4800 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4801 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4803 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4804 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4805 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4806 | if (count < 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4807 | cifs_dbg(FYI, "Illegal size ret in QryIntrnlInf\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | rc = -EIO; |
| 4809 | goto GetInodeNumOut; |
| 4810 | } |
| 4811 | pfinfo = (struct file_internal_info *) |
| 4812 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4813 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | } |
| 4815 | } |
| 4816 | GetInodeNumOut: |
| 4817 | cifs_buf_release(pSMB); |
| 4818 | if (rc == -EAGAIN) |
| 4819 | goto GetInodeNumberRetry; |
| 4820 | return rc; |
| 4821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | |
| 4823 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4824 | CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4825 | const char *search_name, struct dfs_info3_param **target_nodes, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4826 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4827 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | { |
| 4829 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4830 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4831 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | int rc = 0; |
| 4833 | int bytes_returned; |
| 4834 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4836 | *num_of_nodes = 0; |
| 4837 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4839 | cifs_dbg(FYI, "In GetDFSRefer the path %s\n", search_name); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4840 | if (ses == NULL || ses->tcon_ipc == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | return -ENODEV; |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4843 | getDFSRetry: |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4844 | rc = smb_init(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | (void **) &pSMBr); |
| 4846 | if (rc) |
| 4847 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4848 | |
| 4849 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4850 | but should never be null here anyway */ |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 4851 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4852 | pSMB->hdr.Tid = ses->tcon_ipc->tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4854 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4856 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | |
| 4859 | if (ses->capabilities & CAP_UNICODE) { |
| 4860 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4861 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4862 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4863 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4864 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | name_len++; /* trailing null */ |
| 4866 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4867 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4868 | name_len = strnlen(search_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4869 | name_len++; /* trailing null */ |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4870 | strncpy(pSMB->RequestFileName, search_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | } |
| 4872 | |
Dan Carpenter | 65c3b20 | 2015-04-30 17:30:24 +0300 | [diff] [blame] | 4873 | if (ses->server->sign) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 4874 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4875 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4876 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4879 | pSMB->TotalDataCount = 0; |
| 4880 | pSMB->DataCount = 0; |
| 4881 | pSMB->DataOffset = 0; |
| 4882 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4883 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4884 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | pSMB->MaxSetupCount = 0; |
| 4886 | pSMB->Reserved = 0; |
| 4887 | pSMB->Flags = 0; |
| 4888 | pSMB->Timeout = 0; |
| 4889 | pSMB->Reserved2 = 0; |
| 4890 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4891 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | pSMB->SetupCount = 1; |
| 4893 | pSMB->Reserved3 = 0; |
| 4894 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4895 | byte_count = params + 3 /* pad */ ; |
| 4896 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4897 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4898 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4899 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4900 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4901 | |
| 4902 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4903 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4904 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4905 | cifs_dbg(FYI, "Send error in GetDFSRefer = %d\n", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4906 | goto GetDFSRefExit; |
| 4907 | } |
| 4908 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4910 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4911 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4912 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4913 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4915 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4916 | cifs_dbg(FYI, "Decoding GetDFSRefer response BCC: %d Offset %d\n", |
| 4917 | get_bcc(&pSMBr->hdr), le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4918 | |
| 4919 | /* parse returned result into more usable form */ |
Aurelien Aptel | 4ecce92 | 2017-02-13 16:03:47 +0100 | [diff] [blame] | 4920 | rc = parse_dfs_referrals(&pSMBr->dfs_data, |
| 4921 | le16_to_cpu(pSMBr->t2.DataCount), |
| 4922 | num_of_nodes, target_nodes, nls_codepage, |
| 4923 | remap, search_name, |
Steve French | 284316d | 2017-03-02 15:42:48 -0600 | [diff] [blame] | 4924 | (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) != 0); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4927 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | |
| 4929 | if (rc == -EAGAIN) |
| 4930 | goto getDFSRetry; |
| 4931 | |
| 4932 | return rc; |
| 4933 | } |
| 4934 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4935 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4936 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4937 | SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 4938 | struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4939 | { |
| 4940 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4941 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4942 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4943 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4944 | int rc = 0; |
| 4945 | int bytes_returned = 0; |
| 4946 | __u16 params, byte_count; |
| 4947 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4948 | cifs_dbg(FYI, "OldQFSInfo\n"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4949 | oldQFSInfoRetry: |
| 4950 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4951 | (void **) &pSMBr); |
| 4952 | if (rc) |
| 4953 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4954 | |
| 4955 | params = 2; /* level */ |
| 4956 | pSMB->TotalDataCount = 0; |
| 4957 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4958 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4959 | pSMB->MaxSetupCount = 0; |
| 4960 | pSMB->Reserved = 0; |
| 4961 | pSMB->Flags = 0; |
| 4962 | pSMB->Timeout = 0; |
| 4963 | pSMB->Reserved2 = 0; |
| 4964 | byte_count = params + 1 /* pad */ ; |
| 4965 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4966 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4967 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4968 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4969 | pSMB->DataCount = 0; |
| 4970 | pSMB->DataOffset = 0; |
| 4971 | pSMB->SetupCount = 1; |
| 4972 | pSMB->Reserved3 = 0; |
| 4973 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4974 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4975 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4976 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4977 | |
| 4978 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4979 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4980 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4981 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4982 | } else { /* decode response */ |
| 4983 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4984 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4985 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4986 | rc = -EIO; /* bad smb */ |
| 4987 | else { |
| 4988 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4989 | cifs_dbg(FYI, "qfsinf resp BCC: %d Offset %d\n", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4990 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4991 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4992 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4993 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4994 | FSData->f_bsize = |
| 4995 | le16_to_cpu(response_data->BytesPerSector) * |
| 4996 | le32_to_cpu(response_data-> |
| 4997 | SectorsPerAllocationUnit); |
| 4998 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4999 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5000 | FSData->f_bfree = FSData->f_bavail = |
| 5001 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5002 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5003 | (unsigned long long)FSData->f_blocks, |
| 5004 | (unsigned long long)FSData->f_bfree, |
| 5005 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5006 | } |
| 5007 | } |
| 5008 | cifs_buf_release(pSMB); |
| 5009 | |
| 5010 | if (rc == -EAGAIN) |
| 5011 | goto oldQFSInfoRetry; |
| 5012 | |
| 5013 | return rc; |
| 5014 | } |
| 5015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5017 | CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 5018 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | { |
| 5020 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5021 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5022 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5023 | FILE_SYSTEM_INFO *response_data; |
| 5024 | int rc = 0; |
| 5025 | int bytes_returned = 0; |
| 5026 | __u16 params, byte_count; |
| 5027 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5028 | cifs_dbg(FYI, "In QFSInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | QFSInfoRetry: |
| 5030 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5031 | (void **) &pSMBr); |
| 5032 | if (rc) |
| 5033 | return rc; |
| 5034 | |
| 5035 | params = 2; /* level */ |
| 5036 | pSMB->TotalDataCount = 0; |
| 5037 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5038 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | pSMB->MaxSetupCount = 0; |
| 5040 | pSMB->Reserved = 0; |
| 5041 | pSMB->Flags = 0; |
| 5042 | pSMB->Timeout = 0; |
| 5043 | pSMB->Reserved2 = 0; |
| 5044 | byte_count = params + 1 /* pad */ ; |
| 5045 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5046 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5047 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5048 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5049 | pSMB->DataCount = 0; |
| 5050 | pSMB->DataOffset = 0; |
| 5051 | pSMB->SetupCount = 1; |
| 5052 | pSMB->Reserved3 = 0; |
| 5053 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5054 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5055 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5057 | |
| 5058 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5059 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5060 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5061 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5063 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5065 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5066 | rc = -EIO; /* bad smb */ |
| 5067 | else { |
| 5068 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | |
| 5070 | response_data = |
| 5071 | (FILE_SYSTEM_INFO |
| 5072 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5073 | data_offset); |
| 5074 | FSData->f_bsize = |
| 5075 | le32_to_cpu(response_data->BytesPerSector) * |
| 5076 | le32_to_cpu(response_data-> |
| 5077 | SectorsPerAllocationUnit); |
| 5078 | FSData->f_blocks = |
| 5079 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 5080 | FSData->f_bfree = FSData->f_bavail = |
| 5081 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5082 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5083 | (unsigned long long)FSData->f_blocks, |
| 5084 | (unsigned long long)FSData->f_bfree, |
| 5085 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | } |
| 5087 | } |
| 5088 | cifs_buf_release(pSMB); |
| 5089 | |
| 5090 | if (rc == -EAGAIN) |
| 5091 | goto QFSInfoRetry; |
| 5092 | |
| 5093 | return rc; |
| 5094 | } |
| 5095 | |
| 5096 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5097 | CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | { |
| 5099 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5100 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5101 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5102 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5103 | int rc = 0; |
| 5104 | int bytes_returned = 0; |
| 5105 | __u16 params, byte_count; |
| 5106 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5107 | cifs_dbg(FYI, "In QFSAttributeInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | QFSAttributeRetry: |
| 5109 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5110 | (void **) &pSMBr); |
| 5111 | if (rc) |
| 5112 | return rc; |
| 5113 | |
| 5114 | params = 2; /* level */ |
| 5115 | pSMB->TotalDataCount = 0; |
| 5116 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5117 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5118 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | pSMB->MaxSetupCount = 0; |
| 5120 | pSMB->Reserved = 0; |
| 5121 | pSMB->Flags = 0; |
| 5122 | pSMB->Timeout = 0; |
| 5123 | pSMB->Reserved2 = 0; |
| 5124 | byte_count = params + 1 /* pad */ ; |
| 5125 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5126 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5127 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5128 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | pSMB->DataCount = 0; |
| 5130 | pSMB->DataOffset = 0; |
| 5131 | pSMB->SetupCount = 1; |
| 5132 | pSMB->Reserved3 = 0; |
| 5133 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5134 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5135 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5136 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5137 | |
| 5138 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5139 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5140 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5141 | cifs_dbg(VFS, "Send error in QFSAttributeInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5142 | } else { /* decode response */ |
| 5143 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5144 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5145 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5146 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | rc = -EIO; /* bad smb */ |
| 5148 | } else { |
| 5149 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5150 | response_data = |
| 5151 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5152 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5153 | data_offset); |
| 5154 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5155 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5156 | } |
| 5157 | } |
| 5158 | cifs_buf_release(pSMB); |
| 5159 | |
| 5160 | if (rc == -EAGAIN) |
| 5161 | goto QFSAttributeRetry; |
| 5162 | |
| 5163 | return rc; |
| 5164 | } |
| 5165 | |
| 5166 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5167 | CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5168 | { |
| 5169 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5170 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5171 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5172 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5173 | int rc = 0; |
| 5174 | int bytes_returned = 0; |
| 5175 | __u16 params, byte_count; |
| 5176 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5177 | cifs_dbg(FYI, "In QFSDeviceInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | QFSDeviceRetry: |
| 5179 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5180 | (void **) &pSMBr); |
| 5181 | if (rc) |
| 5182 | return rc; |
| 5183 | |
| 5184 | params = 2; /* level */ |
| 5185 | pSMB->TotalDataCount = 0; |
| 5186 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5187 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5188 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | pSMB->MaxSetupCount = 0; |
| 5190 | pSMB->Reserved = 0; |
| 5191 | pSMB->Flags = 0; |
| 5192 | pSMB->Timeout = 0; |
| 5193 | pSMB->Reserved2 = 0; |
| 5194 | byte_count = params + 1 /* pad */ ; |
| 5195 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5196 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5197 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5198 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | |
| 5200 | pSMB->DataCount = 0; |
| 5201 | pSMB->DataOffset = 0; |
| 5202 | pSMB->SetupCount = 1; |
| 5203 | pSMB->Reserved3 = 0; |
| 5204 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5205 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5206 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5207 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5208 | |
| 5209 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5210 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5211 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5212 | cifs_dbg(FYI, "Send error in QFSDeviceInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | } else { /* decode response */ |
| 5214 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5215 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5216 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5217 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5218 | rc = -EIO; /* bad smb */ |
| 5219 | else { |
| 5220 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5221 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5222 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5223 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | data_offset); |
| 5225 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5226 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5227 | } |
| 5228 | } |
| 5229 | cifs_buf_release(pSMB); |
| 5230 | |
| 5231 | if (rc == -EAGAIN) |
| 5232 | goto QFSDeviceRetry; |
| 5233 | |
| 5234 | return rc; |
| 5235 | } |
| 5236 | |
| 5237 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5238 | CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | { |
| 5240 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5241 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5242 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5243 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5244 | int rc = 0; |
| 5245 | int bytes_returned = 0; |
| 5246 | __u16 params, byte_count; |
| 5247 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5248 | cifs_dbg(FYI, "In QFSUnixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5249 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5250 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5251 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5252 | if (rc) |
| 5253 | return rc; |
| 5254 | |
| 5255 | params = 2; /* level */ |
| 5256 | pSMB->TotalDataCount = 0; |
| 5257 | pSMB->DataCount = 0; |
| 5258 | pSMB->DataOffset = 0; |
| 5259 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5260 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5261 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | pSMB->MaxSetupCount = 0; |
| 5263 | pSMB->Reserved = 0; |
| 5264 | pSMB->Flags = 0; |
| 5265 | pSMB->Timeout = 0; |
| 5266 | pSMB->Reserved2 = 0; |
| 5267 | byte_count = params + 1 /* pad */ ; |
| 5268 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5269 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5270 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5271 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | pSMB->SetupCount = 1; |
| 5273 | pSMB->Reserved3 = 0; |
| 5274 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5275 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5276 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5278 | |
| 5279 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5280 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5281 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5282 | cifs_dbg(VFS, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5283 | } else { /* decode response */ |
| 5284 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5285 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5286 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 | rc = -EIO; /* bad smb */ |
| 5288 | } else { |
| 5289 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5290 | response_data = |
| 5291 | (FILE_SYSTEM_UNIX_INFO |
| 5292 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5293 | data_offset); |
| 5294 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5295 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | } |
| 5297 | } |
| 5298 | cifs_buf_release(pSMB); |
| 5299 | |
| 5300 | if (rc == -EAGAIN) |
| 5301 | goto QFSUnixRetry; |
| 5302 | |
| 5303 | |
| 5304 | return rc; |
| 5305 | } |
| 5306 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5307 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5308 | CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5309 | { |
| 5310 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5311 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5312 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5313 | int rc = 0; |
| 5314 | int bytes_returned = 0; |
| 5315 | __u16 params, param_offset, offset, byte_count; |
| 5316 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5317 | cifs_dbg(FYI, "In SETFSUnixInfo\n"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5318 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5319 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5320 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5321 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5322 | if (rc) |
| 5323 | return rc; |
| 5324 | |
| 5325 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5326 | pSMB->MaxSetupCount = 0; |
| 5327 | pSMB->Reserved = 0; |
| 5328 | pSMB->Flags = 0; |
| 5329 | pSMB->Timeout = 0; |
| 5330 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5331 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5332 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5333 | offset = param_offset + params; |
| 5334 | |
| 5335 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5336 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5337 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5338 | pSMB->SetupCount = 1; |
| 5339 | pSMB->Reserved3 = 0; |
| 5340 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5341 | byte_count = 1 /* pad */ + params + 12; |
| 5342 | |
| 5343 | pSMB->DataCount = cpu_to_le16(12); |
| 5344 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5345 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5346 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5347 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5348 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5349 | |
| 5350 | /* Params. */ |
| 5351 | pSMB->FileNum = 0; |
| 5352 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5353 | |
| 5354 | /* Data. */ |
| 5355 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5356 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5357 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5358 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5359 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5360 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5361 | |
| 5362 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5363 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5364 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5365 | cifs_dbg(VFS, "Send error in SETFSUnixInfo = %d\n", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5366 | } else { /* decode response */ |
| 5367 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5368 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5369 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5370 | } |
| 5371 | cifs_buf_release(pSMB); |
| 5372 | |
| 5373 | if (rc == -EAGAIN) |
| 5374 | goto SETFSUnixRetry; |
| 5375 | |
| 5376 | return rc; |
| 5377 | } |
| 5378 | |
| 5379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5380 | |
| 5381 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5382 | CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5383 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5384 | { |
| 5385 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5386 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5387 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5388 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5389 | int rc = 0; |
| 5390 | int bytes_returned = 0; |
| 5391 | __u16 params, byte_count; |
| 5392 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5393 | cifs_dbg(FYI, "In QFSPosixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5394 | QFSPosixRetry: |
| 5395 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5396 | (void **) &pSMBr); |
| 5397 | if (rc) |
| 5398 | return rc; |
| 5399 | |
| 5400 | params = 2; /* level */ |
| 5401 | pSMB->TotalDataCount = 0; |
| 5402 | pSMB->DataCount = 0; |
| 5403 | pSMB->DataOffset = 0; |
| 5404 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5405 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5406 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5407 | pSMB->MaxSetupCount = 0; |
| 5408 | pSMB->Reserved = 0; |
| 5409 | pSMB->Flags = 0; |
| 5410 | pSMB->Timeout = 0; |
| 5411 | pSMB->Reserved2 = 0; |
| 5412 | byte_count = params + 1 /* pad */ ; |
| 5413 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5414 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5415 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5416 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 | pSMB->SetupCount = 1; |
| 5418 | pSMB->Reserved3 = 0; |
| 5419 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5420 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5421 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5422 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5423 | |
| 5424 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5425 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5426 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5427 | cifs_dbg(FYI, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5428 | } else { /* decode response */ |
| 5429 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5430 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5431 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5432 | rc = -EIO; /* bad smb */ |
| 5433 | } else { |
| 5434 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5435 | response_data = |
| 5436 | (FILE_SYSTEM_POSIX_INFO |
| 5437 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5438 | data_offset); |
| 5439 | FSData->f_bsize = |
| 5440 | le32_to_cpu(response_data->BlockSize); |
| 5441 | FSData->f_blocks = |
| 5442 | le64_to_cpu(response_data->TotalBlocks); |
| 5443 | FSData->f_bfree = |
| 5444 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5445 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5446 | FSData->f_bavail = FSData->f_bfree; |
| 5447 | } else { |
| 5448 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5449 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5450 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5451 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5453 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5454 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5455 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5456 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5457 | } |
| 5458 | } |
| 5459 | cifs_buf_release(pSMB); |
| 5460 | |
| 5461 | if (rc == -EAGAIN) |
| 5462 | goto QFSPosixRetry; |
| 5463 | |
| 5464 | return rc; |
| 5465 | } |
| 5466 | |
| 5467 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5468 | /* |
| 5469 | * We can not use write of zero bytes trick to set file size due to need for |
| 5470 | * large file support. Also note that this SetPathInfo is preferred to |
| 5471 | * SetFileInfo based method in next routine which is only needed to work around |
| 5472 | * a sharing violation bugin Samba which this routine can run into. |
| 5473 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5475 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5476 | const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, |
| 5477 | bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 | { |
| 5479 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5480 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5481 | struct file_end_of_file_info *parm_data; |
| 5482 | int name_len; |
| 5483 | int rc = 0; |
| 5484 | int bytes_returned = 0; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 5485 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5488 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5489 | cifs_dbg(FYI, "In SetEOF\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | SetEOFRetry: |
| 5491 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5492 | (void **) &pSMBr); |
| 5493 | if (rc) |
| 5494 | return rc; |
| 5495 | |
| 5496 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5497 | name_len = |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5498 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
| 5499 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | name_len++; /* trailing null */ |
| 5501 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5502 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5503 | name_len = strnlen(file_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | name_len++; /* trailing null */ |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5505 | strncpy(pSMB->FileName, file_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | } |
| 5507 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5508 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5510 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5511 | pSMB->MaxSetupCount = 0; |
| 5512 | pSMB->Reserved = 0; |
| 5513 | pSMB->Flags = 0; |
| 5514 | pSMB->Timeout = 0; |
| 5515 | pSMB->Reserved2 = 0; |
| 5516 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5517 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | offset = param_offset + params; |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5519 | if (set_allocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5520 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5521 | pSMB->InformationLevel = |
| 5522 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5523 | else |
| 5524 | pSMB->InformationLevel = |
| 5525 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5526 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5527 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5528 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5529 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5530 | else |
| 5531 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5532 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | parm_data = |
| 5536 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5537 | offset); |
| 5538 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5539 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5540 | pSMB->SetupCount = 1; |
| 5541 | pSMB->Reserved3 = 0; |
| 5542 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5543 | byte_count = 3 /* pad */ + params + data_count; |
| 5544 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5545 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5546 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5547 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5548 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5549 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5550 | parm_data->FileSize = cpu_to_le64(size); |
| 5551 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5552 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5553 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5554 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5555 | cifs_dbg(FYI, "SetPathInfo (file size) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5556 | |
| 5557 | cifs_buf_release(pSMB); |
| 5558 | |
| 5559 | if (rc == -EAGAIN) |
| 5560 | goto SetEOFRetry; |
| 5561 | |
| 5562 | return rc; |
| 5563 | } |
| 5564 | |
| 5565 | int |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5566 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
| 5567 | struct cifsFileInfo *cfile, __u64 size, bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5568 | { |
| 5569 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5570 | struct file_end_of_file_info *parm_data; |
| 5571 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5572 | __u16 params, param_offset, offset, byte_count, count; |
| 5573 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5574 | cifs_dbg(FYI, "SetFileSize (via SetFileInfo) %lld\n", |
| 5575 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5576 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | if (rc) |
| 5579 | return rc; |
| 5580 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5581 | pSMB->hdr.Pid = cpu_to_le16((__u16)cfile->pid); |
| 5582 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(cfile->pid >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | params = 6; |
| 5585 | pSMB->MaxSetupCount = 0; |
| 5586 | pSMB->Reserved = 0; |
| 5587 | pSMB->Flags = 0; |
| 5588 | pSMB->Timeout = 0; |
| 5589 | pSMB->Reserved2 = 0; |
| 5590 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5591 | offset = param_offset + params; |
| 5592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5593 | count = sizeof(struct file_end_of_file_info); |
| 5594 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5595 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5596 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | pSMB->SetupCount = 1; |
| 5598 | pSMB->Reserved3 = 0; |
| 5599 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5600 | byte_count = 3 /* pad */ + params + count; |
| 5601 | pSMB->DataCount = cpu_to_le16(count); |
| 5602 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5603 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5604 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5605 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5606 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5607 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5608 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5609 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5610 | parm_data->FileSize = cpu_to_le64(size); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5611 | pSMB->Fid = cfile->fid.netfid; |
| 5612 | if (set_allocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5613 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5614 | pSMB->InformationLevel = |
| 5615 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5616 | else |
| 5617 | pSMB->InformationLevel = |
| 5618 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5619 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5621 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5622 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | else |
| 5624 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5625 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5626 | } |
| 5627 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5628 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5629 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5630 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5631 | cifs_small_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5632 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5633 | cifs_dbg(FYI, "Send error in SetFileInfo (SetFileSize) = %d\n", |
| 5634 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | } |
| 5636 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5637 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5638 | since file handle passed in no longer valid */ |
| 5639 | |
| 5640 | return rc; |
| 5641 | } |
| 5642 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5643 | /* 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] | 5644 | an open handle, rather than by pathname - this is awkward due to |
| 5645 | potential access conflicts on the open, but it is unavoidable for these |
| 5646 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5647 | time and resort to the original setpathinfo level which takes the ancient |
| 5648 | DOS time format with 2 second granularity */ |
| 5649 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5650 | CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5651 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5652 | { |
| 5653 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5654 | char *data_offset; |
| 5655 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | __u16 params, param_offset, offset, byte_count, count; |
| 5657 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5658 | cifs_dbg(FYI, "Set Times (via SetFileInfo)\n"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5659 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | if (rc) |
| 5662 | return rc; |
| 5663 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5664 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5665 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | params = 6; |
| 5668 | pSMB->MaxSetupCount = 0; |
| 5669 | pSMB->Reserved = 0; |
| 5670 | pSMB->Flags = 0; |
| 5671 | pSMB->Timeout = 0; |
| 5672 | pSMB->Reserved2 = 0; |
| 5673 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5674 | offset = param_offset + params; |
| 5675 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5676 | data_offset = (char *)pSMB + |
| 5677 | offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5678 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5679 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5680 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5681 | /* BB find max SMB PDU from sess */ |
| 5682 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | pSMB->SetupCount = 1; |
| 5684 | pSMB->Reserved3 = 0; |
| 5685 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5686 | byte_count = 3 /* pad */ + params + count; |
| 5687 | pSMB->DataCount = cpu_to_le16(count); |
| 5688 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5689 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5690 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5691 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5692 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5693 | pSMB->Fid = fid; |
| 5694 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5695 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5696 | else |
| 5697 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5698 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5699 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5701 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5702 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5703 | cifs_small_buf_release(pSMB); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5704 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5705 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 5706 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5707 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5708 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5709 | since file handle passed in no longer valid */ |
| 5710 | |
| 5711 | return rc; |
| 5712 | } |
| 5713 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5714 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5715 | CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5716 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5717 | { |
| 5718 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5719 | char *data_offset; |
| 5720 | int rc = 0; |
| 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 File Disposition (via SetFileInfo)\n"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5724 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5725 | |
| 5726 | if (rc) |
| 5727 | return rc; |
| 5728 | |
| 5729 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5730 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5731 | |
| 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 | |
| 5741 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5742 | |
| 5743 | count = 1; |
| 5744 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5745 | /* BB find max SMB PDU from sess */ |
| 5746 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5747 | pSMB->SetupCount = 1; |
| 5748 | pSMB->Reserved3 = 0; |
| 5749 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5750 | byte_count = 3 /* pad */ + params + count; |
| 5751 | pSMB->DataCount = cpu_to_le16(count); |
| 5752 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5753 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5754 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5755 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5756 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5757 | pSMB->Fid = fid; |
| 5758 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5759 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5760 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5761 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5762 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5763 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5764 | cifs_small_buf_release(pSMB); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5765 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5766 | cifs_dbg(FYI, "Send error in SetFileDisposition = %d\n", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5767 | |
| 5768 | return rc; |
| 5769 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5770 | |
| 5771 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5772 | CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5773 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5774 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | { |
| 5776 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5777 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5778 | int name_len; |
| 5779 | int rc = 0; |
| 5780 | int bytes_returned = 0; |
| 5781 | char *data_offset; |
| 5782 | __u16 params, param_offset, offset, byte_count, count; |
| 5783 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5784 | cifs_dbg(FYI, "In SetTimes\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5785 | |
| 5786 | SetTimesRetry: |
| 5787 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5788 | (void **) &pSMBr); |
| 5789 | if (rc) |
| 5790 | return rc; |
| 5791 | |
| 5792 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5793 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5794 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5795 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5796 | name_len++; /* trailing null */ |
| 5797 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5798 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5799 | name_len = strnlen(fileName, PATH_MAX); |
| 5800 | name_len++; /* trailing null */ |
| 5801 | strncpy(pSMB->FileName, fileName, name_len); |
| 5802 | } |
| 5803 | |
| 5804 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5805 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5807 | /* BB find max SMB PDU from sess structure BB */ |
| 5808 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5809 | pSMB->MaxSetupCount = 0; |
| 5810 | pSMB->Reserved = 0; |
| 5811 | pSMB->Flags = 0; |
| 5812 | pSMB->Timeout = 0; |
| 5813 | pSMB->Reserved2 = 0; |
| 5814 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5815 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5816 | offset = param_offset + params; |
| 5817 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5818 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5819 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5820 | pSMB->SetupCount = 1; |
| 5821 | pSMB->Reserved3 = 0; |
| 5822 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5823 | byte_count = 3 /* pad */ + params + count; |
| 5824 | |
| 5825 | pSMB->DataCount = cpu_to_le16(count); |
| 5826 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5827 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5828 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5829 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5830 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5831 | else |
| 5832 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5833 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5834 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5835 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5837 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5838 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5839 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5840 | cifs_dbg(FYI, "SetPathInfo (times) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5841 | |
| 5842 | cifs_buf_release(pSMB); |
| 5843 | |
| 5844 | if (rc == -EAGAIN) |
| 5845 | goto SetTimesRetry; |
| 5846 | |
| 5847 | return rc; |
| 5848 | } |
| 5849 | |
| 5850 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5851 | /* Can be used to set attributes */ |
| 5852 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5853 | handling it anyway and NT4 was what we thought it would be needed for |
| 5854 | Do not delete it until we prove whether needed for Win9x though */ |
| 5855 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5856 | CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5857 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5858 | { |
| 5859 | SETATTR_REQ *pSMB = NULL; |
| 5860 | SETATTR_RSP *pSMBr = NULL; |
| 5861 | int rc = 0; |
| 5862 | int bytes_returned; |
| 5863 | int name_len; |
| 5864 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5865 | cifs_dbg(FYI, "In SetAttrLegacy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5866 | |
| 5867 | SetAttrLgcyRetry: |
| 5868 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5869 | (void **) &pSMBr); |
| 5870 | if (rc) |
| 5871 | return rc; |
| 5872 | |
| 5873 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5874 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5875 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 5876 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5877 | name_len++; /* trailing null */ |
| 5878 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5879 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | name_len = strnlen(fileName, PATH_MAX); |
| 5881 | name_len++; /* trailing null */ |
| 5882 | strncpy(pSMB->fileName, fileName, name_len); |
| 5883 | } |
| 5884 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5885 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5886 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5887 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5888 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5889 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5890 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5891 | cifs_dbg(FYI, "Error in LegacySetAttr = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5892 | |
| 5893 | cifs_buf_release(pSMB); |
| 5894 | |
| 5895 | if (rc == -EAGAIN) |
| 5896 | goto SetAttrLgcyRetry; |
| 5897 | |
| 5898 | return rc; |
| 5899 | } |
| 5900 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5901 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5902 | static void |
| 5903 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5904 | const struct cifs_unix_set_info_args *args) |
| 5905 | { |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5906 | u64 uid = NO_CHANGE_64, gid = NO_CHANGE_64; |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5907 | u64 mode = args->mode; |
| 5908 | |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5909 | if (uid_valid(args->uid)) |
| 5910 | uid = from_kuid(&init_user_ns, args->uid); |
| 5911 | if (gid_valid(args->gid)) |
| 5912 | gid = from_kgid(&init_user_ns, args->gid); |
| 5913 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5914 | /* |
| 5915 | * Samba server ignores set of file size to zero due to bugs in some |
| 5916 | * older clients, but we should be precise - we use SetFileSize to |
| 5917 | * 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] | 5918 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5919 | * zero instead of -1 here |
| 5920 | */ |
| 5921 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5922 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5923 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5924 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5925 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5926 | data_offset->Uid = cpu_to_le64(uid); |
| 5927 | data_offset->Gid = cpu_to_le64(gid); |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5928 | /* better to leave device as zero when it is */ |
| 5929 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5930 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5931 | data_offset->Permissions = cpu_to_le64(mode); |
| 5932 | |
| 5933 | if (S_ISREG(mode)) |
| 5934 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5935 | else if (S_ISDIR(mode)) |
| 5936 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 5937 | else if (S_ISLNK(mode)) |
| 5938 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 5939 | else if (S_ISCHR(mode)) |
| 5940 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 5941 | else if (S_ISBLK(mode)) |
| 5942 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 5943 | else if (S_ISFIFO(mode)) |
| 5944 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 5945 | else if (S_ISSOCK(mode)) |
| 5946 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5947 | } |
| 5948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5949 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5950 | CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5951 | const struct cifs_unix_set_info_args *args, |
| 5952 | u16 fid, u32 pid_of_opener) |
| 5953 | { |
| 5954 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5955 | char *data_offset; |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5956 | int rc = 0; |
| 5957 | u16 params, param_offset, offset, byte_count, count; |
| 5958 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5959 | cifs_dbg(FYI, "Set Unix Info (via SetFileInfo)\n"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5960 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5961 | |
| 5962 | if (rc) |
| 5963 | return rc; |
| 5964 | |
| 5965 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5966 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5967 | |
| 5968 | params = 6; |
| 5969 | pSMB->MaxSetupCount = 0; |
| 5970 | pSMB->Reserved = 0; |
| 5971 | pSMB->Flags = 0; |
| 5972 | pSMB->Timeout = 0; |
| 5973 | pSMB->Reserved2 = 0; |
| 5974 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5975 | offset = param_offset + params; |
| 5976 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5977 | data_offset = (char *)pSMB + |
| 5978 | offsetof(struct smb_hdr, Protocol) + offset; |
| 5979 | |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5980 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 5981 | |
| 5982 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5983 | /* BB find max SMB PDU from sess */ |
| 5984 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5985 | pSMB->SetupCount = 1; |
| 5986 | pSMB->Reserved3 = 0; |
| 5987 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5988 | byte_count = 3 /* pad */ + params + count; |
| 5989 | pSMB->DataCount = cpu_to_le16(count); |
| 5990 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5991 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5992 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5993 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5994 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5995 | pSMB->Fid = fid; |
| 5996 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5997 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5998 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5999 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6000 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6001 | cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6002 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 6003 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 6004 | cifs_small_buf_release(pSMB); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6005 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6006 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 6007 | rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6008 | |
| 6009 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 6010 | since file handle passed in no longer valid */ |
| 6011 | |
| 6012 | return rc; |
| 6013 | } |
| 6014 | |
| 6015 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6016 | CIFSSMBUnixSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6017 | const char *file_name, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6018 | const struct cifs_unix_set_info_args *args, |
| 6019 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | { |
| 6021 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 6022 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 6023 | int name_len; |
| 6024 | int rc = 0; |
| 6025 | int bytes_returned = 0; |
| 6026 | FILE_UNIX_BASIC_INFO *data_offset; |
| 6027 | __u16 params, param_offset, offset, count, byte_count; |
| 6028 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6029 | cifs_dbg(FYI, "In SetUID/GID/Mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6030 | setPermsRetry: |
| 6031 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6032 | (void **) &pSMBr); |
| 6033 | if (rc) |
| 6034 | return rc; |
| 6035 | |
| 6036 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6037 | name_len = |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6038 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6039 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6040 | name_len++; /* trailing null */ |
| 6041 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 6042 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6043 | name_len = strnlen(file_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6044 | name_len++; /* trailing null */ |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6045 | strncpy(pSMB->FileName, file_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 6049 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6050 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6051 | /* BB find max SMB PDU from sess structure BB */ |
| 6052 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6053 | pSMB->MaxSetupCount = 0; |
| 6054 | pSMB->Reserved = 0; |
| 6055 | pSMB->Flags = 0; |
| 6056 | pSMB->Timeout = 0; |
| 6057 | pSMB->Reserved2 = 0; |
| 6058 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6059 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6060 | offset = param_offset + params; |
| 6061 | data_offset = |
| 6062 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 6063 | offset); |
| 6064 | memset(data_offset, 0, count); |
| 6065 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6066 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6067 | pSMB->SetupCount = 1; |
| 6068 | pSMB->Reserved3 = 0; |
| 6069 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6070 | byte_count = 3 /* pad */ + params + count; |
| 6071 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6072 | pSMB->DataCount = cpu_to_le16(count); |
| 6073 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6074 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6075 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6076 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6077 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6078 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6079 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6080 | |
| 6081 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6082 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6083 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6084 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6085 | cifs_dbg(FYI, "SetPathInfo (perms) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6086 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6087 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6088 | if (rc == -EAGAIN) |
| 6089 | goto setPermsRetry; |
| 6090 | return rc; |
| 6091 | } |
| 6092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6093 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6094 | /* |
| 6095 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 6096 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 6097 | * it looks for that attribute name and stuffs that value into the EAData |
| 6098 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 6099 | * buffer. In both cases, the return value is either the length of the |
| 6100 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 6101 | * the data isn't copied to it, but the length is returned. |
| 6102 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6103 | ssize_t |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6104 | CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6105 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6106 | char *EAData, size_t buf_size, |
Steve French | 67b4c88 | 2017-05-12 20:59:10 -0500 | [diff] [blame] | 6107 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | { |
| 6109 | /* BB assumes one setup word */ |
| 6110 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6111 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
Steve French | 67b4c88 | 2017-05-12 20:59:10 -0500 | [diff] [blame] | 6112 | int remap = cifs_remap(cifs_sb); |
| 6113 | struct nls_table *nls_codepage = cifs_sb->local_nls; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6114 | int rc = 0; |
| 6115 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6116 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6117 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6118 | struct fea *temp_fea; |
| 6119 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6120 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6121 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6122 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6123 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6124 | cifs_dbg(FYI, "In Query All EAs path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | QAllEAsRetry: |
| 6126 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6127 | (void **) &pSMBr); |
| 6128 | if (rc) |
| 6129 | return rc; |
| 6130 | |
| 6131 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6132 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6133 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6134 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6135 | list_len++; /* trailing null */ |
| 6136 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6138 | list_len = strnlen(searchName, PATH_MAX); |
| 6139 | list_len++; /* trailing null */ |
| 6140 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6141 | } |
| 6142 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6143 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | pSMB->TotalDataCount = 0; |
| 6145 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6146 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6147 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6148 | pSMB->MaxSetupCount = 0; |
| 6149 | pSMB->Reserved = 0; |
| 6150 | pSMB->Flags = 0; |
| 6151 | pSMB->Timeout = 0; |
| 6152 | pSMB->Reserved2 = 0; |
| 6153 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6154 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6155 | pSMB->DataCount = 0; |
| 6156 | pSMB->DataOffset = 0; |
| 6157 | pSMB->SetupCount = 1; |
| 6158 | pSMB->Reserved3 = 0; |
| 6159 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6160 | byte_count = params + 1 /* pad */ ; |
| 6161 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6162 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6163 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6164 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6165 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6166 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6167 | |
| 6168 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6169 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6170 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6171 | cifs_dbg(FYI, "Send error in QueryAllEAs = %d\n", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6172 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6173 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6174 | |
| 6175 | |
| 6176 | /* BB also check enough total bytes returned */ |
| 6177 | /* BB we need to improve the validity checking |
| 6178 | of these trans2 responses */ |
| 6179 | |
| 6180 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6181 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6182 | rc = -EIO; /* bad smb */ |
| 6183 | goto QAllEAsOut; |
| 6184 | } |
| 6185 | |
| 6186 | /* check that length of list is not more than bcc */ |
| 6187 | /* check that each entry does not go beyond length |
| 6188 | of list */ |
| 6189 | /* check that each element of each entry does not |
| 6190 | go beyond end of list */ |
| 6191 | /* validate_trans2_offsets() */ |
| 6192 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6193 | |
| 6194 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6195 | ea_response_data = (struct fealist *) |
| 6196 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6197 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6198 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6199 | cifs_dbg(FYI, "ea length %d\n", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6200 | if (list_len <= 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6201 | cifs_dbg(FYI, "empty EA list returned from server\n"); |
Steve French | 60977fc | 2014-03-25 19:46:36 -0500 | [diff] [blame] | 6202 | /* didn't find the named attribute */ |
| 6203 | if (ea_name) |
| 6204 | rc = -ENODATA; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6205 | goto QAllEAsOut; |
| 6206 | } |
| 6207 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6208 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6209 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6210 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6211 | cifs_dbg(FYI, "EA list appears to go beyond SMB\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6212 | rc = -EIO; |
| 6213 | goto QAllEAsOut; |
| 6214 | } |
| 6215 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6216 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6217 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6218 | temp_fea = ea_response_data->list; |
| 6219 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6220 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6221 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6222 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6223 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6224 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6225 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6226 | /* make sure we can read name_len and value_len */ |
| 6227 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6228 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6229 | rc = -EIO; |
| 6230 | goto QAllEAsOut; |
| 6231 | } |
| 6232 | |
| 6233 | name_len = temp_fea->name_len; |
| 6234 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6235 | list_len -= name_len + 1 + value_len; |
| 6236 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6237 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6238 | rc = -EIO; |
| 6239 | goto QAllEAsOut; |
| 6240 | } |
| 6241 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6242 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6243 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6244 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6245 | temp_ptr += name_len + 1; |
| 6246 | rc = value_len; |
| 6247 | if (buf_size == 0) |
| 6248 | goto QAllEAsOut; |
| 6249 | if ((size_t)value_len > buf_size) { |
| 6250 | rc = -ERANGE; |
| 6251 | goto QAllEAsOut; |
| 6252 | } |
| 6253 | memcpy(EAData, temp_ptr, value_len); |
| 6254 | goto QAllEAsOut; |
| 6255 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6256 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6257 | /* account for prefix user. and trailing null */ |
| 6258 | rc += (5 + 1 + name_len); |
| 6259 | if (rc < (int) buf_size) { |
| 6260 | memcpy(EAData, "user.", 5); |
| 6261 | EAData += 5; |
| 6262 | memcpy(EAData, temp_ptr, name_len); |
| 6263 | EAData += name_len; |
| 6264 | /* null terminate name */ |
| 6265 | *EAData = 0; |
| 6266 | ++EAData; |
| 6267 | } else if (buf_size == 0) { |
| 6268 | /* skip copy - calc size only */ |
| 6269 | } else { |
| 6270 | /* stop before overrun buffer */ |
| 6271 | rc = -ERANGE; |
| 6272 | break; |
| 6273 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6274 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6275 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6276 | temp_fea = (struct fea *)temp_ptr; |
| 6277 | } |
| 6278 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6279 | /* didn't find the named attribute */ |
| 6280 | if (ea_name) |
| 6281 | rc = -ENODATA; |
| 6282 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6283 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6284 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6285 | if (rc == -EAGAIN) |
| 6286 | goto QAllEAsRetry; |
| 6287 | |
| 6288 | return (ssize_t)rc; |
| 6289 | } |
| 6290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6292 | CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, |
| 6293 | const char *fileName, const char *ea_name, const void *ea_value, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6294 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 6295 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | { |
| 6297 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6298 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6299 | struct fealist *parm_data; |
| 6300 | int name_len; |
| 6301 | int rc = 0; |
| 6302 | int bytes_returned = 0; |
| 6303 | __u16 params, param_offset, byte_count, offset, count; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 6304 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6305 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6306 | cifs_dbg(FYI, "In SetEA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6307 | SetEARetry: |
| 6308 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6309 | (void **) &pSMBr); |
| 6310 | if (rc) |
| 6311 | return rc; |
| 6312 | |
| 6313 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6314 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6315 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6316 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6317 | name_len++; /* trailing null */ |
| 6318 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6319 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6320 | name_len = strnlen(fileName, PATH_MAX); |
| 6321 | name_len++; /* trailing null */ |
| 6322 | strncpy(pSMB->FileName, fileName, name_len); |
| 6323 | } |
| 6324 | |
| 6325 | params = 6 + name_len; |
| 6326 | |
| 6327 | /* done calculating parms using name_len of file name, |
| 6328 | now use name_len to calculate length of ea name |
| 6329 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6330 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6331 | name_len = 0; |
| 6332 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6333 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6334 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6335 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6337 | /* BB find max SMB PDU from sess */ |
| 6338 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6339 | pSMB->MaxSetupCount = 0; |
| 6340 | pSMB->Reserved = 0; |
| 6341 | pSMB->Flags = 0; |
| 6342 | pSMB->Timeout = 0; |
| 6343 | pSMB->Reserved2 = 0; |
| 6344 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6345 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6346 | offset = param_offset + params; |
| 6347 | pSMB->InformationLevel = |
| 6348 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6349 | |
Arnd Bergmann | ade7db9 | 2018-02-02 16:48:47 +0100 | [diff] [blame] | 6350 | parm_data = (void *)pSMB + offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6351 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6352 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6353 | pSMB->SetupCount = 1; |
| 6354 | pSMB->Reserved3 = 0; |
| 6355 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6356 | byte_count = 3 /* pad */ + params + count; |
| 6357 | pSMB->DataCount = cpu_to_le16(count); |
| 6358 | parm_data->list_len = cpu_to_le32(count); |
| 6359 | parm_data->list[0].EA_flags = 0; |
| 6360 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6361 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6362 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6363 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6364 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6365 | parm_data->list[0].name[name_len] = 0; |
| 6366 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6367 | /* caller ensures that ea_value_len is less than 64K but |
| 6368 | we need to ensure that it fits within the smb */ |
| 6369 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6370 | /*BB add length check to see if it would fit in |
| 6371 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6372 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6373 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6374 | memcpy(parm_data->list[0].name+name_len+1, |
| 6375 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6376 | |
| 6377 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6378 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6379 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6380 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6381 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6382 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6383 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6384 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6385 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6386 | cifs_dbg(FYI, "SetPathInfo (EA) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6387 | |
| 6388 | cifs_buf_release(pSMB); |
| 6389 | |
| 6390 | if (rc == -EAGAIN) |
| 6391 | goto SetEARetry; |
| 6392 | |
| 6393 | return rc; |
| 6394 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6395 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6396 | |
| 6397 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 6398 | /* |
| 6399 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 6400 | * to allow network clients (such as Windows) to display updated |
| 6401 | * lists of files in directory listings automatically when |
| 6402 | * files are added by one user when another user has the |
| 6403 | * same directory open on their desktop. The Linux cifs kernel |
| 6404 | * client hooked into the kernel side of this interface for |
| 6405 | * the same reason, but ironically when the VFS moved from |
| 6406 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 6407 | * network file system clients (the most obvious use case |
| 6408 | * for notify interfaces is when multiple users can update |
| 6409 | * the contents of the same directory - exactly what network |
| 6410 | * file systems can do) although the server (Samba) could |
| 6411 | * still use it. For the short term we leave the worker |
| 6412 | * function ifdeffed out (below) until inotify is fixed |
| 6413 | * in the VFS to make it easier to plug in network file |
| 6414 | * system clients. If inotify turns out to be permanently |
| 6415 | * incompatible for network fs clients, we could instead simply |
| 6416 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 6417 | */ |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6418 | int CIFSSMBNotify(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6419 | const int notify_subdirs, const __u16 netfid, |
| 6420 | __u32 filter, struct file *pfile, int multishot, |
| 6421 | const struct nls_table *nls_codepage) |
| 6422 | { |
| 6423 | int rc = 0; |
| 6424 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 6425 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 6426 | struct dir_notify_req *dnotify_req; |
| 6427 | int bytes_returned; |
| 6428 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6429 | cifs_dbg(FYI, "In CIFSSMBNotify for file handle %d\n", (int)netfid); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6430 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 6431 | (void **) &pSMBr); |
| 6432 | if (rc) |
| 6433 | return rc; |
| 6434 | |
| 6435 | pSMB->TotalParameterCount = 0 ; |
| 6436 | pSMB->TotalDataCount = 0; |
| 6437 | pSMB->MaxParameterCount = cpu_to_le32(2); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6438 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6439 | pSMB->MaxSetupCount = 4; |
| 6440 | pSMB->Reserved = 0; |
| 6441 | pSMB->ParameterOffset = 0; |
| 6442 | pSMB->DataCount = 0; |
| 6443 | pSMB->DataOffset = 0; |
| 6444 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 6445 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 6446 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6447 | if (notify_subdirs) |
| 6448 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 6449 | pSMB->Reserved2 = 0; |
| 6450 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 6451 | pSMB->Fid = netfid; /* file handle always le */ |
| 6452 | pSMB->ByteCount = 0; |
| 6453 | |
| 6454 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6455 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 6456 | CIFS_ASYNC_OP); |
| 6457 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6458 | cifs_dbg(FYI, "Error in Notify = %d\n", rc); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6459 | } else { |
| 6460 | /* Add file to outstanding requests */ |
| 6461 | /* BB change to kmem cache alloc */ |
| 6462 | dnotify_req = kmalloc( |
| 6463 | sizeof(struct dir_notify_req), |
| 6464 | GFP_KERNEL); |
| 6465 | if (dnotify_req) { |
| 6466 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 6467 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 6468 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 6469 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 6470 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 6471 | dnotify_req->netfid = netfid; |
| 6472 | dnotify_req->pfile = pfile; |
| 6473 | dnotify_req->filter = filter; |
| 6474 | dnotify_req->multishot = multishot; |
| 6475 | spin_lock(&GlobalMid_Lock); |
| 6476 | list_add_tail(&dnotify_req->lhead, |
| 6477 | &GlobalDnotifyReqList); |
| 6478 | spin_unlock(&GlobalMid_Lock); |
| 6479 | } else |
| 6480 | rc = -ENOMEM; |
| 6481 | } |
| 6482 | cifs_buf_release(pSMB); |
| 6483 | return rc; |
| 6484 | } |
| 6485 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |