Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cifssmb.c |
| 3 | * |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * Contains the routines for constructing the SMB PDUs themselves |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* SMB/CIFS PDU handling routines here - except for leftovers in connect.c */ |
| 25 | /* These are mostly routines that operate on a pathname, or on a tree id */ |
| 26 | /* (mounted volume), but there are eight handle based routines which must be */ |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 27 | /* treated slightly differently for reconnection purposes since we never */ |
| 28 | /* want to reuse a stale file handle and only the caller knows the file info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <linux/fs.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/vfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/posix_acl_xattr.h> |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 35 | #include <linux/pagemap.h> |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 36 | #include <linux/swap.h> |
| 37 | #include <linux/task_io_accounting_ops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/uaccess.h> |
| 39 | #include "cifspdu.h" |
| 40 | #include "cifsglob.h" |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 41 | #include "cifsacl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "cifsproto.h" |
| 43 | #include "cifs_unicode.h" |
| 44 | #include "cifs_debug.h" |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 45 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #ifdef CONFIG_CIFS_POSIX |
| 48 | static struct { |
| 49 | int index; |
| 50 | char *name; |
| 51 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 52 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 53 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 54 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 55 | #endif /* weak password hashing for legacy clients */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 56 | {CIFS_PROT, "\2NT LM 0.12"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 57 | {POSIX_PROT, "\2POSIX 2"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | {BAD_PROT, "\2"} |
| 59 | }; |
| 60 | #else |
| 61 | static struct { |
| 62 | int index; |
| 63 | char *name; |
| 64 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 65 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 66 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 18f75ca | 2006-10-01 03:13:01 +0000 | [diff] [blame] | 67 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 68 | #endif /* weak password hashing for legacy clients */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 69 | {CIFS_PROT, "\2NT LM 0.12"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | {BAD_PROT, "\2"} |
| 71 | }; |
| 72 | #endif |
| 73 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 74 | /* define the number of elements in the cifs dialect array */ |
| 75 | #ifdef CONFIG_CIFS_POSIX |
| 76 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 77 | #define CIFS_NUM_PROT 4 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 78 | #else |
| 79 | #define CIFS_NUM_PROT 2 |
| 80 | #endif /* CIFS_WEAK_PW_HASH */ |
| 81 | #else /* not posix */ |
| 82 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 83 | #define CIFS_NUM_PROT 3 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 84 | #else |
| 85 | #define CIFS_NUM_PROT 1 |
| 86 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
| 87 | #endif /* CIFS_POSIX */ |
| 88 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 89 | /* |
| 90 | * Mark as invalid, all open files on tree connections since they |
| 91 | * were closed when session to server was lost. |
| 92 | */ |
| 93 | void |
| 94 | cifs_mark_open_files_invalid(struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 97 | struct list_head *tmp; |
| 98 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 100 | /* list all files open on tree connection and mark them invalid */ |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 101 | spin_lock(&cifs_file_list_lock); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 102 | list_for_each_safe(tmp, tmp1, &tcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 103 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 104 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 105 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 107 | spin_unlock(&cifs_file_list_lock); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 108 | /* |
| 109 | * BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 110 | * to this tcon. |
| 111 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 114 | /* reconnect the socket, tcon, and smb session if needed */ |
| 115 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 116 | cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 117 | { |
Jeff Layton | c4a5534 | 2011-07-28 12:40:36 -0400 | [diff] [blame] | 118 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 119 | struct cifs_ses *ses; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 120 | struct TCP_Server_Info *server; |
| 121 | struct nls_table *nls_codepage; |
| 122 | |
| 123 | /* |
| 124 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 125 | * tcp and smb session status done differently for those three - in the |
| 126 | * calling routine |
| 127 | */ |
| 128 | if (!tcon) |
| 129 | return 0; |
| 130 | |
| 131 | ses = tcon->ses; |
| 132 | server = ses->server; |
| 133 | |
| 134 | /* |
| 135 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 136 | * have tcon) are allowed as we start force umount |
| 137 | */ |
| 138 | if (tcon->tidStatus == CifsExiting) { |
| 139 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 140 | smb_command != SMB_COM_OPEN_ANDX && |
| 141 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 142 | cifs_dbg(FYI, "can not send cmd %d while umounting\n", |
| 143 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 144 | return -ENODEV; |
| 145 | } |
| 146 | } |
| 147 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 148 | /* |
| 149 | * Give demultiplex thread up to 10 seconds to reconnect, should be |
| 150 | * greater than cifs socket timeout which is 7 seconds |
| 151 | */ |
| 152 | while (server->tcpStatus == CifsNeedReconnect) { |
| 153 | wait_event_interruptible_timeout(server->response_q, |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 154 | (server->tcpStatus != CifsNeedReconnect), 10 * HZ); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 155 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 156 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 157 | if (server->tcpStatus != CifsNeedReconnect) |
| 158 | break; |
| 159 | |
| 160 | /* |
| 161 | * on "soft" mounts we wait once. Hard mounts keep |
| 162 | * retrying until process is killed or server comes |
| 163 | * back on-line |
| 164 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 165 | if (!tcon->retry) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 166 | cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 167 | return -EHOSTDOWN; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 172 | return 0; |
| 173 | |
| 174 | nls_codepage = load_nls_default(); |
| 175 | |
| 176 | /* |
| 177 | * need to prevent multiple threads trying to simultaneously |
| 178 | * reconnect the same SMB session |
| 179 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 180 | mutex_lock(&ses->session_mutex); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 181 | rc = cifs_negotiate_protocol(0, ses); |
| 182 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 183 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 184 | |
| 185 | /* do we need to reconnect tcon? */ |
| 186 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 187 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 188 | goto out; |
| 189 | } |
| 190 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 191 | cifs_mark_open_files_invalid(tcon); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 192 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 193 | mutex_unlock(&ses->session_mutex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 194 | cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 195 | |
| 196 | if (rc) |
| 197 | goto out; |
| 198 | |
| 199 | /* |
| 200 | * FIXME: check if wsize needs updated due to negotiated smb buffer |
| 201 | * size shrinking |
| 202 | */ |
| 203 | atomic_inc(&tconInfoReconnectCount); |
| 204 | |
| 205 | /* tell server Unix caps we support */ |
| 206 | if (ses->capabilities & CAP_UNIX) |
| 207 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 208 | |
| 209 | /* |
| 210 | * Removed call to reopen open files here. It is safer (and faster) to |
| 211 | * reopen files one at a time as needed in read and write. |
| 212 | * |
| 213 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 214 | */ |
| 215 | |
| 216 | out: |
| 217 | /* |
| 218 | * Check if handle based operation so we know whether we can continue |
| 219 | * or not without returning to caller to reset file handle |
| 220 | */ |
| 221 | switch (smb_command) { |
| 222 | case SMB_COM_READ_ANDX: |
| 223 | case SMB_COM_WRITE_ANDX: |
| 224 | case SMB_COM_CLOSE: |
| 225 | case SMB_COM_FIND_CLOSE2: |
| 226 | case SMB_COM_LOCKING_ANDX: |
| 227 | rc = -EAGAIN; |
| 228 | } |
| 229 | |
| 230 | unload_nls(nls_codepage); |
| 231 | return rc; |
| 232 | } |
| 233 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 234 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 235 | SMB information in the SMB header. If the return code is zero, this |
| 236 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 238 | small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 239 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 241 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 243 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 244 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return rc; |
| 246 | |
| 247 | *request_buf = cifs_small_buf_get(); |
| 248 | if (*request_buf == NULL) { |
| 249 | /* BB should we add a retry in here if not a writepage? */ |
| 250 | return -ENOMEM; |
| 251 | } |
| 252 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 253 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 254 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 256 | if (tcon != NULL) |
| 257 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 258 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 259 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 262 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 263 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 264 | struct cifs_ses *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 265 | { |
| 266 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 267 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 268 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 269 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 270 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 271 | return rc; |
| 272 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 273 | buffer = (struct smb_hdr *)*request_buf; |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 274 | buffer->Mid = get_next_mid(ses->server); |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 275 | if (ses->capabilities & CAP_UNICODE) |
| 276 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 277 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 278 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 279 | |
| 280 | /* uid, tid can stay at zero as set in header assemble */ |
| 281 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 282 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 283 | this function is used after 1st of session setup requests */ |
| 284 | |
| 285 | return rc; |
| 286 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 289 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 290 | __smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 291 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | *request_buf = cifs_buf_get(); |
| 294 | if (*request_buf == NULL) { |
| 295 | /* BB should we add a retry in here if not a writepage? */ |
| 296 | return -ENOMEM; |
| 297 | } |
| 298 | /* Although the original thought was we needed the response buf for */ |
| 299 | /* potential retries of smb operations it turns out we can determine */ |
| 300 | /* from the mid flags when the request buffer can be resent without */ |
| 301 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 302 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 303 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 306 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 308 | if (tcon != NULL) |
| 309 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 310 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 315 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 316 | smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 317 | void **request_buf, void **response_buf) |
| 318 | { |
| 319 | int rc; |
| 320 | |
| 321 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 322 | if (rc) |
| 323 | return rc; |
| 324 | |
| 325 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 326 | } |
| 327 | |
| 328 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 329 | 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] | 330 | void **request_buf, void **response_buf) |
| 331 | { |
| 332 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 333 | return -EHOSTDOWN; |
| 334 | |
| 335 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 338 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 340 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 342 | /* check for plausible wct */ |
| 343 | if (pSMB->hdr.WordCount < 10) |
| 344 | goto vt2_err; |
| 345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 347 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 348 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 349 | goto vt2_err; |
| 350 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 351 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 352 | if (total_size >= 512) |
| 353 | goto vt2_err; |
| 354 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 355 | /* check that bcc is at least as big as parms + data, and that it is |
| 356 | * less than negotiated smb buffer |
| 357 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 358 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 359 | if (total_size > get_bcc(&pSMB->hdr) || |
| 360 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 361 | goto vt2_err; |
| 362 | |
| 363 | return 0; |
| 364 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 365 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 367 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 369 | |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 370 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 371 | decode_ext_sec_blob(struct cifs_ses *ses, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 372 | { |
| 373 | int rc = 0; |
| 374 | u16 count; |
| 375 | char *guid = pSMBr->u.extended_response.GUID; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 376 | struct TCP_Server_Info *server = ses->server; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 377 | |
| 378 | count = get_bcc(&pSMBr->hdr); |
| 379 | if (count < SMB1_CLIENT_GUID_SIZE) |
| 380 | return -EIO; |
| 381 | |
| 382 | spin_lock(&cifs_tcp_ses_lock); |
| 383 | if (server->srv_count > 1) { |
| 384 | spin_unlock(&cifs_tcp_ses_lock); |
| 385 | if (memcmp(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE) != 0) { |
| 386 | cifs_dbg(FYI, "server UID changed\n"); |
| 387 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 388 | } |
| 389 | } else { |
| 390 | spin_unlock(&cifs_tcp_ses_lock); |
| 391 | memcpy(server->server_GUID, guid, SMB1_CLIENT_GUID_SIZE); |
| 392 | } |
| 393 | |
| 394 | if (count == SMB1_CLIENT_GUID_SIZE) { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 395 | server->sec_ntlmssp = true; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 396 | } else { |
| 397 | count -= SMB1_CLIENT_GUID_SIZE; |
| 398 | rc = decode_negTokenInit( |
| 399 | pSMBr->u.extended_response.SecurityBlob, count, server); |
| 400 | if (rc != 1) |
| 401 | return -EINVAL; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 407 | int |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 408 | cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required) |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 409 | { |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 410 | bool srv_sign_required = server->sec_mode & SECMODE_SIGN_REQUIRED; |
| 411 | bool srv_sign_enabled = server->sec_mode & SECMODE_SIGN_ENABLED; |
| 412 | bool mnt_sign_enabled = global_secflags & CIFSSEC_MAY_SIGN; |
| 413 | |
| 414 | /* |
| 415 | * Is signing required by mnt options? If not then check |
| 416 | * global_secflags to see if it is there. |
| 417 | */ |
| 418 | if (!mnt_sign_required) |
| 419 | mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) == |
| 420 | CIFSSEC_MUST_SIGN); |
| 421 | |
| 422 | /* |
| 423 | * If signing is required then it's automatically enabled too, |
| 424 | * otherwise, check to see if the secflags allow it. |
| 425 | */ |
| 426 | mnt_sign_enabled = mnt_sign_required ? mnt_sign_required : |
| 427 | (global_secflags & CIFSSEC_MAY_SIGN); |
| 428 | |
| 429 | /* If server requires signing, does client allow it? */ |
| 430 | if (srv_sign_required) { |
| 431 | if (!mnt_sign_enabled) { |
| 432 | cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!"); |
| 433 | return -ENOTSUPP; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 434 | } |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 435 | server->sign = true; |
| 436 | } |
| 437 | |
| 438 | /* If client requires signing, does server allow it? */ |
| 439 | if (mnt_sign_required) { |
| 440 | if (!srv_sign_enabled) { |
| 441 | cifs_dbg(VFS, "Server does not support signing!"); |
| 442 | return -ENOTSUPP; |
| 443 | } |
| 444 | server->sign = true; |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 450 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 451 | static int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 452 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 453 | { |
| 454 | __s16 tmp; |
| 455 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
| 456 | |
| 457 | if (server->dialect != LANMAN_PROT && server->dialect != LANMAN2_PROT) |
| 458 | return -EOPNOTSUPP; |
| 459 | |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 460 | server->sec_mode = le16_to_cpu(rsp->SecurityMode); |
| 461 | server->maxReq = min_t(unsigned int, |
| 462 | le16_to_cpu(rsp->MaxMpxCount), |
| 463 | cifs_max_pending); |
| 464 | set_credits(server, server->maxReq); |
| 465 | server->maxBuf = le16_to_cpu(rsp->MaxBufSize); |
| 466 | server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); |
| 467 | /* even though we do not use raw we might as well set this |
| 468 | accurately, in case we ever find a need for it */ |
| 469 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
| 470 | server->max_rw = 0xFF00; |
| 471 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 472 | } else { |
| 473 | server->max_rw = 0;/* do not need to use raw anyway */ |
| 474 | server->capabilities = CAP_MPX_MODE; |
| 475 | } |
| 476 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
| 477 | if (tmp == -1) { |
| 478 | /* OS/2 often does not set timezone therefore |
| 479 | * we must use server time to calc time zone. |
| 480 | * Could deviate slightly from the right zone. |
| 481 | * Smallest defined timezone difference is 15 minutes |
| 482 | * (i.e. Nepal). Rounding up/down is done to match |
| 483 | * this requirement. |
| 484 | */ |
| 485 | int val, seconds, remain, result; |
| 486 | struct timespec ts, utc; |
| 487 | utc = CURRENT_TIME; |
| 488 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 489 | rsp->SrvTime.Time, 0); |
| 490 | cifs_dbg(FYI, "SrvTime %d sec since 1970 (utc: %d) diff: %d\n", |
| 491 | (int)ts.tv_sec, (int)utc.tv_sec, |
| 492 | (int)(utc.tv_sec - ts.tv_sec)); |
| 493 | val = (int)(utc.tv_sec - ts.tv_sec); |
| 494 | seconds = abs(val); |
| 495 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
| 496 | remain = seconds % MIN_TZ_ADJ; |
| 497 | if (remain >= (MIN_TZ_ADJ / 2)) |
| 498 | result += MIN_TZ_ADJ; |
| 499 | if (val < 0) |
| 500 | result = -result; |
| 501 | server->timeAdj = result; |
| 502 | } else { |
| 503 | server->timeAdj = (int)tmp; |
| 504 | server->timeAdj *= 60; /* also in seconds */ |
| 505 | } |
| 506 | cifs_dbg(FYI, "server->timeAdj: %d seconds\n", server->timeAdj); |
| 507 | |
| 508 | |
| 509 | /* BB get server time for time conversions and add |
| 510 | code to use it and timezone since this is not UTC */ |
| 511 | |
| 512 | if (rsp->EncryptionKeyLength == |
| 513 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
| 514 | memcpy(server->cryptkey, rsp->EncryptionKey, |
| 515 | CIFS_CRYPTO_KEY_SIZE); |
| 516 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
| 517 | return -EIO; /* need cryptkey unless plain text */ |
| 518 | } |
| 519 | |
| 520 | cifs_dbg(FYI, "LANMAN negotiated\n"); |
| 521 | return 0; |
| 522 | } |
| 523 | #else |
| 524 | static inline int |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 525 | decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 526 | { |
| 527 | cifs_dbg(VFS, "mount failed, cifs module not built with CIFS_WEAK_PW_HASH support\n"); |
| 528 | return -EOPNOTSUPP; |
| 529 | } |
| 530 | #endif |
| 531 | |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 532 | static bool |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 533 | should_set_ext_sec_flag(enum securityEnum sectype) |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 534 | { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 535 | switch (sectype) { |
| 536 | case RawNTLMSSP: |
| 537 | case Kerberos: |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 538 | return true; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 539 | case Unspecified: |
| 540 | if (global_secflags & |
| 541 | (CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)) |
| 542 | return true; |
| 543 | /* Fallthrough */ |
| 544 | default: |
| 545 | return false; |
| 546 | } |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 547 | } |
| 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | int |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 550 | CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { |
| 552 | NEGOTIATE_REQ *pSMB; |
| 553 | NEGOTIATE_RSP *pSMBr; |
| 554 | int rc = 0; |
| 555 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 556 | int i; |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 557 | struct TCP_Server_Info *server = ses->server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | u16 count; |
| 559 | |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 560 | if (!server) { |
| 561 | WARN(1, "%s: server is NULL!\n", __func__); |
| 562 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 566 | (void **) &pSMB, (void **) &pSMBr); |
| 567 | if (rc) |
| 568 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 569 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 570 | pSMB->hdr.Mid = get_next_mid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 571 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 572 | |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 573 | if (should_set_ext_sec_flag(ses->sectype)) { |
Jeff Layton | 9193400 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 574 | cifs_dbg(FYI, "Requesting extended security."); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 575 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 576 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 577 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 578 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 579 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 580 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 581 | count += strlen(protocols[i].name) + 1; |
| 582 | /* null at end of source and target buffers anyway */ |
| 583 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 584 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | pSMB->ByteCount = cpu_to_le16(count); |
| 586 | |
| 587 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 588 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 589 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 590 | goto neg_err_exit; |
| 591 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 592 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 593 | cifs_dbg(FYI, "Dialect: %d\n", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 594 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 595 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 596 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 597 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 598 | could not negotiate a common dialect */ |
| 599 | rc = -EOPNOTSUPP; |
| 600 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 601 | } else if (pSMBr->hdr.WordCount == 13) { |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 602 | server->negflavor = CIFS_NEGFLAVOR_LANMAN; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 603 | rc = decode_lanman_negprot_rsp(server, pSMBr); |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 604 | goto signing_check; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 605 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 606 | /* unknown wct */ |
| 607 | rc = -EOPNOTSUPP; |
| 608 | goto neg_err_exit; |
| 609 | } |
Jeff Layton | 2190eca | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 610 | /* else wct == 17, NTLM or better */ |
| 611 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 612 | server->sec_mode = pSMBr->SecurityMode; |
| 613 | if ((server->sec_mode & SECMODE_USER) == 0) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 614 | cifs_dbg(FYI, "share mode security\n"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 615 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 616 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 617 | little endian */ |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 618 | server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), |
| 619 | cifs_max_pending); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 620 | set_credits(server, server->maxReq); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 621 | /* probably no need to store and check maxvcs */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 622 | server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 623 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 624 | cifs_dbg(NOISY, "Max buf = %d\n", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 625 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 626 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 627 | server->timeAdj *= 60; |
Jeff Layton | 31d9e2b | 2013-05-26 07:00:57 -0400 | [diff] [blame] | 628 | |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 629 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
| 630 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 631 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 632 | CIFS_CRYPTO_KEY_SIZE); |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 633 | } else if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC || |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 634 | server->capabilities & CAP_EXTENDED_SECURITY) && |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 635 | (pSMBr->EncryptionKeyLength == 0)) { |
| 636 | server->negflavor = CIFS_NEGFLAVOR_EXTENDED; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame^] | 637 | rc = decode_ext_sec_blob(ses, pSMBr); |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 638 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 639 | rc = -EIO; /* no crypt key only if plain text pwd */ |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 640 | } else { |
| 641 | server->negflavor = CIFS_NEGFLAVOR_UNENCAP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 642 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 643 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 644 | |
| 645 | signing_check: |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 646 | if (!rc) |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 647 | rc = cifs_enable_signing(server, ses->sign); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 648 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 649 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 650 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 651 | cifs_dbg(FYI, "negprot rc %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | return rc; |
| 653 | } |
| 654 | |
| 655 | int |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 656 | CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { |
| 658 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 661 | cifs_dbg(FYI, "In tree disconnect\n"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 662 | |
| 663 | /* BB: do we need to check this? These should never be NULL. */ |
| 664 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 665 | return -EIO; |
| 666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 668 | * No need to return error on this operation if tid invalidated and |
| 669 | * closed on server already e.g. due to tcp session crashing. Also, |
| 670 | * the tcon is no longer on the list, so no need to take lock before |
| 671 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 673 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 674 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 676 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 677 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 678 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 680 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 681 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 683 | cifs_dbg(FYI, "Tree disconnect failed %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 685 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 686 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | if (rc == -EAGAIN) |
| 688 | rc = 0; |
| 689 | |
| 690 | return rc; |
| 691 | } |
| 692 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 693 | /* |
| 694 | * This is a no-op for now. We're not really interested in the reply, but |
| 695 | * rather in the fact that the server sent one and that server->lstrp |
| 696 | * gets updated. |
| 697 | * |
| 698 | * FIXME: maybe we should consider checking that the reply matches request? |
| 699 | */ |
| 700 | static void |
| 701 | cifs_echo_callback(struct mid_q_entry *mid) |
| 702 | { |
| 703 | struct TCP_Server_Info *server = mid->callback_data; |
| 704 | |
| 705 | DeleteMidQEntry(mid); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 706 | add_credits(server, 1, CIFS_ECHO_OP); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | int |
| 710 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 711 | { |
| 712 | ECHO_REQ *smb; |
| 713 | int rc = 0; |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 714 | struct kvec iov; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 715 | struct smb_rqst rqst = { .rq_iov = &iov, |
| 716 | .rq_nvec = 1 }; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 717 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 718 | cifs_dbg(FYI, "In echo request\n"); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 719 | |
| 720 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 721 | if (rc) |
| 722 | return rc; |
| 723 | |
| 724 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 725 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8f | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 726 | smb->hdr.WordCount = 1; |
| 727 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 728 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 729 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 730 | inc_rfc1001_len(smb, 3); |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 731 | iov.iov_base = smb; |
| 732 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 733 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 734 | rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 735 | server, CIFS_ASYNC_OP | CIFS_ECHO_OP); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 736 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 737 | cifs_dbg(FYI, "Echo request failed: %d\n", rc); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 738 | |
| 739 | cifs_small_buf_release(smb); |
| 740 | |
| 741 | return rc; |
| 742 | } |
| 743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | int |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 745 | CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | LOGOFF_ANDX_REQ *pSMB; |
| 748 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 750 | cifs_dbg(FYI, "In SMBLogoff for session disconnect\n"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 751 | |
| 752 | /* |
| 753 | * BB: do we need to check validity of ses and server? They should |
| 754 | * always be valid since we have an active reference. If not, that |
| 755 | * should probably be a BUG() |
| 756 | */ |
| 757 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | return -EIO; |
| 759 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 760 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 761 | if (ses->need_reconnect) |
| 762 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 763 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 765 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 766 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | return rc; |
| 768 | } |
| 769 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 770 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 771 | |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 772 | if (ses->server->sign) |
| 773 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | pSMB->hdr.Uid = ses->Suid; |
| 776 | |
| 777 | pSMB->AndXCommand = 0xFF; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 778 | rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 779 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 780 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| 782 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 783 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | error */ |
| 785 | if (rc == -EAGAIN) |
| 786 | rc = 0; |
| 787 | return rc; |
| 788 | } |
| 789 | |
| 790 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 791 | CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, |
| 792 | const char *fileName, __u16 type, |
| 793 | const struct nls_table *nls_codepage, int remap) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 794 | { |
| 795 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 796 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 797 | struct unlink_psx_rq *pRqD; |
| 798 | int name_len; |
| 799 | int rc = 0; |
| 800 | int bytes_returned = 0; |
| 801 | __u16 params, param_offset, offset, byte_count; |
| 802 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 803 | cifs_dbg(FYI, "In POSIX delete\n"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 804 | PsxDelete: |
| 805 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 806 | (void **) &pSMBr); |
| 807 | if (rc) |
| 808 | return rc; |
| 809 | |
| 810 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 811 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 812 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 813 | PATH_MAX, nls_codepage, remap); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 814 | name_len++; /* trailing null */ |
| 815 | name_len *= 2; |
| 816 | } else { /* BB add path length overrun check */ |
| 817 | name_len = strnlen(fileName, PATH_MAX); |
| 818 | name_len++; /* trailing null */ |
| 819 | strncpy(pSMB->FileName, fileName, name_len); |
| 820 | } |
| 821 | |
| 822 | params = 6 + name_len; |
| 823 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 824 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 825 | pSMB->MaxSetupCount = 0; |
| 826 | pSMB->Reserved = 0; |
| 827 | pSMB->Flags = 0; |
| 828 | pSMB->Timeout = 0; |
| 829 | pSMB->Reserved2 = 0; |
| 830 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 831 | InformationLevel) - 4; |
| 832 | offset = param_offset + params; |
| 833 | |
| 834 | /* Setup pointer to Request Data (inode type) */ |
| 835 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 836 | pRqD->type = cpu_to_le16(type); |
| 837 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 838 | pSMB->DataOffset = cpu_to_le16(offset); |
| 839 | pSMB->SetupCount = 1; |
| 840 | pSMB->Reserved3 = 0; |
| 841 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 842 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 843 | |
| 844 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 845 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 846 | pSMB->ParameterCount = cpu_to_le16(params); |
| 847 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 848 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 849 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 850 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 851 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 852 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 853 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 854 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 855 | cifs_dbg(FYI, "Posix delete returned %d\n", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 856 | cifs_buf_release(pSMB); |
| 857 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 858 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 859 | |
| 860 | if (rc == -EAGAIN) |
| 861 | goto PsxDelete; |
| 862 | |
| 863 | return rc; |
| 864 | } |
| 865 | |
| 866 | int |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 867 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 868 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
| 870 | DELETE_FILE_REQ *pSMB = NULL; |
| 871 | DELETE_FILE_RSP *pSMBr = NULL; |
| 872 | int rc = 0; |
| 873 | int bytes_returned; |
| 874 | int name_len; |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 875 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
| 877 | DelFileRetry: |
| 878 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 879 | (void **) &pSMBr); |
| 880 | if (rc) |
| 881 | return rc; |
| 882 | |
| 883 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 884 | name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name, |
| 885 | PATH_MAX, cifs_sb->local_nls, |
| 886 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | name_len++; /* trailing null */ |
| 888 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 889 | } else { /* BB improve check for buffer overruns BB */ |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 890 | name_len = strnlen(name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | name_len++; /* trailing null */ |
Pavel Shilovsky | ed6875e | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 892 | strncpy(pSMB->fileName, name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | } |
| 894 | pSMB->SearchAttributes = |
| 895 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 896 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 897 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 899 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 900 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 901 | cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 902 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 903 | cifs_dbg(FYI, "Error in RMFile = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | cifs_buf_release(pSMB); |
| 906 | if (rc == -EAGAIN) |
| 907 | goto DelFileRetry; |
| 908 | |
| 909 | return rc; |
| 910 | } |
| 911 | |
| 912 | int |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 913 | CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 914 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | { |
| 916 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 917 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 918 | int rc = 0; |
| 919 | int bytes_returned; |
| 920 | int name_len; |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 921 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 923 | cifs_dbg(FYI, "In CIFSSMBRmDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | RmDirRetry: |
| 925 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 926 | (void **) &pSMBr); |
| 927 | if (rc) |
| 928 | return rc; |
| 929 | |
| 930 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 931 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
| 932 | PATH_MAX, cifs_sb->local_nls, |
| 933 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | name_len++; /* trailing null */ |
| 935 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 936 | } else { /* BB improve check for buffer overruns BB */ |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 937 | name_len = strnlen(name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | name_len++; /* trailing null */ |
Pavel Shilovsky | f958ca5 | 2012-07-10 16:14:18 +0400 | [diff] [blame] | 939 | strncpy(pSMB->DirName, name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 943 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 945 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 946 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 947 | cifs_stats_inc(&tcon->stats.cifs_stats.num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 948 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 949 | cifs_dbg(FYI, "Error in RMDir = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
| 951 | cifs_buf_release(pSMB); |
| 952 | if (rc == -EAGAIN) |
| 953 | goto RmDirRetry; |
| 954 | return rc; |
| 955 | } |
| 956 | |
| 957 | int |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 958 | CIFSSMBMkDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 959 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | { |
| 961 | int rc = 0; |
| 962 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 963 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 964 | int bytes_returned; |
| 965 | int name_len; |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 966 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 968 | cifs_dbg(FYI, "In CIFSSMBMkDir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | MkDirRetry: |
| 970 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 971 | (void **) &pSMBr); |
| 972 | if (rc) |
| 973 | return rc; |
| 974 | |
| 975 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 976 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
Pavel Shilovsky | f436720 | 2012-03-17 11:41:12 +0300 | [diff] [blame] | 977 | PATH_MAX, cifs_sb->local_nls, |
| 978 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | name_len++; /* trailing null */ |
| 980 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 981 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | name_len = strnlen(name, PATH_MAX); |
| 983 | name_len++; /* trailing null */ |
| 984 | strncpy(pSMB->DirName, name, name_len); |
| 985 | } |
| 986 | |
| 987 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 988 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 990 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 991 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 992 | cifs_stats_inc(&tcon->stats.cifs_stats.num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 993 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 994 | cifs_dbg(FYI, "Error in Mkdir = %d\n", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 995 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | cifs_buf_release(pSMB); |
| 997 | if (rc == -EAGAIN) |
| 998 | goto MkDirRetry; |
| 999 | return rc; |
| 1000 | } |
| 1001 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1002 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1003 | CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, |
| 1004 | __u32 posix_flags, __u64 mode, __u16 *netfid, |
| 1005 | FILE_UNIX_BASIC_INFO *pRetData, __u32 *pOplock, |
| 1006 | const char *name, const struct nls_table *nls_codepage, |
| 1007 | int remap) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1008 | { |
| 1009 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1010 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1011 | int name_len; |
| 1012 | int rc = 0; |
| 1013 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1014 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1015 | OPEN_PSX_REQ *pdata; |
| 1016 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1017 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1018 | cifs_dbg(FYI, "In POSIX Create\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1019 | PsxCreat: |
| 1020 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1021 | (void **) &pSMBr); |
| 1022 | if (rc) |
| 1023 | return rc; |
| 1024 | |
| 1025 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1026 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1027 | cifsConvertToUTF16((__le16 *) pSMB->FileName, name, |
| 1028 | PATH_MAX, nls_codepage, remap); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1029 | name_len++; /* trailing null */ |
| 1030 | name_len *= 2; |
| 1031 | } else { /* BB improve the check for buffer overruns BB */ |
| 1032 | name_len = strnlen(name, PATH_MAX); |
| 1033 | name_len++; /* trailing null */ |
| 1034 | strncpy(pSMB->FileName, name, name_len); |
| 1035 | } |
| 1036 | |
| 1037 | params = 6 + name_len; |
| 1038 | count = sizeof(OPEN_PSX_REQ); |
| 1039 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1040 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1041 | pSMB->MaxSetupCount = 0; |
| 1042 | pSMB->Reserved = 0; |
| 1043 | pSMB->Flags = 0; |
| 1044 | pSMB->Timeout = 0; |
| 1045 | pSMB->Reserved2 = 0; |
| 1046 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1047 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1048 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1049 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1050 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1051 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1052 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1053 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1054 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1055 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1056 | pSMB->SetupCount = 1; |
| 1057 | pSMB->Reserved3 = 0; |
| 1058 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1059 | byte_count = 3 /* pad */ + params + count; |
| 1060 | |
| 1061 | pSMB->DataCount = cpu_to_le16(count); |
| 1062 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1063 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1064 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1065 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1066 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1067 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1068 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1069 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1070 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1071 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1072 | cifs_dbg(FYI, "Posix create returned %d\n", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1073 | goto psx_create_err; |
| 1074 | } |
| 1075 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1076 | cifs_dbg(FYI, "copying inode info\n"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1077 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1078 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1079 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1080 | rc = -EIO; /* bad smb */ |
| 1081 | goto psx_create_err; |
| 1082 | } |
| 1083 | |
| 1084 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1085 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1086 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1087 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1088 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1089 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1090 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1091 | /* Let caller know file was created so we can set the mode. */ |
| 1092 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1093 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1094 | *pOplock |= CIFS_CREATE_ACTION; |
| 1095 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1096 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1097 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1098 | cifs_dbg(NOISY, "unknown type\n"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1099 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1100 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1101 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1102 | cifs_dbg(VFS, "Open response data too small\n"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1103 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1104 | goto psx_create_err; |
| 1105 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1106 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1107 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1108 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1109 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1110 | |
| 1111 | psx_create_err: |
| 1112 | cifs_buf_release(pSMB); |
| 1113 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1114 | if (posix_flags & SMB_O_DIRECTORY) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1115 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixmkdirs); |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1116 | else |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1117 | cifs_stats_inc(&tcon->stats.cifs_stats.num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1118 | |
| 1119 | if (rc == -EAGAIN) |
| 1120 | goto PsxCreat; |
| 1121 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1122 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1125 | static __u16 convert_disposition(int disposition) |
| 1126 | { |
| 1127 | __u16 ofun = 0; |
| 1128 | |
| 1129 | switch (disposition) { |
| 1130 | case FILE_SUPERSEDE: |
| 1131 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1132 | break; |
| 1133 | case FILE_OPEN: |
| 1134 | ofun = SMBOPEN_OAPPEND; |
| 1135 | break; |
| 1136 | case FILE_CREATE: |
| 1137 | ofun = SMBOPEN_OCREATE; |
| 1138 | break; |
| 1139 | case FILE_OPEN_IF: |
| 1140 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1141 | break; |
| 1142 | case FILE_OVERWRITE: |
| 1143 | ofun = SMBOPEN_OTRUNC; |
| 1144 | break; |
| 1145 | case FILE_OVERWRITE_IF: |
| 1146 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1147 | break; |
| 1148 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1149 | cifs_dbg(FYI, "unknown disposition %d\n", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1150 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1151 | } |
| 1152 | return ofun; |
| 1153 | } |
| 1154 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1155 | static int |
| 1156 | access_flags_to_smbopen_mode(const int access_flags) |
| 1157 | { |
| 1158 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1159 | |
| 1160 | if (masked_flags == GENERIC_READ) |
| 1161 | return SMBOPEN_READ; |
| 1162 | else if (masked_flags == GENERIC_WRITE) |
| 1163 | return SMBOPEN_WRITE; |
| 1164 | |
| 1165 | /* just go for read/write */ |
| 1166 | return SMBOPEN_READWRITE; |
| 1167 | } |
| 1168 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1169 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1170 | SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1171 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1172 | const int access_flags, const int create_options, __u16 *netfid, |
| 1173 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1174 | const struct nls_table *nls_codepage, int remap) |
| 1175 | { |
| 1176 | int rc = -EACCES; |
| 1177 | OPENX_REQ *pSMB = NULL; |
| 1178 | OPENX_RSP *pSMBr = NULL; |
| 1179 | int bytes_returned; |
| 1180 | int name_len; |
| 1181 | __u16 count; |
| 1182 | |
| 1183 | OldOpenRetry: |
| 1184 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1185 | (void **) &pSMBr); |
| 1186 | if (rc) |
| 1187 | return rc; |
| 1188 | |
| 1189 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1190 | |
| 1191 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1192 | count = 1; /* account for one byte pad to word boundary */ |
| 1193 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1194 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1195 | fileName, PATH_MAX, nls_codepage, remap); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1196 | name_len++; /* trailing null */ |
| 1197 | name_len *= 2; |
| 1198 | } else { /* BB improve check for buffer overruns BB */ |
| 1199 | count = 0; /* no pad */ |
| 1200 | name_len = strnlen(fileName, PATH_MAX); |
| 1201 | name_len++; /* trailing null */ |
| 1202 | strncpy(pSMB->fileName, fileName, name_len); |
| 1203 | } |
| 1204 | if (*pOplock & REQ_OPLOCK) |
| 1205 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1206 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1207 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1208 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1209 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1210 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1211 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1212 | /* set file as system file if special file such |
| 1213 | as fifo and server expecting SFU style and |
| 1214 | no Unix extensions */ |
| 1215 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1216 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1217 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1218 | else /* BB FIXME BB */ |
| 1219 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1220 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1221 | if (create_options & CREATE_OPTION_READONLY) |
| 1222 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1223 | |
| 1224 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1225 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1226 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1227 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1228 | |
| 1229 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1230 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1231 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1232 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1233 | |
| 1234 | pSMB->ByteCount = cpu_to_le16(count); |
| 1235 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1236 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1237 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1238 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1239 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1240 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1241 | } else { |
| 1242 | /* BB verify if wct == 15 */ |
| 1243 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1244 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1245 | |
| 1246 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1247 | /* Let caller know file was created so we can set the mode. */ |
| 1248 | /* Do we care about the CreateAction in any other cases? */ |
| 1249 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1250 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1251 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1252 | /* BB FIXME END */ |
| 1253 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1254 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1255 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1256 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1257 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1258 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1259 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1260 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1261 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1262 | pfile_info->AllocationSize = |
| 1263 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1264 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1265 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1266 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | cifs_buf_release(pSMB); |
| 1271 | if (rc == -EAGAIN) |
| 1272 | goto OldOpenRetry; |
| 1273 | return rc; |
| 1274 | } |
| 1275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1277 | CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1279 | const int access_flags, const int create_options, __u16 *netfid, |
| 1280 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1281 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | { |
| 1283 | int rc = -EACCES; |
| 1284 | OPEN_REQ *pSMB = NULL; |
| 1285 | OPEN_RSP *pSMBr = NULL; |
| 1286 | int bytes_returned; |
| 1287 | int name_len; |
| 1288 | __u16 count; |
| 1289 | |
| 1290 | openRetry: |
| 1291 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, |
| 1292 | (void **) &pSMBr); |
| 1293 | if (rc) |
| 1294 | return rc; |
| 1295 | |
| 1296 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1297 | |
| 1298 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1299 | count = 1; /* account for one byte pad to word boundary */ |
| 1300 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1301 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1302 | fileName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | name_len++; /* trailing null */ |
| 1304 | name_len *= 2; |
| 1305 | pSMB->NameLength = cpu_to_le16(name_len); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1306 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | count = 0; /* no pad */ |
| 1308 | name_len = strnlen(fileName, PATH_MAX); |
| 1309 | name_len++; /* trailing null */ |
| 1310 | pSMB->NameLength = cpu_to_le16(name_len); |
| 1311 | strncpy(pSMB->fileName, fileName, name_len); |
| 1312 | } |
| 1313 | if (*pOplock & REQ_OPLOCK) |
| 1314 | pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1315 | else if (*pOplock & REQ_BATCHOPLOCK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | pSMB->DesiredAccess = cpu_to_le32(access_flags); |
| 1318 | pSMB->AllocationSize = 0; |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1319 | /* set file as system file if special file such |
| 1320 | as fifo and server expecting SFU style and |
| 1321 | no Unix extensions */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1322 | if (create_options & CREATE_OPTION_SPECIAL) |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1323 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1324 | else |
| 1325 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | /* XP does not handle ATTR_POSIX_SEMANTICS */ |
| 1328 | /* but it helps speed up case sensitive checks for other |
| 1329 | servers such as Samba */ |
| 1330 | if (tcon->ses->capabilities & CAP_UNIX) |
| 1331 | pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
| 1332 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1333 | if (create_options & CREATE_OPTION_READONLY) |
| 1334 | pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
| 1335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1337 | pSMB->CreateDisposition = cpu_to_le32(openDisposition); |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1338 | pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1339 | /* BB Expirement with various impersonation levels and verify */ |
| 1340 | pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | pSMB->SecurityFlags = |
| 1342 | SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY; |
| 1343 | |
| 1344 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1345 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | |
| 1347 | pSMB->ByteCount = cpu_to_le16(count); |
| 1348 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1349 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1350 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1351 | cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1353 | cifs_dbg(FYI, "Error in Open = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | } else { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1355 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1357 | /* Let caller know file was created so we can set the mode. */ |
| 1358 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1359 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1360 | *pOplock |= CIFS_CREATE_ACTION; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1361 | if (pfile_info) { |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1362 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
| 1363 | 36 /* CreationTime to Attributes */); |
| 1364 | /* the file_info buf is endian converted by caller */ |
| 1365 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
| 1366 | pfile_info->EndOfFile = pSMBr->EndOfFile; |
| 1367 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
| 1368 | pfile_info->DeletePending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | cifs_buf_release(pSMB); |
| 1373 | if (rc == -EAGAIN) |
| 1374 | goto openRetry; |
| 1375 | return rc; |
| 1376 | } |
| 1377 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1378 | /* |
| 1379 | * Discard any remaining data in the current SMB. To do this, we borrow the |
| 1380 | * current bigbuf. |
| 1381 | */ |
| 1382 | static int |
| 1383 | cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1384 | { |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1385 | unsigned int rfclen = get_rfc1002_length(server->smallbuf); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1386 | int remaining = rfclen + 4 - server->total_read; |
| 1387 | struct cifs_readdata *rdata = mid->callback_data; |
| 1388 | |
| 1389 | while (remaining > 0) { |
| 1390 | int length; |
| 1391 | |
| 1392 | length = cifs_read_from_socket(server, server->bigbuf, |
| 1393 | min_t(unsigned int, remaining, |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1394 | CIFSMaxBufSize + MAX_HEADER_SIZE(server))); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1395 | if (length < 0) |
| 1396 | return length; |
| 1397 | server->total_read += length; |
| 1398 | remaining -= length; |
| 1399 | } |
| 1400 | |
| 1401 | dequeue_mid(mid, rdata->result); |
| 1402 | return 0; |
| 1403 | } |
| 1404 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1405 | int |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1406 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1407 | { |
| 1408 | int length, len; |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1409 | unsigned int data_offset, data_len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1410 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1411 | char *buf = server->smallbuf; |
| 1412 | unsigned int buflen = get_rfc1002_length(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1413 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1414 | cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n", |
| 1415 | __func__, mid->mid, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1416 | |
| 1417 | /* |
| 1418 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1419 | * can if there's not enough data. At this point, we've read down to |
| 1420 | * the Mid. |
| 1421 | */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1422 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1423 | HEADER_SIZE(server) + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1424 | |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1425 | rdata->iov.iov_base = buf + HEADER_SIZE(server) - 1; |
| 1426 | rdata->iov.iov_len = len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1427 | |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1428 | length = cifs_readv_from_socket(server, &rdata->iov, 1, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1429 | if (length < 0) |
| 1430 | return length; |
| 1431 | server->total_read += length; |
| 1432 | |
| 1433 | /* Was the SMB read successful? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1434 | rdata->result = server->ops->map_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1435 | if (rdata->result != 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1436 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 1437 | __func__, rdata->result); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1438 | return cifs_readv_discard(server, mid); |
| 1439 | } |
| 1440 | |
| 1441 | /* 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] | 1442 | if (server->total_read < server->vals->read_rsp_size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1443 | cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n", |
| 1444 | __func__, server->total_read, |
| 1445 | server->vals->read_rsp_size); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1446 | rdata->result = -EIO; |
| 1447 | return cifs_readv_discard(server, mid); |
| 1448 | } |
| 1449 | |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1450 | data_offset = server->ops->read_data_offset(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1451 | if (data_offset < server->total_read) { |
| 1452 | /* |
| 1453 | * win2k8 sometimes sends an offset of 0 when the read |
| 1454 | * is beyond the EOF. Treat it as if the data starts just after |
| 1455 | * the header. |
| 1456 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1457 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 1458 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1459 | data_offset = server->total_read; |
| 1460 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1461 | /* data_offset is beyond the end of smallbuf */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1462 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 1463 | __func__, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1464 | rdata->result = -EIO; |
| 1465 | return cifs_readv_discard(server, mid); |
| 1466 | } |
| 1467 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1468 | cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n", |
| 1469 | __func__, server->total_read, data_offset); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1470 | |
| 1471 | len = data_offset - server->total_read; |
| 1472 | if (len > 0) { |
| 1473 | /* read any junk before data into the rest of smallbuf */ |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1474 | rdata->iov.iov_base = buf + server->total_read; |
| 1475 | rdata->iov.iov_len = len; |
| 1476 | length = cifs_readv_from_socket(server, &rdata->iov, 1, len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1477 | if (length < 0) |
| 1478 | return length; |
| 1479 | server->total_read += length; |
| 1480 | } |
| 1481 | |
| 1482 | /* set up first iov for signature check */ |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1483 | rdata->iov.iov_base = buf; |
| 1484 | rdata->iov.iov_len = server->total_read; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1485 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 1486 | rdata->iov.iov_base, rdata->iov.iov_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1487 | |
| 1488 | /* how much data is in the response? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1489 | data_len = server->ops->read_data_length(buf); |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1490 | if (data_offset + data_len > buflen) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1491 | /* data_len is corrupt -- discard frame */ |
| 1492 | rdata->result = -EIO; |
| 1493 | return cifs_readv_discard(server, mid); |
| 1494 | } |
| 1495 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1496 | length = rdata->read_into_pages(server, rdata, data_len); |
| 1497 | if (length < 0) |
| 1498 | return length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1499 | |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1500 | server->total_read += length; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1501 | rdata->bytes = length; |
| 1502 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1503 | cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n", |
| 1504 | server->total_read, buflen, data_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1505 | |
| 1506 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1507 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1508 | return cifs_readv_discard(server, mid); |
| 1509 | |
| 1510 | dequeue_mid(mid, false); |
| 1511 | return length; |
| 1512 | } |
| 1513 | |
| 1514 | static void |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1515 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1516 | { |
| 1517 | struct cifs_readdata *rdata = mid->callback_data; |
| 1518 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1519 | struct TCP_Server_Info *server = tcon->ses->server; |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1520 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, |
| 1521 | .rq_nvec = 1, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 1522 | .rq_pages = rdata->pages, |
| 1523 | .rq_npages = rdata->nr_pages, |
| 1524 | .rq_pagesz = rdata->pagesz, |
| 1525 | .rq_tailsz = rdata->tailsz }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1526 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1527 | cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", |
| 1528 | __func__, mid->mid, mid->mid_state, rdata->result, |
| 1529 | rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1530 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1531 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1532 | case MID_RESPONSE_RECEIVED: |
| 1533 | /* result already set, check signature */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 1534 | if (server->sign) { |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1535 | int rc = 0; |
| 1536 | |
Jeff Layton | bf5ea0e | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1537 | rc = cifs_verify_signature(&rqst, server, |
Jeff Layton | 0124cc4 | 2013-04-03 11:55:03 -0400 | [diff] [blame] | 1538 | mid->sequence_number); |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 1539 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1540 | cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
| 1541 | rc); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1542 | } |
| 1543 | /* FIXME: should this be counted toward the initiating task? */ |
| 1544 | task_io_account_read(rdata->bytes); |
| 1545 | cifs_stats_bytes_read(tcon, rdata->bytes); |
| 1546 | break; |
| 1547 | case MID_REQUEST_SUBMITTED: |
| 1548 | case MID_RETRY_NEEDED: |
| 1549 | rdata->result = -EAGAIN; |
| 1550 | break; |
| 1551 | default: |
| 1552 | rdata->result = -EIO; |
| 1553 | } |
| 1554 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1555 | queue_work(cifsiod_wq, &rdata->work); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1556 | DeleteMidQEntry(mid); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1557 | add_credits(server, 1, 0); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1561 | int |
| 1562 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1563 | { |
| 1564 | int rc; |
| 1565 | READ_REQ *smb = NULL; |
| 1566 | int wct; |
| 1567 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1568 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 1569 | .rq_nvec = 1 }; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1570 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1571 | cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n", |
| 1572 | __func__, rdata->offset, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1573 | |
| 1574 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1575 | wct = 12; |
| 1576 | else { |
| 1577 | wct = 10; /* old style read */ |
| 1578 | if ((rdata->offset >> 32) > 0) { |
| 1579 | /* can not handle this big offset for old */ |
| 1580 | return -EIO; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1585 | if (rc) |
| 1586 | return rc; |
| 1587 | |
| 1588 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1589 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1590 | |
| 1591 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1592 | smb->Fid = rdata->cfile->fid.netfid; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1593 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1594 | if (wct == 12) |
| 1595 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1596 | smb->Remaining = 0; |
| 1597 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1598 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1599 | if (wct == 12) |
| 1600 | smb->ByteCount = 0; |
| 1601 | else { |
| 1602 | /* old style read */ |
| 1603 | struct smb_com_readx_req *smbr = |
| 1604 | (struct smb_com_readx_req *)smb; |
| 1605 | smbr->ByteCount = 0; |
| 1606 | } |
| 1607 | |
| 1608 | /* 4 for RFC1001 length + 1 for BCC */ |
Jeff Layton | 5819575 | 2012-09-19 06:22:34 -0700 | [diff] [blame] | 1609 | rdata->iov.iov_base = smb; |
| 1610 | rdata->iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1611 | |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1612 | kref_get(&rdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 1613 | rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, |
| 1614 | cifs_readv_callback, rdata, 0); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1615 | |
| 1616 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1617 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1618 | else |
| 1619 | kref_put(&rdata->refcount, cifs_readdata_release); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1620 | |
| 1621 | cifs_small_buf_release(smb); |
| 1622 | return rc; |
| 1623 | } |
| 1624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1626 | CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms, |
| 1627 | unsigned int *nbytes, char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | { |
| 1629 | int rc = -EACCES; |
| 1630 | READ_REQ *pSMB = NULL; |
| 1631 | READ_RSP *pSMBr = NULL; |
| 1632 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1633 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1634 | int resp_buf_type = 0; |
| 1635 | struct kvec iov[1]; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1636 | __u32 pid = io_parms->pid; |
| 1637 | __u16 netfid = io_parms->netfid; |
| 1638 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1639 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1640 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1642 | cifs_dbg(FYI, "Reading %d bytes on fid %d\n", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1643 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1644 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1645 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1646 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1647 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1648 | /* can not handle this big offset for old */ |
| 1649 | return -EIO; |
| 1650 | } |
| 1651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | |
| 1653 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1654 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | if (rc) |
| 1656 | return rc; |
| 1657 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1658 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1659 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | /* tcon and ses pointer are checked in smb_init */ |
| 1662 | if (tcon->ses->server == NULL) |
| 1663 | return -ECONNABORTED; |
| 1664 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1665 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1667 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1668 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1669 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | pSMB->Remaining = 0; |
| 1672 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1673 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1674 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1675 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1676 | else { |
| 1677 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1678 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1679 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1680 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1681 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1682 | |
| 1683 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1684 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4; |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 1685 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1686 | &resp_buf_type, CIFS_LOG_ERROR); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1687 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1688 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1690 | cifs_dbg(VFS, "Send error in read = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | } else { |
| 1692 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1693 | data_length = data_length << 16; |
| 1694 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1695 | *nbytes = data_length; |
| 1696 | |
| 1697 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1698 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | || (data_length > count)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1700 | cifs_dbg(FYI, "bad length %d for count %d\n", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1701 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | rc = -EIO; |
| 1703 | *nbytes = 0; |
| 1704 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1705 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1706 | le16_to_cpu(pSMBr->DataOffset); |
| 1707 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1708 | cifs_dbg(VFS, "Faulting on read rc = %d\n",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1709 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1710 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1711 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1712 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | } |
| 1714 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1716 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1717 | if (*buf) { |
| 1718 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1719 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1720 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1721 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1722 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1723 | /* return buffer to caller to free */ |
| 1724 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1725 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1726 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1727 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1728 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1729 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1730 | |
| 1731 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | since file handle passed in no longer valid */ |
| 1733 | return rc; |
| 1734 | } |
| 1735 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1738 | CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1739 | unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1740 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | { |
| 1742 | int rc = -EACCES; |
| 1743 | WRITE_REQ *pSMB = NULL; |
| 1744 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1745 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | __u32 bytes_sent; |
| 1747 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1748 | __u32 pid = io_parms->pid; |
| 1749 | __u16 netfid = io_parms->netfid; |
| 1750 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1751 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1752 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1754 | *nbytes = 0; |
| 1755 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1756 | /* cifs_dbg(FYI, "write at %lld %d bytes\n", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1757 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1758 | return -ECONNABORTED; |
| 1759 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1760 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1761 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1762 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1763 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1764 | if ((offset >> 32) > 0) { |
| 1765 | /* can not handle big offset for old srv */ |
| 1766 | return -EIO; |
| 1767 | } |
| 1768 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1769 | |
| 1770 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | (void **) &pSMBr); |
| 1772 | if (rc) |
| 1773 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1774 | |
| 1775 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1776 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | /* tcon and ses pointer are checked in smb_init */ |
| 1779 | if (tcon->ses->server == NULL) |
| 1780 | return -ECONNABORTED; |
| 1781 | |
| 1782 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1783 | pSMB->Fid = netfid; |
| 1784 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1785 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1786 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | pSMB->Reserved = 0xFFFFFFFF; |
| 1789 | pSMB->WriteMode = 0; |
| 1790 | pSMB->Remaining = 0; |
| 1791 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1792 | /* 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] | 1793 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1794 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1795 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1796 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1798 | } else { |
| 1799 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1800 | & ~0xFF; |
| 1801 | } |
| 1802 | |
| 1803 | if (bytes_sent > count) |
| 1804 | bytes_sent = count; |
| 1805 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1806 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1807 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1808 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1809 | else if (ubuf) { |
| 1810 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | cifs_buf_release(pSMB); |
| 1812 | return -EFAULT; |
| 1813 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1814 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | /* No buffer */ |
| 1816 | cifs_buf_release(pSMB); |
| 1817 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1818 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1819 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1820 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1821 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1822 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1825 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1826 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1827 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1828 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1829 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1830 | else { /* old style write has byte count 4 bytes earlier |
| 1831 | so 4 bytes pad */ |
| 1832 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1833 | (struct smb_com_writex_req *)pSMB; |
| 1834 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1835 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
| 1837 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1838 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 1839 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1841 | cifs_dbg(FYI, "Send error in write = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | } else { |
| 1843 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1844 | *nbytes = (*nbytes) << 16; |
| 1845 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1846 | |
| 1847 | /* |
| 1848 | * Mask off high 16 bits when bytes written as returned by the |
| 1849 | * server is greater than bytes requested by the client. Some |
| 1850 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1851 | */ |
| 1852 | if (*nbytes > count) |
| 1853 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | cifs_buf_release(pSMB); |
| 1857 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1858 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | since file handle passed in no longer valid */ |
| 1860 | |
| 1861 | return rc; |
| 1862 | } |
| 1863 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1864 | void |
| 1865 | cifs_writedata_release(struct kref *refcount) |
| 1866 | { |
| 1867 | struct cifs_writedata *wdata = container_of(refcount, |
| 1868 | struct cifs_writedata, refcount); |
| 1869 | |
| 1870 | if (wdata->cfile) |
| 1871 | cifsFileInfo_put(wdata->cfile); |
| 1872 | |
| 1873 | kfree(wdata); |
| 1874 | } |
| 1875 | |
| 1876 | /* |
| 1877 | * Write failed with a retryable error. Resend the write request. It's also |
| 1878 | * possible that the page was redirtied so re-clean the page. |
| 1879 | */ |
| 1880 | static void |
| 1881 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 1882 | { |
| 1883 | int i, rc; |
| 1884 | struct inode *inode = wdata->cfile->dentry->d_inode; |
Pavel Shilovsky | c9de5c8 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1885 | struct TCP_Server_Info *server; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1886 | |
| 1887 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1888 | lock_page(wdata->pages[i]); |
| 1889 | clear_page_dirty_for_io(wdata->pages[i]); |
| 1890 | } |
| 1891 | |
| 1892 | do { |
Pavel Shilovsky | c9de5c8 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1893 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
| 1894 | rc = server->ops->async_writev(wdata); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1895 | } while (rc == -EAGAIN); |
| 1896 | |
| 1897 | for (i = 0; i < wdata->nr_pages; i++) { |
Jeff Layton | 94e1800 | 2013-03-04 15:18:25 -0500 | [diff] [blame] | 1898 | unlock_page(wdata->pages[i]); |
Ouyang Maochun | c51bb0e | 2013-02-18 09:54:52 -0600 | [diff] [blame] | 1899 | if (rc != 0) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1900 | SetPageError(wdata->pages[i]); |
Ouyang Maochun | c51bb0e | 2013-02-18 09:54:52 -0600 | [diff] [blame] | 1901 | end_page_writeback(wdata->pages[i]); |
| 1902 | page_cache_release(wdata->pages[i]); |
| 1903 | } |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | mapping_set_error(inode->i_mapping, rc); |
| 1907 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1908 | } |
| 1909 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 1910 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1911 | cifs_writev_complete(struct work_struct *work) |
| 1912 | { |
| 1913 | struct cifs_writedata *wdata = container_of(work, |
| 1914 | struct cifs_writedata, work); |
| 1915 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1916 | int i = 0; |
| 1917 | |
| 1918 | if (wdata->result == 0) { |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1919 | spin_lock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1920 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1921 | spin_unlock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1922 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 1923 | wdata->bytes); |
| 1924 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 1925 | return cifs_writev_requeue(wdata); |
| 1926 | |
| 1927 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1928 | struct page *page = wdata->pages[i]; |
| 1929 | if (wdata->result == -EAGAIN) |
| 1930 | __set_page_dirty_nobuffers(page); |
| 1931 | else if (wdata->result < 0) |
| 1932 | SetPageError(page); |
| 1933 | end_page_writeback(page); |
| 1934 | page_cache_release(page); |
| 1935 | } |
| 1936 | if (wdata->result != -EAGAIN) |
| 1937 | mapping_set_error(inode->i_mapping, wdata->result); |
| 1938 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1939 | } |
| 1940 | |
| 1941 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 1942 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1943 | { |
| 1944 | struct cifs_writedata *wdata; |
| 1945 | |
| 1946 | /* this would overflow */ |
| 1947 | if (nr_pages == 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1948 | cifs_dbg(VFS, "%s: called with nr_pages == 0!\n", __func__); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1949 | return NULL; |
| 1950 | } |
| 1951 | |
| 1952 | /* writedata + number of page pointers */ |
| 1953 | wdata = kzalloc(sizeof(*wdata) + |
| 1954 | sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); |
| 1955 | if (wdata != NULL) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1956 | kref_init(&wdata->refcount); |
Jeff Layton | da82f7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1957 | INIT_LIST_HEAD(&wdata->list); |
| 1958 | init_completion(&wdata->done); |
| 1959 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1960 | } |
| 1961 | return wdata; |
| 1962 | } |
| 1963 | |
| 1964 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1965 | * 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] | 1966 | * workqueue completion task. |
| 1967 | */ |
| 1968 | static void |
| 1969 | cifs_writev_callback(struct mid_q_entry *mid) |
| 1970 | { |
| 1971 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1972 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1973 | unsigned int written; |
| 1974 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
| 1975 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1976 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1977 | case MID_RESPONSE_RECEIVED: |
| 1978 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 1979 | if (wdata->result != 0) |
| 1980 | break; |
| 1981 | |
| 1982 | written = le16_to_cpu(smb->CountHigh); |
| 1983 | written <<= 16; |
| 1984 | written += le16_to_cpu(smb->Count); |
| 1985 | /* |
| 1986 | * Mask off high 16 bits when bytes written as returned |
| 1987 | * by the server is greater than bytes requested by the |
| 1988 | * client. OS/2 servers are known to set incorrect |
| 1989 | * CountHigh values. |
| 1990 | */ |
| 1991 | if (written > wdata->bytes) |
| 1992 | written &= 0xFFFF; |
| 1993 | |
| 1994 | if (written < wdata->bytes) |
| 1995 | wdata->result = -ENOSPC; |
| 1996 | else |
| 1997 | wdata->bytes = written; |
| 1998 | break; |
| 1999 | case MID_REQUEST_SUBMITTED: |
| 2000 | case MID_RETRY_NEEDED: |
| 2001 | wdata->result = -EAGAIN; |
| 2002 | break; |
| 2003 | default: |
| 2004 | wdata->result = -EIO; |
| 2005 | break; |
| 2006 | } |
| 2007 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2008 | queue_work(cifsiod_wq, &wdata->work); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2009 | DeleteMidQEntry(mid); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2010 | add_credits(tcon->ses->server, 1, 0); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2014 | int |
| 2015 | cifs_async_writev(struct cifs_writedata *wdata) |
| 2016 | { |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2017 | int rc = -EACCES; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2018 | WRITE_REQ *smb = NULL; |
| 2019 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2020 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2021 | struct kvec iov; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2022 | struct smb_rqst rqst = { }; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2023 | |
| 2024 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2025 | wct = 14; |
| 2026 | } else { |
| 2027 | wct = 12; |
| 2028 | if (wdata->offset >> 32 > 0) { |
| 2029 | /* can not handle big offset for old srv */ |
| 2030 | return -EIO; |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2035 | if (rc) |
| 2036 | goto async_writev_out; |
| 2037 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2038 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2039 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2040 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2041 | smb->AndXCommand = 0xFF; /* none */ |
Pavel Shilovsky | 4b4de76 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2042 | smb->Fid = wdata->cfile->fid.netfid; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2043 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2044 | if (wct == 14) |
| 2045 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2046 | smb->Reserved = 0xFFFFFFFF; |
| 2047 | smb->WriteMode = 0; |
| 2048 | smb->Remaining = 0; |
| 2049 | |
| 2050 | smb->DataOffset = |
| 2051 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2052 | |
| 2053 | /* 4 for RFC1001 length + 1 for BCC */ |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2054 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; |
| 2055 | iov.iov_base = smb; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2056 | |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2057 | rqst.rq_iov = &iov; |
| 2058 | rqst.rq_nvec = 1; |
| 2059 | rqst.rq_pages = wdata->pages; |
| 2060 | rqst.rq_npages = wdata->nr_pages; |
| 2061 | rqst.rq_pagesz = wdata->pagesz; |
| 2062 | rqst.rq_tailsz = wdata->tailsz; |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2063 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2064 | cifs_dbg(FYI, "async write at %llu %u bytes\n", |
| 2065 | wdata->offset, wdata->bytes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2066 | |
| 2067 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2068 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2069 | |
| 2070 | if (wct == 14) { |
| 2071 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2072 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2073 | } else { |
| 2074 | /* wct == 12 */ |
| 2075 | struct smb_com_writex_req *smbw = |
| 2076 | (struct smb_com_writex_req *)smb; |
| 2077 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2078 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2079 | iov.iov_len += 4; /* pad bigger by four bytes */ |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | kref_get(&wdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2083 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, |
| 2084 | cifs_writev_callback, wdata, 0); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2085 | |
| 2086 | if (rc == 0) |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2087 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2088 | else |
| 2089 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2090 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2091 | async_writev_out: |
| 2092 | cifs_small_buf_release(smb); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2093 | return rc; |
| 2094 | } |
| 2095 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2096 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2097 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2098 | unsigned int *nbytes, struct kvec *iov, int n_vec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | { |
| 2100 | int rc = -EACCES; |
| 2101 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2102 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2103 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2104 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2105 | __u32 pid = io_parms->pid; |
| 2106 | __u16 netfid = io_parms->netfid; |
| 2107 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2108 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2109 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2111 | *nbytes = 0; |
| 2112 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2113 | 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] | 2114 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2115 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2116 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2117 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2118 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2119 | if ((offset >> 32) > 0) { |
| 2120 | /* can not handle big offset for old srv */ |
| 2121 | return -EIO; |
| 2122 | } |
| 2123 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2124 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | if (rc) |
| 2126 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2127 | |
| 2128 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2129 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | /* tcon and ses pointer are checked in smb_init */ |
| 2132 | if (tcon->ses->server == NULL) |
| 2133 | return -ECONNABORTED; |
| 2134 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2135 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | pSMB->Fid = netfid; |
| 2137 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2138 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2139 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | pSMB->Reserved = 0xFFFFFFFF; |
| 2141 | pSMB->WriteMode = 0; |
| 2142 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2145 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2147 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2148 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2149 | /* header + 1 byte pad */ |
| 2150 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2151 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2152 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2153 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2154 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2155 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2156 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2157 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2158 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2159 | (struct smb_com_writex_req *)pSMB; |
| 2160 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2161 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2162 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2163 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2164 | iov[0].iov_len = smb_hdr_len + 4; |
| 2165 | else /* wct == 12 pad bigger by four bytes */ |
| 2166 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2167 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2168 | |
Pavel Shilovsky | ba9ad725 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2169 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2170 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2172 | cifs_dbg(FYI, "Send error Write2 = %d\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2173 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2174 | /* presumably this can not happen, but best to be safe */ |
| 2175 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2176 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2177 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2178 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2179 | *nbytes = (*nbytes) << 16; |
| 2180 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2181 | |
| 2182 | /* |
| 2183 | * Mask off high 16 bits when bytes written as returned by the |
| 2184 | * server is greater than bytes requested by the client. OS/2 |
| 2185 | * servers are known to set incorrect CountHigh values. |
| 2186 | */ |
| 2187 | if (*nbytes > count) |
| 2188 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 2191 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2192 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2193 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2194 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2195 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2197 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | since file handle passed in no longer valid */ |
| 2199 | |
| 2200 | return rc; |
| 2201 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2202 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2203 | int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon, |
| 2204 | const __u16 netfid, const __u8 lock_type, const __u32 num_unlock, |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2205 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2206 | { |
| 2207 | int rc = 0; |
| 2208 | LOCK_REQ *pSMB = NULL; |
| 2209 | struct kvec iov[2]; |
| 2210 | int resp_buf_type; |
| 2211 | __u16 count; |
| 2212 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2213 | cifs_dbg(FYI, "cifs_lockv num lock %d num unlock %d\n", |
| 2214 | num_lock, num_unlock); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2215 | |
| 2216 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2217 | if (rc) |
| 2218 | return rc; |
| 2219 | |
| 2220 | pSMB->Timeout = 0; |
| 2221 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2222 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2223 | pSMB->LockType = lock_type; |
| 2224 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2225 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2226 | |
| 2227 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2228 | inc_rfc1001_len(pSMB, count); |
| 2229 | pSMB->ByteCount = cpu_to_le16(count); |
| 2230 | |
| 2231 | iov[0].iov_base = (char *)pSMB; |
| 2232 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2233 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2234 | iov[1].iov_base = (char *)buf; |
| 2235 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2236 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2237 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2238 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP); |
| 2239 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2240 | cifs_dbg(FYI, "Send error in cifs_lockv = %d\n", rc); |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2241 | |
| 2242 | return rc; |
| 2243 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2246 | CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2247 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2249 | const __u32 numLock, const __u8 lockType, |
| 2250 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | { |
| 2252 | int rc = 0; |
| 2253 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2254 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | int bytes_returned; |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2256 | int flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | __u16 count; |
| 2258 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2259 | cifs_dbg(FYI, "CIFSSMBLock timeout %d numLock %d\n", |
| 2260 | (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2261 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | if (rc) |
| 2264 | return rc; |
| 2265 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2266 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2267 | /* no response expected */ |
| 2268 | flags = CIFS_ASYNC_OP | CIFS_OBREAK_OP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2270 | } else if (waitFlag) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2271 | flags = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2273 | } else { |
| 2274 | pSMB->Timeout = 0; |
| 2275 | } |
| 2276 | |
| 2277 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2278 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2279 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2280 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2282 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2283 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2284 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2285 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | /* BB where to store pid high? */ |
| 2287 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2288 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2289 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2290 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2291 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2292 | } else { |
| 2293 | /* oplock break */ |
| 2294 | count = 0; |
| 2295 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2296 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | pSMB->ByteCount = cpu_to_le16(count); |
| 2298 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2299 | if (waitFlag) { |
| 2300 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2301 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2302 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2303 | } else { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 2304 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, flags); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2305 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2306 | } |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2307 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2308 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2309 | cifs_dbg(FYI, "Send error in Lock = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2311 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | since file handle passed in no longer valid */ |
| 2313 | return rc; |
| 2314 | } |
| 2315 | |
| 2316 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2317 | CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2318 | const __u16 smb_file_id, const __u32 netpid, |
| 2319 | const loff_t start_offset, const __u64 len, |
| 2320 | struct file_lock *pLockData, const __u16 lock_type, |
| 2321 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2322 | { |
| 2323 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2324 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2325 | struct cifs_posix_lock *parm_data; |
| 2326 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2327 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2328 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2329 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2330 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2331 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2332 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2333 | cifs_dbg(FYI, "Posix Lock\n"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2334 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2335 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2336 | |
| 2337 | if (rc) |
| 2338 | return rc; |
| 2339 | |
| 2340 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2341 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2342 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2343 | pSMB->MaxSetupCount = 0; |
| 2344 | pSMB->Reserved = 0; |
| 2345 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2346 | pSMB->Reserved2 = 0; |
| 2347 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2348 | offset = param_offset + params; |
| 2349 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2350 | count = sizeof(struct cifs_posix_lock); |
| 2351 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2352 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2353 | pSMB->SetupCount = 1; |
| 2354 | pSMB->Reserved3 = 0; |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2355 | if (pLockData) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2356 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2357 | else |
| 2358 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2359 | byte_count = 3 /* pad */ + params + count; |
| 2360 | pSMB->DataCount = cpu_to_le16(count); |
| 2361 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2362 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2363 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2364 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2365 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2366 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2367 | |
| 2368 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2369 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2370 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2371 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2372 | pSMB->Timeout = cpu_to_le32(-1); |
| 2373 | } else |
| 2374 | pSMB->Timeout = 0; |
| 2375 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2376 | parm_data->pid = cpu_to_le32(netpid); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2377 | parm_data->start = cpu_to_le64(start_offset); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2378 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2379 | |
| 2380 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2381 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2382 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2383 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2384 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2385 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2386 | if (waitFlag) { |
| 2387 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2388 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2389 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2390 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2391 | 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] | 2392 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 2393 | &resp_buf_type, timeout); |
| 2394 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 2395 | not try to free it twice below on exit */ |
| 2396 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2399 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2400 | cifs_dbg(FYI, "Send error in Posix Lock = %d\n", rc); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame] | 2401 | } else if (pLockData) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2402 | /* lock structure can be returned on get */ |
| 2403 | __u16 data_offset; |
| 2404 | __u16 data_count; |
| 2405 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2406 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2407 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2408 | rc = -EIO; /* bad smb */ |
| 2409 | goto plk_err_exit; |
| 2410 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2411 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2412 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2413 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2414 | rc = -EIO; |
| 2415 | goto plk_err_exit; |
| 2416 | } |
| 2417 | parm_data = (struct cifs_posix_lock *) |
| 2418 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2419 | if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2420 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2421 | else { |
| 2422 | if (parm_data->lock_type == |
| 2423 | __constant_cpu_to_le16(CIFS_RDLCK)) |
| 2424 | pLockData->fl_type = F_RDLCK; |
| 2425 | else if (parm_data->lock_type == |
| 2426 | __constant_cpu_to_le16(CIFS_WRLCK)) |
| 2427 | pLockData->fl_type = F_WRLCK; |
| 2428 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2429 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2430 | pLockData->fl_end = pLockData->fl_start + |
| 2431 | le64_to_cpu(parm_data->length) - 1; |
| 2432 | pLockData->fl_pid = le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2433 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2434 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2435 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2436 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2437 | if (pSMB) |
| 2438 | cifs_small_buf_release(pSMB); |
| 2439 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2440 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 2441 | cifs_small_buf_release(iov[0].iov_base); |
| 2442 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 2443 | cifs_buf_release(iov[0].iov_base); |
| 2444 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2445 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2446 | since file handle passed in no longer valid */ |
| 2447 | |
| 2448 | return rc; |
| 2449 | } |
| 2450 | |
| 2451 | |
| 2452 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2453 | 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] | 2454 | { |
| 2455 | int rc = 0; |
| 2456 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2457 | cifs_dbg(FYI, "In CIFSSMBClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | |
| 2459 | /* do not retry on dead session on close */ |
| 2460 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2461 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | return 0; |
| 2463 | if (rc) |
| 2464 | return rc; |
| 2465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2467 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2469 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2470 | cifs_stats_inc(&tcon->stats.cifs_stats.num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2472 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2474 | cifs_dbg(VFS, "Send error in Close = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | } |
| 2476 | } |
| 2477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2479 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | rc = 0; |
| 2481 | |
| 2482 | return rc; |
| 2483 | } |
| 2484 | |
| 2485 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2486 | 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] | 2487 | { |
| 2488 | int rc = 0; |
| 2489 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2490 | cifs_dbg(FYI, "In CIFSSMBFlush\n"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2491 | |
| 2492 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2493 | if (rc) |
| 2494 | return rc; |
| 2495 | |
| 2496 | pSMB->FileID = (__u16) smb_file_id; |
| 2497 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2498 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2499 | cifs_stats_inc(&tcon->stats.cifs_stats.num_flushes); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2500 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2501 | cifs_dbg(VFS, "Send error in Flush = %d\n", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2502 | |
| 2503 | return rc; |
| 2504 | } |
| 2505 | |
| 2506 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2507 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2508 | const char *from_name, const char *to_name, |
| 2509 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | { |
| 2511 | int rc = 0; |
| 2512 | RENAME_REQ *pSMB = NULL; |
| 2513 | RENAME_RSP *pSMBr = NULL; |
| 2514 | int bytes_returned; |
| 2515 | int name_len, name_len2; |
| 2516 | __u16 count; |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2517 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2519 | cifs_dbg(FYI, "In CIFSSMBRename\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | renameRetry: |
| 2521 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2522 | (void **) &pSMBr); |
| 2523 | if (rc) |
| 2524 | return rc; |
| 2525 | |
| 2526 | pSMB->BufferFormat = 0x04; |
| 2527 | pSMB->SearchAttributes = |
| 2528 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2529 | ATTR_DIRECTORY); |
| 2530 | |
| 2531 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2532 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2533 | from_name, PATH_MAX, |
| 2534 | cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | name_len++; /* trailing null */ |
| 2536 | name_len *= 2; |
| 2537 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2538 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2539 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2540 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2541 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2542 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 2543 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2545 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2546 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2547 | name_len = strnlen(from_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | name_len++; /* trailing null */ |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2549 | strncpy(pSMB->OldFileName, from_name, name_len); |
| 2550 | name_len2 = strnlen(to_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | name_len2++; /* trailing null */ |
| 2552 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Pavel Shilovsky | 8ceb984 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2553 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | name_len2++; /* trailing null */ |
| 2555 | name_len2++; /* signature byte */ |
| 2556 | } |
| 2557 | |
| 2558 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2559 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | pSMB->ByteCount = cpu_to_le16(count); |
| 2561 | |
| 2562 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2563 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2564 | cifs_stats_inc(&tcon->stats.cifs_stats.num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2565 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2566 | cifs_dbg(FYI, "Send error in rename = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | cifs_buf_release(pSMB); |
| 2569 | |
| 2570 | if (rc == -EAGAIN) |
| 2571 | goto renameRetry; |
| 2572 | |
| 2573 | return rc; |
| 2574 | } |
| 2575 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2576 | int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2577 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2578 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | { |
| 2580 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2581 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2582 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | char *data_offset; |
| 2584 | char dummy_string[30]; |
| 2585 | int rc = 0; |
| 2586 | int bytes_returned = 0; |
| 2587 | int len_of_str; |
| 2588 | __u16 params, param_offset, offset, count, byte_count; |
| 2589 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2590 | cifs_dbg(FYI, "Rename to File by handle\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2592 | (void **) &pSMBr); |
| 2593 | if (rc) |
| 2594 | return rc; |
| 2595 | |
| 2596 | params = 6; |
| 2597 | pSMB->MaxSetupCount = 0; |
| 2598 | pSMB->Reserved = 0; |
| 2599 | pSMB->Flags = 0; |
| 2600 | pSMB->Timeout = 0; |
| 2601 | pSMB->Reserved2 = 0; |
| 2602 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2603 | offset = param_offset + params; |
| 2604 | |
| 2605 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2606 | rename_info = (struct set_file_rename *) data_offset; |
| 2607 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2608 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | pSMB->SetupCount = 1; |
| 2610 | pSMB->Reserved3 = 0; |
| 2611 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2612 | byte_count = 3 /* pad */ + params; |
| 2613 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2614 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2615 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2616 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2617 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2618 | rename_info->overwrite = cpu_to_le32(1); |
| 2619 | rename_info->root_fid = 0; |
| 2620 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2621 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2622 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2623 | len_of_str = |
| 2624 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2625 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2627 | len_of_str = |
| 2628 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2629 | target_name, PATH_MAX, nls_codepage, |
| 2630 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | } |
| 2632 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2633 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | byte_count += count; |
| 2635 | pSMB->DataCount = cpu_to_le16(count); |
| 2636 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2637 | pSMB->Fid = netfid; |
| 2638 | pSMB->InformationLevel = |
| 2639 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2640 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2641 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2643 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2644 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2645 | cifs_stats_inc(&pTcon->stats.cifs_stats.num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2646 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2647 | cifs_dbg(FYI, "Send error in Rename (by file handle) = %d\n", |
| 2648 | rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | cifs_buf_release(pSMB); |
| 2651 | |
| 2652 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2653 | since file handle passed in no longer valid */ |
| 2654 | |
| 2655 | return rc; |
| 2656 | } |
| 2657 | |
| 2658 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2659 | CIFSSMBCopy(const unsigned int xid, struct cifs_tcon *tcon, |
| 2660 | const char *fromName, const __u16 target_tid, const char *toName, |
| 2661 | const int flags, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | { |
| 2663 | int rc = 0; |
| 2664 | COPY_REQ *pSMB = NULL; |
| 2665 | COPY_RSP *pSMBr = NULL; |
| 2666 | int bytes_returned; |
| 2667 | int name_len, name_len2; |
| 2668 | __u16 count; |
| 2669 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2670 | cifs_dbg(FYI, "In CIFSSMBCopy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | copyRetry: |
| 2672 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2673 | (void **) &pSMBr); |
| 2674 | if (rc) |
| 2675 | return rc; |
| 2676 | |
| 2677 | pSMB->BufferFormat = 0x04; |
| 2678 | pSMB->Tid2 = target_tid; |
| 2679 | |
| 2680 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2681 | |
| 2682 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2683 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2684 | fromName, PATH_MAX, nls_codepage, |
| 2685 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | name_len++; /* trailing null */ |
| 2687 | name_len *= 2; |
| 2688 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2689 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2690 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2691 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2692 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2693 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2695 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2696 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | name_len = strnlen(fromName, PATH_MAX); |
| 2698 | name_len++; /* trailing null */ |
| 2699 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2700 | name_len2 = strnlen(toName, PATH_MAX); |
| 2701 | name_len2++; /* trailing null */ |
| 2702 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2703 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2704 | name_len2++; /* trailing null */ |
| 2705 | name_len2++; /* signature byte */ |
| 2706 | } |
| 2707 | |
| 2708 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2709 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | pSMB->ByteCount = cpu_to_le16(count); |
| 2711 | |
| 2712 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2713 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2714 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2715 | cifs_dbg(FYI, "Send error in copy = %d with %d files copied\n", |
| 2716 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2718 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | |
| 2720 | if (rc == -EAGAIN) |
| 2721 | goto copyRetry; |
| 2722 | |
| 2723 | return rc; |
| 2724 | } |
| 2725 | |
| 2726 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2727 | CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | const char *fromName, const char *toName, |
| 2729 | const struct nls_table *nls_codepage) |
| 2730 | { |
| 2731 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2732 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2733 | char *data_offset; |
| 2734 | int name_len; |
| 2735 | int name_len_target; |
| 2736 | int rc = 0; |
| 2737 | int bytes_returned = 0; |
| 2738 | __u16 params, param_offset, offset, byte_count; |
| 2739 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2740 | cifs_dbg(FYI, "In Symlink Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | createSymLinkRetry: |
| 2742 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2743 | (void **) &pSMBr); |
| 2744 | if (rc) |
| 2745 | return rc; |
| 2746 | |
| 2747 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2748 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2749 | cifs_strtoUTF16((__le16 *) pSMB->FileName, fromName, |
| 2750 | /* find define for this maxpathcomponent */ |
| 2751 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | name_len++; /* trailing null */ |
| 2753 | name_len *= 2; |
| 2754 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2755 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | name_len = strnlen(fromName, PATH_MAX); |
| 2757 | name_len++; /* trailing null */ |
| 2758 | strncpy(pSMB->FileName, fromName, name_len); |
| 2759 | } |
| 2760 | params = 6 + name_len; |
| 2761 | pSMB->MaxSetupCount = 0; |
| 2762 | pSMB->Reserved = 0; |
| 2763 | pSMB->Flags = 0; |
| 2764 | pSMB->Timeout = 0; |
| 2765 | pSMB->Reserved2 = 0; |
| 2766 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2767 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | offset = param_offset + params; |
| 2769 | |
| 2770 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2771 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2772 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2773 | cifs_strtoUTF16((__le16 *) data_offset, toName, PATH_MAX |
| 2774 | /* find define for this maxpathcomponent */ |
| 2775 | , nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | name_len_target++; /* trailing null */ |
| 2777 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2778 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | name_len_target = strnlen(toName, PATH_MAX); |
| 2780 | name_len_target++; /* trailing null */ |
| 2781 | strncpy(data_offset, toName, name_len_target); |
| 2782 | } |
| 2783 | |
| 2784 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2785 | /* BB find exact max on data count below from sess */ |
| 2786 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2787 | pSMB->SetupCount = 1; |
| 2788 | pSMB->Reserved3 = 0; |
| 2789 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2790 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2791 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2792 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2793 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2794 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2795 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2796 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2797 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2798 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2799 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2801 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2802 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2803 | cifs_stats_inc(&tcon->stats.cifs_stats.num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2804 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2805 | cifs_dbg(FYI, "Send error in SetPathInfo create symlink = %d\n", |
| 2806 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2808 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | |
| 2810 | if (rc == -EAGAIN) |
| 2811 | goto createSymLinkRetry; |
| 2812 | |
| 2813 | return rc; |
| 2814 | } |
| 2815 | |
| 2816 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2817 | CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2819 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | { |
| 2821 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2822 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2823 | char *data_offset; |
| 2824 | int name_len; |
| 2825 | int name_len_target; |
| 2826 | int rc = 0; |
| 2827 | int bytes_returned = 0; |
| 2828 | __u16 params, param_offset, offset, byte_count; |
| 2829 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2830 | cifs_dbg(FYI, "In Create Hard link Unix style\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | createHardLinkRetry: |
| 2832 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2833 | (void **) &pSMBr); |
| 2834 | if (rc) |
| 2835 | return rc; |
| 2836 | |
| 2837 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2838 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 2839 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | name_len++; /* trailing null */ |
| 2841 | name_len *= 2; |
| 2842 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2843 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | name_len = strnlen(toName, PATH_MAX); |
| 2845 | name_len++; /* trailing null */ |
| 2846 | strncpy(pSMB->FileName, toName, name_len); |
| 2847 | } |
| 2848 | params = 6 + name_len; |
| 2849 | pSMB->MaxSetupCount = 0; |
| 2850 | pSMB->Reserved = 0; |
| 2851 | pSMB->Flags = 0; |
| 2852 | pSMB->Timeout = 0; |
| 2853 | pSMB->Reserved2 = 0; |
| 2854 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2855 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | offset = param_offset + params; |
| 2857 | |
| 2858 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2859 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2860 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2861 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 2862 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | name_len_target++; /* trailing null */ |
| 2864 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2865 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2867 | name_len_target++; /* trailing null */ |
| 2868 | strncpy(data_offset, fromName, name_len_target); |
| 2869 | } |
| 2870 | |
| 2871 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2872 | /* BB find exact max on data count below from sess*/ |
| 2873 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2874 | pSMB->SetupCount = 1; |
| 2875 | pSMB->Reserved3 = 0; |
| 2876 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2877 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2878 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2879 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2880 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2881 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2882 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2883 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2884 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2885 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2886 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2888 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2889 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2890 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2891 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2892 | cifs_dbg(FYI, "Send error in SetPathInfo (hard link) = %d\n", |
| 2893 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | |
| 2895 | cifs_buf_release(pSMB); |
| 2896 | if (rc == -EAGAIN) |
| 2897 | goto createHardLinkRetry; |
| 2898 | |
| 2899 | return rc; |
| 2900 | } |
| 2901 | |
| 2902 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2903 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2904 | const char *from_name, const char *to_name, |
| 2905 | struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | { |
| 2907 | int rc = 0; |
| 2908 | NT_RENAME_REQ *pSMB = NULL; |
| 2909 | RENAME_RSP *pSMBr = NULL; |
| 2910 | int bytes_returned; |
| 2911 | int name_len, name_len2; |
| 2912 | __u16 count; |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2913 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2915 | cifs_dbg(FYI, "In CIFSCreateHardLink\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | winCreateHardLinkRetry: |
| 2917 | |
| 2918 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2919 | (void **) &pSMBr); |
| 2920 | if (rc) |
| 2921 | return rc; |
| 2922 | |
| 2923 | pSMB->SearchAttributes = |
| 2924 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2925 | ATTR_DIRECTORY); |
| 2926 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 2927 | pSMB->ClusterCount = 0; |
| 2928 | |
| 2929 | pSMB->BufferFormat = 0x04; |
| 2930 | |
| 2931 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2932 | name_len = |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2933 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, from_name, |
| 2934 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | name_len++; /* trailing null */ |
| 2936 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 2937 | |
| 2938 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 2939 | pSMB->OldFileName[name_len] = 0x04; |
| 2940 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2942 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2943 | to_name, PATH_MAX, cifs_sb->local_nls, |
| 2944 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2946 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2947 | } else { /* BB improve the check for buffer overruns BB */ |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2948 | name_len = strnlen(from_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | name_len++; /* trailing null */ |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2950 | strncpy(pSMB->OldFileName, from_name, name_len); |
| 2951 | name_len2 = strnlen(to_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | name_len2++; /* trailing null */ |
| 2953 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
Steve French | d6e906f | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2954 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | name_len2++; /* trailing null */ |
| 2956 | name_len2++; /* signature byte */ |
| 2957 | } |
| 2958 | |
| 2959 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2960 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | pSMB->ByteCount = cpu_to_le16(count); |
| 2962 | |
| 2963 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2964 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 2965 | cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2966 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2967 | 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] | 2968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | cifs_buf_release(pSMB); |
| 2970 | if (rc == -EAGAIN) |
| 2971 | goto winCreateHardLinkRetry; |
| 2972 | |
| 2973 | return rc; |
| 2974 | } |
| 2975 | |
| 2976 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2977 | CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2978 | const unsigned char *searchName, char **symlinkinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | const struct nls_table *nls_codepage) |
| 2980 | { |
| 2981 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 2982 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2983 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2984 | int rc = 0; |
| 2985 | int bytes_returned; |
| 2986 | int name_len; |
| 2987 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2988 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2990 | cifs_dbg(FYI, "In QPathSymLinkInfo (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | |
| 2992 | querySymLinkRetry: |
| 2993 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2994 | (void **) &pSMBr); |
| 2995 | if (rc) |
| 2996 | return rc; |
| 2997 | |
| 2998 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2999 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3000 | cifs_strtoUTF16((__le16 *) pSMB->FileName, searchName, |
| 3001 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | name_len++; /* trailing null */ |
| 3003 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3004 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | name_len = strnlen(searchName, PATH_MAX); |
| 3006 | name_len++; /* trailing null */ |
| 3007 | strncpy(pSMB->FileName, searchName, name_len); |
| 3008 | } |
| 3009 | |
| 3010 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3011 | pSMB->TotalDataCount = 0; |
| 3012 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3013 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | pSMB->MaxSetupCount = 0; |
| 3015 | pSMB->Reserved = 0; |
| 3016 | pSMB->Flags = 0; |
| 3017 | pSMB->Timeout = 0; |
| 3018 | pSMB->Reserved2 = 0; |
| 3019 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3020 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | pSMB->DataCount = 0; |
| 3022 | pSMB->DataOffset = 0; |
| 3023 | pSMB->SetupCount = 1; |
| 3024 | pSMB->Reserved3 = 0; |
| 3025 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3026 | byte_count = params + 1 /* pad */ ; |
| 3027 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3028 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3029 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3030 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3031 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3033 | |
| 3034 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3035 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3036 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3037 | cifs_dbg(FYI, "Send error in QuerySymLinkInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | } else { |
| 3039 | /* decode response */ |
| 3040 | |
| 3041 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3043 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3044 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3046 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3047 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3049 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3050 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3051 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3052 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3053 | is_unicode = true; |
| 3054 | else |
| 3055 | is_unicode = false; |
| 3056 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3057 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3058 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3059 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3060 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3061 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | cifs_buf_release(pSMB); |
| 3065 | if (rc == -EAGAIN) |
| 3066 | goto querySymLinkRetry; |
| 3067 | return rc; |
| 3068 | } |
| 3069 | |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3070 | #ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL |
| 3071 | /* |
| 3072 | * Recent Windows versions now create symlinks more frequently |
| 3073 | * and they use the "reparse point" mechanism below. We can of course |
| 3074 | * do symlinks nicely to Samba and other servers which support the |
| 3075 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3076 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3077 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3078 | * In the interim this code has been moved to its own config option so |
| 3079 | * it is not compiled in by default until callers fixed up and more tested. |
| 3080 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3082 | CIFSSMBQueryReparseLinkInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3084 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | const struct nls_table *nls_codepage) |
| 3086 | { |
| 3087 | int rc = 0; |
| 3088 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3089 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3090 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3092 | cifs_dbg(FYI, "In Windows reparse style QueryLink for path %s\n", |
| 3093 | searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3095 | (void **) &pSMBr); |
| 3096 | if (rc) |
| 3097 | return rc; |
| 3098 | |
| 3099 | pSMB->TotalParameterCount = 0 ; |
| 3100 | pSMB->TotalDataCount = 0; |
| 3101 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3102 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3103 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | pSMB->MaxSetupCount = 4; |
| 3105 | pSMB->Reserved = 0; |
| 3106 | pSMB->ParameterOffset = 0; |
| 3107 | pSMB->DataCount = 0; |
| 3108 | pSMB->DataOffset = 0; |
| 3109 | pSMB->SetupCount = 4; |
| 3110 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3111 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3112 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3113 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3114 | pSMB->IsRootFlag = 0; |
| 3115 | pSMB->Fid = fid; /* file handle always le */ |
| 3116 | pSMB->ByteCount = 0; |
| 3117 | |
| 3118 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3119 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3120 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3121 | cifs_dbg(FYI, "Send error in QueryReparseLinkInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | } else { /* decode response */ |
| 3123 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3124 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3125 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3126 | /* BB also check enough total bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | rc = -EIO; /* bad smb */ |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3128 | goto qreparse_out; |
| 3129 | } |
| 3130 | if (data_count && (data_count < 2048)) { |
| 3131 | char *end_of_smb = 2 /* sizeof byte count */ + |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3132 | get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3134 | struct reparse_data *reparse_buf = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3135 | (struct reparse_data *) |
| 3136 | ((char *)&pSMBr->hdr.Protocol |
| 3137 | + data_offset); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3138 | if ((char *)reparse_buf >= end_of_smb) { |
| 3139 | rc = -EIO; |
| 3140 | goto qreparse_out; |
| 3141 | } |
| 3142 | if ((reparse_buf->LinkNamesBuf + |
| 3143 | reparse_buf->TargetNameOffset + |
| 3144 | reparse_buf->TargetNameLen) > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3145 | cifs_dbg(FYI, "reparse buf beyond SMB\n"); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3146 | rc = -EIO; |
| 3147 | goto qreparse_out; |
| 3148 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3149 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3150 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3151 | cifs_from_ucs2(symlinkinfo, (__le16 *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3152 | (reparse_buf->LinkNamesBuf + |
| 3153 | reparse_buf->TargetNameOffset), |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3154 | buflen, |
| 3155 | reparse_buf->TargetNameLen, |
| 3156 | nls_codepage, 0); |
| 3157 | } else { /* ASCII names */ |
| 3158 | strncpy(symlinkinfo, |
| 3159 | reparse_buf->LinkNamesBuf + |
| 3160 | reparse_buf->TargetNameOffset, |
| 3161 | min_t(const int, buflen, |
| 3162 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3164 | } else { |
| 3165 | rc = -EIO; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3166 | cifs_dbg(FYI, "Invalid return data count on get reparse info ioctl\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3168 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 3169 | does not go off the end of the buffer */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3170 | cifs_dbg(FYI, "readlink result - %s\n", symlinkinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3174 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | |
| 3176 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 3177 | since file handle passed in no longer valid */ |
| 3178 | |
| 3179 | return rc; |
| 3180 | } |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3181 | #endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | |
| 3183 | #ifdef CONFIG_CIFS_POSIX |
| 3184 | |
| 3185 | /*Convert an Access Control Entry from wire format to local POSIX xattr format*/ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3186 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 3187 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | { |
| 3189 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3190 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3191 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3192 | 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] | 3193 | /* |
| 3194 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3195 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3196 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | |
| 3198 | return; |
| 3199 | } |
| 3200 | |
| 3201 | /* 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] | 3202 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3203 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | { |
| 3205 | int size = 0; |
| 3206 | int i; |
| 3207 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3208 | struct cifs_posix_ace *pACE; |
| 3209 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 3210 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | |
| 3212 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3213 | return -EOPNOTSUPP; |
| 3214 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3215 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3217 | pACE = &cifs_acl->ace_array[0]; |
| 3218 | size = sizeof(struct cifs_posix_acl); |
| 3219 | size += sizeof(struct cifs_posix_ace) * count; |
| 3220 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3221 | if (size_of_data_area < size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3222 | cifs_dbg(FYI, "bad CIFS POSIX ACL size %d vs. %d\n", |
| 3223 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | return -EINVAL; |
| 3225 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3226 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3228 | size = sizeof(struct cifs_posix_acl); |
| 3229 | size += sizeof(struct cifs_posix_ace) * count; |
| 3230 | /* skip past access ACEs to get to default ACEs */ |
| 3231 | pACE = &cifs_acl->ace_array[count]; |
| 3232 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3233 | size += sizeof(struct cifs_posix_ace) * count; |
| 3234 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3235 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | return -EINVAL; |
| 3237 | } else { |
| 3238 | /* illegal type */ |
| 3239 | return -EINVAL; |
| 3240 | } |
| 3241 | |
| 3242 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3243 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3244 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3245 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | return -ERANGE; |
| 3247 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3248 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3249 | for (i = 0; i < count ; i++) { |
| 3250 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 3251 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | } |
| 3253 | } |
| 3254 | return size; |
| 3255 | } |
| 3256 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3257 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 3258 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | { |
| 3260 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 3261 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3262 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3263 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3265 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3267 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3268 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3269 | 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] | 3270 | /* |
| 3271 | cifs_dbg(FYI, "perm %d tag %d id %d\n", |
| 3272 | ace->e_perm, ace->e_tag, ace->e_id); |
| 3273 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | return rc; |
| 3275 | } |
| 3276 | |
| 3277 | /* 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] | 3278 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3279 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | { |
| 3281 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3282 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 3283 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | int count; |
| 3285 | int i; |
| 3286 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3287 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | return 0; |
| 3289 | |
| 3290 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3291 | cifs_dbg(FYI, "setting acl with %d entries from buf of length %d and version of %d\n", |
| 3292 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3293 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3294 | cifs_dbg(FYI, "unknown POSIX ACL version %d\n", |
| 3295 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | return 0; |
| 3297 | } |
| 3298 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3299 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3300 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3301 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3302 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | else { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3304 | cifs_dbg(FYI, "unknown ACL type %d\n", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | return 0; |
| 3306 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3307 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 3309 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3310 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | /* ACE not converted */ |
| 3312 | break; |
| 3313 | } |
| 3314 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3315 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3317 | rc += sizeof(struct cifs_posix_acl); |
| 3318 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3319 | } |
| 3320 | return rc; |
| 3321 | } |
| 3322 | |
| 3323 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3324 | CIFSSMBGetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3325 | const unsigned char *searchName, |
| 3326 | char *acl_inf, const int buflen, const int acl_type, |
| 3327 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | { |
| 3329 | /* SMB_QUERY_POSIX_ACL */ |
| 3330 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3331 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3332 | int rc = 0; |
| 3333 | int bytes_returned; |
| 3334 | int name_len; |
| 3335 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3336 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3337 | cifs_dbg(FYI, "In GetPosixACL (Unix) for path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | |
| 3339 | queryAclRetry: |
| 3340 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3341 | (void **) &pSMBr); |
| 3342 | if (rc) |
| 3343 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3346 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3347 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3348 | searchName, PATH_MAX, nls_codepage, |
| 3349 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | name_len++; /* trailing null */ |
| 3351 | name_len *= 2; |
| 3352 | pSMB->FileName[name_len] = 0; |
| 3353 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3354 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | name_len = strnlen(searchName, PATH_MAX); |
| 3356 | name_len++; /* trailing null */ |
| 3357 | strncpy(pSMB->FileName, searchName, name_len); |
| 3358 | } |
| 3359 | |
| 3360 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3361 | pSMB->TotalDataCount = 0; |
| 3362 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3363 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3365 | pSMB->MaxSetupCount = 0; |
| 3366 | pSMB->Reserved = 0; |
| 3367 | pSMB->Flags = 0; |
| 3368 | pSMB->Timeout = 0; |
| 3369 | pSMB->Reserved2 = 0; |
| 3370 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3371 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3372 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | pSMB->DataCount = 0; |
| 3374 | pSMB->DataOffset = 0; |
| 3375 | pSMB->SetupCount = 1; |
| 3376 | pSMB->Reserved3 = 0; |
| 3377 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3378 | byte_count = params + 1 /* pad */ ; |
| 3379 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3380 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3381 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3382 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3383 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3385 | |
| 3386 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3387 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3388 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3390 | cifs_dbg(FYI, "Send error in Query POSIX ACL = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | } else { |
| 3392 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3396 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | rc = -EIO; /* bad smb */ |
| 3398 | else { |
| 3399 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3400 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3401 | rc = cifs_copy_posix_acl(acl_inf, |
| 3402 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3403 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | } |
| 3405 | } |
| 3406 | cifs_buf_release(pSMB); |
| 3407 | if (rc == -EAGAIN) |
| 3408 | goto queryAclRetry; |
| 3409 | return rc; |
| 3410 | } |
| 3411 | |
| 3412 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3413 | CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3414 | const unsigned char *fileName, |
| 3415 | const char *local_acl, const int buflen, |
| 3416 | const int acl_type, |
| 3417 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | { |
| 3419 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3420 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3421 | char *parm_data; |
| 3422 | int name_len; |
| 3423 | int rc = 0; |
| 3424 | int bytes_returned = 0; |
| 3425 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3426 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3427 | cifs_dbg(FYI, "In SetPosixACL (Unix) for path %s\n", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | setAclRetry: |
| 3429 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3430 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | if (rc) |
| 3432 | return rc; |
| 3433 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3434 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3435 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3436 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | name_len++; /* trailing null */ |
| 3438 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3439 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | name_len = strnlen(fileName, PATH_MAX); |
| 3441 | name_len++; /* trailing null */ |
| 3442 | strncpy(pSMB->FileName, fileName, name_len); |
| 3443 | } |
| 3444 | params = 6 + name_len; |
| 3445 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3446 | /* BB find max SMB size from sess */ |
| 3447 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | pSMB->MaxSetupCount = 0; |
| 3449 | pSMB->Reserved = 0; |
| 3450 | pSMB->Flags = 0; |
| 3451 | pSMB->Timeout = 0; |
| 3452 | pSMB->Reserved2 = 0; |
| 3453 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3454 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | offset = param_offset + params; |
| 3456 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3457 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3458 | |
| 3459 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3460 | 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] | 3461 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3462 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | rc = -EOPNOTSUPP; |
| 3464 | goto setACLerrorExit; |
| 3465 | } |
| 3466 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3467 | pSMB->SetupCount = 1; |
| 3468 | pSMB->Reserved3 = 0; |
| 3469 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3470 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3471 | byte_count = 3 /* pad */ + params + data_count; |
| 3472 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3473 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3474 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3475 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3476 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3477 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3479 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3480 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3481 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3482 | cifs_dbg(FYI, "Set POSIX ACL returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | |
| 3484 | setACLerrorExit: |
| 3485 | cifs_buf_release(pSMB); |
| 3486 | if (rc == -EAGAIN) |
| 3487 | goto setAclRetry; |
| 3488 | return rc; |
| 3489 | } |
| 3490 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3491 | /* BB fix tabs in this function FIXME BB */ |
| 3492 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3493 | CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3494 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3495 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3496 | int rc = 0; |
| 3497 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3498 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3499 | int bytes_returned; |
| 3500 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3501 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3502 | cifs_dbg(FYI, "In GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3503 | if (tcon == NULL) |
| 3504 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3505 | |
| 3506 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3507 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3508 | (void **) &pSMBr); |
| 3509 | if (rc) |
| 3510 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3511 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3512 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3513 | pSMB->t2.TotalDataCount = 0; |
| 3514 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3515 | /* BB find exact max data count below from sess structure BB */ |
| 3516 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3517 | pSMB->t2.MaxSetupCount = 0; |
| 3518 | pSMB->t2.Reserved = 0; |
| 3519 | pSMB->t2.Flags = 0; |
| 3520 | pSMB->t2.Timeout = 0; |
| 3521 | pSMB->t2.Reserved2 = 0; |
| 3522 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3523 | Fid) - 4); |
| 3524 | pSMB->t2.DataCount = 0; |
| 3525 | pSMB->t2.DataOffset = 0; |
| 3526 | pSMB->t2.SetupCount = 1; |
| 3527 | pSMB->t2.Reserved3 = 0; |
| 3528 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3529 | byte_count = params + 1 /* pad */ ; |
| 3530 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3531 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3532 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3533 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3534 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3535 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3536 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3537 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3538 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3539 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3540 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3541 | cifs_dbg(FYI, "error %d in GetExtAttr\n", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3542 | } else { |
| 3543 | /* decode response */ |
| 3544 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3545 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3546 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3547 | /* If rc should we check for EOPNOSUPP and |
| 3548 | disable the srvino flag? or in caller? */ |
| 3549 | rc = -EIO; /* bad smb */ |
| 3550 | else { |
| 3551 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3552 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3553 | struct file_chattr_info *pfinfo; |
| 3554 | /* BB Do we need a cast or hash here ? */ |
| 3555 | if (count != 16) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3556 | cifs_dbg(FYI, "Illegal size ret in GetExtAttr\n"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3557 | rc = -EIO; |
| 3558 | goto GetExtAttrOut; |
| 3559 | } |
| 3560 | pfinfo = (struct file_chattr_info *) |
| 3561 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3562 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3563 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3564 | } |
| 3565 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3566 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3567 | cifs_buf_release(pSMB); |
| 3568 | if (rc == -EAGAIN) |
| 3569 | goto GetExtAttrRetry; |
| 3570 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3573 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3575 | #ifdef CONFIG_CIFS_ACL |
| 3576 | /* |
| 3577 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3578 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3579 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3580 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3581 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3582 | * by caller |
| 3583 | */ |
| 3584 | static int |
| 3585 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3586 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3587 | void **ret_buf) |
| 3588 | { |
| 3589 | int rc; |
| 3590 | __u32 temp_offset; |
| 3591 | struct smb_com_ntransact_req *pSMB; |
| 3592 | |
| 3593 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3594 | (void **)&pSMB); |
| 3595 | if (rc) |
| 3596 | return rc; |
| 3597 | *ret_buf = (void *)pSMB; |
| 3598 | pSMB->Reserved = 0; |
| 3599 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3600 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3601 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3602 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3603 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3604 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3605 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3606 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3607 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3608 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3609 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3610 | return 0; |
| 3611 | } |
| 3612 | |
| 3613 | static int |
| 3614 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3615 | __u32 *pparmlen, __u32 *pdatalen) |
| 3616 | { |
| 3617 | char *end_of_smb; |
| 3618 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3619 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3620 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3621 | |
| 3622 | *pdatalen = 0; |
| 3623 | *pparmlen = 0; |
| 3624 | |
| 3625 | if (buf == NULL) |
| 3626 | return -EINVAL; |
| 3627 | |
| 3628 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3629 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3630 | bcc = get_bcc(&pSMBr->hdr); |
| 3631 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3632 | (char *)&pSMBr->ByteCount; |
| 3633 | |
| 3634 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3635 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3636 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3637 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3638 | |
| 3639 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3640 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3641 | |
| 3642 | /* should we also check that parm and data areas do not overlap? */ |
| 3643 | if (*ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3644 | cifs_dbg(FYI, "parms start after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3645 | return -EINVAL; |
| 3646 | } else if (parm_count + *ppparm > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3647 | cifs_dbg(FYI, "parm end after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3648 | return -EINVAL; |
| 3649 | } else if (*ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3650 | cifs_dbg(FYI, "data starts after end of smb\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3651 | return -EINVAL; |
| 3652 | } else if (data_count + *ppdata > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3653 | cifs_dbg(FYI, "data %p + count %d (%p) past smb end %p start %p\n", |
| 3654 | *ppdata, data_count, (data_count + *ppdata), |
| 3655 | end_of_smb, pSMBr); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3656 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3657 | } else if (parm_count + data_count > bcc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3658 | cifs_dbg(FYI, "parm count and data count larger than SMB\n"); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3659 | return -EINVAL; |
| 3660 | } |
| 3661 | *pdatalen = data_count; |
| 3662 | *pparmlen = parm_count; |
| 3663 | return 0; |
| 3664 | } |
| 3665 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3666 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3667 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3668 | CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3669 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3670 | { |
| 3671 | int rc = 0; |
| 3672 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3673 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3674 | struct kvec iov[1]; |
| 3675 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3676 | cifs_dbg(FYI, "GetCifsACL\n"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3677 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3678 | *pbuflen = 0; |
| 3679 | *acl_inf = NULL; |
| 3680 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3681 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3682 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3683 | if (rc) |
| 3684 | return rc; |
| 3685 | |
| 3686 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3687 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3688 | pSMB->MaxSetupCount = 0; |
| 3689 | pSMB->Fid = fid; /* file handle always le */ |
| 3690 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3691 | CIFS_ACL_DACL); |
| 3692 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3693 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3694 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3695 | 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] | 3696 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3697 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 3698 | 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 3699 | cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3700 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3701 | cifs_dbg(FYI, "Send error in QuerySecDesc = %d\n", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3702 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3703 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3704 | __u32 parm_len; |
| 3705 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3706 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3707 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3708 | |
| 3709 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3710 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3711 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3712 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3713 | goto qsec_out; |
| 3714 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3715 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3716 | cifs_dbg(FYI, "smb %p parm %p data %p\n", |
| 3717 | pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3718 | |
| 3719 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3720 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3721 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3722 | goto qsec_out; |
| 3723 | } |
| 3724 | |
| 3725 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3726 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3727 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3728 | if (acl_len != *pbuflen) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3729 | cifs_dbg(VFS, "acl length %d does not match %d\n", |
| 3730 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3731 | if (*pbuflen > acl_len) |
| 3732 | *pbuflen = acl_len; |
| 3733 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3734 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3735 | /* check if buffer is big enough for the acl |
| 3736 | header followed by the smallest SID */ |
| 3737 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3738 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3739 | cifs_dbg(VFS, "bad acl length %d\n", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3740 | rc = -EINVAL; |
| 3741 | *pbuflen = 0; |
| 3742 | } else { |
Silviu-Mihai Popescu | f7f7c18 | 2013-03-11 18:22:32 +0200 | [diff] [blame] | 3743 | *acl_inf = kmemdup(pdata, *pbuflen, GFP_KERNEL); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3744 | if (*acl_inf == NULL) { |
| 3745 | *pbuflen = 0; |
| 3746 | rc = -ENOMEM; |
| 3747 | } |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3748 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3749 | } |
| 3750 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3751 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3752 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3753 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3754 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3755 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3756 | return rc; |
| 3757 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3758 | |
| 3759 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3760 | CIFSSMBSetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3761 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3762 | { |
| 3763 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3764 | int rc = 0; |
| 3765 | int bytes_returned = 0; |
| 3766 | SET_SEC_DESC_REQ *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3767 | void *pSMBr; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3768 | |
| 3769 | setCifsAclRetry: |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3770 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3771 | if (rc) |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3772 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3773 | |
| 3774 | pSMB->MaxSetupCount = 0; |
| 3775 | pSMB->Reserved = 0; |
| 3776 | |
| 3777 | param_count = 8; |
| 3778 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3779 | data_count = acllen; |
| 3780 | data_offset = param_offset + param_count; |
| 3781 | byte_count = 3 /* pad */ + param_count; |
| 3782 | |
| 3783 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3784 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3785 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3786 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3787 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3788 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3789 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3790 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3791 | pSMB->SetupCount = 0; |
| 3792 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3793 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3794 | |
| 3795 | pSMB->Fid = fid; /* file handle always le */ |
| 3796 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3797 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3798 | |
| 3799 | if (pntsd && acllen) { |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3800 | memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + |
| 3801 | data_offset, pntsd, acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3802 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3803 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3804 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3805 | |
| 3806 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3807 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3808 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3809 | cifs_dbg(FYI, "SetCIFSACL bytes_returned: %d, rc: %d\n", |
| 3810 | bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3811 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3812 | cifs_dbg(FYI, "Set CIFS ACL returned %d\n", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3813 | cifs_buf_release(pSMB); |
| 3814 | |
| 3815 | if (rc == -EAGAIN) |
| 3816 | goto setCifsAclRetry; |
| 3817 | |
| 3818 | return (rc); |
| 3819 | } |
| 3820 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3821 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3822 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3823 | /* Legacy Query Path Information call for lookup to old servers such |
| 3824 | as Win9x/WinME */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3825 | int |
| 3826 | SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, |
| 3827 | const char *search_name, FILE_ALL_INFO *data, |
| 3828 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3829 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3830 | QUERY_INFORMATION_REQ *pSMB; |
| 3831 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3832 | int rc = 0; |
| 3833 | int bytes_returned; |
| 3834 | int name_len; |
| 3835 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3836 | cifs_dbg(FYI, "In SMBQPath path %s\n", search_name); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3837 | QInfRetry: |
| 3838 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3839 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3840 | if (rc) |
| 3841 | return rc; |
| 3842 | |
| 3843 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3844 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3845 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3846 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3847 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3848 | name_len++; /* trailing null */ |
| 3849 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3850 | } else { |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3851 | name_len = strnlen(search_name, PATH_MAX); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3852 | name_len++; /* trailing null */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3853 | strncpy(pSMB->FileName, search_name, name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3854 | } |
| 3855 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3856 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3857 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3858 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3859 | |
| 3860 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3861 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3862 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3863 | cifs_dbg(FYI, "Send error in QueryInfo = %d\n", rc); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3864 | } else if (data) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3865 | struct timespec ts; |
| 3866 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3867 | |
| 3868 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3869 | /* BB FIXME - add time zone adjustment BB */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3870 | memset(data, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3871 | ts.tv_nsec = 0; |
| 3872 | ts.tv_sec = time; |
| 3873 | /* decode time fields */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3874 | data->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
| 3875 | data->LastWriteTime = data->ChangeTime; |
| 3876 | data->LastAccessTime = 0; |
| 3877 | data->AllocationSize = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3878 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3879 | data->EndOfFile = data->AllocationSize; |
| 3880 | data->Attributes = |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3881 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3882 | } else |
| 3883 | rc = -EIO; /* bad buffer passed in */ |
| 3884 | |
| 3885 | cifs_buf_release(pSMB); |
| 3886 | |
| 3887 | if (rc == -EAGAIN) |
| 3888 | goto QInfRetry; |
| 3889 | |
| 3890 | return rc; |
| 3891 | } |
| 3892 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3893 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3894 | CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3895 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 3896 | { |
| 3897 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3898 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3899 | int rc = 0; |
| 3900 | int bytes_returned; |
| 3901 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3902 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3903 | QFileInfoRetry: |
| 3904 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3905 | (void **) &pSMBr); |
| 3906 | if (rc) |
| 3907 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3908 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3909 | params = 2 /* level */ + 2 /* fid */; |
| 3910 | pSMB->t2.TotalDataCount = 0; |
| 3911 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3912 | /* BB find exact max data count below from sess structure BB */ |
| 3913 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3914 | pSMB->t2.MaxSetupCount = 0; |
| 3915 | pSMB->t2.Reserved = 0; |
| 3916 | pSMB->t2.Flags = 0; |
| 3917 | pSMB->t2.Timeout = 0; |
| 3918 | pSMB->t2.Reserved2 = 0; |
| 3919 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3920 | Fid) - 4); |
| 3921 | pSMB->t2.DataCount = 0; |
| 3922 | pSMB->t2.DataOffset = 0; |
| 3923 | pSMB->t2.SetupCount = 1; |
| 3924 | pSMB->t2.Reserved3 = 0; |
| 3925 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3926 | byte_count = params + 1 /* pad */ ; |
| 3927 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3928 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3929 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 3930 | pSMB->Pad = 0; |
| 3931 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3932 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3933 | |
| 3934 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3935 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3936 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3937 | cifs_dbg(FYI, "Send error in QPathInfo = %d\n", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3938 | } else { /* decode response */ |
| 3939 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3940 | |
| 3941 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3942 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3943 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3944 | rc = -EIO; /* bad smb */ |
| 3945 | else if (pFindData) { |
| 3946 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3947 | memcpy((char *) pFindData, |
| 3948 | (char *) &pSMBr->hdr.Protocol + |
| 3949 | data_offset, sizeof(FILE_ALL_INFO)); |
| 3950 | } else |
| 3951 | rc = -ENOMEM; |
| 3952 | } |
| 3953 | cifs_buf_release(pSMB); |
| 3954 | if (rc == -EAGAIN) |
| 3955 | goto QFileInfoRetry; |
| 3956 | |
| 3957 | return rc; |
| 3958 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3961 | CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3962 | const char *search_name, FILE_ALL_INFO *data, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3963 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3964 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | { |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3966 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3968 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3969 | int rc = 0; |
| 3970 | int bytes_returned; |
| 3971 | int name_len; |
| 3972 | __u16 params, byte_count; |
| 3973 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3974 | /* cifs_dbg(FYI, "In QPathInfo path %s\n", search_name); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | QPathInfoRetry: |
| 3976 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3977 | (void **) &pSMBr); |
| 3978 | if (rc) |
| 3979 | return rc; |
| 3980 | |
| 3981 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3982 | name_len = |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3983 | cifsConvertToUTF16((__le16 *) pSMB->FileName, search_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3984 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | name_len++; /* trailing null */ |
| 3986 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3987 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3988 | name_len = strnlen(search_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | name_len++; /* trailing null */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 3990 | strncpy(pSMB->FileName, search_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | } |
| 3992 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3993 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | pSMB->TotalDataCount = 0; |
| 3995 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3996 | /* BB find exact max SMB PDU from sess structure BB */ |
| 3997 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | pSMB->MaxSetupCount = 0; |
| 3999 | pSMB->Reserved = 0; |
| 4000 | pSMB->Flags = 0; |
| 4001 | pSMB->Timeout = 0; |
| 4002 | pSMB->Reserved2 = 0; |
| 4003 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4004 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | pSMB->DataCount = 0; |
| 4006 | pSMB->DataOffset = 0; |
| 4007 | pSMB->SetupCount = 1; |
| 4008 | pSMB->Reserved3 = 0; |
| 4009 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4010 | byte_count = params + 1 /* pad */ ; |
| 4011 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4012 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4013 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4014 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4015 | else |
| 4016 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4018 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4020 | |
| 4021 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4022 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4023 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4024 | cifs_dbg(FYI, "Send error in QPathInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | } else { /* decode response */ |
| 4026 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4027 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4028 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4029 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4030 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4032 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4033 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4034 | last field */ |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4035 | else if (data) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4036 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4038 | |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4039 | /* |
| 4040 | * On legacy responses we do not read the last field, |
| 4041 | * EAsize, fortunately since it varies by subdialect and |
| 4042 | * also note it differs on Set vs Get, ie two bytes or 4 |
| 4043 | * bytes depending but we don't care here. |
| 4044 | */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4045 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4046 | size = sizeof(FILE_INFO_STANDARD); |
| 4047 | else |
| 4048 | size = sizeof(FILE_ALL_INFO); |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4049 | memcpy((char *) data, (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4050 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | } else |
| 4052 | rc = -ENOMEM; |
| 4053 | } |
| 4054 | cifs_buf_release(pSMB); |
| 4055 | if (rc == -EAGAIN) |
| 4056 | goto QPathInfoRetry; |
| 4057 | |
| 4058 | return rc; |
| 4059 | } |
| 4060 | |
| 4061 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4062 | CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4063 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4064 | { |
| 4065 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4066 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4067 | int rc = 0; |
| 4068 | int bytes_returned; |
| 4069 | __u16 params, byte_count; |
| 4070 | |
| 4071 | UnixQFileInfoRetry: |
| 4072 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4073 | (void **) &pSMBr); |
| 4074 | if (rc) |
| 4075 | return rc; |
| 4076 | |
| 4077 | params = 2 /* level */ + 2 /* fid */; |
| 4078 | pSMB->t2.TotalDataCount = 0; |
| 4079 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4080 | /* BB find exact max data count below from sess structure BB */ |
| 4081 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4082 | pSMB->t2.MaxSetupCount = 0; |
| 4083 | pSMB->t2.Reserved = 0; |
| 4084 | pSMB->t2.Flags = 0; |
| 4085 | pSMB->t2.Timeout = 0; |
| 4086 | pSMB->t2.Reserved2 = 0; |
| 4087 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4088 | Fid) - 4); |
| 4089 | pSMB->t2.DataCount = 0; |
| 4090 | pSMB->t2.DataOffset = 0; |
| 4091 | pSMB->t2.SetupCount = 1; |
| 4092 | pSMB->t2.Reserved3 = 0; |
| 4093 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4094 | byte_count = params + 1 /* pad */ ; |
| 4095 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4096 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4097 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4098 | pSMB->Pad = 0; |
| 4099 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4100 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4101 | |
| 4102 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4103 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4104 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4105 | cifs_dbg(FYI, "Send error in QPathInfo = %d\n", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4106 | } else { /* decode response */ |
| 4107 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4108 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4109 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4110 | 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] | 4111 | rc = -EIO; /* bad smb */ |
| 4112 | } else { |
| 4113 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4114 | memcpy((char *) pFindData, |
| 4115 | (char *) &pSMBr->hdr.Protocol + |
| 4116 | data_offset, |
| 4117 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | cifs_buf_release(pSMB); |
| 4122 | if (rc == -EAGAIN) |
| 4123 | goto UnixQFileInfoRetry; |
| 4124 | |
| 4125 | return rc; |
| 4126 | } |
| 4127 | |
| 4128 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4129 | CIFSSMBUnixQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4131 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4132 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | { |
| 4134 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4135 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4136 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4137 | int rc = 0; |
| 4138 | int bytes_returned = 0; |
| 4139 | int name_len; |
| 4140 | __u16 params, byte_count; |
| 4141 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4142 | cifs_dbg(FYI, "In QPathInfo (Unix) the path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | UnixQPathInfoRetry: |
| 4144 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4145 | (void **) &pSMBr); |
| 4146 | if (rc) |
| 4147 | return rc; |
| 4148 | |
| 4149 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4150 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4151 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4152 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | name_len++; /* trailing null */ |
| 4154 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4155 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | name_len = strnlen(searchName, PATH_MAX); |
| 4157 | name_len++; /* trailing null */ |
| 4158 | strncpy(pSMB->FileName, searchName, name_len); |
| 4159 | } |
| 4160 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4161 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | pSMB->TotalDataCount = 0; |
| 4163 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4164 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4165 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | pSMB->MaxSetupCount = 0; |
| 4167 | pSMB->Reserved = 0; |
| 4168 | pSMB->Flags = 0; |
| 4169 | pSMB->Timeout = 0; |
| 4170 | pSMB->Reserved2 = 0; |
| 4171 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4172 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | pSMB->DataCount = 0; |
| 4174 | pSMB->DataOffset = 0; |
| 4175 | pSMB->SetupCount = 1; |
| 4176 | pSMB->Reserved3 = 0; |
| 4177 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4178 | byte_count = params + 1 /* pad */ ; |
| 4179 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4180 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4181 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4182 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4183 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4185 | |
| 4186 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4187 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4188 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4189 | cifs_dbg(FYI, "Send error in QPathInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | } else { /* decode response */ |
| 4191 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4192 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4193 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4194 | 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] | 4195 | rc = -EIO; /* bad smb */ |
| 4196 | } else { |
| 4197 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4198 | memcpy((char *) pFindData, |
| 4199 | (char *) &pSMBr->hdr.Protocol + |
| 4200 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4201 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | } |
| 4203 | } |
| 4204 | cifs_buf_release(pSMB); |
| 4205 | if (rc == -EAGAIN) |
| 4206 | goto UnixQPathInfoRetry; |
| 4207 | |
| 4208 | return rc; |
| 4209 | } |
| 4210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4212 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4213 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4214 | const char *searchName, struct cifs_sb_info *cifs_sb, |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4215 | __u16 *pnetfid, __u16 search_flags, |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4216 | struct cifs_search_info *psrch_inf, bool msearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | { |
| 4218 | /* level 257 SMB_ */ |
| 4219 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4220 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4221 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | int rc = 0; |
| 4223 | int bytes_returned = 0; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4224 | int name_len, remap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | __u16 params, byte_count; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4226 | struct nls_table *nls_codepage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4228 | cifs_dbg(FYI, "In FindFirst for %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | |
| 4230 | findFirstRetry: |
| 4231 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4232 | (void **) &pSMBr); |
| 4233 | if (rc) |
| 4234 | return rc; |
| 4235 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4236 | nls_codepage = cifs_sb->local_nls; |
| 4237 | remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; |
| 4238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4240 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4241 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4242 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4243 | /* We can not add the asterik earlier in case |
| 4244 | it got remapped to 0xF03A as if it were part of the |
| 4245 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | name_len *= 2; |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4247 | if (msearch) { |
| 4248 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
| 4249 | pSMB->FileName[name_len+1] = 0; |
| 4250 | pSMB->FileName[name_len+2] = '*'; |
| 4251 | pSMB->FileName[name_len+3] = 0; |
| 4252 | name_len += 4; /* now the trailing null */ |
| 4253 | /* null terminate just in case */ |
| 4254 | pSMB->FileName[name_len] = 0; |
| 4255 | pSMB->FileName[name_len+1] = 0; |
| 4256 | name_len += 2; |
| 4257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | } else { /* BB add check for overrun of SMB buf BB */ |
| 4259 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4261 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | free buffer exit; BB */ |
| 4263 | strncpy(pSMB->FileName, searchName, name_len); |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4264 | if (msearch) { |
| 4265 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
| 4266 | pSMB->FileName[name_len+1] = '*'; |
| 4267 | pSMB->FileName[name_len+2] = 0; |
| 4268 | name_len += 3; |
| 4269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | params = 12 + name_len /* includes null */ ; |
| 4273 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4274 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4275 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | pSMB->MaxSetupCount = 0; |
| 4277 | pSMB->Reserved = 0; |
| 4278 | pSMB->Flags = 0; |
| 4279 | pSMB->Timeout = 0; |
| 4280 | pSMB->Reserved2 = 0; |
| 4281 | byte_count = params + 1 /* pad */ ; |
| 4282 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4283 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4284 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4285 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4286 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | pSMB->DataCount = 0; |
| 4288 | pSMB->DataOffset = 0; |
| 4289 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4290 | pSMB->Reserved3 = 0; |
| 4291 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4292 | pSMB->SearchAttributes = |
| 4293 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4294 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4295 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4296 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4298 | |
| 4299 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4300 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4301 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4303 | |
| 4304 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4305 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4306 | cifs_stats_inc(&tcon->stats.cifs_stats.num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4308 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4309 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4311 | cifs_dbg(FYI, "Error in FindFirst = %d\n", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4312 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4313 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | |
| 4315 | /* BB eventually could optimize out free and realloc of buf */ |
| 4316 | /* for this case */ |
| 4317 | if (rc == -EAGAIN) |
| 4318 | goto findFirstRetry; |
| 4319 | } else { /* decode response */ |
| 4320 | /* BB remember to free buffer if error BB */ |
| 4321 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4322 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4323 | unsigned int lnoff; |
| 4324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4326 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4328 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | |
| 4330 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4331 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4332 | psrch_inf->srch_entries_start = |
| 4333 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4336 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4337 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4338 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4339 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4341 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4343 | psrch_inf->entries_in_buffer = |
| 4344 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4345 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4347 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4348 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4349 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4350 | psrch_inf->last_entry = NULL; |
| 4351 | return rc; |
| 4352 | } |
| 4353 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4354 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4355 | lnoff; |
| 4356 | |
Shirish Pargaonkar | c052e2b | 2012-09-28 12:21:14 -0500 | [diff] [blame] | 4357 | if (pnetfid) |
| 4358 | *pnetfid = parms->SearchHandle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | } else { |
| 4360 | cifs_buf_release(pSMB); |
| 4361 | } |
| 4362 | } |
| 4363 | |
| 4364 | return rc; |
| 4365 | } |
| 4366 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4367 | int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, |
| 4368 | __u16 searchHandle, __u16 search_flags, |
| 4369 | struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | { |
| 4371 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4372 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4373 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | char *response_data; |
| 4375 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4376 | int bytes_returned; |
| 4377 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | __u16 params, byte_count; |
| 4379 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4380 | cifs_dbg(FYI, "In FindNext\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4382 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | return -ENOENT; |
| 4384 | |
| 4385 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4386 | (void **) &pSMBr); |
| 4387 | if (rc) |
| 4388 | return rc; |
| 4389 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4390 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | byte_count = 0; |
| 4392 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4393 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4394 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | pSMB->MaxSetupCount = 0; |
| 4396 | pSMB->Reserved = 0; |
| 4397 | pSMB->Flags = 0; |
| 4398 | pSMB->Timeout = 0; |
| 4399 | pSMB->Reserved2 = 0; |
| 4400 | pSMB->ParameterOffset = cpu_to_le16( |
| 4401 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4402 | pSMB->DataCount = 0; |
| 4403 | pSMB->DataOffset = 0; |
| 4404 | pSMB->SetupCount = 1; |
| 4405 | pSMB->Reserved3 = 0; |
| 4406 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4407 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4408 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4409 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4411 | pSMB->ResumeKey = psrch_inf->resume_key; |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4412 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | |
| 4414 | name_len = psrch_inf->resume_name_len; |
| 4415 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4416 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4418 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4419 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4420 | pSMB->ResumeFileName[name_len] = 0; |
| 4421 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | } else { |
| 4423 | rc = -EINVAL; |
| 4424 | goto FNext2_err_exit; |
| 4425 | } |
| 4426 | byte_count = params + 1 /* pad */ ; |
| 4427 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4428 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4429 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4433 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4434 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | if (rc) { |
| 4436 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4437 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4438 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4439 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | } else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4441 | cifs_dbg(FYI, "FindNext returned = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | } else { /* decode response */ |
| 4443 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4444 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4445 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4446 | unsigned int lnoff; |
| 4447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4449 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4450 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4452 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4454 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4455 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4456 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4457 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4458 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4459 | cifs_small_buf_release( |
| 4460 | psrch_inf->ntwrk_buf_start); |
| 4461 | else |
| 4462 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | psrch_inf->srch_entries_start = response_data; |
| 4464 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4465 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4466 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4467 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4469 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4470 | psrch_inf->entries_in_buffer = |
| 4471 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | psrch_inf->index_of_last_entry += |
| 4473 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4474 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4475 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4476 | cifs_dbg(VFS, "ignoring corrupt resume name\n"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4477 | psrch_inf->last_entry = NULL; |
| 4478 | return rc; |
| 4479 | } else |
| 4480 | psrch_inf->last_entry = |
| 4481 | psrch_inf->srch_entries_start + lnoff; |
| 4482 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4483 | /* cifs_dbg(FYI, "fnxt2 entries in buf %d index_of_last %d\n", |
| 4484 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | |
| 4486 | /* BB fixme add unlock here */ |
| 4487 | } |
| 4488 | |
| 4489 | } |
| 4490 | |
| 4491 | /* BB On error, should we leave previous search buf (and count and |
| 4492 | last entry fields) intact or free the previous one? */ |
| 4493 | |
| 4494 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4495 | since file handle passed in no longer valid */ |
| 4496 | FNext2_err_exit: |
| 4497 | if (rc != 0) |
| 4498 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | return rc; |
| 4500 | } |
| 4501 | |
| 4502 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4503 | CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4504 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | { |
| 4506 | int rc = 0; |
| 4507 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4509 | cifs_dbg(FYI, "In CIFSSMBFindClose\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4511 | |
| 4512 | /* no sense returning error if session restarted |
| 4513 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4514 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | return 0; |
| 4516 | if (rc) |
| 4517 | return rc; |
| 4518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | pSMB->FileID = searchHandle; |
| 4520 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4521 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4522 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4523 | cifs_dbg(VFS, "Send error in FindClose = %d\n", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4524 | |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 4525 | cifs_stats_inc(&tcon->stats.cifs_stats.num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | |
| 4527 | /* Since session is dead, search handle closed on server already */ |
| 4528 | if (rc == -EAGAIN) |
| 4529 | rc = 0; |
| 4530 | |
| 4531 | return rc; |
| 4532 | } |
| 4533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4535 | CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4536 | const char *search_name, __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4537 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | { |
| 4539 | int rc = 0; |
| 4540 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4541 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4542 | int name_len, bytes_returned; |
| 4543 | __u16 params, byte_count; |
| 4544 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4545 | cifs_dbg(FYI, "In GetSrvInodeNum for %s\n", search_name); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4546 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4547 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | |
| 4549 | GetInodeNumberRetry: |
| 4550 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4551 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | if (rc) |
| 4553 | return rc; |
| 4554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4556 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4557 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4558 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4559 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | name_len++; /* trailing null */ |
| 4561 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4562 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4563 | name_len = strnlen(search_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | name_len++; /* trailing null */ |
Pavel Shilovsky | 1208ef1 | 2012-05-27 17:34:43 +0400 | [diff] [blame] | 4565 | strncpy(pSMB->FileName, search_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4569 | pSMB->TotalDataCount = 0; |
| 4570 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4571 | /* BB find exact max data count below from sess structure BB */ |
| 4572 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4573 | pSMB->MaxSetupCount = 0; |
| 4574 | pSMB->Reserved = 0; |
| 4575 | pSMB->Flags = 0; |
| 4576 | pSMB->Timeout = 0; |
| 4577 | pSMB->Reserved2 = 0; |
| 4578 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4579 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | pSMB->DataCount = 0; |
| 4581 | pSMB->DataOffset = 0; |
| 4582 | pSMB->SetupCount = 1; |
| 4583 | pSMB->Reserved3 = 0; |
| 4584 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4585 | byte_count = params + 1 /* pad */ ; |
| 4586 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4587 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4588 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4589 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4590 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4592 | |
| 4593 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4594 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4595 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4596 | cifs_dbg(FYI, "error %d in QueryInternalInfo\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | } else { |
| 4598 | /* decode response */ |
| 4599 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4601 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | /* If rc should we check for EOPNOSUPP and |
| 4603 | disable the srvino flag? or in caller? */ |
| 4604 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4605 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4607 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4608 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4610 | if (count < 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4611 | cifs_dbg(FYI, "Illegal size ret in QryIntrnlInf\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | rc = -EIO; |
| 4613 | goto GetInodeNumOut; |
| 4614 | } |
| 4615 | pfinfo = (struct file_internal_info *) |
| 4616 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4617 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | } |
| 4619 | } |
| 4620 | GetInodeNumOut: |
| 4621 | cifs_buf_release(pSMB); |
| 4622 | if (rc == -EAGAIN) |
| 4623 | goto GetInodeNumberRetry; |
| 4624 | return rc; |
| 4625 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4627 | /* parses DFS refferal V3 structure |
| 4628 | * caller is responsible for freeing target_nodes |
| 4629 | * returns: |
| 4630 | * on success - 0 |
| 4631 | * on failure - errno |
| 4632 | */ |
| 4633 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4634 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4635 | unsigned int *num_of_nodes, |
| 4636 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4637 | const struct nls_table *nls_codepage, int remap, |
| 4638 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4639 | { |
| 4640 | int i, rc = 0; |
| 4641 | char *data_end; |
| 4642 | bool is_unicode; |
| 4643 | struct dfs_referral_level_3 *ref; |
| 4644 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 4645 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 4646 | is_unicode = true; |
| 4647 | else |
| 4648 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4649 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 4650 | |
| 4651 | if (*num_of_nodes < 1) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4652 | cifs_dbg(VFS, "num_referrals: must be at least > 0, but we get num_referrals = %d\n", |
| 4653 | *num_of_nodes); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4654 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4655 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4659 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4660 | cifs_dbg(VFS, "Referrals of V%d version are not supported, should be V3\n", |
| 4661 | le16_to_cpu(ref->VersionNumber)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4662 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4663 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | /* get the upper boundary of the resp buffer */ |
| 4667 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 4668 | le16_to_cpu(pSMBr->t2.DataCount); |
| 4669 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4670 | cifs_dbg(FYI, "num_referrals: %d dfs flags: 0x%x ...\n", |
| 4671 | *num_of_nodes, le32_to_cpu(pSMBr->DFSFlags)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4672 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4673 | *target_nodes = kcalloc(*num_of_nodes, sizeof(struct dfs_info3_param), |
| 4674 | GFP_KERNEL); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4675 | if (*target_nodes == NULL) { |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4676 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4677 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4678 | } |
| 4679 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4680 | /* collect necessary data from referrals */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4681 | for (i = 0; i < *num_of_nodes; i++) { |
| 4682 | char *temp; |
| 4683 | int max_len; |
| 4684 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 4685 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4686 | node->flags = le32_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4687 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 4688 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 4689 | GFP_KERNEL); |
Steve French | 2920ee2 | 2009-08-31 15:27:26 +0000 | [diff] [blame] | 4690 | if (tmp == NULL) { |
| 4691 | rc = -ENOMEM; |
| 4692 | goto parse_DFS_referrals_exit; |
| 4693 | } |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4694 | cifsConvertToUTF16((__le16 *) tmp, searchName, |
| 4695 | PATH_MAX, nls_codepage, remap); |
| 4696 | node->path_consumed = cifs_utf16_bytes(tmp, |
Jeff Layton | 69f801f | 2009-04-30 06:46:32 -0400 | [diff] [blame] | 4697 | le16_to_cpu(pSMBr->PathConsumed), |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4698 | nls_codepage); |
| 4699 | kfree(tmp); |
| 4700 | } else |
| 4701 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4702 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4703 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4704 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4705 | |
| 4706 | /* copy DfsPath */ |
| 4707 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4708 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4709 | node->path_name = cifs_strndup_from_utf16(temp, max_len, |
| 4710 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4711 | if (!node->path_name) { |
| 4712 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4713 | goto parse_DFS_referrals_exit; |
Jeff Layton | 066ce68 | 2009-04-30 07:16:14 -0400 | [diff] [blame] | 4714 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4715 | |
| 4716 | /* copy link target UNC */ |
| 4717 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4718 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4719 | node->node_name = cifs_strndup_from_utf16(temp, max_len, |
| 4720 | is_unicode, nls_codepage); |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4721 | if (!node->node_name) { |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4722 | rc = -ENOMEM; |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4723 | goto parse_DFS_referrals_exit; |
| 4724 | } |
| 4725 | |
| 4726 | ref++; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4727 | } |
| 4728 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4729 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4730 | if (rc) { |
| 4731 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4732 | *target_nodes = NULL; |
| 4733 | *num_of_nodes = 0; |
| 4734 | } |
| 4735 | return rc; |
| 4736 | } |
| 4737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4739 | CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4740 | const char *search_name, struct dfs_info3_param **target_nodes, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4741 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4742 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | { |
| 4744 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4745 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4746 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | int rc = 0; |
| 4748 | int bytes_returned; |
| 4749 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4751 | *num_of_nodes = 0; |
| 4752 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4754 | cifs_dbg(FYI, "In GetDFSRefer the path %s\n", search_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | if (ses == NULL) |
| 4756 | return -ENODEV; |
| 4757 | getDFSRetry: |
| 4758 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4759 | (void **) &pSMBr); |
| 4760 | if (rc) |
| 4761 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4762 | |
| 4763 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4764 | but should never be null here anyway */ |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 4765 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4767 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4768 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4770 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4772 | |
| 4773 | if (ses->capabilities & CAP_UNICODE) { |
| 4774 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4775 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4776 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4777 | search_name, PATH_MAX, nls_codepage, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4778 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | name_len++; /* trailing null */ |
| 4780 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4781 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4782 | name_len = strnlen(search_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | name_len++; /* trailing null */ |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4784 | strncpy(pSMB->RequestFileName, search_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | } |
| 4786 | |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 4787 | if (ses->server && ses->server->sign) |
| 4788 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4789 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4790 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4791 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4793 | pSMB->TotalDataCount = 0; |
| 4794 | pSMB->DataCount = 0; |
| 4795 | pSMB->DataOffset = 0; |
| 4796 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4797 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4798 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | pSMB->MaxSetupCount = 0; |
| 4800 | pSMB->Reserved = 0; |
| 4801 | pSMB->Flags = 0; |
| 4802 | pSMB->Timeout = 0; |
| 4803 | pSMB->Reserved2 = 0; |
| 4804 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4805 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4806 | pSMB->SetupCount = 1; |
| 4807 | pSMB->Reserved3 = 0; |
| 4808 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4809 | byte_count = params + 3 /* pad */ ; |
| 4810 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4811 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4812 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4813 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4815 | |
| 4816 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4817 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4818 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4819 | cifs_dbg(FYI, "Send error in GetDFSRefer = %d\n", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4820 | goto GetDFSRefExit; |
| 4821 | } |
| 4822 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4824 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4825 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4826 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4827 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4829 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4830 | cifs_dbg(FYI, "Decoding GetDFSRefer response BCC: %d Offset %d\n", |
| 4831 | get_bcc(&pSMBr->hdr), le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4832 | |
| 4833 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4834 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4835 | target_nodes, nls_codepage, remap, |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 4836 | search_name); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4839 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | |
| 4841 | if (rc == -EAGAIN) |
| 4842 | goto getDFSRetry; |
| 4843 | |
| 4844 | return rc; |
| 4845 | } |
| 4846 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4847 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4848 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4849 | SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 4850 | struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4851 | { |
| 4852 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4853 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4854 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4855 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4856 | int rc = 0; |
| 4857 | int bytes_returned = 0; |
| 4858 | __u16 params, byte_count; |
| 4859 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4860 | cifs_dbg(FYI, "OldQFSInfo\n"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4861 | oldQFSInfoRetry: |
| 4862 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4863 | (void **) &pSMBr); |
| 4864 | if (rc) |
| 4865 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4866 | |
| 4867 | params = 2; /* level */ |
| 4868 | pSMB->TotalDataCount = 0; |
| 4869 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4870 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4871 | pSMB->MaxSetupCount = 0; |
| 4872 | pSMB->Reserved = 0; |
| 4873 | pSMB->Flags = 0; |
| 4874 | pSMB->Timeout = 0; |
| 4875 | pSMB->Reserved2 = 0; |
| 4876 | byte_count = params + 1 /* pad */ ; |
| 4877 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4878 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4879 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4880 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4881 | pSMB->DataCount = 0; |
| 4882 | pSMB->DataOffset = 0; |
| 4883 | pSMB->SetupCount = 1; |
| 4884 | pSMB->Reserved3 = 0; |
| 4885 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4886 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4887 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4888 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4889 | |
| 4890 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4891 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4892 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4893 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4894 | } else { /* decode response */ |
| 4895 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4896 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4897 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4898 | rc = -EIO; /* bad smb */ |
| 4899 | else { |
| 4900 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4901 | cifs_dbg(FYI, "qfsinf resp BCC: %d Offset %d\n", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4902 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4903 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4904 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4905 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4906 | FSData->f_bsize = |
| 4907 | le16_to_cpu(response_data->BytesPerSector) * |
| 4908 | le32_to_cpu(response_data-> |
| 4909 | SectorsPerAllocationUnit); |
| 4910 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4911 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4912 | FSData->f_bfree = FSData->f_bavail = |
| 4913 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4914 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 4915 | (unsigned long long)FSData->f_blocks, |
| 4916 | (unsigned long long)FSData->f_bfree, |
| 4917 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4918 | } |
| 4919 | } |
| 4920 | cifs_buf_release(pSMB); |
| 4921 | |
| 4922 | if (rc == -EAGAIN) |
| 4923 | goto oldQFSInfoRetry; |
| 4924 | |
| 4925 | return rc; |
| 4926 | } |
| 4927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4929 | CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, |
| 4930 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4931 | { |
| 4932 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4933 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4934 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4935 | FILE_SYSTEM_INFO *response_data; |
| 4936 | int rc = 0; |
| 4937 | int bytes_returned = 0; |
| 4938 | __u16 params, byte_count; |
| 4939 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4940 | cifs_dbg(FYI, "In QFSInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | QFSInfoRetry: |
| 4942 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4943 | (void **) &pSMBr); |
| 4944 | if (rc) |
| 4945 | return rc; |
| 4946 | |
| 4947 | params = 2; /* level */ |
| 4948 | pSMB->TotalDataCount = 0; |
| 4949 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4950 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | pSMB->MaxSetupCount = 0; |
| 4952 | pSMB->Reserved = 0; |
| 4953 | pSMB->Flags = 0; |
| 4954 | pSMB->Timeout = 0; |
| 4955 | pSMB->Reserved2 = 0; |
| 4956 | byte_count = params + 1 /* pad */ ; |
| 4957 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4958 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4959 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4960 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | pSMB->DataCount = 0; |
| 4962 | pSMB->DataOffset = 0; |
| 4963 | pSMB->SetupCount = 1; |
| 4964 | pSMB->Reserved3 = 0; |
| 4965 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4966 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4967 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4969 | |
| 4970 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4971 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4972 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4973 | cifs_dbg(FYI, "Send error in QFSInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4974 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4975 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4976 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4977 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | rc = -EIO; /* bad smb */ |
| 4979 | else { |
| 4980 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | |
| 4982 | response_data = |
| 4983 | (FILE_SYSTEM_INFO |
| 4984 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4985 | data_offset); |
| 4986 | FSData->f_bsize = |
| 4987 | le32_to_cpu(response_data->BytesPerSector) * |
| 4988 | le32_to_cpu(response_data-> |
| 4989 | SectorsPerAllocationUnit); |
| 4990 | FSData->f_blocks = |
| 4991 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 4992 | FSData->f_bfree = FSData->f_bavail = |
| 4993 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4994 | cifs_dbg(FYI, "Blocks: %lld Free: %lld Block size %ld\n", |
| 4995 | (unsigned long long)FSData->f_blocks, |
| 4996 | (unsigned long long)FSData->f_bfree, |
| 4997 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | } |
| 4999 | } |
| 5000 | cifs_buf_release(pSMB); |
| 5001 | |
| 5002 | if (rc == -EAGAIN) |
| 5003 | goto QFSInfoRetry; |
| 5004 | |
| 5005 | return rc; |
| 5006 | } |
| 5007 | |
| 5008 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5009 | CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | { |
| 5011 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5012 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5013 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5014 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5015 | int rc = 0; |
| 5016 | int bytes_returned = 0; |
| 5017 | __u16 params, byte_count; |
| 5018 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5019 | cifs_dbg(FYI, "In QFSAttributeInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | QFSAttributeRetry: |
| 5021 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5022 | (void **) &pSMBr); |
| 5023 | if (rc) |
| 5024 | return rc; |
| 5025 | |
| 5026 | params = 2; /* level */ |
| 5027 | pSMB->TotalDataCount = 0; |
| 5028 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5029 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5030 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | pSMB->MaxSetupCount = 0; |
| 5032 | pSMB->Reserved = 0; |
| 5033 | pSMB->Flags = 0; |
| 5034 | pSMB->Timeout = 0; |
| 5035 | pSMB->Reserved2 = 0; |
| 5036 | byte_count = params + 1 /* pad */ ; |
| 5037 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5038 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5039 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5040 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | pSMB->DataCount = 0; |
| 5042 | pSMB->DataOffset = 0; |
| 5043 | pSMB->SetupCount = 1; |
| 5044 | pSMB->Reserved3 = 0; |
| 5045 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5046 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5047 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5049 | |
| 5050 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5051 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5052 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5053 | cifs_dbg(VFS, "Send error in QFSAttributeInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5054 | } else { /* decode response */ |
| 5055 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5056 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5057 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5058 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 | rc = -EIO; /* bad smb */ |
| 5060 | } else { |
| 5061 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5062 | response_data = |
| 5063 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5064 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5065 | data_offset); |
| 5066 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5067 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | } |
| 5069 | } |
| 5070 | cifs_buf_release(pSMB); |
| 5071 | |
| 5072 | if (rc == -EAGAIN) |
| 5073 | goto QFSAttributeRetry; |
| 5074 | |
| 5075 | return rc; |
| 5076 | } |
| 5077 | |
| 5078 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5079 | CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5080 | { |
| 5081 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5082 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5083 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5084 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5085 | int rc = 0; |
| 5086 | int bytes_returned = 0; |
| 5087 | __u16 params, byte_count; |
| 5088 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5089 | cifs_dbg(FYI, "In QFSDeviceInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | QFSDeviceRetry: |
| 5091 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5092 | (void **) &pSMBr); |
| 5093 | if (rc) |
| 5094 | return rc; |
| 5095 | |
| 5096 | params = 2; /* level */ |
| 5097 | pSMB->TotalDataCount = 0; |
| 5098 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5099 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5100 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | pSMB->MaxSetupCount = 0; |
| 5102 | pSMB->Reserved = 0; |
| 5103 | pSMB->Flags = 0; |
| 5104 | pSMB->Timeout = 0; |
| 5105 | pSMB->Reserved2 = 0; |
| 5106 | byte_count = params + 1 /* pad */ ; |
| 5107 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5108 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5109 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5110 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | |
| 5112 | pSMB->DataCount = 0; |
| 5113 | pSMB->DataOffset = 0; |
| 5114 | pSMB->SetupCount = 1; |
| 5115 | pSMB->Reserved3 = 0; |
| 5116 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5117 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5118 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5120 | |
| 5121 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5122 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5123 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5124 | cifs_dbg(FYI, "Send error in QFSDeviceInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | } else { /* decode response */ |
| 5126 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5127 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5128 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5129 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | rc = -EIO; /* bad smb */ |
| 5131 | else { |
| 5132 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5133 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5134 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5135 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5136 | data_offset); |
| 5137 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5138 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | } |
| 5140 | } |
| 5141 | cifs_buf_release(pSMB); |
| 5142 | |
| 5143 | if (rc == -EAGAIN) |
| 5144 | goto QFSDeviceRetry; |
| 5145 | |
| 5146 | return rc; |
| 5147 | } |
| 5148 | |
| 5149 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5150 | CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5151 | { |
| 5152 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5153 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5154 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5155 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5156 | int rc = 0; |
| 5157 | int bytes_returned = 0; |
| 5158 | __u16 params, byte_count; |
| 5159 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5160 | cifs_dbg(FYI, "In QFSUnixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5162 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5163 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | if (rc) |
| 5165 | return rc; |
| 5166 | |
| 5167 | params = 2; /* level */ |
| 5168 | pSMB->TotalDataCount = 0; |
| 5169 | pSMB->DataCount = 0; |
| 5170 | pSMB->DataOffset = 0; |
| 5171 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5172 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5173 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | pSMB->MaxSetupCount = 0; |
| 5175 | pSMB->Reserved = 0; |
| 5176 | pSMB->Flags = 0; |
| 5177 | pSMB->Timeout = 0; |
| 5178 | pSMB->Reserved2 = 0; |
| 5179 | byte_count = params + 1 /* pad */ ; |
| 5180 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5181 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5182 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5183 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | pSMB->SetupCount = 1; |
| 5185 | pSMB->Reserved3 = 0; |
| 5186 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5187 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5188 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5190 | |
| 5191 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5192 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5193 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5194 | cifs_dbg(VFS, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5195 | } else { /* decode response */ |
| 5196 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5197 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5198 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | rc = -EIO; /* bad smb */ |
| 5200 | } else { |
| 5201 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5202 | response_data = |
| 5203 | (FILE_SYSTEM_UNIX_INFO |
| 5204 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5205 | data_offset); |
| 5206 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5207 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | } |
| 5209 | } |
| 5210 | cifs_buf_release(pSMB); |
| 5211 | |
| 5212 | if (rc == -EAGAIN) |
| 5213 | goto QFSUnixRetry; |
| 5214 | |
| 5215 | |
| 5216 | return rc; |
| 5217 | } |
| 5218 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5219 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5220 | CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5221 | { |
| 5222 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5223 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5224 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5225 | int rc = 0; |
| 5226 | int bytes_returned = 0; |
| 5227 | __u16 params, param_offset, offset, byte_count; |
| 5228 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5229 | cifs_dbg(FYI, "In SETFSUnixInfo\n"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5230 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5231 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5232 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5233 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5234 | if (rc) |
| 5235 | return rc; |
| 5236 | |
| 5237 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5238 | pSMB->MaxSetupCount = 0; |
| 5239 | pSMB->Reserved = 0; |
| 5240 | pSMB->Flags = 0; |
| 5241 | pSMB->Timeout = 0; |
| 5242 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5243 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5244 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5245 | offset = param_offset + params; |
| 5246 | |
| 5247 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5248 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5249 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5250 | pSMB->SetupCount = 1; |
| 5251 | pSMB->Reserved3 = 0; |
| 5252 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5253 | byte_count = 1 /* pad */ + params + 12; |
| 5254 | |
| 5255 | pSMB->DataCount = cpu_to_le16(12); |
| 5256 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5257 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5258 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5259 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5260 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5261 | |
| 5262 | /* Params. */ |
| 5263 | pSMB->FileNum = 0; |
| 5264 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5265 | |
| 5266 | /* Data. */ |
| 5267 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5268 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5269 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5270 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5271 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5272 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5273 | |
| 5274 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5275 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5276 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5277 | cifs_dbg(VFS, "Send error in SETFSUnixInfo = %d\n", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5278 | } else { /* decode response */ |
| 5279 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5280 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5281 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5282 | } |
| 5283 | cifs_buf_release(pSMB); |
| 5284 | |
| 5285 | if (rc == -EAGAIN) |
| 5286 | goto SETFSUnixRetry; |
| 5287 | |
| 5288 | return rc; |
| 5289 | } |
| 5290 | |
| 5291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5292 | |
| 5293 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5294 | CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5295 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | { |
| 5297 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5298 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5299 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5300 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5301 | int rc = 0; |
| 5302 | int bytes_returned = 0; |
| 5303 | __u16 params, byte_count; |
| 5304 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5305 | cifs_dbg(FYI, "In QFSPosixInfo\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5306 | QFSPosixRetry: |
| 5307 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5308 | (void **) &pSMBr); |
| 5309 | if (rc) |
| 5310 | return rc; |
| 5311 | |
| 5312 | params = 2; /* level */ |
| 5313 | pSMB->TotalDataCount = 0; |
| 5314 | pSMB->DataCount = 0; |
| 5315 | pSMB->DataOffset = 0; |
| 5316 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5317 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5318 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | pSMB->MaxSetupCount = 0; |
| 5320 | pSMB->Reserved = 0; |
| 5321 | pSMB->Flags = 0; |
| 5322 | pSMB->Timeout = 0; |
| 5323 | pSMB->Reserved2 = 0; |
| 5324 | byte_count = params + 1 /* pad */ ; |
| 5325 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5326 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5327 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5328 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5329 | pSMB->SetupCount = 1; |
| 5330 | pSMB->Reserved3 = 0; |
| 5331 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5332 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5333 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5335 | |
| 5336 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5337 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5338 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5339 | cifs_dbg(FYI, "Send error in QFSUnixInfo = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5340 | } else { /* decode response */ |
| 5341 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5342 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5343 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | rc = -EIO; /* bad smb */ |
| 5345 | } else { |
| 5346 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5347 | response_data = |
| 5348 | (FILE_SYSTEM_POSIX_INFO |
| 5349 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5350 | data_offset); |
| 5351 | FSData->f_bsize = |
| 5352 | le32_to_cpu(response_data->BlockSize); |
| 5353 | FSData->f_blocks = |
| 5354 | le64_to_cpu(response_data->TotalBlocks); |
| 5355 | FSData->f_bfree = |
| 5356 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5357 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5358 | FSData->f_bavail = FSData->f_bfree; |
| 5359 | } else { |
| 5360 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5361 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5363 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5364 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5365 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5366 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5367 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5368 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | } |
| 5370 | } |
| 5371 | cifs_buf_release(pSMB); |
| 5372 | |
| 5373 | if (rc == -EAGAIN) |
| 5374 | goto QFSPosixRetry; |
| 5375 | |
| 5376 | return rc; |
| 5377 | } |
| 5378 | |
| 5379 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5380 | /* |
| 5381 | * We can not use write of zero bytes trick to set file size due to need for |
| 5382 | * large file support. Also note that this SetPathInfo is preferred to |
| 5383 | * SetFileInfo based method in next routine which is only needed to work around |
| 5384 | * a sharing violation bugin Samba which this routine can run into. |
| 5385 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5387 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5388 | const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, |
| 5389 | bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | { |
| 5391 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5392 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5393 | struct file_end_of_file_info *parm_data; |
| 5394 | int name_len; |
| 5395 | int rc = 0; |
| 5396 | int bytes_returned = 0; |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5397 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; |
| 5398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5399 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5400 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5401 | cifs_dbg(FYI, "In SetEOF\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5402 | SetEOFRetry: |
| 5403 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5404 | (void **) &pSMBr); |
| 5405 | if (rc) |
| 5406 | return rc; |
| 5407 | |
| 5408 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5409 | name_len = |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5410 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
| 5411 | PATH_MAX, cifs_sb->local_nls, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | name_len++; /* trailing null */ |
| 5413 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5414 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5415 | name_len = strnlen(file_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | name_len++; /* trailing null */ |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5417 | strncpy(pSMB->FileName, file_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5418 | } |
| 5419 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5420 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5422 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | pSMB->MaxSetupCount = 0; |
| 5424 | pSMB->Reserved = 0; |
| 5425 | pSMB->Flags = 0; |
| 5426 | pSMB->Timeout = 0; |
| 5427 | pSMB->Reserved2 = 0; |
| 5428 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5429 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5430 | offset = param_offset + params; |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5431 | if (set_allocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5432 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5433 | pSMB->InformationLevel = |
| 5434 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5435 | else |
| 5436 | pSMB->InformationLevel = |
| 5437 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5438 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5439 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5440 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5441 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5442 | else |
| 5443 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5444 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5445 | } |
| 5446 | |
| 5447 | parm_data = |
| 5448 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5449 | offset); |
| 5450 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5451 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5452 | pSMB->SetupCount = 1; |
| 5453 | pSMB->Reserved3 = 0; |
| 5454 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5455 | byte_count = 3 /* pad */ + params + data_count; |
| 5456 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5457 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5458 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5459 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5460 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5461 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5462 | parm_data->FileSize = cpu_to_le64(size); |
| 5463 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5464 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5465 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5466 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5467 | cifs_dbg(FYI, "SetPathInfo (file size) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5468 | |
| 5469 | cifs_buf_release(pSMB); |
| 5470 | |
| 5471 | if (rc == -EAGAIN) |
| 5472 | goto SetEOFRetry; |
| 5473 | |
| 5474 | return rc; |
| 5475 | } |
| 5476 | |
| 5477 | int |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5478 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
| 5479 | struct cifsFileInfo *cfile, __u64 size, bool set_allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | { |
| 5481 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5482 | struct file_end_of_file_info *parm_data; |
| 5483 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5484 | __u16 params, param_offset, offset, byte_count, count; |
| 5485 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5486 | cifs_dbg(FYI, "SetFileSize (via SetFileInfo) %lld\n", |
| 5487 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5488 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | if (rc) |
| 5491 | return rc; |
| 5492 | |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5493 | pSMB->hdr.Pid = cpu_to_le16((__u16)cfile->pid); |
| 5494 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(cfile->pid >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | params = 6; |
| 5497 | pSMB->MaxSetupCount = 0; |
| 5498 | pSMB->Reserved = 0; |
| 5499 | pSMB->Flags = 0; |
| 5500 | pSMB->Timeout = 0; |
| 5501 | pSMB->Reserved2 = 0; |
| 5502 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5503 | offset = param_offset + params; |
| 5504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | count = sizeof(struct file_end_of_file_info); |
| 5506 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5507 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5508 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | pSMB->SetupCount = 1; |
| 5510 | pSMB->Reserved3 = 0; |
| 5511 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5512 | byte_count = 3 /* pad */ + params + count; |
| 5513 | pSMB->DataCount = cpu_to_le16(count); |
| 5514 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5515 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5516 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5517 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5518 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5519 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5520 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5522 | parm_data->FileSize = cpu_to_le64(size); |
Pavel Shilovsky | d143341 | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5523 | pSMB->Fid = cfile->fid.netfid; |
| 5524 | if (set_allocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5526 | pSMB->InformationLevel = |
| 5527 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5528 | else |
| 5529 | pSMB->InformationLevel = |
| 5530 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5531 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5533 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5534 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5535 | else |
| 5536 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5537 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | } |
| 5539 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5540 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5541 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5542 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5544 | cifs_dbg(FYI, "Send error in SetFileInfo (SetFileSize) = %d\n", |
| 5545 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5546 | } |
| 5547 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5548 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | since file handle passed in no longer valid */ |
| 5550 | |
| 5551 | return rc; |
| 5552 | } |
| 5553 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5554 | /* 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] | 5555 | an open handle, rather than by pathname - this is awkward due to |
| 5556 | potential access conflicts on the open, but it is unavoidable for these |
| 5557 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5558 | time and resort to the original setpathinfo level which takes the ancient |
| 5559 | DOS time format with 2 second granularity */ |
| 5560 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5561 | CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5562 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5563 | { |
| 5564 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5565 | char *data_offset; |
| 5566 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | __u16 params, param_offset, offset, byte_count, count; |
| 5568 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5569 | cifs_dbg(FYI, "Set Times (via SetFileInfo)\n"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5570 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5572 | if (rc) |
| 5573 | return rc; |
| 5574 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5575 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5576 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | params = 6; |
| 5579 | pSMB->MaxSetupCount = 0; |
| 5580 | pSMB->Reserved = 0; |
| 5581 | pSMB->Flags = 0; |
| 5582 | pSMB->Timeout = 0; |
| 5583 | pSMB->Reserved2 = 0; |
| 5584 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5585 | offset = param_offset + params; |
| 5586 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5587 | data_offset = (char *)pSMB + |
| 5588 | offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5589 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5590 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5591 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5592 | /* BB find max SMB PDU from sess */ |
| 5593 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5594 | pSMB->SetupCount = 1; |
| 5595 | pSMB->Reserved3 = 0; |
| 5596 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5597 | byte_count = 3 /* pad */ + params + count; |
| 5598 | pSMB->DataCount = cpu_to_le16(count); |
| 5599 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5600 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5601 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5602 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5603 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5604 | pSMB->Fid = fid; |
| 5605 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5606 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5607 | else |
| 5608 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5609 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5610 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5611 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5612 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5613 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5614 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5615 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 5616 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5618 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | since file handle passed in no longer valid */ |
| 5620 | |
| 5621 | return rc; |
| 5622 | } |
| 5623 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5624 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5625 | CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5626 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5627 | { |
| 5628 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5629 | char *data_offset; |
| 5630 | int rc = 0; |
| 5631 | __u16 params, param_offset, offset, byte_count, count; |
| 5632 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5633 | cifs_dbg(FYI, "Set File Disposition (via SetFileInfo)\n"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5634 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5635 | |
| 5636 | if (rc) |
| 5637 | return rc; |
| 5638 | |
| 5639 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5640 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5641 | |
| 5642 | params = 6; |
| 5643 | pSMB->MaxSetupCount = 0; |
| 5644 | pSMB->Reserved = 0; |
| 5645 | pSMB->Flags = 0; |
| 5646 | pSMB->Timeout = 0; |
| 5647 | pSMB->Reserved2 = 0; |
| 5648 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5649 | offset = param_offset + params; |
| 5650 | |
| 5651 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5652 | |
| 5653 | count = 1; |
| 5654 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5655 | /* BB find max SMB PDU from sess */ |
| 5656 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5657 | pSMB->SetupCount = 1; |
| 5658 | pSMB->Reserved3 = 0; |
| 5659 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5660 | byte_count = 3 /* pad */ + params + count; |
| 5661 | pSMB->DataCount = cpu_to_le16(count); |
| 5662 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5663 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5664 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5665 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5666 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5667 | pSMB->Fid = fid; |
| 5668 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5669 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5670 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5671 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5672 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5673 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5674 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5675 | cifs_dbg(FYI, "Send error in SetFileDisposition = %d\n", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5676 | |
| 5677 | return rc; |
| 5678 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5679 | |
| 5680 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5681 | CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5682 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5683 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | { |
| 5685 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5686 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5687 | int name_len; |
| 5688 | int rc = 0; |
| 5689 | int bytes_returned = 0; |
| 5690 | char *data_offset; |
| 5691 | __u16 params, param_offset, offset, byte_count, count; |
| 5692 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5693 | cifs_dbg(FYI, "In SetTimes\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5694 | |
| 5695 | SetTimesRetry: |
| 5696 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5697 | (void **) &pSMBr); |
| 5698 | if (rc) |
| 5699 | return rc; |
| 5700 | |
| 5701 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5702 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5703 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5704 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5705 | name_len++; /* trailing null */ |
| 5706 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5707 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | name_len = strnlen(fileName, PATH_MAX); |
| 5709 | name_len++; /* trailing null */ |
| 5710 | strncpy(pSMB->FileName, fileName, name_len); |
| 5711 | } |
| 5712 | |
| 5713 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5714 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5716 | /* BB find max SMB PDU from sess structure BB */ |
| 5717 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | pSMB->MaxSetupCount = 0; |
| 5719 | pSMB->Reserved = 0; |
| 5720 | pSMB->Flags = 0; |
| 5721 | pSMB->Timeout = 0; |
| 5722 | pSMB->Reserved2 = 0; |
| 5723 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5724 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5725 | offset = param_offset + params; |
| 5726 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5727 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5728 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5729 | pSMB->SetupCount = 1; |
| 5730 | pSMB->Reserved3 = 0; |
| 5731 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5732 | byte_count = 3 /* pad */ + params + count; |
| 5733 | |
| 5734 | pSMB->DataCount = cpu_to_le16(count); |
| 5735 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5736 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5737 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5738 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5739 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5740 | else |
| 5741 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5742 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5743 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5744 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5746 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5747 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5748 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5749 | cifs_dbg(FYI, "SetPathInfo (times) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5750 | |
| 5751 | cifs_buf_release(pSMB); |
| 5752 | |
| 5753 | if (rc == -EAGAIN) |
| 5754 | goto SetTimesRetry; |
| 5755 | |
| 5756 | return rc; |
| 5757 | } |
| 5758 | |
| 5759 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5760 | /* Can be used to set attributes */ |
| 5761 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5762 | handling it anyway and NT4 was what we thought it would be needed for |
| 5763 | Do not delete it until we prove whether needed for Win9x though */ |
| 5764 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5765 | CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5766 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5767 | { |
| 5768 | SETATTR_REQ *pSMB = NULL; |
| 5769 | SETATTR_RSP *pSMBr = NULL; |
| 5770 | int rc = 0; |
| 5771 | int bytes_returned; |
| 5772 | int name_len; |
| 5773 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5774 | cifs_dbg(FYI, "In SetAttrLegacy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | |
| 5776 | SetAttrLgcyRetry: |
| 5777 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5778 | (void **) &pSMBr); |
| 5779 | if (rc) |
| 5780 | return rc; |
| 5781 | |
| 5782 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5783 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5784 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 5785 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 | name_len++; /* trailing null */ |
| 5787 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5788 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5789 | name_len = strnlen(fileName, PATH_MAX); |
| 5790 | name_len++; /* trailing null */ |
| 5791 | strncpy(pSMB->fileName, fileName, name_len); |
| 5792 | } |
| 5793 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5794 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5795 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5796 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5797 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5798 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5799 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5800 | cifs_dbg(FYI, "Error in LegacySetAttr = %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5801 | |
| 5802 | cifs_buf_release(pSMB); |
| 5803 | |
| 5804 | if (rc == -EAGAIN) |
| 5805 | goto SetAttrLgcyRetry; |
| 5806 | |
| 5807 | return rc; |
| 5808 | } |
| 5809 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5810 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5811 | static void |
| 5812 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5813 | const struct cifs_unix_set_info_args *args) |
| 5814 | { |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5815 | u64 uid = NO_CHANGE_64, gid = NO_CHANGE_64; |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5816 | u64 mode = args->mode; |
| 5817 | |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5818 | if (uid_valid(args->uid)) |
| 5819 | uid = from_kuid(&init_user_ns, args->uid); |
| 5820 | if (gid_valid(args->gid)) |
| 5821 | gid = from_kgid(&init_user_ns, args->gid); |
| 5822 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5823 | /* |
| 5824 | * Samba server ignores set of file size to zero due to bugs in some |
| 5825 | * older clients, but we should be precise - we use SetFileSize to |
| 5826 | * 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] | 5827 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5828 | * zero instead of -1 here |
| 5829 | */ |
| 5830 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5831 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5832 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5833 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5834 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
Eric W. Biederman | 49418b2 | 2013-02-06 00:57:56 -0800 | [diff] [blame] | 5835 | data_offset->Uid = cpu_to_le64(uid); |
| 5836 | data_offset->Gid = cpu_to_le64(gid); |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5837 | /* better to leave device as zero when it is */ |
| 5838 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5839 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5840 | data_offset->Permissions = cpu_to_le64(mode); |
| 5841 | |
| 5842 | if (S_ISREG(mode)) |
| 5843 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5844 | else if (S_ISDIR(mode)) |
| 5845 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 5846 | else if (S_ISLNK(mode)) |
| 5847 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 5848 | else if (S_ISCHR(mode)) |
| 5849 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 5850 | else if (S_ISBLK(mode)) |
| 5851 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 5852 | else if (S_ISFIFO(mode)) |
| 5853 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 5854 | else if (S_ISSOCK(mode)) |
| 5855 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5856 | } |
| 5857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5859 | CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5860 | const struct cifs_unix_set_info_args *args, |
| 5861 | u16 fid, u32 pid_of_opener) |
| 5862 | { |
| 5863 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5864 | char *data_offset; |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5865 | int rc = 0; |
| 5866 | u16 params, param_offset, offset, byte_count, count; |
| 5867 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5868 | cifs_dbg(FYI, "Set Unix Info (via SetFileInfo)\n"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5869 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5870 | |
| 5871 | if (rc) |
| 5872 | return rc; |
| 5873 | |
| 5874 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5875 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5876 | |
| 5877 | params = 6; |
| 5878 | pSMB->MaxSetupCount = 0; |
| 5879 | pSMB->Reserved = 0; |
| 5880 | pSMB->Flags = 0; |
| 5881 | pSMB->Timeout = 0; |
| 5882 | pSMB->Reserved2 = 0; |
| 5883 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5884 | offset = param_offset + params; |
| 5885 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5886 | data_offset = (char *)pSMB + |
| 5887 | offsetof(struct smb_hdr, Protocol) + offset; |
| 5888 | |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5889 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 5890 | |
| 5891 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5892 | /* BB find max SMB PDU from sess */ |
| 5893 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5894 | pSMB->SetupCount = 1; |
| 5895 | pSMB->Reserved3 = 0; |
| 5896 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5897 | byte_count = 3 /* pad */ + params + count; |
| 5898 | pSMB->DataCount = cpu_to_le16(count); |
| 5899 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5900 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5901 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5902 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5903 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5904 | pSMB->Fid = fid; |
| 5905 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5906 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5907 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5908 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5909 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5910 | cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5911 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5912 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5913 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5914 | cifs_dbg(FYI, "Send error in Set Time (SetFileInfo) = %d\n", |
| 5915 | rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5916 | |
| 5917 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 5918 | since file handle passed in no longer valid */ |
| 5919 | |
| 5920 | return rc; |
| 5921 | } |
| 5922 | |
| 5923 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 5924 | CIFSSMBUnixSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 5925 | const char *file_name, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5926 | const struct cifs_unix_set_info_args *args, |
| 5927 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5928 | { |
| 5929 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5930 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5931 | int name_len; |
| 5932 | int rc = 0; |
| 5933 | int bytes_returned = 0; |
| 5934 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5935 | __u16 params, param_offset, offset, count, byte_count; |
| 5936 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5937 | cifs_dbg(FYI, "In SetUID/GID/Mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5938 | setPermsRetry: |
| 5939 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5940 | (void **) &pSMBr); |
| 5941 | if (rc) |
| 5942 | return rc; |
| 5943 | |
| 5944 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5945 | name_len = |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 5946 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5947 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5948 | name_len++; /* trailing null */ |
| 5949 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5950 | } else { /* BB improve the check for buffer overruns BB */ |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 5951 | name_len = strnlen(file_name, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5952 | name_len++; /* trailing null */ |
Pavel Shilovsky | ff691e9 | 2012-07-13 14:04:46 +0400 | [diff] [blame] | 5953 | strncpy(pSMB->FileName, file_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5957 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5958 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5959 | /* BB find max SMB PDU from sess structure BB */ |
| 5960 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5961 | pSMB->MaxSetupCount = 0; |
| 5962 | pSMB->Reserved = 0; |
| 5963 | pSMB->Flags = 0; |
| 5964 | pSMB->Timeout = 0; |
| 5965 | pSMB->Reserved2 = 0; |
| 5966 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5967 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5968 | offset = param_offset + params; |
| 5969 | data_offset = |
| 5970 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 5971 | offset); |
| 5972 | memset(data_offset, 0, count); |
| 5973 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5974 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5975 | pSMB->SetupCount = 1; |
| 5976 | pSMB->Reserved3 = 0; |
| 5977 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5978 | byte_count = 3 /* pad */ + params + count; |
| 5979 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5980 | pSMB->DataCount = cpu_to_le16(count); |
| 5981 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5982 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5983 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5984 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5985 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5986 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5987 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5988 | |
| 5989 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5990 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5991 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5992 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 5993 | cifs_dbg(FYI, "SetPathInfo (perms) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5995 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5996 | if (rc == -EAGAIN) |
| 5997 | goto setPermsRetry; |
| 5998 | return rc; |
| 5999 | } |
| 6000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6001 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6002 | /* |
| 6003 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 6004 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 6005 | * it looks for that attribute name and stuffs that value into the EAData |
| 6006 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 6007 | * buffer. In both cases, the return value is either the length of the |
| 6008 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 6009 | * the data isn't copied to it, but the length is returned. |
| 6010 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6011 | ssize_t |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6012 | CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6013 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6014 | char *EAData, size_t buf_size, |
| 6015 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | { |
| 6017 | /* BB assumes one setup word */ |
| 6018 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6019 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 6020 | int rc = 0; |
| 6021 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6022 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6023 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6024 | struct fea *temp_fea; |
| 6025 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6026 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6027 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6028 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6030 | cifs_dbg(FYI, "In Query All EAs path %s\n", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6031 | QAllEAsRetry: |
| 6032 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6033 | (void **) &pSMBr); |
| 6034 | if (rc) |
| 6035 | return rc; |
| 6036 | |
| 6037 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6038 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6039 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6040 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6041 | list_len++; /* trailing null */ |
| 6042 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6043 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6044 | list_len = strnlen(searchName, PATH_MAX); |
| 6045 | list_len++; /* trailing null */ |
| 6046 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6047 | } |
| 6048 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6049 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6050 | pSMB->TotalDataCount = 0; |
| 6051 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6052 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6053 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6054 | pSMB->MaxSetupCount = 0; |
| 6055 | pSMB->Reserved = 0; |
| 6056 | pSMB->Flags = 0; |
| 6057 | pSMB->Timeout = 0; |
| 6058 | pSMB->Reserved2 = 0; |
| 6059 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6060 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6061 | pSMB->DataCount = 0; |
| 6062 | pSMB->DataOffset = 0; |
| 6063 | pSMB->SetupCount = 1; |
| 6064 | pSMB->Reserved3 = 0; |
| 6065 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6066 | byte_count = params + 1 /* pad */ ; |
| 6067 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6068 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6069 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6070 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6071 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6072 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6073 | |
| 6074 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6075 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6076 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6077 | cifs_dbg(FYI, "Send error in QueryAllEAs = %d\n", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6078 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6079 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6080 | |
| 6081 | |
| 6082 | /* BB also check enough total bytes returned */ |
| 6083 | /* BB we need to improve the validity checking |
| 6084 | of these trans2 responses */ |
| 6085 | |
| 6086 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6087 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6088 | rc = -EIO; /* bad smb */ |
| 6089 | goto QAllEAsOut; |
| 6090 | } |
| 6091 | |
| 6092 | /* check that length of list is not more than bcc */ |
| 6093 | /* check that each entry does not go beyond length |
| 6094 | of list */ |
| 6095 | /* check that each element of each entry does not |
| 6096 | go beyond end of list */ |
| 6097 | /* validate_trans2_offsets() */ |
| 6098 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6099 | |
| 6100 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6101 | ea_response_data = (struct fealist *) |
| 6102 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6103 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6104 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6105 | cifs_dbg(FYI, "ea length %d\n", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6106 | if (list_len <= 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6107 | cifs_dbg(FYI, "empty EA list returned from server\n"); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6108 | goto QAllEAsOut; |
| 6109 | } |
| 6110 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6111 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6112 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6113 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6114 | cifs_dbg(FYI, "EA list appears to go beyond SMB\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6115 | rc = -EIO; |
| 6116 | goto QAllEAsOut; |
| 6117 | } |
| 6118 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6119 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6120 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6121 | temp_fea = ea_response_data->list; |
| 6122 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6123 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6124 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6125 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6126 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6127 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6128 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6129 | /* make sure we can read name_len and value_len */ |
| 6130 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6131 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6132 | rc = -EIO; |
| 6133 | goto QAllEAsOut; |
| 6134 | } |
| 6135 | |
| 6136 | name_len = temp_fea->name_len; |
| 6137 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6138 | list_len -= name_len + 1 + value_len; |
| 6139 | if (list_len < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6140 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6141 | rc = -EIO; |
| 6142 | goto QAllEAsOut; |
| 6143 | } |
| 6144 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6145 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6146 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6147 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6148 | temp_ptr += name_len + 1; |
| 6149 | rc = value_len; |
| 6150 | if (buf_size == 0) |
| 6151 | goto QAllEAsOut; |
| 6152 | if ((size_t)value_len > buf_size) { |
| 6153 | rc = -ERANGE; |
| 6154 | goto QAllEAsOut; |
| 6155 | } |
| 6156 | memcpy(EAData, temp_ptr, value_len); |
| 6157 | goto QAllEAsOut; |
| 6158 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6159 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6160 | /* account for prefix user. and trailing null */ |
| 6161 | rc += (5 + 1 + name_len); |
| 6162 | if (rc < (int) buf_size) { |
| 6163 | memcpy(EAData, "user.", 5); |
| 6164 | EAData += 5; |
| 6165 | memcpy(EAData, temp_ptr, name_len); |
| 6166 | EAData += name_len; |
| 6167 | /* null terminate name */ |
| 6168 | *EAData = 0; |
| 6169 | ++EAData; |
| 6170 | } else if (buf_size == 0) { |
| 6171 | /* skip copy - calc size only */ |
| 6172 | } else { |
| 6173 | /* stop before overrun buffer */ |
| 6174 | rc = -ERANGE; |
| 6175 | break; |
| 6176 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6177 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6178 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6179 | temp_fea = (struct fea *)temp_ptr; |
| 6180 | } |
| 6181 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6182 | /* didn't find the named attribute */ |
| 6183 | if (ea_name) |
| 6184 | rc = -ENODATA; |
| 6185 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6186 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6187 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | if (rc == -EAGAIN) |
| 6189 | goto QAllEAsRetry; |
| 6190 | |
| 6191 | return (ssize_t)rc; |
| 6192 | } |
| 6193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6194 | int |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6195 | CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, |
| 6196 | const char *fileName, const char *ea_name, const void *ea_value, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6197 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 6198 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6199 | { |
| 6200 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6201 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6202 | struct fealist *parm_data; |
| 6203 | int name_len; |
| 6204 | int rc = 0; |
| 6205 | int bytes_returned = 0; |
| 6206 | __u16 params, param_offset, byte_count, offset, count; |
| 6207 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6208 | cifs_dbg(FYI, "In SetEA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6209 | SetEARetry: |
| 6210 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6211 | (void **) &pSMBr); |
| 6212 | if (rc) |
| 6213 | return rc; |
| 6214 | |
| 6215 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6216 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6217 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6218 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6219 | name_len++; /* trailing null */ |
| 6220 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6221 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6222 | name_len = strnlen(fileName, PATH_MAX); |
| 6223 | name_len++; /* trailing null */ |
| 6224 | strncpy(pSMB->FileName, fileName, name_len); |
| 6225 | } |
| 6226 | |
| 6227 | params = 6 + name_len; |
| 6228 | |
| 6229 | /* done calculating parms using name_len of file name, |
| 6230 | now use name_len to calculate length of ea name |
| 6231 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6232 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6233 | name_len = 0; |
| 6234 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6235 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6236 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6237 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6238 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6239 | /* BB find max SMB PDU from sess */ |
| 6240 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | pSMB->MaxSetupCount = 0; |
| 6242 | pSMB->Reserved = 0; |
| 6243 | pSMB->Flags = 0; |
| 6244 | pSMB->Timeout = 0; |
| 6245 | pSMB->Reserved2 = 0; |
| 6246 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6247 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6248 | offset = param_offset + params; |
| 6249 | pSMB->InformationLevel = |
| 6250 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6251 | |
| 6252 | parm_data = |
| 6253 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 6254 | offset); |
| 6255 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6256 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6257 | pSMB->SetupCount = 1; |
| 6258 | pSMB->Reserved3 = 0; |
| 6259 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6260 | byte_count = 3 /* pad */ + params + count; |
| 6261 | pSMB->DataCount = cpu_to_le16(count); |
| 6262 | parm_data->list_len = cpu_to_le32(count); |
| 6263 | parm_data->list[0].EA_flags = 0; |
| 6264 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6265 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6266 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6267 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6268 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | parm_data->list[0].name[name_len] = 0; |
| 6270 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6271 | /* caller ensures that ea_value_len is less than 64K but |
| 6272 | we need to ensure that it fits within the smb */ |
| 6273 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6274 | /*BB add length check to see if it would fit in |
| 6275 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6276 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6277 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6278 | memcpy(parm_data->list[0].name+name_len+1, |
| 6279 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6280 | |
| 6281 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6282 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6283 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6284 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6285 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6286 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6287 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6288 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6289 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6290 | cifs_dbg(FYI, "SetPathInfo (EA) returned %d\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | |
| 6292 | cifs_buf_release(pSMB); |
| 6293 | |
| 6294 | if (rc == -EAGAIN) |
| 6295 | goto SetEARetry; |
| 6296 | |
| 6297 | return rc; |
| 6298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6299 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6300 | |
| 6301 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 6302 | /* |
| 6303 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 6304 | * to allow network clients (such as Windows) to display updated |
| 6305 | * lists of files in directory listings automatically when |
| 6306 | * files are added by one user when another user has the |
| 6307 | * same directory open on their desktop. The Linux cifs kernel |
| 6308 | * client hooked into the kernel side of this interface for |
| 6309 | * the same reason, but ironically when the VFS moved from |
| 6310 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 6311 | * network file system clients (the most obvious use case |
| 6312 | * for notify interfaces is when multiple users can update |
| 6313 | * the contents of the same directory - exactly what network |
| 6314 | * file systems can do) although the server (Samba) could |
| 6315 | * still use it. For the short term we leave the worker |
| 6316 | * function ifdeffed out (below) until inotify is fixed |
| 6317 | * in the VFS to make it easier to plug in network file |
| 6318 | * system clients. If inotify turns out to be permanently |
| 6319 | * incompatible for network fs clients, we could instead simply |
| 6320 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 6321 | */ |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 6322 | int CIFSSMBNotify(const unsigned int xid, struct cifs_tcon *tcon, |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6323 | const int notify_subdirs, const __u16 netfid, |
| 6324 | __u32 filter, struct file *pfile, int multishot, |
| 6325 | const struct nls_table *nls_codepage) |
| 6326 | { |
| 6327 | int rc = 0; |
| 6328 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 6329 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 6330 | struct dir_notify_req *dnotify_req; |
| 6331 | int bytes_returned; |
| 6332 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6333 | cifs_dbg(FYI, "In CIFSSMBNotify for file handle %d\n", (int)netfid); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6334 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 6335 | (void **) &pSMBr); |
| 6336 | if (rc) |
| 6337 | return rc; |
| 6338 | |
| 6339 | pSMB->TotalParameterCount = 0 ; |
| 6340 | pSMB->TotalDataCount = 0; |
| 6341 | pSMB->MaxParameterCount = cpu_to_le32(2); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6342 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6343 | pSMB->MaxSetupCount = 4; |
| 6344 | pSMB->Reserved = 0; |
| 6345 | pSMB->ParameterOffset = 0; |
| 6346 | pSMB->DataCount = 0; |
| 6347 | pSMB->DataOffset = 0; |
| 6348 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 6349 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 6350 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6351 | if (notify_subdirs) |
| 6352 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 6353 | pSMB->Reserved2 = 0; |
| 6354 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 6355 | pSMB->Fid = netfid; /* file handle always le */ |
| 6356 | pSMB->ByteCount = 0; |
| 6357 | |
| 6358 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6359 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 6360 | CIFS_ASYNC_OP); |
| 6361 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 6362 | cifs_dbg(FYI, "Error in Notify = %d\n", rc); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6363 | } else { |
| 6364 | /* Add file to outstanding requests */ |
| 6365 | /* BB change to kmem cache alloc */ |
| 6366 | dnotify_req = kmalloc( |
| 6367 | sizeof(struct dir_notify_req), |
| 6368 | GFP_KERNEL); |
| 6369 | if (dnotify_req) { |
| 6370 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 6371 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 6372 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 6373 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 6374 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 6375 | dnotify_req->netfid = netfid; |
| 6376 | dnotify_req->pfile = pfile; |
| 6377 | dnotify_req->filter = filter; |
| 6378 | dnotify_req->multishot = multishot; |
| 6379 | spin_lock(&GlobalMid_Lock); |
| 6380 | list_add_tail(&dnotify_req->lhead, |
| 6381 | &GlobalDnotifyReqList); |
| 6382 | spin_unlock(&GlobalMid_Lock); |
| 6383 | } else |
| 6384 | rc = -ENOMEM; |
| 6385 | } |
| 6386 | cifs_buf_release(pSMB); |
| 6387 | return rc; |
| 6388 | } |
| 6389 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |