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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/uaccess.h> |
| 37 | #include "cifspdu.h" |
| 38 | #include "cifsglob.h" |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 39 | #include "cifsacl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include "cifsproto.h" |
| 41 | #include "cifs_unicode.h" |
| 42 | #include "cifs_debug.h" |
| 43 | |
| 44 | #ifdef CONFIG_CIFS_POSIX |
| 45 | static struct { |
| 46 | int index; |
| 47 | char *name; |
| 48 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 49 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 50 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 51 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 52 | #endif /* weak password hashing for legacy clients */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 53 | {CIFS_PROT, "\2NT LM 0.12"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 54 | {POSIX_PROT, "\2POSIX 2"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | {BAD_PROT, "\2"} |
| 56 | }; |
| 57 | #else |
| 58 | static struct { |
| 59 | int index; |
| 60 | char *name; |
| 61 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 62 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 63 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 18f75ca | 2006-10-01 03:13:01 +0000 | [diff] [blame] | 64 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 65 | #endif /* weak password hashing for legacy clients */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 66 | {CIFS_PROT, "\2NT LM 0.12"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | {BAD_PROT, "\2"} |
| 68 | }; |
| 69 | #endif |
| 70 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 71 | /* define the number of elements in the cifs dialect array */ |
| 72 | #ifdef CONFIG_CIFS_POSIX |
| 73 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 74 | #define CIFS_NUM_PROT 4 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 75 | #else |
| 76 | #define CIFS_NUM_PROT 2 |
| 77 | #endif /* CIFS_WEAK_PW_HASH */ |
| 78 | #else /* not posix */ |
| 79 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 80 | #define CIFS_NUM_PROT 3 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 81 | #else |
| 82 | #define CIFS_NUM_PROT 1 |
| 83 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
| 84 | #endif /* CIFS_POSIX */ |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* Mark as invalid, all open files on tree connections since they |
| 87 | were closed when session to server was lost */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 88 | static void mark_open_files_invalid(struct cifsTconInfo *pTcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 91 | struct list_head *tmp; |
| 92 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* list all files open on tree connection and mark them invalid */ |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 95 | spin_lock(&cifs_file_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | list_for_each_safe(tmp, tmp1, &pTcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 97 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 98 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 99 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 101 | spin_unlock(&cifs_file_list_lock); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 102 | /* BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 103 | to this tcon */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 106 | /* reconnect the socket, tcon, and smb session if needed */ |
| 107 | static int |
| 108 | cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command) |
| 109 | { |
| 110 | int rc = 0; |
| 111 | struct cifsSesInfo *ses; |
| 112 | struct TCP_Server_Info *server; |
| 113 | struct nls_table *nls_codepage; |
| 114 | |
| 115 | /* |
| 116 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 117 | * tcp and smb session status done differently for those three - in the |
| 118 | * calling routine |
| 119 | */ |
| 120 | if (!tcon) |
| 121 | return 0; |
| 122 | |
| 123 | ses = tcon->ses; |
| 124 | server = ses->server; |
| 125 | |
| 126 | /* |
| 127 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 128 | * have tcon) are allowed as we start force umount |
| 129 | */ |
| 130 | if (tcon->tidStatus == CifsExiting) { |
| 131 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 132 | smb_command != SMB_COM_OPEN_ANDX && |
| 133 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 134 | cFYI(1, "can not send cmd %d while umounting", |
| 135 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 136 | return -ENODEV; |
| 137 | } |
| 138 | } |
| 139 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 140 | /* |
| 141 | * Give demultiplex thread up to 10 seconds to reconnect, should be |
| 142 | * greater than cifs socket timeout which is 7 seconds |
| 143 | */ |
| 144 | while (server->tcpStatus == CifsNeedReconnect) { |
| 145 | wait_event_interruptible_timeout(server->response_q, |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 146 | (server->tcpStatus != CifsNeedReconnect), 10 * HZ); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 147 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 148 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 149 | if (server->tcpStatus != CifsNeedReconnect) |
| 150 | break; |
| 151 | |
| 152 | /* |
| 153 | * on "soft" mounts we wait once. Hard mounts keep |
| 154 | * retrying until process is killed or server comes |
| 155 | * back on-line |
| 156 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 157 | if (!tcon->retry) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 158 | cFYI(1, "gave up waiting on reconnect in smb_init"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 159 | return -EHOSTDOWN; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 164 | return 0; |
| 165 | |
| 166 | nls_codepage = load_nls_default(); |
| 167 | |
| 168 | /* |
| 169 | * need to prevent multiple threads trying to simultaneously |
| 170 | * reconnect the same SMB session |
| 171 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 172 | mutex_lock(&ses->session_mutex); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 173 | rc = cifs_negotiate_protocol(0, ses); |
| 174 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 175 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 176 | |
| 177 | /* do we need to reconnect tcon? */ |
| 178 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 179 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 180 | goto out; |
| 181 | } |
| 182 | |
| 183 | mark_open_files_invalid(tcon); |
| 184 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 185 | mutex_unlock(&ses->session_mutex); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 186 | cFYI(1, "reconnect tcon rc = %d", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 187 | |
| 188 | if (rc) |
| 189 | goto out; |
| 190 | |
| 191 | /* |
| 192 | * FIXME: check if wsize needs updated due to negotiated smb buffer |
| 193 | * size shrinking |
| 194 | */ |
| 195 | atomic_inc(&tconInfoReconnectCount); |
| 196 | |
| 197 | /* tell server Unix caps we support */ |
| 198 | if (ses->capabilities & CAP_UNIX) |
| 199 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 200 | |
| 201 | /* |
| 202 | * Removed call to reopen open files here. It is safer (and faster) to |
| 203 | * reopen files one at a time as needed in read and write. |
| 204 | * |
| 205 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 206 | */ |
| 207 | |
| 208 | out: |
| 209 | /* |
| 210 | * Check if handle based operation so we know whether we can continue |
| 211 | * or not without returning to caller to reset file handle |
| 212 | */ |
| 213 | switch (smb_command) { |
| 214 | case SMB_COM_READ_ANDX: |
| 215 | case SMB_COM_WRITE_ANDX: |
| 216 | case SMB_COM_CLOSE: |
| 217 | case SMB_COM_FIND_CLOSE2: |
| 218 | case SMB_COM_LOCKING_ANDX: |
| 219 | rc = -EAGAIN; |
| 220 | } |
| 221 | |
| 222 | unload_nls(nls_codepage); |
| 223 | return rc; |
| 224 | } |
| 225 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 226 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 227 | SMB information in the SMB header. If the return code is zero, this |
| 228 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | static int |
| 230 | small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 231 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 233 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 235 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 236 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | return rc; |
| 238 | |
| 239 | *request_buf = cifs_small_buf_get(); |
| 240 | if (*request_buf == NULL) { |
| 241 | /* BB should we add a retry in here if not a writepage? */ |
| 242 | return -ENOMEM; |
| 243 | } |
| 244 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 245 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 246 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 248 | if (tcon != NULL) |
| 249 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 250 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 251 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 254 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 255 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 256 | struct cifsSesInfo *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 257 | { |
| 258 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 259 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 260 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 261 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 262 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 263 | return rc; |
| 264 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 265 | buffer = (struct smb_hdr *)*request_buf; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 266 | buffer->Mid = GetNextMid(ses->server); |
| 267 | if (ses->capabilities & CAP_UNICODE) |
| 268 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 269 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 270 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 271 | |
| 272 | /* uid, tid can stay at zero as set in header assemble */ |
| 273 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 274 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 275 | this function is used after 1st of session setup requests */ |
| 276 | |
| 277 | return rc; |
| 278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 281 | static int |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 282 | __smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, |
| 283 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | *request_buf = cifs_buf_get(); |
| 286 | if (*request_buf == NULL) { |
| 287 | /* BB should we add a retry in here if not a writepage? */ |
| 288 | return -ENOMEM; |
| 289 | } |
| 290 | /* Although the original thought was we needed the response buf for */ |
| 291 | /* potential retries of smb operations it turns out we can determine */ |
| 292 | /* from the mid flags when the request buffer can be resent without */ |
| 293 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 294 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 295 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 298 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 300 | if (tcon != NULL) |
| 301 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 302 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 307 | static int |
| 308 | smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, |
| 309 | void **request_buf, void **response_buf) |
| 310 | { |
| 311 | int rc; |
| 312 | |
| 313 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 314 | if (rc) |
| 315 | return rc; |
| 316 | |
| 317 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 318 | } |
| 319 | |
| 320 | static int |
| 321 | smb_init_no_reconnect(int smb_command, int wct, struct cifsTconInfo *tcon, |
| 322 | void **request_buf, void **response_buf) |
| 323 | { |
| 324 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 325 | return -EHOSTDOWN; |
| 326 | |
| 327 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 330 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 332 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 334 | /* check for plausible wct */ |
| 335 | if (pSMB->hdr.WordCount < 10) |
| 336 | goto vt2_err; |
| 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 339 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 340 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 341 | goto vt2_err; |
| 342 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 343 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 344 | if (total_size >= 512) |
| 345 | goto vt2_err; |
| 346 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 347 | /* check that bcc is at least as big as parms + data, and that it is |
| 348 | * less than negotiated smb buffer |
| 349 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 350 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 351 | if (total_size > get_bcc(&pSMB->hdr) || |
| 352 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 353 | goto vt2_err; |
| 354 | |
| 355 | return 0; |
| 356 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 357 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 359 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 361 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 362 | static inline void inc_rfc1001_len(void *pSMB, int count) |
| 363 | { |
| 364 | struct smb_hdr *hdr = (struct smb_hdr *)pSMB; |
| 365 | |
| 366 | be32_add_cpu(&hdr->smb_buf_length, count); |
| 367 | } |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | int |
| 370 | CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) |
| 371 | { |
| 372 | NEGOTIATE_REQ *pSMB; |
| 373 | NEGOTIATE_RSP *pSMBr; |
| 374 | int rc = 0; |
| 375 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 376 | int i; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 377 | struct TCP_Server_Info *server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | u16 count; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 379 | unsigned int secFlags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 381 | if (ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | server = ses->server; |
| 383 | else { |
| 384 | rc = -EIO; |
| 385 | return rc; |
| 386 | } |
| 387 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 388 | (void **) &pSMB, (void **) &pSMBr); |
| 389 | if (rc) |
| 390 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 391 | |
| 392 | /* 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] | 393 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 394 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 395 | 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] | 396 | secFlags = global_secflags | ses->overrideSecFlg; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 397 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 398 | cFYI(1, "secFlags 0x%x", secFlags); |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 399 | |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 400 | pSMB->hdr.Mid = GetNextMid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 401 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 402 | |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 403 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 404 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 405 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 406 | cFYI(1, "Kerberos only mechanism, enable extended security"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 407 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Jeff Layton | b4d6fcf | 2011-01-07 11:30:28 -0500 | [diff] [blame] | 408 | } else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 409 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 410 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 411 | cFYI(1, "NTLMSSP only mechanism, enable extended security"); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 412 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 413 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 414 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 415 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 416 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 417 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 418 | count += strlen(protocols[i].name) + 1; |
| 419 | /* null at end of source and target buffers anyway */ |
| 420 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 421 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | pSMB->ByteCount = cpu_to_le16(count); |
| 423 | |
| 424 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 425 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 426 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 427 | goto neg_err_exit; |
| 428 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 429 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
| 430 | cFYI(1, "Dialect: %d", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 431 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 432 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 433 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 434 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 435 | could not negotiate a common dialect */ |
| 436 | rc = -EOPNOTSUPP; |
| 437 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 438 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 439 | } else if ((pSMBr->hdr.WordCount == 13) |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 440 | && ((server->dialect == LANMAN_PROT) |
| 441 | || (server->dialect == LANMAN2_PROT))) { |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 442 | __s16 tmp; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 443 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 444 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 445 | if ((secFlags & CIFSSEC_MAY_LANMAN) || |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 446 | (secFlags & CIFSSEC_MAY_PLNTXT)) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 447 | server->secType = LANMAN; |
| 448 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 449 | cERROR(1, "mount failed weak security disabled" |
| 450 | " in /proc/fs/cifs/SecurityFlags"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 451 | rc = -EOPNOTSUPP; |
| 452 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 453 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 454 | server->secMode = (__u8)le16_to_cpu(rsp->SecurityMode); |
| 455 | server->maxReq = le16_to_cpu(rsp->MaxMpxCount); |
| 456 | server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize), |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 457 | (__u32)CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 458 | server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 459 | /* even though we do not use raw we might as well set this |
| 460 | accurately, in case we ever find a need for it */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 461 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 462 | server->max_rw = 0xFF00; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 463 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 464 | } else { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 465 | server->max_rw = 0;/* do not need to use raw anyway */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 466 | server->capabilities = CAP_MPX_MODE; |
| 467 | } |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 468 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
Steve French | 1a70d65 | 2006-10-02 05:59:18 +0000 | [diff] [blame] | 469 | if (tmp == -1) { |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 470 | /* OS/2 often does not set timezone therefore |
| 471 | * we must use server time to calc time zone. |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 472 | * Could deviate slightly from the right zone. |
| 473 | * Smallest defined timezone difference is 15 minutes |
| 474 | * (i.e. Nepal). Rounding up/down is done to match |
| 475 | * this requirement. |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 476 | */ |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 477 | int val, seconds, remain, result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 478 | struct timespec ts, utc; |
| 479 | utc = CURRENT_TIME; |
Jeff Layton | c4a2c08 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 480 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 481 | rsp->SrvTime.Time, 0); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 482 | cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d", |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 483 | (int)ts.tv_sec, (int)utc.tv_sec, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 484 | (int)(utc.tv_sec - ts.tv_sec)); |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 485 | val = (int)(utc.tv_sec - ts.tv_sec); |
Andre Haupt | 8594c15 | 2007-08-30 20:18:41 +0000 | [diff] [blame] | 486 | seconds = abs(val); |
Steve French | 947a506 | 2006-10-02 05:55:25 +0000 | [diff] [blame] | 487 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 488 | remain = seconds % MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 489 | if (remain >= (MIN_TZ_ADJ / 2)) |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 490 | result += MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 491 | if (val < 0) |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 492 | result = -result; |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 493 | server->timeAdj = result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 494 | } else { |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 495 | server->timeAdj = (int)tmp; |
| 496 | server->timeAdj *= 60; /* also in seconds */ |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 497 | } |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 498 | cFYI(1, "server->timeAdj: %d seconds", server->timeAdj); |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 499 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 500 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 501 | /* BB get server time for time conversions and add |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 502 | code to use it and timezone since this is not UTC */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 503 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 504 | if (rsp->EncryptionKeyLength == |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 505 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 506 | memcpy(ses->server->cryptkey, rsp->EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 507 | CIFS_CRYPTO_KEY_SIZE); |
| 508 | } else if (server->secMode & SECMODE_PW_ENCRYPT) { |
| 509 | rc = -EIO; /* need cryptkey unless plain text */ |
| 510 | goto neg_err_exit; |
| 511 | } |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 512 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 513 | cFYI(1, "LANMAN negotiated"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 514 | /* we will not end up setting signing flags - as no signing |
| 515 | was in LANMAN and server did not return the flags on */ |
| 516 | goto signing_check; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 517 | #else /* weak security disabled */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 518 | } else if (pSMBr->hdr.WordCount == 13) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 519 | cERROR(1, "mount failed, cifs module not built " |
| 520 | "with CIFS_WEAK_PW_HASH support"); |
Dan Carpenter | 8212cf7 | 2010-03-15 11:22:26 +0300 | [diff] [blame] | 521 | rc = -EOPNOTSUPP; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 522 | #endif /* WEAK_PW_HASH */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 523 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 524 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 525 | /* unknown wct */ |
| 526 | rc = -EOPNOTSUPP; |
| 527 | goto neg_err_exit; |
| 528 | } |
| 529 | /* else wct == 17 NTLM */ |
| 530 | server->secMode = pSMBr->SecurityMode; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 531 | if ((server->secMode & SECMODE_USER) == 0) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 532 | cFYI(1, "share mode security"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 533 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 534 | if ((server->secMode & SECMODE_PW_ENCRYPT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 535 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 536 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 537 | #endif /* CIFS_WEAK_PW_HASH */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 538 | cERROR(1, "Server requests plain text password" |
| 539 | " but client support disabled"); |
Steve French | 9312f67 | 2006-06-04 22:21:07 +0000 | [diff] [blame] | 540 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 541 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 542 | server->secType = NTLMv2; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 543 | else if (secFlags & CIFSSEC_MAY_NTLM) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 544 | server->secType = NTLM; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 545 | else if (secFlags & CIFSSEC_MAY_NTLMV2) |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 546 | server->secType = NTLMv2; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 547 | else if (secFlags & CIFSSEC_MAY_KRB5) |
| 548 | server->secType = Kerberos; |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 549 | else if (secFlags & CIFSSEC_MAY_NTLMSSP) |
Steve French | f46c723 | 2009-06-25 03:04:20 +0000 | [diff] [blame] | 550 | server->secType = RawNTLMSSP; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 551 | else if (secFlags & CIFSSEC_MAY_LANMAN) |
| 552 | server->secType = LANMAN; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 553 | else { |
| 554 | rc = -EOPNOTSUPP; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 555 | cERROR(1, "Invalid security type"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 556 | goto neg_err_exit; |
| 557 | } |
| 558 | /* else ... any others ...? */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 559 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 560 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 561 | little endian */ |
| 562 | server->maxReq = le16_to_cpu(pSMBr->MaxMpxCount); |
| 563 | /* probably no need to store and check maxvcs */ |
| 564 | server->maxBuf = min(le32_to_cpu(pSMBr->MaxBufferSize), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 566 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 567 | cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 568 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 569 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 570 | server->timeAdj *= 60; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 571 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 572 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 573 | CIFS_CRYPTO_KEY_SIZE); |
| 574 | } else if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) |
| 575 | && (pSMBr->EncryptionKeyLength == 0)) { |
| 576 | /* decode security blob */ |
| 577 | } else if (server->secMode & SECMODE_PW_ENCRYPT) { |
| 578 | rc = -EIO; /* no crypt key only if plain text pwd */ |
| 579 | goto neg_err_exit; |
| 580 | } |
| 581 | |
| 582 | /* BB might be helpful to save off the domain of server here */ |
| 583 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 584 | if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) && |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 585 | (server->capabilities & CAP_EXTENDED_SECURITY)) { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 586 | count = get_bcc(&pSMBr->hdr); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 587 | if (count < 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | rc = -EIO; |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 589 | goto neg_err_exit; |
| 590 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 591 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 592 | if (server->srv_count > 1) { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 593 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 594 | if (memcmp(server->server_GUID, |
| 595 | pSMBr->u.extended_response. |
| 596 | GUID, 16) != 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 597 | cFYI(1, "server UID changed"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 598 | memcpy(server->server_GUID, |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 599 | pSMBr->u.extended_response.GUID, |
| 600 | 16); |
| 601 | } |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 602 | } else { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 603 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 604 | memcpy(server->server_GUID, |
| 605 | pSMBr->u.extended_response.GUID, 16); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 606 | } |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 607 | |
| 608 | if (count == 16) { |
| 609 | server->secType = RawNTLMSSP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 610 | } else { |
| 611 | rc = decode_negTokenInit(pSMBr->u.extended_response. |
Jeff Layton | 26efa0b | 2010-04-24 07:57:49 -0400 | [diff] [blame] | 612 | SecurityBlob, count - 16, |
| 613 | server); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 614 | if (rc == 1) |
Jeff Layton | e545937 | 2007-11-03 05:11:06 +0000 | [diff] [blame] | 615 | rc = 0; |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 616 | else |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 617 | rc = -EINVAL; |
Shirish Pargaonkar | 2b149f1 | 2010-09-18 22:02:18 -0500 | [diff] [blame] | 618 | if (server->secType == Kerberos) { |
| 619 | if (!server->sec_kerberos && |
| 620 | !server->sec_mskerberos) |
| 621 | rc = -EOPNOTSUPP; |
| 622 | } else if (server->secType == RawNTLMSSP) { |
| 623 | if (!server->sec_ntlmssp) |
| 624 | rc = -EOPNOTSUPP; |
| 625 | } else |
| 626 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 628 | } else |
| 629 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
| 630 | |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 631 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 632 | signing_check: |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 633 | #endif |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 634 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
| 635 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
| 636 | so if this is zero it means that signing is disabled */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 637 | cFYI(1, "Signing disabled"); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 638 | if (server->secMode & SECMODE_SIGN_REQUIRED) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 639 | cERROR(1, "Server requires " |
Jeff Layton | 7111d21 | 2007-10-16 16:50:25 +0000 | [diff] [blame] | 640 | "packet signing to be enabled in " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 641 | "/proc/fs/cifs/SecurityFlags."); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 642 | rc = -EOPNOTSUPP; |
| 643 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 644 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 645 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 646 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
| 647 | /* signing required */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 648 | cFYI(1, "Must sign - secFlags 0x%x", secFlags); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 649 | if ((server->secMode & |
| 650 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 651 | cERROR(1, "signing required but server lacks support"); |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 652 | rc = -EOPNOTSUPP; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 653 | } else |
| 654 | server->secMode |= SECMODE_SIGN_REQUIRED; |
| 655 | } else { |
| 656 | /* signing optional ie CIFSSEC_MAY_SIGN */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 657 | if ((server->secMode & SECMODE_SIGN_REQUIRED) == 0) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 658 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 659 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 661 | |
| 662 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 663 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 664 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 665 | cFYI(1, "negprot rc %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | return rc; |
| 667 | } |
| 668 | |
| 669 | int |
| 670 | CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) |
| 671 | { |
| 672 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 675 | cFYI(1, "In tree disconnect"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 676 | |
| 677 | /* BB: do we need to check this? These should never be NULL. */ |
| 678 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 679 | return -EIO; |
| 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 682 | * No need to return error on this operation if tid invalidated and |
| 683 | * closed on server already e.g. due to tcp session crashing. Also, |
| 684 | * the tcon is no longer on the list, so no need to take lock before |
| 685 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 687 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 688 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 690 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 691 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 692 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 694 | |
| 695 | rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 697 | cFYI(1, "Tree disconnect failed %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 699 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 700 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | if (rc == -EAGAIN) |
| 702 | rc = 0; |
| 703 | |
| 704 | return rc; |
| 705 | } |
| 706 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 707 | /* |
| 708 | * This is a no-op for now. We're not really interested in the reply, but |
| 709 | * rather in the fact that the server sent one and that server->lstrp |
| 710 | * gets updated. |
| 711 | * |
| 712 | * FIXME: maybe we should consider checking that the reply matches request? |
| 713 | */ |
| 714 | static void |
| 715 | cifs_echo_callback(struct mid_q_entry *mid) |
| 716 | { |
| 717 | struct TCP_Server_Info *server = mid->callback_data; |
| 718 | |
| 719 | DeleteMidQEntry(mid); |
| 720 | atomic_dec(&server->inFlight); |
| 721 | wake_up(&server->request_q); |
| 722 | } |
| 723 | |
| 724 | int |
| 725 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 726 | { |
| 727 | ECHO_REQ *smb; |
| 728 | int rc = 0; |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 729 | struct kvec iov; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 730 | |
| 731 | cFYI(1, "In echo request"); |
| 732 | |
| 733 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 734 | if (rc) |
| 735 | return rc; |
| 736 | |
| 737 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 738 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8 | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 739 | smb->hdr.WordCount = 1; |
| 740 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 741 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 742 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 743 | inc_rfc1001_len(smb, 3); |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 744 | iov.iov_base = smb; |
| 745 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 746 | |
Jeff Layton | 59ffd84 | 2011-05-19 16:22:55 -0400 | [diff] [blame] | 747 | rc = cifs_call_async(server, &iov, 1, cifs_echo_callback, server, true); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 748 | if (rc) |
| 749 | cFYI(1, "Echo request failed: %d", rc); |
| 750 | |
| 751 | cifs_small_buf_release(smb); |
| 752 | |
| 753 | return rc; |
| 754 | } |
| 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | int |
| 757 | CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) |
| 758 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | LOGOFF_ANDX_REQ *pSMB; |
| 760 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 762 | cFYI(1, "In SMBLogoff for session disconnect"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 763 | |
| 764 | /* |
| 765 | * BB: do we need to check validity of ses and server? They should |
| 766 | * always be valid since we have an active reference. If not, that |
| 767 | * should probably be a BUG() |
| 768 | */ |
| 769 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | return -EIO; |
| 771 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 772 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 773 | if (ses->need_reconnect) |
| 774 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 775 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 777 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 778 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | return rc; |
| 780 | } |
| 781 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 782 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 783 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 784 | if (ses->server->secMode & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 786 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | pSMB->hdr.Uid = ses->Suid; |
| 789 | |
| 790 | pSMB->AndXCommand = 0xFF; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 791 | rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 792 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 793 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 796 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | error */ |
| 798 | if (rc == -EAGAIN) |
| 799 | rc = 0; |
| 800 | return rc; |
| 801 | } |
| 802 | |
| 803 | int |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 804 | CIFSPOSIXDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 805 | __u16 type, const struct nls_table *nls_codepage, int remap) |
| 806 | { |
| 807 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 808 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 809 | struct unlink_psx_rq *pRqD; |
| 810 | int name_len; |
| 811 | int rc = 0; |
| 812 | int bytes_returned = 0; |
| 813 | __u16 params, param_offset, offset, byte_count; |
| 814 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 815 | cFYI(1, "In POSIX delete"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 816 | PsxDelete: |
| 817 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 818 | (void **) &pSMBr); |
| 819 | if (rc) |
| 820 | return rc; |
| 821 | |
| 822 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 823 | name_len = |
| 824 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
| 825 | PATH_MAX, nls_codepage, remap); |
| 826 | name_len++; /* trailing null */ |
| 827 | name_len *= 2; |
| 828 | } else { /* BB add path length overrun check */ |
| 829 | name_len = strnlen(fileName, PATH_MAX); |
| 830 | name_len++; /* trailing null */ |
| 831 | strncpy(pSMB->FileName, fileName, name_len); |
| 832 | } |
| 833 | |
| 834 | params = 6 + name_len; |
| 835 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 836 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 837 | pSMB->MaxSetupCount = 0; |
| 838 | pSMB->Reserved = 0; |
| 839 | pSMB->Flags = 0; |
| 840 | pSMB->Timeout = 0; |
| 841 | pSMB->Reserved2 = 0; |
| 842 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 843 | InformationLevel) - 4; |
| 844 | offset = param_offset + params; |
| 845 | |
| 846 | /* Setup pointer to Request Data (inode type) */ |
| 847 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 848 | pRqD->type = cpu_to_le16(type); |
| 849 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 850 | pSMB->DataOffset = cpu_to_le16(offset); |
| 851 | pSMB->SetupCount = 1; |
| 852 | pSMB->Reserved3 = 0; |
| 853 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 854 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 855 | |
| 856 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 857 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 858 | pSMB->ParameterCount = cpu_to_le16(params); |
| 859 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 860 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 861 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 862 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 863 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 864 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 865 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 866 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 867 | cFYI(1, "Posix delete returned %d", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 868 | cifs_buf_release(pSMB); |
| 869 | |
| 870 | cifs_stats_inc(&tcon->num_deletes); |
| 871 | |
| 872 | if (rc == -EAGAIN) |
| 873 | goto PsxDelete; |
| 874 | |
| 875 | return rc; |
| 876 | } |
| 877 | |
| 878 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 879 | CIFSSMBDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 880 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | { |
| 882 | DELETE_FILE_REQ *pSMB = NULL; |
| 883 | DELETE_FILE_RSP *pSMBr = NULL; |
| 884 | int rc = 0; |
| 885 | int bytes_returned; |
| 886 | int name_len; |
| 887 | |
| 888 | DelFileRetry: |
| 889 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 890 | (void **) &pSMBr); |
| 891 | if (rc) |
| 892 | return rc; |
| 893 | |
| 894 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 895 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 896 | cifsConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 897 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | name_len++; /* trailing null */ |
| 899 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 900 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | name_len = strnlen(fileName, PATH_MAX); |
| 902 | name_len++; /* trailing null */ |
| 903 | strncpy(pSMB->fileName, fileName, name_len); |
| 904 | } |
| 905 | pSMB->SearchAttributes = |
| 906 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 907 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 908 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 910 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 911 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 912 | cifs_stats_inc(&tcon->num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 913 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 914 | cFYI(1, "Error in RMFile = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | cifs_buf_release(pSMB); |
| 917 | if (rc == -EAGAIN) |
| 918 | goto DelFileRetry; |
| 919 | |
| 920 | return rc; |
| 921 | } |
| 922 | |
| 923 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 924 | CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 925 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | { |
| 927 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 928 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 929 | int rc = 0; |
| 930 | int bytes_returned; |
| 931 | int name_len; |
| 932 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 933 | cFYI(1, "In CIFSSMBRmDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | RmDirRetry: |
| 935 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 936 | (void **) &pSMBr); |
| 937 | if (rc) |
| 938 | return rc; |
| 939 | |
| 940 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 941 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, dirName, |
| 942 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | name_len++; /* trailing null */ |
| 944 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 945 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | name_len = strnlen(dirName, PATH_MAX); |
| 947 | name_len++; /* trailing null */ |
| 948 | strncpy(pSMB->DirName, dirName, name_len); |
| 949 | } |
| 950 | |
| 951 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 952 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 954 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 955 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 956 | cifs_stats_inc(&tcon->num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 957 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 958 | cFYI(1, "Error in RMDir = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
| 960 | cifs_buf_release(pSMB); |
| 961 | if (rc == -EAGAIN) |
| 962 | goto RmDirRetry; |
| 963 | return rc; |
| 964 | } |
| 965 | |
| 966 | int |
| 967 | CIFSSMBMkDir(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 968 | const char *name, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | { |
| 970 | int rc = 0; |
| 971 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 972 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 973 | int bytes_returned; |
| 974 | int name_len; |
| 975 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 976 | cFYI(1, "In CIFSSMBMkDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | MkDirRetry: |
| 978 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 979 | (void **) &pSMBr); |
| 980 | if (rc) |
| 981 | return rc; |
| 982 | |
| 983 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 984 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 985 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | name_len++; /* trailing null */ |
| 987 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 988 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | name_len = strnlen(name, PATH_MAX); |
| 990 | name_len++; /* trailing null */ |
| 991 | strncpy(pSMB->DirName, name, name_len); |
| 992 | } |
| 993 | |
| 994 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 995 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 997 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 998 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 999 | cifs_stats_inc(&tcon->num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1000 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1001 | cFYI(1, "Error in Mkdir = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | cifs_buf_release(pSMB); |
| 1004 | if (rc == -EAGAIN) |
| 1005 | goto MkDirRetry; |
| 1006 | return rc; |
| 1007 | } |
| 1008 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1009 | int |
| 1010 | CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1011 | __u64 mode, __u16 *netfid, FILE_UNIX_BASIC_INFO *pRetData, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1012 | __u32 *pOplock, const char *name, |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1013 | const struct nls_table *nls_codepage, int remap) |
| 1014 | { |
| 1015 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1016 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1017 | int name_len; |
| 1018 | int rc = 0; |
| 1019 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1020 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1021 | OPEN_PSX_REQ *pdata; |
| 1022 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1023 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1024 | cFYI(1, "In POSIX Create"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1025 | PsxCreat: |
| 1026 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1027 | (void **) &pSMBr); |
| 1028 | if (rc) |
| 1029 | return rc; |
| 1030 | |
| 1031 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1032 | name_len = |
| 1033 | cifsConvertToUCS((__le16 *) pSMB->FileName, name, |
| 1034 | PATH_MAX, nls_codepage, remap); |
| 1035 | name_len++; /* trailing null */ |
| 1036 | name_len *= 2; |
| 1037 | } else { /* BB improve the check for buffer overruns BB */ |
| 1038 | name_len = strnlen(name, PATH_MAX); |
| 1039 | name_len++; /* trailing null */ |
| 1040 | strncpy(pSMB->FileName, name, name_len); |
| 1041 | } |
| 1042 | |
| 1043 | params = 6 + name_len; |
| 1044 | count = sizeof(OPEN_PSX_REQ); |
| 1045 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1046 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1047 | pSMB->MaxSetupCount = 0; |
| 1048 | pSMB->Reserved = 0; |
| 1049 | pSMB->Flags = 0; |
| 1050 | pSMB->Timeout = 0; |
| 1051 | pSMB->Reserved2 = 0; |
| 1052 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1053 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1054 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1055 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1056 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1057 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1058 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1059 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1060 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1061 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1062 | pSMB->SetupCount = 1; |
| 1063 | pSMB->Reserved3 = 0; |
| 1064 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1065 | byte_count = 3 /* pad */ + params + count; |
| 1066 | |
| 1067 | pSMB->DataCount = cpu_to_le16(count); |
| 1068 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1069 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1070 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1071 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1072 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1073 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1074 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1075 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1076 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1077 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1078 | cFYI(1, "Posix create returned %d", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1079 | goto psx_create_err; |
| 1080 | } |
| 1081 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1082 | cFYI(1, "copying inode info"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1083 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1084 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1085 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1086 | rc = -EIO; /* bad smb */ |
| 1087 | goto psx_create_err; |
| 1088 | } |
| 1089 | |
| 1090 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1091 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1092 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1093 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1094 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1095 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1096 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1097 | /* Let caller know file was created so we can set the mode. */ |
| 1098 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1099 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1100 | *pOplock |= CIFS_CREATE_ACTION; |
| 1101 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1102 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1103 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1104 | cFYI(DBG2, "unknown type"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1105 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1106 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1107 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1108 | cERROR(1, "Open response data too small"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1109 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1110 | goto psx_create_err; |
| 1111 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1112 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1113 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1114 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1115 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1116 | |
| 1117 | psx_create_err: |
| 1118 | cifs_buf_release(pSMB); |
| 1119 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1120 | if (posix_flags & SMB_O_DIRECTORY) |
| 1121 | cifs_stats_inc(&tcon->num_posixmkdirs); |
| 1122 | else |
| 1123 | cifs_stats_inc(&tcon->num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1124 | |
| 1125 | if (rc == -EAGAIN) |
| 1126 | goto PsxCreat; |
| 1127 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1128 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1131 | static __u16 convert_disposition(int disposition) |
| 1132 | { |
| 1133 | __u16 ofun = 0; |
| 1134 | |
| 1135 | switch (disposition) { |
| 1136 | case FILE_SUPERSEDE: |
| 1137 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1138 | break; |
| 1139 | case FILE_OPEN: |
| 1140 | ofun = SMBOPEN_OAPPEND; |
| 1141 | break; |
| 1142 | case FILE_CREATE: |
| 1143 | ofun = SMBOPEN_OCREATE; |
| 1144 | break; |
| 1145 | case FILE_OPEN_IF: |
| 1146 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1147 | break; |
| 1148 | case FILE_OVERWRITE: |
| 1149 | ofun = SMBOPEN_OTRUNC; |
| 1150 | break; |
| 1151 | case FILE_OVERWRITE_IF: |
| 1152 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1153 | break; |
| 1154 | default: |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1155 | cFYI(1, "unknown disposition %d", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1156 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1157 | } |
| 1158 | return ofun; |
| 1159 | } |
| 1160 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1161 | static int |
| 1162 | access_flags_to_smbopen_mode(const int access_flags) |
| 1163 | { |
| 1164 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1165 | |
| 1166 | if (masked_flags == GENERIC_READ) |
| 1167 | return SMBOPEN_READ; |
| 1168 | else if (masked_flags == GENERIC_WRITE) |
| 1169 | return SMBOPEN_WRITE; |
| 1170 | |
| 1171 | /* just go for read/write */ |
| 1172 | return SMBOPEN_READWRITE; |
| 1173 | } |
| 1174 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1175 | int |
| 1176 | SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, |
| 1177 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1178 | const int access_flags, const int create_options, __u16 *netfid, |
| 1179 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1180 | const struct nls_table *nls_codepage, int remap) |
| 1181 | { |
| 1182 | int rc = -EACCES; |
| 1183 | OPENX_REQ *pSMB = NULL; |
| 1184 | OPENX_RSP *pSMBr = NULL; |
| 1185 | int bytes_returned; |
| 1186 | int name_len; |
| 1187 | __u16 count; |
| 1188 | |
| 1189 | OldOpenRetry: |
| 1190 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1191 | (void **) &pSMBr); |
| 1192 | if (rc) |
| 1193 | return rc; |
| 1194 | |
| 1195 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1196 | |
| 1197 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1198 | count = 1; /* account for one byte pad to word boundary */ |
| 1199 | name_len = |
| 1200 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
| 1201 | fileName, PATH_MAX, nls_codepage, remap); |
| 1202 | name_len++; /* trailing null */ |
| 1203 | name_len *= 2; |
| 1204 | } else { /* BB improve check for buffer overruns BB */ |
| 1205 | count = 0; /* no pad */ |
| 1206 | name_len = strnlen(fileName, PATH_MAX); |
| 1207 | name_len++; /* trailing null */ |
| 1208 | strncpy(pSMB->fileName, fileName, name_len); |
| 1209 | } |
| 1210 | if (*pOplock & REQ_OPLOCK) |
| 1211 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1212 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1213 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1214 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1215 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1216 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1217 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1218 | /* set file as system file if special file such |
| 1219 | as fifo and server expecting SFU style and |
| 1220 | no Unix extensions */ |
| 1221 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1222 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1223 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1224 | else /* BB FIXME BB */ |
| 1225 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1226 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1227 | if (create_options & CREATE_OPTION_READONLY) |
| 1228 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1229 | |
| 1230 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1231 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1232 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1233 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1234 | |
| 1235 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1236 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1237 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1238 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1239 | |
| 1240 | pSMB->ByteCount = cpu_to_le16(count); |
| 1241 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1242 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1243 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1244 | cifs_stats_inc(&tcon->num_opens); |
| 1245 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1246 | cFYI(1, "Error in Open = %d", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1247 | } else { |
| 1248 | /* BB verify if wct == 15 */ |
| 1249 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1250 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1251 | |
| 1252 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1253 | /* Let caller know file was created so we can set the mode. */ |
| 1254 | /* Do we care about the CreateAction in any other cases? */ |
| 1255 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1256 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1257 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1258 | /* BB FIXME END */ |
| 1259 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1260 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1261 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1262 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1263 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1264 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1265 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1266 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1267 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1268 | pfile_info->AllocationSize = |
| 1269 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1270 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1271 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1272 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | cifs_buf_release(pSMB); |
| 1277 | if (rc == -EAGAIN) |
| 1278 | goto OldOpenRetry; |
| 1279 | return rc; |
| 1280 | } |
| 1281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | int |
| 1283 | CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon, |
| 1284 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1285 | const int access_flags, const int create_options, __u16 *netfid, |
| 1286 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1287 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | { |
| 1289 | int rc = -EACCES; |
| 1290 | OPEN_REQ *pSMB = NULL; |
| 1291 | OPEN_RSP *pSMBr = NULL; |
| 1292 | int bytes_returned; |
| 1293 | int name_len; |
| 1294 | __u16 count; |
| 1295 | |
| 1296 | openRetry: |
| 1297 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, |
| 1298 | (void **) &pSMBr); |
| 1299 | if (rc) |
| 1300 | return rc; |
| 1301 | |
| 1302 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1303 | |
| 1304 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1305 | count = 1; /* account for one byte pad to word boundary */ |
| 1306 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 1307 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1308 | fileName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | name_len++; /* trailing null */ |
| 1310 | name_len *= 2; |
| 1311 | pSMB->NameLength = cpu_to_le16(name_len); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1312 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | count = 0; /* no pad */ |
| 1314 | name_len = strnlen(fileName, PATH_MAX); |
| 1315 | name_len++; /* trailing null */ |
| 1316 | pSMB->NameLength = cpu_to_le16(name_len); |
| 1317 | strncpy(pSMB->fileName, fileName, name_len); |
| 1318 | } |
| 1319 | if (*pOplock & REQ_OPLOCK) |
| 1320 | pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1321 | else if (*pOplock & REQ_BATCHOPLOCK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | pSMB->DesiredAccess = cpu_to_le32(access_flags); |
| 1324 | pSMB->AllocationSize = 0; |
Steve French | eda3c02 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1325 | /* set file as system file if special file such |
| 1326 | as fifo and server expecting SFU style and |
| 1327 | no Unix extensions */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1328 | if (create_options & CREATE_OPTION_SPECIAL) |
Steve French | eda3c02 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1329 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1330 | else |
| 1331 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | /* XP does not handle ATTR_POSIX_SEMANTICS */ |
| 1334 | /* but it helps speed up case sensitive checks for other |
| 1335 | servers such as Samba */ |
| 1336 | if (tcon->ses->capabilities & CAP_UNIX) |
| 1337 | pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
| 1338 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1339 | if (create_options & CREATE_OPTION_READONLY) |
| 1340 | pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
| 1341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1343 | pSMB->CreateDisposition = cpu_to_le32(openDisposition); |
Steve French | eda3c02 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1344 | pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1345 | /* BB Expirement with various impersonation levels and verify */ |
| 1346 | pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | pSMB->SecurityFlags = |
| 1348 | SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY; |
| 1349 | |
| 1350 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1351 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
| 1353 | pSMB->ByteCount = cpu_to_le16(count); |
| 1354 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1355 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1356 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1357 | cifs_stats_inc(&tcon->num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1359 | cFYI(1, "Error in Open = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | } else { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1361 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1363 | /* Let caller know file was created so we can set the mode. */ |
| 1364 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1365 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1366 | *pOplock |= CIFS_CREATE_ACTION; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1367 | if (pfile_info) { |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1368 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
| 1369 | 36 /* CreationTime to Attributes */); |
| 1370 | /* the file_info buf is endian converted by caller */ |
| 1371 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
| 1372 | pfile_info->EndOfFile = pSMBr->EndOfFile; |
| 1373 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
| 1374 | pfile_info->DeletePending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | cifs_buf_release(pSMB); |
| 1379 | if (rc == -EAGAIN) |
| 1380 | goto openRetry; |
| 1381 | return rc; |
| 1382 | } |
| 1383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1385 | CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, |
| 1386 | const unsigned int count, const __u64 lseek, unsigned int *nbytes, |
| 1387 | char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | { |
| 1389 | int rc = -EACCES; |
| 1390 | READ_REQ *pSMB = NULL; |
| 1391 | READ_RSP *pSMBr = NULL; |
| 1392 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1393 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1394 | int resp_buf_type = 0; |
| 1395 | struct kvec iov[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1397 | cFYI(1, "Reading %d bytes on fid %d", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1398 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1399 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1400 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1401 | wct = 10; /* old style read */ |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1402 | if ((lseek >> 32) > 0) { |
| 1403 | /* can not handle this big offset for old */ |
| 1404 | return -EIO; |
| 1405 | } |
| 1406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | |
| 1408 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1409 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | if (rc) |
| 1411 | return rc; |
| 1412 | |
| 1413 | /* tcon and ses pointer are checked in smb_init */ |
| 1414 | if (tcon->ses->server == NULL) |
| 1415 | return -ECONNABORTED; |
| 1416 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1417 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | pSMB->Fid = netfid; |
| 1419 | pSMB->OffsetLow = cpu_to_le32(lseek & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1420 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1421 | pSMB->OffsetHigh = cpu_to_le32(lseek >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | pSMB->Remaining = 0; |
| 1424 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1425 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1426 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1427 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1428 | else { |
| 1429 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1430 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1431 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1432 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1433 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1434 | |
| 1435 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1436 | 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] | 1437 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1438 | &resp_buf_type, CIFS_LOG_ERROR); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1439 | cifs_stats_inc(&tcon->num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1440 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1442 | cERROR(1, "Send error in read = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | } else { |
| 1444 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1445 | data_length = data_length << 16; |
| 1446 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1447 | *nbytes = data_length; |
| 1448 | |
| 1449 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1450 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | || (data_length > count)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1452 | cFYI(1, "bad length %d for count %d", |
| 1453 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | rc = -EIO; |
| 1455 | *nbytes = 0; |
| 1456 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1457 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1458 | le16_to_cpu(pSMBr->DataOffset); |
| 1459 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1460 | cERROR(1, "Faulting on read rc = %d",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1461 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1462 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1463 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1464 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | } |
| 1466 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1468 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1469 | if (*buf) { |
| 1470 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1471 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1472 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1473 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1474 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1475 | /* return buffer to caller to free */ |
| 1476 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1477 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1478 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1479 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1480 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1481 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1482 | |
| 1483 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | since file handle passed in no longer valid */ |
| 1485 | return rc; |
| 1486 | } |
| 1487 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame^] | 1490 | CIFSSMBWrite(const int xid, struct cifs_io_parms *io_parms, |
| 1491 | unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1492 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | { |
| 1494 | int rc = -EACCES; |
| 1495 | WRITE_REQ *pSMB = NULL; |
| 1496 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1497 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | __u32 bytes_sent; |
| 1499 | __u16 byte_count; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame^] | 1500 | __u32 pid = io_parms->pid; |
| 1501 | __u16 netfid = io_parms->netfid; |
| 1502 | __u64 offset = io_parms->offset; |
| 1503 | struct cifsTconInfo *tcon = io_parms->tcon; |
| 1504 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1506 | *nbytes = 0; |
| 1507 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1508 | /* cFYI(1, "write at %lld %d bytes", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1509 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1510 | return -ECONNABORTED; |
| 1511 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1512 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1513 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1514 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1515 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1516 | if ((offset >> 32) > 0) { |
| 1517 | /* can not handle big offset for old srv */ |
| 1518 | return -EIO; |
| 1519 | } |
| 1520 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1521 | |
| 1522 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | (void **) &pSMBr); |
| 1524 | if (rc) |
| 1525 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame^] | 1526 | |
| 1527 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1528 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | /* tcon and ses pointer are checked in smb_init */ |
| 1531 | if (tcon->ses->server == NULL) |
| 1532 | return -ECONNABORTED; |
| 1533 | |
| 1534 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1535 | pSMB->Fid = netfid; |
| 1536 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1537 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1538 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | pSMB->Reserved = 0xFFFFFFFF; |
| 1541 | pSMB->WriteMode = 0; |
| 1542 | pSMB->Remaining = 0; |
| 1543 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1544 | /* 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] | 1545 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1546 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1547 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1548 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1550 | } else { |
| 1551 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1552 | & ~0xFF; |
| 1553 | } |
| 1554 | |
| 1555 | if (bytes_sent > count) |
| 1556 | bytes_sent = count; |
| 1557 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1558 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1559 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1560 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1561 | else if (ubuf) { |
| 1562 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | cifs_buf_release(pSMB); |
| 1564 | return -EFAULT; |
| 1565 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1566 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | /* No buffer */ |
| 1568 | cifs_buf_release(pSMB); |
| 1569 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1570 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1571 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1572 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1573 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1574 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1577 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1578 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1579 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1580 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1581 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1582 | else { /* old style write has byte count 4 bytes earlier |
| 1583 | so 4 bytes pad */ |
| 1584 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1585 | (struct smb_com_writex_req *)pSMB; |
| 1586 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1587 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
| 1589 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1590 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1591 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 1593 | cFYI(1, "Send error in write = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | } else { |
| 1595 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1596 | *nbytes = (*nbytes) << 16; |
| 1597 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1598 | |
| 1599 | /* |
| 1600 | * Mask off high 16 bits when bytes written as returned by the |
| 1601 | * server is greater than bytes requested by the client. Some |
| 1602 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1603 | */ |
| 1604 | if (*nbytes > count) |
| 1605 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | cifs_buf_release(pSMB); |
| 1609 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1610 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | since file handle passed in no longer valid */ |
| 1612 | |
| 1613 | return rc; |
| 1614 | } |
| 1615 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1616 | void |
| 1617 | cifs_writedata_release(struct kref *refcount) |
| 1618 | { |
| 1619 | struct cifs_writedata *wdata = container_of(refcount, |
| 1620 | struct cifs_writedata, refcount); |
| 1621 | |
| 1622 | if (wdata->cfile) |
| 1623 | cifsFileInfo_put(wdata->cfile); |
| 1624 | |
| 1625 | kfree(wdata); |
| 1626 | } |
| 1627 | |
| 1628 | /* |
| 1629 | * Write failed with a retryable error. Resend the write request. It's also |
| 1630 | * possible that the page was redirtied so re-clean the page. |
| 1631 | */ |
| 1632 | static void |
| 1633 | cifs_writev_requeue(struct cifs_writedata *wdata) |
| 1634 | { |
| 1635 | int i, rc; |
| 1636 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1637 | |
| 1638 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1639 | lock_page(wdata->pages[i]); |
| 1640 | clear_page_dirty_for_io(wdata->pages[i]); |
| 1641 | } |
| 1642 | |
| 1643 | do { |
| 1644 | rc = cifs_async_writev(wdata); |
| 1645 | } while (rc == -EAGAIN); |
| 1646 | |
| 1647 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1648 | if (rc != 0) |
| 1649 | SetPageError(wdata->pages[i]); |
| 1650 | unlock_page(wdata->pages[i]); |
| 1651 | } |
| 1652 | |
| 1653 | mapping_set_error(inode->i_mapping, rc); |
| 1654 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1655 | } |
| 1656 | |
| 1657 | static void |
| 1658 | cifs_writev_complete(struct work_struct *work) |
| 1659 | { |
| 1660 | struct cifs_writedata *wdata = container_of(work, |
| 1661 | struct cifs_writedata, work); |
| 1662 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1663 | int i = 0; |
| 1664 | |
| 1665 | if (wdata->result == 0) { |
| 1666 | cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); |
| 1667 | cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), |
| 1668 | wdata->bytes); |
| 1669 | } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) |
| 1670 | return cifs_writev_requeue(wdata); |
| 1671 | |
| 1672 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1673 | struct page *page = wdata->pages[i]; |
| 1674 | if (wdata->result == -EAGAIN) |
| 1675 | __set_page_dirty_nobuffers(page); |
| 1676 | else if (wdata->result < 0) |
| 1677 | SetPageError(page); |
| 1678 | end_page_writeback(page); |
| 1679 | page_cache_release(page); |
| 1680 | } |
| 1681 | if (wdata->result != -EAGAIN) |
| 1682 | mapping_set_error(inode->i_mapping, wdata->result); |
| 1683 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1684 | } |
| 1685 | |
| 1686 | struct cifs_writedata * |
| 1687 | cifs_writedata_alloc(unsigned int nr_pages) |
| 1688 | { |
| 1689 | struct cifs_writedata *wdata; |
| 1690 | |
| 1691 | /* this would overflow */ |
| 1692 | if (nr_pages == 0) { |
| 1693 | cERROR(1, "%s: called with nr_pages == 0!", __func__); |
| 1694 | return NULL; |
| 1695 | } |
| 1696 | |
| 1697 | /* writedata + number of page pointers */ |
| 1698 | wdata = kzalloc(sizeof(*wdata) + |
| 1699 | sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); |
| 1700 | if (wdata != NULL) { |
| 1701 | INIT_WORK(&wdata->work, cifs_writev_complete); |
| 1702 | kref_init(&wdata->refcount); |
| 1703 | } |
| 1704 | return wdata; |
| 1705 | } |
| 1706 | |
| 1707 | /* |
| 1708 | * Check the midState and signature on received buffer (if any), and queue the |
| 1709 | * workqueue completion task. |
| 1710 | */ |
| 1711 | static void |
| 1712 | cifs_writev_callback(struct mid_q_entry *mid) |
| 1713 | { |
| 1714 | struct cifs_writedata *wdata = mid->callback_data; |
| 1715 | struct cifsTconInfo *tcon = tlink_tcon(wdata->cfile->tlink); |
| 1716 | unsigned int written; |
| 1717 | WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; |
| 1718 | |
| 1719 | switch (mid->midState) { |
| 1720 | case MID_RESPONSE_RECEIVED: |
| 1721 | wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); |
| 1722 | if (wdata->result != 0) |
| 1723 | break; |
| 1724 | |
| 1725 | written = le16_to_cpu(smb->CountHigh); |
| 1726 | written <<= 16; |
| 1727 | written += le16_to_cpu(smb->Count); |
| 1728 | /* |
| 1729 | * Mask off high 16 bits when bytes written as returned |
| 1730 | * by the server is greater than bytes requested by the |
| 1731 | * client. OS/2 servers are known to set incorrect |
| 1732 | * CountHigh values. |
| 1733 | */ |
| 1734 | if (written > wdata->bytes) |
| 1735 | written &= 0xFFFF; |
| 1736 | |
| 1737 | if (written < wdata->bytes) |
| 1738 | wdata->result = -ENOSPC; |
| 1739 | else |
| 1740 | wdata->bytes = written; |
| 1741 | break; |
| 1742 | case MID_REQUEST_SUBMITTED: |
| 1743 | case MID_RETRY_NEEDED: |
| 1744 | wdata->result = -EAGAIN; |
| 1745 | break; |
| 1746 | default: |
| 1747 | wdata->result = -EIO; |
| 1748 | break; |
| 1749 | } |
| 1750 | |
| 1751 | queue_work(system_nrt_wq, &wdata->work); |
| 1752 | DeleteMidQEntry(mid); |
| 1753 | atomic_dec(&tcon->ses->server->inFlight); |
| 1754 | wake_up(&tcon->ses->server->request_q); |
| 1755 | } |
| 1756 | |
| 1757 | /* cifs_async_writev - send an async write, and set up mid to handle result */ |
| 1758 | int |
| 1759 | cifs_async_writev(struct cifs_writedata *wdata) |
| 1760 | { |
| 1761 | int i, rc = -EACCES; |
| 1762 | WRITE_REQ *smb = NULL; |
| 1763 | int wct; |
| 1764 | struct cifsTconInfo *tcon = tlink_tcon(wdata->cfile->tlink); |
| 1765 | struct inode *inode = wdata->cfile->dentry->d_inode; |
| 1766 | struct kvec *iov = NULL; |
| 1767 | |
| 1768 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
| 1769 | wct = 14; |
| 1770 | } else { |
| 1771 | wct = 12; |
| 1772 | if (wdata->offset >> 32 > 0) { |
| 1773 | /* can not handle big offset for old srv */ |
| 1774 | return -EIO; |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb); |
| 1779 | if (rc) |
| 1780 | goto async_writev_out; |
| 1781 | |
| 1782 | /* 1 iov per page + 1 for header */ |
| 1783 | iov = kzalloc((wdata->nr_pages + 1) * sizeof(*iov), GFP_NOFS); |
| 1784 | if (iov == NULL) { |
| 1785 | rc = -ENOMEM; |
| 1786 | goto async_writev_out; |
| 1787 | } |
| 1788 | |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame^] | 1789 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->cfile->pid); |
| 1790 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->cfile->pid >> 16)); |
| 1791 | |
Jeff Layton | c28c89f | 2011-05-19 16:22:56 -0400 | [diff] [blame] | 1792 | smb->AndXCommand = 0xFF; /* none */ |
| 1793 | smb->Fid = wdata->cfile->netfid; |
| 1794 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
| 1795 | if (wct == 14) |
| 1796 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
| 1797 | smb->Reserved = 0xFFFFFFFF; |
| 1798 | smb->WriteMode = 0; |
| 1799 | smb->Remaining = 0; |
| 1800 | |
| 1801 | smb->DataOffset = |
| 1802 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
| 1803 | |
| 1804 | /* 4 for RFC1001 length + 1 for BCC */ |
| 1805 | iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; |
| 1806 | iov[0].iov_base = smb; |
| 1807 | |
| 1808 | /* marshal up the pages into iov array */ |
| 1809 | wdata->bytes = 0; |
| 1810 | for (i = 0; i < wdata->nr_pages; i++) { |
| 1811 | iov[i + 1].iov_len = min(inode->i_size - |
| 1812 | page_offset(wdata->pages[i]), |
| 1813 | (loff_t)PAGE_CACHE_SIZE); |
| 1814 | iov[i + 1].iov_base = kmap(wdata->pages[i]); |
| 1815 | wdata->bytes += iov[i + 1].iov_len; |
| 1816 | } |
| 1817 | |
| 1818 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); |
| 1819 | |
| 1820 | smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF); |
| 1821 | smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16); |
| 1822 | |
| 1823 | if (wct == 14) { |
| 1824 | inc_rfc1001_len(&smb->hdr, wdata->bytes + 1); |
| 1825 | put_bcc(wdata->bytes + 1, &smb->hdr); |
| 1826 | } else { |
| 1827 | /* wct == 12 */ |
| 1828 | struct smb_com_writex_req *smbw = |
| 1829 | (struct smb_com_writex_req *)smb; |
| 1830 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
| 1831 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
| 1832 | iov[0].iov_len += 4; /* pad bigger by four bytes */ |
| 1833 | } |
| 1834 | |
| 1835 | kref_get(&wdata->refcount); |
| 1836 | rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1, |
| 1837 | cifs_writev_callback, wdata, false); |
| 1838 | |
| 1839 | if (rc == 0) |
| 1840 | cifs_stats_inc(&tcon->num_writes); |
| 1841 | else |
| 1842 | kref_put(&wdata->refcount, cifs_writedata_release); |
| 1843 | |
| 1844 | /* send is done, unmap pages */ |
| 1845 | for (i = 0; i < wdata->nr_pages; i++) |
| 1846 | kunmap(wdata->pages[i]); |
| 1847 | |
| 1848 | async_writev_out: |
| 1849 | cifs_small_buf_release(smb); |
| 1850 | kfree(iov); |
| 1851 | return rc; |
| 1852 | } |
| 1853 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1854 | int |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame^] | 1855 | CIFSSMBWrite2(const int xid, struct cifs_io_parms *io_parms, |
| 1856 | unsigned int *nbytes, struct kvec *iov, int n_vec, |
| 1857 | const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | { |
| 1859 | int rc = -EACCES; |
| 1860 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1861 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1862 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1863 | int resp_buf_type = 0; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame^] | 1864 | __u32 pid = io_parms->pid; |
| 1865 | __u16 netfid = io_parms->netfid; |
| 1866 | __u64 offset = io_parms->offset; |
| 1867 | struct cifsTconInfo *tcon = io_parms->tcon; |
| 1868 | unsigned int count = io_parms->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 1870 | *nbytes = 0; |
| 1871 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1872 | cFYI(1, "write2 at %lld %d bytes", (long long)offset, count); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 1873 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1874 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1875 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1876 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1877 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1878 | if ((offset >> 32) > 0) { |
| 1879 | /* can not handle big offset for old srv */ |
| 1880 | return -EIO; |
| 1881 | } |
| 1882 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1883 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | if (rc) |
| 1885 | return rc; |
Pavel Shilovsky | fa2989f | 2011-05-26 10:01:59 +0400 | [diff] [blame^] | 1886 | |
| 1887 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid); |
| 1888 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16)); |
| 1889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | /* tcon and ses pointer are checked in smb_init */ |
| 1891 | if (tcon->ses->server == NULL) |
| 1892 | return -ECONNABORTED; |
| 1893 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1894 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | pSMB->Fid = netfid; |
| 1896 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1897 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1898 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | pSMB->Reserved = 0xFFFFFFFF; |
| 1900 | pSMB->WriteMode = 0; |
| 1901 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1902 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1904 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1906 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 1907 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1908 | /* header + 1 byte pad */ |
| 1909 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1910 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1911 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1912 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1913 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1914 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1915 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 1916 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1917 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1918 | (struct smb_com_writex_req *)pSMB; |
| 1919 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 1920 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1921 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1922 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1923 | iov[0].iov_len = smb_hdr_len + 4; |
| 1924 | else /* wct == 12 pad bigger by four bytes */ |
| 1925 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1926 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1927 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1928 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1929 | long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1930 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1932 | cFYI(1, "Send error Write2 = %d", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1933 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1934 | /* presumably this can not happen, but best to be safe */ |
| 1935 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1936 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1937 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1938 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1939 | *nbytes = (*nbytes) << 16; |
| 1940 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1941 | |
| 1942 | /* |
| 1943 | * Mask off high 16 bits when bytes written as returned by the |
| 1944 | * server is greater than bytes requested by the client. OS/2 |
| 1945 | * servers are known to set incorrect CountHigh values. |
| 1946 | */ |
| 1947 | if (*nbytes > count) |
| 1948 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1949 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1951 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1952 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1953 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1954 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1955 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1957 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | since file handle passed in no longer valid */ |
| 1959 | |
| 1960 | return rc; |
| 1961 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1962 | |
| 1963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | int |
| 1965 | CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, |
| 1966 | const __u16 smb_file_id, const __u64 len, |
| 1967 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 1968 | const __u32 numLock, const __u8 lockType, |
| 1969 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | { |
| 1971 | int rc = 0; |
| 1972 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 1973 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | int bytes_returned; |
| 1975 | int timeout = 0; |
| 1976 | __u16 count; |
| 1977 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1978 | cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 1979 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 1980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | if (rc) |
| 1982 | return rc; |
| 1983 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1984 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1985 | timeout = CIFS_ASYNC_OP; /* no response expected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1987 | } else if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1988 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 1990 | } else { |
| 1991 | pSMB->Timeout = 0; |
| 1992 | } |
| 1993 | |
| 1994 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 1995 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 1996 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 1997 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1999 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 2000 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2001 | if ((numLock != 0) || (numUnlock != 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | pSMB->Locks[0].Pid = cpu_to_le16(current->tgid); |
| 2003 | /* BB where to store pid high? */ |
| 2004 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 2005 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 2006 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 2007 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 2008 | count = sizeof(LOCKING_ANDX_RANGE); |
| 2009 | } else { |
| 2010 | /* oplock break */ |
| 2011 | count = 0; |
| 2012 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2013 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | pSMB->ByteCount = cpu_to_le16(count); |
| 2015 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2016 | if (waitFlag) { |
| 2017 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 2018 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2019 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2020 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2021 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *)pSMB, |
| 2022 | timeout); |
| 2023 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2024 | } |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2025 | cifs_stats_inc(&tcon->num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2026 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2027 | cFYI(1, "Send error in Lock = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2029 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | since file handle passed in no longer valid */ |
| 2031 | return rc; |
| 2032 | } |
| 2033 | |
| 2034 | int |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2035 | CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, |
| 2036 | const __u16 smb_file_id, const int get_flag, const __u64 len, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2037 | struct file_lock *pLockData, const __u16 lock_type, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 2038 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2039 | { |
| 2040 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2041 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2042 | struct cifs_posix_lock *parm_data; |
| 2043 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2044 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2045 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2046 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2047 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2048 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2049 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2050 | cFYI(1, "Posix Lock"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2051 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2052 | if (pLockData == NULL) |
Marcin Slusarz | ed5f037 | 2008-05-13 04:01:01 +0000 | [diff] [blame] | 2053 | return -EINVAL; |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2054 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2055 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 2056 | |
| 2057 | if (rc) |
| 2058 | return rc; |
| 2059 | |
| 2060 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 2061 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2062 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2063 | pSMB->MaxSetupCount = 0; |
| 2064 | pSMB->Reserved = 0; |
| 2065 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2066 | pSMB->Reserved2 = 0; |
| 2067 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2068 | offset = param_offset + params; |
| 2069 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2070 | count = sizeof(struct cifs_posix_lock); |
| 2071 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2072 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2073 | pSMB->SetupCount = 1; |
| 2074 | pSMB->Reserved3 = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2075 | if (get_flag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2076 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2077 | else |
| 2078 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2079 | byte_count = 3 /* pad */ + params + count; |
| 2080 | pSMB->DataCount = cpu_to_le16(count); |
| 2081 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2082 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2083 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2084 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2085 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2086 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 2087 | |
| 2088 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2089 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2090 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2091 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 2092 | pSMB->Timeout = cpu_to_le32(-1); |
| 2093 | } else |
| 2094 | pSMB->Timeout = 0; |
| 2095 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2096 | parm_data->pid = cpu_to_le32(current->tgid); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2097 | parm_data->start = cpu_to_le64(pLockData->fl_start); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 2098 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2099 | |
| 2100 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 2101 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2102 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 2103 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2104 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2105 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2106 | if (waitFlag) { |
| 2107 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 2108 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 2109 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2110 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2111 | 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] | 2112 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 2113 | &resp_buf_type, timeout); |
| 2114 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 2115 | not try to free it twice below on exit */ |
| 2116 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2119 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2120 | cFYI(1, "Send error in Posix Lock = %d", rc); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2121 | } else if (get_flag) { |
| 2122 | /* lock structure can be returned on get */ |
| 2123 | __u16 data_offset; |
| 2124 | __u16 data_count; |
| 2125 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2126 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2127 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2128 | rc = -EIO; /* bad smb */ |
| 2129 | goto plk_err_exit; |
| 2130 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2131 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2132 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2133 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2134 | rc = -EIO; |
| 2135 | goto plk_err_exit; |
| 2136 | } |
| 2137 | parm_data = (struct cifs_posix_lock *) |
| 2138 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2139 | if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2140 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2141 | else { |
| 2142 | if (parm_data->lock_type == |
| 2143 | __constant_cpu_to_le16(CIFS_RDLCK)) |
| 2144 | pLockData->fl_type = F_RDLCK; |
| 2145 | else if (parm_data->lock_type == |
| 2146 | __constant_cpu_to_le16(CIFS_WRLCK)) |
| 2147 | pLockData->fl_type = F_WRLCK; |
| 2148 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 2149 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 2150 | pLockData->fl_end = pLockData->fl_start + |
| 2151 | le64_to_cpu(parm_data->length) - 1; |
| 2152 | pLockData->fl_pid = le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 2153 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2154 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2155 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 2156 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2157 | if (pSMB) |
| 2158 | cifs_small_buf_release(pSMB); |
| 2159 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2160 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 2161 | cifs_small_buf_release(iov[0].iov_base); |
| 2162 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 2163 | cifs_buf_release(iov[0].iov_base); |
| 2164 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 2165 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2166 | since file handle passed in no longer valid */ |
| 2167 | |
| 2168 | return rc; |
| 2169 | } |
| 2170 | |
| 2171 | |
| 2172 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) |
| 2174 | { |
| 2175 | int rc = 0; |
| 2176 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2177 | cFYI(1, "In CIFSSMBClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | |
| 2179 | /* do not retry on dead session on close */ |
| 2180 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2181 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | return 0; |
| 2183 | if (rc) |
| 2184 | return rc; |
| 2185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 2187 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 2189 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2190 | cifs_stats_inc(&tcon->num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2192 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2194 | cERROR(1, "Send error in Close = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2199 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | rc = 0; |
| 2201 | |
| 2202 | return rc; |
| 2203 | } |
| 2204 | |
| 2205 | int |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2206 | CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, int smb_file_id) |
| 2207 | { |
| 2208 | int rc = 0; |
| 2209 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2210 | cFYI(1, "In CIFSSMBFlush"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2211 | |
| 2212 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 2213 | if (rc) |
| 2214 | return rc; |
| 2215 | |
| 2216 | pSMB->FileID = (__u16) smb_file_id; |
| 2217 | pSMB->ByteCount = 0; |
| 2218 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 2219 | cifs_stats_inc(&tcon->num_flushes); |
| 2220 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2221 | cERROR(1, "Send error in Flush = %d", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 2222 | |
| 2223 | return rc; |
| 2224 | } |
| 2225 | |
| 2226 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | CIFSSMBRename(const int xid, struct cifsTconInfo *tcon, |
| 2228 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2229 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | { |
| 2231 | int rc = 0; |
| 2232 | RENAME_REQ *pSMB = NULL; |
| 2233 | RENAME_RSP *pSMBr = NULL; |
| 2234 | int bytes_returned; |
| 2235 | int name_len, name_len2; |
| 2236 | __u16 count; |
| 2237 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2238 | cFYI(1, "In CIFSSMBRename"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | renameRetry: |
| 2240 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 2241 | (void **) &pSMBr); |
| 2242 | if (rc) |
| 2243 | return rc; |
| 2244 | |
| 2245 | pSMB->BufferFormat = 0x04; |
| 2246 | pSMB->SearchAttributes = |
| 2247 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2248 | ATTR_DIRECTORY); |
| 2249 | |
| 2250 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2251 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2252 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2253 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | name_len++; /* trailing null */ |
| 2255 | name_len *= 2; |
| 2256 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2257 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2258 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2259 | name_len2 = |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 2260 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2261 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2263 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2264 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | name_len = strnlen(fromName, PATH_MAX); |
| 2266 | name_len++; /* trailing null */ |
| 2267 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2268 | name_len2 = strnlen(toName, PATH_MAX); |
| 2269 | name_len2++; /* trailing null */ |
| 2270 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2271 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2272 | name_len2++; /* trailing null */ |
| 2273 | name_len2++; /* signature byte */ |
| 2274 | } |
| 2275 | |
| 2276 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2277 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | pSMB->ByteCount = cpu_to_le16(count); |
| 2279 | |
| 2280 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2281 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2282 | cifs_stats_inc(&tcon->num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2283 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2284 | cFYI(1, "Send error in rename = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | cifs_buf_release(pSMB); |
| 2287 | |
| 2288 | if (rc == -EAGAIN) |
| 2289 | goto renameRetry; |
| 2290 | |
| 2291 | return rc; |
| 2292 | } |
| 2293 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2294 | int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2295 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2296 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | { |
| 2298 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2299 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2300 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | char *data_offset; |
| 2302 | char dummy_string[30]; |
| 2303 | int rc = 0; |
| 2304 | int bytes_returned = 0; |
| 2305 | int len_of_str; |
| 2306 | __u16 params, param_offset, offset, count, byte_count; |
| 2307 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2308 | cFYI(1, "Rename to File by handle"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2310 | (void **) &pSMBr); |
| 2311 | if (rc) |
| 2312 | return rc; |
| 2313 | |
| 2314 | params = 6; |
| 2315 | pSMB->MaxSetupCount = 0; |
| 2316 | pSMB->Reserved = 0; |
| 2317 | pSMB->Flags = 0; |
| 2318 | pSMB->Timeout = 0; |
| 2319 | pSMB->Reserved2 = 0; |
| 2320 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2321 | offset = param_offset + params; |
| 2322 | |
| 2323 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2324 | rename_info = (struct set_file_rename *) data_offset; |
| 2325 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2326 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | pSMB->SetupCount = 1; |
| 2328 | pSMB->Reserved3 = 0; |
| 2329 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2330 | byte_count = 3 /* pad */ + params; |
| 2331 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2332 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2333 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2334 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2335 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2336 | rename_info->overwrite = cpu_to_le32(1); |
| 2337 | rename_info->root_fid = 0; |
| 2338 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2339 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2340 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
| 2341 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2342 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | } else { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2344 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2345 | target_name, PATH_MAX, nls_codepage, |
| 2346 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | } |
| 2348 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2349 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | byte_count += count; |
| 2351 | pSMB->DataCount = cpu_to_le16(count); |
| 2352 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2353 | pSMB->Fid = netfid; |
| 2354 | pSMB->InformationLevel = |
| 2355 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2356 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2357 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2359 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2360 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2361 | cifs_stats_inc(&pTcon->num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2362 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2363 | cFYI(1, "Send error in Rename (by file handle) = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | cifs_buf_release(pSMB); |
| 2366 | |
| 2367 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2368 | since file handle passed in no longer valid */ |
| 2369 | |
| 2370 | return rc; |
| 2371 | } |
| 2372 | |
| 2373 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2374 | CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char *fromName, |
| 2375 | const __u16 target_tid, const char *toName, const int flags, |
| 2376 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | { |
| 2378 | int rc = 0; |
| 2379 | COPY_REQ *pSMB = NULL; |
| 2380 | COPY_RSP *pSMBr = NULL; |
| 2381 | int bytes_returned; |
| 2382 | int name_len, name_len2; |
| 2383 | __u16 count; |
| 2384 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2385 | cFYI(1, "In CIFSSMBCopy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | copyRetry: |
| 2387 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2388 | (void **) &pSMBr); |
| 2389 | if (rc) |
| 2390 | return rc; |
| 2391 | |
| 2392 | pSMB->BufferFormat = 0x04; |
| 2393 | pSMB->Tid2 = target_tid; |
| 2394 | |
| 2395 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2396 | |
| 2397 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2398 | name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2399 | fromName, PATH_MAX, nls_codepage, |
| 2400 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | name_len++; /* trailing null */ |
| 2402 | name_len *= 2; |
| 2403 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2404 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2405 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2406 | name_len2 = |
| 2407 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2408 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2410 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2411 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | name_len = strnlen(fromName, PATH_MAX); |
| 2413 | name_len++; /* trailing null */ |
| 2414 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2415 | name_len2 = strnlen(toName, PATH_MAX); |
| 2416 | name_len2++; /* trailing null */ |
| 2417 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2418 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2419 | name_len2++; /* trailing null */ |
| 2420 | name_len2++; /* signature byte */ |
| 2421 | } |
| 2422 | |
| 2423 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2424 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | pSMB->ByteCount = cpu_to_le16(count); |
| 2426 | |
| 2427 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2428 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2429 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2430 | cFYI(1, "Send error in copy = %d with %d files copied", |
| 2431 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2433 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | |
| 2435 | if (rc == -EAGAIN) |
| 2436 | goto copyRetry; |
| 2437 | |
| 2438 | return rc; |
| 2439 | } |
| 2440 | |
| 2441 | int |
| 2442 | CIFSUnixCreateSymLink(const int xid, struct cifsTconInfo *tcon, |
| 2443 | const char *fromName, const char *toName, |
| 2444 | const struct nls_table *nls_codepage) |
| 2445 | { |
| 2446 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2447 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2448 | char *data_offset; |
| 2449 | int name_len; |
| 2450 | int name_len_target; |
| 2451 | int rc = 0; |
| 2452 | int bytes_returned = 0; |
| 2453 | __u16 params, param_offset, offset, byte_count; |
| 2454 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2455 | cFYI(1, "In Symlink Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | createSymLinkRetry: |
| 2457 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2458 | (void **) &pSMBr); |
| 2459 | if (rc) |
| 2460 | return rc; |
| 2461 | |
| 2462 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2463 | name_len = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2464 | cifs_strtoUCS((__le16 *) pSMB->FileName, fromName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | /* find define for this maxpathcomponent */ |
| 2466 | , nls_codepage); |
| 2467 | name_len++; /* trailing null */ |
| 2468 | name_len *= 2; |
| 2469 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2470 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | name_len = strnlen(fromName, PATH_MAX); |
| 2472 | name_len++; /* trailing null */ |
| 2473 | strncpy(pSMB->FileName, fromName, name_len); |
| 2474 | } |
| 2475 | params = 6 + name_len; |
| 2476 | pSMB->MaxSetupCount = 0; |
| 2477 | pSMB->Reserved = 0; |
| 2478 | pSMB->Flags = 0; |
| 2479 | pSMB->Timeout = 0; |
| 2480 | pSMB->Reserved2 = 0; |
| 2481 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2482 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | offset = param_offset + params; |
| 2484 | |
| 2485 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2486 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2487 | name_len_target = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2488 | cifs_strtoUCS((__le16 *) data_offset, toName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | /* find define for this maxpathcomponent */ |
| 2490 | , nls_codepage); |
| 2491 | name_len_target++; /* trailing null */ |
| 2492 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2493 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | name_len_target = strnlen(toName, PATH_MAX); |
| 2495 | name_len_target++; /* trailing null */ |
| 2496 | strncpy(data_offset, toName, name_len_target); |
| 2497 | } |
| 2498 | |
| 2499 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2500 | /* BB find exact max on data count below from sess */ |
| 2501 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2502 | pSMB->SetupCount = 1; |
| 2503 | pSMB->Reserved3 = 0; |
| 2504 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2505 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2506 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2507 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2508 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2509 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2510 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2511 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2512 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2513 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2514 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2516 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2517 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2518 | cifs_stats_inc(&tcon->num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2519 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2520 | cFYI(1, "Send error in SetPathInfo create symlink = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2522 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | |
| 2524 | if (rc == -EAGAIN) |
| 2525 | goto createSymLinkRetry; |
| 2526 | |
| 2527 | return rc; |
| 2528 | } |
| 2529 | |
| 2530 | int |
| 2531 | CIFSUnixCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2532 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2533 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | { |
| 2535 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2536 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2537 | char *data_offset; |
| 2538 | int name_len; |
| 2539 | int name_len_target; |
| 2540 | int rc = 0; |
| 2541 | int bytes_returned = 0; |
| 2542 | __u16 params, param_offset, offset, byte_count; |
| 2543 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2544 | cFYI(1, "In Create Hard link Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | createHardLinkRetry: |
| 2546 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2547 | (void **) &pSMBr); |
| 2548 | if (rc) |
| 2549 | return rc; |
| 2550 | |
| 2551 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2552 | name_len = cifsConvertToUCS((__le16 *) pSMB->FileName, toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2553 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | name_len++; /* trailing null */ |
| 2555 | name_len *= 2; |
| 2556 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2557 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | name_len = strnlen(toName, PATH_MAX); |
| 2559 | name_len++; /* trailing null */ |
| 2560 | strncpy(pSMB->FileName, toName, name_len); |
| 2561 | } |
| 2562 | params = 6 + name_len; |
| 2563 | pSMB->MaxSetupCount = 0; |
| 2564 | pSMB->Reserved = 0; |
| 2565 | pSMB->Flags = 0; |
| 2566 | pSMB->Timeout = 0; |
| 2567 | pSMB->Reserved2 = 0; |
| 2568 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2569 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | offset = param_offset + params; |
| 2571 | |
| 2572 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2573 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2574 | name_len_target = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2575 | cifsConvertToUCS((__le16 *) data_offset, fromName, PATH_MAX, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2576 | nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | name_len_target++; /* trailing null */ |
| 2578 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2579 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2581 | name_len_target++; /* trailing null */ |
| 2582 | strncpy(data_offset, fromName, name_len_target); |
| 2583 | } |
| 2584 | |
| 2585 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2586 | /* BB find exact max on data count below from sess*/ |
| 2587 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2588 | pSMB->SetupCount = 1; |
| 2589 | pSMB->Reserved3 = 0; |
| 2590 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2591 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2592 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2593 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2594 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2595 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2596 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2597 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2598 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2599 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2600 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2602 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2603 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2604 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2605 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2606 | cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | |
| 2608 | cifs_buf_release(pSMB); |
| 2609 | if (rc == -EAGAIN) |
| 2610 | goto createHardLinkRetry; |
| 2611 | |
| 2612 | return rc; |
| 2613 | } |
| 2614 | |
| 2615 | int |
| 2616 | CIFSCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2617 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2618 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | { |
| 2620 | int rc = 0; |
| 2621 | NT_RENAME_REQ *pSMB = NULL; |
| 2622 | RENAME_RSP *pSMBr = NULL; |
| 2623 | int bytes_returned; |
| 2624 | int name_len, name_len2; |
| 2625 | __u16 count; |
| 2626 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2627 | cFYI(1, "In CIFSCreateHardLink"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | winCreateHardLinkRetry: |
| 2629 | |
| 2630 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2631 | (void **) &pSMBr); |
| 2632 | if (rc) |
| 2633 | return rc; |
| 2634 | |
| 2635 | pSMB->SearchAttributes = |
| 2636 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2637 | ATTR_DIRECTORY); |
| 2638 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 2639 | pSMB->ClusterCount = 0; |
| 2640 | |
| 2641 | pSMB->BufferFormat = 0x04; |
| 2642 | |
| 2643 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2644 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2645 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2646 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | name_len++; /* trailing null */ |
| 2648 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 2649 | |
| 2650 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 2651 | pSMB->OldFileName[name_len] = 0x04; |
| 2652 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | name_len2 = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2654 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2655 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2657 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2658 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | name_len = strnlen(fromName, PATH_MAX); |
| 2660 | name_len++; /* trailing null */ |
| 2661 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2662 | name_len2 = strnlen(toName, PATH_MAX); |
| 2663 | name_len2++; /* trailing null */ |
| 2664 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2665 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2666 | name_len2++; /* trailing null */ |
| 2667 | name_len2++; /* signature byte */ |
| 2668 | } |
| 2669 | |
| 2670 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2671 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | pSMB->ByteCount = cpu_to_le16(count); |
| 2673 | |
| 2674 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2675 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2676 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2677 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2678 | cFYI(1, "Send error in hard link (NT rename) = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | cifs_buf_release(pSMB); |
| 2681 | if (rc == -EAGAIN) |
| 2682 | goto winCreateHardLinkRetry; |
| 2683 | |
| 2684 | return rc; |
| 2685 | } |
| 2686 | |
| 2687 | int |
| 2688 | CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2689 | const unsigned char *searchName, char **symlinkinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | const struct nls_table *nls_codepage) |
| 2691 | { |
| 2692 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 2693 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2694 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2695 | int rc = 0; |
| 2696 | int bytes_returned; |
| 2697 | int name_len; |
| 2698 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2699 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2701 | cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | |
| 2703 | querySymLinkRetry: |
| 2704 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2705 | (void **) &pSMBr); |
| 2706 | if (rc) |
| 2707 | return rc; |
| 2708 | |
| 2709 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2710 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2711 | cifs_strtoUCS((__le16 *) pSMB->FileName, searchName, |
| 2712 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | name_len++; /* trailing null */ |
| 2714 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2715 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | name_len = strnlen(searchName, PATH_MAX); |
| 2717 | name_len++; /* trailing null */ |
| 2718 | strncpy(pSMB->FileName, searchName, name_len); |
| 2719 | } |
| 2720 | |
| 2721 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 2722 | pSMB->TotalDataCount = 0; |
| 2723 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 2724 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | pSMB->MaxSetupCount = 0; |
| 2726 | pSMB->Reserved = 0; |
| 2727 | pSMB->Flags = 0; |
| 2728 | pSMB->Timeout = 0; |
| 2729 | pSMB->Reserved2 = 0; |
| 2730 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2731 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | pSMB->DataCount = 0; |
| 2733 | pSMB->DataOffset = 0; |
| 2734 | pSMB->SetupCount = 1; |
| 2735 | pSMB->Reserved3 = 0; |
| 2736 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 2737 | byte_count = params + 1 /* pad */ ; |
| 2738 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 2739 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2740 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 2741 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2742 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2744 | |
| 2745 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2746 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2747 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2748 | cFYI(1, "Send error in QuerySymLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | } else { |
| 2750 | /* decode response */ |
| 2751 | |
| 2752 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2754 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2755 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 2757 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2758 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2760 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 2761 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 2762 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 2763 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 2764 | is_unicode = true; |
| 2765 | else |
| 2766 | is_unicode = false; |
| 2767 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2768 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 2769 | *symlinkinfo = cifs_strndup_from_ucs(data_start, count, |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 2770 | is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 2771 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2772 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | } |
| 2774 | } |
| 2775 | cifs_buf_release(pSMB); |
| 2776 | if (rc == -EAGAIN) |
| 2777 | goto querySymLinkRetry; |
| 2778 | return rc; |
| 2779 | } |
| 2780 | |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 2781 | #ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL |
| 2782 | /* |
| 2783 | * Recent Windows versions now create symlinks more frequently |
| 2784 | * and they use the "reparse point" mechanism below. We can of course |
| 2785 | * do symlinks nicely to Samba and other servers which support the |
| 2786 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 2787 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 2788 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 2789 | * In the interim this code has been moved to its own config option so |
| 2790 | * it is not compiled in by default until callers fixed up and more tested. |
| 2791 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | int |
| 2793 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, |
| 2794 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2795 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | const struct nls_table *nls_codepage) |
| 2797 | { |
| 2798 | int rc = 0; |
| 2799 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2800 | struct smb_com_transaction_ioctl_req *pSMB; |
| 2801 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2803 | cFYI(1, "In Windows reparse style QueryLink for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 2805 | (void **) &pSMBr); |
| 2806 | if (rc) |
| 2807 | return rc; |
| 2808 | |
| 2809 | pSMB->TotalParameterCount = 0 ; |
| 2810 | pSMB->TotalDataCount = 0; |
| 2811 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 2812 | /* BB find exact data count max from sess structure BB */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2813 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 2814 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | pSMB->MaxSetupCount = 4; |
| 2816 | pSMB->Reserved = 0; |
| 2817 | pSMB->ParameterOffset = 0; |
| 2818 | pSMB->DataCount = 0; |
| 2819 | pSMB->DataOffset = 0; |
| 2820 | pSMB->SetupCount = 4; |
| 2821 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 2822 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2823 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 2824 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 2825 | pSMB->IsRootFlag = 0; |
| 2826 | pSMB->Fid = fid; /* file handle always le */ |
| 2827 | pSMB->ByteCount = 0; |
| 2828 | |
| 2829 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2830 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2831 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2832 | cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | } else { /* decode response */ |
| 2834 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 2835 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2836 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 2837 | /* BB also check enough total bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | rc = -EIO; /* bad smb */ |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2839 | goto qreparse_out; |
| 2840 | } |
| 2841 | if (data_count && (data_count < 2048)) { |
| 2842 | char *end_of_smb = 2 /* sizeof byte count */ + |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2843 | get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2845 | struct reparse_data *reparse_buf = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2846 | (struct reparse_data *) |
| 2847 | ((char *)&pSMBr->hdr.Protocol |
| 2848 | + data_offset); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2849 | if ((char *)reparse_buf >= end_of_smb) { |
| 2850 | rc = -EIO; |
| 2851 | goto qreparse_out; |
| 2852 | } |
| 2853 | if ((reparse_buf->LinkNamesBuf + |
| 2854 | reparse_buf->TargetNameOffset + |
| 2855 | reparse_buf->TargetNameLen) > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2856 | cFYI(1, "reparse buf beyond SMB"); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2857 | rc = -EIO; |
| 2858 | goto qreparse_out; |
| 2859 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2860 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2861 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2862 | cifs_from_ucs2(symlinkinfo, (__le16 *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2863 | (reparse_buf->LinkNamesBuf + |
| 2864 | reparse_buf->TargetNameOffset), |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2865 | buflen, |
| 2866 | reparse_buf->TargetNameLen, |
| 2867 | nls_codepage, 0); |
| 2868 | } else { /* ASCII names */ |
| 2869 | strncpy(symlinkinfo, |
| 2870 | reparse_buf->LinkNamesBuf + |
| 2871 | reparse_buf->TargetNameOffset, |
| 2872 | min_t(const int, buflen, |
| 2873 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2875 | } else { |
| 2876 | rc = -EIO; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2877 | cFYI(1, "Invalid return data count on " |
| 2878 | "get reparse info ioctl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2880 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 2881 | does not go off the end of the buffer */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2882 | cFYI(1, "readlink result - %s", symlinkinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 2884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 2886 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | |
| 2888 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2889 | since file handle passed in no longer valid */ |
| 2890 | |
| 2891 | return rc; |
| 2892 | } |
Steve French | c52a955 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 2893 | #endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | |
| 2895 | #ifdef CONFIG_CIFS_POSIX |
| 2896 | |
| 2897 | /*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] | 2898 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 2899 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | { |
| 2901 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2902 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 2903 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 2904 | 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] | 2905 | /* 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] | 2906 | |
| 2907 | return; |
| 2908 | } |
| 2909 | |
| 2910 | /* 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] | 2911 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 2912 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | { |
| 2914 | int size = 0; |
| 2915 | int i; |
| 2916 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2917 | struct cifs_posix_ace *pACE; |
| 2918 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 2919 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | |
| 2921 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 2922 | return -EOPNOTSUPP; |
| 2923 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2924 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2926 | pACE = &cifs_acl->ace_array[0]; |
| 2927 | size = sizeof(struct cifs_posix_acl); |
| 2928 | size += sizeof(struct cifs_posix_ace) * count; |
| 2929 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2930 | if (size_of_data_area < size) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2931 | cFYI(1, "bad CIFS POSIX ACL size %d vs. %d", |
| 2932 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | return -EINVAL; |
| 2934 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2935 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2937 | size = sizeof(struct cifs_posix_acl); |
| 2938 | size += sizeof(struct cifs_posix_ace) * count; |
| 2939 | /* skip past access ACEs to get to default ACEs */ |
| 2940 | pACE = &cifs_acl->ace_array[count]; |
| 2941 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 2942 | size += sizeof(struct cifs_posix_ace) * count; |
| 2943 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2944 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | return -EINVAL; |
| 2946 | } else { |
| 2947 | /* illegal type */ |
| 2948 | return -EINVAL; |
| 2949 | } |
| 2950 | |
| 2951 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2952 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2953 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2954 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | return -ERANGE; |
| 2956 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2957 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2958 | for (i = 0; i < count ; i++) { |
| 2959 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 2960 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | } |
| 2962 | } |
| 2963 | return size; |
| 2964 | } |
| 2965 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2966 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 2967 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | { |
| 2969 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 2970 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2971 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 2972 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2974 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 2976 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2977 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2978 | 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] | 2979 | /*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] | 2980 | return rc; |
| 2981 | } |
| 2982 | |
| 2983 | /* 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] | 2984 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 2985 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | { |
| 2987 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2988 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 2989 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | int count; |
| 2991 | int i; |
| 2992 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2993 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | return 0; |
| 2995 | |
| 2996 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2997 | 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] | 2998 | "version of %d", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2999 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3000 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3001 | cFYI(1, "unknown POSIX ACL version %d", |
| 3002 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | return 0; |
| 3004 | } |
| 3005 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3006 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3007 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3008 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 3009 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3011 | cFYI(1, "unknown ACL type %d", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | return 0; |
| 3013 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3014 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 3016 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3017 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | /* ACE not converted */ |
| 3019 | break; |
| 3020 | } |
| 3021 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3022 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 3024 | rc += sizeof(struct cifs_posix_acl); |
| 3025 | /* BB add check to make sure ACL does not overflow SMB */ |
| 3026 | } |
| 3027 | return rc; |
| 3028 | } |
| 3029 | |
| 3030 | int |
| 3031 | CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3032 | const unsigned char *searchName, |
| 3033 | char *acl_inf, const int buflen, const int acl_type, |
| 3034 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | { |
| 3036 | /* SMB_QUERY_POSIX_ACL */ |
| 3037 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3038 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3039 | int rc = 0; |
| 3040 | int bytes_returned; |
| 3041 | int name_len; |
| 3042 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3043 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3044 | cFYI(1, "In GetPosixACL (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | |
| 3046 | queryAclRetry: |
| 3047 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3048 | (void **) &pSMBr); |
| 3049 | if (rc) |
| 3050 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3053 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3054 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3055 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | name_len++; /* trailing null */ |
| 3057 | name_len *= 2; |
| 3058 | pSMB->FileName[name_len] = 0; |
| 3059 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3060 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | name_len = strnlen(searchName, PATH_MAX); |
| 3062 | name_len++; /* trailing null */ |
| 3063 | strncpy(pSMB->FileName, searchName, name_len); |
| 3064 | } |
| 3065 | |
| 3066 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3067 | pSMB->TotalDataCount = 0; |
| 3068 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3069 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3071 | pSMB->MaxSetupCount = 0; |
| 3072 | pSMB->Reserved = 0; |
| 3073 | pSMB->Flags = 0; |
| 3074 | pSMB->Timeout = 0; |
| 3075 | pSMB->Reserved2 = 0; |
| 3076 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3077 | offsetof(struct smb_com_transaction2_qpi_req, |
| 3078 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | pSMB->DataCount = 0; |
| 3080 | pSMB->DataOffset = 0; |
| 3081 | pSMB->SetupCount = 1; |
| 3082 | pSMB->Reserved3 = 0; |
| 3083 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3084 | byte_count = params + 1 /* pad */ ; |
| 3085 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3086 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3087 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 3088 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3089 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3091 | |
| 3092 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3093 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3094 | cifs_stats_inc(&tcon->num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3096 | cFYI(1, "Send error in Query POSIX ACL = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | } else { |
| 3098 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3102 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | rc = -EIO; /* bad smb */ |
| 3104 | else { |
| 3105 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3106 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3107 | rc = cifs_copy_posix_acl(acl_inf, |
| 3108 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3109 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | } |
| 3111 | } |
| 3112 | cifs_buf_release(pSMB); |
| 3113 | if (rc == -EAGAIN) |
| 3114 | goto queryAclRetry; |
| 3115 | return rc; |
| 3116 | } |
| 3117 | |
| 3118 | int |
| 3119 | CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3120 | const unsigned char *fileName, |
| 3121 | const char *local_acl, const int buflen, |
| 3122 | const int acl_type, |
| 3123 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | { |
| 3125 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 3126 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 3127 | char *parm_data; |
| 3128 | int name_len; |
| 3129 | int rc = 0; |
| 3130 | int bytes_returned = 0; |
| 3131 | __u16 params, byte_count, data_count, param_offset, offset; |
| 3132 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3133 | cFYI(1, "In SetPosixACL (Unix) for path %s", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | setAclRetry: |
| 3135 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3136 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | if (rc) |
| 3138 | return rc; |
| 3139 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3140 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3141 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3142 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | name_len++; /* trailing null */ |
| 3144 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3145 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | name_len = strnlen(fileName, PATH_MAX); |
| 3147 | name_len++; /* trailing null */ |
| 3148 | strncpy(pSMB->FileName, fileName, name_len); |
| 3149 | } |
| 3150 | params = 6 + name_len; |
| 3151 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3152 | /* BB find max SMB size from sess */ |
| 3153 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | pSMB->MaxSetupCount = 0; |
| 3155 | pSMB->Reserved = 0; |
| 3156 | pSMB->Flags = 0; |
| 3157 | pSMB->Timeout = 0; |
| 3158 | pSMB->Reserved2 = 0; |
| 3159 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3160 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | offset = param_offset + params; |
| 3162 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 3163 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 3164 | |
| 3165 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3166 | 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] | 3167 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3168 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | rc = -EOPNOTSUPP; |
| 3170 | goto setACLerrorExit; |
| 3171 | } |
| 3172 | pSMB->DataOffset = cpu_to_le16(offset); |
| 3173 | pSMB->SetupCount = 1; |
| 3174 | pSMB->Reserved3 = 0; |
| 3175 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 3176 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 3177 | byte_count = 3 /* pad */ + params + data_count; |
| 3178 | pSMB->DataCount = cpu_to_le16(data_count); |
| 3179 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3180 | pSMB->ParameterCount = cpu_to_le16(params); |
| 3181 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3182 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3183 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3185 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3186 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3187 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3188 | cFYI(1, "Set POSIX ACL returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | |
| 3190 | setACLerrorExit: |
| 3191 | cifs_buf_release(pSMB); |
| 3192 | if (rc == -EAGAIN) |
| 3193 | goto setAclRetry; |
| 3194 | return rc; |
| 3195 | } |
| 3196 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3197 | /* BB fix tabs in this function FIXME BB */ |
| 3198 | int |
| 3199 | CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3200 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3201 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3202 | int rc = 0; |
| 3203 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3204 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3205 | int bytes_returned; |
| 3206 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3207 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3208 | cFYI(1, "In GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3209 | if (tcon == NULL) |
| 3210 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3211 | |
| 3212 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3213 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3214 | (void **) &pSMBr); |
| 3215 | if (rc) |
| 3216 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3217 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3218 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3219 | pSMB->t2.TotalDataCount = 0; |
| 3220 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3221 | /* BB find exact max data count below from sess structure BB */ |
| 3222 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3223 | pSMB->t2.MaxSetupCount = 0; |
| 3224 | pSMB->t2.Reserved = 0; |
| 3225 | pSMB->t2.Flags = 0; |
| 3226 | pSMB->t2.Timeout = 0; |
| 3227 | pSMB->t2.Reserved2 = 0; |
| 3228 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3229 | Fid) - 4); |
| 3230 | pSMB->t2.DataCount = 0; |
| 3231 | pSMB->t2.DataOffset = 0; |
| 3232 | pSMB->t2.SetupCount = 1; |
| 3233 | pSMB->t2.Reserved3 = 0; |
| 3234 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3235 | byte_count = params + 1 /* pad */ ; |
| 3236 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3237 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3238 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3239 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3240 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3241 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3242 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3243 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3244 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3245 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3246 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3247 | cFYI(1, "error %d in GetExtAttr", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3248 | } else { |
| 3249 | /* decode response */ |
| 3250 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3251 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3252 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3253 | /* If rc should we check for EOPNOSUPP and |
| 3254 | disable the srvino flag? or in caller? */ |
| 3255 | rc = -EIO; /* bad smb */ |
| 3256 | else { |
| 3257 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3258 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3259 | struct file_chattr_info *pfinfo; |
| 3260 | /* BB Do we need a cast or hash here ? */ |
| 3261 | if (count != 16) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3262 | cFYI(1, "Illegal size ret in GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3263 | rc = -EIO; |
| 3264 | goto GetExtAttrOut; |
| 3265 | } |
| 3266 | pfinfo = (struct file_chattr_info *) |
| 3267 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3268 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3269 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3270 | } |
| 3271 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3272 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3273 | cifs_buf_release(pSMB); |
| 3274 | if (rc == -EAGAIN) |
| 3275 | goto GetExtAttrRetry; |
| 3276 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3279 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3281 | #ifdef CONFIG_CIFS_ACL |
| 3282 | /* |
| 3283 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3284 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3285 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3286 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3287 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3288 | * by caller |
| 3289 | */ |
| 3290 | static int |
| 3291 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
| 3292 | const int parm_len, struct cifsTconInfo *tcon, |
| 3293 | void **ret_buf) |
| 3294 | { |
| 3295 | int rc; |
| 3296 | __u32 temp_offset; |
| 3297 | struct smb_com_ntransact_req *pSMB; |
| 3298 | |
| 3299 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3300 | (void **)&pSMB); |
| 3301 | if (rc) |
| 3302 | return rc; |
| 3303 | *ret_buf = (void *)pSMB; |
| 3304 | pSMB->Reserved = 0; |
| 3305 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3306 | pSMB->TotalDataCount = 0; |
| 3307 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 3308 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 3309 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3310 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3311 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3312 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3313 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3314 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3315 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3316 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3317 | return 0; |
| 3318 | } |
| 3319 | |
| 3320 | static int |
| 3321 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3322 | __u32 *pparmlen, __u32 *pdatalen) |
| 3323 | { |
| 3324 | char *end_of_smb; |
| 3325 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3326 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3327 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3328 | |
| 3329 | *pdatalen = 0; |
| 3330 | *pparmlen = 0; |
| 3331 | |
| 3332 | if (buf == NULL) |
| 3333 | return -EINVAL; |
| 3334 | |
| 3335 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3336 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3337 | bcc = get_bcc(&pSMBr->hdr); |
| 3338 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3339 | (char *)&pSMBr->ByteCount; |
| 3340 | |
| 3341 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3342 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3343 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3344 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3345 | |
| 3346 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3347 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3348 | |
| 3349 | /* should we also check that parm and data areas do not overlap? */ |
| 3350 | if (*ppparm > end_of_smb) { |
| 3351 | cFYI(1, "parms start after end of smb"); |
| 3352 | return -EINVAL; |
| 3353 | } else if (parm_count + *ppparm > end_of_smb) { |
| 3354 | cFYI(1, "parm end after end of smb"); |
| 3355 | return -EINVAL; |
| 3356 | } else if (*ppdata > end_of_smb) { |
| 3357 | cFYI(1, "data starts after end of smb"); |
| 3358 | return -EINVAL; |
| 3359 | } else if (data_count + *ppdata > end_of_smb) { |
| 3360 | cFYI(1, "data %p + count %d (%p) past smb end %p start %p", |
| 3361 | *ppdata, data_count, (data_count + *ppdata), |
| 3362 | end_of_smb, pSMBr); |
| 3363 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3364 | } else if (parm_count + data_count > bcc) { |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3365 | cFYI(1, "parm count and data count larger than SMB"); |
| 3366 | return -EINVAL; |
| 3367 | } |
| 3368 | *pdatalen = data_count; |
| 3369 | *pparmlen = parm_count; |
| 3370 | return 0; |
| 3371 | } |
| 3372 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3373 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3374 | int |
| 3375 | CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3376 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3377 | { |
| 3378 | int rc = 0; |
| 3379 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3380 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3381 | struct kvec iov[1]; |
| 3382 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3383 | cFYI(1, "GetCifsACL"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3384 | |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3385 | *pbuflen = 0; |
| 3386 | *acl_inf = NULL; |
| 3387 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3388 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3389 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3390 | if (rc) |
| 3391 | return rc; |
| 3392 | |
| 3393 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3394 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3395 | pSMB->MaxSetupCount = 0; |
| 3396 | pSMB->Fid = fid; /* file handle always le */ |
| 3397 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3398 | CIFS_ACL_DACL); |
| 3399 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3400 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3401 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3402 | 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] | 3403 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3404 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 3405 | 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3406 | cifs_stats_inc(&tcon->num_acl_get); |
| 3407 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3408 | cFYI(1, "Send error in QuerySecDesc = %d", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3409 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3410 | __le32 *parm; |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3411 | __u32 parm_len; |
| 3412 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3413 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3414 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3415 | |
| 3416 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3417 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3418 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3419 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3420 | goto qsec_out; |
| 3421 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3422 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3423 | cFYI(1, "smb %p parm %p data %p", pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3424 | |
| 3425 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3426 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3427 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3428 | goto qsec_out; |
| 3429 | } |
| 3430 | |
| 3431 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3432 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3433 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3434 | if (acl_len != *pbuflen) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3435 | cERROR(1, "acl length %d does not match %d", |
| 3436 | acl_len, *pbuflen); |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3437 | if (*pbuflen > acl_len) |
| 3438 | *pbuflen = acl_len; |
| 3439 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3440 | |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3441 | /* check if buffer is big enough for the acl |
| 3442 | header followed by the smallest SID */ |
| 3443 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3444 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3445 | cERROR(1, "bad acl length %d", *pbuflen); |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3446 | rc = -EINVAL; |
| 3447 | *pbuflen = 0; |
| 3448 | } else { |
| 3449 | *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); |
| 3450 | if (*acl_inf == NULL) { |
| 3451 | *pbuflen = 0; |
| 3452 | rc = -ENOMEM; |
| 3453 | } |
| 3454 | memcpy(*acl_inf, pdata, *pbuflen); |
| 3455 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3456 | } |
| 3457 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3458 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3459 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3460 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3461 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3462 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3463 | return rc; |
| 3464 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3465 | |
| 3466 | int |
| 3467 | CIFSSMBSetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
| 3468 | struct cifs_ntsd *pntsd, __u32 acllen) |
| 3469 | { |
| 3470 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3471 | int rc = 0; |
| 3472 | int bytes_returned = 0; |
| 3473 | SET_SEC_DESC_REQ *pSMB = NULL; |
| 3474 | NTRANSACT_RSP *pSMBr = NULL; |
| 3475 | |
| 3476 | setCifsAclRetry: |
| 3477 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, |
| 3478 | (void **) &pSMBr); |
| 3479 | if (rc) |
| 3480 | return (rc); |
| 3481 | |
| 3482 | pSMB->MaxSetupCount = 0; |
| 3483 | pSMB->Reserved = 0; |
| 3484 | |
| 3485 | param_count = 8; |
| 3486 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3487 | data_count = acllen; |
| 3488 | data_offset = param_offset + param_count; |
| 3489 | byte_count = 3 /* pad */ + param_count; |
| 3490 | |
| 3491 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3492 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3493 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3494 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3495 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3496 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3497 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3498 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3499 | pSMB->SetupCount = 0; |
| 3500 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3501 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3502 | |
| 3503 | pSMB->Fid = fid; /* file handle always le */ |
| 3504 | pSMB->Reserved2 = 0; |
| 3505 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_DACL); |
| 3506 | |
| 3507 | if (pntsd && acllen) { |
| 3508 | memcpy((char *) &pSMBr->hdr.Protocol + data_offset, |
| 3509 | (char *) pntsd, |
| 3510 | acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3511 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3512 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3513 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3514 | |
| 3515 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3516 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3517 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3518 | cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3519 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3520 | cFYI(1, "Set CIFS ACL returned %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3521 | cifs_buf_release(pSMB); |
| 3522 | |
| 3523 | if (rc == -EAGAIN) |
| 3524 | goto setCifsAclRetry; |
| 3525 | |
| 3526 | return (rc); |
| 3527 | } |
| 3528 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3529 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3530 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3531 | /* Legacy Query Path Information call for lookup to old servers such |
| 3532 | as Win9x/WinME */ |
| 3533 | int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3534 | const unsigned char *searchName, |
| 3535 | FILE_ALL_INFO *pFinfo, |
| 3536 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3537 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3538 | QUERY_INFORMATION_REQ *pSMB; |
| 3539 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3540 | int rc = 0; |
| 3541 | int bytes_returned; |
| 3542 | int name_len; |
| 3543 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3544 | cFYI(1, "In SMBQPath path %s", searchName); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3545 | QInfRetry: |
| 3546 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3547 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3548 | if (rc) |
| 3549 | return rc; |
| 3550 | |
| 3551 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3552 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3553 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
| 3554 | PATH_MAX, nls_codepage, remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3555 | name_len++; /* trailing null */ |
| 3556 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3557 | } else { |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3558 | name_len = strnlen(searchName, PATH_MAX); |
| 3559 | name_len++; /* trailing null */ |
| 3560 | strncpy(pSMB->FileName, searchName, name_len); |
| 3561 | } |
| 3562 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3563 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3564 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3565 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3566 | |
| 3567 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3568 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3569 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3570 | cFYI(1, "Send error in QueryInfo = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3571 | } else if (pFinfo) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3572 | struct timespec ts; |
| 3573 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3574 | |
| 3575 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3576 | /* BB FIXME - add time zone adjustment BB */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3577 | memset(pFinfo, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3578 | ts.tv_nsec = 0; |
| 3579 | ts.tv_sec = time; |
| 3580 | /* decode time fields */ |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 3581 | pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3582 | pFinfo->LastWriteTime = pFinfo->ChangeTime; |
| 3583 | pFinfo->LastAccessTime = 0; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3584 | pFinfo->AllocationSize = |
| 3585 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
| 3586 | pFinfo->EndOfFile = pFinfo->AllocationSize; |
| 3587 | pFinfo->Attributes = |
| 3588 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3589 | } else |
| 3590 | rc = -EIO; /* bad buffer passed in */ |
| 3591 | |
| 3592 | cifs_buf_release(pSMB); |
| 3593 | |
| 3594 | if (rc == -EAGAIN) |
| 3595 | goto QInfRetry; |
| 3596 | |
| 3597 | return rc; |
| 3598 | } |
| 3599 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3600 | int |
| 3601 | CIFSSMBQFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 3602 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 3603 | { |
| 3604 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3605 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3606 | int rc = 0; |
| 3607 | int bytes_returned; |
| 3608 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3609 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3610 | QFileInfoRetry: |
| 3611 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3612 | (void **) &pSMBr); |
| 3613 | if (rc) |
| 3614 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3615 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3616 | params = 2 /* level */ + 2 /* fid */; |
| 3617 | pSMB->t2.TotalDataCount = 0; |
| 3618 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3619 | /* BB find exact max data count below from sess structure BB */ |
| 3620 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3621 | pSMB->t2.MaxSetupCount = 0; |
| 3622 | pSMB->t2.Reserved = 0; |
| 3623 | pSMB->t2.Flags = 0; |
| 3624 | pSMB->t2.Timeout = 0; |
| 3625 | pSMB->t2.Reserved2 = 0; |
| 3626 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3627 | Fid) - 4); |
| 3628 | pSMB->t2.DataCount = 0; |
| 3629 | pSMB->t2.DataOffset = 0; |
| 3630 | pSMB->t2.SetupCount = 1; |
| 3631 | pSMB->t2.Reserved3 = 0; |
| 3632 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3633 | byte_count = params + 1 /* pad */ ; |
| 3634 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3635 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3636 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 3637 | pSMB->Pad = 0; |
| 3638 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3639 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3640 | |
| 3641 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3642 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3643 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3644 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3645 | } else { /* decode response */ |
| 3646 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3647 | |
| 3648 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3649 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3650 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3651 | rc = -EIO; /* bad smb */ |
| 3652 | else if (pFindData) { |
| 3653 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3654 | memcpy((char *) pFindData, |
| 3655 | (char *) &pSMBr->hdr.Protocol + |
| 3656 | data_offset, sizeof(FILE_ALL_INFO)); |
| 3657 | } else |
| 3658 | rc = -ENOMEM; |
| 3659 | } |
| 3660 | cifs_buf_release(pSMB); |
| 3661 | if (rc == -EAGAIN) |
| 3662 | goto QFileInfoRetry; |
| 3663 | |
| 3664 | return rc; |
| 3665 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | int |
| 3668 | CIFSSMBQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3669 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3670 | FILE_ALL_INFO *pFindData, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3671 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3672 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | { |
| 3674 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
| 3675 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3676 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3677 | int rc = 0; |
| 3678 | int bytes_returned; |
| 3679 | int name_len; |
| 3680 | __u16 params, byte_count; |
| 3681 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3682 | /* cFYI(1, "In QPathInfo path %s", searchName); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | QPathInfoRetry: |
| 3684 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3685 | (void **) &pSMBr); |
| 3686 | if (rc) |
| 3687 | return rc; |
| 3688 | |
| 3689 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3690 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3691 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3692 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | name_len++; /* trailing null */ |
| 3694 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3695 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | name_len = strnlen(searchName, PATH_MAX); |
| 3697 | name_len++; /* trailing null */ |
| 3698 | strncpy(pSMB->FileName, searchName, name_len); |
| 3699 | } |
| 3700 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3701 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | pSMB->TotalDataCount = 0; |
| 3703 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3704 | /* BB find exact max SMB PDU from sess structure BB */ |
| 3705 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | pSMB->MaxSetupCount = 0; |
| 3707 | pSMB->Reserved = 0; |
| 3708 | pSMB->Flags = 0; |
| 3709 | pSMB->Timeout = 0; |
| 3710 | pSMB->Reserved2 = 0; |
| 3711 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3712 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | pSMB->DataCount = 0; |
| 3714 | pSMB->DataOffset = 0; |
| 3715 | pSMB->SetupCount = 1; |
| 3716 | pSMB->Reserved3 = 0; |
| 3717 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3718 | byte_count = params + 1 /* pad */ ; |
| 3719 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3720 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3721 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3722 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 3723 | else |
| 3724 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3726 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3728 | |
| 3729 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3730 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3731 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3732 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | } else { /* decode response */ |
| 3734 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3735 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3736 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3737 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3738 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3740 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3741 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 3742 | last field */ |
| 3743 | else if (pFindData) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3744 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3746 | |
| 3747 | /* On legacy responses we do not read the last field, |
| 3748 | EAsize, fortunately since it varies by subdialect and |
| 3749 | also note it differs on Set vs. Get, ie two bytes or 4 |
| 3750 | bytes depending but we don't care here */ |
| 3751 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3752 | size = sizeof(FILE_INFO_STANDARD); |
| 3753 | else |
| 3754 | size = sizeof(FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | memcpy((char *) pFindData, |
| 3756 | (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3757 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | } else |
| 3759 | rc = -ENOMEM; |
| 3760 | } |
| 3761 | cifs_buf_release(pSMB); |
| 3762 | if (rc == -EAGAIN) |
| 3763 | goto QPathInfoRetry; |
| 3764 | |
| 3765 | return rc; |
| 3766 | } |
| 3767 | |
| 3768 | int |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3769 | CIFSSMBUnixQFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 3770 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 3771 | { |
| 3772 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3773 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3774 | int rc = 0; |
| 3775 | int bytes_returned; |
| 3776 | __u16 params, byte_count; |
| 3777 | |
| 3778 | UnixQFileInfoRetry: |
| 3779 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3780 | (void **) &pSMBr); |
| 3781 | if (rc) |
| 3782 | return rc; |
| 3783 | |
| 3784 | params = 2 /* level */ + 2 /* fid */; |
| 3785 | pSMB->t2.TotalDataCount = 0; |
| 3786 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3787 | /* BB find exact max data count below from sess structure BB */ |
| 3788 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3789 | pSMB->t2.MaxSetupCount = 0; |
| 3790 | pSMB->t2.Reserved = 0; |
| 3791 | pSMB->t2.Flags = 0; |
| 3792 | pSMB->t2.Timeout = 0; |
| 3793 | pSMB->t2.Reserved2 = 0; |
| 3794 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3795 | Fid) - 4); |
| 3796 | pSMB->t2.DataCount = 0; |
| 3797 | pSMB->t2.DataOffset = 0; |
| 3798 | pSMB->t2.SetupCount = 1; |
| 3799 | pSMB->t2.Reserved3 = 0; |
| 3800 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3801 | byte_count = params + 1 /* pad */ ; |
| 3802 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3803 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3804 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 3805 | pSMB->Pad = 0; |
| 3806 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3807 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3808 | |
| 3809 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3810 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3811 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3812 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3813 | } else { /* decode response */ |
| 3814 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3815 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3816 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3817 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3818 | "Unix Extensions can be disabled on mount " |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3819 | "by specifying the nosfu mount option."); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3820 | rc = -EIO; /* bad smb */ |
| 3821 | } else { |
| 3822 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3823 | memcpy((char *) pFindData, |
| 3824 | (char *) &pSMBr->hdr.Protocol + |
| 3825 | data_offset, |
| 3826 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 3827 | } |
| 3828 | } |
| 3829 | |
| 3830 | cifs_buf_release(pSMB); |
| 3831 | if (rc == -EAGAIN) |
| 3832 | goto UnixQFileInfoRetry; |
| 3833 | |
| 3834 | return rc; |
| 3835 | } |
| 3836 | |
| 3837 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3839 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3840 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3841 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | { |
| 3843 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 3844 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3845 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3846 | int rc = 0; |
| 3847 | int bytes_returned = 0; |
| 3848 | int name_len; |
| 3849 | __u16 params, byte_count; |
| 3850 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3851 | cFYI(1, "In QPathInfo (Unix) the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | UnixQPathInfoRetry: |
| 3853 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3854 | (void **) &pSMBr); |
| 3855 | if (rc) |
| 3856 | return rc; |
| 3857 | |
| 3858 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3859 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 3860 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3861 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | name_len++; /* trailing null */ |
| 3863 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3864 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | name_len = strnlen(searchName, PATH_MAX); |
| 3866 | name_len++; /* trailing null */ |
| 3867 | strncpy(pSMB->FileName, searchName, name_len); |
| 3868 | } |
| 3869 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3870 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | pSMB->TotalDataCount = 0; |
| 3872 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3873 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3874 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | pSMB->MaxSetupCount = 0; |
| 3876 | pSMB->Reserved = 0; |
| 3877 | pSMB->Flags = 0; |
| 3878 | pSMB->Timeout = 0; |
| 3879 | pSMB->Reserved2 = 0; |
| 3880 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3881 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | pSMB->DataCount = 0; |
| 3883 | pSMB->DataOffset = 0; |
| 3884 | pSMB->SetupCount = 1; |
| 3885 | pSMB->Reserved3 = 0; |
| 3886 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3887 | byte_count = params + 1 /* pad */ ; |
| 3888 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3889 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3890 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 3891 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3892 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3894 | |
| 3895 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3896 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3897 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3898 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | } else { /* decode response */ |
| 3900 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3901 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3902 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3903 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Steve French | 1e71f25 | 2007-09-20 15:30:07 +0000 | [diff] [blame] | 3904 | "Unix Extensions can be disabled on mount " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3905 | "by specifying the nosfu mount option."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | rc = -EIO; /* bad smb */ |
| 3907 | } else { |
| 3908 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3909 | memcpy((char *) pFindData, |
| 3910 | (char *) &pSMBr->hdr.Protocol + |
| 3911 | data_offset, |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3912 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | } |
| 3914 | } |
| 3915 | cifs_buf_release(pSMB); |
| 3916 | if (rc == -EAGAIN) |
| 3917 | goto UnixQPathInfoRetry; |
| 3918 | |
| 3919 | return rc; |
| 3920 | } |
| 3921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 3923 | int |
| 3924 | CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3925 | const char *searchName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | const struct nls_table *nls_codepage, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3927 | __u16 *pnetfid, |
| 3928 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | { |
| 3930 | /* level 257 SMB_ */ |
| 3931 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 3932 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3933 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | int rc = 0; |
| 3935 | int bytes_returned = 0; |
| 3936 | int name_len; |
| 3937 | __u16 params, byte_count; |
| 3938 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3939 | cFYI(1, "In FindFirst for %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | |
| 3941 | findFirstRetry: |
| 3942 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3943 | (void **) &pSMBr); |
| 3944 | if (rc) |
| 3945 | return rc; |
| 3946 | |
| 3947 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3948 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3949 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3950 | PATH_MAX, nls_codepage, remap); |
| 3951 | /* We can not add the asterik earlier in case |
| 3952 | it got remapped to 0xF03A as if it were part of the |
| 3953 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | name_len *= 2; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3955 | pSMB->FileName[name_len] = dirsep; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3956 | pSMB->FileName[name_len+1] = 0; |
| 3957 | pSMB->FileName[name_len+2] = '*'; |
| 3958 | pSMB->FileName[name_len+3] = 0; |
| 3959 | name_len += 4; /* now the trailing null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ |
| 3961 | pSMB->FileName[name_len+1] = 0; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3962 | name_len += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | } else { /* BB add check for overrun of SMB buf BB */ |
| 3964 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3966 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | free buffer exit; BB */ |
| 3968 | strncpy(pSMB->FileName, searchName, name_len); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3969 | pSMB->FileName[name_len] = dirsep; |
Steve French | 6857547 | 2005-04-30 11:10:57 -0700 | [diff] [blame] | 3970 | pSMB->FileName[name_len+1] = '*'; |
| 3971 | pSMB->FileName[name_len+2] = 0; |
| 3972 | name_len += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | params = 12 + name_len /* includes null */ ; |
| 3976 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 3977 | pSMB->MaxParameterCount = cpu_to_le16(10); |
| 3978 | pSMB->MaxDataCount = cpu_to_le16((tcon->ses->server->maxBuf - |
| 3979 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 3980 | pSMB->MaxSetupCount = 0; |
| 3981 | pSMB->Reserved = 0; |
| 3982 | pSMB->Flags = 0; |
| 3983 | pSMB->Timeout = 0; |
| 3984 | pSMB->Reserved2 = 0; |
| 3985 | byte_count = params + 1 /* pad */ ; |
| 3986 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3987 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3988 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3989 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 3990 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | pSMB->DataCount = 0; |
| 3992 | pSMB->DataOffset = 0; |
| 3993 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 3994 | pSMB->Reserved3 = 0; |
| 3995 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 3996 | pSMB->SearchAttributes = |
| 3997 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3998 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3999 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
| 4000 | pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | CIFS_SEARCH_RETURN_RESUME); |
| 4002 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4003 | |
| 4004 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 4005 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4006 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4008 | |
| 4009 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4010 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4011 | cifs_stats_inc(&tcon->num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4013 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 4014 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4016 | cFYI(1, "Error in FindFirst = %d", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4017 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 4018 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | |
| 4020 | /* BB eventually could optimize out free and realloc of buf */ |
| 4021 | /* for this case */ |
| 4022 | if (rc == -EAGAIN) |
| 4023 | goto findFirstRetry; |
| 4024 | } else { /* decode response */ |
| 4025 | /* BB remember to free buffer if error BB */ |
| 4026 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4027 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4028 | unsigned int lnoff; |
| 4029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4031 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4033 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | |
| 4035 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4036 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4037 | psrch_inf->srch_entries_start = |
| 4038 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 4041 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 4042 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4043 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4044 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4046 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4048 | psrch_inf->entries_in_buffer = |
| 4049 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 4050 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4052 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 4053 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 4054 | lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4055 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4056 | psrch_inf->last_entry = NULL; |
| 4057 | return rc; |
| 4058 | } |
| 4059 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 4060 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4061 | lnoff; |
| 4062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | *pnetfid = parms->SearchHandle; |
| 4064 | } else { |
| 4065 | cifs_buf_release(pSMB); |
| 4066 | } |
| 4067 | } |
| 4068 | |
| 4069 | return rc; |
| 4070 | } |
| 4071 | |
| 4072 | int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4073 | __u16 searchHandle, struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | { |
| 4075 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 4076 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4077 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | char *response_data; |
| 4079 | int rc = 0; |
| 4080 | int bytes_returned, name_len; |
| 4081 | __u16 params, byte_count; |
| 4082 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4083 | cFYI(1, "In FindNext"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4085 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | return -ENOENT; |
| 4087 | |
| 4088 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4089 | (void **) &pSMBr); |
| 4090 | if (rc) |
| 4091 | return rc; |
| 4092 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4093 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | byte_count = 0; |
| 4095 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 4096 | pSMB->MaxParameterCount = cpu_to_le16(8); |
| 4097 | pSMB->MaxDataCount = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4098 | cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & |
| 4099 | 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | pSMB->MaxSetupCount = 0; |
| 4101 | pSMB->Reserved = 0; |
| 4102 | pSMB->Flags = 0; |
| 4103 | pSMB->Timeout = 0; |
| 4104 | pSMB->Reserved2 = 0; |
| 4105 | pSMB->ParameterOffset = cpu_to_le16( |
| 4106 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 4107 | pSMB->DataCount = 0; |
| 4108 | pSMB->DataOffset = 0; |
| 4109 | pSMB->SetupCount = 1; |
| 4110 | pSMB->Reserved3 = 0; |
| 4111 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 4112 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 4113 | pSMB->SearchCount = |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4114 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 4116 | pSMB->ResumeKey = psrch_inf->resume_key; |
| 4117 | pSMB->SearchFlags = |
| 4118 | cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME); |
| 4119 | |
| 4120 | name_len = psrch_inf->resume_name_len; |
| 4121 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4122 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 4124 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 4125 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 4126 | pSMB->ResumeFileName[name_len] = 0; |
| 4127 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | } else { |
| 4129 | rc = -EINVAL; |
| 4130 | goto FNext2_err_exit; |
| 4131 | } |
| 4132 | byte_count = params + 1 /* pad */ ; |
| 4133 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4134 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4135 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4139 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4140 | cifs_stats_inc(&tcon->num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | if (rc) { |
| 4142 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4143 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 4144 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4145 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | } else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4147 | cFYI(1, "FindNext returned = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | } else { /* decode response */ |
| 4149 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4150 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4151 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4152 | unsigned int lnoff; |
| 4153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | /* BB fixme add lock for file (srch_info) struct here */ |
| 4155 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4156 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4158 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 4160 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 4161 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 4162 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 4163 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4164 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4165 | cifs_small_buf_release( |
| 4166 | psrch_inf->ntwrk_buf_start); |
| 4167 | else |
| 4168 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | psrch_inf->srch_entries_start = response_data; |
| 4170 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 4171 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4172 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4173 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4175 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4176 | psrch_inf->entries_in_buffer = |
| 4177 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | psrch_inf->index_of_last_entry += |
| 4179 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4180 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 4181 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 4182 | lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4183 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 4184 | psrch_inf->last_entry = NULL; |
| 4185 | return rc; |
| 4186 | } else |
| 4187 | psrch_inf->last_entry = |
| 4188 | psrch_inf->srch_entries_start + lnoff; |
| 4189 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4190 | /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d", |
| 4191 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | |
| 4193 | /* BB fixme add unlock here */ |
| 4194 | } |
| 4195 | |
| 4196 | } |
| 4197 | |
| 4198 | /* BB On error, should we leave previous search buf (and count and |
| 4199 | last entry fields) intact or free the previous one? */ |
| 4200 | |
| 4201 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 4202 | since file handle passed in no longer valid */ |
| 4203 | FNext2_err_exit: |
| 4204 | if (rc != 0) |
| 4205 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | return rc; |
| 4207 | } |
| 4208 | |
| 4209 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4210 | CIFSFindClose(const int xid, struct cifsTconInfo *tcon, |
| 4211 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | { |
| 4213 | int rc = 0; |
| 4214 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4216 | cFYI(1, "In CIFSSMBFindClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 4218 | |
| 4219 | /* no sense returning error if session restarted |
| 4220 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4221 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | return 0; |
| 4223 | if (rc) |
| 4224 | return rc; |
| 4225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | pSMB->FileID = searchHandle; |
| 4227 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 4228 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4229 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4230 | cERROR(1, "Send error in FindClose = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4231 | |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 4232 | cifs_stats_inc(&tcon->num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | |
| 4234 | /* Since session is dead, search handle closed on server already */ |
| 4235 | if (rc == -EAGAIN) |
| 4236 | rc = 0; |
| 4237 | |
| 4238 | return rc; |
| 4239 | } |
| 4240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | int |
| 4242 | CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4243 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4244 | __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4245 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | { |
| 4247 | int rc = 0; |
| 4248 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 4249 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 4250 | int name_len, bytes_returned; |
| 4251 | __u16 params, byte_count; |
| 4252 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4253 | cFYI(1, "In GetSrvInodeNum for %s", searchName); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4254 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4255 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | |
| 4257 | GetInodeNumberRetry: |
| 4258 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4259 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | if (rc) |
| 4261 | return rc; |
| 4262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4263 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4264 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4265 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4266 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | name_len++; /* trailing null */ |
| 4268 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4269 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | name_len = strnlen(searchName, PATH_MAX); |
| 4271 | name_len++; /* trailing null */ |
| 4272 | strncpy(pSMB->FileName, searchName, name_len); |
| 4273 | } |
| 4274 | |
| 4275 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4276 | pSMB->TotalDataCount = 0; |
| 4277 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4278 | /* BB find exact max data count below from sess structure BB */ |
| 4279 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4280 | pSMB->MaxSetupCount = 0; |
| 4281 | pSMB->Reserved = 0; |
| 4282 | pSMB->Flags = 0; |
| 4283 | pSMB->Timeout = 0; |
| 4284 | pSMB->Reserved2 = 0; |
| 4285 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4286 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | pSMB->DataCount = 0; |
| 4288 | pSMB->DataOffset = 0; |
| 4289 | pSMB->SetupCount = 1; |
| 4290 | pSMB->Reserved3 = 0; |
| 4291 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4292 | byte_count = params + 1 /* pad */ ; |
| 4293 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4294 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4295 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4296 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4297 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4299 | |
| 4300 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4301 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4302 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4303 | cFYI(1, "error %d in QueryInternalInfo", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | } else { |
| 4305 | /* decode response */ |
| 4306 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4308 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | /* If rc should we check for EOPNOSUPP and |
| 4310 | disable the srvino flag? or in caller? */ |
| 4311 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4312 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4314 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4315 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4317 | if (count < 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4318 | cFYI(1, "Illegal size ret in QryIntrnlInf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | rc = -EIO; |
| 4320 | goto GetInodeNumOut; |
| 4321 | } |
| 4322 | pfinfo = (struct file_internal_info *) |
| 4323 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4324 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | } |
| 4326 | } |
| 4327 | GetInodeNumOut: |
| 4328 | cifs_buf_release(pSMB); |
| 4329 | if (rc == -EAGAIN) |
| 4330 | goto GetInodeNumberRetry; |
| 4331 | return rc; |
| 4332 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4334 | /* parses DFS refferal V3 structure |
| 4335 | * caller is responsible for freeing target_nodes |
| 4336 | * returns: |
| 4337 | * on success - 0 |
| 4338 | * on failure - errno |
| 4339 | */ |
| 4340 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4341 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4342 | unsigned int *num_of_nodes, |
| 4343 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4344 | const struct nls_table *nls_codepage, int remap, |
| 4345 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4346 | { |
| 4347 | int i, rc = 0; |
| 4348 | char *data_end; |
| 4349 | bool is_unicode; |
| 4350 | struct dfs_referral_level_3 *ref; |
| 4351 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 4352 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 4353 | is_unicode = true; |
| 4354 | else |
| 4355 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4356 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 4357 | |
| 4358 | if (*num_of_nodes < 1) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4359 | cERROR(1, "num_referrals: must be at least > 0," |
| 4360 | "but we get num_referrals = %d\n", *num_of_nodes); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4361 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4362 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4363 | } |
| 4364 | |
| 4365 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4366 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4367 | cERROR(1, "Referrals of V%d version are not supported," |
| 4368 | "should be V3", le16_to_cpu(ref->VersionNumber)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4369 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4370 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | /* get the upper boundary of the resp buffer */ |
| 4374 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 4375 | le16_to_cpu(pSMBr->t2.DataCount); |
| 4376 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4377 | cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n", |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4378 | *num_of_nodes, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4379 | le32_to_cpu(pSMBr->DFSFlags)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4380 | |
| 4381 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
| 4382 | *num_of_nodes, GFP_KERNEL); |
| 4383 | if (*target_nodes == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4384 | cERROR(1, "Failed to allocate buffer for target_nodes\n"); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4385 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4386 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4387 | } |
| 4388 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4389 | /* collect necessary data from referrals */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4390 | for (i = 0; i < *num_of_nodes; i++) { |
| 4391 | char *temp; |
| 4392 | int max_len; |
| 4393 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 4394 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4395 | node->flags = le32_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4396 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 4397 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 4398 | GFP_KERNEL); |
Steve French | 2920ee2 | 2009-08-31 15:27:26 +0000 | [diff] [blame] | 4399 | if (tmp == NULL) { |
| 4400 | rc = -ENOMEM; |
| 4401 | goto parse_DFS_referrals_exit; |
| 4402 | } |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4403 | cifsConvertToUCS((__le16 *) tmp, searchName, |
| 4404 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 69f801f | 2009-04-30 06:46:32 -0400 | [diff] [blame] | 4405 | node->path_consumed = cifs_ucs2_bytes(tmp, |
| 4406 | le16_to_cpu(pSMBr->PathConsumed), |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4407 | nls_codepage); |
| 4408 | kfree(tmp); |
| 4409 | } else |
| 4410 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4411 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4412 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4413 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4414 | |
| 4415 | /* copy DfsPath */ |
| 4416 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4417 | max_len = data_end - temp; |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 4418 | node->path_name = cifs_strndup_from_ucs(temp, max_len, |
| 4419 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4420 | if (!node->path_name) { |
| 4421 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4422 | goto parse_DFS_referrals_exit; |
Jeff Layton | 066ce68 | 2009-04-30 07:16:14 -0400 | [diff] [blame] | 4423 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4424 | |
| 4425 | /* copy link target UNC */ |
| 4426 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4427 | max_len = data_end - temp; |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 4428 | node->node_name = cifs_strndup_from_ucs(temp, max_len, |
| 4429 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4430 | if (!node->node_name) |
| 4431 | rc = -ENOMEM; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4432 | } |
| 4433 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4434 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4435 | if (rc) { |
| 4436 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4437 | *target_nodes = NULL; |
| 4438 | *num_of_nodes = 0; |
| 4439 | } |
| 4440 | return rc; |
| 4441 | } |
| 4442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | int |
| 4444 | CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses, |
| 4445 | const unsigned char *searchName, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4446 | struct dfs_info3_param **target_nodes, |
| 4447 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4448 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | { |
| 4450 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4451 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4452 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | int rc = 0; |
| 4454 | int bytes_returned; |
| 4455 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4457 | *num_of_nodes = 0; |
| 4458 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4460 | cFYI(1, "In GetDFSRefer the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | if (ses == NULL) |
| 4462 | return -ENODEV; |
| 4463 | getDFSRetry: |
| 4464 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4465 | (void **) &pSMBr); |
| 4466 | if (rc) |
| 4467 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4468 | |
| 4469 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4470 | but should never be null here anyway */ |
| 4471 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4473 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4474 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4476 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | |
| 4479 | if (ses->capabilities & CAP_UNICODE) { |
| 4480 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4481 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4482 | cifsConvertToUCS((__le16 *) pSMB->RequestFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4483 | searchName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | name_len++; /* trailing null */ |
| 4485 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4486 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | name_len = strnlen(searchName, PATH_MAX); |
| 4488 | name_len++; /* trailing null */ |
| 4489 | strncpy(pSMB->RequestFileName, searchName, name_len); |
| 4490 | } |
| 4491 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4492 | if (ses->server) { |
| 4493 | if (ses->server->secMode & |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4494 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 4495 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4496 | } |
| 4497 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4498 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4501 | pSMB->TotalDataCount = 0; |
| 4502 | pSMB->DataCount = 0; |
| 4503 | pSMB->DataOffset = 0; |
| 4504 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4505 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4506 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | pSMB->MaxSetupCount = 0; |
| 4508 | pSMB->Reserved = 0; |
| 4509 | pSMB->Flags = 0; |
| 4510 | pSMB->Timeout = 0; |
| 4511 | pSMB->Reserved2 = 0; |
| 4512 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4513 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | pSMB->SetupCount = 1; |
| 4515 | pSMB->Reserved3 = 0; |
| 4516 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4517 | byte_count = params + 3 /* pad */ ; |
| 4518 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4519 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4520 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4521 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4523 | |
| 4524 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4525 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4526 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4527 | cFYI(1, "Send error in GetDFSRefer = %d", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4528 | goto GetDFSRefExit; |
| 4529 | } |
| 4530 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4532 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4533 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4534 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4535 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4537 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4538 | cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4539 | get_bcc(&pSMBr->hdr), |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4540 | le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4541 | |
| 4542 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4543 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4544 | target_nodes, nls_codepage, remap, |
| 4545 | searchName); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4548 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | |
| 4550 | if (rc == -EAGAIN) |
| 4551 | goto getDFSRetry; |
| 4552 | |
| 4553 | return rc; |
| 4554 | } |
| 4555 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4556 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4557 | int |
| 4558 | SMBOldQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
| 4559 | { |
| 4560 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4561 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4562 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4563 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4564 | int rc = 0; |
| 4565 | int bytes_returned = 0; |
| 4566 | __u16 params, byte_count; |
| 4567 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4568 | cFYI(1, "OldQFSInfo"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4569 | oldQFSInfoRetry: |
| 4570 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4571 | (void **) &pSMBr); |
| 4572 | if (rc) |
| 4573 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4574 | |
| 4575 | params = 2; /* level */ |
| 4576 | pSMB->TotalDataCount = 0; |
| 4577 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4578 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4579 | pSMB->MaxSetupCount = 0; |
| 4580 | pSMB->Reserved = 0; |
| 4581 | pSMB->Flags = 0; |
| 4582 | pSMB->Timeout = 0; |
| 4583 | pSMB->Reserved2 = 0; |
| 4584 | byte_count = params + 1 /* pad */ ; |
| 4585 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4586 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4587 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4588 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4589 | pSMB->DataCount = 0; |
| 4590 | pSMB->DataOffset = 0; |
| 4591 | pSMB->SetupCount = 1; |
| 4592 | pSMB->Reserved3 = 0; |
| 4593 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4594 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4595 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4596 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4597 | |
| 4598 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4599 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4600 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4601 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4602 | } else { /* decode response */ |
| 4603 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4604 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4605 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4606 | rc = -EIO; /* bad smb */ |
| 4607 | else { |
| 4608 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4609 | cFYI(1, "qfsinf resp BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4610 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4611 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4612 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4613 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4614 | FSData->f_bsize = |
| 4615 | le16_to_cpu(response_data->BytesPerSector) * |
| 4616 | le32_to_cpu(response_data-> |
| 4617 | SectorsPerAllocationUnit); |
| 4618 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4619 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4620 | FSData->f_bfree = FSData->f_bavail = |
| 4621 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4622 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4623 | (unsigned long long)FSData->f_blocks, |
| 4624 | (unsigned long long)FSData->f_bfree, |
| 4625 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4626 | } |
| 4627 | } |
| 4628 | cifs_buf_release(pSMB); |
| 4629 | |
| 4630 | if (rc == -EAGAIN) |
| 4631 | goto oldQFSInfoRetry; |
| 4632 | |
| 4633 | return rc; |
| 4634 | } |
| 4635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4637 | CIFSSMBQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | { |
| 4639 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4640 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4641 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4642 | FILE_SYSTEM_INFO *response_data; |
| 4643 | int rc = 0; |
| 4644 | int bytes_returned = 0; |
| 4645 | __u16 params, byte_count; |
| 4646 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4647 | cFYI(1, "In QFSInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | QFSInfoRetry: |
| 4649 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4650 | (void **) &pSMBr); |
| 4651 | if (rc) |
| 4652 | return rc; |
| 4653 | |
| 4654 | params = 2; /* level */ |
| 4655 | pSMB->TotalDataCount = 0; |
| 4656 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4657 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | pSMB->MaxSetupCount = 0; |
| 4659 | pSMB->Reserved = 0; |
| 4660 | pSMB->Flags = 0; |
| 4661 | pSMB->Timeout = 0; |
| 4662 | pSMB->Reserved2 = 0; |
| 4663 | byte_count = params + 1 /* pad */ ; |
| 4664 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4665 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4666 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4667 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | pSMB->DataCount = 0; |
| 4669 | pSMB->DataOffset = 0; |
| 4670 | pSMB->SetupCount = 1; |
| 4671 | pSMB->Reserved3 = 0; |
| 4672 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4673 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4674 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4675 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4676 | |
| 4677 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4678 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4679 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4680 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4681 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4682 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4683 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4684 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | rc = -EIO; /* bad smb */ |
| 4686 | else { |
| 4687 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | |
| 4689 | response_data = |
| 4690 | (FILE_SYSTEM_INFO |
| 4691 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4692 | data_offset); |
| 4693 | FSData->f_bsize = |
| 4694 | le32_to_cpu(response_data->BytesPerSector) * |
| 4695 | le32_to_cpu(response_data-> |
| 4696 | SectorsPerAllocationUnit); |
| 4697 | FSData->f_blocks = |
| 4698 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 4699 | FSData->f_bfree = FSData->f_bavail = |
| 4700 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4701 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4702 | (unsigned long long)FSData->f_blocks, |
| 4703 | (unsigned long long)FSData->f_bfree, |
| 4704 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | } |
| 4706 | } |
| 4707 | cifs_buf_release(pSMB); |
| 4708 | |
| 4709 | if (rc == -EAGAIN) |
| 4710 | goto QFSInfoRetry; |
| 4711 | |
| 4712 | return rc; |
| 4713 | } |
| 4714 | |
| 4715 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4716 | CIFSSMBQFSAttributeInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4717 | { |
| 4718 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4719 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4720 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4721 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 4722 | int rc = 0; |
| 4723 | int bytes_returned = 0; |
| 4724 | __u16 params, byte_count; |
| 4725 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4726 | cFYI(1, "In QFSAttributeInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | QFSAttributeRetry: |
| 4728 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4729 | (void **) &pSMBr); |
| 4730 | if (rc) |
| 4731 | return rc; |
| 4732 | |
| 4733 | params = 2; /* level */ |
| 4734 | pSMB->TotalDataCount = 0; |
| 4735 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4736 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4737 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | pSMB->MaxSetupCount = 0; |
| 4739 | pSMB->Reserved = 0; |
| 4740 | pSMB->Flags = 0; |
| 4741 | pSMB->Timeout = 0; |
| 4742 | pSMB->Reserved2 = 0; |
| 4743 | byte_count = params + 1 /* pad */ ; |
| 4744 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4745 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4746 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4747 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | pSMB->DataCount = 0; |
| 4749 | pSMB->DataOffset = 0; |
| 4750 | pSMB->SetupCount = 1; |
| 4751 | pSMB->Reserved3 = 0; |
| 4752 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4753 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4754 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4756 | |
| 4757 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4758 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4759 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4760 | cERROR(1, "Send error in QFSAttributeInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4761 | } else { /* decode response */ |
| 4762 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4763 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4764 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4765 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | rc = -EIO; /* bad smb */ |
| 4767 | } else { |
| 4768 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4769 | response_data = |
| 4770 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 4771 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4772 | data_offset); |
| 4773 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4774 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | cifs_buf_release(pSMB); |
| 4778 | |
| 4779 | if (rc == -EAGAIN) |
| 4780 | goto QFSAttributeRetry; |
| 4781 | |
| 4782 | return rc; |
| 4783 | } |
| 4784 | |
| 4785 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4786 | CIFSSMBQFSDeviceInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | { |
| 4788 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4789 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4790 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4791 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 4792 | int rc = 0; |
| 4793 | int bytes_returned = 0; |
| 4794 | __u16 params, byte_count; |
| 4795 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4796 | cFYI(1, "In QFSDeviceInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | QFSDeviceRetry: |
| 4798 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4799 | (void **) &pSMBr); |
| 4800 | if (rc) |
| 4801 | return rc; |
| 4802 | |
| 4803 | params = 2; /* level */ |
| 4804 | pSMB->TotalDataCount = 0; |
| 4805 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4806 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4807 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | pSMB->MaxSetupCount = 0; |
| 4809 | pSMB->Reserved = 0; |
| 4810 | pSMB->Flags = 0; |
| 4811 | pSMB->Timeout = 0; |
| 4812 | pSMB->Reserved2 = 0; |
| 4813 | byte_count = params + 1 /* pad */ ; |
| 4814 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4815 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4816 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4817 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | |
| 4819 | pSMB->DataCount = 0; |
| 4820 | pSMB->DataOffset = 0; |
| 4821 | pSMB->SetupCount = 1; |
| 4822 | pSMB->Reserved3 = 0; |
| 4823 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4824 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4825 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4827 | |
| 4828 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4829 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4830 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4831 | cFYI(1, "Send error in QFSDeviceInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | } else { /* decode response */ |
| 4833 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4834 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4835 | if (rc || get_bcc(&pSMBr->hdr) < |
| 4836 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | rc = -EIO; /* bad smb */ |
| 4838 | else { |
| 4839 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4840 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4841 | (FILE_SYSTEM_DEVICE_INFO *) |
| 4842 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4843 | data_offset); |
| 4844 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4845 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | } |
| 4847 | } |
| 4848 | cifs_buf_release(pSMB); |
| 4849 | |
| 4850 | if (rc == -EAGAIN) |
| 4851 | goto QFSDeviceRetry; |
| 4852 | |
| 4853 | return rc; |
| 4854 | } |
| 4855 | |
| 4856 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4857 | CIFSSMBQFSUnixInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | { |
| 4859 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 4860 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4861 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4862 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 4863 | int rc = 0; |
| 4864 | int bytes_returned = 0; |
| 4865 | __u16 params, byte_count; |
| 4866 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4867 | cFYI(1, "In QFSUnixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 4869 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 4870 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | if (rc) |
| 4872 | return rc; |
| 4873 | |
| 4874 | params = 2; /* level */ |
| 4875 | pSMB->TotalDataCount = 0; |
| 4876 | pSMB->DataCount = 0; |
| 4877 | pSMB->DataOffset = 0; |
| 4878 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4879 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4880 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | pSMB->MaxSetupCount = 0; |
| 4882 | pSMB->Reserved = 0; |
| 4883 | pSMB->Flags = 0; |
| 4884 | pSMB->Timeout = 0; |
| 4885 | pSMB->Reserved2 = 0; |
| 4886 | byte_count = params + 1 /* pad */ ; |
| 4887 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4888 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4889 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 4890 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | pSMB->SetupCount = 1; |
| 4892 | pSMB->Reserved3 = 0; |
| 4893 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4894 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4895 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4897 | |
| 4898 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4899 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4900 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4901 | cERROR(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | } else { /* decode response */ |
| 4903 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4904 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4905 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | rc = -EIO; /* bad smb */ |
| 4907 | } else { |
| 4908 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4909 | response_data = |
| 4910 | (FILE_SYSTEM_UNIX_INFO |
| 4911 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4912 | data_offset); |
| 4913 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4914 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | } |
| 4916 | } |
| 4917 | cifs_buf_release(pSMB); |
| 4918 | |
| 4919 | if (rc == -EAGAIN) |
| 4920 | goto QFSUnixRetry; |
| 4921 | |
| 4922 | |
| 4923 | return rc; |
| 4924 | } |
| 4925 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4926 | int |
Steve French | 45abc6e | 2005-06-23 13:42:03 -0500 | [diff] [blame] | 4927 | CIFSSMBSetFSUnixInfo(const int xid, struct cifsTconInfo *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4928 | { |
| 4929 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 4930 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 4931 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 4932 | int rc = 0; |
| 4933 | int bytes_returned = 0; |
| 4934 | __u16 params, param_offset, offset, byte_count; |
| 4935 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4936 | cFYI(1, "In SETFSUnixInfo"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4937 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 4938 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 4939 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 4940 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4941 | if (rc) |
| 4942 | return rc; |
| 4943 | |
| 4944 | params = 4; /* 2 bytes zero followed by info level. */ |
| 4945 | pSMB->MaxSetupCount = 0; |
| 4946 | pSMB->Reserved = 0; |
| 4947 | pSMB->Flags = 0; |
| 4948 | pSMB->Timeout = 0; |
| 4949 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4950 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 4951 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4952 | offset = param_offset + params; |
| 4953 | |
| 4954 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4955 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4956 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4957 | pSMB->SetupCount = 1; |
| 4958 | pSMB->Reserved3 = 0; |
| 4959 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 4960 | byte_count = 1 /* pad */ + params + 12; |
| 4961 | |
| 4962 | pSMB->DataCount = cpu_to_le16(12); |
| 4963 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4964 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4965 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4966 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4967 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4968 | |
| 4969 | /* Params. */ |
| 4970 | pSMB->FileNum = 0; |
| 4971 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 4972 | |
| 4973 | /* Data. */ |
| 4974 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 4975 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 4976 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 4977 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4978 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4979 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4980 | |
| 4981 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4982 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4983 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4984 | cERROR(1, "Send error in SETFSUnixInfo = %d", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4985 | } else { /* decode response */ |
| 4986 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4987 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4988 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4989 | } |
| 4990 | cifs_buf_release(pSMB); |
| 4991 | |
| 4992 | if (rc == -EAGAIN) |
| 4993 | goto SETFSUnixRetry; |
| 4994 | |
| 4995 | return rc; |
| 4996 | } |
| 4997 | |
| 4998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | |
| 5000 | int |
| 5001 | CIFSSMBQFSPosixInfo(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5002 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | { |
| 5004 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 5005 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 5006 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 5007 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 5008 | int rc = 0; |
| 5009 | int bytes_returned = 0; |
| 5010 | __u16 params, byte_count; |
| 5011 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5012 | cFYI(1, "In QFSPosixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5013 | QFSPosixRetry: |
| 5014 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5015 | (void **) &pSMBr); |
| 5016 | if (rc) |
| 5017 | return rc; |
| 5018 | |
| 5019 | params = 2; /* level */ |
| 5020 | pSMB->TotalDataCount = 0; |
| 5021 | pSMB->DataCount = 0; |
| 5022 | pSMB->DataOffset = 0; |
| 5023 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5024 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5025 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | pSMB->MaxSetupCount = 0; |
| 5027 | pSMB->Reserved = 0; |
| 5028 | pSMB->Flags = 0; |
| 5029 | pSMB->Timeout = 0; |
| 5030 | pSMB->Reserved2 = 0; |
| 5031 | byte_count = params + 1 /* pad */ ; |
| 5032 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5033 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5034 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 5035 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | pSMB->SetupCount = 1; |
| 5037 | pSMB->Reserved3 = 0; |
| 5038 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 5039 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5040 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5042 | |
| 5043 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5044 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5045 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5046 | cFYI(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | } else { /* decode response */ |
| 5048 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5049 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5050 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | rc = -EIO; /* bad smb */ |
| 5052 | } else { |
| 5053 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5054 | response_data = |
| 5055 | (FILE_SYSTEM_POSIX_INFO |
| 5056 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 5057 | data_offset); |
| 5058 | FSData->f_bsize = |
| 5059 | le32_to_cpu(response_data->BlockSize); |
| 5060 | FSData->f_blocks = |
| 5061 | le64_to_cpu(response_data->TotalBlocks); |
| 5062 | FSData->f_bfree = |
| 5063 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5064 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | FSData->f_bavail = FSData->f_bfree; |
| 5066 | } else { |
| 5067 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5068 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5070 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5072 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5073 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5075 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5076 | } |
| 5077 | } |
| 5078 | cifs_buf_release(pSMB); |
| 5079 | |
| 5080 | if (rc == -EAGAIN) |
| 5081 | goto QFSPosixRetry; |
| 5082 | |
| 5083 | return rc; |
| 5084 | } |
| 5085 | |
| 5086 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5087 | /* We can not use write of zero bytes trick to |
| 5088 | set file size due to need for large file support. Also note that |
| 5089 | this SetPathInfo is preferred to SetFileInfo based method in next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | routine which is only needed to work around a sharing violation bug |
| 5091 | in Samba which this routine can run into */ |
| 5092 | |
| 5093 | int |
| 5094 | CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5095 | __u64 size, bool SetAllocation, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5096 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 | { |
| 5098 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5099 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5100 | struct file_end_of_file_info *parm_data; |
| 5101 | int name_len; |
| 5102 | int rc = 0; |
| 5103 | int bytes_returned = 0; |
| 5104 | __u16 params, byte_count, data_count, param_offset, offset; |
| 5105 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5106 | cFYI(1, "In SetEOF"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5107 | SetEOFRetry: |
| 5108 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5109 | (void **) &pSMBr); |
| 5110 | if (rc) |
| 5111 | return rc; |
| 5112 | |
| 5113 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5114 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 5115 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5116 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5117 | name_len++; /* trailing null */ |
| 5118 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5119 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5120 | name_len = strnlen(fileName, PATH_MAX); |
| 5121 | name_len++; /* trailing null */ |
| 5122 | strncpy(pSMB->FileName, fileName, name_len); |
| 5123 | } |
| 5124 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5125 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5126 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5127 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | pSMB->MaxSetupCount = 0; |
| 5129 | pSMB->Reserved = 0; |
| 5130 | pSMB->Flags = 0; |
| 5131 | pSMB->Timeout = 0; |
| 5132 | pSMB->Reserved2 = 0; |
| 5133 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5134 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5135 | offset = param_offset + params; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5136 | if (SetAllocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5137 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5138 | pSMB->InformationLevel = |
| 5139 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5140 | else |
| 5141 | pSMB->InformationLevel = |
| 5142 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 5143 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5144 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5145 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5146 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | else |
| 5148 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5149 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5150 | } |
| 5151 | |
| 5152 | parm_data = |
| 5153 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 5154 | offset); |
| 5155 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5156 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5157 | pSMB->SetupCount = 1; |
| 5158 | pSMB->Reserved3 = 0; |
| 5159 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5160 | byte_count = 3 /* pad */ + params + data_count; |
| 5161 | pSMB->DataCount = cpu_to_le16(data_count); |
| 5162 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5163 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5164 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5165 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5166 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | parm_data->FileSize = cpu_to_le64(size); |
| 5168 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5169 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5170 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5171 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5172 | cFYI(1, "SetPathInfo (file size) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5173 | |
| 5174 | cifs_buf_release(pSMB); |
| 5175 | |
| 5176 | if (rc == -EAGAIN) |
| 5177 | goto SetEOFRetry; |
| 5178 | |
| 5179 | return rc; |
| 5180 | } |
| 5181 | |
| 5182 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5183 | CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 5184 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 | { |
| 5186 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5187 | struct file_end_of_file_info *parm_data; |
| 5188 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | __u16 params, param_offset, offset, byte_count, count; |
| 5190 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5191 | cFYI(1, "SetFileSize (via SetFileInfo) %lld", |
| 5192 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5193 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5195 | if (rc) |
| 5196 | return rc; |
| 5197 | |
| 5198 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5199 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5201 | params = 6; |
| 5202 | pSMB->MaxSetupCount = 0; |
| 5203 | pSMB->Reserved = 0; |
| 5204 | pSMB->Flags = 0; |
| 5205 | pSMB->Timeout = 0; |
| 5206 | pSMB->Reserved2 = 0; |
| 5207 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5208 | offset = param_offset + params; |
| 5209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | count = sizeof(struct file_end_of_file_info); |
| 5211 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5212 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5213 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5214 | pSMB->SetupCount = 1; |
| 5215 | pSMB->Reserved3 = 0; |
| 5216 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5217 | byte_count = 3 /* pad */ + params + count; |
| 5218 | pSMB->DataCount = cpu_to_le16(count); |
| 5219 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5220 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5221 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5222 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5223 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5224 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 5225 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5227 | parm_data->FileSize = cpu_to_le64(size); |
| 5228 | pSMB->Fid = fid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5229 | if (SetAllocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5231 | pSMB->InformationLevel = |
| 5232 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 5233 | else |
| 5234 | pSMB->InformationLevel = |
| 5235 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5236 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5237 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5238 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5239 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | else |
| 5241 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5242 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5243 | } |
| 5244 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5245 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5246 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 5247 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5249 | cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5250 | } |
| 5251 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5252 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5253 | since file handle passed in no longer valid */ |
| 5254 | |
| 5255 | return rc; |
| 5256 | } |
| 5257 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5258 | /* 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] | 5259 | an open handle, rather than by pathname - this is awkward due to |
| 5260 | potential access conflicts on the open, but it is unavoidable for these |
| 5261 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5262 | time and resort to the original setpathinfo level which takes the ancient |
| 5263 | DOS time format with 2 second granularity */ |
| 5264 | int |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5265 | CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 5266 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5267 | { |
| 5268 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | char *data_offset; |
| 5270 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5271 | __u16 params, param_offset, offset, byte_count, count; |
| 5272 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5273 | cFYI(1, "Set Times (via SetFileInfo)"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5274 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5276 | if (rc) |
| 5277 | return rc; |
| 5278 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5279 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5280 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5282 | params = 6; |
| 5283 | pSMB->MaxSetupCount = 0; |
| 5284 | pSMB->Reserved = 0; |
| 5285 | pSMB->Flags = 0; |
| 5286 | pSMB->Timeout = 0; |
| 5287 | pSMB->Reserved2 = 0; |
| 5288 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5289 | offset = param_offset + params; |
| 5290 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5291 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5292 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5293 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5295 | /* BB find max SMB PDU from sess */ |
| 5296 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5297 | pSMB->SetupCount = 1; |
| 5298 | pSMB->Reserved3 = 0; |
| 5299 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5300 | byte_count = 3 /* pad */ + params + count; |
| 5301 | pSMB->DataCount = cpu_to_le16(count); |
| 5302 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5303 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5304 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5305 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5306 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5307 | pSMB->Fid = fid; |
| 5308 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5309 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5310 | else |
| 5311 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5312 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5313 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5314 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5315 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 5316 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5317 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5318 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5320 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | since file handle passed in no longer valid */ |
| 5322 | |
| 5323 | return rc; |
| 5324 | } |
| 5325 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5326 | int |
| 5327 | CIFSSMBSetFileDisposition(const int xid, struct cifsTconInfo *tcon, |
| 5328 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5329 | { |
| 5330 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5331 | char *data_offset; |
| 5332 | int rc = 0; |
| 5333 | __u16 params, param_offset, offset, byte_count, count; |
| 5334 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5335 | cFYI(1, "Set File Disposition (via SetFileInfo)"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5336 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5337 | |
| 5338 | if (rc) |
| 5339 | return rc; |
| 5340 | |
| 5341 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5342 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5343 | |
| 5344 | params = 6; |
| 5345 | pSMB->MaxSetupCount = 0; |
| 5346 | pSMB->Reserved = 0; |
| 5347 | pSMB->Flags = 0; |
| 5348 | pSMB->Timeout = 0; |
| 5349 | pSMB->Reserved2 = 0; |
| 5350 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5351 | offset = param_offset + params; |
| 5352 | |
| 5353 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5354 | |
| 5355 | count = 1; |
| 5356 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5357 | /* BB find max SMB PDU from sess */ |
| 5358 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5359 | pSMB->SetupCount = 1; |
| 5360 | pSMB->Reserved3 = 0; |
| 5361 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5362 | byte_count = 3 /* pad */ + params + count; |
| 5363 | pSMB->DataCount = cpu_to_le16(count); |
| 5364 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5365 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5366 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5367 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5368 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5369 | pSMB->Fid = fid; |
| 5370 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5371 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5372 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5373 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5374 | *data_offset = delete_file ? 1 : 0; |
| 5375 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 5376 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5377 | cFYI(1, "Send error in SetFileDisposition = %d", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5378 | |
| 5379 | return rc; |
| 5380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5381 | |
| 5382 | int |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5383 | CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 5384 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5385 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | { |
| 5387 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5388 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5389 | int name_len; |
| 5390 | int rc = 0; |
| 5391 | int bytes_returned = 0; |
| 5392 | char *data_offset; |
| 5393 | __u16 params, param_offset, offset, byte_count, count; |
| 5394 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5395 | cFYI(1, "In SetTimes"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5396 | |
| 5397 | SetTimesRetry: |
| 5398 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5399 | (void **) &pSMBr); |
| 5400 | if (rc) |
| 5401 | return rc; |
| 5402 | |
| 5403 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5404 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 5405 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5406 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5407 | name_len++; /* trailing null */ |
| 5408 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5409 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5410 | name_len = strnlen(fileName, PATH_MAX); |
| 5411 | name_len++; /* trailing null */ |
| 5412 | strncpy(pSMB->FileName, fileName, name_len); |
| 5413 | } |
| 5414 | |
| 5415 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5416 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5418 | /* BB find max SMB PDU from sess structure BB */ |
| 5419 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5420 | pSMB->MaxSetupCount = 0; |
| 5421 | pSMB->Reserved = 0; |
| 5422 | pSMB->Flags = 0; |
| 5423 | pSMB->Timeout = 0; |
| 5424 | pSMB->Reserved2 = 0; |
| 5425 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5426 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | offset = param_offset + params; |
| 5428 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5429 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5430 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5431 | pSMB->SetupCount = 1; |
| 5432 | pSMB->Reserved3 = 0; |
| 5433 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5434 | byte_count = 3 /* pad */ + params + count; |
| 5435 | |
| 5436 | pSMB->DataCount = cpu_to_le16(count); |
| 5437 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5438 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5439 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5440 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5441 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5442 | else |
| 5443 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5444 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5445 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5446 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5448 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5449 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5450 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5451 | cFYI(1, "SetPathInfo (times) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | |
| 5453 | cifs_buf_release(pSMB); |
| 5454 | |
| 5455 | if (rc == -EAGAIN) |
| 5456 | goto SetTimesRetry; |
| 5457 | |
| 5458 | return rc; |
| 5459 | } |
| 5460 | |
| 5461 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5462 | /* Can be used to set attributes */ |
| 5463 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5464 | handling it anyway and NT4 was what we thought it would be needed for |
| 5465 | Do not delete it until we prove whether needed for Win9x though */ |
| 5466 | int |
| 5467 | CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName, |
| 5468 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5469 | { |
| 5470 | SETATTR_REQ *pSMB = NULL; |
| 5471 | SETATTR_RSP *pSMBr = NULL; |
| 5472 | int rc = 0; |
| 5473 | int bytes_returned; |
| 5474 | int name_len; |
| 5475 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5476 | cFYI(1, "In SetAttrLegacy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | |
| 5478 | SetAttrLgcyRetry: |
| 5479 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5480 | (void **) &pSMBr); |
| 5481 | if (rc) |
| 5482 | return rc; |
| 5483 | |
| 5484 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5485 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5486 | ConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | PATH_MAX, nls_codepage); |
| 5488 | name_len++; /* trailing null */ |
| 5489 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5490 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | name_len = strnlen(fileName, PATH_MAX); |
| 5492 | name_len++; /* trailing null */ |
| 5493 | strncpy(pSMB->fileName, fileName, name_len); |
| 5494 | } |
| 5495 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5496 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5497 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5498 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5499 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5500 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5501 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5502 | cFYI(1, "Error in LegacySetAttr = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | |
| 5504 | cifs_buf_release(pSMB); |
| 5505 | |
| 5506 | if (rc == -EAGAIN) |
| 5507 | goto SetAttrLgcyRetry; |
| 5508 | |
| 5509 | return rc; |
| 5510 | } |
| 5511 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5512 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5513 | static void |
| 5514 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5515 | const struct cifs_unix_set_info_args *args) |
| 5516 | { |
| 5517 | u64 mode = args->mode; |
| 5518 | |
| 5519 | /* |
| 5520 | * Samba server ignores set of file size to zero due to bugs in some |
| 5521 | * older clients, but we should be precise - we use SetFileSize to |
| 5522 | * 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] | 5523 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5524 | * zero instead of -1 here |
| 5525 | */ |
| 5526 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5527 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5528 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5529 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5530 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
| 5531 | data_offset->Uid = cpu_to_le64(args->uid); |
| 5532 | data_offset->Gid = cpu_to_le64(args->gid); |
| 5533 | /* better to leave device as zero when it is */ |
| 5534 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5535 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5536 | data_offset->Permissions = cpu_to_le64(mode); |
| 5537 | |
| 5538 | if (S_ISREG(mode)) |
| 5539 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5540 | else if (S_ISDIR(mode)) |
| 5541 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 5542 | else if (S_ISLNK(mode)) |
| 5543 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 5544 | else if (S_ISCHR(mode)) |
| 5545 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 5546 | else if (S_ISBLK(mode)) |
| 5547 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 5548 | else if (S_ISFIFO(mode)) |
| 5549 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 5550 | else if (S_ISSOCK(mode)) |
| 5551 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5552 | } |
| 5553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 | int |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5555 | CIFSSMBUnixSetFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 5556 | const struct cifs_unix_set_info_args *args, |
| 5557 | u16 fid, u32 pid_of_opener) |
| 5558 | { |
| 5559 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5560 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5561 | int rc = 0; |
| 5562 | u16 params, param_offset, offset, byte_count, count; |
| 5563 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5564 | cFYI(1, "Set Unix Info (via SetFileInfo)"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5565 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5566 | |
| 5567 | if (rc) |
| 5568 | return rc; |
| 5569 | |
| 5570 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5571 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5572 | |
| 5573 | params = 6; |
| 5574 | pSMB->MaxSetupCount = 0; |
| 5575 | pSMB->Reserved = 0; |
| 5576 | pSMB->Flags = 0; |
| 5577 | pSMB->Timeout = 0; |
| 5578 | pSMB->Reserved2 = 0; |
| 5579 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5580 | offset = param_offset + params; |
| 5581 | |
| 5582 | data_offset = (FILE_UNIX_BASIC_INFO *) |
| 5583 | ((char *)(&pSMB->hdr.Protocol) + offset); |
| 5584 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 5585 | |
| 5586 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5587 | /* BB find max SMB PDU from sess */ |
| 5588 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5589 | pSMB->SetupCount = 1; |
| 5590 | pSMB->Reserved3 = 0; |
| 5591 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5592 | byte_count = 3 /* pad */ + params + count; |
| 5593 | pSMB->DataCount = cpu_to_le16(count); |
| 5594 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5595 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5596 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5597 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5598 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5599 | pSMB->Fid = fid; |
| 5600 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5601 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5602 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5603 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5604 | |
| 5605 | cifs_fill_unix_set_info(data_offset, args); |
| 5606 | |
| 5607 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 5608 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5609 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5610 | |
| 5611 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 5612 | since file handle passed in no longer valid */ |
| 5613 | |
| 5614 | return rc; |
| 5615 | } |
| 5616 | |
| 5617 | int |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5618 | CIFSSMBUnixSetPathInfo(const int xid, struct cifsTconInfo *tcon, char *fileName, |
| 5619 | const struct cifs_unix_set_info_args *args, |
| 5620 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5621 | { |
| 5622 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5623 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5624 | int name_len; |
| 5625 | int rc = 0; |
| 5626 | int bytes_returned = 0; |
| 5627 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5628 | __u16 params, param_offset, offset, count, byte_count; |
| 5629 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5630 | cFYI(1, "In SetUID/GID/Mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5631 | setPermsRetry: |
| 5632 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5633 | (void **) &pSMBr); |
| 5634 | if (rc) |
| 5635 | return rc; |
| 5636 | |
| 5637 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5638 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5639 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5640 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5641 | name_len++; /* trailing null */ |
| 5642 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5643 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | name_len = strnlen(fileName, PATH_MAX); |
| 5645 | name_len++; /* trailing null */ |
| 5646 | strncpy(pSMB->FileName, fileName, name_len); |
| 5647 | } |
| 5648 | |
| 5649 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5650 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5652 | /* BB find max SMB PDU from sess structure BB */ |
| 5653 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5654 | pSMB->MaxSetupCount = 0; |
| 5655 | pSMB->Reserved = 0; |
| 5656 | pSMB->Flags = 0; |
| 5657 | pSMB->Timeout = 0; |
| 5658 | pSMB->Reserved2 = 0; |
| 5659 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5660 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | offset = param_offset + params; |
| 5662 | data_offset = |
| 5663 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 5664 | offset); |
| 5665 | memset(data_offset, 0, count); |
| 5666 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5667 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5668 | pSMB->SetupCount = 1; |
| 5669 | pSMB->Reserved3 = 0; |
| 5670 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5671 | byte_count = 3 /* pad */ + params + count; |
| 5672 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5673 | pSMB->DataCount = cpu_to_le16(count); |
| 5674 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5675 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5676 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5677 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5678 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5679 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5680 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5681 | |
| 5682 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5683 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5684 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5685 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5686 | cFYI(1, "SetPathInfo (perms) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5688 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5689 | if (rc == -EAGAIN) |
| 5690 | goto setPermsRetry; |
| 5691 | return rc; |
| 5692 | } |
| 5693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5694 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5695 | /* |
| 5696 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 5697 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 5698 | * it looks for that attribute name and stuffs that value into the EAData |
| 5699 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 5700 | * buffer. In both cases, the return value is either the length of the |
| 5701 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 5702 | * the data isn't copied to it, but the length is returned. |
| 5703 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | ssize_t |
| 5705 | CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5706 | const unsigned char *searchName, const unsigned char *ea_name, |
| 5707 | char *EAData, size_t buf_size, |
| 5708 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5709 | { |
| 5710 | /* BB assumes one setup word */ |
| 5711 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 5712 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 5713 | int rc = 0; |
| 5714 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5715 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5716 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5717 | struct fea *temp_fea; |
| 5718 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5719 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5720 | __u16 params, byte_count, data_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5722 | cFYI(1, "In Query All EAs path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5723 | QAllEAsRetry: |
| 5724 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5725 | (void **) &pSMBr); |
| 5726 | if (rc) |
| 5727 | return rc; |
| 5728 | |
| 5729 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5730 | list_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5731 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5732 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5733 | list_len++; /* trailing null */ |
| 5734 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5736 | list_len = strnlen(searchName, PATH_MAX); |
| 5737 | list_len++; /* trailing null */ |
| 5738 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5739 | } |
| 5740 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5741 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | pSMB->TotalDataCount = 0; |
| 5743 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5744 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5745 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5746 | pSMB->MaxSetupCount = 0; |
| 5747 | pSMB->Reserved = 0; |
| 5748 | pSMB->Flags = 0; |
| 5749 | pSMB->Timeout = 0; |
| 5750 | pSMB->Reserved2 = 0; |
| 5751 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5752 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5753 | pSMB->DataCount = 0; |
| 5754 | pSMB->DataOffset = 0; |
| 5755 | pSMB->SetupCount = 1; |
| 5756 | pSMB->Reserved3 = 0; |
| 5757 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 5758 | byte_count = params + 1 /* pad */ ; |
| 5759 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5760 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5761 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 5762 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5763 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5765 | |
| 5766 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5767 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5768 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5769 | cFYI(1, "Send error in QueryAllEAs = %d", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5770 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5772 | |
| 5773 | |
| 5774 | /* BB also check enough total bytes returned */ |
| 5775 | /* BB we need to improve the validity checking |
| 5776 | of these trans2 responses */ |
| 5777 | |
| 5778 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5779 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5780 | rc = -EIO; /* bad smb */ |
| 5781 | goto QAllEAsOut; |
| 5782 | } |
| 5783 | |
| 5784 | /* check that length of list is not more than bcc */ |
| 5785 | /* check that each entry does not go beyond length |
| 5786 | of list */ |
| 5787 | /* check that each element of each entry does not |
| 5788 | go beyond end of list */ |
| 5789 | /* validate_trans2_offsets() */ |
| 5790 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 5791 | |
| 5792 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5793 | ea_response_data = (struct fealist *) |
| 5794 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 5795 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5796 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5797 | cFYI(1, "ea length %d", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5798 | if (list_len <= 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5799 | cFYI(1, "empty EA list returned from server"); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5800 | goto QAllEAsOut; |
| 5801 | } |
| 5802 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5803 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 5804 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5805 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5806 | cFYI(1, "EA list appears to go beyond SMB"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5807 | rc = -EIO; |
| 5808 | goto QAllEAsOut; |
| 5809 | } |
| 5810 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5811 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5812 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5813 | temp_fea = ea_response_data->list; |
| 5814 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5815 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 5816 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5817 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5818 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5819 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5820 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5821 | /* make sure we can read name_len and value_len */ |
| 5822 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5823 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5824 | rc = -EIO; |
| 5825 | goto QAllEAsOut; |
| 5826 | } |
| 5827 | |
| 5828 | name_len = temp_fea->name_len; |
| 5829 | value_len = le16_to_cpu(temp_fea->value_len); |
| 5830 | list_len -= name_len + 1 + value_len; |
| 5831 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5832 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5833 | rc = -EIO; |
| 5834 | goto QAllEAsOut; |
| 5835 | } |
| 5836 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5837 | if (ea_name) { |
| 5838 | if (strncmp(ea_name, temp_ptr, name_len) == 0) { |
| 5839 | temp_ptr += name_len + 1; |
| 5840 | rc = value_len; |
| 5841 | if (buf_size == 0) |
| 5842 | goto QAllEAsOut; |
| 5843 | if ((size_t)value_len > buf_size) { |
| 5844 | rc = -ERANGE; |
| 5845 | goto QAllEAsOut; |
| 5846 | } |
| 5847 | memcpy(EAData, temp_ptr, value_len); |
| 5848 | goto QAllEAsOut; |
| 5849 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5850 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5851 | /* account for prefix user. and trailing null */ |
| 5852 | rc += (5 + 1 + name_len); |
| 5853 | if (rc < (int) buf_size) { |
| 5854 | memcpy(EAData, "user.", 5); |
| 5855 | EAData += 5; |
| 5856 | memcpy(EAData, temp_ptr, name_len); |
| 5857 | EAData += name_len; |
| 5858 | /* null terminate name */ |
| 5859 | *EAData = 0; |
| 5860 | ++EAData; |
| 5861 | } else if (buf_size == 0) { |
| 5862 | /* skip copy - calc size only */ |
| 5863 | } else { |
| 5864 | /* stop before overrun buffer */ |
| 5865 | rc = -ERANGE; |
| 5866 | break; |
| 5867 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5868 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5869 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5870 | temp_fea = (struct fea *)temp_ptr; |
| 5871 | } |
| 5872 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5873 | /* didn't find the named attribute */ |
| 5874 | if (ea_name) |
| 5875 | rc = -ENODATA; |
| 5876 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5877 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5878 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5879 | if (rc == -EAGAIN) |
| 5880 | goto QAllEAsRetry; |
| 5881 | |
| 5882 | return (ssize_t)rc; |
| 5883 | } |
| 5884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5885 | int |
| 5886 | CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5887 | const char *ea_name, const void *ea_value, |
| 5888 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 5889 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5890 | { |
| 5891 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5892 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5893 | struct fealist *parm_data; |
| 5894 | int name_len; |
| 5895 | int rc = 0; |
| 5896 | int bytes_returned = 0; |
| 5897 | __u16 params, param_offset, byte_count, offset, count; |
| 5898 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5899 | cFYI(1, "In SetEA"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5900 | SetEARetry: |
| 5901 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5902 | (void **) &pSMBr); |
| 5903 | if (rc) |
| 5904 | return rc; |
| 5905 | |
| 5906 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5907 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5908 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5909 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5910 | name_len++; /* trailing null */ |
| 5911 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5912 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5913 | name_len = strnlen(fileName, PATH_MAX); |
| 5914 | name_len++; /* trailing null */ |
| 5915 | strncpy(pSMB->FileName, fileName, name_len); |
| 5916 | } |
| 5917 | |
| 5918 | params = 6 + name_len; |
| 5919 | |
| 5920 | /* done calculating parms using name_len of file name, |
| 5921 | now use name_len to calculate length of ea name |
| 5922 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5923 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5924 | name_len = 0; |
| 5925 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5926 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5927 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 5928 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5929 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5930 | /* BB find max SMB PDU from sess */ |
| 5931 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5932 | pSMB->MaxSetupCount = 0; |
| 5933 | pSMB->Reserved = 0; |
| 5934 | pSMB->Flags = 0; |
| 5935 | pSMB->Timeout = 0; |
| 5936 | pSMB->Reserved2 = 0; |
| 5937 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5938 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | offset = param_offset + params; |
| 5940 | pSMB->InformationLevel = |
| 5941 | cpu_to_le16(SMB_SET_FILE_EA); |
| 5942 | |
| 5943 | parm_data = |
| 5944 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 5945 | offset); |
| 5946 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5947 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5948 | pSMB->SetupCount = 1; |
| 5949 | pSMB->Reserved3 = 0; |
| 5950 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5951 | byte_count = 3 /* pad */ + params + count; |
| 5952 | pSMB->DataCount = cpu_to_le16(count); |
| 5953 | parm_data->list_len = cpu_to_le32(count); |
| 5954 | parm_data->list[0].EA_flags = 0; |
| 5955 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 5956 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5957 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5958 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5959 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5960 | parm_data->list[0].name[name_len] = 0; |
| 5961 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 5962 | /* caller ensures that ea_value_len is less than 64K but |
| 5963 | we need to ensure that it fits within the smb */ |
| 5964 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5965 | /*BB add length check to see if it would fit in |
| 5966 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5967 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 5968 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5969 | memcpy(parm_data->list[0].name+name_len+1, |
| 5970 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5971 | |
| 5972 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5973 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5974 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5975 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5976 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5977 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5978 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5979 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5980 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5981 | cFYI(1, "SetPathInfo (EA) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5982 | |
| 5983 | cifs_buf_release(pSMB); |
| 5984 | |
| 5985 | if (rc == -EAGAIN) |
| 5986 | goto SetEARetry; |
| 5987 | |
| 5988 | return rc; |
| 5989 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5990 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 5991 | |
| 5992 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 5993 | /* |
| 5994 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 5995 | * to allow network clients (such as Windows) to display updated |
| 5996 | * lists of files in directory listings automatically when |
| 5997 | * files are added by one user when another user has the |
| 5998 | * same directory open on their desktop. The Linux cifs kernel |
| 5999 | * client hooked into the kernel side of this interface for |
| 6000 | * the same reason, but ironically when the VFS moved from |
| 6001 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 6002 | * network file system clients (the most obvious use case |
| 6003 | * for notify interfaces is when multiple users can update |
| 6004 | * the contents of the same directory - exactly what network |
| 6005 | * file systems can do) although the server (Samba) could |
| 6006 | * still use it. For the short term we leave the worker |
| 6007 | * function ifdeffed out (below) until inotify is fixed |
| 6008 | * in the VFS to make it easier to plug in network file |
| 6009 | * system clients. If inotify turns out to be permanently |
| 6010 | * incompatible for network fs clients, we could instead simply |
| 6011 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 6012 | */ |
| 6013 | int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, |
| 6014 | const int notify_subdirs, const __u16 netfid, |
| 6015 | __u32 filter, struct file *pfile, int multishot, |
| 6016 | const struct nls_table *nls_codepage) |
| 6017 | { |
| 6018 | int rc = 0; |
| 6019 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 6020 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 6021 | struct dir_notify_req *dnotify_req; |
| 6022 | int bytes_returned; |
| 6023 | |
| 6024 | cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid); |
| 6025 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 6026 | (void **) &pSMBr); |
| 6027 | if (rc) |
| 6028 | return rc; |
| 6029 | |
| 6030 | pSMB->TotalParameterCount = 0 ; |
| 6031 | pSMB->TotalDataCount = 0; |
| 6032 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 6033 | /* BB find exact data count max from sess structure BB */ |
| 6034 | pSMB->MaxDataCount = 0; /* same in little endian or be */ |
| 6035 | /* BB VERIFY verify which is correct for above BB */ |
| 6036 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 6037 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 6038 | |
| 6039 | pSMB->MaxSetupCount = 4; |
| 6040 | pSMB->Reserved = 0; |
| 6041 | pSMB->ParameterOffset = 0; |
| 6042 | pSMB->DataCount = 0; |
| 6043 | pSMB->DataOffset = 0; |
| 6044 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 6045 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 6046 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 6047 | if (notify_subdirs) |
| 6048 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 6049 | pSMB->Reserved2 = 0; |
| 6050 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 6051 | pSMB->Fid = netfid; /* file handle always le */ |
| 6052 | pSMB->ByteCount = 0; |
| 6053 | |
| 6054 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 6055 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 6056 | CIFS_ASYNC_OP); |
| 6057 | if (rc) { |
| 6058 | cFYI(1, "Error in Notify = %d", rc); |
| 6059 | } else { |
| 6060 | /* Add file to outstanding requests */ |
| 6061 | /* BB change to kmem cache alloc */ |
| 6062 | dnotify_req = kmalloc( |
| 6063 | sizeof(struct dir_notify_req), |
| 6064 | GFP_KERNEL); |
| 6065 | if (dnotify_req) { |
| 6066 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 6067 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 6068 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 6069 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 6070 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 6071 | dnotify_req->netfid = netfid; |
| 6072 | dnotify_req->pfile = pfile; |
| 6073 | dnotify_req->filter = filter; |
| 6074 | dnotify_req->multishot = multishot; |
| 6075 | spin_lock(&GlobalMid_Lock); |
| 6076 | list_add_tail(&dnotify_req->lhead, |
| 6077 | &GlobalDnotifyReqList); |
| 6078 | spin_unlock(&GlobalMid_Lock); |
| 6079 | } else |
| 6080 | rc = -ENOMEM; |
| 6081 | } |
| 6082 | cifs_buf_release(pSMB); |
| 6083 | return rc; |
| 6084 | } |
| 6085 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |