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 | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 193 | if (tcon->ses->need_reconnect) |
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 | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 196 | if (!rc && (tcon->need_reconnect)) { |
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 | a4544347 | 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) { |
Steve French | bfb59820 | 2008-11-18 16:33:48 +0000 | [diff] [blame] | 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 | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 340 | if (tcon->ses->need_reconnect) |
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 | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 343 | if (!rc && (tcon->need_reconnect)) { |
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 | a4544347 | 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 | } |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 667 | read_lock(&cifs_tcp_ses_lock); |
| 668 | if (server->srv_count > 1) { |
| 669 | read_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 670 | if (memcmp(server->server_GUID, |
| 671 | pSMBr->u.extended_response. |
| 672 | GUID, 16) != 0) { |
| 673 | cFYI(1, ("server UID changed")); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 674 | memcpy(server->server_GUID, |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 675 | pSMBr->u.extended_response.GUID, |
| 676 | 16); |
| 677 | } |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 678 | } else { |
| 679 | read_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 680 | memcpy(server->server_GUID, |
| 681 | pSMBr->u.extended_response.GUID, 16); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 682 | } |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 683 | |
| 684 | if (count == 16) { |
| 685 | server->secType = RawNTLMSSP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 686 | } else { |
| 687 | rc = decode_negTokenInit(pSMBr->u.extended_response. |
| 688 | SecurityBlob, |
| 689 | count - 16, |
| 690 | &server->secType); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 691 | if (rc == 1) |
Jeff Layton | e545937 | 2007-11-03 05:11:06 +0000 | [diff] [blame] | 692 | rc = 0; |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 693 | else |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 694 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 696 | } else |
| 697 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
| 698 | |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 699 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 700 | signing_check: |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 701 | #endif |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 702 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
| 703 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
| 704 | so if this is zero it means that signing is disabled */ |
| 705 | cFYI(1, ("Signing disabled")); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 706 | if (server->secMode & SECMODE_SIGN_REQUIRED) { |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 707 | cERROR(1, ("Server requires " |
Jeff Layton | 7111d21 | 2007-10-16 16:50:25 +0000 | [diff] [blame] | 708 | "packet signing to be enabled in " |
| 709 | "/proc/fs/cifs/SecurityFlags.")); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 710 | rc = -EOPNOTSUPP; |
| 711 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 712 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 713 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 714 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
| 715 | /* signing required */ |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 716 | cFYI(1, ("Must sign - secFlags 0x%x", secFlags)); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 717 | if ((server->secMode & |
| 718 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
| 719 | cERROR(1, |
| 720 | ("signing required but server lacks support")); |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 721 | rc = -EOPNOTSUPP; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 722 | } else |
| 723 | server->secMode |= SECMODE_SIGN_REQUIRED; |
| 724 | } else { |
| 725 | /* signing optional ie CIFSSEC_MAY_SIGN */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 726 | if ((server->secMode & SECMODE_SIGN_REQUIRED) == 0) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 727 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 728 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 730 | |
| 731 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 732 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 733 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 734 | cFYI(1, ("negprot rc %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return rc; |
| 736 | } |
| 737 | |
| 738 | int |
| 739 | CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) |
| 740 | { |
| 741 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
| 744 | cFYI(1, ("In tree disconnect")); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 745 | |
| 746 | /* BB: do we need to check this? These should never be NULL. */ |
| 747 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 748 | return -EIO; |
| 749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 751 | * No need to return error on this operation if tid invalidated and |
| 752 | * closed on server already e.g. due to tcp session crashing. Also, |
| 753 | * the tcon is no longer on the list, so no need to take lock before |
| 754 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | */ |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 756 | if (tcon->need_reconnect) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 757 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 759 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 760 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 761 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 763 | |
| 764 | rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | if (rc) |
Steve French | 966ca92 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 766 | cFYI(1, ("Tree disconnect failed %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 768 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 769 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | if (rc == -EAGAIN) |
| 771 | rc = 0; |
| 772 | |
| 773 | return rc; |
| 774 | } |
| 775 | |
| 776 | int |
| 777 | CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) |
| 778 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | LOGOFF_ANDX_REQ *pSMB; |
| 780 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| 782 | cFYI(1, ("In SMBLogoff for session disconnect")); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 783 | |
| 784 | /* |
| 785 | * BB: do we need to check validity of ses and server? They should |
| 786 | * always be valid since we have an active reference. If not, that |
| 787 | * should probably be a BUG() |
| 788 | */ |
| 789 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | return -EIO; |
| 791 | |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 792 | down(&ses->sesSem); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 793 | if (ses->need_reconnect) |
| 794 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 795 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 797 | if (rc) { |
| 798 | up(&ses->sesSem); |
| 799 | return rc; |
| 800 | } |
| 801 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 802 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 803 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 804 | if (ses->server->secMode & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 806 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
| 808 | pSMB->hdr.Uid = ses->Suid; |
| 809 | |
| 810 | pSMB->AndXCommand = 0xFF; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 811 | rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 812 | session_already_dead: |
Steve French | a59c658 | 2005-08-17 12:12:19 -0700 | [diff] [blame] | 813 | up(&ses->sesSem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 816 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | error */ |
| 818 | if (rc == -EAGAIN) |
| 819 | rc = 0; |
| 820 | return rc; |
| 821 | } |
| 822 | |
| 823 | int |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 824 | CIFSPOSIXDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 825 | __u16 type, const struct nls_table *nls_codepage, int remap) |
| 826 | { |
| 827 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 828 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 829 | struct unlink_psx_rq *pRqD; |
| 830 | int name_len; |
| 831 | int rc = 0; |
| 832 | int bytes_returned = 0; |
| 833 | __u16 params, param_offset, offset, byte_count; |
| 834 | |
| 835 | cFYI(1, ("In POSIX delete")); |
| 836 | PsxDelete: |
| 837 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 838 | (void **) &pSMBr); |
| 839 | if (rc) |
| 840 | return rc; |
| 841 | |
| 842 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 843 | name_len = |
| 844 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
| 845 | PATH_MAX, nls_codepage, remap); |
| 846 | name_len++; /* trailing null */ |
| 847 | name_len *= 2; |
| 848 | } else { /* BB add path length overrun check */ |
| 849 | name_len = strnlen(fileName, PATH_MAX); |
| 850 | name_len++; /* trailing null */ |
| 851 | strncpy(pSMB->FileName, fileName, name_len); |
| 852 | } |
| 853 | |
| 854 | params = 6 + name_len; |
| 855 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 856 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 857 | pSMB->MaxSetupCount = 0; |
| 858 | pSMB->Reserved = 0; |
| 859 | pSMB->Flags = 0; |
| 860 | pSMB->Timeout = 0; |
| 861 | pSMB->Reserved2 = 0; |
| 862 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 863 | InformationLevel) - 4; |
| 864 | offset = param_offset + params; |
| 865 | |
| 866 | /* Setup pointer to Request Data (inode type) */ |
| 867 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 868 | pRqD->type = cpu_to_le16(type); |
| 869 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 870 | pSMB->DataOffset = cpu_to_le16(offset); |
| 871 | pSMB->SetupCount = 1; |
| 872 | pSMB->Reserved3 = 0; |
| 873 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 874 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 875 | |
| 876 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 877 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 878 | pSMB->ParameterCount = cpu_to_le16(params); |
| 879 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 880 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 881 | pSMB->Reserved4 = 0; |
| 882 | pSMB->hdr.smb_buf_length += byte_count; |
| 883 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 884 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 885 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 886 | if (rc) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 887 | cFYI(1, ("Posix delete returned %d", rc)); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 888 | cifs_buf_release(pSMB); |
| 889 | |
| 890 | cifs_stats_inc(&tcon->num_deletes); |
| 891 | |
| 892 | if (rc == -EAGAIN) |
| 893 | goto PsxDelete; |
| 894 | |
| 895 | return rc; |
| 896 | } |
| 897 | |
| 898 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 899 | CIFSSMBDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 900 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | { |
| 902 | DELETE_FILE_REQ *pSMB = NULL; |
| 903 | DELETE_FILE_RSP *pSMBr = NULL; |
| 904 | int rc = 0; |
| 905 | int bytes_returned; |
| 906 | int name_len; |
| 907 | |
| 908 | DelFileRetry: |
| 909 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 910 | (void **) &pSMBr); |
| 911 | if (rc) |
| 912 | return rc; |
| 913 | |
| 914 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 915 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 916 | cifsConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 917 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | name_len++; /* trailing null */ |
| 919 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 920 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | name_len = strnlen(fileName, PATH_MAX); |
| 922 | name_len++; /* trailing null */ |
| 923 | strncpy(pSMB->fileName, fileName, name_len); |
| 924 | } |
| 925 | pSMB->SearchAttributes = |
| 926 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 927 | pSMB->BufferFormat = 0x04; |
| 928 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 929 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 930 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 931 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 932 | cifs_stats_inc(&tcon->num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 933 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | cFYI(1, ("Error in RMFile = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
| 936 | cifs_buf_release(pSMB); |
| 937 | if (rc == -EAGAIN) |
| 938 | goto DelFileRetry; |
| 939 | |
| 940 | return rc; |
| 941 | } |
| 942 | |
| 943 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 944 | CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 945 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { |
| 947 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 948 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 949 | int rc = 0; |
| 950 | int bytes_returned; |
| 951 | int name_len; |
| 952 | |
| 953 | cFYI(1, ("In CIFSSMBRmDir")); |
| 954 | RmDirRetry: |
| 955 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 956 | (void **) &pSMBr); |
| 957 | if (rc) |
| 958 | return rc; |
| 959 | |
| 960 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 961 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, dirName, |
| 962 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | name_len++; /* trailing null */ |
| 964 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 965 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | name_len = strnlen(dirName, PATH_MAX); |
| 967 | name_len++; /* trailing null */ |
| 968 | strncpy(pSMB->DirName, dirName, name_len); |
| 969 | } |
| 970 | |
| 971 | pSMB->BufferFormat = 0x04; |
| 972 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 973 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 974 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 975 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 976 | cifs_stats_inc(&tcon->num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 977 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | cFYI(1, ("Error in RMDir = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
| 980 | cifs_buf_release(pSMB); |
| 981 | if (rc == -EAGAIN) |
| 982 | goto RmDirRetry; |
| 983 | return rc; |
| 984 | } |
| 985 | |
| 986 | int |
| 987 | CIFSSMBMkDir(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 988 | const char *name, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | { |
| 990 | int rc = 0; |
| 991 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 992 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 993 | int bytes_returned; |
| 994 | int name_len; |
| 995 | |
| 996 | cFYI(1, ("In CIFSSMBMkDir")); |
| 997 | MkDirRetry: |
| 998 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 999 | (void **) &pSMBr); |
| 1000 | if (rc) |
| 1001 | return rc; |
| 1002 | |
| 1003 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1004 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1005 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | name_len++; /* trailing null */ |
| 1007 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1008 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | name_len = strnlen(name, PATH_MAX); |
| 1010 | name_len++; /* trailing null */ |
| 1011 | strncpy(pSMB->DirName, name, name_len); |
| 1012 | } |
| 1013 | |
| 1014 | pSMB->BufferFormat = 0x04; |
| 1015 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 1016 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 1017 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1018 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1019 | cifs_stats_inc(&tcon->num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1020 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | cFYI(1, ("Error in Mkdir = %d", rc)); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | cifs_buf_release(pSMB); |
| 1024 | if (rc == -EAGAIN) |
| 1025 | goto MkDirRetry; |
| 1026 | return rc; |
| 1027 | } |
| 1028 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1029 | int |
| 1030 | CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1031 | __u64 mode, __u16 *netfid, FILE_UNIX_BASIC_INFO *pRetData, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1032 | __u32 *pOplock, const char *name, |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1033 | const struct nls_table *nls_codepage, int remap) |
| 1034 | { |
| 1035 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1036 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1037 | int name_len; |
| 1038 | int rc = 0; |
| 1039 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1040 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1041 | OPEN_PSX_REQ *pdata; |
| 1042 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1043 | |
| 1044 | cFYI(1, ("In POSIX Create")); |
| 1045 | PsxCreat: |
| 1046 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1047 | (void **) &pSMBr); |
| 1048 | if (rc) |
| 1049 | return rc; |
| 1050 | |
| 1051 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1052 | name_len = |
| 1053 | cifsConvertToUCS((__le16 *) pSMB->FileName, name, |
| 1054 | PATH_MAX, nls_codepage, remap); |
| 1055 | name_len++; /* trailing null */ |
| 1056 | name_len *= 2; |
| 1057 | } else { /* BB improve the check for buffer overruns BB */ |
| 1058 | name_len = strnlen(name, PATH_MAX); |
| 1059 | name_len++; /* trailing null */ |
| 1060 | strncpy(pSMB->FileName, name, name_len); |
| 1061 | } |
| 1062 | |
| 1063 | params = 6 + name_len; |
| 1064 | count = sizeof(OPEN_PSX_REQ); |
| 1065 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1066 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1067 | pSMB->MaxSetupCount = 0; |
| 1068 | pSMB->Reserved = 0; |
| 1069 | pSMB->Flags = 0; |
| 1070 | pSMB->Timeout = 0; |
| 1071 | pSMB->Reserved2 = 0; |
| 1072 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1073 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1074 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1075 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1076 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1077 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1078 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1079 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1080 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1081 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1082 | pSMB->SetupCount = 1; |
| 1083 | pSMB->Reserved3 = 0; |
| 1084 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1085 | byte_count = 3 /* pad */ + params + count; |
| 1086 | |
| 1087 | pSMB->DataCount = cpu_to_le16(count); |
| 1088 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1089 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1090 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1091 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1092 | pSMB->Reserved4 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1093 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1094 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1095 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1096 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1097 | if (rc) { |
| 1098 | cFYI(1, ("Posix create returned %d", rc)); |
| 1099 | goto psx_create_err; |
| 1100 | } |
| 1101 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1102 | cFYI(1, ("copying inode info")); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1103 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1104 | |
| 1105 | if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) { |
| 1106 | rc = -EIO; /* bad smb */ |
| 1107 | goto psx_create_err; |
| 1108 | } |
| 1109 | |
| 1110 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1111 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1112 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1113 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1114 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1115 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1116 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1117 | /* Let caller know file was created so we can set the mode. */ |
| 1118 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1119 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1120 | *pOplock |= CIFS_CREATE_ACTION; |
| 1121 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1122 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1123 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 1124 | cFYI(DBG2, ("unknown type")); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1125 | } else { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1126 | if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1127 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1128 | cERROR(1, ("Open response data too small")); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1129 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1130 | goto psx_create_err; |
| 1131 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1132 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1133 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1134 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1135 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1136 | |
| 1137 | psx_create_err: |
| 1138 | cifs_buf_release(pSMB); |
| 1139 | |
| 1140 | cifs_stats_inc(&tcon->num_mkdirs); |
| 1141 | |
| 1142 | if (rc == -EAGAIN) |
| 1143 | goto PsxCreat; |
| 1144 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1145 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1148 | static __u16 convert_disposition(int disposition) |
| 1149 | { |
| 1150 | __u16 ofun = 0; |
| 1151 | |
| 1152 | switch (disposition) { |
| 1153 | case FILE_SUPERSEDE: |
| 1154 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1155 | break; |
| 1156 | case FILE_OPEN: |
| 1157 | ofun = SMBOPEN_OAPPEND; |
| 1158 | break; |
| 1159 | case FILE_CREATE: |
| 1160 | ofun = SMBOPEN_OCREATE; |
| 1161 | break; |
| 1162 | case FILE_OPEN_IF: |
| 1163 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1164 | break; |
| 1165 | case FILE_OVERWRITE: |
| 1166 | ofun = SMBOPEN_OTRUNC; |
| 1167 | break; |
| 1168 | case FILE_OVERWRITE_IF: |
| 1169 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1170 | break; |
| 1171 | default: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1172 | cFYI(1, ("unknown disposition %d", disposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1173 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1174 | } |
| 1175 | return ofun; |
| 1176 | } |
| 1177 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1178 | static int |
| 1179 | access_flags_to_smbopen_mode(const int access_flags) |
| 1180 | { |
| 1181 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1182 | |
| 1183 | if (masked_flags == GENERIC_READ) |
| 1184 | return SMBOPEN_READ; |
| 1185 | else if (masked_flags == GENERIC_WRITE) |
| 1186 | return SMBOPEN_WRITE; |
| 1187 | |
| 1188 | /* just go for read/write */ |
| 1189 | return SMBOPEN_READWRITE; |
| 1190 | } |
| 1191 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1192 | int |
| 1193 | SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, |
| 1194 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1195 | const int access_flags, const int create_options, __u16 *netfid, |
| 1196 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1197 | const struct nls_table *nls_codepage, int remap) |
| 1198 | { |
| 1199 | int rc = -EACCES; |
| 1200 | OPENX_REQ *pSMB = NULL; |
| 1201 | OPENX_RSP *pSMBr = NULL; |
| 1202 | int bytes_returned; |
| 1203 | int name_len; |
| 1204 | __u16 count; |
| 1205 | |
| 1206 | OldOpenRetry: |
| 1207 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1208 | (void **) &pSMBr); |
| 1209 | if (rc) |
| 1210 | return rc; |
| 1211 | |
| 1212 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1213 | |
| 1214 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1215 | count = 1; /* account for one byte pad to word boundary */ |
| 1216 | name_len = |
| 1217 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
| 1218 | fileName, PATH_MAX, nls_codepage, remap); |
| 1219 | name_len++; /* trailing null */ |
| 1220 | name_len *= 2; |
| 1221 | } else { /* BB improve check for buffer overruns BB */ |
| 1222 | count = 0; /* no pad */ |
| 1223 | name_len = strnlen(fileName, PATH_MAX); |
| 1224 | name_len++; /* trailing null */ |
| 1225 | strncpy(pSMB->fileName, fileName, name_len); |
| 1226 | } |
| 1227 | if (*pOplock & REQ_OPLOCK) |
| 1228 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1229 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1230 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1231 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1232 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1233 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1234 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1235 | /* set file as system file if special file such |
| 1236 | as fifo and server expecting SFU style and |
| 1237 | no Unix extensions */ |
| 1238 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1239 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1240 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1241 | else /* BB FIXME BB */ |
| 1242 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1243 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1244 | if (create_options & CREATE_OPTION_READONLY) |
| 1245 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1246 | |
| 1247 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1248 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1249 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1250 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1251 | |
| 1252 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1253 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1254 | count += name_len; |
| 1255 | pSMB->hdr.smb_buf_length += count; |
| 1256 | |
| 1257 | pSMB->ByteCount = cpu_to_le16(count); |
| 1258 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1259 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1260 | (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1261 | cifs_stats_inc(&tcon->num_opens); |
| 1262 | if (rc) { |
| 1263 | cFYI(1, ("Error in Open = %d", rc)); |
| 1264 | } else { |
| 1265 | /* BB verify if wct == 15 */ |
| 1266 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1267 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1268 | |
| 1269 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1270 | /* Let caller know file was created so we can set the mode. */ |
| 1271 | /* Do we care about the CreateAction in any other cases? */ |
| 1272 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1273 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1274 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1275 | /* BB FIXME END */ |
| 1276 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1277 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1278 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1279 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1280 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1281 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1282 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1283 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1284 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1285 | pfile_info->AllocationSize = |
| 1286 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1287 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1288 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1289 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | cifs_buf_release(pSMB); |
| 1294 | if (rc == -EAGAIN) |
| 1295 | goto OldOpenRetry; |
| 1296 | return rc; |
| 1297 | } |
| 1298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | int |
| 1300 | CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon, |
| 1301 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1302 | const int access_flags, const int create_options, __u16 *netfid, |
| 1303 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1304 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | { |
| 1306 | int rc = -EACCES; |
| 1307 | OPEN_REQ *pSMB = NULL; |
| 1308 | OPEN_RSP *pSMBr = NULL; |
| 1309 | int bytes_returned; |
| 1310 | int name_len; |
| 1311 | __u16 count; |
| 1312 | |
| 1313 | openRetry: |
| 1314 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, |
| 1315 | (void **) &pSMBr); |
| 1316 | if (rc) |
| 1317 | return rc; |
| 1318 | |
| 1319 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1320 | |
| 1321 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1322 | count = 1; /* account for one byte pad to word boundary */ |
| 1323 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 1324 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1325 | fileName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | name_len++; /* trailing null */ |
| 1327 | name_len *= 2; |
| 1328 | pSMB->NameLength = cpu_to_le16(name_len); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1329 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | count = 0; /* no pad */ |
| 1331 | name_len = strnlen(fileName, PATH_MAX); |
| 1332 | name_len++; /* trailing null */ |
| 1333 | pSMB->NameLength = cpu_to_le16(name_len); |
| 1334 | strncpy(pSMB->fileName, fileName, name_len); |
| 1335 | } |
| 1336 | if (*pOplock & REQ_OPLOCK) |
| 1337 | pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1338 | else if (*pOplock & REQ_BATCHOPLOCK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | pSMB->DesiredAccess = cpu_to_le32(access_flags); |
| 1341 | pSMB->AllocationSize = 0; |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1342 | /* set file as system file if special file such |
| 1343 | as fifo and server expecting SFU style and |
| 1344 | no Unix extensions */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1345 | if (create_options & CREATE_OPTION_SPECIAL) |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1346 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1347 | else |
| 1348 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | /* XP does not handle ATTR_POSIX_SEMANTICS */ |
| 1351 | /* but it helps speed up case sensitive checks for other |
| 1352 | servers such as Samba */ |
| 1353 | if (tcon->ses->capabilities & CAP_UNIX) |
| 1354 | pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
| 1355 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1356 | if (create_options & CREATE_OPTION_READONLY) |
| 1357 | pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
| 1358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1360 | pSMB->CreateDisposition = cpu_to_le32(openDisposition); |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1361 | pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1362 | /* BB Expirement with various impersonation levels and verify */ |
| 1363 | pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | pSMB->SecurityFlags = |
| 1365 | SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY; |
| 1366 | |
| 1367 | count += name_len; |
| 1368 | pSMB->hdr.smb_buf_length += count; |
| 1369 | |
| 1370 | pSMB->ByteCount = cpu_to_le16(count); |
| 1371 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1372 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1373 | (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1374 | cifs_stats_inc(&tcon->num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | if (rc) { |
| 1376 | cFYI(1, ("Error in Open = %d", rc)); |
| 1377 | } else { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1378 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1380 | /* Let caller know file was created so we can set the mode. */ |
| 1381 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1382 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1383 | *pOplock |= CIFS_CREATE_ACTION; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1384 | if (pfile_info) { |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1385 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
| 1386 | 36 /* CreationTime to Attributes */); |
| 1387 | /* the file_info buf is endian converted by caller */ |
| 1388 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
| 1389 | pfile_info->EndOfFile = pSMBr->EndOfFile; |
| 1390 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
| 1391 | pfile_info->DeletePending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | cifs_buf_release(pSMB); |
| 1396 | if (rc == -EAGAIN) |
| 1397 | goto openRetry; |
| 1398 | return rc; |
| 1399 | } |
| 1400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1402 | CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, |
| 1403 | const unsigned int count, const __u64 lseek, unsigned int *nbytes, |
| 1404 | char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | { |
| 1406 | int rc = -EACCES; |
| 1407 | READ_REQ *pSMB = NULL; |
| 1408 | READ_RSP *pSMBr = NULL; |
| 1409 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1410 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1411 | int resp_buf_type = 0; |
| 1412 | struct kvec iov[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1414 | cFYI(1, ("Reading %d bytes on fid %d", count, netfid)); |
| 1415 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1416 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1417 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1418 | wct = 10; /* old style read */ |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1419 | if ((lseek >> 32) > 0) { |
| 1420 | /* can not handle this big offset for old */ |
| 1421 | return -EIO; |
| 1422 | } |
| 1423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | |
| 1425 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1426 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | if (rc) |
| 1428 | return rc; |
| 1429 | |
| 1430 | /* tcon and ses pointer are checked in smb_init */ |
| 1431 | if (tcon->ses->server == NULL) |
| 1432 | return -ECONNABORTED; |
| 1433 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1434 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | pSMB->Fid = netfid; |
| 1436 | pSMB->OffsetLow = cpu_to_le32(lseek & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1437 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1438 | pSMB->OffsetHigh = cpu_to_le32(lseek >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | pSMB->Remaining = 0; |
| 1441 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1442 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1443 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1444 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1445 | else { |
| 1446 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1447 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1448 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1449 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1450 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1451 | |
| 1452 | iov[0].iov_base = (char *)pSMB; |
| 1453 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 1454 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1455 | &resp_buf_type, CIFS_STD_OP | CIFS_LOG_ERROR); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1456 | cifs_stats_inc(&tcon->num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1457 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | if (rc) { |
| 1459 | cERROR(1, ("Send error in read = %d", rc)); |
| 1460 | } else { |
| 1461 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1462 | data_length = data_length << 16; |
| 1463 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1464 | *nbytes = data_length; |
| 1465 | |
| 1466 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1467 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | || (data_length > count)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1469 | cFYI(1, ("bad length %d for count %d", |
| 1470 | data_length, count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | rc = -EIO; |
| 1472 | *nbytes = 0; |
| 1473 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1474 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1475 | le16_to_cpu(pSMBr->DataOffset); |
| 1476 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1477 | cERROR(1,("Faulting on read rc = %d",rc)); |
| 1478 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1479 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1480 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1481 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | } |
| 1483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1485 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1486 | if (*buf) { |
| 1487 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1488 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1489 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1490 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1491 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1492 | /* return buffer to caller to free */ |
| 1493 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1494 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1495 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1496 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1497 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1498 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1499 | |
| 1500 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | since file handle passed in no longer valid */ |
| 1502 | return rc; |
| 1503 | } |
| 1504 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | int |
| 1507 | CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, |
| 1508 | const int netfid, const unsigned int count, |
| 1509 | const __u64 offset, unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1510 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | { |
| 1512 | int rc = -EACCES; |
| 1513 | WRITE_REQ *pSMB = NULL; |
| 1514 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1515 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | __u32 bytes_sent; |
| 1517 | __u16 byte_count; |
| 1518 | |
Steve French | 61de800 | 2008-10-30 20:15:22 +0000 | [diff] [blame] | 1519 | /* cFYI(1, ("write at %lld %d bytes", offset, count));*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1520 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1521 | return -ECONNABORTED; |
| 1522 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1523 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1524 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1525 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1526 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1527 | if ((offset >> 32) > 0) { |
| 1528 | /* can not handle big offset for old srv */ |
| 1529 | return -EIO; |
| 1530 | } |
| 1531 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1532 | |
| 1533 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | (void **) &pSMBr); |
| 1535 | if (rc) |
| 1536 | return rc; |
| 1537 | /* tcon and ses pointer are checked in smb_init */ |
| 1538 | if (tcon->ses->server == NULL) |
| 1539 | return -ECONNABORTED; |
| 1540 | |
| 1541 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1542 | pSMB->Fid = netfid; |
| 1543 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1544 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1545 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | pSMB->Reserved = 0xFFFFFFFF; |
| 1548 | pSMB->WriteMode = 0; |
| 1549 | pSMB->Remaining = 0; |
| 1550 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1551 | /* 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] | 1552 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1553 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1554 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1555 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1557 | } else { |
| 1558 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1559 | & ~0xFF; |
| 1560 | } |
| 1561 | |
| 1562 | if (bytes_sent > count) |
| 1563 | bytes_sent = count; |
| 1564 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1565 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1566 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1567 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1568 | else if (ubuf) { |
| 1569 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | cifs_buf_release(pSMB); |
| 1571 | return -EFAULT; |
| 1572 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1573 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | /* No buffer */ |
| 1575 | cifs_buf_release(pSMB); |
| 1576 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1577 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1578 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1579 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1580 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1581 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1584 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1585 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1586 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1587 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1588 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1589 | else { /* old style write has byte count 4 bytes earlier |
| 1590 | so 4 bytes pad */ |
| 1591 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1592 | (struct smb_com_writex_req *)pSMB; |
| 1593 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
| 1596 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1597 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1598 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | if (rc) { |
| 1600 | cFYI(1, ("Send error in write = %d", rc)); |
| 1601 | *nbytes = 0; |
| 1602 | } else { |
| 1603 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1604 | *nbytes = (*nbytes) << 16; |
| 1605 | *nbytes += le16_to_cpu(pSMBr->Count); |
| 1606 | } |
| 1607 | |
| 1608 | cifs_buf_release(pSMB); |
| 1609 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1610 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | since file handle passed in no longer valid */ |
| 1612 | |
| 1613 | return rc; |
| 1614 | } |
| 1615 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1616 | int |
| 1617 | CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | const int netfid, const unsigned int count, |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1619 | const __u64 offset, unsigned int *nbytes, struct kvec *iov, |
| 1620 | int n_vec, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | { |
| 1622 | int rc = -EACCES; |
| 1623 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1624 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1625 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1626 | int resp_buf_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1628 | cFYI(1, ("write2 at %lld %d bytes", (long long)offset, count)); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 1629 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1630 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1631 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1632 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1633 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1634 | if ((offset >> 32) > 0) { |
| 1635 | /* can not handle big offset for old srv */ |
| 1636 | return -EIO; |
| 1637 | } |
| 1638 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1639 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | if (rc) |
| 1641 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | /* tcon and ses pointer are checked in smb_init */ |
| 1643 | if (tcon->ses->server == NULL) |
| 1644 | return -ECONNABORTED; |
| 1645 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1646 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | pSMB->Fid = netfid; |
| 1648 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1649 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1650 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | pSMB->Reserved = 0xFFFFFFFF; |
| 1652 | pSMB->WriteMode = 0; |
| 1653 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1656 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1658 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 1659 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1660 | 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] | 1661 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1662 | pSMB->hdr.smb_buf_length += count+1; |
| 1663 | else /* wct == 12 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1664 | pSMB->hdr.smb_buf_length += count+5; /* smb data starts later */ |
| 1665 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1666 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 1667 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1668 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1669 | (struct smb_com_writex_req *)pSMB; |
| 1670 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 1671 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1672 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1673 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1674 | iov[0].iov_len = smb_hdr_len + 4; |
| 1675 | else /* wct == 12 pad bigger by four bytes */ |
| 1676 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1677 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1678 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1679 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1680 | long_op); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1681 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | if (rc) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1683 | cFYI(1, ("Send error Write2 = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | *nbytes = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1685 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1686 | /* presumably this can not happen, but best to be safe */ |
| 1687 | rc = -EIO; |
| 1688 | *nbytes = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1689 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1690 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1691 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1692 | *nbytes = (*nbytes) << 16; |
| 1693 | *nbytes += le16_to_cpu(pSMBr->Count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1696 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1697 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1698 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1699 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1700 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1702 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | since file handle passed in no longer valid */ |
| 1704 | |
| 1705 | return rc; |
| 1706 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1707 | |
| 1708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | int |
| 1710 | CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, |
| 1711 | const __u16 smb_file_id, const __u64 len, |
| 1712 | const __u64 offset, const __u32 numUnlock, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1713 | const __u32 numLock, const __u8 lockType, const bool waitFlag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | { |
| 1715 | int rc = 0; |
| 1716 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 1717 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | int bytes_returned; |
| 1719 | int timeout = 0; |
| 1720 | __u16 count; |
| 1721 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1722 | cFYI(1, ("CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock)); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 1723 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 1724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | if (rc) |
| 1726 | return rc; |
| 1727 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1728 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1729 | timeout = CIFS_ASYNC_OP; /* no response expected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1731 | } else if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1732 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 1734 | } else { |
| 1735 | pSMB->Timeout = 0; |
| 1736 | } |
| 1737 | |
| 1738 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 1739 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 1740 | pSMB->LockType = lockType; |
| 1741 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1742 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 1743 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1744 | if ((numLock != 0) || (numUnlock != 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | pSMB->Locks[0].Pid = cpu_to_le16(current->tgid); |
| 1746 | /* BB where to store pid high? */ |
| 1747 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 1748 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 1749 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 1750 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 1751 | count = sizeof(LOCKING_ANDX_RANGE); |
| 1752 | } else { |
| 1753 | /* oplock break */ |
| 1754 | count = 0; |
| 1755 | } |
| 1756 | pSMB->hdr.smb_buf_length += count; |
| 1757 | pSMB->ByteCount = cpu_to_le16(count); |
| 1758 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1759 | if (waitFlag) { |
| 1760 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 1761 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1762 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1763 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1764 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *)pSMB, |
| 1765 | timeout); |
| 1766 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1767 | } |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1768 | cifs_stats_inc(&tcon->num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1769 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | cFYI(1, ("Send error in Lock = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1772 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | since file handle passed in no longer valid */ |
| 1774 | return rc; |
| 1775 | } |
| 1776 | |
| 1777 | int |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1778 | CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, |
| 1779 | const __u16 smb_file_id, const int get_flag, const __u64 len, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1780 | struct file_lock *pLockData, const __u16 lock_type, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1781 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1782 | { |
| 1783 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 1784 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1785 | struct cifs_posix_lock *parm_data; |
| 1786 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 1787 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1788 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1789 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1790 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1791 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1792 | |
| 1793 | cFYI(1, ("Posix Lock")); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1794 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1795 | if (pLockData == NULL) |
Marcin Slusarz | ed5f037 | 2008-05-13 04:01:01 +0000 | [diff] [blame] | 1796 | return -EINVAL; |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1797 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1798 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 1799 | |
| 1800 | if (rc) |
| 1801 | return rc; |
| 1802 | |
| 1803 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 1804 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1805 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1806 | pSMB->MaxSetupCount = 0; |
| 1807 | pSMB->Reserved = 0; |
| 1808 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1809 | pSMB->Reserved2 = 0; |
| 1810 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 1811 | offset = param_offset + params; |
| 1812 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1813 | count = sizeof(struct cifs_posix_lock); |
| 1814 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1815 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1816 | pSMB->SetupCount = 1; |
| 1817 | pSMB->Reserved3 = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1818 | if (get_flag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1819 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 1820 | else |
| 1821 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 1822 | byte_count = 3 /* pad */ + params + count; |
| 1823 | pSMB->DataCount = cpu_to_le16(count); |
| 1824 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1825 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1826 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1827 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1828 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1829 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 1830 | |
| 1831 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1832 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1833 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 1834 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 1835 | pSMB->Timeout = cpu_to_le32(-1); |
| 1836 | } else |
| 1837 | pSMB->Timeout = 0; |
| 1838 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1839 | parm_data->pid = cpu_to_le32(current->tgid); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1840 | parm_data->start = cpu_to_le64(pLockData->fl_start); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 1841 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1842 | |
| 1843 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 1844 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1845 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 1846 | pSMB->Reserved4 = 0; |
| 1847 | pSMB->hdr.smb_buf_length += byte_count; |
| 1848 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1849 | if (waitFlag) { |
| 1850 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 1851 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 1852 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1853 | iov[0].iov_base = (char *)pSMB; |
| 1854 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
| 1855 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 1856 | &resp_buf_type, timeout); |
| 1857 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 1858 | not try to free it twice below on exit */ |
| 1859 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1862 | if (rc) { |
| 1863 | cFYI(1, ("Send error in Posix Lock = %d", rc)); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1864 | } else if (get_flag) { |
| 1865 | /* lock structure can be returned on get */ |
| 1866 | __u16 data_offset; |
| 1867 | __u16 data_count; |
| 1868 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1869 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1870 | if (rc || (pSMBr->ByteCount < sizeof(struct cifs_posix_lock))) { |
| 1871 | rc = -EIO; /* bad smb */ |
| 1872 | goto plk_err_exit; |
| 1873 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1874 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 1875 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1876 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1877 | rc = -EIO; |
| 1878 | goto plk_err_exit; |
| 1879 | } |
| 1880 | parm_data = (struct cifs_posix_lock *) |
| 1881 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1882 | if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1883 | pLockData->fl_type = F_UNLCK; |
| 1884 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1885 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1886 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1887 | if (pSMB) |
| 1888 | cifs_small_buf_release(pSMB); |
| 1889 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1890 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 1891 | cifs_small_buf_release(iov[0].iov_base); |
| 1892 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 1893 | cifs_buf_release(iov[0].iov_base); |
| 1894 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1895 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 1896 | since file handle passed in no longer valid */ |
| 1897 | |
| 1898 | return rc; |
| 1899 | } |
| 1900 | |
| 1901 | |
| 1902 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) |
| 1904 | { |
| 1905 | int rc = 0; |
| 1906 | CLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | cFYI(1, ("In CIFSSMBClose")); |
| 1908 | |
| 1909 | /* do not retry on dead session on close */ |
| 1910 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1911 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | return 0; |
| 1913 | if (rc) |
| 1914 | return rc; |
| 1915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 1917 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1919 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1920 | cifs_stats_inc(&tcon->num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1922 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | /* EINTR is expected when user ctl-c to kill app */ |
| 1924 | cERROR(1, ("Send error in Close = %d", rc)); |
| 1925 | } |
| 1926 | } |
| 1927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | /* Since session is dead, file will be closed on server already */ |
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 | rc = 0; |
| 1931 | |
| 1932 | return rc; |
| 1933 | } |
| 1934 | |
| 1935 | int |
| 1936 | CIFSSMBRename(const int xid, struct cifsTconInfo *tcon, |
| 1937 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1938 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | { |
| 1940 | int rc = 0; |
| 1941 | RENAME_REQ *pSMB = NULL; |
| 1942 | RENAME_RSP *pSMBr = NULL; |
| 1943 | int bytes_returned; |
| 1944 | int name_len, name_len2; |
| 1945 | __u16 count; |
| 1946 | |
| 1947 | cFYI(1, ("In CIFSSMBRename")); |
| 1948 | renameRetry: |
| 1949 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 1950 | (void **) &pSMBr); |
| 1951 | if (rc) |
| 1952 | return rc; |
| 1953 | |
| 1954 | pSMB->BufferFormat = 0x04; |
| 1955 | pSMB->SearchAttributes = |
| 1956 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 1957 | ATTR_DIRECTORY); |
| 1958 | |
| 1959 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1960 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1961 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1962 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | name_len++; /* trailing null */ |
| 1964 | name_len *= 2; |
| 1965 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 1966 | /* protocol requires ASCII signature byte on Unicode string */ |
| 1967 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 1968 | name_len2 = |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1969 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1970 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 1972 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1973 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | name_len = strnlen(fromName, PATH_MAX); |
| 1975 | name_len++; /* trailing null */ |
| 1976 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 1977 | name_len2 = strnlen(toName, PATH_MAX); |
| 1978 | name_len2++; /* trailing null */ |
| 1979 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 1980 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 1981 | name_len2++; /* trailing null */ |
| 1982 | name_len2++; /* signature byte */ |
| 1983 | } |
| 1984 | |
| 1985 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
| 1986 | pSMB->hdr.smb_buf_length += count; |
| 1987 | pSMB->ByteCount = cpu_to_le16(count); |
| 1988 | |
| 1989 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1990 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1991 | cifs_stats_inc(&tcon->num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1992 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | cFYI(1, ("Send error in rename = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | cifs_buf_release(pSMB); |
| 1996 | |
| 1997 | if (rc == -EAGAIN) |
| 1998 | goto renameRetry; |
| 1999 | |
| 2000 | return rc; |
| 2001 | } |
| 2002 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2003 | int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2004 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2005 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | { |
| 2007 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2008 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2009 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | char *data_offset; |
| 2011 | char dummy_string[30]; |
| 2012 | int rc = 0; |
| 2013 | int bytes_returned = 0; |
| 2014 | int len_of_str; |
| 2015 | __u16 params, param_offset, offset, count, byte_count; |
| 2016 | |
| 2017 | cFYI(1, ("Rename to File by handle")); |
| 2018 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2019 | (void **) &pSMBr); |
| 2020 | if (rc) |
| 2021 | return rc; |
| 2022 | |
| 2023 | params = 6; |
| 2024 | pSMB->MaxSetupCount = 0; |
| 2025 | pSMB->Reserved = 0; |
| 2026 | pSMB->Flags = 0; |
| 2027 | pSMB->Timeout = 0; |
| 2028 | pSMB->Reserved2 = 0; |
| 2029 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2030 | offset = param_offset + params; |
| 2031 | |
| 2032 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2033 | rename_info = (struct set_file_rename *) data_offset; |
| 2034 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2035 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | pSMB->SetupCount = 1; |
| 2037 | pSMB->Reserved3 = 0; |
| 2038 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2039 | byte_count = 3 /* pad */ + params; |
| 2040 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2041 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2042 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2043 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2044 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2045 | rename_info->overwrite = cpu_to_le32(1); |
| 2046 | rename_info->root_fid = 0; |
| 2047 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2048 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2049 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
| 2050 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2051 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | } else { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2053 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2054 | target_name, PATH_MAX, nls_codepage, |
| 2055 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | } |
| 2057 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2058 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | byte_count += count; |
| 2060 | pSMB->DataCount = cpu_to_le16(count); |
| 2061 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2062 | pSMB->Fid = netfid; |
| 2063 | pSMB->InformationLevel = |
| 2064 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2065 | pSMB->Reserved4 = 0; |
| 2066 | pSMB->hdr.smb_buf_length += byte_count; |
| 2067 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2068 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2069 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2070 | cifs_stats_inc(&pTcon->num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2071 | if (rc) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2072 | cFYI(1, ("Send error in Rename (by file handle) = %d", rc)); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | cifs_buf_release(pSMB); |
| 2075 | |
| 2076 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2077 | since file handle passed in no longer valid */ |
| 2078 | |
| 2079 | return rc; |
| 2080 | } |
| 2081 | |
| 2082 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2083 | CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char *fromName, |
| 2084 | const __u16 target_tid, const char *toName, const int flags, |
| 2085 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | { |
| 2087 | int rc = 0; |
| 2088 | COPY_REQ *pSMB = NULL; |
| 2089 | COPY_RSP *pSMBr = NULL; |
| 2090 | int bytes_returned; |
| 2091 | int name_len, name_len2; |
| 2092 | __u16 count; |
| 2093 | |
| 2094 | cFYI(1, ("In CIFSSMBCopy")); |
| 2095 | copyRetry: |
| 2096 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2097 | (void **) &pSMBr); |
| 2098 | if (rc) |
| 2099 | return rc; |
| 2100 | |
| 2101 | pSMB->BufferFormat = 0x04; |
| 2102 | pSMB->Tid2 = target_tid; |
| 2103 | |
| 2104 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2105 | |
| 2106 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2107 | name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2108 | fromName, PATH_MAX, nls_codepage, |
| 2109 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | name_len++; /* trailing null */ |
| 2111 | name_len *= 2; |
| 2112 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2113 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2114 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2115 | name_len2 = |
| 2116 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2117 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2119 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2120 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | name_len = strnlen(fromName, PATH_MAX); |
| 2122 | name_len++; /* trailing null */ |
| 2123 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2124 | name_len2 = strnlen(toName, PATH_MAX); |
| 2125 | name_len2++; /* trailing null */ |
| 2126 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2127 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2128 | name_len2++; /* trailing null */ |
| 2129 | name_len2++; /* signature byte */ |
| 2130 | } |
| 2131 | |
| 2132 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
| 2133 | pSMB->hdr.smb_buf_length += count; |
| 2134 | pSMB->ByteCount = cpu_to_le16(count); |
| 2135 | |
| 2136 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2137 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2138 | if (rc) { |
| 2139 | cFYI(1, ("Send error in copy = %d with %d files copied", |
| 2140 | rc, le16_to_cpu(pSMBr->CopyCount))); |
| 2141 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2142 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | |
| 2144 | if (rc == -EAGAIN) |
| 2145 | goto copyRetry; |
| 2146 | |
| 2147 | return rc; |
| 2148 | } |
| 2149 | |
| 2150 | int |
| 2151 | CIFSUnixCreateSymLink(const int xid, struct cifsTconInfo *tcon, |
| 2152 | const char *fromName, const char *toName, |
| 2153 | const struct nls_table *nls_codepage) |
| 2154 | { |
| 2155 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2156 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2157 | char *data_offset; |
| 2158 | int name_len; |
| 2159 | int name_len_target; |
| 2160 | int rc = 0; |
| 2161 | int bytes_returned = 0; |
| 2162 | __u16 params, param_offset, offset, byte_count; |
| 2163 | |
| 2164 | cFYI(1, ("In Symlink Unix style")); |
| 2165 | createSymLinkRetry: |
| 2166 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2167 | (void **) &pSMBr); |
| 2168 | if (rc) |
| 2169 | return rc; |
| 2170 | |
| 2171 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2172 | name_len = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2173 | cifs_strtoUCS((__le16 *) pSMB->FileName, fromName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | /* find define for this maxpathcomponent */ |
| 2175 | , nls_codepage); |
| 2176 | name_len++; /* trailing null */ |
| 2177 | name_len *= 2; |
| 2178 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2179 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | name_len = strnlen(fromName, PATH_MAX); |
| 2181 | name_len++; /* trailing null */ |
| 2182 | strncpy(pSMB->FileName, fromName, name_len); |
| 2183 | } |
| 2184 | params = 6 + name_len; |
| 2185 | pSMB->MaxSetupCount = 0; |
| 2186 | pSMB->Reserved = 0; |
| 2187 | pSMB->Flags = 0; |
| 2188 | pSMB->Timeout = 0; |
| 2189 | pSMB->Reserved2 = 0; |
| 2190 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2191 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | offset = param_offset + params; |
| 2193 | |
| 2194 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2195 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2196 | name_len_target = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2197 | cifs_strtoUCS((__le16 *) data_offset, toName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | /* find define for this maxpathcomponent */ |
| 2199 | , nls_codepage); |
| 2200 | name_len_target++; /* trailing null */ |
| 2201 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2202 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | name_len_target = strnlen(toName, PATH_MAX); |
| 2204 | name_len_target++; /* trailing null */ |
| 2205 | strncpy(data_offset, toName, name_len_target); |
| 2206 | } |
| 2207 | |
| 2208 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2209 | /* BB find exact max on data count below from sess */ |
| 2210 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2211 | pSMB->SetupCount = 1; |
| 2212 | pSMB->Reserved3 = 0; |
| 2213 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2214 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2215 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2216 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2217 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2218 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2219 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2220 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2221 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2222 | pSMB->Reserved4 = 0; |
| 2223 | pSMB->hdr.smb_buf_length += byte_count; |
| 2224 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2225 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2226 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2227 | cifs_stats_inc(&tcon->num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2228 | if (rc) |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 2229 | cFYI(1, ("Send error in SetPathInfo create symlink = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2231 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | |
| 2233 | if (rc == -EAGAIN) |
| 2234 | goto createSymLinkRetry; |
| 2235 | |
| 2236 | return rc; |
| 2237 | } |
| 2238 | |
| 2239 | int |
| 2240 | CIFSUnixCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2241 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2242 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | { |
| 2244 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2245 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2246 | char *data_offset; |
| 2247 | int name_len; |
| 2248 | int name_len_target; |
| 2249 | int rc = 0; |
| 2250 | int bytes_returned = 0; |
| 2251 | __u16 params, param_offset, offset, byte_count; |
| 2252 | |
| 2253 | cFYI(1, ("In Create Hard link Unix style")); |
| 2254 | createHardLinkRetry: |
| 2255 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2256 | (void **) &pSMBr); |
| 2257 | if (rc) |
| 2258 | return rc; |
| 2259 | |
| 2260 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2261 | name_len = cifsConvertToUCS((__le16 *) pSMB->FileName, toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2262 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | name_len++; /* trailing null */ |
| 2264 | name_len *= 2; |
| 2265 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2266 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | name_len = strnlen(toName, PATH_MAX); |
| 2268 | name_len++; /* trailing null */ |
| 2269 | strncpy(pSMB->FileName, toName, name_len); |
| 2270 | } |
| 2271 | params = 6 + name_len; |
| 2272 | pSMB->MaxSetupCount = 0; |
| 2273 | pSMB->Reserved = 0; |
| 2274 | pSMB->Flags = 0; |
| 2275 | pSMB->Timeout = 0; |
| 2276 | pSMB->Reserved2 = 0; |
| 2277 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2278 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | offset = param_offset + params; |
| 2280 | |
| 2281 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2282 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2283 | name_len_target = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2284 | cifsConvertToUCS((__le16 *) data_offset, fromName, PATH_MAX, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2285 | nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | name_len_target++; /* trailing null */ |
| 2287 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2288 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2290 | name_len_target++; /* trailing null */ |
| 2291 | strncpy(data_offset, fromName, name_len_target); |
| 2292 | } |
| 2293 | |
| 2294 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2295 | /* BB find exact max on data count below from sess*/ |
| 2296 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2297 | pSMB->SetupCount = 1; |
| 2298 | pSMB->Reserved3 = 0; |
| 2299 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2300 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2301 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2302 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2303 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2304 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2305 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2306 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2307 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2308 | pSMB->Reserved4 = 0; |
| 2309 | pSMB->hdr.smb_buf_length += byte_count; |
| 2310 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2311 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2312 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2313 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2314 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | cFYI(1, ("Send error in SetPathInfo (hard link) = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | |
| 2317 | cifs_buf_release(pSMB); |
| 2318 | if (rc == -EAGAIN) |
| 2319 | goto createHardLinkRetry; |
| 2320 | |
| 2321 | return rc; |
| 2322 | } |
| 2323 | |
| 2324 | int |
| 2325 | CIFSCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2326 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2327 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | { |
| 2329 | int rc = 0; |
| 2330 | NT_RENAME_REQ *pSMB = NULL; |
| 2331 | RENAME_RSP *pSMBr = NULL; |
| 2332 | int bytes_returned; |
| 2333 | int name_len, name_len2; |
| 2334 | __u16 count; |
| 2335 | |
| 2336 | cFYI(1, ("In CIFSCreateHardLink")); |
| 2337 | winCreateHardLinkRetry: |
| 2338 | |
| 2339 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2340 | (void **) &pSMBr); |
| 2341 | if (rc) |
| 2342 | return rc; |
| 2343 | |
| 2344 | pSMB->SearchAttributes = |
| 2345 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2346 | ATTR_DIRECTORY); |
| 2347 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 2348 | pSMB->ClusterCount = 0; |
| 2349 | |
| 2350 | pSMB->BufferFormat = 0x04; |
| 2351 | |
| 2352 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2353 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2354 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2355 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | name_len++; /* trailing null */ |
| 2357 | name_len *= 2; |
| 2358 | pSMB->OldFileName[name_len] = 0; /* pad */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2359 | pSMB->OldFileName[name_len + 1] = 0x04; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | name_len2 = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2361 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2362 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2364 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2365 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | name_len = strnlen(fromName, PATH_MAX); |
| 2367 | name_len++; /* trailing null */ |
| 2368 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2369 | name_len2 = strnlen(toName, PATH_MAX); |
| 2370 | name_len2++; /* trailing null */ |
| 2371 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2372 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2373 | name_len2++; /* trailing null */ |
| 2374 | name_len2++; /* signature byte */ |
| 2375 | } |
| 2376 | |
| 2377 | count = 1 /* string type byte */ + name_len + name_len2; |
| 2378 | pSMB->hdr.smb_buf_length += count; |
| 2379 | pSMB->ByteCount = cpu_to_le16(count); |
| 2380 | |
| 2381 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2382 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2383 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2384 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | cFYI(1, ("Send error in hard link (NT rename) = %d", rc)); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | cifs_buf_release(pSMB); |
| 2388 | if (rc == -EAGAIN) |
| 2389 | goto winCreateHardLinkRetry; |
| 2390 | |
| 2391 | return rc; |
| 2392 | } |
| 2393 | |
| 2394 | int |
| 2395 | CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon, |
| 2396 | const unsigned char *searchName, |
| 2397 | char *symlinkinfo, const int buflen, |
| 2398 | const struct nls_table *nls_codepage) |
| 2399 | { |
| 2400 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 2401 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2402 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2403 | int rc = 0; |
| 2404 | int bytes_returned; |
| 2405 | int name_len; |
| 2406 | __u16 params, byte_count; |
| 2407 | |
| 2408 | cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName)); |
| 2409 | |
| 2410 | querySymLinkRetry: |
| 2411 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2412 | (void **) &pSMBr); |
| 2413 | if (rc) |
| 2414 | return rc; |
| 2415 | |
| 2416 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2417 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2418 | cifs_strtoUCS((__le16 *) pSMB->FileName, searchName, |
| 2419 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | name_len++; /* trailing null */ |
| 2421 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2422 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | name_len = strnlen(searchName, PATH_MAX); |
| 2424 | name_len++; /* trailing null */ |
| 2425 | strncpy(pSMB->FileName, searchName, name_len); |
| 2426 | } |
| 2427 | |
| 2428 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 2429 | pSMB->TotalDataCount = 0; |
| 2430 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2431 | /* BB find exact max data count below from sess structure BB */ |
| 2432 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 2433 | pSMB->MaxSetupCount = 0; |
| 2434 | pSMB->Reserved = 0; |
| 2435 | pSMB->Flags = 0; |
| 2436 | pSMB->Timeout = 0; |
| 2437 | pSMB->Reserved2 = 0; |
| 2438 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2439 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | pSMB->DataCount = 0; |
| 2441 | pSMB->DataOffset = 0; |
| 2442 | pSMB->SetupCount = 1; |
| 2443 | pSMB->Reserved3 = 0; |
| 2444 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 2445 | byte_count = params + 1 /* pad */ ; |
| 2446 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 2447 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2448 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 2449 | pSMB->Reserved4 = 0; |
| 2450 | pSMB->hdr.smb_buf_length += byte_count; |
| 2451 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2452 | |
| 2453 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2454 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2455 | if (rc) { |
| 2456 | cFYI(1, ("Send error in QuerySymLinkInfo = %d", rc)); |
| 2457 | } else { |
| 2458 | /* decode response */ |
| 2459 | |
| 2460 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 2461 | if (rc || (pSMBr->ByteCount < 2)) |
| 2462 | /* BB also check enough total bytes returned */ |
| 2463 | rc = -EIO; /* bad smb */ |
| 2464 | else { |
| 2465 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2466 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 2467 | |
| 2468 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2469 | name_len = UniStrnlen((wchar_t *) ((char *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2470 | &pSMBr->hdr.Protocol + data_offset), |
| 2471 | min_t(const int, buflen, count) / 2); |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2472 | /* BB FIXME investigate remapping reserved chars here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | cifs_strfromUCS_le(symlinkinfo, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2474 | (__le16 *) ((char *)&pSMBr->hdr.Protocol |
| 2475 | + data_offset), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | name_len, nls_codepage); |
| 2477 | } else { |
| 2478 | strncpy(symlinkinfo, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2479 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | data_offset, |
| 2481 | min_t(const int, buflen, count)); |
| 2482 | } |
| 2483 | symlinkinfo[buflen] = 0; |
| 2484 | /* just in case so calling code does not go off the end of buffer */ |
| 2485 | } |
| 2486 | } |
| 2487 | cifs_buf_release(pSMB); |
| 2488 | if (rc == -EAGAIN) |
| 2489 | goto querySymLinkRetry; |
| 2490 | return rc; |
| 2491 | } |
| 2492 | |
Parag Warudkar | c948977 | 2007-10-23 18:09:48 +0000 | [diff] [blame] | 2493 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2494 | /* Initialize NT TRANSACT SMB into small smb request buffer. |
| 2495 | This assumes that all NT TRANSACTS that we init here have |
| 2496 | total parm and data under about 400 bytes (to fit in small cifs |
| 2497 | buffer size), which is the case so far, it easily fits. NB: |
| 2498 | Setup words themselves and ByteCount |
| 2499 | MaxSetupCount (size of returned setup area) and |
| 2500 | MaxParameterCount (returned parms size) must be set by caller */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2501 | static int |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 2502 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2503 | const int parm_len, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2504 | void **ret_buf) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2505 | { |
| 2506 | int rc; |
| 2507 | __u32 temp_offset; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2508 | struct smb_com_ntransact_req *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2509 | |
| 2510 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 2511 | (void **)&pSMB); |
| 2512 | if (rc) |
| 2513 | return rc; |
| 2514 | *ret_buf = (void *)pSMB; |
| 2515 | pSMB->Reserved = 0; |
| 2516 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 2517 | pSMB->TotalDataCount = 0; |
| 2518 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 2519 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 2520 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2521 | pSMB->DataCount = pSMB->TotalDataCount; |
| 2522 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 2523 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 2524 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 2525 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 2526 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 2527 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 2528 | return 0; |
| 2529 | } |
| 2530 | |
| 2531 | static int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2532 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 2533 | __u32 *pparmlen, __u32 *pdatalen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2534 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2535 | char *end_of_smb; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2536 | __u32 data_count, data_offset, parm_count, parm_offset; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2537 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2538 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 2539 | *pdatalen = 0; |
| 2540 | *pparmlen = 0; |
| 2541 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2542 | if (buf == NULL) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2543 | return -EINVAL; |
| 2544 | |
| 2545 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 2546 | |
| 2547 | /* ByteCount was converted from little endian in SendReceive */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2548 | end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount + |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2549 | (char *)&pSMBr->ByteCount; |
| 2550 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2551 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 2552 | data_count = le32_to_cpu(pSMBr->DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2553 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2554 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 2555 | |
| 2556 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 2557 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 2558 | |
| 2559 | /* should we also check that parm and data areas do not overlap? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2560 | if (*ppparm > end_of_smb) { |
| 2561 | cFYI(1, ("parms start after end of smb")); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2562 | return -EINVAL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2563 | } else if (parm_count + *ppparm > end_of_smb) { |
| 2564 | cFYI(1, ("parm end after end of smb")); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2565 | return -EINVAL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2566 | } else if (*ppdata > end_of_smb) { |
| 2567 | cFYI(1, ("data starts after end of smb")); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2568 | return -EINVAL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2569 | } else if (data_count + *ppdata > end_of_smb) { |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 2570 | 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] | 2571 | *ppdata, data_count, (data_count + *ppdata), |
| 2572 | end_of_smb, pSMBr)); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2573 | return -EINVAL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2574 | } else if (parm_count + data_count > pSMBr->ByteCount) { |
| 2575 | cFYI(1, ("parm count and data count larger than SMB")); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2576 | return -EINVAL; |
| 2577 | } |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 2578 | *pdatalen = data_count; |
| 2579 | *pparmlen = parm_count; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2580 | return 0; |
| 2581 | } |
Parag Warudkar | c948977 | 2007-10-23 18:09:48 +0000 | [diff] [blame] | 2582 | #endif /* CIFS_EXPERIMENTAL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | int |
| 2585 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, |
| 2586 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2587 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | const struct nls_table *nls_codepage) |
| 2589 | { |
| 2590 | int rc = 0; |
| 2591 | int bytes_returned; |
| 2592 | int name_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2593 | struct smb_com_transaction_ioctl_req *pSMB; |
| 2594 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | |
| 2596 | cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName)); |
| 2597 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 2598 | (void **) &pSMBr); |
| 2599 | if (rc) |
| 2600 | return rc; |
| 2601 | |
| 2602 | pSMB->TotalParameterCount = 0 ; |
| 2603 | pSMB->TotalDataCount = 0; |
| 2604 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 2605 | /* BB find exact data count max from sess structure BB */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2606 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 2607 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | pSMB->MaxSetupCount = 4; |
| 2609 | pSMB->Reserved = 0; |
| 2610 | pSMB->ParameterOffset = 0; |
| 2611 | pSMB->DataCount = 0; |
| 2612 | pSMB->DataOffset = 0; |
| 2613 | pSMB->SetupCount = 4; |
| 2614 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 2615 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2616 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 2617 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 2618 | pSMB->IsRootFlag = 0; |
| 2619 | pSMB->Fid = fid; /* file handle always le */ |
| 2620 | pSMB->ByteCount = 0; |
| 2621 | |
| 2622 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2623 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2624 | if (rc) { |
| 2625 | cFYI(1, ("Send error in QueryReparseLinkInfo = %d", rc)); |
| 2626 | } else { /* decode response */ |
| 2627 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 2628 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
| 2629 | if ((pSMBr->ByteCount < 2) || (data_offset > 512)) |
| 2630 | /* BB also check enough total bytes returned */ |
| 2631 | rc = -EIO; /* bad smb */ |
| 2632 | else { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2633 | if (data_count && (data_count < 2048)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2634 | char *end_of_smb = 2 /* sizeof byte count */ + |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2635 | pSMBr->ByteCount + |
| 2636 | (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2638 | struct reparse_data *reparse_buf = |
| 2639 | (struct reparse_data *) |
| 2640 | ((char *)&pSMBr->hdr.Protocol |
| 2641 | + data_offset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2642 | if ((char *)reparse_buf >= end_of_smb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | rc = -EIO; |
| 2644 | goto qreparse_out; |
| 2645 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2646 | if ((reparse_buf->LinkNamesBuf + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | reparse_buf->TargetNameOffset + |
| 2648 | reparse_buf->TargetNameLen) > |
| 2649 | end_of_smb) { |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 2650 | cFYI(1, ("reparse buf beyond SMB")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | rc = -EIO; |
| 2652 | goto qreparse_out; |
| 2653 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2656 | name_len = UniStrnlen((wchar_t *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2657 | (reparse_buf->LinkNamesBuf + |
| 2658 | reparse_buf->TargetNameOffset), |
| 2659 | min(buflen/2, |
| 2660 | reparse_buf->TargetNameLen / 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | cifs_strfromUCS_le(symlinkinfo, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2662 | (__le16 *) (reparse_buf->LinkNamesBuf + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | reparse_buf->TargetNameOffset), |
| 2664 | name_len, nls_codepage); |
| 2665 | } else { /* ASCII names */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2666 | strncpy(symlinkinfo, |
| 2667 | reparse_buf->LinkNamesBuf + |
| 2668 | reparse_buf->TargetNameOffset, |
| 2669 | min_t(const int, buflen, |
| 2670 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | } |
| 2672 | } else { |
| 2673 | rc = -EIO; |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 2674 | cFYI(1, ("Invalid return data count on " |
| 2675 | "get reparse info ioctl")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | } |
| 2677 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 2678 | does not go off the end of the buffer */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2679 | cFYI(1, ("readlink result - %s", symlinkinfo)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | } |
| 2681 | } |
| 2682 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 2683 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | |
| 2685 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2686 | since file handle passed in no longer valid */ |
| 2687 | |
| 2688 | return rc; |
| 2689 | } |
| 2690 | |
| 2691 | #ifdef CONFIG_CIFS_POSIX |
| 2692 | |
| 2693 | /*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] | 2694 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 2695 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | { |
| 2697 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2698 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 2699 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 2700 | 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] | 2701 | /* cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id)); */ |
| 2702 | |
| 2703 | return; |
| 2704 | } |
| 2705 | |
| 2706 | /* 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] | 2707 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 2708 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | { |
| 2710 | int size = 0; |
| 2711 | int i; |
| 2712 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2713 | struct cifs_posix_ace *pACE; |
| 2714 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 2715 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | |
| 2717 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 2718 | return -EOPNOTSUPP; |
| 2719 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2720 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2722 | pACE = &cifs_acl->ace_array[0]; |
| 2723 | size = sizeof(struct cifs_posix_acl); |
| 2724 | size += sizeof(struct cifs_posix_ace) * count; |
| 2725 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2726 | if (size_of_data_area < size) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2727 | cFYI(1, ("bad CIFS POSIX ACL size %d vs. %d", |
| 2728 | size_of_data_area, size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | return -EINVAL; |
| 2730 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2731 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2733 | size = sizeof(struct cifs_posix_acl); |
| 2734 | size += sizeof(struct cifs_posix_ace) * count; |
| 2735 | /* skip past access ACEs to get to default ACEs */ |
| 2736 | pACE = &cifs_acl->ace_array[count]; |
| 2737 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 2738 | size += sizeof(struct cifs_posix_ace) * count; |
| 2739 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2740 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | return -EINVAL; |
| 2742 | } else { |
| 2743 | /* illegal type */ |
| 2744 | return -EINVAL; |
| 2745 | } |
| 2746 | |
| 2747 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2748 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2749 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2750 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | return -ERANGE; |
| 2752 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2753 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2754 | for (i = 0; i < count ; i++) { |
| 2755 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 2756 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | } |
| 2758 | } |
| 2759 | return size; |
| 2760 | } |
| 2761 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2762 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 2763 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | { |
| 2765 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 2766 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2767 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 2768 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2770 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 2772 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2773 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2774 | 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] | 2775 | /*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] | 2776 | return rc; |
| 2777 | } |
| 2778 | |
| 2779 | /* 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] | 2780 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 2781 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | { |
| 2783 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2784 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 2785 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | int count; |
| 2787 | int i; |
| 2788 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2789 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | return 0; |
| 2791 | |
| 2792 | count = posix_acl_xattr_count((size_t)buflen); |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 2793 | 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] | 2794 | "version of %d", |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2795 | count, buflen, le32_to_cpu(local_acl->a_version))); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2796 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2797 | cFYI(1, ("unknown POSIX ACL version %d", |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2798 | le32_to_cpu(local_acl->a_version))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | return 0; |
| 2800 | } |
| 2801 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2802 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2803 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2804 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2805 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2807 | cFYI(1, ("unknown ACL type %d", acl_type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | return 0; |
| 2809 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2810 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 2812 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2813 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | /* ACE not converted */ |
| 2815 | break; |
| 2816 | } |
| 2817 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2818 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 2820 | rc += sizeof(struct cifs_posix_acl); |
| 2821 | /* BB add check to make sure ACL does not overflow SMB */ |
| 2822 | } |
| 2823 | return rc; |
| 2824 | } |
| 2825 | |
| 2826 | int |
| 2827 | CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2828 | const unsigned char *searchName, |
| 2829 | char *acl_inf, const int buflen, const int acl_type, |
| 2830 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | { |
| 2832 | /* SMB_QUERY_POSIX_ACL */ |
| 2833 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2834 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2835 | int rc = 0; |
| 2836 | int bytes_returned; |
| 2837 | int name_len; |
| 2838 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName)); |
| 2841 | |
| 2842 | queryAclRetry: |
| 2843 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2844 | (void **) &pSMBr); |
| 2845 | if (rc) |
| 2846 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2849 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2850 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2851 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | name_len++; /* trailing null */ |
| 2853 | name_len *= 2; |
| 2854 | pSMB->FileName[name_len] = 0; |
| 2855 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2856 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | name_len = strnlen(searchName, PATH_MAX); |
| 2858 | name_len++; /* trailing null */ |
| 2859 | strncpy(pSMB->FileName, searchName, name_len); |
| 2860 | } |
| 2861 | |
| 2862 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 2863 | pSMB->TotalDataCount = 0; |
| 2864 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2865 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 2867 | pSMB->MaxSetupCount = 0; |
| 2868 | pSMB->Reserved = 0; |
| 2869 | pSMB->Flags = 0; |
| 2870 | pSMB->Timeout = 0; |
| 2871 | pSMB->Reserved2 = 0; |
| 2872 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2873 | offsetof(struct smb_com_transaction2_qpi_req, |
| 2874 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | pSMB->DataCount = 0; |
| 2876 | pSMB->DataOffset = 0; |
| 2877 | pSMB->SetupCount = 1; |
| 2878 | pSMB->Reserved3 = 0; |
| 2879 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 2880 | byte_count = params + 1 /* pad */ ; |
| 2881 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 2882 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2883 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 2884 | pSMB->Reserved4 = 0; |
| 2885 | pSMB->hdr.smb_buf_length += byte_count; |
| 2886 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2887 | |
| 2888 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2889 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2890 | cifs_stats_inc(&tcon->num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | if (rc) { |
| 2892 | cFYI(1, ("Send error in Query POSIX ACL = %d", rc)); |
| 2893 | } else { |
| 2894 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 2897 | if (rc || (pSMBr->ByteCount < 2)) |
| 2898 | /* BB also check enough total bytes returned */ |
| 2899 | rc = -EIO; /* bad smb */ |
| 2900 | else { |
| 2901 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2902 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 2903 | rc = cifs_copy_posix_acl(acl_inf, |
| 2904 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2905 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | } |
| 2907 | } |
| 2908 | cifs_buf_release(pSMB); |
| 2909 | if (rc == -EAGAIN) |
| 2910 | goto queryAclRetry; |
| 2911 | return rc; |
| 2912 | } |
| 2913 | |
| 2914 | int |
| 2915 | CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2916 | const unsigned char *fileName, |
| 2917 | const char *local_acl, const int buflen, |
| 2918 | const int acl_type, |
| 2919 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | { |
| 2921 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 2922 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 2923 | char *parm_data; |
| 2924 | int name_len; |
| 2925 | int rc = 0; |
| 2926 | int bytes_returned = 0; |
| 2927 | __u16 params, byte_count, data_count, param_offset, offset; |
| 2928 | |
| 2929 | cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName)); |
| 2930 | setAclRetry: |
| 2931 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2932 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | if (rc) |
| 2934 | return rc; |
| 2935 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2936 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2937 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2938 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | name_len++; /* trailing null */ |
| 2940 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2941 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | name_len = strnlen(fileName, PATH_MAX); |
| 2943 | name_len++; /* trailing null */ |
| 2944 | strncpy(pSMB->FileName, fileName, name_len); |
| 2945 | } |
| 2946 | params = 6 + name_len; |
| 2947 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 2948 | /* BB find max SMB size from sess */ |
| 2949 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | pSMB->MaxSetupCount = 0; |
| 2951 | pSMB->Reserved = 0; |
| 2952 | pSMB->Flags = 0; |
| 2953 | pSMB->Timeout = 0; |
| 2954 | pSMB->Reserved2 = 0; |
| 2955 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2956 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | offset = param_offset + params; |
| 2958 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 2959 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2960 | |
| 2961 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2962 | 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] | 2963 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2964 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | rc = -EOPNOTSUPP; |
| 2966 | goto setACLerrorExit; |
| 2967 | } |
| 2968 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2969 | pSMB->SetupCount = 1; |
| 2970 | pSMB->Reserved3 = 0; |
| 2971 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2972 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 2973 | byte_count = 3 /* pad */ + params + data_count; |
| 2974 | pSMB->DataCount = cpu_to_le16(data_count); |
| 2975 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2976 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2977 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2978 | pSMB->Reserved4 = 0; |
| 2979 | pSMB->hdr.smb_buf_length += byte_count; |
| 2980 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2981 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2982 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2983 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | cFYI(1, ("Set POSIX ACL returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | |
| 2986 | setACLerrorExit: |
| 2987 | cifs_buf_release(pSMB); |
| 2988 | if (rc == -EAGAIN) |
| 2989 | goto setAclRetry; |
| 2990 | return rc; |
| 2991 | } |
| 2992 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2993 | /* BB fix tabs in this function FIXME BB */ |
| 2994 | int |
| 2995 | CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2996 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2997 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2998 | int rc = 0; |
| 2999 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3000 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3001 | int bytes_returned; |
| 3002 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3003 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3004 | cFYI(1, ("In GetExtAttr")); |
| 3005 | if (tcon == NULL) |
| 3006 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3007 | |
| 3008 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3009 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3010 | (void **) &pSMBr); |
| 3011 | if (rc) |
| 3012 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3013 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3014 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3015 | pSMB->t2.TotalDataCount = 0; |
| 3016 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3017 | /* BB find exact max data count below from sess structure BB */ |
| 3018 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 3019 | pSMB->t2.MaxSetupCount = 0; |
| 3020 | pSMB->t2.Reserved = 0; |
| 3021 | pSMB->t2.Flags = 0; |
| 3022 | pSMB->t2.Timeout = 0; |
| 3023 | pSMB->t2.Reserved2 = 0; |
| 3024 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3025 | Fid) - 4); |
| 3026 | pSMB->t2.DataCount = 0; |
| 3027 | pSMB->t2.DataOffset = 0; |
| 3028 | pSMB->t2.SetupCount = 1; |
| 3029 | pSMB->t2.Reserved3 = 0; |
| 3030 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3031 | byte_count = params + 1 /* pad */ ; |
| 3032 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3033 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3034 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 3035 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3036 | pSMB->Fid = netfid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3037 | pSMB->hdr.smb_buf_length += byte_count; |
| 3038 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3039 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3040 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3041 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3042 | if (rc) { |
| 3043 | cFYI(1, ("error %d in GetExtAttr", rc)); |
| 3044 | } else { |
| 3045 | /* decode response */ |
| 3046 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3047 | if (rc || (pSMBr->ByteCount < 2)) |
| 3048 | /* BB also check enough total bytes returned */ |
| 3049 | /* If rc should we check for EOPNOSUPP and |
| 3050 | disable the srvino flag? or in caller? */ |
| 3051 | rc = -EIO; /* bad smb */ |
| 3052 | else { |
| 3053 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3054 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3055 | struct file_chattr_info *pfinfo; |
| 3056 | /* BB Do we need a cast or hash here ? */ |
| 3057 | if (count != 16) { |
| 3058 | cFYI(1, ("Illegal size ret in GetExtAttr")); |
| 3059 | rc = -EIO; |
| 3060 | goto GetExtAttrOut; |
| 3061 | } |
| 3062 | pfinfo = (struct file_chattr_info *) |
| 3063 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3064 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3065 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3066 | } |
| 3067 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3068 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3069 | cifs_buf_release(pSMB); |
| 3070 | if (rc == -EAGAIN) |
| 3071 | goto GetExtAttrRetry; |
| 3072 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3073 | } |
| 3074 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3075 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 3077 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3078 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3079 | int |
| 3080 | CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3081 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3082 | { |
| 3083 | int rc = 0; |
| 3084 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3085 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3086 | struct kvec iov[1]; |
| 3087 | |
| 3088 | cFYI(1, ("GetCifsACL")); |
| 3089 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3090 | *pbuflen = 0; |
| 3091 | *acl_inf = NULL; |
| 3092 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3093 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3094 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3095 | if (rc) |
| 3096 | return rc; |
| 3097 | |
| 3098 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3099 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3100 | pSMB->MaxSetupCount = 0; |
| 3101 | pSMB->Fid = fid; /* file handle always le */ |
| 3102 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3103 | CIFS_ACL_DACL); |
| 3104 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
| 3105 | pSMB->hdr.smb_buf_length += 11; |
| 3106 | iov[0].iov_base = (char *)pSMB; |
| 3107 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
| 3108 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3109 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 3110 | CIFS_STD_OP); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3111 | cifs_stats_inc(&tcon->num_acl_get); |
| 3112 | if (rc) { |
| 3113 | cFYI(1, ("Send error in QuerySecDesc = %d", rc)); |
| 3114 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3115 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3116 | __u32 parm_len; |
| 3117 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3118 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3119 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3120 | |
| 3121 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3122 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3123 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3124 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3125 | goto qsec_out; |
| 3126 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3127 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3128 | cFYI(1, ("smb %p parm %p data %p", pSMBr, parm, *acl_inf)); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3129 | |
| 3130 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3131 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3132 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3133 | goto qsec_out; |
| 3134 | } |
| 3135 | |
| 3136 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3137 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3138 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3139 | if (acl_len != *pbuflen) { |
| 3140 | cERROR(1, ("acl length %d does not match %d", |
| 3141 | acl_len, *pbuflen)); |
| 3142 | if (*pbuflen > acl_len) |
| 3143 | *pbuflen = acl_len; |
| 3144 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3145 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3146 | /* check if buffer is big enough for the acl |
| 3147 | header followed by the smallest SID */ |
| 3148 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3149 | (*pbuflen >= 64 * 1024)) { |
| 3150 | cERROR(1, ("bad acl length %d", *pbuflen)); |
| 3151 | rc = -EINVAL; |
| 3152 | *pbuflen = 0; |
| 3153 | } else { |
| 3154 | *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); |
| 3155 | if (*acl_inf == NULL) { |
| 3156 | *pbuflen = 0; |
| 3157 | rc = -ENOMEM; |
| 3158 | } |
| 3159 | memcpy(*acl_inf, pdata, *pbuflen); |
| 3160 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3161 | } |
| 3162 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3163 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3164 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3165 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3166 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3167 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3168 | return rc; |
| 3169 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3170 | |
| 3171 | int |
| 3172 | CIFSSMBSetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
| 3173 | struct cifs_ntsd *pntsd, __u32 acllen) |
| 3174 | { |
| 3175 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3176 | int rc = 0; |
| 3177 | int bytes_returned = 0; |
| 3178 | SET_SEC_DESC_REQ *pSMB = NULL; |
| 3179 | NTRANSACT_RSP *pSMBr = NULL; |
| 3180 | |
| 3181 | setCifsAclRetry: |
| 3182 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, |
| 3183 | (void **) &pSMBr); |
| 3184 | if (rc) |
| 3185 | return (rc); |
| 3186 | |
| 3187 | pSMB->MaxSetupCount = 0; |
| 3188 | pSMB->Reserved = 0; |
| 3189 | |
| 3190 | param_count = 8; |
| 3191 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3192 | data_count = acllen; |
| 3193 | data_offset = param_offset + param_count; |
| 3194 | byte_count = 3 /* pad */ + param_count; |
| 3195 | |
| 3196 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3197 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3198 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3199 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3200 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3201 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3202 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3203 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3204 | pSMB->SetupCount = 0; |
| 3205 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3206 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3207 | |
| 3208 | pSMB->Fid = fid; /* file handle always le */ |
| 3209 | pSMB->Reserved2 = 0; |
| 3210 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_DACL); |
| 3211 | |
| 3212 | if (pntsd && acllen) { |
| 3213 | memcpy((char *) &pSMBr->hdr.Protocol + data_offset, |
| 3214 | (char *) pntsd, |
| 3215 | acllen); |
| 3216 | pSMB->hdr.smb_buf_length += (byte_count + data_count); |
| 3217 | |
| 3218 | } else |
| 3219 | pSMB->hdr.smb_buf_length += byte_count; |
| 3220 | |
| 3221 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3222 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3223 | |
| 3224 | cFYI(1, ("SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc)); |
| 3225 | if (rc) |
| 3226 | cFYI(1, ("Set CIFS ACL returned %d", rc)); |
| 3227 | cifs_buf_release(pSMB); |
| 3228 | |
| 3229 | if (rc == -EAGAIN) |
| 3230 | goto setCifsAclRetry; |
| 3231 | |
| 3232 | return (rc); |
| 3233 | } |
| 3234 | |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 3235 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3236 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3237 | /* Legacy Query Path Information call for lookup to old servers such |
| 3238 | as Win9x/WinME */ |
| 3239 | int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3240 | const unsigned char *searchName, |
| 3241 | FILE_ALL_INFO *pFinfo, |
| 3242 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3243 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3244 | QUERY_INFORMATION_REQ *pSMB; |
| 3245 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3246 | int rc = 0; |
| 3247 | int bytes_returned; |
| 3248 | int name_len; |
| 3249 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3250 | cFYI(1, ("In SMBQPath path %s", searchName)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3251 | QInfRetry: |
| 3252 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3253 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3254 | if (rc) |
| 3255 | return rc; |
| 3256 | |
| 3257 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3258 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3259 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
| 3260 | PATH_MAX, nls_codepage, remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3261 | name_len++; /* trailing null */ |
| 3262 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3263 | } else { |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3264 | name_len = strnlen(searchName, PATH_MAX); |
| 3265 | name_len++; /* trailing null */ |
| 3266 | strncpy(pSMB->FileName, searchName, name_len); |
| 3267 | } |
| 3268 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3269 | name_len++; /* account for buffer type byte */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3270 | pSMB->hdr.smb_buf_length += (__u16) name_len; |
| 3271 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3272 | |
| 3273 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3274 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3275 | if (rc) { |
| 3276 | cFYI(1, ("Send error in QueryInfo = %d", rc)); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3277 | } else if (pFinfo) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3278 | struct timespec ts; |
| 3279 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3280 | |
| 3281 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3282 | /* BB FIXME - add time zone adjustment BB */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3283 | memset(pFinfo, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3284 | ts.tv_nsec = 0; |
| 3285 | ts.tv_sec = time; |
| 3286 | /* decode time fields */ |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 3287 | pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3288 | pFinfo->LastWriteTime = pFinfo->ChangeTime; |
| 3289 | pFinfo->LastAccessTime = 0; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3290 | pFinfo->AllocationSize = |
| 3291 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
| 3292 | pFinfo->EndOfFile = pFinfo->AllocationSize; |
| 3293 | pFinfo->Attributes = |
| 3294 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3295 | } else |
| 3296 | rc = -EIO; /* bad buffer passed in */ |
| 3297 | |
| 3298 | cifs_buf_release(pSMB); |
| 3299 | |
| 3300 | if (rc == -EAGAIN) |
| 3301 | goto QInfRetry; |
| 3302 | |
| 3303 | return rc; |
| 3304 | } |
| 3305 | |
| 3306 | |
| 3307 | |
| 3308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | int |
| 3310 | CIFSSMBQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3311 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3312 | FILE_ALL_INFO *pFindData, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3313 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3314 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | { |
| 3316 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
| 3317 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3318 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3319 | int rc = 0; |
| 3320 | int bytes_returned; |
| 3321 | int name_len; |
| 3322 | __u16 params, byte_count; |
| 3323 | |
| 3324 | /* cFYI(1, ("In QPathInfo path %s", searchName)); */ |
| 3325 | QPathInfoRetry: |
| 3326 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3327 | (void **) &pSMBr); |
| 3328 | if (rc) |
| 3329 | return rc; |
| 3330 | |
| 3331 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3332 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3333 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3334 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | name_len++; /* trailing null */ |
| 3336 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3337 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | name_len = strnlen(searchName, PATH_MAX); |
| 3339 | name_len++; /* trailing null */ |
| 3340 | strncpy(pSMB->FileName, searchName, name_len); |
| 3341 | } |
| 3342 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3343 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | pSMB->TotalDataCount = 0; |
| 3345 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3346 | /* BB find exact max SMB PDU from sess structure BB */ |
| 3347 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | pSMB->MaxSetupCount = 0; |
| 3349 | pSMB->Reserved = 0; |
| 3350 | pSMB->Flags = 0; |
| 3351 | pSMB->Timeout = 0; |
| 3352 | pSMB->Reserved2 = 0; |
| 3353 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3354 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | pSMB->DataCount = 0; |
| 3356 | pSMB->DataOffset = 0; |
| 3357 | pSMB->SetupCount = 1; |
| 3358 | pSMB->Reserved3 = 0; |
| 3359 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3360 | byte_count = params + 1 /* pad */ ; |
| 3361 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3362 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3363 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3364 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 3365 | else |
| 3366 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | pSMB->Reserved4 = 0; |
| 3368 | pSMB->hdr.smb_buf_length += byte_count; |
| 3369 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3370 | |
| 3371 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3372 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3373 | if (rc) { |
| 3374 | cFYI(1, ("Send error in QPathInfo = %d", rc)); |
| 3375 | } else { /* decode response */ |
| 3376 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3377 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3378 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3379 | rc = -EIO; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3380 | else if (!legacy && (pSMBr->ByteCount < 40)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | rc = -EIO; /* bad smb */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3382 | else if (legacy && (pSMBr->ByteCount < 24)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3383 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 3384 | last field */ |
| 3385 | else if (pFindData) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3386 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3388 | |
| 3389 | /* On legacy responses we do not read the last field, |
| 3390 | EAsize, fortunately since it varies by subdialect and |
| 3391 | also note it differs on Set vs. Get, ie two bytes or 4 |
| 3392 | bytes depending but we don't care here */ |
| 3393 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3394 | size = sizeof(FILE_INFO_STANDARD); |
| 3395 | else |
| 3396 | size = sizeof(FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | memcpy((char *) pFindData, |
| 3398 | (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3399 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | } else |
| 3401 | rc = -ENOMEM; |
| 3402 | } |
| 3403 | cifs_buf_release(pSMB); |
| 3404 | if (rc == -EAGAIN) |
| 3405 | goto QPathInfoRetry; |
| 3406 | |
| 3407 | return rc; |
| 3408 | } |
| 3409 | |
| 3410 | int |
| 3411 | CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3412 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3413 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3414 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | { |
| 3416 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 3417 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3418 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3419 | int rc = 0; |
| 3420 | int bytes_returned = 0; |
| 3421 | int name_len; |
| 3422 | __u16 params, byte_count; |
| 3423 | |
| 3424 | cFYI(1, ("In QPathInfo (Unix) the path %s", searchName)); |
| 3425 | UnixQPathInfoRetry: |
| 3426 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3427 | (void **) &pSMBr); |
| 3428 | if (rc) |
| 3429 | return rc; |
| 3430 | |
| 3431 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3432 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 3433 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3434 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | name_len++; /* trailing null */ |
| 3436 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3437 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | name_len = strnlen(searchName, PATH_MAX); |
| 3439 | name_len++; /* trailing null */ |
| 3440 | strncpy(pSMB->FileName, searchName, name_len); |
| 3441 | } |
| 3442 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3443 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | pSMB->TotalDataCount = 0; |
| 3445 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3446 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3447 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | pSMB->MaxSetupCount = 0; |
| 3449 | pSMB->Reserved = 0; |
| 3450 | pSMB->Flags = 0; |
| 3451 | pSMB->Timeout = 0; |
| 3452 | pSMB->Reserved2 = 0; |
| 3453 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3454 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | pSMB->DataCount = 0; |
| 3456 | pSMB->DataOffset = 0; |
| 3457 | pSMB->SetupCount = 1; |
| 3458 | pSMB->Reserved3 = 0; |
| 3459 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3460 | byte_count = params + 1 /* pad */ ; |
| 3461 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3462 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3463 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 3464 | pSMB->Reserved4 = 0; |
| 3465 | pSMB->hdr.smb_buf_length += byte_count; |
| 3466 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3467 | |
| 3468 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3469 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3470 | if (rc) { |
| 3471 | cFYI(1, ("Send error in QPathInfo = %d", rc)); |
| 3472 | } else { /* decode response */ |
| 3473 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3474 | |
| 3475 | if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { |
Steve French | 1e71f25 | 2007-09-20 15:30:07 +0000 | [diff] [blame] | 3476 | cERROR(1, ("Malformed FILE_UNIX_BASIC_INFO response.\n" |
| 3477 | "Unix Extensions can be disabled on mount " |
| 3478 | "by specifying the nosfu mount option.")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | rc = -EIO; /* bad smb */ |
| 3480 | } else { |
| 3481 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3482 | memcpy((char *) pFindData, |
| 3483 | (char *) &pSMBr->hdr.Protocol + |
| 3484 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3485 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | } |
| 3487 | } |
| 3488 | cifs_buf_release(pSMB); |
| 3489 | if (rc == -EAGAIN) |
| 3490 | goto UnixQPathInfoRetry; |
| 3491 | |
| 3492 | return rc; |
| 3493 | } |
| 3494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 3496 | int |
| 3497 | CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3498 | const char *searchName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | const struct nls_table *nls_codepage, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3500 | __u16 *pnetfid, |
| 3501 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | { |
| 3503 | /* level 257 SMB_ */ |
| 3504 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 3505 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3506 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | int rc = 0; |
| 3508 | int bytes_returned = 0; |
| 3509 | int name_len; |
| 3510 | __u16 params, byte_count; |
| 3511 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3512 | cFYI(1, ("In FindFirst for %s", searchName)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | |
| 3514 | findFirstRetry: |
| 3515 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3516 | (void **) &pSMBr); |
| 3517 | if (rc) |
| 3518 | return rc; |
| 3519 | |
| 3520 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3521 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3522 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3523 | PATH_MAX, nls_codepage, remap); |
| 3524 | /* We can not add the asterik earlier in case |
| 3525 | it got remapped to 0xF03A as if it were part of the |
| 3526 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | name_len *= 2; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3528 | pSMB->FileName[name_len] = dirsep; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3529 | pSMB->FileName[name_len+1] = 0; |
| 3530 | pSMB->FileName[name_len+2] = '*'; |
| 3531 | pSMB->FileName[name_len+3] = 0; |
| 3532 | name_len += 4; /* now the trailing null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ |
| 3534 | pSMB->FileName[name_len+1] = 0; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3535 | name_len += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | } else { /* BB add check for overrun of SMB buf BB */ |
| 3537 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3539 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | free buffer exit; BB */ |
| 3541 | strncpy(pSMB->FileName, searchName, name_len); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3542 | pSMB->FileName[name_len] = dirsep; |
Steve French | 6857547 | 2005-04-30 11:10:57 -0700 | [diff] [blame] | 3543 | pSMB->FileName[name_len+1] = '*'; |
| 3544 | pSMB->FileName[name_len+2] = 0; |
| 3545 | name_len += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | params = 12 + name_len /* includes null */ ; |
| 3549 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 3550 | pSMB->MaxParameterCount = cpu_to_le16(10); |
| 3551 | pSMB->MaxDataCount = cpu_to_le16((tcon->ses->server->maxBuf - |
| 3552 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 3553 | pSMB->MaxSetupCount = 0; |
| 3554 | pSMB->Reserved = 0; |
| 3555 | pSMB->Flags = 0; |
| 3556 | pSMB->Timeout = 0; |
| 3557 | pSMB->Reserved2 = 0; |
| 3558 | byte_count = params + 1 /* pad */ ; |
| 3559 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3560 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3561 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3562 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 3563 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | pSMB->DataCount = 0; |
| 3565 | pSMB->DataOffset = 0; |
| 3566 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 3567 | pSMB->Reserved3 = 0; |
| 3568 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 3569 | pSMB->SearchAttributes = |
| 3570 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3571 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3572 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
| 3573 | pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | CIFS_SEARCH_RETURN_RESUME); |
| 3575 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 3576 | |
| 3577 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 3578 | pSMB->SearchStorageType = 0; |
| 3579 | pSMB->hdr.smb_buf_length += byte_count; |
| 3580 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3581 | |
| 3582 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3583 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3584 | cifs_stats_inc(&tcon->num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3586 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 3587 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | /* BB Add code to handle unsupported level rc */ |
| 3589 | cFYI(1, ("Error in FindFirst = %d", rc)); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 3590 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3591 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | |
| 3593 | /* BB eventually could optimize out free and realloc of buf */ |
| 3594 | /* for this case */ |
| 3595 | if (rc == -EAGAIN) |
| 3596 | goto findFirstRetry; |
| 3597 | } else { /* decode response */ |
| 3598 | /* BB remember to free buffer if error BB */ |
| 3599 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3600 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3601 | unsigned int lnoff; |
| 3602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3604 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3606 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | |
| 3608 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3609 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3610 | psrch_inf->srch_entries_start = |
| 3611 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 3614 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 3615 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3616 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3617 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3619 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3621 | psrch_inf->entries_in_buffer = |
| 3622 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 3623 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3625 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 3626 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 3627 | lnoff) { |
| 3628 | cERROR(1, ("ignoring corrupt resume name")); |
| 3629 | psrch_inf->last_entry = NULL; |
| 3630 | return rc; |
| 3631 | } |
| 3632 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 3633 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3634 | lnoff; |
| 3635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | *pnetfid = parms->SearchHandle; |
| 3637 | } else { |
| 3638 | cifs_buf_release(pSMB); |
| 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | return rc; |
| 3643 | } |
| 3644 | |
| 3645 | int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3646 | __u16 searchHandle, struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | { |
| 3648 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 3649 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3650 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | char *response_data; |
| 3652 | int rc = 0; |
| 3653 | int bytes_returned, name_len; |
| 3654 | __u16 params, byte_count; |
| 3655 | |
| 3656 | cFYI(1, ("In FindNext")); |
| 3657 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3658 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | return -ENOENT; |
| 3660 | |
| 3661 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3662 | (void **) &pSMBr); |
| 3663 | if (rc) |
| 3664 | return rc; |
| 3665 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3666 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | byte_count = 0; |
| 3668 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 3669 | pSMB->MaxParameterCount = cpu_to_le16(8); |
| 3670 | pSMB->MaxDataCount = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3671 | cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & |
| 3672 | 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | pSMB->MaxSetupCount = 0; |
| 3674 | pSMB->Reserved = 0; |
| 3675 | pSMB->Flags = 0; |
| 3676 | pSMB->Timeout = 0; |
| 3677 | pSMB->Reserved2 = 0; |
| 3678 | pSMB->ParameterOffset = cpu_to_le16( |
| 3679 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 3680 | pSMB->DataCount = 0; |
| 3681 | pSMB->DataOffset = 0; |
| 3682 | pSMB->SetupCount = 1; |
| 3683 | pSMB->Reserved3 = 0; |
| 3684 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 3685 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 3686 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3687 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 3689 | pSMB->ResumeKey = psrch_inf->resume_key; |
| 3690 | pSMB->SearchFlags = |
| 3691 | cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME); |
| 3692 | |
| 3693 | name_len = psrch_inf->resume_name_len; |
| 3694 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3695 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 3697 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 3698 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 3699 | pSMB->ResumeFileName[name_len] = 0; |
| 3700 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | } else { |
| 3702 | rc = -EINVAL; |
| 3703 | goto FNext2_err_exit; |
| 3704 | } |
| 3705 | byte_count = params + 1 /* pad */ ; |
| 3706 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3707 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3708 | pSMB->hdr.smb_buf_length += byte_count; |
| 3709 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3712 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3713 | cifs_stats_inc(&tcon->num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | if (rc) { |
| 3715 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3716 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 3717 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3718 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | } else |
| 3720 | cFYI(1, ("FindNext returned = %d", rc)); |
| 3721 | } else { /* decode response */ |
| 3722 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3723 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3724 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3725 | unsigned int lnoff; |
| 3726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | /* BB fixme add lock for file (srch_info) struct here */ |
| 3728 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3729 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3731 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 3733 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 3734 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 3735 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 3736 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3737 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3738 | cifs_small_buf_release( |
| 3739 | psrch_inf->ntwrk_buf_start); |
| 3740 | else |
| 3741 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | psrch_inf->srch_entries_start = response_data; |
| 3743 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3744 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3745 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3746 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3748 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3749 | psrch_inf->entries_in_buffer = |
| 3750 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | psrch_inf->index_of_last_entry += |
| 3752 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3753 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 3754 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 3755 | lnoff) { |
| 3756 | cERROR(1, ("ignoring corrupt resume name")); |
| 3757 | psrch_inf->last_entry = NULL; |
| 3758 | return rc; |
| 3759 | } else |
| 3760 | psrch_inf->last_entry = |
| 3761 | psrch_inf->srch_entries_start + lnoff; |
| 3762 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3763 | /* cFYI(1,("fnxt2 entries in buf %d index_of_last %d", |
| 3764 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry)); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | |
| 3766 | /* BB fixme add unlock here */ |
| 3767 | } |
| 3768 | |
| 3769 | } |
| 3770 | |
| 3771 | /* BB On error, should we leave previous search buf (and count and |
| 3772 | last entry fields) intact or free the previous one? */ |
| 3773 | |
| 3774 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 3775 | since file handle passed in no longer valid */ |
| 3776 | FNext2_err_exit: |
| 3777 | if (rc != 0) |
| 3778 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | return rc; |
| 3780 | } |
| 3781 | |
| 3782 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3783 | CIFSFindClose(const int xid, struct cifsTconInfo *tcon, |
| 3784 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | { |
| 3786 | int rc = 0; |
| 3787 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | |
| 3789 | cFYI(1, ("In CIFSSMBFindClose")); |
| 3790 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 3791 | |
| 3792 | /* no sense returning error if session restarted |
| 3793 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3794 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | return 0; |
| 3796 | if (rc) |
| 3797 | return rc; |
| 3798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | pSMB->FileID = searchHandle; |
| 3800 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 3801 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3802 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | cERROR(1, ("Send error in FindClose = %d", rc)); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3804 | |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3805 | cifs_stats_inc(&tcon->num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | |
| 3807 | /* Since session is dead, search handle closed on server already */ |
| 3808 | if (rc == -EAGAIN) |
| 3809 | rc = 0; |
| 3810 | |
| 3811 | return rc; |
| 3812 | } |
| 3813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | int |
| 3815 | CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3816 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3817 | __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3818 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | { |
| 3820 | int rc = 0; |
| 3821 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3822 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3823 | int name_len, bytes_returned; |
| 3824 | __u16 params, byte_count; |
| 3825 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3826 | cFYI(1, ("In GetSrvInodeNum for %s", searchName)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3827 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3828 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | |
| 3830 | GetInodeNumberRetry: |
| 3831 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3832 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | if (rc) |
| 3834 | return rc; |
| 3835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3837 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 3838 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3839 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | name_len++; /* trailing null */ |
| 3841 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3842 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | name_len = strnlen(searchName, PATH_MAX); |
| 3844 | name_len++; /* trailing null */ |
| 3845 | strncpy(pSMB->FileName, searchName, name_len); |
| 3846 | } |
| 3847 | |
| 3848 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 3849 | pSMB->TotalDataCount = 0; |
| 3850 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3851 | /* BB find exact max data count below from sess structure BB */ |
| 3852 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 3853 | pSMB->MaxSetupCount = 0; |
| 3854 | pSMB->Reserved = 0; |
| 3855 | pSMB->Flags = 0; |
| 3856 | pSMB->Timeout = 0; |
| 3857 | pSMB->Reserved2 = 0; |
| 3858 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3859 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | pSMB->DataCount = 0; |
| 3861 | pSMB->DataOffset = 0; |
| 3862 | pSMB->SetupCount = 1; |
| 3863 | pSMB->Reserved3 = 0; |
| 3864 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3865 | byte_count = params + 1 /* pad */ ; |
| 3866 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3867 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3868 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 3869 | pSMB->Reserved4 = 0; |
| 3870 | pSMB->hdr.smb_buf_length += byte_count; |
| 3871 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3872 | |
| 3873 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3874 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3875 | if (rc) { |
| 3876 | cFYI(1, ("error %d in QueryInternalInfo", rc)); |
| 3877 | } else { |
| 3878 | /* decode response */ |
| 3879 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3880 | if (rc || (pSMBr->ByteCount < 2)) |
| 3881 | /* BB also check enough total bytes returned */ |
| 3882 | /* If rc should we check for EOPNOSUPP and |
| 3883 | disable the srvino flag? or in caller? */ |
| 3884 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3885 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3887 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3888 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3890 | if (count < 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | cFYI(1, ("Illegal size ret in QryIntrnlInf")); |
| 3892 | rc = -EIO; |
| 3893 | goto GetInodeNumOut; |
| 3894 | } |
| 3895 | pfinfo = (struct file_internal_info *) |
| 3896 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3897 | *inode_number = pfinfo->UniqueId; |
| 3898 | } |
| 3899 | } |
| 3900 | GetInodeNumOut: |
| 3901 | cifs_buf_release(pSMB); |
| 3902 | if (rc == -EAGAIN) |
| 3903 | goto GetInodeNumberRetry; |
| 3904 | return rc; |
| 3905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 3907 | /* computes length of UCS string converted to host codepage |
| 3908 | * @src: UCS string |
| 3909 | * @maxlen: length of the input string in UCS characters |
| 3910 | * (not in bytes) |
| 3911 | * |
| 3912 | * return: size of input string in host codepage |
| 3913 | */ |
| 3914 | static int hostlen_fromUCS(const __le16 *src, const int maxlen, |
| 3915 | const struct nls_table *nls_codepage) { |
| 3916 | int i; |
| 3917 | int hostlen = 0; |
| 3918 | char to[4]; |
| 3919 | int charlen; |
| 3920 | for (i = 0; (i < maxlen) && src[i]; ++i) { |
| 3921 | charlen = nls_codepage->uni2char(le16_to_cpu(src[i]), |
| 3922 | to, NLS_MAX_CHARSET_SIZE); |
| 3923 | hostlen += charlen > 0 ? charlen : 1; |
| 3924 | } |
| 3925 | return hostlen; |
| 3926 | } |
| 3927 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3928 | /* parses DFS refferal V3 structure |
| 3929 | * caller is responsible for freeing target_nodes |
| 3930 | * returns: |
| 3931 | * on success - 0 |
| 3932 | * on failure - errno |
| 3933 | */ |
| 3934 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 3935 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3936 | unsigned int *num_of_nodes, |
| 3937 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 3938 | const struct nls_table *nls_codepage, int remap, |
| 3939 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3940 | { |
| 3941 | int i, rc = 0; |
| 3942 | char *data_end; |
| 3943 | bool is_unicode; |
| 3944 | struct dfs_referral_level_3 *ref; |
| 3945 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 3946 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 3947 | is_unicode = true; |
| 3948 | else |
| 3949 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3950 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 3951 | |
| 3952 | if (*num_of_nodes < 1) { |
| 3953 | cERROR(1, ("num_referrals: must be at least > 0," |
| 3954 | "but we get num_referrals = %d\n", *num_of_nodes)); |
| 3955 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 3956 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 3960 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3961 | cERROR(1, ("Referrals of V%d version are not supported," |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 3962 | "should be V3", le16_to_cpu(ref->VersionNumber))); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3963 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 3964 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | /* get the upper boundary of the resp buffer */ |
| 3968 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 3969 | le16_to_cpu(pSMBr->t2.DataCount); |
| 3970 | |
| 3971 | cFYI(1, ("num_referrals: %d dfs flags: 0x%x ... \n", |
| 3972 | *num_of_nodes, |
| 3973 | le16_to_cpu(pSMBr->DFSFlags))); |
| 3974 | |
| 3975 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
| 3976 | *num_of_nodes, GFP_KERNEL); |
| 3977 | if (*target_nodes == NULL) { |
| 3978 | cERROR(1, ("Failed to allocate buffer for target_nodes\n")); |
| 3979 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 3980 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | /* collect neccessary data from referrals */ |
| 3984 | for (i = 0; i < *num_of_nodes; i++) { |
| 3985 | char *temp; |
| 3986 | int max_len; |
| 3987 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 3988 | |
| 3989 | node->flags = le16_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 3990 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 3991 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 3992 | GFP_KERNEL); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 3993 | cifsConvertToUCS((__le16 *) tmp, searchName, |
| 3994 | PATH_MAX, nls_codepage, remap); |
| 3995 | node->path_consumed = hostlen_fromUCS(tmp, |
| 3996 | le16_to_cpu(pSMBr->PathConsumed)/2, |
| 3997 | nls_codepage); |
| 3998 | kfree(tmp); |
| 3999 | } else |
| 4000 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4001 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4002 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4003 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4004 | |
| 4005 | /* copy DfsPath */ |
| 4006 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4007 | max_len = data_end - temp; |
| 4008 | rc = cifs_strncpy_to_host(&(node->path_name), temp, |
| 4009 | max_len, is_unicode, nls_codepage); |
| 4010 | if (rc) |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4011 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4012 | |
| 4013 | /* copy link target UNC */ |
| 4014 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4015 | max_len = data_end - temp; |
| 4016 | rc = cifs_strncpy_to_host(&(node->node_name), temp, |
| 4017 | max_len, is_unicode, nls_codepage); |
| 4018 | if (rc) |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4019 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4020 | |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4021 | ref += le16_to_cpu(ref->Size); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4022 | } |
| 4023 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4024 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4025 | if (rc) { |
| 4026 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4027 | *target_nodes = NULL; |
| 4028 | *num_of_nodes = 0; |
| 4029 | } |
| 4030 | return rc; |
| 4031 | } |
| 4032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | int |
| 4034 | CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses, |
| 4035 | const unsigned char *searchName, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4036 | struct dfs_info3_param **target_nodes, |
| 4037 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4038 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | { |
| 4040 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4041 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4042 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | int rc = 0; |
| 4044 | int bytes_returned; |
| 4045 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4047 | *num_of_nodes = 0; |
| 4048 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | |
| 4050 | cFYI(1, ("In GetDFSRefer the path %s", searchName)); |
| 4051 | if (ses == NULL) |
| 4052 | return -ENODEV; |
| 4053 | getDFSRetry: |
| 4054 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4055 | (void **) &pSMBr); |
| 4056 | if (rc) |
| 4057 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4058 | |
| 4059 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4060 | but should never be null here anyway */ |
| 4061 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4063 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4064 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4066 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | |
| 4069 | if (ses->capabilities & CAP_UNICODE) { |
| 4070 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4071 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4072 | cifsConvertToUCS((__le16 *) pSMB->RequestFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4073 | searchName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | name_len++; /* trailing null */ |
| 4075 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4076 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | name_len = strnlen(searchName, PATH_MAX); |
| 4078 | name_len++; /* trailing null */ |
| 4079 | strncpy(pSMB->RequestFileName, searchName, name_len); |
| 4080 | } |
| 4081 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4082 | if (ses->server) { |
| 4083 | if (ses->server->secMode & |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4084 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 4085 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4086 | } |
| 4087 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4088 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4091 | pSMB->TotalDataCount = 0; |
| 4092 | pSMB->DataCount = 0; |
| 4093 | pSMB->DataOffset = 0; |
| 4094 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4095 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4096 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | pSMB->MaxSetupCount = 0; |
| 4098 | pSMB->Reserved = 0; |
| 4099 | pSMB->Flags = 0; |
| 4100 | pSMB->Timeout = 0; |
| 4101 | pSMB->Reserved2 = 0; |
| 4102 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4103 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | pSMB->SetupCount = 1; |
| 4105 | pSMB->Reserved3 = 0; |
| 4106 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4107 | byte_count = params + 3 /* pad */ ; |
| 4108 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4109 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4110 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
| 4111 | pSMB->hdr.smb_buf_length += byte_count; |
| 4112 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4113 | |
| 4114 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4115 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4116 | if (rc) { |
| 4117 | cFYI(1, ("Send error in GetDFSRefer = %d", rc)); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4118 | goto GetDFSRefExit; |
| 4119 | } |
| 4120 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4122 | /* BB Also check if enough total bytes returned? */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4123 | if (rc || (pSMBr->ByteCount < 17)) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4124 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4125 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4127 | |
| 4128 | cFYI(1, ("Decoding GetDFSRefer response BCC: %d Offset %d", |
| 4129 | pSMBr->ByteCount, |
| 4130 | le16_to_cpu(pSMBr->t2.DataOffset))); |
| 4131 | |
| 4132 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4133 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4134 | target_nodes, nls_codepage, remap, |
| 4135 | searchName); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4138 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | |
| 4140 | if (rc == -EAGAIN) |
| 4141 | goto getDFSRetry; |
| 4142 | |
| 4143 | return rc; |
| 4144 | } |
| 4145 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4146 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4147 | int |
| 4148 | SMBOldQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
| 4149 | { |
| 4150 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4151 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4152 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4153 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4154 | int rc = 0; |
| 4155 | int bytes_returned = 0; |
| 4156 | __u16 params, byte_count; |
| 4157 | |
| 4158 | cFYI(1, ("OldQFSInfo")); |
| 4159 | oldQFSInfoRetry: |
| 4160 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4161 | (void **) &pSMBr); |
| 4162 | if (rc) |
| 4163 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4164 | |
| 4165 | params = 2; /* level */ |
| 4166 | pSMB->TotalDataCount = 0; |
| 4167 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4168 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4169 | pSMB->MaxSetupCount = 0; |
| 4170 | pSMB->Reserved = 0; |
| 4171 | pSMB->Flags = 0; |
| 4172 | pSMB->Timeout = 0; |
| 4173 | pSMB->Reserved2 = 0; |
| 4174 | byte_count = params + 1 /* pad */ ; |
| 4175 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4176 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4177 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4178 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4179 | pSMB->DataCount = 0; |
| 4180 | pSMB->DataOffset = 0; |
| 4181 | pSMB->SetupCount = 1; |
| 4182 | pSMB->Reserved3 = 0; |
| 4183 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4184 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
| 4185 | pSMB->hdr.smb_buf_length += byte_count; |
| 4186 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4187 | |
| 4188 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4189 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4190 | if (rc) { |
| 4191 | cFYI(1, ("Send error in QFSInfo = %d", rc)); |
| 4192 | } else { /* decode response */ |
| 4193 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4194 | |
| 4195 | if (rc || (pSMBr->ByteCount < 18)) |
| 4196 | rc = -EIO; /* bad smb */ |
| 4197 | else { |
| 4198 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4199 | cFYI(1, ("qfsinf resp BCC: %d Offset %d", |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4200 | pSMBr->ByteCount, data_offset)); |
| 4201 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4202 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4203 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4204 | FSData->f_bsize = |
| 4205 | le16_to_cpu(response_data->BytesPerSector) * |
| 4206 | le32_to_cpu(response_data-> |
| 4207 | SectorsPerAllocationUnit); |
| 4208 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4209 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4210 | FSData->f_bfree = FSData->f_bavail = |
| 4211 | le32_to_cpu(response_data->FreeAllocationUnits); |
| 4212 | cFYI(1, |
| 4213 | ("Blocks: %lld Free: %lld Block size %ld", |
| 4214 | (unsigned long long)FSData->f_blocks, |
| 4215 | (unsigned long long)FSData->f_bfree, |
| 4216 | FSData->f_bsize)); |
| 4217 | } |
| 4218 | } |
| 4219 | cifs_buf_release(pSMB); |
| 4220 | |
| 4221 | if (rc == -EAGAIN) |
| 4222 | goto oldQFSInfoRetry; |
| 4223 | |
| 4224 | return rc; |
| 4225 | } |
| 4226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4228 | CIFSSMBQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | { |
| 4230 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4231 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4232 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4233 | FILE_SYSTEM_INFO *response_data; |
| 4234 | int rc = 0; |
| 4235 | int bytes_returned = 0; |
| 4236 | __u16 params, byte_count; |
| 4237 | |
| 4238 | cFYI(1, ("In QFSInfo")); |
| 4239 | QFSInfoRetry: |
| 4240 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4241 | (void **) &pSMBr); |
| 4242 | if (rc) |
| 4243 | return rc; |
| 4244 | |
| 4245 | params = 2; /* level */ |
| 4246 | pSMB->TotalDataCount = 0; |
| 4247 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4248 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | pSMB->MaxSetupCount = 0; |
| 4250 | pSMB->Reserved = 0; |
| 4251 | pSMB->Flags = 0; |
| 4252 | pSMB->Timeout = 0; |
| 4253 | pSMB->Reserved2 = 0; |
| 4254 | byte_count = params + 1 /* pad */ ; |
| 4255 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4256 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4257 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4258 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | pSMB->DataCount = 0; |
| 4260 | pSMB->DataOffset = 0; |
| 4261 | pSMB->SetupCount = 1; |
| 4262 | pSMB->Reserved3 = 0; |
| 4263 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4264 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
| 4265 | pSMB->hdr.smb_buf_length += byte_count; |
| 4266 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4267 | |
| 4268 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4269 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4270 | if (rc) { |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4271 | cFYI(1, ("Send error in QFSInfo = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4273 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4275 | if (rc || (pSMBr->ByteCount < 24)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | rc = -EIO; /* bad smb */ |
| 4277 | else { |
| 4278 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | |
| 4280 | response_data = |
| 4281 | (FILE_SYSTEM_INFO |
| 4282 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4283 | data_offset); |
| 4284 | FSData->f_bsize = |
| 4285 | le32_to_cpu(response_data->BytesPerSector) * |
| 4286 | le32_to_cpu(response_data-> |
| 4287 | SectorsPerAllocationUnit); |
| 4288 | FSData->f_blocks = |
| 4289 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 4290 | FSData->f_bfree = FSData->f_bavail = |
| 4291 | le64_to_cpu(response_data->FreeAllocationUnits); |
| 4292 | cFYI(1, |
| 4293 | ("Blocks: %lld Free: %lld Block size %ld", |
| 4294 | (unsigned long long)FSData->f_blocks, |
| 4295 | (unsigned long long)FSData->f_bfree, |
| 4296 | FSData->f_bsize)); |
| 4297 | } |
| 4298 | } |
| 4299 | cifs_buf_release(pSMB); |
| 4300 | |
| 4301 | if (rc == -EAGAIN) |
| 4302 | goto QFSInfoRetry; |
| 4303 | |
| 4304 | return rc; |
| 4305 | } |
| 4306 | |
| 4307 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4308 | CIFSSMBQFSAttributeInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | { |
| 4310 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4311 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4312 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4313 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 4314 | int rc = 0; |
| 4315 | int bytes_returned = 0; |
| 4316 | __u16 params, byte_count; |
| 4317 | |
| 4318 | cFYI(1, ("In QFSAttributeInfo")); |
| 4319 | QFSAttributeRetry: |
| 4320 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4321 | (void **) &pSMBr); |
| 4322 | if (rc) |
| 4323 | return rc; |
| 4324 | |
| 4325 | params = 2; /* level */ |
| 4326 | pSMB->TotalDataCount = 0; |
| 4327 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4328 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4329 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | pSMB->MaxSetupCount = 0; |
| 4331 | pSMB->Reserved = 0; |
| 4332 | pSMB->Flags = 0; |
| 4333 | pSMB->Timeout = 0; |
| 4334 | pSMB->Reserved2 = 0; |
| 4335 | byte_count = params + 1 /* pad */ ; |
| 4336 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4337 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4338 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4339 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | pSMB->DataCount = 0; |
| 4341 | pSMB->DataOffset = 0; |
| 4342 | pSMB->SetupCount = 1; |
| 4343 | pSMB->Reserved3 = 0; |
| 4344 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4345 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
| 4346 | pSMB->hdr.smb_buf_length += byte_count; |
| 4347 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4348 | |
| 4349 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4350 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4351 | if (rc) { |
| 4352 | cERROR(1, ("Send error in QFSAttributeInfo = %d", rc)); |
| 4353 | } else { /* decode response */ |
| 4354 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4355 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4356 | if (rc || (pSMBr->ByteCount < 13)) { |
| 4357 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | rc = -EIO; /* bad smb */ |
| 4359 | } else { |
| 4360 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4361 | response_data = |
| 4362 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 4363 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4364 | data_offset); |
| 4365 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4366 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | cifs_buf_release(pSMB); |
| 4370 | |
| 4371 | if (rc == -EAGAIN) |
| 4372 | goto QFSAttributeRetry; |
| 4373 | |
| 4374 | return rc; |
| 4375 | } |
| 4376 | |
| 4377 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4378 | CIFSSMBQFSDeviceInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | { |
| 4380 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4381 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4382 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4383 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 4384 | int rc = 0; |
| 4385 | int bytes_returned = 0; |
| 4386 | __u16 params, byte_count; |
| 4387 | |
| 4388 | cFYI(1, ("In QFSDeviceInfo")); |
| 4389 | QFSDeviceRetry: |
| 4390 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4391 | (void **) &pSMBr); |
| 4392 | if (rc) |
| 4393 | return rc; |
| 4394 | |
| 4395 | params = 2; /* level */ |
| 4396 | pSMB->TotalDataCount = 0; |
| 4397 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4398 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4399 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | pSMB->MaxSetupCount = 0; |
| 4401 | pSMB->Reserved = 0; |
| 4402 | pSMB->Flags = 0; |
| 4403 | pSMB->Timeout = 0; |
| 4404 | pSMB->Reserved2 = 0; |
| 4405 | byte_count = params + 1 /* pad */ ; |
| 4406 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4407 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4408 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4409 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | |
| 4411 | pSMB->DataCount = 0; |
| 4412 | pSMB->DataOffset = 0; |
| 4413 | pSMB->SetupCount = 1; |
| 4414 | pSMB->Reserved3 = 0; |
| 4415 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4416 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
| 4417 | pSMB->hdr.smb_buf_length += byte_count; |
| 4418 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4419 | |
| 4420 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4421 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4422 | if (rc) { |
| 4423 | cFYI(1, ("Send error in QFSDeviceInfo = %d", rc)); |
| 4424 | } else { /* decode response */ |
| 4425 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4426 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4427 | if (rc || (pSMBr->ByteCount < sizeof(FILE_SYSTEM_DEVICE_INFO))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | rc = -EIO; /* bad smb */ |
| 4429 | else { |
| 4430 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4431 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4432 | (FILE_SYSTEM_DEVICE_INFO *) |
| 4433 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | data_offset); |
| 4435 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4436 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | } |
| 4438 | } |
| 4439 | cifs_buf_release(pSMB); |
| 4440 | |
| 4441 | if (rc == -EAGAIN) |
| 4442 | goto QFSDeviceRetry; |
| 4443 | |
| 4444 | return rc; |
| 4445 | } |
| 4446 | |
| 4447 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4448 | CIFSSMBQFSUnixInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | { |
| 4450 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 4451 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4452 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4453 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 4454 | int rc = 0; |
| 4455 | int bytes_returned = 0; |
| 4456 | __u16 params, byte_count; |
| 4457 | |
| 4458 | cFYI(1, ("In QFSUnixInfo")); |
| 4459 | QFSUnixRetry: |
| 4460 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4461 | (void **) &pSMBr); |
| 4462 | if (rc) |
| 4463 | return rc; |
| 4464 | |
| 4465 | params = 2; /* level */ |
| 4466 | pSMB->TotalDataCount = 0; |
| 4467 | pSMB->DataCount = 0; |
| 4468 | pSMB->DataOffset = 0; |
| 4469 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4470 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4471 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | pSMB->MaxSetupCount = 0; |
| 4473 | pSMB->Reserved = 0; |
| 4474 | pSMB->Flags = 0; |
| 4475 | pSMB->Timeout = 0; |
| 4476 | pSMB->Reserved2 = 0; |
| 4477 | byte_count = params + 1 /* pad */ ; |
| 4478 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4479 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4480 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 4481 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | pSMB->SetupCount = 1; |
| 4483 | pSMB->Reserved3 = 0; |
| 4484 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4485 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
| 4486 | pSMB->hdr.smb_buf_length += byte_count; |
| 4487 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4488 | |
| 4489 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4490 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4491 | if (rc) { |
| 4492 | cERROR(1, ("Send error in QFSUnixInfo = %d", rc)); |
| 4493 | } else { /* decode response */ |
| 4494 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4495 | |
| 4496 | if (rc || (pSMBr->ByteCount < 13)) { |
| 4497 | rc = -EIO; /* bad smb */ |
| 4498 | } else { |
| 4499 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4500 | response_data = |
| 4501 | (FILE_SYSTEM_UNIX_INFO |
| 4502 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4503 | data_offset); |
| 4504 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4505 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | } |
| 4507 | } |
| 4508 | cifs_buf_release(pSMB); |
| 4509 | |
| 4510 | if (rc == -EAGAIN) |
| 4511 | goto QFSUnixRetry; |
| 4512 | |
| 4513 | |
| 4514 | return rc; |
| 4515 | } |
| 4516 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4517 | int |
Steve French | 45abc6e | 2005-06-23 13:42:03 -0500 | [diff] [blame] | 4518 | CIFSSMBSetFSUnixInfo(const int xid, struct cifsTconInfo *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4519 | { |
| 4520 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 4521 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 4522 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 4523 | int rc = 0; |
| 4524 | int bytes_returned = 0; |
| 4525 | __u16 params, param_offset, offset, byte_count; |
| 4526 | |
| 4527 | cFYI(1, ("In SETFSUnixInfo")); |
| 4528 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 4529 | /* BB switch to small buf init to save memory */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4530 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4531 | (void **) &pSMBr); |
| 4532 | if (rc) |
| 4533 | return rc; |
| 4534 | |
| 4535 | params = 4; /* 2 bytes zero followed by info level. */ |
| 4536 | pSMB->MaxSetupCount = 0; |
| 4537 | pSMB->Reserved = 0; |
| 4538 | pSMB->Flags = 0; |
| 4539 | pSMB->Timeout = 0; |
| 4540 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4541 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 4542 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4543 | offset = param_offset + params; |
| 4544 | |
| 4545 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4546 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4547 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4548 | pSMB->SetupCount = 1; |
| 4549 | pSMB->Reserved3 = 0; |
| 4550 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 4551 | byte_count = 1 /* pad */ + params + 12; |
| 4552 | |
| 4553 | pSMB->DataCount = cpu_to_le16(12); |
| 4554 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4555 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4556 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4557 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4558 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4559 | |
| 4560 | /* Params. */ |
| 4561 | pSMB->FileNum = 0; |
| 4562 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 4563 | |
| 4564 | /* Data. */ |
| 4565 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 4566 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 4567 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 4568 | |
| 4569 | pSMB->hdr.smb_buf_length += byte_count; |
| 4570 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4571 | |
| 4572 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4573 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4574 | if (rc) { |
| 4575 | cERROR(1, ("Send error in SETFSUnixInfo = %d", rc)); |
| 4576 | } else { /* decode response */ |
| 4577 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4578 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4579 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4580 | } |
| 4581 | cifs_buf_release(pSMB); |
| 4582 | |
| 4583 | if (rc == -EAGAIN) |
| 4584 | goto SETFSUnixRetry; |
| 4585 | |
| 4586 | return rc; |
| 4587 | } |
| 4588 | |
| 4589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | |
| 4591 | int |
| 4592 | CIFSSMBQFSPosixInfo(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4593 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | { |
| 4595 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 4596 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4597 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4598 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 4599 | int rc = 0; |
| 4600 | int bytes_returned = 0; |
| 4601 | __u16 params, byte_count; |
| 4602 | |
| 4603 | cFYI(1, ("In QFSPosixInfo")); |
| 4604 | QFSPosixRetry: |
| 4605 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4606 | (void **) &pSMBr); |
| 4607 | if (rc) |
| 4608 | return rc; |
| 4609 | |
| 4610 | params = 2; /* level */ |
| 4611 | pSMB->TotalDataCount = 0; |
| 4612 | pSMB->DataCount = 0; |
| 4613 | pSMB->DataOffset = 0; |
| 4614 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4615 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4616 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | pSMB->MaxSetupCount = 0; |
| 4618 | pSMB->Reserved = 0; |
| 4619 | pSMB->Flags = 0; |
| 4620 | pSMB->Timeout = 0; |
| 4621 | pSMB->Reserved2 = 0; |
| 4622 | byte_count = params + 1 /* pad */ ; |
| 4623 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4624 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4625 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 4626 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | pSMB->SetupCount = 1; |
| 4628 | pSMB->Reserved3 = 0; |
| 4629 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4630 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
| 4631 | pSMB->hdr.smb_buf_length += byte_count; |
| 4632 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4633 | |
| 4634 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4635 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4636 | if (rc) { |
| 4637 | cFYI(1, ("Send error in QFSUnixInfo = %d", rc)); |
| 4638 | } else { /* decode response */ |
| 4639 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4640 | |
| 4641 | if (rc || (pSMBr->ByteCount < 13)) { |
| 4642 | rc = -EIO; /* bad smb */ |
| 4643 | } else { |
| 4644 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4645 | response_data = |
| 4646 | (FILE_SYSTEM_POSIX_INFO |
| 4647 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4648 | data_offset); |
| 4649 | FSData->f_bsize = |
| 4650 | le32_to_cpu(response_data->BlockSize); |
| 4651 | FSData->f_blocks = |
| 4652 | le64_to_cpu(response_data->TotalBlocks); |
| 4653 | FSData->f_bfree = |
| 4654 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4655 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | FSData->f_bavail = FSData->f_bfree; |
| 4657 | } else { |
| 4658 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4659 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4661 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4663 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4664 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4666 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4667 | } |
| 4668 | } |
| 4669 | cifs_buf_release(pSMB); |
| 4670 | |
| 4671 | if (rc == -EAGAIN) |
| 4672 | goto QFSPosixRetry; |
| 4673 | |
| 4674 | return rc; |
| 4675 | } |
| 4676 | |
| 4677 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4678 | /* We can not use write of zero bytes trick to |
| 4679 | set file size due to need for large file support. Also note that |
| 4680 | this SetPathInfo is preferred to SetFileInfo based method in next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4681 | routine which is only needed to work around a sharing violation bug |
| 4682 | in Samba which this routine can run into */ |
| 4683 | |
| 4684 | int |
| 4685 | CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4686 | __u64 size, bool SetAllocation, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4687 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | { |
| 4689 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 4690 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 4691 | struct file_end_of_file_info *parm_data; |
| 4692 | int name_len; |
| 4693 | int rc = 0; |
| 4694 | int bytes_returned = 0; |
| 4695 | __u16 params, byte_count, data_count, param_offset, offset; |
| 4696 | |
| 4697 | cFYI(1, ("In SetEOF")); |
| 4698 | SetEOFRetry: |
| 4699 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4700 | (void **) &pSMBr); |
| 4701 | if (rc) |
| 4702 | return rc; |
| 4703 | |
| 4704 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4705 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4706 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4707 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | name_len++; /* trailing null */ |
| 4709 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 4710 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | name_len = strnlen(fileName, PATH_MAX); |
| 4712 | name_len++; /* trailing null */ |
| 4713 | strncpy(pSMB->FileName, fileName, name_len); |
| 4714 | } |
| 4715 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4716 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4717 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 4718 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | pSMB->MaxSetupCount = 0; |
| 4720 | pSMB->Reserved = 0; |
| 4721 | pSMB->Flags = 0; |
| 4722 | pSMB->Timeout = 0; |
| 4723 | pSMB->Reserved2 = 0; |
| 4724 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4725 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | offset = param_offset + params; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4727 | if (SetAllocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4728 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4729 | pSMB->InformationLevel = |
| 4730 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 4731 | else |
| 4732 | pSMB->InformationLevel = |
| 4733 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 4734 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4735 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4736 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4737 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | else |
| 4739 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4740 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4741 | } |
| 4742 | |
| 4743 | parm_data = |
| 4744 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 4745 | offset); |
| 4746 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4747 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4748 | pSMB->SetupCount = 1; |
| 4749 | pSMB->Reserved3 = 0; |
| 4750 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 4751 | byte_count = 3 /* pad */ + params + data_count; |
| 4752 | pSMB->DataCount = cpu_to_le16(data_count); |
| 4753 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4754 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4755 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4756 | pSMB->Reserved4 = 0; |
| 4757 | pSMB->hdr.smb_buf_length += byte_count; |
| 4758 | parm_data->FileSize = cpu_to_le64(size); |
| 4759 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4760 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4761 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4762 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | cFYI(1, ("SetPathInfo (file size) returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | |
| 4765 | cifs_buf_release(pSMB); |
| 4766 | |
| 4767 | if (rc == -EAGAIN) |
| 4768 | goto SetEOFRetry; |
| 4769 | |
| 4770 | return rc; |
| 4771 | } |
| 4772 | |
| 4773 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4774 | CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4775 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | { |
| 4777 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4778 | char *data_offset; |
| 4779 | struct file_end_of_file_info *parm_data; |
| 4780 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | __u16 params, param_offset, offset, byte_count, count; |
| 4782 | |
| 4783 | cFYI(1, ("SetFileSize (via SetFileInfo) %lld", |
| 4784 | (long long)size)); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 4785 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 4786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | if (rc) |
| 4788 | return rc; |
| 4789 | |
| 4790 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 4791 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | params = 6; |
| 4794 | pSMB->MaxSetupCount = 0; |
| 4795 | pSMB->Reserved = 0; |
| 4796 | pSMB->Flags = 0; |
| 4797 | pSMB->Timeout = 0; |
| 4798 | pSMB->Reserved2 = 0; |
| 4799 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 4800 | offset = param_offset + params; |
| 4801 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4802 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4803 | |
| 4804 | count = sizeof(struct file_end_of_file_info); |
| 4805 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4806 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4807 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | pSMB->SetupCount = 1; |
| 4809 | pSMB->Reserved3 = 0; |
| 4810 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 4811 | byte_count = 3 /* pad */ + params + count; |
| 4812 | pSMB->DataCount = cpu_to_le16(count); |
| 4813 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4814 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4815 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4816 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4817 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4818 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 4819 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4821 | parm_data->FileSize = cpu_to_le64(size); |
| 4822 | pSMB->Fid = fid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4823 | if (SetAllocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4824 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4825 | pSMB->InformationLevel = |
| 4826 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 4827 | else |
| 4828 | pSMB->InformationLevel = |
| 4829 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4830 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4832 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4833 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4834 | else |
| 4835 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4836 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | } |
| 4838 | pSMB->Reserved4 = 0; |
| 4839 | pSMB->hdr.smb_buf_length += byte_count; |
| 4840 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 4841 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | if (rc) { |
| 4843 | cFYI(1, |
| 4844 | ("Send error in SetFileInfo (SetFileSize) = %d", |
| 4845 | rc)); |
| 4846 | } |
| 4847 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4848 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | since file handle passed in no longer valid */ |
| 4850 | |
| 4851 | return rc; |
| 4852 | } |
| 4853 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4854 | /* 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] | 4855 | an open handle, rather than by pathname - this is awkward due to |
| 4856 | potential access conflicts on the open, but it is unavoidable for these |
| 4857 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 4858 | time and resort to the original setpathinfo level which takes the ancient |
| 4859 | DOS time format with 2 second granularity */ |
| 4860 | int |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 4861 | CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 4862 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | { |
| 4864 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | char *data_offset; |
| 4866 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | __u16 params, param_offset, offset, byte_count, count; |
| 4868 | |
| 4869 | cFYI(1, ("Set Times (via SetFileInfo)")); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 4870 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 4871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | if (rc) |
| 4873 | return rc; |
| 4874 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 4875 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 4876 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | params = 6; |
| 4879 | pSMB->MaxSetupCount = 0; |
| 4880 | pSMB->Reserved = 0; |
| 4881 | pSMB->Flags = 0; |
| 4882 | pSMB->Timeout = 0; |
| 4883 | pSMB->Reserved2 = 0; |
| 4884 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 4885 | offset = param_offset + params; |
| 4886 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4887 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4889 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4891 | /* BB find max SMB PDU from sess */ |
| 4892 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | pSMB->SetupCount = 1; |
| 4894 | pSMB->Reserved3 = 0; |
| 4895 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 4896 | byte_count = 3 /* pad */ + params + count; |
| 4897 | pSMB->DataCount = cpu_to_le16(count); |
| 4898 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4899 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4900 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4901 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4902 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4903 | pSMB->Fid = fid; |
| 4904 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4905 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 4906 | else |
| 4907 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 4908 | pSMB->Reserved4 = 0; |
| 4909 | pSMB->hdr.smb_buf_length += byte_count; |
| 4910 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4911 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 4912 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4913 | if (rc) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4914 | cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4916 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | since file handle passed in no longer valid */ |
| 4918 | |
| 4919 | return rc; |
| 4920 | } |
| 4921 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 4922 | int |
| 4923 | CIFSSMBSetFileDisposition(const int xid, struct cifsTconInfo *tcon, |
| 4924 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 4925 | { |
| 4926 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 4927 | char *data_offset; |
| 4928 | int rc = 0; |
| 4929 | __u16 params, param_offset, offset, byte_count, count; |
| 4930 | |
| 4931 | cFYI(1, ("Set File Disposition (via SetFileInfo)")); |
| 4932 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 4933 | |
| 4934 | if (rc) |
| 4935 | return rc; |
| 4936 | |
| 4937 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 4938 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 4939 | |
| 4940 | params = 6; |
| 4941 | pSMB->MaxSetupCount = 0; |
| 4942 | pSMB->Reserved = 0; |
| 4943 | pSMB->Flags = 0; |
| 4944 | pSMB->Timeout = 0; |
| 4945 | pSMB->Reserved2 = 0; |
| 4946 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 4947 | offset = param_offset + params; |
| 4948 | |
| 4949 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 4950 | |
| 4951 | count = 1; |
| 4952 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4953 | /* BB find max SMB PDU from sess */ |
| 4954 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4955 | pSMB->SetupCount = 1; |
| 4956 | pSMB->Reserved3 = 0; |
| 4957 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 4958 | byte_count = 3 /* pad */ + params + count; |
| 4959 | pSMB->DataCount = cpu_to_le16(count); |
| 4960 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4961 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4962 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4963 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4964 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4965 | pSMB->Fid = fid; |
| 4966 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 4967 | pSMB->Reserved4 = 0; |
| 4968 | pSMB->hdr.smb_buf_length += byte_count; |
| 4969 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4970 | *data_offset = delete_file ? 1 : 0; |
| 4971 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 4972 | if (rc) |
| 4973 | cFYI(1, ("Send error in SetFileDisposition = %d", rc)); |
| 4974 | |
| 4975 | return rc; |
| 4976 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | |
| 4978 | int |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 4979 | CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 4980 | const char *fileName, const FILE_BASIC_INFO *data, |
| 4981 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | { |
| 4983 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 4984 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 4985 | int name_len; |
| 4986 | int rc = 0; |
| 4987 | int bytes_returned = 0; |
| 4988 | char *data_offset; |
| 4989 | __u16 params, param_offset, offset, byte_count, count; |
| 4990 | |
| 4991 | cFYI(1, ("In SetTimes")); |
| 4992 | |
| 4993 | SetTimesRetry: |
| 4994 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4995 | (void **) &pSMBr); |
| 4996 | if (rc) |
| 4997 | return rc; |
| 4998 | |
| 4999 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5000 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 5001 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5002 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | name_len++; /* trailing null */ |
| 5004 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5005 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | name_len = strnlen(fileName, PATH_MAX); |
| 5007 | name_len++; /* trailing null */ |
| 5008 | strncpy(pSMB->FileName, fileName, name_len); |
| 5009 | } |
| 5010 | |
| 5011 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5012 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5013 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5014 | /* BB find max SMB PDU from sess structure BB */ |
| 5015 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | pSMB->MaxSetupCount = 0; |
| 5017 | pSMB->Reserved = 0; |
| 5018 | pSMB->Flags = 0; |
| 5019 | pSMB->Timeout = 0; |
| 5020 | pSMB->Reserved2 = 0; |
| 5021 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5022 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | offset = param_offset + params; |
| 5024 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5025 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5026 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5027 | pSMB->SetupCount = 1; |
| 5028 | pSMB->Reserved3 = 0; |
| 5029 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5030 | byte_count = 3 /* pad */ + params + count; |
| 5031 | |
| 5032 | pSMB->DataCount = cpu_to_le16(count); |
| 5033 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5034 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5035 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5036 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5037 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5038 | else |
| 5039 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5040 | pSMB->Reserved4 = 0; |
| 5041 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5042 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5044 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5045 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5046 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | cFYI(1, ("SetPathInfo (times) returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | |
| 5049 | cifs_buf_release(pSMB); |
| 5050 | |
| 5051 | if (rc == -EAGAIN) |
| 5052 | goto SetTimesRetry; |
| 5053 | |
| 5054 | return rc; |
| 5055 | } |
| 5056 | |
| 5057 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5058 | /* Can be used to set attributes */ |
| 5059 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5060 | handling it anyway and NT4 was what we thought it would be needed for |
| 5061 | Do not delete it until we prove whether needed for Win9x though */ |
| 5062 | int |
| 5063 | CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName, |
| 5064 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5065 | { |
| 5066 | SETATTR_REQ *pSMB = NULL; |
| 5067 | SETATTR_RSP *pSMBr = NULL; |
| 5068 | int rc = 0; |
| 5069 | int bytes_returned; |
| 5070 | int name_len; |
| 5071 | |
| 5072 | cFYI(1, ("In SetAttrLegacy")); |
| 5073 | |
| 5074 | SetAttrLgcyRetry: |
| 5075 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5076 | (void **) &pSMBr); |
| 5077 | if (rc) |
| 5078 | return rc; |
| 5079 | |
| 5080 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5081 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5082 | ConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 | PATH_MAX, nls_codepage); |
| 5084 | name_len++; /* trailing null */ |
| 5085 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5086 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5087 | name_len = strnlen(fileName, PATH_MAX); |
| 5088 | name_len++; /* trailing null */ |
| 5089 | strncpy(pSMB->fileName, fileName, name_len); |
| 5090 | } |
| 5091 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5092 | pSMB->BufferFormat = 0x04; |
| 5093 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 5094 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5095 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5096 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5097 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | cFYI(1, ("Error in LegacySetAttr = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | |
| 5100 | cifs_buf_release(pSMB); |
| 5101 | |
| 5102 | if (rc == -EAGAIN) |
| 5103 | goto SetAttrLgcyRetry; |
| 5104 | |
| 5105 | return rc; |
| 5106 | } |
| 5107 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5108 | |
| 5109 | int |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5110 | CIFSSMBUnixSetInfo(const int xid, struct cifsTconInfo *tcon, char *fileName, |
Steve French | 063ea27 | 2008-08-06 04:23:13 +0000 | [diff] [blame] | 5111 | const struct cifs_unix_set_info_args *args, |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5112 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5113 | { |
| 5114 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5115 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5116 | int name_len; |
| 5117 | int rc = 0; |
| 5118 | int bytes_returned = 0; |
| 5119 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5120 | __u16 params, param_offset, offset, count, byte_count; |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5121 | __u64 mode = args->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 | |
| 5123 | cFYI(1, ("In SetUID/GID/Mode")); |
| 5124 | setPermsRetry: |
| 5125 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5126 | (void **) &pSMBr); |
| 5127 | if (rc) |
| 5128 | return rc; |
| 5129 | |
| 5130 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5131 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5132 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5133 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | name_len++; /* trailing null */ |
| 5135 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5136 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5137 | name_len = strnlen(fileName, PATH_MAX); |
| 5138 | name_len++; /* trailing null */ |
| 5139 | strncpy(pSMB->FileName, fileName, name_len); |
| 5140 | } |
| 5141 | |
| 5142 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5143 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5144 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5145 | /* BB find max SMB PDU from sess structure BB */ |
| 5146 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | pSMB->MaxSetupCount = 0; |
| 5148 | pSMB->Reserved = 0; |
| 5149 | pSMB->Flags = 0; |
| 5150 | pSMB->Timeout = 0; |
| 5151 | pSMB->Reserved2 = 0; |
| 5152 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5153 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | offset = param_offset + params; |
| 5155 | data_offset = |
| 5156 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 5157 | offset); |
| 5158 | memset(data_offset, 0, count); |
| 5159 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5160 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5161 | pSMB->SetupCount = 1; |
| 5162 | pSMB->Reserved3 = 0; |
| 5163 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5164 | byte_count = 3 /* pad */ + params + count; |
| 5165 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5166 | pSMB->DataCount = cpu_to_le16(count); |
| 5167 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5168 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5169 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5170 | pSMB->Reserved4 = 0; |
| 5171 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | c7af185 | 2007-03-01 04:11:22 +0000 | [diff] [blame] | 5172 | /* Samba server ignores set of file size to zero due to bugs in some |
| 5173 | older clients, but we should be precise - we use SetFileSize to |
| 5174 | set file size and do not want to truncate file size to zero |
| 5175 | accidently as happened on one Samba server beta by putting |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5176 | zero instead of -1 here */ |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5177 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5178 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5179 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5180 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5181 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
| 5182 | data_offset->Uid = cpu_to_le64(args->uid); |
| 5183 | data_offset->Gid = cpu_to_le64(args->gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | /* better to leave device as zero when it is */ |
Jeff Layton | 4e1e7fb | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5185 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5186 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5187 | data_offset->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5188 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5189 | if (S_ISREG(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5191 | else if (S_ISDIR(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5193 | else if (S_ISLNK(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5194 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5195 | else if (S_ISCHR(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5196 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5197 | else if (S_ISBLK(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5199 | else if (S_ISFIFO(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5201 | else if (S_ISSOCK(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5202 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5203 | |
| 5204 | |
| 5205 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5206 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5207 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5208 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | cFYI(1, ("SetPathInfo (perms) returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5211 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5212 | if (rc == -EAGAIN) |
| 5213 | goto setPermsRetry; |
| 5214 | return rc; |
| 5215 | } |
| 5216 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5217 | int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, |
Steve French | 167a251 | 2005-08-24 20:03:11 -0700 | [diff] [blame] | 5218 | const int notify_subdirs, const __u16 netfid, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5219 | __u32 filter, struct file *pfile, int multishot, |
Steve French | 167a251 | 2005-08-24 20:03:11 -0700 | [diff] [blame] | 5220 | const struct nls_table *nls_codepage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5221 | { |
| 5222 | int rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5223 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 5224 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
Steve French | abb15b8 | 2005-08-24 18:51:02 -0700 | [diff] [blame] | 5225 | struct dir_notify_req *dnotify_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | int bytes_returned; |
| 5227 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5228 | cFYI(1, ("In CIFSSMBNotify for file handle %d", (int)netfid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5230 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 | if (rc) |
| 5232 | return rc; |
| 5233 | |
| 5234 | pSMB->TotalParameterCount = 0 ; |
| 5235 | pSMB->TotalDataCount = 0; |
| 5236 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 5237 | /* BB find exact data count max from sess structure BB */ |
| 5238 | pSMB->MaxDataCount = 0; /* same in little endian or be */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 5239 | /* BB VERIFY verify which is correct for above BB */ |
| 5240 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 5241 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 5242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5243 | pSMB->MaxSetupCount = 4; |
| 5244 | pSMB->Reserved = 0; |
| 5245 | pSMB->ParameterOffset = 0; |
| 5246 | pSMB->DataCount = 0; |
| 5247 | pSMB->DataOffset = 0; |
| 5248 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 5249 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 5250 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5251 | if (notify_subdirs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5252 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 5253 | pSMB->Reserved2 = 0; |
| 5254 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 5255 | pSMB->Fid = netfid; /* file handle always le */ |
| 5256 | pSMB->ByteCount = 0; |
| 5257 | |
| 5258 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 5259 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 5260 | CIFS_ASYNC_OP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | if (rc) { |
| 5262 | cFYI(1, ("Error in Notify = %d", rc)); |
Steve French | ff5dbd9 | 2005-08-24 17:10:36 -0700 | [diff] [blame] | 5263 | } else { |
| 5264 | /* Add file to outstanding requests */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5265 | /* BB change to kmem cache alloc */ |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 5266 | dnotify_req = kmalloc( |
Steve French | 47c786e | 2005-10-11 20:03:18 -0700 | [diff] [blame] | 5267 | sizeof(struct dir_notify_req), |
| 5268 | GFP_KERNEL); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5269 | if (dnotify_req) { |
Steve French | 47c786e | 2005-10-11 20:03:18 -0700 | [diff] [blame] | 5270 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 5271 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 5272 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 5273 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 5274 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 5275 | dnotify_req->netfid = netfid; |
| 5276 | dnotify_req->pfile = pfile; |
| 5277 | dnotify_req->filter = filter; |
| 5278 | dnotify_req->multishot = multishot; |
| 5279 | spin_lock(&GlobalMid_Lock); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5280 | list_add_tail(&dnotify_req->lhead, |
Steve French | 47c786e | 2005-10-11 20:03:18 -0700 | [diff] [blame] | 5281 | &GlobalDnotifyReqList); |
| 5282 | spin_unlock(&GlobalMid_Lock); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5283 | } else |
Steve French | 47c786e | 2005-10-11 20:03:18 -0700 | [diff] [blame] | 5284 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5285 | } |
| 5286 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5287 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5288 | } |
| 5289 | #ifdef CONFIG_CIFS_XATTR |
| 5290 | ssize_t |
| 5291 | CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, |
| 5292 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5293 | char *EAData, size_t buf_size, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5294 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5295 | { |
| 5296 | /* BB assumes one setup word */ |
| 5297 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 5298 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 5299 | int rc = 0; |
| 5300 | int bytes_returned; |
| 5301 | int name_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5302 | struct fea *temp_fea; |
| 5303 | char *temp_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5304 | __u16 params, byte_count; |
| 5305 | |
| 5306 | cFYI(1, ("In Query All EAs path %s", searchName)); |
| 5307 | QAllEAsRetry: |
| 5308 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5309 | (void **) &pSMBr); |
| 5310 | if (rc) |
| 5311 | return rc; |
| 5312 | |
| 5313 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5314 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5315 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5316 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5317 | name_len++; /* trailing null */ |
| 5318 | name_len *= 2; |
| 5319 | } else { /* BB improve the check for buffer overruns BB */ |
| 5320 | name_len = strnlen(searchName, PATH_MAX); |
| 5321 | name_len++; /* trailing null */ |
| 5322 | strncpy(pSMB->FileName, searchName, name_len); |
| 5323 | } |
| 5324 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5325 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | pSMB->TotalDataCount = 0; |
| 5327 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5328 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5329 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5330 | pSMB->MaxSetupCount = 0; |
| 5331 | pSMB->Reserved = 0; |
| 5332 | pSMB->Flags = 0; |
| 5333 | pSMB->Timeout = 0; |
| 5334 | pSMB->Reserved2 = 0; |
| 5335 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5336 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5337 | pSMB->DataCount = 0; |
| 5338 | pSMB->DataOffset = 0; |
| 5339 | pSMB->SetupCount = 1; |
| 5340 | pSMB->Reserved3 = 0; |
| 5341 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 5342 | byte_count = params + 1 /* pad */ ; |
| 5343 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5344 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5345 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 5346 | pSMB->Reserved4 = 0; |
| 5347 | pSMB->hdr.smb_buf_length += byte_count; |
| 5348 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5349 | |
| 5350 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5351 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5352 | if (rc) { |
| 5353 | cFYI(1, ("Send error in QueryAllEAs = %d", rc)); |
| 5354 | } else { /* decode response */ |
| 5355 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5356 | |
| 5357 | /* BB also check enough total bytes returned */ |
| 5358 | /* BB we need to improve the validity checking |
| 5359 | of these trans2 responses */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5360 | if (rc || (pSMBr->ByteCount < 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | rc = -EIO; /* bad smb */ |
| 5362 | /* else if (pFindData){ |
| 5363 | memcpy((char *) pFindData, |
| 5364 | (char *) &pSMBr->hdr.Protocol + |
| 5365 | data_offset, kl); |
| 5366 | }*/ else { |
| 5367 | /* check that length of list is not more than bcc */ |
| 5368 | /* check that each entry does not go beyond length |
| 5369 | of list */ |
| 5370 | /* check that each element of each entry does not |
| 5371 | go beyond end of list */ |
| 5372 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5373 | struct fealist *ea_response_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5374 | rc = 0; |
| 5375 | /* validate_trans2_offsets() */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5376 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 | ea_response_data = (struct fealist *) |
| 5378 | (((char *) &pSMBr->hdr.Protocol) + |
| 5379 | data_offset); |
| 5380 | name_len = le32_to_cpu(ea_response_data->list_len); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5381 | cFYI(1, ("ea length %d", name_len)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5382 | if (name_len <= 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | /* returned EA size zeroed at top of function */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5384 | cFYI(1, ("empty EA list returned from server")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5385 | } else { |
| 5386 | /* account for ea list len */ |
| 5387 | name_len -= 4; |
| 5388 | temp_fea = ea_response_data->list; |
| 5389 | temp_ptr = (char *)temp_fea; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5390 | while (name_len > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | __u16 value_len; |
| 5392 | name_len -= 4; |
| 5393 | temp_ptr += 4; |
| 5394 | rc += temp_fea->name_len; |
| 5395 | /* account for prefix user. and trailing null */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5396 | rc = rc + 5 + 1; |
| 5397 | if (rc < (int)buf_size) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5398 | memcpy(EAData, "user.", 5); |
| 5399 | EAData += 5; |
| 5400 | memcpy(EAData, temp_ptr, |
| 5401 | temp_fea->name_len); |
| 5402 | EAData += temp_fea->name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5403 | /* null terminate name */ |
| 5404 | *EAData = 0; |
| 5405 | EAData = EAData + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5406 | } else if (buf_size == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5407 | /* skip copy - calc size only */ |
| 5408 | } else { |
| 5409 | /* stop before overrun buffer */ |
| 5410 | rc = -ERANGE; |
| 5411 | break; |
| 5412 | } |
| 5413 | name_len -= temp_fea->name_len; |
| 5414 | temp_ptr += temp_fea->name_len; |
| 5415 | /* account for trailing null */ |
| 5416 | name_len--; |
| 5417 | temp_ptr++; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5418 | value_len = |
| 5419 | le16_to_cpu(temp_fea->value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5420 | name_len -= value_len; |
| 5421 | temp_ptr += value_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5422 | /* BB check that temp_ptr is still |
| 5423 | within the SMB BB*/ |
| 5424 | |
| 5425 | /* no trailing null to account for |
| 5426 | in value len */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | /* go on to next EA */ |
| 5428 | temp_fea = (struct fea *)temp_ptr; |
| 5429 | } |
| 5430 | } |
| 5431 | } |
| 5432 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5433 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5434 | if (rc == -EAGAIN) |
| 5435 | goto QAllEAsRetry; |
| 5436 | |
| 5437 | return (ssize_t)rc; |
| 5438 | } |
| 5439 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5440 | ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon, |
| 5441 | const unsigned char *searchName, const unsigned char *ea_name, |
| 5442 | unsigned char *ea_value, size_t buf_size, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5443 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5444 | { |
| 5445 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 5446 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 5447 | int rc = 0; |
| 5448 | int bytes_returned; |
| 5449 | int name_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5450 | struct fea *temp_fea; |
| 5451 | char *temp_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | __u16 params, byte_count; |
| 5453 | |
| 5454 | cFYI(1, ("In Query EA path %s", searchName)); |
| 5455 | QEARetry: |
| 5456 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5457 | (void **) &pSMBr); |
| 5458 | if (rc) |
| 5459 | return rc; |
| 5460 | |
| 5461 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5462 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5463 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5464 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5465 | name_len++; /* trailing null */ |
| 5466 | name_len *= 2; |
| 5467 | } else { /* BB improve the check for buffer overruns BB */ |
| 5468 | name_len = strnlen(searchName, PATH_MAX); |
| 5469 | name_len++; /* trailing null */ |
| 5470 | strncpy(pSMB->FileName, searchName, name_len); |
| 5471 | } |
| 5472 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5473 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | pSMB->TotalDataCount = 0; |
| 5475 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5476 | /* BB find exact max SMB PDU from sess structure BB */ |
| 5477 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 | pSMB->MaxSetupCount = 0; |
| 5479 | pSMB->Reserved = 0; |
| 5480 | pSMB->Flags = 0; |
| 5481 | pSMB->Timeout = 0; |
| 5482 | pSMB->Reserved2 = 0; |
| 5483 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5484 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5485 | pSMB->DataCount = 0; |
| 5486 | pSMB->DataOffset = 0; |
| 5487 | pSMB->SetupCount = 1; |
| 5488 | pSMB->Reserved3 = 0; |
| 5489 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 5490 | byte_count = params + 1 /* pad */ ; |
| 5491 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5492 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5493 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 5494 | pSMB->Reserved4 = 0; |
| 5495 | pSMB->hdr.smb_buf_length += byte_count; |
| 5496 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5497 | |
| 5498 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5499 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5500 | if (rc) { |
| 5501 | cFYI(1, ("Send error in Query EA = %d", rc)); |
| 5502 | } else { /* decode response */ |
| 5503 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5504 | |
| 5505 | /* BB also check enough total bytes returned */ |
| 5506 | /* BB we need to improve the validity checking |
| 5507 | of these trans2 responses */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5508 | if (rc || (pSMBr->ByteCount < 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | rc = -EIO; /* bad smb */ |
| 5510 | /* else if (pFindData){ |
| 5511 | memcpy((char *) pFindData, |
| 5512 | (char *) &pSMBr->hdr.Protocol + |
| 5513 | data_offset, kl); |
| 5514 | }*/ else { |
| 5515 | /* check that length of list is not more than bcc */ |
| 5516 | /* check that each entry does not go beyond length |
| 5517 | of list */ |
| 5518 | /* check that each element of each entry does not |
| 5519 | go beyond end of list */ |
| 5520 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5521 | struct fealist *ea_response_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | rc = -ENODATA; |
| 5523 | /* validate_trans2_offsets() */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5524 | /* BB check if start of smb + data_offset > &bcc+ bcc*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | ea_response_data = (struct fealist *) |
| 5526 | (((char *) &pSMBr->hdr.Protocol) + |
| 5527 | data_offset); |
| 5528 | name_len = le32_to_cpu(ea_response_data->list_len); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5529 | cFYI(1, ("ea length %d", name_len)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5530 | if (name_len <= 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | /* returned EA size zeroed at top of function */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5532 | cFYI(1, ("empty EA list returned from server")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | } else { |
| 5534 | /* account for ea list len */ |
| 5535 | name_len -= 4; |
| 5536 | temp_fea = ea_response_data->list; |
| 5537 | temp_ptr = (char *)temp_fea; |
| 5538 | /* loop through checking if we have a matching |
| 5539 | name and then return the associated value */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5540 | while (name_len > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5541 | __u16 value_len; |
| 5542 | name_len -= 4; |
| 5543 | temp_ptr += 4; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5544 | value_len = |
| 5545 | le16_to_cpu(temp_fea->value_len); |
| 5546 | /* BB validate that value_len falls within SMB, |
| 5547 | even though maximum for name_len is 255 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5548 | if (memcmp(temp_fea->name, ea_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | temp_fea->name_len) == 0) { |
| 5550 | /* found a match */ |
| 5551 | rc = value_len; |
| 5552 | /* account for prefix user. and trailing null */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5553 | if (rc <= (int)buf_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 | memcpy(ea_value, |
| 5555 | temp_fea->name+temp_fea->name_len+1, |
| 5556 | rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5557 | /* ea values, unlike ea |
| 5558 | names, are not null |
| 5559 | terminated */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5560 | } else if (buf_size == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5561 | /* skip copy - calc size only */ |
| 5562 | } else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5563 | /* stop before overrun buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | rc = -ERANGE; |
| 5565 | } |
| 5566 | break; |
| 5567 | } |
| 5568 | name_len -= temp_fea->name_len; |
| 5569 | temp_ptr += temp_fea->name_len; |
| 5570 | /* account for trailing null */ |
| 5571 | name_len--; |
| 5572 | temp_ptr++; |
| 5573 | name_len -= value_len; |
| 5574 | temp_ptr += value_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5575 | /* No trailing null to account for in |
| 5576 | value_len. Go on to next EA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5577 | temp_fea = (struct fea *)temp_ptr; |
| 5578 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5579 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | } |
| 5581 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5582 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | if (rc == -EAGAIN) |
| 5584 | goto QEARetry; |
| 5585 | |
| 5586 | return (ssize_t)rc; |
| 5587 | } |
| 5588 | |
| 5589 | int |
| 5590 | CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5591 | const char *ea_name, const void *ea_value, |
| 5592 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 5593 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5594 | { |
| 5595 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5596 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5597 | struct fealist *parm_data; |
| 5598 | int name_len; |
| 5599 | int rc = 0; |
| 5600 | int bytes_returned = 0; |
| 5601 | __u16 params, param_offset, byte_count, offset, count; |
| 5602 | |
| 5603 | cFYI(1, ("In SetEA")); |
| 5604 | SetEARetry: |
| 5605 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5606 | (void **) &pSMBr); |
| 5607 | if (rc) |
| 5608 | return rc; |
| 5609 | |
| 5610 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5611 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5612 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5613 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | name_len++; /* trailing null */ |
| 5615 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5616 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | name_len = strnlen(fileName, PATH_MAX); |
| 5618 | name_len++; /* trailing null */ |
| 5619 | strncpy(pSMB->FileName, fileName, name_len); |
| 5620 | } |
| 5621 | |
| 5622 | params = 6 + name_len; |
| 5623 | |
| 5624 | /* done calculating parms using name_len of file name, |
| 5625 | now use name_len to calculate length of ea name |
| 5626 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5627 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | name_len = 0; |
| 5629 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5630 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5631 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 5632 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5633 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5634 | /* BB find max SMB PDU from sess */ |
| 5635 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 | pSMB->MaxSetupCount = 0; |
| 5637 | pSMB->Reserved = 0; |
| 5638 | pSMB->Flags = 0; |
| 5639 | pSMB->Timeout = 0; |
| 5640 | pSMB->Reserved2 = 0; |
| 5641 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5642 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | offset = param_offset + params; |
| 5644 | pSMB->InformationLevel = |
| 5645 | cpu_to_le16(SMB_SET_FILE_EA); |
| 5646 | |
| 5647 | parm_data = |
| 5648 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 5649 | offset); |
| 5650 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5651 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5652 | pSMB->SetupCount = 1; |
| 5653 | pSMB->Reserved3 = 0; |
| 5654 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5655 | byte_count = 3 /* pad */ + params + count; |
| 5656 | pSMB->DataCount = cpu_to_le16(count); |
| 5657 | parm_data->list_len = cpu_to_le32(count); |
| 5658 | parm_data->list[0].EA_flags = 0; |
| 5659 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 5660 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5662 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5663 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5664 | parm_data->list[0].name[name_len] = 0; |
| 5665 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 5666 | /* caller ensures that ea_value_len is less than 64K but |
| 5667 | we need to ensure that it fits within the smb */ |
| 5668 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5669 | /*BB add length check to see if it would fit in |
| 5670 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5671 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 5672 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5673 | memcpy(parm_data->list[0].name+name_len+1, |
| 5674 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | |
| 5676 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5677 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5678 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5679 | pSMB->Reserved4 = 0; |
| 5680 | pSMB->hdr.smb_buf_length += byte_count; |
| 5681 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5682 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5683 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5684 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | cFYI(1, ("SetPathInfo (EA) returned %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5686 | |
| 5687 | cifs_buf_release(pSMB); |
| 5688 | |
| 5689 | if (rc == -EAGAIN) |
| 5690 | goto SetEARetry; |
| 5691 | |
| 5692 | return rc; |
| 5693 | } |
| 5694 | |
| 5695 | #endif |