Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cifssmb.c |
| 3 | * |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2008 |
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> |
| 33 | #include <linux/posix_acl_xattr.h> |
| 34 | #include <asm/uaccess.h> |
| 35 | #include "cifspdu.h" |
| 36 | #include "cifsglob.h" |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 37 | #include "cifsacl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include "cifsproto.h" |
| 39 | #include "cifs_unicode.h" |
| 40 | #include "cifs_debug.h" |
| 41 | |
| 42 | #ifdef CONFIG_CIFS_POSIX |
| 43 | static struct { |
| 44 | int index; |
| 45 | char *name; |
| 46 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 47 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 48 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 49 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 50 | #endif /* weak password hashing for legacy clients */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 51 | {CIFS_PROT, "\2NT LM 0.12"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 52 | {POSIX_PROT, "\2POSIX 2"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | {BAD_PROT, "\2"} |
| 54 | }; |
| 55 | #else |
| 56 | static struct { |
| 57 | int index; |
| 58 | char *name; |
| 59 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 60 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 61 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 18f75ca | 2006-10-01 03:13:01 +0000 | [diff] [blame] | 62 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 63 | #endif /* weak password hashing for legacy clients */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 64 | {CIFS_PROT, "\2NT LM 0.12"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | {BAD_PROT, "\2"} |
| 66 | }; |
| 67 | #endif |
| 68 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 69 | /* define the number of elements in the cifs dialect array */ |
| 70 | #ifdef CONFIG_CIFS_POSIX |
| 71 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 72 | #define CIFS_NUM_PROT 4 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 73 | #else |
| 74 | #define CIFS_NUM_PROT 2 |
| 75 | #endif /* CIFS_WEAK_PW_HASH */ |
| 76 | #else /* not posix */ |
| 77 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 78 | #define CIFS_NUM_PROT 3 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 79 | #else |
| 80 | #define CIFS_NUM_PROT 1 |
| 81 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
| 82 | #endif /* CIFS_POSIX */ |
| 83 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 84 | /* Allocates buffer into dst and copies smb string from src to it. |
| 85 | * caller is responsible for freeing dst if function returned 0. |
| 86 | * returns: |
| 87 | * on success - 0 |
| 88 | * on failure - errno |
| 89 | */ |
| 90 | static int |
| 91 | cifs_strncpy_to_host(char **dst, const char *src, const int maxlen, |
| 92 | const bool is_unicode, const struct nls_table *nls_codepage) |
| 93 | { |
| 94 | int plen; |
| 95 | |
| 96 | if (is_unicode) { |
| 97 | plen = UniStrnlen((wchar_t *)src, maxlen); |
| 98 | *dst = kmalloc(plen + 2, GFP_KERNEL); |
| 99 | if (!*dst) |
| 100 | goto cifs_strncpy_to_host_ErrExit; |
| 101 | cifs_strfromUCS_le(*dst, (__le16 *)src, plen, nls_codepage); |
| 102 | } else { |
| 103 | plen = strnlen(src, maxlen); |
| 104 | *dst = kmalloc(plen + 2, GFP_KERNEL); |
| 105 | if (!*dst) |
| 106 | goto cifs_strncpy_to_host_ErrExit; |
| 107 | strncpy(*dst, src, plen); |
| 108 | } |
| 109 | (*dst)[plen] = 0; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 110 | (*dst)[plen+1] = 0; /* harmless for ASCII case, needed for Unicode */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 111 | return 0; |
| 112 | |
| 113 | cifs_strncpy_to_host_ErrExit: |
| 114 | cERROR(1, ("Failed to allocate buffer for string\n")); |
| 115 | return -ENOMEM; |
| 116 | } |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | /* Mark as invalid, all open files on tree connections since they |
| 120 | were closed when session to server was lost */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 121 | static void mark_open_files_invalid(struct cifsTconInfo *pTcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 124 | struct list_head *tmp; |
| 125 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | /* list all files open on tree connection and mark them invalid */ |
| 128 | write_lock(&GlobalSMBSeslock); |
| 129 | list_for_each_safe(tmp, tmp1, &pTcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 130 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 131 | open_file->invalidHandle = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | write_unlock(&GlobalSMBSeslock); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 134 | /* BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 135 | to this tcon */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 138 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 139 | SMB information in the SMB header. If the return code is zero, this |
| 140 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | static int |
| 142 | small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 143 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
| 145 | int rc = 0; |
| 146 | |
| 147 | /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so |
| 148 | check for tcp and smb session status done differently |
| 149 | for those three - in the calling routine */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 150 | if (tcon) { |
| 151 | if (tcon->tidStatus == CifsExiting) { |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 152 | /* only tree disconnect, open, and write, |
| 153 | (and ulogoff which does not have tcon) |
| 154 | are allowed as we start force umount */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 155 | if ((smb_command != SMB_COM_WRITE_ANDX) && |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 156 | (smb_command != SMB_COM_OPEN_ANDX) && |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 157 | (smb_command != SMB_COM_TREE_DISCONNECT)) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 158 | cFYI(1, ("can not send cmd %d while umounting", |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 159 | smb_command)); |
| 160 | return -ENODEV; |
| 161 | } |
| 162 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 163 | if ((tcon->ses) && (tcon->ses->status != CifsExiting) && |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 164 | (tcon->ses->server)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | struct nls_table *nls_codepage; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 166 | /* Give Demultiplex thread up to 10 seconds to |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 167 | reconnect, should be greater than cifs socket |
| 168 | timeout which is 7 seconds */ |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 169 | while (tcon->ses->server->tcpStatus == |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 170 | CifsNeedReconnect) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | wait_event_interruptible_timeout(tcon->ses->server->response_q, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 172 | (tcon->ses->server->tcpStatus == |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 173 | CifsGood), 10 * HZ); |
| 174 | if (tcon->ses->server->tcpStatus == |
| 175 | CifsNeedReconnect) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | /* on "soft" mounts we wait once */ |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 177 | if (!tcon->retry || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | (tcon->ses->status == CifsExiting)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 179 | cFYI(1, ("gave up waiting on " |
| 180 | "reconnect in smb_init")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | return -EHOSTDOWN; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 182 | } /* else "hard" mount - keep retrying |
| 183 | until process is killed or server |
| 184 | comes back on-line */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } else /* TCP session is reestablished now */ |
| 186 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | nls_codepage = load_nls_default(); |
| 190 | /* need to prevent multiple threads trying to |
| 191 | simultaneously reconnect the same SMB session */ |
| 192 | down(&tcon->ses->sesSem); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 193 | if (tcon->ses->status == CifsNeedReconnect) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 194 | rc = cifs_setup_session(0, tcon->ses, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 195 | nls_codepage); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 196 | if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | mark_open_files_invalid(tcon); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 198 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 199 | tcon, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | up(&tcon->ses->sesSem); |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 201 | /* BB FIXME add code to check if wsize needs |
| 202 | update due to negotiated smb buffer size |
| 203 | shrinking */ |
Steve French | 35028d7 | 2008-04-09 20:32:42 +0000 | [diff] [blame] | 204 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | atomic_inc(&tconInfoReconnectCount); |
Steve French | 35028d7 | 2008-04-09 20:32:42 +0000 | [diff] [blame] | 206 | /* tell server Unix caps we support */ |
| 207 | if (tcon->ses->capabilities & CAP_UNIX) |
| 208 | reset_cifs_unix_caps( |
| 209 | 0 /* no xid */, |
| 210 | tcon, |
| 211 | NULL /* we do not know sb */, |
| 212 | NULL /* no vol info */); |
| 213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | cFYI(1, ("reconnect tcon rc = %d", rc)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 216 | /* Removed call to reopen open files here. |
| 217 | It is safer (and faster) to reopen files |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 218 | one at a time as needed in read and write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 220 | /* Check if handle based operation so we |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 221 | know whether we can continue or not without |
| 222 | returning to caller to reset file handle */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 223 | switch (smb_command) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | case SMB_COM_READ_ANDX: |
| 225 | case SMB_COM_WRITE_ANDX: |
| 226 | case SMB_COM_CLOSE: |
| 227 | case SMB_COM_FIND_CLOSE2: |
| 228 | case SMB_COM_LOCKING_ANDX: { |
| 229 | unload_nls(nls_codepage); |
| 230 | return -EAGAIN; |
| 231 | } |
| 232 | } |
| 233 | } else { |
| 234 | up(&tcon->ses->sesSem); |
| 235 | } |
| 236 | unload_nls(nls_codepage); |
| 237 | |
| 238 | } else { |
| 239 | return -EIO; |
| 240 | } |
| 241 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 242 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | return rc; |
| 244 | |
| 245 | *request_buf = cifs_small_buf_get(); |
| 246 | if (*request_buf == NULL) { |
| 247 | /* BB should we add a retry in here if not a writepage? */ |
| 248 | return -ENOMEM; |
| 249 | } |
| 250 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 251 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 252 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 254 | if (tcon != NULL) |
| 255 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | return rc; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 260 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 261 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 262 | struct cifsSesInfo *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 263 | { |
| 264 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 265 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 266 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 267 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 268 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 269 | return rc; |
| 270 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 271 | buffer = (struct smb_hdr *)*request_buf; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 272 | buffer->Mid = GetNextMid(ses->server); |
| 273 | if (ses->capabilities & CAP_UNICODE) |
| 274 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 275 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 276 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 277 | |
| 278 | /* uid, tid can stay at zero as set in header assemble */ |
| 279 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 280 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 281 | this function is used after 1st of session setup requests */ |
| 282 | |
| 283 | return rc; |
| 284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 287 | static int |
| 288 | smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, |
| 289 | void **request_buf /* returned */ , |
| 290 | void **response_buf /* returned */ ) |
| 291 | { |
| 292 | int rc = 0; |
| 293 | |
| 294 | /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so |
| 295 | check for tcp and smb session status done differently |
| 296 | for those three - in the calling routine */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 297 | if (tcon) { |
| 298 | if (tcon->tidStatus == CifsExiting) { |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 299 | /* only tree disconnect, open, and write, |
| 300 | (and ulogoff which does not have tcon) |
| 301 | are allowed as we start force umount */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 302 | if ((smb_command != SMB_COM_WRITE_ANDX) && |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 303 | (smb_command != SMB_COM_OPEN_ANDX) && |
| 304 | (smb_command != SMB_COM_TREE_DISCONNECT)) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 305 | cFYI(1, ("can not send cmd %d while umounting", |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 306 | smb_command)); |
| 307 | return -ENODEV; |
| 308 | } |
| 309 | } |
| 310 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 311 | if ((tcon->ses) && (tcon->ses->status != CifsExiting) && |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 312 | (tcon->ses->server)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | struct nls_table *nls_codepage; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 314 | /* Give Demultiplex thread up to 10 seconds to |
| 315 | reconnect, should be greater than cifs socket |
| 316 | timeout which is 7 seconds */ |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 317 | while (tcon->ses->server->tcpStatus == |
| 318 | CifsNeedReconnect) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | wait_event_interruptible_timeout(tcon->ses->server->response_q, |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 320 | (tcon->ses->server->tcpStatus == |
| 321 | CifsGood), 10 * HZ); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 322 | if (tcon->ses->server->tcpStatus == |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 323 | CifsNeedReconnect) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* on "soft" mounts we wait once */ |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 325 | if (!tcon->retry || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | (tcon->ses->status == CifsExiting)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 327 | cFYI(1, ("gave up waiting on " |
| 328 | "reconnect in smb_init")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return -EHOSTDOWN; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 330 | } /* else "hard" mount - keep retrying |
| 331 | until process is killed or server |
| 332 | comes on-line */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } else /* TCP session is reestablished now */ |
| 334 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | nls_codepage = load_nls_default(); |
| 337 | /* need to prevent multiple threads trying to |
| 338 | simultaneously reconnect the same SMB session */ |
| 339 | down(&tcon->ses->sesSem); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 340 | if (tcon->ses->status == CifsNeedReconnect) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 341 | rc = cifs_setup_session(0, tcon->ses, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 342 | nls_codepage); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 343 | if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | mark_open_files_invalid(tcon); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 345 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, |
| 346 | tcon, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | up(&tcon->ses->sesSem); |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 348 | /* BB FIXME add code to check if wsize needs |
| 349 | update due to negotiated smb buffer size |
| 350 | shrinking */ |
Steve French | 35028d7 | 2008-04-09 20:32:42 +0000 | [diff] [blame] | 351 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | atomic_inc(&tconInfoReconnectCount); |
Steve French | 35028d7 | 2008-04-09 20:32:42 +0000 | [diff] [blame] | 353 | /* tell server Unix caps we support */ |
| 354 | if (tcon->ses->capabilities & CAP_UNIX) |
| 355 | reset_cifs_unix_caps( |
| 356 | 0 /* no xid */, |
| 357 | tcon, |
| 358 | NULL /* do not know sb */, |
| 359 | NULL /* no vol info */); |
| 360 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | cFYI(1, ("reconnect tcon rc = %d", rc)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 363 | /* Removed call to reopen open files here. |
| 364 | It is safer (and faster) to reopen files |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 365 | one at a time as needed in read and write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 367 | /* Check if handle based operation so we |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 368 | know whether we can continue or not without |
| 369 | returning to caller to reset file handle */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 370 | switch (smb_command) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | case SMB_COM_READ_ANDX: |
| 372 | case SMB_COM_WRITE_ANDX: |
| 373 | case SMB_COM_CLOSE: |
| 374 | case SMB_COM_FIND_CLOSE2: |
| 375 | case SMB_COM_LOCKING_ANDX: { |
| 376 | unload_nls(nls_codepage); |
| 377 | return -EAGAIN; |
| 378 | } |
| 379 | } |
| 380 | } else { |
| 381 | up(&tcon->ses->sesSem); |
| 382 | } |
| 383 | unload_nls(nls_codepage); |
| 384 | |
| 385 | } else { |
| 386 | return -EIO; |
| 387 | } |
| 388 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 389 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | return rc; |
| 391 | |
| 392 | *request_buf = cifs_buf_get(); |
| 393 | if (*request_buf == NULL) { |
| 394 | /* BB should we add a retry in here if not a writepage? */ |
| 395 | return -ENOMEM; |
| 396 | } |
| 397 | /* Although the original thought was we needed the response buf for */ |
| 398 | /* potential retries of smb operations it turns out we can determine */ |
| 399 | /* from the mid flags when the request buffer can be resent without */ |
| 400 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 401 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 402 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
| 404 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 405 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 407 | if (tcon != NULL) |
| 408 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | return rc; |
| 411 | } |
| 412 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 413 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
| 415 | int rc = -EINVAL; |
| 416 | int total_size; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 417 | char *pBCC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | /* check for plausible wct, bcc and t2 data and parm sizes */ |
| 420 | /* check for parm and data offset going beyond end of smb */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 421 | if (pSMB->hdr.WordCount >= 10) { |
| 422 | if ((le16_to_cpu(pSMB->t2_rsp.ParameterOffset) <= 1024) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | (le16_to_cpu(pSMB->t2_rsp.DataOffset) <= 1024)) { |
| 424 | /* check that bcc is at least as big as parms + data */ |
| 425 | /* check that bcc is less than negotiated smb buffer */ |
| 426 | total_size = le16_to_cpu(pSMB->t2_rsp.ParameterCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 427 | if (total_size < 512) { |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 428 | total_size += |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 429 | le16_to_cpu(pSMB->t2_rsp.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | /* BCC le converted in SendReceive */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 431 | pBCC = (pSMB->hdr.WordCount * 2) + |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 432 | sizeof(struct smb_hdr) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | (char *)pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 434 | if ((total_size <= (*(u16 *)pBCC)) && |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 435 | (total_size < |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | CIFSMaxBufSize+MAX_CIFS_HDR_SIZE)) { |
| 437 | return 0; |
| 438 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 442 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | sizeof(struct smb_t2_rsp) + 16); |
| 444 | return rc; |
| 445 | } |
| 446 | int |
| 447 | CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) |
| 448 | { |
| 449 | NEGOTIATE_REQ *pSMB; |
| 450 | NEGOTIATE_RSP *pSMBr; |
| 451 | int rc = 0; |
| 452 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 453 | int i; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 454 | struct TCP_Server_Info *server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | u16 count; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 456 | unsigned int secFlags; |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 457 | u16 dialect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 459 | if (ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | server = ses->server; |
| 461 | else { |
| 462 | rc = -EIO; |
| 463 | return rc; |
| 464 | } |
| 465 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 466 | (void **) &pSMB, (void **) &pSMBr); |
| 467 | if (rc) |
| 468 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 469 | |
| 470 | /* 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] | 471 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 472 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 473 | else /* if override flags set only sign/seal OR them with global auth */ |
| 474 | secFlags = extended_security | ses->overrideSecFlg; |
| 475 | |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 476 | cFYI(1, ("secFlags 0x%x", secFlags)); |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 477 | |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 478 | pSMB->hdr.Mid = GetNextMid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 479 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 480 | |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 481 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 482 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 483 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { |
| 484 | cFYI(1, ("Kerberos only mechanism, enable extended security")); |
| 485 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 486 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 487 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 488 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 489 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 490 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 491 | count += strlen(protocols[i].name) + 1; |
| 492 | /* null at end of source and target buffers anyway */ |
| 493 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | pSMB->hdr.smb_buf_length += count; |
| 495 | pSMB->ByteCount = cpu_to_le16(count); |
| 496 | |
| 497 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 498 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 499 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 500 | goto neg_err_exit; |
| 501 | |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 502 | dialect = le16_to_cpu(pSMBr->DialectIndex); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 503 | cFYI(1, ("Dialect: %d", dialect)); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 504 | /* Check wct = 1 error case */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 505 | if ((pSMBr->hdr.WordCount < 13) || (dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 506 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 507 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 508 | could not negotiate a common dialect */ |
| 509 | rc = -EOPNOTSUPP; |
| 510 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 511 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 512 | } else if ((pSMBr->hdr.WordCount == 13) |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 513 | && ((dialect == LANMAN_PROT) |
| 514 | || (dialect == LANMAN2_PROT))) { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 515 | __s16 tmp; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 516 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 517 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 518 | if ((secFlags & CIFSSEC_MAY_LANMAN) || |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 519 | (secFlags & CIFSSEC_MAY_PLNTXT)) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 520 | server->secType = LANMAN; |
| 521 | else { |
| 522 | cERROR(1, ("mount failed weak security disabled" |
| 523 | " in /proc/fs/cifs/SecurityFlags")); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 524 | rc = -EOPNOTSUPP; |
| 525 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 526 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 527 | server->secMode = (__u8)le16_to_cpu(rsp->SecurityMode); |
| 528 | server->maxReq = le16_to_cpu(rsp->MaxMpxCount); |
| 529 | server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize), |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 530 | (__u32)CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 531 | GETU32(server->sessid) = le32_to_cpu(rsp->SessionKey); |
| 532 | /* even though we do not use raw we might as well set this |
| 533 | accurately, in case we ever find a need for it */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 534 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 535 | server->maxRw = 0xFF00; |
| 536 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 537 | } else { |
| 538 | server->maxRw = 0;/* we do not need to use raw anyway */ |
| 539 | server->capabilities = CAP_MPX_MODE; |
| 540 | } |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 541 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
Steve French | 1a70d65 | 2006-10-02 05:59:18 +0000 | [diff] [blame] | 542 | if (tmp == -1) { |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 543 | /* OS/2 often does not set timezone therefore |
| 544 | * we must use server time to calc time zone. |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 545 | * Could deviate slightly from the right zone. |
| 546 | * Smallest defined timezone difference is 15 minutes |
| 547 | * (i.e. Nepal). Rounding up/down is done to match |
| 548 | * this requirement. |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 549 | */ |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 550 | int val, seconds, remain, result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 551 | struct timespec ts, utc; |
| 552 | utc = CURRENT_TIME; |
| 553 | ts = cnvrtDosUnixTm(le16_to_cpu(rsp->SrvTime.Date), |
| 554 | le16_to_cpu(rsp->SrvTime.Time)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 555 | cFYI(1, ("SrvTime %d sec since 1970 (utc: %d) diff: %d", |
| 556 | (int)ts.tv_sec, (int)utc.tv_sec, |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 557 | (int)(utc.tv_sec - ts.tv_sec))); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 558 | val = (int)(utc.tv_sec - ts.tv_sec); |
Andre Haupt | 8594c15 | 2007-08-30 20:18:41 +0000 | [diff] [blame] | 559 | seconds = abs(val); |
Steve French | 947a506 | 2006-10-02 05:55:25 +0000 | [diff] [blame] | 560 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 561 | remain = seconds % MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 562 | if (remain >= (MIN_TZ_ADJ / 2)) |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 563 | result += MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 564 | if (val < 0) |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 565 | result = -result; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 566 | server->timeAdj = result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 567 | } else { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 568 | server->timeAdj = (int)tmp; |
| 569 | server->timeAdj *= 60; /* also in seconds */ |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 570 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 571 | cFYI(1, ("server->timeAdj: %d seconds", server->timeAdj)); |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 572 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 573 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 574 | /* BB get server time for time conversions and add |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 575 | code to use it and timezone since this is not UTC */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 576 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 577 | if (rsp->EncryptionKeyLength == |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 578 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 579 | memcpy(server->cryptKey, rsp->EncryptionKey, |
| 580 | CIFS_CRYPTO_KEY_SIZE); |
| 581 | } else if (server->secMode & SECMODE_PW_ENCRYPT) { |
| 582 | rc = -EIO; /* need cryptkey unless plain text */ |
| 583 | goto neg_err_exit; |
| 584 | } |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 585 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 586 | cFYI(1, ("LANMAN negotiated")); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 587 | /* we will not end up setting signing flags - as no signing |
| 588 | was in LANMAN and server did not return the flags on */ |
| 589 | goto signing_check; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 590 | #else /* weak security disabled */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 591 | } else if (pSMBr->hdr.WordCount == 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 592 | cERROR(1, ("mount failed, cifs module not built " |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 593 | "with CIFS_WEAK_PW_HASH support")); |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 594 | rc = -EOPNOTSUPP; |
| 595 | #endif /* WEAK_PW_HASH */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 596 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 597 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 598 | /* unknown wct */ |
| 599 | rc = -EOPNOTSUPP; |
| 600 | goto neg_err_exit; |
| 601 | } |
| 602 | /* else wct == 17 NTLM */ |
| 603 | server->secMode = pSMBr->SecurityMode; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 604 | if ((server->secMode & SECMODE_USER) == 0) |
| 605 | cFYI(1, ("share mode security")); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 606 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 607 | if ((server->secMode & SECMODE_PW_ENCRYPT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 608 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 609 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 610 | #endif /* CIFS_WEAK_PW_HASH */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 611 | cERROR(1, ("Server requests plain text password" |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 612 | " but client support disabled")); |
Steve French | 9312f67 | 2006-06-04 22:21:07 +0000 | [diff] [blame] | 613 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 614 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 615 | server->secType = NTLMv2; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 616 | else if (secFlags & CIFSSEC_MAY_NTLM) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 617 | server->secType = NTLM; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 618 | else if (secFlags & CIFSSEC_MAY_NTLMV2) |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 619 | server->secType = NTLMv2; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 620 | else if (secFlags & CIFSSEC_MAY_KRB5) |
| 621 | server->secType = Kerberos; |
| 622 | else if (secFlags & CIFSSEC_MAY_LANMAN) |
| 623 | server->secType = LANMAN; |
| 624 | /* #ifdef CONFIG_CIFS_EXPERIMENTAL |
| 625 | else if (secFlags & CIFSSEC_MAY_PLNTXT) |
| 626 | server->secType = ?? |
| 627 | #endif */ |
| 628 | else { |
| 629 | rc = -EOPNOTSUPP; |
| 630 | cERROR(1, ("Invalid security type")); |
| 631 | goto neg_err_exit; |
| 632 | } |
| 633 | /* else ... any others ...? */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 634 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 635 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 636 | little endian */ |
| 637 | server->maxReq = le16_to_cpu(pSMBr->MaxMpxCount); |
| 638 | /* probably no need to store and check maxvcs */ |
| 639 | server->maxBuf = min(le32_to_cpu(pSMBr->MaxBufferSize), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 641 | server->maxRw = le32_to_cpu(pSMBr->MaxRawSize); |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 642 | cFYI(DBG2, ("Max buf = %d", ses->server->maxBuf)); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 643 | GETU32(ses->server->sessid) = le32_to_cpu(pSMBr->SessionKey); |
| 644 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 645 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 646 | server->timeAdj *= 60; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 647 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
| 648 | memcpy(server->cryptKey, pSMBr->u.EncryptionKey, |
| 649 | CIFS_CRYPTO_KEY_SIZE); |
| 650 | } else if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) |
| 651 | && (pSMBr->EncryptionKeyLength == 0)) { |
| 652 | /* decode security blob */ |
| 653 | } else if (server->secMode & SECMODE_PW_ENCRYPT) { |
| 654 | rc = -EIO; /* no crypt key only if plain text pwd */ |
| 655 | goto neg_err_exit; |
| 656 | } |
| 657 | |
| 658 | /* BB might be helpful to save off the domain of server here */ |
| 659 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 660 | if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) && |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 661 | (server->capabilities & CAP_EXTENDED_SECURITY)) { |
| 662 | count = pSMBr->ByteCount; |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 663 | if (count < 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | rc = -EIO; |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 665 | goto neg_err_exit; |
| 666 | } |
| 667 | |
| 668 | if (server->socketUseCount.counter > 1) { |
| 669 | if (memcmp(server->server_GUID, |
| 670 | pSMBr->u.extended_response. |
| 671 | GUID, 16) != 0) { |
| 672 | cFYI(1, ("server UID changed")); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 673 | memcpy(server->server_GUID, |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 674 | pSMBr->u.extended_response.GUID, |
| 675 | 16); |
| 676 | } |
| 677 | } else |
| 678 | memcpy(server->server_GUID, |
| 679 | pSMBr->u.extended_response.GUID, 16); |
| 680 | |
| 681 | if (count == 16) { |
| 682 | server->secType = RawNTLMSSP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 683 | } else { |
| 684 | rc = decode_negTokenInit(pSMBr->u.extended_response. |
| 685 | SecurityBlob, |
| 686 | count - 16, |
| 687 | &server->secType); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 688 | if (rc == 1) |
Jeff Layton | e545937 | 2007-11-03 05:11:06 +0000 | [diff] [blame] | 689 | rc = 0; |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 690 | else |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 691 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 693 | } else |
| 694 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
| 695 | |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 696 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 697 | signing_check: |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 698 | #endif |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 699 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
| 700 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
| 701 | so if this is zero it means that signing is disabled */ |
| 702 | cFYI(1, ("Signing disabled")); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 703 | if (server->secMode & SECMODE_SIGN_REQUIRED) { |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 704 | cERROR(1, ("Server requires " |
Jeff Layton | 7111d21 | 2007-10-16 16:50:25 +0000 | [diff] [blame] | 705 | "packet signing to be enabled in " |
| 706 | "/proc/fs/cifs/SecurityFlags.")); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 707 | rc = -EOPNOTSUPP; |
| 708 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 709 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 710 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 711 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
| 712 | /* signing required */ |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 713 | cFYI(1, ("Must sign - secFlags 0x%x", secFlags)); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 714 | if ((server->secMode & |
| 715 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
| 716 | cERROR(1, |
| 717 | ("signing required but server lacks support")); |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 718 | rc = -EOPNOTSUPP; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 719 | } else |
| 720 | server->secMode |= SECMODE_SIGN_REQUIRED; |
| 721 | } else { |
| 722 | /* signing optional ie CIFSSEC_MAY_SIGN */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 723 | if ((server->secMode & SECMODE_SIGN_REQUIRED) == 0) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 724 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 725 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 727 | |
| 728 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 729 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 730 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 731 | cFYI(1, ("negprot rc %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | return rc; |
| 733 | } |
| 734 | |
| 735 | int |
| 736 | CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) |
| 737 | { |
| 738 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | cFYI(1, ("In tree disconnect")); |
| 742 | /* |
| 743 | * If last user of the connection and |
| 744 | * connection alive - disconnect it |
| 745 | * If this is the last connection on the server session disconnect it |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 746 | * (and inside session disconnect we should check if tcp socket needs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | * to be freed and kernel thread woken up). |
| 748 | */ |
| 749 | if (tcon) |
| 750 | down(&tcon->tconSem); |
| 751 | else |
| 752 | return -EIO; |
| 753 | |
| 754 | atomic_dec(&tcon->useCount); |
| 755 | if (atomic_read(&tcon->useCount) > 0) { |
| 756 | up(&tcon->tconSem); |
| 757 | return -EBUSY; |
| 758 | } |
| 759 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 760 | /* No need to return error on this operation if tid invalidated and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | closed on server already e.g. due to tcp session crashing */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 762 | if (tcon->tidStatus == CifsNeedReconnect) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | up(&tcon->tconSem); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 764 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 767 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | up(&tcon->tconSem); |
| 769 | return -EIO; |
| 770 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 771 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 772 | (void **)&smb_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | if (rc) { |
| 774 | up(&tcon->tconSem); |
| 775 | return rc; |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 776 | } |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 777 | |
| 778 | rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | if (rc) |
Steve French | 966ca92 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 780 | cFYI(1, ("Tree disconnect failed %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | up(&tcon->tconSem); |
| 783 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 784 | /* No need to return error on this operation if tid invalidated and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | closed on server already e.g. due to tcp session crashing */ |
| 786 | if (rc == -EAGAIN) |
| 787 | rc = 0; |
| 788 | |
| 789 | return rc; |
| 790 | } |
| 791 | |
| 792 | int |
| 793 | CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) |
| 794 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | LOGOFF_ANDX_REQ *pSMB; |
| 796 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
| 798 | cFYI(1, ("In SMBLogoff for session disconnect")); |
| 799 | if (ses) |
| 800 | down(&ses->sesSem); |
| 801 | else |
| 802 | return -EIO; |
| 803 | |
| 804 | atomic_dec(&ses->inUse); |
| 805 | if (atomic_read(&ses->inUse) > 0) { |
| 806 | up(&ses->sesSem); |
| 807 | return -EBUSY; |
| 808 | } |
| 809 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 810 | if (rc) { |
| 811 | up(&ses->sesSem); |
| 812 | return rc; |
| 813 | } |
| 814 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 815 | if (ses->server) { |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 816 | pSMB->hdr.Mid = GetNextMid(ses->server); |
| 817 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 818 | if (ses->server->secMode & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 820 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 821 | } |
| 822 | |
| 823 | pSMB->hdr.Uid = ses->Suid; |
| 824 | |
| 825 | pSMB->AndXCommand = 0xFF; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 826 | rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | if (ses->server) { |
| 828 | atomic_dec(&ses->server->socketUseCount); |
| 829 | if (atomic_read(&ses->server->socketUseCount) == 0) { |
| 830 | spin_lock(&GlobalMid_Lock); |
| 831 | ses->server->tcpStatus = CifsExiting; |
| 832 | spin_unlock(&GlobalMid_Lock); |
| 833 | rc = -ESHUTDOWN; |
| 834 | } |
| 835 | } |
Steve French | a59c658 | 2005-08-17 12:12:19 -0700 | [diff] [blame] | 836 | up(&ses->sesSem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 839 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | error */ |
| 841 | if (rc == -EAGAIN) |
| 842 | rc = 0; |
| 843 | return rc; |
| 844 | } |
| 845 | |
| 846 | int |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 847 | CIFSPOSIXDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 848 | __u16 type, const struct nls_table *nls_codepage, int remap) |
| 849 | { |
| 850 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 851 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 852 | struct unlink_psx_rq *pRqD; |
| 853 | int name_len; |
| 854 | int rc = 0; |
| 855 | int bytes_returned = 0; |
| 856 | __u16 params, param_offset, offset, byte_count; |
| 857 | |
| 858 | cFYI(1, ("In POSIX delete")); |
| 859 | PsxDelete: |
| 860 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 861 | (void **) &pSMBr); |
| 862 | if (rc) |
| 863 | return rc; |
| 864 | |
| 865 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 866 | name_len = |
| 867 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
| 868 | PATH_MAX, nls_codepage, remap); |
| 869 | name_len++; /* trailing null */ |
| 870 | name_len *= 2; |
| 871 | } else { /* BB add path length overrun check */ |
| 872 | name_len = strnlen(fileName, PATH_MAX); |
| 873 | name_len++; /* trailing null */ |
| 874 | strncpy(pSMB->FileName, fileName, name_len); |
| 875 | } |
| 876 | |
| 877 | params = 6 + name_len; |
| 878 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 879 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 880 | pSMB->MaxSetupCount = 0; |
| 881 | pSMB->Reserved = 0; |
| 882 | pSMB->Flags = 0; |
| 883 | pSMB->Timeout = 0; |
| 884 | pSMB->Reserved2 = 0; |
| 885 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 886 | InformationLevel) - 4; |
| 887 | offset = param_offset + params; |
| 888 | |
| 889 | /* Setup pointer to Request Data (inode type) */ |
| 890 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 891 | pRqD->type = cpu_to_le16(type); |
| 892 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 893 | pSMB->DataOffset = cpu_to_le16(offset); |
| 894 | pSMB->SetupCount = 1; |
| 895 | pSMB->Reserved3 = 0; |
| 896 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 897 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 898 | |
| 899 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 900 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 901 | pSMB->ParameterCount = cpu_to_le16(params); |
| 902 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 903 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 904 | pSMB->Reserved4 = 0; |
| 905 | pSMB->hdr.smb_buf_length += byte_count; |
| 906 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 907 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 908 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 909 | if (rc) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 910 | cFYI(1, ("Posix delete returned %d", rc)); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 911 | cifs_buf_release(pSMB); |
| 912 | |
| 913 | cifs_stats_inc(&tcon->num_deletes); |
| 914 | |
| 915 | if (rc == -EAGAIN) |
| 916 | goto PsxDelete; |
| 917 | |
| 918 | return rc; |
| 919 | } |
| 920 | |
| 921 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 922 | CIFSSMBDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 923 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | { |
| 925 | DELETE_FILE_REQ *pSMB = NULL; |
| 926 | DELETE_FILE_RSP *pSMBr = NULL; |
| 927 | int rc = 0; |
| 928 | int bytes_returned; |
| 929 | int name_len; |
| 930 | |
| 931 | DelFileRetry: |
| 932 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 933 | (void **) &pSMBr); |
| 934 | if (rc) |
| 935 | return rc; |
| 936 | |
| 937 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 938 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 939 | cifsConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 940 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | name_len++; /* trailing null */ |
| 942 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 943 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | name_len = strnlen(fileName, PATH_MAX); |
| 945 | name_len++; /* trailing null */ |
| 946 | strncpy(pSMB->fileName, fileName, name_len); |
| 947 | } |
| 948 | pSMB->SearchAttributes = |
| 949 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 950 | pSMB->BufferFormat = 0x04; |
| 951 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 952 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 953 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 954 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 955 | cifs_stats_inc(&tcon->num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 956 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | cFYI(1, ("Error in RMFile = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
| 959 | cifs_buf_release(pSMB); |
| 960 | if (rc == -EAGAIN) |
| 961 | goto DelFileRetry; |
| 962 | |
| 963 | return rc; |
| 964 | } |
| 965 | |
| 966 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 967 | CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 968 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | { |
| 970 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 971 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 972 | int rc = 0; |
| 973 | int bytes_returned; |
| 974 | int name_len; |
| 975 | |
| 976 | cFYI(1, ("In CIFSSMBRmDir")); |
| 977 | RmDirRetry: |
| 978 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 979 | (void **) &pSMBr); |
| 980 | if (rc) |
| 981 | return rc; |
| 982 | |
| 983 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 984 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, dirName, |
| 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(dirName, PATH_MAX); |
| 990 | name_len++; /* trailing null */ |
| 991 | strncpy(pSMB->DirName, dirName, name_len); |
| 992 | } |
| 993 | |
| 994 | pSMB->BufferFormat = 0x04; |
| 995 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 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_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1000 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | cFYI(1, ("Error in RMDir = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
| 1003 | cifs_buf_release(pSMB); |
| 1004 | if (rc == -EAGAIN) |
| 1005 | goto RmDirRetry; |
| 1006 | return rc; |
| 1007 | } |
| 1008 | |
| 1009 | int |
| 1010 | CIFSSMBMkDir(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1011 | const char *name, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | { |
| 1013 | int rc = 0; |
| 1014 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 1015 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 1016 | int bytes_returned; |
| 1017 | int name_len; |
| 1018 | |
| 1019 | cFYI(1, ("In CIFSSMBMkDir")); |
| 1020 | MkDirRetry: |
| 1021 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 1022 | (void **) &pSMBr); |
| 1023 | if (rc) |
| 1024 | return rc; |
| 1025 | |
| 1026 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1027 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1028 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | name_len++; /* trailing null */ |
| 1030 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1031 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | name_len = strnlen(name, PATH_MAX); |
| 1033 | name_len++; /* trailing null */ |
| 1034 | strncpy(pSMB->DirName, name, name_len); |
| 1035 | } |
| 1036 | |
| 1037 | pSMB->BufferFormat = 0x04; |
| 1038 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 1039 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1040 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1041 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1042 | cifs_stats_inc(&tcon->num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1043 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | cFYI(1, ("Error in Mkdir = %d", rc)); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | cifs_buf_release(pSMB); |
| 1047 | if (rc == -EAGAIN) |
| 1048 | goto MkDirRetry; |
| 1049 | return rc; |
| 1050 | } |
| 1051 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1052 | int |
| 1053 | CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1054 | __u64 mode, __u16 *netfid, FILE_UNIX_BASIC_INFO *pRetData, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1055 | __u32 *pOplock, const char *name, |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1056 | const struct nls_table *nls_codepage, int remap) |
| 1057 | { |
| 1058 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1059 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1060 | int name_len; |
| 1061 | int rc = 0; |
| 1062 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1063 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1064 | OPEN_PSX_REQ *pdata; |
| 1065 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1066 | |
| 1067 | cFYI(1, ("In POSIX Create")); |
| 1068 | PsxCreat: |
| 1069 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1070 | (void **) &pSMBr); |
| 1071 | if (rc) |
| 1072 | return rc; |
| 1073 | |
| 1074 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1075 | name_len = |
| 1076 | cifsConvertToUCS((__le16 *) pSMB->FileName, name, |
| 1077 | PATH_MAX, nls_codepage, remap); |
| 1078 | name_len++; /* trailing null */ |
| 1079 | name_len *= 2; |
| 1080 | } else { /* BB improve the check for buffer overruns BB */ |
| 1081 | name_len = strnlen(name, PATH_MAX); |
| 1082 | name_len++; /* trailing null */ |
| 1083 | strncpy(pSMB->FileName, name, name_len); |
| 1084 | } |
| 1085 | |
| 1086 | params = 6 + name_len; |
| 1087 | count = sizeof(OPEN_PSX_REQ); |
| 1088 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1089 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1090 | pSMB->MaxSetupCount = 0; |
| 1091 | pSMB->Reserved = 0; |
| 1092 | pSMB->Flags = 0; |
| 1093 | pSMB->Timeout = 0; |
| 1094 | pSMB->Reserved2 = 0; |
| 1095 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1096 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1097 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1098 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1099 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1100 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1101 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1102 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1103 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1104 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1105 | pSMB->SetupCount = 1; |
| 1106 | pSMB->Reserved3 = 0; |
| 1107 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1108 | byte_count = 3 /* pad */ + params + count; |
| 1109 | |
| 1110 | pSMB->DataCount = cpu_to_le16(count); |
| 1111 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1112 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1113 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1114 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1115 | pSMB->Reserved4 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1116 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1117 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1118 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1119 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1120 | if (rc) { |
| 1121 | cFYI(1, ("Posix create returned %d", rc)); |
| 1122 | goto psx_create_err; |
| 1123 | } |
| 1124 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1125 | cFYI(1, ("copying inode info")); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1126 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1127 | |
| 1128 | if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) { |
| 1129 | rc = -EIO; /* bad smb */ |
| 1130 | goto psx_create_err; |
| 1131 | } |
| 1132 | |
| 1133 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1134 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1135 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1136 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1137 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1138 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1139 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1140 | /* Let caller know file was created so we can set the mode. */ |
| 1141 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1142 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1143 | *pOplock |= CIFS_CREATE_ACTION; |
| 1144 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1145 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1146 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 1147 | cFYI(DBG2, ("unknown type")); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1148 | } else { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1149 | if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1150 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1151 | cERROR(1, ("Open response data too small")); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1152 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1153 | goto psx_create_err; |
| 1154 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1155 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1156 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1157 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1158 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1159 | |
| 1160 | psx_create_err: |
| 1161 | cifs_buf_release(pSMB); |
| 1162 | |
| 1163 | cifs_stats_inc(&tcon->num_mkdirs); |
| 1164 | |
| 1165 | if (rc == -EAGAIN) |
| 1166 | goto PsxCreat; |
| 1167 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1168 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1171 | static __u16 convert_disposition(int disposition) |
| 1172 | { |
| 1173 | __u16 ofun = 0; |
| 1174 | |
| 1175 | switch (disposition) { |
| 1176 | case FILE_SUPERSEDE: |
| 1177 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1178 | break; |
| 1179 | case FILE_OPEN: |
| 1180 | ofun = SMBOPEN_OAPPEND; |
| 1181 | break; |
| 1182 | case FILE_CREATE: |
| 1183 | ofun = SMBOPEN_OCREATE; |
| 1184 | break; |
| 1185 | case FILE_OPEN_IF: |
| 1186 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1187 | break; |
| 1188 | case FILE_OVERWRITE: |
| 1189 | ofun = SMBOPEN_OTRUNC; |
| 1190 | break; |
| 1191 | case FILE_OVERWRITE_IF: |
| 1192 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1193 | break; |
| 1194 | default: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1195 | cFYI(1, ("unknown disposition %d", disposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1196 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1197 | } |
| 1198 | return ofun; |
| 1199 | } |
| 1200 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1201 | static int |
| 1202 | access_flags_to_smbopen_mode(const int access_flags) |
| 1203 | { |
| 1204 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1205 | |
| 1206 | if (masked_flags == GENERIC_READ) |
| 1207 | return SMBOPEN_READ; |
| 1208 | else if (masked_flags == GENERIC_WRITE) |
| 1209 | return SMBOPEN_WRITE; |
| 1210 | |
| 1211 | /* just go for read/write */ |
| 1212 | return SMBOPEN_READWRITE; |
| 1213 | } |
| 1214 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1215 | int |
| 1216 | SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, |
| 1217 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1218 | const int access_flags, const int create_options, __u16 *netfid, |
| 1219 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1220 | const struct nls_table *nls_codepage, int remap) |
| 1221 | { |
| 1222 | int rc = -EACCES; |
| 1223 | OPENX_REQ *pSMB = NULL; |
| 1224 | OPENX_RSP *pSMBr = NULL; |
| 1225 | int bytes_returned; |
| 1226 | int name_len; |
| 1227 | __u16 count; |
| 1228 | |
| 1229 | OldOpenRetry: |
| 1230 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1231 | (void **) &pSMBr); |
| 1232 | if (rc) |
| 1233 | return rc; |
| 1234 | |
| 1235 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1236 | |
| 1237 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1238 | count = 1; /* account for one byte pad to word boundary */ |
| 1239 | name_len = |
| 1240 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
| 1241 | fileName, PATH_MAX, nls_codepage, remap); |
| 1242 | name_len++; /* trailing null */ |
| 1243 | name_len *= 2; |
| 1244 | } else { /* BB improve check for buffer overruns BB */ |
| 1245 | count = 0; /* no pad */ |
| 1246 | name_len = strnlen(fileName, PATH_MAX); |
| 1247 | name_len++; /* trailing null */ |
| 1248 | strncpy(pSMB->fileName, fileName, name_len); |
| 1249 | } |
| 1250 | if (*pOplock & REQ_OPLOCK) |
| 1251 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1252 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1253 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1254 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1255 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1256 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1257 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1258 | /* set file as system file if special file such |
| 1259 | as fifo and server expecting SFU style and |
| 1260 | no Unix extensions */ |
| 1261 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1262 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1263 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1264 | else /* BB FIXME BB */ |
| 1265 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1266 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1267 | if (create_options & CREATE_OPTION_READONLY) |
| 1268 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1269 | |
| 1270 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1271 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1272 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1273 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1274 | |
| 1275 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1276 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1277 | count += name_len; |
| 1278 | pSMB->hdr.smb_buf_length += count; |
| 1279 | |
| 1280 | pSMB->ByteCount = cpu_to_le16(count); |
| 1281 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1282 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1283 | (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1284 | cifs_stats_inc(&tcon->num_opens); |
| 1285 | if (rc) { |
| 1286 | cFYI(1, ("Error in Open = %d", rc)); |
| 1287 | } else { |
| 1288 | /* BB verify if wct == 15 */ |
| 1289 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1290 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1291 | |
| 1292 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1293 | /* Let caller know file was created so we can set the mode. */ |
| 1294 | /* Do we care about the CreateAction in any other cases? */ |
| 1295 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1296 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1297 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1298 | /* BB FIXME END */ |
| 1299 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1300 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1301 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1302 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1303 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1304 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1305 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1306 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1307 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1308 | pfile_info->AllocationSize = |
| 1309 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1310 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1311 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1312 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | cifs_buf_release(pSMB); |
| 1317 | if (rc == -EAGAIN) |
| 1318 | goto OldOpenRetry; |
| 1319 | return rc; |
| 1320 | } |
| 1321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | int |
| 1323 | CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon, |
| 1324 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1325 | const int access_flags, const int create_options, __u16 *netfid, |
| 1326 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1327 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | { |
| 1329 | int rc = -EACCES; |
| 1330 | OPEN_REQ *pSMB = NULL; |
| 1331 | OPEN_RSP *pSMBr = NULL; |
| 1332 | int bytes_returned; |
| 1333 | int name_len; |
| 1334 | __u16 count; |
| 1335 | |
| 1336 | openRetry: |
| 1337 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, |
| 1338 | (void **) &pSMBr); |
| 1339 | if (rc) |
| 1340 | return rc; |
| 1341 | |
| 1342 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1343 | |
| 1344 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1345 | count = 1; /* account for one byte pad to word boundary */ |
| 1346 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 1347 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1348 | fileName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | name_len++; /* trailing null */ |
| 1350 | name_len *= 2; |
| 1351 | pSMB->NameLength = cpu_to_le16(name_len); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1352 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | count = 0; /* no pad */ |
| 1354 | name_len = strnlen(fileName, PATH_MAX); |
| 1355 | name_len++; /* trailing null */ |
| 1356 | pSMB->NameLength = cpu_to_le16(name_len); |
| 1357 | strncpy(pSMB->fileName, fileName, name_len); |
| 1358 | } |
| 1359 | if (*pOplock & REQ_OPLOCK) |
| 1360 | pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1361 | else if (*pOplock & REQ_BATCHOPLOCK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | pSMB->DesiredAccess = cpu_to_le32(access_flags); |
| 1364 | pSMB->AllocationSize = 0; |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1365 | /* set file as system file if special file such |
| 1366 | as fifo and server expecting SFU style and |
| 1367 | no Unix extensions */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1368 | if (create_options & CREATE_OPTION_SPECIAL) |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1369 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1370 | else |
| 1371 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | /* XP does not handle ATTR_POSIX_SEMANTICS */ |
| 1374 | /* but it helps speed up case sensitive checks for other |
| 1375 | servers such as Samba */ |
| 1376 | if (tcon->ses->capabilities & CAP_UNIX) |
| 1377 | pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
| 1378 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1379 | if (create_options & CREATE_OPTION_READONLY) |
| 1380 | pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
| 1381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1383 | pSMB->CreateDisposition = cpu_to_le32(openDisposition); |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1384 | pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1385 | /* BB Expirement with various impersonation levels and verify */ |
| 1386 | pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | pSMB->SecurityFlags = |
| 1388 | SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY; |
| 1389 | |
| 1390 | count += name_len; |
| 1391 | pSMB->hdr.smb_buf_length += count; |
| 1392 | |
| 1393 | pSMB->ByteCount = cpu_to_le16(count); |
| 1394 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1395 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1396 | (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1397 | cifs_stats_inc(&tcon->num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | if (rc) { |
| 1399 | cFYI(1, ("Error in Open = %d", rc)); |
| 1400 | } else { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1401 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1403 | /* Let caller know file was created so we can set the mode. */ |
| 1404 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1405 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1406 | *pOplock |= CIFS_CREATE_ACTION; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1407 | if (pfile_info) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1408 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | 36 /* CreationTime to Attributes */); |
| 1410 | /* the file_info buf is endian converted by caller */ |
| 1411 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
| 1412 | pfile_info->EndOfFile = pSMBr->EndOfFile; |
| 1413 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1414 | pfile_info->DeletePending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | cifs_buf_release(pSMB); |
| 1419 | if (rc == -EAGAIN) |
| 1420 | goto openRetry; |
| 1421 | return rc; |
| 1422 | } |
| 1423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1425 | CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, |
| 1426 | const unsigned int count, const __u64 lseek, unsigned int *nbytes, |
| 1427 | char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | { |
| 1429 | int rc = -EACCES; |
| 1430 | READ_REQ *pSMB = NULL; |
| 1431 | READ_RSP *pSMBr = NULL; |
| 1432 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1433 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1434 | int resp_buf_type = 0; |
| 1435 | struct kvec iov[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1437 | cFYI(1, ("Reading %d bytes on fid %d", count, netfid)); |
| 1438 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1439 | wct = 12; |
| 1440 | else |
| 1441 | wct = 10; /* old style read */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
| 1443 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1444 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | if (rc) |
| 1446 | return rc; |
| 1447 | |
| 1448 | /* tcon and ses pointer are checked in smb_init */ |
| 1449 | if (tcon->ses->server == NULL) |
| 1450 | return -ECONNABORTED; |
| 1451 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1452 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | pSMB->Fid = netfid; |
| 1454 | pSMB->OffsetLow = cpu_to_le32(lseek & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1455 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1456 | pSMB->OffsetHigh = cpu_to_le32(lseek >> 32); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1457 | else if ((lseek >> 32) > 0) /* can not handle this big offset for old */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1458 | return -EIO; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | pSMB->Remaining = 0; |
| 1461 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1462 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1463 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1464 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1465 | else { |
| 1466 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1467 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1468 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1469 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1470 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1471 | |
| 1472 | iov[0].iov_base = (char *)pSMB; |
| 1473 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 1474 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1475 | &resp_buf_type, CIFS_STD_OP | CIFS_LOG_ERROR); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1476 | cifs_stats_inc(&tcon->num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1477 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | if (rc) { |
| 1479 | cERROR(1, ("Send error in read = %d", rc)); |
| 1480 | } else { |
| 1481 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1482 | data_length = data_length << 16; |
| 1483 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1484 | *nbytes = data_length; |
| 1485 | |
| 1486 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1487 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | || (data_length > count)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1489 | cFYI(1, ("bad length %d for count %d", |
| 1490 | data_length, count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | rc = -EIO; |
| 1492 | *nbytes = 0; |
| 1493 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1494 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1495 | le16_to_cpu(pSMBr->DataOffset); |
| 1496 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1497 | cERROR(1,("Faulting on read rc = %d",rc)); |
| 1498 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1499 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1500 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1501 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | } |
| 1503 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1505 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1506 | if (*buf) { |
| 1507 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1508 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1509 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1510 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1511 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1512 | /* return buffer to caller to free */ |
| 1513 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1514 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1515 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1516 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1517 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1518 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1519 | |
| 1520 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | since file handle passed in no longer valid */ |
| 1522 | return rc; |
| 1523 | } |
| 1524 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | int |
| 1527 | CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, |
| 1528 | const int netfid, const unsigned int count, |
| 1529 | const __u64 offset, unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1530 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | { |
| 1532 | int rc = -EACCES; |
| 1533 | WRITE_REQ *pSMB = NULL; |
| 1534 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1535 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | __u32 bytes_sent; |
| 1537 | __u16 byte_count; |
| 1538 | |
| 1539 | /* cFYI(1,("write at %lld %d bytes",offset,count));*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1540 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1541 | return -ECONNABORTED; |
| 1542 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1543 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1544 | wct = 14; |
| 1545 | else |
| 1546 | wct = 12; |
| 1547 | |
| 1548 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | (void **) &pSMBr); |
| 1550 | if (rc) |
| 1551 | return rc; |
| 1552 | /* tcon and ses pointer are checked in smb_init */ |
| 1553 | if (tcon->ses->server == NULL) |
| 1554 | return -ECONNABORTED; |
| 1555 | |
| 1556 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1557 | pSMB->Fid = netfid; |
| 1558 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1559 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1560 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1561 | else if ((offset >> 32) > 0) /* can not handle big offset for old srv */ |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1562 | return -EIO; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | pSMB->Reserved = 0xFFFFFFFF; |
| 1565 | pSMB->WriteMode = 0; |
| 1566 | pSMB->Remaining = 0; |
| 1567 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1568 | /* 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] | 1569 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1570 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1571 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1572 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1574 | } else { |
| 1575 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1576 | & ~0xFF; |
| 1577 | } |
| 1578 | |
| 1579 | if (bytes_sent > count) |
| 1580 | bytes_sent = count; |
| 1581 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1582 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1583 | if (buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1584 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1585 | else if (ubuf) { |
| 1586 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | cifs_buf_release(pSMB); |
| 1588 | return -EFAULT; |
| 1589 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1590 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | /* No buffer */ |
| 1592 | cifs_buf_release(pSMB); |
| 1593 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1594 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1595 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1596 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1597 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1598 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1601 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1602 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1603 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1604 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1605 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1606 | else { /* old style write has byte count 4 bytes earlier |
| 1607 | so 4 bytes pad */ |
| 1608 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1609 | (struct smb_com_writex_req *)pSMB; |
| 1610 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1611 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | |
| 1613 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1614 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1615 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | if (rc) { |
| 1617 | cFYI(1, ("Send error in write = %d", rc)); |
| 1618 | *nbytes = 0; |
| 1619 | } else { |
| 1620 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1621 | *nbytes = (*nbytes) << 16; |
| 1622 | *nbytes += le16_to_cpu(pSMBr->Count); |
| 1623 | } |
| 1624 | |
| 1625 | cifs_buf_release(pSMB); |
| 1626 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1627 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | since file handle passed in no longer valid */ |
| 1629 | |
| 1630 | return rc; |
| 1631 | } |
| 1632 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1633 | int |
| 1634 | CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | const int netfid, const unsigned int count, |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1636 | const __u64 offset, unsigned int *nbytes, struct kvec *iov, |
| 1637 | int n_vec, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | { |
| 1639 | int rc = -EACCES; |
| 1640 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1641 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1642 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1643 | int resp_buf_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1645 | cFYI(1, ("write2 at %lld %d bytes", (long long)offset, count)); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 1646 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1647 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1648 | wct = 14; |
| 1649 | else |
| 1650 | wct = 12; |
| 1651 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | if (rc) |
| 1653 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | /* tcon and ses pointer are checked in smb_init */ |
| 1655 | if (tcon->ses->server == NULL) |
| 1656 | return -ECONNABORTED; |
| 1657 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1658 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | pSMB->Fid = netfid; |
| 1660 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1661 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1662 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1663 | else if ((offset >> 32) > 0) /* can not handle big offset for old srv */ |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1664 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | pSMB->Reserved = 0xFFFFFFFF; |
| 1666 | pSMB->WriteMode = 0; |
| 1667 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1670 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1672 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 1673 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1674 | smb_hdr_len = pSMB->hdr.smb_buf_length + 1; /* hdr + 1 byte pad */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1675 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1676 | pSMB->hdr.smb_buf_length += count+1; |
| 1677 | else /* wct == 12 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1678 | pSMB->hdr.smb_buf_length += count+5; /* smb data starts later */ |
| 1679 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1680 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 1681 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1682 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1683 | (struct smb_com_writex_req *)pSMB; |
| 1684 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 1685 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1686 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1687 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1688 | iov[0].iov_len = smb_hdr_len + 4; |
| 1689 | else /* wct == 12 pad bigger by four bytes */ |
| 1690 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1691 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1692 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1693 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1694 | long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1695 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | if (rc) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1697 | cFYI(1, ("Send error Write2 = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | *nbytes = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1699 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1700 | /* presumably this can not happen, but best to be safe */ |
| 1701 | rc = -EIO; |
| 1702 | *nbytes = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1703 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1704 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1705 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1706 | *nbytes = (*nbytes) << 16; |
| 1707 | *nbytes += le16_to_cpu(pSMBr->Count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1708 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1710 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1711 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1712 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1713 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1714 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1716 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | since file handle passed in no longer valid */ |
| 1718 | |
| 1719 | return rc; |
| 1720 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1721 | |
| 1722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | int |
| 1724 | CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, |
| 1725 | const __u16 smb_file_id, const __u64 len, |
| 1726 | const __u64 offset, const __u32 numUnlock, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1727 | const __u32 numLock, const __u8 lockType, const bool waitFlag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | { |
| 1729 | int rc = 0; |
| 1730 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 1731 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | int bytes_returned; |
| 1733 | int timeout = 0; |
| 1734 | __u16 count; |
| 1735 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1736 | cFYI(1, ("CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock)); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 1737 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 1738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | if (rc) |
| 1740 | return rc; |
| 1741 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1742 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1743 | timeout = CIFS_ASYNC_OP; /* no response expected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1745 | } else if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1746 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 1748 | } else { |
| 1749 | pSMB->Timeout = 0; |
| 1750 | } |
| 1751 | |
| 1752 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 1753 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 1754 | pSMB->LockType = lockType; |
| 1755 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1756 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 1757 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1758 | if ((numLock != 0) || (numUnlock != 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | pSMB->Locks[0].Pid = cpu_to_le16(current->tgid); |
| 1760 | /* BB where to store pid high? */ |
| 1761 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 1762 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 1763 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 1764 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 1765 | count = sizeof(LOCKING_ANDX_RANGE); |
| 1766 | } else { |
| 1767 | /* oplock break */ |
| 1768 | count = 0; |
| 1769 | } |
| 1770 | pSMB->hdr.smb_buf_length += count; |
| 1771 | pSMB->ByteCount = cpu_to_le16(count); |
| 1772 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1773 | if (waitFlag) { |
| 1774 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 1775 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1776 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1777 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1778 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *)pSMB, |
| 1779 | timeout); |
| 1780 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1781 | } |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1782 | cifs_stats_inc(&tcon->num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1783 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | cFYI(1, ("Send error in Lock = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1786 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | since file handle passed in no longer valid */ |
| 1788 | return rc; |
| 1789 | } |
| 1790 | |
| 1791 | int |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1792 | CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, |
| 1793 | const __u16 smb_file_id, const int get_flag, const __u64 len, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1794 | struct file_lock *pLockData, const __u16 lock_type, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1795 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1796 | { |
| 1797 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 1798 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1799 | struct cifs_posix_lock *parm_data; |
| 1800 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 1801 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1802 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1803 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1804 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1805 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1806 | |
| 1807 | cFYI(1, ("Posix Lock")); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1808 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1809 | if (pLockData == NULL) |
Marcin Slusarz | ed5f037 | 2008-05-13 04:01:01 +0000 | [diff] [blame] | 1810 | return -EINVAL; |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1811 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1812 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 1813 | |
| 1814 | if (rc) |
| 1815 | return rc; |
| 1816 | |
| 1817 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 1818 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1819 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1820 | pSMB->MaxSetupCount = 0; |
| 1821 | pSMB->Reserved = 0; |
| 1822 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1823 | pSMB->Reserved2 = 0; |
| 1824 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 1825 | offset = param_offset + params; |
| 1826 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1827 | count = sizeof(struct cifs_posix_lock); |
| 1828 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1829 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1830 | pSMB->SetupCount = 1; |
| 1831 | pSMB->Reserved3 = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1832 | if (get_flag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1833 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 1834 | else |
| 1835 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 1836 | byte_count = 3 /* pad */ + params + count; |
| 1837 | pSMB->DataCount = cpu_to_le16(count); |
| 1838 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1839 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1840 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1841 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1842 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1843 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 1844 | |
| 1845 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1846 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1847 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 1848 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 1849 | pSMB->Timeout = cpu_to_le32(-1); |
| 1850 | } else |
| 1851 | pSMB->Timeout = 0; |
| 1852 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1853 | parm_data->pid = cpu_to_le32(current->tgid); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1854 | parm_data->start = cpu_to_le64(pLockData->fl_start); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 1855 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1856 | |
| 1857 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 1858 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1859 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 1860 | pSMB->Reserved4 = 0; |
| 1861 | pSMB->hdr.smb_buf_length += byte_count; |
| 1862 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1863 | if (waitFlag) { |
| 1864 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 1865 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 1866 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1867 | iov[0].iov_base = (char *)pSMB; |
| 1868 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
| 1869 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 1870 | &resp_buf_type, timeout); |
| 1871 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 1872 | not try to free it twice below on exit */ |
| 1873 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1876 | if (rc) { |
| 1877 | cFYI(1, ("Send error in Posix Lock = %d", rc)); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1878 | } else if (get_flag) { |
| 1879 | /* lock structure can be returned on get */ |
| 1880 | __u16 data_offset; |
| 1881 | __u16 data_count; |
| 1882 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1883 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1884 | if (rc || (pSMBr->ByteCount < sizeof(struct cifs_posix_lock))) { |
| 1885 | rc = -EIO; /* bad smb */ |
| 1886 | goto plk_err_exit; |
| 1887 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1888 | if (pLockData == NULL) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1889 | rc = -EINVAL; |
| 1890 | goto plk_err_exit; |
| 1891 | } |
| 1892 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 1893 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1894 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1895 | rc = -EIO; |
| 1896 | goto plk_err_exit; |
| 1897 | } |
| 1898 | parm_data = (struct cifs_posix_lock *) |
| 1899 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1900 | if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1901 | pLockData->fl_type = F_UNLCK; |
| 1902 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1903 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1904 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1905 | if (pSMB) |
| 1906 | cifs_small_buf_release(pSMB); |
| 1907 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1908 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 1909 | cifs_small_buf_release(iov[0].iov_base); |
| 1910 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 1911 | cifs_buf_release(iov[0].iov_base); |
| 1912 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1913 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 1914 | since file handle passed in no longer valid */ |
| 1915 | |
| 1916 | return rc; |
| 1917 | } |
| 1918 | |
| 1919 | |
| 1920 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) |
| 1922 | { |
| 1923 | int rc = 0; |
| 1924 | CLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | cFYI(1, ("In CIFSSMBClose")); |
| 1926 | |
| 1927 | /* do not retry on dead session on close */ |
| 1928 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1929 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | return 0; |
| 1931 | if (rc) |
| 1932 | return rc; |
| 1933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 1935 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1937 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1938 | cifs_stats_inc(&tcon->num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1940 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | /* EINTR is expected when user ctl-c to kill app */ |
| 1942 | cERROR(1, ("Send error in Close = %d", rc)); |
| 1943 | } |
| 1944 | } |
| 1945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1947 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | rc = 0; |
| 1949 | |
| 1950 | return rc; |
| 1951 | } |
| 1952 | |
| 1953 | int |
| 1954 | CIFSSMBRename(const int xid, struct cifsTconInfo *tcon, |
| 1955 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1956 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | { |
| 1958 | int rc = 0; |
| 1959 | RENAME_REQ *pSMB = NULL; |
| 1960 | RENAME_RSP *pSMBr = NULL; |
| 1961 | int bytes_returned; |
| 1962 | int name_len, name_len2; |
| 1963 | __u16 count; |
| 1964 | |
| 1965 | cFYI(1, ("In CIFSSMBRename")); |
| 1966 | renameRetry: |
| 1967 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 1968 | (void **) &pSMBr); |
| 1969 | if (rc) |
| 1970 | return rc; |
| 1971 | |
| 1972 | pSMB->BufferFormat = 0x04; |
| 1973 | pSMB->SearchAttributes = |
| 1974 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 1975 | ATTR_DIRECTORY); |
| 1976 | |
| 1977 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1978 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1979 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1980 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | name_len++; /* trailing null */ |
| 1982 | name_len *= 2; |
| 1983 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 1984 | /* protocol requires ASCII signature byte on Unicode string */ |
| 1985 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 1986 | name_len2 = |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1987 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1988 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 1990 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1991 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | name_len = strnlen(fromName, PATH_MAX); |
| 1993 | name_len++; /* trailing null */ |
| 1994 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 1995 | name_len2 = strnlen(toName, PATH_MAX); |
| 1996 | name_len2++; /* trailing null */ |
| 1997 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 1998 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 1999 | name_len2++; /* trailing null */ |
| 2000 | name_len2++; /* signature byte */ |
| 2001 | } |
| 2002 | |
| 2003 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
| 2004 | pSMB->hdr.smb_buf_length += count; |
| 2005 | pSMB->ByteCount = cpu_to_le16(count); |
| 2006 | |
| 2007 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2008 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2009 | cifs_stats_inc(&tcon->num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2010 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | cFYI(1, ("Send error in rename = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | cifs_buf_release(pSMB); |
| 2014 | |
| 2015 | if (rc == -EAGAIN) |
| 2016 | goto renameRetry; |
| 2017 | |
| 2018 | return rc; |
| 2019 | } |
| 2020 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2021 | int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2022 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2023 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | { |
| 2025 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2026 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2027 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | char *data_offset; |
| 2029 | char dummy_string[30]; |
| 2030 | int rc = 0; |
| 2031 | int bytes_returned = 0; |
| 2032 | int len_of_str; |
| 2033 | __u16 params, param_offset, offset, count, byte_count; |
| 2034 | |
| 2035 | cFYI(1, ("Rename to File by handle")); |
| 2036 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2037 | (void **) &pSMBr); |
| 2038 | if (rc) |
| 2039 | return rc; |
| 2040 | |
| 2041 | params = 6; |
| 2042 | pSMB->MaxSetupCount = 0; |
| 2043 | pSMB->Reserved = 0; |
| 2044 | pSMB->Flags = 0; |
| 2045 | pSMB->Timeout = 0; |
| 2046 | pSMB->Reserved2 = 0; |
| 2047 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2048 | offset = param_offset + params; |
| 2049 | |
| 2050 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2051 | rename_info = (struct set_file_rename *) data_offset; |
| 2052 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2053 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | pSMB->SetupCount = 1; |
| 2055 | pSMB->Reserved3 = 0; |
| 2056 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2057 | byte_count = 3 /* pad */ + params; |
| 2058 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2059 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2060 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2061 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2062 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2063 | rename_info->overwrite = cpu_to_le32(1); |
| 2064 | rename_info->root_fid = 0; |
| 2065 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2066 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2067 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
| 2068 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2069 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | } else { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2071 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2072 | target_name, PATH_MAX, nls_codepage, |
| 2073 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | } |
| 2075 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2076 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | byte_count += count; |
| 2078 | pSMB->DataCount = cpu_to_le16(count); |
| 2079 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2080 | pSMB->Fid = netfid; |
| 2081 | pSMB->InformationLevel = |
| 2082 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2083 | pSMB->Reserved4 = 0; |
| 2084 | pSMB->hdr.smb_buf_length += byte_count; |
| 2085 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2086 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2087 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2088 | cifs_stats_inc(&pTcon->num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2089 | if (rc) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2090 | cFYI(1, ("Send error in Rename (by file handle) = %d", rc)); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | cifs_buf_release(pSMB); |
| 2093 | |
| 2094 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2095 | since file handle passed in no longer valid */ |
| 2096 | |
| 2097 | return rc; |
| 2098 | } |
| 2099 | |
| 2100 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2101 | CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char *fromName, |
| 2102 | const __u16 target_tid, const char *toName, const int flags, |
| 2103 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | { |
| 2105 | int rc = 0; |
| 2106 | COPY_REQ *pSMB = NULL; |
| 2107 | COPY_RSP *pSMBr = NULL; |
| 2108 | int bytes_returned; |
| 2109 | int name_len, name_len2; |
| 2110 | __u16 count; |
| 2111 | |
| 2112 | cFYI(1, ("In CIFSSMBCopy")); |
| 2113 | copyRetry: |
| 2114 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2115 | (void **) &pSMBr); |
| 2116 | if (rc) |
| 2117 | return rc; |
| 2118 | |
| 2119 | pSMB->BufferFormat = 0x04; |
| 2120 | pSMB->Tid2 = target_tid; |
| 2121 | |
| 2122 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2123 | |
| 2124 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2125 | name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2126 | fromName, PATH_MAX, nls_codepage, |
| 2127 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | name_len++; /* trailing null */ |
| 2129 | name_len *= 2; |
| 2130 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2131 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2132 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2133 | name_len2 = |
| 2134 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2135 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2137 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2138 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | name_len = strnlen(fromName, PATH_MAX); |
| 2140 | name_len++; /* trailing null */ |
| 2141 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2142 | name_len2 = strnlen(toName, PATH_MAX); |
| 2143 | name_len2++; /* trailing null */ |
| 2144 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2145 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2146 | name_len2++; /* trailing null */ |
| 2147 | name_len2++; /* signature byte */ |
| 2148 | } |
| 2149 | |
| 2150 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
| 2151 | pSMB->hdr.smb_buf_length += count; |
| 2152 | pSMB->ByteCount = cpu_to_le16(count); |
| 2153 | |
| 2154 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2155 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2156 | if (rc) { |
| 2157 | cFYI(1, ("Send error in copy = %d with %d files copied", |
| 2158 | rc, le16_to_cpu(pSMBr->CopyCount))); |
| 2159 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2160 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
| 2162 | if (rc == -EAGAIN) |
| 2163 | goto copyRetry; |
| 2164 | |
| 2165 | return rc; |
| 2166 | } |
| 2167 | |
| 2168 | int |
| 2169 | CIFSUnixCreateSymLink(const int xid, struct cifsTconInfo *tcon, |
| 2170 | const char *fromName, const char *toName, |
| 2171 | const struct nls_table *nls_codepage) |
| 2172 | { |
| 2173 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2174 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2175 | char *data_offset; |
| 2176 | int name_len; |
| 2177 | int name_len_target; |
| 2178 | int rc = 0; |
| 2179 | int bytes_returned = 0; |
| 2180 | __u16 params, param_offset, offset, byte_count; |
| 2181 | |
| 2182 | cFYI(1, ("In Symlink Unix style")); |
| 2183 | createSymLinkRetry: |
| 2184 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2185 | (void **) &pSMBr); |
| 2186 | if (rc) |
| 2187 | return rc; |
| 2188 | |
| 2189 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2190 | name_len = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2191 | cifs_strtoUCS((__le16 *) pSMB->FileName, fromName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | /* find define for this maxpathcomponent */ |
| 2193 | , nls_codepage); |
| 2194 | name_len++; /* trailing null */ |
| 2195 | name_len *= 2; |
| 2196 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2197 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | name_len = strnlen(fromName, PATH_MAX); |
| 2199 | name_len++; /* trailing null */ |
| 2200 | strncpy(pSMB->FileName, fromName, name_len); |
| 2201 | } |
| 2202 | params = 6 + name_len; |
| 2203 | pSMB->MaxSetupCount = 0; |
| 2204 | pSMB->Reserved = 0; |
| 2205 | pSMB->Flags = 0; |
| 2206 | pSMB->Timeout = 0; |
| 2207 | pSMB->Reserved2 = 0; |
| 2208 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2209 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | offset = param_offset + params; |
| 2211 | |
| 2212 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2213 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2214 | name_len_target = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2215 | cifs_strtoUCS((__le16 *) data_offset, toName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | /* find define for this maxpathcomponent */ |
| 2217 | , nls_codepage); |
| 2218 | name_len_target++; /* trailing null */ |
| 2219 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2220 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | name_len_target = strnlen(toName, PATH_MAX); |
| 2222 | name_len_target++; /* trailing null */ |
| 2223 | strncpy(data_offset, toName, name_len_target); |
| 2224 | } |
| 2225 | |
| 2226 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2227 | /* BB find exact max on data count below from sess */ |
| 2228 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2229 | pSMB->SetupCount = 1; |
| 2230 | pSMB->Reserved3 = 0; |
| 2231 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2232 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2233 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2234 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2235 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2236 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2237 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2238 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2239 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2240 | pSMB->Reserved4 = 0; |
| 2241 | pSMB->hdr.smb_buf_length += byte_count; |
| 2242 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2243 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2244 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2245 | cifs_stats_inc(&tcon->num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2246 | if (rc) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 2247 | cFYI(1, ("Send error in SetPathInfo create symlink = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2249 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | |
| 2251 | if (rc == -EAGAIN) |
| 2252 | goto createSymLinkRetry; |
| 2253 | |
| 2254 | return rc; |
| 2255 | } |
| 2256 | |
| 2257 | int |
| 2258 | CIFSUnixCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2259 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2260 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | { |
| 2262 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2263 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2264 | char *data_offset; |
| 2265 | int name_len; |
| 2266 | int name_len_target; |
| 2267 | int rc = 0; |
| 2268 | int bytes_returned = 0; |
| 2269 | __u16 params, param_offset, offset, byte_count; |
| 2270 | |
| 2271 | cFYI(1, ("In Create Hard link Unix style")); |
| 2272 | createHardLinkRetry: |
| 2273 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2274 | (void **) &pSMBr); |
| 2275 | if (rc) |
| 2276 | return rc; |
| 2277 | |
| 2278 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2279 | name_len = cifsConvertToUCS((__le16 *) pSMB->FileName, toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2280 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | name_len++; /* trailing null */ |
| 2282 | name_len *= 2; |
| 2283 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2284 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | name_len = strnlen(toName, PATH_MAX); |
| 2286 | name_len++; /* trailing null */ |
| 2287 | strncpy(pSMB->FileName, toName, name_len); |
| 2288 | } |
| 2289 | params = 6 + name_len; |
| 2290 | pSMB->MaxSetupCount = 0; |
| 2291 | pSMB->Reserved = 0; |
| 2292 | pSMB->Flags = 0; |
| 2293 | pSMB->Timeout = 0; |
| 2294 | pSMB->Reserved2 = 0; |
| 2295 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2296 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | offset = param_offset + params; |
| 2298 | |
| 2299 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2300 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2301 | name_len_target = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2302 | cifsConvertToUCS((__le16 *) data_offset, fromName, PATH_MAX, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2303 | nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | name_len_target++; /* trailing null */ |
| 2305 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2306 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2308 | name_len_target++; /* trailing null */ |
| 2309 | strncpy(data_offset, fromName, name_len_target); |
| 2310 | } |
| 2311 | |
| 2312 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2313 | /* BB find exact max on data count below from sess*/ |
| 2314 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2315 | pSMB->SetupCount = 1; |
| 2316 | pSMB->Reserved3 = 0; |
| 2317 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2318 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2319 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2320 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2321 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2322 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2323 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2324 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2325 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2326 | pSMB->Reserved4 = 0; |
| 2327 | pSMB->hdr.smb_buf_length += byte_count; |
| 2328 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2329 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2330 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2331 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2332 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | cFYI(1, ("Send error in SetPathInfo (hard link) = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | |
| 2335 | cifs_buf_release(pSMB); |
| 2336 | if (rc == -EAGAIN) |
| 2337 | goto createHardLinkRetry; |
| 2338 | |
| 2339 | return rc; |
| 2340 | } |
| 2341 | |
| 2342 | int |
| 2343 | CIFSCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2344 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2345 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | { |
| 2347 | int rc = 0; |
| 2348 | NT_RENAME_REQ *pSMB = NULL; |
| 2349 | RENAME_RSP *pSMBr = NULL; |
| 2350 | int bytes_returned; |
| 2351 | int name_len, name_len2; |
| 2352 | __u16 count; |
| 2353 | |
| 2354 | cFYI(1, ("In CIFSCreateHardLink")); |
| 2355 | winCreateHardLinkRetry: |
| 2356 | |
| 2357 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2358 | (void **) &pSMBr); |
| 2359 | if (rc) |
| 2360 | return rc; |
| 2361 | |
| 2362 | pSMB->SearchAttributes = |
| 2363 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2364 | ATTR_DIRECTORY); |
| 2365 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 2366 | pSMB->ClusterCount = 0; |
| 2367 | |
| 2368 | pSMB->BufferFormat = 0x04; |
| 2369 | |
| 2370 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2371 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2372 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2373 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | name_len++; /* trailing null */ |
| 2375 | name_len *= 2; |
| 2376 | pSMB->OldFileName[name_len] = 0; /* pad */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2377 | pSMB->OldFileName[name_len + 1] = 0x04; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | name_len2 = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2379 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2380 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2382 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2383 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | name_len = strnlen(fromName, PATH_MAX); |
| 2385 | name_len++; /* trailing null */ |
| 2386 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2387 | name_len2 = strnlen(toName, PATH_MAX); |
| 2388 | name_len2++; /* trailing null */ |
| 2389 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2390 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2391 | name_len2++; /* trailing null */ |
| 2392 | name_len2++; /* signature byte */ |
| 2393 | } |
| 2394 | |
| 2395 | count = 1 /* string type byte */ + name_len + name_len2; |
| 2396 | pSMB->hdr.smb_buf_length += count; |
| 2397 | pSMB->ByteCount = cpu_to_le16(count); |
| 2398 | |
| 2399 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2400 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2401 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2402 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | cFYI(1, ("Send error in hard link (NT rename) = %d", rc)); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | cifs_buf_release(pSMB); |
| 2406 | if (rc == -EAGAIN) |
| 2407 | goto winCreateHardLinkRetry; |
| 2408 | |
| 2409 | return rc; |
| 2410 | } |
| 2411 | |
| 2412 | int |
| 2413 | CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon, |
| 2414 | const unsigned char *searchName, |
| 2415 | char *symlinkinfo, const int buflen, |
| 2416 | const struct nls_table *nls_codepage) |
| 2417 | { |
| 2418 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 2419 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2420 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2421 | int rc = 0; |
| 2422 | int bytes_returned; |
| 2423 | int name_len; |
| 2424 | __u16 params, byte_count; |
| 2425 | |
| 2426 | cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName)); |
| 2427 | |
| 2428 | querySymLinkRetry: |
| 2429 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2430 | (void **) &pSMBr); |
| 2431 | if (rc) |
| 2432 | return rc; |
| 2433 | |
| 2434 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2435 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2436 | cifs_strtoUCS((__le16 *) pSMB->FileName, searchName, |
| 2437 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | name_len++; /* trailing null */ |
| 2439 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2440 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | name_len = strnlen(searchName, PATH_MAX); |
| 2442 | name_len++; /* trailing null */ |
| 2443 | strncpy(pSMB->FileName, searchName, name_len); |
| 2444 | } |
| 2445 | |
| 2446 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 2447 | pSMB->TotalDataCount = 0; |
| 2448 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2449 | /* BB find exact max data count below from sess structure BB */ |
| 2450 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 2451 | pSMB->MaxSetupCount = 0; |
| 2452 | pSMB->Reserved = 0; |
| 2453 | pSMB->Flags = 0; |
| 2454 | pSMB->Timeout = 0; |
| 2455 | pSMB->Reserved2 = 0; |
| 2456 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2457 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | pSMB->DataCount = 0; |
| 2459 | pSMB->DataOffset = 0; |
| 2460 | pSMB->SetupCount = 1; |
| 2461 | pSMB->Reserved3 = 0; |
| 2462 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 2463 | byte_count = params + 1 /* pad */ ; |
| 2464 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 2465 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2466 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 2467 | pSMB->Reserved4 = 0; |
| 2468 | pSMB->hdr.smb_buf_length += byte_count; |
| 2469 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2470 | |
| 2471 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2472 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2473 | if (rc) { |
| 2474 | cFYI(1, ("Send error in QuerySymLinkInfo = %d", rc)); |
| 2475 | } else { |
| 2476 | /* decode response */ |
| 2477 | |
| 2478 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 2479 | if (rc || (pSMBr->ByteCount < 2)) |
| 2480 | /* BB also check enough total bytes returned */ |
| 2481 | rc = -EIO; /* bad smb */ |
| 2482 | else { |
| 2483 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2484 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 2485 | |
| 2486 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2487 | name_len = UniStrnlen((wchar_t *) ((char *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2488 | &pSMBr->hdr.Protocol + data_offset), |
| 2489 | min_t(const int, buflen, count) / 2); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2490 | /* BB FIXME investigate remapping reserved chars here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | cifs_strfromUCS_le(symlinkinfo, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2492 | (__le16 *) ((char *)&pSMBr->hdr.Protocol |
| 2493 | + data_offset), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | name_len, nls_codepage); |
| 2495 | } else { |
| 2496 | strncpy(symlinkinfo, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2497 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | data_offset, |
| 2499 | min_t(const int, buflen, count)); |
| 2500 | } |
| 2501 | symlinkinfo[buflen] = 0; |
| 2502 | /* just in case so calling code does not go off the end of buffer */ |
| 2503 | } |
| 2504 | } |
| 2505 | cifs_buf_release(pSMB); |
| 2506 | if (rc == -EAGAIN) |
| 2507 | goto querySymLinkRetry; |
| 2508 | return rc; |
| 2509 | } |
| 2510 | |
Parag Warudkar | c948977 | 2007-10-23 18:09:48 +0000 | [diff] [blame] | 2511 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2512 | /* Initialize NT TRANSACT SMB into small smb request buffer. |
| 2513 | This assumes that all NT TRANSACTS that we init here have |
| 2514 | total parm and data under about 400 bytes (to fit in small cifs |
| 2515 | buffer size), which is the case so far, it easily fits. NB: |
| 2516 | Setup words themselves and ByteCount |
| 2517 | MaxSetupCount (size of returned setup area) and |
| 2518 | MaxParameterCount (returned parms size) must be set by caller */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2519 | static int |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 2520 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2521 | const int parm_len, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2522 | void **ret_buf) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2523 | { |
| 2524 | int rc; |
| 2525 | __u32 temp_offset; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2526 | struct smb_com_ntransact_req *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2527 | |
| 2528 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 2529 | (void **)&pSMB); |
| 2530 | if (rc) |
| 2531 | return rc; |
| 2532 | *ret_buf = (void *)pSMB; |
| 2533 | pSMB->Reserved = 0; |
| 2534 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 2535 | pSMB->TotalDataCount = 0; |
| 2536 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 2537 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 2538 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2539 | pSMB->DataCount = pSMB->TotalDataCount; |
| 2540 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 2541 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 2542 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 2543 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 2544 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 2545 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 2546 | return 0; |
| 2547 | } |
| 2548 | |
| 2549 | static int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2550 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 2551 | __u32 *pparmlen, __u32 *pdatalen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2552 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2553 | char *end_of_smb; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2554 | __u32 data_count, data_offset, parm_count, parm_offset; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2555 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2556 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 2557 | *pdatalen = 0; |
| 2558 | *pparmlen = 0; |
| 2559 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2560 | if (buf == NULL) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2561 | return -EINVAL; |
| 2562 | |
| 2563 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 2564 | |
| 2565 | /* ByteCount was converted from little endian in SendReceive */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2566 | end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount + |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2567 | (char *)&pSMBr->ByteCount; |
| 2568 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2569 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 2570 | data_count = le32_to_cpu(pSMBr->DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2571 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2572 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 2573 | |
| 2574 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 2575 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 2576 | |
| 2577 | /* should we also check that parm and data areas do not overlap? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2578 | if (*ppparm > end_of_smb) { |
| 2579 | cFYI(1, ("parms start after end of smb")); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2580 | return -EINVAL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2581 | } else if (parm_count + *ppparm > end_of_smb) { |
| 2582 | cFYI(1, ("parm end after end of smb")); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2583 | return -EINVAL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2584 | } else if (*ppdata > end_of_smb) { |
| 2585 | cFYI(1, ("data starts after end of smb")); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2586 | return -EINVAL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2587 | } else if (data_count + *ppdata > end_of_smb) { |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 2588 | cFYI(1, ("data %p + count %d (%p) ends after end of smb %p start %p", |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2589 | *ppdata, data_count, (data_count + *ppdata), |
| 2590 | end_of_smb, pSMBr)); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2591 | return -EINVAL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2592 | } else if (parm_count + data_count > pSMBr->ByteCount) { |
| 2593 | cFYI(1, ("parm count and data count larger than SMB")); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2594 | return -EINVAL; |
| 2595 | } |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 2596 | *pdatalen = data_count; |
| 2597 | *pparmlen = parm_count; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2598 | return 0; |
| 2599 | } |
Parag Warudkar | c948977 | 2007-10-23 18:09:48 +0000 | [diff] [blame] | 2600 | #endif /* CIFS_EXPERIMENTAL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | int |
| 2603 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, |
| 2604 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2605 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | const struct nls_table *nls_codepage) |
| 2607 | { |
| 2608 | int rc = 0; |
| 2609 | int bytes_returned; |
| 2610 | int name_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2611 | struct smb_com_transaction_ioctl_req *pSMB; |
| 2612 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | |
| 2614 | cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName)); |
| 2615 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 2616 | (void **) &pSMBr); |
| 2617 | if (rc) |
| 2618 | return rc; |
| 2619 | |
| 2620 | pSMB->TotalParameterCount = 0 ; |
| 2621 | pSMB->TotalDataCount = 0; |
| 2622 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 2623 | /* BB find exact data count max from sess structure BB */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2624 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 2625 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | pSMB->MaxSetupCount = 4; |
| 2627 | pSMB->Reserved = 0; |
| 2628 | pSMB->ParameterOffset = 0; |
| 2629 | pSMB->DataCount = 0; |
| 2630 | pSMB->DataOffset = 0; |
| 2631 | pSMB->SetupCount = 4; |
| 2632 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 2633 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2634 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 2635 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 2636 | pSMB->IsRootFlag = 0; |
| 2637 | pSMB->Fid = fid; /* file handle always le */ |
| 2638 | pSMB->ByteCount = 0; |
| 2639 | |
| 2640 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2641 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2642 | if (rc) { |
| 2643 | cFYI(1, ("Send error in QueryReparseLinkInfo = %d", rc)); |
| 2644 | } else { /* decode response */ |
| 2645 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 2646 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
| 2647 | if ((pSMBr->ByteCount < 2) || (data_offset > 512)) |
| 2648 | /* BB also check enough total bytes returned */ |
| 2649 | rc = -EIO; /* bad smb */ |
| 2650 | else { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2651 | if (data_count && (data_count < 2048)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2652 | char *end_of_smb = 2 /* sizeof byte count */ + |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2653 | pSMBr->ByteCount + |
| 2654 | (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2656 | struct reparse_data *reparse_buf = |
| 2657 | (struct reparse_data *) |
| 2658 | ((char *)&pSMBr->hdr.Protocol |
| 2659 | + data_offset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2660 | if ((char *)reparse_buf >= end_of_smb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | rc = -EIO; |
| 2662 | goto qreparse_out; |
| 2663 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2664 | if ((reparse_buf->LinkNamesBuf + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | reparse_buf->TargetNameOffset + |
| 2666 | reparse_buf->TargetNameLen) > |
| 2667 | end_of_smb) { |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 2668 | cFYI(1, ("reparse buf beyond SMB")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | rc = -EIO; |
| 2670 | goto qreparse_out; |
| 2671 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2674 | name_len = UniStrnlen((wchar_t *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2675 | (reparse_buf->LinkNamesBuf + |
| 2676 | reparse_buf->TargetNameOffset), |
| 2677 | min(buflen/2, |
| 2678 | reparse_buf->TargetNameLen / 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | cifs_strfromUCS_le(symlinkinfo, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2680 | (__le16 *) (reparse_buf->LinkNamesBuf + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | reparse_buf->TargetNameOffset), |
| 2682 | name_len, nls_codepage); |
| 2683 | } else { /* ASCII names */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2684 | strncpy(symlinkinfo, |
| 2685 | reparse_buf->LinkNamesBuf + |
| 2686 | reparse_buf->TargetNameOffset, |
| 2687 | min_t(const int, buflen, |
| 2688 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | } |
| 2690 | } else { |
| 2691 | rc = -EIO; |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 2692 | cFYI(1, ("Invalid return data count on " |
| 2693 | "get reparse info ioctl")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | } |
| 2695 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 2696 | does not go off the end of the buffer */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2697 | cFYI(1, ("readlink result - %s", symlinkinfo)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | } |
| 2699 | } |
| 2700 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 2701 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | |
| 2703 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2704 | since file handle passed in no longer valid */ |
| 2705 | |
| 2706 | return rc; |
| 2707 | } |
| 2708 | |
| 2709 | #ifdef CONFIG_CIFS_POSIX |
| 2710 | |
| 2711 | /*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] | 2712 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 2713 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | { |
| 2715 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2716 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 2717 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 2718 | ace->e_id = cpu_to_le32(le64_to_cpu(cifs_ace->cifs_uid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | /* cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id)); */ |
| 2720 | |
| 2721 | return; |
| 2722 | } |
| 2723 | |
| 2724 | /* 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] | 2725 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 2726 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | { |
| 2728 | int size = 0; |
| 2729 | int i; |
| 2730 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2731 | struct cifs_posix_ace *pACE; |
| 2732 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 2733 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | |
| 2735 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 2736 | return -EOPNOTSUPP; |
| 2737 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2738 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2740 | pACE = &cifs_acl->ace_array[0]; |
| 2741 | size = sizeof(struct cifs_posix_acl); |
| 2742 | size += sizeof(struct cifs_posix_ace) * count; |
| 2743 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2744 | if (size_of_data_area < size) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2745 | cFYI(1, ("bad CIFS POSIX ACL size %d vs. %d", |
| 2746 | size_of_data_area, size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | return -EINVAL; |
| 2748 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2749 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2751 | size = sizeof(struct cifs_posix_acl); |
| 2752 | size += sizeof(struct cifs_posix_ace) * count; |
| 2753 | /* skip past access ACEs to get to default ACEs */ |
| 2754 | pACE = &cifs_acl->ace_array[count]; |
| 2755 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 2756 | size += sizeof(struct cifs_posix_ace) * count; |
| 2757 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2758 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | return -EINVAL; |
| 2760 | } else { |
| 2761 | /* illegal type */ |
| 2762 | return -EINVAL; |
| 2763 | } |
| 2764 | |
| 2765 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2766 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2767 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2768 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | return -ERANGE; |
| 2770 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2771 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2772 | for (i = 0; i < count ; i++) { |
| 2773 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 2774 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | } |
| 2776 | } |
| 2777 | return size; |
| 2778 | } |
| 2779 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2780 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 2781 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | { |
| 2783 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 2784 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2785 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 2786 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2788 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 2790 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2791 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2792 | cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2793 | /*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] | 2794 | return rc; |
| 2795 | } |
| 2796 | |
| 2797 | /* 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] | 2798 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 2799 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | { |
| 2801 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2802 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 2803 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | int count; |
| 2805 | int i; |
| 2806 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2807 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | return 0; |
| 2809 | |
| 2810 | count = posix_acl_xattr_count((size_t)buflen); |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 2811 | 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] | 2812 | "version of %d", |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2813 | count, buflen, le32_to_cpu(local_acl->a_version))); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2814 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2815 | cFYI(1, ("unknown POSIX ACL version %d", |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2816 | le32_to_cpu(local_acl->a_version))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | return 0; |
| 2818 | } |
| 2819 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2820 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2821 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2822 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2823 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2825 | cFYI(1, ("unknown ACL type %d", acl_type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | return 0; |
| 2827 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2828 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 2830 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2831 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | /* ACE not converted */ |
| 2833 | break; |
| 2834 | } |
| 2835 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2836 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 2838 | rc += sizeof(struct cifs_posix_acl); |
| 2839 | /* BB add check to make sure ACL does not overflow SMB */ |
| 2840 | } |
| 2841 | return rc; |
| 2842 | } |
| 2843 | |
| 2844 | int |
| 2845 | CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2846 | const unsigned char *searchName, |
| 2847 | char *acl_inf, const int buflen, const int acl_type, |
| 2848 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | { |
| 2850 | /* SMB_QUERY_POSIX_ACL */ |
| 2851 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2852 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2853 | int rc = 0; |
| 2854 | int bytes_returned; |
| 2855 | int name_len; |
| 2856 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName)); |
| 2859 | |
| 2860 | queryAclRetry: |
| 2861 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2862 | (void **) &pSMBr); |
| 2863 | if (rc) |
| 2864 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2867 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2868 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2869 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | name_len++; /* trailing null */ |
| 2871 | name_len *= 2; |
| 2872 | pSMB->FileName[name_len] = 0; |
| 2873 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2874 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | name_len = strnlen(searchName, PATH_MAX); |
| 2876 | name_len++; /* trailing null */ |
| 2877 | strncpy(pSMB->FileName, searchName, name_len); |
| 2878 | } |
| 2879 | |
| 2880 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 2881 | pSMB->TotalDataCount = 0; |
| 2882 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2883 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 2885 | pSMB->MaxSetupCount = 0; |
| 2886 | pSMB->Reserved = 0; |
| 2887 | pSMB->Flags = 0; |
| 2888 | pSMB->Timeout = 0; |
| 2889 | pSMB->Reserved2 = 0; |
| 2890 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2891 | offsetof(struct smb_com_transaction2_qpi_req, |
| 2892 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | pSMB->DataCount = 0; |
| 2894 | pSMB->DataOffset = 0; |
| 2895 | pSMB->SetupCount = 1; |
| 2896 | pSMB->Reserved3 = 0; |
| 2897 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 2898 | byte_count = params + 1 /* pad */ ; |
| 2899 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 2900 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2901 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 2902 | pSMB->Reserved4 = 0; |
| 2903 | pSMB->hdr.smb_buf_length += byte_count; |
| 2904 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2905 | |
| 2906 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2907 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2908 | cifs_stats_inc(&tcon->num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | if (rc) { |
| 2910 | cFYI(1, ("Send error in Query POSIX ACL = %d", rc)); |
| 2911 | } else { |
| 2912 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 2915 | if (rc || (pSMBr->ByteCount < 2)) |
| 2916 | /* BB also check enough total bytes returned */ |
| 2917 | rc = -EIO; /* bad smb */ |
| 2918 | else { |
| 2919 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2920 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 2921 | rc = cifs_copy_posix_acl(acl_inf, |
| 2922 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2923 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | } |
| 2925 | } |
| 2926 | cifs_buf_release(pSMB); |
| 2927 | if (rc == -EAGAIN) |
| 2928 | goto queryAclRetry; |
| 2929 | return rc; |
| 2930 | } |
| 2931 | |
| 2932 | int |
| 2933 | CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2934 | const unsigned char *fileName, |
| 2935 | const char *local_acl, const int buflen, |
| 2936 | const int acl_type, |
| 2937 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | { |
| 2939 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 2940 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 2941 | char *parm_data; |
| 2942 | int name_len; |
| 2943 | int rc = 0; |
| 2944 | int bytes_returned = 0; |
| 2945 | __u16 params, byte_count, data_count, param_offset, offset; |
| 2946 | |
| 2947 | cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName)); |
| 2948 | setAclRetry: |
| 2949 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2950 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | if (rc) |
| 2952 | return rc; |
| 2953 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2954 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2955 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2956 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | name_len++; /* trailing null */ |
| 2958 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2959 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | name_len = strnlen(fileName, PATH_MAX); |
| 2961 | name_len++; /* trailing null */ |
| 2962 | strncpy(pSMB->FileName, fileName, name_len); |
| 2963 | } |
| 2964 | params = 6 + name_len; |
| 2965 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 2966 | /* BB find max SMB size from sess */ |
| 2967 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | pSMB->MaxSetupCount = 0; |
| 2969 | pSMB->Reserved = 0; |
| 2970 | pSMB->Flags = 0; |
| 2971 | pSMB->Timeout = 0; |
| 2972 | pSMB->Reserved2 = 0; |
| 2973 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2974 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | offset = param_offset + params; |
| 2976 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 2977 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2978 | |
| 2979 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2980 | 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] | 2981 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2982 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | rc = -EOPNOTSUPP; |
| 2984 | goto setACLerrorExit; |
| 2985 | } |
| 2986 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2987 | pSMB->SetupCount = 1; |
| 2988 | pSMB->Reserved3 = 0; |
| 2989 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2990 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 2991 | byte_count = 3 /* pad */ + params + data_count; |
| 2992 | pSMB->DataCount = cpu_to_le16(data_count); |
| 2993 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2994 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2995 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2996 | pSMB->Reserved4 = 0; |
| 2997 | pSMB->hdr.smb_buf_length += byte_count; |
| 2998 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2999 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3000 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3001 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | cFYI(1, ("Set POSIX ACL returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | |
| 3004 | setACLerrorExit: |
| 3005 | cifs_buf_release(pSMB); |
| 3006 | if (rc == -EAGAIN) |
| 3007 | goto setAclRetry; |
| 3008 | return rc; |
| 3009 | } |
| 3010 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3011 | /* BB fix tabs in this function FIXME BB */ |
| 3012 | int |
| 3013 | CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3014 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3015 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3016 | int rc = 0; |
| 3017 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3018 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3019 | int bytes_returned; |
| 3020 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3021 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3022 | cFYI(1, ("In GetExtAttr")); |
| 3023 | if (tcon == NULL) |
| 3024 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3025 | |
| 3026 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3027 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3028 | (void **) &pSMBr); |
| 3029 | if (rc) |
| 3030 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3031 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3032 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3033 | pSMB->t2.TotalDataCount = 0; |
| 3034 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3035 | /* BB find exact max data count below from sess structure BB */ |
| 3036 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3037 | pSMB->t2.MaxSetupCount = 0; |
| 3038 | pSMB->t2.Reserved = 0; |
| 3039 | pSMB->t2.Flags = 0; |
| 3040 | pSMB->t2.Timeout = 0; |
| 3041 | pSMB->t2.Reserved2 = 0; |
| 3042 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3043 | Fid) - 4); |
| 3044 | pSMB->t2.DataCount = 0; |
| 3045 | pSMB->t2.DataOffset = 0; |
| 3046 | pSMB->t2.SetupCount = 1; |
| 3047 | pSMB->t2.Reserved3 = 0; |
| 3048 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3049 | byte_count = params + 1 /* pad */ ; |
| 3050 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3051 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3052 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3053 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3054 | pSMB->Fid = netfid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3055 | pSMB->hdr.smb_buf_length += byte_count; |
| 3056 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3057 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3058 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3059 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3060 | if (rc) { |
| 3061 | cFYI(1, ("error %d in GetExtAttr", rc)); |
| 3062 | } else { |
| 3063 | /* decode response */ |
| 3064 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3065 | if (rc || (pSMBr->ByteCount < 2)) |
| 3066 | /* BB also check enough total bytes returned */ |
| 3067 | /* If rc should we check for EOPNOSUPP and |
| 3068 | disable the srvino flag? or in caller? */ |
| 3069 | rc = -EIO; /* bad smb */ |
| 3070 | else { |
| 3071 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3072 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3073 | struct file_chattr_info *pfinfo; |
| 3074 | /* BB Do we need a cast or hash here ? */ |
| 3075 | if (count != 16) { |
| 3076 | cFYI(1, ("Illegal size ret in GetExtAttr")); |
| 3077 | rc = -EIO; |
| 3078 | goto GetExtAttrOut; |
| 3079 | } |
| 3080 | pfinfo = (struct file_chattr_info *) |
| 3081 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3082 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3083 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3084 | } |
| 3085 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3086 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3087 | cifs_buf_release(pSMB); |
| 3088 | if (rc == -EAGAIN) |
| 3089 | goto GetExtAttrRetry; |
| 3090 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3091 | } |
| 3092 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3093 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 3095 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3096 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3097 | int |
| 3098 | CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3099 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3100 | { |
| 3101 | int rc = 0; |
| 3102 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3103 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3104 | struct kvec iov[1]; |
| 3105 | |
| 3106 | cFYI(1, ("GetCifsACL")); |
| 3107 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3108 | *pbuflen = 0; |
| 3109 | *acl_inf = NULL; |
| 3110 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3111 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3112 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3113 | if (rc) |
| 3114 | return rc; |
| 3115 | |
| 3116 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3117 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3118 | pSMB->MaxSetupCount = 0; |
| 3119 | pSMB->Fid = fid; /* file handle always le */ |
| 3120 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3121 | CIFS_ACL_DACL); |
| 3122 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
| 3123 | pSMB->hdr.smb_buf_length += 11; |
| 3124 | iov[0].iov_base = (char *)pSMB; |
| 3125 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
| 3126 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3127 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 3128 | CIFS_STD_OP); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3129 | cifs_stats_inc(&tcon->num_acl_get); |
| 3130 | if (rc) { |
| 3131 | cFYI(1, ("Send error in QuerySecDesc = %d", rc)); |
| 3132 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3133 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3134 | __u32 parm_len; |
| 3135 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3136 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3137 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3138 | |
| 3139 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3140 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3141 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3142 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3143 | goto qsec_out; |
| 3144 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3145 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3146 | cFYI(1, ("smb %p parm %p data %p", pSMBr, parm, *acl_inf)); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3147 | |
| 3148 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3149 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3150 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3151 | goto qsec_out; |
| 3152 | } |
| 3153 | |
| 3154 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3155 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3156 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3157 | if (acl_len != *pbuflen) { |
| 3158 | cERROR(1, ("acl length %d does not match %d", |
| 3159 | acl_len, *pbuflen)); |
| 3160 | if (*pbuflen > acl_len) |
| 3161 | *pbuflen = acl_len; |
| 3162 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3163 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3164 | /* check if buffer is big enough for the acl |
| 3165 | header followed by the smallest SID */ |
| 3166 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3167 | (*pbuflen >= 64 * 1024)) { |
| 3168 | cERROR(1, ("bad acl length %d", *pbuflen)); |
| 3169 | rc = -EINVAL; |
| 3170 | *pbuflen = 0; |
| 3171 | } else { |
| 3172 | *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); |
| 3173 | if (*acl_inf == NULL) { |
| 3174 | *pbuflen = 0; |
| 3175 | rc = -ENOMEM; |
| 3176 | } |
| 3177 | memcpy(*acl_inf, pdata, *pbuflen); |
| 3178 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3179 | } |
| 3180 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3181 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3182 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3183 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3184 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3185 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3186 | return rc; |
| 3187 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3188 | |
| 3189 | int |
| 3190 | CIFSSMBSetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
| 3191 | struct cifs_ntsd *pntsd, __u32 acllen) |
| 3192 | { |
| 3193 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3194 | int rc = 0; |
| 3195 | int bytes_returned = 0; |
| 3196 | SET_SEC_DESC_REQ *pSMB = NULL; |
| 3197 | NTRANSACT_RSP *pSMBr = NULL; |
| 3198 | |
| 3199 | setCifsAclRetry: |
| 3200 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, |
| 3201 | (void **) &pSMBr); |
| 3202 | if (rc) |
| 3203 | return (rc); |
| 3204 | |
| 3205 | pSMB->MaxSetupCount = 0; |
| 3206 | pSMB->Reserved = 0; |
| 3207 | |
| 3208 | param_count = 8; |
| 3209 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3210 | data_count = acllen; |
| 3211 | data_offset = param_offset + param_count; |
| 3212 | byte_count = 3 /* pad */ + param_count; |
| 3213 | |
| 3214 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3215 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3216 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3217 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3218 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3219 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3220 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3221 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3222 | pSMB->SetupCount = 0; |
| 3223 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3224 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3225 | |
| 3226 | pSMB->Fid = fid; /* file handle always le */ |
| 3227 | pSMB->Reserved2 = 0; |
| 3228 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_DACL); |
| 3229 | |
| 3230 | if (pntsd && acllen) { |
| 3231 | memcpy((char *) &pSMBr->hdr.Protocol + data_offset, |
| 3232 | (char *) pntsd, |
| 3233 | acllen); |
| 3234 | pSMB->hdr.smb_buf_length += (byte_count + data_count); |
| 3235 | |
| 3236 | } else |
| 3237 | pSMB->hdr.smb_buf_length += byte_count; |
| 3238 | |
| 3239 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3240 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3241 | |
| 3242 | cFYI(1, ("SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc)); |
| 3243 | if (rc) |
| 3244 | cFYI(1, ("Set CIFS ACL returned %d", rc)); |
| 3245 | cifs_buf_release(pSMB); |
| 3246 | |
| 3247 | if (rc == -EAGAIN) |
| 3248 | goto setCifsAclRetry; |
| 3249 | |
| 3250 | return (rc); |
| 3251 | } |
| 3252 | |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 3253 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3254 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3255 | /* Legacy Query Path Information call for lookup to old servers such |
| 3256 | as Win9x/WinME */ |
| 3257 | int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3258 | const unsigned char *searchName, |
| 3259 | FILE_ALL_INFO *pFinfo, |
| 3260 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3261 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3262 | QUERY_INFORMATION_REQ *pSMB; |
| 3263 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3264 | int rc = 0; |
| 3265 | int bytes_returned; |
| 3266 | int name_len; |
| 3267 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3268 | cFYI(1, ("In SMBQPath path %s", searchName)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3269 | QInfRetry: |
| 3270 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3271 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3272 | if (rc) |
| 3273 | return rc; |
| 3274 | |
| 3275 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3276 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3277 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
| 3278 | PATH_MAX, nls_codepage, remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3279 | name_len++; /* trailing null */ |
| 3280 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3281 | } else { |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3282 | name_len = strnlen(searchName, PATH_MAX); |
| 3283 | name_len++; /* trailing null */ |
| 3284 | strncpy(pSMB->FileName, searchName, name_len); |
| 3285 | } |
| 3286 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3287 | name_len++; /* account for buffer type byte */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3288 | pSMB->hdr.smb_buf_length += (__u16) name_len; |
| 3289 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3290 | |
| 3291 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3292 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3293 | if (rc) { |
| 3294 | cFYI(1, ("Send error in QueryInfo = %d", rc)); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3295 | } else if (pFinfo) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3296 | struct timespec ts; |
| 3297 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3298 | |
| 3299 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3300 | /* BB FIXME - add time zone adjustment BB */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3301 | memset(pFinfo, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3302 | ts.tv_nsec = 0; |
| 3303 | ts.tv_sec = time; |
| 3304 | /* decode time fields */ |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 3305 | pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3306 | pFinfo->LastWriteTime = pFinfo->ChangeTime; |
| 3307 | pFinfo->LastAccessTime = 0; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3308 | pFinfo->AllocationSize = |
| 3309 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
| 3310 | pFinfo->EndOfFile = pFinfo->AllocationSize; |
| 3311 | pFinfo->Attributes = |
| 3312 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3313 | } else |
| 3314 | rc = -EIO; /* bad buffer passed in */ |
| 3315 | |
| 3316 | cifs_buf_release(pSMB); |
| 3317 | |
| 3318 | if (rc == -EAGAIN) |
| 3319 | goto QInfRetry; |
| 3320 | |
| 3321 | return rc; |
| 3322 | } |
| 3323 | |
| 3324 | |
| 3325 | |
| 3326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | int |
| 3328 | CIFSSMBQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3329 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3330 | FILE_ALL_INFO *pFindData, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3331 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3332 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | { |
| 3334 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
| 3335 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3336 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3337 | int rc = 0; |
| 3338 | int bytes_returned; |
| 3339 | int name_len; |
| 3340 | __u16 params, byte_count; |
| 3341 | |
| 3342 | /* cFYI(1, ("In QPathInfo path %s", searchName)); */ |
| 3343 | QPathInfoRetry: |
| 3344 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3345 | (void **) &pSMBr); |
| 3346 | if (rc) |
| 3347 | return rc; |
| 3348 | |
| 3349 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3350 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3351 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3352 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | name_len++; /* trailing null */ |
| 3354 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3355 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | name_len = strnlen(searchName, PATH_MAX); |
| 3357 | name_len++; /* trailing null */ |
| 3358 | strncpy(pSMB->FileName, searchName, name_len); |
| 3359 | } |
| 3360 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3361 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | pSMB->TotalDataCount = 0; |
| 3363 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3364 | /* BB find exact max SMB PDU from sess structure BB */ |
| 3365 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | pSMB->MaxSetupCount = 0; |
| 3367 | pSMB->Reserved = 0; |
| 3368 | pSMB->Flags = 0; |
| 3369 | pSMB->Timeout = 0; |
| 3370 | pSMB->Reserved2 = 0; |
| 3371 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3372 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | pSMB->DataCount = 0; |
| 3374 | pSMB->DataOffset = 0; |
| 3375 | pSMB->SetupCount = 1; |
| 3376 | pSMB->Reserved3 = 0; |
| 3377 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3378 | byte_count = params + 1 /* pad */ ; |
| 3379 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3380 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3381 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3382 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 3383 | else |
| 3384 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | pSMB->Reserved4 = 0; |
| 3386 | pSMB->hdr.smb_buf_length += byte_count; |
| 3387 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3388 | |
| 3389 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3390 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3391 | if (rc) { |
| 3392 | cFYI(1, ("Send error in QPathInfo = %d", rc)); |
| 3393 | } else { /* decode response */ |
| 3394 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3395 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3396 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3397 | rc = -EIO; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3398 | else if (!legacy && (pSMBr->ByteCount < 40)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | rc = -EIO; /* bad smb */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3400 | else if (legacy && (pSMBr->ByteCount < 24)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3401 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 3402 | last field */ |
| 3403 | else if (pFindData) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3404 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3406 | |
| 3407 | /* On legacy responses we do not read the last field, |
| 3408 | EAsize, fortunately since it varies by subdialect and |
| 3409 | also note it differs on Set vs. Get, ie two bytes or 4 |
| 3410 | bytes depending but we don't care here */ |
| 3411 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3412 | size = sizeof(FILE_INFO_STANDARD); |
| 3413 | else |
| 3414 | size = sizeof(FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | memcpy((char *) pFindData, |
| 3416 | (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3417 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | } else |
| 3419 | rc = -ENOMEM; |
| 3420 | } |
| 3421 | cifs_buf_release(pSMB); |
| 3422 | if (rc == -EAGAIN) |
| 3423 | goto QPathInfoRetry; |
| 3424 | |
| 3425 | return rc; |
| 3426 | } |
| 3427 | |
| 3428 | int |
| 3429 | CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3430 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3431 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3432 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | { |
| 3434 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 3435 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3436 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3437 | int rc = 0; |
| 3438 | int bytes_returned = 0; |
| 3439 | int name_len; |
| 3440 | __u16 params, byte_count; |
| 3441 | |
| 3442 | cFYI(1, ("In QPathInfo (Unix) the path %s", searchName)); |
| 3443 | UnixQPathInfoRetry: |
| 3444 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3445 | (void **) &pSMBr); |
| 3446 | if (rc) |
| 3447 | return rc; |
| 3448 | |
| 3449 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3450 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 3451 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3452 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | name_len++; /* trailing null */ |
| 3454 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3455 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | name_len = strnlen(searchName, PATH_MAX); |
| 3457 | name_len++; /* trailing null */ |
| 3458 | strncpy(pSMB->FileName, searchName, name_len); |
| 3459 | } |
| 3460 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3461 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | pSMB->TotalDataCount = 0; |
| 3463 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3464 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3465 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | pSMB->MaxSetupCount = 0; |
| 3467 | pSMB->Reserved = 0; |
| 3468 | pSMB->Flags = 0; |
| 3469 | pSMB->Timeout = 0; |
| 3470 | pSMB->Reserved2 = 0; |
| 3471 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3472 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | pSMB->DataCount = 0; |
| 3474 | pSMB->DataOffset = 0; |
| 3475 | pSMB->SetupCount = 1; |
| 3476 | pSMB->Reserved3 = 0; |
| 3477 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3478 | byte_count = params + 1 /* pad */ ; |
| 3479 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3480 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3481 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 3482 | pSMB->Reserved4 = 0; |
| 3483 | pSMB->hdr.smb_buf_length += byte_count; |
| 3484 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3485 | |
| 3486 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3487 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3488 | if (rc) { |
| 3489 | cFYI(1, ("Send error in QPathInfo = %d", rc)); |
| 3490 | } else { /* decode response */ |
| 3491 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3492 | |
| 3493 | if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { |
Steve French | 1e71f25 | 2007-09-20 15:30:07 +0000 | [diff] [blame] | 3494 | cERROR(1, ("Malformed FILE_UNIX_BASIC_INFO response.\n" |
| 3495 | "Unix Extensions can be disabled on mount " |
| 3496 | "by specifying the nosfu mount option.")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | rc = -EIO; /* bad smb */ |
| 3498 | } else { |
| 3499 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3500 | memcpy((char *) pFindData, |
| 3501 | (char *) &pSMBr->hdr.Protocol + |
| 3502 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3503 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | } |
| 3505 | } |
| 3506 | cifs_buf_release(pSMB); |
| 3507 | if (rc == -EAGAIN) |
| 3508 | goto UnixQPathInfoRetry; |
| 3509 | |
| 3510 | return rc; |
| 3511 | } |
| 3512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 3514 | int |
| 3515 | CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3516 | const char *searchName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | const struct nls_table *nls_codepage, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3518 | __u16 *pnetfid, |
| 3519 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | { |
| 3521 | /* level 257 SMB_ */ |
| 3522 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 3523 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3524 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | int rc = 0; |
| 3526 | int bytes_returned = 0; |
| 3527 | int name_len; |
| 3528 | __u16 params, byte_count; |
| 3529 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3530 | cFYI(1, ("In FindFirst for %s", searchName)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | |
| 3532 | findFirstRetry: |
| 3533 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3534 | (void **) &pSMBr); |
| 3535 | if (rc) |
| 3536 | return rc; |
| 3537 | |
| 3538 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3539 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3540 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3541 | PATH_MAX, nls_codepage, remap); |
| 3542 | /* We can not add the asterik earlier in case |
| 3543 | it got remapped to 0xF03A as if it were part of the |
| 3544 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | name_len *= 2; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3546 | pSMB->FileName[name_len] = dirsep; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3547 | pSMB->FileName[name_len+1] = 0; |
| 3548 | pSMB->FileName[name_len+2] = '*'; |
| 3549 | pSMB->FileName[name_len+3] = 0; |
| 3550 | name_len += 4; /* now the trailing null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ |
| 3552 | pSMB->FileName[name_len+1] = 0; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3553 | name_len += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | } else { /* BB add check for overrun of SMB buf BB */ |
| 3555 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3557 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | free buffer exit; BB */ |
| 3559 | strncpy(pSMB->FileName, searchName, name_len); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3560 | pSMB->FileName[name_len] = dirsep; |
Steve French | 6857547 | 2005-04-30 11:10:57 -0700 | [diff] [blame] | 3561 | pSMB->FileName[name_len+1] = '*'; |
| 3562 | pSMB->FileName[name_len+2] = 0; |
| 3563 | name_len += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | params = 12 + name_len /* includes null */ ; |
| 3567 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 3568 | pSMB->MaxParameterCount = cpu_to_le16(10); |
| 3569 | pSMB->MaxDataCount = cpu_to_le16((tcon->ses->server->maxBuf - |
| 3570 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 3571 | pSMB->MaxSetupCount = 0; |
| 3572 | pSMB->Reserved = 0; |
| 3573 | pSMB->Flags = 0; |
| 3574 | pSMB->Timeout = 0; |
| 3575 | pSMB->Reserved2 = 0; |
| 3576 | byte_count = params + 1 /* pad */ ; |
| 3577 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3578 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3579 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3580 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 3581 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | pSMB->DataCount = 0; |
| 3583 | pSMB->DataOffset = 0; |
| 3584 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 3585 | pSMB->Reserved3 = 0; |
| 3586 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 3587 | pSMB->SearchAttributes = |
| 3588 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3589 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3590 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
| 3591 | pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | CIFS_SEARCH_RETURN_RESUME); |
| 3593 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 3594 | |
| 3595 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 3596 | pSMB->SearchStorageType = 0; |
| 3597 | pSMB->hdr.smb_buf_length += byte_count; |
| 3598 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3599 | |
| 3600 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3601 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3602 | cifs_stats_inc(&tcon->num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3604 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 3605 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | /* BB Add code to handle unsupported level rc */ |
| 3607 | cFYI(1, ("Error in FindFirst = %d", rc)); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 3608 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3609 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | |
| 3611 | /* BB eventually could optimize out free and realloc of buf */ |
| 3612 | /* for this case */ |
| 3613 | if (rc == -EAGAIN) |
| 3614 | goto findFirstRetry; |
| 3615 | } else { /* decode response */ |
| 3616 | /* BB remember to free buffer if error BB */ |
| 3617 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3618 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3619 | unsigned int lnoff; |
| 3620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3622 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3624 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | |
| 3626 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3627 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3628 | psrch_inf->srch_entries_start = |
| 3629 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 3632 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 3633 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3634 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3635 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3637 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3639 | psrch_inf->entries_in_buffer = |
| 3640 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 3641 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3643 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 3644 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 3645 | lnoff) { |
| 3646 | cERROR(1, ("ignoring corrupt resume name")); |
| 3647 | psrch_inf->last_entry = NULL; |
| 3648 | return rc; |
| 3649 | } |
| 3650 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 3651 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3652 | lnoff; |
| 3653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | *pnetfid = parms->SearchHandle; |
| 3655 | } else { |
| 3656 | cifs_buf_release(pSMB); |
| 3657 | } |
| 3658 | } |
| 3659 | |
| 3660 | return rc; |
| 3661 | } |
| 3662 | |
| 3663 | int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3664 | __u16 searchHandle, struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | { |
| 3666 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 3667 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3668 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | char *response_data; |
| 3670 | int rc = 0; |
| 3671 | int bytes_returned, name_len; |
| 3672 | __u16 params, byte_count; |
| 3673 | |
| 3674 | cFYI(1, ("In FindNext")); |
| 3675 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3676 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | return -ENOENT; |
| 3678 | |
| 3679 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3680 | (void **) &pSMBr); |
| 3681 | if (rc) |
| 3682 | return rc; |
| 3683 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3684 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | byte_count = 0; |
| 3686 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 3687 | pSMB->MaxParameterCount = cpu_to_le16(8); |
| 3688 | pSMB->MaxDataCount = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3689 | cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & |
| 3690 | 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | pSMB->MaxSetupCount = 0; |
| 3692 | pSMB->Reserved = 0; |
| 3693 | pSMB->Flags = 0; |
| 3694 | pSMB->Timeout = 0; |
| 3695 | pSMB->Reserved2 = 0; |
| 3696 | pSMB->ParameterOffset = cpu_to_le16( |
| 3697 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 3698 | pSMB->DataCount = 0; |
| 3699 | pSMB->DataOffset = 0; |
| 3700 | pSMB->SetupCount = 1; |
| 3701 | pSMB->Reserved3 = 0; |
| 3702 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 3703 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 3704 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3705 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 3707 | pSMB->ResumeKey = psrch_inf->resume_key; |
| 3708 | pSMB->SearchFlags = |
| 3709 | cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME); |
| 3710 | |
| 3711 | name_len = psrch_inf->resume_name_len; |
| 3712 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3713 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 3715 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 3716 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 3717 | pSMB->ResumeFileName[name_len] = 0; |
| 3718 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | } else { |
| 3720 | rc = -EINVAL; |
| 3721 | goto FNext2_err_exit; |
| 3722 | } |
| 3723 | byte_count = params + 1 /* pad */ ; |
| 3724 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3725 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3726 | pSMB->hdr.smb_buf_length += byte_count; |
| 3727 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3730 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3731 | cifs_stats_inc(&tcon->num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | if (rc) { |
| 3733 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3734 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 3735 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3736 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | } else |
| 3738 | cFYI(1, ("FindNext returned = %d", rc)); |
| 3739 | } else { /* decode response */ |
| 3740 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3741 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3742 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3743 | unsigned int lnoff; |
| 3744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | /* BB fixme add lock for file (srch_info) struct here */ |
| 3746 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3747 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3749 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 3751 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 3752 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 3753 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 3754 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3755 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3756 | cifs_small_buf_release( |
| 3757 | psrch_inf->ntwrk_buf_start); |
| 3758 | else |
| 3759 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | psrch_inf->srch_entries_start = response_data; |
| 3761 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3762 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3763 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3764 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3766 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3767 | psrch_inf->entries_in_buffer = |
| 3768 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | psrch_inf->index_of_last_entry += |
| 3770 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3771 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 3772 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 3773 | lnoff) { |
| 3774 | cERROR(1, ("ignoring corrupt resume name")); |
| 3775 | psrch_inf->last_entry = NULL; |
| 3776 | return rc; |
| 3777 | } else |
| 3778 | psrch_inf->last_entry = |
| 3779 | psrch_inf->srch_entries_start + lnoff; |
| 3780 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3781 | /* cFYI(1,("fnxt2 entries in buf %d index_of_last %d", |
| 3782 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry)); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | |
| 3784 | /* BB fixme add unlock here */ |
| 3785 | } |
| 3786 | |
| 3787 | } |
| 3788 | |
| 3789 | /* BB On error, should we leave previous search buf (and count and |
| 3790 | last entry fields) intact or free the previous one? */ |
| 3791 | |
| 3792 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 3793 | since file handle passed in no longer valid */ |
| 3794 | FNext2_err_exit: |
| 3795 | if (rc != 0) |
| 3796 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | return rc; |
| 3798 | } |
| 3799 | |
| 3800 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3801 | CIFSFindClose(const int xid, struct cifsTconInfo *tcon, |
| 3802 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | { |
| 3804 | int rc = 0; |
| 3805 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | |
| 3807 | cFYI(1, ("In CIFSSMBFindClose")); |
| 3808 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 3809 | |
| 3810 | /* no sense returning error if session restarted |
| 3811 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3812 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | return 0; |
| 3814 | if (rc) |
| 3815 | return rc; |
| 3816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | pSMB->FileID = searchHandle; |
| 3818 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 3819 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3820 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | cERROR(1, ("Send error in FindClose = %d", rc)); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3822 | |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3823 | cifs_stats_inc(&tcon->num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | |
| 3825 | /* Since session is dead, search handle closed on server already */ |
| 3826 | if (rc == -EAGAIN) |
| 3827 | rc = 0; |
| 3828 | |
| 3829 | return rc; |
| 3830 | } |
| 3831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | int |
| 3833 | CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3834 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3835 | __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3836 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | { |
| 3838 | int rc = 0; |
| 3839 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3840 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3841 | int name_len, bytes_returned; |
| 3842 | __u16 params, byte_count; |
| 3843 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3844 | cFYI(1, ("In GetSrvInodeNum for %s", searchName)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3845 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3846 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 | |
| 3848 | GetInodeNumberRetry: |
| 3849 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3850 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | if (rc) |
| 3852 | return rc; |
| 3853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3854 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3855 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 3856 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3857 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | name_len++; /* trailing null */ |
| 3859 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3860 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | name_len = strnlen(searchName, PATH_MAX); |
| 3862 | name_len++; /* trailing null */ |
| 3863 | strncpy(pSMB->FileName, searchName, name_len); |
| 3864 | } |
| 3865 | |
| 3866 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3867 | pSMB->TotalDataCount = 0; |
| 3868 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3869 | /* BB find exact max data count below from sess structure BB */ |
| 3870 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3871 | pSMB->MaxSetupCount = 0; |
| 3872 | pSMB->Reserved = 0; |
| 3873 | pSMB->Flags = 0; |
| 3874 | pSMB->Timeout = 0; |
| 3875 | pSMB->Reserved2 = 0; |
| 3876 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3877 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | pSMB->DataCount = 0; |
| 3879 | pSMB->DataOffset = 0; |
| 3880 | pSMB->SetupCount = 1; |
| 3881 | pSMB->Reserved3 = 0; |
| 3882 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3883 | byte_count = params + 1 /* pad */ ; |
| 3884 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3885 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3886 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 3887 | pSMB->Reserved4 = 0; |
| 3888 | pSMB->hdr.smb_buf_length += byte_count; |
| 3889 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3890 | |
| 3891 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3892 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3893 | if (rc) { |
| 3894 | cFYI(1, ("error %d in QueryInternalInfo", rc)); |
| 3895 | } else { |
| 3896 | /* decode response */ |
| 3897 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3898 | if (rc || (pSMBr->ByteCount < 2)) |
| 3899 | /* BB also check enough total bytes returned */ |
| 3900 | /* If rc should we check for EOPNOSUPP and |
| 3901 | disable the srvino flag? or in caller? */ |
| 3902 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3903 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3905 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3906 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3908 | if (count < 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | cFYI(1, ("Illegal size ret in QryIntrnlInf")); |
| 3910 | rc = -EIO; |
| 3911 | goto GetInodeNumOut; |
| 3912 | } |
| 3913 | pfinfo = (struct file_internal_info *) |
| 3914 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3915 | *inode_number = pfinfo->UniqueId; |
| 3916 | } |
| 3917 | } |
| 3918 | GetInodeNumOut: |
| 3919 | cifs_buf_release(pSMB); |
| 3920 | if (rc == -EAGAIN) |
| 3921 | goto GetInodeNumberRetry; |
| 3922 | return rc; |
| 3923 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3925 | /* parses DFS refferal V3 structure |
| 3926 | * caller is responsible for freeing target_nodes |
| 3927 | * returns: |
| 3928 | * on success - 0 |
| 3929 | * on failure - errno |
| 3930 | */ |
| 3931 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 3932 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3933 | unsigned int *num_of_nodes, |
| 3934 | struct dfs_info3_param **target_nodes, |
| 3935 | const struct nls_table *nls_codepage) |
| 3936 | { |
| 3937 | int i, rc = 0; |
| 3938 | char *data_end; |
| 3939 | bool is_unicode; |
| 3940 | struct dfs_referral_level_3 *ref; |
| 3941 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 3942 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3943 | is_unicode = true; |
| 3944 | else |
| 3945 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3946 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 3947 | |
| 3948 | if (*num_of_nodes < 1) { |
| 3949 | cERROR(1, ("num_referrals: must be at least > 0," |
| 3950 | "but we get num_referrals = %d\n", *num_of_nodes)); |
| 3951 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 3952 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 3956 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3957 | cERROR(1, ("Referrals of V%d version are not supported," |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 3958 | "should be V3", le16_to_cpu(ref->VersionNumber))); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3959 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 3960 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | /* get the upper boundary of the resp buffer */ |
| 3964 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 3965 | le16_to_cpu(pSMBr->t2.DataCount); |
| 3966 | |
| 3967 | cFYI(1, ("num_referrals: %d dfs flags: 0x%x ... \n", |
| 3968 | *num_of_nodes, |
| 3969 | le16_to_cpu(pSMBr->DFSFlags))); |
| 3970 | |
| 3971 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
| 3972 | *num_of_nodes, GFP_KERNEL); |
| 3973 | if (*target_nodes == NULL) { |
| 3974 | cERROR(1, ("Failed to allocate buffer for target_nodes\n")); |
| 3975 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 3976 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | /* collect neccessary data from referrals */ |
| 3980 | for (i = 0; i < *num_of_nodes; i++) { |
| 3981 | char *temp; |
| 3982 | int max_len; |
| 3983 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 3984 | |
| 3985 | node->flags = le16_to_cpu(pSMBr->DFSFlags); |
| 3986 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 3987 | node->server_type = le16_to_cpu(ref->ServerType); |
| 3988 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 3989 | |
| 3990 | /* copy DfsPath */ |
| 3991 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 3992 | max_len = data_end - temp; |
| 3993 | rc = cifs_strncpy_to_host(&(node->path_name), temp, |
| 3994 | max_len, is_unicode, nls_codepage); |
| 3995 | if (rc) |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 3996 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3997 | |
| 3998 | /* copy link target UNC */ |
| 3999 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4000 | max_len = data_end - temp; |
| 4001 | rc = cifs_strncpy_to_host(&(node->node_name), temp, |
| 4002 | max_len, is_unicode, nls_codepage); |
| 4003 | if (rc) |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4004 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4005 | |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4006 | ref += le16_to_cpu(ref->Size); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4007 | } |
| 4008 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4009 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4010 | if (rc) { |
| 4011 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4012 | *target_nodes = NULL; |
| 4013 | *num_of_nodes = 0; |
| 4014 | } |
| 4015 | return rc; |
| 4016 | } |
| 4017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | int |
| 4019 | CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses, |
| 4020 | const unsigned char *searchName, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4021 | struct dfs_info3_param **target_nodes, |
| 4022 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4023 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | { |
| 4025 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4026 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4027 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | int rc = 0; |
| 4029 | int bytes_returned; |
| 4030 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4032 | *num_of_nodes = 0; |
| 4033 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | |
| 4035 | cFYI(1, ("In GetDFSRefer the path %s", searchName)); |
| 4036 | if (ses == NULL) |
| 4037 | return -ENODEV; |
| 4038 | getDFSRetry: |
| 4039 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4040 | (void **) &pSMBr); |
| 4041 | if (rc) |
| 4042 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4043 | |
| 4044 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4045 | but should never be null here anyway */ |
| 4046 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4048 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4049 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4051 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | |
| 4054 | if (ses->capabilities & CAP_UNICODE) { |
| 4055 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4056 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4057 | cifsConvertToUCS((__le16 *) pSMB->RequestFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4058 | searchName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | name_len++; /* trailing null */ |
| 4060 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4061 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | name_len = strnlen(searchName, PATH_MAX); |
| 4063 | name_len++; /* trailing null */ |
| 4064 | strncpy(pSMB->RequestFileName, searchName, name_len); |
| 4065 | } |
| 4066 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4067 | if (ses->server) { |
| 4068 | if (ses->server->secMode & |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4069 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 4070 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4071 | } |
| 4072 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4073 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4074 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4076 | pSMB->TotalDataCount = 0; |
| 4077 | pSMB->DataCount = 0; |
| 4078 | pSMB->DataOffset = 0; |
| 4079 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4080 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4081 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4082 | pSMB->MaxSetupCount = 0; |
| 4083 | pSMB->Reserved = 0; |
| 4084 | pSMB->Flags = 0; |
| 4085 | pSMB->Timeout = 0; |
| 4086 | pSMB->Reserved2 = 0; |
| 4087 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4088 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | pSMB->SetupCount = 1; |
| 4090 | pSMB->Reserved3 = 0; |
| 4091 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4092 | byte_count = params + 3 /* pad */ ; |
| 4093 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4094 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4095 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
| 4096 | pSMB->hdr.smb_buf_length += byte_count; |
| 4097 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4098 | |
| 4099 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4100 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4101 | if (rc) { |
| 4102 | cFYI(1, ("Send error in GetDFSRefer = %d", rc)); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4103 | goto GetDFSRefExit; |
| 4104 | } |
| 4105 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4107 | /* BB Also check if enough total bytes returned? */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4108 | if (rc || (pSMBr->ByteCount < 17)) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4109 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4110 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4112 | |
| 4113 | cFYI(1, ("Decoding GetDFSRefer response BCC: %d Offset %d", |
| 4114 | pSMBr->ByteCount, |
| 4115 | le16_to_cpu(pSMBr->t2.DataOffset))); |
| 4116 | |
| 4117 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4118 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4119 | target_nodes, nls_codepage); |
| 4120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4122 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | |
| 4124 | if (rc == -EAGAIN) |
| 4125 | goto getDFSRetry; |
| 4126 | |
| 4127 | return rc; |
| 4128 | } |
| 4129 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4130 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4131 | int |
| 4132 | SMBOldQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
| 4133 | { |
| 4134 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4135 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4136 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4137 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4138 | int rc = 0; |
| 4139 | int bytes_returned = 0; |
| 4140 | __u16 params, byte_count; |
| 4141 | |
| 4142 | cFYI(1, ("OldQFSInfo")); |
| 4143 | oldQFSInfoRetry: |
| 4144 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4145 | (void **) &pSMBr); |
| 4146 | if (rc) |
| 4147 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4148 | |
| 4149 | params = 2; /* level */ |
| 4150 | pSMB->TotalDataCount = 0; |
| 4151 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4152 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4153 | pSMB->MaxSetupCount = 0; |
| 4154 | pSMB->Reserved = 0; |
| 4155 | pSMB->Flags = 0; |
| 4156 | pSMB->Timeout = 0; |
| 4157 | pSMB->Reserved2 = 0; |
| 4158 | byte_count = params + 1 /* pad */ ; |
| 4159 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4160 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4161 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4162 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4163 | pSMB->DataCount = 0; |
| 4164 | pSMB->DataOffset = 0; |
| 4165 | pSMB->SetupCount = 1; |
| 4166 | pSMB->Reserved3 = 0; |
| 4167 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4168 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
| 4169 | pSMB->hdr.smb_buf_length += byte_count; |
| 4170 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4171 | |
| 4172 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4173 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4174 | if (rc) { |
| 4175 | cFYI(1, ("Send error in QFSInfo = %d", rc)); |
| 4176 | } else { /* decode response */ |
| 4177 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4178 | |
| 4179 | if (rc || (pSMBr->ByteCount < 18)) |
| 4180 | rc = -EIO; /* bad smb */ |
| 4181 | else { |
| 4182 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4183 | cFYI(1, ("qfsinf resp BCC: %d Offset %d", |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4184 | pSMBr->ByteCount, data_offset)); |
| 4185 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4186 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4187 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4188 | FSData->f_bsize = |
| 4189 | le16_to_cpu(response_data->BytesPerSector) * |
| 4190 | le32_to_cpu(response_data-> |
| 4191 | SectorsPerAllocationUnit); |
| 4192 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4193 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4194 | FSData->f_bfree = FSData->f_bavail = |
| 4195 | le32_to_cpu(response_data->FreeAllocationUnits); |
| 4196 | cFYI(1, |
| 4197 | ("Blocks: %lld Free: %lld Block size %ld", |
| 4198 | (unsigned long long)FSData->f_blocks, |
| 4199 | (unsigned long long)FSData->f_bfree, |
| 4200 | FSData->f_bsize)); |
| 4201 | } |
| 4202 | } |
| 4203 | cifs_buf_release(pSMB); |
| 4204 | |
| 4205 | if (rc == -EAGAIN) |
| 4206 | goto oldQFSInfoRetry; |
| 4207 | |
| 4208 | return rc; |
| 4209 | } |
| 4210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4212 | CIFSSMBQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | { |
| 4214 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4215 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4216 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4217 | FILE_SYSTEM_INFO *response_data; |
| 4218 | int rc = 0; |
| 4219 | int bytes_returned = 0; |
| 4220 | __u16 params, byte_count; |
| 4221 | |
| 4222 | cFYI(1, ("In QFSInfo")); |
| 4223 | QFSInfoRetry: |
| 4224 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4225 | (void **) &pSMBr); |
| 4226 | if (rc) |
| 4227 | return rc; |
| 4228 | |
| 4229 | params = 2; /* level */ |
| 4230 | pSMB->TotalDataCount = 0; |
| 4231 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4232 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | pSMB->MaxSetupCount = 0; |
| 4234 | pSMB->Reserved = 0; |
| 4235 | pSMB->Flags = 0; |
| 4236 | pSMB->Timeout = 0; |
| 4237 | pSMB->Reserved2 = 0; |
| 4238 | byte_count = params + 1 /* pad */ ; |
| 4239 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4240 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4241 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4242 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | pSMB->DataCount = 0; |
| 4244 | pSMB->DataOffset = 0; |
| 4245 | pSMB->SetupCount = 1; |
| 4246 | pSMB->Reserved3 = 0; |
| 4247 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4248 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
| 4249 | pSMB->hdr.smb_buf_length += byte_count; |
| 4250 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4251 | |
| 4252 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4253 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4254 | if (rc) { |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4255 | cFYI(1, ("Send error in QFSInfo = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4257 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4259 | if (rc || (pSMBr->ByteCount < 24)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | rc = -EIO; /* bad smb */ |
| 4261 | else { |
| 4262 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4263 | |
| 4264 | response_data = |
| 4265 | (FILE_SYSTEM_INFO |
| 4266 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4267 | data_offset); |
| 4268 | FSData->f_bsize = |
| 4269 | le32_to_cpu(response_data->BytesPerSector) * |
| 4270 | le32_to_cpu(response_data-> |
| 4271 | SectorsPerAllocationUnit); |
| 4272 | FSData->f_blocks = |
| 4273 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 4274 | FSData->f_bfree = FSData->f_bavail = |
| 4275 | le64_to_cpu(response_data->FreeAllocationUnits); |
| 4276 | cFYI(1, |
| 4277 | ("Blocks: %lld Free: %lld Block size %ld", |
| 4278 | (unsigned long long)FSData->f_blocks, |
| 4279 | (unsigned long long)FSData->f_bfree, |
| 4280 | FSData->f_bsize)); |
| 4281 | } |
| 4282 | } |
| 4283 | cifs_buf_release(pSMB); |
| 4284 | |
| 4285 | if (rc == -EAGAIN) |
| 4286 | goto QFSInfoRetry; |
| 4287 | |
| 4288 | return rc; |
| 4289 | } |
| 4290 | |
| 4291 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4292 | CIFSSMBQFSAttributeInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | { |
| 4294 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4295 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4296 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4297 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 4298 | int rc = 0; |
| 4299 | int bytes_returned = 0; |
| 4300 | __u16 params, byte_count; |
| 4301 | |
| 4302 | cFYI(1, ("In QFSAttributeInfo")); |
| 4303 | QFSAttributeRetry: |
| 4304 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4305 | (void **) &pSMBr); |
| 4306 | if (rc) |
| 4307 | return rc; |
| 4308 | |
| 4309 | params = 2; /* level */ |
| 4310 | pSMB->TotalDataCount = 0; |
| 4311 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4312 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4313 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | pSMB->MaxSetupCount = 0; |
| 4315 | pSMB->Reserved = 0; |
| 4316 | pSMB->Flags = 0; |
| 4317 | pSMB->Timeout = 0; |
| 4318 | pSMB->Reserved2 = 0; |
| 4319 | byte_count = params + 1 /* pad */ ; |
| 4320 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4321 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4322 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4323 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | pSMB->DataCount = 0; |
| 4325 | pSMB->DataOffset = 0; |
| 4326 | pSMB->SetupCount = 1; |
| 4327 | pSMB->Reserved3 = 0; |
| 4328 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4329 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
| 4330 | pSMB->hdr.smb_buf_length += byte_count; |
| 4331 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4332 | |
| 4333 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4334 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4335 | if (rc) { |
| 4336 | cERROR(1, ("Send error in QFSAttributeInfo = %d", rc)); |
| 4337 | } else { /* decode response */ |
| 4338 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4339 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4340 | if (rc || (pSMBr->ByteCount < 13)) { |
| 4341 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | rc = -EIO; /* bad smb */ |
| 4343 | } else { |
| 4344 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4345 | response_data = |
| 4346 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 4347 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4348 | data_offset); |
| 4349 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4350 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | } |
| 4352 | } |
| 4353 | cifs_buf_release(pSMB); |
| 4354 | |
| 4355 | if (rc == -EAGAIN) |
| 4356 | goto QFSAttributeRetry; |
| 4357 | |
| 4358 | return rc; |
| 4359 | } |
| 4360 | |
| 4361 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4362 | CIFSSMBQFSDeviceInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | { |
| 4364 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4365 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4366 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4367 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 4368 | int rc = 0; |
| 4369 | int bytes_returned = 0; |
| 4370 | __u16 params, byte_count; |
| 4371 | |
| 4372 | cFYI(1, ("In QFSDeviceInfo")); |
| 4373 | QFSDeviceRetry: |
| 4374 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4375 | (void **) &pSMBr); |
| 4376 | if (rc) |
| 4377 | return rc; |
| 4378 | |
| 4379 | params = 2; /* level */ |
| 4380 | pSMB->TotalDataCount = 0; |
| 4381 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4382 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4383 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | pSMB->MaxSetupCount = 0; |
| 4385 | pSMB->Reserved = 0; |
| 4386 | pSMB->Flags = 0; |
| 4387 | pSMB->Timeout = 0; |
| 4388 | pSMB->Reserved2 = 0; |
| 4389 | byte_count = params + 1 /* pad */ ; |
| 4390 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4391 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4392 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4393 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | |
| 4395 | pSMB->DataCount = 0; |
| 4396 | pSMB->DataOffset = 0; |
| 4397 | pSMB->SetupCount = 1; |
| 4398 | pSMB->Reserved3 = 0; |
| 4399 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4400 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
| 4401 | pSMB->hdr.smb_buf_length += byte_count; |
| 4402 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4403 | |
| 4404 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4405 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4406 | if (rc) { |
| 4407 | cFYI(1, ("Send error in QFSDeviceInfo = %d", rc)); |
| 4408 | } else { /* decode response */ |
| 4409 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4410 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4411 | if (rc || (pSMBr->ByteCount < sizeof(FILE_SYSTEM_DEVICE_INFO))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | rc = -EIO; /* bad smb */ |
| 4413 | else { |
| 4414 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4415 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4416 | (FILE_SYSTEM_DEVICE_INFO *) |
| 4417 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | data_offset); |
| 4419 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4420 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | } |
| 4422 | } |
| 4423 | cifs_buf_release(pSMB); |
| 4424 | |
| 4425 | if (rc == -EAGAIN) |
| 4426 | goto QFSDeviceRetry; |
| 4427 | |
| 4428 | return rc; |
| 4429 | } |
| 4430 | |
| 4431 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4432 | CIFSSMBQFSUnixInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | { |
| 4434 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 4435 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4436 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4437 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 4438 | int rc = 0; |
| 4439 | int bytes_returned = 0; |
| 4440 | __u16 params, byte_count; |
| 4441 | |
| 4442 | cFYI(1, ("In QFSUnixInfo")); |
| 4443 | QFSUnixRetry: |
| 4444 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4445 | (void **) &pSMBr); |
| 4446 | if (rc) |
| 4447 | return rc; |
| 4448 | |
| 4449 | params = 2; /* level */ |
| 4450 | pSMB->TotalDataCount = 0; |
| 4451 | pSMB->DataCount = 0; |
| 4452 | pSMB->DataOffset = 0; |
| 4453 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4454 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4455 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | pSMB->MaxSetupCount = 0; |
| 4457 | pSMB->Reserved = 0; |
| 4458 | pSMB->Flags = 0; |
| 4459 | pSMB->Timeout = 0; |
| 4460 | pSMB->Reserved2 = 0; |
| 4461 | byte_count = params + 1 /* pad */ ; |
| 4462 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4463 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4464 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 4465 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | pSMB->SetupCount = 1; |
| 4467 | pSMB->Reserved3 = 0; |
| 4468 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4469 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
| 4470 | pSMB->hdr.smb_buf_length += byte_count; |
| 4471 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4472 | |
| 4473 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4474 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4475 | if (rc) { |
| 4476 | cERROR(1, ("Send error in QFSUnixInfo = %d", rc)); |
| 4477 | } else { /* decode response */ |
| 4478 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4479 | |
| 4480 | if (rc || (pSMBr->ByteCount < 13)) { |
| 4481 | rc = -EIO; /* bad smb */ |
| 4482 | } else { |
| 4483 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4484 | response_data = |
| 4485 | (FILE_SYSTEM_UNIX_INFO |
| 4486 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4487 | data_offset); |
| 4488 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4489 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | } |
| 4491 | } |
| 4492 | cifs_buf_release(pSMB); |
| 4493 | |
| 4494 | if (rc == -EAGAIN) |
| 4495 | goto QFSUnixRetry; |
| 4496 | |
| 4497 | |
| 4498 | return rc; |
| 4499 | } |
| 4500 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4501 | int |
Steve French | 45abc6e | 2005-06-23 13:42:03 -0500 | [diff] [blame] | 4502 | CIFSSMBSetFSUnixInfo(const int xid, struct cifsTconInfo *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4503 | { |
| 4504 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 4505 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 4506 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 4507 | int rc = 0; |
| 4508 | int bytes_returned = 0; |
| 4509 | __u16 params, param_offset, offset, byte_count; |
| 4510 | |
| 4511 | cFYI(1, ("In SETFSUnixInfo")); |
| 4512 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 4513 | /* BB switch to small buf init to save memory */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4514 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4515 | (void **) &pSMBr); |
| 4516 | if (rc) |
| 4517 | return rc; |
| 4518 | |
| 4519 | params = 4; /* 2 bytes zero followed by info level. */ |
| 4520 | pSMB->MaxSetupCount = 0; |
| 4521 | pSMB->Reserved = 0; |
| 4522 | pSMB->Flags = 0; |
| 4523 | pSMB->Timeout = 0; |
| 4524 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4525 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 4526 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4527 | offset = param_offset + params; |
| 4528 | |
| 4529 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4530 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4531 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4532 | pSMB->SetupCount = 1; |
| 4533 | pSMB->Reserved3 = 0; |
| 4534 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 4535 | byte_count = 1 /* pad */ + params + 12; |
| 4536 | |
| 4537 | pSMB->DataCount = cpu_to_le16(12); |
| 4538 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4539 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4540 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4541 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4542 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4543 | |
| 4544 | /* Params. */ |
| 4545 | pSMB->FileNum = 0; |
| 4546 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 4547 | |
| 4548 | /* Data. */ |
| 4549 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 4550 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 4551 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 4552 | |
| 4553 | pSMB->hdr.smb_buf_length += byte_count; |
| 4554 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4555 | |
| 4556 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4557 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4558 | if (rc) { |
| 4559 | cERROR(1, ("Send error in SETFSUnixInfo = %d", rc)); |
| 4560 | } else { /* decode response */ |
| 4561 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4562 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4563 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4564 | } |
| 4565 | cifs_buf_release(pSMB); |
| 4566 | |
| 4567 | if (rc == -EAGAIN) |
| 4568 | goto SETFSUnixRetry; |
| 4569 | |
| 4570 | return rc; |
| 4571 | } |
| 4572 | |
| 4573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | |
| 4575 | int |
| 4576 | CIFSSMBQFSPosixInfo(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4577 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | { |
| 4579 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 4580 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4581 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4582 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 4583 | int rc = 0; |
| 4584 | int bytes_returned = 0; |
| 4585 | __u16 params, byte_count; |
| 4586 | |
| 4587 | cFYI(1, ("In QFSPosixInfo")); |
| 4588 | QFSPosixRetry: |
| 4589 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4590 | (void **) &pSMBr); |
| 4591 | if (rc) |
| 4592 | return rc; |
| 4593 | |
| 4594 | params = 2; /* level */ |
| 4595 | pSMB->TotalDataCount = 0; |
| 4596 | pSMB->DataCount = 0; |
| 4597 | pSMB->DataOffset = 0; |
| 4598 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4599 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4600 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | pSMB->MaxSetupCount = 0; |
| 4602 | pSMB->Reserved = 0; |
| 4603 | pSMB->Flags = 0; |
| 4604 | pSMB->Timeout = 0; |
| 4605 | pSMB->Reserved2 = 0; |
| 4606 | byte_count = params + 1 /* pad */ ; |
| 4607 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4608 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4609 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 4610 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | pSMB->SetupCount = 1; |
| 4612 | pSMB->Reserved3 = 0; |
| 4613 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4614 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
| 4615 | pSMB->hdr.smb_buf_length += byte_count; |
| 4616 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4617 | |
| 4618 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4619 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4620 | if (rc) { |
| 4621 | cFYI(1, ("Send error in QFSUnixInfo = %d", rc)); |
| 4622 | } else { /* decode response */ |
| 4623 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4624 | |
| 4625 | if (rc || (pSMBr->ByteCount < 13)) { |
| 4626 | rc = -EIO; /* bad smb */ |
| 4627 | } else { |
| 4628 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4629 | response_data = |
| 4630 | (FILE_SYSTEM_POSIX_INFO |
| 4631 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4632 | data_offset); |
| 4633 | FSData->f_bsize = |
| 4634 | le32_to_cpu(response_data->BlockSize); |
| 4635 | FSData->f_blocks = |
| 4636 | le64_to_cpu(response_data->TotalBlocks); |
| 4637 | FSData->f_bfree = |
| 4638 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4639 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | FSData->f_bavail = FSData->f_bfree; |
| 4641 | } else { |
| 4642 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4643 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4645 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4647 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4648 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4650 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | } |
| 4652 | } |
| 4653 | cifs_buf_release(pSMB); |
| 4654 | |
| 4655 | if (rc == -EAGAIN) |
| 4656 | goto QFSPosixRetry; |
| 4657 | |
| 4658 | return rc; |
| 4659 | } |
| 4660 | |
| 4661 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4662 | /* We can not use write of zero bytes trick to |
| 4663 | set file size due to need for large file support. Also note that |
| 4664 | this SetPathInfo is preferred to SetFileInfo based method in next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | routine which is only needed to work around a sharing violation bug |
| 4666 | in Samba which this routine can run into */ |
| 4667 | |
| 4668 | int |
| 4669 | CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4670 | __u64 size, bool SetAllocation, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4671 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | { |
| 4673 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 4674 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 4675 | struct file_end_of_file_info *parm_data; |
| 4676 | int name_len; |
| 4677 | int rc = 0; |
| 4678 | int bytes_returned = 0; |
| 4679 | __u16 params, byte_count, data_count, param_offset, offset; |
| 4680 | |
| 4681 | cFYI(1, ("In SetEOF")); |
| 4682 | SetEOFRetry: |
| 4683 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4684 | (void **) &pSMBr); |
| 4685 | if (rc) |
| 4686 | return rc; |
| 4687 | |
| 4688 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4689 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4690 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4691 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4692 | name_len++; /* trailing null */ |
| 4693 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 4694 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | name_len = strnlen(fileName, PATH_MAX); |
| 4696 | name_len++; /* trailing null */ |
| 4697 | strncpy(pSMB->FileName, fileName, name_len); |
| 4698 | } |
| 4699 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4700 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 4702 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | pSMB->MaxSetupCount = 0; |
| 4704 | pSMB->Reserved = 0; |
| 4705 | pSMB->Flags = 0; |
| 4706 | pSMB->Timeout = 0; |
| 4707 | pSMB->Reserved2 = 0; |
| 4708 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4709 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | offset = param_offset + params; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4711 | if (SetAllocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4712 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4713 | pSMB->InformationLevel = |
| 4714 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 4715 | else |
| 4716 | pSMB->InformationLevel = |
| 4717 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 4718 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4720 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4721 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | else |
| 4723 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4724 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | parm_data = |
| 4728 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 4729 | offset); |
| 4730 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4731 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4732 | pSMB->SetupCount = 1; |
| 4733 | pSMB->Reserved3 = 0; |
| 4734 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 4735 | byte_count = 3 /* pad */ + params + data_count; |
| 4736 | pSMB->DataCount = cpu_to_le16(data_count); |
| 4737 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4738 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4739 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4740 | pSMB->Reserved4 = 0; |
| 4741 | pSMB->hdr.smb_buf_length += byte_count; |
| 4742 | parm_data->FileSize = cpu_to_le64(size); |
| 4743 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4744 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4745 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4746 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | cFYI(1, ("SetPathInfo (file size) returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | |
| 4749 | cifs_buf_release(pSMB); |
| 4750 | |
| 4751 | if (rc == -EAGAIN) |
| 4752 | goto SetEOFRetry; |
| 4753 | |
| 4754 | return rc; |
| 4755 | } |
| 4756 | |
| 4757 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4758 | CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4759 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | { |
| 4761 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | char *data_offset; |
| 4763 | struct file_end_of_file_info *parm_data; |
| 4764 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | __u16 params, param_offset, offset, byte_count, count; |
| 4766 | |
| 4767 | cFYI(1, ("SetFileSize (via SetFileInfo) %lld", |
| 4768 | (long long)size)); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 4769 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 4770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | if (rc) |
| 4772 | return rc; |
| 4773 | |
| 4774 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 4775 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | params = 6; |
| 4778 | pSMB->MaxSetupCount = 0; |
| 4779 | pSMB->Reserved = 0; |
| 4780 | pSMB->Flags = 0; |
| 4781 | pSMB->Timeout = 0; |
| 4782 | pSMB->Reserved2 = 0; |
| 4783 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 4784 | offset = param_offset + params; |
| 4785 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4786 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | |
| 4788 | count = sizeof(struct file_end_of_file_info); |
| 4789 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4790 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4791 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | pSMB->SetupCount = 1; |
| 4793 | pSMB->Reserved3 = 0; |
| 4794 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 4795 | byte_count = 3 /* pad */ + params + count; |
| 4796 | pSMB->DataCount = cpu_to_le16(count); |
| 4797 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4798 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4799 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4800 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4801 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4802 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 4803 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4805 | parm_data->FileSize = cpu_to_le64(size); |
| 4806 | pSMB->Fid = fid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4807 | if (SetAllocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4809 | pSMB->InformationLevel = |
| 4810 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 4811 | else |
| 4812 | pSMB->InformationLevel = |
| 4813 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4814 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4815 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4816 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4817 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | else |
| 4819 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4820 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | } |
| 4822 | pSMB->Reserved4 = 0; |
| 4823 | pSMB->hdr.smb_buf_length += byte_count; |
| 4824 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 4825 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | if (rc) { |
| 4827 | cFYI(1, |
| 4828 | ("Send error in SetFileInfo (SetFileSize) = %d", |
| 4829 | rc)); |
| 4830 | } |
| 4831 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4832 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4833 | since file handle passed in no longer valid */ |
| 4834 | |
| 4835 | return rc; |
| 4836 | } |
| 4837 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4838 | /* 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] | 4839 | an open handle, rather than by pathname - this is awkward due to |
| 4840 | potential access conflicts on the open, but it is unavoidable for these |
| 4841 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 4842 | time and resort to the original setpathinfo level which takes the ancient |
| 4843 | DOS time format with 2 second granularity */ |
| 4844 | int |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 4845 | CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 4846 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | { |
| 4848 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | char *data_offset; |
| 4850 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | __u16 params, param_offset, offset, byte_count, count; |
| 4852 | |
| 4853 | cFYI(1, ("Set Times (via SetFileInfo)")); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 4854 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 4855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | if (rc) |
| 4857 | return rc; |
| 4858 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 4859 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 4860 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | params = 6; |
| 4863 | pSMB->MaxSetupCount = 0; |
| 4864 | pSMB->Reserved = 0; |
| 4865 | pSMB->Flags = 0; |
| 4866 | pSMB->Timeout = 0; |
| 4867 | pSMB->Reserved2 = 0; |
| 4868 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 4869 | offset = param_offset + params; |
| 4870 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4871 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4873 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4875 | /* BB find max SMB PDU from sess */ |
| 4876 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | pSMB->SetupCount = 1; |
| 4878 | pSMB->Reserved3 = 0; |
| 4879 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 4880 | byte_count = 3 /* pad */ + params + count; |
| 4881 | pSMB->DataCount = cpu_to_le16(count); |
| 4882 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4883 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4884 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4885 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4886 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4887 | pSMB->Fid = fid; |
| 4888 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4889 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 4890 | else |
| 4891 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 4892 | pSMB->Reserved4 = 0; |
| 4893 | pSMB->hdr.smb_buf_length += byte_count; |
| 4894 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4895 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 4896 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4897 | if (rc) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4898 | cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4900 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | since file handle passed in no longer valid */ |
| 4902 | |
| 4903 | return rc; |
| 4904 | } |
| 4905 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 4906 | int |
| 4907 | CIFSSMBSetFileDisposition(const int xid, struct cifsTconInfo *tcon, |
| 4908 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 4909 | { |
| 4910 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 4911 | char *data_offset; |
| 4912 | int rc = 0; |
| 4913 | __u16 params, param_offset, offset, byte_count, count; |
| 4914 | |
| 4915 | cFYI(1, ("Set File Disposition (via SetFileInfo)")); |
| 4916 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 4917 | |
| 4918 | if (rc) |
| 4919 | return rc; |
| 4920 | |
| 4921 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 4922 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 4923 | |
| 4924 | params = 6; |
| 4925 | pSMB->MaxSetupCount = 0; |
| 4926 | pSMB->Reserved = 0; |
| 4927 | pSMB->Flags = 0; |
| 4928 | pSMB->Timeout = 0; |
| 4929 | pSMB->Reserved2 = 0; |
| 4930 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 4931 | offset = param_offset + params; |
| 4932 | |
| 4933 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 4934 | |
| 4935 | count = 1; |
| 4936 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4937 | /* BB find max SMB PDU from sess */ |
| 4938 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4939 | pSMB->SetupCount = 1; |
| 4940 | pSMB->Reserved3 = 0; |
| 4941 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 4942 | byte_count = 3 /* pad */ + params + count; |
| 4943 | pSMB->DataCount = cpu_to_le16(count); |
| 4944 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4945 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4946 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4947 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4948 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4949 | pSMB->Fid = fid; |
| 4950 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 4951 | pSMB->Reserved4 = 0; |
| 4952 | pSMB->hdr.smb_buf_length += byte_count; |
| 4953 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4954 | *data_offset = delete_file ? 1 : 0; |
| 4955 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 4956 | if (rc) |
| 4957 | cFYI(1, ("Send error in SetFileDisposition = %d", rc)); |
| 4958 | |
| 4959 | return rc; |
| 4960 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | |
| 4962 | int |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 4963 | CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 4964 | const char *fileName, const FILE_BASIC_INFO *data, |
| 4965 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4966 | { |
| 4967 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 4968 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 4969 | int name_len; |
| 4970 | int rc = 0; |
| 4971 | int bytes_returned = 0; |
| 4972 | char *data_offset; |
| 4973 | __u16 params, param_offset, offset, byte_count, count; |
| 4974 | |
| 4975 | cFYI(1, ("In SetTimes")); |
| 4976 | |
| 4977 | SetTimesRetry: |
| 4978 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4979 | (void **) &pSMBr); |
| 4980 | if (rc) |
| 4981 | return rc; |
| 4982 | |
| 4983 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4984 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4985 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4986 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4987 | name_len++; /* trailing null */ |
| 4988 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4989 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | name_len = strnlen(fileName, PATH_MAX); |
| 4991 | name_len++; /* trailing null */ |
| 4992 | strncpy(pSMB->FileName, fileName, name_len); |
| 4993 | } |
| 4994 | |
| 4995 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4996 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4997 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4998 | /* BB find max SMB PDU from sess structure BB */ |
| 4999 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | pSMB->MaxSetupCount = 0; |
| 5001 | pSMB->Reserved = 0; |
| 5002 | pSMB->Flags = 0; |
| 5003 | pSMB->Timeout = 0; |
| 5004 | pSMB->Reserved2 = 0; |
| 5005 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5006 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | offset = param_offset + params; |
| 5008 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5009 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5010 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5011 | pSMB->SetupCount = 1; |
| 5012 | pSMB->Reserved3 = 0; |
| 5013 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5014 | byte_count = 3 /* pad */ + params + count; |
| 5015 | |
| 5016 | pSMB->DataCount = cpu_to_le16(count); |
| 5017 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5018 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5019 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5020 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5021 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5022 | else |
| 5023 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5024 | pSMB->Reserved4 = 0; |
| 5025 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5026 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5027 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5028 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5029 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5030 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | cFYI(1, ("SetPathInfo (times) returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | |
| 5033 | cifs_buf_release(pSMB); |
| 5034 | |
| 5035 | if (rc == -EAGAIN) |
| 5036 | goto SetTimesRetry; |
| 5037 | |
| 5038 | return rc; |
| 5039 | } |
| 5040 | |
| 5041 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5042 | /* Can be used to set attributes */ |
| 5043 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5044 | handling it anyway and NT4 was what we thought it would be needed for |
| 5045 | Do not delete it until we prove whether needed for Win9x though */ |
| 5046 | int |
| 5047 | CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName, |
| 5048 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5049 | { |
| 5050 | SETATTR_REQ *pSMB = NULL; |
| 5051 | SETATTR_RSP *pSMBr = NULL; |
| 5052 | int rc = 0; |
| 5053 | int bytes_returned; |
| 5054 | int name_len; |
| 5055 | |
| 5056 | cFYI(1, ("In SetAttrLegacy")); |
| 5057 | |
| 5058 | SetAttrLgcyRetry: |
| 5059 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5060 | (void **) &pSMBr); |
| 5061 | if (rc) |
| 5062 | return rc; |
| 5063 | |
| 5064 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5065 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5066 | ConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | PATH_MAX, nls_codepage); |
| 5068 | name_len++; /* trailing null */ |
| 5069 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5070 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | name_len = strnlen(fileName, PATH_MAX); |
| 5072 | name_len++; /* trailing null */ |
| 5073 | strncpy(pSMB->fileName, fileName, name_len); |
| 5074 | } |
| 5075 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5076 | pSMB->BufferFormat = 0x04; |
| 5077 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 5078 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5079 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5080 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5081 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | cFYI(1, ("Error in LegacySetAttr = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 | |
| 5084 | cifs_buf_release(pSMB); |
| 5085 | |
| 5086 | if (rc == -EAGAIN) |
| 5087 | goto SetAttrLgcyRetry; |
| 5088 | |
| 5089 | return rc; |
| 5090 | } |
| 5091 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5092 | |
| 5093 | int |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5094 | CIFSSMBUnixSetInfo(const int xid, struct cifsTconInfo *tcon, char *fileName, |
Steve French | 063ea27 | 2008-08-06 04:23:13 +0000 | [diff] [blame] | 5095 | const struct cifs_unix_set_info_args *args, |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [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 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5099 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5100 | int name_len; |
| 5101 | int rc = 0; |
| 5102 | int bytes_returned = 0; |
| 5103 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5104 | __u16 params, param_offset, offset, count, byte_count; |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5105 | __u64 mode = args->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | |
| 5107 | cFYI(1, ("In SetUID/GID/Mode")); |
| 5108 | setPermsRetry: |
| 5109 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5110 | (void **) &pSMBr); |
| 5111 | if (rc) |
| 5112 | return rc; |
| 5113 | |
| 5114 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5115 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5116 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5117 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | name_len++; /* trailing null */ |
| 5119 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5120 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5121 | name_len = strnlen(fileName, PATH_MAX); |
| 5122 | name_len++; /* trailing null */ |
| 5123 | strncpy(pSMB->FileName, fileName, name_len); |
| 5124 | } |
| 5125 | |
| 5126 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5127 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5129 | /* BB find max SMB PDU from sess structure BB */ |
| 5130 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | pSMB->MaxSetupCount = 0; |
| 5132 | pSMB->Reserved = 0; |
| 5133 | pSMB->Flags = 0; |
| 5134 | pSMB->Timeout = 0; |
| 5135 | pSMB->Reserved2 = 0; |
| 5136 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5137 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | offset = param_offset + params; |
| 5139 | data_offset = |
| 5140 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 5141 | offset); |
| 5142 | memset(data_offset, 0, count); |
| 5143 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5144 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5145 | pSMB->SetupCount = 1; |
| 5146 | pSMB->Reserved3 = 0; |
| 5147 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5148 | byte_count = 3 /* pad */ + params + count; |
| 5149 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5150 | pSMB->DataCount = cpu_to_le16(count); |
| 5151 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5152 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5153 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5154 | pSMB->Reserved4 = 0; |
| 5155 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | c7af185 | 2007-03-01 04:11:22 +0000 | [diff] [blame] | 5156 | /* Samba server ignores set of file size to zero due to bugs in some |
| 5157 | older clients, but we should be precise - we use SetFileSize to |
| 5158 | set file size and do not want to truncate file size to zero |
| 5159 | accidently as happened on one Samba server beta by putting |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5160 | zero instead of -1 here */ |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5161 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5162 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5163 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5164 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5165 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
| 5166 | data_offset->Uid = cpu_to_le64(args->uid); |
| 5167 | data_offset->Gid = cpu_to_le64(args->gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5168 | /* better to leave device as zero when it is */ |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5169 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5170 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5171 | data_offset->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5172 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5173 | if (S_ISREG(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5175 | else if (S_ISDIR(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5176 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5177 | else if (S_ISLNK(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5179 | else if (S_ISCHR(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5180 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5181 | else if (S_ISBLK(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5183 | else if (S_ISFIFO(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5185 | else if (S_ISSOCK(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5187 | |
| 5188 | |
| 5189 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5190 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5191 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5192 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5193 | cFYI(1, ("SetPathInfo (perms) returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5194 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5195 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5196 | if (rc == -EAGAIN) |
| 5197 | goto setPermsRetry; |
| 5198 | return rc; |
| 5199 | } |
| 5200 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5201 | int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, |
Steve French | 167a251 | 2005-08-24 20:03:11 -0700 | [diff] [blame] | 5202 | const int notify_subdirs, const __u16 netfid, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5203 | __u32 filter, struct file *pfile, int multishot, |
Steve French | 167a251 | 2005-08-24 20:03:11 -0700 | [diff] [blame] | 5204 | const struct nls_table *nls_codepage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | { |
| 5206 | int rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5207 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 5208 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
Steve French | abb15b8 | 2005-08-24 18:51:02 -0700 | [diff] [blame] | 5209 | struct dir_notify_req *dnotify_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | int bytes_returned; |
| 5211 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5212 | cFYI(1, ("In CIFSSMBNotify for file handle %d", (int)netfid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5214 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | if (rc) |
| 5216 | return rc; |
| 5217 | |
| 5218 | pSMB->TotalParameterCount = 0 ; |
| 5219 | pSMB->TotalDataCount = 0; |
| 5220 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 5221 | /* BB find exact data count max from sess structure BB */ |
| 5222 | pSMB->MaxDataCount = 0; /* same in little endian or be */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 5223 | /* BB VERIFY verify which is correct for above BB */ |
| 5224 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 5225 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 5226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5227 | pSMB->MaxSetupCount = 4; |
| 5228 | pSMB->Reserved = 0; |
| 5229 | pSMB->ParameterOffset = 0; |
| 5230 | pSMB->DataCount = 0; |
| 5231 | pSMB->DataOffset = 0; |
| 5232 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 5233 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 5234 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5235 | if (notify_subdirs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 5237 | pSMB->Reserved2 = 0; |
| 5238 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 5239 | pSMB->Fid = netfid; /* file handle always le */ |
| 5240 | pSMB->ByteCount = 0; |
| 5241 | |
| 5242 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 5243 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 5244 | CIFS_ASYNC_OP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5245 | if (rc) { |
| 5246 | cFYI(1, ("Error in Notify = %d", rc)); |
Steve French | ff5dbd9 | 2005-08-24 17:10:36 -0700 | [diff] [blame] | 5247 | } else { |
| 5248 | /* Add file to outstanding requests */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5249 | /* BB change to kmem cache alloc */ |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 5250 | dnotify_req = kmalloc( |
Steve French | 47c786e | 2005-10-11 20:03:18 -0700 | [diff] [blame] | 5251 | sizeof(struct dir_notify_req), |
| 5252 | GFP_KERNEL); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5253 | if (dnotify_req) { |
Steve French | 47c786e | 2005-10-11 20:03:18 -0700 | [diff] [blame] | 5254 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 5255 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 5256 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 5257 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 5258 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 5259 | dnotify_req->netfid = netfid; |
| 5260 | dnotify_req->pfile = pfile; |
| 5261 | dnotify_req->filter = filter; |
| 5262 | dnotify_req->multishot = multishot; |
| 5263 | spin_lock(&GlobalMid_Lock); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5264 | list_add_tail(&dnotify_req->lhead, |
Steve French | 47c786e | 2005-10-11 20:03:18 -0700 | [diff] [blame] | 5265 | &GlobalDnotifyReqList); |
| 5266 | spin_unlock(&GlobalMid_Lock); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5267 | } else |
Steve French | 47c786e | 2005-10-11 20:03:18 -0700 | [diff] [blame] | 5268 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | } |
| 5270 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5271 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | } |
| 5273 | #ifdef CONFIG_CIFS_XATTR |
| 5274 | ssize_t |
| 5275 | CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, |
| 5276 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5277 | char *EAData, size_t buf_size, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5278 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5279 | { |
| 5280 | /* BB assumes one setup word */ |
| 5281 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 5282 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 5283 | int rc = 0; |
| 5284 | int bytes_returned; |
| 5285 | int name_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5286 | struct fea *temp_fea; |
| 5287 | char *temp_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5288 | __u16 params, byte_count; |
| 5289 | |
| 5290 | cFYI(1, ("In Query All EAs path %s", searchName)); |
| 5291 | QAllEAsRetry: |
| 5292 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5293 | (void **) &pSMBr); |
| 5294 | if (rc) |
| 5295 | return rc; |
| 5296 | |
| 5297 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5298 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5299 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5300 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5301 | name_len++; /* trailing null */ |
| 5302 | name_len *= 2; |
| 5303 | } else { /* BB improve the check for buffer overruns BB */ |
| 5304 | name_len = strnlen(searchName, PATH_MAX); |
| 5305 | name_len++; /* trailing null */ |
| 5306 | strncpy(pSMB->FileName, searchName, name_len); |
| 5307 | } |
| 5308 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5309 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5310 | pSMB->TotalDataCount = 0; |
| 5311 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5312 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5313 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5314 | pSMB->MaxSetupCount = 0; |
| 5315 | pSMB->Reserved = 0; |
| 5316 | pSMB->Flags = 0; |
| 5317 | pSMB->Timeout = 0; |
| 5318 | pSMB->Reserved2 = 0; |
| 5319 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5320 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | pSMB->DataCount = 0; |
| 5322 | pSMB->DataOffset = 0; |
| 5323 | pSMB->SetupCount = 1; |
| 5324 | pSMB->Reserved3 = 0; |
| 5325 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 5326 | byte_count = params + 1 /* pad */ ; |
| 5327 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5328 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5329 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 5330 | pSMB->Reserved4 = 0; |
| 5331 | pSMB->hdr.smb_buf_length += byte_count; |
| 5332 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5333 | |
| 5334 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5335 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5336 | if (rc) { |
| 5337 | cFYI(1, ("Send error in QueryAllEAs = %d", rc)); |
| 5338 | } else { /* decode response */ |
| 5339 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5340 | |
| 5341 | /* BB also check enough total bytes returned */ |
| 5342 | /* BB we need to improve the validity checking |
| 5343 | of these trans2 responses */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5344 | if (rc || (pSMBr->ByteCount < 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5345 | rc = -EIO; /* bad smb */ |
| 5346 | /* else if (pFindData){ |
| 5347 | memcpy((char *) pFindData, |
| 5348 | (char *) &pSMBr->hdr.Protocol + |
| 5349 | data_offset, kl); |
| 5350 | }*/ else { |
| 5351 | /* check that length of list is not more than bcc */ |
| 5352 | /* check that each entry does not go beyond length |
| 5353 | of list */ |
| 5354 | /* check that each element of each entry does not |
| 5355 | go beyond end of list */ |
| 5356 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5357 | struct fealist *ea_response_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5358 | rc = 0; |
| 5359 | /* validate_trans2_offsets() */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5360 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | ea_response_data = (struct fealist *) |
| 5362 | (((char *) &pSMBr->hdr.Protocol) + |
| 5363 | data_offset); |
| 5364 | name_len = le32_to_cpu(ea_response_data->list_len); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5365 | cFYI(1, ("ea length %d", name_len)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5366 | if (name_len <= 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5367 | /* returned EA size zeroed at top of function */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5368 | cFYI(1, ("empty EA list returned from server")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | } else { |
| 5370 | /* account for ea list len */ |
| 5371 | name_len -= 4; |
| 5372 | temp_fea = ea_response_data->list; |
| 5373 | temp_ptr = (char *)temp_fea; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5374 | while (name_len > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5375 | __u16 value_len; |
| 5376 | name_len -= 4; |
| 5377 | temp_ptr += 4; |
| 5378 | rc += temp_fea->name_len; |
| 5379 | /* account for prefix user. and trailing null */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5380 | rc = rc + 5 + 1; |
| 5381 | if (rc < (int)buf_size) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5382 | memcpy(EAData, "user.", 5); |
| 5383 | EAData += 5; |
| 5384 | memcpy(EAData, temp_ptr, |
| 5385 | temp_fea->name_len); |
| 5386 | EAData += temp_fea->name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5387 | /* null terminate name */ |
| 5388 | *EAData = 0; |
| 5389 | EAData = EAData + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5390 | } else if (buf_size == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | /* skip copy - calc size only */ |
| 5392 | } else { |
| 5393 | /* stop before overrun buffer */ |
| 5394 | rc = -ERANGE; |
| 5395 | break; |
| 5396 | } |
| 5397 | name_len -= temp_fea->name_len; |
| 5398 | temp_ptr += temp_fea->name_len; |
| 5399 | /* account for trailing null */ |
| 5400 | name_len--; |
| 5401 | temp_ptr++; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5402 | value_len = |
| 5403 | le16_to_cpu(temp_fea->value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | name_len -= value_len; |
| 5405 | temp_ptr += value_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5406 | /* BB check that temp_ptr is still |
| 5407 | within the SMB BB*/ |
| 5408 | |
| 5409 | /* no trailing null to account for |
| 5410 | in value len */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 | /* go on to next EA */ |
| 5412 | temp_fea = (struct fea *)temp_ptr; |
| 5413 | } |
| 5414 | } |
| 5415 | } |
| 5416 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5417 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5418 | if (rc == -EAGAIN) |
| 5419 | goto QAllEAsRetry; |
| 5420 | |
| 5421 | return (ssize_t)rc; |
| 5422 | } |
| 5423 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5424 | ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon, |
| 5425 | const unsigned char *searchName, const unsigned char *ea_name, |
| 5426 | unsigned char *ea_value, size_t buf_size, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5427 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5428 | { |
| 5429 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 5430 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 5431 | int rc = 0; |
| 5432 | int bytes_returned; |
| 5433 | int name_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5434 | struct fea *temp_fea; |
| 5435 | char *temp_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5436 | __u16 params, byte_count; |
| 5437 | |
| 5438 | cFYI(1, ("In Query EA path %s", searchName)); |
| 5439 | QEARetry: |
| 5440 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5441 | (void **) &pSMBr); |
| 5442 | if (rc) |
| 5443 | return rc; |
| 5444 | |
| 5445 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5446 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5447 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5448 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5449 | name_len++; /* trailing null */ |
| 5450 | name_len *= 2; |
| 5451 | } else { /* BB improve the check for buffer overruns BB */ |
| 5452 | name_len = strnlen(searchName, PATH_MAX); |
| 5453 | name_len++; /* trailing null */ |
| 5454 | strncpy(pSMB->FileName, searchName, name_len); |
| 5455 | } |
| 5456 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5457 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | pSMB->TotalDataCount = 0; |
| 5459 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5460 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5461 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5462 | pSMB->MaxSetupCount = 0; |
| 5463 | pSMB->Reserved = 0; |
| 5464 | pSMB->Flags = 0; |
| 5465 | pSMB->Timeout = 0; |
| 5466 | pSMB->Reserved2 = 0; |
| 5467 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5468 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5469 | pSMB->DataCount = 0; |
| 5470 | pSMB->DataOffset = 0; |
| 5471 | pSMB->SetupCount = 1; |
| 5472 | pSMB->Reserved3 = 0; |
| 5473 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 5474 | byte_count = params + 1 /* pad */ ; |
| 5475 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5476 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5477 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 5478 | pSMB->Reserved4 = 0; |
| 5479 | pSMB->hdr.smb_buf_length += byte_count; |
| 5480 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5481 | |
| 5482 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5483 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5484 | if (rc) { |
| 5485 | cFYI(1, ("Send error in Query EA = %d", rc)); |
| 5486 | } else { /* decode response */ |
| 5487 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5488 | |
| 5489 | /* BB also check enough total bytes returned */ |
| 5490 | /* BB we need to improve the validity checking |
| 5491 | of these trans2 responses */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5492 | if (rc || (pSMBr->ByteCount < 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | rc = -EIO; /* bad smb */ |
| 5494 | /* else if (pFindData){ |
| 5495 | memcpy((char *) pFindData, |
| 5496 | (char *) &pSMBr->hdr.Protocol + |
| 5497 | data_offset, kl); |
| 5498 | }*/ else { |
| 5499 | /* check that length of list is not more than bcc */ |
| 5500 | /* check that each entry does not go beyond length |
| 5501 | of list */ |
| 5502 | /* check that each element of each entry does not |
| 5503 | go beyond end of list */ |
| 5504 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5505 | struct fealist *ea_response_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | rc = -ENODATA; |
| 5507 | /* validate_trans2_offsets() */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5508 | /* BB check if start of smb + data_offset > &bcc+ bcc*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | ea_response_data = (struct fealist *) |
| 5510 | (((char *) &pSMBr->hdr.Protocol) + |
| 5511 | data_offset); |
| 5512 | name_len = le32_to_cpu(ea_response_data->list_len); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5513 | cFYI(1, ("ea length %d", name_len)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5514 | if (name_len <= 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | /* returned EA size zeroed at top of function */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5516 | cFYI(1, ("empty EA list returned from server")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5517 | } else { |
| 5518 | /* account for ea list len */ |
| 5519 | name_len -= 4; |
| 5520 | temp_fea = ea_response_data->list; |
| 5521 | temp_ptr = (char *)temp_fea; |
| 5522 | /* loop through checking if we have a matching |
| 5523 | name and then return the associated value */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5524 | while (name_len > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | __u16 value_len; |
| 5526 | name_len -= 4; |
| 5527 | temp_ptr += 4; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5528 | value_len = |
| 5529 | le16_to_cpu(temp_fea->value_len); |
| 5530 | /* BB validate that value_len falls within SMB, |
| 5531 | even though maximum for name_len is 255 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5532 | if (memcmp(temp_fea->name, ea_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | temp_fea->name_len) == 0) { |
| 5534 | /* found a match */ |
| 5535 | rc = value_len; |
| 5536 | /* account for prefix user. and trailing null */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5537 | if (rc <= (int)buf_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | memcpy(ea_value, |
| 5539 | temp_fea->name+temp_fea->name_len+1, |
| 5540 | rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5541 | /* ea values, unlike ea |
| 5542 | names, are not null |
| 5543 | terminated */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5544 | } else if (buf_size == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5545 | /* skip copy - calc size only */ |
| 5546 | } else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5547 | /* stop before overrun buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5548 | rc = -ERANGE; |
| 5549 | } |
| 5550 | break; |
| 5551 | } |
| 5552 | name_len -= temp_fea->name_len; |
| 5553 | temp_ptr += temp_fea->name_len; |
| 5554 | /* account for trailing null */ |
| 5555 | name_len--; |
| 5556 | temp_ptr++; |
| 5557 | name_len -= value_len; |
| 5558 | temp_ptr += value_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5559 | /* No trailing null to account for in |
| 5560 | value_len. Go on to next EA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5561 | temp_fea = (struct fea *)temp_ptr; |
| 5562 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | } |
| 5565 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5566 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | if (rc == -EAGAIN) |
| 5568 | goto QEARetry; |
| 5569 | |
| 5570 | return (ssize_t)rc; |
| 5571 | } |
| 5572 | |
| 5573 | int |
| 5574 | CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5575 | const char *ea_name, const void *ea_value, |
| 5576 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 5577 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | { |
| 5579 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5580 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5581 | struct fealist *parm_data; |
| 5582 | int name_len; |
| 5583 | int rc = 0; |
| 5584 | int bytes_returned = 0; |
| 5585 | __u16 params, param_offset, byte_count, offset, count; |
| 5586 | |
| 5587 | cFYI(1, ("In SetEA")); |
| 5588 | SetEARetry: |
| 5589 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5590 | (void **) &pSMBr); |
| 5591 | if (rc) |
| 5592 | return rc; |
| 5593 | |
| 5594 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5595 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5596 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5597 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | name_len++; /* trailing null */ |
| 5599 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5600 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | name_len = strnlen(fileName, PATH_MAX); |
| 5602 | name_len++; /* trailing null */ |
| 5603 | strncpy(pSMB->FileName, fileName, name_len); |
| 5604 | } |
| 5605 | |
| 5606 | params = 6 + name_len; |
| 5607 | |
| 5608 | /* done calculating parms using name_len of file name, |
| 5609 | now use name_len to calculate length of ea name |
| 5610 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5611 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | name_len = 0; |
| 5613 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5614 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5615 | |
Steve French | dae5dbdb | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 5616 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5618 | /* BB find max SMB PDU from sess */ |
| 5619 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | pSMB->MaxSetupCount = 0; |
| 5621 | pSMB->Reserved = 0; |
| 5622 | pSMB->Flags = 0; |
| 5623 | pSMB->Timeout = 0; |
| 5624 | pSMB->Reserved2 = 0; |
| 5625 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5626 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5627 | offset = param_offset + params; |
| 5628 | pSMB->InformationLevel = |
| 5629 | cpu_to_le16(SMB_SET_FILE_EA); |
| 5630 | |
| 5631 | parm_data = |
| 5632 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 5633 | offset); |
| 5634 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5635 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5636 | pSMB->SetupCount = 1; |
| 5637 | pSMB->Reserved3 = 0; |
| 5638 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5639 | byte_count = 3 /* pad */ + params + count; |
| 5640 | pSMB->DataCount = cpu_to_le16(count); |
| 5641 | parm_data->list_len = cpu_to_le32(count); |
| 5642 | parm_data->list[0].EA_flags = 0; |
| 5643 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 5644 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5645 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5646 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5647 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | parm_data->list[0].name[name_len] = 0; |
| 5649 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 5650 | /* caller ensures that ea_value_len is less than 64K but |
| 5651 | we need to ensure that it fits within the smb */ |
| 5652 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5653 | /*BB add length check to see if it would fit in |
| 5654 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5655 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 5656 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5657 | memcpy(parm_data->list[0].name+name_len+1, |
| 5658 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | |
| 5660 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5661 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5662 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5663 | pSMB->Reserved4 = 0; |
| 5664 | pSMB->hdr.smb_buf_length += byte_count; |
| 5665 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5666 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5667 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5668 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5669 | cFYI(1, ("SetPathInfo (EA) returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5670 | |
| 5671 | cifs_buf_release(pSMB); |
| 5672 | |
| 5673 | if (rc == -EAGAIN) |
| 5674 | goto SetEARetry; |
| 5675 | |
| 5676 | return rc; |
| 5677 | } |
| 5678 | |
| 5679 | #endif |