diff options
Diffstat (limited to 'fs/cifs/misc.c')
-rw-r--r-- | fs/cifs/misc.c | 239 |
1 files changed, 124 insertions, 115 deletions
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index 19cc294c7c70..0bcec0844bee 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * fs/cifs/misc.c | 2 | * fs/cifs/misc.c |
3 | * | 3 | * |
4 | * Copyright (C) International Business Machines Corp., 2002,2005 | 4 | * Copyright (C) International Business Machines Corp., 2002,2007 |
5 | * Author(s): Steve French (sfrench@us.ibm.com) | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
6 | * | 6 | * |
7 | * This library is free software; you can redistribute it and/or modify | 7 | * This library is free software; you can redistribute it and/or modify |
@@ -16,7 +16,7 @@ | |||
16 | * | 16 | * |
17 | * You should have received a copy of the GNU Lesser General Public License | 17 | * You should have received a copy of the GNU Lesser General Public License |
18 | * along with this library; if not, write to the Free Software | 18 | * along with this library; if not, write to the Free Software |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
@@ -32,12 +32,12 @@ | |||
32 | 32 | ||
33 | extern mempool_t *cifs_sm_req_poolp; | 33 | extern mempool_t *cifs_sm_req_poolp; |
34 | extern mempool_t *cifs_req_poolp; | 34 | extern mempool_t *cifs_req_poolp; |
35 | extern struct task_struct * oplockThread; | 35 | extern struct task_struct *oplockThread; |
36 | 36 | ||
37 | /* The xid serves as a useful identifier for each incoming vfs request, | 37 | /* The xid serves as a useful identifier for each incoming vfs request, |
38 | in a similar way to the mid which is useful to track each sent smb, | 38 | in a similar way to the mid which is useful to track each sent smb, |
39 | and CurrentXid can also provide a running counter (although it | 39 | and CurrentXid can also provide a running counter (although it |
40 | will eventually wrap past zero) of the total vfs operations handled | 40 | will eventually wrap past zero) of the total vfs operations handled |
41 | since the cifs fs was mounted */ | 41 | since the cifs fs was mounted */ |
42 | 42 | ||
43 | unsigned int | 43 | unsigned int |
@@ -47,10 +47,12 @@ _GetXid(void) | |||
47 | 47 | ||
48 | spin_lock(&GlobalMid_Lock); | 48 | spin_lock(&GlobalMid_Lock); |
49 | GlobalTotalActiveXid++; | 49 | GlobalTotalActiveXid++; |
50 | |||
51 | /* keep high water mark for number of simultaneous ops in filesystem */ | ||
50 | if (GlobalTotalActiveXid > GlobalMaxActiveXid) | 52 | if (GlobalTotalActiveXid > GlobalMaxActiveXid) |
51 | GlobalMaxActiveXid = GlobalTotalActiveXid; /* keep high water mark for number of simultaneous vfs ops in our filesystem */ | 53 | GlobalMaxActiveXid = GlobalTotalActiveXid; |
52 | if(GlobalTotalActiveXid > 65000) | 54 | if (GlobalTotalActiveXid > 65000) |
53 | cFYI(1,("warning: more than 65000 requests active")); | 55 | cFYI(1, ("warning: more than 65000 requests active")); |
54 | xid = GlobalCurrentXid++; | 56 | xid = GlobalCurrentXid++; |
55 | spin_unlock(&GlobalMid_Lock); | 57 | spin_unlock(&GlobalMid_Lock); |
56 | return xid; | 58 | return xid; |
@@ -60,7 +62,7 @@ void | |||
60 | _FreeXid(unsigned int xid) | 62 | _FreeXid(unsigned int xid) |
61 | { | 63 | { |
62 | spin_lock(&GlobalMid_Lock); | 64 | spin_lock(&GlobalMid_Lock); |
63 | /* if(GlobalTotalActiveXid == 0) | 65 | /* if (GlobalTotalActiveXid == 0) |
64 | BUG(); */ | 66 | BUG(); */ |
65 | GlobalTotalActiveXid--; | 67 | GlobalTotalActiveXid--; |
66 | spin_unlock(&GlobalMid_Lock); | 68 | spin_unlock(&GlobalMid_Lock); |
@@ -144,12 +146,12 @@ cifs_buf_get(void) | |||
144 | { | 146 | { |
145 | struct smb_hdr *ret_buf = NULL; | 147 | struct smb_hdr *ret_buf = NULL; |
146 | 148 | ||
147 | /* We could use negotiated size instead of max_msgsize - | 149 | /* We could use negotiated size instead of max_msgsize - |
148 | but it may be more efficient to always alloc same size | 150 | but it may be more efficient to always alloc same size |
149 | albeit slightly larger than necessary and maxbuffersize | 151 | albeit slightly larger than necessary and maxbuffersize |
150 | defaults to this and can not be bigger */ | 152 | defaults to this and can not be bigger */ |
151 | ret_buf = | 153 | ret_buf = (struct smb_hdr *) mempool_alloc(cifs_req_poolp, |
152 | (struct smb_hdr *) mempool_alloc(cifs_req_poolp, GFP_KERNEL | GFP_NOFS); | 154 | GFP_KERNEL | GFP_NOFS); |
153 | 155 | ||
154 | /* clear the first few header bytes */ | 156 | /* clear the first few header bytes */ |
155 | /* for most paths, more is cleared in header_assemble */ | 157 | /* for most paths, more is cleared in header_assemble */ |
@@ -172,7 +174,7 @@ cifs_buf_release(void *buf_to_free) | |||
172 | /* cFYI(1, ("Null buffer passed to cifs_buf_release"));*/ | 174 | /* cFYI(1, ("Null buffer passed to cifs_buf_release"));*/ |
173 | return; | 175 | return; |
174 | } | 176 | } |
175 | mempool_free(buf_to_free,cifs_req_poolp); | 177 | mempool_free(buf_to_free, cifs_req_poolp); |
176 | 178 | ||
177 | atomic_dec(&bufAllocCount); | 179 | atomic_dec(&bufAllocCount); |
178 | return; | 180 | return; |
@@ -183,12 +185,12 @@ cifs_small_buf_get(void) | |||
183 | { | 185 | { |
184 | struct smb_hdr *ret_buf = NULL; | 186 | struct smb_hdr *ret_buf = NULL; |
185 | 187 | ||
186 | /* We could use negotiated size instead of max_msgsize - | 188 | /* We could use negotiated size instead of max_msgsize - |
187 | but it may be more efficient to always alloc same size | 189 | but it may be more efficient to always alloc same size |
188 | albeit slightly larger than necessary and maxbuffersize | 190 | albeit slightly larger than necessary and maxbuffersize |
189 | defaults to this and can not be bigger */ | 191 | defaults to this and can not be bigger */ |
190 | ret_buf = | 192 | ret_buf = (struct smb_hdr *) mempool_alloc(cifs_sm_req_poolp, |
191 | (struct smb_hdr *) mempool_alloc(cifs_sm_req_poolp, GFP_KERNEL | GFP_NOFS); | 193 | GFP_KERNEL | GFP_NOFS); |
192 | if (ret_buf) { | 194 | if (ret_buf) { |
193 | /* No need to clear memory here, cleared in header assemble */ | 195 | /* No need to clear memory here, cleared in header assemble */ |
194 | /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/ | 196 | /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/ |
@@ -209,30 +211,30 @@ cifs_small_buf_release(void *buf_to_free) | |||
209 | cFYI(1, ("Null buffer passed to cifs_small_buf_release")); | 211 | cFYI(1, ("Null buffer passed to cifs_small_buf_release")); |
210 | return; | 212 | return; |
211 | } | 213 | } |
212 | mempool_free(buf_to_free,cifs_sm_req_poolp); | 214 | mempool_free(buf_to_free, cifs_sm_req_poolp); |
213 | 215 | ||
214 | atomic_dec(&smBufAllocCount); | 216 | atomic_dec(&smBufAllocCount); |
215 | return; | 217 | return; |
216 | } | 218 | } |
217 | 219 | ||
218 | /* | 220 | /* |
219 | Find a free multiplex id (SMB mid). Otherwise there could be | 221 | Find a free multiplex id (SMB mid). Otherwise there could be |
220 | mid collisions which might cause problems, demultiplexing the | 222 | mid collisions which might cause problems, demultiplexing the |
221 | wrong response to this request. Multiplex ids could collide if | 223 | wrong response to this request. Multiplex ids could collide if |
222 | one of a series requests takes much longer than the others, or | 224 | one of a series requests takes much longer than the others, or |
223 | if a very large number of long lived requests (byte range | 225 | if a very large number of long lived requests (byte range |
224 | locks or FindNotify requests) are pending. No more than | 226 | locks or FindNotify requests) are pending. No more than |
225 | 64K-1 requests can be outstanding at one time. If no | 227 | 64K-1 requests can be outstanding at one time. If no |
226 | mids are available, return zero. A future optimization | 228 | mids are available, return zero. A future optimization |
227 | could make the combination of mids and uid the key we use | 229 | could make the combination of mids and uid the key we use |
228 | to demultiplex on (rather than mid alone). | 230 | to demultiplex on (rather than mid alone). |
229 | In addition to the above check, the cifs demultiplex | 231 | In addition to the above check, the cifs demultiplex |
230 | code already used the command code as a secondary | 232 | code already used the command code as a secondary |
231 | check of the frame and if signing is negotiated the | 233 | check of the frame and if signing is negotiated the |
232 | response would be discarded if the mid were the same | 234 | response would be discarded if the mid were the same |
233 | but the signature was wrong. Since the mid is not put in the | 235 | but the signature was wrong. Since the mid is not put in the |
234 | pending queue until later (when it is about to be dispatched) | 236 | pending queue until later (when it is about to be dispatched) |
235 | we do have to limit the number of outstanding requests | 237 | we do have to limit the number of outstanding requests |
236 | to somewhat less than 64K-1 although it is hard to imagine | 238 | to somewhat less than 64K-1 although it is hard to imagine |
237 | so many threads being in the vfs at one time. | 239 | so many threads being in the vfs at one time. |
238 | */ | 240 | */ |
@@ -240,27 +242,27 @@ __u16 GetNextMid(struct TCP_Server_Info *server) | |||
240 | { | 242 | { |
241 | __u16 mid = 0; | 243 | __u16 mid = 0; |
242 | __u16 last_mid; | 244 | __u16 last_mid; |
243 | int collision; | 245 | int collision; |
244 | 246 | ||
245 | if(server == NULL) | 247 | if (server == NULL) |
246 | return mid; | 248 | return mid; |
247 | 249 | ||
248 | spin_lock(&GlobalMid_Lock); | 250 | spin_lock(&GlobalMid_Lock); |
249 | last_mid = server->CurrentMid; /* we do not want to loop forever */ | 251 | last_mid = server->CurrentMid; /* we do not want to loop forever */ |
250 | server->CurrentMid++; | 252 | server->CurrentMid++; |
251 | /* This nested loop looks more expensive than it is. | 253 | /* This nested loop looks more expensive than it is. |
252 | In practice the list of pending requests is short, | 254 | In practice the list of pending requests is short, |
253 | fewer than 50, and the mids are likely to be unique | 255 | fewer than 50, and the mids are likely to be unique |
254 | on the first pass through the loop unless some request | 256 | on the first pass through the loop unless some request |
255 | takes longer than the 64 thousand requests before it | 257 | takes longer than the 64 thousand requests before it |
256 | (and it would also have to have been a request that | 258 | (and it would also have to have been a request that |
257 | did not time out) */ | 259 | did not time out) */ |
258 | while(server->CurrentMid != last_mid) { | 260 | while (server->CurrentMid != last_mid) { |
259 | struct list_head *tmp; | 261 | struct list_head *tmp; |
260 | struct mid_q_entry *mid_entry; | 262 | struct mid_q_entry *mid_entry; |
261 | 263 | ||
262 | collision = 0; | 264 | collision = 0; |
263 | if(server->CurrentMid == 0) | 265 | if (server->CurrentMid == 0) |
264 | server->CurrentMid++; | 266 | server->CurrentMid++; |
265 | 267 | ||
266 | list_for_each(tmp, &server->pending_mid_q) { | 268 | list_for_each(tmp, &server->pending_mid_q) { |
@@ -273,7 +275,7 @@ __u16 GetNextMid(struct TCP_Server_Info *server) | |||
273 | break; | 275 | break; |
274 | } | 276 | } |
275 | } | 277 | } |
276 | if(collision == 0) { | 278 | if (collision == 0) { |
277 | mid = server->CurrentMid; | 279 | mid = server->CurrentMid; |
278 | break; | 280 | break; |
279 | } | 281 | } |
@@ -290,11 +292,11 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ , | |||
290 | const struct cifsTconInfo *treeCon, int word_count | 292 | const struct cifsTconInfo *treeCon, int word_count |
291 | /* length of fixed section (word count) in two byte units */) | 293 | /* length of fixed section (word count) in two byte units */) |
292 | { | 294 | { |
293 | struct list_head* temp_item; | 295 | struct list_head *temp_item; |
294 | struct cifsSesInfo * ses; | 296 | struct cifsSesInfo *ses; |
295 | char *temp = (char *) buffer; | 297 | char *temp = (char *) buffer; |
296 | 298 | ||
297 | memset(temp,0,256); /* bigger than MAX_CIFS_HDR_SIZE */ | 299 | memset(temp, 0, 256); /* bigger than MAX_CIFS_HDR_SIZE */ |
298 | 300 | ||
299 | buffer->smb_buf_length = | 301 | buffer->smb_buf_length = |
300 | (2 * word_count) + sizeof (struct smb_hdr) - | 302 | (2 * word_count) + sizeof (struct smb_hdr) - |
@@ -325,7 +327,7 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ , | |||
325 | /* Uid is not converted */ | 327 | /* Uid is not converted */ |
326 | buffer->Uid = treeCon->ses->Suid; | 328 | buffer->Uid = treeCon->ses->Suid; |
327 | buffer->Mid = GetNextMid(treeCon->ses->server); | 329 | buffer->Mid = GetNextMid(treeCon->ses->server); |
328 | if(multiuser_mount != 0) { | 330 | if (multiuser_mount != 0) { |
329 | /* For the multiuser case, there are few obvious technically */ | 331 | /* For the multiuser case, there are few obvious technically */ |
330 | /* possible mechanisms to match the local linux user (uid) */ | 332 | /* possible mechanisms to match the local linux user (uid) */ |
331 | /* to a valid remote smb user (smb_uid): */ | 333 | /* to a valid remote smb user (smb_uid): */ |
@@ -348,21 +350,22 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ , | |||
348 | /* flag were disabled. */ | 350 | /* flag were disabled. */ |
349 | 351 | ||
350 | /* BB Add support for establishing new tCon and SMB Session */ | 352 | /* BB Add support for establishing new tCon and SMB Session */ |
351 | /* with userid/password pairs found on the smb session */ | 353 | /* with userid/password pairs found on the smb session */ |
352 | /* for other target tcp/ip addresses BB */ | 354 | /* for other target tcp/ip addresses BB */ |
353 | if(current->fsuid != treeCon->ses->linux_uid) { | 355 | if (current->fsuid != treeCon->ses->linux_uid) { |
354 | cFYI(1,("Multiuser mode and UID did not match tcon uid")); | 356 | cFYI(1, ("Multiuser mode and UID " |
357 | "did not match tcon uid")); | ||
355 | read_lock(&GlobalSMBSeslock); | 358 | read_lock(&GlobalSMBSeslock); |
356 | list_for_each(temp_item, &GlobalSMBSessionList) { | 359 | list_for_each(temp_item, &GlobalSMBSessionList) { |
357 | ses = list_entry(temp_item, struct cifsSesInfo, cifsSessionList); | 360 | ses = list_entry(temp_item, struct cifsSesInfo, cifsSessionList); |
358 | if(ses->linux_uid == current->fsuid) { | 361 | if (ses->linux_uid == current->fsuid) { |
359 | if(ses->server == treeCon->ses->server) { | 362 | if (ses->server == treeCon->ses->server) { |
360 | cFYI(1,("found matching uid substitute right smb_uid")); | 363 | cFYI(1, ("found matching uid substitute right smb_uid")); |
361 | buffer->Uid = ses->Suid; | 364 | buffer->Uid = ses->Suid; |
362 | break; | 365 | break; |
363 | } else { | 366 | } else { |
364 | /* BB eventually call cifs_setup_session here */ | 367 | /* BB eventually call cifs_setup_session here */ |
365 | cFYI(1,("local UID found but smb sess with this server does not exist")); | 368 | cFYI(1, ("local UID found but no smb sess with this server exists")); |
366 | } | 369 | } |
367 | } | 370 | } |
368 | } | 371 | } |
@@ -374,8 +377,8 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ , | |||
374 | buffer->Flags2 |= SMBFLG2_DFS; | 377 | buffer->Flags2 |= SMBFLG2_DFS; |
375 | if (treeCon->nocase) | 378 | if (treeCon->nocase) |
376 | buffer->Flags |= SMBFLG_CASELESS; | 379 | buffer->Flags |= SMBFLG_CASELESS; |
377 | if((treeCon->ses) && (treeCon->ses->server)) | 380 | if ((treeCon->ses) && (treeCon->ses->server)) |
378 | if(treeCon->ses->server->secMode & | 381 | if (treeCon->ses->server->secMode & |
379 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) | 382 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
380 | buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; | 383 | buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
381 | } | 384 | } |
@@ -388,18 +391,18 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ , | |||
388 | static int | 391 | static int |
389 | checkSMBhdr(struct smb_hdr *smb, __u16 mid) | 392 | checkSMBhdr(struct smb_hdr *smb, __u16 mid) |
390 | { | 393 | { |
391 | /* Make sure that this really is an SMB, that it is a response, | 394 | /* Make sure that this really is an SMB, that it is a response, |
392 | and that the message ids match */ | 395 | and that the message ids match */ |
393 | if ((*(__le32 *) smb->Protocol == cpu_to_le32(0x424d53ff)) && | 396 | if ((*(__le32 *) smb->Protocol == cpu_to_le32(0x424d53ff)) && |
394 | (mid == smb->Mid)) { | 397 | (mid == smb->Mid)) { |
395 | if(smb->Flags & SMBFLG_RESPONSE) | 398 | if (smb->Flags & SMBFLG_RESPONSE) |
396 | return 0; | 399 | return 0; |
397 | else { | 400 | else { |
398 | /* only one valid case where server sends us request */ | 401 | /* only one valid case where server sends us request */ |
399 | if(smb->Command == SMB_COM_LOCKING_ANDX) | 402 | if (smb->Command == SMB_COM_LOCKING_ANDX) |
400 | return 0; | 403 | return 0; |
401 | else | 404 | else |
402 | cERROR(1, ("Rcvd Request not response")); | 405 | cERROR(1, ("Received Request not response")); |
403 | } | 406 | } |
404 | } else { /* bad signature or mid */ | 407 | } else { /* bad signature or mid */ |
405 | if (*(__le32 *) smb->Protocol != cpu_to_le32(0x424d53ff)) | 408 | if (*(__le32 *) smb->Protocol != cpu_to_le32(0x424d53ff)) |
@@ -426,9 +429,9 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
426 | smb->WordCount = 0; | 429 | smb->WordCount = 0; |
427 | /* some error cases do not return wct and bcc */ | 430 | /* some error cases do not return wct and bcc */ |
428 | return 0; | 431 | return 0; |
429 | } else if ((length == sizeof(struct smb_hdr) + 1) && | 432 | } else if ((length == sizeof(struct smb_hdr) + 1) && |
430 | (smb->WordCount == 0)) { | 433 | (smb->WordCount == 0)) { |
431 | char * tmp = (char *)smb; | 434 | char *tmp = (char *)smb; |
432 | /* Need to work around a bug in two servers here */ | 435 | /* Need to work around a bug in two servers here */ |
433 | /* First, check if the part of bcc they sent was zero */ | 436 | /* First, check if the part of bcc they sent was zero */ |
434 | if (tmp[sizeof(struct smb_hdr)] == 0) { | 437 | if (tmp[sizeof(struct smb_hdr)] == 0) { |
@@ -442,7 +445,7 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
442 | tmp[sizeof(struct smb_hdr)+1] = 0; | 445 | tmp[sizeof(struct smb_hdr)+1] = 0; |
443 | return 0; | 446 | return 0; |
444 | } | 447 | } |
445 | cERROR(1,("rcvd invalid byte count (bcc)")); | 448 | cERROR(1, ("rcvd invalid byte count (bcc)")); |
446 | } else { | 449 | } else { |
447 | cERROR(1, ("Length less than smb header size")); | 450 | cERROR(1, ("Length less than smb header size")); |
448 | } | 451 | } |
@@ -458,32 +461,33 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
458 | return 1; | 461 | return 1; |
459 | clc_len = smbCalcSize_LE(smb); | 462 | clc_len = smbCalcSize_LE(smb); |
460 | 463 | ||
461 | if(4 + len != length) { | 464 | if (4 + len != length) { |
462 | cERROR(1, ("Length read does not match RFC1001 length %d",len)); | 465 | cERROR(1, ("Length read does not match RFC1001 length %d", |
466 | len)); | ||
463 | return 1; | 467 | return 1; |
464 | } | 468 | } |
465 | 469 | ||
466 | if (4 + len != clc_len) { | 470 | if (4 + len != clc_len) { |
467 | /* check if bcc wrapped around for large read responses */ | 471 | /* check if bcc wrapped around for large read responses */ |
468 | if((len > 64 * 1024) && (len > clc_len)) { | 472 | if ((len > 64 * 1024) && (len > clc_len)) { |
469 | /* check if lengths match mod 64K */ | 473 | /* check if lengths match mod 64K */ |
470 | if(((4 + len) & 0xFFFF) == (clc_len & 0xFFFF)) | 474 | if (((4 + len) & 0xFFFF) == (clc_len & 0xFFFF)) |
471 | return 0; /* bcc wrapped */ | 475 | return 0; /* bcc wrapped */ |
472 | } | 476 | } |
473 | cFYI(1, ("Calculated size %d vs length %d mismatch for mid %d", | 477 | cFYI(1, ("Calculated size %d vs length %d mismatch for mid %d", |
474 | clc_len, 4 + len, smb->Mid)); | 478 | clc_len, 4 + len, smb->Mid)); |
475 | /* Windows XP can return a few bytes too much, presumably | 479 | /* Windows XP can return a few bytes too much, presumably |
476 | an illegal pad, at the end of byte range lock responses | 480 | an illegal pad, at the end of byte range lock responses |
477 | so we allow for that three byte pad, as long as actual | 481 | so we allow for that three byte pad, as long as actual |
478 | received length is as long or longer than calculated length */ | 482 | received length is as long or longer than calculated length */ |
479 | /* We have now had to extend this more, since there is a | 483 | /* We have now had to extend this more, since there is a |
480 | case in which it needs to be bigger still to handle a | 484 | case in which it needs to be bigger still to handle a |
481 | malformed response to transact2 findfirst from WinXP when | 485 | malformed response to transact2 findfirst from WinXP when |
482 | access denied is returned and thus bcc and wct are zero | 486 | access denied is returned and thus bcc and wct are zero |
483 | but server says length is 0x21 bytes too long as if the server | 487 | but server says length is 0x21 bytes too long as if the server |
484 | forget to reset the smb rfc1001 length when it reset the | 488 | forget to reset the smb rfc1001 length when it reset the |
485 | wct and bcc to minimum size and drop the t2 parms and data */ | 489 | wct and bcc to minimum size and drop the t2 parms and data */ |
486 | if((4+len > clc_len) && (len <= clc_len + 512)) | 490 | if ((4+len > clc_len) && (len <= clc_len + 512)) |
487 | return 0; | 491 | return 0; |
488 | else { | 492 | else { |
489 | cERROR(1, ("RFC1001 size %d bigger than SMB for Mid=%d", | 493 | cERROR(1, ("RFC1001 size %d bigger than SMB for Mid=%d", |
@@ -495,61 +499,64 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
495 | } | 499 | } |
496 | int | 500 | int |
497 | is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) | 501 | is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) |
498 | { | 502 | { |
499 | struct smb_com_lock_req * pSMB = (struct smb_com_lock_req *)buf; | 503 | struct smb_com_lock_req *pSMB = (struct smb_com_lock_req *)buf; |
500 | struct list_head *tmp; | 504 | struct list_head *tmp; |
501 | struct list_head *tmp1; | 505 | struct list_head *tmp1; |
502 | struct cifsTconInfo *tcon; | 506 | struct cifsTconInfo *tcon; |
503 | struct cifsFileInfo *netfile; | 507 | struct cifsFileInfo *netfile; |
504 | 508 | ||
505 | cFYI(1,("Checking for oplock break or dnotify response")); | 509 | cFYI(1, ("Checking for oplock break or dnotify response")); |
506 | if((pSMB->hdr.Command == SMB_COM_NT_TRANSACT) && | 510 | if ((pSMB->hdr.Command == SMB_COM_NT_TRANSACT) && |
507 | (pSMB->hdr.Flags & SMBFLG_RESPONSE)) { | 511 | (pSMB->hdr.Flags & SMBFLG_RESPONSE)) { |
508 | struct smb_com_transaction_change_notify_rsp * pSMBr = | 512 | struct smb_com_transaction_change_notify_rsp *pSMBr = |
509 | (struct smb_com_transaction_change_notify_rsp *)buf; | 513 | (struct smb_com_transaction_change_notify_rsp *)buf; |
510 | struct file_notify_information * pnotify; | 514 | struct file_notify_information *pnotify; |
511 | __u32 data_offset = 0; | 515 | __u32 data_offset = 0; |
512 | if(pSMBr->ByteCount > sizeof(struct file_notify_information)) { | 516 | if (pSMBr->ByteCount > sizeof(struct file_notify_information)) { |
513 | data_offset = le32_to_cpu(pSMBr->DataOffset); | 517 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
514 | 518 | ||
515 | pnotify = (struct file_notify_information *) | 519 | pnotify = (struct file_notify_information *) |
516 | ((char *)&pSMBr->hdr.Protocol + data_offset); | 520 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
517 | cFYI(1,("dnotify on %s Action: 0x%x",pnotify->FileName, | 521 | cFYI(1, ("dnotify on %s Action: 0x%x", |
522 | pnotify->FileName, | ||
518 | pnotify->Action)); /* BB removeme BB */ | 523 | pnotify->Action)); /* BB removeme BB */ |
519 | /* cifs_dump_mem("Rcvd notify Data: ",buf, | 524 | /* cifs_dump_mem("Rcvd notify Data: ",buf, |
520 | sizeof(struct smb_hdr)+60); */ | 525 | sizeof(struct smb_hdr)+60); */ |
521 | return TRUE; | 526 | return TRUE; |
522 | } | 527 | } |
523 | if(pSMBr->hdr.Status.CifsError) { | 528 | if (pSMBr->hdr.Status.CifsError) { |
524 | cFYI(1,("notify err 0x%d",pSMBr->hdr.Status.CifsError)); | 529 | cFYI(1, ("notify err 0x%d", |
530 | pSMBr->hdr.Status.CifsError)); | ||
525 | return TRUE; | 531 | return TRUE; |
526 | } | 532 | } |
527 | return FALSE; | 533 | return FALSE; |
528 | } | 534 | } |
529 | if(pSMB->hdr.Command != SMB_COM_LOCKING_ANDX) | 535 | if (pSMB->hdr.Command != SMB_COM_LOCKING_ANDX) |
530 | return FALSE; | 536 | return FALSE; |
531 | if(pSMB->hdr.Flags & SMBFLG_RESPONSE) { | 537 | if (pSMB->hdr.Flags & SMBFLG_RESPONSE) { |
532 | /* no sense logging error on invalid handle on oplock | 538 | /* no sense logging error on invalid handle on oplock |
533 | break - harmless race between close request and oplock | 539 | break - harmless race between close request and oplock |
534 | break response is expected from time to time writing out | 540 | break response is expected from time to time writing out |
535 | large dirty files cached on the client */ | 541 | large dirty files cached on the client */ |
536 | if ((NT_STATUS_INVALID_HANDLE) == | 542 | if ((NT_STATUS_INVALID_HANDLE) == |
537 | le32_to_cpu(pSMB->hdr.Status.CifsError)) { | 543 | le32_to_cpu(pSMB->hdr.Status.CifsError)) { |
538 | cFYI(1,("invalid handle on oplock break")); | 544 | cFYI(1, ("invalid handle on oplock break")); |
539 | return TRUE; | 545 | return TRUE; |
540 | } else if (ERRbadfid == | 546 | } else if (ERRbadfid == |
541 | le16_to_cpu(pSMB->hdr.Status.DosError.Error)) { | 547 | le16_to_cpu(pSMB->hdr.Status.DosError.Error)) { |
542 | return TRUE; | 548 | return TRUE; |
543 | } else { | 549 | } else { |
544 | return FALSE; /* on valid oplock brk we get "request" */ | 550 | return FALSE; /* on valid oplock brk we get "request" */ |
545 | } | 551 | } |
546 | } | 552 | } |
547 | if(pSMB->hdr.WordCount != 8) | 553 | if (pSMB->hdr.WordCount != 8) |
548 | return FALSE; | 554 | return FALSE; |
549 | 555 | ||
550 | cFYI(1,(" oplock type 0x%d level 0x%d",pSMB->LockType,pSMB->OplockLevel)); | 556 | cFYI(1, ("oplock type 0x%d level 0x%d", |
551 | if(!(pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE)) | 557 | pSMB->LockType, pSMB->OplockLevel)); |
552 | return FALSE; | 558 | if (!(pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE)) |
559 | return FALSE; | ||
553 | 560 | ||
554 | /* look up tcon based on tid & uid */ | 561 | /* look up tcon based on tid & uid */ |
555 | read_lock(&GlobalSMBSeslock); | 562 | read_lock(&GlobalSMBSeslock); |
@@ -557,36 +564,38 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) | |||
557 | tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList); | 564 | tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList); |
558 | if ((tcon->tid == buf->Tid) && (srv == tcon->ses->server)) { | 565 | if ((tcon->tid == buf->Tid) && (srv == tcon->ses->server)) { |
559 | cifs_stats_inc(&tcon->num_oplock_brks); | 566 | cifs_stats_inc(&tcon->num_oplock_brks); |
560 | list_for_each(tmp1,&tcon->openFileList){ | 567 | list_for_each(tmp1, &tcon->openFileList) { |
561 | netfile = list_entry(tmp1,struct cifsFileInfo, | 568 | netfile = list_entry(tmp1, struct cifsFileInfo, |
562 | tlist); | 569 | tlist); |
563 | if(pSMB->Fid == netfile->netfid) { | 570 | if (pSMB->Fid == netfile->netfid) { |
564 | struct cifsInodeInfo *pCifsInode; | 571 | struct cifsInodeInfo *pCifsInode; |
565 | read_unlock(&GlobalSMBSeslock); | 572 | read_unlock(&GlobalSMBSeslock); |
566 | cFYI(1,("file id match, oplock break")); | 573 | cFYI(1, |
567 | pCifsInode = | 574 | ("file id match, oplock break")); |
575 | pCifsInode = | ||
568 | CIFS_I(netfile->pInode); | 576 | CIFS_I(netfile->pInode); |
569 | pCifsInode->clientCanCacheAll = FALSE; | 577 | pCifsInode->clientCanCacheAll = FALSE; |
570 | if(pSMB->OplockLevel == 0) | 578 | if (pSMB->OplockLevel == 0) |
571 | pCifsInode->clientCanCacheRead | 579 | pCifsInode->clientCanCacheRead |
572 | = FALSE; | 580 | = FALSE; |
573 | pCifsInode->oplockPending = TRUE; | 581 | pCifsInode->oplockPending = TRUE; |
574 | AllocOplockQEntry(netfile->pInode, | 582 | AllocOplockQEntry(netfile->pInode, |
575 | netfile->netfid, | 583 | netfile->netfid, |
576 | tcon); | 584 | tcon); |
577 | cFYI(1,("about to wake up oplock thd")); | 585 | cFYI(1, |
578 | if(oplockThread) | 586 | ("about to wake up oplock thread")); |
587 | if (oplockThread) | ||
579 | wake_up_process(oplockThread); | 588 | wake_up_process(oplockThread); |
580 | return TRUE; | 589 | return TRUE; |
581 | } | 590 | } |
582 | } | 591 | } |
583 | read_unlock(&GlobalSMBSeslock); | 592 | read_unlock(&GlobalSMBSeslock); |
584 | cFYI(1,("No matching file for oplock break")); | 593 | cFYI(1, ("No matching file for oplock break")); |
585 | return TRUE; | 594 | return TRUE; |
586 | } | 595 | } |
587 | } | 596 | } |
588 | read_unlock(&GlobalSMBSeslock); | 597 | read_unlock(&GlobalSMBSeslock); |
589 | cFYI(1,("Can not process oplock break for non-existent connection")); | 598 | cFYI(1, ("Can not process oplock break for non-existent connection")); |
590 | return TRUE; | 599 | return TRUE; |
591 | } | 600 | } |
592 | 601 | ||
@@ -643,13 +652,13 @@ dump_smb(struct smb_hdr *smb_buf, int smb_buf_length) | |||
643 | only legal in POSIX-like OS (if they are present in the string). Path | 652 | only legal in POSIX-like OS (if they are present in the string). Path |
644 | names are little endian 16 bit Unicode on the wire */ | 653 | names are little endian 16 bit Unicode on the wire */ |
645 | int | 654 | int |
646 | cifs_convertUCSpath(char *target, const __le16 * source, int maxlen, | 655 | cifs_convertUCSpath(char *target, const __le16 *source, int maxlen, |
647 | const struct nls_table * cp) | 656 | const struct nls_table *cp) |
648 | { | 657 | { |
649 | int i,j,len; | 658 | int i, j, len; |
650 | __u16 src_char; | 659 | __u16 src_char; |
651 | 660 | ||
652 | for(i = 0, j = 0; i < maxlen; i++) { | 661 | for (i = 0, j = 0; i < maxlen; i++) { |
653 | src_char = le16_to_cpu(source[i]); | 662 | src_char = le16_to_cpu(source[i]); |
654 | switch (src_char) { | 663 | switch (src_char) { |
655 | case 0: | 664 | case 0: |
@@ -678,10 +687,10 @@ cifs_convertUCSpath(char *target, const __le16 * source, int maxlen, | |||
678 | case UNI_LESSTHAN: | 687 | case UNI_LESSTHAN: |
679 | target[j] = '<'; | 688 | target[j] = '<'; |
680 | break; | 689 | break; |
681 | default: | 690 | default: |
682 | len = cp->uni2char(src_char, &target[j], | 691 | len = cp->uni2char(src_char, &target[j], |
683 | NLS_MAX_CHARSET_SIZE); | 692 | NLS_MAX_CHARSET_SIZE); |
684 | if(len > 0) { | 693 | if (len > 0) { |
685 | j += len; | 694 | j += len; |
686 | continue; | 695 | continue; |
687 | } else { | 696 | } else { |
@@ -690,7 +699,7 @@ cifs_convertUCSpath(char *target, const __le16 * source, int maxlen, | |||
690 | } | 699 | } |
691 | j++; | 700 | j++; |
692 | /* make sure we do not overrun callers allocated temp buffer */ | 701 | /* make sure we do not overrun callers allocated temp buffer */ |
693 | if(j >= (2 * NAME_MAX)) | 702 | if (j >= (2 * NAME_MAX)) |
694 | break; | 703 | break; |
695 | } | 704 | } |
696 | cUCS_out: | 705 | cUCS_out: |
@@ -703,18 +712,18 @@ cUCS_out: | |||
703 | only legal in POSIX-like OS (if they are present in the string). Path | 712 | only legal in POSIX-like OS (if they are present in the string). Path |
704 | names are little endian 16 bit Unicode on the wire */ | 713 | names are little endian 16 bit Unicode on the wire */ |
705 | int | 714 | int |
706 | cifsConvertToUCS(__le16 * target, const char *source, int maxlen, | 715 | cifsConvertToUCS(__le16 *target, const char *source, int maxlen, |
707 | const struct nls_table * cp, int mapChars) | 716 | const struct nls_table *cp, int mapChars) |
708 | { | 717 | { |
709 | int i,j,charlen; | 718 | int i, j, charlen; |
710 | int len_remaining = maxlen; | 719 | int len_remaining = maxlen; |
711 | char src_char; | 720 | char src_char; |
712 | __u16 temp; | 721 | __u16 temp; |
713 | 722 | ||
714 | if(!mapChars) | 723 | if (!mapChars) |
715 | return cifs_strtoUCS(target, source, PATH_MAX, cp); | 724 | return cifs_strtoUCS(target, source, PATH_MAX, cp); |
716 | 725 | ||
717 | for(i = 0, j = 0; i < maxlen; j++) { | 726 | for (i = 0, j = 0; i < maxlen; j++) { |
718 | src_char = source[i]; | 727 | src_char = source[i]; |
719 | switch (src_char) { | 728 | switch (src_char) { |
720 | case 0: | 729 | case 0: |
@@ -737,7 +746,7 @@ cifsConvertToUCS(__le16 * target, const char *source, int maxlen, | |||
737 | break; | 746 | break; |
738 | case '|': | 747 | case '|': |
739 | target[j] = cpu_to_le16(UNI_PIPE); | 748 | target[j] = cpu_to_le16(UNI_PIPE); |
740 | break; | 749 | break; |
741 | /* BB We can not handle remapping slash until | 750 | /* BB We can not handle remapping slash until |
742 | all the calls to build_path_from_dentry | 751 | all the calls to build_path_from_dentry |
743 | are modified, as they use slash as separator BB */ | 752 | are modified, as they use slash as separator BB */ |
@@ -749,7 +758,7 @@ cifsConvertToUCS(__le16 * target, const char *source, int maxlen, | |||
749 | len_remaining, &temp); | 758 | len_remaining, &temp); |
750 | /* if no match, use question mark, which | 759 | /* if no match, use question mark, which |
751 | at least in some cases servers as wild card */ | 760 | at least in some cases servers as wild card */ |
752 | if(charlen < 1) { | 761 | if (charlen < 1) { |
753 | target[j] = cpu_to_le16(0x003f); | 762 | target[j] = cpu_to_le16(0x003f); |
754 | charlen = 1; | 763 | charlen = 1; |
755 | } else | 764 | } else |
@@ -758,7 +767,7 @@ cifsConvertToUCS(__le16 * target, const char *source, int maxlen, | |||
758 | /* character may take more than one byte in the | 767 | /* character may take more than one byte in the |
759 | the source string, but will take exactly two | 768 | the source string, but will take exactly two |
760 | bytes in the target string */ | 769 | bytes in the target string */ |
761 | i+= charlen; | 770 | i += charlen; |
762 | continue; | 771 | continue; |
763 | } | 772 | } |
764 | i++; /* move to next char in source string */ | 773 | i++; /* move to next char in source string */ |