misc.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /*
  2. * fs/cifs/misc.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002,2005
  5. * Author(s): Steve French (sfrench@us.ibm.com)
  6. *
  7. * This library is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published
  9. * by the Free Software Foundation; either version 2.1 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  15. * the GNU Lesser General Public License for more details.
  16. *
  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
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/slab.h>
  22. #include <linux/ctype.h>
  23. #include <linux/mempool.h>
  24. #include "cifspdu.h"
  25. #include "cifsglob.h"
  26. #include "cifsproto.h"
  27. #include "cifs_debug.h"
  28. #include "smberr.h"
  29. #include "nterr.h"
  30. #include "cifs_unicode.h"
  31. extern mempool_t *cifs_sm_req_poolp;
  32. extern mempool_t *cifs_req_poolp;
  33. extern struct task_struct * oplockThread;
  34. /* The xid serves as a useful identifier for each incoming vfs request,
  35. in a similar way to the mid which is useful to track each sent smb,
  36. and CurrentXid can also provide a running counter (although it
  37. will eventually wrap past zero) of the total vfs operations handled
  38. since the cifs fs was mounted */
  39. unsigned int
  40. _GetXid(void)
  41. {
  42. unsigned int xid;
  43. spin_lock(&GlobalMid_Lock);
  44. GlobalTotalActiveXid++;
  45. if (GlobalTotalActiveXid > GlobalMaxActiveXid)
  46. GlobalMaxActiveXid = GlobalTotalActiveXid; /* keep high water mark for number of simultaneous vfs ops in our filesystem */
  47. if(GlobalTotalActiveXid > 65000)
  48. cFYI(1,("warning: more than 65000 requests active"));
  49. xid = GlobalCurrentXid++;
  50. spin_unlock(&GlobalMid_Lock);
  51. return xid;
  52. }
  53. void
  54. _FreeXid(unsigned int xid)
  55. {
  56. spin_lock(&GlobalMid_Lock);
  57. /* if(GlobalTotalActiveXid == 0)
  58. BUG(); */
  59. GlobalTotalActiveXid--;
  60. spin_unlock(&GlobalMid_Lock);
  61. }
  62. struct cifsSesInfo *
  63. sesInfoAlloc(void)
  64. {
  65. struct cifsSesInfo *ret_buf;
  66. ret_buf =
  67. (struct cifsSesInfo *) kzalloc(sizeof (struct cifsSesInfo),
  68. GFP_KERNEL);
  69. if (ret_buf) {
  70. write_lock(&GlobalSMBSeslock);
  71. atomic_inc(&sesInfoAllocCount);
  72. ret_buf->status = CifsNew;
  73. list_add(&ret_buf->cifsSessionList, &GlobalSMBSessionList);
  74. init_MUTEX(&ret_buf->sesSem);
  75. write_unlock(&GlobalSMBSeslock);
  76. }
  77. return ret_buf;
  78. }
  79. void
  80. sesInfoFree(struct cifsSesInfo *buf_to_free)
  81. {
  82. if (buf_to_free == NULL) {
  83. cFYI(1, ("Null buffer passed to sesInfoFree"));
  84. return;
  85. }
  86. write_lock(&GlobalSMBSeslock);
  87. atomic_dec(&sesInfoAllocCount);
  88. list_del(&buf_to_free->cifsSessionList);
  89. write_unlock(&GlobalSMBSeslock);
  90. kfree(buf_to_free->serverOS);
  91. kfree(buf_to_free->serverDomain);
  92. kfree(buf_to_free->serverNOS);
  93. kfree(buf_to_free->password);
  94. kfree(buf_to_free);
  95. }
  96. struct cifsTconInfo *
  97. tconInfoAlloc(void)
  98. {
  99. struct cifsTconInfo *ret_buf;
  100. ret_buf =
  101. (struct cifsTconInfo *) kzalloc(sizeof (struct cifsTconInfo),
  102. GFP_KERNEL);
  103. if (ret_buf) {
  104. write_lock(&GlobalSMBSeslock);
  105. atomic_inc(&tconInfoAllocCount);
  106. list_add(&ret_buf->cifsConnectionList,
  107. &GlobalTreeConnectionList);
  108. ret_buf->tidStatus = CifsNew;
  109. INIT_LIST_HEAD(&ret_buf->openFileList);
  110. init_MUTEX(&ret_buf->tconSem);
  111. #ifdef CONFIG_CIFS_STATS
  112. spin_lock_init(&ret_buf->stat_lock);
  113. #endif
  114. write_unlock(&GlobalSMBSeslock);
  115. }
  116. return ret_buf;
  117. }
  118. void
  119. tconInfoFree(struct cifsTconInfo *buf_to_free)
  120. {
  121. if (buf_to_free == NULL) {
  122. cFYI(1, ("Null buffer passed to tconInfoFree"));
  123. return;
  124. }
  125. write_lock(&GlobalSMBSeslock);
  126. atomic_dec(&tconInfoAllocCount);
  127. list_del(&buf_to_free->cifsConnectionList);
  128. write_unlock(&GlobalSMBSeslock);
  129. kfree(buf_to_free->nativeFileSystem);
  130. kfree(buf_to_free);
  131. }
  132. struct smb_hdr *
  133. cifs_buf_get(void)
  134. {
  135. struct smb_hdr *ret_buf = NULL;
  136. /* We could use negotiated size instead of max_msgsize -
  137. but it may be more efficient to always alloc same size
  138. albeit slightly larger than necessary and maxbuffersize
  139. defaults to this and can not be bigger */
  140. ret_buf =
  141. (struct smb_hdr *) mempool_alloc(cifs_req_poolp, SLAB_KERNEL | SLAB_NOFS);
  142. /* clear the first few header bytes */
  143. /* for most paths, more is cleared in header_assemble */
  144. if (ret_buf) {
  145. memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
  146. atomic_inc(&bufAllocCount);
  147. #ifdef CONFIG_CIFS_STATS2
  148. atomic_inc(&totBufAllocCount);
  149. #endif /* CONFIG_CIFS_STATS2 */
  150. }
  151. return ret_buf;
  152. }
  153. void
  154. cifs_buf_release(void *buf_to_free)
  155. {
  156. if (buf_to_free == NULL) {
  157. /* cFYI(1, ("Null buffer passed to cifs_buf_release"));*/
  158. return;
  159. }
  160. mempool_free(buf_to_free,cifs_req_poolp);
  161. atomic_dec(&bufAllocCount);
  162. return;
  163. }
  164. struct smb_hdr *
  165. cifs_small_buf_get(void)
  166. {
  167. struct smb_hdr *ret_buf = NULL;
  168. /* We could use negotiated size instead of max_msgsize -
  169. but it may be more efficient to always alloc same size
  170. albeit slightly larger than necessary and maxbuffersize
  171. defaults to this and can not be bigger */
  172. ret_buf =
  173. (struct smb_hdr *) mempool_alloc(cifs_sm_req_poolp, SLAB_KERNEL | SLAB_NOFS);
  174. if (ret_buf) {
  175. /* No need to clear memory here, cleared in header assemble */
  176. /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
  177. atomic_inc(&smBufAllocCount);
  178. #ifdef CONFIG_CIFS_STATS2
  179. atomic_inc(&totSmBufAllocCount);
  180. #endif /* CONFIG_CIFS_STATS2 */
  181. }
  182. return ret_buf;
  183. }
  184. void
  185. cifs_small_buf_release(void *buf_to_free)
  186. {
  187. if (buf_to_free == NULL) {
  188. cFYI(1, ("Null buffer passed to cifs_small_buf_release"));
  189. return;
  190. }
  191. mempool_free(buf_to_free,cifs_sm_req_poolp);
  192. atomic_dec(&smBufAllocCount);
  193. return;
  194. }
  195. /*
  196. Find a free multiplex id (SMB mid). Otherwise there could be
  197. mid collisions which might cause problems, demultiplexing the
  198. wrong response to this request. Multiplex ids could collide if
  199. one of a series requests takes much longer than the others, or
  200. if a very large number of long lived requests (byte range
  201. locks or FindNotify requests) are pending. No more than
  202. 64K-1 requests can be outstanding at one time. If no
  203. mids are available, return zero. A future optimization
  204. could make the combination of mids and uid the key we use
  205. to demultiplex on (rather than mid alone).
  206. In addition to the above check, the cifs demultiplex
  207. code already used the command code as a secondary
  208. check of the frame and if signing is negotiated the
  209. response would be discarded if the mid were the same
  210. but the signature was wrong. Since the mid is not put in the
  211. pending queue until later (when it is about to be dispatched)
  212. we do have to limit the number of outstanding requests
  213. to somewhat less than 64K-1 although it is hard to imagine
  214. so many threads being in the vfs at one time.
  215. */
  216. __u16 GetNextMid(struct TCP_Server_Info *server)
  217. {
  218. __u16 mid = 0;
  219. __u16 last_mid;
  220. int collision;
  221. if(server == NULL)
  222. return mid;
  223. spin_lock(&GlobalMid_Lock);
  224. last_mid = server->CurrentMid; /* we do not want to loop forever */
  225. server->CurrentMid++;
  226. /* This nested loop looks more expensive than it is.
  227. In practice the list of pending requests is short,
  228. fewer than 50, and the mids are likely to be unique
  229. on the first pass through the loop unless some request
  230. takes longer than the 64 thousand requests before it
  231. (and it would also have to have been a request that
  232. did not time out) */
  233. while(server->CurrentMid != last_mid) {
  234. struct list_head *tmp;
  235. struct mid_q_entry *mid_entry;
  236. collision = 0;
  237. if(server->CurrentMid == 0)
  238. server->CurrentMid++;
  239. list_for_each(tmp, &server->pending_mid_q) {
  240. mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  241. if ((mid_entry->mid == server->CurrentMid) &&
  242. (mid_entry->midState == MID_REQUEST_SUBMITTED)) {
  243. /* This mid is in use, try a different one */
  244. collision = 1;
  245. break;
  246. }
  247. }
  248. if(collision == 0) {
  249. mid = server->CurrentMid;
  250. break;
  251. }
  252. server->CurrentMid++;
  253. }
  254. spin_unlock(&GlobalMid_Lock);
  255. return mid;
  256. }
  257. /* NB: MID can not be set if treeCon not passed in, in that
  258. case it is responsbility of caller to set the mid */
  259. void
  260. header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,
  261. const struct cifsTconInfo *treeCon, int word_count
  262. /* length of fixed section (word count) in two byte units */)
  263. {
  264. struct list_head* temp_item;
  265. struct cifsSesInfo * ses;
  266. char *temp = (char *) buffer;
  267. memset(temp,0,256); /* bigger than MAX_CIFS_HDR_SIZE */
  268. buffer->smb_buf_length =
  269. (2 * word_count) + sizeof (struct smb_hdr) -
  270. 4 /* RFC 1001 length field does not count */ +
  271. 2 /* for bcc field itself */ ;
  272. /* Note that this is the only network field that has to be converted
  273. to big endian and it is done just before we send it */
  274. buffer->Protocol[0] = 0xFF;
  275. buffer->Protocol[1] = 'S';
  276. buffer->Protocol[2] = 'M';
  277. buffer->Protocol[3] = 'B';
  278. buffer->Command = smb_command;
  279. buffer->Flags = 0x00; /* case sensitive */
  280. buffer->Flags2 = SMBFLG2_KNOWS_LONG_NAMES;
  281. buffer->Pid = cpu_to_le16((__u16)current->tgid);
  282. buffer->PidHigh = cpu_to_le16((__u16)(current->tgid >> 16));
  283. spin_lock(&GlobalMid_Lock);
  284. spin_unlock(&GlobalMid_Lock);
  285. if (treeCon) {
  286. buffer->Tid = treeCon->tid;
  287. if (treeCon->ses) {
  288. if (treeCon->ses->capabilities & CAP_UNICODE)
  289. buffer->Flags2 |= SMBFLG2_UNICODE;
  290. if (treeCon->ses->capabilities & CAP_STATUS32) {
  291. buffer->Flags2 |= SMBFLG2_ERR_STATUS;
  292. }
  293. /* Uid is not converted */
  294. buffer->Uid = treeCon->ses->Suid;
  295. buffer->Mid = GetNextMid(treeCon->ses->server);
  296. if(multiuser_mount != 0) {
  297. /* For the multiuser case, there are few obvious technically */
  298. /* possible mechanisms to match the local linux user (uid) */
  299. /* to a valid remote smb user (smb_uid): */
  300. /* 1) Query Winbind (or other local pam/nss daemon */
  301. /* for userid/password/logon_domain or credential */
  302. /* 2) Query Winbind for uid to sid to username mapping */
  303. /* and see if we have a matching password for existing*/
  304. /* session for that user perhas getting password by */
  305. /* adding a new pam_cifs module that stores passwords */
  306. /* so that the cifs vfs can get at that for all logged*/
  307. /* on users */
  308. /* 3) (Which is the mechanism we have chosen) */
  309. /* Search through sessions to the same server for a */
  310. /* a match on the uid that was passed in on mount */
  311. /* with the current processes uid (or euid?) and use */
  312. /* that smb uid. If no existing smb session for */
  313. /* that uid found, use the default smb session ie */
  314. /* the smb session for the volume mounted which is */
  315. /* the same as would be used if the multiuser mount */
  316. /* flag were disabled. */
  317. /* BB Add support for establishing new tCon and SMB Session */
  318. /* with userid/password pairs found on the smb session */
  319. /* for other target tcp/ip addresses BB */
  320. if(current->fsuid != treeCon->ses->linux_uid) {
  321. cFYI(1,("Multiuser mode and UID did not match tcon uid"));
  322. read_lock(&GlobalSMBSeslock);
  323. list_for_each(temp_item, &GlobalSMBSessionList) {
  324. ses = list_entry(temp_item, struct cifsSesInfo, cifsSessionList);
  325. if(ses->linux_uid == current->fsuid) {
  326. if(ses->server == treeCon->ses->server) {
  327. cFYI(1,("found matching uid substitute right smb_uid"));
  328. buffer->Uid = ses->Suid;
  329. break;
  330. } else {
  331. /* BB eventually call cifs_setup_session here */
  332. cFYI(1,("local UID found but smb sess with this server does not exist"));
  333. }
  334. }
  335. }
  336. read_unlock(&GlobalSMBSeslock);
  337. }
  338. }
  339. }
  340. if (treeCon->Flags & SMB_SHARE_IS_IN_DFS)
  341. buffer->Flags2 |= SMBFLG2_DFS;
  342. if (treeCon->nocase)
  343. buffer->Flags |= SMBFLG_CASELESS;
  344. if((treeCon->ses) && (treeCon->ses->server))
  345. if(treeCon->ses->server->secMode &
  346. (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
  347. buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
  348. }
  349. /* endian conversion of flags is now done just before sending */
  350. buffer->WordCount = (char) word_count;
  351. return;
  352. }
  353. int
  354. checkSMBhdr(struct smb_hdr *smb, __u16 mid)
  355. {
  356. /* Make sure that this really is an SMB, that it is a response,
  357. and that the message ids match */
  358. if ((*(__le32 *) smb->Protocol == cpu_to_le32(0x424d53ff)) &&
  359. (mid == smb->Mid)) {
  360. if(smb->Flags & SMBFLG_RESPONSE)
  361. return 0;
  362. else {
  363. /* only one valid case where server sends us request */
  364. if(smb->Command == SMB_COM_LOCKING_ANDX)
  365. return 0;
  366. else
  367. cERROR(1, ("Rcvd Request not response"));
  368. }
  369. } else { /* bad signature or mid */
  370. if (*(__le32 *) smb->Protocol != cpu_to_le32(0x424d53ff))
  371. cERROR(1,
  372. ("Bad protocol string signature header %x",
  373. *(unsigned int *) smb->Protocol));
  374. if (mid != smb->Mid)
  375. cERROR(1, ("Mids do not match"));
  376. }
  377. cERROR(1, ("bad smb detected. The Mid=%d", smb->Mid));
  378. return 1;
  379. }
  380. int
  381. checkSMB(struct smb_hdr *smb, __u16 mid, int length)
  382. {
  383. __u32 len = smb->smb_buf_length;
  384. __u32 clc_len; /* calculated length */
  385. cFYI(0, ("checkSMB Length: 0x%x, smb_buf_length: 0x%x", length, len));
  386. if (((unsigned int)length < 2 + sizeof (struct smb_hdr)) ||
  387. (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4)) {
  388. if ((unsigned int)length < 2 + sizeof (struct smb_hdr)) {
  389. if (((unsigned int)length >=
  390. sizeof (struct smb_hdr) - 1)
  391. && (smb->Status.CifsError != 0)) {
  392. smb->WordCount = 0;
  393. /* some error cases do not return wct and bcc */
  394. return 0;
  395. } else {
  396. cERROR(1, ("Length less than smb header size"));
  397. }
  398. }
  399. if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4)
  400. cERROR(1, ("smb length greater than MaxBufSize, mid=%d",
  401. smb->Mid));
  402. return 1;
  403. }
  404. if (checkSMBhdr(smb, mid))
  405. return 1;
  406. clc_len = smbCalcSize_LE(smb);
  407. if(4 + len != (unsigned int)length) {
  408. cERROR(1, ("Length read does not match RFC1001 length %d",len));
  409. return 1;
  410. }
  411. if (4 + len != clc_len) {
  412. /* check if bcc wrapped around for large read responses */
  413. if((len > 64 * 1024) && (len > clc_len)) {
  414. /* check if lengths match mod 64K */
  415. if(((4 + len) & 0xFFFF) == (clc_len & 0xFFFF))
  416. return 0; /* bcc wrapped */
  417. }
  418. cFYI(1, ("Calculated size %d vs length %d mismatch for mid %d",
  419. clc_len, 4 + len, smb->Mid));
  420. /* Windows XP can return a few bytes too much, presumably
  421. an illegal pad, at the end of byte range lock responses
  422. so we allow for that three byte pad, as long as actual
  423. received length is as long or longer than calculated length */
  424. /* We have now had to extend this more, since there is a
  425. case in which it needs to be bigger still to handle a
  426. malformed response to transact2 findfirst from WinXP when
  427. access denied is returned and thus bcc and wct are zero
  428. but server says length is 0x21 bytes too long as if the server
  429. forget to reset the smb rfc1001 length when it reset the
  430. wct and bcc to minimum size and drop the t2 parms and data */
  431. if((4+len > clc_len) && (len <= clc_len + 512))
  432. return 0;
  433. else {
  434. cERROR(1, ("RFC1001 size %d bigger than SMB for Mid=%d",
  435. len, smb->Mid));
  436. return 1;
  437. }
  438. }
  439. return 0;
  440. }
  441. int
  442. is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
  443. {
  444. struct smb_com_lock_req * pSMB = (struct smb_com_lock_req *)buf;
  445. struct list_head *tmp;
  446. struct list_head *tmp1;
  447. struct cifsTconInfo *tcon;
  448. struct cifsFileInfo *netfile;
  449. cFYI(1,("Checking for oplock break or dnotify response"));
  450. if((pSMB->hdr.Command == SMB_COM_NT_TRANSACT) &&
  451. (pSMB->hdr.Flags & SMBFLG_RESPONSE)) {
  452. struct smb_com_transaction_change_notify_rsp * pSMBr =
  453. (struct smb_com_transaction_change_notify_rsp *)buf;
  454. struct file_notify_information * pnotify;
  455. __u32 data_offset = 0;
  456. if(pSMBr->ByteCount > sizeof(struct file_notify_information)) {
  457. data_offset = le32_to_cpu(pSMBr->DataOffset);
  458. pnotify = (struct file_notify_information *)((char *)&pSMBr->hdr.Protocol
  459. + data_offset);
  460. cFYI(1,("dnotify on %s with action: 0x%x",pnotify->FileName,
  461. pnotify->Action)); /* BB removeme BB */
  462. /* cifs_dump_mem("Received notify Data is: ",buf,sizeof(struct smb_hdr)+60); */
  463. return TRUE;
  464. }
  465. if(pSMBr->hdr.Status.CifsError) {
  466. cFYI(1,("notify err 0x%d",pSMBr->hdr.Status.CifsError));
  467. return TRUE;
  468. }
  469. return FALSE;
  470. }
  471. if(pSMB->hdr.Command != SMB_COM_LOCKING_ANDX)
  472. return FALSE;
  473. if(pSMB->hdr.Flags & SMBFLG_RESPONSE) {
  474. /* no sense logging error on invalid handle on oplock
  475. break - harmless race between close request and oplock
  476. break response is expected from time to time writing out
  477. large dirty files cached on the client */
  478. if ((NT_STATUS_INVALID_HANDLE) ==
  479. le32_to_cpu(pSMB->hdr.Status.CifsError)) {
  480. cFYI(1,("invalid handle on oplock break"));
  481. return TRUE;
  482. } else if (ERRbadfid ==
  483. le16_to_cpu(pSMB->hdr.Status.DosError.Error)) {
  484. return TRUE;
  485. } else {
  486. return FALSE; /* on valid oplock brk we get "request" */
  487. }
  488. }
  489. if(pSMB->hdr.WordCount != 8)
  490. return FALSE;
  491. cFYI(1,(" oplock type 0x%d level 0x%d",pSMB->LockType,pSMB->OplockLevel));
  492. if(!(pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE))
  493. return FALSE;
  494. /* look up tcon based on tid & uid */
  495. read_lock(&GlobalSMBSeslock);
  496. list_for_each(tmp, &GlobalTreeConnectionList) {
  497. tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
  498. if ((tcon->tid == buf->Tid) && (srv == tcon->ses->server)) {
  499. cifs_stats_inc(&tcon->num_oplock_brks);
  500. list_for_each(tmp1,&tcon->openFileList){
  501. netfile = list_entry(tmp1,struct cifsFileInfo,
  502. tlist);
  503. if(pSMB->Fid == netfile->netfid) {
  504. struct cifsInodeInfo *pCifsInode;
  505. read_unlock(&GlobalSMBSeslock);
  506. cFYI(1,("file id match, oplock break"));
  507. pCifsInode =
  508. CIFS_I(netfile->pInode);
  509. pCifsInode->clientCanCacheAll = FALSE;
  510. if(pSMB->OplockLevel == 0)
  511. pCifsInode->clientCanCacheRead
  512. = FALSE;
  513. pCifsInode->oplockPending = TRUE;
  514. AllocOplockQEntry(netfile->pInode,
  515. netfile->netfid,
  516. tcon);
  517. cFYI(1,("about to wake up oplock thd"));
  518. if(oplockThread)
  519. wake_up_process(oplockThread);
  520. return TRUE;
  521. }
  522. }
  523. read_unlock(&GlobalSMBSeslock);
  524. cFYI(1,("No matching file for oplock break"));
  525. return TRUE;
  526. }
  527. }
  528. read_unlock(&GlobalSMBSeslock);
  529. cFYI(1,("Can not process oplock break for non-existent connection"));
  530. return TRUE;
  531. }
  532. void
  533. dump_smb(struct smb_hdr *smb_buf, int smb_buf_length)
  534. {
  535. int i, j;
  536. char debug_line[17];
  537. unsigned char *buffer;
  538. if (traceSMB == 0)
  539. return;
  540. buffer = (unsigned char *) smb_buf;
  541. for (i = 0, j = 0; i < smb_buf_length; i++, j++) {
  542. if (i % 8 == 0) { /* have reached the beginning of line */
  543. printk(KERN_DEBUG "| ");
  544. j = 0;
  545. }
  546. printk("%0#4x ", buffer[i]);
  547. debug_line[2 * j] = ' ';
  548. if (isprint(buffer[i]))
  549. debug_line[1 + (2 * j)] = buffer[i];
  550. else
  551. debug_line[1 + (2 * j)] = '_';
  552. if (i % 8 == 7) { /* reached end of line, time to print ascii */
  553. debug_line[16] = 0;
  554. printk(" | %s\n", debug_line);
  555. }
  556. }
  557. for (; j < 8; j++) {
  558. printk(" ");
  559. debug_line[2 * j] = ' ';
  560. debug_line[1 + (2 * j)] = ' ';
  561. }
  562. printk( " | %s\n", debug_line);
  563. return;
  564. }
  565. /* Windows maps these to the user defined 16 bit Unicode range since they are
  566. reserved symbols (along with \ and /), otherwise illegal to store
  567. in filenames in NTFS */
  568. #define UNI_ASTERIK (__u16) ('*' + 0xF000)
  569. #define UNI_QUESTION (__u16) ('?' + 0xF000)
  570. #define UNI_COLON (__u16) (':' + 0xF000)
  571. #define UNI_GRTRTHAN (__u16) ('>' + 0xF000)
  572. #define UNI_LESSTHAN (__u16) ('<' + 0xF000)
  573. #define UNI_PIPE (__u16) ('|' + 0xF000)
  574. #define UNI_SLASH (__u16) ('\\' + 0xF000)
  575. /* Convert 16 bit Unicode pathname from wire format to string in current code
  576. page. Conversion may involve remapping up the seven characters that are
  577. only legal in POSIX-like OS (if they are present in the string). Path
  578. names are little endian 16 bit Unicode on the wire */
  579. int
  580. cifs_convertUCSpath(char *target, const __le16 * source, int maxlen,
  581. const struct nls_table * cp)
  582. {
  583. int i,j,len;
  584. __u16 src_char;
  585. for(i = 0, j = 0; i < maxlen; i++) {
  586. src_char = le16_to_cpu(source[i]);
  587. switch (src_char) {
  588. case 0:
  589. goto cUCS_out; /* BB check this BB */
  590. case UNI_COLON:
  591. target[j] = ':';
  592. break;
  593. case UNI_ASTERIK:
  594. target[j] = '*';
  595. break;
  596. case UNI_QUESTION:
  597. target[j] = '?';
  598. break;
  599. /* BB We can not handle remapping slash until
  600. all the calls to build_path_from_dentry
  601. are modified, as they use slash as separator BB */
  602. /* case UNI_SLASH:
  603. target[j] = '\\';
  604. break;*/
  605. case UNI_PIPE:
  606. target[j] = '|';
  607. break;
  608. case UNI_GRTRTHAN:
  609. target[j] = '>';
  610. break;
  611. case UNI_LESSTHAN:
  612. target[j] = '<';
  613. break;
  614. default:
  615. len = cp->uni2char(src_char, &target[j],
  616. NLS_MAX_CHARSET_SIZE);
  617. if(len > 0) {
  618. j += len;
  619. continue;
  620. } else {
  621. target[j] = '?';
  622. }
  623. }
  624. j++;
  625. /* make sure we do not overrun callers allocated temp buffer */
  626. if(j >= (2 * NAME_MAX))
  627. break;
  628. }
  629. cUCS_out:
  630. target[j] = 0;
  631. return j;
  632. }
  633. /* Convert 16 bit Unicode pathname to wire format from string in current code
  634. page. Conversion may involve remapping up the seven characters that are
  635. only legal in POSIX-like OS (if they are present in the string). Path
  636. names are little endian 16 bit Unicode on the wire */
  637. int
  638. cifsConvertToUCS(__le16 * target, const char *source, int maxlen,
  639. const struct nls_table * cp, int mapChars)
  640. {
  641. int i,j,charlen;
  642. int len_remaining = maxlen;
  643. char src_char;
  644. __u16 temp;
  645. if(!mapChars)
  646. return cifs_strtoUCS(target, source, PATH_MAX, cp);
  647. for(i = 0, j = 0; i < maxlen; j++) {
  648. src_char = source[i];
  649. switch (src_char) {
  650. case 0:
  651. target[j] = 0;
  652. goto ctoUCS_out;
  653. case ':':
  654. target[j] = cpu_to_le16(UNI_COLON);
  655. break;
  656. case '*':
  657. target[j] = cpu_to_le16(UNI_ASTERIK);
  658. break;
  659. case '?':
  660. target[j] = cpu_to_le16(UNI_QUESTION);
  661. break;
  662. case '<':
  663. target[j] = cpu_to_le16(UNI_LESSTHAN);
  664. break;
  665. case '>':
  666. target[j] = cpu_to_le16(UNI_GRTRTHAN);
  667. break;
  668. case '|':
  669. target[j] = cpu_to_le16(UNI_PIPE);
  670. break;
  671. /* BB We can not handle remapping slash until
  672. all the calls to build_path_from_dentry
  673. are modified, as they use slash as separator BB */
  674. /* case '\\':
  675. target[j] = cpu_to_le16(UNI_SLASH);
  676. break;*/
  677. default:
  678. charlen = cp->char2uni(source+i,
  679. len_remaining, &temp);
  680. /* if no match, use question mark, which
  681. at least in some cases servers as wild card */
  682. if(charlen < 1) {
  683. target[j] = cpu_to_le16(0x003f);
  684. charlen = 1;
  685. } else
  686. target[j] = cpu_to_le16(temp);
  687. len_remaining -= charlen;
  688. /* character may take more than one byte in the
  689. the source string, but will take exactly two
  690. bytes in the target string */
  691. i+= charlen;
  692. continue;
  693. }
  694. i++; /* move to next char in source string */
  695. len_remaining--;
  696. }
  697. ctoUCS_out:
  698. return i;
  699. }