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" |
Pavel Shilovsky | d919131 | 2019-12-10 11:44:52 -0800 | [diff] [blame] | 45 | #include "smb2proto.h" |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 46 | #include "fscache.h" |
Long Li | db223a5 | 2017-11-22 17:38:45 -0700 | [diff] [blame] | 47 | #include "smbdirect.h" |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 48 | #ifdef CONFIG_CIFS_DFS_UPCALL |
| 49 | #include "dfs_cache.h" |
| 50 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #ifdef CONFIG_CIFS_POSIX |
| 53 | static struct { |
| 54 | int index; |
| 55 | char *name; |
| 56 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 57 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 58 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 59 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 60 | #endif /* weak password hashing for legacy clients */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 61 | {CIFS_PROT, "\2NT LM 0.12"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 62 | {POSIX_PROT, "\2POSIX 2"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | {BAD_PROT, "\2"} |
| 64 | }; |
| 65 | #else |
| 66 | static struct { |
| 67 | int index; |
| 68 | char *name; |
| 69 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 70 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 71 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 18f75ca | 2006-10-01 03:13:01 +0000 | [diff] [blame] | 72 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 73 | #endif /* weak password hashing for legacy clients */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 74 | {CIFS_PROT, "\2NT LM 0.12"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | {BAD_PROT, "\2"} |
| 76 | }; |
| 77 | #endif |
| 78 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 79 | /* define the number of elements in the cifs dialect array */ |
| 80 | #ifdef CONFIG_CIFS_POSIX |
| 81 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 82 | #define CIFS_NUM_PROT 4 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 83 | #else |
| 84 | #define CIFS_NUM_PROT 2 |
| 85 | #endif /* CIFS_WEAK_PW_HASH */ |
| 86 | #else /* not posix */ |
| 87 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 88 | #define CIFS_NUM_PROT 3 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 89 | #else |
| 90 | #define CIFS_NUM_PROT 1 |
| 91 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
| 92 | #endif /* CIFS_POSIX */ |
| 93 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 94 | /* |
| 95 | * Mark as invalid, all open files on tree connections since they |
| 96 | * were closed when session to server was lost. |
| 97 | */ |
| 98 | void |
| 99 | cifs_mark_open_files_invalid(struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
| 101 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 102 | struct list_head *tmp; |
| 103 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 105 | /* list all files open on tree connection and mark them invalid */ |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 106 | spin_lock(&tcon->open_file_lock); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 107 | list_for_each_safe(tmp, tmp1, &tcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 108 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 109 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 110 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 112 | spin_unlock(&tcon->open_file_lock); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 113 | |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 114 | mutex_lock(&tcon->crfid.fid_mutex); |
| 115 | tcon->crfid.is_valid = false; |
Pavel Shilovsky | d919131 | 2019-12-10 11:44:52 -0800 | [diff] [blame] | 116 | /* cached handle is not valid, so SMB2_CLOSE won't be sent below */ |
| 117 | close_shroot_lease_locked(&tcon->crfid); |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 118 | memset(tcon->crfid.fid, 0, sizeof(struct cifs_fid)); |
| 119 | mutex_unlock(&tcon->crfid.fid_mutex); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 120 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 121 | /* |
| 122 | * BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 123 | * to this tcon. |
| 124 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 127 | /* reconnect the socket, tcon, and smb session if needed */ |
| 128 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 129 | cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 130 | { |
Jeff Layton | c4a5534 | 2011-07-28 12:40:36 -0400 | [diff] [blame] | 131 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 132 | struct cifs_ses *ses; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 133 | struct TCP_Server_Info *server; |
| 134 | struct nls_table *nls_codepage; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 135 | int retries; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 139 | * tcp and smb session status done differently for those three - in the |
| 140 | * calling routine |
| 141 | */ |
| 142 | if (!tcon) |
| 143 | return 0; |
| 144 | |
| 145 | ses = tcon->ses; |
| 146 | server = ses->server; |
| 147 | |
| 148 | /* |
| 149 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 150 | * have tcon) are allowed as we start force umount |
| 151 | */ |
| 152 | if (tcon->tidStatus == CifsExiting) { |
| 153 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 154 | smb_command != SMB_COM_OPEN_ANDX && |
| 155 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 156 | cifs_dbg(FYI, "can not send cmd %d while umounting\n", |
| 157 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 158 | return -ENODEV; |
| 159 | } |
| 160 | } |
| 161 | |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 162 | retries = server->nr_targets; |
| 163 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 164 | /* |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 165 | * Give demultiplex thread up to 10 seconds to each target available for |
| 166 | * reconnect -- should be greater than cifs socket timeout which is 7 |
| 167 | * seconds. |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 168 | */ |
| 169 | while (server->tcpStatus == CifsNeedReconnect) { |
Paulo Alcantara | 7ffbe65 | 2018-07-05 13:46:34 -0300 | [diff] [blame] | 170 | rc = wait_event_interruptible_timeout(server->response_q, |
| 171 | (server->tcpStatus != CifsNeedReconnect), |
| 172 | 10 * HZ); |
| 173 | if (rc < 0) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 174 | cifs_dbg(FYI, "%s: aborting reconnect due to a received signal by the process\n", |
| 175 | __func__); |
Paulo Alcantara | 7ffbe65 | 2018-07-05 13:46:34 -0300 | [diff] [blame] | 176 | return -ERESTARTSYS; |
| 177 | } |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 178 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 179 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 180 | if (server->tcpStatus != CifsNeedReconnect) |
| 181 | break; |
| 182 | |
Ronnie Sahlberg | 09c40b1 | 2020-02-06 13:55:19 +1000 | [diff] [blame] | 183 | if (retries && --retries) |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 184 | continue; |
| 185 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 186 | /* |
| 187 | * on "soft" mounts we wait once. Hard mounts keep |
| 188 | * retrying until process is killed or server comes |
| 189 | * back on-line |
| 190 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 191 | if (!tcon->retry) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 192 | cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 193 | return -EHOSTDOWN; |
| 194 | } |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 195 | retries = server->nr_targets; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 199 | return 0; |
| 200 | |
| 201 | nls_codepage = load_nls_default(); |
| 202 | |
| 203 | /* |
| 204 | * need to prevent multiple threads trying to simultaneously |
| 205 | * reconnect the same SMB session |
| 206 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 207 | mutex_lock(&ses->session_mutex); |
Samuel Cabrero | 76e7527 | 2017-07-11 12:44:39 +0200 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * Recheck after acquire mutex. If another thread is negotiating |
| 211 | * and the server never sends an answer the socket will be closed |
| 212 | * and tcpStatus set to reconnect. |
| 213 | */ |
| 214 | if (server->tcpStatus == CifsNeedReconnect) { |
| 215 | rc = -EHOSTDOWN; |
| 216 | mutex_unlock(&ses->session_mutex); |
| 217 | goto out; |
| 218 | } |
| 219 | |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 220 | rc = cifs_negotiate_protocol(0, ses); |
| 221 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 222 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 223 | |
| 224 | /* do we need to reconnect tcon? */ |
| 225 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 226 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 227 | goto out; |
| 228 | } |
| 229 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 230 | cifs_mark_open_files_invalid(tcon); |
Stefan Metzmacher | 565674d | 2020-07-21 09:36:38 -0300 | [diff] [blame] | 231 | rc = cifs_tree_connect(0, tcon, nls_codepage); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 232 | mutex_unlock(&ses->session_mutex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 233 | cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 234 | |
Steve French | c318e6c | 2018-04-04 14:08:52 -0500 | [diff] [blame] | 235 | if (rc) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 236 | pr_warn_once("reconnect tcon failed rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 237 | goto out; |
Steve French | c318e6c | 2018-04-04 14:08:52 -0500 | [diff] [blame] | 238 | } |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 239 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 240 | atomic_inc(&tconInfoReconnectCount); |
| 241 | |
| 242 | /* tell server Unix caps we support */ |
Stefan Metzmacher | 864138c | 2020-02-24 14:15:00 +0100 | [diff] [blame] | 243 | if (cap_unix(ses)) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 244 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 245 | |
| 246 | /* |
| 247 | * Removed call to reopen open files here. It is safer (and faster) to |
| 248 | * reopen files one at a time as needed in read and write. |
| 249 | * |
| 250 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 251 | */ |
| 252 | |
| 253 | out: |
| 254 | /* |
| 255 | * Check if handle based operation so we know whether we can continue |
| 256 | * or not without returning to caller to reset file handle |
| 257 | */ |
| 258 | switch (smb_command) { |
| 259 | case SMB_COM_READ_ANDX: |
| 260 | case SMB_COM_WRITE_ANDX: |
| 261 | case SMB_COM_CLOSE: |
| 262 | case SMB_COM_FIND_CLOSE2: |
| 263 | case SMB_COM_LOCKING_ANDX: |
| 264 | rc = -EAGAIN; |
| 265 | } |
| 266 | |
| 267 | unload_nls(nls_codepage); |
| 268 | return rc; |
| 269 | } |
| 270 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 271 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 272 | SMB information in the SMB header. If the return code is zero, this |
| 273 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 275 | small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 276 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 278 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 280 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 281 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | return rc; |
| 283 | |
| 284 | *request_buf = cifs_small_buf_get(); |
| 285 | if (*request_buf == NULL) { |
| 286 | /* BB should we add a retry in here if not a writepage? */ |
| 287 | return -ENOMEM; |
| 288 | } |
| 289 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 290 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 291 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 293 | if (tcon != NULL) |
| 294 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 295 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 296 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 299 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 300 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 301 | struct cifs_ses *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 302 | { |
| 303 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 304 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 305 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 306 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 307 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 308 | return rc; |
| 309 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 310 | buffer = (struct smb_hdr *)*request_buf; |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 311 | buffer->Mid = get_next_mid(ses->server); |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 312 | if (ses->capabilities & CAP_UNICODE) |
| 313 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 314 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 315 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 316 | |
| 317 | /* uid, tid can stay at zero as set in header assemble */ |
| 318 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 319 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 320 | this function is used after 1st of session setup requests */ |
| 321 | |
| 322 | return rc; |
| 323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | *request_buf = cifs_buf_get(); |
| 331 | if (*request_buf == NULL) { |
| 332 | /* BB should we add a retry in here if not a writepage? */ |
| 333 | return -ENOMEM; |
| 334 | } |
| 335 | /* Although the original thought was we needed the response buf for */ |
| 336 | /* potential retries of smb operations it turns out we can determine */ |
| 337 | /* from the mid flags when the request buffer can be resent without */ |
| 338 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 339 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 340 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 343 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 345 | if (tcon != NULL) |
| 346 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 347 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 352 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 353 | smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 354 | void **request_buf, void **response_buf) |
| 355 | { |
| 356 | int rc; |
| 357 | |
| 358 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 359 | if (rc) |
| 360 | return rc; |
| 361 | |
| 362 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 363 | } |
| 364 | |
| 365 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 366 | 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] | 367 | void **request_buf, void **response_buf) |
| 368 | { |
| 369 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 370 | return -EHOSTDOWN; |
| 371 | |
| 372 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 375 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 377 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 379 | /* check for plausible wct */ |
| 380 | if (pSMB->hdr.WordCount < 10) |
| 381 | goto vt2_err; |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 384 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 385 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 386 | goto vt2_err; |
| 387 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 388 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 389 | if (total_size >= 512) |
| 390 | goto vt2_err; |
| 391 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 392 | /* check that bcc is at least as big as parms + data, and that it is |
| 393 | * less than negotiated smb buffer |
| 394 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 395 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 396 | if (total_size > get_bcc(&pSMB->hdr) || |
| 397 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 398 | goto vt2_err; |
| 399 | |
| 400 | return 0; |
| 401 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 402 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 404 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 406 | |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 407 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 408 | decode_ext_sec_blob(struct cifs_ses *ses, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 409 | { |
| 410 | int rc = 0; |
| 411 | u16 count; |
| 412 | char *guid = pSMBr->u.extended_response.GUID; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 413 | struct TCP_Server_Info *server = ses->server; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 414 | |
| 415 | count = get_bcc(&pSMBr->hdr); |
| 416 | if (count < SMB1_CLIENT_GUID_SIZE) |
| 417 | return -EIO; |
| 418 | |
| 419 | spin_lock(&cifs_tcp_ses_lock); |
| 420 | if (server->srv_count > 1) { |
| 421 | spin_unlock(&cifs_tcp_ses_lock); |
| 422 | if (memcmp(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE) != 0) { |
| 423 | cifs_dbg(FYI, "server UID changed\n"); |
| 424 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 425 | } |
| 426 | } else { |
| 427 | spin_unlock(&cifs_tcp_ses_lock); |
| 428 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 429 | } |
| 430 | |
| 431 | if (count == SMB1_CLIENT_GUID_SIZE) { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 432 | server->sec_ntlmssp = true; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 433 | } else { |
| 434 | count -= SMB1_CLIENT_GUID_SIZE; |
| 435 | rc = decode_negTokenInit( |
| 436 | pSMBr->u.extended_response.SecurityBlob, count, server); |
| 437 | if (rc != 1) |
| 438 | return -EINVAL; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | return 0; |
| 442 | } |
| 443 | |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 444 | int |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 445 | cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required) |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 446 | { |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 447 | bool srv_sign_required = server->sec_mode & server->vals->signing_required; |
| 448 | bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled; |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 449 | bool mnt_sign_enabled = global_secflags & CIFSSEC_MAY_SIGN; |
| 450 | |
| 451 | /* |
| 452 | * Is signing required by mnt options? If not then check |
| 453 | * global_secflags to see if it is there. |
| 454 | */ |
| 455 | if (!mnt_sign_required) |
| 456 | mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) == |
| 457 | CIFSSEC_MUST_SIGN); |
| 458 | |
| 459 | /* |
| 460 | * If signing is required then it's automatically enabled too, |
| 461 | * otherwise, check to see if the secflags allow it. |
| 462 | */ |
| 463 | mnt_sign_enabled = mnt_sign_required ? mnt_sign_required : |
| 464 | (global_secflags & CIFSSEC_MAY_SIGN); |
| 465 | |
| 466 | /* If server requires signing, does client allow it? */ |
| 467 | if (srv_sign_required) { |
| 468 | if (!mnt_sign_enabled) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 469 | cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!\n"); |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 470 | return -ENOTSUPP; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 471 | } |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 472 | server->sign = true; |
| 473 | } |
| 474 | |
| 475 | /* If client requires signing, does server allow it? */ |
| 476 | if (mnt_sign_required) { |
| 477 | if (!srv_sign_enabled) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 478 | cifs_dbg(VFS, "Server does not support signing!\n"); |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 479 | return -ENOTSUPP; |
| 480 | } |
| 481 | server->sign = true; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 482 | } |
| 483 | |
Long Li | bb4c041 | 2018-04-17 12:17:08 -0700 | [diff] [blame] | 484 | if (cifs_rdma_enabled(server) && server->sign) |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 485 | cifs_dbg(VFS, "Signing is enabled, and RDMA read/write will be disabled\n"); |
Long Li | bb4c041 | 2018-04-17 12:17:08 -0700 | [diff] [blame] | 486 | |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 487 | return 0; |
| 488 | } |
| 489 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 490 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 491 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 492 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 493 | { |
| 494 | __s16 tmp; |
| 495 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
| 496 | |
| 497 | if (server->dialect != LANMAN_PROT && server->dialect != LANMAN2_PROT) |
| 498 | return -EOPNOTSUPP; |
| 499 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 500 | server->sec_mode = le16_to_cpu(rsp->SecurityMode); |
| 501 | server->maxReq = min_t(unsigned int, |
| 502 | le16_to_cpu(rsp->MaxMpxCount), |
| 503 | cifs_max_pending); |
| 504 | set_credits(server, server->maxReq); |
| 505 | server->maxBuf = le16_to_cpu(rsp->MaxBufSize); |
Jones Syue | 1f641d9 | 2020-04-13 09:37:23 +0800 | [diff] [blame] | 506 | /* set up max_read for readpages check */ |
| 507 | server->max_read = server->maxBuf; |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 508 | /* even though we do not use raw we might as well set this |
| 509 | accurately, in case we ever find a need for it */ |
| 510 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
| 511 | server->max_rw = 0xFF00; |
| 512 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 513 | } else { |
| 514 | server->max_rw = 0;/* do not need to use raw anyway */ |
| 515 | server->capabilities = CAP_MPX_MODE; |
| 516 | } |
| 517 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
| 518 | if (tmp == -1) { |
| 519 | /* OS/2 often does not set timezone therefore |
| 520 | * we must use server time to calc time zone. |
| 521 | * Could deviate slightly from the right zone. |
| 522 | * Smallest defined timezone difference is 15 minutes |
| 523 | * (i.e. Nepal). Rounding up/down is done to match |
| 524 | * this requirement. |
| 525 | */ |
| 526 | int val, seconds, remain, result; |
Arnd Bergmann | 9539020 | 2018-06-19 17:27:58 +0200 | [diff] [blame] | 527 | struct timespec64 ts; |
| 528 | time64_t utc = ktime_get_real_seconds(); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 529 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 530 | rsp->SrvTime.Time, 0); |
Arnd Bergmann | 9539020 | 2018-06-19 17:27:58 +0200 | [diff] [blame] | 531 | cifs_dbg(FYI, "SrvTime %lld sec since 1970 (utc: %lld) diff: %lld\n", |
| 532 | ts.tv_sec, utc, |
| 533 | utc - ts.tv_sec); |
Deepa Dinamani | e37fea5 | 2017-05-08 15:59:16 -0700 | [diff] [blame] | 534 | val = (int)(utc - ts.tv_sec); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 535 | seconds = abs(val); |
| 536 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
| 537 | remain = seconds % MIN_TZ_ADJ; |
| 538 | if (remain >= (MIN_TZ_ADJ / 2)) |
| 539 | result += MIN_TZ_ADJ; |
| 540 | if (val < 0) |
| 541 | result = -result; |
| 542 | server->timeAdj = result; |
| 543 | } else { |
| 544 | server->timeAdj = (int)tmp; |
| 545 | server->timeAdj *= 60; /* also in seconds */ |
| 546 | } |
| 547 | cifs_dbg(FYI, "server->timeAdj: %d seconds\n", server->timeAdj); |
| 548 | |
| 549 | |
| 550 | /* BB get server time for time conversions and add |
| 551 | code to use it and timezone since this is not UTC */ |
| 552 | |
| 553 | if (rsp->EncryptionKeyLength == |
| 554 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
| 555 | memcpy(server->cryptkey, rsp->EncryptionKey, |
| 556 | CIFS_CRYPTO_KEY_SIZE); |
| 557 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
| 558 | return -EIO; /* need cryptkey unless plain text */ |
| 559 | } |
| 560 | |
| 561 | cifs_dbg(FYI, "LANMAN negotiated\n"); |
| 562 | return 0; |
| 563 | } |
| 564 | #else |
| 565 | static inline int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 566 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 567 | { |
| 568 | cifs_dbg(VFS, "mount failed, cifs module not built with CIFS_WEAK_PW_HASH support\n"); |
| 569 | return -EOPNOTSUPP; |
| 570 | } |
| 571 | #endif |
| 572 | |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 573 | static bool |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 574 | should_set_ext_sec_flag(enum securityEnum sectype) |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 575 | { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 576 | switch (sectype) { |
| 577 | case RawNTLMSSP: |
| 578 | case Kerberos: |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 579 | return true; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 580 | case Unspecified: |
| 581 | if (global_secflags & |
| 582 | (CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)) |
| 583 | return true; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 584 | fallthrough; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 585 | default: |
| 586 | return false; |
| 587 | } |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | int |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 591 | CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
| 593 | NEGOTIATE_REQ *pSMB; |
| 594 | NEGOTIATE_RSP *pSMBr; |
| 595 | int rc = 0; |
| 596 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 597 | int i; |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 598 | struct TCP_Server_Info *server = ses->server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | u16 count; |
| 600 | |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 601 | if (!server) { |
| 602 | WARN(1, "%s: server is NULL!\n", __func__); |
| 603 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 607 | (void **) &pSMB, (void **) &pSMBr); |
| 608 | if (rc) |
| 609 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 610 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 611 | pSMB->hdr.Mid = get_next_mid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 612 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 613 | |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 614 | if (should_set_ext_sec_flag(ses->sectype)) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 615 | cifs_dbg(FYI, "Requesting extended security\n"); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 616 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 617 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 618 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 619 | count = 0; |
Stephen Rothwell | bcfb84a | 2018-09-03 13:15:58 +1000 | [diff] [blame] | 620 | /* |
| 621 | * We know that all the name entries in the protocols array |
| 622 | * are short (< 16 bytes anyway) and are NUL terminated. |
| 623 | */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 624 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Stephen Rothwell | bcfb84a | 2018-09-03 13:15:58 +1000 | [diff] [blame] | 625 | size_t len = strlen(protocols[i].name) + 1; |
| 626 | |
| 627 | memcpy(pSMB->DialectsArray+count, protocols[i].name, len); |
| 628 | count += len; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 629 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 630 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | pSMB->ByteCount = cpu_to_le16(count); |
| 632 | |
| 633 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 634 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 635 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 636 | goto neg_err_exit; |
| 637 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 638 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 639 | cifs_dbg(FYI, "Dialect: %d\n", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 640 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 641 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 642 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 643 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 644 | could not negotiate a common dialect */ |
| 645 | rc = -EOPNOTSUPP; |
| 646 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 647 | } else if (pSMBr->hdr.WordCount == 13) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 648 | server->negflavor = CIFS_NEGFLAVOR_LANMAN; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 649 | rc = decode_lanman_negprot_rsp(server, pSMBr); |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 650 | goto signing_check; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 651 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 652 | /* unknown wct */ |
| 653 | rc = -EOPNOTSUPP; |
| 654 | goto neg_err_exit; |
| 655 | } |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 656 | /* else wct == 17, NTLM or better */ |
| 657 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 658 | server->sec_mode = pSMBr->SecurityMode; |
| 659 | if ((server->sec_mode & SECMODE_USER) == 0) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 660 | cifs_dbg(FYI, "share mode security\n"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 661 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 662 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 663 | little endian */ |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 664 | server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), |
| 665 | cifs_max_pending); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 666 | set_credits(server, server->maxReq); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 667 | /* probably no need to store and check maxvcs */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 668 | server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); |
Jones Syue | 1f641d9 | 2020-04-13 09:37:23 +0800 | [diff] [blame] | 669 | /* set up max_read for readpages check */ |
| 670 | server->max_read = server->maxBuf; |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 671 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 672 | cifs_dbg(NOISY, "Max buf = %d\n", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 673 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 674 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 675 | server->timeAdj *= 60; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 676 | |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 677 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
| 678 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 679 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 680 | CIFS_CRYPTO_KEY_SIZE); |
Noel Power | f291095 | 2015-05-27 09:22:10 +0100 | [diff] [blame] | 681 | } else if (pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC || |
| 682 | server->capabilities & CAP_EXTENDED_SECURITY) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 683 | server->negflavor = CIFS_NEGFLAVOR_EXTENDED; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 684 | rc = decode_ext_sec_blob(ses, pSMBr); |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 685 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 686 | rc = -EIO; /* no crypt key only if plain text pwd */ |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 687 | } else { |
| 688 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 689 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 690 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 691 | |
| 692 | signing_check: |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 693 | if (!rc) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 694 | rc = cifs_enable_signing(server, ses->sign); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 695 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 696 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 697 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 698 | cifs_dbg(FYI, "negprot rc %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | return rc; |
| 700 | } |
| 701 | |
| 702 | int |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 703 | CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | { |
| 705 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 708 | cifs_dbg(FYI, "In tree disconnect\n"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 709 | |
| 710 | /* BB: do we need to check this? These should never be NULL. */ |
| 711 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 712 | return -EIO; |
| 713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 715 | * No need to return error on this operation if tid invalidated and |
| 716 | * closed on server already e.g. due to tcp session crashing. Also, |
| 717 | * the tcon is no longer on the list, so no need to take lock before |
| 718 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 720 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 721 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 723 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 724 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 725 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 727 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 728 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 729 | cifs_small_buf_release(smb_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 731 | cifs_dbg(FYI, "Tree disconnect failed %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 733 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 734 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | if (rc == -EAGAIN) |
| 736 | rc = 0; |
| 737 | |
| 738 | return rc; |
| 739 | } |
| 740 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 741 | /* |
| 742 | * This is a no-op for now. We're not really interested in the reply, but |
| 743 | * rather in the fact that the server sent one and that server->lstrp |
| 744 | * gets updated. |
| 745 | * |
| 746 | * FIXME: maybe we should consider checking that the reply matches request? |
| 747 | */ |
| 748 | static void |
| 749 | cifs_echo_callback(struct mid_q_entry *mid) |
| 750 | { |
| 751 | struct TCP_Server_Info *server = mid->callback_data; |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 752 | struct cifs_credits credits = { .value = 1, .instance = 0 }; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 753 | |
| 754 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 755 | add_credits(server, &credits, CIFS_ECHO_OP); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | int |
| 759 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 760 | { |
| 761 | ECHO_REQ *smb; |
| 762 | int rc = 0; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 763 | struct kvec iov[2]; |
| 764 | struct smb_rqst rqst = { .rq_iov = iov, |
| 765 | .rq_nvec = 2 }; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 766 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 767 | cifs_dbg(FYI, "In echo request\n"); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 768 | |
| 769 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 770 | if (rc) |
| 771 | return rc; |
| 772 | |
Steve French | 26c9cb6 | 2017-05-02 13:35:20 -0500 | [diff] [blame] | 773 | if (server->capabilities & CAP_UNICODE) |
| 774 | smb->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 775 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 776 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 777 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8f | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 778 | smb->hdr.WordCount = 1; |
| 779 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 780 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 781 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 782 | inc_rfc1001_len(smb, 3); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 783 | |
| 784 | iov[0].iov_len = 4; |
| 785 | iov[0].iov_base = smb; |
| 786 | iov[1].iov_len = get_rfc1002_length(smb); |
| 787 | iov[1].iov_base = (char *)smb + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 788 | |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 789 | rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, NULL, |
Ronnie Sahlberg | 392e1c5 | 2019-05-06 10:00:02 +1000 | [diff] [blame] | 790 | server, CIFS_NON_BLOCKING | CIFS_ECHO_OP, NULL); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 791 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 792 | cifs_dbg(FYI, "Echo request failed: %d\n", rc); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 793 | |
| 794 | cifs_small_buf_release(smb); |
| 795 | |
| 796 | return rc; |
| 797 | } |
| 798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | int |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 800 | CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | LOGOFF_ANDX_REQ *pSMB; |
| 803 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 805 | cifs_dbg(FYI, "In SMBLogoff for session disconnect\n"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 806 | |
| 807 | /* |
| 808 | * BB: do we need to check validity of ses and server? They should |
| 809 | * always be valid since we have an active reference. If not, that |
| 810 | * should probably be a BUG() |
| 811 | */ |
| 812 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | return -EIO; |
| 814 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 815 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 816 | if (ses->need_reconnect) |
| 817 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 818 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 820 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 821 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | return rc; |
| 823 | } |
| 824 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 825 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 826 | |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 827 | if (ses->server->sign) |
| 828 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
| 830 | pSMB->hdr.Uid = ses->Suid; |
| 831 | |
| 832 | pSMB->AndXCommand = 0xFF; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 833 | rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 834 | cifs_small_buf_release(pSMB); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 835 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 836 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 839 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | error */ |
| 841 | if (rc == -EAGAIN) |
| 842 | rc = 0; |
| 843 | return rc; |
| 844 | } |
| 845 | |
| 846 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 847 | CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, |
| 848 | const char *fileName, __u16 type, |
| 849 | const struct nls_table *nls_codepage, int remap) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 850 | { |
| 851 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 852 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 853 | struct unlink_psx_rq *pRqD; |
| 854 | int name_len; |
| 855 | int rc = 0; |
| 856 | int bytes_returned = 0; |
| 857 | __u16 params, param_offset, offset, byte_count; |
| 858 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 859 | cifs_dbg(FYI, "In POSIX delete\n"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 860 | PsxDelete: |
| 861 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 862 | (void **) &pSMBr); |
| 863 | if (rc) |
| 864 | return rc; |
| 865 | |
| 866 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 867 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 868 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 869 | PATH_MAX, nls_codepage, remap); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 870 | name_len++; /* trailing null */ |
| 871 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 872 | } else { |
| 873 | name_len = copy_path_name(pSMB->FileName, fileName); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | params = 6 + name_len; |
| 877 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 878 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 879 | pSMB->MaxSetupCount = 0; |
| 880 | pSMB->Reserved = 0; |
| 881 | pSMB->Flags = 0; |
| 882 | pSMB->Timeout = 0; |
| 883 | pSMB->Reserved2 = 0; |
| 884 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 885 | InformationLevel) - 4; |
| 886 | offset = param_offset + params; |
| 887 | |
| 888 | /* Setup pointer to Request Data (inode type) */ |
| 889 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 890 | pRqD->type = cpu_to_le16(type); |
| 891 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 892 | pSMB->DataOffset = cpu_to_le16(offset); |
| 893 | pSMB->SetupCount = 1; |
| 894 | pSMB->Reserved3 = 0; |
| 895 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 896 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 897 | |
| 898 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 899 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 900 | pSMB->ParameterCount = cpu_to_le16(params); |
| 901 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 902 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 903 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 904 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 905 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 906 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 907 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 908 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 909 | cifs_dbg(FYI, "Posix delete returned %d\n", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 910 | cifs_buf_release(pSMB); |
| 911 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 912 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 913 | |
| 914 | if (rc == -EAGAIN) |
| 915 | goto PsxDelete; |
| 916 | |
| 917 | return rc; |
| 918 | } |
| 919 | |
| 920 | int |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 921 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 922 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
| 924 | DELETE_FILE_REQ *pSMB = NULL; |
| 925 | DELETE_FILE_RSP *pSMBr = NULL; |
| 926 | int rc = 0; |
| 927 | int bytes_returned; |
| 928 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 929 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | DelFileRetry: |
| 932 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 933 | (void **) &pSMBr); |
| 934 | if (rc) |
| 935 | return rc; |
| 936 | |
| 937 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 938 | name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name, |
| 939 | PATH_MAX, cifs_sb->local_nls, |
| 940 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | name_len++; /* trailing null */ |
| 942 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 943 | } else { |
| 944 | name_len = copy_path_name(pSMB->fileName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | } |
| 946 | pSMB->SearchAttributes = |
| 947 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 948 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 949 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 951 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 952 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 953 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 954 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 955 | cifs_dbg(FYI, "Error in RMFile = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | cifs_buf_release(pSMB); |
| 958 | if (rc == -EAGAIN) |
| 959 | goto DelFileRetry; |
| 960 | |
| 961 | return rc; |
| 962 | } |
| 963 | |
| 964 | int |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 965 | CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 966 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | { |
| 968 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 969 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 970 | int rc = 0; |
| 971 | int bytes_returned; |
| 972 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 973 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 975 | cifs_dbg(FYI, "In CIFSSMBRmDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | RmDirRetry: |
| 977 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 978 | (void **) &pSMBr); |
| 979 | if (rc) |
| 980 | return rc; |
| 981 | |
| 982 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 983 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
| 984 | PATH_MAX, cifs_sb->local_nls, |
| 985 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | name_len++; /* trailing null */ |
| 987 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 988 | } else { |
| 989 | name_len = copy_path_name(pSMB->DirName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 993 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 995 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 996 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 997 | cifs_stats_inc(&tcon->stats.cifs_stats.num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 998 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 999 | cifs_dbg(FYI, "Error in RMDir = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
| 1001 | cifs_buf_release(pSMB); |
| 1002 | if (rc == -EAGAIN) |
| 1003 | goto RmDirRetry; |
| 1004 | return rc; |
| 1005 | } |
| 1006 | |
| 1007 | int |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 1008 | CIFSSMBMkDir(const unsigned int xid, struct inode *inode, umode_t mode, |
| 1009 | struct cifs_tcon *tcon, const char *name, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 1010 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
| 1012 | int rc = 0; |
| 1013 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 1014 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 1015 | int bytes_returned; |
| 1016 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1017 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1019 | cifs_dbg(FYI, "In CIFSSMBMkDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | MkDirRetry: |
| 1021 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 1022 | (void **) &pSMBr); |
| 1023 | if (rc) |
| 1024 | return rc; |
| 1025 | |
| 1026 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1027 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 1028 | PATH_MAX, cifs_sb->local_nls, |
| 1029 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | name_len++; /* trailing null */ |
| 1031 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1032 | } else { |
| 1033 | name_len = copy_path_name(pSMB->DirName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1037 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1039 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1040 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1041 | cifs_stats_inc(&tcon->stats.cifs_stats.num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1042 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1043 | cifs_dbg(FYI, "Error in Mkdir = %d\n", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | cifs_buf_release(pSMB); |
| 1046 | if (rc == -EAGAIN) |
| 1047 | goto MkDirRetry; |
| 1048 | return rc; |
| 1049 | } |
| 1050 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1051 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1052 | CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, |
| 1053 | __u32 posix_flags, __u64 mode, __u16 *netfid, |
| 1054 | FILE_UNIX_BASIC_INFO *pRetData, __u32 *pOplock, |
| 1055 | const char *name, const struct nls_table *nls_codepage, |
| 1056 | int remap) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1057 | { |
| 1058 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1059 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1060 | int name_len; |
| 1061 | int rc = 0; |
| 1062 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1063 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1064 | OPEN_PSX_REQ *pdata; |
| 1065 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1066 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1067 | cifs_dbg(FYI, "In POSIX Create\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1068 | PsxCreat: |
| 1069 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1070 | (void **) &pSMBr); |
| 1071 | if (rc) |
| 1072 | return rc; |
| 1073 | |
| 1074 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1075 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1076 | cifsConvertToUTF16((__le16 *) pSMB->FileName, name, |
| 1077 | PATH_MAX, nls_codepage, remap); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1078 | name_len++; /* trailing null */ |
| 1079 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1080 | } else { |
| 1081 | name_len = copy_path_name(pSMB->FileName, name); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | params = 6 + name_len; |
| 1085 | count = sizeof(OPEN_PSX_REQ); |
| 1086 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1087 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1088 | pSMB->MaxSetupCount = 0; |
| 1089 | pSMB->Reserved = 0; |
| 1090 | pSMB->Flags = 0; |
| 1091 | pSMB->Timeout = 0; |
| 1092 | pSMB->Reserved2 = 0; |
| 1093 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1094 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1095 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1096 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1097 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1098 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1099 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1100 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1101 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1102 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1103 | pSMB->SetupCount = 1; |
| 1104 | pSMB->Reserved3 = 0; |
| 1105 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1106 | byte_count = 3 /* pad */ + params + count; |
| 1107 | |
| 1108 | pSMB->DataCount = cpu_to_le16(count); |
| 1109 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1110 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1111 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1112 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1113 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1114 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1115 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1116 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1117 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1118 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1119 | cifs_dbg(FYI, "Posix create returned %d\n", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1120 | goto psx_create_err; |
| 1121 | } |
| 1122 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1123 | cifs_dbg(FYI, "copying inode info\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1124 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1125 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1126 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1127 | rc = -EIO; /* bad smb */ |
| 1128 | goto psx_create_err; |
| 1129 | } |
| 1130 | |
| 1131 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1132 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1133 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1134 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1135 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1136 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1137 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1138 | /* Let caller know file was created so we can set the mode. */ |
| 1139 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1140 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1141 | *pOplock |= CIFS_CREATE_ACTION; |
| 1142 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1143 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1144 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1145 | cifs_dbg(NOISY, "unknown type\n"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1146 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1147 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1148 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1149 | cifs_dbg(VFS, "Open response data too small\n"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1150 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1151 | goto psx_create_err; |
| 1152 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1153 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1154 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1155 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1156 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1157 | |
| 1158 | psx_create_err: |
| 1159 | cifs_buf_release(pSMB); |
| 1160 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1161 | if (posix_flags & SMB_O_DIRECTORY) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1162 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixmkdirs); |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1163 | else |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1164 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1165 | |
| 1166 | if (rc == -EAGAIN) |
| 1167 | goto PsxCreat; |
| 1168 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1169 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1172 | static __u16 convert_disposition(int disposition) |
| 1173 | { |
| 1174 | __u16 ofun = 0; |
| 1175 | |
| 1176 | switch (disposition) { |
| 1177 | case FILE_SUPERSEDE: |
| 1178 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1179 | break; |
| 1180 | case FILE_OPEN: |
| 1181 | ofun = SMBOPEN_OAPPEND; |
| 1182 | break; |
| 1183 | case FILE_CREATE: |
| 1184 | ofun = SMBOPEN_OCREATE; |
| 1185 | break; |
| 1186 | case FILE_OPEN_IF: |
| 1187 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1188 | break; |
| 1189 | case FILE_OVERWRITE: |
| 1190 | ofun = SMBOPEN_OTRUNC; |
| 1191 | break; |
| 1192 | case FILE_OVERWRITE_IF: |
| 1193 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1194 | break; |
| 1195 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1196 | cifs_dbg(FYI, "unknown disposition %d\n", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1197 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1198 | } |
| 1199 | return ofun; |
| 1200 | } |
| 1201 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1202 | static int |
| 1203 | access_flags_to_smbopen_mode(const int access_flags) |
| 1204 | { |
| 1205 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1206 | |
| 1207 | if (masked_flags == GENERIC_READ) |
| 1208 | return SMBOPEN_READ; |
| 1209 | else if (masked_flags == GENERIC_WRITE) |
| 1210 | return SMBOPEN_WRITE; |
| 1211 | |
| 1212 | /* just go for read/write */ |
| 1213 | return SMBOPEN_READWRITE; |
| 1214 | } |
| 1215 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1216 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1217 | SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1218 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1219 | const int access_flags, const int create_options, __u16 *netfid, |
| 1220 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1221 | const struct nls_table *nls_codepage, int remap) |
| 1222 | { |
| 1223 | int rc = -EACCES; |
| 1224 | OPENX_REQ *pSMB = NULL; |
| 1225 | OPENX_RSP *pSMBr = NULL; |
| 1226 | int bytes_returned; |
| 1227 | int name_len; |
| 1228 | __u16 count; |
| 1229 | |
| 1230 | OldOpenRetry: |
| 1231 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1232 | (void **) &pSMBr); |
| 1233 | if (rc) |
| 1234 | return rc; |
| 1235 | |
| 1236 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1237 | |
| 1238 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1239 | count = 1; /* account for one byte pad to word boundary */ |
| 1240 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1241 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1242 | fileName, PATH_MAX, nls_codepage, remap); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1243 | name_len++; /* trailing null */ |
| 1244 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1245 | } else { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1246 | count = 0; /* no pad */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1247 | name_len = copy_path_name(pSMB->fileName, fileName); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1248 | } |
| 1249 | if (*pOplock & REQ_OPLOCK) |
| 1250 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1251 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1252 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1253 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1254 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1255 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1256 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1257 | /* set file as system file if special file such |
| 1258 | as fifo and server expecting SFU style and |
| 1259 | no Unix extensions */ |
| 1260 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1261 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1262 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1263 | else /* BB FIXME BB */ |
| 1264 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1265 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1266 | if (create_options & CREATE_OPTION_READONLY) |
| 1267 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1268 | |
| 1269 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1270 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1271 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1272 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1273 | |
| 1274 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1275 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1276 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1277 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1278 | |
| 1279 | pSMB->ByteCount = cpu_to_le16(count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1280 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1281 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1282 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1283 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1284 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1285 | } else { |
| 1286 | /* BB verify if wct == 15 */ |
| 1287 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1288 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1289 | |
| 1290 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1291 | /* Let caller know file was created so we can set the mode. */ |
| 1292 | /* Do we care about the CreateAction in any other cases? */ |
| 1293 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1294 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1295 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1296 | /* BB FIXME END */ |
| 1297 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1298 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1299 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1300 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1301 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1302 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1303 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1304 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1305 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1306 | pfile_info->AllocationSize = |
| 1307 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1308 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1309 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1310 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | cifs_buf_release(pSMB); |
| 1315 | if (rc == -EAGAIN) |
| 1316 | goto OldOpenRetry; |
| 1317 | return rc; |
| 1318 | } |
| 1319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | int |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1321 | CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock, |
| 1322 | FILE_ALL_INFO *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | { |
Colin Ian King | 1afdea4 | 2019-07-23 16:09:19 +0100 | [diff] [blame] | 1324 | int rc; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1325 | OPEN_REQ *req = NULL; |
| 1326 | OPEN_RSP *rsp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | int bytes_returned; |
| 1328 | int name_len; |
| 1329 | __u16 count; |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1330 | struct cifs_sb_info *cifs_sb = oparms->cifs_sb; |
| 1331 | struct cifs_tcon *tcon = oparms->tcon; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1332 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1333 | const struct nls_table *nls = cifs_sb->local_nls; |
| 1334 | int create_options = oparms->create_options; |
| 1335 | int desired_access = oparms->desired_access; |
| 1336 | int disposition = oparms->disposition; |
| 1337 | const char *path = oparms->path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | |
| 1339 | openRetry: |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1340 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **)&req, |
| 1341 | (void **)&rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | if (rc) |
| 1343 | return rc; |
| 1344 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1345 | /* no commands go after this */ |
| 1346 | req->AndXCommand = 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1348 | if (req->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1349 | /* account for one byte pad to word boundary */ |
| 1350 | count = 1; |
| 1351 | name_len = cifsConvertToUTF16((__le16 *)(req->fileName + 1), |
| 1352 | path, PATH_MAX, nls, remap); |
| 1353 | /* trailing null */ |
| 1354 | name_len++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | name_len *= 2; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1356 | req->NameLength = cpu_to_le16(name_len); |
| 1357 | } else { |
| 1358 | /* BB improve check for buffer overruns BB */ |
| 1359 | /* no pad */ |
| 1360 | count = 0; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1361 | name_len = copy_path_name(req->fileName, path); |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1362 | req->NameLength = cpu_to_le16(name_len); |
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 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1365 | if (*oplock & REQ_OPLOCK) |
| 1366 | req->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
| 1367 | else if (*oplock & REQ_BATCHOPLOCK) |
| 1368 | req->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
| 1369 | |
| 1370 | req->DesiredAccess = cpu_to_le32(desired_access); |
| 1371 | req->AllocationSize = 0; |
| 1372 | |
| 1373 | /* |
| 1374 | * Set file as system file if special file such as fifo and server |
| 1375 | * expecting SFU style and no Unix extensions. |
| 1376 | */ |
| 1377 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1378 | req->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1379 | else |
| 1380 | req->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
| 1381 | |
| 1382 | /* |
| 1383 | * XP does not handle ATTR_POSIX_SEMANTICS but it helps speed up case |
| 1384 | * sensitive checks for other servers such as Samba. |
| 1385 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | if (tcon->ses->capabilities & CAP_UNIX) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1387 | req->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1389 | if (create_options & CREATE_OPTION_READONLY) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1390 | req->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1391 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1392 | req->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1393 | req->CreateDisposition = cpu_to_le32(disposition); |
| 1394 | req->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
| 1395 | |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1396 | /* BB Expirement with various impersonation levels and verify */ |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1397 | req->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
| 1398 | req->SecurityFlags = SECURITY_CONTEXT_TRACKING|SECURITY_EFFECTIVE_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | |
| 1400 | count += name_len; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1401 | inc_rfc1001_len(req, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1403 | req->ByteCount = cpu_to_le16(count); |
| 1404 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *)req, |
| 1405 | (struct smb_hdr *)rsp, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1406 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1408 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1409 | cifs_buf_release(req); |
| 1410 | if (rc == -EAGAIN) |
| 1411 | goto openRetry; |
| 1412 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1414 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1415 | /* 1 byte no need to le_to_cpu */ |
| 1416 | *oplock = rsp->OplockLevel; |
| 1417 | /* cifs fid stays in le */ |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1418 | oparms->fid->netfid = rsp->Fid; |
Aurelien Aptel | 86f740f | 2020-02-21 11:19:06 +0100 | [diff] [blame] | 1419 | oparms->fid->access = desired_access; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1420 | |
| 1421 | /* Let caller know file was created so we can set the mode. */ |
| 1422 | /* Do we care about the CreateAction in any other cases? */ |
| 1423 | if (cpu_to_le32(FILE_CREATE) == rsp->CreateAction) |
| 1424 | *oplock |= CIFS_CREATE_ACTION; |
| 1425 | |
| 1426 | if (buf) { |
| 1427 | /* copy from CreationTime to Attributes */ |
| 1428 | memcpy((char *)buf, (char *)&rsp->CreationTime, 36); |
| 1429 | /* the file_info buf is endian converted by caller */ |
| 1430 | buf->AllocationSize = rsp->AllocationSize; |
| 1431 | buf->EndOfFile = rsp->EndOfFile; |
| 1432 | buf->NumberOfLinks = cpu_to_le32(1); |
| 1433 | buf->DeletePending = 0; |
| 1434 | } |
| 1435 | |
| 1436 | cifs_buf_release(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | return rc; |
| 1438 | } |
| 1439 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1440 | /* |
| 1441 | * Discard any remaining data in the current SMB. To do this, we borrow the |
| 1442 | * current bigbuf. |
| 1443 | */ |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 1444 | int |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1445 | cifs_discard_remaining_data(struct TCP_Server_Info *server) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1446 | { |
Ronnie Sahlberg | 05432e2 | 2018-04-09 18:06:31 +1000 | [diff] [blame] | 1447 | unsigned int rfclen = server->pdu_size; |
| 1448 | int remaining = rfclen + server->vals->header_preamble_size - |
| 1449 | server->total_read; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1450 | |
| 1451 | while (remaining > 0) { |
| 1452 | int length; |
| 1453 | |
| 1454 | length = cifs_read_from_socket(server, server->bigbuf, |
| 1455 | min_t(unsigned int, remaining, |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1456 | CIFSMaxBufSize + MAX_HEADER_SIZE(server))); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1457 | if (length < 0) |
| 1458 | return length; |
| 1459 | server->total_read += length; |
| 1460 | remaining -= length; |
| 1461 | } |
| 1462 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1463 | return 0; |
| 1464 | } |
| 1465 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1466 | static int |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1467 | __cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid, |
| 1468 | bool malformed) |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1469 | { |
| 1470 | int length; |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1471 | |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1472 | length = cifs_discard_remaining_data(server); |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1473 | dequeue_mid(mid, malformed); |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1474 | mid->resp_buf = server->smallbuf; |
| 1475 | server->smallbuf = NULL; |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1476 | return length; |
| 1477 | } |
| 1478 | |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1479 | static int |
| 1480 | cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1481 | { |
| 1482 | struct cifs_readdata *rdata = mid->callback_data; |
| 1483 | |
| 1484 | return __cifs_readv_discard(server, mid, rdata->result); |
| 1485 | } |
| 1486 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1487 | int |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1488 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1489 | { |
| 1490 | int length, len; |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1491 | unsigned int data_offset, data_len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1492 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1493 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 1494 | unsigned int buflen = server->pdu_size + |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 1495 | server->vals->header_preamble_size; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1496 | bool use_rdma_mr = false; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1497 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1498 | cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n", |
| 1499 | __func__, mid->mid, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1500 | |
| 1501 | /* |
| 1502 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1503 | * can if there's not enough data. At this point, we've read down to |
| 1504 | * the Mid. |
| 1505 | */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1506 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1507 | HEADER_SIZE(server) + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1508 | |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1509 | length = cifs_read_from_socket(server, |
| 1510 | buf + HEADER_SIZE(server) - 1, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1511 | if (length < 0) |
| 1512 | return length; |
| 1513 | server->total_read += length; |
| 1514 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1515 | if (server->ops->is_session_expired && |
| 1516 | server->ops->is_session_expired(buf)) { |
| 1517 | cifs_reconnect(server); |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1518 | return -1; |
| 1519 | } |
| 1520 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1521 | if (server->ops->is_status_pending && |
Pavel Shilovsky | 66265f1 | 2019-01-23 17:11:16 -0800 | [diff] [blame] | 1522 | server->ops->is_status_pending(buf, server)) { |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1523 | cifs_discard_remaining_data(server); |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1524 | return -1; |
| 1525 | } |
| 1526 | |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1527 | /* set up first two iov for signature check and to get credits */ |
| 1528 | rdata->iov[0].iov_base = buf; |
Pavel Shilovsky | bb1bccb | 2019-01-17 16:18:38 -0800 | [diff] [blame] | 1529 | rdata->iov[0].iov_len = server->vals->header_preamble_size; |
| 1530 | rdata->iov[1].iov_base = buf + server->vals->header_preamble_size; |
| 1531 | rdata->iov[1].iov_len = |
| 1532 | server->total_read - server->vals->header_preamble_size; |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1533 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 1534 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); |
| 1535 | cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", |
| 1536 | rdata->iov[1].iov_base, rdata->iov[1].iov_len); |
| 1537 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1538 | /* Was the SMB read successful? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1539 | rdata->result = server->ops->map_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1540 | if (rdata->result != 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1541 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 1542 | __func__, rdata->result); |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1543 | /* normal error on read response */ |
| 1544 | return __cifs_readv_discard(server, mid, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | /* 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] | 1548 | if (server->total_read < server->vals->read_rsp_size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1549 | cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n", |
| 1550 | __func__, server->total_read, |
| 1551 | server->vals->read_rsp_size); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1552 | rdata->result = -EIO; |
| 1553 | return cifs_readv_discard(server, mid); |
| 1554 | } |
| 1555 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 1556 | data_offset = server->ops->read_data_offset(buf) + |
| 1557 | server->vals->header_preamble_size; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1558 | if (data_offset < server->total_read) { |
| 1559 | /* |
| 1560 | * win2k8 sometimes sends an offset of 0 when the read |
| 1561 | * is beyond the EOF. Treat it as if the data starts just after |
| 1562 | * the header. |
| 1563 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1564 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 1565 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1566 | data_offset = server->total_read; |
| 1567 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1568 | /* data_offset is beyond the end of smallbuf */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1569 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 1570 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1571 | rdata->result = -EIO; |
| 1572 | return cifs_readv_discard(server, mid); |
| 1573 | } |
| 1574 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1575 | cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n", |
| 1576 | __func__, server->total_read, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1577 | |
| 1578 | len = data_offset - server->total_read; |
| 1579 | if (len > 0) { |
| 1580 | /* read any junk before data into the rest of smallbuf */ |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1581 | length = cifs_read_from_socket(server, |
| 1582 | buf + server->total_read, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1583 | if (length < 0) |
| 1584 | return length; |
| 1585 | server->total_read += length; |
| 1586 | } |
| 1587 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1588 | /* how much data is in the response? */ |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1589 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 1590 | use_rdma_mr = rdata->mr; |
| 1591 | #endif |
| 1592 | data_len = server->ops->read_data_length(buf, use_rdma_mr); |
| 1593 | if (!use_rdma_mr && (data_offset + data_len > buflen)) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1594 | /* data_len is corrupt -- discard frame */ |
| 1595 | rdata->result = -EIO; |
| 1596 | return cifs_readv_discard(server, mid); |
| 1597 | } |
| 1598 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1599 | length = rdata->read_into_pages(server, rdata, data_len); |
| 1600 | if (length < 0) |
| 1601 | return length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1602 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1603 | server->total_read += length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1604 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1605 | cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n", |
| 1606 | server->total_read, buflen, data_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1607 | |
| 1608 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1609 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1610 | return cifs_readv_discard(server, mid); |
| 1611 | |
| 1612 | dequeue_mid(mid, false); |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1613 | mid->resp_buf = server->smallbuf; |
| 1614 | server->smallbuf = NULL; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1615 | return length; |
| 1616 | } |
| 1617 | |
| 1618 | static void |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1619 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1620 | { |
| 1621 | struct cifs_readdata *rdata = mid->callback_data; |
| 1622 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1623 | struct TCP_Server_Info *server = tcon->ses->server; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1624 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 1625 | .rq_nvec = 2, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1626 | .rq_pages = rdata->pages, |
Long Li | 6d3adb2 | 2018-09-20 21:18:38 +0000 | [diff] [blame] | 1627 | .rq_offset = rdata->page_offset, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1628 | .rq_npages = rdata->nr_pages, |
| 1629 | .rq_pagesz = rdata->pagesz, |
| 1630 | .rq_tailsz = rdata->tailsz }; |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 1631 | struct cifs_credits credits = { .value = 1, .instance = 0 }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1632 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1633 | cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", |
| 1634 | __func__, mid->mid, mid->mid_state, rdata->result, |
| 1635 | rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1636 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1637 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1638 | case MID_RESPONSE_RECEIVED: |
| 1639 | /* result already set, check signature */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 1640 | if (server->sign) { |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1641 | int rc = 0; |
| 1642 | |
Jeff Layton | bf5ea0e | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1643 | rc = cifs_verify_signature(&rqst, server, |
Jeff Layton | 0124cc4 | 2013-04-03 11:55:03 -0400 | [diff] [blame] | 1644 | mid->sequence_number); |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1645 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1646 | cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
| 1647 | rc); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1648 | } |
| 1649 | /* FIXME: should this be counted toward the initiating task? */ |
Pavel Shilovsky | 34a54d6 | 2014-07-10 10:03:29 +0400 | [diff] [blame] | 1650 | task_io_account_read(rdata->got_bytes); |
| 1651 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1652 | break; |
| 1653 | case MID_REQUEST_SUBMITTED: |
| 1654 | case MID_RETRY_NEEDED: |
| 1655 | rdata->result = -EAGAIN; |
Pavel Shilovsky | d913ed1 | 2014-07-10 11:31:48 +0400 | [diff] [blame] | 1656 | if (server->sign && rdata->got_bytes) |
| 1657 | /* reset bytes number since we can not check a sign */ |
| 1658 | rdata->got_bytes = 0; |
| 1659 | /* FIXME: should this be counted toward the initiating task? */ |
| 1660 | task_io_account_read(rdata->got_bytes); |
| 1661 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1662 | break; |
| 1663 | default: |
| 1664 | rdata->result = -EIO; |
| 1665 | } |
| 1666 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1667 | queue_work(cifsiod_wq, &rdata->work); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1668 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 1669 | add_credits(server, &credits, 0); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1673 | int |
| 1674 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1675 | { |
| 1676 | int rc; |
| 1677 | READ_REQ *smb = NULL; |
| 1678 | int wct; |
| 1679 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1680 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 1681 | .rq_nvec = 2 }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1682 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1683 | cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n", |
| 1684 | __func__, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1685 | |
| 1686 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1687 | wct = 12; |
| 1688 | else { |
| 1689 | wct = 10; /* old style read */ |
| 1690 | if ((rdata->offset >> 32) > 0) { |
| 1691 | /* can not handle this big offset for old */ |
| 1692 | return -EIO; |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1697 | if (rc) |
| 1698 | return rc; |
| 1699 | |
| 1700 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1701 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1702 | |
| 1703 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1704 | smb->Fid = rdata->cfile->fid.netfid; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1705 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1706 | if (wct == 12) |
| 1707 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1708 | smb->Remaining = 0; |
| 1709 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1710 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1711 | if (wct == 12) |
| 1712 | smb->ByteCount = 0; |
| 1713 | else { |
| 1714 | /* old style read */ |
| 1715 | struct smb_com_readx_req *smbr = |
| 1716 | (struct smb_com_readx_req *)smb; |
| 1717 | smbr->ByteCount = 0; |
| 1718 | } |
| 1719 | |
| 1720 | /* 4 for RFC1001 length + 1 for BCC */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1721 | rdata->iov[0].iov_base = smb; |
| 1722 | rdata->iov[0].iov_len = 4; |
| 1723 | rdata->iov[1].iov_base = (char *)smb + 4; |
| 1724 | rdata->iov[1].iov_len = get_rfc1002_length(smb); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1725 | |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1726 | kref_get(&rdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 1727 | rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, |
Pavel Shilovsky | 3349c3a | 2019-01-15 15:52:29 -0800 | [diff] [blame] | 1728 | cifs_readv_callback, NULL, rdata, 0, NULL); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1729 | |
| 1730 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1731 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1732 | else |
| 1733 | kref_put(&rdata->refcount, cifs_readdata_release); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1734 | |
| 1735 | cifs_small_buf_release(smb); |
| 1736 | return rc; |
| 1737 | } |
| 1738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1740 | CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms, |
| 1741 | unsigned int *nbytes, char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | { |
| 1743 | int rc = -EACCES; |
| 1744 | READ_REQ *pSMB = NULL; |
| 1745 | READ_RSP *pSMBr = NULL; |
| 1746 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1747 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1748 | int resp_buf_type = 0; |
| 1749 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1750 | struct kvec rsp_iov; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1751 | __u32 pid = io_parms->pid; |
| 1752 | __u16 netfid = io_parms->netfid; |
| 1753 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1754 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1755 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1757 | cifs_dbg(FYI, "Reading %d bytes on fid %d\n", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1758 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1759 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1760 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1761 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1762 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1763 | /* can not handle this big offset for old */ |
| 1764 | return -EIO; |
| 1765 | } |
| 1766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | |
| 1768 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1769 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | if (rc) |
| 1771 | return rc; |
| 1772 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1773 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1774 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | /* tcon and ses pointer are checked in smb_init */ |
| 1777 | if (tcon->ses->server == NULL) |
| 1778 | return -ECONNABORTED; |
| 1779 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1780 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1782 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1783 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1784 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | pSMB->Remaining = 0; |
| 1787 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1788 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1789 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1790 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1791 | else { |
| 1792 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1793 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1794 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1795 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1796 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1797 | |
| 1798 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1799 | 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] | 1800 | rc = SendReceive2(xid, tcon->ses, iov, 1, &resp_buf_type, |
| 1801 | CIFS_LOG_ERROR, &rsp_iov); |
| 1802 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1803 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1804 | pSMBr = (READ_RSP *)rsp_iov.iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1806 | cifs_dbg(VFS, "Send error in read = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | } else { |
| 1808 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1809 | data_length = data_length << 16; |
| 1810 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1811 | *nbytes = data_length; |
| 1812 | |
| 1813 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1814 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | || (data_length > count)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1816 | cifs_dbg(FYI, "bad length %d for count %d\n", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1817 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | rc = -EIO; |
| 1819 | *nbytes = 0; |
| 1820 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1821 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1822 | le16_to_cpu(pSMBr->DataOffset); |
| 1823 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1824 | cifs_dbg(VFS, "Faulting on read rc = %d\n",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1825 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1826 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1827 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1828 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | } |
| 1830 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1832 | if (*buf) { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1833 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1834 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1835 | /* return buffer to caller to free */ |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1836 | *buf = rsp_iov.iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1837 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1838 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1839 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1840 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1841 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1842 | |
| 1843 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | since file handle passed in no longer valid */ |
| 1845 | return rc; |
| 1846 | } |
| 1847 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1850 | CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1851 | unsigned int *nbytes, const char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | { |
| 1853 | int rc = -EACCES; |
| 1854 | WRITE_REQ *pSMB = NULL; |
| 1855 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1856 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | __u32 bytes_sent; |
| 1858 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1859 | __u32 pid = io_parms->pid; |
| 1860 | __u16 netfid = io_parms->netfid; |
| 1861 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1862 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1863 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1865 | *nbytes = 0; |
| 1866 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1867 | /* cifs_dbg(FYI, "write at %lld %d bytes\n", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1868 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1869 | return -ECONNABORTED; |
| 1870 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1871 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1872 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1873 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1874 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1875 | if ((offset >> 32) > 0) { |
| 1876 | /* can not handle big offset for old srv */ |
| 1877 | return -EIO; |
| 1878 | } |
| 1879 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1880 | |
| 1881 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | (void **) &pSMBr); |
| 1883 | if (rc) |
| 1884 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1885 | |
| 1886 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1887 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | /* tcon and ses pointer are checked in smb_init */ |
| 1890 | if (tcon->ses->server == NULL) |
| 1891 | return -ECONNABORTED; |
| 1892 | |
| 1893 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1894 | pSMB->Fid = netfid; |
| 1895 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1896 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1897 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | pSMB->Reserved = 0xFFFFFFFF; |
| 1900 | pSMB->WriteMode = 0; |
| 1901 | pSMB->Remaining = 0; |
| 1902 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1903 | /* 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] | 1904 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1905 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1906 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1907 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1909 | } else { |
| 1910 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1911 | & ~0xFF; |
| 1912 | } |
| 1913 | |
| 1914 | if (bytes_sent > count) |
| 1915 | bytes_sent = count; |
| 1916 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1917 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1918 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1919 | memcpy(pSMB->Data, buf, bytes_sent); |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1920 | else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | /* No buffer */ |
| 1922 | cifs_buf_release(pSMB); |
| 1923 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1924 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1925 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1926 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1927 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1928 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1931 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1932 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1933 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1934 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1935 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1936 | else { /* old style write has byte count 4 bytes earlier |
| 1937 | so 4 bytes pad */ |
| 1938 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1939 | (struct smb_com_writex_req *)pSMB; |
| 1940 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1941 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | |
| 1943 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1944 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1945 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1947 | cifs_dbg(FYI, "Send error in write = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | } else { |
| 1949 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1950 | *nbytes = (*nbytes) << 16; |
| 1951 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1952 | |
| 1953 | /* |
| 1954 | * Mask off high 16 bits when bytes written as returned by the |
| 1955 | * server is greater than bytes requested by the client. Some |
| 1956 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1957 | */ |
| 1958 | if (*nbytes > count) |
| 1959 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | cifs_buf_release(pSMB); |
| 1963 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1964 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | since file handle passed in no longer valid */ |
| 1966 | |
| 1967 | return rc; |
| 1968 | } |
| 1969 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1970 | void |
| 1971 | cifs_writedata_release(struct kref *refcount) |
| 1972 | { |
| 1973 | struct cifs_writedata *wdata = container_of(refcount, |
| 1974 | struct cifs_writedata, refcount); |
Long Li | db223a5 | 2017-11-22 17:38:45 -0700 | [diff] [blame] | 1975 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 1976 | if (wdata->mr) { |
| 1977 | smbd_deregister_mr(wdata->mr); |
| 1978 | wdata->mr = NULL; |
| 1979 | } |
| 1980 | #endif |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1981 | |
| 1982 | if (wdata->cfile) |
| 1983 | cifsFileInfo_put(wdata->cfile); |
| 1984 | |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 1985 | kvfree(wdata->pages); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1986 | kfree(wdata); |
| 1987 | } |
| 1988 | |
| 1989 | /* |
| 1990 | * Write failed with a retryable error. Resend the write request. It's also |
| 1991 | * possible that the page was redirtied so re-clean the page. |
| 1992 | */ |
| 1993 | static void |
| 1994 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 1995 | { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1996 | int i, rc = 0; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1997 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Pavel Shilovsky | c9de5c8 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1998 | struct TCP_Server_Info *server; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1999 | unsigned int rest_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2000 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2001 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
| 2002 | i = 0; |
| 2003 | rest_len = wdata->bytes; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2004 | do { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2005 | struct cifs_writedata *wdata2; |
| 2006 | unsigned int j, nr_pages, wsize, tailsz, cur_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2007 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2008 | wsize = server->ops->wp_retry_size(inode); |
| 2009 | if (wsize < rest_len) { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2010 | nr_pages = wsize / PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2011 | if (!nr_pages) { |
| 2012 | rc = -ENOTSUPP; |
| 2013 | break; |
| 2014 | } |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2015 | cur_len = nr_pages * PAGE_SIZE; |
| 2016 | tailsz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2017 | } else { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2018 | nr_pages = DIV_ROUND_UP(rest_len, PAGE_SIZE); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2019 | cur_len = rest_len; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2020 | tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE; |
Ouyang Maochun | c51bb0e | 2013-02-18 09:54:52 -0600 | [diff] [blame] | 2021 | } |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2022 | |
| 2023 | wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete); |
| 2024 | if (!wdata2) { |
| 2025 | rc = -ENOMEM; |
| 2026 | break; |
| 2027 | } |
| 2028 | |
| 2029 | for (j = 0; j < nr_pages; j++) { |
| 2030 | wdata2->pages[j] = wdata->pages[i + j]; |
| 2031 | lock_page(wdata2->pages[j]); |
| 2032 | clear_page_dirty_for_io(wdata2->pages[j]); |
| 2033 | } |
| 2034 | |
| 2035 | wdata2->sync_mode = wdata->sync_mode; |
| 2036 | wdata2->nr_pages = nr_pages; |
| 2037 | wdata2->offset = page_offset(wdata2->pages[0]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2038 | wdata2->pagesz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2039 | wdata2->tailsz = tailsz; |
| 2040 | wdata2->bytes = cur_len; |
| 2041 | |
Aurelien Aptel | 86f740f | 2020-02-21 11:19:06 +0100 | [diff] [blame] | 2042 | rc = cifs_get_writable_file(CIFS_I(inode), FIND_WR_ANY, |
Pavel Shilovsky | fe768d5 | 2019-01-29 12:15:11 -0800 | [diff] [blame] | 2043 | &wdata2->cfile); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2044 | if (!wdata2->cfile) { |
Pavel Shilovsky | fe768d5 | 2019-01-29 12:15:11 -0800 | [diff] [blame] | 2045 | cifs_dbg(VFS, "No writable handle to retry writepages rc=%d\n", |
| 2046 | rc); |
| 2047 | if (!is_retryable_error(rc)) |
| 2048 | rc = -EBADF; |
Pavel Shilovsky | 165df9a | 2019-01-29 16:40:28 -0800 | [diff] [blame] | 2049 | } else { |
| 2050 | wdata2->pid = wdata2->cfile->pid; |
| 2051 | rc = server->ops->async_writev(wdata2, |
| 2052 | cifs_writedata_release); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2053 | } |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2054 | |
| 2055 | for (j = 0; j < nr_pages; j++) { |
| 2056 | unlock_page(wdata2->pages[j]); |
Pavel Shilovsky | 9a66396 | 2019-01-08 11:15:28 -0800 | [diff] [blame] | 2057 | if (rc != 0 && !is_retryable_error(rc)) { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2058 | SetPageError(wdata2->pages[j]); |
| 2059 | end_page_writeback(wdata2->pages[j]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2060 | put_page(wdata2->pages[j]); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | |
Adam McCoy | a481379 | 2020-05-13 11:53:30 +0000 | [diff] [blame] | 2064 | kref_put(&wdata2->refcount, cifs_writedata_release); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2065 | if (rc) { |
Pavel Shilovsky | 9a66396 | 2019-01-08 11:15:28 -0800 | [diff] [blame] | 2066 | if (is_retryable_error(rc)) |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2067 | continue; |
Pavel Shilovsky | 165df9a | 2019-01-29 16:40:28 -0800 | [diff] [blame] | 2068 | i += nr_pages; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2069 | break; |
| 2070 | } |
| 2071 | |
| 2072 | rest_len -= cur_len; |
| 2073 | i += nr_pages; |
| 2074 | } while (i < wdata->nr_pages); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2075 | |
Pavel Shilovsky | 165df9a | 2019-01-29 16:40:28 -0800 | [diff] [blame] | 2076 | /* cleanup remaining pages from the original wdata */ |
| 2077 | for (; i < wdata->nr_pages; i++) { |
| 2078 | SetPageError(wdata->pages[i]); |
| 2079 | end_page_writeback(wdata->pages[i]); |
| 2080 | put_page(wdata->pages[i]); |
| 2081 | } |
| 2082 | |
Pavel Shilovsky | 9a66396 | 2019-01-08 11:15:28 -0800 | [diff] [blame] | 2083 | if (rc != 0 && !is_retryable_error(rc)) |
| 2084 | mapping_set_error(inode->i_mapping, rc); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2085 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2086 | } |
| 2087 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2088 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2089 | cifs_writev_complete(struct work_struct *work) |
| 2090 | { |
| 2091 | struct cifs_writedata *wdata = container_of(work, |
| 2092 | struct cifs_writedata, work); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2093 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2094 | int i = 0; |
| 2095 | |
| 2096 | if (wdata->result == 0) { |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2097 | spin_lock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2098 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2099 | spin_unlock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2100 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 2101 | wdata->bytes); |
| 2102 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 2103 | return cifs_writev_requeue(wdata); |
| 2104 | |
| 2105 | for (i = 0; i < wdata->nr_pages; i++) { |
| 2106 | struct page *page = wdata->pages[i]; |
| 2107 | if (wdata->result == -EAGAIN) |
| 2108 | __set_page_dirty_nobuffers(page); |
| 2109 | else if (wdata->result < 0) |
| 2110 | SetPageError(page); |
| 2111 | end_page_writeback(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2112 | put_page(page); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2113 | } |
| 2114 | if (wdata->result != -EAGAIN) |
| 2115 | mapping_set_error(inode->i_mapping, wdata->result); |
| 2116 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2117 | } |
| 2118 | |
| 2119 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2120 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2121 | { |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2122 | struct page **pages = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2123 | kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2124 | if (pages) |
| 2125 | return cifs_writedata_direct_alloc(pages, complete); |
| 2126 | |
| 2127 | return NULL; |
| 2128 | } |
| 2129 | |
| 2130 | struct cifs_writedata * |
| 2131 | cifs_writedata_direct_alloc(struct page **pages, work_func_t complete) |
| 2132 | { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2133 | struct cifs_writedata *wdata; |
| 2134 | |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2135 | wdata = kzalloc(sizeof(*wdata), GFP_NOFS); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2136 | if (wdata != NULL) { |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2137 | wdata->pages = pages; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2138 | kref_init(&wdata->refcount); |
Jeff Layton | da82f7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2139 | INIT_LIST_HEAD(&wdata->list); |
| 2140 | init_completion(&wdata->done); |
| 2141 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2142 | } |
| 2143 | return wdata; |
| 2144 | } |
| 2145 | |
| 2146 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2147 | * 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] | 2148 | * workqueue completion task. |
| 2149 | */ |
| 2150 | static void |
| 2151 | cifs_writev_callback(struct mid_q_entry *mid) |
| 2152 | { |
| 2153 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2154 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2155 | unsigned int written; |
| 2156 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 2157 | struct cifs_credits credits = { .value = 1, .instance = 0 }; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2158 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2159 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2160 | case MID_RESPONSE_RECEIVED: |
| 2161 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 2162 | if (wdata->result != 0) |
| 2163 | break; |
| 2164 | |
| 2165 | written = le16_to_cpu(smb->CountHigh); |
| 2166 | written <<= 16; |
| 2167 | written += le16_to_cpu(smb->Count); |
| 2168 | /* |
| 2169 | * Mask off high 16 bits when bytes written as returned |
| 2170 | * by the server is greater than bytes requested by the |
| 2171 | * client. OS/2 servers are known to set incorrect |
| 2172 | * CountHigh values. |
| 2173 | */ |
| 2174 | if (written > wdata->bytes) |
| 2175 | written &= 0xFFFF; |
| 2176 | |
| 2177 | if (written < wdata->bytes) |
| 2178 | wdata->result = -ENOSPC; |
| 2179 | else |
| 2180 | wdata->bytes = written; |
| 2181 | break; |
| 2182 | case MID_REQUEST_SUBMITTED: |
| 2183 | case MID_RETRY_NEEDED: |
| 2184 | wdata->result = -EAGAIN; |
| 2185 | break; |
| 2186 | default: |
| 2187 | wdata->result = -EIO; |
| 2188 | break; |
| 2189 | } |
| 2190 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2191 | queue_work(cifsiod_wq, &wdata->work); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2192 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 2193 | add_credits(tcon->ses->server, &credits, 0); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2197 | int |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2198 | cifs_async_writev(struct cifs_writedata *wdata, |
| 2199 | void (*release)(struct kref *kref)) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2200 | { |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2201 | int rc = -EACCES; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2202 | WRITE_REQ *smb = NULL; |
| 2203 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2204 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2205 | struct kvec iov[2]; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2206 | struct smb_rqst rqst = { }; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2207 | |
| 2208 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2209 | wct = 14; |
| 2210 | } else { |
| 2211 | wct = 12; |
| 2212 | if (wdata->offset >> 32 > 0) { |
| 2213 | /* can not handle big offset for old srv */ |
| 2214 | return -EIO; |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2219 | if (rc) |
| 2220 | goto async_writev_out; |
| 2221 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2222 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2223 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2224 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2225 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2226 | smb->Fid = wdata->cfile->fid.netfid; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2227 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2228 | if (wct == 14) |
| 2229 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2230 | smb->Reserved = 0xFFFFFFFF; |
| 2231 | smb->WriteMode = 0; |
| 2232 | smb->Remaining = 0; |
| 2233 | |
| 2234 | smb->DataOffset = |
| 2235 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2236 | |
| 2237 | /* 4 for RFC1001 length + 1 for BCC */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2238 | iov[0].iov_len = 4; |
| 2239 | iov[0].iov_base = smb; |
| 2240 | iov[1].iov_len = get_rfc1002_length(smb) + 1; |
| 2241 | iov[1].iov_base = (char *)smb + 4; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2242 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2243 | rqst.rq_iov = iov; |
| 2244 | rqst.rq_nvec = 2; |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2245 | rqst.rq_pages = wdata->pages; |
Long Li | 6d3adb2 | 2018-09-20 21:18:38 +0000 | [diff] [blame] | 2246 | rqst.rq_offset = wdata->page_offset; |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2247 | rqst.rq_npages = wdata->nr_pages; |
| 2248 | rqst.rq_pagesz = wdata->pagesz; |
| 2249 | rqst.rq_tailsz = wdata->tailsz; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2250 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2251 | cifs_dbg(FYI, "async write at %llu %u bytes\n", |
| 2252 | wdata->offset, wdata->bytes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2253 | |
| 2254 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2255 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2256 | |
| 2257 | if (wct == 14) { |
| 2258 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2259 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2260 | } else { |
| 2261 | /* wct == 12 */ |
| 2262 | struct smb_com_writex_req *smbw = |
| 2263 | (struct smb_com_writex_req *)smb; |
| 2264 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2265 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2266 | iov[1].iov_len += 4; /* pad bigger by four bytes */ |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | kref_get(&wdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2270 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, |
Pavel Shilovsky | 3349c3a | 2019-01-15 15:52:29 -0800 | [diff] [blame] | 2271 | cifs_writev_callback, NULL, wdata, 0, NULL); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2272 | |
| 2273 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2274 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2275 | else |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2276 | kref_put(&wdata->refcount, release); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2277 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2278 | async_writev_out: |
| 2279 | cifs_small_buf_release(smb); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2280 | return rc; |
| 2281 | } |
| 2282 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2283 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2284 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2285 | unsigned int *nbytes, struct kvec *iov, int n_vec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | { |
Colin Ian King | 136a5dc | 2020-05-27 13:50:31 +0100 | [diff] [blame] | 2287 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2289 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2290 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2291 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2292 | __u32 pid = io_parms->pid; |
| 2293 | __u16 netfid = io_parms->netfid; |
| 2294 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2295 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2296 | unsigned int count = io_parms->length; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2297 | struct kvec rsp_iov; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2299 | *nbytes = 0; |
| 2300 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2301 | 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] | 2302 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2303 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2304 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2305 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2306 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2307 | if ((offset >> 32) > 0) { |
| 2308 | /* can not handle big offset for old srv */ |
| 2309 | return -EIO; |
| 2310 | } |
| 2311 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2312 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | if (rc) |
| 2314 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2315 | |
| 2316 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2317 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | /* tcon and ses pointer are checked in smb_init */ |
| 2320 | if (tcon->ses->server == NULL) |
| 2321 | return -ECONNABORTED; |
| 2322 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2323 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | pSMB->Fid = netfid; |
| 2325 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2326 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2327 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | pSMB->Reserved = 0xFFFFFFFF; |
| 2329 | pSMB->WriteMode = 0; |
| 2330 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2333 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2335 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2336 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2337 | /* header + 1 byte pad */ |
| 2338 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2339 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2340 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2341 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2342 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2343 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2344 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2345 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2346 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2347 | (struct smb_com_writex_req *)pSMB; |
| 2348 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2349 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2350 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2351 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2352 | iov[0].iov_len = smb_hdr_len + 4; |
| 2353 | else /* wct == 12 pad bigger by four bytes */ |
| 2354 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2355 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2356 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0, |
| 2357 | &rsp_iov); |
| 2358 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2359 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2361 | cifs_dbg(FYI, "Send error Write2 = %d\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2362 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2363 | /* presumably this can not happen, but best to be safe */ |
| 2364 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2365 | } else { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2366 | WRITE_RSP *pSMBr = (WRITE_RSP *)rsp_iov.iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2367 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2368 | *nbytes = (*nbytes) << 16; |
| 2369 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2370 | |
| 2371 | /* |
| 2372 | * Mask off high 16 bits when bytes written as returned by the |
| 2373 | * server is greater than bytes requested by the client. OS/2 |
| 2374 | * servers are known to set incorrect CountHigh values. |
| 2375 | */ |
| 2376 | if (*nbytes > count) |
| 2377 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2380 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2382 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | since file handle passed in no longer valid */ |
| 2384 | |
| 2385 | return rc; |
| 2386 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2387 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2388 | int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon, |
| 2389 | const __u16 netfid, const __u8 lock_type, const __u32 num_unlock, |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2390 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2391 | { |
| 2392 | int rc = 0; |
| 2393 | LOCK_REQ *pSMB = NULL; |
| 2394 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2395 | struct kvec rsp_iov; |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2396 | int resp_buf_type; |
| 2397 | __u16 count; |
| 2398 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2399 | cifs_dbg(FYI, "cifs_lockv num lock %d num unlock %d\n", |
| 2400 | num_lock, num_unlock); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2401 | |
| 2402 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2403 | if (rc) |
| 2404 | return rc; |
| 2405 | |
| 2406 | pSMB->Timeout = 0; |
| 2407 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2408 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2409 | pSMB->LockType = lock_type; |
| 2410 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2411 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2412 | |
| 2413 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2414 | inc_rfc1001_len(pSMB, count); |
| 2415 | pSMB->ByteCount = cpu_to_le16(count); |
| 2416 | |
| 2417 | iov[0].iov_base = (char *)pSMB; |
| 2418 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2419 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2420 | iov[1].iov_base = (char *)buf; |
| 2421 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2422 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2423 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Ronnie Sahlberg | 392e1c5 | 2019-05-06 10:00:02 +1000 | [diff] [blame] | 2424 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, |
| 2425 | CIFS_NO_RSP_BUF, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2426 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2427 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2428 | cifs_dbg(FYI, "Send error in cifs_lockv = %d\n", rc); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2429 | |
| 2430 | return rc; |
| 2431 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2434 | CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2435 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2437 | const __u32 numLock, const __u8 lockType, |
| 2438 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | { |
| 2440 | int rc = 0; |
| 2441 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2442 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | int bytes_returned; |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2444 | int flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | __u16 count; |
| 2446 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2447 | cifs_dbg(FYI, "CIFSSMBLock timeout %d numLock %d\n", |
| 2448 | (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2449 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | if (rc) |
| 2452 | return rc; |
| 2453 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2454 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2455 | /* no response expected */ |
Ronnie Sahlberg | 392e1c5 | 2019-05-06 10:00:02 +1000 | [diff] [blame] | 2456 | flags = CIFS_NO_SRV_RSP | CIFS_NON_BLOCKING | CIFS_OBREAK_OP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2458 | } else if (waitFlag) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2459 | flags = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2461 | } else { |
| 2462 | pSMB->Timeout = 0; |
| 2463 | } |
| 2464 | |
| 2465 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2466 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2467 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2468 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2470 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2471 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2472 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2473 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | /* BB where to store pid high? */ |
| 2475 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2476 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2477 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2478 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2479 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2480 | } else { |
| 2481 | /* oplock break */ |
| 2482 | count = 0; |
| 2483 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2484 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | pSMB->ByteCount = cpu_to_le16(count); |
| 2486 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2487 | if (waitFlag) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2488 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2489 | (struct smb_hdr *) pSMB, &bytes_returned); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2490 | else |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2491 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, flags); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2492 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2493 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2494 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2495 | cifs_dbg(FYI, "Send error in Lock = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2497 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | since file handle passed in no longer valid */ |
| 2499 | return rc; |
| 2500 | } |
| 2501 | |
| 2502 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2503 | CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2504 | const __u16 smb_file_id, const __u32 netpid, |
| 2505 | const loff_t start_offset, const __u64 len, |
| 2506 | struct file_lock *pLockData, const __u16 lock_type, |
| 2507 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2508 | { |
| 2509 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2510 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2511 | struct cifs_posix_lock *parm_data; |
| 2512 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2513 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2514 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2515 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2516 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2517 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2518 | struct kvec rsp_iov; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2519 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2520 | cifs_dbg(FYI, "Posix Lock\n"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2521 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2522 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2523 | |
| 2524 | if (rc) |
| 2525 | return rc; |
| 2526 | |
| 2527 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2528 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2529 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2530 | pSMB->MaxSetupCount = 0; |
| 2531 | pSMB->Reserved = 0; |
| 2532 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2533 | pSMB->Reserved2 = 0; |
| 2534 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2535 | offset = param_offset + params; |
| 2536 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2537 | count = sizeof(struct cifs_posix_lock); |
| 2538 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2539 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2540 | pSMB->SetupCount = 1; |
| 2541 | pSMB->Reserved3 = 0; |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2542 | if (pLockData) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2543 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2544 | else |
| 2545 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2546 | byte_count = 3 /* pad */ + params + count; |
| 2547 | pSMB->DataCount = cpu_to_le16(count); |
| 2548 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2549 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2550 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2551 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2552 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2553 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2554 | |
| 2555 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2556 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2557 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2558 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2559 | pSMB->Timeout = cpu_to_le32(-1); |
| 2560 | } else |
| 2561 | pSMB->Timeout = 0; |
| 2562 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2563 | parm_data->pid = cpu_to_le32(netpid); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2564 | parm_data->start = cpu_to_le64(start_offset); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2565 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2566 | |
| 2567 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2568 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2569 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2570 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2571 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2572 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2573 | if (waitFlag) { |
| 2574 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2575 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2576 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2577 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2578 | 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] | 2579 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2580 | &resp_buf_type, timeout, &rsp_iov); |
| 2581 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)rsp_iov.iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2582 | } |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2583 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2584 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2585 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2586 | cifs_dbg(FYI, "Send error in Posix Lock = %d\n", rc); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2587 | } else if (pLockData) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2588 | /* lock structure can be returned on get */ |
| 2589 | __u16 data_offset; |
| 2590 | __u16 data_count; |
| 2591 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2592 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2593 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2594 | rc = -EIO; /* bad smb */ |
| 2595 | goto plk_err_exit; |
| 2596 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2597 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2598 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2599 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2600 | rc = -EIO; |
| 2601 | goto plk_err_exit; |
| 2602 | } |
| 2603 | parm_data = (struct cifs_posix_lock *) |
| 2604 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2605 | if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2606 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2607 | else { |
| 2608 | if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2609 | cpu_to_le16(CIFS_RDLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2610 | pLockData->fl_type = F_RDLCK; |
| 2611 | else if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2612 | cpu_to_le16(CIFS_WRLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2613 | pLockData->fl_type = F_WRLCK; |
| 2614 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2615 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2616 | pLockData->fl_end = pLockData->fl_start + |
| 2617 | le64_to_cpu(parm_data->length) - 1; |
Benjamin Coddington | 9d5b86a | 2017-07-16 10:28:22 -0400 | [diff] [blame] | 2618 | pLockData->fl_pid = -le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2619 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2620 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2621 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2622 | plk_err_exit: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2623 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2624 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2625 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2626 | since file handle passed in no longer valid */ |
| 2627 | |
| 2628 | return rc; |
| 2629 | } |
| 2630 | |
| 2631 | |
| 2632 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2633 | 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] | 2634 | { |
| 2635 | int rc = 0; |
| 2636 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2637 | cifs_dbg(FYI, "In CIFSSMBClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | |
| 2639 | /* do not retry on dead session on close */ |
| 2640 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2641 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | return 0; |
| 2643 | if (rc) |
| 2644 | return rc; |
| 2645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2647 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2649 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2650 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2651 | cifs_stats_inc(&tcon->stats.cifs_stats.num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2653 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2655 | cifs_dbg(VFS, "Send error in Close = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | } |
| 2657 | } |
| 2658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2660 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | rc = 0; |
| 2662 | |
| 2663 | return rc; |
| 2664 | } |
| 2665 | |
| 2666 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2667 | 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] | 2668 | { |
| 2669 | int rc = 0; |
| 2670 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2671 | cifs_dbg(FYI, "In CIFSSMBFlush\n"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2672 | |
| 2673 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2674 | if (rc) |
| 2675 | return rc; |
| 2676 | |
| 2677 | pSMB->FileID = (__u16) smb_file_id; |
| 2678 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2679 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2680 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2681 | cifs_stats_inc(&tcon->stats.cifs_stats.num_flushes); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2682 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2683 | cifs_dbg(VFS, "Send error in Flush = %d\n", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2684 | |
| 2685 | return rc; |
| 2686 | } |
| 2687 | |
| 2688 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2689 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2690 | const char *from_name, const char *to_name, |
| 2691 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | { |
| 2693 | int rc = 0; |
| 2694 | RENAME_REQ *pSMB = NULL; |
| 2695 | RENAME_RSP *pSMBr = NULL; |
| 2696 | int bytes_returned; |
| 2697 | int name_len, name_len2; |
| 2698 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 2699 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2701 | cifs_dbg(FYI, "In CIFSSMBRename\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | renameRetry: |
| 2703 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2704 | (void **) &pSMBr); |
| 2705 | if (rc) |
| 2706 | return rc; |
| 2707 | |
| 2708 | pSMB->BufferFormat = 0x04; |
| 2709 | pSMB->SearchAttributes = |
| 2710 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2711 | ATTR_DIRECTORY); |
| 2712 | |
| 2713 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2714 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2715 | from_name, PATH_MAX, |
| 2716 | cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | name_len++; /* trailing null */ |
| 2718 | name_len *= 2; |
| 2719 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2720 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2721 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2722 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2723 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2724 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 2725 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2727 | name_len2 *= 2; /* convert to bytes */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2728 | } else { |
| 2729 | name_len = copy_path_name(pSMB->OldFileName, from_name); |
| 2730 | name_len2 = copy_path_name(pSMB->OldFileName+name_len+1, to_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | name_len2++; /* signature byte */ |
| 2733 | } |
| 2734 | |
| 2735 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2736 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | pSMB->ByteCount = cpu_to_le16(count); |
| 2738 | |
| 2739 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2740 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2741 | cifs_stats_inc(&tcon->stats.cifs_stats.num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2742 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2743 | cifs_dbg(FYI, "Send error in rename = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | cifs_buf_release(pSMB); |
| 2746 | |
| 2747 | if (rc == -EAGAIN) |
| 2748 | goto renameRetry; |
| 2749 | |
| 2750 | return rc; |
| 2751 | } |
| 2752 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2753 | int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2754 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2755 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | { |
| 2757 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2758 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2759 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | char *data_offset; |
| 2761 | char dummy_string[30]; |
| 2762 | int rc = 0; |
| 2763 | int bytes_returned = 0; |
| 2764 | int len_of_str; |
| 2765 | __u16 params, param_offset, offset, count, byte_count; |
| 2766 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2767 | cifs_dbg(FYI, "Rename to File by handle\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2769 | (void **) &pSMBr); |
| 2770 | if (rc) |
| 2771 | return rc; |
| 2772 | |
| 2773 | params = 6; |
| 2774 | pSMB->MaxSetupCount = 0; |
| 2775 | pSMB->Reserved = 0; |
| 2776 | pSMB->Flags = 0; |
| 2777 | pSMB->Timeout = 0; |
| 2778 | pSMB->Reserved2 = 0; |
| 2779 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2780 | offset = param_offset + params; |
| 2781 | |
| 2782 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2783 | rename_info = (struct set_file_rename *) data_offset; |
| 2784 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2785 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | pSMB->SetupCount = 1; |
| 2787 | pSMB->Reserved3 = 0; |
| 2788 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2789 | byte_count = 3 /* pad */ + params; |
| 2790 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2791 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2792 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2793 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2794 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2795 | rename_info->overwrite = cpu_to_le32(1); |
| 2796 | rename_info->root_fid = 0; |
| 2797 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2798 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2799 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2800 | len_of_str = |
| 2801 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2802 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2804 | len_of_str = |
| 2805 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2806 | target_name, PATH_MAX, nls_codepage, |
| 2807 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | } |
| 2809 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2810 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | byte_count += count; |
| 2812 | pSMB->DataCount = cpu_to_le16(count); |
| 2813 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2814 | pSMB->Fid = netfid; |
| 2815 | pSMB->InformationLevel = |
| 2816 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2817 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2818 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2820 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2821 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2822 | cifs_stats_inc(&pTcon->stats.cifs_stats.num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2823 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2824 | cifs_dbg(FYI, "Send error in Rename (by file handle) = %d\n", |
| 2825 | rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | cifs_buf_release(pSMB); |
| 2828 | |
| 2829 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2830 | since file handle passed in no longer valid */ |
| 2831 | |
| 2832 | return rc; |
| 2833 | } |
| 2834 | |
| 2835 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2836 | CIFSSMBCopy(const unsigned int xid, struct cifs_tcon *tcon, |
| 2837 | const char *fromName, const __u16 target_tid, const char *toName, |
| 2838 | const int flags, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | { |
| 2840 | int rc = 0; |
| 2841 | COPY_REQ *pSMB = NULL; |
| 2842 | COPY_RSP *pSMBr = NULL; |
| 2843 | int bytes_returned; |
| 2844 | int name_len, name_len2; |
| 2845 | __u16 count; |
| 2846 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2847 | cifs_dbg(FYI, "In CIFSSMBCopy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | copyRetry: |
| 2849 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2850 | (void **) &pSMBr); |
| 2851 | if (rc) |
| 2852 | return rc; |
| 2853 | |
| 2854 | pSMB->BufferFormat = 0x04; |
| 2855 | pSMB->Tid2 = target_tid; |
| 2856 | |
| 2857 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2858 | |
| 2859 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2860 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2861 | fromName, PATH_MAX, nls_codepage, |
| 2862 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | name_len++; /* trailing null */ |
| 2864 | name_len *= 2; |
| 2865 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2866 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2867 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2868 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2869 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2870 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2872 | name_len2 *= 2; /* convert to bytes */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2873 | } else { |
| 2874 | name_len = copy_path_name(pSMB->OldFileName, fromName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2876 | name_len2 = copy_path_name(pSMB->OldFileName+name_len+1, toName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | name_len2++; /* signature byte */ |
| 2878 | } |
| 2879 | |
| 2880 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2881 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | pSMB->ByteCount = cpu_to_le16(count); |
| 2883 | |
| 2884 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2885 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2886 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2887 | cifs_dbg(FYI, "Send error in copy = %d with %d files copied\n", |
| 2888 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2890 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | |
| 2892 | if (rc == -EAGAIN) |
| 2893 | goto copyRetry; |
| 2894 | |
| 2895 | return rc; |
| 2896 | } |
| 2897 | |
| 2898 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2899 | CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | const char *fromName, const char *toName, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2901 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | { |
| 2903 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2904 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2905 | char *data_offset; |
| 2906 | int name_len; |
| 2907 | int name_len_target; |
| 2908 | int rc = 0; |
| 2909 | int bytes_returned = 0; |
| 2910 | __u16 params, param_offset, offset, byte_count; |
| 2911 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2912 | cifs_dbg(FYI, "In Symlink Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | createSymLinkRetry: |
| 2914 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2915 | (void **) &pSMBr); |
| 2916 | if (rc) |
| 2917 | return rc; |
| 2918 | |
| 2919 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2920 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2921 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fromName, |
| 2922 | /* find define for this maxpathcomponent */ |
| 2923 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | name_len++; /* trailing null */ |
| 2925 | name_len *= 2; |
| 2926 | |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2927 | } else { |
| 2928 | name_len = copy_path_name(pSMB->FileName, fromName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | } |
| 2930 | params = 6 + name_len; |
| 2931 | pSMB->MaxSetupCount = 0; |
| 2932 | pSMB->Reserved = 0; |
| 2933 | pSMB->Flags = 0; |
| 2934 | pSMB->Timeout = 0; |
| 2935 | pSMB->Reserved2 = 0; |
| 2936 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2937 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | offset = param_offset + params; |
| 2939 | |
| 2940 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2941 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2942 | name_len_target = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2943 | cifsConvertToUTF16((__le16 *) data_offset, toName, |
| 2944 | /* find define for this maxpathcomponent */ |
| 2945 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | name_len_target++; /* trailing null */ |
| 2947 | name_len_target *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2948 | } else { |
| 2949 | name_len_target = copy_path_name(data_offset, toName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2953 | /* BB find exact max on data count below from sess */ |
| 2954 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2955 | pSMB->SetupCount = 1; |
| 2956 | pSMB->Reserved3 = 0; |
| 2957 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2958 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2959 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2960 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2961 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2962 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2963 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2964 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2965 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2966 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2967 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2969 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2970 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2971 | cifs_stats_inc(&tcon->stats.cifs_stats.num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2972 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2973 | cifs_dbg(FYI, "Send error in SetPathInfo create symlink = %d\n", |
| 2974 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2976 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | |
| 2978 | if (rc == -EAGAIN) |
| 2979 | goto createSymLinkRetry; |
| 2980 | |
| 2981 | return rc; |
| 2982 | } |
| 2983 | |
| 2984 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2985 | CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2987 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | { |
| 2989 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2990 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2991 | char *data_offset; |
| 2992 | int name_len; |
| 2993 | int name_len_target; |
| 2994 | int rc = 0; |
| 2995 | int bytes_returned = 0; |
| 2996 | __u16 params, param_offset, offset, byte_count; |
| 2997 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2998 | cifs_dbg(FYI, "In Create Hard link Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | createHardLinkRetry: |
| 3000 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3001 | (void **) &pSMBr); |
| 3002 | if (rc) |
| 3003 | return rc; |
| 3004 | |
| 3005 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3006 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 3007 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | name_len++; /* trailing null */ |
| 3009 | name_len *= 2; |
| 3010 | |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3011 | } else { |
| 3012 | name_len = copy_path_name(pSMB->FileName, toName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | } |
| 3014 | params = 6 + name_len; |
| 3015 | pSMB->MaxSetupCount = 0; |
| 3016 | pSMB->Reserved = 0; |
| 3017 | pSMB->Flags = 0; |
| 3018 | pSMB->Timeout = 0; |
| 3019 | pSMB->Reserved2 = 0; |
| 3020 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3021 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | offset = param_offset + params; |
| 3023 | |
| 3024 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 3025 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3026 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3027 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 3028 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | name_len_target++; /* trailing null */ |
| 3030 | name_len_target *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3031 | } else { |
| 3032 | name_len_target = copy_path_name(data_offset, fromName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3036 | /* BB find exact max on data count below from sess*/ |
| 3037 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 3038 | pSMB->SetupCount = 1; |
| 3039 | pSMB->Reserved3 = 0; |
| 3040 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3041 | byte_count = 3 /* pad */ + params + name_len_target; |
| 3042 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3043 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3044 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 3045 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3046 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3047 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3048 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 3049 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3050 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3052 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3053 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3054 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3055 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3056 | cifs_dbg(FYI, "Send error in SetPathInfo (hard link) = %d\n", |
| 3057 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | |
| 3059 | cifs_buf_release(pSMB); |
| 3060 | if (rc == -EAGAIN) |
| 3061 | goto createHardLinkRetry; |
| 3062 | |
| 3063 | return rc; |
| 3064 | } |
| 3065 | |
| 3066 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3067 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3068 | const char *from_name, const char *to_name, |
| 3069 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | { |
| 3071 | int rc = 0; |
| 3072 | NT_RENAME_REQ *pSMB = NULL; |
| 3073 | RENAME_RSP *pSMBr = NULL; |
| 3074 | int bytes_returned; |
| 3075 | int name_len, name_len2; |
| 3076 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 3077 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3079 | cifs_dbg(FYI, "In CIFSCreateHardLink\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | winCreateHardLinkRetry: |
| 3081 | |
| 3082 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 3083 | (void **) &pSMBr); |
| 3084 | if (rc) |
| 3085 | return rc; |
| 3086 | |
| 3087 | pSMB->SearchAttributes = |
| 3088 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3089 | ATTR_DIRECTORY); |
| 3090 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 3091 | pSMB->ClusterCount = 0; |
| 3092 | |
| 3093 | pSMB->BufferFormat = 0x04; |
| 3094 | |
| 3095 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3096 | name_len = |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3097 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, from_name, |
| 3098 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | name_len++; /* trailing null */ |
| 3100 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 3101 | |
| 3102 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 3103 | pSMB->OldFileName[name_len] = 0x04; |
| 3104 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3106 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3107 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 3108 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 3110 | name_len2 *= 2; /* convert to bytes */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3111 | } else { |
| 3112 | name_len = copy_path_name(pSMB->OldFileName, from_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3114 | name_len2 = copy_path_name(pSMB->OldFileName+name_len+1, to_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | name_len2++; /* signature byte */ |
| 3116 | } |
| 3117 | |
| 3118 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3119 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | pSMB->ByteCount = cpu_to_le16(count); |
| 3121 | |
| 3122 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3123 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3124 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3125 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3126 | 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] | 3127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | cifs_buf_release(pSMB); |
| 3129 | if (rc == -EAGAIN) |
| 3130 | goto winCreateHardLinkRetry; |
| 3131 | |
| 3132 | return rc; |
| 3133 | } |
| 3134 | |
| 3135 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3136 | CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3137 | const unsigned char *searchName, char **symlinkinfo, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3138 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | { |
| 3140 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 3141 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3142 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3143 | int rc = 0; |
| 3144 | int bytes_returned; |
| 3145 | int name_len; |
| 3146 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3147 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3149 | cifs_dbg(FYI, "In QPathSymLinkInfo (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | |
| 3151 | querySymLinkRetry: |
| 3152 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3153 | (void **) &pSMBr); |
| 3154 | if (rc) |
| 3155 | return rc; |
| 3156 | |
| 3157 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3158 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3159 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3160 | searchName, PATH_MAX, nls_codepage, |
| 3161 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | name_len++; /* trailing null */ |
| 3163 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3164 | } else { |
| 3165 | name_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3169 | pSMB->TotalDataCount = 0; |
| 3170 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3171 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | pSMB->MaxSetupCount = 0; |
| 3173 | pSMB->Reserved = 0; |
| 3174 | pSMB->Flags = 0; |
| 3175 | pSMB->Timeout = 0; |
| 3176 | pSMB->Reserved2 = 0; |
| 3177 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3178 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | pSMB->DataCount = 0; |
| 3180 | pSMB->DataOffset = 0; |
| 3181 | pSMB->SetupCount = 1; |
| 3182 | pSMB->Reserved3 = 0; |
| 3183 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3184 | byte_count = params + 1 /* pad */ ; |
| 3185 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3186 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3187 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3188 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3189 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3191 | |
| 3192 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3193 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3194 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3195 | cifs_dbg(FYI, "Send error in QuerySymLinkInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | } else { |
| 3197 | /* decode response */ |
| 3198 | |
| 3199 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3201 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3202 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3204 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3205 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3207 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3208 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3209 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3210 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3211 | is_unicode = true; |
| 3212 | else |
| 3213 | is_unicode = false; |
| 3214 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3215 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3216 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3217 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3218 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3219 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | cifs_buf_release(pSMB); |
| 3223 | if (rc == -EAGAIN) |
| 3224 | goto querySymLinkRetry; |
| 3225 | return rc; |
| 3226 | } |
| 3227 | |
Steve French | c52a9554 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3228 | /* |
| 3229 | * Recent Windows versions now create symlinks more frequently |
| 3230 | * and they use the "reparse point" mechanism below. We can of course |
| 3231 | * do symlinks nicely to Samba and other servers which support the |
| 3232 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3233 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3234 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3235 | * In the interim this code has been moved to its own config option so |
| 3236 | * it is not compiled in by default until callers fixed up and more tested. |
| 3237 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | int |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3239 | CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
| 3240 | __u16 fid, char **symlinkinfo, |
| 3241 | const struct nls_table *nls_codepage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | { |
| 3243 | int rc = 0; |
| 3244 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3245 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3246 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3247 | bool is_unicode; |
| 3248 | unsigned int sub_len; |
| 3249 | char *sub_start; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3250 | struct reparse_symlink_data *reparse_buf; |
| 3251 | struct reparse_posix_data *posix_buf; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3252 | __u32 data_offset, data_count; |
| 3253 | char *end_of_smb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3255 | 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] | 3256 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3257 | (void **) &pSMBr); |
| 3258 | if (rc) |
| 3259 | return rc; |
| 3260 | |
| 3261 | pSMB->TotalParameterCount = 0 ; |
| 3262 | pSMB->TotalDataCount = 0; |
| 3263 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3264 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3265 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | pSMB->MaxSetupCount = 4; |
| 3267 | pSMB->Reserved = 0; |
| 3268 | pSMB->ParameterOffset = 0; |
| 3269 | pSMB->DataCount = 0; |
| 3270 | pSMB->DataOffset = 0; |
| 3271 | pSMB->SetupCount = 4; |
| 3272 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3273 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3274 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3275 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3276 | pSMB->IsRootFlag = 0; |
| 3277 | pSMB->Fid = fid; /* file handle always le */ |
| 3278 | pSMB->ByteCount = 0; |
| 3279 | |
| 3280 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3281 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3282 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3283 | cifs_dbg(FYI, "Send error in QueryReparseLinkInfo = %d\n", rc); |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3284 | goto qreparse_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3286 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3287 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3288 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3289 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3290 | /* BB also check enough total bytes returned */ |
| 3291 | rc = -EIO; /* bad smb */ |
| 3292 | goto qreparse_out; |
| 3293 | } |
| 3294 | if (!data_count || (data_count > 2048)) { |
| 3295 | rc = -EIO; |
| 3296 | cifs_dbg(FYI, "Invalid return data count on get reparse info ioctl\n"); |
| 3297 | goto qreparse_out; |
| 3298 | } |
| 3299 | end_of_smb = 2 + get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3300 | reparse_buf = (struct reparse_symlink_data *) |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3301 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
| 3302 | if ((char *)reparse_buf >= end_of_smb) { |
| 3303 | rc = -EIO; |
| 3304 | goto qreparse_out; |
| 3305 | } |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3306 | if (reparse_buf->ReparseTag == cpu_to_le32(IO_REPARSE_TAG_NFS)) { |
| 3307 | cifs_dbg(FYI, "NFS style reparse tag\n"); |
| 3308 | posix_buf = (struct reparse_posix_data *)reparse_buf; |
| 3309 | |
| 3310 | if (posix_buf->InodeType != cpu_to_le64(NFS_SPECFILE_LNK)) { |
| 3311 | cifs_dbg(FYI, "unsupported file type 0x%llx\n", |
| 3312 | le64_to_cpu(posix_buf->InodeType)); |
| 3313 | rc = -EOPNOTSUPP; |
| 3314 | goto qreparse_out; |
| 3315 | } |
| 3316 | is_unicode = true; |
| 3317 | sub_len = le16_to_cpu(reparse_buf->ReparseDataLength); |
| 3318 | if (posix_buf->PathBuffer + sub_len > end_of_smb) { |
| 3319 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3320 | rc = -EIO; |
| 3321 | goto qreparse_out; |
| 3322 | } |
| 3323 | *symlinkinfo = cifs_strndup_from_utf16(posix_buf->PathBuffer, |
| 3324 | sub_len, is_unicode, nls_codepage); |
| 3325 | goto qreparse_out; |
| 3326 | } else if (reparse_buf->ReparseTag != |
| 3327 | cpu_to_le32(IO_REPARSE_TAG_SYMLINK)) { |
| 3328 | rc = -EOPNOTSUPP; |
| 3329 | goto qreparse_out; |
| 3330 | } |
| 3331 | |
| 3332 | /* Reparse tag is NTFS symlink */ |
| 3333 | sub_start = le16_to_cpu(reparse_buf->SubstituteNameOffset) + |
| 3334 | reparse_buf->PathBuffer; |
| 3335 | sub_len = le16_to_cpu(reparse_buf->SubstituteNameLength); |
| 3336 | if (sub_start + sub_len > end_of_smb) { |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3337 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3338 | rc = -EIO; |
| 3339 | goto qreparse_out; |
| 3340 | } |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3341 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3342 | is_unicode = true; |
| 3343 | else |
| 3344 | is_unicode = false; |
| 3345 | |
| 3346 | /* BB FIXME investigate remapping reserved chars here */ |
| 3347 | *symlinkinfo = cifs_strndup_from_utf16(sub_start, sub_len, is_unicode, |
| 3348 | nls_codepage); |
| 3349 | if (!*symlinkinfo) |
| 3350 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3352 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3354 | /* |
| 3355 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3356 | * since file handle passed in no longer valid. |
| 3357 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | return rc; |
| 3359 | } |
| 3360 | |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3361 | int |
| 3362 | CIFSSMB_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 3363 | __u16 fid) |
| 3364 | { |
| 3365 | int rc = 0; |
| 3366 | int bytes_returned; |
| 3367 | struct smb_com_transaction_compr_ioctl_req *pSMB; |
| 3368 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
| 3369 | |
| 3370 | cifs_dbg(FYI, "Set compression for %u\n", fid); |
| 3371 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3372 | (void **) &pSMBr); |
| 3373 | if (rc) |
| 3374 | return rc; |
| 3375 | |
| 3376 | pSMB->compression_state = cpu_to_le16(COMPRESSION_FORMAT_DEFAULT); |
| 3377 | |
| 3378 | pSMB->TotalParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3379 | pSMB->TotalDataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3380 | pSMB->MaxParameterCount = 0; |
| 3381 | pSMB->MaxDataCount = 0; |
| 3382 | pSMB->MaxSetupCount = 4; |
| 3383 | pSMB->Reserved = 0; |
| 3384 | pSMB->ParameterOffset = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3385 | pSMB->DataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3386 | pSMB->DataOffset = |
| 3387 | cpu_to_le32(offsetof(struct smb_com_transaction_compr_ioctl_req, |
| 3388 | compression_state) - 4); /* 84 */ |
| 3389 | pSMB->SetupCount = 4; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3390 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3391 | pSMB->ParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3392 | pSMB->FunctionCode = cpu_to_le32(FSCTL_SET_COMPRESSION); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3393 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3394 | pSMB->IsRootFlag = 0; |
| 3395 | pSMB->Fid = fid; /* file handle always le */ |
| 3396 | /* 3 byte pad, followed by 2 byte compress state */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3397 | pSMB->ByteCount = cpu_to_le16(5); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3398 | inc_rfc1001_len(pSMB, 5); |
| 3399 | |
| 3400 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3401 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3402 | if (rc) |
| 3403 | cifs_dbg(FYI, "Send error in SetCompression = %d\n", rc); |
| 3404 | |
| 3405 | cifs_buf_release(pSMB); |
| 3406 | |
| 3407 | /* |
| 3408 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3409 | * since file handle passed in no longer valid. |
| 3410 | */ |
| 3411 | return rc; |
| 3412 | } |
| 3413 | |
| 3414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | #ifdef CONFIG_CIFS_POSIX |
| 3416 | |
| 3417 | /*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] | 3418 | static void cifs_convert_ace(struct posix_acl_xattr_entry *ace, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3419 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | { |
| 3421 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3422 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3423 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3424 | 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] | 3425 | /* |
| 3426 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3427 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3428 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | |
| 3430 | return; |
| 3431 | } |
| 3432 | |
| 3433 | /* 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] | 3434 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3435 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | { |
| 3437 | int size = 0; |
| 3438 | int i; |
| 3439 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3440 | struct cifs_posix_ace *pACE; |
| 3441 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3442 | struct posix_acl_xattr_header *local_acl = (void *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | |
| 3444 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3445 | return -EOPNOTSUPP; |
| 3446 | |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3447 | if (acl_type == ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3449 | pACE = &cifs_acl->ace_array[0]; |
| 3450 | size = sizeof(struct cifs_posix_acl); |
| 3451 | size += sizeof(struct cifs_posix_ace) * count; |
| 3452 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3453 | if (size_of_data_area < size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3454 | cifs_dbg(FYI, "bad CIFS POSIX ACL size %d vs. %d\n", |
| 3455 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | return -EINVAL; |
| 3457 | } |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3458 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3460 | size = sizeof(struct cifs_posix_acl); |
| 3461 | size += sizeof(struct cifs_posix_ace) * count; |
| 3462 | /* skip past access ACEs to get to default ACEs */ |
| 3463 | pACE = &cifs_acl->ace_array[count]; |
| 3464 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3465 | size += sizeof(struct cifs_posix_ace) * count; |
| 3466 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3467 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | return -EINVAL; |
| 3469 | } else { |
| 3470 | /* illegal type */ |
| 3471 | return -EINVAL; |
| 3472 | } |
| 3473 | |
| 3474 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3475 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3476 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3477 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | return -ERANGE; |
| 3479 | } else /* buffer big enough */ { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3480 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
| 3481 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3482 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3483 | for (i = 0; i < count ; i++) { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3484 | cifs_convert_ace(&ace[i], pACE); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3485 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | } |
| 3487 | } |
| 3488 | return size; |
| 3489 | } |
| 3490 | |
Hariprasad Kelam | 0aa3a24 | 2019-07-02 23:50:02 +0530 | [diff] [blame] | 3491 | static void convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3492 | const struct posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3494 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3495 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3497 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3499 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3500 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3501 | 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] | 3502 | /* |
| 3503 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3504 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3505 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | /* 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] | 3509 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3510 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | { |
| 3512 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3513 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3514 | struct posix_acl_xattr_header *local_acl = (void *)pACL; |
Eryu Guan | ae9ebe7 | 2016-10-24 20:46:40 +0800 | [diff] [blame] | 3515 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | int count; |
| 3517 | int i; |
| 3518 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3519 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | return 0; |
| 3521 | |
| 3522 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3523 | cifs_dbg(FYI, "setting acl with %d entries from buf of length %d and version of %d\n", |
| 3524 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3525 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3526 | cifs_dbg(FYI, "unknown POSIX ACL version %d\n", |
| 3527 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | return 0; |
| 3529 | } |
| 3530 | cifs_acl->version = cpu_to_le16(1); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3531 | if (acl_type == ACL_TYPE_ACCESS) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3532 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3533 | cifs_acl->default_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3534 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3535 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3536 | cifs_acl->access_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3537 | } else { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3538 | cifs_dbg(FYI, "unknown ACL type %d\n", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | return 0; |
| 3540 | } |
Hariprasad Kelam | 0aa3a24 | 2019-07-02 23:50:02 +0530 | [diff] [blame] | 3541 | for (i = 0; i < count; i++) |
| 3542 | convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], &ace[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3543 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3545 | rc += sizeof(struct cifs_posix_acl); |
| 3546 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3547 | } |
| 3548 | return rc; |
| 3549 | } |
| 3550 | |
| 3551 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3552 | CIFSSMBGetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3553 | const unsigned char *searchName, |
| 3554 | char *acl_inf, const int buflen, const int acl_type, |
| 3555 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | { |
| 3557 | /* SMB_QUERY_POSIX_ACL */ |
| 3558 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3559 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3560 | int rc = 0; |
| 3561 | int bytes_returned; |
| 3562 | int name_len; |
| 3563 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3564 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3565 | cifs_dbg(FYI, "In GetPosixACL (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | |
| 3567 | queryAclRetry: |
| 3568 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3569 | (void **) &pSMBr); |
| 3570 | if (rc) |
| 3571 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3574 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3575 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3576 | searchName, PATH_MAX, nls_codepage, |
| 3577 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | name_len++; /* trailing null */ |
| 3579 | name_len *= 2; |
| 3580 | pSMB->FileName[name_len] = 0; |
| 3581 | pSMB->FileName[name_len+1] = 0; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3582 | } else { |
| 3583 | name_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3587 | pSMB->TotalDataCount = 0; |
| 3588 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3589 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3591 | pSMB->MaxSetupCount = 0; |
| 3592 | pSMB->Reserved = 0; |
| 3593 | pSMB->Flags = 0; |
| 3594 | pSMB->Timeout = 0; |
| 3595 | pSMB->Reserved2 = 0; |
| 3596 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3597 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3598 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | pSMB->DataCount = 0; |
| 3600 | pSMB->DataOffset = 0; |
| 3601 | pSMB->SetupCount = 1; |
| 3602 | pSMB->Reserved3 = 0; |
| 3603 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3604 | byte_count = params + 1 /* pad */ ; |
| 3605 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3606 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3607 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3608 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3609 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3611 | |
| 3612 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3613 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3614 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3616 | cifs_dbg(FYI, "Send error in Query POSIX ACL = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | } else { |
| 3618 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3622 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | rc = -EIO; /* bad smb */ |
| 3624 | else { |
| 3625 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3626 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3627 | rc = cifs_copy_posix_acl(acl_inf, |
| 3628 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3629 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | } |
| 3631 | } |
| 3632 | cifs_buf_release(pSMB); |
| 3633 | if (rc == -EAGAIN) |
| 3634 | goto queryAclRetry; |
| 3635 | return rc; |
| 3636 | } |
| 3637 | |
| 3638 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3639 | CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3640 | const unsigned char *fileName, |
| 3641 | const char *local_acl, const int buflen, |
| 3642 | const int acl_type, |
| 3643 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | { |
| 3645 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3646 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3647 | char *parm_data; |
| 3648 | int name_len; |
| 3649 | int rc = 0; |
| 3650 | int bytes_returned = 0; |
| 3651 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3652 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3653 | cifs_dbg(FYI, "In SetPosixACL (Unix) for path %s\n", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | setAclRetry: |
| 3655 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3656 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | if (rc) |
| 3658 | return rc; |
| 3659 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3660 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3661 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3662 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | name_len++; /* trailing null */ |
| 3664 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3665 | } else { |
| 3666 | name_len = copy_path_name(pSMB->FileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | } |
| 3668 | params = 6 + name_len; |
| 3669 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3670 | /* BB find max SMB size from sess */ |
| 3671 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | pSMB->MaxSetupCount = 0; |
| 3673 | pSMB->Reserved = 0; |
| 3674 | pSMB->Flags = 0; |
| 3675 | pSMB->Timeout = 0; |
| 3676 | pSMB->Reserved2 = 0; |
| 3677 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3678 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | offset = param_offset + params; |
| 3680 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3681 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3682 | |
| 3683 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3684 | 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] | 3685 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3686 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | rc = -EOPNOTSUPP; |
| 3688 | goto setACLerrorExit; |
| 3689 | } |
| 3690 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3691 | pSMB->SetupCount = 1; |
| 3692 | pSMB->Reserved3 = 0; |
| 3693 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3694 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3695 | byte_count = 3 /* pad */ + params + data_count; |
| 3696 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3697 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3698 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3699 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3700 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3701 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3703 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3704 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3705 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3706 | cifs_dbg(FYI, "Set POSIX ACL returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | |
| 3708 | setACLerrorExit: |
| 3709 | cifs_buf_release(pSMB); |
| 3710 | if (rc == -EAGAIN) |
| 3711 | goto setAclRetry; |
| 3712 | return rc; |
| 3713 | } |
| 3714 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3715 | /* BB fix tabs in this function FIXME BB */ |
| 3716 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3717 | CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3718 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3719 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3720 | int rc = 0; |
| 3721 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3722 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3723 | int bytes_returned; |
| 3724 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3725 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3726 | cifs_dbg(FYI, "In GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3727 | if (tcon == NULL) |
| 3728 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3729 | |
| 3730 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3731 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3732 | (void **) &pSMBr); |
| 3733 | if (rc) |
| 3734 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3735 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3736 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3737 | pSMB->t2.TotalDataCount = 0; |
| 3738 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3739 | /* BB find exact max data count below from sess structure BB */ |
| 3740 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3741 | pSMB->t2.MaxSetupCount = 0; |
| 3742 | pSMB->t2.Reserved = 0; |
| 3743 | pSMB->t2.Flags = 0; |
| 3744 | pSMB->t2.Timeout = 0; |
| 3745 | pSMB->t2.Reserved2 = 0; |
| 3746 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3747 | Fid) - 4); |
| 3748 | pSMB->t2.DataCount = 0; |
| 3749 | pSMB->t2.DataOffset = 0; |
| 3750 | pSMB->t2.SetupCount = 1; |
| 3751 | pSMB->t2.Reserved3 = 0; |
| 3752 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3753 | byte_count = params + 1 /* pad */ ; |
| 3754 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3755 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3756 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3757 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3758 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3759 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3760 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3761 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3762 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3763 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3764 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3765 | cifs_dbg(FYI, "error %d in GetExtAttr\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3766 | } else { |
| 3767 | /* decode response */ |
| 3768 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3769 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3770 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3771 | /* If rc should we check for EOPNOSUPP and |
| 3772 | disable the srvino flag? or in caller? */ |
| 3773 | rc = -EIO; /* bad smb */ |
| 3774 | else { |
| 3775 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3776 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3777 | struct file_chattr_info *pfinfo; |
| 3778 | /* BB Do we need a cast or hash here ? */ |
| 3779 | if (count != 16) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 3780 | cifs_dbg(FYI, "Invalid size ret in GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3781 | rc = -EIO; |
| 3782 | goto GetExtAttrOut; |
| 3783 | } |
| 3784 | pfinfo = (struct file_chattr_info *) |
| 3785 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3786 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3787 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3788 | } |
| 3789 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3790 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3791 | cifs_buf_release(pSMB); |
| 3792 | if (rc == -EAGAIN) |
| 3793 | goto GetExtAttrRetry; |
| 3794 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3797 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3799 | /* |
| 3800 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3801 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3802 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3803 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3804 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3805 | * by caller |
| 3806 | */ |
| 3807 | static int |
| 3808 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3809 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3810 | void **ret_buf) |
| 3811 | { |
| 3812 | int rc; |
| 3813 | __u32 temp_offset; |
| 3814 | struct smb_com_ntransact_req *pSMB; |
| 3815 | |
| 3816 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3817 | (void **)&pSMB); |
| 3818 | if (rc) |
| 3819 | return rc; |
| 3820 | *ret_buf = (void *)pSMB; |
| 3821 | pSMB->Reserved = 0; |
| 3822 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3823 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3824 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3825 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3826 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3827 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3828 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3829 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3830 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3831 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3832 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3833 | return 0; |
| 3834 | } |
| 3835 | |
| 3836 | static int |
| 3837 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3838 | __u32 *pparmlen, __u32 *pdatalen) |
| 3839 | { |
| 3840 | char *end_of_smb; |
| 3841 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3842 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3843 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3844 | |
| 3845 | *pdatalen = 0; |
| 3846 | *pparmlen = 0; |
| 3847 | |
| 3848 | if (buf == NULL) |
| 3849 | return -EINVAL; |
| 3850 | |
| 3851 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3852 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3853 | bcc = get_bcc(&pSMBr->hdr); |
| 3854 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3855 | (char *)&pSMBr->ByteCount; |
| 3856 | |
| 3857 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3858 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3859 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3860 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3861 | |
| 3862 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3863 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3864 | |
| 3865 | /* should we also check that parm and data areas do not overlap? */ |
| 3866 | if (*ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3867 | cifs_dbg(FYI, "parms start after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3868 | return -EINVAL; |
| 3869 | } else if (parm_count + *ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3870 | cifs_dbg(FYI, "parm end after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3871 | return -EINVAL; |
| 3872 | } else if (*ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3873 | cifs_dbg(FYI, "data starts after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3874 | return -EINVAL; |
| 3875 | } else if (data_count + *ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3876 | cifs_dbg(FYI, "data %p + count %d (%p) past smb end %p start %p\n", |
| 3877 | *ppdata, data_count, (data_count + *ppdata), |
| 3878 | end_of_smb, pSMBr); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3879 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3880 | } else if (parm_count + data_count > bcc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3881 | cifs_dbg(FYI, "parm count and data count larger than SMB\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3882 | return -EINVAL; |
| 3883 | } |
| 3884 | *pdatalen = data_count; |
| 3885 | *pparmlen = parm_count; |
| 3886 | return 0; |
| 3887 | } |
| 3888 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3889 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3890 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3891 | CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3892 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3893 | { |
| 3894 | int rc = 0; |
| 3895 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3896 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3897 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3898 | struct kvec rsp_iov; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3899 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3900 | cifs_dbg(FYI, "GetCifsACL\n"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3901 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3902 | *pbuflen = 0; |
| 3903 | *acl_inf = NULL; |
| 3904 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3905 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3906 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3907 | if (rc) |
| 3908 | return rc; |
| 3909 | |
| 3910 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3911 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3912 | pSMB->MaxSetupCount = 0; |
| 3913 | pSMB->Fid = fid; /* file handle always le */ |
| 3914 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3915 | CIFS_ACL_DACL); |
| 3916 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3917 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3918 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3919 | 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] | 3920 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3921 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3922 | 0, &rsp_iov); |
| 3923 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3924 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3925 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3926 | cifs_dbg(FYI, "Send error in QuerySecDesc = %d\n", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3927 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3928 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3929 | __u32 parm_len; |
| 3930 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3931 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3932 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3933 | |
| 3934 | /* validate_nttransact */ |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3935 | rc = validate_ntransact(rsp_iov.iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3936 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3937 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3938 | goto qsec_out; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3939 | pSMBr = (struct smb_com_ntransact_rsp *)rsp_iov.iov_base; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3940 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3941 | cifs_dbg(FYI, "smb %p parm %p data %p\n", |
| 3942 | pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3943 | |
| 3944 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3945 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3946 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3947 | goto qsec_out; |
| 3948 | } |
| 3949 | |
| 3950 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3951 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3952 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3953 | if (acl_len != *pbuflen) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3954 | cifs_dbg(VFS, "acl length %d does not match %d\n", |
| 3955 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3956 | if (*pbuflen > acl_len) |
| 3957 | *pbuflen = acl_len; |
| 3958 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3959 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3960 | /* check if buffer is big enough for the acl |
| 3961 | header followed by the smallest SID */ |
| 3962 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3963 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3964 | cifs_dbg(VFS, "bad acl length %d\n", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3965 | rc = -EINVAL; |
| 3966 | *pbuflen = 0; |
| 3967 | } else { |
Silviu-Mihai Popescu | f7f7c18 | 2013-03-11 18:22:32 +0200 | [diff] [blame] | 3968 | *acl_inf = kmemdup(pdata, *pbuflen, GFP_KERNEL); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3969 | if (*acl_inf == NULL) { |
| 3970 | *pbuflen = 0; |
| 3971 | rc = -ENOMEM; |
| 3972 | } |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3973 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3974 | } |
| 3975 | qsec_out: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3976 | free_rsp_buf(buf_type, rsp_iov.iov_base); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3977 | return rc; |
| 3978 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3979 | |
| 3980 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3981 | CIFSSMBSetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3982 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3983 | { |
| 3984 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3985 | int rc = 0; |
| 3986 | int bytes_returned = 0; |
| 3987 | SET_SEC_DESC_REQ *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3988 | void *pSMBr; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3989 | |
| 3990 | setCifsAclRetry: |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3991 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3992 | if (rc) |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3993 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3994 | |
| 3995 | pSMB->MaxSetupCount = 0; |
| 3996 | pSMB->Reserved = 0; |
| 3997 | |
| 3998 | param_count = 8; |
| 3999 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 4000 | data_count = acllen; |
| 4001 | data_offset = param_offset + param_count; |
| 4002 | byte_count = 3 /* pad */ + param_count; |
| 4003 | |
| 4004 | pSMB->DataCount = cpu_to_le32(data_count); |
| 4005 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4006 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 4007 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 4008 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 4009 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 4010 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4011 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 4012 | pSMB->SetupCount = 0; |
| 4013 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 4014 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 4015 | |
| 4016 | pSMB->Fid = fid; /* file handle always le */ |
| 4017 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 4018 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4019 | |
| 4020 | if (pntsd && acllen) { |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 4021 | memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + |
| 4022 | data_offset, pntsd, acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4023 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4024 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4025 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4026 | |
| 4027 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4028 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4029 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4030 | cifs_dbg(FYI, "SetCIFSACL bytes_returned: %d, rc: %d\n", |
| 4031 | bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4032 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4033 | cifs_dbg(FYI, "Set CIFS ACL returned %d\n", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4034 | cifs_buf_release(pSMB); |
| 4035 | |
| 4036 | if (rc == -EAGAIN) |
| 4037 | goto setCifsAclRetry; |
| 4038 | |
| 4039 | return (rc); |
| 4040 | } |
| 4041 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4042 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4043 | /* Legacy Query Path Information call for lookup to old servers such |
| 4044 | as Win9x/WinME */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4045 | int |
| 4046 | SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, |
| 4047 | const char *search_name, FILE_ALL_INFO *data, |
| 4048 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4049 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4050 | QUERY_INFORMATION_REQ *pSMB; |
| 4051 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4052 | int rc = 0; |
| 4053 | int bytes_returned; |
| 4054 | int name_len; |
| 4055 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4056 | cifs_dbg(FYI, "In SMBQPath path %s\n", search_name); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4057 | QInfRetry: |
| 4058 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4059 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4060 | if (rc) |
| 4061 | return rc; |
| 4062 | |
| 4063 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4064 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4065 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4066 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4067 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4068 | name_len++; /* trailing null */ |
| 4069 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4070 | } else { |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4071 | name_len = copy_path_name(pSMB->FileName, search_name); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4072 | } |
| 4073 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4074 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4075 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4076 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 4077 | |
| 4078 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4079 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4080 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4081 | cifs_dbg(FYI, "Send error in QueryInfo = %d\n", rc); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4082 | } else if (data) { |
Arnd Bergmann | 9539020 | 2018-06-19 17:27:58 +0200 | [diff] [blame] | 4083 | struct timespec64 ts; |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4084 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4085 | |
| 4086 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4087 | /* BB FIXME - add time zone adjustment BB */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4088 | memset(data, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4089 | ts.tv_nsec = 0; |
| 4090 | ts.tv_sec = time; |
| 4091 | /* decode time fields */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4092 | data->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
| 4093 | data->LastWriteTime = data->ChangeTime; |
| 4094 | data->LastAccessTime = 0; |
| 4095 | data->AllocationSize = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4096 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4097 | data->EndOfFile = data->AllocationSize; |
| 4098 | data->Attributes = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4099 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4100 | } else |
| 4101 | rc = -EIO; /* bad buffer passed in */ |
| 4102 | |
| 4103 | cifs_buf_release(pSMB); |
| 4104 | |
| 4105 | if (rc == -EAGAIN) |
| 4106 | goto QInfRetry; |
| 4107 | |
| 4108 | return rc; |
| 4109 | } |
| 4110 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4111 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4112 | CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4113 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 4114 | { |
| 4115 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4116 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4117 | int rc = 0; |
| 4118 | int bytes_returned; |
| 4119 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4120 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4121 | QFileInfoRetry: |
| 4122 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4123 | (void **) &pSMBr); |
| 4124 | if (rc) |
| 4125 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4126 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4127 | params = 2 /* level */ + 2 /* fid */; |
| 4128 | pSMB->t2.TotalDataCount = 0; |
| 4129 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4130 | /* BB find exact max data count below from sess structure BB */ |
| 4131 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4132 | pSMB->t2.MaxSetupCount = 0; |
| 4133 | pSMB->t2.Reserved = 0; |
| 4134 | pSMB->t2.Flags = 0; |
| 4135 | pSMB->t2.Timeout = 0; |
| 4136 | pSMB->t2.Reserved2 = 0; |
| 4137 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4138 | Fid) - 4); |
| 4139 | pSMB->t2.DataCount = 0; |
| 4140 | pSMB->t2.DataOffset = 0; |
| 4141 | pSMB->t2.SetupCount = 1; |
| 4142 | pSMB->t2.Reserved3 = 0; |
| 4143 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4144 | byte_count = params + 1 /* pad */ ; |
| 4145 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4146 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4147 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 4148 | pSMB->Pad = 0; |
| 4149 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4150 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4151 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4152 | |
| 4153 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4154 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4155 | if (rc) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 4156 | cifs_dbg(FYI, "Send error in QFileInfo = %d\n", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4157 | } else { /* decode response */ |
| 4158 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4159 | |
| 4160 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4161 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4162 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4163 | rc = -EIO; /* bad smb */ |
| 4164 | else if (pFindData) { |
| 4165 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4166 | memcpy((char *) pFindData, |
| 4167 | (char *) &pSMBr->hdr.Protocol + |
| 4168 | data_offset, sizeof(FILE_ALL_INFO)); |
| 4169 | } else |
| 4170 | rc = -ENOMEM; |
| 4171 | } |
| 4172 | cifs_buf_release(pSMB); |
| 4173 | if (rc == -EAGAIN) |
| 4174 | goto QFileInfoRetry; |
| 4175 | |
| 4176 | return rc; |
| 4177 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4180 | CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4181 | const char *search_name, FILE_ALL_INFO *data, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4182 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4183 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | { |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4185 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4187 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4188 | int rc = 0; |
| 4189 | int bytes_returned; |
| 4190 | int name_len; |
| 4191 | __u16 params, byte_count; |
| 4192 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4193 | /* cifs_dbg(FYI, "In QPathInfo path %s\n", search_name); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | QPathInfoRetry: |
| 4195 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4196 | (void **) &pSMBr); |
| 4197 | if (rc) |
| 4198 | return rc; |
| 4199 | |
| 4200 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4201 | name_len = |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4202 | cifsConvertToUTF16((__le16 *) pSMB->FileName, search_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4203 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | name_len++; /* trailing null */ |
| 4205 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4206 | } else { |
| 4207 | name_len = copy_path_name(pSMB->FileName, search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | } |
| 4209 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4210 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | pSMB->TotalDataCount = 0; |
| 4212 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4213 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4214 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | pSMB->MaxSetupCount = 0; |
| 4216 | pSMB->Reserved = 0; |
| 4217 | pSMB->Flags = 0; |
| 4218 | pSMB->Timeout = 0; |
| 4219 | pSMB->Reserved2 = 0; |
| 4220 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4221 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | pSMB->DataCount = 0; |
| 4223 | pSMB->DataOffset = 0; |
| 4224 | pSMB->SetupCount = 1; |
| 4225 | pSMB->Reserved3 = 0; |
| 4226 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4227 | byte_count = params + 1 /* pad */ ; |
| 4228 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4229 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4230 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4231 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4232 | else |
| 4233 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4235 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4237 | |
| 4238 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4239 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4240 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4241 | cifs_dbg(FYI, "Send error in QPathInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | } else { /* decode response */ |
| 4243 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4244 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4245 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4246 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4247 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4249 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4250 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4251 | last field */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4252 | else if (data) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4253 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4255 | |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4256 | /* |
| 4257 | * On legacy responses we do not read the last field, |
| 4258 | * EAsize, fortunately since it varies by subdialect and |
| 4259 | * also note it differs on Set vs Get, ie two bytes or 4 |
| 4260 | * bytes depending but we don't care here. |
| 4261 | */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4262 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4263 | size = sizeof(FILE_INFO_STANDARD); |
| 4264 | else |
| 4265 | size = sizeof(FILE_ALL_INFO); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4266 | memcpy((char *) data, (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4267 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | } else |
| 4269 | rc = -ENOMEM; |
| 4270 | } |
| 4271 | cifs_buf_release(pSMB); |
| 4272 | if (rc == -EAGAIN) |
| 4273 | goto QPathInfoRetry; |
| 4274 | |
| 4275 | return rc; |
| 4276 | } |
| 4277 | |
| 4278 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4279 | CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4280 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4281 | { |
| 4282 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4283 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4284 | int rc = 0; |
| 4285 | int bytes_returned; |
| 4286 | __u16 params, byte_count; |
| 4287 | |
| 4288 | UnixQFileInfoRetry: |
| 4289 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4290 | (void **) &pSMBr); |
| 4291 | if (rc) |
| 4292 | return rc; |
| 4293 | |
| 4294 | params = 2 /* level */ + 2 /* fid */; |
| 4295 | pSMB->t2.TotalDataCount = 0; |
| 4296 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4297 | /* BB find exact max data count below from sess structure BB */ |
| 4298 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4299 | pSMB->t2.MaxSetupCount = 0; |
| 4300 | pSMB->t2.Reserved = 0; |
| 4301 | pSMB->t2.Flags = 0; |
| 4302 | pSMB->t2.Timeout = 0; |
| 4303 | pSMB->t2.Reserved2 = 0; |
| 4304 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4305 | Fid) - 4); |
| 4306 | pSMB->t2.DataCount = 0; |
| 4307 | pSMB->t2.DataOffset = 0; |
| 4308 | pSMB->t2.SetupCount = 1; |
| 4309 | pSMB->t2.Reserved3 = 0; |
| 4310 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4311 | byte_count = params + 1 /* pad */ ; |
| 4312 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4313 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4314 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4315 | pSMB->Pad = 0; |
| 4316 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4317 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4318 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4319 | |
| 4320 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4321 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4322 | if (rc) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 4323 | cifs_dbg(FYI, "Send error in UnixQFileInfo = %d\n", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4324 | } else { /* decode response */ |
| 4325 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4326 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4327 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4328 | 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] | 4329 | rc = -EIO; /* bad smb */ |
| 4330 | } else { |
| 4331 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4332 | memcpy((char *) pFindData, |
| 4333 | (char *) &pSMBr->hdr.Protocol + |
| 4334 | data_offset, |
| 4335 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | cifs_buf_release(pSMB); |
| 4340 | if (rc == -EAGAIN) |
| 4341 | goto UnixQFileInfoRetry; |
| 4342 | |
| 4343 | return rc; |
| 4344 | } |
| 4345 | |
| 4346 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4347 | CIFSSMBUnixQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4349 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4350 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | { |
| 4352 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4353 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4354 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4355 | int rc = 0; |
| 4356 | int bytes_returned = 0; |
| 4357 | int name_len; |
| 4358 | __u16 params, byte_count; |
| 4359 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4360 | cifs_dbg(FYI, "In QPathInfo (Unix) the path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | UnixQPathInfoRetry: |
| 4362 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4363 | (void **) &pSMBr); |
| 4364 | if (rc) |
| 4365 | return rc; |
| 4366 | |
| 4367 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4368 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4369 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4370 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | name_len++; /* trailing null */ |
| 4372 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4373 | } else { |
| 4374 | name_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4375 | } |
| 4376 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4377 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | pSMB->TotalDataCount = 0; |
| 4379 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4380 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4381 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | pSMB->MaxSetupCount = 0; |
| 4383 | pSMB->Reserved = 0; |
| 4384 | pSMB->Flags = 0; |
| 4385 | pSMB->Timeout = 0; |
| 4386 | pSMB->Reserved2 = 0; |
| 4387 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4388 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | pSMB->DataCount = 0; |
| 4390 | pSMB->DataOffset = 0; |
| 4391 | pSMB->SetupCount = 1; |
| 4392 | pSMB->Reserved3 = 0; |
| 4393 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4394 | byte_count = params + 1 /* pad */ ; |
| 4395 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4396 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4397 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4398 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4399 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4401 | |
| 4402 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4403 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4404 | if (rc) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 4405 | cifs_dbg(FYI, "Send error in UnixQPathInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | } else { /* decode response */ |
| 4407 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4408 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4409 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4410 | 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] | 4411 | rc = -EIO; /* bad smb */ |
| 4412 | } else { |
| 4413 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4414 | memcpy((char *) pFindData, |
| 4415 | (char *) &pSMBr->hdr.Protocol + |
| 4416 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4417 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | } |
| 4419 | } |
| 4420 | cifs_buf_release(pSMB); |
| 4421 | if (rc == -EAGAIN) |
| 4422 | goto UnixQPathInfoRetry; |
| 4423 | |
| 4424 | return rc; |
| 4425 | } |
| 4426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4428 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4429 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4430 | const char *searchName, struct cifs_sb_info *cifs_sb, |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4431 | __u16 *pnetfid, __u16 search_flags, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4432 | struct cifs_search_info *psrch_inf, bool msearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | { |
| 4434 | /* level 257 SMB_ */ |
| 4435 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4436 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4437 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | int rc = 0; |
| 4439 | int bytes_returned = 0; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4440 | int name_len, remap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | __u16 params, byte_count; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4442 | struct nls_table *nls_codepage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4444 | cifs_dbg(FYI, "In FindFirst for %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | |
| 4446 | findFirstRetry: |
| 4447 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4448 | (void **) &pSMBr); |
| 4449 | if (rc) |
| 4450 | return rc; |
| 4451 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4452 | nls_codepage = cifs_sb->local_nls; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 4453 | remap = cifs_remap(cifs_sb); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4456 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4457 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4458 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4459 | /* We can not add the asterik earlier in case |
| 4460 | it got remapped to 0xF03A as if it were part of the |
| 4461 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | name_len *= 2; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4463 | if (msearch) { |
| 4464 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
| 4465 | pSMB->FileName[name_len+1] = 0; |
| 4466 | pSMB->FileName[name_len+2] = '*'; |
| 4467 | pSMB->FileName[name_len+3] = 0; |
| 4468 | name_len += 4; /* now the trailing null */ |
| 4469 | /* null terminate just in case */ |
| 4470 | pSMB->FileName[name_len] = 0; |
| 4471 | pSMB->FileName[name_len+1] = 0; |
| 4472 | name_len += 2; |
| 4473 | } |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4474 | } else { |
| 4475 | name_len = copy_path_name(pSMB->FileName, searchName); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4476 | if (msearch) { |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4477 | if (WARN_ON_ONCE(name_len > PATH_MAX-2)) |
| 4478 | name_len = PATH_MAX-2; |
| 4479 | /* overwrite nul byte */ |
| 4480 | pSMB->FileName[name_len-1] = CIFS_DIR_SEP(cifs_sb); |
| 4481 | pSMB->FileName[name_len] = '*'; |
| 4482 | pSMB->FileName[name_len+1] = 0; |
| 4483 | name_len += 2; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4484 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | params = 12 + name_len /* includes null */ ; |
| 4488 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4489 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4490 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | pSMB->MaxSetupCount = 0; |
| 4492 | pSMB->Reserved = 0; |
| 4493 | pSMB->Flags = 0; |
| 4494 | pSMB->Timeout = 0; |
| 4495 | pSMB->Reserved2 = 0; |
| 4496 | byte_count = params + 1 /* pad */ ; |
| 4497 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4498 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4499 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4500 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4501 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | pSMB->DataCount = 0; |
| 4503 | pSMB->DataOffset = 0; |
| 4504 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4505 | pSMB->Reserved3 = 0; |
| 4506 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4507 | pSMB->SearchAttributes = |
| 4508 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4509 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4510 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4511 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4513 | |
| 4514 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4515 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4516 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4518 | |
| 4519 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4520 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4521 | cifs_stats_inc(&tcon->stats.cifs_stats.num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4523 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4524 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4526 | cifs_dbg(FYI, "Error in FindFirst = %d\n", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4527 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4528 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | |
| 4530 | /* BB eventually could optimize out free and realloc of buf */ |
| 4531 | /* for this case */ |
| 4532 | if (rc == -EAGAIN) |
| 4533 | goto findFirstRetry; |
| 4534 | } else { /* decode response */ |
| 4535 | /* BB remember to free buffer if error BB */ |
| 4536 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4537 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4538 | unsigned int lnoff; |
| 4539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4541 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4543 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | |
| 4545 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
zhengbin | 01d1bd7 | 2019-12-25 11:30:21 +0800 | [diff] [blame] | 4546 | psrch_inf->smallBuf = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4547 | psrch_inf->srch_entries_start = |
| 4548 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4550 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4551 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4552 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4553 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4554 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4556 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4558 | psrch_inf->entries_in_buffer = |
| 4559 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4560 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4562 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4563 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4564 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4565 | psrch_inf->last_entry = NULL; |
| 4566 | return rc; |
| 4567 | } |
| 4568 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4569 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4570 | lnoff; |
| 4571 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4572 | if (pnetfid) |
| 4573 | *pnetfid = parms->SearchHandle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | } else { |
| 4575 | cifs_buf_release(pSMB); |
| 4576 | } |
| 4577 | } |
| 4578 | |
| 4579 | return rc; |
| 4580 | } |
| 4581 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4582 | int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, |
| 4583 | __u16 searchHandle, __u16 search_flags, |
| 4584 | struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | { |
| 4586 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4587 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4588 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | char *response_data; |
| 4590 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4591 | int bytes_returned; |
| 4592 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | __u16 params, byte_count; |
| 4594 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4595 | cifs_dbg(FYI, "In FindNext\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4597 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | return -ENOENT; |
| 4599 | |
| 4600 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4601 | (void **) &pSMBr); |
| 4602 | if (rc) |
| 4603 | return rc; |
| 4604 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4605 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | byte_count = 0; |
| 4607 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4608 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4609 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4610 | pSMB->MaxSetupCount = 0; |
| 4611 | pSMB->Reserved = 0; |
| 4612 | pSMB->Flags = 0; |
| 4613 | pSMB->Timeout = 0; |
| 4614 | pSMB->Reserved2 = 0; |
| 4615 | pSMB->ParameterOffset = cpu_to_le16( |
| 4616 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4617 | pSMB->DataCount = 0; |
| 4618 | pSMB->DataOffset = 0; |
| 4619 | pSMB->SetupCount = 1; |
| 4620 | pSMB->Reserved3 = 0; |
| 4621 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4622 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4623 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4624 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4626 | pSMB->ResumeKey = psrch_inf->resume_key; |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4627 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | |
| 4629 | name_len = psrch_inf->resume_name_len; |
| 4630 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4631 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4633 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4634 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4635 | pSMB->ResumeFileName[name_len] = 0; |
| 4636 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | } else { |
| 4638 | rc = -EINVAL; |
| 4639 | goto FNext2_err_exit; |
| 4640 | } |
| 4641 | byte_count = params + 1 /* pad */ ; |
| 4642 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4643 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4644 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4648 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4649 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4650 | if (rc) { |
| 4651 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4652 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4653 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4654 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | } else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4656 | cifs_dbg(FYI, "FindNext returned = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | } else { /* decode response */ |
| 4658 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4659 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4660 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4661 | unsigned int lnoff; |
| 4662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4664 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4665 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4667 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4669 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4670 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4671 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4672 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4673 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4674 | cifs_small_buf_release( |
| 4675 | psrch_inf->ntwrk_buf_start); |
| 4676 | else |
| 4677 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | psrch_inf->srch_entries_start = response_data; |
| 4679 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
zhengbin | 01d1bd7 | 2019-12-25 11:30:21 +0800 | [diff] [blame] | 4680 | psrch_inf->smallBuf = false; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4681 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4682 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4683 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4684 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4685 | psrch_inf->entries_in_buffer = |
| 4686 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | psrch_inf->index_of_last_entry += |
| 4688 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4689 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4690 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4691 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4692 | psrch_inf->last_entry = NULL; |
| 4693 | return rc; |
| 4694 | } else |
| 4695 | psrch_inf->last_entry = |
| 4696 | psrch_inf->srch_entries_start + lnoff; |
| 4697 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4698 | /* cifs_dbg(FYI, "fnxt2 entries in buf %d index_of_last %d\n", |
| 4699 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | |
| 4701 | /* BB fixme add unlock here */ |
| 4702 | } |
| 4703 | |
| 4704 | } |
| 4705 | |
| 4706 | /* BB On error, should we leave previous search buf (and count and |
| 4707 | last entry fields) intact or free the previous one? */ |
| 4708 | |
| 4709 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4710 | since file handle passed in no longer valid */ |
| 4711 | FNext2_err_exit: |
| 4712 | if (rc != 0) |
| 4713 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | return rc; |
| 4715 | } |
| 4716 | |
| 4717 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4718 | CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4719 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | { |
| 4721 | int rc = 0; |
| 4722 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4724 | cifs_dbg(FYI, "In CIFSSMBFindClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4726 | |
| 4727 | /* no sense returning error if session restarted |
| 4728 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4729 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | return 0; |
| 4731 | if (rc) |
| 4732 | return rc; |
| 4733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | pSMB->FileID = searchHandle; |
| 4735 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4736 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4737 | cifs_small_buf_release(pSMB); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4738 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4739 | cifs_dbg(VFS, "Send error in FindClose = %d\n", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4740 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4741 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4742 | |
| 4743 | /* Since session is dead, search handle closed on server already */ |
| 4744 | if (rc == -EAGAIN) |
| 4745 | rc = 0; |
| 4746 | |
| 4747 | return rc; |
| 4748 | } |
| 4749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4751 | CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4752 | const char *search_name, __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4753 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | { |
| 4755 | int rc = 0; |
| 4756 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4757 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4758 | int name_len, bytes_returned; |
| 4759 | __u16 params, byte_count; |
| 4760 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4761 | cifs_dbg(FYI, "In GetSrvInodeNum for %s\n", search_name); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4762 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4763 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | |
| 4765 | GetInodeNumberRetry: |
| 4766 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4767 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | if (rc) |
| 4769 | return rc; |
| 4770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4772 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4773 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4774 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4775 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | name_len++; /* trailing null */ |
| 4777 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4778 | } else { |
| 4779 | name_len = copy_path_name(pSMB->FileName, search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4783 | pSMB->TotalDataCount = 0; |
| 4784 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4785 | /* BB find exact max data count below from sess structure BB */ |
| 4786 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4787 | pSMB->MaxSetupCount = 0; |
| 4788 | pSMB->Reserved = 0; |
| 4789 | pSMB->Flags = 0; |
| 4790 | pSMB->Timeout = 0; |
| 4791 | pSMB->Reserved2 = 0; |
| 4792 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4793 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | pSMB->DataCount = 0; |
| 4795 | pSMB->DataOffset = 0; |
| 4796 | pSMB->SetupCount = 1; |
| 4797 | pSMB->Reserved3 = 0; |
| 4798 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4799 | byte_count = params + 1 /* pad */ ; |
| 4800 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4801 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4802 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4803 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4804 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4805 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4806 | |
| 4807 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4808 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4809 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4810 | cifs_dbg(FYI, "error %d in QueryInternalInfo\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | } else { |
| 4812 | /* decode response */ |
| 4813 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4815 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | /* If rc should we check for EOPNOSUPP and |
| 4817 | disable the srvino flag? or in caller? */ |
| 4818 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4819 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4821 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4822 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4824 | if (count < 8) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 4825 | cifs_dbg(FYI, "Invalid size ret in QryIntrnlInf\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | rc = -EIO; |
| 4827 | goto GetInodeNumOut; |
| 4828 | } |
| 4829 | pfinfo = (struct file_internal_info *) |
| 4830 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4831 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | } |
| 4833 | } |
| 4834 | GetInodeNumOut: |
| 4835 | cifs_buf_release(pSMB); |
| 4836 | if (rc == -EAGAIN) |
| 4837 | goto GetInodeNumberRetry; |
| 4838 | return rc; |
| 4839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | |
| 4841 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4842 | CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4843 | const char *search_name, struct dfs_info3_param **target_nodes, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4844 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4845 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | { |
| 4847 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4848 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4849 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | int rc = 0; |
| 4851 | int bytes_returned; |
| 4852 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4854 | *num_of_nodes = 0; |
| 4855 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4857 | cifs_dbg(FYI, "In GetDFSRefer the path %s\n", search_name); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4858 | if (ses == NULL || ses->tcon_ipc == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | return -ENODEV; |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | getDFSRetry: |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4862 | rc = smb_init(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | (void **) &pSMBr); |
| 4864 | if (rc) |
| 4865 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4866 | |
| 4867 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4868 | but should never be null here anyway */ |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 4869 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4870 | pSMB->hdr.Tid = ses->tcon_ipc->tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4872 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4874 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | |
| 4877 | if (ses->capabilities & CAP_UNICODE) { |
| 4878 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4879 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4880 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4881 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4882 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | name_len++; /* trailing null */ |
| 4884 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4885 | } else { /* BB improve the check for buffer overruns BB */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4886 | name_len = copy_path_name(pSMB->RequestFileName, search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
Dan Carpenter | 65c3b20 | 2015-04-30 17:30:24 +0300 | [diff] [blame] | 4889 | if (ses->server->sign) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 4890 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4891 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4892 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4895 | pSMB->TotalDataCount = 0; |
| 4896 | pSMB->DataCount = 0; |
| 4897 | pSMB->DataOffset = 0; |
| 4898 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4899 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4900 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | pSMB->MaxSetupCount = 0; |
| 4902 | pSMB->Reserved = 0; |
| 4903 | pSMB->Flags = 0; |
| 4904 | pSMB->Timeout = 0; |
| 4905 | pSMB->Reserved2 = 0; |
| 4906 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4907 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | pSMB->SetupCount = 1; |
| 4909 | pSMB->Reserved3 = 0; |
| 4910 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4911 | byte_count = params + 3 /* pad */ ; |
| 4912 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4913 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4914 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4915 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4917 | |
| 4918 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4919 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4920 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4921 | cifs_dbg(FYI, "Send error in GetDFSRefer = %d\n", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4922 | goto GetDFSRefExit; |
| 4923 | } |
| 4924 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4926 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4927 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4928 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4929 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4931 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4932 | cifs_dbg(FYI, "Decoding GetDFSRefer response BCC: %d Offset %d\n", |
| 4933 | get_bcc(&pSMBr->hdr), le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4934 | |
| 4935 | /* parse returned result into more usable form */ |
Aurelien Aptel | 4ecce92 | 2017-02-13 16:03:47 +0100 | [diff] [blame] | 4936 | rc = parse_dfs_referrals(&pSMBr->dfs_data, |
| 4937 | le16_to_cpu(pSMBr->t2.DataCount), |
| 4938 | num_of_nodes, target_nodes, nls_codepage, |
| 4939 | remap, search_name, |
Steve French | 284316d | 2017-03-02 15:42:48 -0600 | [diff] [blame] | 4940 | (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) != 0); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4943 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | |
| 4945 | if (rc == -EAGAIN) |
| 4946 | goto getDFSRetry; |
| 4947 | |
| 4948 | return rc; |
| 4949 | } |
| 4950 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4951 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4952 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4953 | SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 4954 | struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4955 | { |
| 4956 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4957 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4958 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4959 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4960 | int rc = 0; |
| 4961 | int bytes_returned = 0; |
| 4962 | __u16 params, byte_count; |
| 4963 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4964 | cifs_dbg(FYI, "OldQFSInfo\n"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4965 | oldQFSInfoRetry: |
| 4966 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4967 | (void **) &pSMBr); |
| 4968 | if (rc) |
| 4969 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4970 | |
| 4971 | params = 2; /* level */ |
| 4972 | pSMB->TotalDataCount = 0; |
| 4973 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4974 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4975 | pSMB->MaxSetupCount = 0; |
| 4976 | pSMB->Reserved = 0; |
| 4977 | pSMB->Flags = 0; |
| 4978 | pSMB->Timeout = 0; |
| 4979 | pSMB->Reserved2 = 0; |
| 4980 | byte_count = params + 1 /* pad */ ; |
| 4981 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4982 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4983 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4984 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4985 | pSMB->DataCount = 0; |
| 4986 | pSMB->DataOffset = 0; |
| 4987 | pSMB->SetupCount = 1; |
| 4988 | pSMB->Reserved3 = 0; |
| 4989 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4990 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4991 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4992 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4993 | |
| 4994 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4995 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4996 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4997 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4998 | } else { /* decode response */ |
| 4999 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5000 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5001 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5002 | rc = -EIO; /* bad smb */ |
| 5003 | else { |
| 5004 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5005 | cifs_dbg(FYI, "qfsinf resp BCC: %d Offset %d\n", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5006 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5007 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5008 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5009 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 5010 | FSData->f_bsize = |
| 5011 | le16_to_cpu(response_data->BytesPerSector) * |
| 5012 | le32_to_cpu(response_data-> |
| 5013 | SectorsPerAllocationUnit); |
Steve French | 5a519be | 2018-09-15 14:07:09 -0500 | [diff] [blame] | 5014 | /* |
| 5015 | * much prefer larger but if server doesn't report |
| 5016 | * a valid size than 4K is a reasonable minimum |
| 5017 | */ |
| 5018 | if (FSData->f_bsize < 512) |
| 5019 | FSData->f_bsize = 4096; |
| 5020 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5021 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5022 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5023 | FSData->f_bfree = FSData->f_bavail = |
| 5024 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5025 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5026 | (unsigned long long)FSData->f_blocks, |
| 5027 | (unsigned long long)FSData->f_bfree, |
| 5028 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5029 | } |
| 5030 | } |
| 5031 | cifs_buf_release(pSMB); |
| 5032 | |
| 5033 | if (rc == -EAGAIN) |
| 5034 | goto oldQFSInfoRetry; |
| 5035 | |
| 5036 | return rc; |
| 5037 | } |
| 5038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5040 | CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 5041 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | { |
| 5043 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5044 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5045 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5046 | FILE_SYSTEM_INFO *response_data; |
| 5047 | int rc = 0; |
| 5048 | int bytes_returned = 0; |
| 5049 | __u16 params, byte_count; |
| 5050 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5051 | cifs_dbg(FYI, "In QFSInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | QFSInfoRetry: |
| 5053 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5054 | (void **) &pSMBr); |
| 5055 | if (rc) |
| 5056 | return rc; |
| 5057 | |
| 5058 | params = 2; /* level */ |
| 5059 | pSMB->TotalDataCount = 0; |
| 5060 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5061 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | pSMB->MaxSetupCount = 0; |
| 5063 | pSMB->Reserved = 0; |
| 5064 | pSMB->Flags = 0; |
| 5065 | pSMB->Timeout = 0; |
| 5066 | pSMB->Reserved2 = 0; |
| 5067 | byte_count = params + 1 /* pad */ ; |
| 5068 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5069 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5070 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5071 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5072 | pSMB->DataCount = 0; |
| 5073 | pSMB->DataOffset = 0; |
| 5074 | pSMB->SetupCount = 1; |
| 5075 | pSMB->Reserved3 = 0; |
| 5076 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5077 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5078 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5080 | |
| 5081 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5082 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5083 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5084 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5086 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5087 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5088 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5089 | rc = -EIO; /* bad smb */ |
| 5090 | else { |
| 5091 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | |
| 5093 | response_data = |
| 5094 | (FILE_SYSTEM_INFO |
| 5095 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5096 | data_offset); |
| 5097 | FSData->f_bsize = |
| 5098 | le32_to_cpu(response_data->BytesPerSector) * |
| 5099 | le32_to_cpu(response_data-> |
| 5100 | SectorsPerAllocationUnit); |
Steve French | 5a519be | 2018-09-15 14:07:09 -0500 | [diff] [blame] | 5101 | /* |
| 5102 | * much prefer larger but if server doesn't report |
| 5103 | * a valid size than 4K is a reasonable minimum |
| 5104 | */ |
| 5105 | if (FSData->f_bsize < 512) |
| 5106 | FSData->f_bsize = 4096; |
| 5107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | FSData->f_blocks = |
| 5109 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 5110 | FSData->f_bfree = FSData->f_bavail = |
| 5111 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5112 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5113 | (unsigned long long)FSData->f_blocks, |
| 5114 | (unsigned long long)FSData->f_bfree, |
| 5115 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5116 | } |
| 5117 | } |
| 5118 | cifs_buf_release(pSMB); |
| 5119 | |
| 5120 | if (rc == -EAGAIN) |
| 5121 | goto QFSInfoRetry; |
| 5122 | |
| 5123 | return rc; |
| 5124 | } |
| 5125 | |
| 5126 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5127 | CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | { |
| 5129 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5130 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5131 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5132 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5133 | int rc = 0; |
| 5134 | int bytes_returned = 0; |
| 5135 | __u16 params, byte_count; |
| 5136 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5137 | cifs_dbg(FYI, "In QFSAttributeInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | QFSAttributeRetry: |
| 5139 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5140 | (void **) &pSMBr); |
| 5141 | if (rc) |
| 5142 | return rc; |
| 5143 | |
| 5144 | params = 2; /* level */ |
| 5145 | pSMB->TotalDataCount = 0; |
| 5146 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5147 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5148 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | pSMB->MaxSetupCount = 0; |
| 5150 | pSMB->Reserved = 0; |
| 5151 | pSMB->Flags = 0; |
| 5152 | pSMB->Timeout = 0; |
| 5153 | pSMB->Reserved2 = 0; |
| 5154 | byte_count = params + 1 /* pad */ ; |
| 5155 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5156 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5157 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5158 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5159 | pSMB->DataCount = 0; |
| 5160 | pSMB->DataOffset = 0; |
| 5161 | pSMB->SetupCount = 1; |
| 5162 | pSMB->Reserved3 = 0; |
| 5163 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5164 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5165 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5166 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5167 | |
| 5168 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5169 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5170 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5171 | cifs_dbg(VFS, "Send error in QFSAttributeInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | } else { /* decode response */ |
| 5173 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5174 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5175 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5176 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | rc = -EIO; /* bad smb */ |
| 5178 | } else { |
| 5179 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5180 | response_data = |
| 5181 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5182 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5183 | data_offset); |
| 5184 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5185 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 | } |
| 5187 | } |
| 5188 | cifs_buf_release(pSMB); |
| 5189 | |
| 5190 | if (rc == -EAGAIN) |
| 5191 | goto QFSAttributeRetry; |
| 5192 | |
| 5193 | return rc; |
| 5194 | } |
| 5195 | |
| 5196 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5197 | CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | { |
| 5199 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5200 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5201 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5202 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5203 | int rc = 0; |
| 5204 | int bytes_returned = 0; |
| 5205 | __u16 params, byte_count; |
| 5206 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5207 | cifs_dbg(FYI, "In QFSDeviceInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | QFSDeviceRetry: |
| 5209 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5210 | (void **) &pSMBr); |
| 5211 | if (rc) |
| 5212 | return rc; |
| 5213 | |
| 5214 | params = 2; /* level */ |
| 5215 | pSMB->TotalDataCount = 0; |
| 5216 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5217 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5218 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | pSMB->MaxSetupCount = 0; |
| 5220 | pSMB->Reserved = 0; |
| 5221 | pSMB->Flags = 0; |
| 5222 | pSMB->Timeout = 0; |
| 5223 | pSMB->Reserved2 = 0; |
| 5224 | byte_count = params + 1 /* pad */ ; |
| 5225 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5226 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5227 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5228 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | |
| 5230 | pSMB->DataCount = 0; |
| 5231 | pSMB->DataOffset = 0; |
| 5232 | pSMB->SetupCount = 1; |
| 5233 | pSMB->Reserved3 = 0; |
| 5234 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5235 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5236 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5237 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5238 | |
| 5239 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5240 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5241 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5242 | cifs_dbg(FYI, "Send error in QFSDeviceInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5243 | } else { /* decode response */ |
| 5244 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5245 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5246 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5247 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | rc = -EIO; /* bad smb */ |
| 5249 | else { |
| 5250 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5251 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5252 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5253 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | data_offset); |
| 5255 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5256 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5257 | } |
| 5258 | } |
| 5259 | cifs_buf_release(pSMB); |
| 5260 | |
| 5261 | if (rc == -EAGAIN) |
| 5262 | goto QFSDeviceRetry; |
| 5263 | |
| 5264 | return rc; |
| 5265 | } |
| 5266 | |
| 5267 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5268 | CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | { |
| 5270 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5271 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5272 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5273 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5274 | int rc = 0; |
| 5275 | int bytes_returned = 0; |
| 5276 | __u16 params, byte_count; |
| 5277 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5278 | cifs_dbg(FYI, "In QFSUnixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5279 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5280 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5281 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5282 | if (rc) |
| 5283 | return rc; |
| 5284 | |
| 5285 | params = 2; /* level */ |
| 5286 | pSMB->TotalDataCount = 0; |
| 5287 | pSMB->DataCount = 0; |
| 5288 | pSMB->DataOffset = 0; |
| 5289 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5290 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5291 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5292 | pSMB->MaxSetupCount = 0; |
| 5293 | pSMB->Reserved = 0; |
| 5294 | pSMB->Flags = 0; |
| 5295 | pSMB->Timeout = 0; |
| 5296 | pSMB->Reserved2 = 0; |
| 5297 | byte_count = params + 1 /* pad */ ; |
| 5298 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5299 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5300 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5301 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | pSMB->SetupCount = 1; |
| 5303 | pSMB->Reserved3 = 0; |
| 5304 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5305 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5306 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5307 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5308 | |
| 5309 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5310 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5311 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5312 | cifs_dbg(VFS, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | } else { /* decode response */ |
| 5314 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5315 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5316 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5317 | rc = -EIO; /* bad smb */ |
| 5318 | } else { |
| 5319 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5320 | response_data = |
| 5321 | (FILE_SYSTEM_UNIX_INFO |
| 5322 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5323 | data_offset); |
| 5324 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5325 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | } |
| 5327 | } |
| 5328 | cifs_buf_release(pSMB); |
| 5329 | |
| 5330 | if (rc == -EAGAIN) |
| 5331 | goto QFSUnixRetry; |
| 5332 | |
| 5333 | |
| 5334 | return rc; |
| 5335 | } |
| 5336 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5337 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5338 | CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5339 | { |
| 5340 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5341 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5342 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5343 | int rc = 0; |
| 5344 | int bytes_returned = 0; |
| 5345 | __u16 params, param_offset, offset, byte_count; |
| 5346 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5347 | cifs_dbg(FYI, "In SETFSUnixInfo\n"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5348 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5349 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5350 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5351 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5352 | if (rc) |
| 5353 | return rc; |
| 5354 | |
| 5355 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5356 | pSMB->MaxSetupCount = 0; |
| 5357 | pSMB->Reserved = 0; |
| 5358 | pSMB->Flags = 0; |
| 5359 | pSMB->Timeout = 0; |
| 5360 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5361 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5362 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5363 | offset = param_offset + params; |
| 5364 | |
| 5365 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5366 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5367 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5368 | pSMB->SetupCount = 1; |
| 5369 | pSMB->Reserved3 = 0; |
| 5370 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5371 | byte_count = 1 /* pad */ + params + 12; |
| 5372 | |
| 5373 | pSMB->DataCount = cpu_to_le16(12); |
| 5374 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5375 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5376 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5377 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5378 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5379 | |
| 5380 | /* Params. */ |
| 5381 | pSMB->FileNum = 0; |
| 5382 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5383 | |
| 5384 | /* Data. */ |
| 5385 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5386 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5387 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5388 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5389 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5390 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5391 | |
| 5392 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5393 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5394 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5395 | cifs_dbg(VFS, "Send error in SETFSUnixInfo = %d\n", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5396 | } else { /* decode response */ |
| 5397 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5398 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5399 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5400 | } |
| 5401 | cifs_buf_release(pSMB); |
| 5402 | |
| 5403 | if (rc == -EAGAIN) |
| 5404 | goto SETFSUnixRetry; |
| 5405 | |
| 5406 | return rc; |
| 5407 | } |
| 5408 | |
| 5409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5410 | |
| 5411 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5412 | CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5413 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5414 | { |
| 5415 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5416 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5417 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5418 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5419 | int rc = 0; |
| 5420 | int bytes_returned = 0; |
| 5421 | __u16 params, byte_count; |
| 5422 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5423 | cifs_dbg(FYI, "In QFSPosixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5424 | QFSPosixRetry: |
| 5425 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5426 | (void **) &pSMBr); |
| 5427 | if (rc) |
| 5428 | return rc; |
| 5429 | |
| 5430 | params = 2; /* level */ |
| 5431 | pSMB->TotalDataCount = 0; |
| 5432 | pSMB->DataCount = 0; |
| 5433 | pSMB->DataOffset = 0; |
| 5434 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5435 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5436 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5437 | pSMB->MaxSetupCount = 0; |
| 5438 | pSMB->Reserved = 0; |
| 5439 | pSMB->Flags = 0; |
| 5440 | pSMB->Timeout = 0; |
| 5441 | pSMB->Reserved2 = 0; |
| 5442 | byte_count = params + 1 /* pad */ ; |
| 5443 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5444 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5445 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5446 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | pSMB->SetupCount = 1; |
| 5448 | pSMB->Reserved3 = 0; |
| 5449 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5450 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5451 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5453 | |
| 5454 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5455 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5456 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5457 | cifs_dbg(FYI, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | } else { /* decode response */ |
| 5459 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5460 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5461 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5462 | rc = -EIO; /* bad smb */ |
| 5463 | } else { |
| 5464 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5465 | response_data = |
| 5466 | (FILE_SYSTEM_POSIX_INFO |
| 5467 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5468 | data_offset); |
| 5469 | FSData->f_bsize = |
| 5470 | le32_to_cpu(response_data->BlockSize); |
Steve French | 5a519be | 2018-09-15 14:07:09 -0500 | [diff] [blame] | 5471 | /* |
| 5472 | * much prefer larger but if server doesn't report |
| 5473 | * a valid size than 4K is a reasonable minimum |
| 5474 | */ |
| 5475 | if (FSData->f_bsize < 512) |
| 5476 | FSData->f_bsize = 4096; |
| 5477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 | FSData->f_blocks = |
| 5479 | le64_to_cpu(response_data->TotalBlocks); |
| 5480 | FSData->f_bfree = |
| 5481 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5482 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 | FSData->f_bavail = FSData->f_bfree; |
| 5484 | } else { |
| 5485 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5486 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5488 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5490 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5491 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5493 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | } |
| 5495 | } |
| 5496 | cifs_buf_release(pSMB); |
| 5497 | |
| 5498 | if (rc == -EAGAIN) |
| 5499 | goto QFSPosixRetry; |
| 5500 | |
| 5501 | return rc; |
| 5502 | } |
| 5503 | |
| 5504 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5505 | /* |
| 5506 | * We can not use write of zero bytes trick to set file size due to need for |
| 5507 | * large file support. Also note that this SetPathInfo is preferred to |
| 5508 | * SetFileInfo based method in next routine which is only needed to work around |
| 5509 | * a sharing violation bugin Samba which this routine can run into. |
| 5510 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5511 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5512 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5513 | const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, |
| 5514 | bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | { |
| 5516 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5517 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5518 | struct file_end_of_file_info *parm_data; |
| 5519 | int name_len; |
| 5520 | int rc = 0; |
| 5521 | int bytes_returned = 0; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 5522 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5525 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5526 | cifs_dbg(FYI, "In SetEOF\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5527 | SetEOFRetry: |
| 5528 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5529 | (void **) &pSMBr); |
| 5530 | if (rc) |
| 5531 | return rc; |
| 5532 | |
| 5533 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5534 | name_len = |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5535 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
| 5536 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | name_len++; /* trailing null */ |
| 5538 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 5539 | } else { |
| 5540 | name_len = copy_path_name(pSMB->FileName, file_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5541 | } |
| 5542 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5543 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5545 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5546 | pSMB->MaxSetupCount = 0; |
| 5547 | pSMB->Reserved = 0; |
| 5548 | pSMB->Flags = 0; |
| 5549 | pSMB->Timeout = 0; |
| 5550 | pSMB->Reserved2 = 0; |
| 5551 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5552 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | offset = param_offset + params; |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5554 | if (set_allocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5555 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5556 | pSMB->InformationLevel = |
| 5557 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5558 | else |
| 5559 | pSMB->InformationLevel = |
| 5560 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5561 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5562 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5563 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5564 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5565 | else |
| 5566 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5567 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | parm_data = |
| 5571 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5572 | offset); |
| 5573 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5574 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5575 | pSMB->SetupCount = 1; |
| 5576 | pSMB->Reserved3 = 0; |
| 5577 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5578 | byte_count = 3 /* pad */ + params + data_count; |
| 5579 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5580 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5581 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5582 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5583 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5584 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5585 | parm_data->FileSize = cpu_to_le64(size); |
| 5586 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5587 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5588 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5589 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5590 | cifs_dbg(FYI, "SetPathInfo (file size) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5591 | |
| 5592 | cifs_buf_release(pSMB); |
| 5593 | |
| 5594 | if (rc == -EAGAIN) |
| 5595 | goto SetEOFRetry; |
| 5596 | |
| 5597 | return rc; |
| 5598 | } |
| 5599 | |
| 5600 | int |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5601 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
| 5602 | struct cifsFileInfo *cfile, __u64 size, bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5603 | { |
| 5604 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | struct file_end_of_file_info *parm_data; |
| 5606 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5607 | __u16 params, param_offset, offset, byte_count, count; |
| 5608 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5609 | cifs_dbg(FYI, "SetFileSize (via SetFileInfo) %lld\n", |
| 5610 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5611 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5613 | if (rc) |
| 5614 | return rc; |
| 5615 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5616 | pSMB->hdr.Pid = cpu_to_le16((__u16)cfile->pid); |
| 5617 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(cfile->pid >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | params = 6; |
| 5620 | pSMB->MaxSetupCount = 0; |
| 5621 | pSMB->Reserved = 0; |
| 5622 | pSMB->Flags = 0; |
| 5623 | pSMB->Timeout = 0; |
| 5624 | pSMB->Reserved2 = 0; |
| 5625 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5626 | offset = param_offset + params; |
| 5627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | count = sizeof(struct file_end_of_file_info); |
| 5629 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5630 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5631 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5632 | pSMB->SetupCount = 1; |
| 5633 | pSMB->Reserved3 = 0; |
| 5634 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5635 | byte_count = 3 /* pad */ + params + count; |
| 5636 | pSMB->DataCount = cpu_to_le16(count); |
| 5637 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5638 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5639 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5640 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5641 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5642 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5643 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5645 | parm_data->FileSize = cpu_to_le64(size); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5646 | pSMB->Fid = cfile->fid.netfid; |
| 5647 | if (set_allocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5649 | pSMB->InformationLevel = |
| 5650 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5651 | else |
| 5652 | pSMB->InformationLevel = |
| 5653 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5654 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5655 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5656 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5657 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5658 | else |
| 5659 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5660 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | } |
| 5662 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5663 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5664 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5665 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5666 | cifs_small_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5668 | cifs_dbg(FYI, "Send error in SetFileInfo (SetFileSize) = %d\n", |
| 5669 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5670 | } |
| 5671 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5672 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5673 | since file handle passed in no longer valid */ |
| 5674 | |
| 5675 | return rc; |
| 5676 | } |
| 5677 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5678 | /* 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] | 5679 | an open handle, rather than by pathname - this is awkward due to |
| 5680 | potential access conflicts on the open, but it is unavoidable for these |
| 5681 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5682 | time and resort to the original setpathinfo level which takes the ancient |
| 5683 | DOS time format with 2 second granularity */ |
| 5684 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5685 | CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5686 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | { |
| 5688 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5689 | char *data_offset; |
| 5690 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5691 | __u16 params, param_offset, offset, byte_count, count; |
| 5692 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5693 | cifs_dbg(FYI, "Set Times (via SetFileInfo)\n"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5694 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5695 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | if (rc) |
| 5697 | return rc; |
| 5698 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5699 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5700 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | params = 6; |
| 5703 | pSMB->MaxSetupCount = 0; |
| 5704 | pSMB->Reserved = 0; |
| 5705 | pSMB->Flags = 0; |
| 5706 | pSMB->Timeout = 0; |
| 5707 | pSMB->Reserved2 = 0; |
| 5708 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5709 | offset = param_offset + params; |
| 5710 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5711 | data_offset = (char *)pSMB + |
| 5712 | offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5714 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5716 | /* BB find max SMB PDU from sess */ |
| 5717 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | pSMB->SetupCount = 1; |
| 5719 | pSMB->Reserved3 = 0; |
| 5720 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5721 | byte_count = 3 /* pad */ + params + count; |
| 5722 | pSMB->DataCount = cpu_to_le16(count); |
| 5723 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5724 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5725 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5726 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5727 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5728 | pSMB->Fid = fid; |
| 5729 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5730 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5731 | else |
| 5732 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5733 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5734 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5736 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5737 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5738 | cifs_small_buf_release(pSMB); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5739 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5740 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 5741 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5743 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5744 | since file handle passed in no longer valid */ |
| 5745 | |
| 5746 | return rc; |
| 5747 | } |
| 5748 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5749 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5750 | CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5751 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5752 | { |
| 5753 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5754 | char *data_offset; |
| 5755 | int rc = 0; |
| 5756 | __u16 params, param_offset, offset, byte_count, count; |
| 5757 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5758 | cifs_dbg(FYI, "Set File Disposition (via SetFileInfo)\n"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5759 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5760 | |
| 5761 | if (rc) |
| 5762 | return rc; |
| 5763 | |
| 5764 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5765 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5766 | |
| 5767 | params = 6; |
| 5768 | pSMB->MaxSetupCount = 0; |
| 5769 | pSMB->Reserved = 0; |
| 5770 | pSMB->Flags = 0; |
| 5771 | pSMB->Timeout = 0; |
| 5772 | pSMB->Reserved2 = 0; |
| 5773 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5774 | offset = param_offset + params; |
| 5775 | |
| 5776 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5777 | |
| 5778 | count = 1; |
| 5779 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5780 | /* BB find max SMB PDU from sess */ |
| 5781 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5782 | pSMB->SetupCount = 1; |
| 5783 | pSMB->Reserved3 = 0; |
| 5784 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5785 | byte_count = 3 /* pad */ + params + count; |
| 5786 | pSMB->DataCount = cpu_to_le16(count); |
| 5787 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5788 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5789 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5790 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5791 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5792 | pSMB->Fid = fid; |
| 5793 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5794 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5795 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5796 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5797 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5798 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5799 | cifs_small_buf_release(pSMB); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5800 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5801 | cifs_dbg(FYI, "Send error in SetFileDisposition = %d\n", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5802 | |
| 5803 | return rc; |
| 5804 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5805 | |
Ronnie Sahlberg | 8e408fc | 2020-07-15 08:18:05 +1000 | [diff] [blame] | 5806 | static int |
| 5807 | CIFSSMBSetPathInfoFB(const unsigned int xid, struct cifs_tcon *tcon, |
| 5808 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5809 | const struct nls_table *nls_codepage, |
| 5810 | struct cifs_sb_info *cifs_sb) |
| 5811 | { |
| 5812 | int oplock = 0; |
| 5813 | struct cifs_open_parms oparms; |
| 5814 | struct cifs_fid fid; |
| 5815 | int rc; |
| 5816 | |
| 5817 | oparms.tcon = tcon; |
| 5818 | oparms.cifs_sb = cifs_sb; |
| 5819 | oparms.desired_access = GENERIC_WRITE; |
| 5820 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
| 5821 | oparms.disposition = FILE_OPEN; |
| 5822 | oparms.path = fileName; |
| 5823 | oparms.fid = &fid; |
| 5824 | oparms.reconnect = false; |
| 5825 | |
| 5826 | rc = CIFS_open(xid, &oparms, &oplock, NULL); |
| 5827 | if (rc) |
| 5828 | goto out; |
| 5829 | |
| 5830 | rc = CIFSSMBSetFileInfo(xid, tcon, data, fid.netfid, current->tgid); |
| 5831 | CIFSSMBClose(xid, tcon, fid.netfid); |
| 5832 | out: |
| 5833 | |
| 5834 | return rc; |
| 5835 | } |
| 5836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5837 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5838 | CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5839 | const char *fileName, const FILE_BASIC_INFO *data, |
Ronnie Sahlberg | 8e408fc | 2020-07-15 08:18:05 +1000 | [diff] [blame] | 5840 | const struct nls_table *nls_codepage, |
| 5841 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | { |
| 5843 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5844 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5845 | int name_len; |
| 5846 | int rc = 0; |
| 5847 | int bytes_returned = 0; |
| 5848 | char *data_offset; |
| 5849 | __u16 params, param_offset, offset, byte_count, count; |
Ronnie Sahlberg | 8e408fc | 2020-07-15 08:18:05 +1000 | [diff] [blame] | 5850 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5851 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5852 | cifs_dbg(FYI, "In SetTimes\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | |
| 5854 | SetTimesRetry: |
| 5855 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5856 | (void **) &pSMBr); |
| 5857 | if (rc) |
| 5858 | return rc; |
| 5859 | |
| 5860 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5861 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5862 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5863 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5864 | name_len++; /* trailing null */ |
| 5865 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 5866 | } else { |
| 5867 | name_len = copy_path_name(pSMB->FileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
| 5870 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5871 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5872 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5873 | /* BB find max SMB PDU from sess structure BB */ |
| 5874 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5875 | pSMB->MaxSetupCount = 0; |
| 5876 | pSMB->Reserved = 0; |
| 5877 | pSMB->Flags = 0; |
| 5878 | pSMB->Timeout = 0; |
| 5879 | pSMB->Reserved2 = 0; |
| 5880 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5881 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5882 | offset = param_offset + params; |
| 5883 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5884 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5885 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5886 | pSMB->SetupCount = 1; |
| 5887 | pSMB->Reserved3 = 0; |
| 5888 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5889 | byte_count = 3 /* pad */ + params + count; |
| 5890 | |
| 5891 | pSMB->DataCount = cpu_to_le16(count); |
| 5892 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5893 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5894 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5895 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5896 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5897 | else |
| 5898 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5899 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5900 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5901 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5902 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5903 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5904 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5905 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5906 | cifs_dbg(FYI, "SetPathInfo (times) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5907 | |
| 5908 | cifs_buf_release(pSMB); |
| 5909 | |
| 5910 | if (rc == -EAGAIN) |
| 5911 | goto SetTimesRetry; |
| 5912 | |
Ronnie Sahlberg | 8e408fc | 2020-07-15 08:18:05 +1000 | [diff] [blame] | 5913 | if (rc == -EOPNOTSUPP) |
| 5914 | return CIFSSMBSetPathInfoFB(xid, tcon, fileName, data, |
| 5915 | nls_codepage, cifs_sb); |
| 5916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5917 | return rc; |
| 5918 | } |
| 5919 | |
| 5920 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5921 | /* Can be used to set attributes */ |
| 5922 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5923 | handling it anyway and NT4 was what we thought it would be needed for |
| 5924 | Do not delete it until we prove whether needed for Win9x though */ |
| 5925 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5926 | CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5927 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5928 | { |
| 5929 | SETATTR_REQ *pSMB = NULL; |
| 5930 | SETATTR_RSP *pSMBr = NULL; |
| 5931 | int rc = 0; |
| 5932 | int bytes_returned; |
| 5933 | int name_len; |
| 5934 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5935 | cifs_dbg(FYI, "In SetAttrLegacy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5936 | |
| 5937 | SetAttrLgcyRetry: |
| 5938 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5939 | (void **) &pSMBr); |
| 5940 | if (rc) |
| 5941 | return rc; |
| 5942 | |
| 5943 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5944 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5945 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 5946 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5947 | name_len++; /* trailing null */ |
| 5948 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 5949 | } else { |
| 5950 | name_len = copy_path_name(pSMB->fileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5951 | } |
| 5952 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5953 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5954 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5955 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5956 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5957 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5958 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5959 | cifs_dbg(FYI, "Error in LegacySetAttr = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5960 | |
| 5961 | cifs_buf_release(pSMB); |
| 5962 | |
| 5963 | if (rc == -EAGAIN) |
| 5964 | goto SetAttrLgcyRetry; |
| 5965 | |
| 5966 | return rc; |
| 5967 | } |
| 5968 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5969 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5970 | static void |
| 5971 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5972 | const struct cifs_unix_set_info_args *args) |
| 5973 | { |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5974 | u64 uid = NO_CHANGE_64, gid = NO_CHANGE_64; |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5975 | u64 mode = args->mode; |
| 5976 | |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5977 | if (uid_valid(args->uid)) |
| 5978 | uid = from_kuid(&init_user_ns, args->uid); |
| 5979 | if (gid_valid(args->gid)) |
| 5980 | gid = from_kgid(&init_user_ns, args->gid); |
| 5981 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5982 | /* |
| 5983 | * Samba server ignores set of file size to zero due to bugs in some |
| 5984 | * older clients, but we should be precise - we use SetFileSize to |
| 5985 | * 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] | 5986 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5987 | * zero instead of -1 here |
| 5988 | */ |
| 5989 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5990 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5991 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5992 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5993 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5994 | data_offset->Uid = cpu_to_le64(uid); |
| 5995 | data_offset->Gid = cpu_to_le64(gid); |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5996 | /* better to leave device as zero when it is */ |
| 5997 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5998 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5999 | data_offset->Permissions = cpu_to_le64(mode); |
| 6000 | |
| 6001 | if (S_ISREG(mode)) |
| 6002 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 6003 | else if (S_ISDIR(mode)) |
| 6004 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 6005 | else if (S_ISLNK(mode)) |
| 6006 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 6007 | else if (S_ISCHR(mode)) |
| 6008 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 6009 | else if (S_ISBLK(mode)) |
| 6010 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 6011 | else if (S_ISFIFO(mode)) |
| 6012 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 6013 | else if (S_ISSOCK(mode)) |
| 6014 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 6015 | } |
| 6016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6017 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6018 | CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6019 | const struct cifs_unix_set_info_args *args, |
| 6020 | u16 fid, u32 pid_of_opener) |
| 6021 | { |
| 6022 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6023 | char *data_offset; |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6024 | int rc = 0; |
| 6025 | u16 params, param_offset, offset, byte_count, count; |
| 6026 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6027 | cifs_dbg(FYI, "Set Unix Info (via SetFileInfo)\n"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6028 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 6029 | |
| 6030 | if (rc) |
| 6031 | return rc; |
| 6032 | |
| 6033 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 6034 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 6035 | |
| 6036 | params = 6; |
| 6037 | pSMB->MaxSetupCount = 0; |
| 6038 | pSMB->Reserved = 0; |
| 6039 | pSMB->Flags = 0; |
| 6040 | pSMB->Timeout = 0; |
| 6041 | pSMB->Reserved2 = 0; |
| 6042 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 6043 | offset = param_offset + params; |
| 6044 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6045 | data_offset = (char *)pSMB + |
| 6046 | offsetof(struct smb_hdr, Protocol) + offset; |
| 6047 | |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6048 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 6049 | |
| 6050 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 6051 | /* BB find max SMB PDU from sess */ |
| 6052 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 6053 | pSMB->SetupCount = 1; |
| 6054 | pSMB->Reserved3 = 0; |
| 6055 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 6056 | byte_count = 3 /* pad */ + params + count; |
| 6057 | pSMB->DataCount = cpu_to_le16(count); |
| 6058 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6059 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6060 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6061 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6062 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6063 | pSMB->Fid = fid; |
| 6064 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6065 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6066 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6067 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6068 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6069 | cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6070 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 6071 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 6072 | cifs_small_buf_release(pSMB); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6073 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6074 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 6075 | rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6076 | |
| 6077 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 6078 | since file handle passed in no longer valid */ |
| 6079 | |
| 6080 | return rc; |
| 6081 | } |
| 6082 | |
| 6083 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6084 | CIFSSMBUnixSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6085 | const char *file_name, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6086 | const struct cifs_unix_set_info_args *args, |
| 6087 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6088 | { |
| 6089 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 6090 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 6091 | int name_len; |
| 6092 | int rc = 0; |
| 6093 | int bytes_returned = 0; |
| 6094 | FILE_UNIX_BASIC_INFO *data_offset; |
| 6095 | __u16 params, param_offset, offset, count, byte_count; |
| 6096 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6097 | cifs_dbg(FYI, "In SetUID/GID/Mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6098 | setPermsRetry: |
| 6099 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6100 | (void **) &pSMBr); |
| 6101 | if (rc) |
| 6102 | return rc; |
| 6103 | |
| 6104 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6105 | name_len = |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6106 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6107 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | name_len++; /* trailing null */ |
| 6109 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6110 | } else { |
| 6111 | name_len = copy_path_name(pSMB->FileName, file_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6112 | } |
| 6113 | |
| 6114 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 6115 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6116 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6117 | /* BB find max SMB PDU from sess structure BB */ |
| 6118 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6119 | pSMB->MaxSetupCount = 0; |
| 6120 | pSMB->Reserved = 0; |
| 6121 | pSMB->Flags = 0; |
| 6122 | pSMB->Timeout = 0; |
| 6123 | pSMB->Reserved2 = 0; |
| 6124 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6125 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6126 | offset = param_offset + params; |
| 6127 | data_offset = |
| 6128 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 6129 | offset); |
| 6130 | memset(data_offset, 0, count); |
| 6131 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6132 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6133 | pSMB->SetupCount = 1; |
| 6134 | pSMB->Reserved3 = 0; |
| 6135 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6136 | byte_count = 3 /* pad */ + params + count; |
| 6137 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6138 | pSMB->DataCount = cpu_to_le16(count); |
| 6139 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6140 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6141 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6142 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6143 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6144 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6145 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6146 | |
| 6147 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6148 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6149 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6150 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6151 | cifs_dbg(FYI, "SetPathInfo (perms) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6153 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6154 | if (rc == -EAGAIN) |
| 6155 | goto setPermsRetry; |
| 6156 | return rc; |
| 6157 | } |
| 6158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6159 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6160 | /* |
| 6161 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 6162 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 6163 | * it looks for that attribute name and stuffs that value into the EAData |
| 6164 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 6165 | * buffer. In both cases, the return value is either the length of the |
| 6166 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 6167 | * the data isn't copied to it, but the length is returned. |
| 6168 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6169 | ssize_t |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6170 | CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6171 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6172 | char *EAData, size_t buf_size, |
Steve French | 67b4c88 | 2017-05-12 20:59:10 -0500 | [diff] [blame] | 6173 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6174 | { |
| 6175 | /* BB assumes one setup word */ |
| 6176 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6177 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
Steve French | 67b4c88 | 2017-05-12 20:59:10 -0500 | [diff] [blame] | 6178 | int remap = cifs_remap(cifs_sb); |
| 6179 | struct nls_table *nls_codepage = cifs_sb->local_nls; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6180 | int rc = 0; |
| 6181 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6182 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6183 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6184 | struct fea *temp_fea; |
| 6185 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6186 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6187 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6188 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6189 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6190 | cifs_dbg(FYI, "In Query All EAs path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6191 | QAllEAsRetry: |
| 6192 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6193 | (void **) &pSMBr); |
| 6194 | if (rc) |
| 6195 | return rc; |
| 6196 | |
| 6197 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6198 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6199 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6200 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6201 | list_len++; /* trailing null */ |
| 6202 | list_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6203 | } else { |
| 6204 | list_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | } |
| 6206 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6207 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6208 | pSMB->TotalDataCount = 0; |
| 6209 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6210 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6211 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6212 | pSMB->MaxSetupCount = 0; |
| 6213 | pSMB->Reserved = 0; |
| 6214 | pSMB->Flags = 0; |
| 6215 | pSMB->Timeout = 0; |
| 6216 | pSMB->Reserved2 = 0; |
| 6217 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6218 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6219 | pSMB->DataCount = 0; |
| 6220 | pSMB->DataOffset = 0; |
| 6221 | pSMB->SetupCount = 1; |
| 6222 | pSMB->Reserved3 = 0; |
| 6223 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6224 | byte_count = params + 1 /* pad */ ; |
| 6225 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6226 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6227 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6228 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6229 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6230 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6231 | |
| 6232 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6233 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6234 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6235 | cifs_dbg(FYI, "Send error in QueryAllEAs = %d\n", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6236 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6237 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6238 | |
| 6239 | |
| 6240 | /* BB also check enough total bytes returned */ |
| 6241 | /* BB we need to improve the validity checking |
| 6242 | of these trans2 responses */ |
| 6243 | |
| 6244 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6245 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6246 | rc = -EIO; /* bad smb */ |
| 6247 | goto QAllEAsOut; |
| 6248 | } |
| 6249 | |
| 6250 | /* check that length of list is not more than bcc */ |
| 6251 | /* check that each entry does not go beyond length |
| 6252 | of list */ |
| 6253 | /* check that each element of each entry does not |
| 6254 | go beyond end of list */ |
| 6255 | /* validate_trans2_offsets() */ |
| 6256 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6257 | |
| 6258 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6259 | ea_response_data = (struct fealist *) |
| 6260 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6261 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6262 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6263 | cifs_dbg(FYI, "ea length %d\n", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6264 | if (list_len <= 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6265 | cifs_dbg(FYI, "empty EA list returned from server\n"); |
Steve French | 60977fc | 2014-03-25 19:46:36 -0500 | [diff] [blame] | 6266 | /* didn't find the named attribute */ |
| 6267 | if (ea_name) |
| 6268 | rc = -ENODATA; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6269 | goto QAllEAsOut; |
| 6270 | } |
| 6271 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6272 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6273 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6274 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6275 | cifs_dbg(FYI, "EA list appears to go beyond SMB\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6276 | rc = -EIO; |
| 6277 | goto QAllEAsOut; |
| 6278 | } |
| 6279 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6280 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6281 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6282 | temp_fea = ea_response_data->list; |
| 6283 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6284 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6285 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6286 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6287 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6288 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6289 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6290 | /* make sure we can read name_len and value_len */ |
| 6291 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6292 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6293 | rc = -EIO; |
| 6294 | goto QAllEAsOut; |
| 6295 | } |
| 6296 | |
| 6297 | name_len = temp_fea->name_len; |
| 6298 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6299 | list_len -= name_len + 1 + value_len; |
| 6300 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6301 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6302 | rc = -EIO; |
| 6303 | goto QAllEAsOut; |
| 6304 | } |
| 6305 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6306 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6307 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6308 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6309 | temp_ptr += name_len + 1; |
| 6310 | rc = value_len; |
| 6311 | if (buf_size == 0) |
| 6312 | goto QAllEAsOut; |
| 6313 | if ((size_t)value_len > buf_size) { |
| 6314 | rc = -ERANGE; |
| 6315 | goto QAllEAsOut; |
| 6316 | } |
| 6317 | memcpy(EAData, temp_ptr, value_len); |
| 6318 | goto QAllEAsOut; |
| 6319 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6320 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6321 | /* account for prefix user. and trailing null */ |
| 6322 | rc += (5 + 1 + name_len); |
| 6323 | if (rc < (int) buf_size) { |
| 6324 | memcpy(EAData, "user.", 5); |
| 6325 | EAData += 5; |
| 6326 | memcpy(EAData, temp_ptr, name_len); |
| 6327 | EAData += name_len; |
| 6328 | /* null terminate name */ |
| 6329 | *EAData = 0; |
| 6330 | ++EAData; |
| 6331 | } else if (buf_size == 0) { |
| 6332 | /* skip copy - calc size only */ |
| 6333 | } else { |
| 6334 | /* stop before overrun buffer */ |
| 6335 | rc = -ERANGE; |
| 6336 | break; |
| 6337 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6338 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6339 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6340 | temp_fea = (struct fea *)temp_ptr; |
| 6341 | } |
| 6342 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6343 | /* didn't find the named attribute */ |
| 6344 | if (ea_name) |
| 6345 | rc = -ENODATA; |
| 6346 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6347 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6348 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6349 | if (rc == -EAGAIN) |
| 6350 | goto QAllEAsRetry; |
| 6351 | |
| 6352 | return (ssize_t)rc; |
| 6353 | } |
| 6354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6355 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6356 | CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, |
| 6357 | const char *fileName, const char *ea_name, const void *ea_value, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6358 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 6359 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6360 | { |
| 6361 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6362 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6363 | struct fealist *parm_data; |
| 6364 | int name_len; |
| 6365 | int rc = 0; |
| 6366 | int bytes_returned = 0; |
| 6367 | __u16 params, param_offset, byte_count, offset, count; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 6368 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6369 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6370 | cifs_dbg(FYI, "In SetEA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6371 | SetEARetry: |
| 6372 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6373 | (void **) &pSMBr); |
| 6374 | if (rc) |
| 6375 | return rc; |
| 6376 | |
| 6377 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6378 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6379 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6380 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6381 | name_len++; /* trailing null */ |
| 6382 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6383 | } else { |
| 6384 | name_len = copy_path_name(pSMB->FileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | params = 6 + name_len; |
| 6388 | |
| 6389 | /* done calculating parms using name_len of file name, |
| 6390 | now use name_len to calculate length of ea name |
| 6391 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6392 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6393 | name_len = 0; |
| 6394 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6395 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6396 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6397 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6398 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6399 | /* BB find max SMB PDU from sess */ |
| 6400 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6401 | pSMB->MaxSetupCount = 0; |
| 6402 | pSMB->Reserved = 0; |
| 6403 | pSMB->Flags = 0; |
| 6404 | pSMB->Timeout = 0; |
| 6405 | pSMB->Reserved2 = 0; |
| 6406 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6407 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6408 | offset = param_offset + params; |
| 6409 | pSMB->InformationLevel = |
| 6410 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6411 | |
Arnd Bergmann | ade7db9 | 2018-02-02 16:48:47 +0100 | [diff] [blame] | 6412 | parm_data = (void *)pSMB + offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6413 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6414 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6415 | pSMB->SetupCount = 1; |
| 6416 | pSMB->Reserved3 = 0; |
| 6417 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6418 | byte_count = 3 /* pad */ + params + count; |
| 6419 | pSMB->DataCount = cpu_to_le16(count); |
| 6420 | parm_data->list_len = cpu_to_le32(count); |
| 6421 | parm_data->list[0].EA_flags = 0; |
| 6422 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6423 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6424 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6425 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6426 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6427 | parm_data->list[0].name[name_len] = 0; |
| 6428 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6429 | /* caller ensures that ea_value_len is less than 64K but |
| 6430 | we need to ensure that it fits within the smb */ |
| 6431 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6432 | /*BB add length check to see if it would fit in |
| 6433 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6434 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6435 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6436 | memcpy(parm_data->list[0].name+name_len+1, |
| 6437 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6438 | |
| 6439 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6440 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6441 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6442 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6443 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6444 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6445 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6446 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6447 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6448 | cifs_dbg(FYI, "SetPathInfo (EA) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6449 | |
| 6450 | cifs_buf_release(pSMB); |
| 6451 | |
| 6452 | if (rc == -EAGAIN) |
| 6453 | goto SetEARetry; |
| 6454 | |
| 6455 | return rc; |
| 6456 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6457 | #endif |