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 | |
Jeff Layton | 3cf003c | 2012-07-11 09:09:36 -0400 | [diff] [blame] | 89 | #ifdef CONFIG_HIGHMEM |
| 90 | /* |
| 91 | * On arches that have high memory, kmap address space is limited. By |
| 92 | * serializing the kmap operations on those arches, we ensure that we don't |
| 93 | * end up with a bunch of threads in writeback with partially mapped page |
| 94 | * arrays, stuck waiting for kmap to come back. That situation prevents |
| 95 | * progress and can deadlock. |
| 96 | */ |
| 97 | static DEFINE_MUTEX(cifs_kmap_mutex); |
| 98 | |
| 99 | static inline void |
| 100 | cifs_kmap_lock(void) |
| 101 | { |
| 102 | mutex_lock(&cifs_kmap_mutex); |
| 103 | } |
| 104 | |
| 105 | static inline void |
| 106 | cifs_kmap_unlock(void) |
| 107 | { |
| 108 | mutex_unlock(&cifs_kmap_mutex); |
| 109 | } |
| 110 | #else /* !CONFIG_HIGHMEM */ |
| 111 | #define cifs_kmap_lock() do { ; } while(0) |
| 112 | #define cifs_kmap_unlock() do { ; } while(0) |
| 113 | #endif /* CONFIG_HIGHMEM */ |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* Mark as invalid, all open files on tree connections since they |
| 116 | were closed when session to server was lost */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 117 | static void mark_open_files_invalid(struct cifs_tcon *pTcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
| 119 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 120 | struct list_head *tmp; |
| 121 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | /* list all files open on tree connection and mark them invalid */ |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 124 | spin_lock(&cifs_file_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | list_for_each_safe(tmp, tmp1, &pTcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 126 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 127 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 128 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 130 | spin_unlock(&cifs_file_list_lock); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 131 | /* BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 132 | to this tcon */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 135 | /* reconnect the socket, tcon, and smb session if needed */ |
| 136 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 137 | cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 138 | { |
Jeff Layton | c4a5534 | 2011-07-28 12:40:36 -0400 | [diff] [blame] | 139 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 140 | struct cifs_ses *ses; |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 141 | struct TCP_Server_Info *server; |
| 142 | struct nls_table *nls_codepage; |
| 143 | |
| 144 | /* |
| 145 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 146 | * tcp and smb session status done differently for those three - in the |
| 147 | * calling routine |
| 148 | */ |
| 149 | if (!tcon) |
| 150 | return 0; |
| 151 | |
| 152 | ses = tcon->ses; |
| 153 | server = ses->server; |
| 154 | |
| 155 | /* |
| 156 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 157 | * have tcon) are allowed as we start force umount |
| 158 | */ |
| 159 | if (tcon->tidStatus == CifsExiting) { |
| 160 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 161 | smb_command != SMB_COM_OPEN_ANDX && |
| 162 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 163 | cFYI(1, "can not send cmd %d while umounting", |
| 164 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 165 | return -ENODEV; |
| 166 | } |
| 167 | } |
| 168 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 169 | /* |
| 170 | * Give demultiplex thread up to 10 seconds to reconnect, should be |
| 171 | * greater than cifs socket timeout which is 7 seconds |
| 172 | */ |
| 173 | while (server->tcpStatus == CifsNeedReconnect) { |
| 174 | wait_event_interruptible_timeout(server->response_q, |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 175 | (server->tcpStatus != CifsNeedReconnect), 10 * HZ); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 176 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 177 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 178 | if (server->tcpStatus != CifsNeedReconnect) |
| 179 | break; |
| 180 | |
| 181 | /* |
| 182 | * on "soft" mounts we wait once. Hard mounts keep |
| 183 | * retrying until process is killed or server comes |
| 184 | * back on-line |
| 185 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 186 | if (!tcon->retry) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 187 | cFYI(1, "gave up waiting on reconnect in smb_init"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 188 | return -EHOSTDOWN; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 193 | return 0; |
| 194 | |
| 195 | nls_codepage = load_nls_default(); |
| 196 | |
| 197 | /* |
| 198 | * need to prevent multiple threads trying to simultaneously |
| 199 | * reconnect the same SMB session |
| 200 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 201 | mutex_lock(&ses->session_mutex); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 202 | rc = cifs_negotiate_protocol(0, ses); |
| 203 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 204 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 205 | |
| 206 | /* do we need to reconnect tcon? */ |
| 207 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 208 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 209 | goto out; |
| 210 | } |
| 211 | |
| 212 | mark_open_files_invalid(tcon); |
| 213 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 214 | mutex_unlock(&ses->session_mutex); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 215 | cFYI(1, "reconnect tcon rc = %d", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 216 | |
| 217 | if (rc) |
| 218 | goto out; |
| 219 | |
| 220 | /* |
| 221 | * FIXME: check if wsize needs updated due to negotiated smb buffer |
| 222 | * size shrinking |
| 223 | */ |
| 224 | atomic_inc(&tconInfoReconnectCount); |
| 225 | |
| 226 | /* tell server Unix caps we support */ |
| 227 | if (ses->capabilities & CAP_UNIX) |
| 228 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 229 | |
| 230 | /* |
| 231 | * Removed call to reopen open files here. It is safer (and faster) to |
| 232 | * reopen files one at a time as needed in read and write. |
| 233 | * |
| 234 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 235 | */ |
| 236 | |
| 237 | out: |
| 238 | /* |
| 239 | * Check if handle based operation so we know whether we can continue |
| 240 | * or not without returning to caller to reset file handle |
| 241 | */ |
| 242 | switch (smb_command) { |
| 243 | case SMB_COM_READ_ANDX: |
| 244 | case SMB_COM_WRITE_ANDX: |
| 245 | case SMB_COM_CLOSE: |
| 246 | case SMB_COM_FIND_CLOSE2: |
| 247 | case SMB_COM_LOCKING_ANDX: |
| 248 | rc = -EAGAIN; |
| 249 | } |
| 250 | |
| 251 | unload_nls(nls_codepage); |
| 252 | return rc; |
| 253 | } |
| 254 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 255 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 256 | SMB information in the SMB header. If the return code is zero, this |
| 257 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 259 | small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 260 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 262 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 264 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 265 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | return rc; |
| 267 | |
| 268 | *request_buf = cifs_small_buf_get(); |
| 269 | if (*request_buf == NULL) { |
| 270 | /* BB should we add a retry in here if not a writepage? */ |
| 271 | return -ENOMEM; |
| 272 | } |
| 273 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 274 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 275 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 277 | if (tcon != NULL) |
| 278 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 279 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 280 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 283 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 284 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 285 | struct cifs_ses *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 286 | { |
| 287 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 288 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 289 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 290 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 291 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 292 | return rc; |
| 293 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 294 | buffer = (struct smb_hdr *)*request_buf; |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 295 | buffer->Mid = get_next_mid(ses->server); |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 296 | if (ses->capabilities & CAP_UNICODE) |
| 297 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 298 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 299 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 300 | |
| 301 | /* uid, tid can stay at zero as set in header assemble */ |
| 302 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 303 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 304 | this function is used after 1st of session setup requests */ |
| 305 | |
| 306 | return rc; |
| 307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 310 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 311 | __smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 312 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | *request_buf = cifs_buf_get(); |
| 315 | if (*request_buf == NULL) { |
| 316 | /* BB should we add a retry in here if not a writepage? */ |
| 317 | return -ENOMEM; |
| 318 | } |
| 319 | /* Although the original thought was we needed the response buf for */ |
| 320 | /* potential retries of smb operations it turns out we can determine */ |
| 321 | /* from the mid flags when the request buffer can be resent without */ |
| 322 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 323 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 324 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 327 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 329 | if (tcon != NULL) |
| 330 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 331 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 336 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 337 | smb_init(int smb_command, int wct, struct cifs_tcon *tcon, |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 338 | void **request_buf, void **response_buf) |
| 339 | { |
| 340 | int rc; |
| 341 | |
| 342 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 343 | if (rc) |
| 344 | return rc; |
| 345 | |
| 346 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 347 | } |
| 348 | |
| 349 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 350 | 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] | 351 | void **request_buf, void **response_buf) |
| 352 | { |
| 353 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 354 | return -EHOSTDOWN; |
| 355 | |
| 356 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 359 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 361 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 363 | /* check for plausible wct */ |
| 364 | if (pSMB->hdr.WordCount < 10) |
| 365 | goto vt2_err; |
| 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 368 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 369 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 370 | goto vt2_err; |
| 371 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 372 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 373 | if (total_size >= 512) |
| 374 | goto vt2_err; |
| 375 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 376 | /* check that bcc is at least as big as parms + data, and that it is |
| 377 | * less than negotiated smb buffer |
| 378 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 379 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 380 | if (total_size > get_bcc(&pSMB->hdr) || |
| 381 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 382 | goto vt2_err; |
| 383 | |
| 384 | return 0; |
| 385 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 386 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 388 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 390 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 391 | static inline void inc_rfc1001_len(void *pSMB, int count) |
| 392 | { |
| 393 | struct smb_hdr *hdr = (struct smb_hdr *)pSMB; |
| 394 | |
| 395 | be32_add_cpu(&hdr->smb_buf_length, count); |
| 396 | } |
| 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 399 | CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
| 401 | NEGOTIATE_REQ *pSMB; |
| 402 | NEGOTIATE_RSP *pSMBr; |
| 403 | int rc = 0; |
| 404 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 405 | int i; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 406 | struct TCP_Server_Info *server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | u16 count; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 408 | unsigned int secFlags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 410 | if (ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | server = ses->server; |
| 412 | else { |
| 413 | rc = -EIO; |
| 414 | return rc; |
| 415 | } |
| 416 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 417 | (void **) &pSMB, (void **) &pSMBr); |
| 418 | if (rc) |
| 419 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 420 | |
| 421 | /* if any of auth flags (ie not sign or seal) are overriden use them */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 422 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 423 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 424 | else /* if override flags set only sign/seal OR them with global auth */ |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 425 | secFlags = global_secflags | ses->overrideSecFlg; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 426 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 427 | cFYI(1, "secFlags 0x%x", secFlags); |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 428 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 429 | pSMB->hdr.Mid = get_next_mid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 430 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 431 | |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 432 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 433 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 434 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 435 | cFYI(1, "Kerberos only mechanism, enable extended security"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 436 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Jeff Layton | b4d6fcf | 2011-01-07 11:30:28 -0500 | [diff] [blame] | 437 | } else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 438 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 439 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 440 | cFYI(1, "NTLMSSP only mechanism, enable extended security"); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 441 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 442 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 443 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 444 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 445 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 446 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 447 | count += strlen(protocols[i].name) + 1; |
| 448 | /* null at end of source and target buffers anyway */ |
| 449 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 450 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | pSMB->ByteCount = cpu_to_le16(count); |
| 452 | |
| 453 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 454 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 455 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 456 | goto neg_err_exit; |
| 457 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 458 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
| 459 | cFYI(1, "Dialect: %d", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 460 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 461 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 462 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 463 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 464 | could not negotiate a common dialect */ |
| 465 | rc = -EOPNOTSUPP; |
| 466 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 467 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 468 | } else if ((pSMBr->hdr.WordCount == 13) |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 469 | && ((server->dialect == LANMAN_PROT) |
| 470 | || (server->dialect == LANMAN2_PROT))) { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 471 | __s16 tmp; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 472 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 473 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 474 | if ((secFlags & CIFSSEC_MAY_LANMAN) || |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 475 | (secFlags & CIFSSEC_MAY_PLNTXT)) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 476 | server->secType = LANMAN; |
| 477 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 478 | cERROR(1, "mount failed weak security disabled" |
| 479 | " in /proc/fs/cifs/SecurityFlags"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 480 | rc = -EOPNOTSUPP; |
| 481 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 482 | } |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 483 | server->sec_mode = (__u8)le16_to_cpu(rsp->SecurityMode); |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 484 | server->maxReq = min_t(unsigned int, |
| 485 | le16_to_cpu(rsp->MaxMpxCount), |
| 486 | cifs_max_pending); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 487 | set_credits(server, server->maxReq); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 488 | server->maxBuf = le16_to_cpu(rsp->MaxBufSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 489 | server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 490 | /* even though we do not use raw we might as well set this |
| 491 | accurately, in case we ever find a need for it */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 492 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 493 | server->max_rw = 0xFF00; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 494 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 495 | } else { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 496 | server->max_rw = 0;/* do not need to use raw anyway */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 497 | server->capabilities = CAP_MPX_MODE; |
| 498 | } |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 499 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
Steve French | 1a70d65 | 2006-10-02 05:59:18 +0000 | [diff] [blame] | 500 | if (tmp == -1) { |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 501 | /* OS/2 often does not set timezone therefore |
| 502 | * we must use server time to calc time zone. |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 503 | * Could deviate slightly from the right zone. |
| 504 | * Smallest defined timezone difference is 15 minutes |
| 505 | * (i.e. Nepal). Rounding up/down is done to match |
| 506 | * this requirement. |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 507 | */ |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 508 | int val, seconds, remain, result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 509 | struct timespec ts, utc; |
| 510 | utc = CURRENT_TIME; |
Jeff Layton | c4a2c08 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 511 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 512 | rsp->SrvTime.Time, 0); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 513 | cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d", |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 514 | (int)ts.tv_sec, (int)utc.tv_sec, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 515 | (int)(utc.tv_sec - ts.tv_sec)); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 516 | val = (int)(utc.tv_sec - ts.tv_sec); |
Andre Haupt | 8594c15 | 2007-08-30 20:18:41 +0000 | [diff] [blame] | 517 | seconds = abs(val); |
Steve French | 947a506 | 2006-10-02 05:55:25 +0000 | [diff] [blame] | 518 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 519 | remain = seconds % MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 520 | if (remain >= (MIN_TZ_ADJ / 2)) |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 521 | result += MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 522 | if (val < 0) |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 523 | result = -result; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 524 | server->timeAdj = result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 525 | } else { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 526 | server->timeAdj = (int)tmp; |
| 527 | server->timeAdj *= 60; /* also in seconds */ |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 528 | } |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 529 | cFYI(1, "server->timeAdj: %d seconds", server->timeAdj); |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 530 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 531 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 532 | /* BB get server time for time conversions and add |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 533 | code to use it and timezone since this is not UTC */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 534 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 535 | if (rsp->EncryptionKeyLength == |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 536 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 537 | memcpy(ses->server->cryptkey, rsp->EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 538 | CIFS_CRYPTO_KEY_SIZE); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 539 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 540 | rc = -EIO; /* need cryptkey unless plain text */ |
| 541 | goto neg_err_exit; |
| 542 | } |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 543 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 544 | cFYI(1, "LANMAN negotiated"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 545 | /* we will not end up setting signing flags - as no signing |
| 546 | was in LANMAN and server did not return the flags on */ |
| 547 | goto signing_check; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 548 | #else /* weak security disabled */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 549 | } else if (pSMBr->hdr.WordCount == 13) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 550 | cERROR(1, "mount failed, cifs module not built " |
| 551 | "with CIFS_WEAK_PW_HASH support"); |
Dan Carpenter | 8212cf7 | 2010-03-15 11:22:26 +0300 | [diff] [blame] | 552 | rc = -EOPNOTSUPP; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 553 | #endif /* WEAK_PW_HASH */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 554 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 555 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 556 | /* unknown wct */ |
| 557 | rc = -EOPNOTSUPP; |
| 558 | goto neg_err_exit; |
| 559 | } |
| 560 | /* else wct == 17 NTLM */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 561 | server->sec_mode = pSMBr->SecurityMode; |
| 562 | if ((server->sec_mode & SECMODE_USER) == 0) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 563 | cFYI(1, "share mode security"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 564 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 565 | if ((server->sec_mode & SECMODE_PW_ENCRYPT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 566 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 567 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 568 | #endif /* CIFS_WEAK_PW_HASH */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 569 | cERROR(1, "Server requests plain text password" |
| 570 | " but client support disabled"); |
Steve French | 9312f67 | 2006-06-04 22:21:07 +0000 | [diff] [blame] | 571 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 572 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 573 | server->secType = NTLMv2; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 574 | else if (secFlags & CIFSSEC_MAY_NTLM) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 575 | server->secType = NTLM; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 576 | else if (secFlags & CIFSSEC_MAY_NTLMV2) |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 577 | server->secType = NTLMv2; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 578 | else if (secFlags & CIFSSEC_MAY_KRB5) |
| 579 | server->secType = Kerberos; |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 580 | else if (secFlags & CIFSSEC_MAY_NTLMSSP) |
Steve French | f46c723 | 2009-06-25 03:04:20 +0000 | [diff] [blame] | 581 | server->secType = RawNTLMSSP; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 582 | else if (secFlags & CIFSSEC_MAY_LANMAN) |
| 583 | server->secType = LANMAN; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 584 | else { |
| 585 | rc = -EOPNOTSUPP; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 586 | cERROR(1, "Invalid security type"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 587 | goto neg_err_exit; |
| 588 | } |
| 589 | /* else ... any others ...? */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 590 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 591 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 592 | little endian */ |
Pavel Shilovsky | 10b9b98 | 2012-03-20 12:55:09 +0300 | [diff] [blame] | 593 | server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), |
| 594 | cifs_max_pending); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 595 | set_credits(server, server->maxReq); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 596 | /* probably no need to store and check maxvcs */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 597 | server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 598 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 599 | cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 600 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 601 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 602 | server->timeAdj *= 60; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 603 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 604 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 605 | CIFS_CRYPTO_KEY_SIZE); |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 606 | } else if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC || |
| 607 | server->capabilities & CAP_EXTENDED_SECURITY) && |
| 608 | (pSMBr->EncryptionKeyLength == 0)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 609 | /* decode security blob */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 610 | count = get_bcc(&pSMBr->hdr); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 611 | if (count < 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | rc = -EIO; |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 613 | goto neg_err_exit; |
| 614 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 615 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 616 | if (server->srv_count > 1) { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 617 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 618 | if (memcmp(server->server_GUID, |
| 619 | pSMBr->u.extended_response. |
| 620 | GUID, 16) != 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 621 | cFYI(1, "server UID changed"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 622 | memcpy(server->server_GUID, |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 623 | pSMBr->u.extended_response.GUID, |
| 624 | 16); |
| 625 | } |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 626 | } else { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 627 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 628 | memcpy(server->server_GUID, |
| 629 | pSMBr->u.extended_response.GUID, 16); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 630 | } |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 631 | |
| 632 | if (count == 16) { |
| 633 | server->secType = RawNTLMSSP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 634 | } else { |
| 635 | rc = decode_negTokenInit(pSMBr->u.extended_response. |
Jeff Layton | 26efa0b | 2010-04-24 07:57:49 -0400 | [diff] [blame] | 636 | SecurityBlob, count - 16, |
| 637 | server); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 638 | if (rc == 1) |
Jeff Layton | e545937 | 2007-11-03 05:11:06 +0000 | [diff] [blame] | 639 | rc = 0; |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 640 | else |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 641 | rc = -EINVAL; |
Shirish Pargaonkar | 2b149f1 | 2010-09-18 22:02:18 -0500 | [diff] [blame] | 642 | if (server->secType == Kerberos) { |
| 643 | if (!server->sec_kerberos && |
| 644 | !server->sec_mskerberos) |
| 645 | rc = -EOPNOTSUPP; |
| 646 | } else if (server->secType == RawNTLMSSP) { |
| 647 | if (!server->sec_ntlmssp) |
| 648 | rc = -EOPNOTSUPP; |
| 649 | } else |
| 650 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 652 | } else if (server->sec_mode & SECMODE_PW_ENCRYPT) { |
Steve French | 07cc6cf | 2011-05-27 04:12:29 +0000 | [diff] [blame] | 653 | rc = -EIO; /* no crypt key only if plain text pwd */ |
| 654 | goto neg_err_exit; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 655 | } else |
| 656 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
| 657 | |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 658 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 659 | signing_check: |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 660 | #endif |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 661 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
| 662 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
| 663 | so if this is zero it means that signing is disabled */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 664 | cFYI(1, "Signing disabled"); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 665 | if (server->sec_mode & SECMODE_SIGN_REQUIRED) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 666 | cERROR(1, "Server requires " |
Jeff Layton | 7111d21 | 2007-10-16 16:50:25 +0000 | [diff] [blame] | 667 | "packet signing to be enabled in " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 668 | "/proc/fs/cifs/SecurityFlags."); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 669 | rc = -EOPNOTSUPP; |
| 670 | } |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 671 | server->sec_mode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 672 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 673 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
| 674 | /* signing required */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 675 | cFYI(1, "Must sign - secFlags 0x%x", secFlags); |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 676 | if ((server->sec_mode & |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 677 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 678 | cERROR(1, "signing required but server lacks support"); |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 679 | rc = -EOPNOTSUPP; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 680 | } else |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 681 | server->sec_mode |= SECMODE_SIGN_REQUIRED; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 682 | } else { |
| 683 | /* signing optional ie CIFSSEC_MAY_SIGN */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 684 | if ((server->sec_mode & SECMODE_SIGN_REQUIRED) == 0) |
| 685 | server->sec_mode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 686 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 688 | |
| 689 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 690 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 691 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 692 | cFYI(1, "negprot rc %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | return rc; |
| 694 | } |
| 695 | |
| 696 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 697 | CIFSSMBTDis(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | { |
| 699 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 702 | cFYI(1, "In tree disconnect"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 703 | |
| 704 | /* BB: do we need to check this? These should never be NULL. */ |
| 705 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 706 | return -EIO; |
| 707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 709 | * No need to return error on this operation if tid invalidated and |
| 710 | * closed on server already e.g. due to tcp session crashing. Also, |
| 711 | * the tcon is no longer on the list, so no need to take lock before |
| 712 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 714 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 715 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 717 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 718 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 719 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 721 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 722 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 724 | cFYI(1, "Tree disconnect failed %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 726 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 727 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | if (rc == -EAGAIN) |
| 729 | rc = 0; |
| 730 | |
| 731 | return rc; |
| 732 | } |
| 733 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 734 | /* |
| 735 | * This is a no-op for now. We're not really interested in the reply, but |
| 736 | * rather in the fact that the server sent one and that server->lstrp |
| 737 | * gets updated. |
| 738 | * |
| 739 | * FIXME: maybe we should consider checking that the reply matches request? |
| 740 | */ |
| 741 | static void |
| 742 | cifs_echo_callback(struct mid_q_entry *mid) |
| 743 | { |
| 744 | struct TCP_Server_Info *server = mid->callback_data; |
| 745 | |
| 746 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 747 | add_credits(server, 1); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | int |
| 751 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 752 | { |
| 753 | ECHO_REQ *smb; |
| 754 | int rc = 0; |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 755 | struct kvec iov; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 756 | |
| 757 | cFYI(1, "In echo request"); |
| 758 | |
| 759 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 760 | if (rc) |
| 761 | return rc; |
| 762 | |
| 763 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 764 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8f | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 765 | smb->hdr.WordCount = 1; |
| 766 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 767 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 768 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 769 | inc_rfc1001_len(smb, 3); |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 770 | iov.iov_base = smb; |
| 771 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 772 | |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 773 | rc = cifs_call_async(server, &iov, 1, NULL, cifs_echo_callback, |
| 774 | server, true); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 775 | if (rc) |
| 776 | cFYI(1, "Echo request failed: %d", rc); |
| 777 | |
| 778 | cifs_small_buf_release(smb); |
| 779 | |
| 780 | return rc; |
| 781 | } |
| 782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 784 | CIFSSMBLogoff(const int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | LOGOFF_ANDX_REQ *pSMB; |
| 787 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 789 | cFYI(1, "In SMBLogoff for session disconnect"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 790 | |
| 791 | /* |
| 792 | * BB: do we need to check validity of ses and server? They should |
| 793 | * always be valid since we have an active reference. If not, that |
| 794 | * should probably be a BUG() |
| 795 | */ |
| 796 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | return -EIO; |
| 798 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 799 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 800 | if (ses->need_reconnect) |
| 801 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 802 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 804 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 805 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | return rc; |
| 807 | } |
| 808 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 809 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 810 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 811 | if (ses->server->sec_mode & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 813 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | pSMB->hdr.Uid = ses->Suid; |
| 816 | |
| 817 | pSMB->AndXCommand = 0xFF; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 818 | rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 819 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 820 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
| 822 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 823 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | error */ |
| 825 | if (rc == -EAGAIN) |
| 826 | rc = 0; |
| 827 | return rc; |
| 828 | } |
| 829 | |
| 830 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 831 | CIFSPOSIXDelFile(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 832 | __u16 type, const struct nls_table *nls_codepage, int remap) |
| 833 | { |
| 834 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 835 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 836 | struct unlink_psx_rq *pRqD; |
| 837 | int name_len; |
| 838 | int rc = 0; |
| 839 | int bytes_returned = 0; |
| 840 | __u16 params, param_offset, offset, byte_count; |
| 841 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 842 | cFYI(1, "In POSIX delete"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 843 | PsxDelete: |
| 844 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 845 | (void **) &pSMBr); |
| 846 | if (rc) |
| 847 | return rc; |
| 848 | |
| 849 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 850 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 851 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 852 | PATH_MAX, nls_codepage, remap); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 853 | name_len++; /* trailing null */ |
| 854 | name_len *= 2; |
| 855 | } else { /* BB add path length overrun check */ |
| 856 | name_len = strnlen(fileName, PATH_MAX); |
| 857 | name_len++; /* trailing null */ |
| 858 | strncpy(pSMB->FileName, fileName, name_len); |
| 859 | } |
| 860 | |
| 861 | params = 6 + name_len; |
| 862 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 863 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 864 | pSMB->MaxSetupCount = 0; |
| 865 | pSMB->Reserved = 0; |
| 866 | pSMB->Flags = 0; |
| 867 | pSMB->Timeout = 0; |
| 868 | pSMB->Reserved2 = 0; |
| 869 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 870 | InformationLevel) - 4; |
| 871 | offset = param_offset + params; |
| 872 | |
| 873 | /* Setup pointer to Request Data (inode type) */ |
| 874 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 875 | pRqD->type = cpu_to_le16(type); |
| 876 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 877 | pSMB->DataOffset = cpu_to_le16(offset); |
| 878 | pSMB->SetupCount = 1; |
| 879 | pSMB->Reserved3 = 0; |
| 880 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 881 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 882 | |
| 883 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 884 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 885 | pSMB->ParameterCount = cpu_to_le16(params); |
| 886 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 887 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 888 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 889 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 890 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 891 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 892 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 893 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 894 | cFYI(1, "Posix delete returned %d", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 895 | cifs_buf_release(pSMB); |
| 896 | |
| 897 | cifs_stats_inc(&tcon->num_deletes); |
| 898 | |
| 899 | if (rc == -EAGAIN) |
| 900 | goto PsxDelete; |
| 901 | |
| 902 | return rc; |
| 903 | } |
| 904 | |
| 905 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 906 | CIFSSMBDelFile(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 907 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | { |
| 909 | DELETE_FILE_REQ *pSMB = NULL; |
| 910 | DELETE_FILE_RSP *pSMBr = NULL; |
| 911 | int rc = 0; |
| 912 | int bytes_returned; |
| 913 | int name_len; |
| 914 | |
| 915 | DelFileRetry: |
| 916 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 917 | (void **) &pSMBr); |
| 918 | if (rc) |
| 919 | return rc; |
| 920 | |
| 921 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 922 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 923 | cifsConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 924 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | name_len++; /* trailing null */ |
| 926 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 927 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | name_len = strnlen(fileName, PATH_MAX); |
| 929 | name_len++; /* trailing null */ |
| 930 | strncpy(pSMB->fileName, fileName, name_len); |
| 931 | } |
| 932 | pSMB->SearchAttributes = |
| 933 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 934 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 935 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 937 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 938 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 939 | cifs_stats_inc(&tcon->num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 940 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 941 | cFYI(1, "Error in RMFile = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | |
| 943 | cifs_buf_release(pSMB); |
| 944 | if (rc == -EAGAIN) |
| 945 | goto DelFileRetry; |
| 946 | |
| 947 | return rc; |
| 948 | } |
| 949 | |
| 950 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 951 | CIFSSMBRmDir(const int xid, struct cifs_tcon *tcon, const char *dirName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 952 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | { |
| 954 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 955 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 956 | int rc = 0; |
| 957 | int bytes_returned; |
| 958 | int name_len; |
| 959 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 960 | cFYI(1, "In CIFSSMBRmDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | RmDirRetry: |
| 962 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 963 | (void **) &pSMBr); |
| 964 | if (rc) |
| 965 | return rc; |
| 966 | |
| 967 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 968 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, dirName, |
| 969 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | name_len++; /* trailing null */ |
| 971 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 972 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | name_len = strnlen(dirName, PATH_MAX); |
| 974 | name_len++; /* trailing null */ |
| 975 | strncpy(pSMB->DirName, dirName, name_len); |
| 976 | } |
| 977 | |
| 978 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 979 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 981 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 982 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 983 | cifs_stats_inc(&tcon->num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 984 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 985 | cFYI(1, "Error in RMDir = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | |
| 987 | cifs_buf_release(pSMB); |
| 988 | if (rc == -EAGAIN) |
| 989 | goto RmDirRetry; |
| 990 | return rc; |
| 991 | } |
| 992 | |
| 993 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 994 | CIFSSMBMkDir(const int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 995 | const char *name, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | { |
| 997 | int rc = 0; |
| 998 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 999 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 1000 | int bytes_returned; |
| 1001 | int name_len; |
| 1002 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1003 | cFYI(1, "In CIFSSMBMkDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | MkDirRetry: |
| 1005 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 1006 | (void **) &pSMBr); |
| 1007 | if (rc) |
| 1008 | return rc; |
| 1009 | |
| 1010 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1011 | name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, |
| 1012 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | name_len++; /* trailing null */ |
| 1014 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1015 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | name_len = strnlen(name, PATH_MAX); |
| 1017 | name_len++; /* trailing null */ |
| 1018 | strncpy(pSMB->DirName, name, name_len); |
| 1019 | } |
| 1020 | |
| 1021 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1022 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1024 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1025 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1026 | cifs_stats_inc(&tcon->num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1027 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1028 | cFYI(1, "Error in Mkdir = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | cifs_buf_release(pSMB); |
| 1031 | if (rc == -EAGAIN) |
| 1032 | goto MkDirRetry; |
| 1033 | return rc; |
| 1034 | } |
| 1035 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1036 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1037 | CIFSPOSIXCreate(const int xid, struct cifs_tcon *tcon, __u32 posix_flags, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1038 | __u64 mode, __u16 *netfid, FILE_UNIX_BASIC_INFO *pRetData, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1039 | __u32 *pOplock, const char *name, |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1040 | const struct nls_table *nls_codepage, int remap) |
| 1041 | { |
| 1042 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1043 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1044 | int name_len; |
| 1045 | int rc = 0; |
| 1046 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1047 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1048 | OPEN_PSX_REQ *pdata; |
| 1049 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1050 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1051 | cFYI(1, "In POSIX Create"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1052 | PsxCreat: |
| 1053 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1054 | (void **) &pSMBr); |
| 1055 | if (rc) |
| 1056 | return rc; |
| 1057 | |
| 1058 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1059 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1060 | cifsConvertToUTF16((__le16 *) pSMB->FileName, name, |
| 1061 | PATH_MAX, nls_codepage, remap); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1062 | name_len++; /* trailing null */ |
| 1063 | name_len *= 2; |
| 1064 | } else { /* BB improve the check for buffer overruns BB */ |
| 1065 | name_len = strnlen(name, PATH_MAX); |
| 1066 | name_len++; /* trailing null */ |
| 1067 | strncpy(pSMB->FileName, name, name_len); |
| 1068 | } |
| 1069 | |
| 1070 | params = 6 + name_len; |
| 1071 | count = sizeof(OPEN_PSX_REQ); |
| 1072 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1073 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1074 | pSMB->MaxSetupCount = 0; |
| 1075 | pSMB->Reserved = 0; |
| 1076 | pSMB->Flags = 0; |
| 1077 | pSMB->Timeout = 0; |
| 1078 | pSMB->Reserved2 = 0; |
| 1079 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1080 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1081 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1082 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1083 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1084 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1085 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1086 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1087 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1088 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1089 | pSMB->SetupCount = 1; |
| 1090 | pSMB->Reserved3 = 0; |
| 1091 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1092 | byte_count = 3 /* pad */ + params + count; |
| 1093 | |
| 1094 | pSMB->DataCount = cpu_to_le16(count); |
| 1095 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1096 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1097 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1098 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1099 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1100 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1101 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1102 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1103 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1104 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1105 | cFYI(1, "Posix create returned %d", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1106 | goto psx_create_err; |
| 1107 | } |
| 1108 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1109 | cFYI(1, "copying inode info"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1110 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1111 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1112 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1113 | rc = -EIO; /* bad smb */ |
| 1114 | goto psx_create_err; |
| 1115 | } |
| 1116 | |
| 1117 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1118 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1119 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1120 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1121 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1122 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1123 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1124 | /* Let caller know file was created so we can set the mode. */ |
| 1125 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1126 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1127 | *pOplock |= CIFS_CREATE_ACTION; |
| 1128 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1129 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1130 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1131 | cFYI(DBG2, "unknown type"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1132 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1133 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1134 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1135 | cERROR(1, "Open response data too small"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1136 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1137 | goto psx_create_err; |
| 1138 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1139 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1140 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1141 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1142 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1143 | |
| 1144 | psx_create_err: |
| 1145 | cifs_buf_release(pSMB); |
| 1146 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1147 | if (posix_flags & SMB_O_DIRECTORY) |
| 1148 | cifs_stats_inc(&tcon->num_posixmkdirs); |
| 1149 | else |
| 1150 | cifs_stats_inc(&tcon->num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1151 | |
| 1152 | if (rc == -EAGAIN) |
| 1153 | goto PsxCreat; |
| 1154 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1155 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1158 | static __u16 convert_disposition(int disposition) |
| 1159 | { |
| 1160 | __u16 ofun = 0; |
| 1161 | |
| 1162 | switch (disposition) { |
| 1163 | case FILE_SUPERSEDE: |
| 1164 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1165 | break; |
| 1166 | case FILE_OPEN: |
| 1167 | ofun = SMBOPEN_OAPPEND; |
| 1168 | break; |
| 1169 | case FILE_CREATE: |
| 1170 | ofun = SMBOPEN_OCREATE; |
| 1171 | break; |
| 1172 | case FILE_OPEN_IF: |
| 1173 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1174 | break; |
| 1175 | case FILE_OVERWRITE: |
| 1176 | ofun = SMBOPEN_OTRUNC; |
| 1177 | break; |
| 1178 | case FILE_OVERWRITE_IF: |
| 1179 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1180 | break; |
| 1181 | default: |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1182 | cFYI(1, "unknown disposition %d", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1183 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1184 | } |
| 1185 | return ofun; |
| 1186 | } |
| 1187 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1188 | static int |
| 1189 | access_flags_to_smbopen_mode(const int access_flags) |
| 1190 | { |
| 1191 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1192 | |
| 1193 | if (masked_flags == GENERIC_READ) |
| 1194 | return SMBOPEN_READ; |
| 1195 | else if (masked_flags == GENERIC_WRITE) |
| 1196 | return SMBOPEN_WRITE; |
| 1197 | |
| 1198 | /* just go for read/write */ |
| 1199 | return SMBOPEN_READWRITE; |
| 1200 | } |
| 1201 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1202 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1203 | SMBLegacyOpen(const int xid, struct cifs_tcon *tcon, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1204 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1205 | const int access_flags, const int create_options, __u16 *netfid, |
| 1206 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1207 | const struct nls_table *nls_codepage, int remap) |
| 1208 | { |
| 1209 | int rc = -EACCES; |
| 1210 | OPENX_REQ *pSMB = NULL; |
| 1211 | OPENX_RSP *pSMBr = NULL; |
| 1212 | int bytes_returned; |
| 1213 | int name_len; |
| 1214 | __u16 count; |
| 1215 | |
| 1216 | OldOpenRetry: |
| 1217 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1218 | (void **) &pSMBr); |
| 1219 | if (rc) |
| 1220 | return rc; |
| 1221 | |
| 1222 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1223 | |
| 1224 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1225 | count = 1; /* account for one byte pad to word boundary */ |
| 1226 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1227 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1228 | fileName, PATH_MAX, nls_codepage, remap); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1229 | name_len++; /* trailing null */ |
| 1230 | name_len *= 2; |
| 1231 | } else { /* BB improve check for buffer overruns BB */ |
| 1232 | count = 0; /* no pad */ |
| 1233 | name_len = strnlen(fileName, PATH_MAX); |
| 1234 | name_len++; /* trailing null */ |
| 1235 | strncpy(pSMB->fileName, fileName, name_len); |
| 1236 | } |
| 1237 | if (*pOplock & REQ_OPLOCK) |
| 1238 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1239 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1240 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1241 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1242 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1243 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1244 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1245 | /* set file as system file if special file such |
| 1246 | as fifo and server expecting SFU style and |
| 1247 | no Unix extensions */ |
| 1248 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1249 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1250 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1251 | else /* BB FIXME BB */ |
| 1252 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1253 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1254 | if (create_options & CREATE_OPTION_READONLY) |
| 1255 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1256 | |
| 1257 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1258 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1259 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1260 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1261 | |
| 1262 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1263 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1264 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1265 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1266 | |
| 1267 | pSMB->ByteCount = cpu_to_le16(count); |
| 1268 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1269 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1270 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1271 | cifs_stats_inc(&tcon->num_opens); |
| 1272 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1273 | cFYI(1, "Error in Open = %d", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1274 | } else { |
| 1275 | /* BB verify if wct == 15 */ |
| 1276 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1277 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1278 | |
| 1279 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1280 | /* Let caller know file was created so we can set the mode. */ |
| 1281 | /* Do we care about the CreateAction in any other cases? */ |
| 1282 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1283 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1284 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1285 | /* BB FIXME END */ |
| 1286 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1287 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1288 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1289 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1290 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1291 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1292 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1293 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1294 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1295 | pfile_info->AllocationSize = |
| 1296 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1297 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1298 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1299 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | cifs_buf_release(pSMB); |
| 1304 | if (rc == -EAGAIN) |
| 1305 | goto OldOpenRetry; |
| 1306 | return rc; |
| 1307 | } |
| 1308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1310 | CIFSSMBOpen(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1312 | const int access_flags, const int create_options, __u16 *netfid, |
| 1313 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1314 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | { |
| 1316 | int rc = -EACCES; |
| 1317 | OPEN_REQ *pSMB = NULL; |
| 1318 | OPEN_RSP *pSMBr = NULL; |
| 1319 | int bytes_returned; |
| 1320 | int name_len; |
| 1321 | __u16 count; |
| 1322 | |
| 1323 | openRetry: |
| 1324 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, |
| 1325 | (void **) &pSMBr); |
| 1326 | if (rc) |
| 1327 | return rc; |
| 1328 | |
| 1329 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1330 | |
| 1331 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1332 | count = 1; /* account for one byte pad to word boundary */ |
| 1333 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 1334 | cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), |
| 1335 | fileName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | name_len++; /* trailing null */ |
| 1337 | name_len *= 2; |
| 1338 | pSMB->NameLength = cpu_to_le16(name_len); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1339 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | count = 0; /* no pad */ |
| 1341 | name_len = strnlen(fileName, PATH_MAX); |
| 1342 | name_len++; /* trailing null */ |
| 1343 | pSMB->NameLength = cpu_to_le16(name_len); |
| 1344 | strncpy(pSMB->fileName, fileName, name_len); |
| 1345 | } |
| 1346 | if (*pOplock & REQ_OPLOCK) |
| 1347 | pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1348 | else if (*pOplock & REQ_BATCHOPLOCK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | pSMB->DesiredAccess = cpu_to_le32(access_flags); |
| 1351 | pSMB->AllocationSize = 0; |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1352 | /* set file as system file if special file such |
| 1353 | as fifo and server expecting SFU style and |
| 1354 | no Unix extensions */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1355 | if (create_options & CREATE_OPTION_SPECIAL) |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1356 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1357 | else |
| 1358 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | /* XP does not handle ATTR_POSIX_SEMANTICS */ |
| 1361 | /* but it helps speed up case sensitive checks for other |
| 1362 | servers such as Samba */ |
| 1363 | if (tcon->ses->capabilities & CAP_UNIX) |
| 1364 | pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
| 1365 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1366 | if (create_options & CREATE_OPTION_READONLY) |
| 1367 | pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
| 1368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1370 | pSMB->CreateDisposition = cpu_to_le32(openDisposition); |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1371 | pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1372 | /* BB Expirement with various impersonation levels and verify */ |
| 1373 | pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | pSMB->SecurityFlags = |
| 1375 | SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY; |
| 1376 | |
| 1377 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1378 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
| 1380 | pSMB->ByteCount = cpu_to_le16(count); |
| 1381 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1382 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1383 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1384 | cifs_stats_inc(&tcon->num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1386 | cFYI(1, "Error in Open = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | } else { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1388 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1390 | /* Let caller know file was created so we can set the mode. */ |
| 1391 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1392 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1393 | *pOplock |= CIFS_CREATE_ACTION; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1394 | if (pfile_info) { |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1395 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
| 1396 | 36 /* CreationTime to Attributes */); |
| 1397 | /* the file_info buf is endian converted by caller */ |
| 1398 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
| 1399 | pfile_info->EndOfFile = pSMBr->EndOfFile; |
| 1400 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
| 1401 | pfile_info->DeletePending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | cifs_buf_release(pSMB); |
| 1406 | if (rc == -EAGAIN) |
| 1407 | goto openRetry; |
| 1408 | return rc; |
| 1409 | } |
| 1410 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1411 | /* |
| 1412 | * Discard any remaining data in the current SMB. To do this, we borrow the |
| 1413 | * current bigbuf. |
| 1414 | */ |
| 1415 | static int |
| 1416 | cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1417 | { |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1418 | unsigned int rfclen = get_rfc1002_length(server->smallbuf); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1419 | int remaining = rfclen + 4 - server->total_read; |
| 1420 | struct cifs_readdata *rdata = mid->callback_data; |
| 1421 | |
| 1422 | while (remaining > 0) { |
| 1423 | int length; |
| 1424 | |
| 1425 | length = cifs_read_from_socket(server, server->bigbuf, |
| 1426 | min_t(unsigned int, remaining, |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1427 | CIFSMaxBufSize + MAX_HEADER_SIZE(server))); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1428 | if (length < 0) |
| 1429 | return length; |
| 1430 | server->total_read += length; |
| 1431 | remaining -= length; |
| 1432 | } |
| 1433 | |
| 1434 | dequeue_mid(mid, rdata->result); |
| 1435 | return 0; |
| 1436 | } |
| 1437 | |
| 1438 | static int |
| 1439 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 1440 | { |
| 1441 | int length, len; |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1442 | unsigned int data_offset, data_len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1443 | struct cifs_readdata *rdata = mid->callback_data; |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1444 | char *buf = server->smallbuf; |
| 1445 | unsigned int buflen = get_rfc1002_length(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1446 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1447 | cFYI(1, "%s: mid=%llu offset=%llu bytes=%u", __func__, |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1448 | mid->mid, rdata->offset, rdata->bytes); |
| 1449 | |
| 1450 | /* |
| 1451 | * read the rest of READ_RSP header (sans Data array), or whatever we |
| 1452 | * can if there's not enough data. At this point, we've read down to |
| 1453 | * the Mid. |
| 1454 | */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1455 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1456 | HEADER_SIZE(server) + 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1457 | |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 1458 | rdata->iov[0].iov_base = buf + HEADER_SIZE(server) - 1; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1459 | rdata->iov[0].iov_len = len; |
| 1460 | |
| 1461 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); |
| 1462 | if (length < 0) |
| 1463 | return length; |
| 1464 | server->total_read += length; |
| 1465 | |
| 1466 | /* Was the SMB read successful? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1467 | rdata->result = server->ops->map_error(buf, false); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1468 | if (rdata->result != 0) { |
| 1469 | cFYI(1, "%s: server returned error %d", __func__, |
| 1470 | rdata->result); |
| 1471 | return cifs_readv_discard(server, mid); |
| 1472 | } |
| 1473 | |
| 1474 | /* 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] | 1475 | if (server->total_read < server->vals->read_rsp_size) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1476 | cFYI(1, "%s: server returned short header. got=%u expected=%zu", |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1477 | __func__, server->total_read, |
| 1478 | server->vals->read_rsp_size); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1479 | rdata->result = -EIO; |
| 1480 | return cifs_readv_discard(server, mid); |
| 1481 | } |
| 1482 | |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1483 | data_offset = server->ops->read_data_offset(buf) + 4; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1484 | if (data_offset < server->total_read) { |
| 1485 | /* |
| 1486 | * win2k8 sometimes sends an offset of 0 when the read |
| 1487 | * is beyond the EOF. Treat it as if the data starts just after |
| 1488 | * the header. |
| 1489 | */ |
| 1490 | cFYI(1, "%s: data offset (%u) inside read response header", |
| 1491 | __func__, data_offset); |
| 1492 | data_offset = server->total_read; |
| 1493 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1494 | /* data_offset is beyond the end of smallbuf */ |
| 1495 | cFYI(1, "%s: data offset (%u) beyond end of smallbuf", |
| 1496 | __func__, data_offset); |
| 1497 | rdata->result = -EIO; |
| 1498 | return cifs_readv_discard(server, mid); |
| 1499 | } |
| 1500 | |
| 1501 | cFYI(1, "%s: total_read=%u data_offset=%u", __func__, |
| 1502 | server->total_read, data_offset); |
| 1503 | |
| 1504 | len = data_offset - server->total_read; |
| 1505 | if (len > 0) { |
| 1506 | /* read any junk before data into the rest of smallbuf */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1507 | rdata->iov[0].iov_base = buf + server->total_read; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1508 | rdata->iov[0].iov_len = len; |
| 1509 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); |
| 1510 | if (length < 0) |
| 1511 | return length; |
| 1512 | server->total_read += length; |
| 1513 | } |
| 1514 | |
| 1515 | /* set up first iov for signature check */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1516 | rdata->iov[0].iov_base = buf; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1517 | rdata->iov[0].iov_len = server->total_read; |
| 1518 | cFYI(1, "0: iov_base=%p iov_len=%zu", |
| 1519 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); |
| 1520 | |
| 1521 | /* how much data is in the response? */ |
Pavel Shilovsky | eb37871 | 2012-05-17 13:02:51 +0400 | [diff] [blame] | 1522 | data_len = server->ops->read_data_length(buf); |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1523 | if (data_offset + data_len > buflen) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1524 | /* data_len is corrupt -- discard frame */ |
| 1525 | rdata->result = -EIO; |
| 1526 | return cifs_readv_discard(server, mid); |
| 1527 | } |
| 1528 | |
| 1529 | /* marshal up the page array */ |
Jeff Layton | 3cf003c | 2012-07-11 09:09:36 -0400 | [diff] [blame] | 1530 | cifs_kmap_lock(); |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1531 | len = rdata->marshal_iov(rdata, data_len); |
Jeff Layton | 3cf003c | 2012-07-11 09:09:36 -0400 | [diff] [blame] | 1532 | cifs_kmap_unlock(); |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1533 | data_len -= len; |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1534 | |
| 1535 | /* issue the read if we have any iovecs left to fill */ |
| 1536 | if (rdata->nr_iov > 1) { |
| 1537 | length = cifs_readv_from_socket(server, &rdata->iov[1], |
| 1538 | rdata->nr_iov - 1, len); |
| 1539 | if (length < 0) |
| 1540 | return length; |
| 1541 | server->total_read += length; |
| 1542 | } else { |
| 1543 | length = 0; |
| 1544 | } |
| 1545 | |
| 1546 | rdata->bytes = length; |
| 1547 | |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1548 | cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read, |
Jeff Layton | 8d5ce4d | 2012-05-16 07:13:16 -0400 | [diff] [blame] | 1549 | buflen, data_len); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1550 | |
| 1551 | /* discard anything left over */ |
Pavel Shilovsky | 5ffef7b | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1552 | if (server->total_read < buflen) |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1553 | return cifs_readv_discard(server, mid); |
| 1554 | |
| 1555 | dequeue_mid(mid, false); |
| 1556 | return length; |
| 1557 | } |
| 1558 | |
| 1559 | static void |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1560 | cifs_readv_callback(struct mid_q_entry *mid) |
| 1561 | { |
| 1562 | struct cifs_readdata *rdata = mid->callback_data; |
| 1563 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1564 | struct TCP_Server_Info *server = tcon->ses->server; |
| 1565 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1566 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, |
| 1567 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1568 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1569 | switch (mid->mid_state) { |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1570 | case MID_RESPONSE_RECEIVED: |
| 1571 | /* result already set, check signature */ |
| 1572 | if (server->sec_mode & |
| 1573 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
| 1574 | if (cifs_verify_signature(rdata->iov, rdata->nr_iov, |
| 1575 | server, mid->sequence_number + 1)) |
| 1576 | cERROR(1, "Unexpected SMB signature"); |
| 1577 | } |
| 1578 | /* FIXME: should this be counted toward the initiating task? */ |
| 1579 | task_io_account_read(rdata->bytes); |
| 1580 | cifs_stats_bytes_read(tcon, rdata->bytes); |
| 1581 | break; |
| 1582 | case MID_REQUEST_SUBMITTED: |
| 1583 | case MID_RETRY_NEEDED: |
| 1584 | rdata->result = -EAGAIN; |
| 1585 | break; |
| 1586 | default: |
| 1587 | rdata->result = -EIO; |
| 1588 | } |
| 1589 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 1590 | queue_work(cifsiod_wq, &rdata->work); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1591 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 1592 | add_credits(server, 1); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | /* cifs_async_readv - send an async write, and set up mid to handle result */ |
| 1596 | int |
| 1597 | cifs_async_readv(struct cifs_readdata *rdata) |
| 1598 | { |
| 1599 | int rc; |
| 1600 | READ_REQ *smb = NULL; |
| 1601 | int wct; |
| 1602 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 1603 | |
| 1604 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, |
| 1605 | rdata->offset, rdata->bytes); |
| 1606 | |
| 1607 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
| 1608 | wct = 12; |
| 1609 | else { |
| 1610 | wct = 10; /* old style read */ |
| 1611 | if ((rdata->offset >> 32) > 0) { |
| 1612 | /* can not handle this big offset for old */ |
| 1613 | return -EIO; |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb); |
| 1618 | if (rc) |
| 1619 | return rc; |
| 1620 | |
| 1621 | smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid); |
| 1622 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
| 1623 | |
| 1624 | smb->AndXCommand = 0xFF; /* none */ |
| 1625 | smb->Fid = rdata->cfile->netfid; |
| 1626 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
| 1627 | if (wct == 12) |
| 1628 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
| 1629 | smb->Remaining = 0; |
| 1630 | smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF); |
| 1631 | smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16); |
| 1632 | if (wct == 12) |
| 1633 | smb->ByteCount = 0; |
| 1634 | else { |
| 1635 | /* old style read */ |
| 1636 | struct smb_com_readx_req *smbr = |
| 1637 | (struct smb_com_readx_req *)smb; |
| 1638 | smbr->ByteCount = 0; |
| 1639 | } |
| 1640 | |
| 1641 | /* 4 for RFC1001 length + 1 for BCC */ |
| 1642 | rdata->iov[0].iov_base = smb; |
| 1643 | rdata->iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
| 1644 | |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1645 | kref_get(&rdata->refcount); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1646 | rc = cifs_call_async(tcon->ses->server, rdata->iov, 1, |
| 1647 | cifs_readv_receive, cifs_readv_callback, |
| 1648 | rdata, false); |
| 1649 | |
| 1650 | if (rc == 0) |
| 1651 | cifs_stats_inc(&tcon->num_reads); |
Jeff Layton | 6993f74 | 2012-05-16 07:13:17 -0400 | [diff] [blame] | 1652 | else |
| 1653 | kref_put(&rdata->refcount, cifs_readdata_release); |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 1654 | |
| 1655 | cifs_small_buf_release(smb); |
| 1656 | return rc; |
| 1657 | } |
| 1658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | int |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1660 | CIFSSMBRead(const int xid, struct cifs_io_parms *io_parms, unsigned int *nbytes, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1661 | char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | { |
| 1663 | int rc = -EACCES; |
| 1664 | READ_REQ *pSMB = NULL; |
| 1665 | READ_RSP *pSMBr = NULL; |
| 1666 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1667 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1668 | int resp_buf_type = 0; |
| 1669 | struct kvec iov[1]; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1670 | __u32 pid = io_parms->pid; |
| 1671 | __u16 netfid = io_parms->netfid; |
| 1672 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1673 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1674 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1676 | cFYI(1, "Reading %d bytes on fid %d", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1677 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1678 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1679 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1680 | wct = 10; /* old style read */ |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1681 | if ((offset >> 32) > 0) { |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1682 | /* can not handle this big offset for old */ |
| 1683 | return -EIO; |
| 1684 | } |
| 1685 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | |
| 1687 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1688 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | if (rc) |
| 1690 | return rc; |
| 1691 | |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1692 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1693 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | /* tcon and ses pointer are checked in smb_init */ |
| 1696 | if (tcon->ses->server == NULL) |
| 1697 | return -ECONNABORTED; |
| 1698 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1699 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | pSMB->Fid = netfid; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1701 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1702 | if (wct == 12) |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1703 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | pSMB->Remaining = 0; |
| 1706 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1707 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1708 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1709 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1710 | else { |
| 1711 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1712 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1713 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1714 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1715 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1716 | |
| 1717 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1718 | 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] | 1719 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1720 | &resp_buf_type, CIFS_LOG_ERROR); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1721 | cifs_stats_inc(&tcon->num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1722 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1724 | cERROR(1, "Send error in read = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | } else { |
| 1726 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1727 | data_length = data_length << 16; |
| 1728 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1729 | *nbytes = data_length; |
| 1730 | |
| 1731 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1732 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | || (data_length > count)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1734 | cFYI(1, "bad length %d for count %d", |
| 1735 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | rc = -EIO; |
| 1737 | *nbytes = 0; |
| 1738 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1739 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1740 | le16_to_cpu(pSMBr->DataOffset); |
| 1741 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1742 | cERROR(1, "Faulting on read rc = %d",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1743 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1744 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1745 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1746 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | } |
| 1748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1750 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1751 | if (*buf) { |
| 1752 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1753 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1754 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1755 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1756 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1757 | /* return buffer to caller to free */ |
| 1758 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1759 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1760 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1761 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1762 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1763 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1764 | |
| 1765 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | since file handle passed in no longer valid */ |
| 1767 | return rc; |
| 1768 | } |
| 1769 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1772 | CIFSSMBWrite(const int xid, struct cifs_io_parms *io_parms, |
| 1773 | unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1774 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | { |
| 1776 | int rc = -EACCES; |
| 1777 | WRITE_REQ *pSMB = NULL; |
| 1778 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1779 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | __u32 bytes_sent; |
| 1781 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1782 | __u32 pid = io_parms->pid; |
| 1783 | __u16 netfid = io_parms->netfid; |
| 1784 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1785 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1786 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1788 | *nbytes = 0; |
| 1789 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1790 | /* cFYI(1, "write at %lld %d bytes", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1791 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1792 | return -ECONNABORTED; |
| 1793 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1794 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1795 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1796 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1797 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1798 | if ((offset >> 32) > 0) { |
| 1799 | /* can not handle big offset for old srv */ |
| 1800 | return -EIO; |
| 1801 | } |
| 1802 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1803 | |
| 1804 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | (void **) &pSMBr); |
| 1806 | if (rc) |
| 1807 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 1808 | |
| 1809 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1810 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | /* tcon and ses pointer are checked in smb_init */ |
| 1813 | if (tcon->ses->server == NULL) |
| 1814 | return -ECONNABORTED; |
| 1815 | |
| 1816 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1817 | pSMB->Fid = netfid; |
| 1818 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1819 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1820 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | pSMB->Reserved = 0xFFFFFFFF; |
| 1823 | pSMB->WriteMode = 0; |
| 1824 | pSMB->Remaining = 0; |
| 1825 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1826 | /* 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] | 1827 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1828 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1829 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1830 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1832 | } else { |
| 1833 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1834 | & ~0xFF; |
| 1835 | } |
| 1836 | |
| 1837 | if (bytes_sent > count) |
| 1838 | bytes_sent = count; |
| 1839 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1840 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1841 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1842 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1843 | else if (ubuf) { |
| 1844 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | cifs_buf_release(pSMB); |
| 1846 | return -EFAULT; |
| 1847 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1848 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | /* No buffer */ |
| 1850 | cifs_buf_release(pSMB); |
| 1851 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1852 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1853 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1854 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1855 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1856 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1859 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1860 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1861 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1862 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1863 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1864 | else { /* old style write has byte count 4 bytes earlier |
| 1865 | so 4 bytes pad */ |
| 1866 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1867 | (struct smb_com_writex_req *)pSMB; |
| 1868 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1869 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | |
| 1871 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1872 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1873 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 1875 | cFYI(1, "Send error in write = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | } else { |
| 1877 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1878 | *nbytes = (*nbytes) << 16; |
| 1879 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1880 | |
| 1881 | /* |
| 1882 | * Mask off high 16 bits when bytes written as returned by the |
| 1883 | * server is greater than bytes requested by the client. Some |
| 1884 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1885 | */ |
| 1886 | if (*nbytes > count) |
| 1887 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | cifs_buf_release(pSMB); |
| 1891 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1892 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | since file handle passed in no longer valid */ |
| 1894 | |
| 1895 | return rc; |
| 1896 | } |
| 1897 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1898 | void |
| 1899 | cifs_writedata_release(struct kref *refcount) |
| 1900 | { |
| 1901 | struct cifs_writedata *wdata = container_of(refcount, |
| 1902 | struct cifs_writedata, refcount); |
| 1903 | |
| 1904 | if (wdata->cfile) |
| 1905 | cifsFileInfo_put(wdata->cfile); |
| 1906 | |
| 1907 | kfree(wdata); |
| 1908 | } |
| 1909 | |
| 1910 | /* |
| 1911 | * Write failed with a retryable error. Resend the write request. It's also |
| 1912 | * possible that the page was redirtied so re-clean the page. |
| 1913 | */ |
| 1914 | static void |
| 1915 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 1916 | { |
| 1917 | int i, rc; |
| 1918 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1919 | |
| 1920 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1921 | lock_page(wdata->pages[i]); |
| 1922 | clear_page_dirty_for_io(wdata->pages[i]); |
| 1923 | } |
| 1924 | |
| 1925 | do { |
| 1926 | rc = cifs_async_writev(wdata); |
| 1927 | } while (rc == -EAGAIN); |
| 1928 | |
| 1929 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1930 | if (rc != 0) |
| 1931 | SetPageError(wdata->pages[i]); |
| 1932 | unlock_page(wdata->pages[i]); |
| 1933 | } |
| 1934 | |
| 1935 | mapping_set_error(inode->i_mapping, rc); |
| 1936 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1937 | } |
| 1938 | |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 1939 | void |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1940 | cifs_writev_complete(struct work_struct *work) |
| 1941 | { |
| 1942 | struct cifs_writedata *wdata = container_of(work, |
| 1943 | struct cifs_writedata, work); |
| 1944 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1945 | int i = 0; |
| 1946 | |
| 1947 | if (wdata->result == 0) { |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1948 | spin_lock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1949 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
Jeff Layton | 597b027 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1950 | spin_unlock(&inode->i_lock); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1951 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 1952 | wdata->bytes); |
| 1953 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 1954 | return cifs_writev_requeue(wdata); |
| 1955 | |
| 1956 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1957 | struct page *page = wdata->pages[i]; |
| 1958 | if (wdata->result == -EAGAIN) |
| 1959 | __set_page_dirty_nobuffers(page); |
| 1960 | else if (wdata->result < 0) |
| 1961 | SetPageError(page); |
| 1962 | end_page_writeback(page); |
| 1963 | page_cache_release(page); |
| 1964 | } |
| 1965 | if (wdata->result != -EAGAIN) |
| 1966 | mapping_set_error(inode->i_mapping, wdata->result); |
| 1967 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1968 | } |
| 1969 | |
| 1970 | struct cifs_writedata * |
Jeff Layton | c2e8764 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 1971 | cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1972 | { |
| 1973 | struct cifs_writedata *wdata; |
| 1974 | |
| 1975 | /* this would overflow */ |
| 1976 | if (nr_pages == 0) { |
| 1977 | cERROR(1, "%s: called with nr_pages == 0!", __func__); |
| 1978 | return NULL; |
| 1979 | } |
| 1980 | |
| 1981 | /* writedata + number of page pointers */ |
| 1982 | wdata = kzalloc(sizeof(*wdata) + |
| 1983 | sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); |
| 1984 | if (wdata != NULL) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1985 | kref_init(&wdata->refcount); |
Jeff Layton | da82f7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1986 | INIT_LIST_HEAD(&wdata->list); |
| 1987 | init_completion(&wdata->done); |
| 1988 | INIT_WORK(&wdata->work, complete); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1989 | } |
| 1990 | return wdata; |
| 1991 | } |
| 1992 | |
| 1993 | /* |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1994 | * 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] | 1995 | * workqueue completion task. |
| 1996 | */ |
| 1997 | static void |
| 1998 | cifs_writev_callback(struct mid_q_entry *mid) |
| 1999 | { |
| 2000 | struct cifs_writedata *wdata = mid->callback_data; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2001 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2002 | unsigned int written; |
| 2003 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
| 2004 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 2005 | switch (mid->mid_state) { |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2006 | case MID_RESPONSE_RECEIVED: |
| 2007 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 2008 | if (wdata->result != 0) |
| 2009 | break; |
| 2010 | |
| 2011 | written = le16_to_cpu(smb->CountHigh); |
| 2012 | written <<= 16; |
| 2013 | written += le16_to_cpu(smb->Count); |
| 2014 | /* |
| 2015 | * Mask off high 16 bits when bytes written as returned |
| 2016 | * by the server is greater than bytes requested by the |
| 2017 | * client. OS/2 servers are known to set incorrect |
| 2018 | * CountHigh values. |
| 2019 | */ |
| 2020 | if (written > wdata->bytes) |
| 2021 | written &= 0xFFFF; |
| 2022 | |
| 2023 | if (written < wdata->bytes) |
| 2024 | wdata->result = -ENOSPC; |
| 2025 | else |
| 2026 | wdata->bytes = written; |
| 2027 | break; |
| 2028 | case MID_REQUEST_SUBMITTED: |
| 2029 | case MID_RETRY_NEEDED: |
| 2030 | wdata->result = -EAGAIN; |
| 2031 | break; |
| 2032 | default: |
| 2033 | wdata->result = -EIO; |
| 2034 | break; |
| 2035 | } |
| 2036 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 2037 | queue_work(cifsiod_wq, &wdata->work); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2038 | DeleteMidQEntry(mid); |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 2039 | add_credits(tcon->ses->server, 1); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 2043 | int |
| 2044 | cifs_async_writev(struct cifs_writedata *wdata) |
| 2045 | { |
| 2046 | int i, rc = -EACCES; |
| 2047 | WRITE_REQ *smb = NULL; |
| 2048 | int wct; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2049 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2050 | struct kvec *iov = NULL; |
| 2051 | |
| 2052 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 2053 | wct = 14; |
| 2054 | } else { |
| 2055 | wct = 12; |
| 2056 | if (wdata->offset >> 32 > 0) { |
| 2057 | /* can not handle big offset for old srv */ |
| 2058 | return -EIO; |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 2063 | if (rc) |
| 2064 | goto async_writev_out; |
| 2065 | |
| 2066 | /* 1 iov per page + 1 for header */ |
| 2067 | iov = kzalloc((wdata->nr_pages + 1) * sizeof(*iov), GFP_NOFS); |
| 2068 | if (iov == NULL) { |
| 2069 | rc = -ENOMEM; |
| 2070 | goto async_writev_out; |
| 2071 | } |
| 2072 | |
Jeff Layton | fe5f5d2 | 2012-03-23 14:40:55 -0400 | [diff] [blame] | 2073 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
| 2074 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2075 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2076 | smb->AndXCommand = 0xFF; /* none */ |
| 2077 | smb->Fid = wdata->cfile->netfid; |
| 2078 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 2079 | if (wct == 14) |
| 2080 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 2081 | smb->Reserved = 0xFFFFFFFF; |
| 2082 | smb->WriteMode = 0; |
| 2083 | smb->Remaining = 0; |
| 2084 | |
| 2085 | smb->DataOffset = |
| 2086 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 2087 | |
| 2088 | /* 4 for RFC1001 length + 1 for BCC */ |
| 2089 | iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; |
| 2090 | iov[0].iov_base = smb; |
| 2091 | |
Jeff Layton | e949287 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2092 | /* |
| 2093 | * This function should marshal up the page array into the kvec |
| 2094 | * array, reserving [0] for the header. It should kmap the pages |
| 2095 | * and set the iov_len properly for each one. It may also set |
| 2096 | * wdata->bytes too. |
| 2097 | */ |
Jeff Layton | 3cf003c | 2012-07-11 09:09:36 -0400 | [diff] [blame] | 2098 | cifs_kmap_lock(); |
Jeff Layton | e949287 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2099 | wdata->marshal_iov(iov, wdata); |
Jeff Layton | 3cf003c | 2012-07-11 09:09:36 -0400 | [diff] [blame] | 2100 | cifs_kmap_unlock(); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2101 | |
| 2102 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); |
| 2103 | |
| 2104 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 2105 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 2106 | |
| 2107 | if (wct == 14) { |
| 2108 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 2109 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 2110 | } else { |
| 2111 | /* wct == 12 */ |
| 2112 | struct smb_com_writex_req *smbw = |
| 2113 | (struct smb_com_writex_req *)smb; |
| 2114 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 2115 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
| 2116 | iov[0].iov_len += 4; /* pad bigger by four bytes */ |
| 2117 | } |
| 2118 | |
| 2119 | kref_get(&wdata->refcount); |
| 2120 | rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1, |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 2121 | NULL, cifs_writev_callback, wdata, false); |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 2122 | |
| 2123 | if (rc == 0) |
| 2124 | cifs_stats_inc(&tcon->num_writes); |
| 2125 | else |
| 2126 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 2127 | |
| 2128 | /* send is done, unmap pages */ |
| 2129 | for (i = 0; i < wdata->nr_pages; i++) |
| 2130 | kunmap(wdata->pages[i]); |
| 2131 | |
| 2132 | async_writev_out: |
| 2133 | cifs_small_buf_release(smb); |
| 2134 | kfree(iov); |
| 2135 | return rc; |
| 2136 | } |
| 2137 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2138 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2139 | CIFSSMBWrite2(const int xid, struct cifs_io_parms *io_parms, |
| 2140 | unsigned int *nbytes, struct kvec *iov, int n_vec, |
| 2141 | const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | { |
| 2143 | int rc = -EACCES; |
| 2144 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2145 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2146 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2147 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2148 | __u32 pid = io_parms->pid; |
| 2149 | __u16 netfid = io_parms->netfid; |
| 2150 | __u64 offset = io_parms->offset; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2151 | struct cifs_tcon *tcon = io_parms->tcon; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2152 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 2154 | *nbytes = 0; |
| 2155 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2156 | cFYI(1, "write2 at %lld %d bytes", (long long)offset, count); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2157 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2158 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2159 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2160 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2161 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 2162 | if ((offset >> 32) > 0) { |
| 2163 | /* can not handle big offset for old srv */ |
| 2164 | return -EIO; |
| 2165 | } |
| 2166 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2167 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | if (rc) |
| 2169 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame] | 2170 | |
| 2171 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 2172 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 2173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | /* tcon and ses pointer are checked in smb_init */ |
| 2175 | if (tcon->ses->server == NULL) |
| 2176 | return -ECONNABORTED; |
| 2177 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2178 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | pSMB->Fid = netfid; |
| 2180 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2181 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2182 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | pSMB->Reserved = 0xFFFFFFFF; |
| 2184 | pSMB->WriteMode = 0; |
| 2185 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2188 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2190 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 2191 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2192 | /* header + 1 byte pad */ |
| 2193 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2194 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2195 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2196 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2197 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2198 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2199 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 2200 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2201 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 2202 | (struct smb_com_writex_req *)pSMB; |
| 2203 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 2204 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2205 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2206 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2207 | iov[0].iov_len = smb_hdr_len + 4; |
| 2208 | else /* wct == 12 pad bigger by four bytes */ |
| 2209 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2210 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2211 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2212 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2213 | long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2214 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2216 | cFYI(1, "Send error Write2 = %d", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2217 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2218 | /* presumably this can not happen, but best to be safe */ |
| 2219 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2220 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2221 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2222 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 2223 | *nbytes = (*nbytes) << 16; |
| 2224 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 2225 | |
| 2226 | /* |
| 2227 | * Mask off high 16 bits when bytes written as returned by the |
| 2228 | * server is greater than bytes requested by the client. OS/2 |
| 2229 | * servers are known to set incorrect CountHigh values. |
| 2230 | */ |
| 2231 | if (*nbytes > count) |
| 2232 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2233 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 2235 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2236 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2237 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2238 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 2239 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2241 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | since file handle passed in no longer valid */ |
| 2243 | |
| 2244 | return rc; |
| 2245 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2246 | |
Pavel Shilovsky | 9ee305b | 2011-10-22 15:33:31 +0400 | [diff] [blame] | 2247 | int cifs_lockv(const int xid, struct cifs_tcon *tcon, const __u16 netfid, |
| 2248 | const __u8 lock_type, const __u32 num_unlock, |
| 2249 | const __u32 num_lock, LOCKING_ANDX_RANGE *buf) |
| 2250 | { |
| 2251 | int rc = 0; |
| 2252 | LOCK_REQ *pSMB = NULL; |
| 2253 | struct kvec iov[2]; |
| 2254 | int resp_buf_type; |
| 2255 | __u16 count; |
| 2256 | |
| 2257 | cFYI(1, "cifs_lockv num lock %d num unlock %d", num_lock, num_unlock); |
| 2258 | |
| 2259 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2260 | if (rc) |
| 2261 | return rc; |
| 2262 | |
| 2263 | pSMB->Timeout = 0; |
| 2264 | pSMB->NumberOfLocks = cpu_to_le16(num_lock); |
| 2265 | pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock); |
| 2266 | pSMB->LockType = lock_type; |
| 2267 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2268 | pSMB->Fid = netfid; /* netfid stays le */ |
| 2269 | |
| 2270 | count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2271 | inc_rfc1001_len(pSMB, count); |
| 2272 | pSMB->ByteCount = cpu_to_le16(count); |
| 2273 | |
| 2274 | iov[0].iov_base = (char *)pSMB; |
| 2275 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 - |
| 2276 | (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2277 | iov[1].iov_base = (char *)buf; |
| 2278 | iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE); |
| 2279 | |
| 2280 | cifs_stats_inc(&tcon->num_locks); |
| 2281 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP); |
| 2282 | if (rc) |
| 2283 | cFYI(1, "Send error in cifs_lockv = %d", rc); |
| 2284 | |
| 2285 | return rc; |
| 2286 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 2287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2289 | CIFSSMBLock(const int xid, struct cifs_tcon *tcon, |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2290 | const __u16 smb_file_id, const __u32 netpid, const __u64 len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2292 | const __u32 numLock, const __u8 lockType, |
| 2293 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | { |
| 2295 | int rc = 0; |
| 2296 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2297 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | int bytes_returned; |
| 2299 | int timeout = 0; |
| 2300 | __u16 count; |
| 2301 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2302 | cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 2303 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 2304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | if (rc) |
| 2306 | return rc; |
| 2307 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2308 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2309 | timeout = CIFS_ASYNC_OP; /* no response expected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2311 | } else if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2312 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 2314 | } else { |
| 2315 | pSMB->Timeout = 0; |
| 2316 | } |
| 2317 | |
| 2318 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 2319 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 2320 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 2321 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | pSMB->AndXCommand = 0xFF; /* none */ |
| 2323 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2324 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2325 | if ((numLock != 0) || (numUnlock != 0)) { |
Pavel Shilovsky | 03776f4 | 2010-08-17 11:26:00 +0400 | [diff] [blame] | 2326 | pSMB->Locks[0].Pid = cpu_to_le16(netpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | /* BB where to store pid high? */ |
| 2328 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2329 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2330 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2331 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2332 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2333 | } else { |
| 2334 | /* oplock break */ |
| 2335 | count = 0; |
| 2336 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2337 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | pSMB->ByteCount = cpu_to_le16(count); |
| 2339 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2340 | if (waitFlag) { |
| 2341 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2342 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2343 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2344 | } else { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2345 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, timeout); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2346 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2347 | } |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2348 | cifs_stats_inc(&tcon->num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2349 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2350 | cFYI(1, "Send error in Lock = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2352 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | since file handle passed in no longer valid */ |
| 2354 | return rc; |
| 2355 | } |
| 2356 | |
| 2357 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2358 | CIFSSMBPosixLock(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame^] | 2359 | const __u16 smb_file_id, const __u32 netpid, |
| 2360 | const loff_t start_offset, const __u64 len, |
| 2361 | struct file_lock *pLockData, const __u16 lock_type, |
| 2362 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2363 | { |
| 2364 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2365 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2366 | struct cifs_posix_lock *parm_data; |
| 2367 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2368 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2369 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2370 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2371 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2372 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2373 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2374 | cFYI(1, "Posix Lock"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2375 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2376 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2377 | |
| 2378 | if (rc) |
| 2379 | return rc; |
| 2380 | |
| 2381 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2382 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2383 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2384 | pSMB->MaxSetupCount = 0; |
| 2385 | pSMB->Reserved = 0; |
| 2386 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2387 | pSMB->Reserved2 = 0; |
| 2388 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2389 | offset = param_offset + params; |
| 2390 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2391 | count = sizeof(struct cifs_posix_lock); |
| 2392 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2393 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2394 | pSMB->SetupCount = 1; |
| 2395 | pSMB->Reserved3 = 0; |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame^] | 2396 | if (pLockData) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2397 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2398 | else |
| 2399 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2400 | byte_count = 3 /* pad */ + params + count; |
| 2401 | pSMB->DataCount = cpu_to_le16(count); |
| 2402 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2403 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2404 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2405 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2406 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2407 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2408 | |
| 2409 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2410 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2411 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2412 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2413 | pSMB->Timeout = cpu_to_le32(-1); |
| 2414 | } else |
| 2415 | pSMB->Timeout = 0; |
| 2416 | |
Pavel Shilovsky | 4f6bcec | 2011-10-22 15:33:30 +0400 | [diff] [blame] | 2417 | parm_data->pid = cpu_to_le32(netpid); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame^] | 2418 | parm_data->start = cpu_to_le64(start_offset); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2419 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2420 | |
| 2421 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2422 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2423 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2424 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2425 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2426 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2427 | if (waitFlag) { |
| 2428 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2429 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2430 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2431 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2432 | 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] | 2433 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 2434 | &resp_buf_type, timeout); |
| 2435 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 2436 | not try to free it twice below on exit */ |
| 2437 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2440 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2441 | cFYI(1, "Send error in Posix Lock = %d", rc); |
Jeff Layton | c5fd363 | 2012-07-23 13:28:37 -0400 | [diff] [blame^] | 2442 | } else if (pLockData) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2443 | /* lock structure can be returned on get */ |
| 2444 | __u16 data_offset; |
| 2445 | __u16 data_count; |
| 2446 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2447 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2448 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2449 | rc = -EIO; /* bad smb */ |
| 2450 | goto plk_err_exit; |
| 2451 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2452 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2453 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2454 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2455 | rc = -EIO; |
| 2456 | goto plk_err_exit; |
| 2457 | } |
| 2458 | parm_data = (struct cifs_posix_lock *) |
| 2459 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2460 | if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2461 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2462 | else { |
| 2463 | if (parm_data->lock_type == |
| 2464 | __constant_cpu_to_le16(CIFS_RDLCK)) |
| 2465 | pLockData->fl_type = F_RDLCK; |
| 2466 | else if (parm_data->lock_type == |
| 2467 | __constant_cpu_to_le16(CIFS_WRLCK)) |
| 2468 | pLockData->fl_type = F_WRLCK; |
| 2469 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2470 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2471 | pLockData->fl_end = pLockData->fl_start + |
| 2472 | le64_to_cpu(parm_data->length) - 1; |
| 2473 | pLockData->fl_pid = le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2474 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2475 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2476 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2477 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2478 | if (pSMB) |
| 2479 | cifs_small_buf_release(pSMB); |
| 2480 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2481 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 2482 | cifs_small_buf_release(iov[0].iov_base); |
| 2483 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 2484 | cifs_buf_release(iov[0].iov_base); |
| 2485 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2486 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2487 | since file handle passed in no longer valid */ |
| 2488 | |
| 2489 | return rc; |
| 2490 | } |
| 2491 | |
| 2492 | |
| 2493 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2494 | CIFSSMBClose(const int xid, struct cifs_tcon *tcon, int smb_file_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | { |
| 2496 | int rc = 0; |
| 2497 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2498 | cFYI(1, "In CIFSSMBClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | |
| 2500 | /* do not retry on dead session on close */ |
| 2501 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2502 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | return 0; |
| 2504 | if (rc) |
| 2505 | return rc; |
| 2506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2508 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2510 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2511 | cifs_stats_inc(&tcon->num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2513 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2515 | cERROR(1, "Send error in Close = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | } |
| 2517 | } |
| 2518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2520 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | rc = 0; |
| 2522 | |
| 2523 | return rc; |
| 2524 | } |
| 2525 | |
| 2526 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2527 | CIFSSMBFlush(const int xid, struct cifs_tcon *tcon, int smb_file_id) |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2528 | { |
| 2529 | int rc = 0; |
| 2530 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2531 | cFYI(1, "In CIFSSMBFlush"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2532 | |
| 2533 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2534 | if (rc) |
| 2535 | return rc; |
| 2536 | |
| 2537 | pSMB->FileID = (__u16) smb_file_id; |
| 2538 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 2539 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2540 | cifs_stats_inc(&tcon->num_flushes); |
| 2541 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2542 | cERROR(1, "Send error in Flush = %d", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2543 | |
| 2544 | return rc; |
| 2545 | } |
| 2546 | |
| 2547 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2548 | CIFSSMBRename(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2550 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | { |
| 2552 | int rc = 0; |
| 2553 | RENAME_REQ *pSMB = NULL; |
| 2554 | RENAME_RSP *pSMBr = NULL; |
| 2555 | int bytes_returned; |
| 2556 | int name_len, name_len2; |
| 2557 | __u16 count; |
| 2558 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2559 | cFYI(1, "In CIFSSMBRename"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | renameRetry: |
| 2561 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2562 | (void **) &pSMBr); |
| 2563 | if (rc) |
| 2564 | return rc; |
| 2565 | |
| 2566 | pSMB->BufferFormat = 0x04; |
| 2567 | pSMB->SearchAttributes = |
| 2568 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2569 | ATTR_DIRECTORY); |
| 2570 | |
| 2571 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2572 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2573 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, |
| 2574 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | name_len++; /* trailing null */ |
| 2576 | name_len *= 2; |
| 2577 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2578 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2579 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2580 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2581 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2582 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2584 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2585 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | name_len = strnlen(fromName, PATH_MAX); |
| 2587 | name_len++; /* trailing null */ |
| 2588 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2589 | name_len2 = strnlen(toName, PATH_MAX); |
| 2590 | name_len2++; /* trailing null */ |
| 2591 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2592 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2593 | name_len2++; /* trailing null */ |
| 2594 | name_len2++; /* signature byte */ |
| 2595 | } |
| 2596 | |
| 2597 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2598 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | pSMB->ByteCount = cpu_to_le16(count); |
| 2600 | |
| 2601 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2602 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2603 | cifs_stats_inc(&tcon->num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2604 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2605 | cFYI(1, "Send error in rename = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | cifs_buf_release(pSMB); |
| 2608 | |
| 2609 | if (rc == -EAGAIN) |
| 2610 | goto renameRetry; |
| 2611 | |
| 2612 | return rc; |
| 2613 | } |
| 2614 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2615 | int CIFSSMBRenameOpenFile(const int xid, struct cifs_tcon *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2616 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2617 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | { |
| 2619 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2620 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2621 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | char *data_offset; |
| 2623 | char dummy_string[30]; |
| 2624 | int rc = 0; |
| 2625 | int bytes_returned = 0; |
| 2626 | int len_of_str; |
| 2627 | __u16 params, param_offset, offset, count, byte_count; |
| 2628 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2629 | cFYI(1, "Rename to File by handle"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2631 | (void **) &pSMBr); |
| 2632 | if (rc) |
| 2633 | return rc; |
| 2634 | |
| 2635 | params = 6; |
| 2636 | pSMB->MaxSetupCount = 0; |
| 2637 | pSMB->Reserved = 0; |
| 2638 | pSMB->Flags = 0; |
| 2639 | pSMB->Timeout = 0; |
| 2640 | pSMB->Reserved2 = 0; |
| 2641 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2642 | offset = param_offset + params; |
| 2643 | |
| 2644 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2645 | rename_info = (struct set_file_rename *) data_offset; |
| 2646 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2647 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | pSMB->SetupCount = 1; |
| 2649 | pSMB->Reserved3 = 0; |
| 2650 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2651 | byte_count = 3 /* pad */ + params; |
| 2652 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2653 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2654 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2655 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2656 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2657 | rename_info->overwrite = cpu_to_le32(1); |
| 2658 | rename_info->root_fid = 0; |
| 2659 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2660 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2661 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2662 | len_of_str = |
| 2663 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2664 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | } else { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2666 | len_of_str = |
| 2667 | cifsConvertToUTF16((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2668 | target_name, PATH_MAX, nls_codepage, |
| 2669 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | } |
| 2671 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2672 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | byte_count += count; |
| 2674 | pSMB->DataCount = cpu_to_le16(count); |
| 2675 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2676 | pSMB->Fid = netfid; |
| 2677 | pSMB->InformationLevel = |
| 2678 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2679 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2680 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2682 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2683 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2684 | cifs_stats_inc(&pTcon->num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2685 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2686 | cFYI(1, "Send error in Rename (by file handle) = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | cifs_buf_release(pSMB); |
| 2689 | |
| 2690 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2691 | since file handle passed in no longer valid */ |
| 2692 | |
| 2693 | return rc; |
| 2694 | } |
| 2695 | |
| 2696 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2697 | CIFSSMBCopy(const int xid, struct cifs_tcon *tcon, const char *fromName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2698 | const __u16 target_tid, const char *toName, const int flags, |
| 2699 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | { |
| 2701 | int rc = 0; |
| 2702 | COPY_REQ *pSMB = NULL; |
| 2703 | COPY_RSP *pSMBr = NULL; |
| 2704 | int bytes_returned; |
| 2705 | int name_len, name_len2; |
| 2706 | __u16 count; |
| 2707 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2708 | cFYI(1, "In CIFSSMBCopy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | copyRetry: |
| 2710 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2711 | (void **) &pSMBr); |
| 2712 | if (rc) |
| 2713 | return rc; |
| 2714 | |
| 2715 | pSMB->BufferFormat = 0x04; |
| 2716 | pSMB->Tid2 = target_tid; |
| 2717 | |
| 2718 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2719 | |
| 2720 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2721 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
| 2722 | fromName, PATH_MAX, nls_codepage, |
| 2723 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | name_len++; /* trailing null */ |
| 2725 | name_len *= 2; |
| 2726 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2727 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2728 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2729 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2730 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2731 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2733 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2734 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | name_len = strnlen(fromName, PATH_MAX); |
| 2736 | name_len++; /* trailing null */ |
| 2737 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2738 | name_len2 = strnlen(toName, PATH_MAX); |
| 2739 | name_len2++; /* trailing null */ |
| 2740 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2741 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2742 | name_len2++; /* trailing null */ |
| 2743 | name_len2++; /* signature byte */ |
| 2744 | } |
| 2745 | |
| 2746 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2747 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | pSMB->ByteCount = cpu_to_le16(count); |
| 2749 | |
| 2750 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2751 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2752 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2753 | cFYI(1, "Send error in copy = %d with %d files copied", |
| 2754 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2756 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | |
| 2758 | if (rc == -EAGAIN) |
| 2759 | goto copyRetry; |
| 2760 | |
| 2761 | return rc; |
| 2762 | } |
| 2763 | |
| 2764 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2765 | CIFSUnixCreateSymLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | const char *fromName, const char *toName, |
| 2767 | const struct nls_table *nls_codepage) |
| 2768 | { |
| 2769 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2770 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2771 | char *data_offset; |
| 2772 | int name_len; |
| 2773 | int name_len_target; |
| 2774 | int rc = 0; |
| 2775 | int bytes_returned = 0; |
| 2776 | __u16 params, param_offset, offset, byte_count; |
| 2777 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2778 | cFYI(1, "In Symlink Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | createSymLinkRetry: |
| 2780 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2781 | (void **) &pSMBr); |
| 2782 | if (rc) |
| 2783 | return rc; |
| 2784 | |
| 2785 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2786 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2787 | cifs_strtoUTF16((__le16 *) pSMB->FileName, fromName, |
| 2788 | /* find define for this maxpathcomponent */ |
| 2789 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | name_len++; /* trailing null */ |
| 2791 | name_len *= 2; |
| 2792 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2793 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | name_len = strnlen(fromName, PATH_MAX); |
| 2795 | name_len++; /* trailing null */ |
| 2796 | strncpy(pSMB->FileName, fromName, name_len); |
| 2797 | } |
| 2798 | params = 6 + name_len; |
| 2799 | pSMB->MaxSetupCount = 0; |
| 2800 | pSMB->Reserved = 0; |
| 2801 | pSMB->Flags = 0; |
| 2802 | pSMB->Timeout = 0; |
| 2803 | pSMB->Reserved2 = 0; |
| 2804 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2805 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | offset = param_offset + params; |
| 2807 | |
| 2808 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2809 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2810 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2811 | cifs_strtoUTF16((__le16 *) data_offset, toName, PATH_MAX |
| 2812 | /* find define for this maxpathcomponent */ |
| 2813 | , nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | name_len_target++; /* trailing null */ |
| 2815 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2816 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | name_len_target = strnlen(toName, PATH_MAX); |
| 2818 | name_len_target++; /* trailing null */ |
| 2819 | strncpy(data_offset, toName, name_len_target); |
| 2820 | } |
| 2821 | |
| 2822 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2823 | /* BB find exact max on data count below from sess */ |
| 2824 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2825 | pSMB->SetupCount = 1; |
| 2826 | pSMB->Reserved3 = 0; |
| 2827 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2828 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2829 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2830 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2831 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2832 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2833 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2834 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2835 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2836 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2837 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2839 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2840 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2841 | cifs_stats_inc(&tcon->num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2842 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2843 | cFYI(1, "Send error in SetPathInfo create symlink = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2845 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | |
| 2847 | if (rc == -EAGAIN) |
| 2848 | goto createSymLinkRetry; |
| 2849 | |
| 2850 | return rc; |
| 2851 | } |
| 2852 | |
| 2853 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2854 | CIFSUnixCreateHardLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2856 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | { |
| 2858 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2859 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2860 | char *data_offset; |
| 2861 | int name_len; |
| 2862 | int name_len_target; |
| 2863 | int rc = 0; |
| 2864 | int bytes_returned = 0; |
| 2865 | __u16 params, param_offset, offset, byte_count; |
| 2866 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2867 | cFYI(1, "In Create Hard link Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | createHardLinkRetry: |
| 2869 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2870 | (void **) &pSMBr); |
| 2871 | if (rc) |
| 2872 | return rc; |
| 2873 | |
| 2874 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2875 | name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, |
| 2876 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | name_len++; /* trailing null */ |
| 2878 | name_len *= 2; |
| 2879 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2880 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | name_len = strnlen(toName, PATH_MAX); |
| 2882 | name_len++; /* trailing null */ |
| 2883 | strncpy(pSMB->FileName, toName, name_len); |
| 2884 | } |
| 2885 | params = 6 + name_len; |
| 2886 | pSMB->MaxSetupCount = 0; |
| 2887 | pSMB->Reserved = 0; |
| 2888 | pSMB->Flags = 0; |
| 2889 | pSMB->Timeout = 0; |
| 2890 | pSMB->Reserved2 = 0; |
| 2891 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2892 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | offset = param_offset + params; |
| 2894 | |
| 2895 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2896 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2897 | name_len_target = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2898 | cifsConvertToUTF16((__le16 *) data_offset, fromName, |
| 2899 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | name_len_target++; /* trailing null */ |
| 2901 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2902 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2904 | name_len_target++; /* trailing null */ |
| 2905 | strncpy(data_offset, fromName, name_len_target); |
| 2906 | } |
| 2907 | |
| 2908 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2909 | /* BB find exact max on data count below from sess*/ |
| 2910 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2911 | pSMB->SetupCount = 1; |
| 2912 | pSMB->Reserved3 = 0; |
| 2913 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2914 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2915 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2916 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2917 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2918 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2919 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2920 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2921 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2922 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2923 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2925 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2926 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2927 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2928 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2929 | cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | |
| 2931 | cifs_buf_release(pSMB); |
| 2932 | if (rc == -EAGAIN) |
| 2933 | goto createHardLinkRetry; |
| 2934 | |
| 2935 | return rc; |
| 2936 | } |
| 2937 | |
| 2938 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2939 | CIFSCreateHardLink(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2941 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | { |
| 2943 | int rc = 0; |
| 2944 | NT_RENAME_REQ *pSMB = NULL; |
| 2945 | RENAME_RSP *pSMBr = NULL; |
| 2946 | int bytes_returned; |
| 2947 | int name_len, name_len2; |
| 2948 | __u16 count; |
| 2949 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2950 | cFYI(1, "In CIFSCreateHardLink"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | winCreateHardLinkRetry: |
| 2952 | |
| 2953 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2954 | (void **) &pSMBr); |
| 2955 | if (rc) |
| 2956 | return rc; |
| 2957 | |
| 2958 | pSMB->SearchAttributes = |
| 2959 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2960 | ATTR_DIRECTORY); |
| 2961 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 2962 | pSMB->ClusterCount = 0; |
| 2963 | |
| 2964 | pSMB->BufferFormat = 0x04; |
| 2965 | |
| 2966 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2967 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2968 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, |
| 2969 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | name_len++; /* trailing null */ |
| 2971 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 2972 | |
| 2973 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 2974 | pSMB->OldFileName[name_len] = 0x04; |
| 2975 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | name_len2 = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 2977 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
| 2978 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2980 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2981 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | name_len = strnlen(fromName, PATH_MAX); |
| 2983 | name_len++; /* trailing null */ |
| 2984 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2985 | name_len2 = strnlen(toName, PATH_MAX); |
| 2986 | name_len2++; /* trailing null */ |
| 2987 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2988 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2989 | name_len2++; /* trailing null */ |
| 2990 | name_len2++; /* signature byte */ |
| 2991 | } |
| 2992 | |
| 2993 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2994 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | pSMB->ByteCount = cpu_to_le16(count); |
| 2996 | |
| 2997 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2998 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2999 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3000 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3001 | cFYI(1, "Send error in hard link (NT rename) = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | cifs_buf_release(pSMB); |
| 3004 | if (rc == -EAGAIN) |
| 3005 | goto winCreateHardLinkRetry; |
| 3006 | |
| 3007 | return rc; |
| 3008 | } |
| 3009 | |
| 3010 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3011 | CIFSSMBUnixQuerySymLink(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3012 | const unsigned char *searchName, char **symlinkinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | const struct nls_table *nls_codepage) |
| 3014 | { |
| 3015 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 3016 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3017 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3018 | int rc = 0; |
| 3019 | int bytes_returned; |
| 3020 | int name_len; |
| 3021 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3022 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3024 | cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | |
| 3026 | querySymLinkRetry: |
| 3027 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3028 | (void **) &pSMBr); |
| 3029 | if (rc) |
| 3030 | return rc; |
| 3031 | |
| 3032 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3033 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3034 | cifs_strtoUTF16((__le16 *) pSMB->FileName, searchName, |
| 3035 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | name_len++; /* trailing null */ |
| 3037 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3038 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | name_len = strnlen(searchName, PATH_MAX); |
| 3040 | name_len++; /* trailing null */ |
| 3041 | strncpy(pSMB->FileName, searchName, name_len); |
| 3042 | } |
| 3043 | |
| 3044 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3045 | pSMB->TotalDataCount = 0; |
| 3046 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 3047 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | pSMB->MaxSetupCount = 0; |
| 3049 | pSMB->Reserved = 0; |
| 3050 | pSMB->Flags = 0; |
| 3051 | pSMB->Timeout = 0; |
| 3052 | pSMB->Reserved2 = 0; |
| 3053 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3054 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | pSMB->DataCount = 0; |
| 3056 | pSMB->DataOffset = 0; |
| 3057 | pSMB->SetupCount = 1; |
| 3058 | pSMB->Reserved3 = 0; |
| 3059 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3060 | byte_count = params + 1 /* pad */ ; |
| 3061 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3062 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3063 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 3064 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3065 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3067 | |
| 3068 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3069 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3070 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3071 | cFYI(1, "Send error in QuerySymLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | } else { |
| 3073 | /* decode response */ |
| 3074 | |
| 3075 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3077 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3078 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3080 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3081 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3083 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 3084 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 3085 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 3086 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3087 | is_unicode = true; |
| 3088 | else |
| 3089 | is_unicode = false; |
| 3090 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3091 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3092 | *symlinkinfo = cifs_strndup_from_utf16(data_start, |
| 3093 | count, is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 3094 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 3095 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | } |
| 3097 | } |
| 3098 | cifs_buf_release(pSMB); |
| 3099 | if (rc == -EAGAIN) |
| 3100 | goto querySymLinkRetry; |
| 3101 | return rc; |
| 3102 | } |
| 3103 | |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3104 | #ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL |
| 3105 | /* |
| 3106 | * Recent Windows versions now create symlinks more frequently |
| 3107 | * and they use the "reparse point" mechanism below. We can of course |
| 3108 | * do symlinks nicely to Samba and other servers which support the |
| 3109 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 3110 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 3111 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 3112 | * In the interim this code has been moved to its own config option so |
| 3113 | * it is not compiled in by default until callers fixed up and more tested. |
| 3114 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3116 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3118 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | const struct nls_table *nls_codepage) |
| 3120 | { |
| 3121 | int rc = 0; |
| 3122 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3123 | struct smb_com_transaction_ioctl_req *pSMB; |
| 3124 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3126 | cFYI(1, "In Windows reparse style QueryLink for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 3128 | (void **) &pSMBr); |
| 3129 | if (rc) |
| 3130 | return rc; |
| 3131 | |
| 3132 | pSMB->TotalParameterCount = 0 ; |
| 3133 | pSMB->TotalDataCount = 0; |
| 3134 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 3135 | /* BB find exact data count max from sess structure BB */ |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3136 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | pSMB->MaxSetupCount = 4; |
| 3138 | pSMB->Reserved = 0; |
| 3139 | pSMB->ParameterOffset = 0; |
| 3140 | pSMB->DataCount = 0; |
| 3141 | pSMB->DataOffset = 0; |
| 3142 | pSMB->SetupCount = 4; |
| 3143 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 3144 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3145 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 3146 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 3147 | pSMB->IsRootFlag = 0; |
| 3148 | pSMB->Fid = fid; /* file handle always le */ |
| 3149 | pSMB->ByteCount = 0; |
| 3150 | |
| 3151 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3152 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3153 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3154 | cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | } else { /* decode response */ |
| 3156 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3157 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3158 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 3159 | /* BB also check enough total bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | rc = -EIO; /* bad smb */ |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3161 | goto qreparse_out; |
| 3162 | } |
| 3163 | if (data_count && (data_count < 2048)) { |
| 3164 | char *end_of_smb = 2 /* sizeof byte count */ + |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3165 | get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3167 | struct reparse_data *reparse_buf = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3168 | (struct reparse_data *) |
| 3169 | ((char *)&pSMBr->hdr.Protocol |
| 3170 | + data_offset); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3171 | if ((char *)reparse_buf >= end_of_smb) { |
| 3172 | rc = -EIO; |
| 3173 | goto qreparse_out; |
| 3174 | } |
| 3175 | if ((reparse_buf->LinkNamesBuf + |
| 3176 | reparse_buf->TargetNameOffset + |
| 3177 | reparse_buf->TargetNameLen) > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3178 | cFYI(1, "reparse buf beyond SMB"); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3179 | rc = -EIO; |
| 3180 | goto qreparse_out; |
| 3181 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3182 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3183 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3184 | cifs_from_ucs2(symlinkinfo, (__le16 *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3185 | (reparse_buf->LinkNamesBuf + |
| 3186 | reparse_buf->TargetNameOffset), |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3187 | buflen, |
| 3188 | reparse_buf->TargetNameLen, |
| 3189 | nls_codepage, 0); |
| 3190 | } else { /* ASCII names */ |
| 3191 | strncpy(symlinkinfo, |
| 3192 | reparse_buf->LinkNamesBuf + |
| 3193 | reparse_buf->TargetNameOffset, |
| 3194 | min_t(const int, buflen, |
| 3195 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3197 | } else { |
| 3198 | rc = -EIO; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3199 | cFYI(1, "Invalid return data count on " |
| 3200 | "get reparse info ioctl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 3202 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 3203 | does not go off the end of the buffer */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3204 | cFYI(1, "readlink result - %s", symlinkinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 3206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 3208 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | |
| 3210 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 3211 | since file handle passed in no longer valid */ |
| 3212 | |
| 3213 | return rc; |
| 3214 | } |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 3215 | #endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | |
| 3217 | #ifdef CONFIG_CIFS_POSIX |
| 3218 | |
| 3219 | /*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] | 3220 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 3221 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | { |
| 3223 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3224 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 3225 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 3226 | ace->e_id = cpu_to_le32(le64_to_cpu(cifs_ace->cifs_uid)); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3227 | /* cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | |
| 3229 | return; |
| 3230 | } |
| 3231 | |
| 3232 | /* 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] | 3233 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 3234 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | { |
| 3236 | int size = 0; |
| 3237 | int i; |
| 3238 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3239 | struct cifs_posix_ace *pACE; |
| 3240 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 3241 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | |
| 3243 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 3244 | return -EOPNOTSUPP; |
| 3245 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3246 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3248 | pACE = &cifs_acl->ace_array[0]; |
| 3249 | size = sizeof(struct cifs_posix_acl); |
| 3250 | size += sizeof(struct cifs_posix_ace) * count; |
| 3251 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3252 | if (size_of_data_area < size) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3253 | cFYI(1, "bad CIFS POSIX ACL size %d vs. %d", |
| 3254 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | return -EINVAL; |
| 3256 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3257 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 3259 | size = sizeof(struct cifs_posix_acl); |
| 3260 | size += sizeof(struct cifs_posix_ace) * count; |
| 3261 | /* skip past access ACEs to get to default ACEs */ |
| 3262 | pACE = &cifs_acl->ace_array[count]; |
| 3263 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 3264 | size += sizeof(struct cifs_posix_ace) * count; |
| 3265 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3266 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | return -EINVAL; |
| 3268 | } else { |
| 3269 | /* illegal type */ |
| 3270 | return -EINVAL; |
| 3271 | } |
| 3272 | |
| 3273 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3274 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3275 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3276 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | return -ERANGE; |
| 3278 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3279 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3280 | for (i = 0; i < count ; i++) { |
| 3281 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 3282 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | } |
| 3284 | } |
| 3285 | return size; |
| 3286 | } |
| 3287 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3288 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 3289 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | { |
| 3291 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 3292 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3293 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 3294 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3296 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 3298 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3299 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3300 | cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3301 | /*cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | return rc; |
| 3303 | } |
| 3304 | |
| 3305 | /* 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] | 3306 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 3307 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | { |
| 3309 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3310 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 3311 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | int count; |
| 3313 | int i; |
| 3314 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3315 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | return 0; |
| 3317 | |
| 3318 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3319 | cFYI(1, "setting acl with %d entries from buf of length %d and " |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 3320 | "version of %d", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3321 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3322 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3323 | cFYI(1, "unknown POSIX ACL version %d", |
| 3324 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | return 0; |
| 3326 | } |
| 3327 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3328 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3329 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3330 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3331 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3333 | cFYI(1, "unknown ACL type %d", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | return 0; |
| 3335 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3336 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 3338 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3339 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | /* ACE not converted */ |
| 3341 | break; |
| 3342 | } |
| 3343 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3344 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3346 | rc += sizeof(struct cifs_posix_acl); |
| 3347 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3348 | } |
| 3349 | return rc; |
| 3350 | } |
| 3351 | |
| 3352 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3353 | CIFSSMBGetPosixACL(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3354 | const unsigned char *searchName, |
| 3355 | char *acl_inf, const int buflen, const int acl_type, |
| 3356 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | { |
| 3358 | /* SMB_QUERY_POSIX_ACL */ |
| 3359 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3360 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3361 | int rc = 0; |
| 3362 | int bytes_returned; |
| 3363 | int name_len; |
| 3364 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3365 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3366 | cFYI(1, "In GetPosixACL (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | |
| 3368 | queryAclRetry: |
| 3369 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3370 | (void **) &pSMBr); |
| 3371 | if (rc) |
| 3372 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3375 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3376 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3377 | searchName, PATH_MAX, nls_codepage, |
| 3378 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | name_len++; /* trailing null */ |
| 3380 | name_len *= 2; |
| 3381 | pSMB->FileName[name_len] = 0; |
| 3382 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3383 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | name_len = strnlen(searchName, PATH_MAX); |
| 3385 | name_len++; /* trailing null */ |
| 3386 | strncpy(pSMB->FileName, searchName, name_len); |
| 3387 | } |
| 3388 | |
| 3389 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3390 | pSMB->TotalDataCount = 0; |
| 3391 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3392 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3394 | pSMB->MaxSetupCount = 0; |
| 3395 | pSMB->Reserved = 0; |
| 3396 | pSMB->Flags = 0; |
| 3397 | pSMB->Timeout = 0; |
| 3398 | pSMB->Reserved2 = 0; |
| 3399 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3400 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3401 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | pSMB->DataCount = 0; |
| 3403 | pSMB->DataOffset = 0; |
| 3404 | pSMB->SetupCount = 1; |
| 3405 | pSMB->Reserved3 = 0; |
| 3406 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3407 | byte_count = params + 1 /* pad */ ; |
| 3408 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3409 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3410 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3411 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3412 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3414 | |
| 3415 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3416 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3417 | cifs_stats_inc(&tcon->num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3419 | cFYI(1, "Send error in Query POSIX ACL = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | } else { |
| 3421 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3425 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | rc = -EIO; /* bad smb */ |
| 3427 | else { |
| 3428 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3429 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3430 | rc = cifs_copy_posix_acl(acl_inf, |
| 3431 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3432 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | } |
| 3434 | } |
| 3435 | cifs_buf_release(pSMB); |
| 3436 | if (rc == -EAGAIN) |
| 3437 | goto queryAclRetry; |
| 3438 | return rc; |
| 3439 | } |
| 3440 | |
| 3441 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3442 | CIFSSMBSetPosixACL(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3443 | const unsigned char *fileName, |
| 3444 | const char *local_acl, const int buflen, |
| 3445 | const int acl_type, |
| 3446 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | { |
| 3448 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3449 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3450 | char *parm_data; |
| 3451 | int name_len; |
| 3452 | int rc = 0; |
| 3453 | int bytes_returned = 0; |
| 3454 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3455 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3456 | cFYI(1, "In SetPosixACL (Unix) for path %s", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | setAclRetry: |
| 3458 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3459 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | if (rc) |
| 3461 | return rc; |
| 3462 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3463 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3464 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 3465 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | name_len++; /* trailing null */ |
| 3467 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3468 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | name_len = strnlen(fileName, PATH_MAX); |
| 3470 | name_len++; /* trailing null */ |
| 3471 | strncpy(pSMB->FileName, fileName, name_len); |
| 3472 | } |
| 3473 | params = 6 + name_len; |
| 3474 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3475 | /* BB find max SMB size from sess */ |
| 3476 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | pSMB->MaxSetupCount = 0; |
| 3478 | pSMB->Reserved = 0; |
| 3479 | pSMB->Flags = 0; |
| 3480 | pSMB->Timeout = 0; |
| 3481 | pSMB->Reserved2 = 0; |
| 3482 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3483 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | offset = param_offset + params; |
| 3485 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3486 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3487 | |
| 3488 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3489 | 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] | 3490 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3491 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | rc = -EOPNOTSUPP; |
| 3493 | goto setACLerrorExit; |
| 3494 | } |
| 3495 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3496 | pSMB->SetupCount = 1; |
| 3497 | pSMB->Reserved3 = 0; |
| 3498 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3499 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3500 | byte_count = 3 /* pad */ + params + data_count; |
| 3501 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3502 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3503 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3504 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3505 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3506 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3508 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3509 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3510 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3511 | cFYI(1, "Set POSIX ACL returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | |
| 3513 | setACLerrorExit: |
| 3514 | cifs_buf_release(pSMB); |
| 3515 | if (rc == -EAGAIN) |
| 3516 | goto setAclRetry; |
| 3517 | return rc; |
| 3518 | } |
| 3519 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3520 | /* BB fix tabs in this function FIXME BB */ |
| 3521 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3522 | CIFSGetExtAttr(const int xid, struct cifs_tcon *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3523 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3524 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3525 | int rc = 0; |
| 3526 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3527 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3528 | int bytes_returned; |
| 3529 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3530 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3531 | cFYI(1, "In GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3532 | if (tcon == NULL) |
| 3533 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3534 | |
| 3535 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3536 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3537 | (void **) &pSMBr); |
| 3538 | if (rc) |
| 3539 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3540 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3541 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3542 | pSMB->t2.TotalDataCount = 0; |
| 3543 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3544 | /* BB find exact max data count below from sess structure BB */ |
| 3545 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3546 | pSMB->t2.MaxSetupCount = 0; |
| 3547 | pSMB->t2.Reserved = 0; |
| 3548 | pSMB->t2.Flags = 0; |
| 3549 | pSMB->t2.Timeout = 0; |
| 3550 | pSMB->t2.Reserved2 = 0; |
| 3551 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3552 | Fid) - 4); |
| 3553 | pSMB->t2.DataCount = 0; |
| 3554 | pSMB->t2.DataOffset = 0; |
| 3555 | pSMB->t2.SetupCount = 1; |
| 3556 | pSMB->t2.Reserved3 = 0; |
| 3557 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3558 | byte_count = params + 1 /* pad */ ; |
| 3559 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3560 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3561 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3562 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3563 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3564 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3565 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3566 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3567 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3568 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3569 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3570 | cFYI(1, "error %d in GetExtAttr", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3571 | } else { |
| 3572 | /* decode response */ |
| 3573 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3574 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3575 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3576 | /* If rc should we check for EOPNOSUPP and |
| 3577 | disable the srvino flag? or in caller? */ |
| 3578 | rc = -EIO; /* bad smb */ |
| 3579 | else { |
| 3580 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3581 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3582 | struct file_chattr_info *pfinfo; |
| 3583 | /* BB Do we need a cast or hash here ? */ |
| 3584 | if (count != 16) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3585 | cFYI(1, "Illegal size ret in GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3586 | rc = -EIO; |
| 3587 | goto GetExtAttrOut; |
| 3588 | } |
| 3589 | pfinfo = (struct file_chattr_info *) |
| 3590 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3591 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3592 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3593 | } |
| 3594 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3595 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3596 | cifs_buf_release(pSMB); |
| 3597 | if (rc == -EAGAIN) |
| 3598 | goto GetExtAttrRetry; |
| 3599 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3602 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3604 | #ifdef CONFIG_CIFS_ACL |
| 3605 | /* |
| 3606 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3607 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3608 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3609 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3610 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3611 | * by caller |
| 3612 | */ |
| 3613 | static int |
| 3614 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3615 | const int parm_len, struct cifs_tcon *tcon, |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3616 | void **ret_buf) |
| 3617 | { |
| 3618 | int rc; |
| 3619 | __u32 temp_offset; |
| 3620 | struct smb_com_ntransact_req *pSMB; |
| 3621 | |
| 3622 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3623 | (void **)&pSMB); |
| 3624 | if (rc) |
| 3625 | return rc; |
| 3626 | *ret_buf = (void *)pSMB; |
| 3627 | pSMB->Reserved = 0; |
| 3628 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3629 | pSMB->TotalDataCount = 0; |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 3630 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3631 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3632 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3633 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3634 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3635 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3636 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3637 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3638 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3639 | return 0; |
| 3640 | } |
| 3641 | |
| 3642 | static int |
| 3643 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3644 | __u32 *pparmlen, __u32 *pdatalen) |
| 3645 | { |
| 3646 | char *end_of_smb; |
| 3647 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3648 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3649 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3650 | |
| 3651 | *pdatalen = 0; |
| 3652 | *pparmlen = 0; |
| 3653 | |
| 3654 | if (buf == NULL) |
| 3655 | return -EINVAL; |
| 3656 | |
| 3657 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3658 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3659 | bcc = get_bcc(&pSMBr->hdr); |
| 3660 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3661 | (char *)&pSMBr->ByteCount; |
| 3662 | |
| 3663 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3664 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3665 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3666 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3667 | |
| 3668 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3669 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3670 | |
| 3671 | /* should we also check that parm and data areas do not overlap? */ |
| 3672 | if (*ppparm > end_of_smb) { |
| 3673 | cFYI(1, "parms start after end of smb"); |
| 3674 | return -EINVAL; |
| 3675 | } else if (parm_count + *ppparm > end_of_smb) { |
| 3676 | cFYI(1, "parm end after end of smb"); |
| 3677 | return -EINVAL; |
| 3678 | } else if (*ppdata > end_of_smb) { |
| 3679 | cFYI(1, "data starts after end of smb"); |
| 3680 | return -EINVAL; |
| 3681 | } else if (data_count + *ppdata > end_of_smb) { |
| 3682 | cFYI(1, "data %p + count %d (%p) past smb end %p start %p", |
| 3683 | *ppdata, data_count, (data_count + *ppdata), |
| 3684 | end_of_smb, pSMBr); |
| 3685 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3686 | } else if (parm_count + data_count > bcc) { |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3687 | cFYI(1, "parm count and data count larger than SMB"); |
| 3688 | return -EINVAL; |
| 3689 | } |
| 3690 | *pdatalen = data_count; |
| 3691 | *pparmlen = parm_count; |
| 3692 | return 0; |
| 3693 | } |
| 3694 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3695 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3696 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3697 | CIFSSMBGetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3698 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3699 | { |
| 3700 | int rc = 0; |
| 3701 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3702 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3703 | struct kvec iov[1]; |
| 3704 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3705 | cFYI(1, "GetCifsACL"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3706 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3707 | *pbuflen = 0; |
| 3708 | *acl_inf = NULL; |
| 3709 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3710 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3711 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3712 | if (rc) |
| 3713 | return rc; |
| 3714 | |
| 3715 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3716 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3717 | pSMB->MaxSetupCount = 0; |
| 3718 | pSMB->Fid = fid; /* file handle always le */ |
| 3719 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3720 | CIFS_ACL_DACL); |
| 3721 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3722 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3723 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3724 | 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] | 3725 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3726 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 3727 | 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3728 | cifs_stats_inc(&tcon->num_acl_get); |
| 3729 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3730 | cFYI(1, "Send error in QuerySecDesc = %d", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3731 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3732 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3733 | __u32 parm_len; |
| 3734 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3735 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3736 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3737 | |
| 3738 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3739 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3740 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3741 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3742 | goto qsec_out; |
| 3743 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3744 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3745 | cFYI(1, "smb %p parm %p data %p", pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3746 | |
| 3747 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3748 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3749 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3750 | goto qsec_out; |
| 3751 | } |
| 3752 | |
| 3753 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3754 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3755 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3756 | if (acl_len != *pbuflen) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3757 | cERROR(1, "acl length %d does not match %d", |
| 3758 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3759 | if (*pbuflen > acl_len) |
| 3760 | *pbuflen = acl_len; |
| 3761 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3762 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3763 | /* check if buffer is big enough for the acl |
| 3764 | header followed by the smallest SID */ |
| 3765 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3766 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3767 | cERROR(1, "bad acl length %d", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3768 | rc = -EINVAL; |
| 3769 | *pbuflen = 0; |
| 3770 | } else { |
| 3771 | *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); |
| 3772 | if (*acl_inf == NULL) { |
| 3773 | *pbuflen = 0; |
| 3774 | rc = -ENOMEM; |
| 3775 | } |
| 3776 | memcpy(*acl_inf, pdata, *pbuflen); |
| 3777 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3778 | } |
| 3779 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3780 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3781 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3782 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3783 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3784 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3785 | return rc; |
| 3786 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3787 | |
| 3788 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3789 | CIFSSMBSetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid, |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3790 | struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3791 | { |
| 3792 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3793 | int rc = 0; |
| 3794 | int bytes_returned = 0; |
| 3795 | SET_SEC_DESC_REQ *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3796 | void *pSMBr; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3797 | |
| 3798 | setCifsAclRetry: |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3799 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3800 | if (rc) |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3801 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3802 | |
| 3803 | pSMB->MaxSetupCount = 0; |
| 3804 | pSMB->Reserved = 0; |
| 3805 | |
| 3806 | param_count = 8; |
| 3807 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3808 | data_count = acllen; |
| 3809 | data_offset = param_offset + param_count; |
| 3810 | byte_count = 3 /* pad */ + param_count; |
| 3811 | |
| 3812 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3813 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3814 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3815 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3816 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3817 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3818 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3819 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3820 | pSMB->SetupCount = 0; |
| 3821 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3822 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3823 | |
| 3824 | pSMB->Fid = fid; /* file handle always le */ |
| 3825 | pSMB->Reserved2 = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 3826 | pSMB->AclFlags = cpu_to_le32(aclflag); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3827 | |
| 3828 | if (pntsd && acllen) { |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 3829 | memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + |
| 3830 | data_offset, pntsd, acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3831 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3832 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3833 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3834 | |
| 3835 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3836 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3837 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3838 | cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3839 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3840 | cFYI(1, "Set CIFS ACL returned %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3841 | cifs_buf_release(pSMB); |
| 3842 | |
| 3843 | if (rc == -EAGAIN) |
| 3844 | goto setCifsAclRetry; |
| 3845 | |
| 3846 | return (rc); |
| 3847 | } |
| 3848 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3849 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3850 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3851 | /* Legacy Query Path Information call for lookup to old servers such |
| 3852 | as Win9x/WinME */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3853 | int SMBQueryInformation(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3854 | const unsigned char *searchName, |
| 3855 | FILE_ALL_INFO *pFinfo, |
| 3856 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3857 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3858 | QUERY_INFORMATION_REQ *pSMB; |
| 3859 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3860 | int rc = 0; |
| 3861 | int bytes_returned; |
| 3862 | int name_len; |
| 3863 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3864 | cFYI(1, "In SMBQPath path %s", searchName); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3865 | QInfRetry: |
| 3866 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3867 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3868 | if (rc) |
| 3869 | return rc; |
| 3870 | |
| 3871 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3872 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 3873 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 3874 | searchName, PATH_MAX, nls_codepage, |
| 3875 | remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3876 | name_len++; /* trailing null */ |
| 3877 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3878 | } else { |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3879 | name_len = strnlen(searchName, PATH_MAX); |
| 3880 | name_len++; /* trailing null */ |
| 3881 | strncpy(pSMB->FileName, searchName, name_len); |
| 3882 | } |
| 3883 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3884 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3885 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3886 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3887 | |
| 3888 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3889 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3890 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3891 | cFYI(1, "Send error in QueryInfo = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3892 | } else if (pFinfo) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3893 | struct timespec ts; |
| 3894 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3895 | |
| 3896 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3897 | /* BB FIXME - add time zone adjustment BB */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3898 | memset(pFinfo, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3899 | ts.tv_nsec = 0; |
| 3900 | ts.tv_sec = time; |
| 3901 | /* decode time fields */ |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 3902 | pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3903 | pFinfo->LastWriteTime = pFinfo->ChangeTime; |
| 3904 | pFinfo->LastAccessTime = 0; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3905 | pFinfo->AllocationSize = |
| 3906 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
| 3907 | pFinfo->EndOfFile = pFinfo->AllocationSize; |
| 3908 | pFinfo->Attributes = |
| 3909 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3910 | } else |
| 3911 | rc = -EIO; /* bad buffer passed in */ |
| 3912 | |
| 3913 | cifs_buf_release(pSMB); |
| 3914 | |
| 3915 | if (rc == -EAGAIN) |
| 3916 | goto QInfRetry; |
| 3917 | |
| 3918 | return rc; |
| 3919 | } |
| 3920 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3921 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3922 | CIFSSMBQFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3923 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 3924 | { |
| 3925 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3926 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3927 | int rc = 0; |
| 3928 | int bytes_returned; |
| 3929 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3930 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3931 | QFileInfoRetry: |
| 3932 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3933 | (void **) &pSMBr); |
| 3934 | if (rc) |
| 3935 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3936 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3937 | params = 2 /* level */ + 2 /* fid */; |
| 3938 | pSMB->t2.TotalDataCount = 0; |
| 3939 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3940 | /* BB find exact max data count below from sess structure BB */ |
| 3941 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3942 | pSMB->t2.MaxSetupCount = 0; |
| 3943 | pSMB->t2.Reserved = 0; |
| 3944 | pSMB->t2.Flags = 0; |
| 3945 | pSMB->t2.Timeout = 0; |
| 3946 | pSMB->t2.Reserved2 = 0; |
| 3947 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3948 | Fid) - 4); |
| 3949 | pSMB->t2.DataCount = 0; |
| 3950 | pSMB->t2.DataOffset = 0; |
| 3951 | pSMB->t2.SetupCount = 1; |
| 3952 | pSMB->t2.Reserved3 = 0; |
| 3953 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3954 | byte_count = params + 1 /* pad */ ; |
| 3955 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3956 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3957 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 3958 | pSMB->Pad = 0; |
| 3959 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3960 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3961 | |
| 3962 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3963 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3964 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3965 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3966 | } else { /* decode response */ |
| 3967 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3968 | |
| 3969 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3970 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3971 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3972 | rc = -EIO; /* bad smb */ |
| 3973 | else if (pFindData) { |
| 3974 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3975 | memcpy((char *) pFindData, |
| 3976 | (char *) &pSMBr->hdr.Protocol + |
| 3977 | data_offset, sizeof(FILE_ALL_INFO)); |
| 3978 | } else |
| 3979 | rc = -ENOMEM; |
| 3980 | } |
| 3981 | cifs_buf_release(pSMB); |
| 3982 | if (rc == -EAGAIN) |
| 3983 | goto QFileInfoRetry; |
| 3984 | |
| 3985 | return rc; |
| 3986 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3989 | CIFSSMBQPathInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3991 | FILE_ALL_INFO *pFindData, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3992 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3993 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | { |
| 3995 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
| 3996 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3997 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3998 | int rc = 0; |
| 3999 | int bytes_returned; |
| 4000 | int name_len; |
| 4001 | __u16 params, byte_count; |
| 4002 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4003 | /* cFYI(1, "In QPathInfo path %s", searchName); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | QPathInfoRetry: |
| 4005 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4006 | (void **) &pSMBr); |
| 4007 | if (rc) |
| 4008 | return rc; |
| 4009 | |
| 4010 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4011 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4012 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4013 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | name_len++; /* trailing null */ |
| 4015 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4016 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | name_len = strnlen(searchName, PATH_MAX); |
| 4018 | name_len++; /* trailing null */ |
| 4019 | strncpy(pSMB->FileName, searchName, name_len); |
| 4020 | } |
| 4021 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4022 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | pSMB->TotalDataCount = 0; |
| 4024 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4025 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4026 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | pSMB->MaxSetupCount = 0; |
| 4028 | pSMB->Reserved = 0; |
| 4029 | pSMB->Flags = 0; |
| 4030 | pSMB->Timeout = 0; |
| 4031 | pSMB->Reserved2 = 0; |
| 4032 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4033 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | pSMB->DataCount = 0; |
| 4035 | pSMB->DataOffset = 0; |
| 4036 | pSMB->SetupCount = 1; |
| 4037 | pSMB->Reserved3 = 0; |
| 4038 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4039 | byte_count = params + 1 /* pad */ ; |
| 4040 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4041 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4042 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4043 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 4044 | else |
| 4045 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4047 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4049 | |
| 4050 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4051 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4052 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4053 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | } else { /* decode response */ |
| 4055 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4056 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4057 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 4058 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4059 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4061 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4062 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 4063 | last field */ |
| 4064 | else if (pFindData) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4065 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4067 | |
| 4068 | /* On legacy responses we do not read the last field, |
| 4069 | EAsize, fortunately since it varies by subdialect and |
| 4070 | also note it differs on Set vs. Get, ie two bytes or 4 |
| 4071 | bytes depending but we don't care here */ |
| 4072 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4073 | size = sizeof(FILE_INFO_STANDARD); |
| 4074 | else |
| 4075 | size = sizeof(FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | memcpy((char *) pFindData, |
| 4077 | (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 4078 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | } else |
| 4080 | rc = -ENOMEM; |
| 4081 | } |
| 4082 | cifs_buf_release(pSMB); |
| 4083 | if (rc == -EAGAIN) |
| 4084 | goto QPathInfoRetry; |
| 4085 | |
| 4086 | return rc; |
| 4087 | } |
| 4088 | |
| 4089 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4090 | CIFSSMBUnixQFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4091 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 4092 | { |
| 4093 | struct smb_t2_qfi_req *pSMB = NULL; |
| 4094 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 4095 | int rc = 0; |
| 4096 | int bytes_returned; |
| 4097 | __u16 params, byte_count; |
| 4098 | |
| 4099 | UnixQFileInfoRetry: |
| 4100 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4101 | (void **) &pSMBr); |
| 4102 | if (rc) |
| 4103 | return rc; |
| 4104 | |
| 4105 | params = 2 /* level */ + 2 /* fid */; |
| 4106 | pSMB->t2.TotalDataCount = 0; |
| 4107 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 4108 | /* BB find exact max data count below from sess structure BB */ |
| 4109 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 4110 | pSMB->t2.MaxSetupCount = 0; |
| 4111 | pSMB->t2.Reserved = 0; |
| 4112 | pSMB->t2.Flags = 0; |
| 4113 | pSMB->t2.Timeout = 0; |
| 4114 | pSMB->t2.Reserved2 = 0; |
| 4115 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 4116 | Fid) - 4); |
| 4117 | pSMB->t2.DataCount = 0; |
| 4118 | pSMB->t2.DataOffset = 0; |
| 4119 | pSMB->t2.SetupCount = 1; |
| 4120 | pSMB->t2.Reserved3 = 0; |
| 4121 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 4122 | byte_count = params + 1 /* pad */ ; |
| 4123 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 4124 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 4125 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4126 | pSMB->Pad = 0; |
| 4127 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4128 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4129 | |
| 4130 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4131 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4132 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4133 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4134 | } else { /* decode response */ |
| 4135 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4136 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4137 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Jeff Layton | ac3aa2f | 2012-07-23 13:14:28 -0400 | [diff] [blame] | 4138 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response. " |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4139 | "Unix Extensions can be disabled on mount " |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4140 | "by specifying the nosfu mount option."); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 4141 | rc = -EIO; /* bad smb */ |
| 4142 | } else { |
| 4143 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4144 | memcpy((char *) pFindData, |
| 4145 | (char *) &pSMBr->hdr.Protocol + |
| 4146 | data_offset, |
| 4147 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 4148 | } |
| 4149 | } |
| 4150 | |
| 4151 | cifs_buf_release(pSMB); |
| 4152 | if (rc == -EAGAIN) |
| 4153 | goto UnixQFileInfoRetry; |
| 4154 | |
| 4155 | return rc; |
| 4156 | } |
| 4157 | |
| 4158 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4159 | CIFSSMBUnixQPathInfo(const int xid, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4161 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4162 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | { |
| 4164 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 4165 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4166 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4167 | int rc = 0; |
| 4168 | int bytes_returned = 0; |
| 4169 | int name_len; |
| 4170 | __u16 params, byte_count; |
| 4171 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4172 | cFYI(1, "In QPathInfo (Unix) the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | UnixQPathInfoRetry: |
| 4174 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4175 | (void **) &pSMBr); |
| 4176 | if (rc) |
| 4177 | return rc; |
| 4178 | |
| 4179 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4180 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4181 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4182 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | name_len++; /* trailing null */ |
| 4184 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4185 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | name_len = strnlen(searchName, PATH_MAX); |
| 4187 | name_len++; /* trailing null */ |
| 4188 | strncpy(pSMB->FileName, searchName, name_len); |
| 4189 | } |
| 4190 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4191 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | pSMB->TotalDataCount = 0; |
| 4193 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4194 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4195 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | pSMB->MaxSetupCount = 0; |
| 4197 | pSMB->Reserved = 0; |
| 4198 | pSMB->Flags = 0; |
| 4199 | pSMB->Timeout = 0; |
| 4200 | pSMB->Reserved2 = 0; |
| 4201 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4202 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | pSMB->DataCount = 0; |
| 4204 | pSMB->DataOffset = 0; |
| 4205 | pSMB->SetupCount = 1; |
| 4206 | pSMB->Reserved3 = 0; |
| 4207 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4208 | byte_count = params + 1 /* pad */ ; |
| 4209 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4210 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4211 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 4212 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4213 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4215 | |
| 4216 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4217 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4218 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4219 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | } else { /* decode response */ |
| 4221 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4222 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4223 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Jeff Layton | ac3aa2f | 2012-07-23 13:14:28 -0400 | [diff] [blame] | 4224 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response. " |
Steve French | 1e71f25 | 2007-09-20 15:30:07 +0000 | [diff] [blame] | 4225 | "Unix Extensions can be disabled on mount " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4226 | "by specifying the nosfu mount option."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | rc = -EIO; /* bad smb */ |
| 4228 | } else { |
| 4229 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4230 | memcpy((char *) pFindData, |
| 4231 | (char *) &pSMBr->hdr.Protocol + |
| 4232 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4233 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | } |
| 4235 | } |
| 4236 | cifs_buf_release(pSMB); |
| 4237 | if (rc == -EAGAIN) |
| 4238 | goto UnixQPathInfoRetry; |
| 4239 | |
| 4240 | return rc; |
| 4241 | } |
| 4242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 4244 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4245 | CIFSFindFirst(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4246 | const char *searchName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | const struct nls_table *nls_codepage, |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4248 | __u16 *pnetfid, __u16 search_flags, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4249 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | { |
| 4251 | /* level 257 SMB_ */ |
| 4252 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 4253 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4254 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | int rc = 0; |
| 4256 | int bytes_returned = 0; |
| 4257 | int name_len; |
| 4258 | __u16 params, byte_count; |
| 4259 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4260 | cFYI(1, "In FindFirst for %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | |
| 4262 | findFirstRetry: |
| 4263 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4264 | (void **) &pSMBr); |
| 4265 | if (rc) |
| 4266 | return rc; |
| 4267 | |
| 4268 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4269 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4270 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 4271 | PATH_MAX, nls_codepage, remap); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4272 | /* We can not add the asterik earlier in case |
| 4273 | it got remapped to 0xF03A as if it were part of the |
| 4274 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | name_len *= 2; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4276 | pSMB->FileName[name_len] = dirsep; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4277 | pSMB->FileName[name_len+1] = 0; |
| 4278 | pSMB->FileName[name_len+2] = '*'; |
| 4279 | pSMB->FileName[name_len+3] = 0; |
| 4280 | name_len += 4; /* now the trailing null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ |
| 4282 | pSMB->FileName[name_len+1] = 0; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4283 | name_len += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | } else { /* BB add check for overrun of SMB buf BB */ |
| 4285 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4287 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | free buffer exit; BB */ |
| 4289 | strncpy(pSMB->FileName, searchName, name_len); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4290 | pSMB->FileName[name_len] = dirsep; |
Steve French | 6857547 | 2005-04-30 11:10:57 -0700 | [diff] [blame] | 4291 | pSMB->FileName[name_len+1] = '*'; |
| 4292 | pSMB->FileName[name_len+2] = 0; |
| 4293 | name_len += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | params = 12 + name_len /* includes null */ ; |
| 4297 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4298 | pSMB->MaxParameterCount = cpu_to_le16(10); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4299 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | pSMB->MaxSetupCount = 0; |
| 4301 | pSMB->Reserved = 0; |
| 4302 | pSMB->Flags = 0; |
| 4303 | pSMB->Timeout = 0; |
| 4304 | pSMB->Reserved2 = 0; |
| 4305 | byte_count = params + 1 /* pad */ ; |
| 4306 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4307 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4308 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4309 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 4310 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | pSMB->DataCount = 0; |
| 4312 | pSMB->DataOffset = 0; |
| 4313 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 4314 | pSMB->Reserved3 = 0; |
| 4315 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 4316 | pSMB->SearchAttributes = |
| 4317 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 4318 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4319 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4320 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4322 | |
| 4323 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4324 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4325 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4327 | |
| 4328 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4329 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4330 | cifs_stats_inc(&tcon->num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4332 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4333 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4335 | cFYI(1, "Error in FindFirst = %d", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4336 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4337 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | |
| 4339 | /* BB eventually could optimize out free and realloc of buf */ |
| 4340 | /* for this case */ |
| 4341 | if (rc == -EAGAIN) |
| 4342 | goto findFirstRetry; |
| 4343 | } else { /* decode response */ |
| 4344 | /* BB remember to free buffer if error BB */ |
| 4345 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4346 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4347 | unsigned int lnoff; |
| 4348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4350 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4352 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | |
| 4354 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4355 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4356 | psrch_inf->srch_entries_start = |
| 4357 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4360 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4361 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4362 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4363 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4365 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4367 | psrch_inf->entries_in_buffer = |
| 4368 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4369 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4371 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4372 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4373 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4374 | psrch_inf->last_entry = NULL; |
| 4375 | return rc; |
| 4376 | } |
| 4377 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4378 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4379 | lnoff; |
| 4380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | *pnetfid = parms->SearchHandle; |
| 4382 | } else { |
| 4383 | cifs_buf_release(pSMB); |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | return rc; |
| 4388 | } |
| 4389 | |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4390 | int CIFSFindNext(const int xid, struct cifs_tcon *tcon, __u16 searchHandle, |
| 4391 | __u16 search_flags, struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | { |
| 4393 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4394 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4395 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | char *response_data; |
| 4397 | int rc = 0; |
Jeff Layton | 9438fab | 2011-08-23 07:21:28 -0400 | [diff] [blame] | 4398 | int bytes_returned; |
| 4399 | unsigned int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | __u16 params, byte_count; |
| 4401 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4402 | cFYI(1, "In FindNext"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4404 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | return -ENOENT; |
| 4406 | |
| 4407 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4408 | (void **) &pSMBr); |
| 4409 | if (rc) |
| 4410 | return rc; |
| 4411 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4412 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | byte_count = 0; |
| 4414 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4415 | pSMB->MaxParameterCount = cpu_to_le16(8); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4416 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | pSMB->MaxSetupCount = 0; |
| 4418 | pSMB->Reserved = 0; |
| 4419 | pSMB->Flags = 0; |
| 4420 | pSMB->Timeout = 0; |
| 4421 | pSMB->Reserved2 = 0; |
| 4422 | pSMB->ParameterOffset = cpu_to_le16( |
| 4423 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4424 | pSMB->DataCount = 0; |
| 4425 | pSMB->DataOffset = 0; |
| 4426 | pSMB->SetupCount = 1; |
| 4427 | pSMB->Reserved3 = 0; |
| 4428 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4429 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4430 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4431 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4433 | pSMB->ResumeKey = psrch_inf->resume_key; |
Shirish Pargaonkar | 2608bee | 2012-05-15 10:19:16 -0500 | [diff] [blame] | 4434 | pSMB->SearchFlags = cpu_to_le16(search_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | |
| 4436 | name_len = psrch_inf->resume_name_len; |
| 4437 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4438 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4440 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4441 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4442 | pSMB->ResumeFileName[name_len] = 0; |
| 4443 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | } else { |
| 4445 | rc = -EINVAL; |
| 4446 | goto FNext2_err_exit; |
| 4447 | } |
| 4448 | byte_count = params + 1 /* pad */ ; |
| 4449 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4450 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4451 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4455 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4456 | cifs_stats_inc(&tcon->num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | if (rc) { |
| 4458 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4459 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4460 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4461 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | } else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4463 | cFYI(1, "FindNext returned = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | } else { /* decode response */ |
| 4465 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4466 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4467 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4468 | unsigned int lnoff; |
| 4469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4471 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4472 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4474 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4476 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4477 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4478 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4479 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4480 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4481 | cifs_small_buf_release( |
| 4482 | psrch_inf->ntwrk_buf_start); |
| 4483 | else |
| 4484 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | psrch_inf->srch_entries_start = response_data; |
| 4486 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4487 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4488 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4489 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4491 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4492 | psrch_inf->entries_in_buffer = |
| 4493 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | psrch_inf->index_of_last_entry += |
| 4495 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4496 | lnoff = le16_to_cpu(parms->LastNameOffset); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 4497 | if (CIFSMaxBufSize < lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4498 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4499 | psrch_inf->last_entry = NULL; |
| 4500 | return rc; |
| 4501 | } else |
| 4502 | psrch_inf->last_entry = |
| 4503 | psrch_inf->srch_entries_start + lnoff; |
| 4504 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4505 | /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d", |
| 4506 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | |
| 4508 | /* BB fixme add unlock here */ |
| 4509 | } |
| 4510 | |
| 4511 | } |
| 4512 | |
| 4513 | /* BB On error, should we leave previous search buf (and count and |
| 4514 | last entry fields) intact or free the previous one? */ |
| 4515 | |
| 4516 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4517 | since file handle passed in no longer valid */ |
| 4518 | FNext2_err_exit: |
| 4519 | if (rc != 0) |
| 4520 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | return rc; |
| 4522 | } |
| 4523 | |
| 4524 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4525 | CIFSFindClose(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4526 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | { |
| 4528 | int rc = 0; |
| 4529 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4531 | cFYI(1, "In CIFSSMBFindClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4533 | |
| 4534 | /* no sense returning error if session restarted |
| 4535 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4536 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | return 0; |
| 4538 | if (rc) |
| 4539 | return rc; |
| 4540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | pSMB->FileID = searchHandle; |
| 4542 | pSMB->ByteCount = 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 4543 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4544 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4545 | cERROR(1, "Send error in FindClose = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4546 | |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4547 | cifs_stats_inc(&tcon->num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | |
| 4549 | /* Since session is dead, search handle closed on server already */ |
| 4550 | if (rc == -EAGAIN) |
| 4551 | rc = 0; |
| 4552 | |
| 4553 | return rc; |
| 4554 | } |
| 4555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4557 | CIFSGetSrvInodeNumber(const int xid, struct cifs_tcon *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4558 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4559 | __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4560 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | { |
| 4562 | int rc = 0; |
| 4563 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4564 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4565 | int name_len, bytes_returned; |
| 4566 | __u16 params, byte_count; |
| 4567 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4568 | cFYI(1, "In GetSrvInodeNum for %s", searchName); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4569 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4570 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | |
| 4572 | GetInodeNumberRetry: |
| 4573 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4574 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | if (rc) |
| 4576 | return rc; |
| 4577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4579 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4580 | cifsConvertToUTF16((__le16 *) pSMB->FileName, |
| 4581 | searchName, PATH_MAX, nls_codepage, |
| 4582 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4583 | name_len++; /* trailing null */ |
| 4584 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4585 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | name_len = strnlen(searchName, PATH_MAX); |
| 4587 | name_len++; /* trailing null */ |
| 4588 | strncpy(pSMB->FileName, searchName, name_len); |
| 4589 | } |
| 4590 | |
| 4591 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4592 | pSMB->TotalDataCount = 0; |
| 4593 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4594 | /* BB find exact max data count below from sess structure BB */ |
| 4595 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4596 | pSMB->MaxSetupCount = 0; |
| 4597 | pSMB->Reserved = 0; |
| 4598 | pSMB->Flags = 0; |
| 4599 | pSMB->Timeout = 0; |
| 4600 | pSMB->Reserved2 = 0; |
| 4601 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4602 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | pSMB->DataCount = 0; |
| 4604 | pSMB->DataOffset = 0; |
| 4605 | pSMB->SetupCount = 1; |
| 4606 | pSMB->Reserved3 = 0; |
| 4607 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4608 | byte_count = params + 1 /* pad */ ; |
| 4609 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4610 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4611 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4612 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4613 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4614 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4615 | |
| 4616 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4617 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4618 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4619 | cFYI(1, "error %d in QueryInternalInfo", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4620 | } else { |
| 4621 | /* decode response */ |
| 4622 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4624 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | /* If rc should we check for EOPNOSUPP and |
| 4626 | disable the srvino flag? or in caller? */ |
| 4627 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4628 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4630 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4631 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4633 | if (count < 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4634 | cFYI(1, "Illegal size ret in QryIntrnlInf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | rc = -EIO; |
| 4636 | goto GetInodeNumOut; |
| 4637 | } |
| 4638 | pfinfo = (struct file_internal_info *) |
| 4639 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4640 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | } |
| 4642 | } |
| 4643 | GetInodeNumOut: |
| 4644 | cifs_buf_release(pSMB); |
| 4645 | if (rc == -EAGAIN) |
| 4646 | goto GetInodeNumberRetry; |
| 4647 | return rc; |
| 4648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4650 | /* parses DFS refferal V3 structure |
| 4651 | * caller is responsible for freeing target_nodes |
| 4652 | * returns: |
| 4653 | * on success - 0 |
| 4654 | * on failure - errno |
| 4655 | */ |
| 4656 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4657 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4658 | unsigned int *num_of_nodes, |
| 4659 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4660 | const struct nls_table *nls_codepage, int remap, |
| 4661 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4662 | { |
| 4663 | int i, rc = 0; |
| 4664 | char *data_end; |
| 4665 | bool is_unicode; |
| 4666 | struct dfs_referral_level_3 *ref; |
| 4667 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 4668 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 4669 | is_unicode = true; |
| 4670 | else |
| 4671 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4672 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 4673 | |
| 4674 | if (*num_of_nodes < 1) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4675 | cERROR(1, "num_referrals: must be at least > 0," |
Jeff Layton | ac3aa2f | 2012-07-23 13:14:28 -0400 | [diff] [blame] | 4676 | "but we get num_referrals = %d", *num_of_nodes); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4677 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4678 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4682 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4683 | cERROR(1, "Referrals of V%d version are not supported," |
| 4684 | "should be V3", le16_to_cpu(ref->VersionNumber)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4685 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4686 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | /* get the upper boundary of the resp buffer */ |
| 4690 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 4691 | le16_to_cpu(pSMBr->t2.DataCount); |
| 4692 | |
Jeff Layton | ac3aa2f | 2012-07-23 13:14:28 -0400 | [diff] [blame] | 4693 | cFYI(1, "num_referrals: %d dfs flags: 0x%x ...", |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4694 | *num_of_nodes, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4695 | le32_to_cpu(pSMBr->DFSFlags)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4696 | |
| 4697 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
| 4698 | *num_of_nodes, GFP_KERNEL); |
| 4699 | if (*target_nodes == NULL) { |
Jeff Layton | ac3aa2f | 2012-07-23 13:14:28 -0400 | [diff] [blame] | 4700 | cERROR(1, "Failed to allocate buffer for target_nodes"); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4701 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4702 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4703 | } |
| 4704 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4705 | /* collect necessary data from referrals */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4706 | for (i = 0; i < *num_of_nodes; i++) { |
| 4707 | char *temp; |
| 4708 | int max_len; |
| 4709 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 4710 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4711 | node->flags = le32_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4712 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 4713 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 4714 | GFP_KERNEL); |
Steve French | 2920ee2 | 2009-08-31 15:27:26 +0000 | [diff] [blame] | 4715 | if (tmp == NULL) { |
| 4716 | rc = -ENOMEM; |
| 4717 | goto parse_DFS_referrals_exit; |
| 4718 | } |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4719 | cifsConvertToUTF16((__le16 *) tmp, searchName, |
| 4720 | PATH_MAX, nls_codepage, remap); |
| 4721 | node->path_consumed = cifs_utf16_bytes(tmp, |
Jeff Layton | 69f801f | 2009-04-30 06:46:32 -0400 | [diff] [blame] | 4722 | le16_to_cpu(pSMBr->PathConsumed), |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4723 | nls_codepage); |
| 4724 | kfree(tmp); |
| 4725 | } else |
| 4726 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4727 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4728 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4729 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4730 | |
| 4731 | /* copy DfsPath */ |
| 4732 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4733 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4734 | node->path_name = cifs_strndup_from_utf16(temp, max_len, |
| 4735 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4736 | if (!node->path_name) { |
| 4737 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4738 | goto parse_DFS_referrals_exit; |
Jeff Layton | 066ce68 | 2009-04-30 07:16:14 -0400 | [diff] [blame] | 4739 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4740 | |
| 4741 | /* copy link target UNC */ |
| 4742 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4743 | max_len = data_end - temp; |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4744 | node->node_name = cifs_strndup_from_utf16(temp, max_len, |
| 4745 | is_unicode, nls_codepage); |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4746 | if (!node->node_name) { |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4747 | rc = -ENOMEM; |
Stefan Metzmacher | d8f2799 | 2012-05-04 00:19:28 +0200 | [diff] [blame] | 4748 | goto parse_DFS_referrals_exit; |
| 4749 | } |
| 4750 | |
| 4751 | ref++; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4752 | } |
| 4753 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4754 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4755 | if (rc) { |
| 4756 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4757 | *target_nodes = NULL; |
| 4758 | *num_of_nodes = 0; |
| 4759 | } |
| 4760 | return rc; |
| 4761 | } |
| 4762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4764 | CIFSGetDFSRefer(const int xid, struct cifs_ses *ses, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | const unsigned char *searchName, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4766 | struct dfs_info3_param **target_nodes, |
| 4767 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4768 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | { |
| 4770 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4771 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4772 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | int rc = 0; |
| 4774 | int bytes_returned; |
| 4775 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4777 | *num_of_nodes = 0; |
| 4778 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4780 | cFYI(1, "In GetDFSRefer the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | if (ses == NULL) |
| 4782 | return -ENODEV; |
| 4783 | getDFSRetry: |
| 4784 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4785 | (void **) &pSMBr); |
| 4786 | if (rc) |
| 4787 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4788 | |
| 4789 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4790 | but should never be null here anyway */ |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 4791 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4793 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4794 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4795 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4796 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | |
| 4799 | if (ses->capabilities & CAP_UNICODE) { |
| 4800 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4801 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4802 | cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, |
| 4803 | searchName, PATH_MAX, nls_codepage, |
| 4804 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4805 | name_len++; /* trailing null */ |
| 4806 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4807 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | name_len = strnlen(searchName, PATH_MAX); |
| 4809 | name_len++; /* trailing null */ |
| 4810 | strncpy(pSMB->RequestFileName, searchName, name_len); |
| 4811 | } |
| 4812 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4813 | if (ses->server) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4814 | if (ses->server->sec_mode & |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4815 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 4816 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4817 | } |
| 4818 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4819 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4822 | pSMB->TotalDataCount = 0; |
| 4823 | pSMB->DataCount = 0; |
| 4824 | pSMB->DataOffset = 0; |
| 4825 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4826 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4827 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | pSMB->MaxSetupCount = 0; |
| 4829 | pSMB->Reserved = 0; |
| 4830 | pSMB->Flags = 0; |
| 4831 | pSMB->Timeout = 0; |
| 4832 | pSMB->Reserved2 = 0; |
| 4833 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4834 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | pSMB->SetupCount = 1; |
| 4836 | pSMB->Reserved3 = 0; |
| 4837 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4838 | byte_count = params + 3 /* pad */ ; |
| 4839 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4840 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4841 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4842 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4843 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4844 | |
| 4845 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4846 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4847 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4848 | cFYI(1, "Send error in GetDFSRefer = %d", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4849 | goto GetDFSRefExit; |
| 4850 | } |
| 4851 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4852 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4853 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4854 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4855 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4856 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4858 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4859 | cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4860 | get_bcc(&pSMBr->hdr), |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4861 | le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4862 | |
| 4863 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4864 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4865 | target_nodes, nls_codepage, remap, |
| 4866 | searchName); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4869 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4870 | |
| 4871 | if (rc == -EAGAIN) |
| 4872 | goto getDFSRetry; |
| 4873 | |
| 4874 | return rc; |
| 4875 | } |
| 4876 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4877 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4878 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4879 | SMBOldQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4880 | { |
| 4881 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4882 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4883 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4884 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4885 | int rc = 0; |
| 4886 | int bytes_returned = 0; |
| 4887 | __u16 params, byte_count; |
| 4888 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4889 | cFYI(1, "OldQFSInfo"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4890 | oldQFSInfoRetry: |
| 4891 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4892 | (void **) &pSMBr); |
| 4893 | if (rc) |
| 4894 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4895 | |
| 4896 | params = 2; /* level */ |
| 4897 | pSMB->TotalDataCount = 0; |
| 4898 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4899 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4900 | pSMB->MaxSetupCount = 0; |
| 4901 | pSMB->Reserved = 0; |
| 4902 | pSMB->Flags = 0; |
| 4903 | pSMB->Timeout = 0; |
| 4904 | pSMB->Reserved2 = 0; |
| 4905 | byte_count = params + 1 /* pad */ ; |
| 4906 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4907 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4908 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4909 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4910 | pSMB->DataCount = 0; |
| 4911 | pSMB->DataOffset = 0; |
| 4912 | pSMB->SetupCount = 1; |
| 4913 | pSMB->Reserved3 = 0; |
| 4914 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4915 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4916 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4917 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4918 | |
| 4919 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4920 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4921 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4922 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4923 | } else { /* decode response */ |
| 4924 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4925 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4926 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4927 | rc = -EIO; /* bad smb */ |
| 4928 | else { |
| 4929 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4930 | cFYI(1, "qfsinf resp BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4931 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4932 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4933 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4934 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4935 | FSData->f_bsize = |
| 4936 | le16_to_cpu(response_data->BytesPerSector) * |
| 4937 | le32_to_cpu(response_data-> |
| 4938 | SectorsPerAllocationUnit); |
| 4939 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4940 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4941 | FSData->f_bfree = FSData->f_bavail = |
| 4942 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4943 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4944 | (unsigned long long)FSData->f_blocks, |
| 4945 | (unsigned long long)FSData->f_bfree, |
| 4946 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4947 | } |
| 4948 | } |
| 4949 | cifs_buf_release(pSMB); |
| 4950 | |
| 4951 | if (rc == -EAGAIN) |
| 4952 | goto oldQFSInfoRetry; |
| 4953 | |
| 4954 | return rc; |
| 4955 | } |
| 4956 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4958 | CIFSSMBQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | { |
| 4960 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4961 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4962 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4963 | FILE_SYSTEM_INFO *response_data; |
| 4964 | int rc = 0; |
| 4965 | int bytes_returned = 0; |
| 4966 | __u16 params, byte_count; |
| 4967 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4968 | cFYI(1, "In QFSInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | QFSInfoRetry: |
| 4970 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4971 | (void **) &pSMBr); |
| 4972 | if (rc) |
| 4973 | return rc; |
| 4974 | |
| 4975 | params = 2; /* level */ |
| 4976 | pSMB->TotalDataCount = 0; |
| 4977 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4978 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4979 | pSMB->MaxSetupCount = 0; |
| 4980 | pSMB->Reserved = 0; |
| 4981 | pSMB->Flags = 0; |
| 4982 | pSMB->Timeout = 0; |
| 4983 | pSMB->Reserved2 = 0; |
| 4984 | byte_count = params + 1 /* pad */ ; |
| 4985 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4986 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4987 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4988 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 | pSMB->DataCount = 0; |
| 4990 | pSMB->DataOffset = 0; |
| 4991 | pSMB->SetupCount = 1; |
| 4992 | pSMB->Reserved3 = 0; |
| 4993 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4994 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4995 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4997 | |
| 4998 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4999 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5000 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5001 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5003 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5004 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5005 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | rc = -EIO; /* bad smb */ |
| 5007 | else { |
| 5008 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5009 | |
| 5010 | response_data = |
| 5011 | (FILE_SYSTEM_INFO |
| 5012 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5013 | data_offset); |
| 5014 | FSData->f_bsize = |
| 5015 | le32_to_cpu(response_data->BytesPerSector) * |
| 5016 | le32_to_cpu(response_data-> |
| 5017 | SectorsPerAllocationUnit); |
| 5018 | FSData->f_blocks = |
| 5019 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 5020 | FSData->f_bfree = FSData->f_bavail = |
| 5021 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5022 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 5023 | (unsigned long long)FSData->f_blocks, |
| 5024 | (unsigned long long)FSData->f_bfree, |
| 5025 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | } |
| 5027 | } |
| 5028 | cifs_buf_release(pSMB); |
| 5029 | |
| 5030 | if (rc == -EAGAIN) |
| 5031 | goto QFSInfoRetry; |
| 5032 | |
| 5033 | return rc; |
| 5034 | } |
| 5035 | |
| 5036 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5037 | CIFSSMBQFSAttributeInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | { |
| 5039 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5040 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5041 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5042 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 5043 | int rc = 0; |
| 5044 | int bytes_returned = 0; |
| 5045 | __u16 params, byte_count; |
| 5046 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5047 | cFYI(1, "In QFSAttributeInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | QFSAttributeRetry: |
| 5049 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5050 | (void **) &pSMBr); |
| 5051 | if (rc) |
| 5052 | return rc; |
| 5053 | |
| 5054 | params = 2; /* level */ |
| 5055 | pSMB->TotalDataCount = 0; |
| 5056 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5057 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5058 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 | pSMB->MaxSetupCount = 0; |
| 5060 | pSMB->Reserved = 0; |
| 5061 | pSMB->Flags = 0; |
| 5062 | pSMB->Timeout = 0; |
| 5063 | pSMB->Reserved2 = 0; |
| 5064 | byte_count = params + 1 /* pad */ ; |
| 5065 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5066 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5067 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5068 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | pSMB->DataCount = 0; |
| 5070 | pSMB->DataOffset = 0; |
| 5071 | pSMB->SetupCount = 1; |
| 5072 | pSMB->Reserved3 = 0; |
| 5073 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5074 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5075 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5076 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5077 | |
| 5078 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5079 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5080 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5081 | cERROR(1, "Send error in QFSAttributeInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | } else { /* decode response */ |
| 5083 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5084 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5085 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5086 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5087 | rc = -EIO; /* bad smb */ |
| 5088 | } else { |
| 5089 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5090 | response_data = |
| 5091 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 5092 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5093 | data_offset); |
| 5094 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5095 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | } |
| 5097 | } |
| 5098 | cifs_buf_release(pSMB); |
| 5099 | |
| 5100 | if (rc == -EAGAIN) |
| 5101 | goto QFSAttributeRetry; |
| 5102 | |
| 5103 | return rc; |
| 5104 | } |
| 5105 | |
| 5106 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5107 | CIFSSMBQFSDeviceInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | { |
| 5109 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 5110 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5111 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5112 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 5113 | int rc = 0; |
| 5114 | int bytes_returned = 0; |
| 5115 | __u16 params, byte_count; |
| 5116 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5117 | cFYI(1, "In QFSDeviceInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | QFSDeviceRetry: |
| 5119 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5120 | (void **) &pSMBr); |
| 5121 | if (rc) |
| 5122 | return rc; |
| 5123 | |
| 5124 | params = 2; /* level */ |
| 5125 | pSMB->TotalDataCount = 0; |
| 5126 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5127 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5128 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | pSMB->MaxSetupCount = 0; |
| 5130 | pSMB->Reserved = 0; |
| 5131 | pSMB->Flags = 0; |
| 5132 | pSMB->Timeout = 0; |
| 5133 | pSMB->Reserved2 = 0; |
| 5134 | byte_count = params + 1 /* pad */ ; |
| 5135 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5136 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5137 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5138 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | |
| 5140 | pSMB->DataCount = 0; |
| 5141 | pSMB->DataOffset = 0; |
| 5142 | pSMB->SetupCount = 1; |
| 5143 | pSMB->Reserved3 = 0; |
| 5144 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5145 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5146 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5148 | |
| 5149 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5150 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5151 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5152 | cFYI(1, "Send error in QFSDeviceInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5153 | } else { /* decode response */ |
| 5154 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5155 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5156 | if (rc || get_bcc(&pSMBr->hdr) < |
| 5157 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | rc = -EIO; /* bad smb */ |
| 5159 | else { |
| 5160 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5161 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5162 | (FILE_SYSTEM_DEVICE_INFO *) |
| 5163 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | data_offset); |
| 5165 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5166 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | } |
| 5168 | } |
| 5169 | cifs_buf_release(pSMB); |
| 5170 | |
| 5171 | if (rc == -EAGAIN) |
| 5172 | goto QFSDeviceRetry; |
| 5173 | |
| 5174 | return rc; |
| 5175 | } |
| 5176 | |
| 5177 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5178 | CIFSSMBQFSUnixInfo(const int xid, struct cifs_tcon *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5179 | { |
| 5180 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 5181 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5182 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5183 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 5184 | int rc = 0; |
| 5185 | int bytes_returned = 0; |
| 5186 | __u16 params, byte_count; |
| 5187 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5188 | cFYI(1, "In QFSUnixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5190 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5191 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | if (rc) |
| 5193 | return rc; |
| 5194 | |
| 5195 | params = 2; /* level */ |
| 5196 | pSMB->TotalDataCount = 0; |
| 5197 | pSMB->DataCount = 0; |
| 5198 | pSMB->DataOffset = 0; |
| 5199 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5200 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5201 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5202 | pSMB->MaxSetupCount = 0; |
| 5203 | pSMB->Reserved = 0; |
| 5204 | pSMB->Flags = 0; |
| 5205 | pSMB->Timeout = 0; |
| 5206 | pSMB->Reserved2 = 0; |
| 5207 | byte_count = params + 1 /* pad */ ; |
| 5208 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5209 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5210 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5211 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5212 | pSMB->SetupCount = 1; |
| 5213 | pSMB->Reserved3 = 0; |
| 5214 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5215 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5216 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5218 | |
| 5219 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5220 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5221 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5222 | cERROR(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5223 | } else { /* decode response */ |
| 5224 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5225 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5226 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5227 | rc = -EIO; /* bad smb */ |
| 5228 | } else { |
| 5229 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5230 | response_data = |
| 5231 | (FILE_SYSTEM_UNIX_INFO |
| 5232 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5233 | data_offset); |
| 5234 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5235 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | } |
| 5237 | } |
| 5238 | cifs_buf_release(pSMB); |
| 5239 | |
| 5240 | if (rc == -EAGAIN) |
| 5241 | goto QFSUnixRetry; |
| 5242 | |
| 5243 | |
| 5244 | return rc; |
| 5245 | } |
| 5246 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5247 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5248 | CIFSSMBSetFSUnixInfo(const int xid, struct cifs_tcon *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5249 | { |
| 5250 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 5251 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 5252 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 5253 | int rc = 0; |
| 5254 | int bytes_returned = 0; |
| 5255 | __u16 params, param_offset, offset, byte_count; |
| 5256 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5257 | cFYI(1, "In SETFSUnixInfo"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5258 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 5259 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 5260 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 5261 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5262 | if (rc) |
| 5263 | return rc; |
| 5264 | |
| 5265 | params = 4; /* 2 bytes zero followed by info level. */ |
| 5266 | pSMB->MaxSetupCount = 0; |
| 5267 | pSMB->Reserved = 0; |
| 5268 | pSMB->Flags = 0; |
| 5269 | pSMB->Timeout = 0; |
| 5270 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5271 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 5272 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5273 | offset = param_offset + params; |
| 5274 | |
| 5275 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5276 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5277 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5278 | pSMB->SetupCount = 1; |
| 5279 | pSMB->Reserved3 = 0; |
| 5280 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 5281 | byte_count = 1 /* pad */ + params + 12; |
| 5282 | |
| 5283 | pSMB->DataCount = cpu_to_le16(12); |
| 5284 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5285 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5286 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5287 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5288 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5289 | |
| 5290 | /* Params. */ |
| 5291 | pSMB->FileNum = 0; |
| 5292 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 5293 | |
| 5294 | /* Data. */ |
| 5295 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 5296 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 5297 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 5298 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5299 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5300 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5301 | |
| 5302 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5303 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5304 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5305 | cERROR(1, "Send error in SETFSUnixInfo = %d", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5306 | } else { /* decode response */ |
| 5307 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5308 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5309 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 5310 | } |
| 5311 | cifs_buf_release(pSMB); |
| 5312 | |
| 5313 | if (rc == -EAGAIN) |
| 5314 | goto SETFSUnixRetry; |
| 5315 | |
| 5316 | return rc; |
| 5317 | } |
| 5318 | |
| 5319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | |
| 5321 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5322 | CIFSSMBQFSPosixInfo(const int xid, struct cifs_tcon *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5323 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5324 | { |
| 5325 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5326 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5327 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5328 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5329 | int rc = 0; |
| 5330 | int bytes_returned = 0; |
| 5331 | __u16 params, byte_count; |
| 5332 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5333 | cFYI(1, "In QFSPosixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 | QFSPosixRetry: |
| 5335 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5336 | (void **) &pSMBr); |
| 5337 | if (rc) |
| 5338 | return rc; |
| 5339 | |
| 5340 | params = 2; /* level */ |
| 5341 | pSMB->TotalDataCount = 0; |
| 5342 | pSMB->DataCount = 0; |
| 5343 | pSMB->DataOffset = 0; |
| 5344 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5345 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5346 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5347 | pSMB->MaxSetupCount = 0; |
| 5348 | pSMB->Reserved = 0; |
| 5349 | pSMB->Flags = 0; |
| 5350 | pSMB->Timeout = 0; |
| 5351 | pSMB->Reserved2 = 0; |
| 5352 | byte_count = params + 1 /* pad */ ; |
| 5353 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5354 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5355 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5356 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | pSMB->SetupCount = 1; |
| 5358 | pSMB->Reserved3 = 0; |
| 5359 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5360 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5361 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5363 | |
| 5364 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5365 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5366 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5367 | cFYI(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5368 | } else { /* decode response */ |
| 5369 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5370 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5371 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5372 | rc = -EIO; /* bad smb */ |
| 5373 | } else { |
| 5374 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5375 | response_data = |
| 5376 | (FILE_SYSTEM_POSIX_INFO |
| 5377 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5378 | data_offset); |
| 5379 | FSData->f_bsize = |
| 5380 | le32_to_cpu(response_data->BlockSize); |
| 5381 | FSData->f_blocks = |
| 5382 | le64_to_cpu(response_data->TotalBlocks); |
| 5383 | FSData->f_bfree = |
| 5384 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5385 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | FSData->f_bavail = FSData->f_bfree; |
| 5387 | } else { |
| 5388 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5389 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5391 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5392 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5393 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5394 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5395 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5396 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5397 | } |
| 5398 | } |
| 5399 | cifs_buf_release(pSMB); |
| 5400 | |
| 5401 | if (rc == -EAGAIN) |
| 5402 | goto QFSPosixRetry; |
| 5403 | |
| 5404 | return rc; |
| 5405 | } |
| 5406 | |
| 5407 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5408 | /* We can not use write of zero bytes trick to |
| 5409 | set file size due to need for large file support. Also note that |
| 5410 | this SetPathInfo is preferred to SetFileInfo based method in next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 | routine which is only needed to work around a sharing violation bug |
| 5412 | in Samba which this routine can run into */ |
| 5413 | |
| 5414 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5415 | CIFSSMBSetEOF(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5416 | __u64 size, bool SetAllocation, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5417 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5418 | { |
| 5419 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5420 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5421 | struct file_end_of_file_info *parm_data; |
| 5422 | int name_len; |
| 5423 | int rc = 0; |
| 5424 | int bytes_returned = 0; |
| 5425 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5426 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5427 | cFYI(1, "In SetEOF"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5428 | SetEOFRetry: |
| 5429 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5430 | (void **) &pSMBr); |
| 5431 | if (rc) |
| 5432 | return rc; |
| 5433 | |
| 5434 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5435 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5436 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5437 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 | name_len++; /* trailing null */ |
| 5439 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5440 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5441 | name_len = strnlen(fileName, PATH_MAX); |
| 5442 | name_len++; /* trailing null */ |
| 5443 | strncpy(pSMB->FileName, fileName, name_len); |
| 5444 | } |
| 5445 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5446 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5448 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5449 | pSMB->MaxSetupCount = 0; |
| 5450 | pSMB->Reserved = 0; |
| 5451 | pSMB->Flags = 0; |
| 5452 | pSMB->Timeout = 0; |
| 5453 | pSMB->Reserved2 = 0; |
| 5454 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5455 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5456 | offset = param_offset + params; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5457 | if (SetAllocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5458 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5459 | pSMB->InformationLevel = |
| 5460 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5461 | else |
| 5462 | pSMB->InformationLevel = |
| 5463 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5464 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5465 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5466 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5467 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5468 | else |
| 5469 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5470 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | parm_data = |
| 5474 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5475 | offset); |
| 5476 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5477 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5478 | pSMB->SetupCount = 1; |
| 5479 | pSMB->Reserved3 = 0; |
| 5480 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5481 | byte_count = 3 /* pad */ + params + data_count; |
| 5482 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5483 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5484 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5485 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5486 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5487 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5488 | parm_data->FileSize = cpu_to_le64(size); |
| 5489 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5490 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5491 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5492 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5493 | cFYI(1, "SetPathInfo (file size) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | |
| 5495 | cifs_buf_release(pSMB); |
| 5496 | |
| 5497 | if (rc == -EAGAIN) |
| 5498 | goto SetEOFRetry; |
| 5499 | |
| 5500 | return rc; |
| 5501 | } |
| 5502 | |
| 5503 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5504 | CIFSSMBSetFileSize(const int xid, struct cifs_tcon *tcon, __u64 size, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5505 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | { |
| 5507 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5508 | struct file_end_of_file_info *parm_data; |
| 5509 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | __u16 params, param_offset, offset, byte_count, count; |
| 5511 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5512 | cFYI(1, "SetFileSize (via SetFileInfo) %lld", |
| 5513 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5514 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | if (rc) |
| 5517 | return rc; |
| 5518 | |
| 5519 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5520 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | params = 6; |
| 5523 | pSMB->MaxSetupCount = 0; |
| 5524 | pSMB->Reserved = 0; |
| 5525 | pSMB->Flags = 0; |
| 5526 | pSMB->Timeout = 0; |
| 5527 | pSMB->Reserved2 = 0; |
| 5528 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5529 | offset = param_offset + params; |
| 5530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | count = sizeof(struct file_end_of_file_info); |
| 5532 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5533 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5534 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5535 | pSMB->SetupCount = 1; |
| 5536 | pSMB->Reserved3 = 0; |
| 5537 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5538 | byte_count = 3 /* pad */ + params + count; |
| 5539 | pSMB->DataCount = cpu_to_le16(count); |
| 5540 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5541 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5542 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5543 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5544 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5545 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5546 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5548 | parm_data->FileSize = cpu_to_le64(size); |
| 5549 | pSMB->Fid = fid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5550 | if (SetAllocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5551 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5552 | pSMB->InformationLevel = |
| 5553 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5554 | else |
| 5555 | pSMB->InformationLevel = |
| 5556 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5557 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5558 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5559 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5560 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5561 | else |
| 5562 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5563 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | } |
| 5565 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5566 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5568 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5569 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5570 | cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | } |
| 5572 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5573 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5574 | since file handle passed in no longer valid */ |
| 5575 | |
| 5576 | return rc; |
| 5577 | } |
| 5578 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5579 | /* 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] | 5580 | an open handle, rather than by pathname - this is awkward due to |
| 5581 | potential access conflicts on the open, but it is unavoidable for these |
| 5582 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5583 | time and resort to the original setpathinfo level which takes the ancient |
| 5584 | DOS time format with 2 second granularity */ |
| 5585 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5586 | CIFSSMBSetFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5587 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5588 | { |
| 5589 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | char *data_offset; |
| 5591 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | __u16 params, param_offset, offset, byte_count, count; |
| 5593 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5594 | cFYI(1, "Set Times (via SetFileInfo)"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5595 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | if (rc) |
| 5598 | return rc; |
| 5599 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5600 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5601 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5603 | params = 6; |
| 5604 | pSMB->MaxSetupCount = 0; |
| 5605 | pSMB->Reserved = 0; |
| 5606 | pSMB->Flags = 0; |
| 5607 | pSMB->Timeout = 0; |
| 5608 | pSMB->Reserved2 = 0; |
| 5609 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5610 | offset = param_offset + params; |
| 5611 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5612 | data_offset = (char *)pSMB + |
| 5613 | offsetof(struct smb_hdr, Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5615 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5617 | /* BB find max SMB PDU from sess */ |
| 5618 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | pSMB->SetupCount = 1; |
| 5620 | pSMB->Reserved3 = 0; |
| 5621 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5622 | byte_count = 3 /* pad */ + params + count; |
| 5623 | pSMB->DataCount = cpu_to_le16(count); |
| 5624 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5625 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5626 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5627 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5628 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5629 | pSMB->Fid = fid; |
| 5630 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5631 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5632 | else |
| 5633 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5634 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5635 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5637 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5638 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5639 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5640 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5641 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5642 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | since file handle passed in no longer valid */ |
| 5644 | |
| 5645 | return rc; |
| 5646 | } |
| 5647 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5648 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5649 | CIFSSMBSetFileDisposition(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5650 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5651 | { |
| 5652 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5653 | char *data_offset; |
| 5654 | int rc = 0; |
| 5655 | __u16 params, param_offset, offset, byte_count, count; |
| 5656 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5657 | cFYI(1, "Set File Disposition (via SetFileInfo)"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5658 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5659 | |
| 5660 | if (rc) |
| 5661 | return rc; |
| 5662 | |
| 5663 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5664 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5665 | |
| 5666 | params = 6; |
| 5667 | pSMB->MaxSetupCount = 0; |
| 5668 | pSMB->Reserved = 0; |
| 5669 | pSMB->Flags = 0; |
| 5670 | pSMB->Timeout = 0; |
| 5671 | pSMB->Reserved2 = 0; |
| 5672 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5673 | offset = param_offset + params; |
| 5674 | |
| 5675 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5676 | |
| 5677 | count = 1; |
| 5678 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5679 | /* BB find max SMB PDU from sess */ |
| 5680 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5681 | pSMB->SetupCount = 1; |
| 5682 | pSMB->Reserved3 = 0; |
| 5683 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5684 | byte_count = 3 /* pad */ + params + count; |
| 5685 | pSMB->DataCount = cpu_to_le16(count); |
| 5686 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5687 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5688 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5689 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5690 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5691 | pSMB->Fid = fid; |
| 5692 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5693 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5694 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5695 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5696 | *data_offset = delete_file ? 1 : 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5697 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5698 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5699 | cFYI(1, "Send error in SetFileDisposition = %d", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5700 | |
| 5701 | return rc; |
| 5702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | |
| 5704 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5705 | CIFSSMBSetPathInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5706 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5707 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | { |
| 5709 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5710 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5711 | int name_len; |
| 5712 | int rc = 0; |
| 5713 | int bytes_returned = 0; |
| 5714 | char *data_offset; |
| 5715 | __u16 params, param_offset, offset, byte_count, count; |
| 5716 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5717 | cFYI(1, "In SetTimes"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | |
| 5719 | SetTimesRetry: |
| 5720 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5721 | (void **) &pSMBr); |
| 5722 | if (rc) |
| 5723 | return rc; |
| 5724 | |
| 5725 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5726 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5727 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5728 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5729 | name_len++; /* trailing null */ |
| 5730 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5731 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | name_len = strnlen(fileName, PATH_MAX); |
| 5733 | name_len++; /* trailing null */ |
| 5734 | strncpy(pSMB->FileName, fileName, name_len); |
| 5735 | } |
| 5736 | |
| 5737 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5738 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5739 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5740 | /* BB find max SMB PDU from sess structure BB */ |
| 5741 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | pSMB->MaxSetupCount = 0; |
| 5743 | pSMB->Reserved = 0; |
| 5744 | pSMB->Flags = 0; |
| 5745 | pSMB->Timeout = 0; |
| 5746 | pSMB->Reserved2 = 0; |
| 5747 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5748 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5749 | offset = param_offset + params; |
| 5750 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5751 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5752 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5753 | pSMB->SetupCount = 1; |
| 5754 | pSMB->Reserved3 = 0; |
| 5755 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5756 | byte_count = 3 /* pad */ + params + count; |
| 5757 | |
| 5758 | pSMB->DataCount = cpu_to_le16(count); |
| 5759 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5760 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5761 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5762 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5763 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5764 | else |
| 5765 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5766 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5767 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5768 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5769 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5770 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5771 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5772 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5773 | cFYI(1, "SetPathInfo (times) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5774 | |
| 5775 | cifs_buf_release(pSMB); |
| 5776 | |
| 5777 | if (rc == -EAGAIN) |
| 5778 | goto SetTimesRetry; |
| 5779 | |
| 5780 | return rc; |
| 5781 | } |
| 5782 | |
| 5783 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5784 | /* Can be used to set attributes */ |
| 5785 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5786 | handling it anyway and NT4 was what we thought it would be needed for |
| 5787 | Do not delete it until we prove whether needed for Win9x though */ |
| 5788 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5789 | CIFSSMBSetAttrLegacy(int xid, struct cifs_tcon *tcon, char *fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5790 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5791 | { |
| 5792 | SETATTR_REQ *pSMB = NULL; |
| 5793 | SETATTR_RSP *pSMBr = NULL; |
| 5794 | int rc = 0; |
| 5795 | int bytes_returned; |
| 5796 | int name_len; |
| 5797 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5798 | cFYI(1, "In SetAttrLegacy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5799 | |
| 5800 | SetAttrLgcyRetry: |
| 5801 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5802 | (void **) &pSMBr); |
| 5803 | if (rc) |
| 5804 | return rc; |
| 5805 | |
| 5806 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5807 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5808 | ConvertToUTF16((__le16 *) pSMB->fileName, fileName, |
| 5809 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5810 | name_len++; /* trailing null */ |
| 5811 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5812 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5813 | name_len = strnlen(fileName, PATH_MAX); |
| 5814 | name_len++; /* trailing null */ |
| 5815 | strncpy(pSMB->fileName, fileName, name_len); |
| 5816 | } |
| 5817 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5818 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5819 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5820 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5821 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5822 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5823 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5824 | cFYI(1, "Error in LegacySetAttr = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | |
| 5826 | cifs_buf_release(pSMB); |
| 5827 | |
| 5828 | if (rc == -EAGAIN) |
| 5829 | goto SetAttrLgcyRetry; |
| 5830 | |
| 5831 | return rc; |
| 5832 | } |
| 5833 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5834 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5835 | static void |
| 5836 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5837 | const struct cifs_unix_set_info_args *args) |
| 5838 | { |
| 5839 | u64 mode = args->mode; |
| 5840 | |
| 5841 | /* |
| 5842 | * Samba server ignores set of file size to zero due to bugs in some |
| 5843 | * older clients, but we should be precise - we use SetFileSize to |
| 5844 | * 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] | 5845 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5846 | * zero instead of -1 here |
| 5847 | */ |
| 5848 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5849 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5850 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5851 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5852 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
| 5853 | data_offset->Uid = cpu_to_le64(args->uid); |
| 5854 | data_offset->Gid = cpu_to_le64(args->gid); |
| 5855 | /* better to leave device as zero when it is */ |
| 5856 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5857 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5858 | data_offset->Permissions = cpu_to_le64(mode); |
| 5859 | |
| 5860 | if (S_ISREG(mode)) |
| 5861 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5862 | else if (S_ISDIR(mode)) |
| 5863 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 5864 | else if (S_ISLNK(mode)) |
| 5865 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 5866 | else if (S_ISCHR(mode)) |
| 5867 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 5868 | else if (S_ISBLK(mode)) |
| 5869 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 5870 | else if (S_ISFIFO(mode)) |
| 5871 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 5872 | else if (S_ISSOCK(mode)) |
| 5873 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5874 | } |
| 5875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5876 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5877 | CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5878 | const struct cifs_unix_set_info_args *args, |
| 5879 | u16 fid, u32 pid_of_opener) |
| 5880 | { |
| 5881 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5882 | char *data_offset; |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5883 | int rc = 0; |
| 5884 | u16 params, param_offset, offset, byte_count, count; |
| 5885 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5886 | cFYI(1, "Set Unix Info (via SetFileInfo)"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5887 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5888 | |
| 5889 | if (rc) |
| 5890 | return rc; |
| 5891 | |
| 5892 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5893 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5894 | |
| 5895 | params = 6; |
| 5896 | pSMB->MaxSetupCount = 0; |
| 5897 | pSMB->Reserved = 0; |
| 5898 | pSMB->Flags = 0; |
| 5899 | pSMB->Timeout = 0; |
| 5900 | pSMB->Reserved2 = 0; |
| 5901 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5902 | offset = param_offset + params; |
| 5903 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5904 | data_offset = (char *)pSMB + |
| 5905 | offsetof(struct smb_hdr, Protocol) + offset; |
| 5906 | |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5907 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 5908 | |
| 5909 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5910 | /* BB find max SMB PDU from sess */ |
| 5911 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5912 | pSMB->SetupCount = 1; |
| 5913 | pSMB->Reserved3 = 0; |
| 5914 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5915 | byte_count = 3 /* pad */ + params + count; |
| 5916 | pSMB->DataCount = cpu_to_le16(count); |
| 5917 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5918 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5919 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5920 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5921 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5922 | pSMB->Fid = fid; |
| 5923 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5924 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5925 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5926 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5927 | |
Jeff Layton | b2a3ad9 | 2012-03-26 09:55:29 -0400 | [diff] [blame] | 5928 | cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5929 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 5930 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5931 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5932 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5933 | |
| 5934 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 5935 | since file handle passed in no longer valid */ |
| 5936 | |
| 5937 | return rc; |
| 5938 | } |
| 5939 | |
| 5940 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 5941 | CIFSSMBUnixSetPathInfo(const int xid, struct cifs_tcon *tcon, char *fileName, |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5942 | const struct cifs_unix_set_info_args *args, |
| 5943 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5944 | { |
| 5945 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5946 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5947 | int name_len; |
| 5948 | int rc = 0; |
| 5949 | int bytes_returned = 0; |
| 5950 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5951 | __u16 params, param_offset, offset, count, byte_count; |
| 5952 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5953 | cFYI(1, "In SetUID/GID/Mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5954 | setPermsRetry: |
| 5955 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5956 | (void **) &pSMBr); |
| 5957 | if (rc) |
| 5958 | return rc; |
| 5959 | |
| 5960 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5961 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 5962 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 5963 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5964 | name_len++; /* trailing null */ |
| 5965 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5966 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5967 | name_len = strnlen(fileName, PATH_MAX); |
| 5968 | name_len++; /* trailing null */ |
| 5969 | strncpy(pSMB->FileName, fileName, name_len); |
| 5970 | } |
| 5971 | |
| 5972 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5973 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5974 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5975 | /* BB find max SMB PDU from sess structure BB */ |
| 5976 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5977 | pSMB->MaxSetupCount = 0; |
| 5978 | pSMB->Reserved = 0; |
| 5979 | pSMB->Flags = 0; |
| 5980 | pSMB->Timeout = 0; |
| 5981 | pSMB->Reserved2 = 0; |
| 5982 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5983 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5984 | offset = param_offset + params; |
| 5985 | data_offset = |
| 5986 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 5987 | offset); |
| 5988 | memset(data_offset, 0, count); |
| 5989 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5990 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5991 | pSMB->SetupCount = 1; |
| 5992 | pSMB->Reserved3 = 0; |
| 5993 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5994 | byte_count = 3 /* pad */ + params + count; |
| 5995 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5996 | pSMB->DataCount = cpu_to_le16(count); |
| 5997 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5998 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5999 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 6000 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6001 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6002 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 6003 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6004 | |
| 6005 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6006 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6007 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6008 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6009 | cFYI(1, "SetPathInfo (perms) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6011 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6012 | if (rc == -EAGAIN) |
| 6013 | goto setPermsRetry; |
| 6014 | return rc; |
| 6015 | } |
| 6016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6017 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6018 | /* |
| 6019 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 6020 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 6021 | * it looks for that attribute name and stuffs that value into the EAData |
| 6022 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 6023 | * buffer. In both cases, the return value is either the length of the |
| 6024 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 6025 | * the data isn't copied to it, but the length is returned. |
| 6026 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6027 | ssize_t |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6028 | CIFSSMBQAllEAs(const int xid, struct cifs_tcon *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6029 | const unsigned char *searchName, const unsigned char *ea_name, |
| 6030 | char *EAData, size_t buf_size, |
| 6031 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6032 | { |
| 6033 | /* BB assumes one setup word */ |
| 6034 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 6035 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 6036 | int rc = 0; |
| 6037 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6038 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6039 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6040 | struct fea *temp_fea; |
| 6041 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6042 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6043 | __u16 params, byte_count, data_offset; |
Jeff Layton | 5980fc9 | 2011-07-28 12:48:26 -0400 | [diff] [blame] | 6044 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6045 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6046 | cFYI(1, "In Query All EAs path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6047 | QAllEAsRetry: |
| 6048 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6049 | (void **) &pSMBr); |
| 6050 | if (rc) |
| 6051 | return rc; |
| 6052 | |
| 6053 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6054 | list_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6055 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
| 6056 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6057 | list_len++; /* trailing null */ |
| 6058 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6059 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6060 | list_len = strnlen(searchName, PATH_MAX); |
| 6061 | list_len++; /* trailing null */ |
| 6062 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6063 | } |
| 6064 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6065 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6066 | pSMB->TotalDataCount = 0; |
| 6067 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6068 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6069 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6070 | pSMB->MaxSetupCount = 0; |
| 6071 | pSMB->Reserved = 0; |
| 6072 | pSMB->Flags = 0; |
| 6073 | pSMB->Timeout = 0; |
| 6074 | pSMB->Reserved2 = 0; |
| 6075 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6076 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6077 | pSMB->DataCount = 0; |
| 6078 | pSMB->DataOffset = 0; |
| 6079 | pSMB->SetupCount = 1; |
| 6080 | pSMB->Reserved3 = 0; |
| 6081 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 6082 | byte_count = params + 1 /* pad */ ; |
| 6083 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 6084 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6085 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 6086 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6087 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6088 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6089 | |
| 6090 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6091 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 6092 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6093 | cFYI(1, "Send error in QueryAllEAs = %d", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6094 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6095 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6096 | |
| 6097 | |
| 6098 | /* BB also check enough total bytes returned */ |
| 6099 | /* BB we need to improve the validity checking |
| 6100 | of these trans2 responses */ |
| 6101 | |
| 6102 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 6103 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6104 | rc = -EIO; /* bad smb */ |
| 6105 | goto QAllEAsOut; |
| 6106 | } |
| 6107 | |
| 6108 | /* check that length of list is not more than bcc */ |
| 6109 | /* check that each entry does not go beyond length |
| 6110 | of list */ |
| 6111 | /* check that each element of each entry does not |
| 6112 | go beyond end of list */ |
| 6113 | /* validate_trans2_offsets() */ |
| 6114 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 6115 | |
| 6116 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 6117 | ea_response_data = (struct fealist *) |
| 6118 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 6119 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6120 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6121 | cFYI(1, "ea length %d", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6122 | if (list_len <= 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6123 | cFYI(1, "empty EA list returned from server"); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6124 | goto QAllEAsOut; |
| 6125 | } |
| 6126 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6127 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 6128 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6129 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6130 | cFYI(1, "EA list appears to go beyond SMB"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6131 | rc = -EIO; |
| 6132 | goto QAllEAsOut; |
| 6133 | } |
| 6134 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6135 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6136 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6137 | temp_fea = ea_response_data->list; |
| 6138 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6139 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 6140 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6141 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6142 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6143 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6144 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6145 | /* make sure we can read name_len and value_len */ |
| 6146 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6147 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6148 | rc = -EIO; |
| 6149 | goto QAllEAsOut; |
| 6150 | } |
| 6151 | |
| 6152 | name_len = temp_fea->name_len; |
| 6153 | value_len = le16_to_cpu(temp_fea->value_len); |
| 6154 | list_len -= name_len + 1 + value_len; |
| 6155 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6156 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6157 | rc = -EIO; |
| 6158 | goto QAllEAsOut; |
| 6159 | } |
| 6160 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6161 | if (ea_name) { |
Jeff Layton | 91d065c | 2011-07-26 18:23:47 -0400 | [diff] [blame] | 6162 | if (ea_name_len == name_len && |
Jeff Layton | ac42344 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6163 | memcmp(ea_name, temp_ptr, name_len) == 0) { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6164 | temp_ptr += name_len + 1; |
| 6165 | rc = value_len; |
| 6166 | if (buf_size == 0) |
| 6167 | goto QAllEAsOut; |
| 6168 | if ((size_t)value_len > buf_size) { |
| 6169 | rc = -ERANGE; |
| 6170 | goto QAllEAsOut; |
| 6171 | } |
| 6172 | memcpy(EAData, temp_ptr, value_len); |
| 6173 | goto QAllEAsOut; |
| 6174 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6175 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6176 | /* account for prefix user. and trailing null */ |
| 6177 | rc += (5 + 1 + name_len); |
| 6178 | if (rc < (int) buf_size) { |
| 6179 | memcpy(EAData, "user.", 5); |
| 6180 | EAData += 5; |
| 6181 | memcpy(EAData, temp_ptr, name_len); |
| 6182 | EAData += name_len; |
| 6183 | /* null terminate name */ |
| 6184 | *EAData = 0; |
| 6185 | ++EAData; |
| 6186 | } else if (buf_size == 0) { |
| 6187 | /* skip copy - calc size only */ |
| 6188 | } else { |
| 6189 | /* stop before overrun buffer */ |
| 6190 | rc = -ERANGE; |
| 6191 | break; |
| 6192 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6193 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6194 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6195 | temp_fea = (struct fea *)temp_ptr; |
| 6196 | } |
| 6197 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6198 | /* didn't find the named attribute */ |
| 6199 | if (ea_name) |
| 6200 | rc = -ENODATA; |
| 6201 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 6202 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 6203 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6204 | if (rc == -EAGAIN) |
| 6205 | goto QAllEAsRetry; |
| 6206 | |
| 6207 | return (ssize_t)rc; |
| 6208 | } |
| 6209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6211 | CIFSSMBSetEA(const int xid, struct cifs_tcon *tcon, const char *fileName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6212 | const char *ea_name, const void *ea_value, |
| 6213 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 6214 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6215 | { |
| 6216 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 6217 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 6218 | struct fealist *parm_data; |
| 6219 | int name_len; |
| 6220 | int rc = 0; |
| 6221 | int bytes_returned = 0; |
| 6222 | __u16 params, param_offset, byte_count, offset, count; |
| 6223 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6224 | cFYI(1, "In SetEA"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6225 | SetEARetry: |
| 6226 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 6227 | (void **) &pSMBr); |
| 6228 | if (rc) |
| 6229 | return rc; |
| 6230 | |
| 6231 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 6232 | name_len = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 6233 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, |
| 6234 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6235 | name_len++; /* trailing null */ |
| 6236 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6237 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6238 | name_len = strnlen(fileName, PATH_MAX); |
| 6239 | name_len++; /* trailing null */ |
| 6240 | strncpy(pSMB->FileName, fileName, name_len); |
| 6241 | } |
| 6242 | |
| 6243 | params = 6 + name_len; |
| 6244 | |
| 6245 | /* done calculating parms using name_len of file name, |
| 6246 | now use name_len to calculate length of ea name |
| 6247 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6248 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6249 | name_len = 0; |
| 6250 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6251 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6252 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 6253 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6254 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 6255 | /* BB find max SMB PDU from sess */ |
| 6256 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6257 | pSMB->MaxSetupCount = 0; |
| 6258 | pSMB->Reserved = 0; |
| 6259 | pSMB->Flags = 0; |
| 6260 | pSMB->Timeout = 0; |
| 6261 | pSMB->Reserved2 = 0; |
| 6262 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6263 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6264 | offset = param_offset + params; |
| 6265 | pSMB->InformationLevel = |
| 6266 | cpu_to_le16(SMB_SET_FILE_EA); |
| 6267 | |
| 6268 | parm_data = |
| 6269 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 6270 | offset); |
| 6271 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 6272 | pSMB->DataOffset = cpu_to_le16(offset); |
| 6273 | pSMB->SetupCount = 1; |
| 6274 | pSMB->Reserved3 = 0; |
| 6275 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 6276 | byte_count = 3 /* pad */ + params + count; |
| 6277 | pSMB->DataCount = cpu_to_le16(count); |
| 6278 | parm_data->list_len = cpu_to_le32(count); |
| 6279 | parm_data->list[0].EA_flags = 0; |
| 6280 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 6281 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6282 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6283 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6284 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6285 | parm_data->list[0].name[name_len] = 0; |
| 6286 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 6287 | /* caller ensures that ea_value_len is less than 64K but |
| 6288 | we need to ensure that it fits within the smb */ |
| 6289 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6290 | /*BB add length check to see if it would fit in |
| 6291 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6292 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 6293 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 6294 | memcpy(parm_data->list[0].name+name_len+1, |
| 6295 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | |
| 6297 | pSMB->TotalDataCount = pSMB->DataCount; |
| 6298 | pSMB->ParameterCount = cpu_to_le16(params); |
| 6299 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 6300 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 6301 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6302 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 6303 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6304 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 6305 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 6306 | cFYI(1, "SetPathInfo (EA) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6307 | |
| 6308 | cifs_buf_release(pSMB); |
| 6309 | |
| 6310 | if (rc == -EAGAIN) |
| 6311 | goto SetEARetry; |
| 6312 | |
| 6313 | return rc; |
| 6314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6315 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6316 | |
| 6317 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 6318 | /* |
| 6319 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 6320 | * to allow network clients (such as Windows) to display updated |
| 6321 | * lists of files in directory listings automatically when |
| 6322 | * files are added by one user when another user has the |
| 6323 | * same directory open on their desktop. The Linux cifs kernel |
| 6324 | * client hooked into the kernel side of this interface for |
| 6325 | * the same reason, but ironically when the VFS moved from |
| 6326 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 6327 | * network file system clients (the most obvious use case |
| 6328 | * for notify interfaces is when multiple users can update |
| 6329 | * the contents of the same directory - exactly what network |
| 6330 | * file systems can do) although the server (Samba) could |
| 6331 | * still use it. For the short term we leave the worker |
| 6332 | * function ifdeffed out (below) until inotify is fixed |
| 6333 | * in the VFS to make it easier to plug in network file |
| 6334 | * system clients. If inotify turns out to be permanently |
| 6335 | * incompatible for network fs clients, we could instead simply |
| 6336 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 6337 | */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 6338 | int CIFSSMBNotify(const int xid, struct cifs_tcon *tcon, |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6339 | const int notify_subdirs, const __u16 netfid, |
| 6340 | __u32 filter, struct file *pfile, int multishot, |
| 6341 | const struct nls_table *nls_codepage) |
| 6342 | { |
| 6343 | int rc = 0; |
| 6344 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 6345 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 6346 | struct dir_notify_req *dnotify_req; |
| 6347 | int bytes_returned; |
| 6348 | |
| 6349 | cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid); |
| 6350 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 6351 | (void **) &pSMBr); |
| 6352 | if (rc) |
| 6353 | return rc; |
| 6354 | |
| 6355 | pSMB->TotalParameterCount = 0 ; |
| 6356 | pSMB->TotalDataCount = 0; |
| 6357 | pSMB->MaxParameterCount = cpu_to_le32(2); |
Jeff Layton | c974bef | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 6358 | pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 6359 | pSMB->MaxSetupCount = 4; |
| 6360 | pSMB->Reserved = 0; |
| 6361 | pSMB->ParameterOffset = 0; |
| 6362 | pSMB->DataCount = 0; |
| 6363 | pSMB->DataOffset = 0; |
| 6364 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 6365 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 6366 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6367 | if (notify_subdirs) |
| 6368 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 6369 | pSMB->Reserved2 = 0; |
| 6370 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 6371 | pSMB->Fid = netfid; /* file handle always le */ |
| 6372 | pSMB->ByteCount = 0; |
| 6373 | |
| 6374 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6375 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 6376 | CIFS_ASYNC_OP); |
| 6377 | if (rc) { |
| 6378 | cFYI(1, "Error in Notify = %d", rc); |
| 6379 | } else { |
| 6380 | /* Add file to outstanding requests */ |
| 6381 | /* BB change to kmem cache alloc */ |
| 6382 | dnotify_req = kmalloc( |
| 6383 | sizeof(struct dir_notify_req), |
| 6384 | GFP_KERNEL); |
| 6385 | if (dnotify_req) { |
| 6386 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 6387 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 6388 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 6389 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 6390 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 6391 | dnotify_req->netfid = netfid; |
| 6392 | dnotify_req->pfile = pfile; |
| 6393 | dnotify_req->filter = filter; |
| 6394 | dnotify_req->multishot = multishot; |
| 6395 | spin_lock(&GlobalMid_Lock); |
| 6396 | list_add_tail(&dnotify_req->lhead, |
| 6397 | &GlobalDnotifyReqList); |
| 6398 | spin_unlock(&GlobalMid_Lock); |
| 6399 | } else |
| 6400 | rc = -ENOMEM; |
| 6401 | } |
| 6402 | cifs_buf_release(pSMB); |
| 6403 | return rc; |
| 6404 | } |
| 6405 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |