Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cifssmb.c |
| 3 | * |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * Contains the routines for constructing the SMB PDUs themselves |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* SMB/CIFS PDU handling routines here - except for leftovers in connect.c */ |
| 25 | /* These are mostly routines that operate on a pathname, or on a tree id */ |
| 26 | /* (mounted volume), but there are eight handle based routines which must be */ |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 27 | /* treated slightly differently for reconnection purposes since we never */ |
| 28 | /* want to reuse a stale file handle and only the caller knows the file info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <linux/fs.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/vfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/posix_acl_xattr.h> |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 35 | #include <linux/pagemap.h> |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 36 | #include <linux/swap.h> |
| 37 | #include <linux/task_io_accounting_ops.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 38 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "cifspdu.h" |
| 40 | #include "cifsglob.h" |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 41 | #include "cifsacl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "cifsproto.h" |
| 43 | #include "cifs_unicode.h" |
| 44 | #include "cifs_debug.h" |
Pavel Shilovsky | d919131 | 2019-12-10 11:44:52 -0800 | [diff] [blame] | 45 | #include "smb2proto.h" |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 46 | #include "fscache.h" |
Long Li | db223a5 | 2017-11-22 17:38:45 -0700 | [diff] [blame] | 47 | #include "smbdirect.h" |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 48 | #ifdef CONFIG_CIFS_DFS_UPCALL |
| 49 | #include "dfs_cache.h" |
| 50 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #ifdef CONFIG_CIFS_POSIX |
| 53 | static struct { |
| 54 | int index; |
| 55 | char *name; |
| 56 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 57 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 58 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 59 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 60 | #endif /* weak password hashing for legacy clients */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 61 | {CIFS_PROT, "\2NT LM 0.12"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 62 | {POSIX_PROT, "\2POSIX 2"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | {BAD_PROT, "\2"} |
| 64 | }; |
| 65 | #else |
| 66 | static struct { |
| 67 | int index; |
| 68 | char *name; |
| 69 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 70 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 71 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 18f75ca | 2006-10-01 03:13:01 +0000 | [diff] [blame] | 72 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 73 | #endif /* weak password hashing for legacy clients */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 74 | {CIFS_PROT, "\2NT LM 0.12"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | {BAD_PROT, "\2"} |
| 76 | }; |
| 77 | #endif |
| 78 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 79 | /* define the number of elements in the cifs dialect array */ |
| 80 | #ifdef CONFIG_CIFS_POSIX |
| 81 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 82 | #define CIFS_NUM_PROT 4 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 83 | #else |
| 84 | #define CIFS_NUM_PROT 2 |
| 85 | #endif /* CIFS_WEAK_PW_HASH */ |
| 86 | #else /* not posix */ |
| 87 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 88 | #define CIFS_NUM_PROT 3 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 89 | #else |
| 90 | #define CIFS_NUM_PROT 1 |
| 91 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
| 92 | #endif /* CIFS_POSIX */ |
| 93 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 94 | /* |
| 95 | * Mark as invalid, all open files on tree connections since they |
| 96 | * were closed when session to server was lost. |
| 97 | */ |
| 98 | void |
| 99 | cifs_mark_open_files_invalid(struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
| 101 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 102 | struct list_head *tmp; |
| 103 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 105 | /* list all files open on tree connection and mark them invalid */ |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 106 | spin_lock(&tcon->open_file_lock); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 107 | list_for_each_safe(tmp, tmp1, &tcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 108 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 109 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 110 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
Steve French | 3afca26 | 2016-09-22 18:58:16 -0500 | [diff] [blame] | 112 | spin_unlock(&tcon->open_file_lock); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 113 | |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 114 | mutex_lock(&tcon->crfid.fid_mutex); |
| 115 | tcon->crfid.is_valid = false; |
Pavel Shilovsky | d919131 | 2019-12-10 11:44:52 -0800 | [diff] [blame] | 116 | /* cached handle is not valid, so SMB2_CLOSE won't be sent below */ |
| 117 | close_shroot_lease_locked(&tcon->crfid); |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 118 | memset(tcon->crfid.fid, 0, sizeof(struct cifs_fid)); |
| 119 | mutex_unlock(&tcon->crfid.fid_mutex); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 120 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 121 | /* |
| 122 | * BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 123 | * to this tcon. |
| 124 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 127 | #ifdef CONFIG_CIFS_DFS_UPCALL |
| 128 | static int __cifs_reconnect_tcon(const struct nls_table *nlsc, |
| 129 | struct cifs_tcon *tcon) |
| 130 | { |
| 131 | int rc; |
| 132 | struct dfs_cache_tgt_list tl; |
| 133 | struct dfs_cache_tgt_iterator *it = NULL; |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 134 | char *tree; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 135 | const char *tcp_host; |
| 136 | size_t tcp_host_len; |
| 137 | const char *dfs_host; |
| 138 | size_t dfs_host_len; |
| 139 | |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 140 | tree = kzalloc(MAX_TREE_SIZE, GFP_KERNEL); |
| 141 | if (!tree) |
| 142 | return -ENOMEM; |
| 143 | |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 144 | if (tcon->ipc) { |
Ronnie Sahlberg | 74ea5f9 | 2019-02-09 09:51:11 +1000 | [diff] [blame] | 145 | scnprintf(tree, MAX_TREE_SIZE, "\\\\%s\\IPC$", |
| 146 | tcon->ses->server->hostname); |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 147 | rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc); |
| 148 | goto out; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 149 | } |
| 150 | |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 151 | if (!tcon->dfs_path) { |
| 152 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, tcon, nlsc); |
| 153 | goto out; |
| 154 | } |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 155 | |
| 156 | rc = dfs_cache_noreq_find(tcon->dfs_path + 1, NULL, &tl); |
| 157 | if (rc) |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 158 | goto out; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 159 | |
| 160 | extract_unc_hostname(tcon->ses->server->hostname, &tcp_host, |
| 161 | &tcp_host_len); |
| 162 | |
| 163 | for (it = dfs_cache_get_tgt_iterator(&tl); it; |
| 164 | it = dfs_cache_get_next_tgt(&tl, it)) { |
Paulo Alcantara (SUSE) | bacd704 | 2020-02-20 19:49:34 -0300 | [diff] [blame] | 165 | const char *share, *prefix; |
| 166 | size_t share_len, prefix_len; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 167 | |
Paulo Alcantara (SUSE) | bacd704 | 2020-02-20 19:49:34 -0300 | [diff] [blame] | 168 | rc = dfs_cache_get_tgt_share(it, &share, &share_len, &prefix, |
| 169 | &prefix_len); |
| 170 | if (rc) { |
| 171 | cifs_dbg(VFS, "%s: failed to parse target share %d\n", |
| 172 | __func__, rc); |
| 173 | continue; |
| 174 | } |
| 175 | |
| 176 | extract_unc_hostname(share, &dfs_host, &dfs_host_len); |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 177 | |
| 178 | if (dfs_host_len != tcp_host_len |
| 179 | || strncasecmp(dfs_host, tcp_host, dfs_host_len) != 0) { |
| 180 | cifs_dbg(FYI, "%s: skipping %.*s, doesn't match %.*s", |
| 181 | __func__, |
| 182 | (int)dfs_host_len, dfs_host, |
| 183 | (int)tcp_host_len, tcp_host); |
| 184 | continue; |
| 185 | } |
| 186 | |
Paulo Alcantara (SUSE) | bacd704 | 2020-02-20 19:49:34 -0300 | [diff] [blame] | 187 | scnprintf(tree, MAX_TREE_SIZE, "\\%.*s", (int)share_len, share); |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 188 | |
| 189 | rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc); |
Paulo Alcantara (SUSE) | bacd704 | 2020-02-20 19:49:34 -0300 | [diff] [blame] | 190 | if (!rc) { |
| 191 | rc = update_super_prepath(tcon, prefix, prefix_len); |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 192 | break; |
Paulo Alcantara (SUSE) | bacd704 | 2020-02-20 19:49:34 -0300 | [diff] [blame] | 193 | } |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 194 | if (rc == -EREMOTE) |
| 195 | break; |
| 196 | } |
| 197 | |
| 198 | if (!rc) { |
| 199 | if (it) |
| 200 | rc = dfs_cache_noreq_update_tgthint(tcon->dfs_path + 1, |
| 201 | it); |
| 202 | else |
| 203 | rc = -ENOENT; |
| 204 | } |
| 205 | dfs_cache_free_tgts(&tl); |
Aurelien Aptel | 15bc77f | 2019-01-08 13:41:00 +0100 | [diff] [blame] | 206 | out: |
| 207 | kfree(tree); |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 208 | return rc; |
| 209 | } |
| 210 | #else |
| 211 | static inline int __cifs_reconnect_tcon(const struct nls_table *nlsc, |
| 212 | struct cifs_tcon *tcon) |
| 213 | { |
| 214 | return CIFSTCon(0, tcon->ses, tcon->treeName, tcon, nlsc); |
| 215 | } |
| 216 | #endif |
| 217 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 218 | /* reconnect the socket, tcon, and smb session if needed */ |
| 219 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 220 | cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 221 | { |
Jeff Layton | c4a5534 | 2011-07-28 12:40:36 -0400 | [diff] [blame] | 222 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 223 | struct cifs_ses *ses; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 224 | struct TCP_Server_Info *server; |
| 225 | struct nls_table *nls_codepage; |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 226 | int retries; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 227 | |
| 228 | /* |
| 229 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 230 | * tcp and smb session status done differently for those three - in the |
| 231 | * calling routine |
| 232 | */ |
| 233 | if (!tcon) |
| 234 | return 0; |
| 235 | |
| 236 | ses = tcon->ses; |
| 237 | server = ses->server; |
| 238 | |
| 239 | /* |
| 240 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 241 | * have tcon) are allowed as we start force umount |
| 242 | */ |
| 243 | if (tcon->tidStatus == CifsExiting) { |
| 244 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 245 | smb_command != SMB_COM_OPEN_ANDX && |
| 246 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 247 | cifs_dbg(FYI, "can not send cmd %d while umounting\n", |
| 248 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 249 | return -ENODEV; |
| 250 | } |
| 251 | } |
| 252 | |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 253 | retries = server->nr_targets; |
| 254 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 255 | /* |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 256 | * Give demultiplex thread up to 10 seconds to each target available for |
| 257 | * reconnect -- should be greater than cifs socket timeout which is 7 |
| 258 | * seconds. |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 259 | */ |
| 260 | while (server->tcpStatus == CifsNeedReconnect) { |
Paulo Alcantara | 7ffbe65 | 2018-07-05 13:46:34 -0300 | [diff] [blame] | 261 | rc = wait_event_interruptible_timeout(server->response_q, |
| 262 | (server->tcpStatus != CifsNeedReconnect), |
| 263 | 10 * HZ); |
| 264 | if (rc < 0) { |
| 265 | cifs_dbg(FYI, "%s: aborting reconnect due to a received" |
| 266 | " signal by the process\n", __func__); |
| 267 | return -ERESTARTSYS; |
| 268 | } |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 269 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 270 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 271 | if (server->tcpStatus != CifsNeedReconnect) |
| 272 | break; |
| 273 | |
Ronnie Sahlberg | 09c40b1 | 2020-02-06 13:55:19 +1000 | [diff] [blame] | 274 | if (retries && --retries) |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 275 | continue; |
| 276 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 277 | /* |
| 278 | * on "soft" mounts we wait once. Hard mounts keep |
| 279 | * retrying until process is killed or server comes |
| 280 | * back on-line |
| 281 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 282 | if (!tcon->retry) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 283 | cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 284 | return -EHOSTDOWN; |
| 285 | } |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 286 | retries = server->nr_targets; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 290 | return 0; |
| 291 | |
| 292 | nls_codepage = load_nls_default(); |
| 293 | |
| 294 | /* |
| 295 | * need to prevent multiple threads trying to simultaneously |
| 296 | * reconnect the same SMB session |
| 297 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 298 | mutex_lock(&ses->session_mutex); |
Samuel Cabrero | 76e7527 | 2017-07-11 12:44:39 +0200 | [diff] [blame] | 299 | |
| 300 | /* |
| 301 | * Recheck after acquire mutex. If another thread is negotiating |
| 302 | * and the server never sends an answer the socket will be closed |
| 303 | * and tcpStatus set to reconnect. |
| 304 | */ |
| 305 | if (server->tcpStatus == CifsNeedReconnect) { |
| 306 | rc = -EHOSTDOWN; |
| 307 | mutex_unlock(&ses->session_mutex); |
| 308 | goto out; |
| 309 | } |
| 310 | |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 311 | rc = cifs_negotiate_protocol(0, ses); |
| 312 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 313 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 314 | |
| 315 | /* do we need to reconnect tcon? */ |
| 316 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 317 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 318 | goto out; |
| 319 | } |
| 320 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 321 | cifs_mark_open_files_invalid(tcon); |
Paulo Alcantara | 0874401 | 2018-11-14 17:24:29 -0200 | [diff] [blame] | 322 | rc = __cifs_reconnect_tcon(nls_codepage, tcon); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 323 | mutex_unlock(&ses->session_mutex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 324 | cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 325 | |
Steve French | c318e6c | 2018-04-04 14:08:52 -0500 | [diff] [blame] | 326 | if (rc) { |
| 327 | printk_once(KERN_WARNING "reconnect tcon failed rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 328 | goto out; |
Steve French | c318e6c | 2018-04-04 14:08:52 -0500 | [diff] [blame] | 329 | } |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 330 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 331 | atomic_inc(&tconInfoReconnectCount); |
| 332 | |
| 333 | /* tell server Unix caps we support */ |
Stefan Metzmacher | 864138c | 2020-02-24 14:15:00 +0100 | [diff] [blame] | 334 | if (cap_unix(ses)) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 335 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 336 | |
| 337 | /* |
| 338 | * Removed call to reopen open files here. It is safer (and faster) to |
| 339 | * reopen files one at a time as needed in read and write. |
| 340 | * |
| 341 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 342 | */ |
| 343 | |
| 344 | out: |
| 345 | /* |
| 346 | * Check if handle based operation so we know whether we can continue |
| 347 | * or not without returning to caller to reset file handle |
| 348 | */ |
| 349 | switch (smb_command) { |
| 350 | case SMB_COM_READ_ANDX: |
| 351 | case SMB_COM_WRITE_ANDX: |
| 352 | case SMB_COM_CLOSE: |
| 353 | case SMB_COM_FIND_CLOSE2: |
| 354 | case SMB_COM_LOCKING_ANDX: |
| 355 | rc = -EAGAIN; |
| 356 | } |
| 357 | |
| 358 | unload_nls(nls_codepage); |
| 359 | return rc; |
| 360 | } |
| 361 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 362 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 363 | SMB information in the SMB header. If the return code is zero, this |
| 364 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 366 | small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 367 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 369 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 371 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 372 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return rc; |
| 374 | |
| 375 | *request_buf = cifs_small_buf_get(); |
| 376 | if (*request_buf == NULL) { |
| 377 | /* BB should we add a retry in here if not a writepage? */ |
| 378 | return -ENOMEM; |
| 379 | } |
| 380 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 381 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 382 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 384 | if (tcon != NULL) |
| 385 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 386 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 387 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 390 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 391 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 392 | struct cifs_ses *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 393 | { |
| 394 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 395 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 396 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 397 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 398 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 399 | return rc; |
| 400 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 401 | buffer = (struct smb_hdr *)*request_buf; |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 402 | buffer->Mid = get_next_mid(ses->server); |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 403 | if (ses->capabilities & CAP_UNICODE) |
| 404 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 405 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 406 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 407 | |
| 408 | /* uid, tid can stay at zero as set in header assemble */ |
| 409 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 410 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 411 | this function is used after 1st of session setup requests */ |
| 412 | |
| 413 | return rc; |
| 414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
| 416 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 417 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 418 | __smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 419 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | *request_buf = cifs_buf_get(); |
| 422 | if (*request_buf == NULL) { |
| 423 | /* BB should we add a retry in here if not a writepage? */ |
| 424 | return -ENOMEM; |
| 425 | } |
| 426 | /* Although the original thought was we needed the response buf for */ |
| 427 | /* potential retries of smb operations it turns out we can determine */ |
| 428 | /* from the mid flags when the request buffer can be resent without */ |
| 429 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 430 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 431 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 434 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 436 | if (tcon != NULL) |
| 437 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 438 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 443 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 444 | smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 445 | void **request_buf, void **response_buf) |
| 446 | { |
| 447 | int rc; |
| 448 | |
| 449 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 450 | if (rc) |
| 451 | return rc; |
| 452 | |
| 453 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 454 | } |
| 455 | |
| 456 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 457 | 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] | 458 | void **request_buf, void **response_buf) |
| 459 | { |
| 460 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 461 | return -EHOSTDOWN; |
| 462 | |
| 463 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 466 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 468 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 470 | /* check for plausible wct */ |
| 471 | if (pSMB->hdr.WordCount < 10) |
| 472 | goto vt2_err; |
| 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 475 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 476 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 477 | goto vt2_err; |
| 478 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 479 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 480 | if (total_size >= 512) |
| 481 | goto vt2_err; |
| 482 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 483 | /* check that bcc is at least as big as parms + data, and that it is |
| 484 | * less than negotiated smb buffer |
| 485 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 486 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 487 | if (total_size > get_bcc(&pSMB->hdr) || |
| 488 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 489 | goto vt2_err; |
| 490 | |
| 491 | return 0; |
| 492 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 493 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 495 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 497 | |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 498 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 499 | decode_ext_sec_blob(struct cifs_ses *ses, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 500 | { |
| 501 | int rc = 0; |
| 502 | u16 count; |
| 503 | char *guid = pSMBr->u.extended_response.GUID; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 504 | struct TCP_Server_Info *server = ses->server; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 505 | |
| 506 | count = get_bcc(&pSMBr->hdr); |
| 507 | if (count < SMB1_CLIENT_GUID_SIZE) |
| 508 | return -EIO; |
| 509 | |
| 510 | spin_lock(&cifs_tcp_ses_lock); |
| 511 | if (server->srv_count > 1) { |
| 512 | spin_unlock(&cifs_tcp_ses_lock); |
| 513 | if (memcmp(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE) != 0) { |
| 514 | cifs_dbg(FYI, "server UID changed\n"); |
| 515 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 516 | } |
| 517 | } else { |
| 518 | spin_unlock(&cifs_tcp_ses_lock); |
| 519 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 520 | } |
| 521 | |
| 522 | if (count == SMB1_CLIENT_GUID_SIZE) { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 523 | server->sec_ntlmssp = true; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 524 | } else { |
| 525 | count -= SMB1_CLIENT_GUID_SIZE; |
| 526 | rc = decode_negTokenInit( |
| 527 | pSMBr->u.extended_response.SecurityBlob, count, server); |
| 528 | if (rc != 1) |
| 529 | return -EINVAL; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 535 | int |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 536 | cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required) |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 537 | { |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 538 | bool srv_sign_required = server->sec_mode & server->vals->signing_required; |
| 539 | bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled; |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 540 | bool mnt_sign_enabled = global_secflags & CIFSSEC_MAY_SIGN; |
| 541 | |
| 542 | /* |
| 543 | * Is signing required by mnt options? If not then check |
| 544 | * global_secflags to see if it is there. |
| 545 | */ |
| 546 | if (!mnt_sign_required) |
| 547 | mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) == |
| 548 | CIFSSEC_MUST_SIGN); |
| 549 | |
| 550 | /* |
| 551 | * If signing is required then it's automatically enabled too, |
| 552 | * otherwise, check to see if the secflags allow it. |
| 553 | */ |
| 554 | mnt_sign_enabled = mnt_sign_required ? mnt_sign_required : |
| 555 | (global_secflags & CIFSSEC_MAY_SIGN); |
| 556 | |
| 557 | /* If server requires signing, does client allow it? */ |
| 558 | if (srv_sign_required) { |
| 559 | if (!mnt_sign_enabled) { |
| 560 | cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!"); |
| 561 | return -ENOTSUPP; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 562 | } |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 563 | server->sign = true; |
| 564 | } |
| 565 | |
| 566 | /* If client requires signing, does server allow it? */ |
| 567 | if (mnt_sign_required) { |
| 568 | if (!srv_sign_enabled) { |
| 569 | cifs_dbg(VFS, "Server does not support signing!"); |
| 570 | return -ENOTSUPP; |
| 571 | } |
| 572 | server->sign = true; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Long Li | bb4c041 | 2018-04-17 12:17:08 -0700 | [diff] [blame] | 575 | if (cifs_rdma_enabled(server) && server->sign) |
| 576 | cifs_dbg(VFS, "Signing is enabled, and RDMA read/write will be disabled"); |
| 577 | |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 578 | return 0; |
| 579 | } |
| 580 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 581 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 582 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 583 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 584 | { |
| 585 | __s16 tmp; |
| 586 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
| 587 | |
| 588 | if (server->dialect != LANMAN_PROT && server->dialect != LANMAN2_PROT) |
| 589 | return -EOPNOTSUPP; |
| 590 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 591 | server->sec_mode = le16_to_cpu(rsp->SecurityMode); |
| 592 | server->maxReq = min_t(unsigned int, |
| 593 | le16_to_cpu(rsp->MaxMpxCount), |
| 594 | cifs_max_pending); |
| 595 | set_credits(server, server->maxReq); |
| 596 | server->maxBuf = le16_to_cpu(rsp->MaxBufSize); |
Jones Syue | 1f641d9 | 2020-04-13 09:37:23 +0800 | [diff] [blame] | 597 | /* set up max_read for readpages check */ |
| 598 | server->max_read = server->maxBuf; |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 599 | /* even though we do not use raw we might as well set this |
| 600 | accurately, in case we ever find a need for it */ |
| 601 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
| 602 | server->max_rw = 0xFF00; |
| 603 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 604 | } else { |
| 605 | server->max_rw = 0;/* do not need to use raw anyway */ |
| 606 | server->capabilities = CAP_MPX_MODE; |
| 607 | } |
| 608 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
| 609 | if (tmp == -1) { |
| 610 | /* OS/2 often does not set timezone therefore |
| 611 | * we must use server time to calc time zone. |
| 612 | * Could deviate slightly from the right zone. |
| 613 | * Smallest defined timezone difference is 15 minutes |
| 614 | * (i.e. Nepal). Rounding up/down is done to match |
| 615 | * this requirement. |
| 616 | */ |
| 617 | int val, seconds, remain, result; |
Arnd Bergmann | 9539020 | 2018-06-19 17:27:58 +0200 | [diff] [blame] | 618 | struct timespec64 ts; |
| 619 | time64_t utc = ktime_get_real_seconds(); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 620 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 621 | rsp->SrvTime.Time, 0); |
Arnd Bergmann | 9539020 | 2018-06-19 17:27:58 +0200 | [diff] [blame] | 622 | cifs_dbg(FYI, "SrvTime %lld sec since 1970 (utc: %lld) diff: %lld\n", |
| 623 | ts.tv_sec, utc, |
| 624 | utc - ts.tv_sec); |
Deepa Dinamani | e37fea5 | 2017-05-08 15:59:16 -0700 | [diff] [blame] | 625 | val = (int)(utc - ts.tv_sec); |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 626 | seconds = abs(val); |
| 627 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
| 628 | remain = seconds % MIN_TZ_ADJ; |
| 629 | if (remain >= (MIN_TZ_ADJ / 2)) |
| 630 | result += MIN_TZ_ADJ; |
| 631 | if (val < 0) |
| 632 | result = -result; |
| 633 | server->timeAdj = result; |
| 634 | } else { |
| 635 | server->timeAdj = (int)tmp; |
| 636 | server->timeAdj *= 60; /* also in seconds */ |
| 637 | } |
| 638 | cifs_dbg(FYI, "server->timeAdj: %d seconds\n", server->timeAdj); |
| 639 | |
| 640 | |
| 641 | /* BB get server time for time conversions and add |
| 642 | code to use it and timezone since this is not UTC */ |
| 643 | |
| 644 | if (rsp->EncryptionKeyLength == |
| 645 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
| 646 | memcpy(server->cryptkey, rsp->EncryptionKey, |
| 647 | CIFS_CRYPTO_KEY_SIZE); |
| 648 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
| 649 | return -EIO; /* need cryptkey unless plain text */ |
| 650 | } |
| 651 | |
| 652 | cifs_dbg(FYI, "LANMAN negotiated\n"); |
| 653 | return 0; |
| 654 | } |
| 655 | #else |
| 656 | static inline int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 657 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 658 | { |
| 659 | cifs_dbg(VFS, "mount failed, cifs module not built with CIFS_WEAK_PW_HASH support\n"); |
| 660 | return -EOPNOTSUPP; |
| 661 | } |
| 662 | #endif |
| 663 | |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 664 | static bool |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 665 | should_set_ext_sec_flag(enum securityEnum sectype) |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 666 | { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 667 | switch (sectype) { |
| 668 | case RawNTLMSSP: |
| 669 | case Kerberos: |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 670 | return true; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 671 | case Unspecified: |
| 672 | if (global_secflags & |
| 673 | (CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)) |
| 674 | return true; |
| 675 | /* Fallthrough */ |
| 676 | default: |
| 677 | return false; |
| 678 | } |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 679 | } |
| 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | int |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 682 | CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { |
| 684 | NEGOTIATE_REQ *pSMB; |
| 685 | NEGOTIATE_RSP *pSMBr; |
| 686 | int rc = 0; |
| 687 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 688 | int i; |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 689 | struct TCP_Server_Info *server = ses->server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | u16 count; |
| 691 | |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 692 | if (!server) { |
| 693 | WARN(1, "%s: server is NULL!\n", __func__); |
| 694 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 698 | (void **) &pSMB, (void **) &pSMBr); |
| 699 | if (rc) |
| 700 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 701 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 702 | pSMB->hdr.Mid = get_next_mid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 703 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 704 | |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 705 | if (should_set_ext_sec_flag(ses->sectype)) { |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 706 | cifs_dbg(FYI, "Requesting extended security."); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 707 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 708 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 709 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 710 | count = 0; |
Stephen Rothwell | bcfb84a | 2018-09-03 13:15:58 +1000 | [diff] [blame] | 711 | /* |
| 712 | * We know that all the name entries in the protocols array |
| 713 | * are short (< 16 bytes anyway) and are NUL terminated. |
| 714 | */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 715 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Stephen Rothwell | bcfb84a | 2018-09-03 13:15:58 +1000 | [diff] [blame] | 716 | size_t len = strlen(protocols[i].name) + 1; |
| 717 | |
| 718 | memcpy(pSMB->DialectsArray+count, protocols[i].name, len); |
| 719 | count += len; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 720 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 721 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | pSMB->ByteCount = cpu_to_le16(count); |
| 723 | |
| 724 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 725 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 726 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 727 | goto neg_err_exit; |
| 728 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 729 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 730 | cifs_dbg(FYI, "Dialect: %d\n", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 731 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 732 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 733 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 734 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 735 | could not negotiate a common dialect */ |
| 736 | rc = -EOPNOTSUPP; |
| 737 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 738 | } else if (pSMBr->hdr.WordCount == 13) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 739 | server->negflavor = CIFS_NEGFLAVOR_LANMAN; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 740 | rc = decode_lanman_negprot_rsp(server, pSMBr); |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 741 | goto signing_check; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 742 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 743 | /* unknown wct */ |
| 744 | rc = -EOPNOTSUPP; |
| 745 | goto neg_err_exit; |
| 746 | } |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 747 | /* else wct == 17, NTLM or better */ |
| 748 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 749 | server->sec_mode = pSMBr->SecurityMode; |
| 750 | if ((server->sec_mode & SECMODE_USER) == 0) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 751 | cifs_dbg(FYI, "share mode security\n"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 752 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 753 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 754 | little endian */ |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 755 | server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), |
| 756 | cifs_max_pending); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 757 | set_credits(server, server->maxReq); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 758 | /* probably no need to store and check maxvcs */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 759 | server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); |
Jones Syue | 1f641d9 | 2020-04-13 09:37:23 +0800 | [diff] [blame] | 760 | /* set up max_read for readpages check */ |
| 761 | server->max_read = server->maxBuf; |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 762 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 763 | cifs_dbg(NOISY, "Max buf = %d\n", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 764 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 765 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 766 | server->timeAdj *= 60; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 767 | |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 768 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
| 769 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 770 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 771 | CIFS_CRYPTO_KEY_SIZE); |
Noel Power | f291095 | 2015-05-27 09:22:10 +0100 | [diff] [blame] | 772 | } else if (pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC || |
| 773 | server->capabilities & CAP_EXTENDED_SECURITY) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 774 | server->negflavor = CIFS_NEGFLAVOR_EXTENDED; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 775 | rc = decode_ext_sec_blob(ses, pSMBr); |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 776 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 777 | rc = -EIO; /* no crypt key only if plain text pwd */ |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 778 | } else { |
| 779 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 780 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 781 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 782 | |
| 783 | signing_check: |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 784 | if (!rc) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 785 | rc = cifs_enable_signing(server, ses->sign); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 786 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 787 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 788 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 789 | cifs_dbg(FYI, "negprot rc %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | return rc; |
| 791 | } |
| 792 | |
| 793 | int |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 794 | CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
| 796 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 799 | cifs_dbg(FYI, "In tree disconnect\n"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 800 | |
| 801 | /* BB: do we need to check this? These should never be NULL. */ |
| 802 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 803 | return -EIO; |
| 804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 806 | * No need to return error on this operation if tid invalidated and |
| 807 | * closed on server already e.g. due to tcp session crashing. Also, |
| 808 | * the tcon is no longer on the list, so no need to take lock before |
| 809 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 811 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 812 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 814 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 815 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 816 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 818 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 819 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 820 | cifs_small_buf_release(smb_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 822 | cifs_dbg(FYI, "Tree disconnect failed %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 824 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 825 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | if (rc == -EAGAIN) |
| 827 | rc = 0; |
| 828 | |
| 829 | return rc; |
| 830 | } |
| 831 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 832 | /* |
| 833 | * This is a no-op for now. We're not really interested in the reply, but |
| 834 | * rather in the fact that the server sent one and that server->lstrp |
| 835 | * gets updated. |
| 836 | * |
| 837 | * FIXME: maybe we should consider checking that the reply matches request? |
| 838 | */ |
| 839 | static void |
| 840 | cifs_echo_callback(struct mid_q_entry *mid) |
| 841 | { |
| 842 | struct TCP_Server_Info *server = mid->callback_data; |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 843 | struct cifs_credits credits = { .value = 1, .instance = 0 }; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 844 | |
| 845 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 846 | add_credits(server, &credits, CIFS_ECHO_OP); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | int |
| 850 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 851 | { |
| 852 | ECHO_REQ *smb; |
| 853 | int rc = 0; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 854 | struct kvec iov[2]; |
| 855 | struct smb_rqst rqst = { .rq_iov = iov, |
| 856 | .rq_nvec = 2 }; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 857 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 858 | cifs_dbg(FYI, "In echo request\n"); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 859 | |
| 860 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 861 | if (rc) |
| 862 | return rc; |
| 863 | |
Steve French | 26c9cb6 | 2017-05-02 13:35:20 -0500 | [diff] [blame] | 864 | if (server->capabilities & CAP_UNICODE) |
| 865 | smb->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 866 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 867 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 868 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8f | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 869 | smb->hdr.WordCount = 1; |
| 870 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 871 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 872 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 873 | inc_rfc1001_len(smb, 3); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 874 | |
| 875 | iov[0].iov_len = 4; |
| 876 | iov[0].iov_base = smb; |
| 877 | iov[1].iov_len = get_rfc1002_length(smb); |
| 878 | iov[1].iov_base = (char *)smb + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 879 | |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 880 | rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, NULL, |
Ronnie Sahlberg | 392e1c5 | 2019-05-06 10:00:02 +1000 | [diff] [blame] | 881 | server, CIFS_NON_BLOCKING | CIFS_ECHO_OP, NULL); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 882 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 883 | cifs_dbg(FYI, "Echo request failed: %d\n", rc); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 884 | |
| 885 | cifs_small_buf_release(smb); |
| 886 | |
| 887 | return rc; |
| 888 | } |
| 889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | int |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 891 | CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | LOGOFF_ANDX_REQ *pSMB; |
| 894 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 896 | cifs_dbg(FYI, "In SMBLogoff for session disconnect\n"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 897 | |
| 898 | /* |
| 899 | * BB: do we need to check validity of ses and server? They should |
| 900 | * always be valid since we have an active reference. If not, that |
| 901 | * should probably be a BUG() |
| 902 | */ |
| 903 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | return -EIO; |
| 905 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 906 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 907 | if (ses->need_reconnect) |
| 908 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 909 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 911 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 912 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | return rc; |
| 914 | } |
| 915 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 916 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 917 | |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 918 | if (ses->server->sign) |
| 919 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
| 921 | pSMB->hdr.Uid = ses->Suid; |
| 922 | |
| 923 | pSMB->AndXCommand = 0xFF; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 924 | rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 925 | cifs_small_buf_release(pSMB); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 926 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 927 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
| 929 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 930 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | error */ |
| 932 | if (rc == -EAGAIN) |
| 933 | rc = 0; |
| 934 | return rc; |
| 935 | } |
| 936 | |
| 937 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 938 | CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, |
| 939 | const char *fileName, __u16 type, |
| 940 | const struct nls_table *nls_codepage, int remap) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 941 | { |
| 942 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 943 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 944 | struct unlink_psx_rq *pRqD; |
| 945 | int name_len; |
| 946 | int rc = 0; |
| 947 | int bytes_returned = 0; |
| 948 | __u16 params, param_offset, offset, byte_count; |
| 949 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 950 | cifs_dbg(FYI, "In POSIX delete\n"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 951 | PsxDelete: |
| 952 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 953 | (void **) &pSMBr); |
| 954 | if (rc) |
| 955 | return rc; |
| 956 | |
| 957 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 958 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 959 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 960 | PATH_MAX, nls_codepage, remap); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 961 | name_len++; /* trailing null */ |
| 962 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 963 | } else { |
| 964 | name_len = copy_path_name(pSMB->FileName, fileName); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | params = 6 + name_len; |
| 968 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 969 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 970 | pSMB->MaxSetupCount = 0; |
| 971 | pSMB->Reserved = 0; |
| 972 | pSMB->Flags = 0; |
| 973 | pSMB->Timeout = 0; |
| 974 | pSMB->Reserved2 = 0; |
| 975 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 976 | InformationLevel) - 4; |
| 977 | offset = param_offset + params; |
| 978 | |
| 979 | /* Setup pointer to Request Data (inode type) */ |
| 980 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 981 | pRqD->type = cpu_to_le16(type); |
| 982 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 983 | pSMB->DataOffset = cpu_to_le16(offset); |
| 984 | pSMB->SetupCount = 1; |
| 985 | pSMB->Reserved3 = 0; |
| 986 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 987 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 988 | |
| 989 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 990 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 991 | pSMB->ParameterCount = cpu_to_le16(params); |
| 992 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 993 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 994 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 995 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 996 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 997 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 998 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 999 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1000 | cifs_dbg(FYI, "Posix delete returned %d\n", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 1001 | cifs_buf_release(pSMB); |
| 1002 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1003 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 1004 | |
| 1005 | if (rc == -EAGAIN) |
| 1006 | goto PsxDelete; |
| 1007 | |
| 1008 | return rc; |
| 1009 | } |
| 1010 | |
| 1011 | int |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 1012 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 1013 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | { |
| 1015 | DELETE_FILE_REQ *pSMB = NULL; |
| 1016 | DELETE_FILE_RSP *pSMBr = NULL; |
| 1017 | int rc = 0; |
| 1018 | int bytes_returned; |
| 1019 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1020 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
| 1022 | DelFileRetry: |
| 1023 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 1024 | (void **) &pSMBr); |
| 1025 | if (rc) |
| 1026 | return rc; |
| 1027 | |
| 1028 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 1029 | name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name, |
| 1030 | PATH_MAX, cifs_sb->local_nls, |
| 1031 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | name_len++; /* trailing null */ |
| 1033 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1034 | } else { |
| 1035 | name_len = copy_path_name(pSMB->fileName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | } |
| 1037 | pSMB->SearchAttributes = |
| 1038 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 1039 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1040 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1042 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1043 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1044 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1045 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1046 | cifs_dbg(FYI, "Error in RMFile = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
| 1048 | cifs_buf_release(pSMB); |
| 1049 | if (rc == -EAGAIN) |
| 1050 | goto DelFileRetry; |
| 1051 | |
| 1052 | return rc; |
| 1053 | } |
| 1054 | |
| 1055 | int |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 1056 | CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 1057 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | { |
| 1059 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 1060 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 1061 | int rc = 0; |
| 1062 | int bytes_returned; |
| 1063 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1064 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1066 | cifs_dbg(FYI, "In CIFSSMBRmDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | RmDirRetry: |
| 1068 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 1069 | (void **) &pSMBr); |
| 1070 | if (rc) |
| 1071 | return rc; |
| 1072 | |
| 1073 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 1074 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
| 1075 | PATH_MAX, cifs_sb->local_nls, |
| 1076 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | name_len++; /* trailing null */ |
| 1078 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1079 | } else { |
| 1080 | name_len = copy_path_name(pSMB->DirName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1084 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1086 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1087 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1088 | cifs_stats_inc(&tcon->stats.cifs_stats.num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1089 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1090 | cifs_dbg(FYI, "Error in RMDir = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
| 1092 | cifs_buf_release(pSMB); |
| 1093 | if (rc == -EAGAIN) |
| 1094 | goto RmDirRetry; |
| 1095 | return rc; |
| 1096 | } |
| 1097 | |
| 1098 | int |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 1099 | CIFSSMBMkDir(const unsigned int xid, struct inode *inode, umode_t mode, |
| 1100 | struct cifs_tcon *tcon, const char *name, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 1101 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | { |
| 1103 | int rc = 0; |
| 1104 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 1105 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 1106 | int bytes_returned; |
| 1107 | int name_len; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1108 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1110 | cifs_dbg(FYI, "In CIFSSMBMkDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | MkDirRetry: |
| 1112 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 1113 | (void **) &pSMBr); |
| 1114 | if (rc) |
| 1115 | return rc; |
| 1116 | |
| 1117 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1118 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 1119 | PATH_MAX, cifs_sb->local_nls, |
| 1120 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | name_len++; /* trailing null */ |
| 1122 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1123 | } else { |
| 1124 | name_len = copy_path_name(pSMB->DirName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1128 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1130 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1131 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1132 | cifs_stats_inc(&tcon->stats.cifs_stats.num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1133 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1134 | cifs_dbg(FYI, "Error in Mkdir = %d\n", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | cifs_buf_release(pSMB); |
| 1137 | if (rc == -EAGAIN) |
| 1138 | goto MkDirRetry; |
| 1139 | return rc; |
| 1140 | } |
| 1141 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1142 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1143 | CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, |
| 1144 | __u32 posix_flags, __u64 mode, __u16 *netfid, |
| 1145 | FILE_UNIX_BASIC_INFO *pRetData, __u32 *pOplock, |
| 1146 | const char *name, const struct nls_table *nls_codepage, |
| 1147 | int remap) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1148 | { |
| 1149 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1150 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1151 | int name_len; |
| 1152 | int rc = 0; |
| 1153 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1154 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1155 | OPEN_PSX_REQ *pdata; |
| 1156 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1157 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1158 | cifs_dbg(FYI, "In POSIX Create\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1159 | PsxCreat: |
| 1160 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1161 | (void **) &pSMBr); |
| 1162 | if (rc) |
| 1163 | return rc; |
| 1164 | |
| 1165 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1166 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1167 | cifsConvertToUTF16((__le16 *) pSMB->FileName, name, |
| 1168 | PATH_MAX, nls_codepage, remap); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1169 | name_len++; /* trailing null */ |
| 1170 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1171 | } else { |
| 1172 | name_len = copy_path_name(pSMB->FileName, name); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | params = 6 + name_len; |
| 1176 | count = sizeof(OPEN_PSX_REQ); |
| 1177 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1178 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1179 | pSMB->MaxSetupCount = 0; |
| 1180 | pSMB->Reserved = 0; |
| 1181 | pSMB->Flags = 0; |
| 1182 | pSMB->Timeout = 0; |
| 1183 | pSMB->Reserved2 = 0; |
| 1184 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1185 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1186 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1187 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1188 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1189 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1190 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1191 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1192 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1193 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1194 | pSMB->SetupCount = 1; |
| 1195 | pSMB->Reserved3 = 0; |
| 1196 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1197 | byte_count = 3 /* pad */ + params + count; |
| 1198 | |
| 1199 | pSMB->DataCount = cpu_to_le16(count); |
| 1200 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1201 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1202 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1203 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1204 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1205 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1206 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1207 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1208 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1209 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1210 | cifs_dbg(FYI, "Posix create returned %d\n", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1211 | goto psx_create_err; |
| 1212 | } |
| 1213 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1214 | cifs_dbg(FYI, "copying inode info\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1215 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1216 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1217 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1218 | rc = -EIO; /* bad smb */ |
| 1219 | goto psx_create_err; |
| 1220 | } |
| 1221 | |
| 1222 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1223 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1224 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1225 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1226 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1227 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1228 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1229 | /* Let caller know file was created so we can set the mode. */ |
| 1230 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1231 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1232 | *pOplock |= CIFS_CREATE_ACTION; |
| 1233 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1234 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1235 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1236 | cifs_dbg(NOISY, "unknown type\n"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1237 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1238 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1239 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1240 | cifs_dbg(VFS, "Open response data too small\n"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1241 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1242 | goto psx_create_err; |
| 1243 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1244 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1245 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1246 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1247 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1248 | |
| 1249 | psx_create_err: |
| 1250 | cifs_buf_release(pSMB); |
| 1251 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1252 | if (posix_flags & SMB_O_DIRECTORY) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1253 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixmkdirs); |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1254 | else |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1255 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1256 | |
| 1257 | if (rc == -EAGAIN) |
| 1258 | goto PsxCreat; |
| 1259 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1260 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1263 | static __u16 convert_disposition(int disposition) |
| 1264 | { |
| 1265 | __u16 ofun = 0; |
| 1266 | |
| 1267 | switch (disposition) { |
| 1268 | case FILE_SUPERSEDE: |
| 1269 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1270 | break; |
| 1271 | case FILE_OPEN: |
| 1272 | ofun = SMBOPEN_OAPPEND; |
| 1273 | break; |
| 1274 | case FILE_CREATE: |
| 1275 | ofun = SMBOPEN_OCREATE; |
| 1276 | break; |
| 1277 | case FILE_OPEN_IF: |
| 1278 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1279 | break; |
| 1280 | case FILE_OVERWRITE: |
| 1281 | ofun = SMBOPEN_OTRUNC; |
| 1282 | break; |
| 1283 | case FILE_OVERWRITE_IF: |
| 1284 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1285 | break; |
| 1286 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1287 | cifs_dbg(FYI, "unknown disposition %d\n", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1288 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1289 | } |
| 1290 | return ofun; |
| 1291 | } |
| 1292 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1293 | static int |
| 1294 | access_flags_to_smbopen_mode(const int access_flags) |
| 1295 | { |
| 1296 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1297 | |
| 1298 | if (masked_flags == GENERIC_READ) |
| 1299 | return SMBOPEN_READ; |
| 1300 | else if (masked_flags == GENERIC_WRITE) |
| 1301 | return SMBOPEN_WRITE; |
| 1302 | |
| 1303 | /* just go for read/write */ |
| 1304 | return SMBOPEN_READWRITE; |
| 1305 | } |
| 1306 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1307 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1308 | SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1309 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1310 | const int access_flags, const int create_options, __u16 *netfid, |
| 1311 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1312 | const struct nls_table *nls_codepage, int remap) |
| 1313 | { |
| 1314 | int rc = -EACCES; |
| 1315 | OPENX_REQ *pSMB = NULL; |
| 1316 | OPENX_RSP *pSMBr = NULL; |
| 1317 | int bytes_returned; |
| 1318 | int name_len; |
| 1319 | __u16 count; |
| 1320 | |
| 1321 | OldOpenRetry: |
| 1322 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1323 | (void **) &pSMBr); |
| 1324 | if (rc) |
| 1325 | return rc; |
| 1326 | |
| 1327 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1328 | |
| 1329 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1330 | count = 1; /* account for one byte pad to word boundary */ |
| 1331 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1332 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1333 | fileName, PATH_MAX, nls_codepage, remap); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1334 | name_len++; /* trailing null */ |
| 1335 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1336 | } else { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1337 | count = 0; /* no pad */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1338 | name_len = copy_path_name(pSMB->fileName, fileName); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1339 | } |
| 1340 | if (*pOplock & REQ_OPLOCK) |
| 1341 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1342 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1343 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1344 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1345 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1346 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1347 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1348 | /* set file as system file if special file such |
| 1349 | as fifo and server expecting SFU style and |
| 1350 | no Unix extensions */ |
| 1351 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1352 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1353 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1354 | else /* BB FIXME BB */ |
| 1355 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1356 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1357 | if (create_options & CREATE_OPTION_READONLY) |
| 1358 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1359 | |
| 1360 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1361 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1362 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1363 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1364 | |
| 1365 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1366 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1367 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1368 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1369 | |
| 1370 | pSMB->ByteCount = cpu_to_le16(count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1371 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1372 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1373 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1374 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1375 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1376 | } else { |
| 1377 | /* BB verify if wct == 15 */ |
| 1378 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1379 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1380 | |
| 1381 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1382 | /* Let caller know file was created so we can set the mode. */ |
| 1383 | /* Do we care about the CreateAction in any other cases? */ |
| 1384 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1385 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1386 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1387 | /* BB FIXME END */ |
| 1388 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1389 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1390 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1391 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1392 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1393 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1394 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1395 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1396 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1397 | pfile_info->AllocationSize = |
| 1398 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1399 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1400 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1401 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | cifs_buf_release(pSMB); |
| 1406 | if (rc == -EAGAIN) |
| 1407 | goto OldOpenRetry; |
| 1408 | return rc; |
| 1409 | } |
| 1410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | int |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1412 | CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock, |
| 1413 | FILE_ALL_INFO *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | { |
Colin Ian King | 1afdea4 | 2019-07-23 16:09:19 +0100 | [diff] [blame] | 1415 | int rc; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1416 | OPEN_REQ *req = NULL; |
| 1417 | OPEN_RSP *rsp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | int bytes_returned; |
| 1419 | int name_len; |
| 1420 | __u16 count; |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1421 | struct cifs_sb_info *cifs_sb = oparms->cifs_sb; |
| 1422 | struct cifs_tcon *tcon = oparms->tcon; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1423 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1424 | const struct nls_table *nls = cifs_sb->local_nls; |
| 1425 | int create_options = oparms->create_options; |
| 1426 | int desired_access = oparms->desired_access; |
| 1427 | int disposition = oparms->disposition; |
| 1428 | const char *path = oparms->path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
| 1430 | openRetry: |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1431 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **)&req, |
| 1432 | (void **)&rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | if (rc) |
| 1434 | return rc; |
| 1435 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1436 | /* no commands go after this */ |
| 1437 | req->AndXCommand = 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1439 | if (req->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1440 | /* account for one byte pad to word boundary */ |
| 1441 | count = 1; |
| 1442 | name_len = cifsConvertToUTF16((__le16 *)(req->fileName + 1), |
| 1443 | path, PATH_MAX, nls, remap); |
| 1444 | /* trailing null */ |
| 1445 | name_len++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | name_len *= 2; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1447 | req->NameLength = cpu_to_le16(name_len); |
| 1448 | } else { |
| 1449 | /* BB improve check for buffer overruns BB */ |
| 1450 | /* no pad */ |
| 1451 | count = 0; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 1452 | name_len = copy_path_name(req->fileName, path); |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1453 | req->NameLength = cpu_to_le16(name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | } |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1455 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1456 | if (*oplock & REQ_OPLOCK) |
| 1457 | req->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
| 1458 | else if (*oplock & REQ_BATCHOPLOCK) |
| 1459 | req->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
| 1460 | |
| 1461 | req->DesiredAccess = cpu_to_le32(desired_access); |
| 1462 | req->AllocationSize = 0; |
| 1463 | |
| 1464 | /* |
| 1465 | * Set file as system file if special file such as fifo and server |
| 1466 | * expecting SFU style and no Unix extensions. |
| 1467 | */ |
| 1468 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1469 | req->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1470 | else |
| 1471 | req->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
| 1472 | |
| 1473 | /* |
| 1474 | * XP does not handle ATTR_POSIX_SEMANTICS but it helps speed up case |
| 1475 | * sensitive checks for other servers such as Samba. |
| 1476 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | if (tcon->ses->capabilities & CAP_UNIX) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1478 | req->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1480 | if (create_options & CREATE_OPTION_READONLY) |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1481 | req->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1482 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1483 | req->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1484 | req->CreateDisposition = cpu_to_le32(disposition); |
| 1485 | req->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
| 1486 | |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1487 | /* BB Expirement with various impersonation levels and verify */ |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1488 | req->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
| 1489 | req->SecurityFlags = SECURITY_CONTEXT_TRACKING|SECURITY_EFFECTIVE_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
| 1491 | count += name_len; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1492 | inc_rfc1001_len(req, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1494 | req->ByteCount = cpu_to_le16(count); |
| 1495 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *)req, |
| 1496 | (struct smb_hdr *)rsp, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1497 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1499 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1500 | cifs_buf_release(req); |
| 1501 | if (rc == -EAGAIN) |
| 1502 | goto openRetry; |
| 1503 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1505 | |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1506 | /* 1 byte no need to le_to_cpu */ |
| 1507 | *oplock = rsp->OplockLevel; |
| 1508 | /* cifs fid stays in le */ |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1509 | oparms->fid->netfid = rsp->Fid; |
Aurelien Aptel | 86f740f | 2020-02-21 11:19:06 +0100 | [diff] [blame] | 1510 | oparms->fid->access = desired_access; |
Pavel Shilovsky | 9bf4fa0 | 2014-01-16 15:53:33 +0400 | [diff] [blame] | 1511 | |
| 1512 | /* Let caller know file was created so we can set the mode. */ |
| 1513 | /* Do we care about the CreateAction in any other cases? */ |
| 1514 | if (cpu_to_le32(FILE_CREATE) == rsp->CreateAction) |
| 1515 | *oplock |= CIFS_CREATE_ACTION; |
| 1516 | |
| 1517 | if (buf) { |
| 1518 | /* copy from CreationTime to Attributes */ |
| 1519 | memcpy((char *)buf, (char *)&rsp->CreationTime, 36); |
| 1520 | /* the file_info buf is endian converted by caller */ |
| 1521 | buf->AllocationSize = rsp->AllocationSize; |
| 1522 | buf->EndOfFile = rsp->EndOfFile; |
| 1523 | buf->NumberOfLinks = cpu_to_le32(1); |
| 1524 | buf->DeletePending = 0; |
| 1525 | } |
| 1526 | |
| 1527 | cifs_buf_release(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | return rc; |
| 1529 | } |
| 1530 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1531 | /* |
| 1532 | * Discard any remaining data in the current SMB. To do this, we borrow the |
| 1533 | * current bigbuf. |
| 1534 | */ |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 1535 | int |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1536 | cifs_discard_remaining_data(struct TCP_Server_Info *server) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1537 | { |
Ronnie Sahlberg | 05432e2 | 2018-04-09 18:06:31 +1000 | [diff] [blame] | 1538 | unsigned int rfclen = server->pdu_size; |
| 1539 | int remaining = rfclen + server->vals->header_preamble_size - |
| 1540 | server->total_read; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1541 | |
| 1542 | while (remaining > 0) { |
| 1543 | int length; |
| 1544 | |
| 1545 | length = cifs_read_from_socket(server, server->bigbuf, |
| 1546 | min_t(unsigned int, remaining, |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1547 | CIFSMaxBufSize + MAX_HEADER_SIZE(server))); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1548 | if (length < 0) |
| 1549 | return length; |
| 1550 | server->total_read += length; |
| 1551 | remaining -= length; |
| 1552 | } |
| 1553 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1554 | return 0; |
| 1555 | } |
| 1556 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1557 | static int |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1558 | __cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid, |
| 1559 | bool malformed) |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1560 | { |
| 1561 | int length; |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1562 | |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1563 | length = cifs_discard_remaining_data(server); |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1564 | dequeue_mid(mid, malformed); |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1565 | mid->resp_buf = server->smallbuf; |
| 1566 | server->smallbuf = NULL; |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1567 | return length; |
| 1568 | } |
| 1569 | |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1570 | static int |
| 1571 | cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1572 | { |
| 1573 | struct cifs_readdata *rdata = mid->callback_data; |
| 1574 | |
| 1575 | return __cifs_readv_discard(server, mid, rdata->result); |
| 1576 | } |
| 1577 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1578 | int |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1579 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1580 | { |
| 1581 | int length, len; |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1582 | unsigned int data_offset, data_len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1583 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1584 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 1585 | unsigned int buflen = server->pdu_size + |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 1586 | server->vals->header_preamble_size; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1587 | bool use_rdma_mr = false; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1588 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1589 | cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n", |
| 1590 | __func__, mid->mid, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1591 | |
| 1592 | /* |
| 1593 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1594 | * can if there's not enough data. At this point, we've read down to |
| 1595 | * the Mid. |
| 1596 | */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1597 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1598 | HEADER_SIZE(server) + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1599 | |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1600 | length = cifs_read_from_socket(server, |
| 1601 | buf + HEADER_SIZE(server) - 1, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1602 | if (length < 0) |
| 1603 | return length; |
| 1604 | server->total_read += length; |
| 1605 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1606 | if (server->ops->is_session_expired && |
| 1607 | server->ops->is_session_expired(buf)) { |
| 1608 | cifs_reconnect(server); |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1609 | return -1; |
| 1610 | } |
| 1611 | |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1612 | if (server->ops->is_status_pending && |
Pavel Shilovsky | 66265f1 | 2019-01-23 17:11:16 -0800 | [diff] [blame] | 1613 | server->ops->is_status_pending(buf, server)) { |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1614 | cifs_discard_remaining_data(server); |
Pavel Shilovsky | 6cc3b24 | 2016-02-27 11:58:18 +0300 | [diff] [blame] | 1615 | return -1; |
| 1616 | } |
| 1617 | |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1618 | /* set up first two iov for signature check and to get credits */ |
| 1619 | rdata->iov[0].iov_base = buf; |
Pavel Shilovsky | bb1bccb | 2019-01-17 16:18:38 -0800 | [diff] [blame] | 1620 | rdata->iov[0].iov_len = server->vals->header_preamble_size; |
| 1621 | rdata->iov[1].iov_base = buf + server->vals->header_preamble_size; |
| 1622 | rdata->iov[1].iov_len = |
| 1623 | server->total_read - server->vals->header_preamble_size; |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1624 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 1625 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); |
| 1626 | cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", |
| 1627 | rdata->iov[1].iov_base, rdata->iov[1].iov_len); |
| 1628 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1629 | /* Was the SMB read successful? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1630 | rdata->result = server->ops->map_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1631 | if (rdata->result != 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1632 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 1633 | __func__, rdata->result); |
Pavel Shilovsky | 8004c78 | 2019-01-17 15:29:26 -0800 | [diff] [blame] | 1634 | /* normal error on read response */ |
| 1635 | return __cifs_readv_discard(server, mid, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | /* 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] | 1639 | if (server->total_read < server->vals->read_rsp_size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1640 | cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n", |
| 1641 | __func__, server->total_read, |
| 1642 | server->vals->read_rsp_size); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1643 | rdata->result = -EIO; |
| 1644 | return cifs_readv_discard(server, mid); |
| 1645 | } |
| 1646 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 1647 | data_offset = server->ops->read_data_offset(buf) + |
| 1648 | server->vals->header_preamble_size; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1649 | if (data_offset < server->total_read) { |
| 1650 | /* |
| 1651 | * win2k8 sometimes sends an offset of 0 when the read |
| 1652 | * is beyond the EOF. Treat it as if the data starts just after |
| 1653 | * the header. |
| 1654 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1655 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 1656 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1657 | data_offset = server->total_read; |
| 1658 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1659 | /* data_offset is beyond the end of smallbuf */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1660 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 1661 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1662 | rdata->result = -EIO; |
| 1663 | return cifs_readv_discard(server, mid); |
| 1664 | } |
| 1665 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1666 | cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n", |
| 1667 | __func__, server->total_read, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1668 | |
| 1669 | len = data_offset - server->total_read; |
| 1670 | if (len > 0) { |
| 1671 | /* read any junk before data into the rest of smallbuf */ |
Al Viro | a613730 | 2016-01-09 19:37:16 -0500 | [diff] [blame] | 1672 | length = cifs_read_from_socket(server, |
| 1673 | buf + server->total_read, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1674 | if (length < 0) |
| 1675 | return length; |
| 1676 | server->total_read += length; |
| 1677 | } |
| 1678 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1679 | /* how much data is in the response? */ |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1680 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 1681 | use_rdma_mr = rdata->mr; |
| 1682 | #endif |
| 1683 | data_len = server->ops->read_data_length(buf, use_rdma_mr); |
| 1684 | if (!use_rdma_mr && (data_offset + data_len > buflen)) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1685 | /* data_len is corrupt -- discard frame */ |
| 1686 | rdata->result = -EIO; |
| 1687 | return cifs_readv_discard(server, mid); |
| 1688 | } |
| 1689 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1690 | length = rdata->read_into_pages(server, rdata, data_len); |
| 1691 | if (length < 0) |
| 1692 | return length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1693 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1694 | server->total_read += length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1695 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1696 | cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n", |
| 1697 | server->total_read, buflen, data_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1698 | |
| 1699 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1700 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1701 | return cifs_readv_discard(server, mid); |
| 1702 | |
| 1703 | dequeue_mid(mid, false); |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 1704 | mid->resp_buf = server->smallbuf; |
| 1705 | server->smallbuf = NULL; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1706 | return length; |
| 1707 | } |
| 1708 | |
| 1709 | static void |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1710 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1711 | { |
| 1712 | struct cifs_readdata *rdata = mid->callback_data; |
| 1713 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1714 | struct TCP_Server_Info *server = tcon->ses->server; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1715 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 1716 | .rq_nvec = 2, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1717 | .rq_pages = rdata->pages, |
Long Li | 6d3adb2 | 2018-09-20 21:18:38 +0000 | [diff] [blame] | 1718 | .rq_offset = rdata->page_offset, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1719 | .rq_npages = rdata->nr_pages, |
| 1720 | .rq_pagesz = rdata->pagesz, |
| 1721 | .rq_tailsz = rdata->tailsz }; |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 1722 | struct cifs_credits credits = { .value = 1, .instance = 0 }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1723 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1724 | cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", |
| 1725 | __func__, mid->mid, mid->mid_state, rdata->result, |
| 1726 | rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1727 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1728 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1729 | case MID_RESPONSE_RECEIVED: |
| 1730 | /* result already set, check signature */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 1731 | if (server->sign) { |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1732 | int rc = 0; |
| 1733 | |
Jeff Layton | bf5ea0e | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1734 | rc = cifs_verify_signature(&rqst, server, |
Jeff Layton | 0124cc4 | 2013-04-03 11:55:03 -0400 | [diff] [blame] | 1735 | mid->sequence_number); |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1736 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1737 | cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
| 1738 | rc); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1739 | } |
| 1740 | /* FIXME: should this be counted toward the initiating task? */ |
Pavel Shilovsky | 34a54d6 | 2014-07-10 10:03:29 +0400 | [diff] [blame] | 1741 | task_io_account_read(rdata->got_bytes); |
| 1742 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1743 | break; |
| 1744 | case MID_REQUEST_SUBMITTED: |
| 1745 | case MID_RETRY_NEEDED: |
| 1746 | rdata->result = -EAGAIN; |
Pavel Shilovsky | d913ed1 | 2014-07-10 11:31:48 +0400 | [diff] [blame] | 1747 | if (server->sign && rdata->got_bytes) |
| 1748 | /* reset bytes number since we can not check a sign */ |
| 1749 | rdata->got_bytes = 0; |
| 1750 | /* FIXME: should this be counted toward the initiating task? */ |
| 1751 | task_io_account_read(rdata->got_bytes); |
| 1752 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1753 | break; |
| 1754 | default: |
| 1755 | rdata->result = -EIO; |
| 1756 | } |
| 1757 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1758 | queue_work(cifsiod_wq, &rdata->work); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1759 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 1760 | add_credits(server, &credits, 0); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1764 | int |
| 1765 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1766 | { |
| 1767 | int rc; |
| 1768 | READ_REQ *smb = NULL; |
| 1769 | int wct; |
| 1770 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1771 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 1772 | .rq_nvec = 2 }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1773 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1774 | cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n", |
| 1775 | __func__, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1776 | |
| 1777 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1778 | wct = 12; |
| 1779 | else { |
| 1780 | wct = 10; /* old style read */ |
| 1781 | if ((rdata->offset >> 32) > 0) { |
| 1782 | /* can not handle this big offset for old */ |
| 1783 | return -EIO; |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1788 | if (rc) |
| 1789 | return rc; |
| 1790 | |
| 1791 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1792 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1793 | |
| 1794 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1795 | smb->Fid = rdata->cfile->fid.netfid; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1796 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1797 | if (wct == 12) |
| 1798 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1799 | smb->Remaining = 0; |
| 1800 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1801 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1802 | if (wct == 12) |
| 1803 | smb->ByteCount = 0; |
| 1804 | else { |
| 1805 | /* old style read */ |
| 1806 | struct smb_com_readx_req *smbr = |
| 1807 | (struct smb_com_readx_req *)smb; |
| 1808 | smbr->ByteCount = 0; |
| 1809 | } |
| 1810 | |
| 1811 | /* 4 for RFC1001 length + 1 for BCC */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1812 | rdata->iov[0].iov_base = smb; |
| 1813 | rdata->iov[0].iov_len = 4; |
| 1814 | rdata->iov[1].iov_base = (char *)smb + 4; |
| 1815 | rdata->iov[1].iov_len = get_rfc1002_length(smb); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1816 | |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1817 | kref_get(&rdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 1818 | rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, |
Pavel Shilovsky | 3349c3a | 2019-01-15 15:52:29 -0800 | [diff] [blame] | 1819 | cifs_readv_callback, NULL, rdata, 0, NULL); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1820 | |
| 1821 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1822 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1823 | else |
| 1824 | kref_put(&rdata->refcount, cifs_readdata_release); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1825 | |
| 1826 | cifs_small_buf_release(smb); |
| 1827 | return rc; |
| 1828 | } |
| 1829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1831 | CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms, |
| 1832 | unsigned int *nbytes, char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | { |
| 1834 | int rc = -EACCES; |
| 1835 | READ_REQ *pSMB = NULL; |
| 1836 | READ_RSP *pSMBr = NULL; |
| 1837 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1838 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1839 | int resp_buf_type = 0; |
| 1840 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1841 | struct kvec rsp_iov; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1842 | __u32 pid = io_parms->pid; |
| 1843 | __u16 netfid = io_parms->netfid; |
| 1844 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1845 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1846 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1848 | cifs_dbg(FYI, "Reading %d bytes on fid %d\n", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1849 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1850 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1851 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1852 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1853 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1854 | /* can not handle this big offset for old */ |
| 1855 | return -EIO; |
| 1856 | } |
| 1857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | |
| 1859 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1860 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | if (rc) |
| 1862 | return rc; |
| 1863 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1864 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1865 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | /* tcon and ses pointer are checked in smb_init */ |
| 1868 | if (tcon->ses->server == NULL) |
| 1869 | return -ECONNABORTED; |
| 1870 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1871 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1873 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1874 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1875 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | pSMB->Remaining = 0; |
| 1878 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1879 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1880 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1881 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1882 | else { |
| 1883 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1884 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1885 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1886 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1887 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1888 | |
| 1889 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1890 | 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] | 1891 | rc = SendReceive2(xid, tcon->ses, iov, 1, &resp_buf_type, |
| 1892 | CIFS_LOG_ERROR, &rsp_iov); |
| 1893 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1894 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1895 | pSMBr = (READ_RSP *)rsp_iov.iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1897 | cifs_dbg(VFS, "Send error in read = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | } else { |
| 1899 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1900 | data_length = data_length << 16; |
| 1901 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1902 | *nbytes = data_length; |
| 1903 | |
| 1904 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1905 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | || (data_length > count)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1907 | cifs_dbg(FYI, "bad length %d for count %d\n", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1908 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | rc = -EIO; |
| 1910 | *nbytes = 0; |
| 1911 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1912 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1913 | le16_to_cpu(pSMBr->DataOffset); |
| 1914 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1915 | cifs_dbg(VFS, "Faulting on read rc = %d\n",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1916 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1917 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1918 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1919 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | } |
| 1921 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1923 | if (*buf) { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1924 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1925 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1926 | /* return buffer to caller to free */ |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1927 | *buf = rsp_iov.iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1928 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1929 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1930 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1931 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1932 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1933 | |
| 1934 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | since file handle passed in no longer valid */ |
| 1936 | return rc; |
| 1937 | } |
| 1938 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1941 | CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 1942 | unsigned int *nbytes, const char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | { |
| 1944 | int rc = -EACCES; |
| 1945 | WRITE_REQ *pSMB = NULL; |
| 1946 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1947 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | __u32 bytes_sent; |
| 1949 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1950 | __u32 pid = io_parms->pid; |
| 1951 | __u16 netfid = io_parms->netfid; |
| 1952 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1953 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1954 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1956 | *nbytes = 0; |
| 1957 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1958 | /* cifs_dbg(FYI, "write at %lld %d bytes\n", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1959 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1960 | return -ECONNABORTED; |
| 1961 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1962 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1963 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1964 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1965 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1966 | if ((offset >> 32) > 0) { |
| 1967 | /* can not handle big offset for old srv */ |
| 1968 | return -EIO; |
| 1969 | } |
| 1970 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1971 | |
| 1972 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | (void **) &pSMBr); |
| 1974 | if (rc) |
| 1975 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1976 | |
| 1977 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1978 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | /* tcon and ses pointer are checked in smb_init */ |
| 1981 | if (tcon->ses->server == NULL) |
| 1982 | return -ECONNABORTED; |
| 1983 | |
| 1984 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1985 | pSMB->Fid = netfid; |
| 1986 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1987 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1988 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | pSMB->Reserved = 0xFFFFFFFF; |
| 1991 | pSMB->WriteMode = 0; |
| 1992 | pSMB->Remaining = 0; |
| 1993 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1994 | /* 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] | 1995 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1996 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1997 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1998 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 2000 | } else { |
| 2001 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 2002 | & ~0xFF; |
| 2003 | } |
| 2004 | |
| 2005 | if (bytes_sent > count) |
| 2006 | bytes_sent = count; |
| 2007 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2008 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2009 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 2010 | memcpy(pSMB->Data, buf, bytes_sent); |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 2011 | else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | /* No buffer */ |
| 2013 | cifs_buf_release(pSMB); |
| 2014 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 2015 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2016 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 2017 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2018 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 2019 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 2022 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2023 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 2024 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2025 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 2026 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2027 | else { /* old style write has byte count 4 bytes earlier |
| 2028 | so 4 bytes pad */ |
| 2029 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 2030 | (struct smb_com_writex_req *)pSMB; |
| 2031 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 2032 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | |
| 2034 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Al Viro | dbbab32 | 2016-09-05 17:53:43 -0400 | [diff] [blame] | 2035 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2036 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2038 | cifs_dbg(FYI, "Send error in write = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | } else { |
| 2040 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2041 | *nbytes = (*nbytes) << 16; |
| 2042 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2043 | |
| 2044 | /* |
| 2045 | * Mask off high 16 bits when bytes written as returned by the |
| 2046 | * server is greater than bytes requested by the client. Some |
| 2047 | * OS/2 servers are known to set incorrect CountHigh values. |
| 2048 | */ |
| 2049 | if (*nbytes > count) |
| 2050 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | cifs_buf_release(pSMB); |
| 2054 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2055 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | since file handle passed in no longer valid */ |
| 2057 | |
| 2058 | return rc; |
| 2059 | } |
| 2060 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2061 | void |
| 2062 | cifs_writedata_release(struct kref *refcount) |
| 2063 | { |
| 2064 | struct cifs_writedata *wdata = container_of(refcount, |
| 2065 | struct cifs_writedata, refcount); |
Long Li | db223a5 | 2017-11-22 17:38:45 -0700 | [diff] [blame] | 2066 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 2067 | if (wdata->mr) { |
| 2068 | smbd_deregister_mr(wdata->mr); |
| 2069 | wdata->mr = NULL; |
| 2070 | } |
| 2071 | #endif |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2072 | |
| 2073 | if (wdata->cfile) |
| 2074 | cifsFileInfo_put(wdata->cfile); |
| 2075 | |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2076 | kvfree(wdata->pages); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2077 | kfree(wdata); |
| 2078 | } |
| 2079 | |
| 2080 | /* |
| 2081 | * Write failed with a retryable error. Resend the write request. It's also |
| 2082 | * possible that the page was redirtied so re-clean the page. |
| 2083 | */ |
| 2084 | static void |
| 2085 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 2086 | { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2087 | int i, rc = 0; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2088 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Pavel Shilovsky | c9de5c8 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2089 | struct TCP_Server_Info *server; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2090 | unsigned int rest_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2091 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2092 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
| 2093 | i = 0; |
| 2094 | rest_len = wdata->bytes; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2095 | do { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2096 | struct cifs_writedata *wdata2; |
| 2097 | unsigned int j, nr_pages, wsize, tailsz, cur_len; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2098 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2099 | wsize = server->ops->wp_retry_size(inode); |
| 2100 | if (wsize < rest_len) { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2101 | nr_pages = wsize / PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2102 | if (!nr_pages) { |
| 2103 | rc = -ENOTSUPP; |
| 2104 | break; |
| 2105 | } |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2106 | cur_len = nr_pages * PAGE_SIZE; |
| 2107 | tailsz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2108 | } else { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2109 | nr_pages = DIV_ROUND_UP(rest_len, PAGE_SIZE); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2110 | cur_len = rest_len; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2111 | tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE; |
Ouyang Maochun | c51bb0e | 2013-02-18 09:54:52 -0600 | [diff] [blame] | 2112 | } |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2113 | |
| 2114 | wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete); |
| 2115 | if (!wdata2) { |
| 2116 | rc = -ENOMEM; |
| 2117 | break; |
| 2118 | } |
| 2119 | |
| 2120 | for (j = 0; j < nr_pages; j++) { |
| 2121 | wdata2->pages[j] = wdata->pages[i + j]; |
| 2122 | lock_page(wdata2->pages[j]); |
| 2123 | clear_page_dirty_for_io(wdata2->pages[j]); |
| 2124 | } |
| 2125 | |
| 2126 | wdata2->sync_mode = wdata->sync_mode; |
| 2127 | wdata2->nr_pages = nr_pages; |
| 2128 | wdata2->offset = page_offset(wdata2->pages[0]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2129 | wdata2->pagesz = PAGE_SIZE; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2130 | wdata2->tailsz = tailsz; |
| 2131 | wdata2->bytes = cur_len; |
| 2132 | |
Aurelien Aptel | 86f740f | 2020-02-21 11:19:06 +0100 | [diff] [blame] | 2133 | rc = cifs_get_writable_file(CIFS_I(inode), FIND_WR_ANY, |
Pavel Shilovsky | fe768d5 | 2019-01-29 12:15:11 -0800 | [diff] [blame] | 2134 | &wdata2->cfile); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2135 | if (!wdata2->cfile) { |
Pavel Shilovsky | fe768d5 | 2019-01-29 12:15:11 -0800 | [diff] [blame] | 2136 | cifs_dbg(VFS, "No writable handle to retry writepages rc=%d\n", |
| 2137 | rc); |
| 2138 | if (!is_retryable_error(rc)) |
| 2139 | rc = -EBADF; |
Pavel Shilovsky | 165df9a | 2019-01-29 16:40:28 -0800 | [diff] [blame] | 2140 | } else { |
| 2141 | wdata2->pid = wdata2->cfile->pid; |
| 2142 | rc = server->ops->async_writev(wdata2, |
| 2143 | cifs_writedata_release); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2144 | } |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2145 | |
| 2146 | for (j = 0; j < nr_pages; j++) { |
| 2147 | unlock_page(wdata2->pages[j]); |
Pavel Shilovsky | 9a66396 | 2019-01-08 11:15:28 -0800 | [diff] [blame] | 2148 | if (rc != 0 && !is_retryable_error(rc)) { |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2149 | SetPageError(wdata2->pages[j]); |
| 2150 | end_page_writeback(wdata2->pages[j]); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2151 | put_page(wdata2->pages[j]); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2152 | } |
| 2153 | } |
| 2154 | |
Adam McCoy | a481379 | 2020-05-13 11:53:30 +0000 | [diff] [blame] | 2155 | kref_put(&wdata2->refcount, cifs_writedata_release); |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2156 | if (rc) { |
Pavel Shilovsky | 9a66396 | 2019-01-08 11:15:28 -0800 | [diff] [blame] | 2157 | if (is_retryable_error(rc)) |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2158 | continue; |
Pavel Shilovsky | 165df9a | 2019-01-29 16:40:28 -0800 | [diff] [blame] | 2159 | i += nr_pages; |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2160 | break; |
| 2161 | } |
| 2162 | |
| 2163 | rest_len -= cur_len; |
| 2164 | i += nr_pages; |
| 2165 | } while (i < wdata->nr_pages); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2166 | |
Pavel Shilovsky | 165df9a | 2019-01-29 16:40:28 -0800 | [diff] [blame] | 2167 | /* cleanup remaining pages from the original wdata */ |
| 2168 | for (; i < wdata->nr_pages; i++) { |
| 2169 | SetPageError(wdata->pages[i]); |
| 2170 | end_page_writeback(wdata->pages[i]); |
| 2171 | put_page(wdata->pages[i]); |
| 2172 | } |
| 2173 | |
Pavel Shilovsky | 9a66396 | 2019-01-08 11:15:28 -0800 | [diff] [blame] | 2174 | if (rc != 0 && !is_retryable_error(rc)) |
| 2175 | mapping_set_error(inode->i_mapping, rc); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2176 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2177 | } |
| 2178 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2179 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2180 | cifs_writev_complete(struct work_struct *work) |
| 2181 | { |
| 2182 | struct cifs_writedata *wdata = container_of(work, |
| 2183 | struct cifs_writedata, work); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2184 | struct inode *inode = d_inode(wdata->cfile->dentry); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2185 | int i = 0; |
| 2186 | |
| 2187 | if (wdata->result == 0) { |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2188 | spin_lock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2189 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2190 | spin_unlock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2191 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 2192 | wdata->bytes); |
| 2193 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 2194 | return cifs_writev_requeue(wdata); |
| 2195 | |
| 2196 | for (i = 0; i < wdata->nr_pages; i++) { |
| 2197 | struct page *page = wdata->pages[i]; |
| 2198 | if (wdata->result == -EAGAIN) |
| 2199 | __set_page_dirty_nobuffers(page); |
| 2200 | else if (wdata->result < 0) |
| 2201 | SetPageError(page); |
| 2202 | end_page_writeback(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2203 | put_page(page); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2204 | } |
| 2205 | if (wdata->result != -EAGAIN) |
| 2206 | mapping_set_error(inode->i_mapping, wdata->result); |
| 2207 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2208 | } |
| 2209 | |
| 2210 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2211 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2212 | { |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2213 | struct page **pages = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2214 | kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2215 | if (pages) |
| 2216 | return cifs_writedata_direct_alloc(pages, complete); |
| 2217 | |
| 2218 | return NULL; |
| 2219 | } |
| 2220 | |
| 2221 | struct cifs_writedata * |
| 2222 | cifs_writedata_direct_alloc(struct page **pages, work_func_t complete) |
| 2223 | { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2224 | struct cifs_writedata *wdata; |
| 2225 | |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2226 | wdata = kzalloc(sizeof(*wdata), GFP_NOFS); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2227 | if (wdata != NULL) { |
Long Li | 8e7360f | 2018-05-30 12:47:56 -0700 | [diff] [blame] | 2228 | wdata->pages = pages; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2229 | kref_init(&wdata->refcount); |
Jeff Layton | da82f7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2230 | INIT_LIST_HEAD(&wdata->list); |
| 2231 | init_completion(&wdata->done); |
| 2232 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2233 | } |
| 2234 | return wdata; |
| 2235 | } |
| 2236 | |
| 2237 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2238 | * 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] | 2239 | * workqueue completion task. |
| 2240 | */ |
| 2241 | static void |
| 2242 | cifs_writev_callback(struct mid_q_entry *mid) |
| 2243 | { |
| 2244 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2245 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2246 | unsigned int written; |
| 2247 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 2248 | struct cifs_credits credits = { .value = 1, .instance = 0 }; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2249 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2250 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2251 | case MID_RESPONSE_RECEIVED: |
| 2252 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 2253 | if (wdata->result != 0) |
| 2254 | break; |
| 2255 | |
| 2256 | written = le16_to_cpu(smb->CountHigh); |
| 2257 | written <<= 16; |
| 2258 | written += le16_to_cpu(smb->Count); |
| 2259 | /* |
| 2260 | * Mask off high 16 bits when bytes written as returned |
| 2261 | * by the server is greater than bytes requested by the |
| 2262 | * client. OS/2 servers are known to set incorrect |
| 2263 | * CountHigh values. |
| 2264 | */ |
| 2265 | if (written > wdata->bytes) |
| 2266 | written &= 0xFFFF; |
| 2267 | |
| 2268 | if (written < wdata->bytes) |
| 2269 | wdata->result = -ENOSPC; |
| 2270 | else |
| 2271 | wdata->bytes = written; |
| 2272 | break; |
| 2273 | case MID_REQUEST_SUBMITTED: |
| 2274 | case MID_RETRY_NEEDED: |
| 2275 | wdata->result = -EAGAIN; |
| 2276 | break; |
| 2277 | default: |
| 2278 | wdata->result = -EIO; |
| 2279 | break; |
| 2280 | } |
| 2281 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2282 | queue_work(cifsiod_wq, &wdata->work); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2283 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 34f4deb | 2019-01-16 11:22:29 -0800 | [diff] [blame] | 2284 | add_credits(tcon->ses->server, &credits, 0); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2288 | int |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2289 | cifs_async_writev(struct cifs_writedata *wdata, |
| 2290 | void (*release)(struct kref *kref)) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2291 | { |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2292 | int rc = -EACCES; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2293 | WRITE_REQ *smb = NULL; |
| 2294 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2295 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2296 | struct kvec iov[2]; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2297 | struct smb_rqst rqst = { }; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2298 | |
| 2299 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2300 | wct = 14; |
| 2301 | } else { |
| 2302 | wct = 12; |
| 2303 | if (wdata->offset >> 32 > 0) { |
| 2304 | /* can not handle big offset for old srv */ |
| 2305 | return -EIO; |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2310 | if (rc) |
| 2311 | goto async_writev_out; |
| 2312 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2313 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2314 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2315 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2316 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2317 | smb->Fid = wdata->cfile->fid.netfid; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2318 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2319 | if (wct == 14) |
| 2320 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2321 | smb->Reserved = 0xFFFFFFFF; |
| 2322 | smb->WriteMode = 0; |
| 2323 | smb->Remaining = 0; |
| 2324 | |
| 2325 | smb->DataOffset = |
| 2326 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2327 | |
| 2328 | /* 4 for RFC1001 length + 1 for BCC */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2329 | iov[0].iov_len = 4; |
| 2330 | iov[0].iov_base = smb; |
| 2331 | iov[1].iov_len = get_rfc1002_length(smb) + 1; |
| 2332 | iov[1].iov_base = (char *)smb + 4; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2333 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2334 | rqst.rq_iov = iov; |
| 2335 | rqst.rq_nvec = 2; |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2336 | rqst.rq_pages = wdata->pages; |
Long Li | 6d3adb2 | 2018-09-20 21:18:38 +0000 | [diff] [blame] | 2337 | rqst.rq_offset = wdata->page_offset; |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2338 | rqst.rq_npages = wdata->nr_pages; |
| 2339 | rqst.rq_pagesz = wdata->pagesz; |
| 2340 | rqst.rq_tailsz = wdata->tailsz; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2341 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2342 | cifs_dbg(FYI, "async write at %llu %u bytes\n", |
| 2343 | wdata->offset, wdata->bytes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2344 | |
| 2345 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2346 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2347 | |
| 2348 | if (wct == 14) { |
| 2349 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2350 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2351 | } else { |
| 2352 | /* wct == 12 */ |
| 2353 | struct smb_com_writex_req *smbw = |
| 2354 | (struct smb_com_writex_req *)smb; |
| 2355 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2356 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2357 | iov[1].iov_len += 4; /* pad bigger by four bytes */ |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | kref_get(&wdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2361 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, |
Pavel Shilovsky | 3349c3a | 2019-01-15 15:52:29 -0800 | [diff] [blame] | 2362 | cifs_writev_callback, NULL, wdata, 0, NULL); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2363 | |
| 2364 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2365 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2366 | else |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2367 | kref_put(&wdata->refcount, release); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2368 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2369 | async_writev_out: |
| 2370 | cifs_small_buf_release(smb); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2371 | return rc; |
| 2372 | } |
| 2373 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2374 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2375 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2376 | unsigned int *nbytes, struct kvec *iov, int n_vec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | { |
Colin Ian King | 136a5dc | 2020-05-27 13:50:31 +0100 | [diff] [blame^] | 2378 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2380 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2381 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2382 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2383 | __u32 pid = io_parms->pid; |
| 2384 | __u16 netfid = io_parms->netfid; |
| 2385 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2386 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2387 | unsigned int count = io_parms->length; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2388 | struct kvec rsp_iov; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2390 | *nbytes = 0; |
| 2391 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2392 | 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] | 2393 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2394 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2395 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2396 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2397 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2398 | if ((offset >> 32) > 0) { |
| 2399 | /* can not handle big offset for old srv */ |
| 2400 | return -EIO; |
| 2401 | } |
| 2402 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2403 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | if (rc) |
| 2405 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2406 | |
| 2407 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2408 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | /* tcon and ses pointer are checked in smb_init */ |
| 2411 | if (tcon->ses->server == NULL) |
| 2412 | return -ECONNABORTED; |
| 2413 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2414 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | pSMB->Fid = netfid; |
| 2416 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2417 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2418 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | pSMB->Reserved = 0xFFFFFFFF; |
| 2420 | pSMB->WriteMode = 0; |
| 2421 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2424 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2426 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2427 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2428 | /* header + 1 byte pad */ |
| 2429 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2430 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2431 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2432 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2433 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2434 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2435 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2436 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2437 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2438 | (struct smb_com_writex_req *)pSMB; |
| 2439 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2440 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2441 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2442 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2443 | iov[0].iov_len = smb_hdr_len + 4; |
| 2444 | else /* wct == 12 pad bigger by four bytes */ |
| 2445 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2446 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2447 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0, |
| 2448 | &rsp_iov); |
| 2449 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2450 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2452 | cifs_dbg(FYI, "Send error Write2 = %d\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2453 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2454 | /* presumably this can not happen, but best to be safe */ |
| 2455 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2456 | } else { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2457 | WRITE_RSP *pSMBr = (WRITE_RSP *)rsp_iov.iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2458 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2459 | *nbytes = (*nbytes) << 16; |
| 2460 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2461 | |
| 2462 | /* |
| 2463 | * Mask off high 16 bits when bytes written as returned by the |
| 2464 | * server is greater than bytes requested by the client. OS/2 |
| 2465 | * servers are known to set incorrect CountHigh values. |
| 2466 | */ |
| 2467 | if (*nbytes > count) |
| 2468 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2471 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2473 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | since file handle passed in no longer valid */ |
| 2475 | |
| 2476 | return rc; |
| 2477 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2478 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2479 | int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon, |
| 2480 | const __u16 netfid, const __u8 lock_type, const __u32 num_unlock, |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2481 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2482 | { |
| 2483 | int rc = 0; |
| 2484 | LOCK_REQ *pSMB = NULL; |
| 2485 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2486 | struct kvec rsp_iov; |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2487 | int resp_buf_type; |
| 2488 | __u16 count; |
| 2489 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2490 | cifs_dbg(FYI, "cifs_lockv num lock %d num unlock %d\n", |
| 2491 | num_lock, num_unlock); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2492 | |
| 2493 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2494 | if (rc) |
| 2495 | return rc; |
| 2496 | |
| 2497 | pSMB->Timeout = 0; |
| 2498 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2499 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2500 | pSMB->LockType = lock_type; |
| 2501 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2502 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2503 | |
| 2504 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2505 | inc_rfc1001_len(pSMB, count); |
| 2506 | pSMB->ByteCount = cpu_to_le16(count); |
| 2507 | |
| 2508 | iov[0].iov_base = (char *)pSMB; |
| 2509 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2510 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2511 | iov[1].iov_base = (char *)buf; |
| 2512 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2513 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2514 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Ronnie Sahlberg | 392e1c5 | 2019-05-06 10:00:02 +1000 | [diff] [blame] | 2515 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, |
| 2516 | CIFS_NO_RSP_BUF, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2517 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2518 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2519 | cifs_dbg(FYI, "Send error in cifs_lockv = %d\n", rc); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2520 | |
| 2521 | return rc; |
| 2522 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2525 | CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2526 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2528 | const __u32 numLock, const __u8 lockType, |
| 2529 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | { |
| 2531 | int rc = 0; |
| 2532 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2533 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | int bytes_returned; |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2535 | int flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | __u16 count; |
| 2537 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2538 | cifs_dbg(FYI, "CIFSSMBLock timeout %d numLock %d\n", |
| 2539 | (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2540 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | if (rc) |
| 2543 | return rc; |
| 2544 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2545 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2546 | /* no response expected */ |
Ronnie Sahlberg | 392e1c5 | 2019-05-06 10:00:02 +1000 | [diff] [blame] | 2547 | flags = CIFS_NO_SRV_RSP | CIFS_NON_BLOCKING | CIFS_OBREAK_OP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2549 | } else if (waitFlag) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2550 | flags = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2552 | } else { |
| 2553 | pSMB->Timeout = 0; |
| 2554 | } |
| 2555 | |
| 2556 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2557 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2558 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2559 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2561 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2562 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2563 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2564 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | /* BB where to store pid high? */ |
| 2566 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2567 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2568 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2569 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2570 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2571 | } else { |
| 2572 | /* oplock break */ |
| 2573 | count = 0; |
| 2574 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2575 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | pSMB->ByteCount = cpu_to_le16(count); |
| 2577 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2578 | if (waitFlag) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2579 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2580 | (struct smb_hdr *) pSMB, &bytes_returned); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2581 | else |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2582 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, flags); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2583 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2584 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2585 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2586 | cifs_dbg(FYI, "Send error in Lock = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2588 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | since file handle passed in no longer valid */ |
| 2590 | return rc; |
| 2591 | } |
| 2592 | |
| 2593 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2594 | CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2595 | const __u16 smb_file_id, const __u32 netpid, |
| 2596 | const loff_t start_offset, const __u64 len, |
| 2597 | struct file_lock *pLockData, const __u16 lock_type, |
| 2598 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2599 | { |
| 2600 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2601 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2602 | struct cifs_posix_lock *parm_data; |
| 2603 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2604 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2605 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2606 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2607 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2608 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2609 | struct kvec rsp_iov; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2610 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2611 | cifs_dbg(FYI, "Posix Lock\n"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2612 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2613 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2614 | |
| 2615 | if (rc) |
| 2616 | return rc; |
| 2617 | |
| 2618 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2619 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2620 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2621 | pSMB->MaxSetupCount = 0; |
| 2622 | pSMB->Reserved = 0; |
| 2623 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2624 | pSMB->Reserved2 = 0; |
| 2625 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2626 | offset = param_offset + params; |
| 2627 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2628 | count = sizeof(struct cifs_posix_lock); |
| 2629 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2630 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2631 | pSMB->SetupCount = 1; |
| 2632 | pSMB->Reserved3 = 0; |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2633 | if (pLockData) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2634 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2635 | else |
| 2636 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2637 | byte_count = 3 /* pad */ + params + count; |
| 2638 | pSMB->DataCount = cpu_to_le16(count); |
| 2639 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2640 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2641 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2642 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2643 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2644 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2645 | |
| 2646 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2647 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2648 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2649 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2650 | pSMB->Timeout = cpu_to_le32(-1); |
| 2651 | } else |
| 2652 | pSMB->Timeout = 0; |
| 2653 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2654 | parm_data->pid = cpu_to_le32(netpid); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2655 | parm_data->start = cpu_to_le64(start_offset); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2656 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2657 | |
| 2658 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2659 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2660 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2661 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2662 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2663 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2664 | if (waitFlag) { |
| 2665 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2666 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2667 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2668 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2669 | 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] | 2670 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2671 | &resp_buf_type, timeout, &rsp_iov); |
| 2672 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)rsp_iov.iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2673 | } |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2674 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2675 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2676 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2677 | cifs_dbg(FYI, "Send error in Posix Lock = %d\n", rc); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2678 | } else if (pLockData) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2679 | /* lock structure can be returned on get */ |
| 2680 | __u16 data_offset; |
| 2681 | __u16 data_count; |
| 2682 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2683 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2684 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2685 | rc = -EIO; /* bad smb */ |
| 2686 | goto plk_err_exit; |
| 2687 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2688 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2689 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2690 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2691 | rc = -EIO; |
| 2692 | goto plk_err_exit; |
| 2693 | } |
| 2694 | parm_data = (struct cifs_posix_lock *) |
| 2695 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2696 | if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2697 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2698 | else { |
| 2699 | if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2700 | cpu_to_le16(CIFS_RDLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2701 | pLockData->fl_type = F_RDLCK; |
| 2702 | else if (parm_data->lock_type == |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 2703 | cpu_to_le16(CIFS_WRLCK)) |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2704 | pLockData->fl_type = F_WRLCK; |
| 2705 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2706 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2707 | pLockData->fl_end = pLockData->fl_start + |
| 2708 | le64_to_cpu(parm_data->length) - 1; |
Benjamin Coddington | 9d5b86a | 2017-07-16 10:28:22 -0400 | [diff] [blame] | 2709 | pLockData->fl_pid = -le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2710 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2711 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2712 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2713 | plk_err_exit: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2714 | free_rsp_buf(resp_buf_type, rsp_iov.iov_base); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2715 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2716 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2717 | since file handle passed in no longer valid */ |
| 2718 | |
| 2719 | return rc; |
| 2720 | } |
| 2721 | |
| 2722 | |
| 2723 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2724 | 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] | 2725 | { |
| 2726 | int rc = 0; |
| 2727 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2728 | cifs_dbg(FYI, "In CIFSSMBClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | |
| 2730 | /* do not retry on dead session on close */ |
| 2731 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2732 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | return 0; |
| 2734 | if (rc) |
| 2735 | return rc; |
| 2736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2738 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2740 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2741 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2742 | cifs_stats_inc(&tcon->stats.cifs_stats.num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2744 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2746 | cifs_dbg(VFS, "Send error in Close = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | } |
| 2748 | } |
| 2749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2751 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | rc = 0; |
| 2753 | |
| 2754 | return rc; |
| 2755 | } |
| 2756 | |
| 2757 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2758 | 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] | 2759 | { |
| 2760 | int rc = 0; |
| 2761 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2762 | cifs_dbg(FYI, "In CIFSSMBFlush\n"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2763 | |
| 2764 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2765 | if (rc) |
| 2766 | return rc; |
| 2767 | |
| 2768 | pSMB->FileID = (__u16) smb_file_id; |
| 2769 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2770 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2771 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2772 | cifs_stats_inc(&tcon->stats.cifs_stats.num_flushes); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2773 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2774 | cifs_dbg(VFS, "Send error in Flush = %d\n", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2775 | |
| 2776 | return rc; |
| 2777 | } |
| 2778 | |
| 2779 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2780 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2781 | const char *from_name, const char *to_name, |
| 2782 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | { |
| 2784 | int rc = 0; |
| 2785 | RENAME_REQ *pSMB = NULL; |
| 2786 | RENAME_RSP *pSMBr = NULL; |
| 2787 | int bytes_returned; |
| 2788 | int name_len, name_len2; |
| 2789 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 2790 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2792 | cifs_dbg(FYI, "In CIFSSMBRename\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | renameRetry: |
| 2794 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2795 | (void **) &pSMBr); |
| 2796 | if (rc) |
| 2797 | return rc; |
| 2798 | |
| 2799 | pSMB->BufferFormat = 0x04; |
| 2800 | pSMB->SearchAttributes = |
| 2801 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2802 | ATTR_DIRECTORY); |
| 2803 | |
| 2804 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2805 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2806 | from_name, PATH_MAX, |
| 2807 | cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | name_len++; /* trailing null */ |
| 2809 | name_len *= 2; |
| 2810 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2811 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2812 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2813 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2814 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2815 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 2816 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2818 | name_len2 *= 2; /* convert to bytes */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2819 | } else { |
| 2820 | name_len = copy_path_name(pSMB->OldFileName, from_name); |
| 2821 | name_len2 = copy_path_name(pSMB->OldFileName+name_len+1, to_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | name_len2++; /* signature byte */ |
| 2824 | } |
| 2825 | |
| 2826 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2827 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | pSMB->ByteCount = cpu_to_le16(count); |
| 2829 | |
| 2830 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2831 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2832 | cifs_stats_inc(&tcon->stats.cifs_stats.num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2833 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2834 | cifs_dbg(FYI, "Send error in rename = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | cifs_buf_release(pSMB); |
| 2837 | |
| 2838 | if (rc == -EAGAIN) |
| 2839 | goto renameRetry; |
| 2840 | |
| 2841 | return rc; |
| 2842 | } |
| 2843 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2844 | int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2845 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2846 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | { |
| 2848 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2849 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2850 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | char *data_offset; |
| 2852 | char dummy_string[30]; |
| 2853 | int rc = 0; |
| 2854 | int bytes_returned = 0; |
| 2855 | int len_of_str; |
| 2856 | __u16 params, param_offset, offset, count, byte_count; |
| 2857 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2858 | cifs_dbg(FYI, "Rename to File by handle\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2860 | (void **) &pSMBr); |
| 2861 | if (rc) |
| 2862 | return rc; |
| 2863 | |
| 2864 | params = 6; |
| 2865 | pSMB->MaxSetupCount = 0; |
| 2866 | pSMB->Reserved = 0; |
| 2867 | pSMB->Flags = 0; |
| 2868 | pSMB->Timeout = 0; |
| 2869 | pSMB->Reserved2 = 0; |
| 2870 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2871 | offset = param_offset + params; |
| 2872 | |
| 2873 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2874 | rename_info = (struct set_file_rename *) data_offset; |
| 2875 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2876 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | pSMB->SetupCount = 1; |
| 2878 | pSMB->Reserved3 = 0; |
| 2879 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2880 | byte_count = 3 /* pad */ + params; |
| 2881 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2882 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2883 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2884 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2885 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2886 | rename_info->overwrite = cpu_to_le32(1); |
| 2887 | rename_info->root_fid = 0; |
| 2888 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2889 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2890 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2891 | len_of_str = |
| 2892 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2893 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2895 | len_of_str = |
| 2896 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2897 | target_name, PATH_MAX, nls_codepage, |
| 2898 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | } |
| 2900 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2901 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | byte_count += count; |
| 2903 | pSMB->DataCount = cpu_to_le16(count); |
| 2904 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2905 | pSMB->Fid = netfid; |
| 2906 | pSMB->InformationLevel = |
| 2907 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2908 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2909 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2911 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2912 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2913 | cifs_stats_inc(&pTcon->stats.cifs_stats.num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2914 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2915 | cifs_dbg(FYI, "Send error in Rename (by file handle) = %d\n", |
| 2916 | rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | cifs_buf_release(pSMB); |
| 2919 | |
| 2920 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2921 | since file handle passed in no longer valid */ |
| 2922 | |
| 2923 | return rc; |
| 2924 | } |
| 2925 | |
| 2926 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2927 | CIFSSMBCopy(const unsigned int xid, struct cifs_tcon *tcon, |
| 2928 | const char *fromName, const __u16 target_tid, const char *toName, |
| 2929 | const int flags, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | { |
| 2931 | int rc = 0; |
| 2932 | COPY_REQ *pSMB = NULL; |
| 2933 | COPY_RSP *pSMBr = NULL; |
| 2934 | int bytes_returned; |
| 2935 | int name_len, name_len2; |
| 2936 | __u16 count; |
| 2937 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2938 | cifs_dbg(FYI, "In CIFSSMBCopy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | copyRetry: |
| 2940 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2941 | (void **) &pSMBr); |
| 2942 | if (rc) |
| 2943 | return rc; |
| 2944 | |
| 2945 | pSMB->BufferFormat = 0x04; |
| 2946 | pSMB->Tid2 = target_tid; |
| 2947 | |
| 2948 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2949 | |
| 2950 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2951 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2952 | fromName, PATH_MAX, nls_codepage, |
| 2953 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | name_len++; /* trailing null */ |
| 2955 | name_len *= 2; |
| 2956 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2957 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2958 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2959 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2960 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2961 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2963 | name_len2 *= 2; /* convert to bytes */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2964 | } else { |
| 2965 | name_len = copy_path_name(pSMB->OldFileName, fromName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 2967 | name_len2 = copy_path_name(pSMB->OldFileName+name_len+1, toName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | name_len2++; /* signature byte */ |
| 2969 | } |
| 2970 | |
| 2971 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2972 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | pSMB->ByteCount = cpu_to_le16(count); |
| 2974 | |
| 2975 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2976 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2977 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2978 | cifs_dbg(FYI, "Send error in copy = %d with %d files copied\n", |
| 2979 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2981 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | |
| 2983 | if (rc == -EAGAIN) |
| 2984 | goto copyRetry; |
| 2985 | |
| 2986 | return rc; |
| 2987 | } |
| 2988 | |
| 2989 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2990 | CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | const char *fromName, const char *toName, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 2992 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | { |
| 2994 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2995 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2996 | char *data_offset; |
| 2997 | int name_len; |
| 2998 | int name_len_target; |
| 2999 | int rc = 0; |
| 3000 | int bytes_returned = 0; |
| 3001 | __u16 params, param_offset, offset, byte_count; |
| 3002 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3003 | cifs_dbg(FYI, "In Symlink Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | createSymLinkRetry: |
| 3005 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3006 | (void **) &pSMBr); |
| 3007 | if (rc) |
| 3008 | return rc; |
| 3009 | |
| 3010 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3011 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3012 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fromName, |
| 3013 | /* find define for this maxpathcomponent */ |
| 3014 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | name_len++; /* trailing null */ |
| 3016 | name_len *= 2; |
| 3017 | |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3018 | } else { |
| 3019 | name_len = copy_path_name(pSMB->FileName, fromName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | } |
| 3021 | params = 6 + name_len; |
| 3022 | pSMB->MaxSetupCount = 0; |
| 3023 | pSMB->Reserved = 0; |
| 3024 | pSMB->Flags = 0; |
| 3025 | pSMB->Timeout = 0; |
| 3026 | pSMB->Reserved2 = 0; |
| 3027 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3028 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | offset = param_offset + params; |
| 3030 | |
| 3031 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 3032 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3033 | name_len_target = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3034 | cifsConvertToUTF16((__le16 *) data_offset, toName, |
| 3035 | /* find define for this maxpathcomponent */ |
| 3036 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | name_len_target++; /* trailing null */ |
| 3038 | name_len_target *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3039 | } else { |
| 3040 | name_len_target = copy_path_name(data_offset, toName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3044 | /* BB find exact max on data count below from sess */ |
| 3045 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 3046 | pSMB->SetupCount = 1; |
| 3047 | pSMB->Reserved3 = 0; |
| 3048 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3049 | byte_count = 3 /* pad */ + params + name_len_target; |
| 3050 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 3051 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3052 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3053 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3054 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3055 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3056 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 3057 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3058 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3060 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3061 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3062 | cifs_stats_inc(&tcon->stats.cifs_stats.num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3063 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3064 | cifs_dbg(FYI, "Send error in SetPathInfo create symlink = %d\n", |
| 3065 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 3067 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | |
| 3069 | if (rc == -EAGAIN) |
| 3070 | goto createSymLinkRetry; |
| 3071 | |
| 3072 | return rc; |
| 3073 | } |
| 3074 | |
| 3075 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3076 | CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3078 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | { |
| 3080 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 3081 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 3082 | char *data_offset; |
| 3083 | int name_len; |
| 3084 | int name_len_target; |
| 3085 | int rc = 0; |
| 3086 | int bytes_returned = 0; |
| 3087 | __u16 params, param_offset, offset, byte_count; |
| 3088 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3089 | cifs_dbg(FYI, "In Create Hard link Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | createHardLinkRetry: |
| 3091 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3092 | (void **) &pSMBr); |
| 3093 | if (rc) |
| 3094 | return rc; |
| 3095 | |
| 3096 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3097 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 3098 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | name_len++; /* trailing null */ |
| 3100 | name_len *= 2; |
| 3101 | |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3102 | } else { |
| 3103 | name_len = copy_path_name(pSMB->FileName, toName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | } |
| 3105 | params = 6 + name_len; |
| 3106 | pSMB->MaxSetupCount = 0; |
| 3107 | pSMB->Reserved = 0; |
| 3108 | pSMB->Flags = 0; |
| 3109 | pSMB->Timeout = 0; |
| 3110 | pSMB->Reserved2 = 0; |
| 3111 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3112 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | offset = param_offset + params; |
| 3114 | |
| 3115 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 3116 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3117 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3118 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 3119 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | name_len_target++; /* trailing null */ |
| 3121 | name_len_target *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3122 | } else { |
| 3123 | name_len_target = copy_path_name(data_offset, fromName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3127 | /* BB find exact max on data count below from sess*/ |
| 3128 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 3129 | pSMB->SetupCount = 1; |
| 3130 | pSMB->Reserved3 = 0; |
| 3131 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3132 | byte_count = 3 /* pad */ + params + name_len_target; |
| 3133 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3134 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3135 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 3136 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3137 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3138 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3139 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 3140 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3141 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3143 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3144 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3145 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3146 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3147 | cifs_dbg(FYI, "Send error in SetPathInfo (hard link) = %d\n", |
| 3148 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | |
| 3150 | cifs_buf_release(pSMB); |
| 3151 | if (rc == -EAGAIN) |
| 3152 | goto createHardLinkRetry; |
| 3153 | |
| 3154 | return rc; |
| 3155 | } |
| 3156 | |
| 3157 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3158 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3159 | const char *from_name, const char *to_name, |
| 3160 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | { |
| 3162 | int rc = 0; |
| 3163 | NT_RENAME_REQ *pSMB = NULL; |
| 3164 | RENAME_RSP *pSMBr = NULL; |
| 3165 | int bytes_returned; |
| 3166 | int name_len, name_len2; |
| 3167 | __u16 count; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 3168 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3170 | cifs_dbg(FYI, "In CIFSCreateHardLink\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | winCreateHardLinkRetry: |
| 3172 | |
| 3173 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 3174 | (void **) &pSMBr); |
| 3175 | if (rc) |
| 3176 | return rc; |
| 3177 | |
| 3178 | pSMB->SearchAttributes = |
| 3179 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3180 | ATTR_DIRECTORY); |
| 3181 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 3182 | pSMB->ClusterCount = 0; |
| 3183 | |
| 3184 | pSMB->BufferFormat = 0x04; |
| 3185 | |
| 3186 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3187 | name_len = |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3188 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, from_name, |
| 3189 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | name_len++; /* trailing null */ |
| 3191 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 3192 | |
| 3193 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 3194 | pSMB->OldFileName[name_len] = 0x04; |
| 3195 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3197 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3198 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 3199 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 3201 | name_len2 *= 2; /* convert to bytes */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3202 | } else { |
| 3203 | name_len = copy_path_name(pSMB->OldFileName, from_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3205 | name_len2 = copy_path_name(pSMB->OldFileName+name_len+1, to_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | name_len2++; /* signature byte */ |
| 3207 | } |
| 3208 | |
| 3209 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3210 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | pSMB->ByteCount = cpu_to_le16(count); |
| 3212 | |
| 3213 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3214 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3215 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3216 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3217 | 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] | 3218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | cifs_buf_release(pSMB); |
| 3220 | if (rc == -EAGAIN) |
| 3221 | goto winCreateHardLinkRetry; |
| 3222 | |
| 3223 | return rc; |
| 3224 | } |
| 3225 | |
| 3226 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3227 | CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3228 | const unsigned char *searchName, char **symlinkinfo, |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3229 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | { |
| 3231 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 3232 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3233 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3234 | int rc = 0; |
| 3235 | int bytes_returned; |
| 3236 | int name_len; |
| 3237 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3238 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3240 | cifs_dbg(FYI, "In QPathSymLinkInfo (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | |
| 3242 | querySymLinkRetry: |
| 3243 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3244 | (void **) &pSMBr); |
| 3245 | if (rc) |
| 3246 | return rc; |
| 3247 | |
| 3248 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3249 | name_len = |
Nakajima Akira | bc8ebdc4 | 2015-02-13 15:35:58 +0900 | [diff] [blame] | 3250 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3251 | searchName, PATH_MAX, nls_codepage, |
| 3252 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | name_len++; /* trailing null */ |
| 3254 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3255 | } else { |
| 3256 | name_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3260 | pSMB->TotalDataCount = 0; |
| 3261 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3262 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | pSMB->MaxSetupCount = 0; |
| 3264 | pSMB->Reserved = 0; |
| 3265 | pSMB->Flags = 0; |
| 3266 | pSMB->Timeout = 0; |
| 3267 | pSMB->Reserved2 = 0; |
| 3268 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3269 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | pSMB->DataCount = 0; |
| 3271 | pSMB->DataOffset = 0; |
| 3272 | pSMB->SetupCount = 1; |
| 3273 | pSMB->Reserved3 = 0; |
| 3274 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3275 | byte_count = params + 1 /* pad */ ; |
| 3276 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3277 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3278 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3279 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3280 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3282 | |
| 3283 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3284 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3285 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3286 | cifs_dbg(FYI, "Send error in QuerySymLinkInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | } else { |
| 3288 | /* decode response */ |
| 3289 | |
| 3290 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3292 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3293 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3295 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3296 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3298 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3299 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3300 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3301 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3302 | is_unicode = true; |
| 3303 | else |
| 3304 | is_unicode = false; |
| 3305 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3306 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3307 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3308 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3309 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3310 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | } |
| 3312 | } |
| 3313 | cifs_buf_release(pSMB); |
| 3314 | if (rc == -EAGAIN) |
| 3315 | goto querySymLinkRetry; |
| 3316 | return rc; |
| 3317 | } |
| 3318 | |
Steve French | c52a9554 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3319 | /* |
| 3320 | * Recent Windows versions now create symlinks more frequently |
| 3321 | * and they use the "reparse point" mechanism below. We can of course |
| 3322 | * do symlinks nicely to Samba and other servers which support the |
| 3323 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3324 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3325 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3326 | * In the interim this code has been moved to its own config option so |
| 3327 | * it is not compiled in by default until callers fixed up and more tested. |
| 3328 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | int |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3330 | CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
| 3331 | __u16 fid, char **symlinkinfo, |
| 3332 | const struct nls_table *nls_codepage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | { |
| 3334 | int rc = 0; |
| 3335 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3336 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3337 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3338 | bool is_unicode; |
| 3339 | unsigned int sub_len; |
| 3340 | char *sub_start; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3341 | struct reparse_symlink_data *reparse_buf; |
| 3342 | struct reparse_posix_data *posix_buf; |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3343 | __u32 data_offset, data_count; |
| 3344 | char *end_of_smb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3346 | 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] | 3347 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3348 | (void **) &pSMBr); |
| 3349 | if (rc) |
| 3350 | return rc; |
| 3351 | |
| 3352 | pSMB->TotalParameterCount = 0 ; |
| 3353 | pSMB->TotalDataCount = 0; |
| 3354 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3355 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3356 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | pSMB->MaxSetupCount = 4; |
| 3358 | pSMB->Reserved = 0; |
| 3359 | pSMB->ParameterOffset = 0; |
| 3360 | pSMB->DataCount = 0; |
| 3361 | pSMB->DataOffset = 0; |
| 3362 | pSMB->SetupCount = 4; |
| 3363 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3364 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3365 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3366 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3367 | pSMB->IsRootFlag = 0; |
| 3368 | pSMB->Fid = fid; /* file handle always le */ |
| 3369 | pSMB->ByteCount = 0; |
| 3370 | |
| 3371 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3372 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3373 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3374 | cifs_dbg(FYI, "Send error in QueryReparseLinkInfo = %d\n", rc); |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3375 | goto qreparse_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3377 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3378 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3379 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3380 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3381 | /* BB also check enough total bytes returned */ |
| 3382 | rc = -EIO; /* bad smb */ |
| 3383 | goto qreparse_out; |
| 3384 | } |
| 3385 | if (!data_count || (data_count > 2048)) { |
| 3386 | rc = -EIO; |
| 3387 | cifs_dbg(FYI, "Invalid return data count on get reparse info ioctl\n"); |
| 3388 | goto qreparse_out; |
| 3389 | } |
| 3390 | end_of_smb = 2 + get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3391 | reparse_buf = (struct reparse_symlink_data *) |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3392 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
| 3393 | if ((char *)reparse_buf >= end_of_smb) { |
| 3394 | rc = -EIO; |
| 3395 | goto qreparse_out; |
| 3396 | } |
Steve French | c31f330 | 2013-09-28 18:24:12 -0500 | [diff] [blame] | 3397 | if (reparse_buf->ReparseTag == cpu_to_le32(IO_REPARSE_TAG_NFS)) { |
| 3398 | cifs_dbg(FYI, "NFS style reparse tag\n"); |
| 3399 | posix_buf = (struct reparse_posix_data *)reparse_buf; |
| 3400 | |
| 3401 | if (posix_buf->InodeType != cpu_to_le64(NFS_SPECFILE_LNK)) { |
| 3402 | cifs_dbg(FYI, "unsupported file type 0x%llx\n", |
| 3403 | le64_to_cpu(posix_buf->InodeType)); |
| 3404 | rc = -EOPNOTSUPP; |
| 3405 | goto qreparse_out; |
| 3406 | } |
| 3407 | is_unicode = true; |
| 3408 | sub_len = le16_to_cpu(reparse_buf->ReparseDataLength); |
| 3409 | if (posix_buf->PathBuffer + sub_len > end_of_smb) { |
| 3410 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3411 | rc = -EIO; |
| 3412 | goto qreparse_out; |
| 3413 | } |
| 3414 | *symlinkinfo = cifs_strndup_from_utf16(posix_buf->PathBuffer, |
| 3415 | sub_len, is_unicode, nls_codepage); |
| 3416 | goto qreparse_out; |
| 3417 | } else if (reparse_buf->ReparseTag != |
| 3418 | cpu_to_le32(IO_REPARSE_TAG_SYMLINK)) { |
| 3419 | rc = -EOPNOTSUPP; |
| 3420 | goto qreparse_out; |
| 3421 | } |
| 3422 | |
| 3423 | /* Reparse tag is NTFS symlink */ |
| 3424 | sub_start = le16_to_cpu(reparse_buf->SubstituteNameOffset) + |
| 3425 | reparse_buf->PathBuffer; |
| 3426 | sub_len = le16_to_cpu(reparse_buf->SubstituteNameLength); |
| 3427 | if (sub_start + sub_len > end_of_smb) { |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3428 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
| 3429 | rc = -EIO; |
| 3430 | goto qreparse_out; |
| 3431 | } |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3432 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3433 | is_unicode = true; |
| 3434 | else |
| 3435 | is_unicode = false; |
| 3436 | |
| 3437 | /* BB FIXME investigate remapping reserved chars here */ |
| 3438 | *symlinkinfo = cifs_strndup_from_utf16(sub_start, sub_len, is_unicode, |
| 3439 | nls_codepage); |
| 3440 | if (!*symlinkinfo) |
| 3441 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3443 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | |
Pavel Shilovsky | d244bf2 | 2013-08-14 19:25:22 +0400 | [diff] [blame] | 3445 | /* |
| 3446 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3447 | * since file handle passed in no longer valid. |
| 3448 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | return rc; |
| 3450 | } |
| 3451 | |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3452 | int |
| 3453 | CIFSSMB_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 3454 | __u16 fid) |
| 3455 | { |
| 3456 | int rc = 0; |
| 3457 | int bytes_returned; |
| 3458 | struct smb_com_transaction_compr_ioctl_req *pSMB; |
| 3459 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
| 3460 | |
| 3461 | cifs_dbg(FYI, "Set compression for %u\n", fid); |
| 3462 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3463 | (void **) &pSMBr); |
| 3464 | if (rc) |
| 3465 | return rc; |
| 3466 | |
| 3467 | pSMB->compression_state = cpu_to_le16(COMPRESSION_FORMAT_DEFAULT); |
| 3468 | |
| 3469 | pSMB->TotalParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3470 | pSMB->TotalDataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3471 | pSMB->MaxParameterCount = 0; |
| 3472 | pSMB->MaxDataCount = 0; |
| 3473 | pSMB->MaxSetupCount = 4; |
| 3474 | pSMB->Reserved = 0; |
| 3475 | pSMB->ParameterOffset = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3476 | pSMB->DataCount = cpu_to_le32(2); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3477 | pSMB->DataOffset = |
| 3478 | cpu_to_le32(offsetof(struct smb_com_transaction_compr_ioctl_req, |
| 3479 | compression_state) - 4); /* 84 */ |
| 3480 | pSMB->SetupCount = 4; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3481 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3482 | pSMB->ParameterCount = 0; |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3483 | pSMB->FunctionCode = cpu_to_le32(FSCTL_SET_COMPRESSION); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3484 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3485 | pSMB->IsRootFlag = 0; |
| 3486 | pSMB->Fid = fid; /* file handle always le */ |
| 3487 | /* 3 byte pad, followed by 2 byte compress state */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3488 | pSMB->ByteCount = cpu_to_le16(5); |
Steve French | c7f508a | 2013-10-14 15:27:32 -0500 | [diff] [blame] | 3489 | inc_rfc1001_len(pSMB, 5); |
| 3490 | |
| 3491 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3492 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3493 | if (rc) |
| 3494 | cifs_dbg(FYI, "Send error in SetCompression = %d\n", rc); |
| 3495 | |
| 3496 | cifs_buf_release(pSMB); |
| 3497 | |
| 3498 | /* |
| 3499 | * Note: On -EAGAIN error only caller can retry on handle based calls |
| 3500 | * since file handle passed in no longer valid. |
| 3501 | */ |
| 3502 | return rc; |
| 3503 | } |
| 3504 | |
| 3505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | #ifdef CONFIG_CIFS_POSIX |
| 3507 | |
| 3508 | /*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] | 3509 | static void cifs_convert_ace(struct posix_acl_xattr_entry *ace, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3510 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | { |
| 3512 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3513 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3514 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3515 | 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] | 3516 | /* |
| 3517 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3518 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3519 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | |
| 3521 | return; |
| 3522 | } |
| 3523 | |
| 3524 | /* 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] | 3525 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3526 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | { |
| 3528 | int size = 0; |
| 3529 | int i; |
| 3530 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3531 | struct cifs_posix_ace *pACE; |
| 3532 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3533 | struct posix_acl_xattr_header *local_acl = (void *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | |
| 3535 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3536 | return -EOPNOTSUPP; |
| 3537 | |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3538 | if (acl_type == ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3540 | pACE = &cifs_acl->ace_array[0]; |
| 3541 | size = sizeof(struct cifs_posix_acl); |
| 3542 | size += sizeof(struct cifs_posix_ace) * count; |
| 3543 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3544 | if (size_of_data_area < size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3545 | cifs_dbg(FYI, "bad CIFS POSIX ACL size %d vs. %d\n", |
| 3546 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | return -EINVAL; |
| 3548 | } |
Andreas Gruenbacher | 45987e0 | 2016-04-14 00:30:14 +0200 | [diff] [blame] | 3549 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3551 | size = sizeof(struct cifs_posix_acl); |
| 3552 | size += sizeof(struct cifs_posix_ace) * count; |
| 3553 | /* skip past access ACEs to get to default ACEs */ |
| 3554 | pACE = &cifs_acl->ace_array[count]; |
| 3555 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3556 | size += sizeof(struct cifs_posix_ace) * count; |
| 3557 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3558 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | return -EINVAL; |
| 3560 | } else { |
| 3561 | /* illegal type */ |
| 3562 | return -EINVAL; |
| 3563 | } |
| 3564 | |
| 3565 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3566 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3567 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3568 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | return -ERANGE; |
| 3570 | } else /* buffer big enough */ { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3571 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
| 3572 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3573 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3574 | for (i = 0; i < count ; i++) { |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3575 | cifs_convert_ace(&ace[i], pACE); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3576 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | } |
| 3578 | } |
| 3579 | return size; |
| 3580 | } |
| 3581 | |
Hariprasad Kelam | 0aa3a24 | 2019-07-02 23:50:02 +0530 | [diff] [blame] | 3582 | 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] | 3583 | const struct posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3585 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3586 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3588 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3590 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3591 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3592 | 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] | 3593 | /* |
| 3594 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3595 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3596 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | /* 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] | 3600 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3601 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | { |
| 3603 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3604 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
Andreas Gruenbacher | 2211d5b | 2016-09-27 13:03:22 +0200 | [diff] [blame] | 3605 | struct posix_acl_xattr_header *local_acl = (void *)pACL; |
Eryu Guan | ae9ebe7 | 2016-10-24 20:46:40 +0800 | [diff] [blame] | 3606 | struct posix_acl_xattr_entry *ace = (void *)(local_acl + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | int count; |
| 3608 | int i; |
| 3609 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3610 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | return 0; |
| 3612 | |
| 3613 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3614 | cifs_dbg(FYI, "setting acl with %d entries from buf of length %d and version of %d\n", |
| 3615 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3616 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3617 | cifs_dbg(FYI, "unknown POSIX ACL version %d\n", |
| 3618 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | return 0; |
| 3620 | } |
| 3621 | cifs_acl->version = cpu_to_le16(1); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3622 | if (acl_type == ACL_TYPE_ACCESS) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3623 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3624 | cifs_acl->default_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3625 | } else if (acl_type == ACL_TYPE_DEFAULT) { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3626 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 3627 | cifs_acl->access_entry_count = cpu_to_le16(0xFFFF); |
Steve French | b1d9335 | 2013-11-15 20:41:32 -0600 | [diff] [blame] | 3628 | } else { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3629 | cifs_dbg(FYI, "unknown ACL type %d\n", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | return 0; |
| 3631 | } |
Hariprasad Kelam | 0aa3a24 | 2019-07-02 23:50:02 +0530 | [diff] [blame] | 3632 | for (i = 0; i < count; i++) |
| 3633 | convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], &ace[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3634 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3636 | rc += sizeof(struct cifs_posix_acl); |
| 3637 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3638 | } |
| 3639 | return rc; |
| 3640 | } |
| 3641 | |
| 3642 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3643 | CIFSSMBGetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3644 | const unsigned char *searchName, |
| 3645 | char *acl_inf, const int buflen, const int acl_type, |
| 3646 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | { |
| 3648 | /* SMB_QUERY_POSIX_ACL */ |
| 3649 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3650 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3651 | int rc = 0; |
| 3652 | int bytes_returned; |
| 3653 | int name_len; |
| 3654 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3655 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3656 | cifs_dbg(FYI, "In GetPosixACL (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | |
| 3658 | queryAclRetry: |
| 3659 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3660 | (void **) &pSMBr); |
| 3661 | if (rc) |
| 3662 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3665 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3666 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3667 | searchName, PATH_MAX, nls_codepage, |
| 3668 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | name_len++; /* trailing null */ |
| 3670 | name_len *= 2; |
| 3671 | pSMB->FileName[name_len] = 0; |
| 3672 | pSMB->FileName[name_len+1] = 0; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3673 | } else { |
| 3674 | name_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | } |
| 3676 | |
| 3677 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3678 | pSMB->TotalDataCount = 0; |
| 3679 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3680 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3682 | pSMB->MaxSetupCount = 0; |
| 3683 | pSMB->Reserved = 0; |
| 3684 | pSMB->Flags = 0; |
| 3685 | pSMB->Timeout = 0; |
| 3686 | pSMB->Reserved2 = 0; |
| 3687 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3688 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3689 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | pSMB->DataCount = 0; |
| 3691 | pSMB->DataOffset = 0; |
| 3692 | pSMB->SetupCount = 1; |
| 3693 | pSMB->Reserved3 = 0; |
| 3694 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3695 | byte_count = params + 1 /* pad */ ; |
| 3696 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3697 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3698 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3699 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3700 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3702 | |
| 3703 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3704 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3705 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3707 | cifs_dbg(FYI, "Send error in Query POSIX ACL = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | } else { |
| 3709 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3713 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | rc = -EIO; /* bad smb */ |
| 3715 | else { |
| 3716 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3717 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3718 | rc = cifs_copy_posix_acl(acl_inf, |
| 3719 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3720 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | } |
| 3722 | } |
| 3723 | cifs_buf_release(pSMB); |
| 3724 | if (rc == -EAGAIN) |
| 3725 | goto queryAclRetry; |
| 3726 | return rc; |
| 3727 | } |
| 3728 | |
| 3729 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3730 | CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3731 | const unsigned char *fileName, |
| 3732 | const char *local_acl, const int buflen, |
| 3733 | const int acl_type, |
| 3734 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | { |
| 3736 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3737 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3738 | char *parm_data; |
| 3739 | int name_len; |
| 3740 | int rc = 0; |
| 3741 | int bytes_returned = 0; |
| 3742 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3743 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3744 | cifs_dbg(FYI, "In SetPosixACL (Unix) for path %s\n", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | setAclRetry: |
| 3746 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3747 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | if (rc) |
| 3749 | return rc; |
| 3750 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3751 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3752 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3753 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | name_len++; /* trailing null */ |
| 3755 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 3756 | } else { |
| 3757 | name_len = copy_path_name(pSMB->FileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | } |
| 3759 | params = 6 + name_len; |
| 3760 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3761 | /* BB find max SMB size from sess */ |
| 3762 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | pSMB->MaxSetupCount = 0; |
| 3764 | pSMB->Reserved = 0; |
| 3765 | pSMB->Flags = 0; |
| 3766 | pSMB->Timeout = 0; |
| 3767 | pSMB->Reserved2 = 0; |
| 3768 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3769 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | offset = param_offset + params; |
| 3771 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3772 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3773 | |
| 3774 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3775 | 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] | 3776 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3777 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | rc = -EOPNOTSUPP; |
| 3779 | goto setACLerrorExit; |
| 3780 | } |
| 3781 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3782 | pSMB->SetupCount = 1; |
| 3783 | pSMB->Reserved3 = 0; |
| 3784 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3785 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3786 | byte_count = 3 /* pad */ + params + data_count; |
| 3787 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3788 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3789 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3790 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3791 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3792 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3794 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3795 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3796 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3797 | cifs_dbg(FYI, "Set POSIX ACL returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | |
| 3799 | setACLerrorExit: |
| 3800 | cifs_buf_release(pSMB); |
| 3801 | if (rc == -EAGAIN) |
| 3802 | goto setAclRetry; |
| 3803 | return rc; |
| 3804 | } |
| 3805 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3806 | /* BB fix tabs in this function FIXME BB */ |
| 3807 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3808 | CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3809 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3810 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3811 | int rc = 0; |
| 3812 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3813 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3814 | int bytes_returned; |
| 3815 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3816 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3817 | cifs_dbg(FYI, "In GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3818 | if (tcon == NULL) |
| 3819 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3820 | |
| 3821 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3822 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3823 | (void **) &pSMBr); |
| 3824 | if (rc) |
| 3825 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3826 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3827 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3828 | pSMB->t2.TotalDataCount = 0; |
| 3829 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3830 | /* BB find exact max data count below from sess structure BB */ |
| 3831 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3832 | pSMB->t2.MaxSetupCount = 0; |
| 3833 | pSMB->t2.Reserved = 0; |
| 3834 | pSMB->t2.Flags = 0; |
| 3835 | pSMB->t2.Timeout = 0; |
| 3836 | pSMB->t2.Reserved2 = 0; |
| 3837 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3838 | Fid) - 4); |
| 3839 | pSMB->t2.DataCount = 0; |
| 3840 | pSMB->t2.DataOffset = 0; |
| 3841 | pSMB->t2.SetupCount = 1; |
| 3842 | pSMB->t2.Reserved3 = 0; |
| 3843 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3844 | byte_count = params + 1 /* pad */ ; |
| 3845 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3846 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3847 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3848 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3849 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3850 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3851 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3852 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3853 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3854 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3855 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3856 | cifs_dbg(FYI, "error %d in GetExtAttr\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3857 | } else { |
| 3858 | /* decode response */ |
| 3859 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3860 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3861 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3862 | /* If rc should we check for EOPNOSUPP and |
| 3863 | disable the srvino flag? or in caller? */ |
| 3864 | rc = -EIO; /* bad smb */ |
| 3865 | else { |
| 3866 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3867 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3868 | struct file_chattr_info *pfinfo; |
| 3869 | /* BB Do we need a cast or hash here ? */ |
| 3870 | if (count != 16) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3871 | cifs_dbg(FYI, "Illegal size ret in GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3872 | rc = -EIO; |
| 3873 | goto GetExtAttrOut; |
| 3874 | } |
| 3875 | pfinfo = (struct file_chattr_info *) |
| 3876 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3877 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3878 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3879 | } |
| 3880 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3881 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3882 | cifs_buf_release(pSMB); |
| 3883 | if (rc == -EAGAIN) |
| 3884 | goto GetExtAttrRetry; |
| 3885 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3888 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3890 | /* |
| 3891 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3892 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3893 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3894 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3895 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3896 | * by caller |
| 3897 | */ |
| 3898 | static int |
| 3899 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3900 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3901 | void **ret_buf) |
| 3902 | { |
| 3903 | int rc; |
| 3904 | __u32 temp_offset; |
| 3905 | struct smb_com_ntransact_req *pSMB; |
| 3906 | |
| 3907 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3908 | (void **)&pSMB); |
| 3909 | if (rc) |
| 3910 | return rc; |
| 3911 | *ret_buf = (void *)pSMB; |
| 3912 | pSMB->Reserved = 0; |
| 3913 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3914 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3915 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3916 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3917 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3918 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3919 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3920 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3921 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3922 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3923 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3924 | return 0; |
| 3925 | } |
| 3926 | |
| 3927 | static int |
| 3928 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3929 | __u32 *pparmlen, __u32 *pdatalen) |
| 3930 | { |
| 3931 | char *end_of_smb; |
| 3932 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3933 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3934 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3935 | |
| 3936 | *pdatalen = 0; |
| 3937 | *pparmlen = 0; |
| 3938 | |
| 3939 | if (buf == NULL) |
| 3940 | return -EINVAL; |
| 3941 | |
| 3942 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3943 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3944 | bcc = get_bcc(&pSMBr->hdr); |
| 3945 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3946 | (char *)&pSMBr->ByteCount; |
| 3947 | |
| 3948 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3949 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3950 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3951 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3952 | |
| 3953 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3954 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3955 | |
| 3956 | /* should we also check that parm and data areas do not overlap? */ |
| 3957 | if (*ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3958 | cifs_dbg(FYI, "parms start after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3959 | return -EINVAL; |
| 3960 | } else if (parm_count + *ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3961 | cifs_dbg(FYI, "parm end after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3962 | return -EINVAL; |
| 3963 | } else if (*ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3964 | cifs_dbg(FYI, "data starts after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3965 | return -EINVAL; |
| 3966 | } else if (data_count + *ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3967 | cifs_dbg(FYI, "data %p + count %d (%p) past smb end %p start %p\n", |
| 3968 | *ppdata, data_count, (data_count + *ppdata), |
| 3969 | end_of_smb, pSMBr); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3970 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3971 | } else if (parm_count + data_count > bcc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3972 | cifs_dbg(FYI, "parm count and data count larger than SMB\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3973 | return -EINVAL; |
| 3974 | } |
| 3975 | *pdatalen = data_count; |
| 3976 | *pparmlen = parm_count; |
| 3977 | return 0; |
| 3978 | } |
| 3979 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3980 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3981 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3982 | CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3983 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3984 | { |
| 3985 | int rc = 0; |
| 3986 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3987 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3988 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3989 | struct kvec rsp_iov; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3990 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3991 | cifs_dbg(FYI, "GetCifsACL\n"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3992 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3993 | *pbuflen = 0; |
| 3994 | *acl_inf = NULL; |
| 3995 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3996 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3997 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3998 | if (rc) |
| 3999 | return rc; |
| 4000 | |
| 4001 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 4002 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 4003 | pSMB->MaxSetupCount = 0; |
| 4004 | pSMB->Fid = fid; /* file handle always le */ |
| 4005 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 4006 | CIFS_ACL_DACL); |
| 4007 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4008 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4009 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4010 | 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] | 4011 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 4012 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4013 | 0, &rsp_iov); |
| 4014 | cifs_small_buf_release(pSMB); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4015 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4016 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4017 | cifs_dbg(FYI, "Send error in QuerySecDesc = %d\n", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4018 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4019 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4020 | __u32 parm_len; |
| 4021 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4022 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4023 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4024 | |
| 4025 | /* validate_nttransact */ |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4026 | rc = validate_ntransact(rsp_iov.iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4027 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4028 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4029 | goto qsec_out; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4030 | pSMBr = (struct smb_com_ntransact_rsp *)rsp_iov.iov_base; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4031 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4032 | cifs_dbg(FYI, "smb %p parm %p data %p\n", |
| 4033 | pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4034 | |
| 4035 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 4036 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4037 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4038 | goto qsec_out; |
| 4039 | } |
| 4040 | |
| 4041 | /* BB check that data area is minimum length and as big as acl_len */ |
| 4042 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 4043 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4044 | if (acl_len != *pbuflen) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4045 | cifs_dbg(VFS, "acl length %d does not match %d\n", |
| 4046 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4047 | if (*pbuflen > acl_len) |
| 4048 | *pbuflen = acl_len; |
| 4049 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4050 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4051 | /* check if buffer is big enough for the acl |
| 4052 | header followed by the smallest SID */ |
| 4053 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 4054 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4055 | cifs_dbg(VFS, "bad acl length %d\n", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4056 | rc = -EINVAL; |
| 4057 | *pbuflen = 0; |
| 4058 | } else { |
Silviu-Mihai Popescu | f7f7c18 | 2013-03-11 18:22:32 +0200 | [diff] [blame] | 4059 | *acl_inf = kmemdup(pdata, *pbuflen, GFP_KERNEL); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4060 | if (*acl_inf == NULL) { |
| 4061 | *pbuflen = 0; |
| 4062 | rc = -ENOMEM; |
| 4063 | } |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4064 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4065 | } |
| 4066 | qsec_out: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4067 | free_rsp_buf(buf_type, rsp_iov.iov_base); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4068 | return rc; |
| 4069 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4070 | |
| 4071 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4072 | CIFSSMBSetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 4073 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4074 | { |
| 4075 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 4076 | int rc = 0; |
| 4077 | int bytes_returned = 0; |
| 4078 | SET_SEC_DESC_REQ *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 4079 | void *pSMBr; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4080 | |
| 4081 | setCifsAclRetry: |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 4082 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4083 | if (rc) |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 4084 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4085 | |
| 4086 | pSMB->MaxSetupCount = 0; |
| 4087 | pSMB->Reserved = 0; |
| 4088 | |
| 4089 | param_count = 8; |
| 4090 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 4091 | data_count = acllen; |
| 4092 | data_offset = param_offset + param_count; |
| 4093 | byte_count = 3 /* pad */ + param_count; |
| 4094 | |
| 4095 | pSMB->DataCount = cpu_to_le32(data_count); |
| 4096 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4097 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 4098 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 4099 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 4100 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 4101 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4102 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 4103 | pSMB->SetupCount = 0; |
| 4104 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 4105 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 4106 | |
| 4107 | pSMB->Fid = fid; /* file handle always le */ |
| 4108 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 4109 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4110 | |
| 4111 | if (pntsd && acllen) { |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 4112 | memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + |
| 4113 | data_offset, pntsd, acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4114 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4115 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4116 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4117 | |
| 4118 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4119 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4120 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4121 | cifs_dbg(FYI, "SetCIFSACL bytes_returned: %d, rc: %d\n", |
| 4122 | bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4123 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4124 | cifs_dbg(FYI, "Set CIFS ACL returned %d\n", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 4125 | cifs_buf_release(pSMB); |
| 4126 | |
| 4127 | if (rc == -EAGAIN) |
| 4128 | goto setCifsAclRetry; |
| 4129 | |
| 4130 | return (rc); |
| 4131 | } |
| 4132 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 4133 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4134 | /* Legacy Query Path Information call for lookup to old servers such |
| 4135 | as Win9x/WinME */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4136 | int |
| 4137 | SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, |
| 4138 | const char *search_name, FILE_ALL_INFO *data, |
| 4139 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4140 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4141 | QUERY_INFORMATION_REQ *pSMB; |
| 4142 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4143 | int rc = 0; |
| 4144 | int bytes_returned; |
| 4145 | int name_len; |
| 4146 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4147 | cifs_dbg(FYI, "In SMBQPath path %s\n", search_name); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4148 | QInfRetry: |
| 4149 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4150 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4151 | if (rc) |
| 4152 | return rc; |
| 4153 | |
| 4154 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4155 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4156 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4157 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4158 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4159 | name_len++; /* trailing null */ |
| 4160 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4161 | } else { |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4162 | name_len = copy_path_name(pSMB->FileName, search_name); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4163 | } |
| 4164 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4165 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4166 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4167 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 4168 | |
| 4169 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4170 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4171 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4172 | cifs_dbg(FYI, "Send error in QueryInfo = %d\n", rc); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4173 | } else if (data) { |
Arnd Bergmann | 9539020 | 2018-06-19 17:27:58 +0200 | [diff] [blame] | 4174 | struct timespec64 ts; |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4175 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4176 | |
| 4177 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4178 | /* BB FIXME - add time zone adjustment BB */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4179 | memset(data, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 4180 | ts.tv_nsec = 0; |
| 4181 | ts.tv_sec = time; |
| 4182 | /* decode time fields */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4183 | data->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
| 4184 | data->LastWriteTime = data->ChangeTime; |
| 4185 | data->LastAccessTime = 0; |
| 4186 | data->AllocationSize = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4187 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4188 | data->EndOfFile = data->AllocationSize; |
| 4189 | data->Attributes = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 4190 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4191 | } else |
| 4192 | rc = -EIO; /* bad buffer passed in */ |
| 4193 | |
| 4194 | cifs_buf_release(pSMB); |
| 4195 | |
| 4196 | if (rc == -EAGAIN) |
| 4197 | goto QInfRetry; |
| 4198 | |
| 4199 | return rc; |
| 4200 | } |
| 4201 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4202 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4203 | CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4204 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 4205 | { |
| 4206 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4207 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4208 | int rc = 0; |
| 4209 | int bytes_returned; |
| 4210 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4211 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4212 | QFileInfoRetry: |
| 4213 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4214 | (void **) &pSMBr); |
| 4215 | if (rc) |
| 4216 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4217 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4218 | params = 2 /* level */ + 2 /* fid */; |
| 4219 | pSMB->t2.TotalDataCount = 0; |
| 4220 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4221 | /* BB find exact max data count below from sess structure BB */ |
| 4222 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4223 | pSMB->t2.MaxSetupCount = 0; |
| 4224 | pSMB->t2.Reserved = 0; |
| 4225 | pSMB->t2.Flags = 0; |
| 4226 | pSMB->t2.Timeout = 0; |
| 4227 | pSMB->t2.Reserved2 = 0; |
| 4228 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4229 | Fid) - 4); |
| 4230 | pSMB->t2.DataCount = 0; |
| 4231 | pSMB->t2.DataOffset = 0; |
| 4232 | pSMB->t2.SetupCount = 1; |
| 4233 | pSMB->t2.Reserved3 = 0; |
| 4234 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4235 | byte_count = params + 1 /* pad */ ; |
| 4236 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4237 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4238 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 4239 | pSMB->Pad = 0; |
| 4240 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4241 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4242 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4243 | |
| 4244 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4245 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4246 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4247 | cifs_dbg(FYI, "Send error in QFileInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4248 | } else { /* decode response */ |
| 4249 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4250 | |
| 4251 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4252 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4253 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 4254 | rc = -EIO; /* bad smb */ |
| 4255 | else if (pFindData) { |
| 4256 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4257 | memcpy((char *) pFindData, |
| 4258 | (char *) &pSMBr->hdr.Protocol + |
| 4259 | data_offset, sizeof(FILE_ALL_INFO)); |
| 4260 | } else |
| 4261 | rc = -ENOMEM; |
| 4262 | } |
| 4263 | cifs_buf_release(pSMB); |
| 4264 | if (rc == -EAGAIN) |
| 4265 | goto QFileInfoRetry; |
| 4266 | |
| 4267 | return rc; |
| 4268 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 4269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4271 | CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4272 | const char *search_name, FILE_ALL_INFO *data, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4273 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4274 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | { |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4276 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4278 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4279 | int rc = 0; |
| 4280 | int bytes_returned; |
| 4281 | int name_len; |
| 4282 | __u16 params, byte_count; |
| 4283 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4284 | /* cifs_dbg(FYI, "In QPathInfo path %s\n", search_name); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | QPathInfoRetry: |
| 4286 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4287 | (void **) &pSMBr); |
| 4288 | if (rc) |
| 4289 | return rc; |
| 4290 | |
| 4291 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4292 | name_len = |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4293 | cifsConvertToUTF16((__le16 *) pSMB->FileName, search_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4294 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | name_len++; /* trailing null */ |
| 4296 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4297 | } else { |
| 4298 | name_len = copy_path_name(pSMB->FileName, search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4301 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | pSMB->TotalDataCount = 0; |
| 4303 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4304 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4305 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | pSMB->MaxSetupCount = 0; |
| 4307 | pSMB->Reserved = 0; |
| 4308 | pSMB->Flags = 0; |
| 4309 | pSMB->Timeout = 0; |
| 4310 | pSMB->Reserved2 = 0; |
| 4311 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4312 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | pSMB->DataCount = 0; |
| 4314 | pSMB->DataOffset = 0; |
| 4315 | pSMB->SetupCount = 1; |
| 4316 | pSMB->Reserved3 = 0; |
| 4317 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4318 | byte_count = params + 1 /* pad */ ; |
| 4319 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4320 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4321 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4322 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4323 | else |
| 4324 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4326 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4328 | |
| 4329 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4330 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4331 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4332 | cifs_dbg(FYI, "Send error in QPathInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | } else { /* decode response */ |
| 4334 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4335 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4336 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4337 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4338 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4340 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4341 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4342 | last field */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4343 | else if (data) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4344 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4346 | |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4347 | /* |
| 4348 | * On legacy responses we do not read the last field, |
| 4349 | * EAsize, fortunately since it varies by subdialect and |
| 4350 | * also note it differs on Set vs Get, ie two bytes or 4 |
| 4351 | * bytes depending but we don't care here. |
| 4352 | */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4353 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4354 | size = sizeof(FILE_INFO_STANDARD); |
| 4355 | else |
| 4356 | size = sizeof(FILE_ALL_INFO); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4357 | memcpy((char *) data, (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4358 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | } else |
| 4360 | rc = -ENOMEM; |
| 4361 | } |
| 4362 | cifs_buf_release(pSMB); |
| 4363 | if (rc == -EAGAIN) |
| 4364 | goto QPathInfoRetry; |
| 4365 | |
| 4366 | return rc; |
| 4367 | } |
| 4368 | |
| 4369 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4370 | CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4371 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4372 | { |
| 4373 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4374 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4375 | int rc = 0; |
| 4376 | int bytes_returned; |
| 4377 | __u16 params, byte_count; |
| 4378 | |
| 4379 | UnixQFileInfoRetry: |
| 4380 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4381 | (void **) &pSMBr); |
| 4382 | if (rc) |
| 4383 | return rc; |
| 4384 | |
| 4385 | params = 2 /* level */ + 2 /* fid */; |
| 4386 | pSMB->t2.TotalDataCount = 0; |
| 4387 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4388 | /* BB find exact max data count below from sess structure BB */ |
| 4389 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4390 | pSMB->t2.MaxSetupCount = 0; |
| 4391 | pSMB->t2.Reserved = 0; |
| 4392 | pSMB->t2.Flags = 0; |
| 4393 | pSMB->t2.Timeout = 0; |
| 4394 | pSMB->t2.Reserved2 = 0; |
| 4395 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4396 | Fid) - 4); |
| 4397 | pSMB->t2.DataCount = 0; |
| 4398 | pSMB->t2.DataOffset = 0; |
| 4399 | pSMB->t2.SetupCount = 1; |
| 4400 | pSMB->t2.Reserved3 = 0; |
| 4401 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4402 | byte_count = params + 1 /* pad */ ; |
| 4403 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4404 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4405 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4406 | pSMB->Pad = 0; |
| 4407 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4408 | inc_rfc1001_len(pSMB, byte_count); |
David Disseldorp | 7ac0feb | 2013-06-28 11:47:33 +0200 | [diff] [blame] | 4409 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4410 | |
| 4411 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4412 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4413 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4414 | cifs_dbg(FYI, "Send error in UnixQFileInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4415 | } else { /* decode response */ |
| 4416 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4417 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4418 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4419 | 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] | 4420 | rc = -EIO; /* bad smb */ |
| 4421 | } else { |
| 4422 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4423 | memcpy((char *) pFindData, |
| 4424 | (char *) &pSMBr->hdr.Protocol + |
| 4425 | data_offset, |
| 4426 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | cifs_buf_release(pSMB); |
| 4431 | if (rc == -EAGAIN) |
| 4432 | goto UnixQFileInfoRetry; |
| 4433 | |
| 4434 | return rc; |
| 4435 | } |
| 4436 | |
| 4437 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4438 | CIFSSMBUnixQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4440 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4441 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | { |
| 4443 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4444 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4445 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4446 | int rc = 0; |
| 4447 | int bytes_returned = 0; |
| 4448 | int name_len; |
| 4449 | __u16 params, byte_count; |
| 4450 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4451 | cifs_dbg(FYI, "In QPathInfo (Unix) the path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | UnixQPathInfoRetry: |
| 4453 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4454 | (void **) &pSMBr); |
| 4455 | if (rc) |
| 4456 | return rc; |
| 4457 | |
| 4458 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4459 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4460 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4461 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | name_len++; /* trailing null */ |
| 4463 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4464 | } else { |
| 4465 | name_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4468 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | pSMB->TotalDataCount = 0; |
| 4470 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4471 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4472 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | pSMB->MaxSetupCount = 0; |
| 4474 | pSMB->Reserved = 0; |
| 4475 | pSMB->Flags = 0; |
| 4476 | pSMB->Timeout = 0; |
| 4477 | pSMB->Reserved2 = 0; |
| 4478 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4479 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | pSMB->DataCount = 0; |
| 4481 | pSMB->DataOffset = 0; |
| 4482 | pSMB->SetupCount = 1; |
| 4483 | pSMB->Reserved3 = 0; |
| 4484 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4485 | byte_count = params + 1 /* pad */ ; |
| 4486 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4487 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4488 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4489 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4490 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4492 | |
| 4493 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4494 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4495 | if (rc) { |
Steve French | ebcc943 | 2013-12-09 09:18:09 -0600 | [diff] [blame] | 4496 | cifs_dbg(FYI, "Send error in UnixQPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | } else { /* decode response */ |
| 4498 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4499 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4500 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4501 | 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] | 4502 | rc = -EIO; /* bad smb */ |
| 4503 | } else { |
| 4504 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4505 | memcpy((char *) pFindData, |
| 4506 | (char *) &pSMBr->hdr.Protocol + |
| 4507 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4508 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | } |
| 4510 | } |
| 4511 | cifs_buf_release(pSMB); |
| 4512 | if (rc == -EAGAIN) |
| 4513 | goto UnixQPathInfoRetry; |
| 4514 | |
| 4515 | return rc; |
| 4516 | } |
| 4517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4519 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4520 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4521 | const char *searchName, struct cifs_sb_info *cifs_sb, |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4522 | __u16 *pnetfid, __u16 search_flags, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4523 | struct cifs_search_info *psrch_inf, bool msearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | { |
| 4525 | /* level 257 SMB_ */ |
| 4526 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4527 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4528 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | int rc = 0; |
| 4530 | int bytes_returned = 0; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4531 | int name_len, remap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | __u16 params, byte_count; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4533 | struct nls_table *nls_codepage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4535 | cifs_dbg(FYI, "In FindFirst for %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | |
| 4537 | findFirstRetry: |
| 4538 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4539 | (void **) &pSMBr); |
| 4540 | if (rc) |
| 4541 | return rc; |
| 4542 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4543 | nls_codepage = cifs_sb->local_nls; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 4544 | remap = cifs_remap(cifs_sb); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4547 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4548 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4549 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4550 | /* We can not add the asterik earlier in case |
| 4551 | it got remapped to 0xF03A as if it were part of the |
| 4552 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | name_len *= 2; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4554 | if (msearch) { |
| 4555 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
| 4556 | pSMB->FileName[name_len+1] = 0; |
| 4557 | pSMB->FileName[name_len+2] = '*'; |
| 4558 | pSMB->FileName[name_len+3] = 0; |
| 4559 | name_len += 4; /* now the trailing null */ |
| 4560 | /* null terminate just in case */ |
| 4561 | pSMB->FileName[name_len] = 0; |
| 4562 | pSMB->FileName[name_len+1] = 0; |
| 4563 | name_len += 2; |
| 4564 | } |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4565 | } else { |
| 4566 | name_len = copy_path_name(pSMB->FileName, searchName); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4567 | if (msearch) { |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4568 | if (WARN_ON_ONCE(name_len > PATH_MAX-2)) |
| 4569 | name_len = PATH_MAX-2; |
| 4570 | /* overwrite nul byte */ |
| 4571 | pSMB->FileName[name_len-1] = CIFS_DIR_SEP(cifs_sb); |
| 4572 | pSMB->FileName[name_len] = '*'; |
| 4573 | pSMB->FileName[name_len+1] = 0; |
| 4574 | name_len += 2; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | params = 12 + name_len /* includes null */ ; |
| 4579 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4580 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4581 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | pSMB->MaxSetupCount = 0; |
| 4583 | pSMB->Reserved = 0; |
| 4584 | pSMB->Flags = 0; |
| 4585 | pSMB->Timeout = 0; |
| 4586 | pSMB->Reserved2 = 0; |
| 4587 | byte_count = params + 1 /* pad */ ; |
| 4588 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4589 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4590 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4591 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4592 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | pSMB->DataCount = 0; |
| 4594 | pSMB->DataOffset = 0; |
| 4595 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4596 | pSMB->Reserved3 = 0; |
| 4597 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4598 | pSMB->SearchAttributes = |
| 4599 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4600 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4601 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4602 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4604 | |
| 4605 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4606 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4607 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4609 | |
| 4610 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4611 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4612 | cifs_stats_inc(&tcon->stats.cifs_stats.num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4614 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4615 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4616 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4617 | cifs_dbg(FYI, "Error in FindFirst = %d\n", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4618 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4619 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4620 | |
| 4621 | /* BB eventually could optimize out free and realloc of buf */ |
| 4622 | /* for this case */ |
| 4623 | if (rc == -EAGAIN) |
| 4624 | goto findFirstRetry; |
| 4625 | } else { /* decode response */ |
| 4626 | /* BB remember to free buffer if error BB */ |
| 4627 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4628 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4629 | unsigned int lnoff; |
| 4630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4632 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4634 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | |
| 4636 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
zhengbin | 01d1bd7 | 2019-12-25 11:30:21 +0800 | [diff] [blame] | 4637 | psrch_inf->smallBuf = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4638 | psrch_inf->srch_entries_start = |
| 4639 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4642 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4643 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4644 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4645 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4647 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4649 | psrch_inf->entries_in_buffer = |
| 4650 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4651 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4653 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4654 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4655 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4656 | psrch_inf->last_entry = NULL; |
| 4657 | return rc; |
| 4658 | } |
| 4659 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4660 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4661 | lnoff; |
| 4662 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4663 | if (pnetfid) |
| 4664 | *pnetfid = parms->SearchHandle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | } else { |
| 4666 | cifs_buf_release(pSMB); |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | return rc; |
| 4671 | } |
| 4672 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4673 | int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, |
| 4674 | __u16 searchHandle, __u16 search_flags, |
| 4675 | struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | { |
| 4677 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4678 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4679 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | char *response_data; |
| 4681 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4682 | int bytes_returned; |
| 4683 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | __u16 params, byte_count; |
| 4685 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4686 | cifs_dbg(FYI, "In FindNext\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4688 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | return -ENOENT; |
| 4690 | |
| 4691 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4692 | (void **) &pSMBr); |
| 4693 | if (rc) |
| 4694 | return rc; |
| 4695 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4696 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | byte_count = 0; |
| 4698 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4699 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4700 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | pSMB->MaxSetupCount = 0; |
| 4702 | pSMB->Reserved = 0; |
| 4703 | pSMB->Flags = 0; |
| 4704 | pSMB->Timeout = 0; |
| 4705 | pSMB->Reserved2 = 0; |
| 4706 | pSMB->ParameterOffset = cpu_to_le16( |
| 4707 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4708 | pSMB->DataCount = 0; |
| 4709 | pSMB->DataOffset = 0; |
| 4710 | pSMB->SetupCount = 1; |
| 4711 | pSMB->Reserved3 = 0; |
| 4712 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4713 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4714 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4715 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4717 | pSMB->ResumeKey = psrch_inf->resume_key; |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4718 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | |
| 4720 | name_len = psrch_inf->resume_name_len; |
| 4721 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4722 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4724 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4725 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4726 | pSMB->ResumeFileName[name_len] = 0; |
| 4727 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4728 | } else { |
| 4729 | rc = -EINVAL; |
| 4730 | goto FNext2_err_exit; |
| 4731 | } |
| 4732 | byte_count = params + 1 /* pad */ ; |
| 4733 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4734 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4735 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4739 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4740 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4741 | if (rc) { |
| 4742 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4743 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4744 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4745 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | } else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4747 | cifs_dbg(FYI, "FindNext returned = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | } else { /* decode response */ |
| 4749 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4750 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4751 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4752 | unsigned int lnoff; |
| 4753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4755 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4756 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4758 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4759 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4760 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4761 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4762 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4763 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4764 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4765 | cifs_small_buf_release( |
| 4766 | psrch_inf->ntwrk_buf_start); |
| 4767 | else |
| 4768 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | psrch_inf->srch_entries_start = response_data; |
| 4770 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
zhengbin | 01d1bd7 | 2019-12-25 11:30:21 +0800 | [diff] [blame] | 4771 | psrch_inf->smallBuf = false; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4772 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4773 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4775 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4776 | psrch_inf->entries_in_buffer = |
| 4777 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4778 | psrch_inf->index_of_last_entry += |
| 4779 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4780 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4781 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4782 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4783 | psrch_inf->last_entry = NULL; |
| 4784 | return rc; |
| 4785 | } else |
| 4786 | psrch_inf->last_entry = |
| 4787 | psrch_inf->srch_entries_start + lnoff; |
| 4788 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4789 | /* cifs_dbg(FYI, "fnxt2 entries in buf %d index_of_last %d\n", |
| 4790 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | |
| 4792 | /* BB fixme add unlock here */ |
| 4793 | } |
| 4794 | |
| 4795 | } |
| 4796 | |
| 4797 | /* BB On error, should we leave previous search buf (and count and |
| 4798 | last entry fields) intact or free the previous one? */ |
| 4799 | |
| 4800 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4801 | since file handle passed in no longer valid */ |
| 4802 | FNext2_err_exit: |
| 4803 | if (rc != 0) |
| 4804 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4805 | return rc; |
| 4806 | } |
| 4807 | |
| 4808 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4809 | CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4810 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | { |
| 4812 | int rc = 0; |
| 4813 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4815 | cifs_dbg(FYI, "In CIFSSMBFindClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4817 | |
| 4818 | /* no sense returning error if session restarted |
| 4819 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4820 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | return 0; |
| 4822 | if (rc) |
| 4823 | return rc; |
| 4824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | pSMB->FileID = searchHandle; |
| 4826 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4827 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 4828 | cifs_small_buf_release(pSMB); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4829 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4830 | cifs_dbg(VFS, "Send error in FindClose = %d\n", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4831 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4832 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4833 | |
| 4834 | /* Since session is dead, search handle closed on server already */ |
| 4835 | if (rc == -EAGAIN) |
| 4836 | rc = 0; |
| 4837 | |
| 4838 | return rc; |
| 4839 | } |
| 4840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4842 | CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4843 | const char *search_name, __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4844 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | { |
| 4846 | int rc = 0; |
| 4847 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4848 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4849 | int name_len, bytes_returned; |
| 4850 | __u16 params, byte_count; |
| 4851 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4852 | cifs_dbg(FYI, "In GetSrvInodeNum for %s\n", search_name); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4853 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4854 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | |
| 4856 | GetInodeNumberRetry: |
| 4857 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4858 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | if (rc) |
| 4860 | return rc; |
| 4861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4863 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4864 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4865 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4866 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | name_len++; /* trailing null */ |
| 4868 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4869 | } else { |
| 4870 | name_len = copy_path_name(pSMB->FileName, search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | } |
| 4872 | |
| 4873 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4874 | pSMB->TotalDataCount = 0; |
| 4875 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4876 | /* BB find exact max data count below from sess structure BB */ |
| 4877 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4878 | pSMB->MaxSetupCount = 0; |
| 4879 | pSMB->Reserved = 0; |
| 4880 | pSMB->Flags = 0; |
| 4881 | pSMB->Timeout = 0; |
| 4882 | pSMB->Reserved2 = 0; |
| 4883 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4884 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | pSMB->DataCount = 0; |
| 4886 | pSMB->DataOffset = 0; |
| 4887 | pSMB->SetupCount = 1; |
| 4888 | pSMB->Reserved3 = 0; |
| 4889 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4890 | byte_count = params + 1 /* pad */ ; |
| 4891 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4892 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4893 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4894 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4895 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4897 | |
| 4898 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4899 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4900 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4901 | cifs_dbg(FYI, "error %d in QueryInternalInfo\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | } else { |
| 4903 | /* decode response */ |
| 4904 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4906 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | /* If rc should we check for EOPNOSUPP and |
| 4908 | disable the srvino flag? or in caller? */ |
| 4909 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4910 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4912 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4913 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4915 | if (count < 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4916 | cifs_dbg(FYI, "Illegal size ret in QryIntrnlInf\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | rc = -EIO; |
| 4918 | goto GetInodeNumOut; |
| 4919 | } |
| 4920 | pfinfo = (struct file_internal_info *) |
| 4921 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4922 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | } |
| 4924 | } |
| 4925 | GetInodeNumOut: |
| 4926 | cifs_buf_release(pSMB); |
| 4927 | if (rc == -EAGAIN) |
| 4928 | goto GetInodeNumberRetry; |
| 4929 | return rc; |
| 4930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4931 | |
| 4932 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4933 | CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4934 | const char *search_name, struct dfs_info3_param **target_nodes, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4935 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4936 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | { |
| 4938 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4939 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4940 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | int rc = 0; |
| 4942 | int bytes_returned; |
| 4943 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4945 | *num_of_nodes = 0; |
| 4946 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4947 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4948 | cifs_dbg(FYI, "In GetDFSRefer the path %s\n", search_name); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4949 | if (ses == NULL || ses->tcon_ipc == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | return -ENODEV; |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | getDFSRetry: |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4953 | rc = smb_init(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | (void **) &pSMBr); |
| 4955 | if (rc) |
| 4956 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4957 | |
| 4958 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4959 | but should never be null here anyway */ |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 4960 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4961 | pSMB->hdr.Tid = ses->tcon_ipc->tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4963 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4964 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4965 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4966 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | |
| 4968 | if (ses->capabilities & CAP_UNICODE) { |
| 4969 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4970 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4971 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4972 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4973 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4974 | name_len++; /* trailing null */ |
| 4975 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4976 | } else { /* BB improve the check for buffer overruns BB */ |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 4977 | name_len = copy_path_name(pSMB->RequestFileName, search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | } |
| 4979 | |
Dan Carpenter | 65c3b20 | 2015-04-30 17:30:24 +0300 | [diff] [blame] | 4980 | if (ses->server->sign) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 4981 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4982 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4983 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4986 | pSMB->TotalDataCount = 0; |
| 4987 | pSMB->DataCount = 0; |
| 4988 | pSMB->DataOffset = 0; |
| 4989 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4990 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4991 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | pSMB->MaxSetupCount = 0; |
| 4993 | pSMB->Reserved = 0; |
| 4994 | pSMB->Flags = 0; |
| 4995 | pSMB->Timeout = 0; |
| 4996 | pSMB->Reserved2 = 0; |
| 4997 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4998 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | pSMB->SetupCount = 1; |
| 5000 | pSMB->Reserved3 = 0; |
| 5001 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 5002 | byte_count = params + 3 /* pad */ ; |
| 5003 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5004 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5005 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5006 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5008 | |
| 5009 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 5010 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5011 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5012 | cifs_dbg(FYI, "Send error in GetDFSRefer = %d\n", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 5013 | goto GetDFSRefExit; |
| 5014 | } |
| 5015 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 5017 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5018 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 5019 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 5020 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 5022 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5023 | cifs_dbg(FYI, "Decoding GetDFSRefer response BCC: %d Offset %d\n", |
| 5024 | get_bcc(&pSMBr->hdr), le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 5025 | |
| 5026 | /* parse returned result into more usable form */ |
Aurelien Aptel | 4ecce92 | 2017-02-13 16:03:47 +0100 | [diff] [blame] | 5027 | rc = parse_dfs_referrals(&pSMBr->dfs_data, |
| 5028 | le16_to_cpu(pSMBr->t2.DataCount), |
| 5029 | num_of_nodes, target_nodes, nls_codepage, |
| 5030 | remap, search_name, |
Steve French | 284316d | 2017-03-02 15:42:48 -0600 | [diff] [blame] | 5031 | (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) != 0); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 5032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5033 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5034 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | |
| 5036 | if (rc == -EAGAIN) |
| 5037 | goto getDFSRetry; |
| 5038 | |
| 5039 | return rc; |
| 5040 | } |
| 5041 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5042 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 5043 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5044 | SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 5045 | struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5046 | { |
| 5047 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5048 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5049 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5050 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 5051 | int rc = 0; |
| 5052 | int bytes_returned = 0; |
| 5053 | __u16 params, byte_count; |
| 5054 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5055 | cifs_dbg(FYI, "OldQFSInfo\n"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5056 | oldQFSInfoRetry: |
| 5057 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5058 | (void **) &pSMBr); |
| 5059 | if (rc) |
| 5060 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5061 | |
| 5062 | params = 2; /* level */ |
| 5063 | pSMB->TotalDataCount = 0; |
| 5064 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5065 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5066 | pSMB->MaxSetupCount = 0; |
| 5067 | pSMB->Reserved = 0; |
| 5068 | pSMB->Flags = 0; |
| 5069 | pSMB->Timeout = 0; |
| 5070 | pSMB->Reserved2 = 0; |
| 5071 | byte_count = params + 1 /* pad */ ; |
| 5072 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5073 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5074 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 5075 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 5076 | pSMB->DataCount = 0; |
| 5077 | pSMB->DataOffset = 0; |
| 5078 | pSMB->SetupCount = 1; |
| 5079 | pSMB->Reserved3 = 0; |
| 5080 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5081 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5082 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5083 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5084 | |
| 5085 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5086 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5087 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5088 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5089 | } else { /* decode response */ |
| 5090 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5091 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5092 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5093 | rc = -EIO; /* bad smb */ |
| 5094 | else { |
| 5095 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5096 | cifs_dbg(FYI, "qfsinf resp BCC: %d Offset %d\n", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5097 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5098 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5099 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5100 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 5101 | FSData->f_bsize = |
| 5102 | le16_to_cpu(response_data->BytesPerSector) * |
| 5103 | le32_to_cpu(response_data-> |
| 5104 | SectorsPerAllocationUnit); |
Steve French | 5a519be | 2018-09-15 14:07:09 -0500 | [diff] [blame] | 5105 | /* |
| 5106 | * much prefer larger but if server doesn't report |
| 5107 | * a valid size than 4K is a reasonable minimum |
| 5108 | */ |
| 5109 | if (FSData->f_bsize < 512) |
| 5110 | FSData->f_bsize = 4096; |
| 5111 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5112 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5113 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5114 | FSData->f_bfree = FSData->f_bavail = |
| 5115 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5116 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5117 | (unsigned long long)FSData->f_blocks, |
| 5118 | (unsigned long long)FSData->f_bfree, |
| 5119 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5120 | } |
| 5121 | } |
| 5122 | cifs_buf_release(pSMB); |
| 5123 | |
| 5124 | if (rc == -EAGAIN) |
| 5125 | goto oldQFSInfoRetry; |
| 5126 | |
| 5127 | return rc; |
| 5128 | } |
| 5129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5131 | CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 5132 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | { |
| 5134 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5135 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5136 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5137 | FILE_SYSTEM_INFO *response_data; |
| 5138 | int rc = 0; |
| 5139 | int bytes_returned = 0; |
| 5140 | __u16 params, byte_count; |
| 5141 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5142 | cifs_dbg(FYI, "In QFSInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | QFSInfoRetry: |
| 5144 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5145 | (void **) &pSMBr); |
| 5146 | if (rc) |
| 5147 | return rc; |
| 5148 | |
| 5149 | params = 2; /* level */ |
| 5150 | pSMB->TotalDataCount = 0; |
| 5151 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 5152 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5153 | pSMB->MaxSetupCount = 0; |
| 5154 | pSMB->Reserved = 0; |
| 5155 | pSMB->Flags = 0; |
| 5156 | pSMB->Timeout = 0; |
| 5157 | pSMB->Reserved2 = 0; |
| 5158 | byte_count = params + 1 /* pad */ ; |
| 5159 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5160 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5161 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5162 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5163 | pSMB->DataCount = 0; |
| 5164 | pSMB->DataOffset = 0; |
| 5165 | pSMB->SetupCount = 1; |
| 5166 | pSMB->Reserved3 = 0; |
| 5167 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5168 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5169 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5170 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5171 | |
| 5172 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5173 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5174 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5175 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5176 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5177 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5179 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5180 | rc = -EIO; /* bad smb */ |
| 5181 | else { |
| 5182 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5183 | |
| 5184 | response_data = |
| 5185 | (FILE_SYSTEM_INFO |
| 5186 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5187 | data_offset); |
| 5188 | FSData->f_bsize = |
| 5189 | le32_to_cpu(response_data->BytesPerSector) * |
| 5190 | le32_to_cpu(response_data-> |
| 5191 | SectorsPerAllocationUnit); |
Steve French | 5a519be | 2018-09-15 14:07:09 -0500 | [diff] [blame] | 5192 | /* |
| 5193 | * much prefer larger but if server doesn't report |
| 5194 | * a valid size than 4K is a reasonable minimum |
| 5195 | */ |
| 5196 | if (FSData->f_bsize < 512) |
| 5197 | FSData->f_bsize = 4096; |
| 5198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | FSData->f_blocks = |
| 5200 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 5201 | FSData->f_bfree = FSData->f_bavail = |
| 5202 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5203 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 5204 | (unsigned long long)FSData->f_blocks, |
| 5205 | (unsigned long long)FSData->f_bfree, |
| 5206 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5207 | } |
| 5208 | } |
| 5209 | cifs_buf_release(pSMB); |
| 5210 | |
| 5211 | if (rc == -EAGAIN) |
| 5212 | goto QFSInfoRetry; |
| 5213 | |
| 5214 | return rc; |
| 5215 | } |
| 5216 | |
| 5217 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5218 | CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | { |
| 5220 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5221 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5222 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5223 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5224 | int rc = 0; |
| 5225 | int bytes_returned = 0; |
| 5226 | __u16 params, byte_count; |
| 5227 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5228 | cifs_dbg(FYI, "In QFSAttributeInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | QFSAttributeRetry: |
| 5230 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5231 | (void **) &pSMBr); |
| 5232 | if (rc) |
| 5233 | return rc; |
| 5234 | |
| 5235 | params = 2; /* level */ |
| 5236 | pSMB->TotalDataCount = 0; |
| 5237 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5238 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5239 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | pSMB->MaxSetupCount = 0; |
| 5241 | pSMB->Reserved = 0; |
| 5242 | pSMB->Flags = 0; |
| 5243 | pSMB->Timeout = 0; |
| 5244 | pSMB->Reserved2 = 0; |
| 5245 | byte_count = params + 1 /* pad */ ; |
| 5246 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5247 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5248 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5249 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5250 | pSMB->DataCount = 0; |
| 5251 | pSMB->DataOffset = 0; |
| 5252 | pSMB->SetupCount = 1; |
| 5253 | pSMB->Reserved3 = 0; |
| 5254 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5255 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5256 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5257 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5258 | |
| 5259 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5260 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5261 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5262 | cifs_dbg(VFS, "Send error in QFSAttributeInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 | } else { /* decode response */ |
| 5264 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5265 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5266 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5267 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5268 | rc = -EIO; /* bad smb */ |
| 5269 | } else { |
| 5270 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5271 | response_data = |
| 5272 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5273 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5274 | data_offset); |
| 5275 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5276 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | } |
| 5278 | } |
| 5279 | cifs_buf_release(pSMB); |
| 5280 | |
| 5281 | if (rc == -EAGAIN) |
| 5282 | goto QFSAttributeRetry; |
| 5283 | |
| 5284 | return rc; |
| 5285 | } |
| 5286 | |
| 5287 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5288 | CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5289 | { |
| 5290 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5291 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5292 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5293 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5294 | int rc = 0; |
| 5295 | int bytes_returned = 0; |
| 5296 | __u16 params, byte_count; |
| 5297 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5298 | cifs_dbg(FYI, "In QFSDeviceInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | QFSDeviceRetry: |
| 5300 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5301 | (void **) &pSMBr); |
| 5302 | if (rc) |
| 5303 | return rc; |
| 5304 | |
| 5305 | params = 2; /* level */ |
| 5306 | pSMB->TotalDataCount = 0; |
| 5307 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5308 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5309 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5310 | pSMB->MaxSetupCount = 0; |
| 5311 | pSMB->Reserved = 0; |
| 5312 | pSMB->Flags = 0; |
| 5313 | pSMB->Timeout = 0; |
| 5314 | pSMB->Reserved2 = 0; |
| 5315 | byte_count = params + 1 /* pad */ ; |
| 5316 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5317 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5318 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5319 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | |
| 5321 | pSMB->DataCount = 0; |
| 5322 | pSMB->DataOffset = 0; |
| 5323 | pSMB->SetupCount = 1; |
| 5324 | pSMB->Reserved3 = 0; |
| 5325 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5326 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5327 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5328 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5329 | |
| 5330 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5331 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5332 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5333 | cifs_dbg(FYI, "Send error in QFSDeviceInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 | } else { /* decode response */ |
| 5335 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5336 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5337 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5338 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5339 | rc = -EIO; /* bad smb */ |
| 5340 | else { |
| 5341 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5342 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5343 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5344 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5345 | data_offset); |
| 5346 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5347 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5348 | } |
| 5349 | } |
| 5350 | cifs_buf_release(pSMB); |
| 5351 | |
| 5352 | if (rc == -EAGAIN) |
| 5353 | goto QFSDeviceRetry; |
| 5354 | |
| 5355 | return rc; |
| 5356 | } |
| 5357 | |
| 5358 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5359 | CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | { |
| 5361 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5362 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5363 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5364 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5365 | int rc = 0; |
| 5366 | int bytes_returned = 0; |
| 5367 | __u16 params, byte_count; |
| 5368 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5369 | cifs_dbg(FYI, "In QFSUnixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5371 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5372 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | if (rc) |
| 5374 | return rc; |
| 5375 | |
| 5376 | params = 2; /* level */ |
| 5377 | pSMB->TotalDataCount = 0; |
| 5378 | pSMB->DataCount = 0; |
| 5379 | pSMB->DataOffset = 0; |
| 5380 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5381 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5382 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | pSMB->MaxSetupCount = 0; |
| 5384 | pSMB->Reserved = 0; |
| 5385 | pSMB->Flags = 0; |
| 5386 | pSMB->Timeout = 0; |
| 5387 | pSMB->Reserved2 = 0; |
| 5388 | byte_count = params + 1 /* pad */ ; |
| 5389 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5390 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5391 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5392 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5393 | pSMB->SetupCount = 1; |
| 5394 | pSMB->Reserved3 = 0; |
| 5395 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5396 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5397 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5398 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5399 | |
| 5400 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5401 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5402 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5403 | cifs_dbg(VFS, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | } else { /* decode response */ |
| 5405 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5406 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5407 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5408 | rc = -EIO; /* bad smb */ |
| 5409 | } else { |
| 5410 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5411 | response_data = |
| 5412 | (FILE_SYSTEM_UNIX_INFO |
| 5413 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5414 | data_offset); |
| 5415 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5416 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 | } |
| 5418 | } |
| 5419 | cifs_buf_release(pSMB); |
| 5420 | |
| 5421 | if (rc == -EAGAIN) |
| 5422 | goto QFSUnixRetry; |
| 5423 | |
| 5424 | |
| 5425 | return rc; |
| 5426 | } |
| 5427 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5428 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5429 | CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5430 | { |
| 5431 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5432 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5433 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5434 | int rc = 0; |
| 5435 | int bytes_returned = 0; |
| 5436 | __u16 params, param_offset, offset, byte_count; |
| 5437 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5438 | cifs_dbg(FYI, "In SETFSUnixInfo\n"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5439 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5440 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5441 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5442 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5443 | if (rc) |
| 5444 | return rc; |
| 5445 | |
| 5446 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5447 | pSMB->MaxSetupCount = 0; |
| 5448 | pSMB->Reserved = 0; |
| 5449 | pSMB->Flags = 0; |
| 5450 | pSMB->Timeout = 0; |
| 5451 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5452 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5453 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5454 | offset = param_offset + params; |
| 5455 | |
| 5456 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5457 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5458 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5459 | pSMB->SetupCount = 1; |
| 5460 | pSMB->Reserved3 = 0; |
| 5461 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5462 | byte_count = 1 /* pad */ + params + 12; |
| 5463 | |
| 5464 | pSMB->DataCount = cpu_to_le16(12); |
| 5465 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5466 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5467 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5468 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5469 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5470 | |
| 5471 | /* Params. */ |
| 5472 | pSMB->FileNum = 0; |
| 5473 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5474 | |
| 5475 | /* Data. */ |
| 5476 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5477 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5478 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5479 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5480 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5481 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5482 | |
| 5483 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5484 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5485 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5486 | cifs_dbg(VFS, "Send error in SETFSUnixInfo = %d\n", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5487 | } else { /* decode response */ |
| 5488 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5489 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5490 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5491 | } |
| 5492 | cifs_buf_release(pSMB); |
| 5493 | |
| 5494 | if (rc == -EAGAIN) |
| 5495 | goto SETFSUnixRetry; |
| 5496 | |
| 5497 | return rc; |
| 5498 | } |
| 5499 | |
| 5500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | |
| 5502 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5503 | CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5504 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | { |
| 5506 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5507 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5508 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5509 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5510 | int rc = 0; |
| 5511 | int bytes_returned = 0; |
| 5512 | __u16 params, byte_count; |
| 5513 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5514 | cifs_dbg(FYI, "In QFSPosixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | QFSPosixRetry: |
| 5516 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5517 | (void **) &pSMBr); |
| 5518 | if (rc) |
| 5519 | return rc; |
| 5520 | |
| 5521 | params = 2; /* level */ |
| 5522 | pSMB->TotalDataCount = 0; |
| 5523 | pSMB->DataCount = 0; |
| 5524 | pSMB->DataOffset = 0; |
| 5525 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5526 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5527 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5528 | pSMB->MaxSetupCount = 0; |
| 5529 | pSMB->Reserved = 0; |
| 5530 | pSMB->Flags = 0; |
| 5531 | pSMB->Timeout = 0; |
| 5532 | pSMB->Reserved2 = 0; |
| 5533 | byte_count = params + 1 /* pad */ ; |
| 5534 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5535 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5536 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5537 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | pSMB->SetupCount = 1; |
| 5539 | pSMB->Reserved3 = 0; |
| 5540 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5541 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5542 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5544 | |
| 5545 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5546 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5547 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5548 | cifs_dbg(FYI, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | } else { /* decode response */ |
| 5550 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5551 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5552 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | rc = -EIO; /* bad smb */ |
| 5554 | } else { |
| 5555 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5556 | response_data = |
| 5557 | (FILE_SYSTEM_POSIX_INFO |
| 5558 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5559 | data_offset); |
| 5560 | FSData->f_bsize = |
| 5561 | le32_to_cpu(response_data->BlockSize); |
Steve French | 5a519be | 2018-09-15 14:07:09 -0500 | [diff] [blame] | 5562 | /* |
| 5563 | * much prefer larger but if server doesn't report |
| 5564 | * a valid size than 4K is a reasonable minimum |
| 5565 | */ |
| 5566 | if (FSData->f_bsize < 512) |
| 5567 | FSData->f_bsize = 4096; |
| 5568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5569 | FSData->f_blocks = |
| 5570 | le64_to_cpu(response_data->TotalBlocks); |
| 5571 | FSData->f_bfree = |
| 5572 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5573 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5574 | FSData->f_bavail = FSData->f_bfree; |
| 5575 | } else { |
| 5576 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5577 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5579 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5581 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5582 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5584 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5585 | } |
| 5586 | } |
| 5587 | cifs_buf_release(pSMB); |
| 5588 | |
| 5589 | if (rc == -EAGAIN) |
| 5590 | goto QFSPosixRetry; |
| 5591 | |
| 5592 | return rc; |
| 5593 | } |
| 5594 | |
| 5595 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5596 | /* |
| 5597 | * We can not use write of zero bytes trick to set file size due to need for |
| 5598 | * large file support. Also note that this SetPathInfo is preferred to |
| 5599 | * SetFileInfo based method in next routine which is only needed to work around |
| 5600 | * a sharing violation bugin Samba which this routine can run into. |
| 5601 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5602 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5603 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5604 | const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, |
| 5605 | bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | { |
| 5607 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5608 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5609 | struct file_end_of_file_info *parm_data; |
| 5610 | int name_len; |
| 5611 | int rc = 0; |
| 5612 | int bytes_returned = 0; |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 5613 | int remap = cifs_remap(cifs_sb); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5615 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5616 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5617 | cifs_dbg(FYI, "In SetEOF\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 | SetEOFRetry: |
| 5619 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5620 | (void **) &pSMBr); |
| 5621 | if (rc) |
| 5622 | return rc; |
| 5623 | |
| 5624 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5625 | name_len = |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5626 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
| 5627 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | name_len++; /* trailing null */ |
| 5629 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 5630 | } else { |
| 5631 | name_len = copy_path_name(pSMB->FileName, file_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5632 | } |
| 5633 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5634 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5636 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5637 | pSMB->MaxSetupCount = 0; |
| 5638 | pSMB->Reserved = 0; |
| 5639 | pSMB->Flags = 0; |
| 5640 | pSMB->Timeout = 0; |
| 5641 | pSMB->Reserved2 = 0; |
| 5642 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5643 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | offset = param_offset + params; |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5645 | if (set_allocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5646 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5647 | pSMB->InformationLevel = |
| 5648 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5649 | else |
| 5650 | pSMB->InformationLevel = |
| 5651 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5652 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5653 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5654 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5655 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | else |
| 5657 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5658 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | parm_data = |
| 5662 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5663 | offset); |
| 5664 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5665 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5666 | pSMB->SetupCount = 1; |
| 5667 | pSMB->Reserved3 = 0; |
| 5668 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5669 | byte_count = 3 /* pad */ + params + data_count; |
| 5670 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5671 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5672 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5673 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5674 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5675 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5676 | parm_data->FileSize = cpu_to_le64(size); |
| 5677 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5678 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5679 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5680 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5681 | cifs_dbg(FYI, "SetPathInfo (file size) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | |
| 5683 | cifs_buf_release(pSMB); |
| 5684 | |
| 5685 | if (rc == -EAGAIN) |
| 5686 | goto SetEOFRetry; |
| 5687 | |
| 5688 | return rc; |
| 5689 | } |
| 5690 | |
| 5691 | int |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5692 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
| 5693 | struct cifsFileInfo *cfile, __u64 size, bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5694 | { |
| 5695 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | struct file_end_of_file_info *parm_data; |
| 5697 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | __u16 params, param_offset, offset, byte_count, count; |
| 5699 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5700 | cifs_dbg(FYI, "SetFileSize (via SetFileInfo) %lld\n", |
| 5701 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5702 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | if (rc) |
| 5705 | return rc; |
| 5706 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5707 | pSMB->hdr.Pid = cpu_to_le16((__u16)cfile->pid); |
| 5708 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(cfile->pid >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5710 | params = 6; |
| 5711 | pSMB->MaxSetupCount = 0; |
| 5712 | pSMB->Reserved = 0; |
| 5713 | pSMB->Flags = 0; |
| 5714 | pSMB->Timeout = 0; |
| 5715 | pSMB->Reserved2 = 0; |
| 5716 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5717 | offset = param_offset + params; |
| 5718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | count = sizeof(struct file_end_of_file_info); |
| 5720 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5721 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5722 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5723 | pSMB->SetupCount = 1; |
| 5724 | pSMB->Reserved3 = 0; |
| 5725 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5726 | byte_count = 3 /* pad */ + params + count; |
| 5727 | pSMB->DataCount = cpu_to_le16(count); |
| 5728 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5729 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5730 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5731 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5732 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5733 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5734 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5736 | parm_data->FileSize = cpu_to_le64(size); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5737 | pSMB->Fid = cfile->fid.netfid; |
| 5738 | if (set_allocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5739 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5740 | pSMB->InformationLevel = |
| 5741 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5742 | else |
| 5743 | pSMB->InformationLevel = |
| 5744 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5745 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5746 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5747 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5748 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5749 | else |
| 5750 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5751 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5752 | } |
| 5753 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5754 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5755 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5756 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5757 | cifs_small_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5759 | cifs_dbg(FYI, "Send error in SetFileInfo (SetFileSize) = %d\n", |
| 5760 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5761 | } |
| 5762 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5763 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | since file handle passed in no longer valid */ |
| 5765 | |
| 5766 | return rc; |
| 5767 | } |
| 5768 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5769 | /* 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] | 5770 | an open handle, rather than by pathname - this is awkward due to |
| 5771 | potential access conflicts on the open, but it is unavoidable for these |
| 5772 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5773 | time and resort to the original setpathinfo level which takes the ancient |
| 5774 | DOS time format with 2 second granularity */ |
| 5775 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5776 | CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5777 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5778 | { |
| 5779 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5780 | char *data_offset; |
| 5781 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5782 | __u16 params, param_offset, offset, byte_count, count; |
| 5783 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5784 | cifs_dbg(FYI, "Set Times (via SetFileInfo)\n"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5785 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5787 | if (rc) |
| 5788 | return rc; |
| 5789 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5790 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5791 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5793 | params = 6; |
| 5794 | pSMB->MaxSetupCount = 0; |
| 5795 | pSMB->Reserved = 0; |
| 5796 | pSMB->Flags = 0; |
| 5797 | pSMB->Timeout = 0; |
| 5798 | pSMB->Reserved2 = 0; |
| 5799 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5800 | offset = param_offset + params; |
| 5801 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5802 | data_offset = (char *)pSMB + |
| 5803 | offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5804 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5805 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5807 | /* BB find max SMB PDU from sess */ |
| 5808 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5809 | pSMB->SetupCount = 1; |
| 5810 | pSMB->Reserved3 = 0; |
| 5811 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5812 | byte_count = 3 /* pad */ + params + count; |
| 5813 | pSMB->DataCount = cpu_to_le16(count); |
| 5814 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5815 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5816 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5817 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5818 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5819 | pSMB->Fid = fid; |
| 5820 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5821 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5822 | else |
| 5823 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5824 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5825 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5827 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5828 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5829 | cifs_small_buf_release(pSMB); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5830 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5831 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 5832 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5834 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5835 | since file handle passed in no longer valid */ |
| 5836 | |
| 5837 | return rc; |
| 5838 | } |
| 5839 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5840 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5841 | CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5842 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5843 | { |
| 5844 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5845 | char *data_offset; |
| 5846 | int rc = 0; |
| 5847 | __u16 params, param_offset, offset, byte_count, count; |
| 5848 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5849 | cifs_dbg(FYI, "Set File Disposition (via SetFileInfo)\n"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5850 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5851 | |
| 5852 | if (rc) |
| 5853 | return rc; |
| 5854 | |
| 5855 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5856 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5857 | |
| 5858 | params = 6; |
| 5859 | pSMB->MaxSetupCount = 0; |
| 5860 | pSMB->Reserved = 0; |
| 5861 | pSMB->Flags = 0; |
| 5862 | pSMB->Timeout = 0; |
| 5863 | pSMB->Reserved2 = 0; |
| 5864 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5865 | offset = param_offset + params; |
| 5866 | |
| 5867 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5868 | |
| 5869 | count = 1; |
| 5870 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5871 | /* BB find max SMB PDU from sess */ |
| 5872 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5873 | pSMB->SetupCount = 1; |
| 5874 | pSMB->Reserved3 = 0; |
| 5875 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5876 | byte_count = 3 /* pad */ + params + count; |
| 5877 | pSMB->DataCount = cpu_to_le16(count); |
| 5878 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5879 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5880 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5881 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5882 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5883 | pSMB->Fid = fid; |
| 5884 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5885 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5886 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5887 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5888 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5889 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 5890 | cifs_small_buf_release(pSMB); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5891 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5892 | cifs_dbg(FYI, "Send error in SetFileDisposition = %d\n", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5893 | |
| 5894 | return rc; |
| 5895 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5896 | |
| 5897 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5898 | CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5899 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5900 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5901 | { |
| 5902 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5903 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5904 | int name_len; |
| 5905 | int rc = 0; |
| 5906 | int bytes_returned = 0; |
| 5907 | char *data_offset; |
| 5908 | __u16 params, param_offset, offset, byte_count, count; |
| 5909 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5910 | cifs_dbg(FYI, "In SetTimes\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5911 | |
| 5912 | SetTimesRetry: |
| 5913 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5914 | (void **) &pSMBr); |
| 5915 | if (rc) |
| 5916 | return rc; |
| 5917 | |
| 5918 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5919 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5920 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5921 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | name_len++; /* trailing null */ |
| 5923 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 5924 | } else { |
| 5925 | name_len = copy_path_name(pSMB->FileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | } |
| 5927 | |
| 5928 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5929 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5930 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5931 | /* BB find max SMB PDU from sess structure BB */ |
| 5932 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5933 | pSMB->MaxSetupCount = 0; |
| 5934 | pSMB->Reserved = 0; |
| 5935 | pSMB->Flags = 0; |
| 5936 | pSMB->Timeout = 0; |
| 5937 | pSMB->Reserved2 = 0; |
| 5938 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5939 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5940 | offset = param_offset + params; |
| 5941 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5942 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5943 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5944 | pSMB->SetupCount = 1; |
| 5945 | pSMB->Reserved3 = 0; |
| 5946 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5947 | byte_count = 3 /* pad */ + params + count; |
| 5948 | |
| 5949 | pSMB->DataCount = cpu_to_le16(count); |
| 5950 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5951 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5952 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5953 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5954 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5955 | else |
| 5956 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5957 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5958 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5959 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5960 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5961 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5962 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5963 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5964 | cifs_dbg(FYI, "SetPathInfo (times) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5965 | |
| 5966 | cifs_buf_release(pSMB); |
| 5967 | |
| 5968 | if (rc == -EAGAIN) |
| 5969 | goto SetTimesRetry; |
| 5970 | |
| 5971 | return rc; |
| 5972 | } |
| 5973 | |
| 5974 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5975 | /* Can be used to set attributes */ |
| 5976 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5977 | handling it anyway and NT4 was what we thought it would be needed for |
| 5978 | Do not delete it until we prove whether needed for Win9x though */ |
| 5979 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5980 | CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5981 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5982 | { |
| 5983 | SETATTR_REQ *pSMB = NULL; |
| 5984 | SETATTR_RSP *pSMBr = NULL; |
| 5985 | int rc = 0; |
| 5986 | int bytes_returned; |
| 5987 | int name_len; |
| 5988 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5989 | cifs_dbg(FYI, "In SetAttrLegacy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5990 | |
| 5991 | SetAttrLgcyRetry: |
| 5992 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5993 | (void **) &pSMBr); |
| 5994 | if (rc) |
| 5995 | return rc; |
| 5996 | |
| 5997 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5998 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5999 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 6000 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6001 | name_len++; /* trailing null */ |
| 6002 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6003 | } else { |
| 6004 | name_len = copy_path_name(pSMB->fileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6005 | } |
| 6006 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 6007 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6008 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6009 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 6010 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6011 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6012 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6013 | cifs_dbg(FYI, "Error in LegacySetAttr = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6014 | |
| 6015 | cifs_buf_release(pSMB); |
| 6016 | |
| 6017 | if (rc == -EAGAIN) |
| 6018 | goto SetAttrLgcyRetry; |
| 6019 | |
| 6020 | return rc; |
| 6021 | } |
| 6022 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 6023 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6024 | static void |
| 6025 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 6026 | const struct cifs_unix_set_info_args *args) |
| 6027 | { |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 6028 | u64 uid = NO_CHANGE_64, gid = NO_CHANGE_64; |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6029 | u64 mode = args->mode; |
| 6030 | |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 6031 | if (uid_valid(args->uid)) |
| 6032 | uid = from_kuid(&init_user_ns, args->uid); |
| 6033 | if (gid_valid(args->gid)) |
| 6034 | gid = from_kgid(&init_user_ns, args->gid); |
| 6035 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6036 | /* |
| 6037 | * Samba server ignores set of file size to zero due to bugs in some |
| 6038 | * older clients, but we should be precise - we use SetFileSize to |
| 6039 | * 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] | 6040 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6041 | * zero instead of -1 here |
| 6042 | */ |
| 6043 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 6044 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 6045 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 6046 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 6047 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 6048 | data_offset->Uid = cpu_to_le64(uid); |
| 6049 | data_offset->Gid = cpu_to_le64(gid); |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6050 | /* better to leave device as zero when it is */ |
| 6051 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 6052 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 6053 | data_offset->Permissions = cpu_to_le64(mode); |
| 6054 | |
| 6055 | if (S_ISREG(mode)) |
| 6056 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 6057 | else if (S_ISDIR(mode)) |
| 6058 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 6059 | else if (S_ISLNK(mode)) |
| 6060 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 6061 | else if (S_ISCHR(mode)) |
| 6062 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 6063 | else if (S_ISBLK(mode)) |
| 6064 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 6065 | else if (S_ISFIFO(mode)) |
| 6066 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 6067 | else if (S_ISSOCK(mode)) |
| 6068 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 6069 | } |
| 6070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6071 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6072 | CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6073 | const struct cifs_unix_set_info_args *args, |
| 6074 | u16 fid, u32 pid_of_opener) |
| 6075 | { |
| 6076 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6077 | char *data_offset; |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6078 | int rc = 0; |
| 6079 | u16 params, param_offset, offset, byte_count, count; |
| 6080 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6081 | cifs_dbg(FYI, "Set Unix Info (via SetFileInfo)\n"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6082 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 6083 | |
| 6084 | if (rc) |
| 6085 | return rc; |
| 6086 | |
| 6087 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 6088 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 6089 | |
| 6090 | params = 6; |
| 6091 | pSMB->MaxSetupCount = 0; |
| 6092 | pSMB->Reserved = 0; |
| 6093 | pSMB->Flags = 0; |
| 6094 | pSMB->Timeout = 0; |
| 6095 | pSMB->Reserved2 = 0; |
| 6096 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 6097 | offset = param_offset + params; |
| 6098 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6099 | data_offset = (char *)pSMB + |
| 6100 | offsetof(struct smb_hdr, Protocol) + offset; |
| 6101 | |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6102 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 6103 | |
| 6104 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 6105 | /* BB find max SMB PDU from sess */ |
| 6106 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 6107 | pSMB->SetupCount = 1; |
| 6108 | pSMB->Reserved3 = 0; |
| 6109 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 6110 | byte_count = 3 /* pad */ + params + count; |
| 6111 | pSMB->DataCount = cpu_to_le16(count); |
| 6112 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6113 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6114 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6115 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6116 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6117 | pSMB->Fid = fid; |
| 6118 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6119 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6120 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6121 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6122 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 6123 | cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6124 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 6125 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 6126 | cifs_small_buf_release(pSMB); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6127 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6128 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 6129 | rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 6130 | |
| 6131 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 6132 | since file handle passed in no longer valid */ |
| 6133 | |
| 6134 | return rc; |
| 6135 | } |
| 6136 | |
| 6137 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6138 | CIFSSMBUnixSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6139 | const char *file_name, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6140 | const struct cifs_unix_set_info_args *args, |
| 6141 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6142 | { |
| 6143 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 6144 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 6145 | int name_len; |
| 6146 | int rc = 0; |
| 6147 | int bytes_returned = 0; |
| 6148 | FILE_UNIX_BASIC_INFO *data_offset; |
| 6149 | __u16 params, param_offset, offset, count, byte_count; |
| 6150 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6151 | cifs_dbg(FYI, "In SetUID/GID/Mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | setPermsRetry: |
| 6153 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6154 | (void **) &pSMBr); |
| 6155 | if (rc) |
| 6156 | return rc; |
| 6157 | |
| 6158 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6159 | name_len = |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 6160 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6161 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6162 | name_len++; /* trailing null */ |
| 6163 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6164 | } else { |
| 6165 | name_len = copy_path_name(pSMB->FileName, file_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 6169 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6170 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6171 | /* BB find max SMB PDU from sess structure BB */ |
| 6172 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6173 | pSMB->MaxSetupCount = 0; |
| 6174 | pSMB->Reserved = 0; |
| 6175 | pSMB->Flags = 0; |
| 6176 | pSMB->Timeout = 0; |
| 6177 | pSMB->Reserved2 = 0; |
| 6178 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6179 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6180 | offset = param_offset + params; |
| 6181 | data_offset = |
| 6182 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 6183 | offset); |
| 6184 | memset(data_offset, 0, count); |
| 6185 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6186 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6187 | pSMB->SetupCount = 1; |
| 6188 | pSMB->Reserved3 = 0; |
| 6189 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6190 | byte_count = 3 /* pad */ + params + count; |
| 6191 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6192 | pSMB->DataCount = cpu_to_le16(count); |
| 6193 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6194 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6195 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6196 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6197 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6198 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6199 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6200 | |
| 6201 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6202 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6203 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6204 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6205 | cifs_dbg(FYI, "SetPathInfo (perms) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6206 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6207 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6208 | if (rc == -EAGAIN) |
| 6209 | goto setPermsRetry; |
| 6210 | return rc; |
| 6211 | } |
| 6212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6213 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6214 | /* |
| 6215 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 6216 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 6217 | * it looks for that attribute name and stuffs that value into the EAData |
| 6218 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 6219 | * buffer. In both cases, the return value is either the length of the |
| 6220 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 6221 | * the data isn't copied to it, but the length is returned. |
| 6222 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6223 | ssize_t |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6224 | CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6225 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6226 | char *EAData, size_t buf_size, |
Steve French | 67b4c88 | 2017-05-12 20:59:10 -0500 | [diff] [blame] | 6227 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | { |
| 6229 | /* BB assumes one setup word */ |
| 6230 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6231 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
Steve French | 67b4c88 | 2017-05-12 20:59:10 -0500 | [diff] [blame] | 6232 | int remap = cifs_remap(cifs_sb); |
| 6233 | struct nls_table *nls_codepage = cifs_sb->local_nls; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6234 | int rc = 0; |
| 6235 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6236 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6237 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6238 | struct fea *temp_fea; |
| 6239 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6240 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6241 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6242 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6244 | cifs_dbg(FYI, "In Query All EAs path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6245 | QAllEAsRetry: |
| 6246 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6247 | (void **) &pSMBr); |
| 6248 | if (rc) |
| 6249 | return rc; |
| 6250 | |
| 6251 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6252 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6253 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6254 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6255 | list_len++; /* trailing null */ |
| 6256 | list_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6257 | } else { |
| 6258 | list_len = copy_path_name(pSMB->FileName, searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6259 | } |
| 6260 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6261 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6262 | pSMB->TotalDataCount = 0; |
| 6263 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6264 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6265 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6266 | pSMB->MaxSetupCount = 0; |
| 6267 | pSMB->Reserved = 0; |
| 6268 | pSMB->Flags = 0; |
| 6269 | pSMB->Timeout = 0; |
| 6270 | pSMB->Reserved2 = 0; |
| 6271 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6272 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6273 | pSMB->DataCount = 0; |
| 6274 | pSMB->DataOffset = 0; |
| 6275 | pSMB->SetupCount = 1; |
| 6276 | pSMB->Reserved3 = 0; |
| 6277 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6278 | byte_count = params + 1 /* pad */ ; |
| 6279 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6280 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6281 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6282 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6283 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6285 | |
| 6286 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6287 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6288 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6289 | cifs_dbg(FYI, "Send error in QueryAllEAs = %d\n", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6290 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6292 | |
| 6293 | |
| 6294 | /* BB also check enough total bytes returned */ |
| 6295 | /* BB we need to improve the validity checking |
| 6296 | of these trans2 responses */ |
| 6297 | |
| 6298 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6299 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6300 | rc = -EIO; /* bad smb */ |
| 6301 | goto QAllEAsOut; |
| 6302 | } |
| 6303 | |
| 6304 | /* check that length of list is not more than bcc */ |
| 6305 | /* check that each entry does not go beyond length |
| 6306 | of list */ |
| 6307 | /* check that each element of each entry does not |
| 6308 | go beyond end of list */ |
| 6309 | /* validate_trans2_offsets() */ |
| 6310 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6311 | |
| 6312 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6313 | ea_response_data = (struct fealist *) |
| 6314 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6315 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6316 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6317 | cifs_dbg(FYI, "ea length %d\n", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6318 | if (list_len <= 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6319 | cifs_dbg(FYI, "empty EA list returned from server\n"); |
Steve French | 60977fc | 2014-03-25 19:46:36 -0500 | [diff] [blame] | 6320 | /* didn't find the named attribute */ |
| 6321 | if (ea_name) |
| 6322 | rc = -ENODATA; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6323 | goto QAllEAsOut; |
| 6324 | } |
| 6325 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6326 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6327 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6328 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6329 | cifs_dbg(FYI, "EA list appears to go beyond SMB\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6330 | rc = -EIO; |
| 6331 | goto QAllEAsOut; |
| 6332 | } |
| 6333 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6334 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6335 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6336 | temp_fea = ea_response_data->list; |
| 6337 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6338 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6339 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6340 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6341 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6342 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6343 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6344 | /* make sure we can read name_len and value_len */ |
| 6345 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6346 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6347 | rc = -EIO; |
| 6348 | goto QAllEAsOut; |
| 6349 | } |
| 6350 | |
| 6351 | name_len = temp_fea->name_len; |
| 6352 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6353 | list_len -= name_len + 1 + value_len; |
| 6354 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6355 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6356 | rc = -EIO; |
| 6357 | goto QAllEAsOut; |
| 6358 | } |
| 6359 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6360 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6361 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6362 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6363 | temp_ptr += name_len + 1; |
| 6364 | rc = value_len; |
| 6365 | if (buf_size == 0) |
| 6366 | goto QAllEAsOut; |
| 6367 | if ((size_t)value_len > buf_size) { |
| 6368 | rc = -ERANGE; |
| 6369 | goto QAllEAsOut; |
| 6370 | } |
| 6371 | memcpy(EAData, temp_ptr, value_len); |
| 6372 | goto QAllEAsOut; |
| 6373 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6374 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6375 | /* account for prefix user. and trailing null */ |
| 6376 | rc += (5 + 1 + name_len); |
| 6377 | if (rc < (int) buf_size) { |
| 6378 | memcpy(EAData, "user.", 5); |
| 6379 | EAData += 5; |
| 6380 | memcpy(EAData, temp_ptr, name_len); |
| 6381 | EAData += name_len; |
| 6382 | /* null terminate name */ |
| 6383 | *EAData = 0; |
| 6384 | ++EAData; |
| 6385 | } else if (buf_size == 0) { |
| 6386 | /* skip copy - calc size only */ |
| 6387 | } else { |
| 6388 | /* stop before overrun buffer */ |
| 6389 | rc = -ERANGE; |
| 6390 | break; |
| 6391 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6392 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6393 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6394 | temp_fea = (struct fea *)temp_ptr; |
| 6395 | } |
| 6396 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6397 | /* didn't find the named attribute */ |
| 6398 | if (ea_name) |
| 6399 | rc = -ENODATA; |
| 6400 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6401 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6402 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6403 | if (rc == -EAGAIN) |
| 6404 | goto QAllEAsRetry; |
| 6405 | |
| 6406 | return (ssize_t)rc; |
| 6407 | } |
| 6408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6409 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6410 | CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, |
| 6411 | const char *fileName, const char *ea_name, const void *ea_value, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6412 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 6413 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6414 | { |
| 6415 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6416 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6417 | struct fealist *parm_data; |
| 6418 | int name_len; |
| 6419 | int rc = 0; |
| 6420 | int bytes_returned = 0; |
| 6421 | __u16 params, param_offset, byte_count, offset, count; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 6422 | int remap = cifs_remap(cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6423 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6424 | cifs_dbg(FYI, "In SetEA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6425 | SetEARetry: |
| 6426 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6427 | (void **) &pSMBr); |
| 6428 | if (rc) |
| 6429 | return rc; |
| 6430 | |
| 6431 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6432 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6433 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6434 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6435 | name_len++; /* trailing null */ |
| 6436 | name_len *= 2; |
Ronnie Sahlberg | 340625e | 2019-08-27 09:30:14 +1000 | [diff] [blame] | 6437 | } else { |
| 6438 | name_len = copy_path_name(pSMB->FileName, fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6439 | } |
| 6440 | |
| 6441 | params = 6 + name_len; |
| 6442 | |
| 6443 | /* done calculating parms using name_len of file name, |
| 6444 | now use name_len to calculate length of ea name |
| 6445 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6446 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6447 | name_len = 0; |
| 6448 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6449 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6450 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6451 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6452 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6453 | /* BB find max SMB PDU from sess */ |
| 6454 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6455 | pSMB->MaxSetupCount = 0; |
| 6456 | pSMB->Reserved = 0; |
| 6457 | pSMB->Flags = 0; |
| 6458 | pSMB->Timeout = 0; |
| 6459 | pSMB->Reserved2 = 0; |
| 6460 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6461 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6462 | offset = param_offset + params; |
| 6463 | pSMB->InformationLevel = |
| 6464 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6465 | |
Arnd Bergmann | ade7db9 | 2018-02-02 16:48:47 +0100 | [diff] [blame] | 6466 | parm_data = (void *)pSMB + offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6467 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6468 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6469 | pSMB->SetupCount = 1; |
| 6470 | pSMB->Reserved3 = 0; |
| 6471 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6472 | byte_count = 3 /* pad */ + params + count; |
| 6473 | pSMB->DataCount = cpu_to_le16(count); |
| 6474 | parm_data->list_len = cpu_to_le32(count); |
| 6475 | parm_data->list[0].EA_flags = 0; |
| 6476 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6477 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6478 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6479 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6480 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6481 | parm_data->list[0].name[name_len] = 0; |
| 6482 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6483 | /* caller ensures that ea_value_len is less than 64K but |
| 6484 | we need to ensure that it fits within the smb */ |
| 6485 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6486 | /*BB add length check to see if it would fit in |
| 6487 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6488 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6489 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6490 | memcpy(parm_data->list[0].name+name_len+1, |
| 6491 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6492 | |
| 6493 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6494 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6495 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6496 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6497 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6498 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6499 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6500 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6501 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6502 | cifs_dbg(FYI, "SetPathInfo (EA) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6503 | |
| 6504 | cifs_buf_release(pSMB); |
| 6505 | |
| 6506 | if (rc == -EAGAIN) |
| 6507 | goto SetEARetry; |
| 6508 | |
| 6509 | return rc; |
| 6510 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6511 | #endif |