misc.c 22 KB

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