Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cifssmb.c |
| 3 | * |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * Contains the routines for constructing the SMB PDUs themselves |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* SMB/CIFS PDU handling routines here - except for leftovers in connect.c */ |
| 25 | /* These are mostly routines that operate on a pathname, or on a tree id */ |
| 26 | /* (mounted volume), but there are eight handle based routines which must be */ |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 27 | /* treated slightly differently for reconnection purposes since we never */ |
| 28 | /* want to reuse a stale file handle and only the caller knows the file info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <linux/fs.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/vfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/posix_acl_xattr.h> |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 35 | #include <linux/pagemap.h> |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 36 | #include <linux/swap.h> |
| 37 | #include <linux/task_io_accounting_ops.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 38 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "cifspdu.h" |
| 40 | #include "cifsglob.h" |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 41 | #include "cifsacl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "cifsproto.h" |
| 43 | #include "cifs_unicode.h" |
| 44 | #include "cifs_debug.h" |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 45 | #include "fscache.h" |
Long Li | db223a5 | 2017-11-22 17:38:45 -0700 | [diff] [blame] | 46 | #include "smbdirect.h" |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 47 | #ifdef CONFIG_CIFS_DFS_UPCALL |
| 48 | #include "dfs_cache.h" |
| 49 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #ifdef CONFIG_CIFS_POSIX |
| 52 | static struct { |
| 53 | int index; |
| 54 | char *name; |
| 55 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 56 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 57 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 58 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 59 | #endif /* weak password hashing for legacy clients */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 60 | {CIFS_PROT, "\2NT LM 0.12"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 61 | {POSIX_PROT, "\2POSIX 2"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | {BAD_PROT, "\2"} |
| 63 | }; |
| 64 | #else |
| 65 | static struct { |
| 66 | int index; |
| 67 | char *name; |
| 68 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 69 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 70 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 18f75ca | 2006-10-01 03:13:01 +0000 | [diff] [blame] | 71 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 72 | #endif /* weak password hashing for legacy clients */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 73 | {CIFS_PROT, "\2NT LM 0.12"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | {BAD_PROT, "\2"} |
| 75 | }; |
| 76 | #endif |
| 77 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 78 | /* define the number of elements in the cifs dialect array */ |
| 79 | #ifdef CONFIG_CIFS_POSIX |
| 80 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 81 | #define CIFS_NUM_PROT 4 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 82 | #else |
| 83 | #define CIFS_NUM_PROT 2 |
| 84 | #endif /* CIFS_WEAK_PW_HASH */ |
| 85 | #else /* not posix */ |
| 86 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 87 | #define CIFS_NUM_PROT 3 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 88 | #else |
| 89 | #define CIFS_NUM_PROT 1 |
| 90 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
| 91 | #endif /* CIFS_POSIX */ |
| 92 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 93 | /* |
| 94 | * Mark as invalid, all open files on tree connections since they |
| 95 | * were closed when session to server was lost. |
| 96 | */ |
| 97 | void |
| 98 | cifs_mark_open_files_invalid(struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
| 100 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 101 | struct list_head *tmp; |
| 102 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 104 | /* list all files open on tree connection and mark them invalid */ |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 105 | spin_lock(&tcon->open_file_lock); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 106 | list_for_each_safe(tmp, tmp1, &tcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 107 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 108 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 109 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 111 | spin_unlock(&tcon->open_file_lock); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 112 | |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 113 | mutex_lock(&tcon->crfid.fid_mutex); |
| 114 | tcon->crfid.is_valid = false; |
| 115 | memset(tcon->crfid.fid, 0, sizeof(struct cifs_fid)); |
| 116 | mutex_unlock(&tcon->crfid.fid_mutex); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 117 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 118 | /* |
| 119 | * BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 120 | * to this tcon. |
| 121 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 124 | #ifdef CONFIG_CIFS_DFS_UPCALL |
| 125 | static int __cifs_reconnect_tcon(const struct nls_table *nlsc, |
| 126 | struct cifs_tcon *tcon) |
| 127 | { |
| 128 | int rc; |
| 129 | struct dfs_cache_tgt_list tl; |
| 130 | struct dfs_cache_tgt_iterator *it = NULL; |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 131 | char *tree; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 132 | const char *tcp_host; |
| 133 | size_t tcp_host_len; |
| 134 | const char *dfs_host; |
| 135 | size_t dfs_host_len; |
| 136 | |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 137 | tree = kzalloc(MAX_TREE_SIZE, GFP_KERNEL); |
| 138 | if (!tree) |
| 139 | return -ENOMEM; |
| 140 | |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 141 | if (tcon->ipc) { |
Ronnie Sahlberg | 74ea5f9 | 2019-02-09 09:51:11 +1000 | [diff] [blame] | 142 | scnprintf(tree, MAX_TREE_SIZE, "\\\\%s\\IPC$", |
| 143 | tcon->ses->server->hostname); |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 144 | rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc); |
| 145 | goto out; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 146 | } |
| 147 | |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 148 | if (!tcon->dfs_path) { |
| 149 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, tcon, nlsc); |
| 150 | goto out; |
| 151 | } |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 152 | |
| 153 | rc = dfs_cache_noreq_find(tcon->dfs_path + 1, NULL, &tl); |
| 154 | if (rc) |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 155 | goto out; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 156 | |
| 157 | extract_unc_hostname(tcon->ses->server->hostname, &tcp_host, |
| 158 | &tcp_host_len); |
| 159 | |
| 160 | for (it = dfs_cache_get_tgt_iterator(&tl); it; |
| 161 | it = dfs_cache_get_next_tgt(&tl, it)) { |
| 162 | const char *tgt = dfs_cache_get_tgt_name(it); |
| 163 | |
| 164 | extract_unc_hostname(tgt, &dfs_host, &dfs_host_len); |
| 165 | |
| 166 | if (dfs_host_len != tcp_host_len |
| 167 | || strncasecmp(dfs_host, tcp_host, dfs_host_len) != 0) { |
| 168 | cifs_dbg(FYI, "%s: skipping %.*s, doesn't match %.*s", |
| 169 | __func__, |
| 170 | (int)dfs_host_len, dfs_host, |
| 171 | (int)tcp_host_len, tcp_host); |
| 172 | continue; |
| 173 | } |
| 174 | |
Ronnie Sahlberg | 74ea5f9 | 2019-02-09 09:51:11 +1000 | [diff] [blame] | 175 | scnprintf(tree, MAX_TREE_SIZE, "\\%s", tgt); |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 176 | |
| 177 | rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc); |
| 178 | if (!rc) |
| 179 | break; |
| 180 | if (rc == -EREMOTE) |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | if (!rc) { |
| 185 | if (it) |
| 186 | rc = dfs_cache_noreq_update_tgthint(tcon->dfs_path + 1, |
| 187 | it); |
| 188 | else |
| 189 | rc = -ENOENT; |
| 190 | } |
| 191 | dfs_cache_free_tgts(&tl); |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 192 | out: |
| 193 | kfree(tree); |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 194 | return rc; |
| 195 | } |
| 196 | #else |
| 197 | static inline int __cifs_reconnect_tcon(const struct nls_table *nlsc, |
| 198 | struct cifs_tcon *tcon) |
| 199 | { |
| 200 | return CIFSTCon(0, tcon->ses, tcon->treeName, tcon, nlsc); |
| 201 | } |
| 202 | #endif |
| 203 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 204 | /* reconnect the socket, tcon, and smb session if needed */ |
| 205 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 206 | cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 207 | { |
Jeff Layton | c4a5534 | 2011-07-28 12:40:36 -0400 | [diff] [blame] | 208 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 209 | struct cifs_ses *ses; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 210 | struct TCP_Server_Info *server; |
| 211 | struct nls_table *nls_codepage; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 212 | int retries; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 216 | * tcp and smb session status done differently for those three - in the |
| 217 | * calling routine |
| 218 | */ |
| 219 | if (!tcon) |
| 220 | return 0; |
| 221 | |
| 222 | ses = tcon->ses; |
| 223 | server = ses->server; |
| 224 | |
| 225 | /* |
| 226 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 227 | * have tcon) are allowed as we start force umount |
| 228 | */ |
| 229 | if (tcon->tidStatus == CifsExiting) { |
| 230 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 231 | smb_command != SMB_COM_OPEN_ANDX && |
| 232 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 233 | cifs_dbg(FYI, "can not send cmd %d while umounting\n", |
| 234 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 235 | return -ENODEV; |
| 236 | } |
| 237 | } |
| 238 | |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 239 | retries = server->nr_targets; |
| 240 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 241 | /* |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 242 | * Give demultiplex thread up to 10 seconds to each target available for |
| 243 | * reconnect -- should be greater than cifs socket timeout which is 7 |
| 244 | * seconds. |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 245 | */ |
| 246 | while (server->tcpStatus == CifsNeedReconnect) { |
Paulo Alcantara | 7ffbe65 | 2018-07-05 13:46:34 -0300 | [diff] [blame] | 247 | rc = wait_event_interruptible_timeout(server->response_q, |
| 248 | (server->tcpStatus != CifsNeedReconnect), |
| 249 | 10 * HZ); |
| 250 | if (rc < 0) { |
| 251 | cifs_dbg(FYI, "%s: aborting reconnect due to a received" |
| 252 | " signal by the process\n", __func__); |
| 253 | return -ERESTARTSYS; |
| 254 | } |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 255 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 256 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 257 | if (server->tcpStatus != CifsNeedReconnect) |
| 258 | break; |
| 259 | |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 260 | if (--retries) |
| 261 | continue; |
| 262 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 263 | /* |
| 264 | * on "soft" mounts we wait once. Hard mounts keep |
| 265 | * retrying until process is killed or server comes |
| 266 | * back on-line |
| 267 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 268 | if (!tcon->retry) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 269 | cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 270 | return -EHOSTDOWN; |
| 271 | } |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 272 | retries = server->nr_targets; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 276 | return 0; |
| 277 | |
| 278 | nls_codepage = load_nls_default(); |
| 279 | |
| 280 | /* |
| 281 | * need to prevent multiple threads trying to simultaneously |
| 282 | * reconnect the same SMB session |
| 283 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 284 | mutex_lock(&ses->session_mutex); |
Samuel Cabrero | 76e7527 | 2017-07-11 12:44:39 +0200 | [diff] [blame] | 285 | |
| 286 | /* |
| 287 | * Recheck after acquire mutex. If another thread is negotiating |
| 288 | * and the server never sends an answer the socket will be closed |
| 289 | * and tcpStatus set to reconnect. |
| 290 | */ |
| 291 | if (server->tcpStatus == CifsNeedReconnect) { |
| 292 | rc = -EHOSTDOWN; |
| 293 | mutex_unlock(&ses->session_mutex); |
| 294 | goto out; |
| 295 | } |
| 296 | |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 297 | rc = cifs_negotiate_protocol(0, ses); |
| 298 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 299 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 300 | |
| 301 | /* do we need to reconnect tcon? */ |
| 302 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 303 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 304 | goto out; |
| 305 | } |
| 306 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 307 | cifs_mark_open_files_invalid(tcon); |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 308 | rc = __cifs_reconnect_tcon(nls_codepage, tcon); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 309 | mutex_unlock(&ses->session_mutex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 310 | cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 311 | |
Steve French | c318e6c | 2018-04-04 14:08:52 -0500 | [diff] [blame] | 312 | if (rc) { |
| 313 | printk_once(KERN_WARNING "reconnect tcon failed rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 314 | goto out; |
Steve French | c318e6c | 2018-04-04 14:08:52 -0500 | [diff] [blame] | 315 | } |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 316 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 317 | atomic_inc(&tconInfoReconnectCount); |
| 318 | |
| 319 | /* tell server Unix caps we support */ |
| 320 | if (ses->capabilities & CAP_UNIX) |
| 321 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 322 | |
| 323 | /* |
| 324 | * Removed call to reopen open files here. It is safer (and faster) to |
| 325 | * reopen files one at a time as needed in read and write. |
| 326 | * |
| 327 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 328 | */ |
| 329 | |
| 330 | out: |
| 331 | /* |
| 332 | * Check if handle based operation so we know whether we can continue |
| 333 | * or not without returning to caller to reset file handle |
| 334 | */ |
| 335 | switch (smb_command) { |
| 336 | case SMB_COM_READ_ANDX: |
| 337 | case SMB_COM_WRITE_ANDX: |
| 338 | case SMB_COM_CLOSE: |
| 339 | case SMB_COM_FIND_CLOSE2: |
| 340 | case SMB_COM_LOCKING_ANDX: |
| 341 | rc = -EAGAIN; |
| 342 | } |
| 343 | |
| 344 | unload_nls(nls_codepage); |
| 345 | return rc; |
| 346 | } |
| 347 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 348 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 349 | SMB information in the SMB header. If the return code is zero, this |
| 350 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 352 | small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 353 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 355 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 357 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 358 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | return rc; |
| 360 | |
| 361 | *request_buf = cifs_small_buf_get(); |
| 362 | if (*request_buf == NULL) { |
| 363 | /* BB should we add a retry in here if not a writepage? */ |
| 364 | return -ENOMEM; |
| 365 | } |
| 366 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 367 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 368 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 370 | if (tcon != NULL) |
| 371 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 372 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 373 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 376 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 377 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 378 | struct cifs_ses *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 379 | { |
| 380 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 381 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 382 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 383 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 384 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 385 | return rc; |
| 386 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 387 | buffer = (struct smb_hdr *)*request_buf; |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 388 | buffer->Mid = get_next_mid(ses->server); |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 389 | if (ses->capabilities & CAP_UNICODE) |
| 390 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 391 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 392 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 393 | |
| 394 | /* uid, tid can stay at zero as set in header assemble */ |
| 395 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 396 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 397 | this function is used after 1st of session setup requests */ |
| 398 | |
| 399 | return rc; |
| 400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 403 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 404 | __smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 405 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | *request_buf = cifs_buf_get(); |
| 408 | if (*request_buf == NULL) { |
| 409 | /* BB should we add a retry in here if not a writepage? */ |
| 410 | return -ENOMEM; |
| 411 | } |
| 412 | /* Although the original thought was we needed the response buf for */ |
| 413 | /* potential retries of smb operations it turns out we can determine */ |
| 414 | /* from the mid flags when the request buffer can be resent without */ |
| 415 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 416 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 417 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 420 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 422 | if (tcon != NULL) |
| 423 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 424 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 429 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 430 | smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 431 | void **request_buf, void **response_buf) |
| 432 | { |
| 433 | int rc; |
| 434 | |
| 435 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 436 | if (rc) |
| 437 | return rc; |
| 438 | |
| 439 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 440 | } |
| 441 | |
| 442 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 443 | 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] | 444 | void **request_buf, void **response_buf) |
| 445 | { |
| 446 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 447 | return -EHOSTDOWN; |
| 448 | |
| 449 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 452 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 454 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 456 | /* check for plausible wct */ |
| 457 | if (pSMB->hdr.WordCount < 10) |
| 458 | goto vt2_err; |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 461 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 462 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 463 | goto vt2_err; |
| 464 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 465 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 466 | if (total_size >= 512) |
| 467 | goto vt2_err; |
| 468 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 469 | /* check that bcc is at least as big as parms + data, and that it is |
| 470 | * less than negotiated smb buffer |
| 471 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 472 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 473 | if (total_size > get_bcc(&pSMB->hdr) || |
| 474 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 475 | goto vt2_err; |
| 476 | |
| 477 | return 0; |
| 478 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 479 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 481 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 483 | |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 484 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 485 | decode_ext_sec_blob(struct cifs_ses *ses, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 486 | { |
| 487 | int rc = 0; |
| 488 | u16 count; |
| 489 | char *guid = pSMBr->u.extended_response.GUID; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 490 | struct TCP_Server_Info *server = ses->server; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 491 | |
| 492 | count = get_bcc(&pSMBr->hdr); |
| 493 | if (count < SMB1_CLIENT_GUID_SIZE) |
| 494 | return -EIO; |
| 495 | |
| 496 | spin_lock(&cifs_tcp_ses_lock); |
| 497 | if (server->srv_count > 1) { |
| 498 | spin_unlock(&cifs_tcp_ses_lock); |
| 499 | if (memcmp(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE) != 0) { |
| 500 | cifs_dbg(FYI, "server UID changed\n"); |
| 501 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 502 | } |
| 503 | } else { |
| 504 | spin_unlock(&cifs_tcp_ses_lock); |
| 505 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 506 | } |
| 507 | |
| 508 | if (count == SMB1_CLIENT_GUID_SIZE) { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 509 | server->sec_ntlmssp = true; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 510 | } else { |
| 511 | count -= SMB1_CLIENT_GUID_SIZE; |
| 512 | rc = decode_negTokenInit( |
| 513 | pSMBr->u.extended_response.SecurityBlob, count, server); |
| 514 | if (rc != 1) |
| 515 | return -EINVAL; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 521 | int |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 522 | cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required) |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 523 | { |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 524 | bool srv_sign_required = server->sec_mode & server->vals->signing_required; |
| 525 | bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled; |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 526 | bool mnt_sign_enabled = global_secflags & CIFSSEC_MAY_SIGN; |
| 527 | |
| 528 | /* |
| 529 | * Is signing required by mnt options? If not then check |
| 530 | * global_secflags to see if it is there. |
| 531 | */ |
| 532 | if (!mnt_sign_required) |
| 533 | mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) == |
| 534 | CIFSSEC_MUST_SIGN); |
| 535 | |
| 536 | /* |
| 537 | * If signing is required then it's automatically enabled too, |
| 538 | * otherwise, check to see if the secflags allow it. |
| 539 | */ |
| 540 | mnt_sign_enabled = mnt_sign_required ? mnt_sign_required : |
| 541 | (global_secflags & CIFSSEC_MAY_SIGN); |
| 542 | |
| 543 | /* If server requires signing, does client allow it? */ |
| 544 | if (srv_sign_required) { |
| 545 | if (!mnt_sign_enabled) { |
| 546 | cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!"); |
| 547 | return -ENOTSUPP; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 548 | } |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 549 | server->sign = true; |
| 550 | } |
| 551 | |
| 552 | /* If client requires signing, does server allow it? */ |
| 553 | if (mnt_sign_required) { |
| 554 | if (!srv_sign_enabled) { |
| 555 | cifs_dbg(VFS, "Server does not support signing!"); |
| 556 | return -ENOTSUPP; |
| 557 | } |
| 558 | server->sign = true; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 559 | } |
| 560 | |
Long Li | bb4c041 | 2018-04-17 12:17:08 -0700 | [diff] [blame] | 561 | if (cifs_rdma_enabled(server) && server->sign) |
| 562 | cifs_dbg(VFS, "Signing is enabled, and RDMA read/write will be disabled"); |
| 563 | |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 564 | return 0; |
| 565 | } |
| 566 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 567 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 568 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 569 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 570 | { |
| 571 | __s16 tmp; |
| 572 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
| 573 | |
| 574 | if (server->dialect != LANMAN_PROT && server->dialect != LANMAN2_PROT) |
| 575 | return -EOPNOTSUPP; |
| 576 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 577 | server->sec_mode = le16_to_cpu(rsp->SecurityMode); |
| 578 | server->maxReq = min_t(unsigned int, |
| 579 | le16_to_cpu(rsp->MaxMpxCount), |
| 580 | cifs_max_pending); |
| 581 | set_credits(server, server->maxReq); |
| 582 | server->maxBuf = le16_to_cpu(rsp->MaxBufSize); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 583 | /* even though we do not use raw we might as well set this |
| 584 | accurately, in case we ever find a need for it */ |
| 585 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
| 586 | server->max_rw = 0xFF00; |
| 587 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 588 | } else { |
| 589 | server->max_rw = 0;/* do not need to use raw anyway */ |
| 590 | server->capabilities = CAP_MPX_MODE; |
| 591 | } |
| 592 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
| 593 | if (tmp == -1) { |
| 594 | /* OS/2 often does not set timezone therefore |
| 595 | * we must use server time to calc time zone. |
| 596 | * Could deviate slightly from the right zone. |
| 597 | * Smallest defined timezone difference is 15 minutes |
| 598 | * (i.e. Nepal). Rounding up/down is done to match |
| 599 | * this requirement. |
| 600 | */ |
| 601 | int val, seconds, remain, result; |
Arnd Bergmann | 9539020 | 2018-06-19 17:27:58 +0200 | [diff] [blame] | 602 | struct timespec64 ts; |
| 603 | time64_t utc = ktime_get_real_seconds(); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 604 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 605 | rsp->SrvTime.Time, 0); |
Arnd Bergmann | 9539020 | 2018-06-19 17:27:58 +0200 | [diff] [blame] | 606 | cifs_dbg(FYI, "SrvTime %lld sec since 1970 (utc: %lld) diff: %lld\n", |
| 607 | ts.tv_sec, utc, |
| 608 | utc - ts.tv_sec); |
Deepa Dinamani | e37fea5 | 2017-05-08 15:59:16 -0700 | [diff] [blame] | 609 | val = (int)(utc - ts.tv_sec); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 610 | seconds = abs(val); |
| 611 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
| 612 | remain = seconds % MIN_TZ_ADJ; |
| 613 | if (remain >= (MIN_TZ_ADJ / 2)) |
| 614 | result += MIN_TZ_ADJ; |
| 615 | if (val < 0) |
| 616 | result = -result; |
| 617 | server->timeAdj = result; |
| 618 | } else { |
| 619 | server->timeAdj = (int)tmp; |
| 620 | server->timeAdj *= 60; /* also in seconds */ |
| 621 | } |
| 622 | cifs_dbg(FYI, "server->timeAdj: %d seconds\n", server->timeAdj); |
| 623 | |
| 624 | |
| 625 | /* BB get server time for time conversions and add |
| 626 | code to use it and timezone since this is not UTC */ |
| 627 | |
| 628 | if (rsp->EncryptionKeyLength == |
| 629 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
| 630 | memcpy(server->cryptkey, rsp->EncryptionKey, |
| 631 | CIFS_CRYPTO_KEY_SIZE); |
| 632 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
| 633 | return -EIO; /* need cryptkey unless plain text */ |
| 634 | } |
| 635 | |
| 636 | cifs_dbg(FYI, "LANMAN negotiated\n"); |
| 637 | return 0; |
| 638 | } |
| 639 | #else |
| 640 | static inline int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 641 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 642 | { |
| 643 | cifs_dbg(VFS, "mount failed, cifs module not built with CIFS_WEAK_PW_HASH support\n"); |
| 644 | return -EOPNOTSUPP; |
| 645 | } |
| 646 | #endif |
| 647 | |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 648 | static bool |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 649 | should_set_ext_sec_flag(enum securityEnum sectype) |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 650 | { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 651 | switch (sectype) { |
| 652 | case RawNTLMSSP: |
| 653 | case Kerberos: |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 654 | return true; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 655 | case Unspecified: |
| 656 | if (global_secflags & |
| 657 | (CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)) |
| 658 | return true; |
| 659 | /* Fallthrough */ |
| 660 | default: |
| 661 | return false; |
| 662 | } |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 663 | } |
| 664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | int |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 666 | CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
| 668 | NEGOTIATE_REQ *pSMB; |
| 669 | NEGOTIATE_RSP *pSMBr; |
| 670 | int rc = 0; |
| 671 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 672 | int i; |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 673 | struct TCP_Server_Info *server = ses->server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | u16 count; |
| 675 | |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 676 | if (!server) { |
| 677 | WARN(1, "%s: server is NULL!\n", __func__); |
| 678 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 682 | (void **) &pSMB, (void **) &pSMBr); |
| 683 | if (rc) |
| 684 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 685 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 686 | pSMB->hdr.Mid = get_next_mid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 687 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 688 | |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 689 | if (should_set_ext_sec_flag(ses->sectype)) { |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 690 | cifs_dbg(FYI, "Requesting extended security."); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 691 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 692 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 693 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 694 | count = 0; |
Stephen Rothwell | bcfb84a | 2018-09-03 13:15:58 +1000 | [diff] [blame] | 695 | /* |
| 696 | * We know that all the name entries in the protocols array |
| 697 | * are short (< 16 bytes anyway) and are NUL terminated. |
| 698 | */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 699 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Stephen Rothwell | bcfb84a | 2018-09-03 13:15:58 +1000 | [diff] [blame] | 700 | size_t len = strlen(protocols[i].name) + 1; |
| 701 | |
| 702 | memcpy(pSMB->DialectsArray+count, protocols[i].name, len); |
| 703 | count += len; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 704 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 705 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | pSMB->ByteCount = cpu_to_le16(count); |
| 707 | |
| 708 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 709 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 710 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 711 | goto neg_err_exit; |
| 712 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 713 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 714 | cifs_dbg(FYI, "Dialect: %d\n", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 715 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 716 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 717 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 718 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 719 | could not negotiate a common dialect */ |
| 720 | rc = -EOPNOTSUPP; |
| 721 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 722 | } else if (pSMBr->hdr.WordCount == 13) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 723 | server->negflavor = CIFS_NEGFLAVOR_LANMAN; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 724 | rc = decode_lanman_negprot_rsp(server, pSMBr); |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 725 | goto signing_check; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 726 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 727 | /* unknown wct */ |
| 728 | rc = -EOPNOTSUPP; |
| 729 | goto neg_err_exit; |
| 730 | } |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 731 | /* else wct == 17, NTLM or better */ |
| 732 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 733 | server->sec_mode = pSMBr->SecurityMode; |
| 734 | if ((server->sec_mode & SECMODE_USER) == 0) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 735 | cifs_dbg(FYI, "share mode security\n"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 736 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 737 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 738 | little endian */ |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 739 | server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), |
| 740 | cifs_max_pending); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 741 | set_credits(server, server->maxReq); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 742 | /* probably no need to store and check maxvcs */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 743 | server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 744 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 745 | cifs_dbg(NOISY, "Max buf = %d\n", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 746 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 747 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 748 | server->timeAdj *= 60; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 749 | |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 750 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
| 751 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 752 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 753 | CIFS_CRYPTO_KEY_SIZE); |
Noel Power | f291095 | 2015-05-27 09:22:10 +0100 | [diff] [blame] | 754 | } else if (pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC || |
| 755 | server->capabilities & CAP_EXTENDED_SECURITY) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 756 | server->negflavor = CIFS_NEGFLAVOR_EXTENDED; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 757 | rc = decode_ext_sec_blob(ses, pSMBr); |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 758 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 759 | rc = -EIO; /* no crypt key only if plain text pwd */ |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 760 | } else { |
| 761 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 762 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 763 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 764 | |
| 765 | signing_check: |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 766 | if (!rc) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 767 | rc = cifs_enable_signing(server, ses->sign); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 768 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 769 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 770 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 771 | cifs_dbg(FYI, "negprot rc %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | return rc; |
| 773 | } |
| 774 | |
| 775 | int |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 776 | CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
| 778 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 781 | cifs_dbg(FYI, "In tree disconnect\n"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 782 | |
| 783 | /* BB: do we need to check this? These should never be NULL. */ |
| 784 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 785 | return -EIO; |
| 786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 788 | * No need to return error on this operation if tid invalidated and |
| 789 | * closed on server already e.g. due to tcp session crashing. Also, |
| 790 | * the tcon is no longer on the list, so no need to take lock before |
| 791 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 793 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 794 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 796 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 797 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 798 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 800 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 801 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 802 | cifs_small_buf_release(smb_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 804 | cifs_dbg(FYI, "Tree disconnect failed %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 806 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 807 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (rc == -EAGAIN) |
| 809 | rc = 0; |
| 810 | |
| 811 | return rc; |
| 812 | } |
| 813 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 814 | /* |
| 815 | * This is a no-op for now. We're not really interested in the reply, but |
| 816 | * rather in the fact that the server sent one and that server->lstrp |
| 817 | * gets updated. |
| 818 | * |
| 819 | * FIXME: maybe we should consider checking that the reply matches request? |
| 820 | */ |
| 821 | static void |
| 822 | cifs_echo_callback(struct mid_q_entry *mid) |
| 823 | { |
| 824 | struct TCP_Server_Info *server = mid->callback_data; |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 825 | struct cifs_credits credits = { .value = 1, .instance = 0 }; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 826 | |
| 827 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 828 | add_credits(server, &credits, CIFS_ECHO_OP); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | int |
| 832 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 833 | { |
| 834 | ECHO_REQ *smb; |
| 835 | int rc = 0; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 836 | struct kvec iov[2]; |
| 837 | struct smb_rqst rqst = { .rq_iov = iov, |
| 838 | .rq_nvec = 2 }; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 839 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 840 | cifs_dbg(FYI, "In echo request\n"); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 841 | |
| 842 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 843 | if (rc) |
| 844 | return rc; |
| 845 | |
Steve French | 26c9cb6 | 2017-05-02 13:35:20 -0500 | [diff] [blame] | 846 | if (server->capabilities & CAP_UNICODE) |
| 847 | smb->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 848 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 849 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 850 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8f | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 851 | smb->hdr.WordCount = 1; |
| 852 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 853 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 854 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 855 | inc_rfc1001_len(smb, 3); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 856 | |
| 857 | iov[0].iov_len = 4; |
| 858 | iov[0].iov_base = smb; |
| 859 | iov[1].iov_len = get_rfc1002_length(smb); |
| 860 | iov[1].iov_base = (char *)smb + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 861 | |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 862 | rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, NULL, |
Ronnie Sahlberg | 392e1c5 | 2019-05-06 10:00:02 +1000 | [diff] [blame] | 863 | server, CIFS_NON_BLOCKING | CIFS_ECHO_OP, NULL); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 864 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 865 | cifs_dbg(FYI, "Echo request failed: %d\n", rc); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 866 | |
| 867 | cifs_small_buf_release(smb); |
| 868 | |
| 869 | return rc; |
| 870 | } |
| 871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | int |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 873 | CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | LOGOFF_ANDX_REQ *pSMB; |
| 876 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 878 | cifs_dbg(FYI, "In SMBLogoff for session disconnect\n"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 879 | |
| 880 | /* |
| 881 | * BB: do we need to check validity of ses and server? They should |
| 882 | * always be valid since we have an active reference. If not, that |
| 883 | * should probably be a BUG() |
| 884 | */ |
| 885 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | return -EIO; |
| 887 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 888 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 889 | if (ses->need_reconnect) |
| 890 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 891 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 893 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 894 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | return rc; |
| 896 | } |
| 897 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 898 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 899 | |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 900 | if (ses->server->sign) |
| 901 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
| 903 | pSMB->hdr.Uid = ses->Suid; |
| 904 | |
| 905 | pSMB->AndXCommand = 0xFF; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 906 | rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 907 | cifs_small_buf_release(pSMB); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 908 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 909 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
| 911 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 912 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | error */ |
| 914 | if (rc == -EAGAIN) |
| 915 | rc = 0; |
| 916 | return rc; |
| 917 | } |
| 918 | |
| 919 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 920 | CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, |
| 921 | const char *fileName, __u16 type, |
| 922 | const struct nls_table *nls_codepage, int remap) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 923 | { |
| 924 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 925 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 926 | struct unlink_psx_rq *pRqD; |
| 927 | int name_len; |
| 928 | int rc = 0; |
| 929 | int bytes_returned = 0; |
| 930 | __u16 params, param_offset, offset, byte_count; |
| 931 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 932 | cifs_dbg(FYI, "In POSIX delete\n"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 933 | PsxDelete: |
| 934 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 935 | (void **) &pSMBr); |
| 936 | if (rc) |
| 937 | return rc; |
| 938 | |
| 939 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 940 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 941 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 942 | PATH_MAX, nls_codepage, remap); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 943 | name_len++; /* trailing null */ |
| 944 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 945 | } else { |
| 946 | name_len = copy_path_name(pSMB->FileName, fileName); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | params = 6 + name_len; |
| 950 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 951 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 952 | pSMB->MaxSetupCount = 0; |
| 953 | pSMB->Reserved = 0; |
| 954 | pSMB->Flags = 0; |
| 955 | pSMB->Timeout = 0; |
| 956 | pSMB->Reserved2 = 0; |
| 957 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 958 | InformationLevel) - 4; |
| 959 | offset = param_offset + params; |
| 960 | |
| 961 | /* Setup pointer to Request Data (inode type) */ |
| 962 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 963 | pRqD->type = cpu_to_le16(type); |
| 964 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 965 | pSMB->DataOffset = cpu_to_le16(offset); |
| 966 | pSMB->SetupCount = 1; |
| 967 | pSMB->Reserved3 = 0; |
| 968 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 969 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 970 | |
| 971 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 972 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 973 | pSMB->ParameterCount = cpu_to_le16(params); |
| 974 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 975 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 976 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 977 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 978 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 979 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 980 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 981 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 982 | cifs_dbg(FYI, "Posix delete returned %d\n", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 983 | cifs_buf_release(pSMB); |
| 984 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 985 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 986 | |
| 987 | if (rc == -EAGAIN) |
| 988 | goto PsxDelete; |
| 989 | |
| 990 | return rc; |
| 991 | } |
| 992 | |
| 993 | int |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 994 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 995 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | { |
| 997 | DELETE_FILE_REQ *pSMB = NULL; |
| 998 | DELETE_FILE_RSP *pSMBr = NULL; |
| 999 | int rc = 0; |
| 1000 | int bytes_returned; |
| 1001 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1002 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
| 1004 | DelFileRetry: |
| 1005 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 1006 | (void **) &pSMBr); |
| 1007 | if (rc) |
| 1008 | return rc; |
| 1009 | |
| 1010 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 1011 | name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name, |
| 1012 | PATH_MAX, cifs_sb->local_nls, |
| 1013 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | name_len++; /* trailing null */ |
| 1015 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1016 | } else { |
| 1017 | name_len = copy_path_name(pSMB->fileName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | } |
| 1019 | pSMB->SearchAttributes = |
| 1020 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 1021 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1022 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1024 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1025 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1026 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1027 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1028 | cifs_dbg(FYI, "Error in RMFile = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | |
| 1030 | cifs_buf_release(pSMB); |
| 1031 | if (rc == -EAGAIN) |
| 1032 | goto DelFileRetry; |
| 1033 | |
| 1034 | return rc; |
| 1035 | } |
| 1036 | |
| 1037 | int |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 1038 | CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 1039 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | { |
| 1041 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 1042 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 1043 | int rc = 0; |
| 1044 | int bytes_returned; |
| 1045 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1046 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1048 | cifs_dbg(FYI, "In CIFSSMBRmDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | RmDirRetry: |
| 1050 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 1051 | (void **) &pSMBr); |
| 1052 | if (rc) |
| 1053 | return rc; |
| 1054 | |
| 1055 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 1056 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
| 1057 | PATH_MAX, cifs_sb->local_nls, |
| 1058 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | name_len++; /* trailing null */ |
| 1060 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1061 | } else { |
| 1062 | name_len = copy_path_name(pSMB->DirName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1066 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1068 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1069 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1070 | cifs_stats_inc(&tcon->stats.cifs_stats.num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1071 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1072 | cifs_dbg(FYI, "Error in RMDir = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
| 1074 | cifs_buf_release(pSMB); |
| 1075 | if (rc == -EAGAIN) |
| 1076 | goto RmDirRetry; |
| 1077 | return rc; |
| 1078 | } |
| 1079 | |
| 1080 | int |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame^] | 1081 | CIFSSMBMkDir(const unsigned int xid, struct inode *inode, umode_t mode, |
| 1082 | struct cifs_tcon *tcon, const char *name, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 1083 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | { |
| 1085 | int rc = 0; |
| 1086 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 1087 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 1088 | int bytes_returned; |
| 1089 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1090 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1092 | cifs_dbg(FYI, "In CIFSSMBMkDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | MkDirRetry: |
| 1094 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 1095 | (void **) &pSMBr); |
| 1096 | if (rc) |
| 1097 | return rc; |
| 1098 | |
| 1099 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1100 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 1101 | PATH_MAX, cifs_sb->local_nls, |
| 1102 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | name_len++; /* trailing null */ |
| 1104 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1105 | } else { |
| 1106 | name_len = copy_path_name(pSMB->DirName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1110 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1112 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1113 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1114 | cifs_stats_inc(&tcon->stats.cifs_stats.num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1115 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1116 | cifs_dbg(FYI, "Error in Mkdir = %d\n", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | cifs_buf_release(pSMB); |
| 1119 | if (rc == -EAGAIN) |
| 1120 | goto MkDirRetry; |
| 1121 | return rc; |
| 1122 | } |
| 1123 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1124 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1125 | CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, |
| 1126 | __u32 posix_flags, __u64 mode, __u16 *netfid, |
| 1127 | FILE_UNIX_BASIC_INFO *pRetData, __u32 *pOplock, |
| 1128 | const char *name, const struct nls_table *nls_codepage, |
| 1129 | int remap) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1130 | { |
| 1131 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1132 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1133 | int name_len; |
| 1134 | int rc = 0; |
| 1135 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1136 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1137 | OPEN_PSX_REQ *pdata; |
| 1138 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1139 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1140 | cifs_dbg(FYI, "In POSIX Create\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1141 | PsxCreat: |
| 1142 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1143 | (void **) &pSMBr); |
| 1144 | if (rc) |
| 1145 | return rc; |
| 1146 | |
| 1147 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1148 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1149 | cifsConvertToUTF16((__le16 *) pSMB->FileName, name, |
| 1150 | PATH_MAX, nls_codepage, remap); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1151 | name_len++; /* trailing null */ |
| 1152 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1153 | } else { |
| 1154 | name_len = copy_path_name(pSMB->FileName, name); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | params = 6 + name_len; |
| 1158 | count = sizeof(OPEN_PSX_REQ); |
| 1159 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1160 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1161 | pSMB->MaxSetupCount = 0; |
| 1162 | pSMB->Reserved = 0; |
| 1163 | pSMB->Flags = 0; |
| 1164 | pSMB->Timeout = 0; |
| 1165 | pSMB->Reserved2 = 0; |
| 1166 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1167 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1168 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1169 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1170 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1171 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1172 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1173 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1174 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1175 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1176 | pSMB->SetupCount = 1; |
| 1177 | pSMB->Reserved3 = 0; |
| 1178 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1179 | byte_count = 3 /* pad */ + params + count; |
| 1180 | |
| 1181 | pSMB->DataCount = cpu_to_le16(count); |
| 1182 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1183 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1184 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1185 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1186 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1187 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1188 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1189 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1190 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1191 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1192 | cifs_dbg(FYI, "Posix create returned %d\n", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1193 | goto psx_create_err; |
| 1194 | } |
| 1195 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1196 | cifs_dbg(FYI, "copying inode info\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1197 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1198 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1199 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1200 | rc = -EIO; /* bad smb */ |
| 1201 | goto psx_create_err; |
| 1202 | } |
| 1203 | |
| 1204 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1205 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1206 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1207 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1208 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1209 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1210 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1211 | /* Let caller know file was created so we can set the mode. */ |
| 1212 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1213 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1214 | *pOplock |= CIFS_CREATE_ACTION; |
| 1215 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1216 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1217 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1218 | cifs_dbg(NOISY, "unknown type\n"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1219 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1220 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1221 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1222 | cifs_dbg(VFS, "Open response data too small\n"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1223 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1224 | goto psx_create_err; |
| 1225 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1226 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1227 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1228 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1229 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1230 | |
| 1231 | psx_create_err: |
| 1232 | cifs_buf_release(pSMB); |
| 1233 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1234 | if (posix_flags & SMB_O_DIRECTORY) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1235 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixmkdirs); |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1236 | else |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1237 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1238 | |
| 1239 | if (rc == -EAGAIN) |
| 1240 | goto PsxCreat; |
| 1241 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1242 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1245 | static __u16 convert_disposition(int disposition) |
| 1246 | { |
| 1247 | __u16 ofun = 0; |
| 1248 | |
| 1249 | switch (disposition) { |
| 1250 | case FILE_SUPERSEDE: |
| 1251 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1252 | break; |
| 1253 | case FILE_OPEN: |
| 1254 | ofun = SMBOPEN_OAPPEND; |
| 1255 | break; |
| 1256 | case FILE_CREATE: |
| 1257 | ofun = SMBOPEN_OCREATE; |
| 1258 | break; |
| 1259 | case FILE_OPEN_IF: |
| 1260 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1261 | break; |
| 1262 | case FILE_OVERWRITE: |
| 1263 | ofun = SMBOPEN_OTRUNC; |
| 1264 | break; |
| 1265 | case FILE_OVERWRITE_IF: |
| 1266 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1267 | break; |
| 1268 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1269 | cifs_dbg(FYI, "unknown disposition %d\n", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1270 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1271 | } |
| 1272 | return ofun; |
| 1273 | } |
| 1274 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1275 | static int |
| 1276 | access_flags_to_smbopen_mode(const int access_flags) |
| 1277 | { |
| 1278 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1279 | |
| 1280 | if (masked_flags == GENERIC_READ) |
| 1281 | return SMBOPEN_READ; |
| 1282 | else if (masked_flags == GENERIC_WRITE) |
| 1283 | return SMBOPEN_WRITE; |
| 1284 | |
| 1285 | /* just go for read/write */ |
| 1286 | return SMBOPEN_READWRITE; |
| 1287 | } |
| 1288 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1289 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1290 | SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1291 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1292 | const int access_flags, const int create_options, __u16 *netfid, |
| 1293 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1294 | const struct nls_table *nls_codepage, int remap) |
| 1295 | { |
| 1296 | int rc = -EACCES; |
| 1297 | OPENX_REQ *pSMB = NULL; |
| 1298 | OPENX_RSP *pSMBr = NULL; |
| 1299 | int bytes_returned; |
| 1300 | int name_len; |
| 1301 | __u16 count; |
| 1302 | |
| 1303 | OldOpenRetry: |
| 1304 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1305 | (void **) &pSMBr); |
| 1306 | if (rc) |
| 1307 | return rc; |
| 1308 | |
| 1309 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1310 | |
| 1311 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1312 | count = 1; /* account for one byte pad to word boundary */ |
| 1313 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1314 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1315 | fileName, PATH_MAX, nls_codepage, remap); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1316 | name_len++; /* trailing null */ |
| 1317 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1318 | } else { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1319 | count = 0; /* no pad */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1320 | name_len = copy_path_name(pSMB->fileName, fileName); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1321 | } |
| 1322 | if (*pOplock & REQ_OPLOCK) |
| 1323 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1324 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1325 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1326 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1327 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1328 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1329 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1330 | /* set file as system file if special file such |
| 1331 | as fifo and server expecting SFU style and |
| 1332 | no Unix extensions */ |
| 1333 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1334 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1335 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1336 | else /* BB FIXME BB */ |
| 1337 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1338 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1339 | if (create_options & CREATE_OPTION_READONLY) |
| 1340 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1341 | |
| 1342 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1343 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1344 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1345 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1346 | |
| 1347 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1348 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1349 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1350 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1351 | |
| 1352 | pSMB->ByteCount = cpu_to_le16(count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1353 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1354 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1355 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1356 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1357 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1358 | } else { |
| 1359 | /* BB verify if wct == 15 */ |
| 1360 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1361 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1362 | |
| 1363 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1364 | /* Let caller know file was created so we can set the mode. */ |
| 1365 | /* Do we care about the CreateAction in any other cases? */ |
| 1366 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1367 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1368 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1369 | /* BB FIXME END */ |
| 1370 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1371 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1372 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1373 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1374 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1375 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1376 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1377 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1378 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1379 | pfile_info->AllocationSize = |
| 1380 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1381 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1382 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1383 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | cifs_buf_release(pSMB); |
| 1388 | if (rc == -EAGAIN) |
| 1389 | goto OldOpenRetry; |
| 1390 | return rc; |
| 1391 | } |
| 1392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | int |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1394 | CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock, |
| 1395 | FILE_ALL_INFO *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | { |
Colin Ian King | 1afdea4 | 2019-07-23 16:09:19 +0100 | [diff] [blame] | 1397 | int rc; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1398 | OPEN_REQ *req = NULL; |
| 1399 | OPEN_RSP *rsp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | int bytes_returned; |
| 1401 | int name_len; |
| 1402 | __u16 count; |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1403 | struct cifs_sb_info *cifs_sb = oparms->cifs_sb; |
| 1404 | struct cifs_tcon *tcon = oparms->tcon; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1405 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1406 | const struct nls_table *nls = cifs_sb->local_nls; |
| 1407 | int create_options = oparms->create_options; |
| 1408 | int desired_access = oparms->desired_access; |
| 1409 | int disposition = oparms->disposition; |
| 1410 | const char *path = oparms->path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | |
| 1412 | openRetry: |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1413 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **)&req, |
| 1414 | (void **)&rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | if (rc) |
| 1416 | return rc; |
| 1417 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1418 | /* no commands go after this */ |
| 1419 | req->AndXCommand = 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1421 | if (req->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1422 | /* account for one byte pad to word boundary */ |
| 1423 | count = 1; |
| 1424 | name_len = cifsConvertToUTF16((__le16 *)(req->fileName + 1), |
| 1425 | path, PATH_MAX, nls, remap); |
| 1426 | /* trailing null */ |
| 1427 | name_len++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | name_len *= 2; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1429 | req->NameLength = cpu_to_le16(name_len); |
| 1430 | } else { |
| 1431 | /* BB improve check for buffer overruns BB */ |
| 1432 | /* no pad */ |
| 1433 | count = 0; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1434 | name_len = copy_path_name(req->fileName, path); |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1435 | req->NameLength = cpu_to_le16(name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | } |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1437 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1438 | if (*oplock & REQ_OPLOCK) |
| 1439 | req->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
| 1440 | else if (*oplock & REQ_BATCHOPLOCK) |
| 1441 | req->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
| 1442 | |
| 1443 | req->DesiredAccess = cpu_to_le32(desired_access); |
| 1444 | req->AllocationSize = 0; |
| 1445 | |
| 1446 | /* |
| 1447 | * Set file as system file if special file such as fifo and server |
| 1448 | * expecting SFU style and no Unix extensions. |
| 1449 | */ |
| 1450 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1451 | req->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1452 | else |
| 1453 | req->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
| 1454 | |
| 1455 | /* |
| 1456 | * XP does not handle ATTR_POSIX_SEMANTICS but it helps speed up case |
| 1457 | * sensitive checks for other servers such as Samba. |
| 1458 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | if (tcon->ses->capabilities & CAP_UNIX) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1460 | req->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1462 | if (create_options & CREATE_OPTION_READONLY) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1463 | req->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1464 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1465 | req->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1466 | req->CreateDisposition = cpu_to_le32(disposition); |
| 1467 | req->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
| 1468 | |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1469 | /* BB Expirement with various impersonation levels and verify */ |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1470 | req->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
| 1471 | req->SecurityFlags = SECURITY_CONTEXT_TRACKING|SECURITY_EFFECTIVE_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
| 1473 | count += name_len; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1474 | inc_rfc1001_len(req, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1476 | req->ByteCount = cpu_to_le16(count); |
| 1477 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *)req, |
| 1478 | (struct smb_hdr *)rsp, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1479 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1481 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1482 | cifs_buf_release(req); |
| 1483 | if (rc == -EAGAIN) |
| 1484 | goto openRetry; |
| 1485 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1487 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1488 | /* 1 byte no need to le_to_cpu */ |
| 1489 | *oplock = rsp->OplockLevel; |
| 1490 | /* cifs fid stays in le */ |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1491 | oparms->fid->netfid = rsp->Fid; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1492 | |
| 1493 | /* Let caller know file was created so we can set the mode. */ |
| 1494 | /* Do we care about the CreateAction in any other cases? */ |
| 1495 | if (cpu_to_le32(FILE_CREATE) == rsp->CreateAction) |
| 1496 | *oplock |= CIFS_CREATE_ACTION; |
| 1497 | |
| 1498 | if (buf) { |
| 1499 | /* copy from CreationTime to Attributes */ |
| 1500 | memcpy((char *)buf, (char *)&rsp->CreationTime, 36); |
| 1501 | /* the file_info buf is endian converted by caller */ |
| 1502 | buf->AllocationSize = rsp->AllocationSize; |
| 1503 | buf->EndOfFile = rsp->EndOfFile; |
| 1504 | buf->NumberOfLinks = cpu_to_le32(1); |
| 1505 | buf->DeletePending = 0; |
| 1506 | } |
| 1507 | |
| 1508 | cifs_buf_release(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | return rc; |
| 1510 | } |
| 1511 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1512 | /* |
| 1513 | * Discard any remaining data in the current SMB. To do this, we borrow the |
| 1514 | * current bigbuf. |
| 1515 | */ |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 1516 | int |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1517 | cifs_discard_remaining_data(struct TCP_Server_Info *server) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1518 | { |
Ronnie Sahlberg | 05432e2 | 2018-04-09 18:06:31 +1000 | [diff] [blame] | 1519 | unsigned int rfclen = server->pdu_size; |
| 1520 | int remaining = rfclen + server->vals->header_preamble_size - |
| 1521 | server->total_read; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1522 | |
| 1523 | while (remaining > 0) { |
| 1524 | int length; |
| 1525 | |
| 1526 | length = cifs_read_from_socket(server, server->bigbuf, |
| 1527 | min_t(unsigned int, remaining, |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1528 | CIFSMaxBufSize + MAX_HEADER_SIZE(server))); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1529 | if (length < 0) |
| 1530 | return length; |
| 1531 | server->total_read += length; |
| 1532 | remaining -= length; |
| 1533 | } |
| 1534 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1535 | return 0; |
| 1536 | } |
| 1537 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1538 | static int |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1539 | __cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid, |
| 1540 | bool malformed) |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1541 | { |
| 1542 | int length; |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1543 | |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1544 | length = cifs_discard_remaining_data(server); |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1545 | dequeue_mid(mid, malformed); |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1546 | mid->resp_buf = server->smallbuf; |
| 1547 | server->smallbuf = NULL; |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1548 | return length; |
| 1549 | } |
| 1550 | |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1551 | static int |
| 1552 | cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1553 | { |
| 1554 | struct cifs_readdata *rdata = mid->callback_data; |
| 1555 | |
| 1556 | return __cifs_readv_discard(server, mid, rdata->result); |
| 1557 | } |
| 1558 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1559 | int |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1560 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1561 | { |
| 1562 | int length, len; |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1563 | unsigned int data_offset, data_len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1564 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1565 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 1566 | unsigned int buflen = server->pdu_size + |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 1567 | server->vals->header_preamble_size; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1568 | bool use_rdma_mr = false; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1569 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1570 | cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n", |
| 1571 | __func__, mid->mid, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1572 | |
| 1573 | /* |
| 1574 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1575 | * can if there's not enough data. At this point, we've read down to |
| 1576 | * the Mid. |
| 1577 | */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1578 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1579 | HEADER_SIZE(server) + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1580 | |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1581 | length = cifs_read_from_socket(server, |
| 1582 | buf + HEADER_SIZE(server) - 1, 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 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1587 | if (server->ops->is_session_expired && |
| 1588 | server->ops->is_session_expired(buf)) { |
| 1589 | cifs_reconnect(server); |
| 1590 | wake_up(&server->response_q); |
| 1591 | return -1; |
| 1592 | } |
| 1593 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1594 | if (server->ops->is_status_pending && |
Pavel Shilovsky | 66265f1 | 2019-01-23 17:11:16 -0800 | [diff] [blame] | 1595 | server->ops->is_status_pending(buf, server)) { |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1596 | cifs_discard_remaining_data(server); |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1597 | return -1; |
| 1598 | } |
| 1599 | |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1600 | /* set up first two iov for signature check and to get credits */ |
| 1601 | rdata->iov[0].iov_base = buf; |
Pavel Shilovsky | bb1bccb | 2019-01-17 16:18:38 -0800 | [diff] [blame] | 1602 | rdata->iov[0].iov_len = server->vals->header_preamble_size; |
| 1603 | rdata->iov[1].iov_base = buf + server->vals->header_preamble_size; |
| 1604 | rdata->iov[1].iov_len = |
| 1605 | server->total_read - server->vals->header_preamble_size; |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1606 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 1607 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); |
| 1608 | cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", |
| 1609 | rdata->iov[1].iov_base, rdata->iov[1].iov_len); |
| 1610 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1611 | /* Was the SMB read successful? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1612 | rdata->result = server->ops->map_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1613 | if (rdata->result != 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1614 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 1615 | __func__, rdata->result); |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1616 | /* normal error on read response */ |
| 1617 | return __cifs_readv_discard(server, mid, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | /* 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] | 1621 | if (server->total_read < server->vals->read_rsp_size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1622 | cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n", |
| 1623 | __func__, server->total_read, |
| 1624 | server->vals->read_rsp_size); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1625 | rdata->result = -EIO; |
| 1626 | return cifs_readv_discard(server, mid); |
| 1627 | } |
| 1628 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 1629 | data_offset = server->ops->read_data_offset(buf) + |
| 1630 | server->vals->header_preamble_size; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1631 | if (data_offset < server->total_read) { |
| 1632 | /* |
| 1633 | * win2k8 sometimes sends an offset of 0 when the read |
| 1634 | * is beyond the EOF. Treat it as if the data starts just after |
| 1635 | * the header. |
| 1636 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1637 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 1638 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1639 | data_offset = server->total_read; |
| 1640 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1641 | /* data_offset is beyond the end of smallbuf */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1642 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 1643 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1644 | rdata->result = -EIO; |
| 1645 | return cifs_readv_discard(server, mid); |
| 1646 | } |
| 1647 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1648 | cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n", |
| 1649 | __func__, server->total_read, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1650 | |
| 1651 | len = data_offset - server->total_read; |
| 1652 | if (len > 0) { |
| 1653 | /* read any junk before data into the rest of smallbuf */ |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1654 | length = cifs_read_from_socket(server, |
| 1655 | buf + server->total_read, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1656 | if (length < 0) |
| 1657 | return length; |
| 1658 | server->total_read += length; |
| 1659 | } |
| 1660 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1661 | /* how much data is in the response? */ |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1662 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 1663 | use_rdma_mr = rdata->mr; |
| 1664 | #endif |
| 1665 | data_len = server->ops->read_data_length(buf, use_rdma_mr); |
| 1666 | if (!use_rdma_mr && (data_offset + data_len > buflen)) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1667 | /* data_len is corrupt -- discard frame */ |
| 1668 | rdata->result = -EIO; |
| 1669 | return cifs_readv_discard(server, mid); |
| 1670 | } |
| 1671 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1672 | length = rdata->read_into_pages(server, rdata, data_len); |
| 1673 | if (length < 0) |
| 1674 | return length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1675 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1676 | server->total_read += length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1677 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1678 | cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n", |
| 1679 | server->total_read, buflen, data_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1680 | |
| 1681 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1682 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1683 | return cifs_readv_discard(server, mid); |
| 1684 | |
| 1685 | dequeue_mid(mid, false); |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1686 | mid->resp_buf = server->smallbuf; |
| 1687 | server->smallbuf = NULL; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1688 | return length; |
| 1689 | } |
| 1690 | |
| 1691 | static void |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1692 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1693 | { |
| 1694 | struct cifs_readdata *rdata = mid->callback_data; |
| 1695 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1696 | struct TCP_Server_Info *server = tcon->ses->server; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1697 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 1698 | .rq_nvec = 2, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1699 | .rq_pages = rdata->pages, |
Long Li | 6d3adb2 | 2018-09-20 21:18:38 +0000 | [diff] [blame] | 1700 | .rq_offset = rdata->page_offset, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1701 | .rq_npages = rdata->nr_pages, |
| 1702 | .rq_pagesz = rdata->pagesz, |
| 1703 | .rq_tailsz = rdata->tailsz }; |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 1704 | struct cifs_credits credits = { .value = 1, .instance = 0 }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1705 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1706 | cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", |
| 1707 | __func__, mid->mid, mid->mid_state, rdata->result, |
| 1708 | rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1709 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1710 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1711 | case MID_RESPONSE_RECEIVED: |
| 1712 | /* result already set, check signature */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 1713 | if (server->sign) { |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1714 | int rc = 0; |
| 1715 | |
Jeff Layton | bf5ea0e | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1716 | rc = cifs_verify_signature(&rqst, server, |
Jeff Layton | 0124cc4 | 2013-04-03 11:55:03 -0400 | [diff] [blame] | 1717 | mid->sequence_number); |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1718 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1719 | cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
| 1720 | rc); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1721 | } |
| 1722 | /* FIXME: should this be counted toward the initiating task? */ |
Pavel Shilovsky | 34a54d6 | 2014-07-10 10:03:29 +0400 | [diff] [blame] | 1723 | task_io_account_read(rdata->got_bytes); |
| 1724 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1725 | break; |
| 1726 | case MID_REQUEST_SUBMITTED: |
| 1727 | case MID_RETRY_NEEDED: |
| 1728 | rdata->result = -EAGAIN; |
Pavel Shilovsky | d913ed1 | 2014-07-10 11:31:48 +0400 | [diff] [blame] | 1729 | if (server->sign && rdata->got_bytes) |
| 1730 | /* reset bytes number since we can not check a sign */ |
| 1731 | rdata->got_bytes = 0; |
| 1732 | /* FIXME: should this be counted toward the initiating task? */ |
| 1733 | task_io_account_read(rdata->got_bytes); |
| 1734 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1735 | break; |
| 1736 | default: |
| 1737 | rdata->result = -EIO; |
| 1738 | } |
| 1739 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1740 | queue_work(cifsiod_wq, &rdata->work); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1741 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 1742 | add_credits(server, &credits, 0); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1746 | int |
| 1747 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1748 | { |
| 1749 | int rc; |
| 1750 | READ_REQ *smb = NULL; |
| 1751 | int wct; |
| 1752 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1753 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 1754 | .rq_nvec = 2 }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1755 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1756 | cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n", |
| 1757 | __func__, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1758 | |
| 1759 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1760 | wct = 12; |
| 1761 | else { |
| 1762 | wct = 10; /* old style read */ |
| 1763 | if ((rdata->offset >> 32) > 0) { |
| 1764 | /* can not handle this big offset for old */ |
| 1765 | return -EIO; |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1770 | if (rc) |
| 1771 | return rc; |
| 1772 | |
| 1773 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1774 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1775 | |
| 1776 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1777 | smb->Fid = rdata->cfile->fid.netfid; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1778 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1779 | if (wct == 12) |
| 1780 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1781 | smb->Remaining = 0; |
| 1782 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1783 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1784 | if (wct == 12) |
| 1785 | smb->ByteCount = 0; |
| 1786 | else { |
| 1787 | /* old style read */ |
| 1788 | struct smb_com_readx_req *smbr = |
| 1789 | (struct smb_com_readx_req *)smb; |
| 1790 | smbr->ByteCount = 0; |
| 1791 | } |
| 1792 | |
| 1793 | /* 4 for RFC1001 length + 1 for BCC */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1794 | rdata->iov[0].iov_base = smb; |
| 1795 | rdata->iov[0].iov_len = 4; |
| 1796 | rdata->iov[1].iov_base = (char *)smb + 4; |
| 1797 | rdata->iov[1].iov_len = get_rfc1002_length(smb); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1798 | |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1799 | kref_get(&rdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 1800 | rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, |
Pavel Shilovsky | 3349c3a | 2019-01-15 15:52:29 -0800 | [diff] [blame] | 1801 | cifs_readv_callback, NULL, rdata, 0, NULL); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1802 | |
| 1803 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1804 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1805 | else |
| 1806 | kref_put(&rdata->refcount, cifs_readdata_release); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1807 | |
| 1808 | cifs_small_buf_release(smb); |
| 1809 | return rc; |
| 1810 | } |
| 1811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1813 | CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms, |
| 1814 | unsigned int *nbytes, char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | { |
| 1816 | int rc = -EACCES; |
| 1817 | READ_REQ *pSMB = NULL; |
| 1818 | READ_RSP *pSMBr = NULL; |
| 1819 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1820 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1821 | int resp_buf_type = 0; |
| 1822 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1823 | struct kvec rsp_iov; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1824 | __u32 pid = io_parms->pid; |
| 1825 | __u16 netfid = io_parms->netfid; |
| 1826 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1827 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1828 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1830 | cifs_dbg(FYI, "Reading %d bytes on fid %d\n", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1831 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1832 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1833 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1834 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1835 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1836 | /* can not handle this big offset for old */ |
| 1837 | return -EIO; |
| 1838 | } |
| 1839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | |
| 1841 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1842 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | if (rc) |
| 1844 | return rc; |
| 1845 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1846 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1847 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | /* tcon and ses pointer are checked in smb_init */ |
| 1850 | if (tcon->ses->server == NULL) |
| 1851 | return -ECONNABORTED; |
| 1852 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1853 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1855 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1856 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1857 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | pSMB->Remaining = 0; |
| 1860 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1861 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1862 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1863 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1864 | else { |
| 1865 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1866 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1867 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1868 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1869 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1870 | |
| 1871 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1872 | 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] | 1873 | rc = SendReceive2(xid, tcon->ses, iov, 1, &resp_buf_type, |
| 1874 | CIFS_LOG_ERROR, &rsp_iov); |
| 1875 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1876 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1877 | pSMBr = (READ_RSP *)rsp_iov.iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1879 | cifs_dbg(VFS, "Send error in read = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | } else { |
| 1881 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1882 | data_length = data_length << 16; |
| 1883 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1884 | *nbytes = data_length; |
| 1885 | |
| 1886 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1887 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | || (data_length > count)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1889 | cifs_dbg(FYI, "bad length %d for count %d\n", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1890 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | rc = -EIO; |
| 1892 | *nbytes = 0; |
| 1893 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1894 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1895 | le16_to_cpu(pSMBr->DataOffset); |
| 1896 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1897 | cifs_dbg(VFS, "Faulting on read rc = %d\n",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1898 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1899 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1900 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1901 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | } |
| 1903 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1905 | if (*buf) { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1906 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1907 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1908 | /* return buffer to caller to free */ |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1909 | *buf = rsp_iov.iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1910 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1911 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1912 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1913 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1914 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1915 | |
| 1916 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | since file handle passed in no longer valid */ |
| 1918 | return rc; |
| 1919 | } |
| 1920 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1923 | CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1924 | unsigned int *nbytes, const char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | { |
| 1926 | int rc = -EACCES; |
| 1927 | WRITE_REQ *pSMB = NULL; |
| 1928 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1929 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | __u32 bytes_sent; |
| 1931 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1932 | __u32 pid = io_parms->pid; |
| 1933 | __u16 netfid = io_parms->netfid; |
| 1934 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1935 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1936 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1938 | *nbytes = 0; |
| 1939 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1940 | /* cifs_dbg(FYI, "write at %lld %d bytes\n", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1941 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1942 | return -ECONNABORTED; |
| 1943 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1944 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1945 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1946 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1947 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1948 | if ((offset >> 32) > 0) { |
| 1949 | /* can not handle big offset for old srv */ |
| 1950 | return -EIO; |
| 1951 | } |
| 1952 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1953 | |
| 1954 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | (void **) &pSMBr); |
| 1956 | if (rc) |
| 1957 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1958 | |
| 1959 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1960 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | /* tcon and ses pointer are checked in smb_init */ |
| 1963 | if (tcon->ses->server == NULL) |
| 1964 | return -ECONNABORTED; |
| 1965 | |
| 1966 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1967 | pSMB->Fid = netfid; |
| 1968 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1969 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1970 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | pSMB->Reserved = 0xFFFFFFFF; |
| 1973 | pSMB->WriteMode = 0; |
| 1974 | pSMB->Remaining = 0; |
| 1975 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1976 | /* 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] | 1977 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1978 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1979 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1980 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1982 | } else { |
| 1983 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1984 | & ~0xFF; |
| 1985 | } |
| 1986 | |
| 1987 | if (bytes_sent > count) |
| 1988 | bytes_sent = count; |
| 1989 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1990 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1991 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1992 | memcpy(pSMB->Data, buf, bytes_sent); |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1993 | else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | /* No buffer */ |
| 1995 | cifs_buf_release(pSMB); |
| 1996 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1997 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1998 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1999 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2000 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 2001 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 2004 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2005 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 2006 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2007 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 2008 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2009 | else { /* old style write has byte count 4 bytes earlier |
| 2010 | so 4 bytes pad */ |
| 2011 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 2012 | (struct smb_com_writex_req *)pSMB; |
| 2013 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 2014 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | |
| 2016 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 2017 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2018 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2020 | cifs_dbg(FYI, "Send error in write = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | } else { |
| 2022 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2023 | *nbytes = (*nbytes) << 16; |
| 2024 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2025 | |
| 2026 | /* |
| 2027 | * Mask off high 16 bits when bytes written as returned by the |
| 2028 | * server is greater than bytes requested by the client. Some |
| 2029 | * OS/2 servers are known to set incorrect CountHigh values. |
| 2030 | */ |
| 2031 | if (*nbytes > count) |
| 2032 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | cifs_buf_release(pSMB); |
| 2036 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2037 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | since file handle passed in no longer valid */ |
| 2039 | |
| 2040 | return rc; |
| 2041 | } |
| 2042 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2043 | void |
| 2044 | cifs_writedata_release(struct kref *refcount) |
| 2045 | { |
| 2046 | struct cifs_writedata *wdata = container_of(refcount, |
| 2047 | struct cifs_writedata, refcount); |
Long Li | db223a5 | 2017-11-22 17:38:45 -0700 | [diff] [blame] | 2048 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 2049 | if (wdata->mr) { |
| 2050 | smbd_deregister_mr(wdata->mr); |
| 2051 | wdata->mr = NULL; |
| 2052 | } |
| 2053 | #endif |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2054 | |
| 2055 | if (wdata->cfile) |
| 2056 | cifsFileInfo_put(wdata->cfile); |
| 2057 | |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2058 | kvfree(wdata->pages); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2059 | kfree(wdata); |
| 2060 | } |
| 2061 | |
| 2062 | /* |
| 2063 | * Write failed with a retryable error. Resend the write request. It's also |
| 2064 | * possible that the page was redirtied so re-clean the page. |
| 2065 | */ |
| 2066 | static void |
| 2067 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 2068 | { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2069 | int i, rc = 0; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2070 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Pavel Shilovsky | c9de5c8 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2071 | struct TCP_Server_Info *server; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2072 | unsigned int rest_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2073 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2074 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
| 2075 | i = 0; |
| 2076 | rest_len = wdata->bytes; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2077 | do { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2078 | struct cifs_writedata *wdata2; |
| 2079 | unsigned int j, nr_pages, wsize, tailsz, cur_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2080 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2081 | wsize = server->ops->wp_retry_size(inode); |
| 2082 | if (wsize < rest_len) { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2083 | nr_pages = wsize / PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2084 | if (!nr_pages) { |
| 2085 | rc = -ENOTSUPP; |
| 2086 | break; |
| 2087 | } |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2088 | cur_len = nr_pages * PAGE_SIZE; |
| 2089 | tailsz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2090 | } else { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2091 | nr_pages = DIV_ROUND_UP(rest_len, PAGE_SIZE); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2092 | cur_len = rest_len; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2093 | tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE; |
Ouyang Maochun | c51bb0e | 2013-02-18 09:54:52 -0600 | [diff] [blame] | 2094 | } |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2095 | |
| 2096 | wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete); |
| 2097 | if (!wdata2) { |
| 2098 | rc = -ENOMEM; |
| 2099 | break; |
| 2100 | } |
| 2101 | |
| 2102 | for (j = 0; j < nr_pages; j++) { |
| 2103 | wdata2->pages[j] = wdata->pages[i + j]; |
| 2104 | lock_page(wdata2->pages[j]); |
| 2105 | clear_page_dirty_for_io(wdata2->pages[j]); |
| 2106 | } |
| 2107 | |
| 2108 | wdata2->sync_mode = wdata->sync_mode; |
| 2109 | wdata2->nr_pages = nr_pages; |
| 2110 | wdata2->offset = page_offset(wdata2->pages[0]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2111 | wdata2->pagesz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2112 | wdata2->tailsz = tailsz; |
| 2113 | wdata2->bytes = cur_len; |
| 2114 | |
Pavel Shilovsky | fe768d5 | 2019-01-29 12:15:11 -0800 | [diff] [blame] | 2115 | rc = cifs_get_writable_file(CIFS_I(inode), false, |
| 2116 | &wdata2->cfile); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2117 | if (!wdata2->cfile) { |
Pavel Shilovsky | fe768d5 | 2019-01-29 12:15:11 -0800 | [diff] [blame] | 2118 | cifs_dbg(VFS, "No writable handle to retry writepages rc=%d\n", |
| 2119 | rc); |
| 2120 | if (!is_retryable_error(rc)) |
| 2121 | rc = -EBADF; |
Pavel Shilovsky | 165df9a | 2019-01-29 16:40:28 -0800 | [diff] [blame] | 2122 | } else { |
| 2123 | wdata2->pid = wdata2->cfile->pid; |
| 2124 | rc = server->ops->async_writev(wdata2, |
| 2125 | cifs_writedata_release); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2126 | } |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2127 | |
| 2128 | for (j = 0; j < nr_pages; j++) { |
| 2129 | unlock_page(wdata2->pages[j]); |
Pavel Shilovsky | 9a66396 | 2019-01-08 11:15:28 -0800 | [diff] [blame] | 2130 | if (rc != 0 && !is_retryable_error(rc)) { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2131 | SetPageError(wdata2->pages[j]); |
| 2132 | end_page_writeback(wdata2->pages[j]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2133 | put_page(wdata2->pages[j]); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | if (rc) { |
| 2138 | kref_put(&wdata2->refcount, cifs_writedata_release); |
Pavel Shilovsky | 9a66396 | 2019-01-08 11:15:28 -0800 | [diff] [blame] | 2139 | if (is_retryable_error(rc)) |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2140 | continue; |
Pavel Shilovsky | 165df9a | 2019-01-29 16:40:28 -0800 | [diff] [blame] | 2141 | i += nr_pages; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2142 | break; |
| 2143 | } |
| 2144 | |
| 2145 | rest_len -= cur_len; |
| 2146 | i += nr_pages; |
| 2147 | } while (i < wdata->nr_pages); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2148 | |
Pavel Shilovsky | 165df9a | 2019-01-29 16:40:28 -0800 | [diff] [blame] | 2149 | /* cleanup remaining pages from the original wdata */ |
| 2150 | for (; i < wdata->nr_pages; i++) { |
| 2151 | SetPageError(wdata->pages[i]); |
| 2152 | end_page_writeback(wdata->pages[i]); |
| 2153 | put_page(wdata->pages[i]); |
| 2154 | } |
| 2155 | |
Pavel Shilovsky | 9a66396 | 2019-01-08 11:15:28 -0800 | [diff] [blame] | 2156 | if (rc != 0 && !is_retryable_error(rc)) |
| 2157 | mapping_set_error(inode->i_mapping, rc); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2158 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2159 | } |
| 2160 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2161 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2162 | cifs_writev_complete(struct work_struct *work) |
| 2163 | { |
| 2164 | struct cifs_writedata *wdata = container_of(work, |
| 2165 | struct cifs_writedata, work); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2166 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2167 | int i = 0; |
| 2168 | |
| 2169 | if (wdata->result == 0) { |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2170 | spin_lock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2171 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2172 | spin_unlock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2173 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 2174 | wdata->bytes); |
| 2175 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 2176 | return cifs_writev_requeue(wdata); |
| 2177 | |
| 2178 | for (i = 0; i < wdata->nr_pages; i++) { |
| 2179 | struct page *page = wdata->pages[i]; |
| 2180 | if (wdata->result == -EAGAIN) |
| 2181 | __set_page_dirty_nobuffers(page); |
| 2182 | else if (wdata->result < 0) |
| 2183 | SetPageError(page); |
| 2184 | end_page_writeback(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2185 | put_page(page); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2186 | } |
| 2187 | if (wdata->result != -EAGAIN) |
| 2188 | mapping_set_error(inode->i_mapping, wdata->result); |
| 2189 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2190 | } |
| 2191 | |
| 2192 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2193 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2194 | { |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2195 | struct page **pages = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2196 | kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2197 | if (pages) |
| 2198 | return cifs_writedata_direct_alloc(pages, complete); |
| 2199 | |
| 2200 | return NULL; |
| 2201 | } |
| 2202 | |
| 2203 | struct cifs_writedata * |
| 2204 | cifs_writedata_direct_alloc(struct page **pages, work_func_t complete) |
| 2205 | { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2206 | struct cifs_writedata *wdata; |
| 2207 | |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2208 | wdata = kzalloc(sizeof(*wdata), GFP_NOFS); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2209 | if (wdata != NULL) { |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2210 | wdata->pages = pages; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2211 | kref_init(&wdata->refcount); |
Jeff Layton | da82f7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2212 | INIT_LIST_HEAD(&wdata->list); |
| 2213 | init_completion(&wdata->done); |
| 2214 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2215 | } |
| 2216 | return wdata; |
| 2217 | } |
| 2218 | |
| 2219 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2220 | * 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] | 2221 | * workqueue completion task. |
| 2222 | */ |
| 2223 | static void |
| 2224 | cifs_writev_callback(struct mid_q_entry *mid) |
| 2225 | { |
| 2226 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2227 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2228 | unsigned int written; |
| 2229 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 2230 | struct cifs_credits credits = { .value = 1, .instance = 0 }; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2231 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2232 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2233 | case MID_RESPONSE_RECEIVED: |
| 2234 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 2235 | if (wdata->result != 0) |
| 2236 | break; |
| 2237 | |
| 2238 | written = le16_to_cpu(smb->CountHigh); |
| 2239 | written <<= 16; |
| 2240 | written += le16_to_cpu(smb->Count); |
| 2241 | /* |
| 2242 | * Mask off high 16 bits when bytes written as returned |
| 2243 | * by the server is greater than bytes requested by the |
| 2244 | * client. OS/2 servers are known to set incorrect |
| 2245 | * CountHigh values. |
| 2246 | */ |
| 2247 | if (written > wdata->bytes) |
| 2248 | written &= 0xFFFF; |
| 2249 | |
| 2250 | if (written < wdata->bytes) |
| 2251 | wdata->result = -ENOSPC; |
| 2252 | else |
| 2253 | wdata->bytes = written; |
| 2254 | break; |
| 2255 | case MID_REQUEST_SUBMITTED: |
| 2256 | case MID_RETRY_NEEDED: |
| 2257 | wdata->result = -EAGAIN; |
| 2258 | break; |
| 2259 | default: |
| 2260 | wdata->result = -EIO; |
| 2261 | break; |
| 2262 | } |
| 2263 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2264 | queue_work(cifsiod_wq, &wdata->work); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2265 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 2266 | add_credits(tcon->ses->server, &credits, 0); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2270 | int |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2271 | cifs_async_writev(struct cifs_writedata *wdata, |
| 2272 | void (*release)(struct kref *kref)) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2273 | { |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2274 | int rc = -EACCES; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2275 | WRITE_REQ *smb = NULL; |
| 2276 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2277 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2278 | struct kvec iov[2]; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2279 | struct smb_rqst rqst = { }; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2280 | |
| 2281 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2282 | wct = 14; |
| 2283 | } else { |
| 2284 | wct = 12; |
| 2285 | if (wdata->offset >> 32 > 0) { |
| 2286 | /* can not handle big offset for old srv */ |
| 2287 | return -EIO; |
| 2288 | } |
| 2289 | } |
| 2290 | |
| 2291 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2292 | if (rc) |
| 2293 | goto async_writev_out; |
| 2294 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2295 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2296 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2297 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2298 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2299 | smb->Fid = wdata->cfile->fid.netfid; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2300 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2301 | if (wct == 14) |
| 2302 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2303 | smb->Reserved = 0xFFFFFFFF; |
| 2304 | smb->WriteMode = 0; |
| 2305 | smb->Remaining = 0; |
| 2306 | |
| 2307 | smb->DataOffset = |
| 2308 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2309 | |
| 2310 | /* 4 for RFC1001 length + 1 for BCC */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2311 | iov[0].iov_len = 4; |
| 2312 | iov[0].iov_base = smb; |
| 2313 | iov[1].iov_len = get_rfc1002_length(smb) + 1; |
| 2314 | iov[1].iov_base = (char *)smb + 4; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2315 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2316 | rqst.rq_iov = iov; |
| 2317 | rqst.rq_nvec = 2; |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2318 | rqst.rq_pages = wdata->pages; |
Long Li | 6d3adb2 | 2018-09-20 21:18:38 +0000 | [diff] [blame] | 2319 | rqst.rq_offset = wdata->page_offset; |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2320 | rqst.rq_npages = wdata->nr_pages; |
| 2321 | rqst.rq_pagesz = wdata->pagesz; |
| 2322 | rqst.rq_tailsz = wdata->tailsz; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2323 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2324 | cifs_dbg(FYI, "async write at %llu %u bytes\n", |
| 2325 | wdata->offset, wdata->bytes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2326 | |
| 2327 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2328 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2329 | |
| 2330 | if (wct == 14) { |
| 2331 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2332 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2333 | } else { |
| 2334 | /* wct == 12 */ |
| 2335 | struct smb_com_writex_req *smbw = |
| 2336 | (struct smb_com_writex_req *)smb; |
| 2337 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2338 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2339 | iov[1].iov_len += 4; /* pad bigger by four bytes */ |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | kref_get(&wdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2343 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, |
Pavel Shilovsky | 3349c3a | 2019-01-15 15:52:29 -0800 | [diff] [blame] | 2344 | cifs_writev_callback, NULL, wdata, 0, NULL); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2345 | |
| 2346 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2347 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2348 | else |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2349 | kref_put(&wdata->refcount, release); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2350 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2351 | async_writev_out: |
| 2352 | cifs_small_buf_release(smb); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2353 | return rc; |
| 2354 | } |
| 2355 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2356 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2357 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2358 | unsigned int *nbytes, struct kvec *iov, int n_vec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | { |
| 2360 | int rc = -EACCES; |
| 2361 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2362 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2363 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2364 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2365 | __u32 pid = io_parms->pid; |
| 2366 | __u16 netfid = io_parms->netfid; |
| 2367 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2368 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2369 | unsigned int count = io_parms->length; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2370 | struct kvec rsp_iov; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2372 | *nbytes = 0; |
| 2373 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2374 | 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] | 2375 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2376 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2377 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2378 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2379 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2380 | if ((offset >> 32) > 0) { |
| 2381 | /* can not handle big offset for old srv */ |
| 2382 | return -EIO; |
| 2383 | } |
| 2384 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2385 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | if (rc) |
| 2387 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2388 | |
| 2389 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2390 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | /* tcon and ses pointer are checked in smb_init */ |
| 2393 | if (tcon->ses->server == NULL) |
| 2394 | return -ECONNABORTED; |
| 2395 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2396 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | pSMB->Fid = netfid; |
| 2398 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2399 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2400 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | pSMB->Reserved = 0xFFFFFFFF; |
| 2402 | pSMB->WriteMode = 0; |
| 2403 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2406 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2408 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2409 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2410 | /* header + 1 byte pad */ |
| 2411 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2412 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2413 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2414 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2415 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2416 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2417 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2418 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2419 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2420 | (struct smb_com_writex_req *)pSMB; |
| 2421 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2422 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2423 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2424 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2425 | iov[0].iov_len = smb_hdr_len + 4; |
| 2426 | else /* wct == 12 pad bigger by four bytes */ |
| 2427 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2428 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2429 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0, |
| 2430 | &rsp_iov); |
| 2431 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2432 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2434 | cifs_dbg(FYI, "Send error Write2 = %d\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2435 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2436 | /* presumably this can not happen, but best to be safe */ |
| 2437 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2438 | } else { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2439 | WRITE_RSP *pSMBr = (WRITE_RSP *)rsp_iov.iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2440 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2441 | *nbytes = (*nbytes) << 16; |
| 2442 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2443 | |
| 2444 | /* |
| 2445 | * Mask off high 16 bits when bytes written as returned by the |
| 2446 | * server is greater than bytes requested by the client. OS/2 |
| 2447 | * servers are known to set incorrect CountHigh values. |
| 2448 | */ |
| 2449 | if (*nbytes > count) |
| 2450 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2453 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2455 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | since file handle passed in no longer valid */ |
| 2457 | |
| 2458 | return rc; |
| 2459 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2460 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2461 | int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon, |
| 2462 | const __u16 netfid, const __u8 lock_type, const __u32 num_unlock, |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2463 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2464 | { |
| 2465 | int rc = 0; |
| 2466 | LOCK_REQ *pSMB = NULL; |
| 2467 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2468 | struct kvec rsp_iov; |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2469 | int resp_buf_type; |
| 2470 | __u16 count; |
| 2471 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2472 | cifs_dbg(FYI, "cifs_lockv num lock %d num unlock %d\n", |
| 2473 | num_lock, num_unlock); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2474 | |
| 2475 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2476 | if (rc) |
| 2477 | return rc; |
| 2478 | |
| 2479 | pSMB->Timeout = 0; |
| 2480 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2481 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2482 | pSMB->LockType = lock_type; |
| 2483 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2484 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2485 | |
| 2486 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2487 | inc_rfc1001_len(pSMB, count); |
| 2488 | pSMB->ByteCount = cpu_to_le16(count); |
| 2489 | |
| 2490 | iov[0].iov_base = (char *)pSMB; |
| 2491 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2492 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2493 | iov[1].iov_base = (char *)buf; |
| 2494 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2495 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2496 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Ronnie Sahlberg | 392e1c5 | 2019-05-06 10:00:02 +1000 | [diff] [blame] | 2497 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, |
| 2498 | CIFS_NO_RSP_BUF, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2499 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2500 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2501 | cifs_dbg(FYI, "Send error in cifs_lockv = %d\n", rc); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2502 | |
| 2503 | return rc; |
| 2504 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2507 | CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2508 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2510 | const __u32 numLock, const __u8 lockType, |
| 2511 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | { |
| 2513 | int rc = 0; |
| 2514 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2515 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | int bytes_returned; |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2517 | int flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | __u16 count; |
| 2519 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2520 | cifs_dbg(FYI, "CIFSSMBLock timeout %d numLock %d\n", |
| 2521 | (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2522 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | if (rc) |
| 2525 | return rc; |
| 2526 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2527 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2528 | /* no response expected */ |
Ronnie Sahlberg | 392e1c5 | 2019-05-06 10:00:02 +1000 | [diff] [blame] | 2529 | flags = CIFS_NO_SRV_RSP | CIFS_NON_BLOCKING | CIFS_OBREAK_OP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2531 | } else if (waitFlag) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2532 | flags = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2534 | } else { |
| 2535 | pSMB->Timeout = 0; |
| 2536 | } |
| 2537 | |
| 2538 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2539 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2540 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2541 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2543 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2544 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2545 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2546 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | /* BB where to store pid high? */ |
| 2548 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2549 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2550 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2551 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2552 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2553 | } else { |
| 2554 | /* oplock break */ |
| 2555 | count = 0; |
| 2556 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2557 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | pSMB->ByteCount = cpu_to_le16(count); |
| 2559 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2560 | if (waitFlag) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2561 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2562 | (struct smb_hdr *) pSMB, &bytes_returned); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2563 | else |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2564 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, flags); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2565 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2566 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2567 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2568 | cifs_dbg(FYI, "Send error in Lock = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2570 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | since file handle passed in no longer valid */ |
| 2572 | return rc; |
| 2573 | } |
| 2574 | |
| 2575 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2576 | CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2577 | const __u16 smb_file_id, const __u32 netpid, |
| 2578 | const loff_t start_offset, const __u64 len, |
| 2579 | struct file_lock *pLockData, const __u16 lock_type, |
| 2580 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2581 | { |
| 2582 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2583 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2584 | struct cifs_posix_lock *parm_data; |
| 2585 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2586 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2587 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2588 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2589 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2590 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2591 | struct kvec rsp_iov; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2592 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2593 | cifs_dbg(FYI, "Posix Lock\n"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2594 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2595 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2596 | |
| 2597 | if (rc) |
| 2598 | return rc; |
| 2599 | |
| 2600 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2601 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2602 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2603 | pSMB->MaxSetupCount = 0; |
| 2604 | pSMB->Reserved = 0; |
| 2605 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2606 | pSMB->Reserved2 = 0; |
| 2607 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2608 | offset = param_offset + params; |
| 2609 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2610 | count = sizeof(struct cifs_posix_lock); |
| 2611 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2612 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2613 | pSMB->SetupCount = 1; |
| 2614 | pSMB->Reserved3 = 0; |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2615 | if (pLockData) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2616 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2617 | else |
| 2618 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2619 | byte_count = 3 /* pad */ + params + count; |
| 2620 | pSMB->DataCount = cpu_to_le16(count); |
| 2621 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2622 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2623 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2624 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2625 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2626 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2627 | |
| 2628 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2629 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2630 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2631 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2632 | pSMB->Timeout = cpu_to_le32(-1); |
| 2633 | } else |
| 2634 | pSMB->Timeout = 0; |
| 2635 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2636 | parm_data->pid = cpu_to_le32(netpid); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2637 | parm_data->start = cpu_to_le64(start_offset); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2638 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2639 | |
| 2640 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2641 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2642 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2643 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2644 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2645 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2646 | if (waitFlag) { |
| 2647 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2648 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2649 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2650 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2651 | 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] | 2652 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2653 | &resp_buf_type, timeout, &rsp_iov); |
| 2654 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)rsp_iov.iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2655 | } |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2656 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2657 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2658 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2659 | cifs_dbg(FYI, "Send error in Posix Lock = %d\n", rc); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2660 | } else if (pLockData) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2661 | /* lock structure can be returned on get */ |
| 2662 | __u16 data_offset; |
| 2663 | __u16 data_count; |
| 2664 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2665 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2666 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2667 | rc = -EIO; /* bad smb */ |
| 2668 | goto plk_err_exit; |
| 2669 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2670 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2671 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2672 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2673 | rc = -EIO; |
| 2674 | goto plk_err_exit; |
| 2675 | } |
| 2676 | parm_data = (struct cifs_posix_lock *) |
| 2677 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2678 | if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2679 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2680 | else { |
| 2681 | if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2682 | cpu_to_le16(CIFS_RDLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2683 | pLockData->fl_type = F_RDLCK; |
| 2684 | else if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2685 | cpu_to_le16(CIFS_WRLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2686 | pLockData->fl_type = F_WRLCK; |
| 2687 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2688 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2689 | pLockData->fl_end = pLockData->fl_start + |
| 2690 | le64_to_cpu(parm_data->length) - 1; |
Benjamin Coddington | 9d5b86a | 2017-07-16 10:28:22 -0400 | [diff] [blame] | 2691 | pLockData->fl_pid = -le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2692 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2693 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2694 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2695 | plk_err_exit: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2696 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2697 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2698 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2699 | since file handle passed in no longer valid */ |
| 2700 | |
| 2701 | return rc; |
| 2702 | } |
| 2703 | |
| 2704 | |
| 2705 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2706 | 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] | 2707 | { |
| 2708 | int rc = 0; |
| 2709 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2710 | cifs_dbg(FYI, "In CIFSSMBClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | |
| 2712 | /* do not retry on dead session on close */ |
| 2713 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2714 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | return 0; |
| 2716 | if (rc) |
| 2717 | return rc; |
| 2718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2720 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2722 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2723 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2724 | cifs_stats_inc(&tcon->stats.cifs_stats.num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2726 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2728 | cifs_dbg(VFS, "Send error in Close = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | } |
| 2730 | } |
| 2731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2733 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | rc = 0; |
| 2735 | |
| 2736 | return rc; |
| 2737 | } |
| 2738 | |
| 2739 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2740 | 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] | 2741 | { |
| 2742 | int rc = 0; |
| 2743 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2744 | cifs_dbg(FYI, "In CIFSSMBFlush\n"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2745 | |
| 2746 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2747 | if (rc) |
| 2748 | return rc; |
| 2749 | |
| 2750 | pSMB->FileID = (__u16) smb_file_id; |
| 2751 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2752 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2753 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2754 | cifs_stats_inc(&tcon->stats.cifs_stats.num_flushes); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2755 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2756 | cifs_dbg(VFS, "Send error in Flush = %d\n", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2757 | |
| 2758 | return rc; |
| 2759 | } |
| 2760 | |
| 2761 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2762 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2763 | const char *from_name, const char *to_name, |
| 2764 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | { |
| 2766 | int rc = 0; |
| 2767 | RENAME_REQ *pSMB = NULL; |
| 2768 | RENAME_RSP *pSMBr = NULL; |
| 2769 | int bytes_returned; |
| 2770 | int name_len, name_len2; |
| 2771 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 2772 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2774 | cifs_dbg(FYI, "In CIFSSMBRename\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | renameRetry: |
| 2776 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2777 | (void **) &pSMBr); |
| 2778 | if (rc) |
| 2779 | return rc; |
| 2780 | |
| 2781 | pSMB->BufferFormat = 0x04; |
| 2782 | pSMB->SearchAttributes = |
| 2783 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2784 | ATTR_DIRECTORY); |
| 2785 | |
| 2786 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2787 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2788 | from_name, PATH_MAX, |
| 2789 | cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | name_len++; /* trailing null */ |
| 2791 | name_len *= 2; |
| 2792 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2793 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2794 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2795 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2796 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2797 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 2798 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2800 | name_len2 *= 2; /* convert to bytes */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2801 | } else { |
| 2802 | name_len = copy_path_name(pSMB->OldFileName, from_name); |
| 2803 | name_len2 = copy_path_name(pSMB->OldFileName+name_len+1, to_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | name_len2++; /* signature byte */ |
| 2806 | } |
| 2807 | |
| 2808 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2809 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | pSMB->ByteCount = cpu_to_le16(count); |
| 2811 | |
| 2812 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2813 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2814 | cifs_stats_inc(&tcon->stats.cifs_stats.num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2815 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2816 | cifs_dbg(FYI, "Send error in rename = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | cifs_buf_release(pSMB); |
| 2819 | |
| 2820 | if (rc == -EAGAIN) |
| 2821 | goto renameRetry; |
| 2822 | |
| 2823 | return rc; |
| 2824 | } |
| 2825 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2826 | int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2827 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2828 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | { |
| 2830 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2831 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2832 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | char *data_offset; |
| 2834 | char dummy_string[30]; |
| 2835 | int rc = 0; |
| 2836 | int bytes_returned = 0; |
| 2837 | int len_of_str; |
| 2838 | __u16 params, param_offset, offset, count, byte_count; |
| 2839 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2840 | cifs_dbg(FYI, "Rename to File by handle\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2842 | (void **) &pSMBr); |
| 2843 | if (rc) |
| 2844 | return rc; |
| 2845 | |
| 2846 | params = 6; |
| 2847 | pSMB->MaxSetupCount = 0; |
| 2848 | pSMB->Reserved = 0; |
| 2849 | pSMB->Flags = 0; |
| 2850 | pSMB->Timeout = 0; |
| 2851 | pSMB->Reserved2 = 0; |
| 2852 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2853 | offset = param_offset + params; |
| 2854 | |
| 2855 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2856 | rename_info = (struct set_file_rename *) data_offset; |
| 2857 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2858 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | pSMB->SetupCount = 1; |
| 2860 | pSMB->Reserved3 = 0; |
| 2861 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2862 | byte_count = 3 /* pad */ + params; |
| 2863 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2864 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2865 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2866 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2867 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2868 | rename_info->overwrite = cpu_to_le32(1); |
| 2869 | rename_info->root_fid = 0; |
| 2870 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2871 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2872 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2873 | len_of_str = |
| 2874 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2875 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2877 | len_of_str = |
| 2878 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2879 | target_name, PATH_MAX, nls_codepage, |
| 2880 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | } |
| 2882 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2883 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | byte_count += count; |
| 2885 | pSMB->DataCount = cpu_to_le16(count); |
| 2886 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2887 | pSMB->Fid = netfid; |
| 2888 | pSMB->InformationLevel = |
| 2889 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2890 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2891 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2893 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2894 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2895 | cifs_stats_inc(&pTcon->stats.cifs_stats.num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2896 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2897 | cifs_dbg(FYI, "Send error in Rename (by file handle) = %d\n", |
| 2898 | rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | cifs_buf_release(pSMB); |
| 2901 | |
| 2902 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2903 | since file handle passed in no longer valid */ |
| 2904 | |
| 2905 | return rc; |
| 2906 | } |
| 2907 | |
| 2908 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2909 | CIFSSMBCopy(const unsigned int xid, struct cifs_tcon *tcon, |
| 2910 | const char *fromName, const __u16 target_tid, const char *toName, |
| 2911 | const int flags, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | { |
| 2913 | int rc = 0; |
| 2914 | COPY_REQ *pSMB = NULL; |
| 2915 | COPY_RSP *pSMBr = NULL; |
| 2916 | int bytes_returned; |
| 2917 | int name_len, name_len2; |
| 2918 | __u16 count; |
| 2919 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2920 | cifs_dbg(FYI, "In CIFSSMBCopy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | copyRetry: |
| 2922 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2923 | (void **) &pSMBr); |
| 2924 | if (rc) |
| 2925 | return rc; |
| 2926 | |
| 2927 | pSMB->BufferFormat = 0x04; |
| 2928 | pSMB->Tid2 = target_tid; |
| 2929 | |
| 2930 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2931 | |
| 2932 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2933 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2934 | fromName, PATH_MAX, nls_codepage, |
| 2935 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | name_len++; /* trailing null */ |
| 2937 | name_len *= 2; |
| 2938 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2939 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2940 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2941 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2942 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2943 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2945 | name_len2 *= 2; /* convert to bytes */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2946 | } else { |
| 2947 | name_len = copy_path_name(pSMB->OldFileName, fromName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2949 | name_len2 = copy_path_name(pSMB->OldFileName+name_len+1, toName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | name_len2++; /* signature byte */ |
| 2951 | } |
| 2952 | |
| 2953 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2954 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | pSMB->ByteCount = cpu_to_le16(count); |
| 2956 | |
| 2957 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2958 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2959 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2960 | cifs_dbg(FYI, "Send error in copy = %d with %d files copied\n", |
| 2961 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2963 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | |
| 2965 | if (rc == -EAGAIN) |
| 2966 | goto copyRetry; |
| 2967 | |
| 2968 | return rc; |
| 2969 | } |
| 2970 | |
| 2971 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2972 | CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | const char *fromName, const char *toName, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2974 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | { |
| 2976 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2977 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2978 | char *data_offset; |
| 2979 | int name_len; |
| 2980 | int name_len_target; |
| 2981 | int rc = 0; |
| 2982 | int bytes_returned = 0; |
| 2983 | __u16 params, param_offset, offset, byte_count; |
| 2984 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2985 | cifs_dbg(FYI, "In Symlink Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | createSymLinkRetry: |
| 2987 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2988 | (void **) &pSMBr); |
| 2989 | if (rc) |
| 2990 | return rc; |
| 2991 | |
| 2992 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2993 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2994 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fromName, |
| 2995 | /* find define for this maxpathcomponent */ |
| 2996 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | name_len++; /* trailing null */ |
| 2998 | name_len *= 2; |
| 2999 | |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3000 | } else { |
| 3001 | name_len = copy_path_name(pSMB->FileName, fromName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | } |
| 3003 | params = 6 + name_len; |
| 3004 | pSMB->MaxSetupCount = 0; |
| 3005 | pSMB->Reserved = 0; |
| 3006 | pSMB->Flags = 0; |
| 3007 | pSMB->Timeout = 0; |
| 3008 | pSMB->Reserved2 = 0; |
| 3009 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3010 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | offset = param_offset + params; |
| 3012 | |
| 3013 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 3014 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3015 | name_len_target = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3016 | cifsConvertToUTF16((__le16 *) data_offset, toName, |
| 3017 | /* find define for this maxpathcomponent */ |
| 3018 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | name_len_target++; /* trailing null */ |
| 3020 | name_len_target *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3021 | } else { |
| 3022 | name_len_target = copy_path_name(data_offset, toName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3026 | /* BB find exact max on data count below from sess */ |
| 3027 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 3028 | pSMB->SetupCount = 1; |
| 3029 | pSMB->Reserved3 = 0; |
| 3030 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3031 | byte_count = 3 /* pad */ + params + name_len_target; |
| 3032 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 3033 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3034 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3035 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3036 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3037 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3038 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 3039 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3040 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3042 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3043 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3044 | cifs_stats_inc(&tcon->stats.cifs_stats.num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3045 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3046 | cifs_dbg(FYI, "Send error in SetPathInfo create symlink = %d\n", |
| 3047 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 3049 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | |
| 3051 | if (rc == -EAGAIN) |
| 3052 | goto createSymLinkRetry; |
| 3053 | |
| 3054 | return rc; |
| 3055 | } |
| 3056 | |
| 3057 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3058 | CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3060 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | { |
| 3062 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 3063 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 3064 | char *data_offset; |
| 3065 | int name_len; |
| 3066 | int name_len_target; |
| 3067 | int rc = 0; |
| 3068 | int bytes_returned = 0; |
| 3069 | __u16 params, param_offset, offset, byte_count; |
| 3070 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3071 | cifs_dbg(FYI, "In Create Hard link Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | createHardLinkRetry: |
| 3073 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3074 | (void **) &pSMBr); |
| 3075 | if (rc) |
| 3076 | return rc; |
| 3077 | |
| 3078 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3079 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 3080 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | name_len++; /* trailing null */ |
| 3082 | name_len *= 2; |
| 3083 | |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3084 | } else { |
| 3085 | name_len = copy_path_name(pSMB->FileName, toName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | } |
| 3087 | params = 6 + name_len; |
| 3088 | pSMB->MaxSetupCount = 0; |
| 3089 | pSMB->Reserved = 0; |
| 3090 | pSMB->Flags = 0; |
| 3091 | pSMB->Timeout = 0; |
| 3092 | pSMB->Reserved2 = 0; |
| 3093 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3094 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | offset = param_offset + params; |
| 3096 | |
| 3097 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 3098 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3099 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3100 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 3101 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | name_len_target++; /* trailing null */ |
| 3103 | name_len_target *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3104 | } else { |
| 3105 | name_len_target = copy_path_name(data_offset, fromName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3109 | /* BB find exact max on data count below from sess*/ |
| 3110 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 3111 | pSMB->SetupCount = 1; |
| 3112 | pSMB->Reserved3 = 0; |
| 3113 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3114 | byte_count = 3 /* pad */ + params + name_len_target; |
| 3115 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3116 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3117 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 3118 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3119 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3120 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3121 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 3122 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3123 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3125 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3126 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3127 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3128 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3129 | cifs_dbg(FYI, "Send error in SetPathInfo (hard link) = %d\n", |
| 3130 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | |
| 3132 | cifs_buf_release(pSMB); |
| 3133 | if (rc == -EAGAIN) |
| 3134 | goto createHardLinkRetry; |
| 3135 | |
| 3136 | return rc; |
| 3137 | } |
| 3138 | |
| 3139 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3140 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3141 | const char *from_name, const char *to_name, |
| 3142 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | { |
| 3144 | int rc = 0; |
| 3145 | NT_RENAME_REQ *pSMB = NULL; |
| 3146 | RENAME_RSP *pSMBr = NULL; |
| 3147 | int bytes_returned; |
| 3148 | int name_len, name_len2; |
| 3149 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 3150 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3152 | cifs_dbg(FYI, "In CIFSCreateHardLink\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | winCreateHardLinkRetry: |
| 3154 | |
| 3155 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 3156 | (void **) &pSMBr); |
| 3157 | if (rc) |
| 3158 | return rc; |
| 3159 | |
| 3160 | pSMB->SearchAttributes = |
| 3161 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3162 | ATTR_DIRECTORY); |
| 3163 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 3164 | pSMB->ClusterCount = 0; |
| 3165 | |
| 3166 | pSMB->BufferFormat = 0x04; |
| 3167 | |
| 3168 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3169 | name_len = |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3170 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, from_name, |
| 3171 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | name_len++; /* trailing null */ |
| 3173 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 3174 | |
| 3175 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 3176 | pSMB->OldFileName[name_len] = 0x04; |
| 3177 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3179 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3180 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 3181 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 3183 | name_len2 *= 2; /* convert to bytes */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3184 | } else { |
| 3185 | name_len = copy_path_name(pSMB->OldFileName, from_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3187 | name_len2 = copy_path_name(pSMB->OldFileName+name_len+1, to_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | name_len2++; /* signature byte */ |
| 3189 | } |
| 3190 | |
| 3191 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3192 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | pSMB->ByteCount = cpu_to_le16(count); |
| 3194 | |
| 3195 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3196 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3197 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3198 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3199 | 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] | 3200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | cifs_buf_release(pSMB); |
| 3202 | if (rc == -EAGAIN) |
| 3203 | goto winCreateHardLinkRetry; |
| 3204 | |
| 3205 | return rc; |
| 3206 | } |
| 3207 | |
| 3208 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3209 | CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3210 | const unsigned char *searchName, char **symlinkinfo, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3211 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | { |
| 3213 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 3214 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3215 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3216 | int rc = 0; |
| 3217 | int bytes_returned; |
| 3218 | int name_len; |
| 3219 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3220 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3222 | cifs_dbg(FYI, "In QPathSymLinkInfo (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | |
| 3224 | querySymLinkRetry: |
| 3225 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3226 | (void **) &pSMBr); |
| 3227 | if (rc) |
| 3228 | return rc; |
| 3229 | |
| 3230 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3231 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3232 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3233 | searchName, PATH_MAX, nls_codepage, |
| 3234 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | name_len++; /* trailing null */ |
| 3236 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3237 | } else { |
| 3238 | name_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3242 | pSMB->TotalDataCount = 0; |
| 3243 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3244 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | pSMB->MaxSetupCount = 0; |
| 3246 | pSMB->Reserved = 0; |
| 3247 | pSMB->Flags = 0; |
| 3248 | pSMB->Timeout = 0; |
| 3249 | pSMB->Reserved2 = 0; |
| 3250 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3251 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | pSMB->DataCount = 0; |
| 3253 | pSMB->DataOffset = 0; |
| 3254 | pSMB->SetupCount = 1; |
| 3255 | pSMB->Reserved3 = 0; |
| 3256 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3257 | byte_count = params + 1 /* pad */ ; |
| 3258 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3259 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3260 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3261 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3262 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3264 | |
| 3265 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3266 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3267 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3268 | cifs_dbg(FYI, "Send error in QuerySymLinkInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | } else { |
| 3270 | /* decode response */ |
| 3271 | |
| 3272 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3274 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3275 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3277 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3278 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3280 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3281 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3282 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3283 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3284 | is_unicode = true; |
| 3285 | else |
| 3286 | is_unicode = false; |
| 3287 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3288 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3289 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3290 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3291 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3292 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | } |
| 3294 | } |
| 3295 | cifs_buf_release(pSMB); |
| 3296 | if (rc == -EAGAIN) |
| 3297 | goto querySymLinkRetry; |
| 3298 | return rc; |
| 3299 | } |
| 3300 | |
Steve French | c52a9554 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3301 | /* |
| 3302 | * Recent Windows versions now create symlinks more frequently |
| 3303 | * and they use the "reparse point" mechanism below. We can of course |
| 3304 | * do symlinks nicely to Samba and other servers which support the |
| 3305 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3306 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3307 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3308 | * In the interim this code has been moved to its own config option so |
| 3309 | * it is not compiled in by default until callers fixed up and more tested. |
| 3310 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | int |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3312 | CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
| 3313 | __u16 fid, char **symlinkinfo, |
| 3314 | const struct nls_table *nls_codepage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | { |
| 3316 | int rc = 0; |
| 3317 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3318 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3319 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3320 | bool is_unicode; |
| 3321 | unsigned int sub_len; |
| 3322 | char *sub_start; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3323 | struct reparse_symlink_data *reparse_buf; |
| 3324 | struct reparse_posix_data *posix_buf; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3325 | __u32 data_offset, data_count; |
| 3326 | char *end_of_smb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3328 | 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] | 3329 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3330 | (void **) &pSMBr); |
| 3331 | if (rc) |
| 3332 | return rc; |
| 3333 | |
| 3334 | pSMB->TotalParameterCount = 0 ; |
| 3335 | pSMB->TotalDataCount = 0; |
| 3336 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3337 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3338 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | pSMB->MaxSetupCount = 4; |
| 3340 | pSMB->Reserved = 0; |
| 3341 | pSMB->ParameterOffset = 0; |
| 3342 | pSMB->DataCount = 0; |
| 3343 | pSMB->DataOffset = 0; |
| 3344 | pSMB->SetupCount = 4; |
| 3345 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3346 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3347 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3348 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3349 | pSMB->IsRootFlag = 0; |
| 3350 | pSMB->Fid = fid; /* file handle always le */ |
| 3351 | pSMB->ByteCount = 0; |
| 3352 | |
| 3353 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3354 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3355 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3356 | cifs_dbg(FYI, "Send error in QueryReparseLinkInfo = %d\n", rc); |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3357 | goto qreparse_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3359 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3360 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3361 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3362 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3363 | /* BB also check enough total bytes returned */ |
| 3364 | rc = -EIO; /* bad smb */ |
| 3365 | goto qreparse_out; |
| 3366 | } |
| 3367 | if (!data_count || (data_count > 2048)) { |
| 3368 | rc = -EIO; |
| 3369 | cifs_dbg(FYI, "Invalid return data count on get reparse info ioctl\n"); |
| 3370 | goto qreparse_out; |
| 3371 | } |
| 3372 | end_of_smb = 2 + get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3373 | reparse_buf = (struct reparse_symlink_data *) |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3374 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
| 3375 | if ((char *)reparse_buf >= end_of_smb) { |
| 3376 | rc = -EIO; |
| 3377 | goto qreparse_out; |
| 3378 | } |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3379 | if (reparse_buf->ReparseTag == cpu_to_le32(IO_REPARSE_TAG_NFS)) { |
| 3380 | cifs_dbg(FYI, "NFS style reparse tag\n"); |
| 3381 | posix_buf = (struct reparse_posix_data *)reparse_buf; |
| 3382 | |
| 3383 | if (posix_buf->InodeType != cpu_to_le64(NFS_SPECFILE_LNK)) { |
| 3384 | cifs_dbg(FYI, "unsupported file type 0x%llx\n", |
| 3385 | le64_to_cpu(posix_buf->InodeType)); |
| 3386 | rc = -EOPNOTSUPP; |
| 3387 | goto qreparse_out; |
| 3388 | } |
| 3389 | is_unicode = true; |
| 3390 | sub_len = le16_to_cpu(reparse_buf->ReparseDataLength); |
| 3391 | if (posix_buf->PathBuffer + sub_len > end_of_smb) { |
| 3392 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3393 | rc = -EIO; |
| 3394 | goto qreparse_out; |
| 3395 | } |
| 3396 | *symlinkinfo = cifs_strndup_from_utf16(posix_buf->PathBuffer, |
| 3397 | sub_len, is_unicode, nls_codepage); |
| 3398 | goto qreparse_out; |
| 3399 | } else if (reparse_buf->ReparseTag != |
| 3400 | cpu_to_le32(IO_REPARSE_TAG_SYMLINK)) { |
| 3401 | rc = -EOPNOTSUPP; |
| 3402 | goto qreparse_out; |
| 3403 | } |
| 3404 | |
| 3405 | /* Reparse tag is NTFS symlink */ |
| 3406 | sub_start = le16_to_cpu(reparse_buf->SubstituteNameOffset) + |
| 3407 | reparse_buf->PathBuffer; |
| 3408 | sub_len = le16_to_cpu(reparse_buf->SubstituteNameLength); |
| 3409 | if (sub_start + sub_len > end_of_smb) { |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3410 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3411 | rc = -EIO; |
| 3412 | goto qreparse_out; |
| 3413 | } |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3414 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3415 | is_unicode = true; |
| 3416 | else |
| 3417 | is_unicode = false; |
| 3418 | |
| 3419 | /* BB FIXME investigate remapping reserved chars here */ |
| 3420 | *symlinkinfo = cifs_strndup_from_utf16(sub_start, sub_len, is_unicode, |
| 3421 | nls_codepage); |
| 3422 | if (!*symlinkinfo) |
| 3423 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3425 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3427 | /* |
| 3428 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3429 | * since file handle passed in no longer valid. |
| 3430 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | return rc; |
| 3432 | } |
| 3433 | |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3434 | int |
| 3435 | CIFSSMB_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 3436 | __u16 fid) |
| 3437 | { |
| 3438 | int rc = 0; |
| 3439 | int bytes_returned; |
| 3440 | struct smb_com_transaction_compr_ioctl_req *pSMB; |
| 3441 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
| 3442 | |
| 3443 | cifs_dbg(FYI, "Set compression for %u\n", fid); |
| 3444 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3445 | (void **) &pSMBr); |
| 3446 | if (rc) |
| 3447 | return rc; |
| 3448 | |
| 3449 | pSMB->compression_state = cpu_to_le16(COMPRESSION_FORMAT_DEFAULT); |
| 3450 | |
| 3451 | pSMB->TotalParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3452 | pSMB->TotalDataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3453 | pSMB->MaxParameterCount = 0; |
| 3454 | pSMB->MaxDataCount = 0; |
| 3455 | pSMB->MaxSetupCount = 4; |
| 3456 | pSMB->Reserved = 0; |
| 3457 | pSMB->ParameterOffset = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3458 | pSMB->DataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3459 | pSMB->DataOffset = |
| 3460 | cpu_to_le32(offsetof(struct smb_com_transaction_compr_ioctl_req, |
| 3461 | compression_state) - 4); /* 84 */ |
| 3462 | pSMB->SetupCount = 4; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3463 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3464 | pSMB->ParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3465 | pSMB->FunctionCode = cpu_to_le32(FSCTL_SET_COMPRESSION); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3466 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3467 | pSMB->IsRootFlag = 0; |
| 3468 | pSMB->Fid = fid; /* file handle always le */ |
| 3469 | /* 3 byte pad, followed by 2 byte compress state */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3470 | pSMB->ByteCount = cpu_to_le16(5); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3471 | inc_rfc1001_len(pSMB, 5); |
| 3472 | |
| 3473 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3474 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3475 | if (rc) |
| 3476 | cifs_dbg(FYI, "Send error in SetCompression = %d\n", rc); |
| 3477 | |
| 3478 | cifs_buf_release(pSMB); |
| 3479 | |
| 3480 | /* |
| 3481 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3482 | * since file handle passed in no longer valid. |
| 3483 | */ |
| 3484 | return rc; |
| 3485 | } |
| 3486 | |
| 3487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | #ifdef CONFIG_CIFS_POSIX |
| 3489 | |
| 3490 | /*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] | 3491 | static void cifs_convert_ace(struct posix_acl_xattr_entry *ace, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3492 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | { |
| 3494 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3495 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3496 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3497 | 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] | 3498 | /* |
| 3499 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3500 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3501 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | |
| 3503 | return; |
| 3504 | } |
| 3505 | |
| 3506 | /* 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] | 3507 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3508 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | { |
| 3510 | int size = 0; |
| 3511 | int i; |
| 3512 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3513 | struct cifs_posix_ace *pACE; |
| 3514 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3515 | struct posix_acl_xattr_header *local_acl = (void *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | |
| 3517 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3518 | return -EOPNOTSUPP; |
| 3519 | |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3520 | if (acl_type == ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3522 | pACE = &cifs_acl->ace_array[0]; |
| 3523 | size = sizeof(struct cifs_posix_acl); |
| 3524 | size += sizeof(struct cifs_posix_ace) * count; |
| 3525 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3526 | if (size_of_data_area < size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3527 | cifs_dbg(FYI, "bad CIFS POSIX ACL size %d vs. %d\n", |
| 3528 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | return -EINVAL; |
| 3530 | } |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3531 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3533 | size = sizeof(struct cifs_posix_acl); |
| 3534 | size += sizeof(struct cifs_posix_ace) * count; |
| 3535 | /* skip past access ACEs to get to default ACEs */ |
| 3536 | pACE = &cifs_acl->ace_array[count]; |
| 3537 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3538 | size += sizeof(struct cifs_posix_ace) * count; |
| 3539 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3540 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | return -EINVAL; |
| 3542 | } else { |
| 3543 | /* illegal type */ |
| 3544 | return -EINVAL; |
| 3545 | } |
| 3546 | |
| 3547 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3548 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3549 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3550 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | return -ERANGE; |
| 3552 | } else /* buffer big enough */ { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3553 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
| 3554 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3555 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3556 | for (i = 0; i < count ; i++) { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3557 | cifs_convert_ace(&ace[i], pACE); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3558 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | } |
| 3560 | } |
| 3561 | return size; |
| 3562 | } |
| 3563 | |
Hariprasad Kelam | 0aa3a24 | 2019-07-02 23:50:02 +0530 | [diff] [blame] | 3564 | 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] | 3565 | const struct posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3567 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3568 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3570 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3572 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3573 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3574 | 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] | 3575 | /* |
| 3576 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3577 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3578 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | /* 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] | 3582 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3583 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | { |
| 3585 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3586 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3587 | struct posix_acl_xattr_header *local_acl = (void *)pACL; |
Eryu Guan | ae9ebe7 | 2016-10-24 20:46:40 +0800 | [diff] [blame] | 3588 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | int count; |
| 3590 | int i; |
| 3591 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3592 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | return 0; |
| 3594 | |
| 3595 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3596 | cifs_dbg(FYI, "setting acl with %d entries from buf of length %d and version of %d\n", |
| 3597 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3598 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3599 | cifs_dbg(FYI, "unknown POSIX ACL version %d\n", |
| 3600 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | return 0; |
| 3602 | } |
| 3603 | cifs_acl->version = cpu_to_le16(1); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3604 | if (acl_type == ACL_TYPE_ACCESS) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3605 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3606 | cifs_acl->default_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3607 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3608 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3609 | cifs_acl->access_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3610 | } else { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3611 | cifs_dbg(FYI, "unknown ACL type %d\n", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | return 0; |
| 3613 | } |
Hariprasad Kelam | 0aa3a24 | 2019-07-02 23:50:02 +0530 | [diff] [blame] | 3614 | for (i = 0; i < count; i++) |
| 3615 | convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], &ace[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3616 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3618 | rc += sizeof(struct cifs_posix_acl); |
| 3619 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3620 | } |
| 3621 | return rc; |
| 3622 | } |
| 3623 | |
| 3624 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3625 | CIFSSMBGetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3626 | const unsigned char *searchName, |
| 3627 | char *acl_inf, const int buflen, const int acl_type, |
| 3628 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | { |
| 3630 | /* SMB_QUERY_POSIX_ACL */ |
| 3631 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3632 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3633 | int rc = 0; |
| 3634 | int bytes_returned; |
| 3635 | int name_len; |
| 3636 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3637 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3638 | cifs_dbg(FYI, "In GetPosixACL (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | |
| 3640 | queryAclRetry: |
| 3641 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3642 | (void **) &pSMBr); |
| 3643 | if (rc) |
| 3644 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3647 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3648 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3649 | searchName, PATH_MAX, nls_codepage, |
| 3650 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | name_len++; /* trailing null */ |
| 3652 | name_len *= 2; |
| 3653 | pSMB->FileName[name_len] = 0; |
| 3654 | pSMB->FileName[name_len+1] = 0; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3655 | } else { |
| 3656 | name_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3660 | pSMB->TotalDataCount = 0; |
| 3661 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3662 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3664 | pSMB->MaxSetupCount = 0; |
| 3665 | pSMB->Reserved = 0; |
| 3666 | pSMB->Flags = 0; |
| 3667 | pSMB->Timeout = 0; |
| 3668 | pSMB->Reserved2 = 0; |
| 3669 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3670 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3671 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | pSMB->DataCount = 0; |
| 3673 | pSMB->DataOffset = 0; |
| 3674 | pSMB->SetupCount = 1; |
| 3675 | pSMB->Reserved3 = 0; |
| 3676 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3677 | byte_count = params + 1 /* pad */ ; |
| 3678 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3679 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3680 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3681 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3682 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3684 | |
| 3685 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3686 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3687 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3689 | cifs_dbg(FYI, "Send error in Query POSIX ACL = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | } else { |
| 3691 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3695 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | rc = -EIO; /* bad smb */ |
| 3697 | else { |
| 3698 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3699 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3700 | rc = cifs_copy_posix_acl(acl_inf, |
| 3701 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3702 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | cifs_buf_release(pSMB); |
| 3706 | if (rc == -EAGAIN) |
| 3707 | goto queryAclRetry; |
| 3708 | return rc; |
| 3709 | } |
| 3710 | |
| 3711 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3712 | CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3713 | const unsigned char *fileName, |
| 3714 | const char *local_acl, const int buflen, |
| 3715 | const int acl_type, |
| 3716 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | { |
| 3718 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3719 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3720 | char *parm_data; |
| 3721 | int name_len; |
| 3722 | int rc = 0; |
| 3723 | int bytes_returned = 0; |
| 3724 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3725 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3726 | cifs_dbg(FYI, "In SetPosixACL (Unix) for path %s\n", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | setAclRetry: |
| 3728 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3729 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | if (rc) |
| 3731 | return rc; |
| 3732 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3733 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3734 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3735 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | name_len++; /* trailing null */ |
| 3737 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3738 | } else { |
| 3739 | name_len = copy_path_name(pSMB->FileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | } |
| 3741 | params = 6 + name_len; |
| 3742 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3743 | /* BB find max SMB size from sess */ |
| 3744 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | pSMB->MaxSetupCount = 0; |
| 3746 | pSMB->Reserved = 0; |
| 3747 | pSMB->Flags = 0; |
| 3748 | pSMB->Timeout = 0; |
| 3749 | pSMB->Reserved2 = 0; |
| 3750 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3751 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | offset = param_offset + params; |
| 3753 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3754 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3755 | |
| 3756 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3757 | 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] | 3758 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3759 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | rc = -EOPNOTSUPP; |
| 3761 | goto setACLerrorExit; |
| 3762 | } |
| 3763 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3764 | pSMB->SetupCount = 1; |
| 3765 | pSMB->Reserved3 = 0; |
| 3766 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3767 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3768 | byte_count = 3 /* pad */ + params + data_count; |
| 3769 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3770 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3771 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3772 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3773 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3774 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3776 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3777 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3778 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3779 | cifs_dbg(FYI, "Set POSIX ACL returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | |
| 3781 | setACLerrorExit: |
| 3782 | cifs_buf_release(pSMB); |
| 3783 | if (rc == -EAGAIN) |
| 3784 | goto setAclRetry; |
| 3785 | return rc; |
| 3786 | } |
| 3787 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3788 | /* BB fix tabs in this function FIXME BB */ |
| 3789 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3790 | CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3791 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3792 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3793 | int rc = 0; |
| 3794 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3795 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3796 | int bytes_returned; |
| 3797 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3798 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3799 | cifs_dbg(FYI, "In GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3800 | if (tcon == NULL) |
| 3801 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3802 | |
| 3803 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3804 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3805 | (void **) &pSMBr); |
| 3806 | if (rc) |
| 3807 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3808 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3809 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3810 | pSMB->t2.TotalDataCount = 0; |
| 3811 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3812 | /* BB find exact max data count below from sess structure BB */ |
| 3813 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3814 | pSMB->t2.MaxSetupCount = 0; |
| 3815 | pSMB->t2.Reserved = 0; |
| 3816 | pSMB->t2.Flags = 0; |
| 3817 | pSMB->t2.Timeout = 0; |
| 3818 | pSMB->t2.Reserved2 = 0; |
| 3819 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3820 | Fid) - 4); |
| 3821 | pSMB->t2.DataCount = 0; |
| 3822 | pSMB->t2.DataOffset = 0; |
| 3823 | pSMB->t2.SetupCount = 1; |
| 3824 | pSMB->t2.Reserved3 = 0; |
| 3825 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3826 | byte_count = params + 1 /* pad */ ; |
| 3827 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3828 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3829 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3830 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3831 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3832 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3833 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3834 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3835 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3836 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3837 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3838 | cifs_dbg(FYI, "error %d in GetExtAttr\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3839 | } else { |
| 3840 | /* decode response */ |
| 3841 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3842 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3843 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3844 | /* If rc should we check for EOPNOSUPP and |
| 3845 | disable the srvino flag? or in caller? */ |
| 3846 | rc = -EIO; /* bad smb */ |
| 3847 | else { |
| 3848 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3849 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3850 | struct file_chattr_info *pfinfo; |
| 3851 | /* BB Do we need a cast or hash here ? */ |
| 3852 | if (count != 16) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3853 | cifs_dbg(FYI, "Illegal size ret in GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3854 | rc = -EIO; |
| 3855 | goto GetExtAttrOut; |
| 3856 | } |
| 3857 | pfinfo = (struct file_chattr_info *) |
| 3858 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3859 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3860 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3861 | } |
| 3862 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3863 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3864 | cifs_buf_release(pSMB); |
| 3865 | if (rc == -EAGAIN) |
| 3866 | goto GetExtAttrRetry; |
| 3867 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3868 | } |
| 3869 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3870 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3872 | /* |
| 3873 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3874 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3875 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3876 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3877 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3878 | * by caller |
| 3879 | */ |
| 3880 | static int |
| 3881 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3882 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3883 | void **ret_buf) |
| 3884 | { |
| 3885 | int rc; |
| 3886 | __u32 temp_offset; |
| 3887 | struct smb_com_ntransact_req *pSMB; |
| 3888 | |
| 3889 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3890 | (void **)&pSMB); |
| 3891 | if (rc) |
| 3892 | return rc; |
| 3893 | *ret_buf = (void *)pSMB; |
| 3894 | pSMB->Reserved = 0; |
| 3895 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3896 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3897 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3898 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3899 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3900 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3901 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3902 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3903 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3904 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3905 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3906 | return 0; |
| 3907 | } |
| 3908 | |
| 3909 | static int |
| 3910 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3911 | __u32 *pparmlen, __u32 *pdatalen) |
| 3912 | { |
| 3913 | char *end_of_smb; |
| 3914 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3915 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3916 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3917 | |
| 3918 | *pdatalen = 0; |
| 3919 | *pparmlen = 0; |
| 3920 | |
| 3921 | if (buf == NULL) |
| 3922 | return -EINVAL; |
| 3923 | |
| 3924 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3925 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3926 | bcc = get_bcc(&pSMBr->hdr); |
| 3927 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3928 | (char *)&pSMBr->ByteCount; |
| 3929 | |
| 3930 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3931 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3932 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3933 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3934 | |
| 3935 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3936 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3937 | |
| 3938 | /* should we also check that parm and data areas do not overlap? */ |
| 3939 | if (*ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3940 | cifs_dbg(FYI, "parms start after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3941 | return -EINVAL; |
| 3942 | } else if (parm_count + *ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3943 | cifs_dbg(FYI, "parm end after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3944 | return -EINVAL; |
| 3945 | } else if (*ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3946 | cifs_dbg(FYI, "data starts after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3947 | return -EINVAL; |
| 3948 | } else if (data_count + *ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3949 | cifs_dbg(FYI, "data %p + count %d (%p) past smb end %p start %p\n", |
| 3950 | *ppdata, data_count, (data_count + *ppdata), |
| 3951 | end_of_smb, pSMBr); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3952 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3953 | } else if (parm_count + data_count > bcc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3954 | cifs_dbg(FYI, "parm count and data count larger than SMB\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3955 | return -EINVAL; |
| 3956 | } |
| 3957 | *pdatalen = data_count; |
| 3958 | *pparmlen = parm_count; |
| 3959 | return 0; |
| 3960 | } |
| 3961 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3962 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3963 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3964 | CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3965 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3966 | { |
| 3967 | int rc = 0; |
| 3968 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3969 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3970 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3971 | struct kvec rsp_iov; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3972 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3973 | cifs_dbg(FYI, "GetCifsACL\n"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3974 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3975 | *pbuflen = 0; |
| 3976 | *acl_inf = NULL; |
| 3977 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3978 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3979 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3980 | if (rc) |
| 3981 | return rc; |
| 3982 | |
| 3983 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3984 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3985 | pSMB->MaxSetupCount = 0; |
| 3986 | pSMB->Fid = fid; /* file handle always le */ |
| 3987 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3988 | CIFS_ACL_DACL); |
| 3989 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3990 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3991 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3992 | 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] | 3993 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3994 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3995 | 0, &rsp_iov); |
| 3996 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3997 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3998 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3999 | cifs_dbg(FYI, "Send error in QuerySecDesc = %d\n", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4000 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4001 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4002 | __u32 parm_len; |
| 4003 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4004 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4005 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4006 | |
| 4007 | /* validate_nttransact */ |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4008 | rc = validate_ntransact(rsp_iov.iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4009 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4010 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4011 | goto qsec_out; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4012 | pSMBr = (struct smb_com_ntransact_rsp *)rsp_iov.iov_base; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4013 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4014 | cifs_dbg(FYI, "smb %p parm %p data %p\n", |
| 4015 | pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4016 | |
| 4017 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 4018 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4019 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4020 | goto qsec_out; |
| 4021 | } |
| 4022 | |
| 4023 | /* BB check that data area is minimum length and as big as acl_len */ |
| 4024 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 4025 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4026 | if (acl_len != *pbuflen) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4027 | cifs_dbg(VFS, "acl length %d does not match %d\n", |
| 4028 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4029 | if (*pbuflen > acl_len) |
| 4030 | *pbuflen = acl_len; |
| 4031 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4032 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4033 | /* check if buffer is big enough for the acl |
| 4034 | header followed by the smallest SID */ |
| 4035 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 4036 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4037 | cifs_dbg(VFS, "bad acl length %d\n", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4038 | rc = -EINVAL; |
| 4039 | *pbuflen = 0; |
| 4040 | } else { |
Silviu-Mihai Popescu | f7f7c18 | 2013-03-11 18:22:32 +0200 | [diff] [blame] | 4041 | *acl_inf = kmemdup(pdata, *pbuflen, GFP_KERNEL); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4042 | if (*acl_inf == NULL) { |
| 4043 | *pbuflen = 0; |
| 4044 | rc = -ENOMEM; |
| 4045 | } |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4046 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4047 | } |
| 4048 | qsec_out: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4049 | free_rsp_buf(buf_type, rsp_iov.iov_base); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4050 | return rc; |
| 4051 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4052 | |
| 4053 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4054 | CIFSSMBSetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 4055 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4056 | { |
| 4057 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 4058 | int rc = 0; |
| 4059 | int bytes_returned = 0; |
| 4060 | SET_SEC_DESC_REQ *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 4061 | void *pSMBr; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4062 | |
| 4063 | setCifsAclRetry: |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 4064 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4065 | if (rc) |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 4066 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4067 | |
| 4068 | pSMB->MaxSetupCount = 0; |
| 4069 | pSMB->Reserved = 0; |
| 4070 | |
| 4071 | param_count = 8; |
| 4072 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 4073 | data_count = acllen; |
| 4074 | data_offset = param_offset + param_count; |
| 4075 | byte_count = 3 /* pad */ + param_count; |
| 4076 | |
| 4077 | pSMB->DataCount = cpu_to_le32(data_count); |
| 4078 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4079 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 4080 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 4081 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 4082 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 4083 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4084 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 4085 | pSMB->SetupCount = 0; |
| 4086 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 4087 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 4088 | |
| 4089 | pSMB->Fid = fid; /* file handle always le */ |
| 4090 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 4091 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4092 | |
| 4093 | if (pntsd && acllen) { |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 4094 | memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + |
| 4095 | data_offset, pntsd, acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4096 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4097 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4098 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4099 | |
| 4100 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4101 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4102 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4103 | cifs_dbg(FYI, "SetCIFSACL bytes_returned: %d, rc: %d\n", |
| 4104 | bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4105 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4106 | cifs_dbg(FYI, "Set CIFS ACL returned %d\n", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4107 | cifs_buf_release(pSMB); |
| 4108 | |
| 4109 | if (rc == -EAGAIN) |
| 4110 | goto setCifsAclRetry; |
| 4111 | |
| 4112 | return (rc); |
| 4113 | } |
| 4114 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4115 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4116 | /* Legacy Query Path Information call for lookup to old servers such |
| 4117 | as Win9x/WinME */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4118 | int |
| 4119 | SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, |
| 4120 | const char *search_name, FILE_ALL_INFO *data, |
| 4121 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4122 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4123 | QUERY_INFORMATION_REQ *pSMB; |
| 4124 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4125 | int rc = 0; |
| 4126 | int bytes_returned; |
| 4127 | int name_len; |
| 4128 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4129 | cifs_dbg(FYI, "In SMBQPath path %s\n", search_name); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4130 | QInfRetry: |
| 4131 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4132 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4133 | if (rc) |
| 4134 | return rc; |
| 4135 | |
| 4136 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4137 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4138 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4139 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4140 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4141 | name_len++; /* trailing null */ |
| 4142 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4143 | } else { |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4144 | name_len = copy_path_name(pSMB->FileName, search_name); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4145 | } |
| 4146 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4147 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4148 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4149 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 4150 | |
| 4151 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4152 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4153 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4154 | cifs_dbg(FYI, "Send error in QueryInfo = %d\n", rc); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4155 | } else if (data) { |
Arnd Bergmann | 9539020 | 2018-06-19 17:27:58 +0200 | [diff] [blame] | 4156 | struct timespec64 ts; |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4157 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4158 | |
| 4159 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4160 | /* BB FIXME - add time zone adjustment BB */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4161 | memset(data, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4162 | ts.tv_nsec = 0; |
| 4163 | ts.tv_sec = time; |
| 4164 | /* decode time fields */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4165 | data->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
| 4166 | data->LastWriteTime = data->ChangeTime; |
| 4167 | data->LastAccessTime = 0; |
| 4168 | data->AllocationSize = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4169 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4170 | data->EndOfFile = data->AllocationSize; |
| 4171 | data->Attributes = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4172 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4173 | } else |
| 4174 | rc = -EIO; /* bad buffer passed in */ |
| 4175 | |
| 4176 | cifs_buf_release(pSMB); |
| 4177 | |
| 4178 | if (rc == -EAGAIN) |
| 4179 | goto QInfRetry; |
| 4180 | |
| 4181 | return rc; |
| 4182 | } |
| 4183 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4184 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4185 | CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4186 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 4187 | { |
| 4188 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4189 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4190 | int rc = 0; |
| 4191 | int bytes_returned; |
| 4192 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4193 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4194 | QFileInfoRetry: |
| 4195 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4196 | (void **) &pSMBr); |
| 4197 | if (rc) |
| 4198 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4199 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4200 | params = 2 /* level */ + 2 /* fid */; |
| 4201 | pSMB->t2.TotalDataCount = 0; |
| 4202 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4203 | /* BB find exact max data count below from sess structure BB */ |
| 4204 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4205 | pSMB->t2.MaxSetupCount = 0; |
| 4206 | pSMB->t2.Reserved = 0; |
| 4207 | pSMB->t2.Flags = 0; |
| 4208 | pSMB->t2.Timeout = 0; |
| 4209 | pSMB->t2.Reserved2 = 0; |
| 4210 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4211 | Fid) - 4); |
| 4212 | pSMB->t2.DataCount = 0; |
| 4213 | pSMB->t2.DataOffset = 0; |
| 4214 | pSMB->t2.SetupCount = 1; |
| 4215 | pSMB->t2.Reserved3 = 0; |
| 4216 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4217 | byte_count = params + 1 /* pad */ ; |
| 4218 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4219 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4220 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 4221 | pSMB->Pad = 0; |
| 4222 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4223 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4224 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4225 | |
| 4226 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4227 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4228 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4229 | cifs_dbg(FYI, "Send error in QFileInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4230 | } else { /* decode response */ |
| 4231 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4232 | |
| 4233 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4234 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4235 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4236 | rc = -EIO; /* bad smb */ |
| 4237 | else if (pFindData) { |
| 4238 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4239 | memcpy((char *) pFindData, |
| 4240 | (char *) &pSMBr->hdr.Protocol + |
| 4241 | data_offset, sizeof(FILE_ALL_INFO)); |
| 4242 | } else |
| 4243 | rc = -ENOMEM; |
| 4244 | } |
| 4245 | cifs_buf_release(pSMB); |
| 4246 | if (rc == -EAGAIN) |
| 4247 | goto QFileInfoRetry; |
| 4248 | |
| 4249 | return rc; |
| 4250 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4253 | CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4254 | const char *search_name, FILE_ALL_INFO *data, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4255 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4256 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | { |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4258 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4260 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4261 | int rc = 0; |
| 4262 | int bytes_returned; |
| 4263 | int name_len; |
| 4264 | __u16 params, byte_count; |
| 4265 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4266 | /* cifs_dbg(FYI, "In QPathInfo path %s\n", search_name); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | QPathInfoRetry: |
| 4268 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4269 | (void **) &pSMBr); |
| 4270 | if (rc) |
| 4271 | return rc; |
| 4272 | |
| 4273 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4274 | name_len = |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4275 | cifsConvertToUTF16((__le16 *) pSMB->FileName, search_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4276 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | name_len++; /* trailing null */ |
| 4278 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4279 | } else { |
| 4280 | name_len = copy_path_name(pSMB->FileName, search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | } |
| 4282 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4283 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | pSMB->TotalDataCount = 0; |
| 4285 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4286 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4287 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | pSMB->MaxSetupCount = 0; |
| 4289 | pSMB->Reserved = 0; |
| 4290 | pSMB->Flags = 0; |
| 4291 | pSMB->Timeout = 0; |
| 4292 | pSMB->Reserved2 = 0; |
| 4293 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4294 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | pSMB->DataCount = 0; |
| 4296 | pSMB->DataOffset = 0; |
| 4297 | pSMB->SetupCount = 1; |
| 4298 | pSMB->Reserved3 = 0; |
| 4299 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4300 | byte_count = params + 1 /* pad */ ; |
| 4301 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4302 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4303 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4304 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4305 | else |
| 4306 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4308 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4310 | |
| 4311 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4312 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4313 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4314 | cifs_dbg(FYI, "Send error in QPathInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | } else { /* decode response */ |
| 4316 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4317 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4318 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4319 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4320 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4322 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4323 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4324 | last field */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4325 | else if (data) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4326 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4328 | |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4329 | /* |
| 4330 | * On legacy responses we do not read the last field, |
| 4331 | * EAsize, fortunately since it varies by subdialect and |
| 4332 | * also note it differs on Set vs Get, ie two bytes or 4 |
| 4333 | * bytes depending but we don't care here. |
| 4334 | */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4335 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4336 | size = sizeof(FILE_INFO_STANDARD); |
| 4337 | else |
| 4338 | size = sizeof(FILE_ALL_INFO); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4339 | memcpy((char *) data, (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4340 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | } else |
| 4342 | rc = -ENOMEM; |
| 4343 | } |
| 4344 | cifs_buf_release(pSMB); |
| 4345 | if (rc == -EAGAIN) |
| 4346 | goto QPathInfoRetry; |
| 4347 | |
| 4348 | return rc; |
| 4349 | } |
| 4350 | |
| 4351 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4352 | CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4353 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4354 | { |
| 4355 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4356 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4357 | int rc = 0; |
| 4358 | int bytes_returned; |
| 4359 | __u16 params, byte_count; |
| 4360 | |
| 4361 | UnixQFileInfoRetry: |
| 4362 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4363 | (void **) &pSMBr); |
| 4364 | if (rc) |
| 4365 | return rc; |
| 4366 | |
| 4367 | params = 2 /* level */ + 2 /* fid */; |
| 4368 | pSMB->t2.TotalDataCount = 0; |
| 4369 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4370 | /* BB find exact max data count below from sess structure BB */ |
| 4371 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4372 | pSMB->t2.MaxSetupCount = 0; |
| 4373 | pSMB->t2.Reserved = 0; |
| 4374 | pSMB->t2.Flags = 0; |
| 4375 | pSMB->t2.Timeout = 0; |
| 4376 | pSMB->t2.Reserved2 = 0; |
| 4377 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4378 | Fid) - 4); |
| 4379 | pSMB->t2.DataCount = 0; |
| 4380 | pSMB->t2.DataOffset = 0; |
| 4381 | pSMB->t2.SetupCount = 1; |
| 4382 | pSMB->t2.Reserved3 = 0; |
| 4383 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4384 | byte_count = params + 1 /* pad */ ; |
| 4385 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4386 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4387 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4388 | pSMB->Pad = 0; |
| 4389 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4390 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4391 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4392 | |
| 4393 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4394 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4395 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4396 | cifs_dbg(FYI, "Send error in UnixQFileInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4397 | } else { /* decode response */ |
| 4398 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4399 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4400 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4401 | 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] | 4402 | rc = -EIO; /* bad smb */ |
| 4403 | } else { |
| 4404 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4405 | memcpy((char *) pFindData, |
| 4406 | (char *) &pSMBr->hdr.Protocol + |
| 4407 | data_offset, |
| 4408 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | cifs_buf_release(pSMB); |
| 4413 | if (rc == -EAGAIN) |
| 4414 | goto UnixQFileInfoRetry; |
| 4415 | |
| 4416 | return rc; |
| 4417 | } |
| 4418 | |
| 4419 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4420 | CIFSSMBUnixQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4422 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4423 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | { |
| 4425 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4426 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4427 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4428 | int rc = 0; |
| 4429 | int bytes_returned = 0; |
| 4430 | int name_len; |
| 4431 | __u16 params, byte_count; |
| 4432 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4433 | cifs_dbg(FYI, "In QPathInfo (Unix) the path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | UnixQPathInfoRetry: |
| 4435 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4436 | (void **) &pSMBr); |
| 4437 | if (rc) |
| 4438 | return rc; |
| 4439 | |
| 4440 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4441 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4442 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4443 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | name_len++; /* trailing null */ |
| 4445 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4446 | } else { |
| 4447 | name_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4450 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | pSMB->TotalDataCount = 0; |
| 4452 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4453 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4454 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | pSMB->MaxSetupCount = 0; |
| 4456 | pSMB->Reserved = 0; |
| 4457 | pSMB->Flags = 0; |
| 4458 | pSMB->Timeout = 0; |
| 4459 | pSMB->Reserved2 = 0; |
| 4460 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4461 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | pSMB->DataCount = 0; |
| 4463 | pSMB->DataOffset = 0; |
| 4464 | pSMB->SetupCount = 1; |
| 4465 | pSMB->Reserved3 = 0; |
| 4466 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4467 | byte_count = params + 1 /* pad */ ; |
| 4468 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4469 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4470 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4471 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4472 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4474 | |
| 4475 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4476 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4477 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4478 | cifs_dbg(FYI, "Send error in UnixQPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | } else { /* decode response */ |
| 4480 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4481 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4482 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4483 | 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] | 4484 | rc = -EIO; /* bad smb */ |
| 4485 | } else { |
| 4486 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4487 | memcpy((char *) pFindData, |
| 4488 | (char *) &pSMBr->hdr.Protocol + |
| 4489 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4490 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | } |
| 4492 | } |
| 4493 | cifs_buf_release(pSMB); |
| 4494 | if (rc == -EAGAIN) |
| 4495 | goto UnixQPathInfoRetry; |
| 4496 | |
| 4497 | return rc; |
| 4498 | } |
| 4499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4501 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4502 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4503 | const char *searchName, struct cifs_sb_info *cifs_sb, |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4504 | __u16 *pnetfid, __u16 search_flags, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4505 | struct cifs_search_info *psrch_inf, bool msearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | { |
| 4507 | /* level 257 SMB_ */ |
| 4508 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4509 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4510 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | int rc = 0; |
| 4512 | int bytes_returned = 0; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4513 | int name_len, remap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | __u16 params, byte_count; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4515 | struct nls_table *nls_codepage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4517 | cifs_dbg(FYI, "In FindFirst for %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | |
| 4519 | findFirstRetry: |
| 4520 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4521 | (void **) &pSMBr); |
| 4522 | if (rc) |
| 4523 | return rc; |
| 4524 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4525 | nls_codepage = cifs_sb->local_nls; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 4526 | remap = cifs_remap(cifs_sb); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4529 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4530 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4531 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4532 | /* We can not add the asterik earlier in case |
| 4533 | it got remapped to 0xF03A as if it were part of the |
| 4534 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | name_len *= 2; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4536 | if (msearch) { |
| 4537 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
| 4538 | pSMB->FileName[name_len+1] = 0; |
| 4539 | pSMB->FileName[name_len+2] = '*'; |
| 4540 | pSMB->FileName[name_len+3] = 0; |
| 4541 | name_len += 4; /* now the trailing null */ |
| 4542 | /* null terminate just in case */ |
| 4543 | pSMB->FileName[name_len] = 0; |
| 4544 | pSMB->FileName[name_len+1] = 0; |
| 4545 | name_len += 2; |
| 4546 | } |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4547 | } else { |
| 4548 | name_len = copy_path_name(pSMB->FileName, searchName); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4549 | if (msearch) { |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4550 | if (WARN_ON_ONCE(name_len > PATH_MAX-2)) |
| 4551 | name_len = PATH_MAX-2; |
| 4552 | /* overwrite nul byte */ |
| 4553 | pSMB->FileName[name_len-1] = CIFS_DIR_SEP(cifs_sb); |
| 4554 | pSMB->FileName[name_len] = '*'; |
| 4555 | pSMB->FileName[name_len+1] = 0; |
| 4556 | name_len += 2; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4557 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | params = 12 + name_len /* includes null */ ; |
| 4561 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4562 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4563 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | pSMB->MaxSetupCount = 0; |
| 4565 | pSMB->Reserved = 0; |
| 4566 | pSMB->Flags = 0; |
| 4567 | pSMB->Timeout = 0; |
| 4568 | pSMB->Reserved2 = 0; |
| 4569 | byte_count = params + 1 /* pad */ ; |
| 4570 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4571 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4572 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4573 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4574 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | pSMB->DataCount = 0; |
| 4576 | pSMB->DataOffset = 0; |
| 4577 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4578 | pSMB->Reserved3 = 0; |
| 4579 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4580 | pSMB->SearchAttributes = |
| 4581 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4582 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4583 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4584 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4586 | |
| 4587 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4588 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4589 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4591 | |
| 4592 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4593 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4594 | cifs_stats_inc(&tcon->stats.cifs_stats.num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4596 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4597 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4599 | cifs_dbg(FYI, "Error in FindFirst = %d\n", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4600 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4601 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | |
| 4603 | /* BB eventually could optimize out free and realloc of buf */ |
| 4604 | /* for this case */ |
| 4605 | if (rc == -EAGAIN) |
| 4606 | goto findFirstRetry; |
| 4607 | } else { /* decode response */ |
| 4608 | /* BB remember to free buffer if error BB */ |
| 4609 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4610 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4611 | unsigned int lnoff; |
| 4612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4614 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4616 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | |
| 4618 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4619 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4620 | psrch_inf->srch_entries_start = |
| 4621 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4624 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4625 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4626 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4627 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4629 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4630 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4631 | psrch_inf->entries_in_buffer = |
| 4632 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4633 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4635 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4636 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4637 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4638 | psrch_inf->last_entry = NULL; |
| 4639 | return rc; |
| 4640 | } |
| 4641 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4642 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4643 | lnoff; |
| 4644 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4645 | if (pnetfid) |
| 4646 | *pnetfid = parms->SearchHandle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | } else { |
| 4648 | cifs_buf_release(pSMB); |
| 4649 | } |
| 4650 | } |
| 4651 | |
| 4652 | return rc; |
| 4653 | } |
| 4654 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4655 | int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, |
| 4656 | __u16 searchHandle, __u16 search_flags, |
| 4657 | struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | { |
| 4659 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4660 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4661 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | char *response_data; |
| 4663 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4664 | int bytes_returned; |
| 4665 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | __u16 params, byte_count; |
| 4667 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4668 | cifs_dbg(FYI, "In FindNext\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4670 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | return -ENOENT; |
| 4672 | |
| 4673 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4674 | (void **) &pSMBr); |
| 4675 | if (rc) |
| 4676 | return rc; |
| 4677 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4678 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | byte_count = 0; |
| 4680 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4681 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4682 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4683 | pSMB->MaxSetupCount = 0; |
| 4684 | pSMB->Reserved = 0; |
| 4685 | pSMB->Flags = 0; |
| 4686 | pSMB->Timeout = 0; |
| 4687 | pSMB->Reserved2 = 0; |
| 4688 | pSMB->ParameterOffset = cpu_to_le16( |
| 4689 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4690 | pSMB->DataCount = 0; |
| 4691 | pSMB->DataOffset = 0; |
| 4692 | pSMB->SetupCount = 1; |
| 4693 | pSMB->Reserved3 = 0; |
| 4694 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4695 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4696 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4697 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4699 | pSMB->ResumeKey = psrch_inf->resume_key; |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4700 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | |
| 4702 | name_len = psrch_inf->resume_name_len; |
| 4703 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4704 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4706 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4707 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4708 | pSMB->ResumeFileName[name_len] = 0; |
| 4709 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | } else { |
| 4711 | rc = -EINVAL; |
| 4712 | goto FNext2_err_exit; |
| 4713 | } |
| 4714 | byte_count = params + 1 /* pad */ ; |
| 4715 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4716 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4717 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4718 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4721 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4722 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | if (rc) { |
| 4724 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4725 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4726 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4727 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4728 | } else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4729 | cifs_dbg(FYI, "FindNext returned = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | } else { /* decode response */ |
| 4731 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4732 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4733 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4734 | unsigned int lnoff; |
| 4735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4737 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4738 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4740 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4741 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4742 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4743 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4744 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4745 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4746 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4747 | cifs_small_buf_release( |
| 4748 | psrch_inf->ntwrk_buf_start); |
| 4749 | else |
| 4750 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | psrch_inf->srch_entries_start = response_data; |
| 4752 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4753 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4754 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4755 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4757 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4758 | psrch_inf->entries_in_buffer = |
| 4759 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | psrch_inf->index_of_last_entry += |
| 4761 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4762 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4763 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4764 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4765 | psrch_inf->last_entry = NULL; |
| 4766 | return rc; |
| 4767 | } else |
| 4768 | psrch_inf->last_entry = |
| 4769 | psrch_inf->srch_entries_start + lnoff; |
| 4770 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4771 | /* cifs_dbg(FYI, "fnxt2 entries in buf %d index_of_last %d\n", |
| 4772 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | |
| 4774 | /* BB fixme add unlock here */ |
| 4775 | } |
| 4776 | |
| 4777 | } |
| 4778 | |
| 4779 | /* BB On error, should we leave previous search buf (and count and |
| 4780 | last entry fields) intact or free the previous one? */ |
| 4781 | |
| 4782 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4783 | since file handle passed in no longer valid */ |
| 4784 | FNext2_err_exit: |
| 4785 | if (rc != 0) |
| 4786 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | return rc; |
| 4788 | } |
| 4789 | |
| 4790 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4791 | CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4792 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | { |
| 4794 | int rc = 0; |
| 4795 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4797 | cifs_dbg(FYI, "In CIFSSMBFindClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4799 | |
| 4800 | /* no sense returning error if session restarted |
| 4801 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4802 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4803 | return 0; |
| 4804 | if (rc) |
| 4805 | return rc; |
| 4806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4807 | pSMB->FileID = searchHandle; |
| 4808 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4809 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4810 | cifs_small_buf_release(pSMB); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4811 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4812 | cifs_dbg(VFS, "Send error in FindClose = %d\n", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4813 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4814 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4815 | |
| 4816 | /* Since session is dead, search handle closed on server already */ |
| 4817 | if (rc == -EAGAIN) |
| 4818 | rc = 0; |
| 4819 | |
| 4820 | return rc; |
| 4821 | } |
| 4822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4824 | CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4825 | const char *search_name, __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4826 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | { |
| 4828 | int rc = 0; |
| 4829 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4830 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4831 | int name_len, bytes_returned; |
| 4832 | __u16 params, byte_count; |
| 4833 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4834 | cifs_dbg(FYI, "In GetSrvInodeNum for %s\n", search_name); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4835 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4836 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | |
| 4838 | GetInodeNumberRetry: |
| 4839 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4840 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | if (rc) |
| 4842 | return rc; |
| 4843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4845 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4846 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4847 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4848 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | name_len++; /* trailing null */ |
| 4850 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4851 | } else { |
| 4852 | name_len = copy_path_name(pSMB->FileName, search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4856 | pSMB->TotalDataCount = 0; |
| 4857 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4858 | /* BB find exact max data count below from sess structure BB */ |
| 4859 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4860 | pSMB->MaxSetupCount = 0; |
| 4861 | pSMB->Reserved = 0; |
| 4862 | pSMB->Flags = 0; |
| 4863 | pSMB->Timeout = 0; |
| 4864 | pSMB->Reserved2 = 0; |
| 4865 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4866 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | pSMB->DataCount = 0; |
| 4868 | pSMB->DataOffset = 0; |
| 4869 | pSMB->SetupCount = 1; |
| 4870 | pSMB->Reserved3 = 0; |
| 4871 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4872 | byte_count = params + 1 /* pad */ ; |
| 4873 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4874 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4875 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4876 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4877 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4879 | |
| 4880 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4881 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4882 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4883 | cifs_dbg(FYI, "error %d in QueryInternalInfo\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | } else { |
| 4885 | /* decode response */ |
| 4886 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4888 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | /* If rc should we check for EOPNOSUPP and |
| 4890 | disable the srvino flag? or in caller? */ |
| 4891 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4892 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4894 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4895 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4897 | if (count < 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4898 | cifs_dbg(FYI, "Illegal size ret in QryIntrnlInf\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | rc = -EIO; |
| 4900 | goto GetInodeNumOut; |
| 4901 | } |
| 4902 | pfinfo = (struct file_internal_info *) |
| 4903 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4904 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | } |
| 4906 | } |
| 4907 | GetInodeNumOut: |
| 4908 | cifs_buf_release(pSMB); |
| 4909 | if (rc == -EAGAIN) |
| 4910 | goto GetInodeNumberRetry; |
| 4911 | return rc; |
| 4912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | |
| 4914 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4915 | CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4916 | const char *search_name, struct dfs_info3_param **target_nodes, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4917 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4918 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | { |
| 4920 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4921 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4922 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | int rc = 0; |
| 4924 | int bytes_returned; |
| 4925 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4927 | *num_of_nodes = 0; |
| 4928 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4930 | cifs_dbg(FYI, "In GetDFSRefer the path %s\n", search_name); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4931 | if (ses == NULL || ses->tcon_ipc == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | return -ENODEV; |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | getDFSRetry: |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4935 | rc = smb_init(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4936 | (void **) &pSMBr); |
| 4937 | if (rc) |
| 4938 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4939 | |
| 4940 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4941 | but should never be null here anyway */ |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 4942 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4943 | pSMB->hdr.Tid = ses->tcon_ipc->tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4945 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4947 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | |
| 4950 | if (ses->capabilities & CAP_UNICODE) { |
| 4951 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4952 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4953 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4954 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4955 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4956 | name_len++; /* trailing null */ |
| 4957 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4958 | } else { /* BB improve the check for buffer overruns BB */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4959 | name_len = copy_path_name(pSMB->RequestFileName, search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | } |
| 4961 | |
Dan Carpenter | 65c3b20 | 2015-04-30 17:30:24 +0300 | [diff] [blame] | 4962 | if (ses->server->sign) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 4963 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4964 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4965 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4968 | pSMB->TotalDataCount = 0; |
| 4969 | pSMB->DataCount = 0; |
| 4970 | pSMB->DataOffset = 0; |
| 4971 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4972 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4973 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4974 | pSMB->MaxSetupCount = 0; |
| 4975 | pSMB->Reserved = 0; |
| 4976 | pSMB->Flags = 0; |
| 4977 | pSMB->Timeout = 0; |
| 4978 | pSMB->Reserved2 = 0; |
| 4979 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4980 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | pSMB->SetupCount = 1; |
| 4982 | pSMB->Reserved3 = 0; |
| 4983 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4984 | byte_count = params + 3 /* pad */ ; |
| 4985 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4986 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4987 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4988 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4990 | |
| 4991 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4992 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4993 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4994 | cifs_dbg(FYI, "Send error in GetDFSRefer = %d\n", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4995 | goto GetDFSRefExit; |
| 4996 | } |
| 4997 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4999 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5000 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 5001 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 5002 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 5004 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5005 | cifs_dbg(FYI, "Decoding GetDFSRefer response BCC: %d Offset %d\n", |
| 5006 | get_bcc(&pSMBr->hdr), le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 5007 | |
| 5008 | /* parse returned result into more usable form */ |
Aurelien Aptel | 4ecce92 | 2017-02-13 16:03:47 +0100 | [diff] [blame] | 5009 | rc = parse_dfs_referrals(&pSMBr->dfs_data, |
| 5010 | le16_to_cpu(pSMBr->t2.DataCount), |
| 5011 | num_of_nodes, target_nodes, nls_codepage, |
| 5012 | remap, search_name, |
Steve French | 284316d | 2017-03-02 15:42:48 -0600 | [diff] [blame] | 5013 | (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) != 0); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 5014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5016 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | |
| 5018 | if (rc == -EAGAIN) |
| 5019 | goto getDFSRetry; |
| 5020 | |
| 5021 | return rc; |
| 5022 | } |
| 5023 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5024 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 5025 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5026 | SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 5027 | struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5028 | { |
| 5029 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5030 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5031 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5032 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 5033 | int rc = 0; |
| 5034 | int bytes_returned = 0; |
| 5035 | __u16 params, byte_count; |
| 5036 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5037 | cifs_dbg(FYI, "OldQFSInfo\n"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5038 | oldQFSInfoRetry: |
| 5039 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5040 | (void **) &pSMBr); |
| 5041 | if (rc) |
| 5042 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5043 | |
| 5044 | params = 2; /* level */ |
| 5045 | pSMB->TotalDataCount = 0; |
| 5046 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5047 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5048 | pSMB->MaxSetupCount = 0; |
| 5049 | pSMB->Reserved = 0; |
| 5050 | pSMB->Flags = 0; |
| 5051 | pSMB->Timeout = 0; |
| 5052 | pSMB->Reserved2 = 0; |
| 5053 | byte_count = params + 1 /* pad */ ; |
| 5054 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5055 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5056 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 5057 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 5058 | pSMB->DataCount = 0; |
| 5059 | pSMB->DataOffset = 0; |
| 5060 | pSMB->SetupCount = 1; |
| 5061 | pSMB->Reserved3 = 0; |
| 5062 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5063 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5064 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5065 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5066 | |
| 5067 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5068 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5069 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5070 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5071 | } else { /* decode response */ |
| 5072 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5073 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5074 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5075 | rc = -EIO; /* bad smb */ |
| 5076 | else { |
| 5077 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5078 | cifs_dbg(FYI, "qfsinf resp BCC: %d Offset %d\n", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5079 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5080 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5081 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5082 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 5083 | FSData->f_bsize = |
| 5084 | le16_to_cpu(response_data->BytesPerSector) * |
| 5085 | le32_to_cpu(response_data-> |
| 5086 | SectorsPerAllocationUnit); |
Steve French | 5a519be | 2018-09-15 14:07:09 -0500 | [diff] [blame] | 5087 | /* |
| 5088 | * much prefer larger but if server doesn't report |
| 5089 | * a valid size than 4K is a reasonable minimum |
| 5090 | */ |
| 5091 | if (FSData->f_bsize < 512) |
| 5092 | FSData->f_bsize = 4096; |
| 5093 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5094 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5095 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5096 | FSData->f_bfree = FSData->f_bavail = |
| 5097 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5098 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5099 | (unsigned long long)FSData->f_blocks, |
| 5100 | (unsigned long long)FSData->f_bfree, |
| 5101 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5102 | } |
| 5103 | } |
| 5104 | cifs_buf_release(pSMB); |
| 5105 | |
| 5106 | if (rc == -EAGAIN) |
| 5107 | goto oldQFSInfoRetry; |
| 5108 | |
| 5109 | return rc; |
| 5110 | } |
| 5111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5112 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5113 | CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 5114 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5115 | { |
| 5116 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5117 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5118 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5119 | FILE_SYSTEM_INFO *response_data; |
| 5120 | int rc = 0; |
| 5121 | int bytes_returned = 0; |
| 5122 | __u16 params, byte_count; |
| 5123 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5124 | cifs_dbg(FYI, "In QFSInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | QFSInfoRetry: |
| 5126 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5127 | (void **) &pSMBr); |
| 5128 | if (rc) |
| 5129 | return rc; |
| 5130 | |
| 5131 | params = 2; /* level */ |
| 5132 | pSMB->TotalDataCount = 0; |
| 5133 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5134 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5135 | pSMB->MaxSetupCount = 0; |
| 5136 | pSMB->Reserved = 0; |
| 5137 | pSMB->Flags = 0; |
| 5138 | pSMB->Timeout = 0; |
| 5139 | pSMB->Reserved2 = 0; |
| 5140 | byte_count = params + 1 /* pad */ ; |
| 5141 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5142 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5143 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5144 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | pSMB->DataCount = 0; |
| 5146 | pSMB->DataOffset = 0; |
| 5147 | pSMB->SetupCount = 1; |
| 5148 | pSMB->Reserved3 = 0; |
| 5149 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5150 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5151 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5153 | |
| 5154 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5155 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5156 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5157 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5159 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5161 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | rc = -EIO; /* bad smb */ |
| 5163 | else { |
| 5164 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | |
| 5166 | response_data = |
| 5167 | (FILE_SYSTEM_INFO |
| 5168 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5169 | data_offset); |
| 5170 | FSData->f_bsize = |
| 5171 | le32_to_cpu(response_data->BytesPerSector) * |
| 5172 | le32_to_cpu(response_data-> |
| 5173 | SectorsPerAllocationUnit); |
Steve French | 5a519be | 2018-09-15 14:07:09 -0500 | [diff] [blame] | 5174 | /* |
| 5175 | * much prefer larger but if server doesn't report |
| 5176 | * a valid size than 4K is a reasonable minimum |
| 5177 | */ |
| 5178 | if (FSData->f_bsize < 512) |
| 5179 | FSData->f_bsize = 4096; |
| 5180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5181 | FSData->f_blocks = |
| 5182 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 5183 | FSData->f_bfree = FSData->f_bavail = |
| 5184 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5185 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5186 | (unsigned long long)FSData->f_blocks, |
| 5187 | (unsigned long long)FSData->f_bfree, |
| 5188 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | } |
| 5190 | } |
| 5191 | cifs_buf_release(pSMB); |
| 5192 | |
| 5193 | if (rc == -EAGAIN) |
| 5194 | goto QFSInfoRetry; |
| 5195 | |
| 5196 | return rc; |
| 5197 | } |
| 5198 | |
| 5199 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5200 | CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5201 | { |
| 5202 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5203 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5204 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5205 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5206 | int rc = 0; |
| 5207 | int bytes_returned = 0; |
| 5208 | __u16 params, byte_count; |
| 5209 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5210 | cifs_dbg(FYI, "In QFSAttributeInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5211 | QFSAttributeRetry: |
| 5212 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5213 | (void **) &pSMBr); |
| 5214 | if (rc) |
| 5215 | return rc; |
| 5216 | |
| 5217 | params = 2; /* level */ |
| 5218 | pSMB->TotalDataCount = 0; |
| 5219 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5220 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5221 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5222 | pSMB->MaxSetupCount = 0; |
| 5223 | pSMB->Reserved = 0; |
| 5224 | pSMB->Flags = 0; |
| 5225 | pSMB->Timeout = 0; |
| 5226 | pSMB->Reserved2 = 0; |
| 5227 | byte_count = params + 1 /* pad */ ; |
| 5228 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5229 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5230 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5231 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5232 | pSMB->DataCount = 0; |
| 5233 | pSMB->DataOffset = 0; |
| 5234 | pSMB->SetupCount = 1; |
| 5235 | pSMB->Reserved3 = 0; |
| 5236 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5237 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5238 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5240 | |
| 5241 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5242 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5243 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5244 | cifs_dbg(VFS, "Send error in QFSAttributeInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5245 | } else { /* decode response */ |
| 5246 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5247 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5248 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5249 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5250 | rc = -EIO; /* bad smb */ |
| 5251 | } else { |
| 5252 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5253 | response_data = |
| 5254 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5255 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5256 | data_offset); |
| 5257 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5258 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5259 | } |
| 5260 | } |
| 5261 | cifs_buf_release(pSMB); |
| 5262 | |
| 5263 | if (rc == -EAGAIN) |
| 5264 | goto QFSAttributeRetry; |
| 5265 | |
| 5266 | return rc; |
| 5267 | } |
| 5268 | |
| 5269 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5270 | CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5271 | { |
| 5272 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5273 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5274 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5275 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5276 | int rc = 0; |
| 5277 | int bytes_returned = 0; |
| 5278 | __u16 params, byte_count; |
| 5279 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5280 | cifs_dbg(FYI, "In QFSDeviceInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5281 | QFSDeviceRetry: |
| 5282 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5283 | (void **) &pSMBr); |
| 5284 | if (rc) |
| 5285 | return rc; |
| 5286 | |
| 5287 | params = 2; /* level */ |
| 5288 | pSMB->TotalDataCount = 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(1000); |
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->TotalParameterCount = cpu_to_le16(params); |
| 5299 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5300 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5301 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | |
| 5303 | pSMB->DataCount = 0; |
| 5304 | pSMB->DataOffset = 0; |
| 5305 | pSMB->SetupCount = 1; |
| 5306 | pSMB->Reserved3 = 0; |
| 5307 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5308 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5309 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5310 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5311 | |
| 5312 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5313 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5314 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5315 | cifs_dbg(FYI, "Send error in QFSDeviceInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5316 | } else { /* decode response */ |
| 5317 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5318 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5319 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5320 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | rc = -EIO; /* bad smb */ |
| 5322 | else { |
| 5323 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5324 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5325 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5326 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | data_offset); |
| 5328 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5329 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5330 | } |
| 5331 | } |
| 5332 | cifs_buf_release(pSMB); |
| 5333 | |
| 5334 | if (rc == -EAGAIN) |
| 5335 | goto QFSDeviceRetry; |
| 5336 | |
| 5337 | return rc; |
| 5338 | } |
| 5339 | |
| 5340 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5341 | CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | { |
| 5343 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5344 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5345 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5346 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5347 | int rc = 0; |
| 5348 | int bytes_returned = 0; |
| 5349 | __u16 params, byte_count; |
| 5350 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5351 | cifs_dbg(FYI, "In QFSUnixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5352 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5353 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5354 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5355 | if (rc) |
| 5356 | return rc; |
| 5357 | |
| 5358 | params = 2; /* level */ |
| 5359 | pSMB->TotalDataCount = 0; |
| 5360 | pSMB->DataCount = 0; |
| 5361 | pSMB->DataOffset = 0; |
| 5362 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5363 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5364 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5365 | pSMB->MaxSetupCount = 0; |
| 5366 | pSMB->Reserved = 0; |
| 5367 | pSMB->Flags = 0; |
| 5368 | pSMB->Timeout = 0; |
| 5369 | pSMB->Reserved2 = 0; |
| 5370 | byte_count = params + 1 /* pad */ ; |
| 5371 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5372 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5373 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5374 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5375 | pSMB->SetupCount = 1; |
| 5376 | pSMB->Reserved3 = 0; |
| 5377 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5378 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5379 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5380 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5381 | |
| 5382 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5383 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5384 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5385 | cifs_dbg(VFS, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | } else { /* decode response */ |
| 5387 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5388 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5389 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | rc = -EIO; /* bad smb */ |
| 5391 | } else { |
| 5392 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5393 | response_data = |
| 5394 | (FILE_SYSTEM_UNIX_INFO |
| 5395 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5396 | data_offset); |
| 5397 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5398 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5399 | } |
| 5400 | } |
| 5401 | cifs_buf_release(pSMB); |
| 5402 | |
| 5403 | if (rc == -EAGAIN) |
| 5404 | goto QFSUnixRetry; |
| 5405 | |
| 5406 | |
| 5407 | return rc; |
| 5408 | } |
| 5409 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5410 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5411 | CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5412 | { |
| 5413 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5414 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5415 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5416 | int rc = 0; |
| 5417 | int bytes_returned = 0; |
| 5418 | __u16 params, param_offset, offset, byte_count; |
| 5419 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5420 | cifs_dbg(FYI, "In SETFSUnixInfo\n"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5421 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5422 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5423 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5424 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5425 | if (rc) |
| 5426 | return rc; |
| 5427 | |
| 5428 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5429 | pSMB->MaxSetupCount = 0; |
| 5430 | pSMB->Reserved = 0; |
| 5431 | pSMB->Flags = 0; |
| 5432 | pSMB->Timeout = 0; |
| 5433 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5434 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5435 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5436 | offset = param_offset + params; |
| 5437 | |
| 5438 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5439 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5440 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5441 | pSMB->SetupCount = 1; |
| 5442 | pSMB->Reserved3 = 0; |
| 5443 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5444 | byte_count = 1 /* pad */ + params + 12; |
| 5445 | |
| 5446 | pSMB->DataCount = cpu_to_le16(12); |
| 5447 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5448 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5449 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5450 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5451 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5452 | |
| 5453 | /* Params. */ |
| 5454 | pSMB->FileNum = 0; |
| 5455 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5456 | |
| 5457 | /* Data. */ |
| 5458 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5459 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5460 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5461 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5462 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5463 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5464 | |
| 5465 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5466 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5467 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5468 | cifs_dbg(VFS, "Send error in SETFSUnixInfo = %d\n", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5469 | } else { /* decode response */ |
| 5470 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5471 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5472 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5473 | } |
| 5474 | cifs_buf_release(pSMB); |
| 5475 | |
| 5476 | if (rc == -EAGAIN) |
| 5477 | goto SETFSUnixRetry; |
| 5478 | |
| 5479 | return rc; |
| 5480 | } |
| 5481 | |
| 5482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 | |
| 5484 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5485 | CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5486 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | { |
| 5488 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5489 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5490 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5491 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5492 | int rc = 0; |
| 5493 | int bytes_returned = 0; |
| 5494 | __u16 params, byte_count; |
| 5495 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5496 | cifs_dbg(FYI, "In QFSPosixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | QFSPosixRetry: |
| 5498 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5499 | (void **) &pSMBr); |
| 5500 | if (rc) |
| 5501 | return rc; |
| 5502 | |
| 5503 | params = 2; /* level */ |
| 5504 | pSMB->TotalDataCount = 0; |
| 5505 | pSMB->DataCount = 0; |
| 5506 | pSMB->DataOffset = 0; |
| 5507 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5508 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5509 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | pSMB->MaxSetupCount = 0; |
| 5511 | pSMB->Reserved = 0; |
| 5512 | pSMB->Flags = 0; |
| 5513 | pSMB->Timeout = 0; |
| 5514 | pSMB->Reserved2 = 0; |
| 5515 | byte_count = params + 1 /* pad */ ; |
| 5516 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5517 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5518 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5519 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | pSMB->SetupCount = 1; |
| 5521 | pSMB->Reserved3 = 0; |
| 5522 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5523 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5524 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5526 | |
| 5527 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5528 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5529 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5530 | cifs_dbg(FYI, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | } else { /* decode response */ |
| 5532 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5533 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5534 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5535 | rc = -EIO; /* bad smb */ |
| 5536 | } else { |
| 5537 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5538 | response_data = |
| 5539 | (FILE_SYSTEM_POSIX_INFO |
| 5540 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5541 | data_offset); |
| 5542 | FSData->f_bsize = |
| 5543 | le32_to_cpu(response_data->BlockSize); |
Steve French | 5a519be | 2018-09-15 14:07:09 -0500 | [diff] [blame] | 5544 | /* |
| 5545 | * much prefer larger but if server doesn't report |
| 5546 | * a valid size than 4K is a reasonable minimum |
| 5547 | */ |
| 5548 | if (FSData->f_bsize < 512) |
| 5549 | FSData->f_bsize = 4096; |
| 5550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5551 | FSData->f_blocks = |
| 5552 | le64_to_cpu(response_data->TotalBlocks); |
| 5553 | FSData->f_bfree = |
| 5554 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5555 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5556 | FSData->f_bavail = FSData->f_bfree; |
| 5557 | } else { |
| 5558 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5559 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5560 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5561 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5562 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5563 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5564 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5565 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5566 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | } |
| 5568 | } |
| 5569 | cifs_buf_release(pSMB); |
| 5570 | |
| 5571 | if (rc == -EAGAIN) |
| 5572 | goto QFSPosixRetry; |
| 5573 | |
| 5574 | return rc; |
| 5575 | } |
| 5576 | |
| 5577 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5578 | /* |
| 5579 | * We can not use write of zero bytes trick to set file size due to need for |
| 5580 | * large file support. Also note that this SetPathInfo is preferred to |
| 5581 | * SetFileInfo based method in next routine which is only needed to work around |
| 5582 | * a sharing violation bugin Samba which this routine can run into. |
| 5583 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5585 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5586 | const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, |
| 5587 | bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5588 | { |
| 5589 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5590 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5591 | struct file_end_of_file_info *parm_data; |
| 5592 | int name_len; |
| 5593 | int rc = 0; |
| 5594 | int bytes_returned = 0; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 5595 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5598 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5599 | cifs_dbg(FYI, "In SetEOF\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5600 | SetEOFRetry: |
| 5601 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5602 | (void **) &pSMBr); |
| 5603 | if (rc) |
| 5604 | return rc; |
| 5605 | |
| 5606 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5607 | name_len = |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5608 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
| 5609 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | name_len++; /* trailing null */ |
| 5611 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 5612 | } else { |
| 5613 | name_len = copy_path_name(pSMB->FileName, file_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | } |
| 5615 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5616 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5618 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | pSMB->MaxSetupCount = 0; |
| 5620 | pSMB->Reserved = 0; |
| 5621 | pSMB->Flags = 0; |
| 5622 | pSMB->Timeout = 0; |
| 5623 | pSMB->Reserved2 = 0; |
| 5624 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5625 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5626 | offset = param_offset + params; |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5627 | if (set_allocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5628 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5629 | pSMB->InformationLevel = |
| 5630 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5631 | else |
| 5632 | pSMB->InformationLevel = |
| 5633 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5634 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5636 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5637 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5638 | else |
| 5639 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5640 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5641 | } |
| 5642 | |
| 5643 | parm_data = |
| 5644 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5645 | offset); |
| 5646 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5647 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5648 | pSMB->SetupCount = 1; |
| 5649 | pSMB->Reserved3 = 0; |
| 5650 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5651 | byte_count = 3 /* pad */ + params + data_count; |
| 5652 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5653 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5654 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5655 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5656 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5657 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5658 | parm_data->FileSize = cpu_to_le64(size); |
| 5659 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5660 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5661 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5662 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5663 | cifs_dbg(FYI, "SetPathInfo (file size) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5664 | |
| 5665 | cifs_buf_release(pSMB); |
| 5666 | |
| 5667 | if (rc == -EAGAIN) |
| 5668 | goto SetEOFRetry; |
| 5669 | |
| 5670 | return rc; |
| 5671 | } |
| 5672 | |
| 5673 | int |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5674 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
| 5675 | struct cifsFileInfo *cfile, __u64 size, bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5676 | { |
| 5677 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5678 | struct file_end_of_file_info *parm_data; |
| 5679 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5680 | __u16 params, param_offset, offset, byte_count, count; |
| 5681 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5682 | cifs_dbg(FYI, "SetFileSize (via SetFileInfo) %lld\n", |
| 5683 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5684 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5686 | if (rc) |
| 5687 | return rc; |
| 5688 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5689 | pSMB->hdr.Pid = cpu_to_le16((__u16)cfile->pid); |
| 5690 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(cfile->pid >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5691 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | params = 6; |
| 5693 | pSMB->MaxSetupCount = 0; |
| 5694 | pSMB->Reserved = 0; |
| 5695 | pSMB->Flags = 0; |
| 5696 | pSMB->Timeout = 0; |
| 5697 | pSMB->Reserved2 = 0; |
| 5698 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5699 | offset = param_offset + params; |
| 5700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | count = sizeof(struct file_end_of_file_info); |
| 5702 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5703 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5704 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5705 | pSMB->SetupCount = 1; |
| 5706 | pSMB->Reserved3 = 0; |
| 5707 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5708 | byte_count = 3 /* pad */ + params + count; |
| 5709 | pSMB->DataCount = cpu_to_le16(count); |
| 5710 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5711 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5712 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5713 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5714 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5715 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5716 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5718 | parm_data->FileSize = cpu_to_le64(size); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5719 | pSMB->Fid = cfile->fid.netfid; |
| 5720 | if (set_allocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5722 | pSMB->InformationLevel = |
| 5723 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5724 | else |
| 5725 | pSMB->InformationLevel = |
| 5726 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5727 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5729 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5730 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5731 | else |
| 5732 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5733 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5734 | } |
| 5735 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5736 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5737 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5738 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5739 | cifs_small_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5740 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5741 | cifs_dbg(FYI, "Send error in SetFileInfo (SetFileSize) = %d\n", |
| 5742 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5743 | } |
| 5744 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5745 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5746 | since file handle passed in no longer valid */ |
| 5747 | |
| 5748 | return rc; |
| 5749 | } |
| 5750 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5751 | /* 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] | 5752 | an open handle, rather than by pathname - this is awkward due to |
| 5753 | potential access conflicts on the open, but it is unavoidable for these |
| 5754 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5755 | time and resort to the original setpathinfo level which takes the ancient |
| 5756 | DOS time format with 2 second granularity */ |
| 5757 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5758 | CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5759 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5760 | { |
| 5761 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5762 | char *data_offset; |
| 5763 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | __u16 params, param_offset, offset, byte_count, count; |
| 5765 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5766 | cifs_dbg(FYI, "Set Times (via SetFileInfo)\n"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5767 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5769 | if (rc) |
| 5770 | return rc; |
| 5771 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5772 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5773 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | params = 6; |
| 5776 | pSMB->MaxSetupCount = 0; |
| 5777 | pSMB->Reserved = 0; |
| 5778 | pSMB->Flags = 0; |
| 5779 | pSMB->Timeout = 0; |
| 5780 | pSMB->Reserved2 = 0; |
| 5781 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5782 | offset = param_offset + params; |
| 5783 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5784 | data_offset = (char *)pSMB + |
| 5785 | offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5787 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5788 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5789 | /* BB find max SMB PDU from sess */ |
| 5790 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5791 | pSMB->SetupCount = 1; |
| 5792 | pSMB->Reserved3 = 0; |
| 5793 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5794 | byte_count = 3 /* pad */ + params + count; |
| 5795 | pSMB->DataCount = cpu_to_le16(count); |
| 5796 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5797 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5798 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5799 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5800 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5801 | pSMB->Fid = fid; |
| 5802 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5803 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5804 | else |
| 5805 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5806 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5807 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5809 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5810 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5811 | cifs_small_buf_release(pSMB); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5812 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5813 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 5814 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5815 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5816 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5817 | since file handle passed in no longer valid */ |
| 5818 | |
| 5819 | return rc; |
| 5820 | } |
| 5821 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5822 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5823 | CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5824 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5825 | { |
| 5826 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5827 | char *data_offset; |
| 5828 | int rc = 0; |
| 5829 | __u16 params, param_offset, offset, byte_count, count; |
| 5830 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5831 | cifs_dbg(FYI, "Set File Disposition (via SetFileInfo)\n"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5832 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5833 | |
| 5834 | if (rc) |
| 5835 | return rc; |
| 5836 | |
| 5837 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5838 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5839 | |
| 5840 | params = 6; |
| 5841 | pSMB->MaxSetupCount = 0; |
| 5842 | pSMB->Reserved = 0; |
| 5843 | pSMB->Flags = 0; |
| 5844 | pSMB->Timeout = 0; |
| 5845 | pSMB->Reserved2 = 0; |
| 5846 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5847 | offset = param_offset + params; |
| 5848 | |
| 5849 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5850 | |
| 5851 | count = 1; |
| 5852 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5853 | /* BB find max SMB PDU from sess */ |
| 5854 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5855 | pSMB->SetupCount = 1; |
| 5856 | pSMB->Reserved3 = 0; |
| 5857 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5858 | byte_count = 3 /* pad */ + params + count; |
| 5859 | pSMB->DataCount = cpu_to_le16(count); |
| 5860 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5861 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5862 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5863 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5864 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5865 | pSMB->Fid = fid; |
| 5866 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5867 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5868 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5869 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5870 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5871 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5872 | cifs_small_buf_release(pSMB); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5873 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5874 | cifs_dbg(FYI, "Send error in SetFileDisposition = %d\n", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5875 | |
| 5876 | return rc; |
| 5877 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5878 | |
| 5879 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5880 | CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5881 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5882 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5883 | { |
| 5884 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5885 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5886 | int name_len; |
| 5887 | int rc = 0; |
| 5888 | int bytes_returned = 0; |
| 5889 | char *data_offset; |
| 5890 | __u16 params, param_offset, offset, byte_count, count; |
| 5891 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5892 | cifs_dbg(FYI, "In SetTimes\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5893 | |
| 5894 | SetTimesRetry: |
| 5895 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5896 | (void **) &pSMBr); |
| 5897 | if (rc) |
| 5898 | return rc; |
| 5899 | |
| 5900 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5901 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5902 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5903 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5904 | name_len++; /* trailing null */ |
| 5905 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 5906 | } else { |
| 5907 | name_len = copy_path_name(pSMB->FileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5911 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5912 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5913 | /* BB find max SMB PDU from sess structure BB */ |
| 5914 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5915 | pSMB->MaxSetupCount = 0; |
| 5916 | pSMB->Reserved = 0; |
| 5917 | pSMB->Flags = 0; |
| 5918 | pSMB->Timeout = 0; |
| 5919 | pSMB->Reserved2 = 0; |
| 5920 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5921 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | offset = param_offset + params; |
| 5923 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5924 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5925 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5926 | pSMB->SetupCount = 1; |
| 5927 | pSMB->Reserved3 = 0; |
| 5928 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5929 | byte_count = 3 /* pad */ + params + count; |
| 5930 | |
| 5931 | pSMB->DataCount = cpu_to_le16(count); |
| 5932 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5933 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5934 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5935 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5936 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5937 | else |
| 5938 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5939 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5940 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5941 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5942 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5943 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5944 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5945 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5946 | cifs_dbg(FYI, "SetPathInfo (times) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5947 | |
| 5948 | cifs_buf_release(pSMB); |
| 5949 | |
| 5950 | if (rc == -EAGAIN) |
| 5951 | goto SetTimesRetry; |
| 5952 | |
| 5953 | return rc; |
| 5954 | } |
| 5955 | |
| 5956 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5957 | /* Can be used to set attributes */ |
| 5958 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5959 | handling it anyway and NT4 was what we thought it would be needed for |
| 5960 | Do not delete it until we prove whether needed for Win9x though */ |
| 5961 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5962 | CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5963 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5964 | { |
| 5965 | SETATTR_REQ *pSMB = NULL; |
| 5966 | SETATTR_RSP *pSMBr = NULL; |
| 5967 | int rc = 0; |
| 5968 | int bytes_returned; |
| 5969 | int name_len; |
| 5970 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5971 | cifs_dbg(FYI, "In SetAttrLegacy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5972 | |
| 5973 | SetAttrLgcyRetry: |
| 5974 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5975 | (void **) &pSMBr); |
| 5976 | if (rc) |
| 5977 | return rc; |
| 5978 | |
| 5979 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5980 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5981 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 5982 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5983 | name_len++; /* trailing null */ |
| 5984 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 5985 | } else { |
| 5986 | name_len = copy_path_name(pSMB->fileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5987 | } |
| 5988 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5989 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5990 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5991 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5992 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5993 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5994 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5995 | cifs_dbg(FYI, "Error in LegacySetAttr = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5996 | |
| 5997 | cifs_buf_release(pSMB); |
| 5998 | |
| 5999 | if (rc == -EAGAIN) |
| 6000 | goto SetAttrLgcyRetry; |
| 6001 | |
| 6002 | return rc; |
| 6003 | } |
| 6004 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 6005 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6006 | static void |
| 6007 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 6008 | const struct cifs_unix_set_info_args *args) |
| 6009 | { |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 6010 | u64 uid = NO_CHANGE_64, gid = NO_CHANGE_64; |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6011 | u64 mode = args->mode; |
| 6012 | |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 6013 | if (uid_valid(args->uid)) |
| 6014 | uid = from_kuid(&init_user_ns, args->uid); |
| 6015 | if (gid_valid(args->gid)) |
| 6016 | gid = from_kgid(&init_user_ns, args->gid); |
| 6017 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6018 | /* |
| 6019 | * Samba server ignores set of file size to zero due to bugs in some |
| 6020 | * older clients, but we should be precise - we use SetFileSize to |
| 6021 | * 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] | 6022 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6023 | * zero instead of -1 here |
| 6024 | */ |
| 6025 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 6026 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 6027 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 6028 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 6029 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 6030 | data_offset->Uid = cpu_to_le64(uid); |
| 6031 | data_offset->Gid = cpu_to_le64(gid); |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6032 | /* better to leave device as zero when it is */ |
| 6033 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 6034 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 6035 | data_offset->Permissions = cpu_to_le64(mode); |
| 6036 | |
| 6037 | if (S_ISREG(mode)) |
| 6038 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 6039 | else if (S_ISDIR(mode)) |
| 6040 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 6041 | else if (S_ISLNK(mode)) |
| 6042 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 6043 | else if (S_ISCHR(mode)) |
| 6044 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 6045 | else if (S_ISBLK(mode)) |
| 6046 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 6047 | else if (S_ISFIFO(mode)) |
| 6048 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 6049 | else if (S_ISSOCK(mode)) |
| 6050 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 6051 | } |
| 6052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6053 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6054 | CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6055 | const struct cifs_unix_set_info_args *args, |
| 6056 | u16 fid, u32 pid_of_opener) |
| 6057 | { |
| 6058 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6059 | char *data_offset; |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6060 | int rc = 0; |
| 6061 | u16 params, param_offset, offset, byte_count, count; |
| 6062 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6063 | cifs_dbg(FYI, "Set Unix Info (via SetFileInfo)\n"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6064 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 6065 | |
| 6066 | if (rc) |
| 6067 | return rc; |
| 6068 | |
| 6069 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 6070 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 6071 | |
| 6072 | params = 6; |
| 6073 | pSMB->MaxSetupCount = 0; |
| 6074 | pSMB->Reserved = 0; |
| 6075 | pSMB->Flags = 0; |
| 6076 | pSMB->Timeout = 0; |
| 6077 | pSMB->Reserved2 = 0; |
| 6078 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 6079 | offset = param_offset + params; |
| 6080 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6081 | data_offset = (char *)pSMB + |
| 6082 | offsetof(struct smb_hdr, Protocol) + offset; |
| 6083 | |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6084 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 6085 | |
| 6086 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 6087 | /* BB find max SMB PDU from sess */ |
| 6088 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 6089 | pSMB->SetupCount = 1; |
| 6090 | pSMB->Reserved3 = 0; |
| 6091 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 6092 | byte_count = 3 /* pad */ + params + count; |
| 6093 | pSMB->DataCount = cpu_to_le16(count); |
| 6094 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6095 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6096 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6097 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6098 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6099 | pSMB->Fid = fid; |
| 6100 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6101 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6102 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6103 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6104 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6105 | cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6106 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 6107 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 6108 | cifs_small_buf_release(pSMB); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6109 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6110 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 6111 | rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6112 | |
| 6113 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 6114 | since file handle passed in no longer valid */ |
| 6115 | |
| 6116 | return rc; |
| 6117 | } |
| 6118 | |
| 6119 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6120 | CIFSSMBUnixSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6121 | const char *file_name, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6122 | const struct cifs_unix_set_info_args *args, |
| 6123 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6124 | { |
| 6125 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 6126 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 6127 | int name_len; |
| 6128 | int rc = 0; |
| 6129 | int bytes_returned = 0; |
| 6130 | FILE_UNIX_BASIC_INFO *data_offset; |
| 6131 | __u16 params, param_offset, offset, count, byte_count; |
| 6132 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6133 | cifs_dbg(FYI, "In SetUID/GID/Mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | setPermsRetry: |
| 6135 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6136 | (void **) &pSMBr); |
| 6137 | if (rc) |
| 6138 | return rc; |
| 6139 | |
| 6140 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6141 | name_len = |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6142 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6143 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | name_len++; /* trailing null */ |
| 6145 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6146 | } else { |
| 6147 | name_len = copy_path_name(pSMB->FileName, file_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 6151 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6153 | /* BB find max SMB PDU from sess structure BB */ |
| 6154 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6155 | pSMB->MaxSetupCount = 0; |
| 6156 | pSMB->Reserved = 0; |
| 6157 | pSMB->Flags = 0; |
| 6158 | pSMB->Timeout = 0; |
| 6159 | pSMB->Reserved2 = 0; |
| 6160 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6161 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6162 | offset = param_offset + params; |
| 6163 | data_offset = |
| 6164 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 6165 | offset); |
| 6166 | memset(data_offset, 0, count); |
| 6167 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6168 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6169 | pSMB->SetupCount = 1; |
| 6170 | pSMB->Reserved3 = 0; |
| 6171 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6172 | byte_count = 3 /* pad */ + params + count; |
| 6173 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6174 | pSMB->DataCount = cpu_to_le16(count); |
| 6175 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6176 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6177 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6178 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6179 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6180 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6181 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6182 | |
| 6183 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6184 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6185 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6186 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6187 | cifs_dbg(FYI, "SetPathInfo (perms) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6189 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6190 | if (rc == -EAGAIN) |
| 6191 | goto setPermsRetry; |
| 6192 | return rc; |
| 6193 | } |
| 6194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6195 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6196 | /* |
| 6197 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 6198 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 6199 | * it looks for that attribute name and stuffs that value into the EAData |
| 6200 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 6201 | * buffer. In both cases, the return value is either the length of the |
| 6202 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 6203 | * the data isn't copied to it, but the length is returned. |
| 6204 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | ssize_t |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6206 | CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6207 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6208 | char *EAData, size_t buf_size, |
Steve French | 67b4c88 | 2017-05-12 20:59:10 -0500 | [diff] [blame] | 6209 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | { |
| 6211 | /* BB assumes one setup word */ |
| 6212 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6213 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
Steve French | 67b4c88 | 2017-05-12 20:59:10 -0500 | [diff] [blame] | 6214 | int remap = cifs_remap(cifs_sb); |
| 6215 | struct nls_table *nls_codepage = cifs_sb->local_nls; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6216 | int rc = 0; |
| 6217 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6218 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6219 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6220 | struct fea *temp_fea; |
| 6221 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6222 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6223 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6224 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6225 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6226 | cifs_dbg(FYI, "In Query All EAs path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6227 | QAllEAsRetry: |
| 6228 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6229 | (void **) &pSMBr); |
| 6230 | if (rc) |
| 6231 | return rc; |
| 6232 | |
| 6233 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6234 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6235 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6236 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6237 | list_len++; /* trailing null */ |
| 6238 | list_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6239 | } else { |
| 6240 | list_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | } |
| 6242 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6243 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6244 | pSMB->TotalDataCount = 0; |
| 6245 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6246 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6247 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6248 | pSMB->MaxSetupCount = 0; |
| 6249 | pSMB->Reserved = 0; |
| 6250 | pSMB->Flags = 0; |
| 6251 | pSMB->Timeout = 0; |
| 6252 | pSMB->Reserved2 = 0; |
| 6253 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6254 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6255 | pSMB->DataCount = 0; |
| 6256 | pSMB->DataOffset = 0; |
| 6257 | pSMB->SetupCount = 1; |
| 6258 | pSMB->Reserved3 = 0; |
| 6259 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6260 | byte_count = params + 1 /* pad */ ; |
| 6261 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6262 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6263 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6264 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6265 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6266 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6267 | |
| 6268 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6269 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6270 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6271 | cifs_dbg(FYI, "Send error in QueryAllEAs = %d\n", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6272 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6273 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6274 | |
| 6275 | |
| 6276 | /* BB also check enough total bytes returned */ |
| 6277 | /* BB we need to improve the validity checking |
| 6278 | of these trans2 responses */ |
| 6279 | |
| 6280 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6281 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6282 | rc = -EIO; /* bad smb */ |
| 6283 | goto QAllEAsOut; |
| 6284 | } |
| 6285 | |
| 6286 | /* check that length of list is not more than bcc */ |
| 6287 | /* check that each entry does not go beyond length |
| 6288 | of list */ |
| 6289 | /* check that each element of each entry does not |
| 6290 | go beyond end of list */ |
| 6291 | /* validate_trans2_offsets() */ |
| 6292 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6293 | |
| 6294 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6295 | ea_response_data = (struct fealist *) |
| 6296 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6297 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6298 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6299 | cifs_dbg(FYI, "ea length %d\n", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6300 | if (list_len <= 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6301 | cifs_dbg(FYI, "empty EA list returned from server\n"); |
Steve French | 60977fc | 2014-03-25 19:46:36 -0500 | [diff] [blame] | 6302 | /* didn't find the named attribute */ |
| 6303 | if (ea_name) |
| 6304 | rc = -ENODATA; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6305 | goto QAllEAsOut; |
| 6306 | } |
| 6307 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6308 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6309 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6310 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6311 | cifs_dbg(FYI, "EA list appears to go beyond SMB\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6312 | rc = -EIO; |
| 6313 | goto QAllEAsOut; |
| 6314 | } |
| 6315 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6316 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6317 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6318 | temp_fea = ea_response_data->list; |
| 6319 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6320 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6321 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6322 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6323 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6324 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6325 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6326 | /* make sure we can read name_len and value_len */ |
| 6327 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6328 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6329 | rc = -EIO; |
| 6330 | goto QAllEAsOut; |
| 6331 | } |
| 6332 | |
| 6333 | name_len = temp_fea->name_len; |
| 6334 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6335 | list_len -= name_len + 1 + value_len; |
| 6336 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6337 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6338 | rc = -EIO; |
| 6339 | goto QAllEAsOut; |
| 6340 | } |
| 6341 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6342 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6343 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6344 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6345 | temp_ptr += name_len + 1; |
| 6346 | rc = value_len; |
| 6347 | if (buf_size == 0) |
| 6348 | goto QAllEAsOut; |
| 6349 | if ((size_t)value_len > buf_size) { |
| 6350 | rc = -ERANGE; |
| 6351 | goto QAllEAsOut; |
| 6352 | } |
| 6353 | memcpy(EAData, temp_ptr, value_len); |
| 6354 | goto QAllEAsOut; |
| 6355 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6356 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6357 | /* account for prefix user. and trailing null */ |
| 6358 | rc += (5 + 1 + name_len); |
| 6359 | if (rc < (int) buf_size) { |
| 6360 | memcpy(EAData, "user.", 5); |
| 6361 | EAData += 5; |
| 6362 | memcpy(EAData, temp_ptr, name_len); |
| 6363 | EAData += name_len; |
| 6364 | /* null terminate name */ |
| 6365 | *EAData = 0; |
| 6366 | ++EAData; |
| 6367 | } else if (buf_size == 0) { |
| 6368 | /* skip copy - calc size only */ |
| 6369 | } else { |
| 6370 | /* stop before overrun buffer */ |
| 6371 | rc = -ERANGE; |
| 6372 | break; |
| 6373 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6374 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6375 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6376 | temp_fea = (struct fea *)temp_ptr; |
| 6377 | } |
| 6378 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6379 | /* didn't find the named attribute */ |
| 6380 | if (ea_name) |
| 6381 | rc = -ENODATA; |
| 6382 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6383 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6384 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6385 | if (rc == -EAGAIN) |
| 6386 | goto QAllEAsRetry; |
| 6387 | |
| 6388 | return (ssize_t)rc; |
| 6389 | } |
| 6390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6391 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6392 | CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, |
| 6393 | const char *fileName, const char *ea_name, const void *ea_value, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6394 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 6395 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6396 | { |
| 6397 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6398 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6399 | struct fealist *parm_data; |
| 6400 | int name_len; |
| 6401 | int rc = 0; |
| 6402 | int bytes_returned = 0; |
| 6403 | __u16 params, param_offset, byte_count, offset, count; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 6404 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6405 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6406 | cifs_dbg(FYI, "In SetEA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6407 | SetEARetry: |
| 6408 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6409 | (void **) &pSMBr); |
| 6410 | if (rc) |
| 6411 | return rc; |
| 6412 | |
| 6413 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6414 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6415 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6416 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6417 | name_len++; /* trailing null */ |
| 6418 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6419 | } else { |
| 6420 | name_len = copy_path_name(pSMB->FileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6421 | } |
| 6422 | |
| 6423 | params = 6 + name_len; |
| 6424 | |
| 6425 | /* done calculating parms using name_len of file name, |
| 6426 | now use name_len to calculate length of ea name |
| 6427 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6428 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6429 | name_len = 0; |
| 6430 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6431 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6432 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6433 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6434 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6435 | /* BB find max SMB PDU from sess */ |
| 6436 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6437 | pSMB->MaxSetupCount = 0; |
| 6438 | pSMB->Reserved = 0; |
| 6439 | pSMB->Flags = 0; |
| 6440 | pSMB->Timeout = 0; |
| 6441 | pSMB->Reserved2 = 0; |
| 6442 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6443 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6444 | offset = param_offset + params; |
| 6445 | pSMB->InformationLevel = |
| 6446 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6447 | |
Arnd Bergmann | ade7db9 | 2018-02-02 16:48:47 +0100 | [diff] [blame] | 6448 | parm_data = (void *)pSMB + offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6449 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6450 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6451 | pSMB->SetupCount = 1; |
| 6452 | pSMB->Reserved3 = 0; |
| 6453 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6454 | byte_count = 3 /* pad */ + params + count; |
| 6455 | pSMB->DataCount = cpu_to_le16(count); |
| 6456 | parm_data->list_len = cpu_to_le32(count); |
| 6457 | parm_data->list[0].EA_flags = 0; |
| 6458 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6459 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6460 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6461 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6462 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6463 | parm_data->list[0].name[name_len] = 0; |
| 6464 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6465 | /* caller ensures that ea_value_len is less than 64K but |
| 6466 | we need to ensure that it fits within the smb */ |
| 6467 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6468 | /*BB add length check to see if it would fit in |
| 6469 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6470 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6471 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6472 | memcpy(parm_data->list[0].name+name_len+1, |
| 6473 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6474 | |
| 6475 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6476 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6477 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6478 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6479 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6480 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6481 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6482 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6483 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6484 | cifs_dbg(FYI, "SetPathInfo (EA) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6485 | |
| 6486 | cifs_buf_release(pSMB); |
| 6487 | |
| 6488 | if (rc == -EAGAIN) |
| 6489 | goto SetEARetry; |
| 6490 | |
| 6491 | return rc; |
| 6492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6493 | #endif |